Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.
C calculatorcalculator-gamescasiochesscrossy-roaddrive-madfx-cg50gamesgeometry-dashgraphing-calculatorndlessnumworksnumworks-appsnumworks-calculatornumworks-gamenumworks-gamestetristi-84-plus-ceti-nspire
Retro-Go: SG-1000 games
Mason363a75ec2e992a4
diff --git a/README.md b/README.mdindex 6826bf40..171d148b 100644--- a/README.md+++ b/README.md@@ -161,7 +161,7 @@ These are too big to fit next to NumPlay, so each one is its own app. Install it</tr></table>-Retro-Go plays the Game Boy, Game Boy Color, NES, Master System and Game Gear games you choose: games you own, or free ones like homebrew games. It isn't in NumPlay.nwa. Drop your games on [NumPlay Studio](https://mason363.github.io/NumPlay/customize/) and you get a NumPlay with Retro-Go and your games inside. Big games, like the 2 MB Game Boy Color ones, need the extra space of Epsilon 26 or Nwagra: pick it in NumPlay Studio.+Retro-Go plays the Game Boy, Game Boy Color, NES, Master System, Game Gear and SG-1000 games you choose: games you own, or free ones like homebrew games. It isn't in NumPlay.nwa. Drop your games on [NumPlay Studio](https://mason363.github.io/NumPlay/customize/) and you get a NumPlay with Retro-Go and your games inside. Big games, like the 2 MB Game Boy Color ones, need the extra space of Epsilon 26 or Nwagra: pick it in NumPlay Studio.Other apps for your calculator go in too: drop their .nwa files on [NumPlay Studio](https://mason363.github.io/NumPlay/customize/) and each one gets its own card in your NumPlay.@@ -301,6 +301,7 @@ Read **[Make your own NumWorks game](docs/make-a-game.md)** to go from there, an- [x] Mahjong- [x] Meowdoku- [x] Rider+- [x] SG-1000 games in Retro-Go- [ ] Full Minecraft 1.18.2 as a standalone app- [ ] Among Us, against bots- [ ] Cat Ninja@@ -323,7 +324,7 @@ Read **[Make your own NumWorks game](docs/make-a-game.md)** to go from there, an- [ ] Hungry Shark Evolution and Hungry Shark World- [ ] Castle Crashers- [ ] Hotline Miami-- [ ] More of Retro-Go: Game & Watch, SNES, Mega Drive, SG-1000 and ColecoVision+- [ ] More of Retro-Go: Game & Watch, SNES, Mega Drive and ColecoVision- [ ] Five Nights at Freddy's 2, 3, 4 and FNAF World- [ ] Brawl Stars, against bots- [ ] Papers, Please, with the story and Endless@@ -410,7 +411,7 @@ NumPlay is a fan project, made out of love for these games and for the NumWorksNumPlay is licensed under the [GNU General Public License v3.0](LICENSE). Copyright (c) 2026 Mason Chen. Code and fonts from others keep their own licenses: the `UNLICENSE` files in the games' folders and the [LICENSES](LICENSES) folder. The names, artwork and music of the games NumPlay is inspired by belong to their makers and are not covered by it.-<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, LocalThunk or Playstack (Balatro), Mike Klubnika or Critical Reflex (Buckshot Roulette), Hungry Studio (Block Blast!), Aladdin X (Suika Game), Voodoo (Flappy Dunk), Lima Sky (Doodle Jump), Mojang or Microsoft (Minecraft), Maddy Makes Games (Celeste), Team Cherry (Hollow Knight), Toby Fox (Undertale), jcw87 (Bad Time Simulator), id Software (Doom), Edmund McMillen, Florian Himsl or Nicalis (The Binding of Isaac), PopCap Games or Electronic Arts (Plants vs. Zombies), Scott Cawthon (Five Nights at Freddy's), SEGA (Sonic the Hedgehog, Master System, Game Gear), SYBO or Kiloo (Subway Surfers), Fingersoft (Hill Climb Racing), Unept (Level Devil), Halfbrick (Jetpack Joyride), Madbox (Stickman Hook), Nintendo (Donkey Kong, Game Boy, NES), Team Lava (Dune!), Inlogic Software (Dune Rider), TinyDobbins (Monkey Mart), Playgendary (Tomb of the Mask), Mattel (UNO), the Funkin' Crew (Friday Night Funkin'), W Production (Turbo Rush), Rovio Entertainment (Angry Birds), Kodub (PolyTrack), Frank Lantz or Everybody House Games (Universal Paperclips), Ketchapp (Rider), Brodie Lockard or Activision (Shanghai), Atari (Pong), Disney (Tron), Orteil or DashNet (Cookie Clicker), Taito or Midway (Space Invaders), Thinking Rabbit or Falcon (Sokoban), Oakever Games (Meowdoku), Florian van Strien (The Final Earth 2), The Powder Toy's developers (The Powder Toy), MateoConLechuga (Portal Returns), Valve (Portal), .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Chrome Dino, Doodle Champion Island Games), STUDIO4°C or Microsoft (Minesweeper), ducalex (Retro-Go). Tetris is a trademark of The Tetris Company, Chrome of Google LLC, Minecraft of Mojang Synergies AB, Pac-Man of Bandai Namco, Connect Four of Hasbro, DOOM of ZeniMax Media, Sonic the Hedgehog, Master System and Game Gear of SEGA, Space Invaders of Taito, UNO of Mattel, Angry Birds of Rovio Entertainment, and Donkey Kong, Game Boy, Game Boy Color and NES of Nintendo.</sub>+<sub>Unofficial fan games, not affiliated with NumWorks, RobTop Games (Geometry Dash), Hipster Whale (Crossy Road), the makers of Drive Mad, LocalThunk or Playstack (Balatro), Mike Klubnika or Critical Reflex (Buckshot Roulette), Hungry Studio (Block Blast!), Aladdin X (Suika Game), Voodoo (Flappy Dunk), Lima Sky (Doodle Jump), Mojang or Microsoft (Minecraft), Maddy Makes Games (Celeste), Team Cherry (Hollow Knight), Toby Fox (Undertale), jcw87 (Bad Time Simulator), id Software (Doom), Edmund McMillen, Florian Himsl or Nicalis (The Binding of Isaac), PopCap Games or Electronic Arts (Plants vs. Zombies), Scott Cawthon (Five Nights at Freddy's), SEGA (Sonic the Hedgehog, Master System, Game Gear, SG-1000), SYBO or Kiloo (Subway Surfers), Fingersoft (Hill Climb Racing), Unept (Level Devil), Halfbrick (Jetpack Joyride), Madbox (Stickman Hook), Nintendo (Donkey Kong, Game Boy, NES), Team Lava (Dune!), Inlogic Software (Dune Rider), TinyDobbins (Monkey Mart), Playgendary (Tomb of the Mask), Mattel (UNO), the Funkin' Crew (Friday Night Funkin'), W Production (Turbo Rush), Rovio Entertainment (Angry Birds), Kodub (PolyTrack), Frank Lantz or Everybody House Games (Universal Paperclips), Ketchapp (Rider), Brodie Lockard or Activision (Shanghai), Atari (Pong), Disney (Tron), Orteil or DashNet (Cookie Clicker), Taito or Midway (Space Invaders), Thinking Rabbit or Falcon (Sokoban), Oakever Games (Meowdoku), Florian van Strien (The Final Earth 2), The Powder Toy's developers (The Powder Toy), MateoConLechuga (Portal Returns), Valve (Portal), .GEARS (Flappy Bird), Bandai Namco (Pac-Man), Hasbro (Connect Four), Google (Snake, Solitaire, Block Breaker, Chrome Dino, Doodle Champion Island Games), STUDIO4°C or Microsoft (Minesweeper), ducalex (Retro-Go). Tetris is a trademark of The Tetris Company, Chrome of Google LLC, Minecraft of Mojang Synergies AB, Pac-Man of Bandai Namco, Connect Four of Hasbro, DOOM of ZeniMax Media, Sonic the Hedgehog, Master System, Game Gear and SG-1000 of SEGA, Space Invaders of Taito, UNO of Mattel, Angry Birds of Rovio Entertainment, and Donkey Kong, Game Boy, Game Boy Color and NES of Nintendo.</sub>## Gallerydiff --git a/customize/app.js b/customize/app.jsindex 01909dcf..526922a4 100644--- a/customize/app.js+++ b/customize/app.js@@ -17,8 +17,9 @@3: { tag: 'NES', name: 'NES', color: '#c43a2f', shell: '#d9d9de' },4: { tag: 'SMS', name: 'Master System', color: '#2f62c4', shell: '#cfd6e4' },5: { tag: 'GG', name: 'Game Gear', color: '#3b3b3b', shell: '#c8c8cc' },+ 6: { tag: 'SG', name: 'SG-1000', color: '#c0392b', shell: '#2b2b2e' },};- const EXT = { gb: 1, gbc: 2, nes: 3, sms: 4, gg: 5 };+ const EXT = { gb: 1, gbc: 2, nes: 3, sms: 4, gg: 5, sg: 6 };const ROM_ENTRY = 52, ROM_HEAD = 12;const PRESETS = { 'NumPlay': ['NumPlay', 'NumPlay'], 'NumPlay-Invisible': ['Invisible', ' '], 'NumPlay-Matrices': ['Matrices', 'Matrices'] };const LANGS = { en: ['EN', 'English'], fr: ['FR', 'Français'], zh: ['中文', '中文'] };diff --git a/docs/play.md b/docs/play.mdindex db78c5af..af8bba81 100644--- a/docs/play.md+++ b/docs/play.md@@ -1067,6 +1067,6 @@ NumVisuals comes on its own, as NumVisuals.nwa, or in a NumPlay of your own from| **Backspace** | Retro-Go's menu: save, load, reset, options || **Home** | Save and quit |-Game Boy, Game Boy Color, NES, Master System and Game Gear games you pick on NumPlay's customizer website. Open a game for New game, or Resume game from one of its 4 save slots. In a game, Backspace opens Retro-Go's menu: Save & Continue, Save & Quit, Load game, Reset, Options, where the picture can be 1x, Fit or Full screen, and Controls, where you give any button the key you want: pick it, press **OK**, then its new key. The cartridges' own saves are kept as well.+Game Boy, Game Boy Color, NES, Master System, Game Gear and SG-1000 games you pick on NumPlay's customizer website. Open a game for New game, or Resume game from one of its 4 save slots. In a game, Backspace opens Retro-Go's menu: Save & Continue, Save & Quit, Load game, Reset, Options, where the picture can be 1x, Fit or Full screen, and Controls, where you give any button the key you want: pick it, press **OK**, then its new key. The cartridges' own saves are kept as well.<br clear="right">diff --git a/games/games.json b/games/games.jsonindex db5d2c8a..0ae35267 100644--- a/games/games.json+++ b/games/games.json@@ -618,7 +618,8 @@2,3,4,- 5+ 5,+ 6]},{diff --git a/games/retrogo/README.md b/games/retrogo/README.mdindex 07e95e13..f9c7b7f2 100644--- a/games/retrogo/README.md+++ b/games/retrogo/README.md@@ -1,6 +1,6 @@# Retro-Go-Play your own Game Boy, Game Boy Color, NES, Master System and Game Gear games on the NumWorks calculator. Retro-Go is the launcher and emulators of handhelds like the ODROID-GO, whose screen is the calculator's size; this is its look and its menus, made for the keypad.+Play your own Game Boy, Game Boy Color, NES, Master System, Game Gear and SG-1000 games on the NumWorks calculator. Retro-Go is the launcher and emulators of handhelds like the ODROID-GO, whose screen is the calculator's size; this is its look and its menus, made for the keypad.<img src="docs/shot.png" width="320" alt="Retro-Go's list of NES games, with Thwaite chosen">@@ -9,7 +9,7 @@ You pick the games on NumPlay's customizer website: it puts them inside your Num- **Retro-Go's launcher:** a tab for each system with its own colours, the game list, and for each game Resume game, New game, Delete save and Properties.- **Game Boy and Game Boy Color** with gnuboy, the emulator Retro-Go started from: the cartridges with MBC1, MBC2, MBC3 (with its clock), MBC5, HuC1 and HuC3 bank controllers, up to 32 KB of cartridge RAM. Big games fit too, like the 2 MB Game Boy Color ones, in a NumPlay made for Epsilon 26 or Nwagra (NumPlay Studio says when a game needs it).- **NES** with nofrendo, Retro-Go's NES emulator at its start: 34 mappers, among them NROM, MMC1, UNROM, CNROM, MMC3, MMC5, AxROM, MMC2, Namco 163 and the Konami VRC chips.-- **Master System and Game Gear** with a machine written for NumPlay around superzazu's Z80: Sega's, Codemasters' and the Korean mappers, the cartridges' RAM, the 224-line pictures, the European games that need 50 Hz, and the Game Gear games made for the Master System's mode.+- **Master System, Game Gear and SG-1000** with a machine written for NumPlay around superzazu's Z80: Sega's, Codemasters' and the Korean mappers, the cartridges' RAM, the 224-line pictures, the European games that need 50 Hz, the Game Gear games made for the Master System's mode, and the SG-1000's TMS9918 pictures (Graphics I and II, Text, Multicolor and its sprites).- **Full speed** on every calculator: as Retro-Go does, a frame is drawn, then at least one is skipped, more when the calculator can't keep up, so the game always runs at its own speed.- **Retro-Go's menu** in a game: Save & Continue, Save & Quit, Load game, Reset, Options, Controls, About and Quit.- **4 save slots** for each game, and the cartridges' own battery saves, kept a few seconds after the game writes them. Home saves and quits.@@ -28,6 +28,10 @@ You pick the games on NumPlay's customizer website: it puts them inside your Num<td align="center"><img src="docs/sms.png" width="320" alt="Raposa do Sol, a Master System homebrew game, in Fit"><br><sub>Raposa do Sol, a Master System homebrew game</sub></td><td align="center"><img src="docs/gg.png" width="320" alt="Waternet, a Game Gear homebrew game, at 1x with the keys on the side"><br><sub>Waternet on the Game Gear, at 1x</sub></td></tr>+ <tr>+ <td align="center"><img src="docs/sgtab.png" width="320" alt="Retro-Go's SG-1000 tab: a red background with the console"><br><sub>The SG-1000 tab</sub></td>+ <td align="center"><img src="docs/sg.png" width="320" alt="Cheril Perils Classic, an SG-1000 homebrew game, in Fit"><br><sub>Cheril Perils Classic on the SG-1000</sub></td>+ </tr></table>## Controls@@ -50,7 +54,7 @@ In 1x on the Game Boy and the Game Gear, the keys are written on the side of the- The calculator has about 42 KB for every app's saves. A Game Boy or NES state takes 2 to 10 KB, a Master System or Game Gear one 3 to 15 KB, a Game Boy Color one up to 30 KB, so keep the slots you need and delete the others in the launcher (Delete save).- The calculator has no clock for apps: a Game Boy game's clock runs while you play, and you can set it in Options, RTC config.- Cartridges with more than 32 KB of RAM (a few Game Boy Color games) and NES mappers nofrendo doesn't have say so instead of starting.-- The SG-1000's games, and the light gun and 3-D glasses games of the Master System, don't play.+- The light gun and 3-D glasses games of the Master System don't play, nor do the SC-3000's keyboard and BASIC.## Credits@@ -58,9 +62,9 @@ In 1x on the Game Boy and the Game Gear, the keys are written on the side of the- **[gnuboy](https://github.com/rofl0r/gnuboy)** by Laguna and Gilgamesh and gnuboy's contributors (GPL-2.0-or-later, [COPYING](src/gb/COPYING)), from rofl0r's tree, emulates the Game Boy. Its picture is drawn by new code here: gnuboy's keeps 256 KB of decoded tiles, more than the calculator has.- **nofrendo** by Matthew Conte and nofrendo's contributors (version 2 of the GNU Library GPL, [COPYING.LGPL](src/nes/COPYING.LGPL), used under the GPL as its section 3 allows) emulates the NES. Its 2.0 release is the one used here.-- **[z80](https://github.com/superzazu/z80)** by Nicolas Allemand (superzazu) (MIT License, [LICENSE.z80](src/sms/LICENSE.z80)) is the Master System's and Game Gear's processor, changed to run faster on the calculator. The rest of those machines is NumPlay's, written from Charles MacDonald's notes on their hardware and SMS Power's pages. Retro-Go's own Master System emulator, SMS Plus, can't be used: its Z80 may not be shared freely. The short list of games that need something of their own is [SMS Plus GX](https://github.com/libretro/smsplus-gx)'s (GPL-2.0-or-later).-- The tests run [Blargg's test ROMs](https://github.com/retrio/gb-test-roms), [dmg-acid2 and cgb-acid2](https://github.com/mattcurrie) by Matt Currie, [nestest](https://github.com/christopherpow/nes-test-roms) by kevtris, Frank Cringle's zexdoc and zexall, as [superzazu's z80](https://github.com/superzazu/z80) has them and in [Maxim's Master System port](https://github.com/maxim-zhao/zexall-sms), which aren't in NumPlay. The pictures show [Thwaite](https://github.com/pinobatch/thwaite-nes), [Concentration Room](https://github.com/pinobatch/croom-nes), [Libbet and the Magic Floor](https://github.com/pinobatch/libbet) and the [240p Test Suite](https://github.com/pinobatch/240p-test-mini) by Damian Yerrick and others, [µCity](https://github.com/AntonioND/ucity) by Antonio Niño Díaz, [Raposa do Sol](https://github.com/jflores82/raposadosol) by tibonev, [Waternet](https://github.com/joyrider3774/waternet) by Willems Davy and [Tunnel](https://github.com/liamhays/tunnel) by Liam Hays, all free homebrew games.-- Game Boy, Game Boy Color and NES are trademarks of Nintendo, Master System and Game Gear of Sega. Not affiliated with Nintendo or Sega.+- **[z80](https://github.com/superzazu/z80)** by Nicolas Allemand (superzazu) (MIT License, [LICENSE.z80](src/sms/LICENSE.z80)) is the Master System's and Game Gear's processor, changed to run faster on the calculator. The rest of those machines is NumPlay's, written from Charles MacDonald's notes on their hardware, Texas Instruments' TMS9918A manual and SMS Power's pages. Retro-Go's own Master System emulator, SMS Plus, can't be used: its Z80 may not be shared freely. The short list of games that need something of their own is [SMS Plus GX](https://github.com/libretro/smsplus-gx)'s (GPL-2.0-or-later).+- The tests run [Blargg's test ROMs](https://github.com/retrio/gb-test-roms), [dmg-acid2 and cgb-acid2](https://github.com/mattcurrie) by Matt Currie, [nestest](https://github.com/christopherpow/nes-test-roms) by kevtris, Frank Cringle's zexdoc and zexall, as [superzazu's z80](https://github.com/superzazu/z80) has them and in [Maxim's Master System port](https://github.com/maxim-zhao/zexall-sms), which aren't in NumPlay. The pictures show [Thwaite](https://github.com/pinobatch/thwaite-nes), [Concentration Room](https://github.com/pinobatch/croom-nes), [Libbet and the Magic Floor](https://github.com/pinobatch/libbet) and the [240p Test Suite](https://github.com/pinobatch/240p-test-mini) by Damian Yerrick and others, [µCity](https://github.com/AntonioND/ucity) by Antonio Niño Díaz, [Raposa do Sol](https://github.com/jflores82/raposadosol) by tibonev, [Waternet](https://github.com/joyrider3774/waternet) by Willems Davy, [Tunnel](https://github.com/liamhays/tunnel) by Liam Hays and [Cheril Perils Classic](https://www.mojontwins.com/) by the Mojon Twins, all free homebrew games.+- Game Boy, Game Boy Color and NES are trademarks of Nintendo, Master System, Game Gear and SG-1000 of Sega. Not affiliated with Nintendo or Sega.Made by Mason Chen as part of NumPlay. It comes from the customizer website with your games in it, inside [NumPlay](https://github.com/Mason363/NumPlay) or on its own.diff --git a/games/retrogo/docs/sg.png b/games/retrogo/docs/sg.pngnew file mode 100644index 00000000..742836f1Binary files /dev/null and b/games/retrogo/docs/sg.png differdiff --git a/games/retrogo/docs/sgtab.png b/games/retrogo/docs/sgtab.pngnew file mode 100644index 00000000..fffadaf8Binary files /dev/null and b/games/retrogo/docs/sgtab.png differdiff --git a/games/retrogo/lang/fr.txt b/games/retrogo/lang/fr.txtindex 809ef846..3f8f5e55 100644--- a/games/retrogo/lang/fr.txt+++ b/games/retrogo/lang/fr.txt@@ -86,7 +86,7 @@ Welcome to Retro-Go! Bienvenue dans Retro-Go !Add games on NumPlay's Ajoute des jeux sur le sitecustomizer website: de personnalisation de NumPlay :Game Boy, Game Boy Color, NES, des jeux Game Boy, Game Boy Color, NES,-Master System and Game Gear. Master System et Game Gear.+Master System, Game Gear, SG-1000. Master System, Game Gear et SG-1000.Home: quit Accueil : quitterLeft/Right: system OK: games Home: quit Gauche/Droite : console OK : jeux Accueil : quitterOK: play Back: systems Left/Right: system OK : jouer Retour : consoles Gauche/Droite : consolediff --git a/games/retrogo/lang/zh.txt b/games/retrogo/lang/zh.txtindex c33d26b7..2a756445 100644--- a/games/retrogo/lang/zh.txt+++ b/games/retrogo/lang/zh.txt@@ -86,7 +86,7 @@ Welcome to Retro-Go! 欢迎使用 Retro-Go!Add games on NumPlay's 请在 NumPlay 的customizer website: 定制网站上添加Game Boy, Game Boy Color, NES, Game Boy、Game Boy Color、NES、-Master System and Game Gear. Master System 和 Game Gear 游戏。+Master System, Game Gear, SG-1000. Master System、Game Gear 和 SG-1000 游戏。Home: quit 主页:退出Left/Right: system OK: games Home: quit 左/右:主机 OK:游戏 主页:退出OK: play Back: systems Left/Right: system OK:开始 返回:主机 左/右:切换主机diff --git a/games/retrogo/src/main.c b/games/retrogo/src/main.cindex 5ea81d9b..f37a9f89 100644--- a/games/retrogo/src/main.c+++ b/games/retrogo/src/main.c@@ -1,4 +1,5 @@-/* Retro-Go: Game Boy, Game Boy Color, NES, Master System and Game Gear games on the calculator.+/* Retro-Go: Game Boy, Game Boy Color, NES, Master System, Game Gear and SG-1000 games on the+ * calculator.** Retro-Go (ducalex) is a launcher and a set of emulators for ESP32 handhelds whose 320 x 240* screen is the calculator's. This is its look and its ways, made again for the keypad: the@@ -6,7 +7,7 @@* Reset, Options...), its scaling (1x, Fit, Full), its frame skipping (a frame drawn, then at* least one skipped, more when the calculator can't keep up), save states in 4 slots and the* cartridges' battery saves. The emulators are gnuboy (Game Boy, Game Boy Color) and nofrendo- * (NES), the ones Retro-Go started from, and for the Master System and Game Gear a machine+ * (NES), the ones Retro-Go started from, and for the Master System, Game Gear and SG-1000 a machine* written for NumPlay around superzazu's Z80 (sms/); Retro-Go's own code is GPL-2.0 only, so* none of it is here (see README.md).*@@ -87,10 +88,12 @@ static struct {uint8_t autosave; /* the battery save, so many seconds after the game wrote it; 0 off */uint8_t flags; /* 1: the controls were shown */uint8_t tab, browse;- uint8_t cursor[RG_SYS_COUNT];+ uint8_t cursor[8]; /* each system's game chosen (room for the systems to come) */uint8_t keys[8]; /* the calculator's key for each of the pad's buttons, in pad_bits' order */} cfg;#define CFG_NAME "retrogo.cfg"+#define CFG_V1_SIZE 19 /* (version 1: the same up to the five systems' games, without the keys) */+_Static_assert(RG_SYS_COUNT <= 8, "cfg.cursor");/* ------------------------------------------------------------ the keys *//* the pad's buttons: the D-pad, then A, B, Select and Start */@@ -135,9 +138,7 @@ static void cfg_load(void) {uint32_t len = 0;const uint8_t *d = np_file_read(CFG_NAME, &len);cfg_defaults();- /* (version 1: the same, before the keys) */- if (!d || d[0] != 'R' || (!(len == sizeof cfg && d[1] == 2) && !(len == sizeof cfg - sizeof cfg.keys && d[1] == 1)))- return;+ if (!d || d[0] != 'R' || (!(len == sizeof cfg && d[1] == 2) && !(len == CFG_V1_SIZE && d[1] == 1))) return;memcpy(&cfg, d, len);cfg.version = 2;if (!keys_ok(cfg.keys)) memcpy(cfg.keys, default_keys, sizeof cfg.keys);@@ -157,13 +158,14 @@ static void cfg_save(void) { np_file_write(CFG_NAME, &cfg, sizeof cfg); }static rg_rom_t roms[RG_MAX_ROMS];static int nroms;/* Retro-Go's tabs, in its order */-static const uint8_t tab_order[] = {RG_SYS_NES, RG_SYS_GB, RG_SYS_GBC, RG_SYS_SMS, RG_SYS_GG};-static uint8_t tabs[5], ntabs;-static const char *const sys_short[RG_SYS_COUNT] = {"", "GB", "GBC", "NES", "SMS", "GG"};+static const uint8_t tab_order[] = {RG_SYS_NES, RG_SYS_GB, RG_SYS_GBC, RG_SYS_SMS, RG_SYS_GG, RG_SYS_SG};+static uint8_t tabs[sizeof tab_order], ntabs;+static const char *const sys_short[RG_SYS_COUNT] = {"", "GB", "GBC", "NES", "SMS", "GG", "SG"};/* the tab's banner: the maker, then the system, as Retro-Go's banners show them */-static const char *const sys_maker[RG_SYS_COUNT] = {"", "Nintendo", "Nintendo", "Nintendo", "SEGA", "SEGA"};+static const char *const sys_maker[RG_SYS_COUNT] = {"", "Nintendo", "Nintendo", "Nintendo", "SEGA", "SEGA", "SEGA"};static const char *const sys_model[RG_SYS_COUNT] = {"Retro-Go", "Game Boy", "Game Boy Color", "Entertainment System",- "Master System", "Game Gear"};+ "Master System", "Game Gear", "SG-1000"};+static bool is_sega(int sys) { return sys == RG_SYS_SMS || sys == RG_SYS_GG || sys == RG_SYS_SG; }static int tab_first(int sys) {for (int i = 0; i < nroms; i++)@@ -303,7 +305,7 @@ static void set_view(void) {sy = cfg.overscan ? 8 : 0;sx = cfg.crop_sides ? 8 : 0;sw = NES_WIDTH - 2 * sx, sh = NES_HEIGHT - 2 * sy;- } else if (sys_now == RG_SYS_SMS || sys_now == RG_SYS_GG) {+ } else if (is_sega(sys_now)) {sms_view(&sx, &sy, &sw, &sh); /* (the Game Gear's screen, or the taller pictures of some games) */}view.src_x = sx, view.src_y = sy, view.src_w = sw, view.src_h = sh;@@ -340,6 +342,9 @@ static const shape_t nes_shape[] = {{6, -2, 32, 8, 4, 1}, {58, -14, 86, 14, 14, 1}, {98, -14, 126, 14, 14, 1}};static const shape_t sms_shape[] = {{-150, -50, 150, 50, 4, 0}, {-120, -30, -20, 30, 6, 1}, {30, -20, 60, 10, 15, 1}, {75, -20, 105, 10, 15, 1}};+static const shape_t sg_shape[] = {+ {-140, -56, 140, 56, 4, 0}, {-110, -40, 10, -20, 3, 1}, {-110, 0, 10, 40, 2, 1}, {40, -30, 70, 0, 4, 1},+ {85, -30, 115, 0, 4, 1}, {40, 16, 115, 26, 2, 1}};static const shape_t gg_shape[] = {{-140, -62, 140, 62, 40, 0}, {-56, -46, 56, 40, 6, 1}, {-112, -12, -84, 0, 2, 1}, {-104, -20, -92, 8, 2, 1},{84, -8, 100, 8, 8, 1}, {106, -18, 122, -2, 8, 1}};@@ -350,6 +355,7 @@ static const look_t looks[RG_SYS_COUNT] = {{0xE84B39, 0xC23627, "1985", nes_shape, sizeof nes_shape / sizeof nes_shape[0]},{0x3199DB, 0x2481BA, "1986", sms_shape, sizeof sms_shape / sizeof sms_shape[0]},{0x0EA186, 0x13BC9D, "1990", gg_shape, sizeof gg_shape / sizeof gg_shape[0]},+ {0xC0392B, 0xA93226, "1983", sg_shape, sizeof sg_shape / sizeof sg_shape[0]},};static bool in_shape(const shape_t *s, int u, int v) {@@ -394,7 +400,7 @@ static void header(int sys, int y) {gfx_rrect(1, y + 1, LOGO_W - 2, HEADER_H - 2, 4, WHITE, 256);gfx_rrect_outline(1, y + 1, LOGO_W - 2, HEADER_H - 2, 4, 1, HEX(0x9AA0A6), 256);/* a little console: the body, its screen or its pad */- if (sys == RG_SYS_NES || sys == RG_SYS_SMS) {+ if (sys == RG_SYS_NES || sys == RG_SYS_SMS || sys == RG_SYS_SG) {gfx_fill(7, y + 11, 32, 15, HEX(0x8C8C8C));gfx_fill(7, y + 22, 32, 4, HEX(0x3C3C3C));gfx_fill(10, y + 14, 12, 4, HEX(0xD8D8D8));@@ -728,7 +734,7 @@ static int session_slot = -1; /* the slot this game was loaded from or sastatic int frameskip = 1, skip; /* Retro-Go's frame skipping */static uint32_t autosave_at; /* when the battery save is due, 0 none */-/* the three emulators: gnuboy, nofrendo, and the Master System's (for the Game Gear too) */+/* the three emulators: gnuboy, nofrendo, and the Master System's (for the Game Gear and the SG-1000 too) */enum { CORE_GB, CORE_NES, CORE_SMS };static int core;static bool is_gb(void) { return core == CORE_GB; }@@ -860,10 +866,10 @@ static void apply_settings(void) {System's pause button is on the console), NULL for none; with no game, every system's. */static const char *button_name(int k) {static const char *const names[] = {T("D-pad"), "A", "B", T("Select"), T("Start")};- bool sega = sys_now == RG_SYS_SMS || sys_now == RG_SYS_GG;+ bool sega = is_sega(sys_now);if (!game) {bool any = false;- for (int i = 0; i < ntabs; i++) any |= tabs[i] == RG_SYS_SMS || tabs[i] == RG_SYS_GG;+ for (int i = 0; i < ntabs; i++) any |= is_sega(tabs[i]);static const char *const both[] = {NULL, T("A, 2"), T("B, 1"), NULL, T("Start, Pause")};return any && both[k] ? both[k] : names[k];}@@ -1101,7 +1107,7 @@ static int controls(void) {static int about(void) {item_t items[] = {{0, T("Retro-Go"), "ducalex", IT_MESSAGE, 1, NULL, 0}, {0, "Game Boy", "gnuboy", IT_MESSAGE, 1, NULL, 0},- {0, "NES", "nofrendo", IT_MESSAGE, 1, NULL, 0}, {0, "SMS, GG", T("z80 by superzazu"), IT_MESSAGE, 1, NULL, 0},+ {0, "NES", "nofrendo", IT_MESSAGE, 1, NULL, 0}, {0, "SMS, GG, SG", T("z80 by superzazu"), IT_MESSAGE, 1, NULL, 0},{0, T("Port"), "NumPlay", IT_MESSAGE, 1, NULL, 0}, MESSAGE(T("Not affiliated with Retro-Go")),ITEM(1, T("OK"))};return dialog_run(T("About Retro-Go"), items, 7, 6);@@ -1202,12 +1208,13 @@ uint32_t perf_frames, perf_drawn;static int play(const rg_rom_t *r, int slot) {sys_now = r->system;- core = sys_now == RG_SYS_NES ? CORE_NES : sys_now == RG_SYS_SMS || sys_now == RG_SYS_GG ? CORE_SMS : CORE_GB;+ core = sys_now == RG_SYS_NES ? CORE_NES : is_sega(sys_now) ? CORE_SMS : CORE_GB;game = r;game_crc = rom_crc(r);int err = core == CORE_GB ? gb_load(r->data, r->size): core == CORE_NES ? nes_load(r->data, r->size)- : sms_load(r->data, r->size, game_crc, sys_now == RG_SYS_GG);+ : sms_load(r->data, r->size, game_crc,+ sys_now == RG_SYS_GG ? SMS_GG : sys_now == RG_SYS_SG ? SMS_SG : SMS_SMS);if (err != RG_OK) {game = NULL;const char *why = err == RG_ERR_MAPPER ? T("This cartridge type isn't supported.")@@ -1316,7 +1323,7 @@ static void picker_scene(void *ctx) {if (!ntabs) { /* (no games: Retro-Go's welcome, and where they come from) */header(0, 0);static const char *const lines[] = {T("Welcome to Retro-Go!"), "", T("Add games on NumPlay's"),- T("customizer website:"), T("Game Boy, Game Boy Color, NES,"), T("Master System and Game Gear."),+ T("customizer website:"), T("Game Boy, Game Boy Color, NES,"), T("Master System, Game Gear, SG-1000."),"", T("Home: quit")};for (int i = 0; i < 8; i++) gfx_text(&np_font_body, 8, 80 + 18 * i, lines[i], i ? 0xAD55 : WHITE, 256);return;diff --git a/games/retrogo/src/romtable.h b/games/retrogo/src/romtable.hindex d2485018..1f585919 100644--- a/games/retrogo/src/romtable.h+++ b/games/retrogo/src/romtable.h@@ -11,7 +11,7 @@#define RG_ROMS_NAME 40#define RG_MAX_ROMS 96-enum { RG_SYS_GB = 1, RG_SYS_GBC, RG_SYS_NES, RG_SYS_SMS, RG_SYS_GG, RG_SYS_COUNT };+enum { RG_SYS_GB = 1, RG_SYS_GBC, RG_SYS_NES, RG_SYS_SMS, RG_SYS_GG, RG_SYS_SG, RG_SYS_COUNT };typedef struct {const uint8_t *data;diff --git a/games/retrogo/src/sms/sms.c b/games/retrogo/src/sms/sms.cindex 9e4288b9..17891b91 100644--- a/games/retrogo/src/sms/sms.c+++ b/games/retrogo/src/sms/sms.c@@ -1,11 +1,12 @@-/* The Sega Master System and Game Gear around superzazu's Z80: the cartridge's mappers (Sega's,- * Codemasters', the Korean one), the work RAM, the pads, the Game Gear's ports and the video chip- * (mode 4: the tiles, their scrolling and priorities, the sprites, the line and frame- * interrupts, the counters), drawn a line at a time. Written for NumPlay from the hardware's- * public descriptions (Charles MacDonald's notes on the VDP and the Master System, SMS Power's- * pages); no sound, the calculator has no speaker. The short list of games that need something- * of their own (their CRC32s) is SMS Plus GX's (GNU GPL v2 or later). The old TMS9918 modes of- * the SG-1000 are not drawn. */+/* The Sega Master System, Game Gear and SG-1000 around superzazu's Z80: the cartridge's mappers+ * (Sega's, Codemasters', the Korean one), the work RAM, the pads, the Game Gear's ports and the+ * video chip (mode 4: the tiles, their scrolling and priorities, the sprites, the line and frame+ * interrupts, the counters; and the TMS9918's modes the SG-1000 draws with: Graphics I and II,+ * Text and Multicolor, with its sprites), drawn a line at a time. Written for NumPlay from the+ * hardware's public descriptions (Charles MacDonald's notes on the VDP and the Master System,+ * Texas Instruments' TMS9918A manual, SMS Power's pages); no sound, the calculator has no+ * speaker. The short list of games that need something of their own (their CRC32s) is SMS Plus+ * GX's (GNU GPL v2 or later). */#include <string.h>#include "sms.h"#include "z80.h"@@ -58,7 +59,7 @@ typedef struct {} state_t;/* a line's registers as it was drawn (sms_redraw draws the frame again from them) */-typedef struct { uint8_t r0, r1, r2, r5, r6, r7, hs, vs; } line_regs_t;+typedef struct { uint8_t r0, r1, r2, r3, r4, r5, r6, r7, hs, vs; } line_regs_t;static z80 cpu;static state_t st;@@ -69,11 +70,17 @@ static int snap_lines;static const uint8_t *rom;static uint32_t rom_size, banks;static uint8_t mapper_kind;-static bool gg, gg_vdp, pal, sram_dirty;+static bool gg, gg_vdp, sg, pal, sram_dirty;static uint8_t pad_bits;static bool start_button;static uint32_t line_start, line_end;static uint16_t pal565[32];+/* the TMS9918's colours (0 is see-through: the backdrop shows) */+#define RGB565(c) (uint16_t)(((c) >> 19 & 31) << 11 | ((c) >> 10 & 63) << 5 | ((c) >> 3 & 31))+static const uint16_t tms565[16] = {+ RGB565(0x000000), RGB565(0x000000), RGB565(0x21C842), RGB565(0x5EDC78), RGB565(0x5455ED), RGB565(0x7D76FC),+ RGB565(0xD4524D), RGB565(0x42EBF5), RGB565(0xFC5554), RGB565(0xFF7978), RGB565(0xD4C154), RGB565(0xE6CE80),+ RGB565(0x21B03B), RGB565(0xC95BBA), RGB565(0xCCCCCC), RGB565(0xFFFFFF)};static uint8_t lb[256 + 16]; /* a line: colour index (0-31), 0x40 the tile over the sprites, 0x20 a sprite */static uint16_t px[256];static const uint8_t open_bus[0x400] = {[0 ... 0x3FF] = 0xFF};@@ -87,6 +94,14 @@ static const uint8_t *rom_page(uint32_t bank, int k) {static void map_update(void) {sram_slot = NULL;+ if (sg) { /* the SG-1000: 48 KB of cartridge in a row (the smaller ones with RAM after them), 1 KB of RAM */+ for (int k = 0; k < 48; k++) {+ uint32_t at = (uint32_t)k * 0x400;+ z80_rmap[k] = at + 0x400 <= rom_size ? rom + at : k >= 32 && rom_size <= 0x8000 ? sram + (at & 0x3FFF) : open_bus;+ }+ for (int k = 0; k < 16; k++) z80_rmap[48 + k] = ram;+ return;+ }if (mapper_kind == MAP_SEGA) {z80_rmap[0] = rom_page(0, 0); /* (the first 1 KB never moves) */for (int k = 1; k < 16; k++) z80_rmap[k] = rom_page(st.mapper[1], k);@@ -104,6 +119,11 @@ static void map_update(void) {}void z80_bus_write(uint16_t a, uint8_t v) {+ if (sg) {+ if (a >= 0xC000) ram[a & 0x3FF] = v;+ else if (a >= 0x8000 && rom_size <= 0x8000) sram[a & 0x3FFF] = v; /* (The Castle's and Othello's RAM) */+ return;+ }if (a >= 0xC000) {ram[a & 0x1FFF] = v;if (a >= 0xFFFC && mapper_kind == MAP_SEGA) {@@ -134,7 +154,7 @@ static int height_of(uint8_t r0, uint8_t r1) {static int height(void) { return height_of(st.reg[0], st.reg[1]); }static void irq_update(void) {- cpu.irq_line = (st.vint && (st.reg[1] & 0x20)) || (st.hint && (st.reg[0] & 0x10));+ cpu.irq_line = (st.vint && (st.reg[1] & 0x20)) || (st.hint && (st.reg[0] & 0x10) && !sg);}static void palette_update(int i) {@@ -151,7 +171,7 @@ static void palette_update(int i) {}static uint8_t vdp_status(void) {- uint8_t v = st.status | 0x1F;+ uint8_t v = sg ? st.status : st.status | 0x1F;st.status = 0, st.pending = 0, st.vint = 0, st.hint = 0;irq_update();return v;@@ -320,6 +340,77 @@ static void sprites(int line, const line_regs_t *r) {}}+/* ---- the TMS9918's modes: lb gets its colours (0-15, 0 see-through) */+static void tms_background(int line, const line_regs_t *r) {+ uint8_t *o = lb + 8, fg, bg;+ unsigned nt = (r->r2 & 0x0F) << 10, row = (unsigned)line & 7;+ if (r->r1 & 0x10) { /* Text: 40 columns of 6 pixels, in R7's colours */+ fg = r->r7 >> 4, bg = r->r7 & 15;+ memset(o, 0, 256);+ for (int c = 0; c < 40; c++) {+ uint8_t bits = vram[((r->r4 & 7) << 11 | vram[(nt + (unsigned)(line >> 3) * 40 + (unsigned)c) & 0x3FFF] << 3 | row) & 0x3FFF];+ for (int i = 0; i < 6; i++) o[8 + 6 * c + i] = bits & (0x80 >> i) ? fg : bg;+ }+ return;+ }+ for (int c = 0; c < 32; c++) {+ unsigned name = vram[nt + (unsigned)(line >> 3) * 32 + (unsigned)c];+ uint8_t *d = o + 8 * c;+ if (r->r1 & 0x08) { /* Multicolor: blocks of 4 by 4 */+ uint8_t v = vram[((r->r4 & 7) << 11 | name << 3 | ((unsigned)(line >> 3) & 3) << 1 | ((unsigned)line >> 2 & 1)) & 0x3FFF];+ memset(d, v >> 4, 4), memset(d + 4, v & 15, 4);+ continue;+ }+ uint8_t bits, col;+ if (r->r0 & 0x02) { /* Graphics II: a pattern and colours for each third of the screen */+ unsigned i = ((unsigned)(line >> 6) << 8 | name) << 3 | row;+ bits = vram[(r->r4 & 4) << 11 | (i & ((r->r4 & 3) << 11 | 0x7FF))];+ col = vram[(r->r3 & 0x80) << 6 | (i & ((r->r3 & 0x7F) << 6 | 0x3F))];+ } else { /* Graphics I: colours for each 8 patterns */+ bits = vram[((r->r4 & 7) << 11 | name << 3 | row) & 0x3FFF];+ col = vram[(r->r3 << 6 | name >> 3) & 0x3FFF];+ }+ fg = col >> 4, bg = col & 15;+ for (int i = 0; i < 8; i++) d[i] = bits & (0x80 >> i) ? fg : bg;+ }+}++/* its sprites: 32, 4 on a line (the fifth sets the flag and its number), one colour each; two+ sprites' pixels on each other set the collision flag */+static void tms_sprites(int line, const line_regs_t *r) {+ const uint8_t *sat = vram + ((r->r5 & 0x7F) << 7);+ unsigned pg = (r->r6 & 7) << 11;+ int size = r->r1 & 2 ? 16 : 8, zoom = r->r1 & 1, span = size << zoom, count = 0;+ uint8_t taken[256 + 32] = {0};+ for (int i = 0; i < 32; i++) {+ int y = sat[4 * i];+ if (y == 0xD0) break;+ if (y > 0xE0) y -= 256;+ int row = line - (y + 1);+ if (row < 0 || row >= span) continue;+ if (++count > 4) {+ if (!(st.status & 0x40)) st.status = (uint8_t)((st.status & 0xA0) | 0x40 | i);+ break;+ }+ int x = sat[4 * i + 1], t = sat[4 * i + 2], c = sat[4 * i + 3] & 15;+ if (sat[4 * i + 3] & 0x80) x -= 32;+ row >>= zoom;+ if (size == 16) t &= 0xFC;+ unsigned bits = (unsigned)vram[(pg | (unsigned)t << 3) + (unsigned)row] << 8;+ if (size == 16) bits |= vram[(pg | (unsigned)t << 3) + 16 + (unsigned)row];+ for (int j = 0; j < size; j++) {+ if (!(bits & (0x8000u >> j))) continue;+ for (int s = 0; s <= zoom; s++) {+ int xx = x + (j << zoom) + s;+ if (xx < 0) continue;+ if (xx >= 256) break;+ if (taken[xx]) st.status |= 0x20;+ else if (taken[xx] = 1, c) lb[8 + xx] = (uint8_t)c;+ }+ }+ }+}+/* the picture shown (the Game Gear's screen: 160 x 144 in the middle) */void sms_view(int *x, int *y, int *w, int *h) {int lines = height();@@ -328,13 +419,23 @@ void sms_view(int *x, int *y, int *w, int *h) {}static void draw_line(int line, const line_regs_t *r, bool draw) {- bool on = (r->r1 & 0x40) && (r->r0 & 0x04);+ bool on = r->r1 & 0x40, tms = !(r->r0 & 0x04), text = tms && (r->r1 & 0x10);int vx, vy, vw, vh;sms_view(&vx, &vy, &vw, &vh);if (!draw || line < vy || line >= vy + vh) { /* (not seen: only the flags the game can read) */- if (!on) return;+ if (!on || text) return;memset(lb + 8, 0, 256);- sprites(line, r);+ tms ? tms_sprites(line, r) : sprites(line, r);+ return;+ }+ if (tms) {+ uint16_t back = tms565[r->r7 & 15];+ if (on) {+ tms_background(line, r);+ if (!text) tms_sprites(line, r);+ }+ for (int x = vx; x < vx + vw; x++) px[x] = on && lb[8 + x] ? tms565[lb[8 + x]] : back;+ rg_line(line, px);return;}uint8_t backdrop = (uint8_t)(16 | (r->r7 & 15));@@ -351,7 +452,7 @@ static void draw_line(int line, const line_regs_t *r, bool draw) {static void snap_line(int line) {line_regs_t *r = &snap[line];- *r = (line_regs_t){st.reg[0], st.reg[1], st.reg[2], st.reg[5], st.reg[6], st.reg[7],+ *r = (line_regs_t){st.reg[0], st.reg[1], st.reg[2], st.reg[3], st.reg[4], st.reg[5], st.reg[6], st.reg[7],(uint8_t)((st.reg[0] & 0x40) && line < 16 ? 0 : st.reg[8]), st.vscroll};}@@ -411,15 +512,16 @@ void sms_set_pad(int p) {uint32_t sms_frame_us(void) { return pal ? 20120 : 16688; } /* (313 or 262 lines of 228 clocks) */bool sms_is_gg(void) { return gg; }+bool sms_is_sg(void) { return sg; }void sms_reset(bool hard) {if (hard) {memset(ram, 0, 0x2000);memset(vram, 0, 0x4000);memset(&st, 0, sizeof st);- /* the video chip as the BIOS leaves it */+ /* the video chip as the BIOS leaves it (the SG-1000 has none: all 0) */static const uint8_t regs[11] = {0x36, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0x00, 0x00, 0x00, 0xFF};- memcpy(st.reg, regs, sizeof regs);+ if (!sg) memcpy(st.reg, regs, sizeof regs);st.counter = 0xFF;for (int i = 0; i < 32; i++) palette_update(i);memset(snap, 0, 240 * sizeof *snap);@@ -430,12 +532,12 @@ void sms_reset(bool hard) {st.line = 0, st.pause = 0;map_update();z80_init(&cpu);- cpu.sp = 0xDFF0; /* (where the BIOS leaves it; a few games count on it) */+ if (!sg) cpu.sp = 0xDFF0; /* (where the BIOS leaves it; a few games count on it) */line_start = line_end = 0;irq_update();}-int sms_load(const uint8_t *data, uint32_t size, uint32_t crc, bool is_gg) {+int sms_load(const uint8_t *data, uint32_t size, uint32_t crc, int machine) {if ((size & 0x3FFF) == 512 && size > 512) data += 512, size -= 512; /* (a copier's header) */if (size < 0x400) return RG_ERR_ROM;rg_alloc_reset();@@ -459,7 +561,8 @@ int sms_load(const uint8_t *data, uint32_t size, uint32_t crc, bool is_gg) {}mapper_kind = flags & DB_CODIES ? MAP_CODIES : flags & DB_KOREA ? MAP_KOREA : MAP_SEGA;pal = flags & DB_PAL;- gg = is_gg, gg_vdp = is_gg && !(flags & DB_GGMS);+ gg = machine == SMS_GG, gg_vdp = gg && !(flags & DB_GGMS), sg = machine == SMS_SG;+ if (sg) pal = false;pad_bits = 0, start_button = false, sram_dirty = false;sms_reset(true);return RG_OK;diff --git a/games/retrogo/src/sms/sms.h b/games/retrogo/src/sms/sms.hindex e589ee27..6dbb14b7 100644--- a/games/retrogo/src/sms/sms.h+++ b/games/retrogo/src/sms/sms.h@@ -1,5 +1,5 @@-/* The Sega Master System and Game Gear (sms.c and superzazu's Z80), as Retro-Go's screens drive- * them. */+/* The Sega Master System, Game Gear and SG-1000 (sms.c and superzazu's Z80), as Retro-Go's+ * screens drive them. */#ifndef SMS_H#define SMS_H#include "../rg.h"@@ -7,10 +7,11 @@#define SMS_WIDTH 256#define SMS_HEIGHT 240 /* (the tallest picture; most games show 192 lines) */-/* Loads a ROM read in place, a Game Gear's (gg) or a Master System's; crc is its CRC32, for the- few games that need something of their own (the mapper, 50 Hz, Master System mode on the Game- Gear). RG_OK or an RG_ERR_ code. */-int sms_load(const uint8_t *data, uint32_t size, uint32_t crc, bool gg);+/* Loads a ROM read in place, for a Master System, a Game Gear or an SG-1000 (machine); crc is its+ CRC32, for the few games that need something of their own (the mapper, 50 Hz, Master System+ mode on the Game Gear). RG_OK or an RG_ERR_ code. */+enum { SMS_SMS, SMS_GG, SMS_SG };+int sms_load(const uint8_t *data, uint32_t size, uint32_t crc, int machine);void sms_reset(bool hard);void sms_run_frame(bool draw);void sms_set_pad(int rg_pad);@@ -20,6 +21,7 @@ void sms_view(int *x, int *y, int *w, int *h);/* a frame's length in microseconds: 60 frames a second, 50 for the European games that need it */uint32_t sms_frame_us(void);bool sms_is_gg(void);+bool sms_is_sg(void);/* the last frame drawn, line by line through rg_line again (under the menus) */void sms_redraw(void);diff --git a/games/retrogo/tests/host_core.c b/games/retrogo/tests/host_core.cindex 494daba2..6c5c4cde 100644--- a/games/retrogo/tests/host_core.c+++ b/games/retrogo/tests/host_core.c@@ -1,7 +1,7 @@/* Retro-Go's emulators on a computer: runs a ROM for some frames, with random keys if asked,* and writes the last frame as a PPM picture.* host_core ROM FRAMES OUT.ppm [SEED] [SCRIPT] (SEED: random pad presses; 0 for none)- * The system comes from the file's extension (.gb .gbc .nes .sms .gg). */+ * The system comes from the file's extension (.gb .gbc .nes .sms .gg .sg). */#include <stdio.h>#include <stdlib.h>#include <string.h>@@ -83,9 +83,9 @@ int main(int argc, char **argv) {int frames = atoi(argv[2]);unsigned seed = argc > 4 ? (unsigned)atoi(argv[4]) : 0;const char *ext = strrchr(argv[1], '.');- kind = ext && !strcmp(ext, ".nes") ? NES : ext && (!strcmp(ext, ".sms") || !strcmp(ext, ".gg")) ? SMS : GB;+ kind = ext && !strcmp(ext, ".nes") ? NES : ext && (!strcmp(ext, ".sms") || !strcmp(ext, ".gg") || !strcmp(ext, ".sg")) ? SMS : GB;int r = kind == NES ? nes_load(rom, size)- : kind == SMS ? sms_load(rom, size, crc32(rom, size), !strcmp(ext, ".gg"))+ : kind == SMS ? sms_load(rom, size, crc32(rom, size), !strcmp(ext, ".gg") ? SMS_GG : !strcmp(ext, ".sg") ? SMS_SG : SMS_SMS): gb_load(rom, size);if (r != RG_OK) return fprintf(stderr, "load failed: %d\n", r), 1;int pad = 0;diff --git a/games/retrogo/tests/test_app.py b/games/retrogo/tests/test_app.pyindex 94a3733b..9aa4ef94 100644--- a/games/retrogo/tests/test_app.py+++ b/games/retrogo/tests/test_app.py@@ -178,8 +178,8 @@ def keys_test(out, problems):keys += [f"{t + 500}-{t + 1100}:7", f"{t + 1500}-{t + 2100}:8"]recs, _ = session(nwa, storage, ",".join(keys), t + 2600, "home", problems, "Keys")cfg = recs.get("retrogo.cfg", b"")- if cfg[19:27] != bytes([31, 43, 36, 38, 30, 5, 12, 52]):- problems.append(f"Keys: retrogo.cfg holds the keys {list(cfg[19:27])}")+ if cfg[21:29] != bytes([31, 43, 36, 38, 30, 5, 12, 52]):+ problems.append(f"Keys: retrogo.cfg holds the keys {list(cfg[21:29])}")srm = [n for n in recs if n.endswith(".srm")]seen = battery(recs, srm[0]) if srm else -1if seen != 0x0401:diff --git a/games/retrogo/tests/test_cores.py b/games/retrogo/tests/test_cores.pyindex 37fc6dfd..0414a74a 100644--- a/games/retrogo/tests/test_cores.py+++ b/games/retrogo/tests/test_cores.py@@ -3,7 +3,8 @@behaviour sanitizers, the ROM read only like the calculator's flash):- test ROMs give the pictures they should (Blargg's cpu_instrs and instr_timing, dmg-acid2 and- cgb-acid2, nestest, zexdoc for the Master System), when they are in the test ROM folder, and the+ cgb-acid2, nestest, zexdoc for the Master System, Cheril Perils Classic for the SG-1000), when they are in+ the test ROM folder, and theMaster System's Z80 runs the CP/M instruction exercisers (prelim; zexdoc and zexall with ZEX=1)to the clock;- every ROM there plays a few hundred runs of random keys without a crash;@@ -33,10 +34,12 @@ EXPECTED = {"cgb-acid2.gbc": (120, "", "3e99d1d0cb67"),"nestests/nes-test-roms-master/other/nestest.nes": (400, "30=8,35=0", "9c699fb5f8ff"),"sega/zexall/x/zexdoc.sms": (3000, "", "e20e5a6fb45d"),+ # (the SG-1000: the Mojon Twins' homebrew, its title, the menu, then Cheril in the first room)+ "sg1000/cheril_perils_ntsc.sg": (1500, "900=2,910=0,1000=2,1010=0,1100=128,1300=129,1320=128", "fd4688405166"),}# the CP/M exercisers and the clocks superzazu's z80 takes for themZEX = [("z80/prelim.com", 8721), ("z80/zexdoc.cim", 46734978649), ("z80/zexall.cim", 46734978649)]-SYSTEMS = (".gb", ".gbc", ".nes", ".sms", ".gg")+SYSTEMS = (".gb", ".gbc", ".nes", ".sms", ".gg", ".sg")def run(rom, frames, seed=0, script=""):diff --git a/tests/test_games.py b/tests/test_games.pyindex 3fdde809..f895e5e6 100644--- a/tests/test_games.py+++ b/tests/test_games.py@@ -605,8 +605,8 @@ CHECKS = {# a game kept (Easy, the guide read) with the two digits the hints wrote (the digits at 109); then three"sudoku": (lambda v: len(v) == 352 and v[:4] == b"S\1\3\0" and sum(1 <= b <= 9 for b in v[109:190]) == 2,lambda v: v[2] & 1 and sum(1 <= b <= 9 for b in v[109:190]) == 3),- # the scaling (third byte): Full, then 1x; the keys (at 19) the first ones- "retrogo": (lambda v: len(v) == 27 and v[:2] == b"R\2" and v[2] == 2 and v[19:27] == bytes([1, 2, 0, 3, 4, 5, 12, 52]),+ # the scaling (third byte): Full, then 1x; the keys (at 21) the first ones+ "retrogo": (lambda v: len(v) == 29 and v[:2] == b"R\2" and v[2] == 2 and v[21:29] == bytes([1, 2, 0, 3, 4, 5, 12, 52]),lambda v: v[2] == 0),}diff --git a/tools/romtable.py b/tools/romtable.pyindex 89c267ad..e3de2c1c 100644--- a/tools/romtable.py+++ b/tools/romtable.py@@ -13,7 +13,7 @@ All numbers are little-endian. To be the same byte for byte as the website's foreach next one at the end of the one before rounded up to a multiple of 4, zeros in between;- the table ends with the last ROM's bytes, then zeros up to a multiple of 4 (no ROMs: the 12-byteheader with count 0);-- the system comes from the file's extension, in any case: .gb 1, .gbc 2, .nes 3, .sms 4, .gg 5;+- the system comes from the file's extension, in any case: .gb 1, .gbc 2, .nes 3, .sms 4, .gg 5, .sg 6;- the name is the file's name without its last extension, its UTF-8 bytes cut to the longeststart of at most 40 bytes that ends on a whole letter, zero-padded to 40 (no ending zero when ittakes all 40).@@ -29,7 +29,7 @@ import structimport sysMAGIC, VERSION, ENTRY, NAME = 0x4D52504E, 1, 52, 40-SYSTEMS = {".gb": 1, ".gbc": 2, ".nes": 3, ".sms": 4, ".gg": 5}+SYSTEMS = {".gb": 1, ".gbc": 2, ".nes": 3, ".sms": 4, ".gg": 5, ".sg": 6}def entry_name(path):@@ -45,7 +45,7 @@ def table(paths):for p in paths:ext = os.path.splitext(p)[1].lower()if ext not in SYSTEMS:- sys.exit(f"romtable: {p}: not a .gb, .gbc, .nes, .sms or .gg file")+ sys.exit(f"romtable: {p}: not a .gb, .gbc, .nes, .sms, .gg or .sg file")roms.append((open(p, "rb").read(), SYSTEMS[ext], entry_name(p)))out = bytearray(struct.pack("<III", MAGIC, VERSION, len(roms)))out += bytes(ENTRY * len(roms))