From 432844304e99db85769e9f1de26bf2baaa301657 Mon Sep 17 00:00:00 2001 From: Godzil Date: Sun, 4 Apr 2021 23:15:50 +0100 Subject: [PATCH] Add a simple boot rom stub so we can start the emulated console without need for special case in the code, and not adding any copyrighted material in the project. Also automatically copy the stub rom in the build folder. --- CMakeLists.txt | 7 +++ irom_stub/Makefile | 20 ++++++++ irom_stub/irom_stub.asm | 104 ++++++++++++++++++++++++++++++++++++++++ irom_stub/wc_irom.bin | Bin 0 -> 8188 bytes irom_stub/ws_irom.bin | Bin 0 -> 4092 bytes irom_stub/wsc_irom.bin | Bin 0 -> 8188 bytes 6 files changed, 131 insertions(+) create mode 100644 irom_stub/Makefile create mode 100644 irom_stub/irom_stub.asm create mode 100644 irom_stub/wc_irom.bin create mode 100644 irom_stub/ws_irom.bin create mode 100644 irom_stub/wsc_irom.bin diff --git a/CMakeLists.txt b/CMakeLists.txt index ea3f693..d61f991 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,13 @@ set_property(TARGET wonderswan PROPERTY CXX_STANDARD 98) target_compile_definitions(wonderswan PUBLIC VERSION="${VERSION}") target_include_directories(wonderswan PUBLIC source) +add_custom_command( + TARGET wonderswan POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_SOURCE_DIR}/irom_stub/*.bin + ${CMAKE_CURRENT_BINARY_DIR}/ +) + add_subdirectory(source) target_link_libraries(wonderswan wswan glfw ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY}) diff --git a/irom_stub/Makefile b/irom_stub/Makefile new file mode 100644 index 0000000..28de77a --- /dev/null +++ b/irom_stub/Makefile @@ -0,0 +1,20 @@ +.PHONY: all clean + +all: ws_irom.bin wsc_irom.bin wc_irom.bin + +clean: + @echo " RM" + @rm -f *.bin + +ws_irom.bin: irom_stub.asm + @echo " AS $@" + @nasm $^ -o $@ -DWONDERSWAN=1 + +wsc_irom.bin: irom_stub.asm + @echo " AS $@" + @nasm $^ -o $@ -DWONDERSWANCOLOR=1 + +wc_irom.bin: irom_stub.asm + @echo " AS $@" + @nasm $^ -o $@ -DSWANCRYSTAL=1 + diff --git a/irom_stub/irom_stub.asm b/irom_stub/irom_stub.asm new file mode 100644 index 0000000..60f9310 --- /dev/null +++ b/irom_stub/irom_stub.asm @@ -0,0 +1,104 @@ +; WonderSwan Internal ROM Stub +; -------------------------------------- +; Version 1.0 + +; This is a replacement for the internal rom to prevent using/including any copyrighted material. +; It does nothing, just lauching the cartridge. +; It may later include a bootsplah. + +%ifdef WONDERSWAN +%define ROM_SIZE 4096 +%define ROM_SEG 0FF00h +%else +%define ROM_SIZE 8192 +%define ROM_SEG 0FE00h +%endif + +; Setup NASM for a 80186 + bits 16 + cpu 186 + + org 0000h + +%define JUMPER_LOCATION 0000h:0400h +; --------------------------------------------------------------------------------------------- +; Boot ROM jumper +; --------------------------------------------------------------------------------------------- +; Lock the bootrom +; Clear a bit of itself +; Jump to FFFF:FFF0 +; +; Must be copied to 0000:0400 then jmp 0000:0400 +ram_jumper: + + ; Lock the boot rom away + IN al, 0A0h + OR al, 001h ; Bit 0 lock the boot rom + out 0A0h, al + + mov ax, cs + mov es, ax + mov di, 0400h + mov cx, (.rm_te_end - ram_jumper) + xor ax, ax + xor bx, bx +.rm_te_end: + rep stosb + jmp 0FFFFh:00000h +ram_jumper_end: + +_start: + cli + cld + push cs + pop ds + xor ax, ax + mov es, ax + + ; Clear the IRAM + mov di, 0 + mov cx, 16384 + xor al, al + rep stosb ; STOSB -> ES:DI + + ; Copy the jumper + mov si, ram_jumper + mov cx, (ram_jumper_end - ram_jumper) + mov di, 0400h + xor ax, ax + mov es, ax + rep movsb ; DS:SI -> ES:DI + + ; Do some register cleanup + mov al, 0FFh + out 0C0h, al + out 0C1h, al + out 0C2h, al + xor ax, ax + xor cx, cx + xor dx, dx + mov ds, ax + mov es, ax + + ; Jump to the jumper! + jmp JUMPER_LOCATION + +%ifdef WONDERSWAN + db "WonderSwan" +%elifdef WONDERSWANCOLOR + db "WonderSwan Color" +%elifdef SWANCRYSTAL + db "WonderSwan Crystal" +%else +%endif + db " internal ROM Stub for NewOswan (c)2021 986-Studio" +; Create at the end of the block, add padding if needed +TIMES (ROM_SIZE - 16) - ($-$$) DB 0FFh + + jmp ROM_SEG:_start ; 0 + db 00 ; ?? ; 5 + db 0F0h ; Dev ID ; 6 + db 00 ; Min Swan type ; 7 + db 00000100b ; flags ; C + db 01 ; No RTC ; D + dw 0FFFFh ; CRC (need to update it after, but as not used by the rom, no need for now) \ No newline at end of file diff --git a/irom_stub/wc_irom.bin b/irom_stub/wc_irom.bin new file mode 100644 index 0000000000000000000000000000000000000000..4e0b5aa4f64c3c5a448430c1cf05c113edf6e633 GIT binary patch literal 8188 zcmeIuuL{CY6bA4!SQL}Z;EfstuR*j4W*ulS`)7h68*G!|JIJ14!L(#u(W^_5ZL`pi**tX`TGx8@E>p2_Oo2=N<@=V84%h2evk++_*h3&9` z=^JidtIlf8Mw7EnyH!`|d}&Jz1Rwwb2tWV=5P$##AOHafKmY;|fB*y_009U<00Izz Y00bZa0SG_<0{;clGSQb_q-#?C02%{=a=zJYabH^Qu=24FCWC`okx0cmO29u#>^T;K1iq`+zKI z2B1Qa@aH8P{y#hL?BKIQKs_f7FZJE%JMfBug@GYFKQASvX