Minimal midlet

jarnoh@komplex.org

proof-of-concept level midlet showing a graphical effect with hardcore size optimization: 937 bytes as MIDP 2.0 ready-to-run JAR application. I know, I'm bending the rules quite a bit here...

In my earlier experiments, I had figured that basic demo effect would need something like 1400 bytes to be properly executed in MIDP environment. This sounded like a lot to me, so this is my attempt to break down some MIDP size barriers. Long story short, some techniques used:

Needless to say, it doesn't even contain exit! On nokia series 40 devices, hold down that red button to kill midlet. And if you manage to optimize this further, I'm all ears...

Edit

  1. Just noticed that using just g.setColor(-(a & 1)); would cut down size to 936 bytes.
    And really, it was just a leftover after experimenting with colors. Try something like g.setColor(0x382007*(a & 3)); for colors (941 bytes). Using some other dimensions for fillArc would give you footprint of about 930 bytes, but then it wouldnt fill screen on most of the devices


minilet.jad minilet.jar
minilet.zip (includes jad, jar)

Source

Source code in beatiful decompiled format, as generated by excellent JAD decompiler.

a.java (entrypoint)

// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) annotate

import javax.microedition.midlet.MIDlet;

public class a extends MIDlet
{

    public a()
    {
    //    0    0:aload_0
    //    1    1:invokespecial   #4   
    //    2    4:return
    }

    public void startApp()
    {
        new b(this);
    //    0    0:new             #2   
    //    1    3:aload_0
    //    2    4:invokespecial   #5   
    //    3    7:return
    }
}

b.java (Canvas)

// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) annotate 

import javax.microedition.lcdui.*;

public final class b extends Canvas
{

    public b(a a1)
    {
    //    0    0:aload_0         
    //    1    1:invokespecial   #6   
        Display.getDisplay(a1).setCurrent(this);
    //    2    4:aload_1         
    //    3    5:invokestatic    #8   
    //    4    8:aload_0         
    //    5    9:invokevirtual   #12  
        do
        {
            repaint();
    //    6   12:aload_0         
    //    7   13:invokevirtual   #9   
            serviceRepaints();
    //    8   16:aload_0         
    //    9   17:invokevirtual   #10  
        } while(true);
    //   10   20:goto            12
    }

    public final void paint(Graphics g)
    {
        g.setColor(-1 * (a & 1));
    //    0    0:aload_1         
    //    1    1:iconst_m1       
    //    2    2:getstatic       #5   
    //    3    5:iconst_1        
    //    4    6:iand            
    //    5    7:imul            
    //    6    8:invokevirtual   #11  
        g.fillArc(-128, -128, 512, 512, a += 31, 32);
    //    7   11:aload_1         
    //    8   12:bipush          -128
    //    9   14:bipush          -128
    //   10   16:sipush          512
    //   11   19:sipush          512
    //   12   22:getstatic       #5   
    //   13   25:bipush          31
    //   14   27:iadd            
    //   15   28:dup             
    //   16   29:putstatic       #5   
    //   17   32:bipush          32
    //   18   34:invokevirtual   #7   
    //   19   37:return          
    }

    public static int a;
}