Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sega Master System / Game Gear support via SMSPlus #52

Merged
merged 24 commits into from
Jan 7, 2024
Merged

Conversation

finger563
Copy link
Contributor

@finger563 finger563 commented Dec 30, 2023

Description

  • Add smsplus emulator (modified from https://github.com/ducalex/retro-go)
  • Update box-emu-hal component to have video_task and audio_task which expose some simple methods for pushing video and audio data to the video and audio tasks (as well as setting config data such as resolution, palette, and sample count)
  • Use same video and audio tasks for
    • NES
    • Gameboy / Color
    • Sega Master System / Game Gear
  • Update carts to support new video resolution management
  • Update i2s_audio configuration (buffer size and sample count)
  • Update i2s_audio to support two dma-ed audio buffers instead of just one
  • Removed gameboy emulation task in favor of running gameboy emulation from within the run() function (main thread context) just like NES and SMS/GG emulators
  • Moved nes/src/video_audio.c to nes/src/video_audio.cpp for interfacing with audio/video tasks (C++)
  • Added msx_cart in prep for next emulator :)

Motivation and Context

How has this been tested?

Building and running main on Hardware V0, testing emulation of SMS, GG, NES, and GBC games (including save state loading and saving).

Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):

smsplus-gg-sonic1-with-sound-compressed.mp4
box-emu-sms-compressed.mp4

image

image

Console Logs:
CleanShot 2024-01-04 at 12 48 41
CleanShot 2024-01-04 at 12 48 54

