Skip to content

Commit 43cb328

Browse files
authored
feat(msx): Add MSX emulator 🚀 ⚙️ (#100)
* feat(msx): Add MSX emulator 🚀 ⚙️ * Add msx component using `fmsx` core * Modify `fmsx` core to use `shared_memory` component * Modify `fmsx` core to execute as a cart with interruptible execution * Add associated msx cart and update carts appropriately * Simplify gbc screenshot functionality * Modify `fmsx` core so that its Z80 implementation does not conflict with Genesis Z80 implementation * Update sdkconfig to reduce warnings but maintain performance. MSX allows playing `Metal Gear` and `Metal Gear 2: Solid Snake` which are awesome ⚙️ Build and run `main` on BOX-3-EMU hardware and ensure all emulators still work, both metal gear games can run and they both have functional save/load state * readme: update * ignore fmsx for sa
1 parent d67d1bd commit 43cb328

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+31044
-26
lines changed

.github/workflows/static_analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929
esp_idf_version: release/v5.4
3030

3131
# (Optional) cppcheck args
32-
cppcheck_args: -i$GITHUB_WORKSPACE/components/gbc/gnuboy -i$GITHUB_WORKSPACE/components/nes/nofrendo -i$GITHUB_WORKSPACE/components/sms/smsplus -i$GITHUB_WORKSPACE/components/genesis/gwenesis -i$GITHUB_WORKSPACE/components/gui/generated -i$GITHUB_WORKSPACE/components/menu/generated -i$GITHUB_WORKSPACE/components/jpegdec --check-level=exhaustive --force --enable=all --inline-suppr --inconclusive --platform=mips32 --std=c++17 --suppressions-list=$GITHUB_WORKSPACE/suppressions.txt
32+
cppcheck_args: -i$GITHUB_WORKSPACE/components/gbc/gnuboy -i$GITHUB_WORKSPACE/components/nes/nofrendo -i$GITHUB_WORKSPACE/components/msx/fmsx -i$GITHUB_WORKSPACE/components/sms/smsplus -i$GITHUB_WORKSPACE/components/genesis/gwenesis -i$GITHUB_WORKSPACE/components/gui/generated -i$GITHUB_WORKSPACE/components/menu/generated -i$GITHUB_WORKSPACE/components/jpegdec --check-level=exhaustive --force --enable=all --inline-suppr --inconclusive --platform=mips32 --std=c++17 --suppressions-list=$GITHUB_WORKSPACE/suppressions.txt

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ set(SMS_COMPONENTS "sms")
2525
# set(SNES_COMPONENTS "snes")
2626

2727
### MSX ###
28-
# set(MSX_COMPONENTS "msx")
28+
set(MSX_COMPONENTS "msx")
2929

3030
### GENESIS ###
3131
set(GENESIS_COMPONENTS "genesis")

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ ESP32-S3-BOX-3 which provides:
2020
- NES Emulator (nofrendo)
2121
- Regular Controls (D-Pad/A/B/Start/Select)
2222
- Unlocked mode (fastest execution), toggled with the X button
23+
- MSX I / II Emulator (fmsx)
24+
- Regular Controls (D-Pad/A/B/Start/Select)
2325
- Gameboy / Gameboy Color emulator (gnuboy)
2426
- Regular Controls (D-Pad/A/B/Start/Select)
2527
- Unlocked mode (fastest execution), toggled with the X button
@@ -75,13 +77,14 @@ This project has the following features (still WIP):
7577
- [x] User input with d-pad + buttons (a/b/x/y, start/select) (using MCP23x17 [v0 hardware] or AW9523 [v1 hardware])
7678
- [x] Interaction with touchscreen (using [tt21100 component](./components/tt21100))
7779
- [x] Navigation of LVGL rom menu with controller (up,down,a,b,start)
80+
- [x] Shared memory system shared between emulators to allow for many emulators to compile in together while still enabling their main state to be stored in fast internal memory.
7881
- [x] Runnable emulators (automatically selected by rom extension):
7982
- [x] NES emulator
8083
- [x] GB/GBC emulator
8184
- [x] Sega Master System (SMS) / GameGear (GG) emulator
82-
- [ ] MSX emulator (WIP)
83-
- [x] Sega Mega Drive / Genesis emulator (WIP)
84-
- [ ] SNES emulator
85+
- [x] MSX emulator
86+
- [x] Sega Mega Drive / Genesis emulator
87+
- [ ] SNES emulator (WIP)
8588
- [ ] Doom (WIP)
8689
- [x] uSD card (FAT) filesystem over SPI
8790
- [x] TinyUSB MSC device for optionally exposing the uSD to the attached USB host

components/gbc/src/gameboy.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ std::vector<uint8_t> get_gameboy_video_buffer() {
215215
auto width = GAMEBOY_SCREEN_WIDTH;
216216
auto height = GAMEBOY_SCREEN_HEIGHT;
217217
std::vector<uint8_t> new_frame_buffer(width * 2 * height);
218-
for (int y = 0; y < height; ++y) {
219-
memcpy(&new_frame_buffer[y * width * 2], &frame_buffer[y * width * 2], width * 2);
220-
}
218+
memcpy(new_frame_buffer.data(), frame_buffer, width * 2 * height);
221219
return new_frame_buffer;
222220
}
223221

components/msx/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
idf_component_register(
2+
INCLUDE_DIRS "include"
3+
SRC_DIRS "src" "fmsx" "fmsx/src/EMULib" "fmsx/src/fMSX" "fmsx/src/Z80"
4+
PRIV_INCLUDE_DIRS "fmsx" "fmsx/src/EMULib" "fmsx/src/fMSX" "fmsx/src/Z80"
5+
REQUIRES box-emu statistics shared_memory
6+
)
7+
# target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-char-subscripts -Wno-attributes -Wno-implicit-fallthrough -Wno-unused-function -Wno-unused-variable -Wno-discarded-qualifiers)
8+
target_compile_options(${COMPONENT_LIB} PRIVATE
9+
-Wno-error=stringop-truncation
10+
-Wno-error=format-overflow
11+
-Wno-implicit-fallthrough
12+
-Wno-format-overflow
13+
-Wno-stringop-truncation
14+
-Wno-unused-but-set-variable
15+
-Wno-unused-variable
16+
-Wno-register
17+
-DBPS16 -DUNIX -DLSB_FIRST -DNARROW -O2
18+
)
19+
file(GLOB_RECURSE c_sources "fmsx/src/*.c")
20+
set_source_files_properties(${c_sources} PROPERTIES COMPILE_FLAGS "-include msxfix.h")

components/msx/fmsx/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set(COMPONENT_SRCDIRS ". src/EMULib src/fMSX src/Z80")
2+
set(COMPONENT_ADD_INCLUDEDIRS ". src/EMULib src/fMSX src/Z80")
3+
set(COMPONENT_REQUIRES "retro-go")
4+
register_component()
5+
rg_setup_compile_options(
6+
-Wno-error=stringop-truncation
7+
-Wno-error=format-overflow
8+
-Wno-implicit-fallthrough
9+
-Wno-format-overflow
10+
-Wno-stringop-truncation
11+
-Wno-unused-but-set-variable
12+
-Wno-unused-variable
13+
-DBPS16 -DUNIX -DLSB_FIRST -DNARROW -O2
14+
)
15+
file(GLOB_RECURSE c_sources "src/*.c")
16+
set_source_files_properties(${c_sources} PROPERTIES COMPILE_FLAGS "-include msxfix.h")

components/msx/fmsx/LibUnix.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/** EMULib Emulation Library *********************************/
2+
/** **/
3+
/** LibUnix.h **/
4+
/** **/
5+
/** This file contains Unix-dependent definitions and **/
6+
/** declarations for the emulation library. **/
7+
/** **/
8+
/** Copyright (C) Marat Fayzullin 1996-2021 **/
9+
/** You are not allowed to distribute this software **/
10+
/** commercially. Please, notify me, if you make any **/
11+
/** changes to this file. **/
12+
/*************************************************************/
13+
#ifndef LIBUNIX_H
14+
#define LIBUNIX_H
15+
16+
#define XImage void
17+
18+
#define SND_CHANNELS 16 /* Number of sound channels */
19+
#define SND_BITS 8
20+
#define SND_BUFSIZE (1<<SND_BITS)
21+
22+
/** PIXEL() **************************************************/
23+
/** Unix may use multiple pixel formats. **/
24+
/*************************************************************/
25+
#if defined(BPP32) || defined(BPP24)
26+
#define PIXEL(R,G,B) (pixel)(((int)R<<16)|((int)G<<8)|B)
27+
#define PIXEL2MONO(P) (((P>>16)&0xFF)+((P>>8)&0xFF)+(P&0xFF))/3)
28+
#define RMASK 0xFF0000
29+
#define GMASK 0x00FF00
30+
#define BMASK 0x0000FF
31+
32+
#elif defined(BPP16)
33+
#define PIXEL(R,G,B) (pixel)(((31*(R)/255)<<11)|((63*(G)/255)<<5)|(31*(B)/255))
34+
#define PIXEL2MONO(P) (522*(((P)&31)+(((P)>>5)&63)+(((P)>>11)&31))>>8)
35+
#define RMASK 0xF800
36+
#define GMASK 0x07E0
37+
#define BMASK 0x001F
38+
39+
#elif defined(BPP8)
40+
#define PIXEL(R,G,B) (pixel)(((7*(R)/255)<<5)|((7*(G)/255)<<2)|(3*(B)/255))
41+
#define PIXEL2MONO(P) (3264*((((P)<<1)&7)+(((P)>>2)&7)+(((P)>>5)&7))>>8)
42+
#define RMASK 0xE0
43+
#define GMASK 0x1C
44+
#define BMASK 0x03
45+
#endif
46+
47+
unsigned int InitAudio(unsigned int Rate,unsigned int Latency);
48+
void TrashAudio(void);
49+
int PauseAudio(int Switch);
50+
51+
#endif /* LIBUNIX_H */

components/msx/fmsx/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
In the `src` folder is unmodified fMSX 6.0 by Marat Fayzullin from https://fms.komkon.org/fMSX/.
2+
3+
`msxfix.c` wraps certain functions to allow it to work well within retro-go/esp-idf.

0 commit comments

Comments
 (0)