512 bytes! We have a ROM that actually does something that is the size of a full MD header. It's worth noting that the only emulator that will run the ROMs from this point is Regen. Surely we can't go smaller than this. Or can we...?

Turns out, a lot of the header isn't required. In fact, most of it - the only *requirement* is the first 8 bytes. So if we set the start of the code to $8... we can just paste our code straight afterwards removing almost the entire header.

Part of the code is used to set the start of the code. A nop (4E71) is added to align it to the correct place and then the code sets the start to $0. This then runs through the code again, ignores the nop, and executes the rest as normal - so the bytes used to set the address of the code are reused as part of the code.

I don't know how well I explained that or if you will understand it. Please ask if you don't get it.

===

From this point I'd pretty much called it a day, there wasn't much more i could do to optimise this any further. I sent the ROMs off to TmEE to find out which ones will run on hardware. Unfortunatly none :(. Well, at least they were running on Regen!

Anyway, after this he sent me the smallest ROM he could think of that runs on hardware. 38 bytes! Apparently, the MD required some VDP initilisation that I overlooked. Here is his code;

Note; this will work on non-TMSS hardware only, TMSS based ROMs have a lower bound and trying to make them small is fairly trivial and uninteresting.

Anyhoo, as you can see the code is pretty compact leaving little room for optimisation. That doesn't mean I didn't try anyway ;)

Here is my final piece of code. With use of the trick I demonstrated before, and a little shifting around of the code, I managed to get it down to 32 bytes. Just trace the execution of this thing, it's beautiful.

This is surely interesting information for 256/512b intro or minigame (1K/2K/4K) creators.

I think, relying for padding zeroes is somewhat wrong, because in the real world if you have, say, 256 byte ROM chip, it will not have zeroes above 256 byte. Instead, it will be repeated throughout whole address space.

Most of the exception vectors will never get called, so you could easily use most of that space for code. The rom header should probably be left alone, but you could also stick code or data in the strings of the header.

Chinese programmers don't fill required header (except vectors table) and they games run only on chinese MD clones (without TMSS). So, to run your code on MD with TMSS you will need to fill only used vectors and string at $100..$103 (wich contains "SEGA" word, that presence checked by TMSS). All other places can be filled your own data/code.

snkenjoi wrote:Here is my final piece of code. With use of the trick I demonstrated before, and a little shifting around of the code, I managed to get it down to 32 bytes. Just trace the execution of this thing, it's beautiful.

Nice, but it could be shorter. You get a free register load because of the stack pointer, and you're moving 2 words that you can fit into 1 longword.

You might argue the validity of what I'm going to say next, but I believe it counts.

I believe 26 bytes is possible by simply truncating your example to 26. This will cause the game to crash eventually. However, this will not change the graphics on the screen - resulting in the same behaviour as the infinite loop anyway. This leads me to think you can just drop it. Ugly, but it works. (I think?)

snkenjoi wrote:Note; this will work on non-TMSS hardware only, TMSS based ROMs have a lower bound and trying to make them small is fairly trivial and uninteresting.

Sure I did. That doesn't change my position that unless it works on all (official) models, it doesn't count. It's not so much that the minimum size is 260 bytes as much as what you do with it. Who gives a rat's ass if you can do a "loop: bra loop" demo - I want a tiny demo that really does something (and works on any model).

Without TMSS, the smallest rom possible is always going to be 10 bytes: the reset SSP, the reset PC, and one bra.b opcode. There's nothing special about that. That won't earn anything more than "Noob...".