The repository does not include the game. With the ROM at the root as elevator_sg.sg (32,768 bytes, sha1
f72b3e44309e7c2e447c46928ce795453102f717), make all traces the code, generates the listing, assembles it again
with pasmo and checks that the same ROM comes out, byte for byte; then the tests run. You need pasmo,
z80dasm, make and Python 3.
| code | 17,431 bytes |
| data | 15,337 bytes |
| instructions | 8,182, of which 3,776 carry a comment (46.2%) |
| named routines | 952 |
The listing comes from src/elevator_sg.notes (names and comments), src/elevator_sg.entries (the reset, the
interrupt, the NMI, the six jump tables and the three return addresses pushed before a jp (hl)) and
src/elevator_sg.nocode.
32 flat KB from 0x0000 to 0x7FFF, no mapper. The SG-1000 has no BIOS: the cartridge starts at address 0 with
di / ld sp,0xC400 / im 1 / jp 0x0069, the VDP interrupt comes in at 0x0038 and the pause button through the NMI
(0x0066).
| area | what is there |
|---|---|
| 0x0000-0x381F | the code, with its small tables in between |
| 0x3820-0x3F0D | the sound: 28 pieces and their envelopes |
| 0x3F0E-0x5B45 | more code: collisions, end of round, doors, drawing, title and demos |
| 0x5B46-0x5C4D | the title logo |
| 0x5C4E-0x5FFF | a 0x00 and 0xFF padding |
| 0x6000-0x719E | patterns, colours and sprites, compressed |
| 0x719F-0x7EBE | the score panel footer and the building's 103 row kinds |
| 0x7EBF-0x7FFF | a 0x00 and 0xFF padding |
The graphics are compressed with a simple scheme (descomprime, 0x1CB2): a count byte; with bit 7 clear, the next
byte is repeated that many times; with bit 7 set, that many bytes follow as they are.
bucle_juego (0x00FE) does one frame: it waits for the interrupt, brings enemies out of the doors, runs the 13
actors (each with its state from table 0x015F), moves the lifts and the view and repaints whatever changed. The
interrupt (int_cuadro, 0x0315) uses the alternate registers, copies the sprites to VRAM, swaps name tables, reads
the joypads, keeps the clock and plays the sound; it only does the game part once the loop has finished its frame
(0xC053).
The SG-1000 has 1 KB, from 0xC000 to 0xC3FF, and the stack grows down from 0xC400.
| where | what |
|---|---|
| 0xC000 | 0 if there is a keyboard |
| 0xC002 | the pause |
| 0xC008, 0xC00B, 0xC00E | the high score and both players' scores (BCD) |
| 0xC012-0xC02D | the other player's copy; 0xC02E the round, 0xC02F the lives |
| 0xC030, 0xC031 | the view and the round's building |
| 0xC032-0xC037 | the lamps (one bit each) |
| 0xC038-0xC047 | the red doors left (one bit each) |
| 0xC049, 0xC04A | the round clock |
| 0xC04F, 0xC050 | the joypads, this frame and the previous one |
| 0xC051, 0xC09C | the enemies' virtual joypad and each one's last |
| 0xC0A0-0xC20B | the 13 actors, 28 bytes each: agent's bullets (0-2), enemy bullets (3-6), the agent (7), the enemies (8-11) and the falling lamp (12) |
| 0xC20C-0xC25F | the copy of the 21 sprites |
| 0xC260-0xC2EE | the 11 lifts, 13 bytes each |
| 0xC2EF-0xC37C | the sound: the request, what is playing and the 5 channels |
tools/z80trace.py follows the flow from the entry points; tools/mkasm.py writes the listing with the notes;
tools/verify_build.sh assembles it and compares; tools/presupuesto.py checks that no byte is left unexplained;
tools/densidad.py measures the comments and tools/mapas.py paints the buildings. With the ROM, make sprites and make musica produce on your machine the sprites (PNG and GIF) and the music (MP3), which are not published.