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 0000000..4e0b5aa Binary files /dev/null and b/irom_stub/wc_irom.bin differ diff --git a/irom_stub/ws_irom.bin b/irom_stub/ws_irom.bin new file mode 100644 index 0000000..5e44ed5 Binary files /dev/null and b/irom_stub/ws_irom.bin differ diff --git a/irom_stub/wsc_irom.bin b/irom_stub/wsc_irom.bin new file mode 100644 index 0000000..21d04e8 Binary files /dev/null and b/irom_stub/wsc_irom.bin differ