# SMSEmu The Sega Master System on the Tamagotchi Paradise, as a further program of the Paramix menu. No ROM here: bring your own game (.sms, or .gg for the Game Gear: SMS_GG, 160 x 144 shrunk to 128 x 115, its 12-bit colours, START on port 0). State (SMS_STATE): on leaving (wheel held) the whole machine goes to the flash (`emu/src/emu/pstate.h`), read once at the next start. Settings: "Restart game". - `src/core/z80.h`: own Z80 interpreter (flags as on the chip, tables for sign, zero and parity). The opcode cases are generated by `src/core/gen_z80.py` into `z80_ops.inc` and `z80_fns.inc`. Passes zexdoc and zexall. - `src/core/sms.h`: the machine: memory map with read pages of 1 KB (the ROM is read in place from the flash window), Sega mapper (FFFC..FFFF, cartridge RAM up to 32 KB), VDP mode 4 (background with scrolling and the locked areas, priority, sprites 8 x 8 and 8 x 16, zoom, eight per line, overflow and collision flags, line and frame interrupts, tiles kept decoded), PSG registers, ports (pad, export console). NTSC timing: 262 lines of 228 cycles. - `src/app/main.c`: the Paradise program (PRAM, about 40 KB). Settings block "PMXS" at 0x140, laid out as GBEmu's: ROM, length, save (4 KB settings of the device, then the cartridge RAM, 32 KB), flags (bit 0 English, bit 1 wheel the other way round), name, keys (9 bytes). - Screen: 256 x 192 to 128 x 96, every 2 x 2 dots mixed, black bars above and below. Lines go to the display while the frame runs; a row that did not change is not sent again. Normally every second frame is drawn; when the game falls behind, up to three in a row are left out. - Keys: `keys[i]` are Master System buttons (1 up, 2 down, 4 left, 8 right, 16 button 1, 32 button 2, 64 pause) for the Paradise input i: 0 A, 1 B, 2 C, 3 wheel press, 4 wheel up, 5 wheel down, 6 A+C, 7 B+C, 8 A+B. Default: A left, B button 1, C right, wheel press button 2, wheel up/down, A+C pause. Fixed: A+B+C settings (pause, sound, light, dim, screen off, restart game, language); wheel held 2 s = save and back to the Paradise. - Sound: the loudest of the three tone channels on the buzzer (the noise channel never); a new pitch starts the timer anew (as GB_TONE_RESTART). - Save: the 4 KB pages of the cartridge RAM the game changed go to the flash 3 s after the last write (1 s without a key), when the screen goes off and on leaving. Build: `sh src/app/build.sh` (clang, lld) gives `sms.bin`. Test on the PC: `gcc -O2 -o smshost src/host/host.c`, then `SHOTS=100,200 KEYS=700:16,710:0 ./smshost game.sms 1000 outdir`. Device simulation: `python3 test/mkimg.py sms.bin game.sms img.bin` then `python3 test/devsms.py src/app/sms.elf img.bin ` (KEYS, WHEEL, SHOTS, OUT as for GBEmu; US_PX = display time per dot in microseconds). `test/zex.c` runs the CP/M exercisers (not included) on the Z80. Author: mameise No session (1.7.3 test7, switch SESS_FLAG): flags bit 12 set by the Studio ("Remember where you left off" off): leaving writes no state, a start drops an old one; only the game's own save (cartridge RAM or EEPROM) is kept.