Click for Full text Console Logs
I (993) main_task: Calling app_main()
Starting esp-box-emu...
Initializing SD card
Using SPI peripheral
Mounting filesystem
I (1006) gpio: GPIO[10]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1056) sdspi_transaction: cmd=52, R1 response: command not supported
I (1098) sdspi_transaction: cmd=5, R1 response: command not supported
Filesystem mounted
Name: 00000
Type: SDHC/SDXC
Speed: 20.00 MHz (limit: 20.00 MHz)
Size: 30543MB
CSD: ver=2, sector_size=512, capacity=62552064 read_bl_len=9
SSR: bus_width=1
I (1132) gpio: GPIO[4]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1141) gpio: GPIO[48]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (1567) gpio: GPIO[46]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
initializing i2s driver...
Using newer I2S standard
initializing es7210 codec...
I (1574) ES7210: ES7210 in Slave mode
I (1580) ES7210: Enable ES7210_INPUT_MIC1
I (1583) ES7210: Enable ES7210_INPUT_MIC2
I (1587) ES7210: Enable ES7210_INPUT_MIC3
I (1592) ES7210: Enable ES7210_INPUT_MIC4
I (1600) ES7210: The ES7210_CLOCK_OFF_REG01 value before stop is 0
I (1605) ES7210: Enable ES7210_INPUT_MIC1
I (1608) ES7210: Enable ES7210_INPUT_MIC2
I (1613) ES7210: Enable ES7210_INPUT_MIC3
I (1618) ES7210: Enable ES7210_INPUT_MIC4
Failed initialize codec
initializing es8311 codec...
I (1628) DRV8311: ES8311 in Slave mode
I (1637) gpio: GPIO[1]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:3
Initializing input drivers...
Initializing touch driver
Initializing touchpad
initializing input driver
Initializing keypad
Initializing input task
initializing gui...
RomInfo { name: Sonic The Hedgehog, boxart_path: /sdcard/boxart/sonic_1_sms.jpg, rom_path: /sdcard/sms/Sonic The Hedgehog.sms, platform: SEGA_MASTER_SYSTEM }
RomInfo { name: Sonic The Hedgehog 2, boxart_path: /sdcard/boxart/sonic-the-hedgehog-2-sms.jpg, rom_path: /sdcard/sms/Sonic The Hedgehog 2.sms, platform: SEGA_MASTER_SYSTEM }
RomInfo { name: Sonic The Hedgehog, boxart_path: /sdcard/boxart/sonic_game_gear_box.jpg, rom_path: /sdcard/gg/Sonic The Hedgehog.gg, platform: SEGA_GAME_GEAR }
RomInfo { name: Sonic The Hedgehog 2, boxart_path: /sdcard/boxart/sonic-the-hedgehog-2-gg.jpg, rom_path: /sdcard/gg/Sonic The Hedgehog 2.gg, platform: SEGA_GAME_GEAR }
RomInfo { name: The Adventures of Batman & Robin, boxart_path: /sdcard/boxart/The-Adventures-of-Batman-and-Robin-Game-Gear.jpg, rom_path: /sdcard/gg/adventures-of-batman-and-robin.gg, platform: SEGA_GAME_GEAR }
RomInfo { name: Aladdin, boxart_path: /sdcard/boxart/aladdin-gg.jpg, rom_path: /sdcard/gg/Aladdin.gg, platform: SEGA_GAME_GEAR }
RomInfo { name: Jurassic Park, boxart_path: /sdcard/boxart/jurassic-park-gg.jpg, rom_path: /sdcard/gg/Jurassic Park.gg, platform: SEGA_GAME_GEAR }
RomInfo { name: Star Trek Generations Beyond The Nexus, boxart_path: /sdcard/boxart/Star-Trek-Generations-Beyond-the-Nexus-gg.jpg, rom_path: /sdcard/gg/Star Trek Generations - Beyond the Nexus.gg, platform: SEGA_GAME_GEAR }
RomInfo { name: Metal Gear, boxart_path: /sdcard/boxart/mg1msxartwork_front.jpg, rom_path: /sdcard/msx/metal_gear.rom, platform: MSX }
RomInfo { name: Metal Gear 2: Solid Snake, boxart_path: /sdcard/boxart/mg2msxartwork.jpg, rom_path: /sdcard/msx/metal_gear_2.rom, platform: MSX }
RomInfo { name: Mario Bros., boxart_path: /sdcard/boxart/mario.jpg, rom_path: /sdcard/nes/mario.nes, platform: NES }
RomInfo { name: Super Mario Bros., boxart_path: /sdcard/boxart/super_mario_bros_1.jpg, rom_path: /sdcard/nes/super_mario_1.nes, platform: NES }
RomInfo { name: Super Mario Bros. 3, boxart_path: /sdcard/boxart/super_mario_bros_3.jpg, rom_path: /sdcard/nes/super_mario_3.nes, platform: NES }
RomInfo { name: The Legend of Zelda, boxart_path: /sdcard/boxart/zelda1.jpg, rom_path: /sdcard/nes/zelda.nes, platform: NES }
RomInfo { name: The Legend of Zelda 2: the Adventure of Link, boxart_path: /sdcard/boxart/zelda2.jpg, rom_path: /sdcard/nes/zelda_2.nes, platform: NES }
RomInfo { name: MegaMan, boxart_path: /sdcard/boxart/megaman1.jpg, rom_path: /sdcard/nes/mega_man.nes, platform: NES }
RomInfo { name: Metroid, boxart_path: /sdcard/boxart/metroid1.jpg, rom_path: /sdcard/nes/metroid.nes, platform: NES }
RomInfo { name: Mario Open Golf, boxart_path: /sdcard/boxart/mario_open_golf.jpg, rom_path: /sdcard/nes/mario_open_golf.nes, platform: NES }
RomInfo { name: Metal Gear, boxart_path: /sdcard/boxart/metal_gear.jpg, rom_path: /sdcard/nes/metal_gear.nes, platform: NES }
RomInfo { name: Final Fantasy, boxart_path: /sdcard/boxart/final_fantasy.jpg, rom_path: /sdcard/nes/final_fantasy.nes, platform: NES }
RomInfo { name: Final Fantasy II, boxart_path: /sdcard/boxart/final_fantasy_ii.jpg, rom_path: /sdcard/nes/final_fantasy_ii.nes, platform: NES }
RomInfo { name: Final Fantasy III, boxart_path: /sdcard/boxart/final_fantasy_iii.jpg, rom_path: /sdcard/nes/final_fantasy_iii.nes, platform: NES }
RomInfo { name: River City Ransom, boxart_path: /sdcard/boxart/river-city-ransom.jpg, rom_path: /sdcard/nes/river_city_ransom.nes, platform: NES }
RomInfo { name: Batman: The Animated Series, boxart_path: /sdcard/boxart/batman_the_animated_series.jpg, rom_path: /sdcard/gbc/batman_the_animated_series.gb, platform: GAMEBOY }
RomInfo { name: Duck Tales, boxart_path: /sdcard/boxart/duck_tales.jpg, rom_path: /sdcard/gbc/duck_tales.gb, platform: GAMEBOY }
RomInfo { name: Final Fantasy Adventure, boxart_path: /sdcard/boxart/final_fantasy_adventure.jpg, rom_path: /sdcard/gbc/final_fantasy_adventure.gb, platform: GAMEBOY }
RomInfo { name: Harvest Moon, boxart_path: /sdcard/boxart/harvest_moon.jpg, rom_path: /sdcard/gbc/harvest_moon.gb, platform: GAMEBOY }
RomInfo { name: Mario Golf, boxart_path: /sdcard/boxart/mario_golf.jpg, rom_path: /sdcard/gbc/mario_golf.gbc, platform: GAMEBOY_COLOR }
RomInfo { name: Mario Tennis, boxart_path: /sdcard/boxart/mario_tennis.jpg, rom_path: /sdcard/gbc/mario_tennis.gbc, platform: GAMEBOY_COLOR }
RomInfo { name: Metroid 2: Return of Samus, boxart_path: /sdcard/boxart/metroid_2_return_of_samus.jpg, rom_path: /sdcard/gbc/metroid_2_return_of_samus.gb, platform: GAMEBOY }
RomInfo { name: Metal Gear Solid, boxart_path: /sdcard/boxart/metal_gear_solid.jpg, rom_path: /sdcard/gbc/metal_gear_solid.gbc, platform: GAMEBOY_COLOR }
RomInfo { name: Pokemon Blue, boxart_path: /sdcard/boxart/pokemon_blue.jpg, rom_path: /sdcard/gbc/pokemon_blue.gb, platform: GAMEBOY }
RomInfo { name: Pokemon Red, boxart_path: /sdcard/boxart/pokemon_red.jpg, rom_path: /sdcard/gbc/pokemon_red.gb, platform: GAMEBOY }
RomInfo { name: Pokemon Yellow, boxart_path: /sdcard/boxart/pokemon_yellow.jpg, rom_path: /sdcard/gbc/pokemon_yellow.gbc, platform: GAMEBOY_COLOR }
RomInfo { name: Pokemon Crystal, boxart_path: /sdcard/boxart/pokemon_crystal.jpg, rom_path: /sdcard/gbc/pokemon_crystal.gbc, platform: GAMEBOY_COLOR }
RomInfo { name: Tetris: DX, boxart_path: /sdcard/boxart/tetris_dx.jpg, rom_path: /sdcard/gbc/tetris_dx.gb, platform: GAMEBOY }
RomInfo { name: The Legend of Zelda: Link's Awakening, boxart_path: /sdcard/boxart/tloz_links_awakening.jpg, rom_path: /sdcard/gbc/links_awakening.gb, platform: GAMEBOY }
RomInfo { name: The Legend of Zelda: Link's Awakening DX, boxart_path: /sdcard/boxart/tloz_links_awakening_dx.jpg, rom_path: /sdcard/gbc/links_awakening.gbc, platform: GAMEBOY_COLOR }
RomInfo { name: The Legend of Zelda: Oracle of Ages, boxart_path: /sdcard/boxart/tloz_oracle_ages.jpg, rom_path: /sdcard/gbc/tloz_oracle_of_ages.gbc, platform: GAMEBOY_COLOR }
RomInfo { name: The Legend of Zelda: Oracle of Seasons, boxart_path: /sdcard/boxart/tloz_oracle_seasons.jpg, rom_path: /sdcard/gbc/tloz_oracle_of_seasons.gbc, platform: GAMEBOY_COLOR }
          Biggest /     Free /    Total
DRAM  : [    9216 /    19370 /   360170]
PSRAM : [ 3735552 /  3796884 /  8388608]
DMA   : [    9216 /    11598 /   352018]
Selected rom:
  RomInfo { name: Sonic The Hedgehog, boxart_path: /sdcard/boxart/sonic_1_sms.jpg, rom_path: /sdcard/sms/Sonic The Hedgehog.sms, platform: SEGA_MASTER_SYSTEM }

          Biggest /     Free /    Total
DRAM  : [    9216 /    19370 /   360170]
PSRAM : [ 3735552 /  3796784 /  8388608]
DMA   : [    9216 /    11598 /   352018]
Initialized. ROM@0x3c150e54
sms init done
Running cart...
Resuming your regularly scheduled programming...
During emulation, minimum free heap: 3603984
Selected rom:
  RomInfo { name: The Legend of Zelda: Link's Awakening DX, boxart_path: /sdcard/boxart/tloz_links_awakening_dx.jpg, rom_path: /sdcard/gbc/links_awakening.gbc, platform: GAMEBOY_COLOR }

          Biggest /     Free /    Total
DRAM  : [    9216 /    19370 /   360170]
PSRAM : [ 3670016 /  3692620 /  8388608]
DMA   : [    9216 /    11598 /   352018]
Initialized. ROM@0x3c150e54
Initialized. ROM@0x3c150e54
loader: mbc.type=MBC_MBC5, mbc.romsize=64 (1024K), mbc.ramsize=4 (32K)
Running cart...
Resuming your regularly scheduled programming...
During emulation, minimum free heap: 3577668
Selected rom:
  RomInfo { name: Super Mario Bros., boxart_path: /sdcard/boxart/super_mario_bros_1.jpg, rom_path: /sdcard/nes/super_mario_1.nes, platform: NES }

          Biggest /     Free /    Total
DRAM  : [    9216 /    19370 /   360170]
PSRAM : [ 3604480 /  3659708 /  8388608]
DMA   : [    9216 /    11598 /   352018]
Initialized. ROM@0x3c150e54
bmp_create: width=256, height=240, overdraw=8
set palette!
Initialized. ROM@0x3c150e54
rom_load: rominfo->filename='/sdcard/nes/super_mario_1.nes'
Head: 0x3c150e54 (4e 45 53 1a)
setting up mapper 0
bmp_create: width=256, height=224, overdraw=0
setting up mapper 0
setting up mapper 0
Running cart...
Resuming your regularly scheduled programming...
During emulation, minimum free heap: 3418352
Selected rom:
  RomInfo { name: Super Mario Bros. 3, boxart_path: /sdcard/boxart/super_mario_bros_3.jpg, rom_path: /sdcard/nes/super_mario_3.nes, platform: NES }

          Biggest /     Free /    Total
DRAM  : [    9216 /    19370 /   360170]
PSRAM : [ 3604480 /  3637700 /  8388608]
DMA   : [    9216 /    11598 /   352018]
Initialized. ROM@0x3c150e54
setting up mapper 0
Initialized. ROM@0x3c150e54
rom_load: rominfo->filename='/sdcard/nes/super_mario_3.nes'
Head: 0x3c150e54 (4e 45 53 1a)
setting up mapper 4
bmp_create: width=256, height=224, overdraw=0
Running cart...
state_load: fn='/sdcard//saves//super_mario_3_0_nes.sav'
state_load: snssFile->headerBlock.numberOfBlocks=4
load_baseblock
load_sramblock
load_soundblock
load_mapperblock
State 0 restoredstate_load: fn='/sdcard//saves//super_mario_3_0_nes.sav'
state_load: snssFile->headerBlock.numberOfBlocks=4
load_baseblock
load_sramblock
load_soundblock
load_mapperblock
State 0 restoredstate_load: fn='/sdcard//saves//super_mario_3_0_nes.sav'
state_load: snssFile->headerBlock.numberOfBlocks=4
load_baseblock
load_sramblock
load_soundblock
load_mapperblock
State 0 restoredstate_save: fn='/sdcard//saves//super_mario_3_0_nes.sav'
state_save: SNSS_OpenFile OK
save_baseblock
state_save: save_baseblock OK
save_vramblock
save_vramblock: NULL == state->rominfo->vram
state_save: save_vramblock OK
save_sramblock
state_save: save_sramblock OK
save_soundblock
state_save: save_soundblock OK
save_mapperblock
state_save: save_mapperblock OK
State 0 saved
state_save: fn='/sdcard//saves//super_mario_3_0_nes.sav'
state_save: SNSS_OpenFile OK
save_baseblock
state_save: save_baseblock OK
save_vramblock
save_vramblock: NULL == state->rominfo->vram
state_save: save_vramblock OK
save_sramblock
state_save: save_sramblock OK
save_soundblock
state_save: save_soundblock OK
save_mapperblock
state_save: save_mapperblock OK
State 0 saved
state_save: fn='/sdcard//saves//super_mario_3_0_nes.sav'
state_save: SNSS_OpenFile OK
save_baseblock
state_save: save_baseblock OK
save_vramblock
save_vramblock: NULL == state->rominfo->vram
state_save: save_vramblock OK
save_sramblock
state_save: save_sramblock OK
save_soundblock
state_save: save_soundblock OK
save_mapperblock
state_save: save_mapperblock OK
State 0 saved
Resuming your regularly scheduled programming...
During emulation, minimum free heap: 3254768
Selected rom:
  RomInfo { name: Sonic The Hedgehog, boxart_path: /sdcard/boxart/sonic_game_gear_box.jpg, rom_path: /sdcard/gg/Sonic The Hedgehog.gg, platform: SEGA_GAME_GEAR }

          Biggest /     Free /    Total
DRAM  : [    9216 /    19370 /   360170]
PSRAM : [ 3276800 /  3589204 /  8388608]
DMA   : [    9216 /    11598 /   352018]
Initialized. ROM@0x3c150e54
gg init done
Running cart...

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

@finger563 finger563 added enhancement New feature or request emulation sms sega master system gg sega game gear labels Dec 30, 2023
@finger563 finger563 self-assigned this Dec 30, 2023
@finger563 finger563 changed the title feat(sms): initial (somewhat working) smsplus (SMS/GG) emulator Sega Master System / Game Gear support via SMSPlus Dec 30, 2023
Copy link

github-actions bot commented Dec 30, 2023

✅Static analysis result - no issues found! ✅

* Added audio code to sms component
* Fixed cache memory size issue
* WIP sizing of SMS and GG displays (right now GG is boxed in)
@finger563 finger563 linked an issue Jan 4, 2024 that may be closed by this pull request
2 tasks
@finger563 finger563 mentioned this pull request Jan 4, 2024
15 tasks
* Working sound
* Mostly working display (palette seems to be wrong for some colors?)
* Working scaling
* Working saving and loading of both gg and sms games
* Removed second audio buffer since its not used
* Updated hal to support palette sizes which are not 256 (which is still the default)
…ed for DMA and main task stack size is reduced by 2k
@finger563 finger563 merged commit f9f4723 into main Jan 7, 2024
2 checks passed
@finger563 finger563 deleted the feature/sms branch January 7, 2024 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emulation enhancement New feature or request gameboy color gameboy gg sega game gear NES sms sega master system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DMA capable memory decreasing over time
1 participant