gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit f38583f032a6e49dc820a105b074c2295d055908 parent fdcfd07934e2abec0fe918c97bf79b9f9f68ff5e Author: Toxa <56631470+untoxa@users.noreply.github.com> Date: Fri, 22 Apr 2022 00:08:49 +0300 Merge pull request #338 from gbdk-2020/SDCC_4_2 SDCC 4.2 Diffstat:
205 files changed, 2915 insertions(+), 3685 deletions(-)
diff --git a/.github/workflows/gbdk_build_and_package.yml b/.github/workflows/gbdk_build_and_package.yml @@ -33,7 +33,9 @@ jobs: # For GBDK-2020 4.0.5 # curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched/sdcc-amd64-linux2.5-20210711-12539--sms-gg-patched.tar.bz2 # For GBDK-2020 4.0.6 - curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-amd64-linux2.5-20211031-12539--sms-gg-patched.tar.bz2 + # curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-amd64-linux2.5-20211031-12539--sms-gg-patched.tar.bz2 + # For GBDK-2020 4.1.0 + curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-13350-patched-gbdk-4.1.0/sdcc-amd64-linux2.5-20220402-13350--sdldz80-patched-at-12539.tar.bz2 bunzip2 sdcc.tar.bz2 tar xvf sdcc.tar @@ -44,7 +46,9 @@ jobs: # For GBDK-2020 4.0.5 # curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched/sdcc-x86_64-apple-macosx-20210718-12548--sms-gg-patched.tar.bz2 # For GBDK-2020 4.0.6 - curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-x86_64-apple-macosx-20210718-12548--sms-gg-patched.tar.bz2 + # curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-x86_64-apple-macosx-20210718-12548--sms-gg-patched.tar.bz2 + # For GBDK-2020 4.1.0 + curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-13350-patched-gbdk-4.1.0/sdcc-x86_64-apple-macosx-20220402-13350--sdldz80-patched-at-12539.tar.bz2 bunzip2 sdcc.tar.bz2 tar xvf sdcc.tar @@ -55,7 +59,9 @@ jobs: # For GBDK-2020 4.0.5 # curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched/sdcc-x86_64-w64-mingw32-20210711-12539--sms-gg-patched.zip # For GBDK-2020 4.0.6: adds makebin -yN - curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-x86_64-w64-mingw32-20210711-12539--sms-gg-patched_makebin_yN.zip + # curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-x86_64-w64-mingw32-20210711-12539--sms-gg-patched_makebin_yN.zip + # For GBDK-2020 4.1.0 + curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-13350-patched-gbdk-4.1.0/sdcc-x86_64-w64-mingw32-20220402-13350--sdldz80-patched-at-12539.zip 7z x sdcc.zip - name: Windows-x32 Depends @@ -63,7 +69,9 @@ jobs: run: | # Use patched sms/gg z80 build: # For GBDK-2020 4.0.6: adds makebin -yN - curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-i586-mingw32msvc-20210711-12539--sms-gg-patched_makebin_yN.zip + # curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-i586-mingw32msvc-20210711-12539--sms-gg-patched_makebin_yN.zip + # For GBDK-2020 4.1.0 + curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-13350-patched-gbdk-4.1.0/sdcc-i586-mingw32msvc-20220402-13350--sdldz80-patched-at-12539.zip 7z x sdcc.zip - name: Windows Depends MSYS2/MinGW64 diff --git a/.github/workflows/gbdk_build_examples.yml b/.github/workflows/gbdk_build_examples.yml @@ -33,7 +33,9 @@ jobs: # For GBDK-2020 4.0.5 # curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched/sdcc-amd64-linux2.5-20210711-12539--sms-gg-patched.tar.bz2 # For GBDK-2020 4.0.6 - curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-amd64-linux2.5-20211031-12539--sms-gg-patched.tar.bz2 + # curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-amd64-linux2.5-20211031-12539--sms-gg-patched.tar.bz2 + # For GBDK-2020 4.1.0 + curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-13350-patched-gbdk-4.1.0/sdcc-amd64-linux2.5-20220402-13350--sdldz80-patched-at-12539.tar.bz2 bunzip2 sdcc.tar.bz2 tar xvf sdcc.tar @@ -44,7 +46,9 @@ jobs: # For GBDK-2020 4.0.5 # curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched/sdcc-x86_64-apple-macosx-20210718-12548--sms-gg-patched.tar.bz2 # For GBDK-2020 4.0.6 - curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-x86_64-apple-macosx-20210718-12548--sms-gg-patched.tar.bz2 + # curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-x86_64-apple-macosx-20210718-12548--sms-gg-patched.tar.bz2 + # For GBDK-2020 4.1.0 + curl -Lo sdcc.tar.bz2 https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-13350-patched-gbdk-4.1.0/sdcc-x86_64-apple-macosx-20220402-13350--sdldz80-patched-at-12539.tar.bz2 bunzip2 sdcc.tar.bz2 tar xvf sdcc.tar @@ -55,7 +59,9 @@ jobs: # For GBDK-2020 4.0.5 # curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched/sdcc-x86_64-w64-mingw32-20210711-12539--sms-gg-patched.zip # For GBDK-2020 4.0.6: adds makebin -yN - curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-x86_64-w64-mingw32-20210711-12539--sms-gg-patched_makebin_yN.zip + # curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-x86_64-w64-mingw32-20210711-12539--sms-gg-patched_makebin_yN.zip + # For GBDK-2020 4.1.0 + curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-13350-patched-gbdk-4.1.0/sdcc-x86_64-w64-mingw32-20220402-13350--sdldz80-patched-at-12539.zip 7z x sdcc.zip - name: Windows-x32 Depends @@ -63,7 +69,9 @@ jobs: run: | # Use patched sms/gg z80 build: # For GBDK-2020 4.0.6: adds makebin -yN - curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-i586-mingw32msvc-20210711-12539--sms-gg-patched_makebin_yN.zip + # curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-12539-patched-gbdk0-4.0.6/sdcc-i586-mingw32msvc-20210711-12539--sms-gg-patched_makebin_yN.zip + # For GBDK-2020 4.1.0 + curl -Lo sdcc.zip https://github.com/gbdk-2020/gbdk-2020-sdcc/releases/download/sdcc-13350-patched-gbdk-4.1.0/sdcc-i586-mingw32msvc-20220402-13350--sdldz80-patched-at-12539.zip 7z x sdcc.zip - name: Windows Depends MSYS2/MinGW64 diff --git a/Makefile b/Makefile @@ -10,7 +10,7 @@ PKG = gbdk # Version, used for tarballs & docs VER = 4.0.6 -PORTS=gbz80 z80 +PORTS=sm83 z80 PLATFORMS=gb ap duck gg sms msxdos # Prefix to add to the standard tools. Usefull for a standard gcc diff --git a/gbdk-lib/Makefile.common b/gbdk-lib/Makefile.common @@ -8,7 +8,7 @@ MODEL = small endif ifndef PORTS -PORTS = gbz80 z80 +PORTS = sm83 z80 endif ifndef PLATFORMS PLATFORMS = gb ap duck gg sms msxdos @@ -24,11 +24,7 @@ SDAR = $(subst \,/,'$(SDCCLIB)')/bin/sdar AS_Z80 = $(SDCCLIB)/bin/sdasz80 -ifeq ($(RGBDS),1) -AS_GBZ80 = rgbasm -else -AS_GBZ80 = $(SDCCLIB)/bin/sdasgb -endif +AS_SM83 = $(SDCCLIB)/bin/sdasgb CLEANSPEC = *.o *.cdb *.sym *.lst *~ *.asm diff --git a/gbdk-lib/examples/ap/Makefile.rgbds b/gbdk-lib/examples/ap/Makefile.rgbds @@ -1,92 +0,0 @@ -TOPDIR= ../.. -CC= $(TOPDIR)/bin/sdcc -mgbz80 --asm=rgbds -I$(TOPDIR)/include -v -GBLIB = $(TOPDIR)/lib/rgbds -LIB = $(GBLIB)/gbz80/gbz80.lib $(GBLIB)/gb/gb.lib -CRT0 = $(GBLIB)/gb/crt0.o - -BINS = \ - galaxy.gb \ - paint.gb \ - rpn.gb \ - rand.gb \ - comm.gb \ - irq.gb \ - filltest.gb \ - fonts.gb \ - samptest.gb - -# sound.gb: Cant do bitfields -OTHER = sound.gb \ - banks.gb \ - ram_fn.gb - -all: $(BINS) - -compile.bat: Makefile - make -sn | sed y/\\//\\\\/ | grep -v make > compile.bat - -%.o: %.s - -%.asm: %.s - astorgb.pl $< > $@ - -%.o: %.c - $(CC) -c $< - -%.s: %.c - $(CC) -S $< - -%.o: %.asm - rgbasm -o$@ $< - -%.gb: %.o - $(CC) $(CRT0) $< $(LIB) - cp a.gb $@ - rgbfix -p -v $@ - -clean: - rm -f *.o *.lst *.map *.gb *~ *.rel *.cdb *.ihx *.lnk *.sym *.asm - -############################################################ -# Multiple bank example - -# Compile bank 0 (no ROM) -# RAM bank 0 : -Wf-ba0 -# -bank_0.o: bank_0.c - $(CC) -Wf-ba0 -c -o $@ $< - -# Compile bank 1 (ROM+RAM) -# ROM bank 1 : -Wf-bo1 -# RAM bank 1 : -Wf-ba1 -# -bank_1.o: bank_1.c - $(CC) -Wf-bo1 -Wf-ba1 -c -o $@ $< - -# Compile bank 2 (ROM+RAM) -# ROM bank 2 : -Wf-bo2 -# RAM bank 2 : -Wf-ba2 -# -bank_2.o: bank_2.c - $(CC) -Wf-bo2 -Wf-ba2 -c -o $@ $< - -# Compile bank 3 (ROM+RAM) -# ROM bank 3 : -Wf-bo3 -# RAM bank 3 : -Wf-ba3 -# -bank_3.o: bank_3.c - $(CC) -Wf-bo3 -Wf-ba3 -c -o $@ $< - -# Link banks -# ROM+MBC1+RAM : -Wl-yt2 -# 4 ROM banks : -Wl-yo4 -# 4 RAM banks : -Wl-ya4 -# -banks.gb: banks.o bank_0.o bank_1.o bank_2.o bank_3.o - $(CC) -Wl-yt2 -Wl-yo4 -Wl-ya4 -o $@ banks.o bank_0.o bank_1.o bank_2.o bank_3.o - -############################################################ -# RAM function example - -ram_fn.gb: ram_fn.o - $(CC) -Wl-g_inc_ram=0xD000 -Wl-g_inc_hiram=0xFFA0 -o $@ ram_fn.o diff --git a/gbdk-lib/examples/ap/bcd/Makefile b/gbdk-lib/examples/ap/bcd/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = bcd.pocket diff --git a/gbdk-lib/examples/ap/colorbar/Makefile b/gbdk-lib/examples/ap/colorbar/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS # CFLAGS = diff --git a/gbdk-lib/examples/ap/comm/Makefile b/gbdk-lib/examples/ap/comm/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = comm.pocket diff --git a/gbdk-lib/examples/ap/crash/Makefile b/gbdk-lib/examples/ap/crash/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = crash.pocket diff --git a/gbdk-lib/examples/ap/dscan/Makefile b/gbdk-lib/examples/ap/dscan/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wm-yc -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wm-yc -Wl-j -Wm-yS BINS = dscan.pocket diff --git a/gbdk-lib/examples/ap/emu_debug/Makefile b/gbdk-lib/examples/ap/emu_debug/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS -Wm-yc +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS -Wm-yc BINS = emu_debug.pocket diff --git a/gbdk-lib/examples/ap/filltest/Makefile b/gbdk-lib/examples/ap/filltest/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = filltest.pocket diff --git a/gbdk-lib/examples/ap/galaxy/Makefile b/gbdk-lib/examples/ap/galaxy/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = galaxy.pocket diff --git a/gbdk-lib/examples/ap/gb-dtmf/Makefile b/gbdk-lib/examples/ap/gb-dtmf/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = gb-dtmf.pocket diff --git a/gbdk-lib/examples/ap/gbdecompress/Makefile b/gbdk-lib/examples/ap/gbdecompress/Makefile @@ -6,7 +6,7 @@ # to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/" GBDK_HOME = ../../../ -LCC = $(GBDK_HOME)bin/lcc -mgbz80:ap -Wl-j -Wm-yS +LCC = $(GBDK_HOME)bin/lcc -msm83:ap -Wl-j -Wm-yS # You can uncomment the line below to turn on debug output # LCC = $(LCC) -debug diff --git a/gbdk-lib/examples/ap/irq/Makefile b/gbdk-lib/examples/ap/irq/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = irq.pocket diff --git a/gbdk-lib/examples/ap/large_map/Makefile b/gbdk-lib/examples/ap/large_map/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS all: $(CC) -o large_map.pocket large_map.c bigmap_map.c bigmap_tiles.c diff --git a/gbdk-lib/examples/ap/lcd_isr_wobble/Makefile b/gbdk-lib/examples/ap/lcd_isr_wobble/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = lcd_isr_wobble.pocket diff --git a/gbdk-lib/examples/ap/linkerfile/Makefile b/gbdk-lib/examples/ap/linkerfile/Makefile @@ -11,7 +11,7 @@ LCC = $(GBDK_HOME)bin/lcc # You can set flags for LCC here # For example, you can uncomment the line below to turn on debug output -LCCFLAGS = -mgbz80:ap +LCCFLAGS = -msm83:ap # LCCFLAGS += -debug # LCCFLAGS += -v diff --git a/gbdk-lib/examples/ap/paint/Makefile b/gbdk-lib/examples/ap/paint/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = paint.pocket diff --git a/gbdk-lib/examples/ap/ram_function/Makefile b/gbdk-lib/examples/ap/ram_function/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = ram_fn.pocket diff --git a/gbdk-lib/examples/ap/rand/Makefile b/gbdk-lib/examples/ap/rand/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = rand.pocket diff --git a/gbdk-lib/examples/ap/rpn/Makefile b/gbdk-lib/examples/ap/rpn/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = rpn.pocket diff --git a/gbdk-lib/examples/ap/scroller/Makefile b/gbdk-lib/examples/ap/scroller/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = text_scroller.pocket diff --git a/gbdk-lib/examples/ap/sgb_border/Makefile b/gbdk-lib/examples/ap/sgb_border/Makefile @@ -1,7 +1,7 @@ CC = ../../../bin/lcc all: - $(CC) -mgbz80:ap -Wl-j -Wm-yS -Wm-ys -o border.pocket border.c sgb_border.c border_data.c + $(CC) -msm83:ap -Wl-j -Wm-yS -Wm-ys -o border.pocket border.c sgb_border.c border_data.c compile.bat: Makefile @echo "REM Automatically generated from Makefile" > compile.bat diff --git a/gbdk-lib/examples/ap/sgb_multiplayer/Makefile b/gbdk-lib/examples/ap/sgb_multiplayer/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS -Wm-ys +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS -Wm-ys BINS = sgb_multiplayer.pocket diff --git a/gbdk-lib/examples/ap/sound/Makefile b/gbdk-lib/examples/ap/sound/Makefile @@ -1,4 +1,4 @@ -CC = ../../../bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = ../../../bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = sound.pocket diff --git a/gbdk-lib/examples/ap/space/Makefile b/gbdk-lib/examples/ap/space/Makefile @@ -1,5 +1,5 @@ GBDK = ../../.. -CC = $(GBDK)/bin/lcc -mgbz80:ap -Wl-j -Wm-yS +CC = $(GBDK)/bin/lcc -msm83:ap -Wl-j -Wm-yS BINS = space.pocket diff --git a/gbdk-lib/examples/ap/template_minimal/Makefile b/gbdk-lib/examples/ap/template_minimal/Makefile @@ -6,7 +6,7 @@ # to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/" GBDK_HOME = ../../../ -LCC = $(GBDK_HOME)bin/lcc -mgbz80:ap +LCC = $(GBDK_HOME)bin/lcc -msm83:ap # You can uncomment the line below to turn on debug output # LCC = $(LCC) -debug diff --git a/gbdk-lib/examples/ap/template_subfolders/Makefile b/gbdk-lib/examples/ap/template_subfolders/Makefile @@ -9,7 +9,7 @@ GBDK_HOME = ../../../ LCC = $(GBDK_HOME)bin/lcc -LCCFLAGS = -mgbz80:ap +LCCFLAGS = -msm83:ap # You can set flags for LCC here # For example, you can uncomment the line below to turn on debug output # LCCFLAGS += -debug diff --git a/gbdk-lib/examples/cross-platform/banks/Makefile.targets b/gbdk-lib/examples/cross-platform/banks/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/banks_autobank/Makefile.targets b/gbdk-lib/examples/cross-platform/banks_autobank/Makefile.targets @@ -11,35 +11,30 @@ build-target: $(BINS) clean-target: rm -rf $(OBJDIR) - rm -f $(BINDIR)/*.com $(BINDIR)/*.bin $(BINDIR)/*.noi $(BINDIR)/*.sym $(BINDIR)/*.ihx $(BINDIR)/*.map $(BINDIR)/*.0?? - -msxdos-clean: - ${MAKE} clean-target EXT=com -msxdos: - ${MAKE} build-target PORT=z80 PLAT=msxdos EXT=com + rm -rf $(BINDIR) gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: @@ -53,3 +48,8 @@ gg-clean: gg: ${MAKE} build-target PORT=z80 PLAT=gg EXT=gg +msxdos-clean: + ${MAKE} clean-target EXT=com +msxdos: + ${MAKE} build-target PORT=z80 PLAT=msxdos EXT=com + diff --git a/gbdk-lib/examples/cross-platform/banks_autobank/src/banks.c b/gbdk-lib/examples/cross-platform/banks_autobank/src/banks.c @@ -23,7 +23,9 @@ void main(void) { uint8_t _saved_bank; + #ifndef MSXDOS // TODO set_default_palette(); + #endif printf("Program Start...\n\n"); // Call the functions, unbanked first then the banked ones diff --git a/gbdk-lib/examples/cross-platform/banks_farptr/Makefile.targets b/gbdk-lib/examples/cross-platform/banks_farptr/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/banks_nonintrinsic/Makefile.targets b/gbdk-lib/examples/cross-platform/banks_nonintrinsic/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/emu_debug/Makefile.targets b/gbdk-lib/examples/cross-platform/emu_debug/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/fonts/Makefile.targets b/gbdk-lib/examples/cross-platform/fonts/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/gbdecompress/Makefile.targets b/gbdk-lib/examples/cross-platform/gbdecompress/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/incbin/Makefile.targets b/gbdk-lib/examples/cross-platform/incbin/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/large_map/Makefile.targets b/gbdk-lib/examples/cross-platform/large_map/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/logo/Makefile b/gbdk-lib/examples/cross-platform/logo/Makefile @@ -29,7 +29,7 @@ RESFLAGS_SEGA = -map -use_map_attributes -bpp 4 -max_palettes 2 -pack_mode sms RESFLAGS += $(RESFLAGS_$(TYP)) -CFLAGS += -Wf-I$(OBJDIR) -DSYSTEM_$(TYP) +CFLAGS += -I$(OBJDIR) -DSYSTEM_$(TYP) # You can set the name of the ROM file here PROJECTNAME = logo @@ -45,7 +45,7 @@ BINS = $(OBJDIR)/$(PROJECTNAME).$(EXT) IMAGES = $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.png))) CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) -OBJS = $(IMAGES:%.png=$(OBJDIR)/%.c) $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o) +OBJS = $(IMAGES:%.png=$(OBJDIR)/%.o) $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o) # Builds all targets sequentially all: $(TARGETS) @@ -53,6 +53,9 @@ all: $(TARGETS) $(OBJDIR)/%.c: $(RESDIR)/%.png $(PNG2ASSETS) $< $(RESFLAGS) -c $@ +$(OBJDIR)/%.o: $(OBJDIR)/%.c + $(LCC) $(CFLAGS) -c -o $@ $< + # Compile .c files in "src/" to .o object files $(OBJDIR)/%.o: $(SRCDIR)/%.c $(LCC) $(CFLAGS) -c -o $@ $< diff --git a/gbdk-lib/examples/cross-platform/logo/Makefile.targets b/gbdk-lib/examples/cross-platform/logo/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb TYP=DMG + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb TYP=DMG gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc TYP=CGB + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc TYP=CGB pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket TYP=DMG + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket TYP=DMG megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck TYP=DMG + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck TYP=DMG sms-clean: diff --git a/gbdk-lib/examples/cross-platform/metasprites/Makefile.targets b/gbdk-lib/examples/cross-platform/metasprites/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/pong/Makefile.targets b/gbdk-lib/examples/cross-platform/pong/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/randtest/Makefile.targets b/gbdk-lib/examples/cross-platform/randtest/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/rle_map/Makefile.targets b/gbdk-lib/examples/cross-platform/rle_map/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/cross-platform/scroller/Makefile.targets b/gbdk-lib/examples/cross-platform/scroller/Makefile.targets @@ -16,25 +16,25 @@ clean-target: gb-clean: ${MAKE} clean-target EXT=gb gb: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gb + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb gbc-clean: ${MAKE} clean-target EXT=gbc gbc: - ${MAKE} build-target PORT=gbz80 PLAT=gb EXT=gbc + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc pocket-clean: ${MAKE} clean-target EXT=pocket pocket: - ${MAKE} build-target PORT=gbz80 PLAT=ap EXT=pocket + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket megaduck-clean: ${MAKE} clean-target EXT=duck megaduck: - ${MAKE} build-target PORT=gbz80 PLAT=duck EXT=duck + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck sms-clean: diff --git a/gbdk-lib/examples/gb/Makefile.rgbds b/gbdk-lib/examples/gb/Makefile.rgbds @@ -1,92 +0,0 @@ -TOPDIR= ../.. -CC= $(TOPDIR)/bin/sdcc -mgbz80 --asm=rgbds -I$(TOPDIR)/include -v -GBLIB = $(TOPDIR)/lib/rgbds -LIB = $(GBLIB)/gbz80/gbz80.lib $(GBLIB)/gb/gb.lib -CRT0 = $(GBLIB)/gb/crt0.o - -BINS = \ - galaxy.gb \ - paint.gb \ - rpn.gb \ - rand.gb \ - comm.gb \ - irq.gb \ - filltest.gb \ - fonts.gb \ - samptest.gb - -# sound.gb: Cant do bitfields -OTHER = sound.gb \ - banks.gb \ - ram_fn.gb - -all: $(BINS) - -compile.bat: Makefile - make -sn | sed y/\\//\\\\/ | grep -v make > compile.bat - -%.o: %.s - -%.asm: %.s - astorgb.pl $< > $@ - -%.o: %.c - $(CC) -c $< - -%.s: %.c - $(CC) -S $< - -%.o: %.asm - rgbasm -o$@ $< - -%.gb: %.o - $(CC) $(CRT0) $< $(LIB) - cp a.gb $@ - rgbfix -p -v $@ - -clean: - rm -f *.o *.lst *.map *.gb *~ *.rel *.cdb *.ihx *.lnk *.sym *.asm - -############################################################ -# Multiple bank example - -# Compile bank 0 (no ROM) -# RAM bank 0 : -Wf-ba0 -# -bank_0.o: bank_0.c - $(CC) -Wf-ba0 -c -o $@ $< - -# Compile bank 1 (ROM+RAM) -# ROM bank 1 : -Wf-bo1 -# RAM bank 1 : -Wf-ba1 -# -bank_1.o: bank_1.c - $(CC) -Wf-bo1 -Wf-ba1 -c -o $@ $< - -# Compile bank 2 (ROM+RAM) -# ROM bank 2 : -Wf-bo2 -# RAM bank 2 : -Wf-ba2 -# -bank_2.o: bank_2.c - $(CC) -Wf-bo2 -Wf-ba2 -c -o $@ $< - -# Compile bank 3 (ROM+RAM) -# ROM bank 3 : -Wf-bo3 -# RAM bank 3 : -Wf-ba3 -# -bank_3.o: bank_3.c - $(CC) -Wf-bo3 -Wf-ba3 -c -o $@ $< - -# Link banks -# ROM+MBC1+RAM : -Wl-yt2 -# 4 ROM banks : -Wl-yo4 -# 4 RAM banks : -Wl-ya4 -# -banks.gb: banks.o bank_0.o bank_1.o bank_2.o bank_3.o - $(CC) -Wl-yt2 -Wl-yo4 -Wl-ya4 -o $@ banks.o bank_0.o bank_1.o bank_2.o bank_3.o - -############################################################ -# RAM function example - -ram_fn.gb: ram_fn.o - $(CC) -Wl-g_inc_ram=0xD000 -Wl-g_inc_hiram=0xFFA0 -o $@ ram_fn.o diff --git a/gbdk-lib/include/asm/gbz80/stdarg.h b/gbdk-lib/include/asm/gbz80/stdarg.h @@ -1,18 +0,0 @@ -#ifndef ASM_GBZ80_STDARG_INCLUDE -#define ASM_GBZ80_STDARG_INCLUDE - -/* sdcc pushes right to left with the real sizes, not cast up - to an int. - so printf(int, char, long) - results in push long, push char, push int - On the z80 the stack grows down, so the things seem to be in - the correct order. - */ - -typedef unsigned char * va_list; -#define va_start(list, last) list = (unsigned char *)&last + sizeof(last) -#define va_arg(list, type) *((type *)((list += sizeof(type)) - sizeof(type))) - -#define va_end(list) - -#endif diff --git a/gbdk-lib/include/asm/gbz80/string.h b/gbdk-lib/include/asm/gbz80/string.h @@ -1,150 +0,0 @@ -/** @file string.h - Generic string functions. - */ -#ifndef STRING_INCLUDE -#define STRING_INCLUDE - -#include <types.h> - -/** Copies the string pointed to by __src__ (including the terminating - `\0' character) to the array pointed to by __dest__. - - The strings may not overlap, and the destination string dest must - be large enough to receive the copy. - - @param dest Array to copy into - @param src Array to copy from - - @return A pointer to dest -*/ -char *strcpy(char *dest, const char *src) OLDCALL PRESERVES_REGS(b, c); - -/** Compares strings - - @param s1 First string to compare - @param s2 Second string to compare - - Returns: - \li > 0 if __s1__ > __s2__ - \li 0 if __s1__ == __s2__ - \li < 0 if __s1__ < __s2__ -*/ -int strcmp(const char *s1, const char *s2) OLDCALL PRESERVES_REGS(b, c); - -/** Copies n bytes from memory area src to memory area dest. - - The memory areas may not overlap. - - @param dest Buffer to copy into - @param src Buffer to copy from - @param len Number of Bytes to copy -*/ -void *memcpy(void *dest, const void *src, size_t len) OLDCALL PRESERVES_REGS(b, c); - -/** Copies n bytes from memory area src to memory area dest, areas may overlap - */ -void *memmove (void *dest, const void *src, size_t n); - -/** Fills the memory region __s__ with __n__ bytes using value __c__ - - @param s Buffer to fill - @param c char value to fill with (truncated from int) - @param n Number of bytes to fill -*/ -void *memset (void *s, int c, size_t n) OLDCALL PRESERVES_REGS(b, c); - -/** Reverses the characters in a string - - @param s Pointer to string to reverse. - - For example 'abcdefg' will become 'gfedcba'. - - Banked as the string must be modifiable. - - Returns: Pointer to __s__ -*/ -char *reverse(char *s) OLDCALL PRESERVES_REGS(b, c); - -/** Concatenate Strings. Appends string __s2__ to the end of string __s1__ - - @param s1 String to append onto - @param s2 String to copy from - - For example 'abc' and 'def' will become 'abcdef'. - - String __s1__ must be large enough to store both __s1__ and __s2__. - - Returns: Pointer to __s1__ -*/ -char *strcat(char *s1, const char *s2); - -/** Calculates the length of a string - - @param s String to calculate length of - - Returns: Length of string not including the terminating `\0' character. -*/ -int strlen(const char *s) OLDCALL PRESERVES_REGS(b, c); - -/**Concatenate at most __n__ characters from string __s2__ onto the end of __s1__. - - @param s1 String to append onto - @param s2 String to copy from - @param n Max number of characters to copy from __s2__ - - String __s1__ must be large enough to store both __s1__ and __n__ characters of __s2__ - - Returns: Pointer to __s1__ -*/ -char *strncat(char *s1, const char *s2, int n); - -/** Compare strings (at most __n__ characters): - - @param s1 First string to compare - @param s2 Second string to compare - @param n Max number of characters to compare - - Returns zero if the strings are identical, or non-zero - if they are not (see below). - - Returns: - \li > 0 if __s1__ > __s2__ (at first non-matching byte) - \li 0 if __s1__ == __s2__ - \li < 0 if __s1__ < __s2__ (at first non-matching byte) -*/ -int strncmp(const char *s1, const char *s2, int n); - -/** Copy __n__ characters from string __s2__ to __s1__ - - - @param s1 String to copy into - @param s2 String to copy from - @param n Max number of characters to copy from __s2__ - - If __s2__ is shorter than __n__, the remaining - bytes in __s1__ are filled with \0. - - Warning: If there is no \0 in the first __n__ bytes of __s2__ then __s1__ - will not be null terminated. - - Returns: Pointer to __s1__ -*/ -char *strncpy(char *s1, const char *s2, int n); - -/** Compare up to __count__ bytes in buffers __buf1__ and __buf2__ - - @param buf1 Pointer to First buffer to compare - @param buf2 Pointer to Second buffer to compare - @param count Max number of bytes to compare - - Returns zero if the buffers are identical, or non-zero - if they are not (see below). - - Returns: - \li > 0 if __buf1__ > __buf2__ (at first non-matching byte) - \li 0 if __buf1__ == __buf2__ - \li < 0 if __buf1__ < __buf2__ (at first non-matching byte) -*/ -int memcmp(const void *buf1, const void *buf2, size_t count) OLDCALL; - -#endif diff --git a/gbdk-lib/include/asm/gbz80/types.h b/gbdk-lib/include/asm/gbz80/types.h @@ -1,70 +0,0 @@ -/** @file asm/gbz80/types.h - @anchor file_asm_gbz80_types_h - Types definitions for the gb. -*/ -#ifndef ASM_GBZ80_TYPES_INCLUDE -#define ASM_GBZ80_TYPES_INCLUDE - -#ifndef __PORT_gbz80 - #error gbz80 only. -#endif - -#ifdef __SDCC - -#define NONBANKED __nonbanked /**< Placed in the non-banked lower 16K region (bank 0), regardless of the bank selected by it's source file. */ -#define BANKED __banked /**< The function will use banked sdcc calls, and is placed in the bank selected by it's source file (or compiler switches). */ - -/** Use to create a block of of code which should execute with interrupts temporarily turned off. - - __Do not__ use @ref CRITICAL and @ref INTERRUPT attributes for a - function added via add_VBL() (or LCD, etc). The attributes - are only required when constructing a bare jump from the - interrupt vector itself. - - @see enable_interrupts, disable_interrupts -*/ -#define CRITICAL __critical - -/** Indicate to the compiler the function will be used as an interrupt handler. - - __Do not__ use @ref CRITICAL and @ref INTERRUPT attributes for a - function added via add_VBL() (or LCD, etc). The attributes - are only required when constructing a bare jump from the - interrupt vector itself. - - @see ISR_VECTOR(), ISR_NESTED_VECTOR() -*/ -#define INTERRUPT __interrupt - -#endif - -/** Signed eight bit. - */ -typedef signed char INT8; -/** Unsigned eight bit. - */ -typedef unsigned char UINT8; -/** Signed sixteen bit. - */ -typedef signed int INT16; -/** Unsigned sixteen bit. - */ -typedef unsigned int UINT16; -/** Signed 32 bit. - */ -typedef signed long INT32; -/** Unsigned 32 bit. - */ -typedef unsigned long UINT32; - -#ifndef __SIZE_T_DEFINED -#define __SIZE_T_DEFINED -typedef unsigned int size_t; -#endif - -/** Returned from clock - @see clock -*/ -typedef unsigned int clock_t; - -#endif diff --git a/gbdk-lib/include/asm/gbz80/provides.h b/gbdk-lib/include/asm/sm83/provides.h diff --git a/gbdk-lib/include/asm/sm83/stdarg.h b/gbdk-lib/include/asm/sm83/stdarg.h @@ -0,0 +1,18 @@ +#ifndef ASM_SM83_STDARG_INCLUDE +#define ASM_SM83_STDARG_INCLUDE + +/* sdcc pushes right to left with the real sizes, not cast up + to an int. + so printf(int, char, long) + results in push long, push char, push int + On the z80 the stack grows down, so the things seem to be in + the correct order. + */ + +typedef unsigned char * va_list; +#define va_start(list, last) list = (unsigned char *)&last + sizeof(last) +#define va_arg(list, type) *((type *)((list += sizeof(type)) - sizeof(type))) + +#define va_end(list) + +#endif diff --git a/gbdk-lib/include/asm/sm83/string.h b/gbdk-lib/include/asm/sm83/string.h @@ -0,0 +1,150 @@ +/** @file string.h + Generic string functions. + */ +#ifndef STRING_INCLUDE +#define STRING_INCLUDE + +#include <types.h> + +/** Copies the string pointed to by __src__ (including the terminating + `\0' character) to the array pointed to by __dest__. + + The strings may not overlap, and the destination string dest must + be large enough to receive the copy. + + @param dest Array to copy into + @param src Array to copy from + + @return A pointer to dest +*/ +char *strcpy(char *dest, const char *src) OLDCALL PRESERVES_REGS(b, c); + +/** Compares strings + + @param s1 First string to compare + @param s2 Second string to compare + + Returns: + \li > 0 if __s1__ > __s2__ + \li 0 if __s1__ == __s2__ + \li < 0 if __s1__ < __s2__ +*/ +int strcmp(const char *s1, const char *s2) OLDCALL PRESERVES_REGS(b, c); + +/** Copies n bytes from memory area src to memory area dest. + + The memory areas may not overlap. + + @param dest Buffer to copy into + @param src Buffer to copy from + @param len Number of Bytes to copy +*/ +void *memcpy(void *dest, const void *src, size_t len); + +/** Copies n bytes from memory area src to memory area dest, areas may overlap + */ +void *memmove (void *dest, const void *src, size_t n); + +/** Fills the memory region __s__ with __n__ bytes using value __c__ + + @param s Buffer to fill + @param c char value to fill with (truncated from int) + @param n Number of bytes to fill +*/ +void *memset (void *s, int c, size_t n) OLDCALL PRESERVES_REGS(b, c); + +/** Reverses the characters in a string + + @param s Pointer to string to reverse. + + For example 'abcdefg' will become 'gfedcba'. + + Banked as the string must be modifiable. + + Returns: Pointer to __s__ +*/ +char *reverse(char *s) OLDCALL PRESERVES_REGS(b, c); + +/** Concatenate Strings. Appends string __s2__ to the end of string __s1__ + + @param s1 String to append onto + @param s2 String to copy from + + For example 'abc' and 'def' will become 'abcdef'. + + String __s1__ must be large enough to store both __s1__ and __s2__. + + Returns: Pointer to __s1__ +*/ +char *strcat(char *s1, const char *s2); + +/** Calculates the length of a string + + @param s String to calculate length of + + Returns: Length of string not including the terminating `\0' character. +*/ +int strlen(const char *s) OLDCALL PRESERVES_REGS(b, c); + +/**Concatenate at most __n__ characters from string __s2__ onto the end of __s1__. + + @param s1 String to append onto + @param s2 String to copy from + @param n Max number of characters to copy from __s2__ + + String __s1__ must be large enough to store both __s1__ and __n__ characters of __s2__ + + Returns: Pointer to __s1__ +*/ +char *strncat(char *s1, const char *s2, int n); + +/** Compare strings (at most __n__ characters): + + @param s1 First string to compare + @param s2 Second string to compare + @param n Max number of characters to compare + + Returns zero if the strings are identical, or non-zero + if they are not (see below). + + Returns: + \li > 0 if __s1__ > __s2__ (at first non-matching byte) + \li 0 if __s1__ == __s2__ + \li < 0 if __s1__ < __s2__ (at first non-matching byte) +*/ +int strncmp(const char *s1, const char *s2, int n); + +/** Copy __n__ characters from string __s2__ to __s1__ + + + @param s1 String to copy into + @param s2 String to copy from + @param n Max number of characters to copy from __s2__ + + If __s2__ is shorter than __n__, the remaining + bytes in __s1__ are filled with \0. + + Warning: If there is no \0 in the first __n__ bytes of __s2__ then __s1__ + will not be null terminated. + + Returns: Pointer to __s1__ +*/ +char *strncpy(char *s1, const char *s2, int n); + +/** Compare up to __count__ bytes in buffers __buf1__ and __buf2__ + + @param buf1 Pointer to First buffer to compare + @param buf2 Pointer to Second buffer to compare + @param count Max number of bytes to compare + + Returns zero if the buffers are identical, or non-zero + if they are not (see below). + + Returns: + \li > 0 if __buf1__ > __buf2__ (at first non-matching byte) + \li 0 if __buf1__ == __buf2__ + \li < 0 if __buf1__ < __buf2__ (at first non-matching byte) +*/ +int memcmp(const void *buf1, const void *buf2, size_t count) OLDCALL; + +#endif diff --git a/gbdk-lib/include/asm/sm83/types.h b/gbdk-lib/include/asm/sm83/types.h @@ -0,0 +1,70 @@ +/** @file asm/sm83/types.h + @anchor file_asm_sm83_types_h + Types definitions for the gb. +*/ +#ifndef ASM_SM83_TYPES_INCLUDE +#define ASM_SM83_TYPES_INCLUDE + +#ifndef __PORT_sm83 + #error sm83 only. +#endif + +#ifdef __SDCC + +#define NONBANKED __nonbanked /**< Placed in the non-banked lower 16K region (bank 0), regardless of the bank selected by it's source file. */ +#define BANKED __banked /**< The function will use banked sdcc calls, and is placed in the bank selected by it's source file (or compiler switches). */ + +/** Use to create a block of of code which should execute with interrupts temporarily turned off. + + __Do not__ use @ref CRITICAL and @ref INTERRUPT attributes for a + function added via add_VBL() (or LCD, etc). The attributes + are only required when constructing a bare jump from the + interrupt vector itself. + + @see enable_interrupts, disable_interrupts +*/ +#define CRITICAL __critical + +/** Indicate to the compiler the function will be used as an interrupt handler. + + __Do not__ use @ref CRITICAL and @ref INTERRUPT attributes for a + function added via add_VBL() (or LCD, etc). The attributes + are only required when constructing a bare jump from the + interrupt vector itself. + + @see ISR_VECTOR(), ISR_NESTED_VECTOR() +*/ +#define INTERRUPT __interrupt + +#endif + +/** Signed eight bit. + */ +typedef signed char INT8; +/** Unsigned eight bit. + */ +typedef unsigned char UINT8; +/** Signed sixteen bit. + */ +typedef signed int INT16; +/** Unsigned sixteen bit. + */ +typedef unsigned int UINT16; +/** Signed 32 bit. + */ +typedef signed long INT32; +/** Unsigned 32 bit. + */ +typedef unsigned long UINT32; + +#ifndef __SIZE_T_DEFINED +#define __SIZE_T_DEFINED +typedef unsigned int size_t; +#endif + +/** Returned from clock + @see clock +*/ +typedef unsigned int clock_t; + +#endif diff --git a/gbdk-lib/include/asm/types.h b/gbdk-lib/include/asm/types.h @@ -4,8 +4,8 @@ #ifndef ASM_TYPES_INCLUDE #define ASM_TYPES_INCLUDE -#if defined(__PORT_gbz80) -#include <asm/gbz80/types.h> +#if defined(__PORT_sm83) +#include <asm/sm83/types.h> #elif defined(__PORT_z80) #include <asm/z80/types.h> #else diff --git a/gbdk-lib/include/asm/z80/string.h b/gbdk-lib/include/asm/z80/string.h @@ -39,7 +39,7 @@ int strcmp(const char *s1, const char *s2); @param src Buffer to copy from @param len Number of Bytes to copy */ -void *memcpy(void *dest, const void *src, size_t len) OLDCALL; +void *memcpy(void *dest, const void *src, size_t len); /** Copies n bytes from memory area src to memory area dest, areas may overlap */ diff --git a/gbdk-lib/include/asm/z80/types.h b/gbdk-lib/include/asm/z80/types.h @@ -1,4 +1,4 @@ -/** @file asm/gbz80/types.h +/** @file asm/z80/types.h @anchor file_asm_z80_types_h Types definitions for the gb. */ @@ -11,7 +11,7 @@ #ifdef __SDCC -#define Z88DK_CALLEE __z88dk_callee +#define Z88DK_CALLEE __sdcccall(0) __z88dk_callee #define Z88DK_FASTCALL __z88dk_fastcall #define NONBANKED __nonbanked /**< Placed in the non-banked lower 16K region (bank 0), regardless of the bank selected by it's source file. */ diff --git a/gbdk-lib/include/gbdk/gbdk-lib.h b/gbdk-lib/include/gbdk/gbdk-lib.h @@ -4,8 +4,8 @@ #ifndef GBDK_LIB_INCLUDE #define GBDK_LIB_INCLUDE -#if defined(__PORT_gbz80) - #include <asm/gbz80/provides.h> +#if defined(__PORT_sm83) + #include <asm/sm83/provides.h> #elif defined(__PORT_z80) #include <asm/z80/provides.h> #else diff --git a/gbdk-lib/include/rand.h b/gbdk-lib/include/rand.h @@ -25,7 +25,7 @@ @see rand(), randw() */ -#if defined(__PORT_gbz80) +#if defined(__PORT_sm83) void initrand(uint16_t seed) OLDCALL; #elif defined(__PORT_z80) void initrand(uint16_t seed) Z88DK_FASTCALL; @@ -68,7 +68,7 @@ uint16_t randw() OLDCALL; @see initrand() for suggestions about seed values, arand() */ -#if defined(__PORT_gbz80) +#if defined(__PORT_sm83) void initarand(uint16_t seed) OLDCALL; #elif defined(__PORT_z80) void initarand(uint16_t seed) Z88DK_FASTCALL; diff --git a/gbdk-lib/include/setjmp.h b/gbdk-lib/include/setjmp.h @@ -55,7 +55,7 @@ typedef unsigned char jmp_buf[6]; /* 2 for the stack pointer, 2 for the return address, 2 for the frame pointer. */ #elif defined (__SDCC_ds390) || defined (__SDCC_stm8) && defined (__SDCC_MODEL_LARGE) typedef unsigned char jmp_buf[5]; /* 2 for the stack pointer, 3 for the return address. */ -#elif defined (__SDCC_stm8) || defined (__SDCC_gbz80) || defined (__SDCC_hc08) || defined (__SDCC_s08) +#elif defined (__SDCC_stm8) || defined (__SDCC_sm83) || defined (__SDCC_hc08) || defined (__SDCC_s08) typedef unsigned char jmp_buf[4]; /* 2 for the stack pointer, 2 for the return address. */ #elif defined (__SDCC_pdk13) || defined (__SDCC_pdk14) || defined (__SDCC_pdk15) typedef unsigned char jmp_buf[3]; /* 1 for the stack pointer, 2 for the return address. */ diff --git a/gbdk-lib/include/stdarg.h b/gbdk-lib/include/stdarg.h @@ -1,9 +1,9 @@ #ifndef STDARG_INCLUDE #define STDARG_INCLUDE -#if SDCC_PORT==gbz80 -#include <asm/gbz80/stdarg.h> -#elif SDCC_PORT==z80 +#if defined(__PORT_sm83) +#include <asm/sm83/stdarg.h> +#elif defined(__PORT_z80) #include <asm/z80/stdarg.h> #else #error Unrecognised port. diff --git a/gbdk-lib/include/stdatomic.h b/gbdk-lib/include/stdatomic.h @@ -5,7 +5,7 @@ typedef struct {unsigned char flag;} atomic_flag; -#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_ez80_z80) || defined(__SDCC_gbz80) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) || defined(__SDCC_stm8) || defined(__SDCC_hc08) || defined(__SDCC_s08) +#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_ez80_z80) || defined(__SDCC_sm83) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) || defined(__SDCC_stm8) || defined(__SDCC_hc08) || defined(__SDCC_s08) #define ATOMIC_FLAG_INIT {1} //#elif defined(__SDCC_mcs51) //#define ATOMIC_FLAG_INIT {0} diff --git a/gbdk-lib/include/string.h b/gbdk-lib/include/string.h @@ -4,8 +4,8 @@ #ifndef STD_STRING_INCLUDE #define STD_STRING_INCLUDE -#ifdef __PORT_gbz80 - #include <asm/gbz80/string.h> +#ifdef __PORT_sm83 + #include <asm/sm83/string.h> #else #ifdef __PORT_z80 #include <asm/z80/string.h> diff --git a/gbdk-lib/libc/Makefile b/gbdk-lib/libc/Makefile @@ -3,7 +3,7 @@ .EXPORT_ALL_VARIABLES: ifeq ($(PORTS),) - PORTS = gbz80 z80 + PORTS = sm83 z80 endif ifeq ($(PLATFORMS),) diff --git a/gbdk-lib/libc/_divulong.c b/gbdk-lib/libc/_divulong.c @@ -322,7 +322,7 @@ _divulong (unsigned long a, unsigned long b) { unsigned long reste = 0L; unsigned char count = 32; - #if defined(__SDCC_STACK_AUTO) || defined(__SDCC_z80) || defined(__SDCC_gbz80) + #if defined(__SDCC_STACK_AUTO) || defined(__SDCC_z80) || defined(__SDCC_sm83) char c; #else bit c; diff --git a/gbdk-lib/libc/_mullong.c b/gbdk-lib/libc/_mullong.c @@ -64,7 +64,7 @@ union bil { if 16x16->16 is faster than three 8x8->16. 2009, by M.Bodrato ( http://bodrato.it/ ) - z80 and gbz80 don't have any hardware multiplication. + z80 and sm83 don't have any hardware multiplication. r2k and r3k have 16x16 hardware multiplication. */ long _mullong (long a, long b) diff --git a/gbdk-lib/libc/asm/gbz80/Makefile b/gbdk-lib/libc/asm/gbz80/Makefile @@ -1,22 +0,0 @@ -# gbz80 specific Makefile - -TOPDIR = ../../.. - -THIS = gbz80 - -ASSRC = __sdcc_call_hl.s abs.s mul.s div.s shift.s crt0_rle.s \ - itoa.s strlen.s reverse.s labs.s ltoa.s \ - setjmp.s atomic_flag_test_and_set.s \ - _memcpy.s _memset.s _strcmp.s _strcpy.s _memcmp.s \ - rand.s arand.s \ - bcd.s - -CSRC = _memmove.c - -include $(TOPDIR)/Makefile.common - -AS = $(AS_GBZ80) - -include ../Makefile.port - - diff --git a/gbdk-lib/libc/asm/gbz80/_memcpy.s b/gbdk-lib/libc/asm/gbz80/_memcpy.s @@ -1,71 +0,0 @@ - .module memcpy - - .area _HOME - -; void *memcpy(void *dest, const void *source, int count) -___memcpy:: -_memcpy:: - lda hl,7(sp) - ld a,(hl-) - ld d, a - ld a,(hl-) - ld e,a ; de == count - or d - jr z, 6$ - - push bc ; preserve bc (smallc convention) - - ld a,(hl-) - ld b,a - ld a,(hl-) - ld c,a ; bc == source - ld a,(hl-) - ld l,(hl) - ld h,a ; hl == dest - - srl d - rr e - jr nc,4$ - ld a,(bc) ; copy one byte - ld (hl+),a - inc bc -4$: - srl d - rr e - jr nc,5$ - ld a,(bc) ; copy two bytes - ld (hl+),a - inc bc - ld a,(bc) - ld (hl+),a - inc bc -5$: - inc d - inc e - jr 2$ -1$: - ld a,(bc) ; copy four bytes - ld (hl+),a - inc bc - ld a,(bc) - ld (hl+),a - inc bc - ld a,(bc) - ld (hl+),a - inc bc - ld a,(bc) - ld (hl+),a - inc bc -2$: - dec e - jr nz,1$ - dec d - jr nz,1$ -3$: - pop bc ; restore bc -6$: - lda hl,2(sp) ; return dest - ld a,(hl+) - ld e,a - ld d,(hl) - ret diff --git a/gbdk-lib/libc/asm/gbz80/div.s b/gbdk-lib/libc/asm/gbz80/div.s @@ -1,415 +0,0 @@ -;-------------------------------------------------------------------------- -; div.s -; -; Copyright (C) 2000, Michael Hope -; -; This library is free software; you can redistribute it and/or modify it -; under the terms of the GNU General Public License as published by the -; Free Software Foundation; either version 2, or (at your option) any -; later version. -; -; This library is distributed in the hope that it will be useful, -; but WITHOUT ANY WARRANTY; without even the implied warranty of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; GNU General Public License for more details. -; -; You should have received a copy of the GNU General Public License -; along with this library; see the file COPYING. If not, write to the -; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, -; MA 02110-1301, USA. -; -; As a special exception, if you link this library with other files, -; some of which are compiled with SDCC, to produce an executable, -; this library does not by itself cause the resulting executable to -; be covered by the GNU General Public License. This exception does -; not however invalidate any other reasons why the executable file -; might be covered by the GNU General Public License. -;-------------------------------------------------------------------------- - - ;; Originally from GBDK by Pascal Felber. - - .module div - - .area _HOME - -.globl __divsuchar -.globl __modsuchar -.globl __divuschar -.globl __moduschar -.globl __divschar -.globl __modschar -.globl __divsint -.globl __modsint -.globl __divuchar -.globl __moduchar -.globl __divuint -.globl __moduint - -__divsuchar: - ldhl sp,#2+1 - - ld e,(hl) - dec hl - ld c,(hl) - ld b,#0 - - call signexte - - ld e,c - ld d,b - - ret - -__modsuchar: - ldhl sp,#2+1 - - ld e,(hl) - dec hl - ld c,(hl) - ld b,#0 - - jp signexte - -__divuschar: - ld hl,#2+1 - ld d, h - add hl,sp - - ld a,(hl-) - ld e, a - ld c,(hl) - - ld a,c ; Sign extend - rlca - sbc a - ld b,a - - call .div16 - - ld e,c - ld d,b - - ret - -__moduschar: - ld hl,#2+1 - ld d, h - add hl,sp - - ld a,(hl-) - ld e, a - ld c,(hl) - - ld a,c ; Sign extend - rlca - sbc a - ld b,a - - call .div16 - - ret - -__divschar: - ldhl sp,#2+1 - - ld e,(hl) - dec hl - ld l,(hl) - - ld c,l - - call .div8 - - ld e,c - ld d,b - - ret - -__modschar: - ldhl sp,#2+1 - - ld e,(hl) - dec hl - ld l,(hl) - - ld c,l - - call .div8 - - ;; Already in DE - - ret - -__divsint: - ldhl sp,#2+3 - - ld a,(hl-) - ld d, a - ld a,(hl-) - ld e, a - ld a,(hl-) - ld l,(hl) - ld h,a - - ld b,h - ld c,l - - call .div16 - - ld e,c - ld d,b - - ret - -__modsint: - ldhl sp,#2+3 - - ld a,(hl-) - ld d, a - ld a,(hl-) - ld e, a - ld a,(hl-) - ld l,(hl) - ld h,a - - ld b,h - ld c,l - - call .div16 - - ;; Already in DE - - ret - - ;; Unsigned -__divuchar: - ldhl sp,#2+1 - - ld e,(hl) - dec hl - ld l,(hl) - - ld c,l - call .divu8 - - ld e,c - ld d,b - - ret - -__moduchar: - ldhl sp,#2+1 - - ld e,(hl) - dec hl - ld l,(hl) - - ld c,l - call .divu8 - - ;; Already in DE - - ret - -__divuint: - ldhl sp,#2+3 - - ld a,(hl-) - ld d, a - ld a,(hl-) - ld e, a - ld a,(hl-) - ld l,(hl) - ld h,a - - ld b,h - ld c,l - call .divu16 - - ld e,c - ld d,b - - ret - -__moduint: - ldhl sp,#2+3 - - ld a,(hl-) - ld d, a - ld a,(hl-) - ld e, a - ld a,(hl-) - ld l,(hl) - ld h,a - - ld b,h - ld c,l - - call .divu16 - - ;; Already in DE - - ret - -.div8:: -.mod8:: - ld a,c ; Sign extend - rlca - sbc a - ld b,a -signexte: - ld a,e ; Sign extend - rlca - sbc a - ld d,a - - ; Fall through to .div16 - - ;; 16-bit division - ;; - ;; Entry conditions - ;; BC = dividend - ;; DE = divisor - ;; - ;; Exit conditions - ;; BC = quotient - ;; DE = remainder - ;; If divisor is non-zero, carry=0 - ;; If divisor is 0, carry=1 and both quotient and remainder are 0 - ;; - ;; Register used: AF,BC,DE,HL -.div16:: -.mod16:: - ;; Determine sign of quotient by xor-ing high bytes of dividend - ;; and divisor. Quotient is positive if signs are the same, negative - ;; if signs are different - ;; Remainder has same sign as dividend - ld a,b ; Get high byte of dividend - push af ; Save as sign of remainder - xor d ; Xor with high byte of divisor - push af ; Save sign of quotient - - ;; Take absolute value of divisor - bit 7,d - jr Z,.chkde ; Jump if divisor is positive - sub a ; Substract divisor from 0 - sub e - ld e,a - sbc a ; Propagate borrow (A=0xFF if borrow) - sub d - ld d,a - ;; Take absolute value of dividend -.chkde: - bit 7,b - jr Z,.dodiv ; Jump if dividend is positive - sub a ; Substract dividend from 0 - sub c - ld c,a - sbc a ; Propagate borrow (A=0xFF if borrow) - sub b - ld b,a - ;; Divide absolute values -.dodiv: - call .divu16 - jr C,.exit ; Exit if divide by zero - ;; Negate quotient if it is negative - pop af ; recover sign of quotient - and #0x80 - jr Z,.dorem ; Jump if quotient is positive - sub a ; Substract quotient from 0 - sub c - ld c,a - sbc a ; Propagate borrow (A=0xFF if borrow) - sub b - ld b,a -.dorem: - ;; Negate remainder if it is negative - pop af ; recover sign of remainder - and #0x80 - ret Z ; Return if remainder is positive - sub a ; Substract remainder from 0 - sub e - ld e,a - sbc a ; Propagate remainder (A=0xFF if borrow) - sub d - ld d,a - ret -.exit: - pop af - pop af - ret - -.divu8:: -.modu8:: - ld b,#0x00 - ld d,b - ; Fall through to divu16 - -.divu16:: -.modu16:: - ;; Check for division by zero - ld a,e - or d - jr NZ,.divide ; Branch if divisor is non-zero - ld bc,#0x00 ; Divide by zero error - ld d,b - ld e,c - scf ; Set carry, invalid result - ret -.divide: - ld l,c ; L = low byte of dividend/quotient - ld h,b ; H = high byte of dividend/quotient - ld bc,#0x00 ; BC = remainder - or a ; Clear carry to start - ld a,#16 ; 16 bits in dividend -.dvloop: - ;; Shift next bit of quotient into bit 0 of dividend - ;; Shift next MSB of dividend into LSB of remainder - ;; BC holds both dividend and quotient. While we shift a bit from - ;; MSB of dividend, we shift next bit of quotient in from carry - ;; HL holds remainder - ;; Do a 32-bit left shift, shifting carry to L, L to H, - ;; H to C, C to B - push af ; save number of bits remaining - rl l ; Carry (next bit of quotient) to bit 0 - rl h ; Shift remaining bytes - rl c - rl b ; Clears carry since BC was 0 - ;; If remainder is >= divisor, next bit of quotient is 1. This - ;; bit goes to carry - push bc ; Save current remainder - ld a,c ; Substract divisor from remainder - sbc e - ld c,a - ld a,b - sbc d - ld b,a - ccf ; Complement borrow so 1 indicates a - ; successful substraction (this is the - ; next bit of quotient) - jr C,.drop ; Jump if remainder is >= dividend - pop bc ; Otherwise, restore remainder - pop af ; recover # bits remaining, carry flag destroyed - dec a - or a ; restore (clear) the carry flag - jr NZ,.dvloop - jr .nodrop -.drop: - inc sp - inc sp - pop af ; recover # bits remaining, carry flag destroyed - dec a - scf ; restore (set) the carry flag - jr NZ,.dvloop - jr .nodrop -.nodrop: - ;; Shift last carry bit into quotient - ld d,b ; DE = remainder - ld e,c - rl l ; Carry to L - ld c,l ; C = low byte of quotient - rl h - ld b,h ; B = high byte of quotient - or a ; Clear carry, valid result - ret - diff --git a/gbdk-lib/libc/asm/gbz80/mul.s b/gbdk-lib/libc/asm/gbz80/mul.s @@ -1,159 +0,0 @@ -;-------------------------------------------------------------------------- -; mul.s -; -; Copyright (C) 2000, Michael Hope -; -; This library is free software; you can redistribute it and/or modify it -; under the terms of the GNU General Public License as published by the -; Free Software Foundation; either version 2, or (at your option) any -; later version. -; -; This library is distributed in the hope that it will be useful, -; but WITHOUT ANY WARRANTY; without even the implied warranty of -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -; GNU General Public License for more details. -; -; You should have received a copy of the GNU General Public License -; along with this library; see the file COPYING. If not, write to the -; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, -; MA 02110-1301, USA. -; -; As a special exception, if you link this library with other files, -; some of which are compiled with SDCC, to produce an executable, -; this library does not by itself cause the resulting executable to -; be covered by the GNU General Public License. This exception does -; not however invalidate any other reasons why the executable file -; might be covered by the GNU General Public License. -;-------------------------------------------------------------------------- - - ;; Originally from GBDK by Pascal Felber. - - .module mul - - .area _HOME - -.globl __mulsuchar -.globl __muluschar -.globl __mulschar -.globl __muluchar -.globl __mulint - -; operands have different sign - -__mulsuchar: - ld hl,#2+1 - ld b, h - add hl,sp - - ld e,(hl) - dec hl - ld c,(hl) - jr signexte - -__muluschar: - ld hl,#2 - ld b, h - add hl,sp - - ld e,(hl) - inc hl - ld c,(hl) - jr signexte - -__mulschar: - ld hl,#2 - add hl,sp - - ld a,(hl+) - ld a, e - ld l,(hl) - - ;; Need to sign extend before going in. - ld c,l - - ld a,l - rla - sbc a,a - ld b,a -signexte: - ld a,e - rla - sbc a,a - ld d,a - - jr .mul16 - -__muluchar: - ld hl,#2 - add hl,sp - - ld a,(hl+) - - ld e, a - ld c,(hl) - - ;; Clear the top - xor a - ld d,a - ld b,a - - jr .mul16 - -__mulint: - ld hl,#2 - add hl,sp - - ld a,(hl+) - ld e, a - ld a,(hl+) - ld d, a - ld a,(hl+) - ld h,(hl) - ld l,a - - ;; Parameters: - ;; HL, DE (left, right irrelivent) - ld b,h - ld c,l - - ;; 16-bit multiplication - ;; - ;; Entry conditions - ;; BC = multiplicand - ;; DE = multiplier - ;; - ;; Exit conditions - ;; DE = less significant word of product - ;; - ;; Register used: AF,BC,DE,HL -.mul16: - ld hl,#0 - ld a,b - ; ld c,c - ld b,#16 - - ;; Optimise for the case when this side has 8 bits of data or - ;; less. This is often the case with support address calls. - or a - jr NZ,1$ - - ld b,#8 - ld a,c -1$: - ;; Taken from z88dk, which originally borrowed from the - ;; Spectrum rom. - add hl,hl - rl c - rla ;DLE 27/11/98 - jr NC,2$ - add hl,de -2$: - dec b - jr NZ,1$ - - ;; Return in DE - ld e,l - ld d,h - - ret - diff --git a/gbdk-lib/libc/asm/sm83/Makefile b/gbdk-lib/libc/asm/sm83/Makefile @@ -0,0 +1,22 @@ +# sm83 specific Makefile + +TOPDIR = ../../.. + +THIS = sm83 + +ASSRC = __sdcc_call_hl.s abs.s mul.s div.s shift.s crt0_rle.s \ + itoa.s strlen.s reverse.s labs.s ltoa.s \ + setjmp.s atomic_flag_test_and_set.s \ + memcpy.s _memset.s _strcmp.s _strcpy.s _memcmp.s \ + rand.s arand.s \ + bcd.s + +CSRC = _memmove.c + +include $(TOPDIR)/Makefile.common + +AS = $(AS_SM83) + +include ../Makefile.port + + diff --git a/gbdk-lib/libc/asm/gbz80/__sdcc_call_hl.s b/gbdk-lib/libc/asm/sm83/__sdcc_call_hl.s diff --git a/gbdk-lib/libc/asm/gbz80/_memcmp.s b/gbdk-lib/libc/asm/sm83/_memcmp.s diff --git a/gbdk-lib/libc/asm/gbz80/_memmove.c b/gbdk-lib/libc/asm/sm83/_memmove.c diff --git a/gbdk-lib/libc/asm/gbz80/_memset.s b/gbdk-lib/libc/asm/sm83/_memset.s diff --git a/gbdk-lib/libc/asm/gbz80/_strcmp.s b/gbdk-lib/libc/asm/sm83/_strcmp.s diff --git a/gbdk-lib/libc/asm/gbz80/_strcpy.s b/gbdk-lib/libc/asm/sm83/_strcpy.s diff --git a/gbdk-lib/libc/asm/gbz80/abs.s b/gbdk-lib/libc/asm/sm83/abs.s diff --git a/gbdk-lib/libc/asm/gbz80/arand.s b/gbdk-lib/libc/asm/sm83/arand.s diff --git a/gbdk-lib/libc/asm/gbz80/atomic_flag_test_and_set.s b/gbdk-lib/libc/asm/sm83/atomic_flag_test_and_set.s diff --git a/gbdk-lib/libc/asm/gbz80/bcd.s b/gbdk-lib/libc/asm/sm83/bcd.s diff --git a/gbdk-lib/libc/asm/gbz80/crt0_rle.s b/gbdk-lib/libc/asm/sm83/crt0_rle.s diff --git a/gbdk-lib/libc/asm/sm83/div.s b/gbdk-lib/libc/asm/sm83/div.s @@ -0,0 +1,339 @@ +;-------------------------------------------------------------------------- +; div.s +; +; Copyright (C) 2000, Michael Hope +; Copyright (C) 2021, Sebastian 'basxto' Riedel (sdcc@basxto.de) +; Copyright (c) 2021, Philipp Klaus Krause +; +; This library is free software; you can redistribute it and/or modify it +; under the terms of the GNU General Public License as published by the +; Free Software Foundation; either version 2, or (at your option) any +; later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this library; see the file COPYING. If not, write to the +; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, +; MA 02110-1301, USA. +; +; As a special exception, if you link this library with other files, +; some of which are compiled with SDCC, to produce an executable, +; this library does not by itself cause the resulting executable to +; be covered by the GNU General Public License. This exception does +; not however invalidate any other reasons why the executable file +; might be covered by the GNU General Public License. +;-------------------------------------------------------------------------- + + ;; Originally from GBDK by Pascal Felber. + .module divmod + .area _CODE +.globl __divsuchar +.globl __modsuchar +.globl __divuschar +.globl __moduschar +.globl __divschar +.globl __modschar +.globl __divsint +.globl __modsint +.globl __divuchar +.globl __moduchar +.globl __divuint +.globl __moduint + +__divsuchar: + ld c, a + ld b, #0 + + jp signexte + +__modsuchar: + ld c, a + ld b, #0 + + call signexte + + ld c, e + ld b, d + + ret + +__divuschar: + ld d, #0 + + ld c, a ; Sign extend + rlca + sbc a + ld b,a + + jp .div16 + +__moduschar: + ld e, a + ld d, #0 + + ld a,c ; Sign extend + rlca + sbc a + ld b,a + + call .div16 + + ld c, e + ld b, d + + ret + +__divschar: + ld c, a + + call .div8 + + ret + +__modschar: + ld c, a + + call .div8 + + ld c, e + ld b, d + + ret + +__divsint: + ld a, e + ld e, c + ld c, a + + ld a, d + ld d, b + ld b, a + + jp .div16 + +__modsint: + ld a, e + ld e, c + ld c, a + + ld a, d + ld d, b + ld b, a + + call .div16 + + ld c, e + ld b, d + + ret + + ;; Unsigned +__divuchar: + ld c, a + + call .divu8 + + ret + +__moduchar: + ld c, a + + call .divu8 + + ld c, e + ld b, d + + ret + +__divuint: + ld a, e + ld e, c + ld c, a + + ld a, d + ld d, b + ld b, a + + jp .divu16 + +__moduint: + ld a, e + ld e, c + ld c, a + + ld a, d + ld d, b + ld b, a + + call .divu16 + + ld c, e + ld b, d + + ret + +.div8:: +.mod8:: + ld a,c ; Sign extend + rlca + sbc a + ld b,a +signexte: + ld a, e ; Sign extend + rlca + sbc a + ld d, a + + ; Fall through to .div16 + + ;; 16-bit division + ;; + ;; Entry conditions + ;; BC = dividend + ;; DE = divisor + ;; + ;; Exit conditions + ;; BC = quotient + ;; DE = remainder + ;; If divisor is non-zero, carry=0 + ;; If divisor is 0, carry=1 and both quotient and remainder are 0 + ;; + ;; Register used: AF,BC,DE,HL +.div16:: +.mod16:: + ;; Determine sign of quotient by xor-ing high bytes of dividend + ;; and divisor. Quotient is positive if signs are the same, negative + ;; if signs are different + ;; Remainder has same sign as dividend + ld a,b ; Get high byte of dividend + push af ; Save as sign of remainder + xor d ; Xor with high byte of divisor + push af ; Save sign of quotient + + ;; Take absolute value of divisor + bit 7,d + jr Z,.chkde ; Jump if divisor is positive + sub a ; Substract divisor from 0 + sub e + ld e,a + sbc a ; Propagate borrow (A=0xFF if borrow) + sub d + ld d,a + ;; Take absolute value of dividend +.chkde: + bit 7,b + jr Z,.dodiv ; Jump if dividend is positive + sub a ; Substract dividend from 0 + sub c + ld c,a + sbc a ; Propagate borrow (A=0xFF if borrow) + sub b + ld b,a + ;; Divide absolute values +.dodiv: + call .divu16 + jr C,.exit ; Exit if divide by zero + ;; Negate quotient if it is negative + pop af ; recover sign of quotient + and #0x80 + jr Z,.dorem ; Jump if quotient is positive + sub a ; Substract quotient from 0 + sub c + ld c,a + sbc a ; Propagate borrow (A=0xFF if borrow) + sub b + ld b,a +.dorem: + ;; Negate remainder if it is negative + pop af ; recover sign of remainder + and #0x80 + ret Z ; Return if remainder is positive + sub a ; Substract remainder from 0 + sub e + ld e,a + sbc a ; Propagate remainder (A=0xFF if borrow) + sub d + ld d,a + ret +.exit: + pop af + pop af + ret + +.divu8:: +.modu8:: + ld b,#0x00 + ld d,b + ; Fall through to divu16 + +.divu16:: +.modu16:: + ;; Check for division by zero + ld a,e + or d + jr NZ,.divide ; Branch if divisor is non-zero + ld bc,#0x00 ; Divide by zero error + ld d,b + ld e,c + scf ; Set carry, invalid result + ret +.divide: + ld l,c ; L = low byte of dividend/quotient + ld h,b ; H = high byte of dividend/quotient + ld bc,#0x00 ; BC = remainder + or a ; Clear carry to start + ld a,#16 ; 16 bits in dividend +.dvloop: + ;; Shift next bit of quotient into bit 0 of dividend + ;; Shift next MSB of dividend into LSB of remainder + ;; BC holds both dividend and quotient. While we shift a bit from + ;; MSB of dividend, we shift next bit of quotient in from carry + ;; HL holds remainder + ;; Do a 32-bit left shift, shifting carry to L, L to H, + ;; H to C, C to B + push af ; save number of bits remaining + rl l ; Carry (next bit of quotient) to bit 0 + rl h ; Shift remaining bytes + rl c + rl b ; Clears carry since BC was 0 + ;; If remainder is >= divisor, next bit of quotient is 1. This + ;; bit goes to carry + push bc ; Save current remainder + ld a,c ; Substract divisor from remainder + sbc e + ld c,a + ld a,b + sbc d + ld b,a + ccf ; Complement borrow so 1 indicates a + ; successful substraction (this is the + ; next bit of quotient) + jr C,.drop ; Jump if remainder is >= dividend + pop bc ; Otherwise, restore remainder + pop af ; recover # bits remaining, carry flag destroyed + dec a + or a ; restore (clear) the carry flag + jr NZ,.dvloop + jr .nodrop +.drop: + pop af ; faster and smaller than 2x inc sp + pop af ; recover # bits remaining, carry flag destroyed + dec a + scf ; restore (set) the carry flag + jr NZ,.dvloop + jr .nodrop +.nodrop: + ;; Shift last carry bit into quotient + ld d,b ; DE = remainder + ld e,c + rl l ; Carry to L + ld c,l ; C = low byte of quotient + rl h + ld b,h ; B = high byte of quotient + or a ; Clear carry, valid result + ret + diff --git a/gbdk-lib/libc/asm/gbz80/itoa.s b/gbdk-lib/libc/asm/sm83/itoa.s diff --git a/gbdk-lib/libc/asm/gbz80/labs.s b/gbdk-lib/libc/asm/sm83/labs.s diff --git a/gbdk-lib/libc/asm/gbz80/ltoa.s b/gbdk-lib/libc/asm/sm83/ltoa.s diff --git a/gbdk-lib/libc/asm/sm83/memcpy.s b/gbdk-lib/libc/asm/sm83/memcpy.s @@ -0,0 +1,94 @@ +;-------------------------------------------------------------------------- +; memcpy.s +; +; Copies in groups of four. Algorithm is Duff's device. +; +; Copyright (c) 2021, Philipp Klaus Krause +; Copyright (c) 2022, Sebastian 'basxto' Riedel <sdcc@basxto.de> +; +; This library is free software; you can redistribute it and/or modify it +; under the terms of the GNU General Public License as published by the +; Free Software Foundation; either version 2, or (at your option) any +; later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this library; see the file COPYING. If not, write to the +; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, +; MA 02110-1301, USA. +; +; As a special exception, if you link this library with other files, +; some of which are compiled with SDCC, to produce an executable, +; this library does not by itself cause the resulting executable to +; be covered by the GNU General Public License. This exception does +; not however invalidate any other reasons why the executable file +; might be covered by the GNU General Public License. +;-------------------------------------------------------------------------- + + .area _CODE + + .globl _memcpy + .globl ___memcpy + + ; gets called by memmove for (s >= d) + ; bigger than the old algorithm but faster for n>=5 +_memcpy:: +___memcpy:: + ;dest in de + ;src in bc + ;n in sp+2,sp+3 + push de + ldhl sp, #5 + ld a, (hl-) + ld l, (hl) + ld h, b + ld b, a + ld a, l + ld l, c + srl b + rra + ld c, a + ;dest in de (backup in sp+0,sp+1) + ;src in hl + ;n/2 in bc + ;LSB of bc in carry + jr nc, skip_one + ld a, (hl+) + ld (de), a + inc de +skip_one: + ;n/2 in bc + ;shift second LSB to carry + srl b + rr c + ;n/4 in bc + inc b + inc c + jr nc, test + jr copy_two +.irp idx,copy_four,copy_two + idx: + .rept 2 + ld a, (hl+) + ld (de), a + inc de + .endm +.endm +test: +.irp idx,c,b + dec idx + jr nz, copy_four +.endm + +end: + ;restore dest + pop bc + ;get return address + pop hl + ;throw away n + pop af + jp (hl) + diff --git a/gbdk-lib/libc/asm/sm83/mul.s b/gbdk-lib/libc/asm/sm83/mul.s @@ -0,0 +1,158 @@ +;-------------------------------------------------------------------------- +; mul.s +; +; Copyright (C) 2000, Michael Hope +; Copyright (C) 2021-2022, Sebastian 'basxto' Riedel (sdcc@basxto.de) +; Copyright (c) 2021, Philipp Klaus Krause +; +; This library is free software; you can redistribute it and/or modify it +; under the terms of the GNU General Public License as published by the +; Free Software Foundation; either version 2, or (at your option) any +; later version. +; +; This library is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +; GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License +; along with this library; see the file COPYING. If not, write to the +; Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, +; MA 02110-1301, USA. +; +; As a special exception, if you link this library with other files, +; some of which are compiled with SDCC, to produce an executable, +; this library does not by itself cause the resulting executable to +; be covered by the GNU General Public License. This exception does +; not however invalidate any other reasons why the executable file +; might be covered by the GNU General Public License. +;-------------------------------------------------------------------------- + + ;; Originally from GBDK by Pascal Felber. + + .module mul + .area _CODE + +.globl __mulsuchar +.globl __muluschar +.globl __mulschar +.globl __muluchar +.globl __mulint + +; operands with different sign + +__mulsuchar: + ld c, a + jr signexte + +__muluschar: + ld c, e + ld e, a + +signexte: + ld a,e + rla + sbc a,a + ld d,a + + xor a + jr .mul8 + +__mulschar: + ; Sign-extend before going in. + ld c,a + + rla + sbc a,a + ld b,a + + ld a,e + rla + sbc a,a + ld d,a + +__mulint: + ;; 16-bit multiplication + ;; + ;; Entry conditions + ;; BC = multiplicand + ;; DE = multiplier + ;; + ;; Exit conditions + ;; BC = less significant word of product + ;; + ;; Register used: AF,BC,DE,HL +.mul16: + ;; Let the smaller number loop + ld a,b + cp a,d + jr c, keep + ;; d <= b + ld a, e + ld e, c + ld c, a + ld a, d + ld d, b + ld b, a +keep: + ;; Optimise for the case when this side has 8 bits of data or + ;; less. This is often the case with support address calls. + or a + jp Z, .mul8 + + ld l,#0 + ld b,#16 +loop16: + ;; Taken from z88dk, which originally borrowed from the + ;; Spectrum rom. + add hl,hl + rl c + rla ;DLE 27/11/98 + jr NC,skip16 + add hl,de +skip16: + dec b + jr NZ,loop16 + + ;; Return in bc + ld c,l + ld b,h + + ret + +__muluchar: + ld c, a + xor a + ;; Clear the top + ld d, a + + ;; Version that uses an 8bit multiplicand + ;; + ;; Entry conditions + ;; C = multiplicand + ;; DE = multiplier + ;; A = 0 + ;; + ;; Exit conditions + ;; BC = less significant word of product + ;; + ;; Register used: AF,BC,DE,HL +.mul8: + ld l,a + ld b,#8 + ld a,c +loop8: + add hl,hl + rla + jr NC,skip8 + add hl,de +skip8: + dec b + jr NZ,loop8 + + ;; Return in bc + ld c,l + ld b,h + + ret + diff --git a/gbdk-lib/libc/asm/gbz80/rand.s b/gbdk-lib/libc/asm/sm83/rand.s diff --git a/gbdk-lib/libc/asm/gbz80/reverse.s b/gbdk-lib/libc/asm/sm83/reverse.s diff --git a/gbdk-lib/libc/asm/gbz80/setjmp.s b/gbdk-lib/libc/asm/sm83/setjmp.s diff --git a/gbdk-lib/libc/asm/gbz80/shift.s b/gbdk-lib/libc/asm/sm83/shift.s diff --git a/gbdk-lib/libc/asm/gbz80/strlen.s b/gbdk-lib/libc/asm/sm83/strlen.s diff --git a/gbdk-lib/libc/asm/z80/divmixed.s b/gbdk-lib/libc/asm/z80/divmixed.s @@ -1,7 +1,7 @@ ;-------------------------------------------------------------------------- ; divmixed.s ; -; Copyright (C) 2010, Philipp Klaus Krause +; Copyright (C) 2010-2021, Philipp Klaus Krause ; ; This library is free software; you can redistribute it and/or modify it ; under the terms of the GNU General Public License as published by the @@ -30,27 +30,18 @@ .globl __divuschar __divsuchar: - ld hl, #2+1 - add hl, sp - - ld e, (hl) - dec hl - ld l, (hl) + ld e, l + ld l, a ld h, #0 jp __div_signexte __divuschar: - ld hl, #2+1 - ld d, h - add hl, sp - - ld e, (hl) - dec hl - ld l, (hl) + ld e, l + ld d, #0 + ld l, a - ld a, l ; Sign extend - rlca + rlca ; Sign extend sbc a, a ld h, a diff --git a/gbdk-lib/libc/asm/z80/divsigned.s b/gbdk-lib/libc/asm/z80/divsigned.s @@ -1,7 +1,7 @@ ;-------------------------------------------------------------------------- ; divsigned.s ; -; Copyright (C) 2000-2010, Michael Hope, Philipp Klaus Krause +; Copyright (C) 2000-2021, Michael Hope, Philipp Klaus Krause ; ; This library is free software; you can redistribute it and/or modify it ; under the terms of the GNU General Public License as published by the @@ -31,23 +31,9 @@ .globl __divsint .globl __divschar -__divsint: - pop af - pop hl - pop de - push de - push hl - push af - - jp __div16 - __divschar: - ld hl, #2+1 - add hl, sp - - ld e, (hl) - dec hl - ld l, (hl) + ld e, l + ld l, a __div8:: ld a, l ; Sign extend @@ -55,11 +41,11 @@ __div8:: sbc a,a ld h, a __div_signexte:: - ld a, e ; Sign extend - rlca - sbc a,a - ld d, a - ; Fall through to __div16 + ld a, e ; Sign extend + rlca + sbc a, a + ld d, a + ; Fall through to __div16 ;; signed 16-bit division ;; @@ -68,10 +54,11 @@ __div_signexte:: ;; DE = divisor ;; ;; Exit conditions - ;; HL = quotient - ;; DE = remainder + ;; DE = quotient + ;; HL = remainder ;; ;; Register used: AF,B,DE,HL +__divsint: __div16:: ;; Determine sign of quotient by xor-ing high bytes of dividend ;; and divisor. Quotient is positive if signs are the same, negative @@ -114,24 +101,24 @@ __div16:: ret NC ; Jump if quotient is positive ld b, a sub a, a ; Subtract quotient from 0 - sub a, l - ld l, a + sub a, e + ld e, a sbc a, a ; Propagate borrow (A=0xFF if borrow) - sub a, h - ld h, a + sub a, d + ld d, a ld a, b ret __get_remainder:: - ; Negate remainder if it is negative and move it into hl + ; Negate remainder if it is negative. rla - ex de, hl + ex de, hl ret NC ; Return if remainder is positive - sub a, a ; Subtract remainder from 0 - sub a, l - ld l, a - sbc a, a ; Propagate remainder (A=0xFF if borrow) - sub a, h - ld h, a + sub a, a ; Subtract quotient from 0 + sub a, e + ld e, a + sbc a, a ; Propagate borrow (A=0xFF if borrow) + sub a, d + ld d, a ret diff --git a/gbdk-lib/libc/asm/z80/divunsigned.s b/gbdk-lib/libc/asm/z80/divunsigned.s @@ -1,7 +1,7 @@ ;-------------------------------------------------------------------------- ; divunsigned.s ; -; Copyright (C) 2000-2012, Michael Hope, Philipp Klaus Krause, Marco Bodrato +; Copyright (C) 2000-2021, Michael Hope, Philipp Klaus Krause, Marco Bodrato ; ; This library is free software; you can redistribute it and/or modify it ; under the terms of the GNU General Public License as published by the @@ -33,23 +33,10 @@ .globl __divuint .globl __divuchar -__divuint: - pop af - pop hl - pop de - push de - push hl - push af - - jr __divu16 __divuchar: - ld hl,#2+1 - add hl,sp - - ld e,(hl) - dec hl - ld l,(hl) + ld e, l + ld l, a ;; Fall through __divu8:: @@ -64,12 +51,13 @@ __divu8:: ;; DE = divisor ;; ;; Exit conditions - ;; HL = quotient - ;; DE = remainder + ;; DE = quotient + ;; HL = remainder ;; carry = 0 ;; If divisor is 0, quotient is set to "infinity", i.e HL = 0xFFFF. ;; ;; Register used: AF,B,DE,HL +__divuint: __divu16:: ;; Two algorithms: one assumes divisor <2^7, the second ;; assumes divisor >=2^7; choose the applicable one. @@ -105,6 +93,7 @@ __divu16:: ;; Carry now contains the same value it contained before ;; entering .dvloop7[*]: "0" = valid result. ld e,a ; DE = remainder, HL = quotient + ex de, hl ret .morethan7bits: @@ -138,6 +127,5 @@ __divu16:: ;; Carry now contains "0" = valid result. ld d,b ld e,a ; DE = quotient, HL = remainder - ex de,hl ; HL = quotient, DE = remainder ret diff --git a/gbdk-lib/libc/asm/z80/memcpy.s b/gbdk-lib/libc/asm/z80/memcpy.s @@ -2,6 +2,7 @@ ; memcpy.s ; ; Copyright (C) 2020, Sergey Belyashov +; Copyright (c) 2021, Philipp Klaus Krause ; ; This library is free software; you can redistribute it and/or modify it ; under the terms of the GNU General Public License as published by the @@ -34,20 +35,15 @@ ; The Z80 has the ldir instruction, which is perfect for implementing memcpy(). _memcpy: ___memcpy: - pop af - pop hl ;return value expected to be in HL, so pop dst to HL - pop de + ex de, hl + pop iy pop bc - push bc - push de - push hl - push af ld a, c or a, b - ret Z - push hl - ex de, hl + jr Z, end + push de ldir - pop hl - ret + pop de +end: + jp (iy) diff --git a/gbdk-lib/libc/asm/z80/modmixed.s b/gbdk-lib/libc/asm/z80/modmixed.s @@ -1,7 +1,7 @@ ;-------------------------------------------------------------------------- ; modmixed.s ; -; Copyright (C) 2010, Philipp Klaus Krause +; Copyright (C) 2010-2021, Philipp Klaus Krause ; ; This library is free software; you can redistribute it and/or modify it ; under the terms of the GNU General Public License as published by the @@ -30,31 +30,22 @@ .globl __moduschar __modsuchar: - ld hl,#2+1 - add hl,sp - - ld e,(hl) - dec hl - ld l,(hl) - ld h,#0 + ld e, l + ld l, a + ld h, #0 call __div_signexte jp __get_remainder __moduschar: - ld hl,#2+1 - ld d, h - add hl,sp - - ld e,(hl) - dec hl - ld l,(hl) - - ld a,l ; Sign extend - rlca - sbc a, a - ld h, a + ld e, l + ld d, #0 + ld l, a + + rlca ; Sign extend + sbc a, a + ld h, a call __div16 diff --git a/gbdk-lib/libc/asm/z80/modsigned.s b/gbdk-lib/libc/asm/z80/modsigned.s @@ -1,7 +1,7 @@ ;-------------------------------------------------------------------------- ; modsigned.s ; -; Copyright (C) 2009, Philipp Klaus Krause +; Copyright (C) 2009-2021, Philipp Klaus Krause ; ; This library is free software; you can redistribute it and/or modify it ; under the terms of the GNU General Public License as published by the @@ -32,26 +32,15 @@ .globl __modsint __modschar: - ld hl,#2+1 - add hl,sp + ld e, l + ld l, a - ld e,(hl) - dec hl - ld l,(hl) + call __div8 - call __div8 - - jp __get_remainder + jp __get_remainder __modsint: - pop af - pop hl - pop de - push de - push hl - push af - - call __div16 + call __div16 - jp __get_remainder + jp __get_remainder diff --git a/gbdk-lib/libc/asm/z80/modunsigned.s b/gbdk-lib/libc/asm/z80/modunsigned.s @@ -32,30 +32,15 @@ .globl __moduint __moduchar: - ld hl,#2+1 - add hl,sp + ld e, l + ld l, a - ld e,(hl) - dec hl - ld l,(hl) - - call __divu8 - - ex de,hl - - ret + call __divu8 + ex de, hl + ret __moduint: - pop af - pop hl - pop de - push de - push hl - push af - - call __divu16 - - ex de,hl - - ret + call __divu16 + ex de, hl + ret diff --git a/gbdk-lib/libc/asm/z80/mul.s b/gbdk-lib/libc/asm/z80/mul.s @@ -1,7 +1,8 @@ ;-------------------------------------------------------------------------- -; mulchar.s +; mul.s ; ; Copyright (C) 2000, Michael Hope +; Copyright (C) 2021, Philipp Klaus Krause ; ; This library is free software; you can redistribute it and/or modify it ; under the terms of the GNU General Public License as published by the @@ -31,12 +32,8 @@ .globl __mulint __mulint: - pop af - pop bc - pop de - push de - push bc - push af + ld c, l + ld b, h ;; 16-bit multiplication ;; @@ -45,7 +42,7 @@ __mulint: ;; de = multiplier ;; ;; Exit conditions - ;; hl = less significant word of product + ;; de = less significant word of product ;; ;; Register used: AF,BC,DE,HL __mul16:: @@ -70,5 +67,6 @@ __mul16:: add hl,de 3$: djnz 1$ + ex de, hl ret diff --git a/gbdk-lib/libc/asm/z80/mulchar.s b/gbdk-lib/libc/asm/z80/mulchar.s @@ -1,7 +1,7 @@ ;-------------------------------------------------------------------------- ; mulchar.s ; -; Copyright (c) 2017, Philipp Klaus Krause +; Copyright (c) 2017-2021, Philipp Klaus Krause ; ; This library is free software; you can redistribute it and/or modify it ; under the terms of the GNU General Public License as published by the @@ -36,44 +36,33 @@ ; operands have different sign -__mulsuchar: - ld hl,#2+1 - ld b, h - add hl,sp +__muluschar: + ld e, a + ld c, l + ld b, #0 - ld e,(hl) - dec hl - ld c,(hl) jr signexte -__muluschar: - ld hl,#2 - ld b, h - add hl,sp +__mulsuchar: + ld c, a + ld b, #0 + ld e, l - ld e,(hl) - inc hl - ld c,(hl) jr signexte __mulschar: - ld hl,#2+1 - add hl,sp - - ld e,(hl) - dec hl - ld c,(hl) + ld e, l + ld c, a ;; Need to sign extend before going in. - ld a,c rla - sbc a,a - ld b,a + sbc a, a + ld b, a signexte: - ld a,e + ld a, e rla - sbc a,a - ld d,a + sbc a, a + ld d, a jp __mul16 diff --git a/gbdk-lib/libc/atomic_flag_clear.c b/gbdk-lib/libc/atomic_flag_clear.c @@ -30,7 +30,7 @@ void atomic_flag_clear(volatile atomic_flag *object) { -#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_ez80_z80) || defined(__SDCC_gbz80) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) || defined(__SDCC_stm8) || defined(__SDCC_hc08) || defined(__SDCC_s08) +#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_ez80_z80) || defined(__SDCC_sm83) || defined(__SDCC_r2k) || defined(__SDCC_r3ka) || defined(__SDCC_stm8) || defined(__SDCC_hc08) || defined(__SDCC_s08) object->flag = 1; #elif defined(__SDCC_mcs51) object->flag = 0; diff --git a/gbdk-lib/libc/rules-rgbds.mk b/gbdk-lib/libc/rules-rgbds.mk @@ -1,30 +0,0 @@ -ifeq ($(ASM),rgbds) -CFLAGS += --asm=rgbds -# Override the default rule -%.o: %.s - -$(LIB): pre $(OBJ) $(CRT0) - mkdir -p $(BUILD) -ifneq ($(LIB_APPEND), 1) - rm -f $(LIB) -endif - xlib $(LIB) a $(OBJ) -ifdef CRT0 - cp -f $(CRT0) $(BUILD) -endif - -pre: set-model - -astorgb.pl global.s > global.asm - -%.o: %.c - $(CC) $(CFLAGS) -c $< - -%.asm: %.s - astorgb.pl $< > $@ - -%.o: %.rasm - rgbasm -o$@ $< - -%.o: %.asm - rgbasm -o$@ $< - diff --git a/gbdk-lib/libc/targets/gbz80/ap/Makefile b/gbdk-lib/libc/targets/gbz80/ap/Makefile @@ -1,53 +0,0 @@ -# GB specific Makefile - -TOPDIR = ../../../.. - -THIS = ap -PORT = gbz80 - -CSRC = crlf.c digits.c gprint.c gprintf.c gprintln.c gprintn.c - -ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ - cpy_data.s \ - drawing.s drawing_isr.s color.s \ - f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ - get_bk_t.s get_data.s get_tile.s \ - get_wi_t.s get_xy_t.s \ - get_addr.s \ - hiramcpy.s init_tt.s input.s \ - pad.s \ - serial.s set_bk_t.s set_tile.s \ - set_data.s set_prop.s set_spr.s set_wi_t.s set_xy_t.s \ - set_1bit_data.s \ - sgb.s font.s font_color.s delay.s \ - emu_debug.s emu_debug_printf.s \ - nowait.s far_ptr.s \ - lcd.s joy.s tim.s tim_nested.s tim_common.s \ - crash_handler.s \ - ___sdcc_bcall_ehl.s ___sdcc_bcall.s \ - mv_spr.s \ - pad_ex.s \ - mode.s clock.s \ - get_t.s set_t.s init_vram.s \ - fill_rect.s fill_rect_bk.s fill_rect_wi.s \ - metasprites.s metasprites_flip.s metasprites_hide.s metasprites_hide_spr.s \ - set_tile_submap.s set_win_tile_submap.s \ - gb_decompress.s gb_decompress_tiles.s \ - rle_decompress.s \ - heap.s \ - crt0.s - -ifeq ($(ASM),asxxxx) -ASSRC += sfr.s -endif -ifeq ($(ASM),rgbds) -ASSRC += stubs.s -endif - -CRT0 = crt0.s - -include $(TOPDIR)/Makefile.common - -AS = $(AS_GBZ80) - -include ../../../Makefile.platform diff --git a/gbdk-lib/libc/targets/gbz80/ap/global.s b/gbdk-lib/libc/targets/gbz80/ap/global.s @@ -1,536 +0,0 @@ - .NEAR_CALLS = 1 ; <near_calls> - tag so that sed can change this - - ;; Changed by astorgb.pl to 1 - __RGBDS__ = 0 - - _VRAM = 0x8000 ; $8000->$9FFF - _VRAM8000 = 0x8000 - _VRAM8800 = 0x8800 - _VRAM9000 = 0x9000 - _SCRN0 = 0x9800 ; $9800->$9BFF - _SCRN1 = 0x9C00 ; $9C00->$9FFF - _SRAM = 0xA000 ; $A000->$BFFF - _RAM = 0xC000 ; $C000->$CFFF / $C000->$DFFF - _RAMBANK = 0xD000 ; $D000->$DFFF - _OAMRAM = 0xFE00 ; $FE00->$FE9F - _IO = 0xFF00 ; $FF00->$FF7F,$FFFF - _AUD3WAVERAM = 0xFF30 ; $FF30->$FF3F - _HRAM = 0xFF80 ; $FF80->$FFFE - - ;; MBC Equates - - .MBC1_ROM_PAGE = 0x2000 ; Address to write to for MBC1 switching - .MBC_ROM_PAGE = 0x2000 ; Default platform MBC rom switching address - - rRAMG = 0x0000 ; $0000->$1fff - rROMB0 = 0x2000 ; $2000->$2fff - rROMB1 = 0x3000 ; $3000->$3fff - If more than 256 ROM banks are present. - rRAMB = 0x4000 ; $4000->$5fff - Bit 3 enables rumble (if present) - - ;; Keypad - .START = 0x80 - .SELECT = 0x40 - .B = 0x20 - .A = 0x10 - .DOWN = 0x08 - .UP = 0x04 - .LEFT = 0x02 - .RIGHT = 0x01 - - .P14 = 0x10 - .P15 = 0x20 - - ;; Screen dimensions - .MAXCURSPOSX = 0x13 ; In tiles - .MAXCURSPOSY = 0x11 - - .SCREENWIDTH = 0xA0 - .SCREENHEIGHT = 0x90 - .MINWNDPOSX = 0x07 - .MINWNDPOSY = 0x00 - .MAXWNDPOSX = 0xA6 - .MAXWNDPOSY = 0x8F - - ;; Hardware registers - - .P1 = 0x00 ; Joystick: 1.1.P15.P14.P13.P12.P11.P10 - rP1 = 0xFF00 - - P1F_5 = 0b00100000 ; P15 out port, set to 0 to get buttons - P1F_4 = 0b00010000 ; P14 out port, set to 0 to get dpad - P1F_3 = 0b00001000 ; P13 in port - P1F_2 = 0b00000100 ; P12 in port - P1F_1 = 0b00000010 ; P11 in port - P1F_0 = 0b00000001 ; P10 in port - - P1F_GET_DPAD = 0b00100000 - P1F_GET_BTN = 0b00010000 - P1F_GET_NONE = 0b00110000 - - .SB = 0x01 ; Serial IO data buffer - rSB = 0xFF01 - - .SC = 0x02 ; Serial IO control register - rSC = 0xFF02 - - .DIV = 0x04 ; Divider register - rDIV = 0xFF04 - - .TIMA = 0x05 ; Timer counter - rTIMA = 0xFF05 - - .TMA = 0x06 ; Timer modulo - rTMA = 0xFF06 - - .TAC = 0x07 ; Timer control - rTAC = 0xFF07 - - TACF_START = 0b00000100 - TACF_STOP = 0b00000000 - TACF_4KHZ = 0b00000000 - TACF_16KHZ = 0b00000011 - TACF_65KHZ = 0b00000010 - TACF_262KHZ = 0b00000001 - - .IF = 0x0F ; Interrupt flags: 0.0.0.JST.SIO.TIM.LCD.VBL - rIF = 0xFF0F - - .NR10 = 0x10 ; Sound register - rNR10 = 0xFF10 - rAUD1SWEEP = 0xFF10 - - AUD1SWEEP_UP = 0b00000000 - AUD1SWEEP_DOWN = 0b00001000 - - .NR11 = 0x11 ; Sound register - rNR11 = 0xFF11 - rAUD1LEN = 0xFF11 - - .NR12 = 0x12 ; Sound register - rNR12 = 0xFF12 - rAUD1ENV = 0xFF12 - - .NR13 = 0x13 ; Sound register - rNR13 = 0xFF13 - rAUD1LOW = 0xFF13 - - .NR14 = 0x14 ; Sound register - rNR14 = 0xFF14 - rAUD1HIGH = 0xFF14 - - .NR21 = 0x16 ; Sound register - rNR21 = 0xFF16 - rAUD2LEN = 0xFF16 - - .NR22 = 0x17 ; Sound register - rNR22 = 0xFF17 - rAUD2ENV = 0xFF17 - - .NR23 = 0x18 ; Sound register - rNR23 = 0xFF18 - rAUD2LOW = 0xFF18 - - .NR24 = 0x19 ; Sound register - rNR24 = 0xFF19 - rAUD2HIGH = 0xFF19 - - .NR30 = 0x1A ; Sound register - rNR30 = 0xFF1A - rAUD3ENA = 0xFF1A - - .NR31 = 0x1B ; Sound register - rNR31 = 0xFF1B - rAUD3LEN = 0xFF1B - - .NR32 = 0x1C ; Sound register - rNR32 = 0xFF1C - rAUD3LEVEL = 0xFF1C - - .NR33 = 0x1D ; Sound register - rNR33 = 0xFF1D - rAUD3LOW = 0xFF1D - - .NR34 = 0x1E ; Sound register - rNR34 = 0xFF1E - rAUD3HIGH = 0xFF1E - - .NR41 = 0x20 ; Sound register - rNR41 = 0xFF20 - rAUD4LEN = 0xFF20 - - .NR42 = 0x21 ; Sound register - rNR42 = 0xFF21 - rAUD4ENV = 0xFF21 - - .NR43 = 0x22 ; Sound register - rNR43 = 0xFF22 - rAUD4POLY = 0xFF22 - - .NR44 = 0x23 ; Sound register - rNR44 = 0xFF23 - rAUD4GO = 0xFF23 - - .NR50 = 0x24 ; Sound register - rNR50 = 0xFF24 - rAUDVOL = 0xFF24 - - AUDVOL_VIN_LEFT = 0b10000000 ; SO2 - AUDVOL_VIN_RIGHT = 0b00001000 ; SO1 - - .NR51 = 0x25 ; Sound register - rNR51 = 0xFF25 - rAUDTERM = 0xFF25 - - AUDTERM_4_LEFT = 0b10000000 - AUDTERM_3_LEFT = 0b01000000 - AUDTERM_2_LEFT = 0b00100000 - AUDTERM_1_LEFT = 0b00010000 - AUDTERM_4_RIGHT = 0b00001000 - AUDTERM_3_RIGHT = 0b00000100 - AUDTERM_2_RIGHT = 0b00000010 - AUDTERM_1_RIGHT = 0b00000001 - - .NR52 = 0x26 ; Sound register - rNR52 = 0xFF26 - rAUDENA = 0xFF26 - - AUDENA_ON = 0b10000000 - AUDENA_OFF = 0b00000000 ; sets all audio regs to 0! - - .LCDC = 0x4E ; LCD control - rLCDC = 0xFF4E - - LCDCF_OFF = 0b00000000 ; LCD Control Operation - LCDCF_ON = 0b00000001 ; LCD Control Operation - LCDCF_WIN9800 = 0b00000000 ; Window Tile Map Display Select - LCDCF_WIN9C00 = 0b00000010 ; Window Tile Map Display Select - LCDCF_WINOFF = 0b00000000 ; Window Display - LCDCF_WINON = 0b00000100 ; Window Display - LCDCF_BG8800 = 0b00000000 ; BG & Window Tile Data Select - LCDCF_BG8000 = 0b00001000 ; BG & Window Tile Data Select - LCDCF_BG9800 = 0b00000000 ; BG Tile Map Display Select - LCDCF_BG9C00 = 0b00010000 ; BG Tile Map Display Select - LCDCF_OBJ8 = 0b00000000 ; OBJ Construction - LCDCF_OBJ16 = 0b00100000 ; OBJ Construction - LCDCF_OBJOFF = 0b00000000 ; OBJ Display - LCDCF_OBJON = 0b01000000 ; OBJ Display - LCDCF_BGOFF = 0b00000000 ; BG Display - LCDCF_BGON = 0b10000000 ; BG Display - LCDCF_B_ON = 0 - LCDCF_B_WIN9C00 = 1 - LCDCF_B_WINON = 2 - LCDCF_B_BG8000 = 3 - LCDCF_B_BG9C00 = 4 - LCDCF_B_OBJ16 = 5 - LCDCF_B_OBJON = 6 - LCDCF_B_BGON = 7 - - .STAT = 0x41 ; LCD status - rSTAT = 0xFF41 - - STATF_LYC = 0b00000010 ; LYC=LY Coincidence (Selectable) - STATF_MODE10 = 0b00000100 ; Mode 10 - STATF_MODE01 = 0b00001000 ; Mode 01 (V-Blank) - STATF_MODE00 = 0b00010000 ; Mode 00 (H-Blank) - STATF_LYCF = 0b00100000 ; Coincidence Flag - STATF_HBL = 0b00000000 ; H-Blank - STATF_VBL = 0b10000000 ; V-Blank - STATF_OAM = 0b01000000 ; OAM-RAM is used by system - STATF_LCD = 0b11000000 ; Both OAM and VRAM used by system - STATF_BUSY = 0b01000000 ; When set, VRAM access is unsafe - STATF_B_LYC = 1 - STATF_B_MODE10 = 2 - STATF_B_MODE01 = 3 - STATF_B_MODE00 = 4 - STATF_B_LYCF = 5 - STATF_B_VBL = 7 - STATF_B_OAM = 6 - STATF_B_BUSY = 6 - - .SCY = 0x42 ; Scroll Y - rSCY = 0xFF42 - - .SCX = 0x43 ; Scroll X - rSCX = 0xFF43 - - .LY = 0x44 ; LCDC Y-coordinate - rLY = 0xFF44 - - .LYC = 0x45 ; LY compare - rLYC = 0xFF45 - - .DMA = 0x46 ; DMA transfer - rDMA = 0xFF46 - - .BGP = 0x47 ; BG palette data - rBGP = 0xFF47 - - .OBP0 = 0x48 ; OBJ palette 0 data - rOBP0 = 0xFF48 - - .OBP1 = 0x49 ; OBJ palette 1 data - rOBP1 = 0xFF49 - - .WY = 0x4A ; Window Y coordinate - rWY = 0xFF4A - - .WX = 0x4B ; Window X coordinate - rWX = 0xFF4B - - .KEY1 = 0x4D ; CPU speed - rKEY1 = 0xFF4D - rSPD = 0xFF4D - - KEY1F_DBLSPEED = 0b10000000 ; 0=Normal Speed, 1=Double Speed (R) - KEY1F_PREPARE = 0b00000001 ; 0=No, 1=Prepare (R/W) - - .VBK = 0x4F ; VRAM bank - rVBK = 0xFF4F - - .HDMA1 = 0x51 ; DMA control 1 - rHDMA1 = 0xFF51 - - .HDMA2 = 0x52 ; DMA control 2 - rHDMA2 = 0xFF52 - - .HDMA3 = 0x53 ; DMA control 3 - rHDMA3 = 0xFF53 - - .HDMA4 = 0x54 ; DMA control 4 - rHDMA4 = 0xFF54 - - .HDMA5 = 0x55 ; DMA control 5 - rHDMA5 = 0xFF55 - - HDMA5F_MODE_GP = 0b00000000 ; General Purpose DMA (W) - HDMA5F_MODE_HBL = 0b10000000 ; HBlank DMA (W) - - HDMA5F_BUSY = 0b10000000 ; 0=Busy (DMA still in progress), 1=Transfer complete (R) - - .RP = 0x56 ; IR port - rRP = 0xFF56 - - RPF_ENREAD = 0b11000000 - RPF_DATAIN = 0b00000010 ; 0=Receiving IR Signal, 1=Normal - RPF_WRITE_HI = 0b00000001 - RPF_WRITE_LO = 0b00000000 - - .BCPS = 0x68 ; BG color palette specification - rBCPS = 0xFF68 - - BCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) - - .BCPD = 0x69 ; BG color palette data - rBCPD = 0xFF69 - - .OCPS = 0x6A ; OBJ color palette specification - rOCPS = 0xFF6A - - OCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) - - .OCPD = 0x6B ; OBJ color palette data - rOCPD = 0xFF6B - - .SVBK = 0x70 ; WRAM bank - rSVBK = 0xFF70 - rSMBK = 0xFF70 - - rPCM12 = 0xFF76 - - rPCM34 = 0xFF77 - - .IE = 0xFF ; Interrupt enable - rIE = 0xFFFF - - .VBL_IFLAG = 0x01 - .LCD_IFLAG = 0x02 - .TIM_IFLAG = 0x04 - .SIO_IFLAG = 0x08 - .JOY_IFLAG = 0x10 - - IEF_HILO = 0b00010000 ; Transition from High to Low of Pin number P10-P13 - IEF_SERIAL = 0b00001000 ; Serial I/O transfer end - IEF_TIMER = 0b00000100 ; Timer Overflow - IEF_STAT = 0b00000010 ; STAT - IEF_VBLANK = 0b00000001 ; V-Blank - - ;; Flags common to multiple sound channels - - AUDLEN_DUTY_12_5 = 0b00000000 ; 12.5% - AUDLEN_DUTY_25 = 0b01000000 ; 25% - AUDLEN_DUTY_50 = 0b10000000 ; 50% - AUDLEN_DUTY_75 = 0b11000000 ; 75% - - AUDENV_UP = 0b00001000 - AUDENV_DOWN = 0b00000000 - - AUDHIGH_RESTART = 0b10000000 - AUDHIGH_LENGTH_ON = 0b01000000 - AUDHIGH_LENGTH_OFF = 0b00000000 - - ;; OAM related constants - - OAM_COUNT = 40 ; number of OAM entries in OAM RAM - - OAMF_PRI = 0b10000000 ; Priority - OAMF_YFLIP = 0b01000000 ; Y flip - OAMF_XFLIP = 0b00100000 ; X flip - OAMF_PAL0 = 0b00000000 ; Palette number; 0,1 (DMG) - OAMF_PAL1 = 0b00010000 ; Palette number; 0,1 (DMG) - OAMF_BANK0 = 0b00000000 ; Bank number; 0,1 (GBC) - OAMF_BANK1 = 0b00001000 ; Bank number; 0,1 (GBC) - - OAMF_PALMASK = 0b00000111 ; Palette (GBC) - - OAMB_PRI = 7 ; Priority - OAMB_YFLIP = 6 ; Y flip - OAMB_XFLIP = 5 ; X flip - OAMB_PAL1 = 4 ; Palette number; 0,1 (DMG) - OAMB_BANK1 = 3 ; Bank number; 0,1 (GBC) - - ;; SGB packets - .PAL_01 = 0x00 - .PAL_23 = 0x01 - .PAL_03 = 0x02 - .PAL_12 = 0x03 - .ATTR_BLK = 0x04 - .ATTR_LIN = 0x05 - .ATTR_DIV = 0x06 - .ATTR_CHR = 0x07 - .SOUND = 0x08 - .SOU_TRN = 0x09 - .PAL_SET = 0x0A - .PAL_TRN = 0x0B - .ATRC_EN = 0x0C - .TEST_EN = 0x0D - .ICON_EN = 0x0E - .DATA_SND = 0x0F - .DATA_TRN = 0x10 - .MLT_REQ = 0x11 - .JUMP = 0x12 - .CHR_TRN = 0x13 - .PCT_TRN = 0x14 - .ATTR_TRN = 0x15 - .ATTR_SET = 0x16 - .MASK_EN = 0x17 - .OBJ_TRN = 0x18 - - ;; CPU detection - .DMG_TYPE = 0x01 ; Original GB or Super GB - .MGB_TYPE = 0xFF ; Pocket GB or Super GB 2 - .CGB_TYPE = 0x11 ; Color GB - - ;; GBDK library screen modes - - .G_MODE = 0x01 ; Graphic mode - .T_MODE = 0x02 ; Text mode (bit 2) - .T_MODE_OUT = 0x02 ; Text mode output only - .T_MODE_INOUT = 0x03 ; Text mode with input - .M_NO_SCROLL = 0x04 ; Disables scrolling of the screen in text mode - .M_NO_INTERP = 0x08 ; Disables special character interpretation - - ;; Status codes for IO - .IO_IDLE = 0x00 - .IO_SENDING = 0x01 - .IO_RECEIVING = 0x02 - .IO_ERROR = 0x04 - - ;; Type of IO data - .DT_IDLE = 0x66 - .DT_RECEIVING = 0x55 - - ;; Table of routines for modes - .MODE_TABLE = 0x01E0 - - ;; C related - ;; Overheap of a banked call. Used for parameters - ;; = ret + real ret + bank - - .if .NEAR_CALLS - .BANKOV = 2 - - .else - .BANKOV = 6 - - .endif - - .globl __current_bank - .globl __shadow_OAM_base - - ;; Global variables - .globl .mode - - .globl __cpu - .globl __is_GBA - - ;; Global routines -; .globl .set_mode ;; don't link mode.o by default - - .globl .reset - - .globl .display_off - - .globl .wait_vbl_done - - ;; Interrupt routines - .globl .add_VBL -; .globl .add_LCD ;; don't link LCD.o by default -; .globl .add_TIM ;; don't link TIM.o by default -; .globl .add_SIO ;; don't link serial.o by default -; .globl .add_JOY ;; don't link JOY.o by default - - ;; Symbols defined at link time - .globl .STACK - .globl _shadow_OAM - .globl .refresh_OAM - - ;; Main user routine - .globl _main - - ;; Macro definitions - -.macro WAIT_STAT ?lbl -lbl: LDH A, (.STAT) - AND #STATF_BUSY ; Check if in LCD modes 0 or 1 - JR NZ, lbl -.endm - -.macro ADD_A_REG16 regH regL - ADD regL - LD regL, A - ADC regH - SUB regL - LD regH, A -.endm - -.macro SIGNED_ADD_A_REG16 regH regL ?lbl - ; If A is negative, we need to subtract 1 from upper byte of 16-bit value - BIT 7, A ; set z if a signed bit is 0 - JR Z, lbl ; if z is set jump to positive - dec regH ; if negative decrement upper byte -lbl: - ADD_A_REG16 regH, regL -.endm - -.macro SIGNED_SUB_A_REG16 regH regL ?lbl - ; negate A then add to 16-bit value - CPL - INC A - SIGNED_ADD_A_REG16 regH, regL -.endm - -.macro MUL_DE_BY_A_RET_HL ?lbl1 ?lbl2 ?lbl3 - ; Multiply DE by A, return result in HL; preserves: BC - LD HL, #0 -lbl1: - SRL A - JR NC, lbl2 - ADD HL, DE -lbl2: - JR Z, lbl3 - SLA E - RL D - JR lbl1 -lbl3: -.endm - diff --git a/gbdk-lib/libc/targets/gbz80/duck/Makefile b/gbdk-lib/libc/targets/gbz80/duck/Makefile @@ -1,53 +0,0 @@ -# GB specific Makefile - -TOPDIR = ../../../.. - -THIS = duck -PORT = gbz80 - -CSRC = crlf.c digits.c gprint.c gprintf.c gprintln.c gprintn.c - -ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ - cpy_data.s \ - drawing.s drawing_isr.s color.s \ - f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ - get_bk_t.s get_data.s get_tile.s \ - get_wi_t.s get_xy_t.s \ - get_addr.s \ - hiramcpy.s init_tt.s input.s \ - pad.s \ - serial.s set_bk_t.s set_tile.s \ - set_data.s set_prop.s set_spr.s set_wi_t.s set_xy_t.s \ - set_1bit_data.s \ - sgb.s font.s font_color.s delay.s \ - emu_debug.s emu_debug_printf.s \ - nowait.s far_ptr.s \ - lcd.s joy.s tim.s tim.s tim_nested.s tim_common.s \ - crash_handler.s \ - ___sdcc_bcall_ehl.s ___sdcc_bcall.s \ - mv_spr.s \ - pad_ex.s \ - mode.s clock.s \ - get_t.s set_t.s init_vram.s \ - fill_rect.s fill_rect_bk.s fill_rect_wi.s \ - metasprites.s metasprites_flip.s metasprites_hide.s metasprites_hide_spr.s \ - set_tile_submap.s set_win_tile_submap.s \ - gb_decompress.s gb_decompress_tiles.s \ - rle_decompress.s \ - heap.s \ - crt0.s - -ifeq ($(ASM),asxxxx) -ASSRC += sfr.s -endif -ifeq ($(ASM),rgbds) -ASSRC += stubs.s -endif - -CRT0 = crt0.s - -include $(TOPDIR)/Makefile.common - -AS = $(AS_GBZ80) - -include ../../../Makefile.platform diff --git a/gbdk-lib/libc/targets/gbz80/duck/global.s b/gbdk-lib/libc/targets/gbz80/duck/global.s @@ -1,536 +0,0 @@ - .NEAR_CALLS = 1 ; <near_calls> - tag so that sed can change this - - ;; Changed by astorgb.pl to 1 - __RGBDS__ = 0 - - _VRAM = 0x8000 ; $8000->$9FFF - _VRAM8000 = 0x8000 - _VRAM8800 = 0x8800 - _VRAM9000 = 0x9000 - _SCRN0 = 0x9800 ; $9800->$9BFF - _SCRN1 = 0x9C00 ; $9C00->$9FFF - _SRAM = 0xA000 ; $A000->$BFFF - _RAM = 0xC000 ; $C000->$CFFF / $C000->$DFFF - _RAMBANK = 0xD000 ; $D000->$DFFF - _OAMRAM = 0xFE00 ; $FE00->$FE9F - _IO = 0xFF00 ; $FF00->$FF7F,$FFFF - _AUD3WAVERAM = 0xFF30 ; $FF30->$FF3F - _HRAM = 0xFF80 ; $FF80->$FFFE - - ;; MBC Equates - - .MBC1_ROM_PAGE = 0x2000 ; Address to write to for MBC1 switching - .MBC_ROM_PAGE = 0x0001 ; Default platform MBC rom switching address - - rRAMG = 0x0000 ; $0000->$1fff - rROMB0 = 0x0001 ; $2000->$2fff - rROMB1 = 0x3000 ; $3000->$3fff - If more than 256 ROM banks are present. - rRAMB = 0x4000 ; $4000->$5fff - Bit 3 enables rumble (if present) - - ;; Keypad - .START = 0x80 - .SELECT = 0x40 - .B = 0x20 - .A = 0x10 - .DOWN = 0x08 - .UP = 0x04 - .LEFT = 0x02 - .RIGHT = 0x01 - - .P14 = 0x10 - .P15 = 0x20 - - ;; Screen dimensions - .MAXCURSPOSX = 0x13 ; In tiles - .MAXCURSPOSY = 0x11 - - .SCREENWIDTH = 0xA0 - .SCREENHEIGHT = 0x90 - .MINWNDPOSX = 0x07 - .MINWNDPOSY = 0x00 - .MAXWNDPOSX = 0xA6 - .MAXWNDPOSY = 0x8F - - ;; Hardware registers - - .P1 = 0x00 ; Joystick: 1.1.P15.P14.P13.P12.P11.P10 - rP1 = 0xFF00 - - P1F_5 = 0b00100000 ; P15 out port, set to 0 to get buttons - P1F_4 = 0b00010000 ; P14 out port, set to 0 to get dpad - P1F_3 = 0b00001000 ; P13 in port - P1F_2 = 0b00000100 ; P12 in port - P1F_1 = 0b00000010 ; P11 in port - P1F_0 = 0b00000001 ; P10 in port - - P1F_GET_DPAD = 0b00100000 - P1F_GET_BTN = 0b00010000 - P1F_GET_NONE = 0b00110000 - - .SB = 0x01 ; Serial IO data buffer - rSB = 0xFF01 - - .SC = 0x02 ; Serial IO control register - rSC = 0xFF02 - - .DIV = 0x04 ; Divider register - rDIV = 0xFF04 - - .TIMA = 0x05 ; Timer counter - rTIMA = 0xFF05 - - .TMA = 0x06 ; Timer modulo - rTMA = 0xFF06 - - .TAC = 0x07 ; Timer control - rTAC = 0xFF07 - - TACF_START = 0b00000100 - TACF_STOP = 0b00000000 - TACF_4KHZ = 0b00000000 - TACF_16KHZ = 0b00000011 - TACF_65KHZ = 0b00000010 - TACF_262KHZ = 0b00000001 - - .IF = 0x0F ; Interrupt flags: 0.0.0.JST.SIO.TIM.LCD.VBL - rIF = 0xFF0F - - .NR10 = 0x20 ; Sound register - rNR10 = 0xFF20 - rAUD1SWEEP = 0xFF20 - - AUD1SWEEP_UP = 0b00000000 - AUD1SWEEP_DOWN = 0b00001000 - - .NR11 = 0x22 ; Sound register - rNR11 = 0xFF22 - rAUD1LEN = 0xFF22 - - .NR12 = 0x21 ; Sound register - rNR12 = 0xFF21 - rAUD1ENV = 0xFF21 - - .NR13 = 0x23 ; Sound register - rNR13 = 0xFF23 - rAUD1LOW = 0xFF23 - - .NR14 = 0x24 ; Sound register - rNR14 = 0xFF24 - rAUD1HIGH = 0xFF24 - - .NR21 = 0x25 ; Sound register - rNR21 = 0xFF25 - rAUD2LEN = 0xFF25 - - .NR22 = 0x27 ; Sound register - rNR22 = 0xFF27 - rAUD2ENV = 0xFF27 - - .NR23 = 0x28 ; Sound register - rNR23 = 0xFF28 - rAUD2LOW = 0xFF28 - - .NR24 = 0x29 ; Sound register - rNR24 = 0xFF29 - rAUD2HIGH = 0xFF29 - - .NR30 = 0x2A ; Sound register - rNR30 = 0xFF2A - rAUD3ENA = 0xFF2A - - .NR31 = 0x2B ; Sound register - rNR31 = 0xFF2B - rAUD3LEN = 0xFF2B - - .NR32 = 0x2C ; Sound register - rNR32 = 0xFF2C - rAUD3LEVEL = 0xFF2C - - .NR33 = 0x2E ; Sound register - rNR33 = 0xFF2E - rAUD3LOW = 0xFF2E - - .NR34 = 0x2D ; Sound register - rNR34 = 0xFF2D - rAUD3HIGH = 0xFF2D - - .NR41 = 0x40 ; Sound register - rNR41 = 0xFF40 - rAUD4LEN = 0xFF40 - - .NR42 = 0x42 ; Sound register - rNR42 = 0xFF42 - rAUD4ENV = 0xFF42 - - .NR43 = 0x41 ; Sound register - rNR43 = 0xFF41 - rAUD4POLY = 0xFF41 - - .NR44 = 0x43 ; Sound register - rNR44 = 0xFF43 - rAUD4GO = 0xFF43 - - .NR50 = 0x44 ; Sound register - rNR50 = 0xFF44 - rAUDVOL = 0xFF44 - - AUDVOL_VIN_LEFT = 0b10000000 ; SO2 - AUDVOL_VIN_RIGHT = 0b00001000 ; SO1 - - .NR51 = 0x46 ; Sound register - rNR51 = 0xFF46 - rAUDTERM = 0xFF46 - - AUDTERM_4_LEFT = 0b10000000 - AUDTERM_3_LEFT = 0b01000000 - AUDTERM_2_LEFT = 0b00100000 - AUDTERM_1_LEFT = 0b00010000 - AUDTERM_4_RIGHT = 0b00001000 - AUDTERM_3_RIGHT = 0b00000100 - AUDTERM_2_RIGHT = 0b00000010 - AUDTERM_1_RIGHT = 0b00000001 - - .NR52 = 0x45 ; Sound register - rNR52 = 0xFF45 - rAUDENA = 0xFF45 - - AUDENA_ON = 0b10000000 - AUDENA_OFF = 0b00000000 ; sets all audio regs to 0! - - .LCDC = 0x10 ; LCD control - rLCDC = 0xFF10 - - LCDCF_OFF = 0b00000000 ; LCD Control Operation - LCDCF_ON = 0b10000000 ; LCD Control Operation - LCDCF_WIN9800 = 0b00000000 ; Window Tile Map Display Select - LCDCF_WIN9C00 = 0b00001000 ; Window Tile Map Display Select - LCDCF_WINOFF = 0b00000000 ; Window Display - LCDCF_WINON = 0b00100000 ; Window Display - LCDCF_BG8800 = 0b00000000 ; BG & Window Tile Data Select - LCDCF_BG8000 = 0b00010000 ; BG & Window Tile Data Select - LCDCF_BG9800 = 0b00000000 ; BG Tile Map Display Select - LCDCF_BG9C00 = 0b00000100 ; BG Tile Map Display Select - LCDCF_OBJ8 = 0b00000000 ; OBJ Construction - LCDCF_OBJ16 = 0b00000010 ; OBJ Construction - LCDCF_OBJOFF = 0b00000000 ; OBJ Display - LCDCF_OBJON = 0b00000001 ; OBJ Display - LCDCF_BGOFF = 0b00000000 ; BG Display - LCDCF_BGON = 0b01000000 ; BG Display - LCDCF_B_ON = 7 - LCDCF_B_WIN9C00 = 3 - LCDCF_B_WINON = 5 - LCDCF_B_BG8000 = 4 - LCDCF_B_BG9C00 = 2 - LCDCF_B_OBJ16 = 1 - LCDCF_B_OBJON = 0 - LCDCF_B_BGON = 6 - - .STAT = 0x11 ; LCD status - rSTAT = 0xFF11 - - STATF_LYC = 0b01000000 ; LYC=LY Coincidence (Selectable) - STATF_MODE10 = 0b00100000 ; Mode 10 - STATF_MODE01 = 0b00010000 ; Mode 01 (V-Blank) - STATF_MODE00 = 0b00001000 ; Mode 00 (H-Blank) - STATF_LYCF = 0b00000100 ; Coincidence Flag - STATF_HBL = 0b00000000 ; H-Blank - STATF_VBL = 0b00000001 ; V-Blank - STATF_OAM = 0b00000010 ; OAM-RAM is used by system - STATF_LCD = 0b00000011 ; Both OAM and VRAM used by system - STATF_BUSY = 0b00000010 ; When set, VRAM access is unsafe - STATF_B_LYC = 6 - STATF_B_MODE10 = 5 - STATF_B_MODE01 = 4 - STATF_B_MODE00 = 3 - STATF_B_LYCF = 2 - STATF_B_VBL = 0 - STATF_B_OAM = 1 - STATF_B_BUSY = 1 - - .SCY = 0x12 ; Scroll Y - rSCY = 0xFF12 - - .SCX = 0x13 ; Scroll X - rSCX = 0xFF13 - - .LY = 0x18 ; LCDC Y-coordinate - rLY = 0xFF18 - - .LYC = 0x19 ; LY compare - rLYC = 0xFF19 - - .DMA = 0x1A ; DMA transfer - rDMA = 0xFF1A - - .BGP = 0x1B ; BG palette data - rBGP = 0xFF1B - - .OBP0 = 0x14 ; OBJ palette 0 data - rOBP0 = 0xFF14 - - .OBP1 = 0x15 ; OBJ palette 1 data - rOBP1 = 0xFF15 - - .WY = 0x16 ; Window Y coordinate - rWY = 0xFF16 - - .WX = 0x17 ; Window X coordinate - rWX = 0xFF17 - - .KEY1 = 0x4D ; CPU speed - rKEY1 = 0xFF4D - rSPD = 0xFF4D - - KEY1F_DBLSPEED = 0b10000000 ; 0=Normal Speed, 1=Double Speed (R) - KEY1F_PREPARE = 0b00000001 ; 0=No, 1=Prepare (R/W) - - .VBK = 0x4F ; VRAM bank - rVBK = 0xFF4F - - .HDMA1 = 0x51 ; DMA control 1 - rHDMA1 = 0xFF51 - - .HDMA2 = 0x52 ; DMA control 2 - rHDMA2 = 0xFF52 - - .HDMA3 = 0x53 ; DMA control 3 - rHDMA3 = 0xFF53 - - .HDMA4 = 0x54 ; DMA control 4 - rHDMA4 = 0xFF54 - - .HDMA5 = 0x55 ; DMA control 5 - rHDMA5 = 0xFF55 - - HDMA5F_MODE_GP = 0b00000000 ; General Purpose DMA (W) - HDMA5F_MODE_HBL = 0b10000000 ; HBlank DMA (W) - - HDMA5F_BUSY = 0b10000000 ; 0=Busy (DMA still in progress), 1=Transfer complete (R) - - .RP = 0x56 ; IR port - rRP = 0xFF56 - - RPF_ENREAD = 0b11000000 - RPF_DATAIN = 0b00000010 ; 0=Receiving IR Signal, 1=Normal - RPF_WRITE_HI = 0b00000001 - RPF_WRITE_LO = 0b00000000 - - .BCPS = 0x68 ; BG color palette specification - rBCPS = 0xFF68 - - BCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) - - .BCPD = 0x69 ; BG color palette data - rBCPD = 0xFF69 - - .OCPS = 0x6A ; OBJ color palette specification - rOCPS = 0xFF6A - - OCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) - - .OCPD = 0x6B ; OBJ color palette data - rOCPD = 0xFF6B - - .SVBK = 0x70 ; WRAM bank - rSVBK = 0xFF70 - rSMBK = 0xFF70 - - rPCM12 = 0xFF76 - - rPCM34 = 0xFF77 - - .IE = 0xFF ; Interrupt enable - rIE = 0xFFFF - - .VBL_IFLAG = 0x01 - .LCD_IFLAG = 0x02 - .TIM_IFLAG = 0x04 - .SIO_IFLAG = 0x08 - .JOY_IFLAG = 0x10 - - IEF_HILO = 0b00010000 ; Transition from High to Low of Pin number P10-P13 - IEF_SERIAL = 0b00001000 ; Serial I/O transfer end - IEF_TIMER = 0b00000100 ; Timer Overflow - IEF_STAT = 0b00000010 ; STAT - IEF_VBLANK = 0b00000001 ; V-Blank - - ;; Flags common to multiple sound channels - - AUDLEN_DUTY_12_5 = 0b00000000 ; 12.5% - AUDLEN_DUTY_25 = 0b01000000 ; 25% - AUDLEN_DUTY_50 = 0b10000000 ; 50% - AUDLEN_DUTY_75 = 0b11000000 ; 75% - - AUDENV_UP = 0b00001000 - AUDENV_DOWN = 0b00000000 - - AUDHIGH_RESTART = 0b10000000 - AUDHIGH_LENGTH_ON = 0b01000000 - AUDHIGH_LENGTH_OFF = 0b00000000 - - ;; OAM related constants - - OAM_COUNT = 40 ; number of OAM entries in OAM RAM - - OAMF_PRI = 0b10000000 ; Priority - OAMF_YFLIP = 0b01000000 ; Y flip - OAMF_XFLIP = 0b00100000 ; X flip - OAMF_PAL0 = 0b00000000 ; Palette number; 0,1 (DMG) - OAMF_PAL1 = 0b00010000 ; Palette number; 0,1 (DMG) - OAMF_BANK0 = 0b00000000 ; Bank number; 0,1 (GBC) - OAMF_BANK1 = 0b00001000 ; Bank number; 0,1 (GBC) - - OAMF_PALMASK = 0b00000111 ; Palette (GBC) - - OAMB_PRI = 7 ; Priority - OAMB_YFLIP = 6 ; Y flip - OAMB_XFLIP = 5 ; X flip - OAMB_PAL1 = 4 ; Palette number; 0,1 (DMG) - OAMB_BANK1 = 3 ; Bank number; 0,1 (GBC) - - ;; SGB packets - .PAL_01 = 0x00 - .PAL_23 = 0x01 - .PAL_03 = 0x02 - .PAL_12 = 0x03 - .ATTR_BLK = 0x04 - .ATTR_LIN = 0x05 - .ATTR_DIV = 0x06 - .ATTR_CHR = 0x07 - .SOUND = 0x08 - .SOU_TRN = 0x09 - .PAL_SET = 0x0A - .PAL_TRN = 0x0B - .ATRC_EN = 0x0C - .TEST_EN = 0x0D - .ICON_EN = 0x0E - .DATA_SND = 0x0F - .DATA_TRN = 0x10 - .MLT_REQ = 0x11 - .JUMP = 0x12 - .CHR_TRN = 0x13 - .PCT_TRN = 0x14 - .ATTR_TRN = 0x15 - .ATTR_SET = 0x16 - .MASK_EN = 0x17 - .OBJ_TRN = 0x18 - - ;; CPU detection - .DMG_TYPE = 0x01 ; Original GB or Super GB - .MGB_TYPE = 0xFF ; Pocket GB or Super GB 2 - .CGB_TYPE = 0x11 ; Color GB - - ;; GBDK library screen modes - - .G_MODE = 0x01 ; Graphic mode - .T_MODE = 0x02 ; Text mode (bit 2) - .T_MODE_OUT = 0x02 ; Text mode output only - .T_MODE_INOUT = 0x03 ; Text mode with input - .M_NO_SCROLL = 0x04 ; Disables scrolling of the screen in text mode - .M_NO_INTERP = 0x08 ; Disables special character interpretation - - ;; Status codes for IO - .IO_IDLE = 0x00 - .IO_SENDING = 0x01 - .IO_RECEIVING = 0x02 - .IO_ERROR = 0x04 - - ;; Type of IO data - .DT_IDLE = 0x66 - .DT_RECEIVING = 0x55 - - ;; Table of routines for modes - .MODE_TABLE = 0x01E0 - - ;; C related - ;; Overheap of a banked call. Used for parameters - ;; = ret + real ret + bank - - .if .NEAR_CALLS - .BANKOV = 2 - - .else - .BANKOV = 6 - - .endif - - .globl __current_bank - .globl __shadow_OAM_base - - ;; Global variables - .globl .mode - - .globl __cpu - .globl __is_GBA - - ;; Global routines -; .globl .set_mode ;; don't link mode.o by default - - .globl .reset - - .globl .display_off - - .globl .wait_vbl_done - - ;; Interrupt routines - .globl .add_VBL -; .globl .add_LCD ;; don't link LCD.o by default -; .globl .add_TIM ;; don't link TIM.o by default -; .globl .add_SIO ;; don't link serial.o by default -; .globl .add_JOY ;; don't link JOY.o by default - - ;; Symbols defined at link time - .globl .STACK - .globl _shadow_OAM - .globl .refresh_OAM - - ;; Main user routine - .globl _main - - ;; Macro definitions - -.macro WAIT_STAT ?lbl -lbl: LDH A, (.STAT) - AND #STATF_BUSY ; Check if in LCD modes 0 or 1 - JR NZ, lbl -.endm - -.macro ADD_A_REG16 regH regL - ADD regL - LD regL, A - ADC regH - SUB regL - LD regH, A -.endm - -.macro SIGNED_ADD_A_REG16 regH regL ?lbl - ; If A is negative, we need to subtract 1 from upper byte of 16-bit value - BIT 7, A ; set z if a signed bit is 0 - JR Z, lbl ; if z is set jump to positive - dec regH ; if negative decrement upper byte -lbl: - ADD_A_REG16 regH, regL -.endm - -.macro SIGNED_SUB_A_REG16 regH regL ?lbl - ; negate A then add to 16-bit value - CPL - INC A - SIGNED_ADD_A_REG16 regH, regL -.endm - -.macro MUL_DE_BY_A_RET_HL ?lbl1 ?lbl2 ?lbl3 - ; Multiply DE by A, return result in HL; preserves: BC - LD HL, #0 -lbl1: - SRL A - JR NC, lbl2 - ADD HL, DE -lbl2: - JR Z, lbl3 - SLA E - RL D - JR lbl1 -lbl3: -.endm - diff --git a/gbdk-lib/libc/targets/gbz80/gb/Makefile b/gbdk-lib/libc/targets/gbz80/gb/Makefile @@ -1,53 +0,0 @@ -# GB specific Makefile - -TOPDIR = ../../../.. - -THIS = gb -PORT = gbz80 - -CSRC = crlf.c digits.c gprint.c gprintf.c gprintln.c gprintn.c - -ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ - cpy_data.s \ - drawing.s drawing_isr.s color.s \ - f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ - get_bk_t.s get_data.s get_tile.s \ - get_wi_t.s get_xy_t.s \ - get_addr.s \ - hiramcpy.s init_tt.s input.s \ - pad.s \ - serial.s set_bk_t.s set_tile.s \ - set_data.s set_prop.s set_spr.s set_wi_t.s set_xy_t.s \ - set_1bit_data.s \ - sgb.s font.s font_color.s delay.s \ - emu_debug.s emu_debug_printf.s \ - nowait.s far_ptr.s \ - lcd.s joy.s tim.s tim.s tim_nested.s tim_common.s \ - crash_handler.s \ - ___sdcc_bcall_ehl.s ___sdcc_bcall.s \ - mv_spr.s \ - pad_ex.s \ - mode.s clock.s \ - get_t.s set_t.s init_vram.s \ - fill_rect.s fill_rect_bk.s fill_rect_wi.s \ - metasprites.s metasprites_flip.s metasprites_hide.s metasprites_hide_spr.s \ - set_tile_submap.s set_win_tile_submap.s \ - gb_decompress.s gb_decompress_tiles.s \ - rle_decompress.s \ - heap.s \ - crt0.s - -ifeq ($(ASM),asxxxx) -ASSRC += sfr.s -endif -ifeq ($(ASM),rgbds) -ASSRC += stubs.s -endif - -CRT0 = crt0.s - -include $(TOPDIR)/Makefile.common - -AS = $(AS_GBZ80) - -include ../../../Makefile.platform diff --git a/gbdk-lib/libc/targets/gbz80/gb/global.s b/gbdk-lib/libc/targets/gbz80/gb/global.s @@ -1,535 +0,0 @@ - .NEAR_CALLS = 1 ; <near_calls> - tag so that sed can change this - - ;; Changed by astorgb.pl to 1 - __RGBDS__ = 0 - - _VRAM = 0x8000 ; $8000->$9FFF - _VRAM8000 = 0x8000 - _VRAM8800 = 0x8800 - _VRAM9000 = 0x9000 - _SCRN0 = 0x9800 ; $9800->$9BFF - _SCRN1 = 0x9C00 ; $9C00->$9FFF - _SRAM = 0xA000 ; $A000->$BFFF - _RAM = 0xC000 ; $C000->$CFFF / $C000->$DFFF - _RAMBANK = 0xD000 ; $D000->$DFFF - _OAMRAM = 0xFE00 ; $FE00->$FE9F - _IO = 0xFF00 ; $FF00->$FF7F,$FFFF - _AUD3WAVERAM = 0xFF30 ; $FF30->$FF3F - _HRAM = 0xFF80 ; $FF80->$FFFE - - ;; MBC Equates - - .MBC1_ROM_PAGE = 0x2000 ; Address to write to for MBC1 switching - .MBC_ROM_PAGE = 0x2000 ; Default platform MBC rom switching address - - rRAMG = 0x0000 ; $0000->$1fff - rROMB0 = 0x2000 ; $2000->$2fff - rROMB1 = 0x3000 ; $3000->$3fff - If more than 256 ROM banks are present. - rRAMB = 0x4000 ; $4000->$5fff - Bit 3 enables rumble (if present) - - ;; Keypad - .UP = 0x04 - .DOWN = 0x08 - .LEFT = 0x02 - .RIGHT = 0x01 - .A = 0x10 - .B = 0x20 - .SELECT = 0x40 - .START = 0x80 - - .P14 = 0x10 - .P15 = 0x20 - - ;; Screen dimensions - .MAXCURSPOSX = 0x13 ; In tiles - .MAXCURSPOSY = 0x11 - - .SCREENWIDTH = 0xA0 - .SCREENHEIGHT = 0x90 - .MINWNDPOSX = 0x07 - .MINWNDPOSY = 0x00 - .MAXWNDPOSX = 0xA6 - .MAXWNDPOSY = 0x8F - - ;; Hardware registers - - .P1 = 0x00 ; Joystick: 1.1.P15.P14.P13.P12.P11.P10 - rP1 = 0xFF00 - - P1F_5 = 0b00100000 ; P15 out port, set to 0 to get buttons - P1F_4 = 0b00010000 ; P14 out port, set to 0 to get dpad - P1F_3 = 0b00001000 ; P13 in port - P1F_2 = 0b00000100 ; P12 in port - P1F_1 = 0b00000010 ; P11 in port - P1F_0 = 0b00000001 ; P10 in port - - P1F_GET_DPAD = 0b00100000 - P1F_GET_BTN = 0b00010000 - P1F_GET_NONE = 0b00110000 - - .SB = 0x01 ; Serial IO data buffer - rSB = 0xFF01 - - .SC = 0x02 ; Serial IO control register - rSC = 0xFF02 - - .DIV = 0x04 ; Divider register - rDIV = 0xFF04 - - .TIMA = 0x05 ; Timer counter - rTIMA = 0xFF05 - - .TMA = 0x06 ; Timer modulo - rTMA = 0xFF06 - - .TAC = 0x07 ; Timer control - rTAC = 0xFF07 - - TACF_START = 0b00000100 - TACF_STOP = 0b00000000 - TACF_4KHZ = 0b00000000 - TACF_16KHZ = 0b00000011 - TACF_65KHZ = 0b00000010 - TACF_262KHZ = 0b00000001 - - .IF = 0x0F ; Interrupt flags: 0.0.0.JST.SIO.TIM.LCD.VBL - rIF = 0xFF0F - - .NR10 = 0x10 ; Sound register - rNR10 = 0xFF10 - rAUD1SWEEP = 0xFF10 - - AUD1SWEEP_UP = 0b00000000 - AUD1SWEEP_DOWN = 0b00001000 - - .NR11 = 0x11 ; Sound register - rNR11 = 0xFF11 - rAUD1LEN = 0xFF11 - - .NR12 = 0x12 ; Sound register - rNR12 = 0xFF12 - rAUD1ENV = 0xFF12 - - .NR13 = 0x13 ; Sound register - rNR13 = 0xFF13 - rAUD1LOW = 0xFF13 - - .NR14 = 0x14 ; Sound register - rNR14 = 0xFF14 - rAUD1HIGH = 0xFF14 - - .NR21 = 0x16 ; Sound register - rNR21 = 0xFF16 - rAUD2LEN = 0xFF16 - - .NR22 = 0x17 ; Sound register - rNR22 = 0xFF17 - rAUD2ENV = 0xFF17 - - .NR23 = 0x18 ; Sound register - rNR23 = 0xFF18 - rAUD2LOW = 0xFF18 - - .NR24 = 0x19 ; Sound register - rNR24 = 0xFF19 - rAUD2HIGH = 0xFF19 - - .NR30 = 0x1A ; Sound register - rNR30 = 0xFF1A - rAUD3ENA = 0xFF1A - - .NR31 = 0x1B ; Sound register - rNR31 = 0xFF1B - rAUD3LEN = 0xFF1B - - .NR32 = 0x1C ; Sound register - rNR32 = 0xFF1C - rAUD3LEVEL = 0xFF1C - - .NR33 = 0x1D ; Sound register - rNR33 = 0xFF1D - rAUD3LOW = 0xFF1D - - .NR34 = 0x1E ; Sound register - rNR34 = 0xFF1E - rAUD3HIGH = 0xFF1E - - .NR41 = 0x20 ; Sound register - rNR41 = 0xFF20 - rAUD4LEN = 0xFF20 - - .NR42 = 0x21 ; Sound register - rNR42 = 0xFF21 - rAUD4ENV = 0xFF21 - - .NR43 = 0x22 ; Sound register - rNR43 = 0xFF22 - rAUD4POLY = 0xFF22 - - .NR44 = 0x23 ; Sound register - rNR44 = 0xFF23 - rAUD4GO = 0xFF23 - - .NR50 = 0x24 ; Sound register - rNR50 = 0xFF24 - rAUDVOL = 0xFF24 - - AUDVOL_VIN_LEFT = 0b10000000 ; SO2 - AUDVOL_VIN_RIGHT = 0b00001000 ; SO1 - - .NR51 = 0x25 ; Sound register - rNR51 = 0xFF25 - rAUDTERM = 0xFF25 - - AUDTERM_4_LEFT = 0b10000000 - AUDTERM_3_LEFT = 0b01000000 - AUDTERM_2_LEFT = 0b00100000 - AUDTERM_1_LEFT = 0b00010000 - AUDTERM_4_RIGHT = 0b00001000 - AUDTERM_3_RIGHT = 0b00000100 - AUDTERM_2_RIGHT = 0b00000010 - AUDTERM_1_RIGHT = 0b00000001 - - .NR52 = 0x26 ; Sound register - rNR52 = 0xFF26 - rAUDENA = 0xFF26 - - AUDENA_ON = 0b10000000 - AUDENA_OFF = 0b00000000 ; sets all audio regs to 0! - - .LCDC = 0x40 ; LCD control - rLCDC = 0xFF40 - - LCDCF_OFF = 0b00000000 ; LCD Control Operation - LCDCF_ON = 0b10000000 ; LCD Control Operation - LCDCF_WIN9800 = 0b00000000 ; Window Tile Map Display Select - LCDCF_WIN9C00 = 0b01000000 ; Window Tile Map Display Select - LCDCF_WINOFF = 0b00000000 ; Window Display - LCDCF_WINON = 0b00100000 ; Window Display - LCDCF_BG8800 = 0b00000000 ; BG & Window Tile Data Select - LCDCF_BG8000 = 0b00010000 ; BG & Window Tile Data Select - LCDCF_BG9800 = 0b00000000 ; BG Tile Map Display Select - LCDCF_BG9C00 = 0b00001000 ; BG Tile Map Display Select - LCDCF_OBJ8 = 0b00000000 ; OBJ Construction - LCDCF_OBJ16 = 0b00000100 ; OBJ Construction - LCDCF_OBJOFF = 0b00000000 ; OBJ Display - LCDCF_OBJON = 0b00000010 ; OBJ Display - LCDCF_BGOFF = 0b00000000 ; BG Display - LCDCF_BGON = 0b00000001 ; BG Display - LCDCF_B_ON = 7 - LCDCF_B_WIN9C00 = 6 - LCDCF_B_WINON = 5 - LCDCF_B_BG8000 = 4 - LCDCF_B_BG9C00 = 3 - LCDCF_B_OBJ16 = 2 - LCDCF_B_OBJON = 1 - LCDCF_B_BGON = 0 - - .STAT = 0x41 ; LCD status - rSTAT = 0xFF41 - - STATF_LYC = 0b01000000 ; LYC=LY Coincidence (Selectable) - STATF_MODE10 = 0b00100000 ; Mode 10 - STATF_MODE01 = 0b00010000 ; Mode 01 (V-Blank) - STATF_MODE00 = 0b00001000 ; Mode 00 (H-Blank) - STATF_LYCF = 0b00000100 ; Coincidence Flag - STATF_HBL = 0b00000000 ; H-Blank - STATF_VBL = 0b00000001 ; V-Blank - STATF_OAM = 0b00000010 ; OAM-RAM is used by system - STATF_LCD = 0b00000011 ; Both OAM and VRAM used by system - STATF_BUSY = 0b00000010 ; When set, VRAM access is unsafe - STATF_B_LYC = 6 - STATF_B_MODE10 = 5 - STATF_B_MODE01 = 4 - STATF_B_MODE00 = 3 - STATF_B_LYCF = 2 - STATF_B_VBL = 0 - STATF_B_OAM = 1 - STATF_B_BUSY = 1 - - .SCY = 0x42 ; Scroll Y - rSCY = 0xFF42 - - .SCX = 0x43 ; Scroll X - rSCX = 0xFF43 - - .LY = 0x44 ; LCDC Y-coordinate - rLY = 0xFF44 - - .LYC = 0x45 ; LY compare - rLYC = 0xFF45 - - .DMA = 0x46 ; DMA transfer - rDMA = 0xFF46 - - .BGP = 0x47 ; BG palette data - rBGP = 0xFF47 - - .OBP0 = 0x48 ; OBJ palette 0 data - rOBP0 = 0xFF48 - - .OBP1 = 0x49 ; OBJ palette 1 data - rOBP1 = 0xFF49 - - .WY = 0x4A ; Window Y coordinate - rWY = 0xFF4A - - .WX = 0x4B ; Window X coordinate - rWX = 0xFF4B - - .KEY1 = 0x4D ; CPU speed - rKEY1 = 0xFF4D - rSPD = 0xFF4D - - KEY1F_DBLSPEED = 0b10000000 ; 0=Normal Speed, 1=Double Speed (R) - KEY1F_PREPARE = 0b00000001 ; 0=No, 1=Prepare (R/W) - - .VBK = 0x4F ; VRAM bank - rVBK = 0xFF4F - - .HDMA1 = 0x51 ; DMA control 1 - rHDMA1 = 0xFF51 - - .HDMA2 = 0x52 ; DMA control 2 - rHDMA2 = 0xFF52 - - .HDMA3 = 0x53 ; DMA control 3 - rHDMA3 = 0xFF53 - - .HDMA4 = 0x54 ; DMA control 4 - rHDMA4 = 0xFF54 - - .HDMA5 = 0x55 ; DMA control 5 - rHDMA5 = 0xFF55 - - HDMA5F_MODE_GP = 0b00000000 ; General Purpose DMA (W) - HDMA5F_MODE_HBL = 0b10000000 ; HBlank DMA (W) - - HDMA5F_BUSY = 0b10000000 ; 0=Busy (DMA still in progress), 1=Transfer complete (R) - - .RP = 0x56 ; IR port - rRP = 0xFF56 - - RPF_ENREAD = 0b11000000 - RPF_DATAIN = 0b00000010 ; 0=Receiving IR Signal, 1=Normal - RPF_WRITE_HI = 0b00000001 - RPF_WRITE_LO = 0b00000000 - - .BCPS = 0x68 ; BG color palette specification - rBCPS = 0xFF68 - - BCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) - - .BCPD = 0x69 ; BG color palette data - rBCPD = 0xFF69 - - .OCPS = 0x6A ; OBJ color palette specification - rOCPS = 0xFF6A - - OCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) - - .OCPD = 0x6B ; OBJ color palette data - rOCPD = 0xFF6B - - .SVBK = 0x70 ; WRAM bank - rSVBK = 0xFF70 - rSMBK = 0xFF70 - - rPCM12 = 0xFF76 - - rPCM34 = 0xFF77 - - .IE = 0xFF ; Interrupt enable - rIE = 0xFFFF - - .VBL_IFLAG = 0x01 - .LCD_IFLAG = 0x02 - .TIM_IFLAG = 0x04 - .SIO_IFLAG = 0x08 - .JOY_IFLAG = 0x10 - - IEF_HILO = 0b00010000 ; Transition from High to Low of Pin number P10-P13 - IEF_SERIAL = 0b00001000 ; Serial I/O transfer end - IEF_TIMER = 0b00000100 ; Timer Overflow - IEF_STAT = 0b00000010 ; STAT - IEF_VBLANK = 0b00000001 ; V-Blank - - ;; Flags common to multiple sound channels - - AUDLEN_DUTY_12_5 = 0b00000000 ; 12.5% - AUDLEN_DUTY_25 = 0b01000000 ; 25% - AUDLEN_DUTY_50 = 0b10000000 ; 50% - AUDLEN_DUTY_75 = 0b11000000 ; 75% - - AUDENV_UP = 0b00001000 - AUDENV_DOWN = 0b00000000 - - AUDHIGH_RESTART = 0b10000000 - AUDHIGH_LENGTH_ON = 0b01000000 - AUDHIGH_LENGTH_OFF = 0b00000000 - - ;; OAM related constants - - OAM_COUNT = 40 ; number of OAM entries in OAM RAM - - OAMF_PRI = 0b10000000 ; Priority - OAMF_YFLIP = 0b01000000 ; Y flip - OAMF_XFLIP = 0b00100000 ; X flip - OAMF_PAL0 = 0b00000000 ; Palette number; 0,1 (DMG) - OAMF_PAL1 = 0b00010000 ; Palette number; 0,1 (DMG) - OAMF_BANK0 = 0b00000000 ; Bank number; 0,1 (GBC) - OAMF_BANK1 = 0b00001000 ; Bank number; 0,1 (GBC) - - OAMF_PALMASK = 0b00000111 ; Palette (GBC) - - OAMB_PRI = 7 ; Priority - OAMB_YFLIP = 6 ; Y flip - OAMB_XFLIP = 5 ; X flip - OAMB_PAL1 = 4 ; Palette number; 0,1 (DMG) - OAMB_BANK1 = 3 ; Bank number; 0,1 (GBC) - - ;; SGB packets - .PAL_01 = 0x00 - .PAL_23 = 0x01 - .PAL_03 = 0x02 - .PAL_12 = 0x03 - .ATTR_BLK = 0x04 - .ATTR_LIN = 0x05 - .ATTR_DIV = 0x06 - .ATTR_CHR = 0x07 - .SOUND = 0x08 - .SOU_TRN = 0x09 - .PAL_SET = 0x0A - .PAL_TRN = 0x0B - .ATRC_EN = 0x0C - .TEST_EN = 0x0D - .ICON_EN = 0x0E - .DATA_SND = 0x0F - .DATA_TRN = 0x10 - .MLT_REQ = 0x11 - .JUMP = 0x12 - .CHR_TRN = 0x13 - .PCT_TRN = 0x14 - .ATTR_TRN = 0x15 - .ATTR_SET = 0x16 - .MASK_EN = 0x17 - .OBJ_TRN = 0x18 - - ;; CPU detection - .DMG_TYPE = 0x01 ; Original GB or Super GB - .MGB_TYPE = 0xFF ; Pocket GB or Super GB 2 - .CGB_TYPE = 0x11 ; Color GB - - ;; GBDK library screen modes - - .G_MODE = 0x01 ; Graphic mode - .T_MODE = 0x02 ; Text mode (bit 2) - .T_MODE_OUT = 0x02 ; Text mode output only - .T_MODE_INOUT = 0x03 ; Text mode with input - .M_NO_SCROLL = 0x04 ; Disables scrolling of the screen in text mode - .M_NO_INTERP = 0x08 ; Disables special character interpretation - - ;; Status codes for IO - .IO_IDLE = 0x00 - .IO_SENDING = 0x01 - .IO_RECEIVING = 0x02 - .IO_ERROR = 0x04 - - ;; Type of IO data - .DT_IDLE = 0x66 - .DT_RECEIVING = 0x55 - - ;; Table of routines for modes - .MODE_TABLE = 0x01E0 - - ;; C related - ;; Overheap of a banked call. Used for parameters - ;; = ret + real ret + bank - - .if .NEAR_CALLS - .BANKOV = 2 - - .else - .BANKOV = 6 - - .endif - - .globl __current_bank - .globl __shadow_OAM_base - - ;; Global variables - .globl .mode - - .globl __cpu - .globl __is_GBA - - ;; Global routines -; .globl .set_mode ;; don't link mode.o by default - - .globl .reset - - .globl .display_off - - .globl .wait_vbl_done - - ;; Interrupt routines - .globl .add_VBL -; .globl .add_LCD ;; don't link LCD.o by default -; .globl .add_TIM ;; don't link TIM.o by default -; .globl .add_SIO ;; don't link serial.o by default -; .globl .add_JOY ;; don't link JOY.o by default - - ;; Symbols defined at link time - .globl .STACK - .globl _shadow_OAM - .globl .refresh_OAM - - ;; Main user routine - .globl _main - - ;; Macro definitions - -.macro WAIT_STAT ?lbl -lbl: LDH A, (.STAT) - AND #STATF_BUSY ; Check if in LCD modes 0 or 1 - JR NZ, lbl -.endm - -.macro ADD_A_REG16 regH regL - ADD regL - LD regL, A - ADC regH - SUB regL - LD regH, A -.endm - -.macro SIGNED_ADD_A_REG16 regH regL ?lbl - ; If A is negative, we need to subtract 1 from upper byte of 16-bit value - BIT 7, A ; set z if a signed bit is 0 - JR Z, lbl ; if z is set jump to positive - dec regH ; if negative decrement upper byte -lbl: - ADD_A_REG16 regH, regL -.endm - -.macro SIGNED_SUB_A_REG16 regH regL ?lbl - ; negate A then add to 16-bit value - CPL - INC A - SIGNED_ADD_A_REG16 regH, regL -.endm - -.macro MUL_DE_BY_A_RET_HL ?lbl1 ?lbl2 - ; Multiply DE by A, return result in HL; preserves: BC - LD HL, #0 -lbl1: - SRL A - JR NC, lbl2 - ADD HL, DE -lbl2: - SLA E - RL D - OR A - JR NZ, lbl1 -.endm - diff --git a/gbdk-lib/libc/targets/gbz80/stubs.rasm b/gbdk-lib/libc/targets/gbz80/stubs.rasm @@ -1,11 +0,0 @@ - GLOBAL STACK - GLOBAL OAM - GLOBAL refresh_OAM - - SECTION "stubs_1", BSS[$C000] -OAM: - DS $A0 - SECTION "stubs_2", HRAM[$FF80] -refresh_OAM: - SECTION "stubs_4", BSS[$E000] -STACK: diff --git a/gbdk-lib/libc/targets/gbz80/stubs.s b/gbdk-lib/libc/targets/gbz80/stubs.s @@ -1,129 +0,0 @@ - ;; Stubs to match between function names - .area _CODE - - .globl __mulslong - .globl __mululong - .globl __modslong - .globl __modulong - .globl __divslong - .globl __divulong - .globl __divschar_rrx_s - .globl __divsint_rrx_s - .globl __divuchar_rrx_s - .globl __divuint_rrx_s - .globl __mulschar_rrx_s - .globl __mulsint_rrx_s - .globl __muluchar_rrx_s - .globl __muluint_rrx_s - .globl __moduchar_rrx_s - .globl __modschar_rrx_s - .globl __moduint_rrx_s - .globl __modsint_rrx_s - .globl __rrulong_rrx_s - .globl __rrslong_rrx_s - .globl __rlulong_rrx_s - .globl __rlslong_rrx_s - -__mulslong_rrx_s:: -__mulslong_rrf_s:: - jp __mulslong - -__mululong_rrx_s:: -__mululong_rrf_s:: - jp __mululong - -__modslong_rrx_s:: -__modslong_rrf_s:: - jp __modslong - -__modulong_rrx_s:: -__modulong_rrf_s:: - jp __modulong - -__divslong_rrx_s:: -__divslong_rrf_s:: - jp __divslong - -__divulong_rrx_s:: -__divulong_rrf_s:: - jp __divulong - -__mulsint_rrf_s:: - ld a,#5 - rst 0x08 - jp __mulsint_rrx_s - -__divsint_rrf_s:: - ld a,#5 - rst 0x08 - jp __divsint_rrx_s - -__muluint_rrf_s:: - ld a,#5 - rst 0x08 - jp __muluint_rrx_s - -__divuint_rrf_s:: - ld a,#5 - rst 0x08 - jp __divuint_rrx_s - -__mulschar_rrf_s:: - ld a,#5 - rst 0x08 - jp __mulschar_rrx_s - -__divschar_rrf_s:: - ld a,#5 - rst 0x08 - jp __divschar_rrx_s - -__muluchar_rrf_s:: - ld a,#5 - rst 0x08 - jp __muluchar_rrx_s - -__divuchar_rrf_s:: - ld a,#5 - rst 0x08 - jp __divuchar_rrx_s - -__modschar_rrf_s:: - ld a,#5 - rst 0x08 - jp __modschar_rrx_s - -__moduchar_rrf_s:: - ld a,#5 - rst 0x08 - jp __moduchar_rrx_s - -__modsint_rrf_s:: - ld a,#5 - rst 0x08 - jp __modsint_rrx_s - -__moduint_rrf_s:: - ld a,#5 - rst 0x08 - jp __moduint_rrx_s - -__rrulong_rrf_s:: - ld a,#5 - rst 0x08 - jp __rrulong_rrx_s - -__rrslong_rrf_s:: - ld a,#5 - rst 0x08 - jp __rrslong_rrx_s - -__rlulong_rrf_s:: - ld a,#5 - rst 0x08 - jp __rlulong_rrx_s - -__rlslong_rrf_s:: - ld a,#5 - rst 0x08 - jp __rlslong_rrx_s diff --git a/gbdk-lib/libc/targets/gbz80/___sdcc_bcall.s b/gbdk-lib/libc/targets/sm83/___sdcc_bcall.s diff --git a/gbdk-lib/libc/targets/gbz80/___sdcc_bcall_ehl.s b/gbdk-lib/libc/targets/sm83/___sdcc_bcall_ehl.s diff --git a/gbdk-lib/libc/targets/sm83/ap/Makefile b/gbdk-lib/libc/targets/sm83/ap/Makefile @@ -0,0 +1,47 @@ +# GB specific Makefile + +TOPDIR = ../../../.. + +THIS = ap +PORT = sm83 + +CSRC = crlf.c digits.c gprint.c gprintf.c gprintln.c gprintn.c + +ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ + cpy_data.s \ + drawing.s drawing_isr.s color.s \ + f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ + get_bk_t.s get_data.s get_tile.s \ + get_wi_t.s get_xy_t.s \ + get_addr.s \ + hiramcpy.s init_tt.s input.s \ + pad.s \ + serial.s set_bk_t.s set_tile.s \ + set_data.s set_prop.s set_spr.s set_wi_t.s set_xy_t.s \ + set_1bit_data.s \ + sgb.s font.s font_color.s delay.s \ + emu_debug.s emu_debug_printf.s \ + nowait.s far_ptr.s \ + lcd.s joy.s tim.s tim_nested.s tim_common.s \ + crash_handler.s \ + ___sdcc_bcall_ehl.s ___sdcc_bcall.s \ + mv_spr.s \ + pad_ex.s \ + mode.s clock.s \ + get_t.s set_t.s init_vram.s \ + fill_rect.s fill_rect_bk.s fill_rect_wi.s \ + metasprites.s metasprites_flip.s metasprites_hide.s metasprites_hide_spr.s \ + set_tile_submap.s set_win_tile_submap.s \ + gb_decompress.s gb_decompress_tiles.s \ + rle_decompress.s \ + heap.s \ + sfr.s \ + crt0.s + +CRT0 = crt0.s + +include $(TOPDIR)/Makefile.common + +AS = $(AS_SM83) + +include ../../../Makefile.platform diff --git a/gbdk-lib/libc/targets/gbz80/ap/crash_handler.s b/gbdk-lib/libc/targets/sm83/ap/crash_handler.s diff --git a/gbdk-lib/libc/targets/gbz80/ap/crt0.s b/gbdk-lib/libc/targets/sm83/ap/crt0.s diff --git a/gbdk-lib/libc/targets/sm83/ap/global.s b/gbdk-lib/libc/targets/sm83/ap/global.s @@ -0,0 +1,533 @@ + .NEAR_CALLS = 1 ; <near_calls> - tag so that sed can change this + + _VRAM = 0x8000 ; $8000->$9FFF + _VRAM8000 = 0x8000 + _VRAM8800 = 0x8800 + _VRAM9000 = 0x9000 + _SCRN0 = 0x9800 ; $9800->$9BFF + _SCRN1 = 0x9C00 ; $9C00->$9FFF + _SRAM = 0xA000 ; $A000->$BFFF + _RAM = 0xC000 ; $C000->$CFFF / $C000->$DFFF + _RAMBANK = 0xD000 ; $D000->$DFFF + _OAMRAM = 0xFE00 ; $FE00->$FE9F + _IO = 0xFF00 ; $FF00->$FF7F,$FFFF + _AUD3WAVERAM = 0xFF30 ; $FF30->$FF3F + _HRAM = 0xFF80 ; $FF80->$FFFE + + ;; MBC Equates + + .MBC1_ROM_PAGE = 0x2000 ; Address to write to for MBC1 switching + .MBC_ROM_PAGE = 0x2000 ; Default platform MBC rom switching address + + rRAMG = 0x0000 ; $0000->$1fff + rROMB0 = 0x2000 ; $2000->$2fff + rROMB1 = 0x3000 ; $3000->$3fff - If more than 256 ROM banks are present. + rRAMB = 0x4000 ; $4000->$5fff - Bit 3 enables rumble (if present) + + ;; Keypad + .START = 0x80 + .SELECT = 0x40 + .B = 0x20 + .A = 0x10 + .DOWN = 0x08 + .UP = 0x04 + .LEFT = 0x02 + .RIGHT = 0x01 + + .P14 = 0x10 + .P15 = 0x20 + + ;; Screen dimensions + .MAXCURSPOSX = 0x13 ; In tiles + .MAXCURSPOSY = 0x11 + + .SCREENWIDTH = 0xA0 + .SCREENHEIGHT = 0x90 + .MINWNDPOSX = 0x07 + .MINWNDPOSY = 0x00 + .MAXWNDPOSX = 0xA6 + .MAXWNDPOSY = 0x8F + + ;; Hardware registers + + .P1 = 0x00 ; Joystick: 1.1.P15.P14.P13.P12.P11.P10 + rP1 = 0xFF00 + + P1F_5 = 0b00100000 ; P15 out port, set to 0 to get buttons + P1F_4 = 0b00010000 ; P14 out port, set to 0 to get dpad + P1F_3 = 0b00001000 ; P13 in port + P1F_2 = 0b00000100 ; P12 in port + P1F_1 = 0b00000010 ; P11 in port + P1F_0 = 0b00000001 ; P10 in port + + P1F_GET_DPAD = 0b00100000 + P1F_GET_BTN = 0b00010000 + P1F_GET_NONE = 0b00110000 + + .SB = 0x01 ; Serial IO data buffer + rSB = 0xFF01 + + .SC = 0x02 ; Serial IO control register + rSC = 0xFF02 + + .DIV = 0x04 ; Divider register + rDIV = 0xFF04 + + .TIMA = 0x05 ; Timer counter + rTIMA = 0xFF05 + + .TMA = 0x06 ; Timer modulo + rTMA = 0xFF06 + + .TAC = 0x07 ; Timer control + rTAC = 0xFF07 + + TACF_START = 0b00000100 + TACF_STOP = 0b00000000 + TACF_4KHZ = 0b00000000 + TACF_16KHZ = 0b00000011 + TACF_65KHZ = 0b00000010 + TACF_262KHZ = 0b00000001 + + .IF = 0x0F ; Interrupt flags: 0.0.0.JST.SIO.TIM.LCD.VBL + rIF = 0xFF0F + + .NR10 = 0x10 ; Sound register + rNR10 = 0xFF10 + rAUD1SWEEP = 0xFF10 + + AUD1SWEEP_UP = 0b00000000 + AUD1SWEEP_DOWN = 0b00001000 + + .NR11 = 0x11 ; Sound register + rNR11 = 0xFF11 + rAUD1LEN = 0xFF11 + + .NR12 = 0x12 ; Sound register + rNR12 = 0xFF12 + rAUD1ENV = 0xFF12 + + .NR13 = 0x13 ; Sound register + rNR13 = 0xFF13 + rAUD1LOW = 0xFF13 + + .NR14 = 0x14 ; Sound register + rNR14 = 0xFF14 + rAUD1HIGH = 0xFF14 + + .NR21 = 0x16 ; Sound register + rNR21 = 0xFF16 + rAUD2LEN = 0xFF16 + + .NR22 = 0x17 ; Sound register + rNR22 = 0xFF17 + rAUD2ENV = 0xFF17 + + .NR23 = 0x18 ; Sound register + rNR23 = 0xFF18 + rAUD2LOW = 0xFF18 + + .NR24 = 0x19 ; Sound register + rNR24 = 0xFF19 + rAUD2HIGH = 0xFF19 + + .NR30 = 0x1A ; Sound register + rNR30 = 0xFF1A + rAUD3ENA = 0xFF1A + + .NR31 = 0x1B ; Sound register + rNR31 = 0xFF1B + rAUD3LEN = 0xFF1B + + .NR32 = 0x1C ; Sound register + rNR32 = 0xFF1C + rAUD3LEVEL = 0xFF1C + + .NR33 = 0x1D ; Sound register + rNR33 = 0xFF1D + rAUD3LOW = 0xFF1D + + .NR34 = 0x1E ; Sound register + rNR34 = 0xFF1E + rAUD3HIGH = 0xFF1E + + .NR41 = 0x20 ; Sound register + rNR41 = 0xFF20 + rAUD4LEN = 0xFF20 + + .NR42 = 0x21 ; Sound register + rNR42 = 0xFF21 + rAUD4ENV = 0xFF21 + + .NR43 = 0x22 ; Sound register + rNR43 = 0xFF22 + rAUD4POLY = 0xFF22 + + .NR44 = 0x23 ; Sound register + rNR44 = 0xFF23 + rAUD4GO = 0xFF23 + + .NR50 = 0x24 ; Sound register + rNR50 = 0xFF24 + rAUDVOL = 0xFF24 + + AUDVOL_VIN_LEFT = 0b10000000 ; SO2 + AUDVOL_VIN_RIGHT = 0b00001000 ; SO1 + + .NR51 = 0x25 ; Sound register + rNR51 = 0xFF25 + rAUDTERM = 0xFF25 + + AUDTERM_4_LEFT = 0b10000000 + AUDTERM_3_LEFT = 0b01000000 + AUDTERM_2_LEFT = 0b00100000 + AUDTERM_1_LEFT = 0b00010000 + AUDTERM_4_RIGHT = 0b00001000 + AUDTERM_3_RIGHT = 0b00000100 + AUDTERM_2_RIGHT = 0b00000010 + AUDTERM_1_RIGHT = 0b00000001 + + .NR52 = 0x26 ; Sound register + rNR52 = 0xFF26 + rAUDENA = 0xFF26 + + AUDENA_ON = 0b10000000 + AUDENA_OFF = 0b00000000 ; sets all audio regs to 0! + + .LCDC = 0x4E ; LCD control + rLCDC = 0xFF4E + + LCDCF_OFF = 0b00000000 ; LCD Control Operation + LCDCF_ON = 0b00000001 ; LCD Control Operation + LCDCF_WIN9800 = 0b00000000 ; Window Tile Map Display Select + LCDCF_WIN9C00 = 0b00000010 ; Window Tile Map Display Select + LCDCF_WINOFF = 0b00000000 ; Window Display + LCDCF_WINON = 0b00000100 ; Window Display + LCDCF_BG8800 = 0b00000000 ; BG & Window Tile Data Select + LCDCF_BG8000 = 0b00001000 ; BG & Window Tile Data Select + LCDCF_BG9800 = 0b00000000 ; BG Tile Map Display Select + LCDCF_BG9C00 = 0b00010000 ; BG Tile Map Display Select + LCDCF_OBJ8 = 0b00000000 ; OBJ Construction + LCDCF_OBJ16 = 0b00100000 ; OBJ Construction + LCDCF_OBJOFF = 0b00000000 ; OBJ Display + LCDCF_OBJON = 0b01000000 ; OBJ Display + LCDCF_BGOFF = 0b00000000 ; BG Display + LCDCF_BGON = 0b10000000 ; BG Display + LCDCF_B_ON = 0 + LCDCF_B_WIN9C00 = 1 + LCDCF_B_WINON = 2 + LCDCF_B_BG8000 = 3 + LCDCF_B_BG9C00 = 4 + LCDCF_B_OBJ16 = 5 + LCDCF_B_OBJON = 6 + LCDCF_B_BGON = 7 + + .STAT = 0x41 ; LCD status + rSTAT = 0xFF41 + + STATF_LYC = 0b00000010 ; LYC=LY Coincidence (Selectable) + STATF_MODE10 = 0b00000100 ; Mode 10 + STATF_MODE01 = 0b00001000 ; Mode 01 (V-Blank) + STATF_MODE00 = 0b00010000 ; Mode 00 (H-Blank) + STATF_LYCF = 0b00100000 ; Coincidence Flag + STATF_HBL = 0b00000000 ; H-Blank + STATF_VBL = 0b10000000 ; V-Blank + STATF_OAM = 0b01000000 ; OAM-RAM is used by system + STATF_LCD = 0b11000000 ; Both OAM and VRAM used by system + STATF_BUSY = 0b01000000 ; When set, VRAM access is unsafe + STATF_B_LYC = 1 + STATF_B_MODE10 = 2 + STATF_B_MODE01 = 3 + STATF_B_MODE00 = 4 + STATF_B_LYCF = 5 + STATF_B_VBL = 7 + STATF_B_OAM = 6 + STATF_B_BUSY = 6 + + .SCY = 0x42 ; Scroll Y + rSCY = 0xFF42 + + .SCX = 0x43 ; Scroll X + rSCX = 0xFF43 + + .LY = 0x44 ; LCDC Y-coordinate + rLY = 0xFF44 + + .LYC = 0x45 ; LY compare + rLYC = 0xFF45 + + .DMA = 0x46 ; DMA transfer + rDMA = 0xFF46 + + .BGP = 0x47 ; BG palette data + rBGP = 0xFF47 + + .OBP0 = 0x48 ; OBJ palette 0 data + rOBP0 = 0xFF48 + + .OBP1 = 0x49 ; OBJ palette 1 data + rOBP1 = 0xFF49 + + .WY = 0x4A ; Window Y coordinate + rWY = 0xFF4A + + .WX = 0x4B ; Window X coordinate + rWX = 0xFF4B + + .KEY1 = 0x4D ; CPU speed + rKEY1 = 0xFF4D + rSPD = 0xFF4D + + KEY1F_DBLSPEED = 0b10000000 ; 0=Normal Speed, 1=Double Speed (R) + KEY1F_PREPARE = 0b00000001 ; 0=No, 1=Prepare (R/W) + + .VBK = 0x4F ; VRAM bank + rVBK = 0xFF4F + + .HDMA1 = 0x51 ; DMA control 1 + rHDMA1 = 0xFF51 + + .HDMA2 = 0x52 ; DMA control 2 + rHDMA2 = 0xFF52 + + .HDMA3 = 0x53 ; DMA control 3 + rHDMA3 = 0xFF53 + + .HDMA4 = 0x54 ; DMA control 4 + rHDMA4 = 0xFF54 + + .HDMA5 = 0x55 ; DMA control 5 + rHDMA5 = 0xFF55 + + HDMA5F_MODE_GP = 0b00000000 ; General Purpose DMA (W) + HDMA5F_MODE_HBL = 0b10000000 ; HBlank DMA (W) + + HDMA5F_BUSY = 0b10000000 ; 0=Busy (DMA still in progress), 1=Transfer complete (R) + + .RP = 0x56 ; IR port + rRP = 0xFF56 + + RPF_ENREAD = 0b11000000 + RPF_DATAIN = 0b00000010 ; 0=Receiving IR Signal, 1=Normal + RPF_WRITE_HI = 0b00000001 + RPF_WRITE_LO = 0b00000000 + + .BCPS = 0x68 ; BG color palette specification + rBCPS = 0xFF68 + + BCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) + + .BCPD = 0x69 ; BG color palette data + rBCPD = 0xFF69 + + .OCPS = 0x6A ; OBJ color palette specification + rOCPS = 0xFF6A + + OCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) + + .OCPD = 0x6B ; OBJ color palette data + rOCPD = 0xFF6B + + .SVBK = 0x70 ; WRAM bank + rSVBK = 0xFF70 + rSMBK = 0xFF70 + + rPCM12 = 0xFF76 + + rPCM34 = 0xFF77 + + .IE = 0xFF ; Interrupt enable + rIE = 0xFFFF + + .VBL_IFLAG = 0x01 + .LCD_IFLAG = 0x02 + .TIM_IFLAG = 0x04 + .SIO_IFLAG = 0x08 + .JOY_IFLAG = 0x10 + + IEF_HILO = 0b00010000 ; Transition from High to Low of Pin number P10-P13 + IEF_SERIAL = 0b00001000 ; Serial I/O transfer end + IEF_TIMER = 0b00000100 ; Timer Overflow + IEF_STAT = 0b00000010 ; STAT + IEF_VBLANK = 0b00000001 ; V-Blank + + ;; Flags common to multiple sound channels + + AUDLEN_DUTY_12_5 = 0b00000000 ; 12.5% + AUDLEN_DUTY_25 = 0b01000000 ; 25% + AUDLEN_DUTY_50 = 0b10000000 ; 50% + AUDLEN_DUTY_75 = 0b11000000 ; 75% + + AUDENV_UP = 0b00001000 + AUDENV_DOWN = 0b00000000 + + AUDHIGH_RESTART = 0b10000000 + AUDHIGH_LENGTH_ON = 0b01000000 + AUDHIGH_LENGTH_OFF = 0b00000000 + + ;; OAM related constants + + OAM_COUNT = 40 ; number of OAM entries in OAM RAM + + OAMF_PRI = 0b10000000 ; Priority + OAMF_YFLIP = 0b01000000 ; Y flip + OAMF_XFLIP = 0b00100000 ; X flip + OAMF_PAL0 = 0b00000000 ; Palette number; 0,1 (DMG) + OAMF_PAL1 = 0b00010000 ; Palette number; 0,1 (DMG) + OAMF_BANK0 = 0b00000000 ; Bank number; 0,1 (GBC) + OAMF_BANK1 = 0b00001000 ; Bank number; 0,1 (GBC) + + OAMF_PALMASK = 0b00000111 ; Palette (GBC) + + OAMB_PRI = 7 ; Priority + OAMB_YFLIP = 6 ; Y flip + OAMB_XFLIP = 5 ; X flip + OAMB_PAL1 = 4 ; Palette number; 0,1 (DMG) + OAMB_BANK1 = 3 ; Bank number; 0,1 (GBC) + + ;; SGB packets + .PAL_01 = 0x00 + .PAL_23 = 0x01 + .PAL_03 = 0x02 + .PAL_12 = 0x03 + .ATTR_BLK = 0x04 + .ATTR_LIN = 0x05 + .ATTR_DIV = 0x06 + .ATTR_CHR = 0x07 + .SOUND = 0x08 + .SOU_TRN = 0x09 + .PAL_SET = 0x0A + .PAL_TRN = 0x0B + .ATRC_EN = 0x0C + .TEST_EN = 0x0D + .ICON_EN = 0x0E + .DATA_SND = 0x0F + .DATA_TRN = 0x10 + .MLT_REQ = 0x11 + .JUMP = 0x12 + .CHR_TRN = 0x13 + .PCT_TRN = 0x14 + .ATTR_TRN = 0x15 + .ATTR_SET = 0x16 + .MASK_EN = 0x17 + .OBJ_TRN = 0x18 + + ;; CPU detection + .DMG_TYPE = 0x01 ; Original GB or Super GB + .MGB_TYPE = 0xFF ; Pocket GB or Super GB 2 + .CGB_TYPE = 0x11 ; Color GB + + ;; GBDK library screen modes + + .G_MODE = 0x01 ; Graphic mode + .T_MODE = 0x02 ; Text mode (bit 2) + .T_MODE_OUT = 0x02 ; Text mode output only + .T_MODE_INOUT = 0x03 ; Text mode with input + .M_NO_SCROLL = 0x04 ; Disables scrolling of the screen in text mode + .M_NO_INTERP = 0x08 ; Disables special character interpretation + + ;; Status codes for IO + .IO_IDLE = 0x00 + .IO_SENDING = 0x01 + .IO_RECEIVING = 0x02 + .IO_ERROR = 0x04 + + ;; Type of IO data + .DT_IDLE = 0x66 + .DT_RECEIVING = 0x55 + + ;; Table of routines for modes + .MODE_TABLE = 0x01E0 + + ;; C related + ;; Overheap of a banked call. Used for parameters + ;; = ret + real ret + bank + + .if .NEAR_CALLS + .BANKOV = 2 + + .else + .BANKOV = 6 + + .endif + + .globl __current_bank + .globl __shadow_OAM_base + + ;; Global variables + .globl .mode + + .globl __cpu + .globl __is_GBA + + ;; Global routines +; .globl .set_mode ;; don't link mode.o by default + + .globl .reset + + .globl .display_off + + .globl .wait_vbl_done + + ;; Interrupt routines + .globl .add_VBL +; .globl .add_LCD ;; don't link LCD.o by default +; .globl .add_TIM ;; don't link TIM.o by default +; .globl .add_SIO ;; don't link serial.o by default +; .globl .add_JOY ;; don't link JOY.o by default + + ;; Symbols defined at link time + .globl .STACK + .globl _shadow_OAM + .globl .refresh_OAM + + ;; Main user routine + .globl _main + + ;; Macro definitions + +.macro WAIT_STAT ?lbl +lbl: LDH A, (.STAT) + AND #STATF_BUSY ; Check if in LCD modes 0 or 1 + JR NZ, lbl +.endm + +.macro ADD_A_REG16 regH regL + ADD regL + LD regL, A + ADC regH + SUB regL + LD regH, A +.endm + +.macro SIGNED_ADD_A_REG16 regH regL ?lbl + ; If A is negative, we need to subtract 1 from upper byte of 16-bit value + BIT 7, A ; set z if a signed bit is 0 + JR Z, lbl ; if z is set jump to positive + dec regH ; if negative decrement upper byte +lbl: + ADD_A_REG16 regH, regL +.endm + +.macro SIGNED_SUB_A_REG16 regH regL ?lbl + ; negate A then add to 16-bit value + CPL + INC A + SIGNED_ADD_A_REG16 regH, regL +.endm + +.macro MUL_DE_BY_A_RET_HL ?lbl1 ?lbl2 ?lbl3 + ; Multiply DE by A, return result in HL; preserves: BC + LD HL, #0 +lbl1: + SRL A + JR NC, lbl2 + ADD HL, DE +lbl2: + JR Z, lbl3 + SLA E + RL D + JR lbl1 +lbl3: +.endm + diff --git a/gbdk-lib/libc/targets/gbz80/ap/sfr.s b/gbdk-lib/libc/targets/sm83/ap/sfr.s diff --git a/gbdk-lib/libc/targets/gbz80/cgb.s b/gbdk-lib/libc/targets/sm83/cgb.s diff --git a/gbdk-lib/libc/targets/gbz80/cgb_compat.s b/gbdk-lib/libc/targets/sm83/cgb_compat.s diff --git a/gbdk-lib/libc/targets/gbz80/cgb_palettes.s b/gbdk-lib/libc/targets/sm83/cgb_palettes.s diff --git a/gbdk-lib/libc/targets/gbz80/clock.s b/gbdk-lib/libc/targets/sm83/clock.s diff --git a/gbdk-lib/libc/targets/gbz80/color.s b/gbdk-lib/libc/targets/sm83/color.s diff --git a/gbdk-lib/libc/targets/gbz80/cpy_data.s b/gbdk-lib/libc/targets/sm83/cpy_data.s diff --git a/gbdk-lib/libc/targets/gbz80/crlf.c b/gbdk-lib/libc/targets/sm83/crlf.c diff --git a/gbdk-lib/libc/targets/gbz80/delay.s b/gbdk-lib/libc/targets/sm83/delay.s diff --git a/gbdk-lib/libc/targets/gbz80/digits.c b/gbdk-lib/libc/targets/sm83/digits.c diff --git a/gbdk-lib/libc/targets/gbz80/drawing.s b/gbdk-lib/libc/targets/sm83/drawing.s diff --git a/gbdk-lib/libc/targets/gbz80/drawing_isr.s b/gbdk-lib/libc/targets/sm83/drawing_isr.s diff --git a/gbdk-lib/libc/targets/sm83/duck/Makefile b/gbdk-lib/libc/targets/sm83/duck/Makefile @@ -0,0 +1,47 @@ +# GB specific Makefile + +TOPDIR = ../../../.. + +THIS = duck +PORT = sm83 + +CSRC = crlf.c digits.c gprint.c gprintf.c gprintln.c gprintn.c + +ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ + cpy_data.s \ + drawing.s drawing_isr.s color.s \ + f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ + get_bk_t.s get_data.s get_tile.s \ + get_wi_t.s get_xy_t.s \ + get_addr.s \ + hiramcpy.s init_tt.s input.s \ + pad.s \ + serial.s set_bk_t.s set_tile.s \ + set_data.s set_prop.s set_spr.s set_wi_t.s set_xy_t.s \ + set_1bit_data.s \ + sgb.s font.s font_color.s delay.s \ + emu_debug.s emu_debug_printf.s \ + nowait.s far_ptr.s \ + lcd.s joy.s tim.s tim.s tim_nested.s tim_common.s \ + crash_handler.s \ + ___sdcc_bcall_ehl.s ___sdcc_bcall.s \ + mv_spr.s \ + pad_ex.s \ + mode.s clock.s \ + get_t.s set_t.s init_vram.s \ + fill_rect.s fill_rect_bk.s fill_rect_wi.s \ + metasprites.s metasprites_flip.s metasprites_hide.s metasprites_hide_spr.s \ + set_tile_submap.s set_win_tile_submap.s \ + gb_decompress.s gb_decompress_tiles.s \ + rle_decompress.s \ + heap.s \ + sfr.s \ + crt0.s + +CRT0 = crt0.s + +include $(TOPDIR)/Makefile.common + +AS = $(AS_SM83) + +include ../../../Makefile.platform diff --git a/gbdk-lib/libc/targets/gbz80/duck/crash_handler.s b/gbdk-lib/libc/targets/sm83/duck/crash_handler.s diff --git a/gbdk-lib/libc/targets/gbz80/duck/crt0.s b/gbdk-lib/libc/targets/sm83/duck/crt0.s diff --git a/gbdk-lib/libc/targets/sm83/duck/global.s b/gbdk-lib/libc/targets/sm83/duck/global.s @@ -0,0 +1,533 @@ + .NEAR_CALLS = 1 ; <near_calls> - tag so that sed can change this + + _VRAM = 0x8000 ; $8000->$9FFF + _VRAM8000 = 0x8000 + _VRAM8800 = 0x8800 + _VRAM9000 = 0x9000 + _SCRN0 = 0x9800 ; $9800->$9BFF + _SCRN1 = 0x9C00 ; $9C00->$9FFF + _SRAM = 0xA000 ; $A000->$BFFF + _RAM = 0xC000 ; $C000->$CFFF / $C000->$DFFF + _RAMBANK = 0xD000 ; $D000->$DFFF + _OAMRAM = 0xFE00 ; $FE00->$FE9F + _IO = 0xFF00 ; $FF00->$FF7F,$FFFF + _AUD3WAVERAM = 0xFF30 ; $FF30->$FF3F + _HRAM = 0xFF80 ; $FF80->$FFFE + + ;; MBC Equates + + .MBC1_ROM_PAGE = 0x2000 ; Address to write to for MBC1 switching + .MBC_ROM_PAGE = 0x0001 ; Default platform MBC rom switching address + + rRAMG = 0x0000 ; $0000->$1fff + rROMB0 = 0x0001 ; $2000->$2fff + rROMB1 = 0x3000 ; $3000->$3fff - If more than 256 ROM banks are present. + rRAMB = 0x4000 ; $4000->$5fff - Bit 3 enables rumble (if present) + + ;; Keypad + .START = 0x80 + .SELECT = 0x40 + .B = 0x20 + .A = 0x10 + .DOWN = 0x08 + .UP = 0x04 + .LEFT = 0x02 + .RIGHT = 0x01 + + .P14 = 0x10 + .P15 = 0x20 + + ;; Screen dimensions + .MAXCURSPOSX = 0x13 ; In tiles + .MAXCURSPOSY = 0x11 + + .SCREENWIDTH = 0xA0 + .SCREENHEIGHT = 0x90 + .MINWNDPOSX = 0x07 + .MINWNDPOSY = 0x00 + .MAXWNDPOSX = 0xA6 + .MAXWNDPOSY = 0x8F + + ;; Hardware registers + + .P1 = 0x00 ; Joystick: 1.1.P15.P14.P13.P12.P11.P10 + rP1 = 0xFF00 + + P1F_5 = 0b00100000 ; P15 out port, set to 0 to get buttons + P1F_4 = 0b00010000 ; P14 out port, set to 0 to get dpad + P1F_3 = 0b00001000 ; P13 in port + P1F_2 = 0b00000100 ; P12 in port + P1F_1 = 0b00000010 ; P11 in port + P1F_0 = 0b00000001 ; P10 in port + + P1F_GET_DPAD = 0b00100000 + P1F_GET_BTN = 0b00010000 + P1F_GET_NONE = 0b00110000 + + .SB = 0x01 ; Serial IO data buffer + rSB = 0xFF01 + + .SC = 0x02 ; Serial IO control register + rSC = 0xFF02 + + .DIV = 0x04 ; Divider register + rDIV = 0xFF04 + + .TIMA = 0x05 ; Timer counter + rTIMA = 0xFF05 + + .TMA = 0x06 ; Timer modulo + rTMA = 0xFF06 + + .TAC = 0x07 ; Timer control + rTAC = 0xFF07 + + TACF_START = 0b00000100 + TACF_STOP = 0b00000000 + TACF_4KHZ = 0b00000000 + TACF_16KHZ = 0b00000011 + TACF_65KHZ = 0b00000010 + TACF_262KHZ = 0b00000001 + + .IF = 0x0F ; Interrupt flags: 0.0.0.JST.SIO.TIM.LCD.VBL + rIF = 0xFF0F + + .NR10 = 0x20 ; Sound register + rNR10 = 0xFF20 + rAUD1SWEEP = 0xFF20 + + AUD1SWEEP_UP = 0b00000000 + AUD1SWEEP_DOWN = 0b00001000 + + .NR11 = 0x22 ; Sound register + rNR11 = 0xFF22 + rAUD1LEN = 0xFF22 + + .NR12 = 0x21 ; Sound register + rNR12 = 0xFF21 + rAUD1ENV = 0xFF21 + + .NR13 = 0x23 ; Sound register + rNR13 = 0xFF23 + rAUD1LOW = 0xFF23 + + .NR14 = 0x24 ; Sound register + rNR14 = 0xFF24 + rAUD1HIGH = 0xFF24 + + .NR21 = 0x25 ; Sound register + rNR21 = 0xFF25 + rAUD2LEN = 0xFF25 + + .NR22 = 0x27 ; Sound register + rNR22 = 0xFF27 + rAUD2ENV = 0xFF27 + + .NR23 = 0x28 ; Sound register + rNR23 = 0xFF28 + rAUD2LOW = 0xFF28 + + .NR24 = 0x29 ; Sound register + rNR24 = 0xFF29 + rAUD2HIGH = 0xFF29 + + .NR30 = 0x2A ; Sound register + rNR30 = 0xFF2A + rAUD3ENA = 0xFF2A + + .NR31 = 0x2B ; Sound register + rNR31 = 0xFF2B + rAUD3LEN = 0xFF2B + + .NR32 = 0x2C ; Sound register + rNR32 = 0xFF2C + rAUD3LEVEL = 0xFF2C + + .NR33 = 0x2E ; Sound register + rNR33 = 0xFF2E + rAUD3LOW = 0xFF2E + + .NR34 = 0x2D ; Sound register + rNR34 = 0xFF2D + rAUD3HIGH = 0xFF2D + + .NR41 = 0x40 ; Sound register + rNR41 = 0xFF40 + rAUD4LEN = 0xFF40 + + .NR42 = 0x42 ; Sound register + rNR42 = 0xFF42 + rAUD4ENV = 0xFF42 + + .NR43 = 0x41 ; Sound register + rNR43 = 0xFF41 + rAUD4POLY = 0xFF41 + + .NR44 = 0x43 ; Sound register + rNR44 = 0xFF43 + rAUD4GO = 0xFF43 + + .NR50 = 0x44 ; Sound register + rNR50 = 0xFF44 + rAUDVOL = 0xFF44 + + AUDVOL_VIN_LEFT = 0b10000000 ; SO2 + AUDVOL_VIN_RIGHT = 0b00001000 ; SO1 + + .NR51 = 0x46 ; Sound register + rNR51 = 0xFF46 + rAUDTERM = 0xFF46 + + AUDTERM_4_LEFT = 0b10000000 + AUDTERM_3_LEFT = 0b01000000 + AUDTERM_2_LEFT = 0b00100000 + AUDTERM_1_LEFT = 0b00010000 + AUDTERM_4_RIGHT = 0b00001000 + AUDTERM_3_RIGHT = 0b00000100 + AUDTERM_2_RIGHT = 0b00000010 + AUDTERM_1_RIGHT = 0b00000001 + + .NR52 = 0x45 ; Sound register + rNR52 = 0xFF45 + rAUDENA = 0xFF45 + + AUDENA_ON = 0b10000000 + AUDENA_OFF = 0b00000000 ; sets all audio regs to 0! + + .LCDC = 0x10 ; LCD control + rLCDC = 0xFF10 + + LCDCF_OFF = 0b00000000 ; LCD Control Operation + LCDCF_ON = 0b10000000 ; LCD Control Operation + LCDCF_WIN9800 = 0b00000000 ; Window Tile Map Display Select + LCDCF_WIN9C00 = 0b00001000 ; Window Tile Map Display Select + LCDCF_WINOFF = 0b00000000 ; Window Display + LCDCF_WINON = 0b00100000 ; Window Display + LCDCF_BG8800 = 0b00000000 ; BG & Window Tile Data Select + LCDCF_BG8000 = 0b00010000 ; BG & Window Tile Data Select + LCDCF_BG9800 = 0b00000000 ; BG Tile Map Display Select + LCDCF_BG9C00 = 0b00000100 ; BG Tile Map Display Select + LCDCF_OBJ8 = 0b00000000 ; OBJ Construction + LCDCF_OBJ16 = 0b00000010 ; OBJ Construction + LCDCF_OBJOFF = 0b00000000 ; OBJ Display + LCDCF_OBJON = 0b00000001 ; OBJ Display + LCDCF_BGOFF = 0b00000000 ; BG Display + LCDCF_BGON = 0b01000000 ; BG Display + LCDCF_B_ON = 7 + LCDCF_B_WIN9C00 = 3 + LCDCF_B_WINON = 5 + LCDCF_B_BG8000 = 4 + LCDCF_B_BG9C00 = 2 + LCDCF_B_OBJ16 = 1 + LCDCF_B_OBJON = 0 + LCDCF_B_BGON = 6 + + .STAT = 0x11 ; LCD status + rSTAT = 0xFF11 + + STATF_LYC = 0b01000000 ; LYC=LY Coincidence (Selectable) + STATF_MODE10 = 0b00100000 ; Mode 10 + STATF_MODE01 = 0b00010000 ; Mode 01 (V-Blank) + STATF_MODE00 = 0b00001000 ; Mode 00 (H-Blank) + STATF_LYCF = 0b00000100 ; Coincidence Flag + STATF_HBL = 0b00000000 ; H-Blank + STATF_VBL = 0b00000001 ; V-Blank + STATF_OAM = 0b00000010 ; OAM-RAM is used by system + STATF_LCD = 0b00000011 ; Both OAM and VRAM used by system + STATF_BUSY = 0b00000010 ; When set, VRAM access is unsafe + STATF_B_LYC = 6 + STATF_B_MODE10 = 5 + STATF_B_MODE01 = 4 + STATF_B_MODE00 = 3 + STATF_B_LYCF = 2 + STATF_B_VBL = 0 + STATF_B_OAM = 1 + STATF_B_BUSY = 1 + + .SCY = 0x12 ; Scroll Y + rSCY = 0xFF12 + + .SCX = 0x13 ; Scroll X + rSCX = 0xFF13 + + .LY = 0x18 ; LCDC Y-coordinate + rLY = 0xFF18 + + .LYC = 0x19 ; LY compare + rLYC = 0xFF19 + + .DMA = 0x1A ; DMA transfer + rDMA = 0xFF1A + + .BGP = 0x1B ; BG palette data + rBGP = 0xFF1B + + .OBP0 = 0x14 ; OBJ palette 0 data + rOBP0 = 0xFF14 + + .OBP1 = 0x15 ; OBJ palette 1 data + rOBP1 = 0xFF15 + + .WY = 0x16 ; Window Y coordinate + rWY = 0xFF16 + + .WX = 0x17 ; Window X coordinate + rWX = 0xFF17 + + .KEY1 = 0x4D ; CPU speed + rKEY1 = 0xFF4D + rSPD = 0xFF4D + + KEY1F_DBLSPEED = 0b10000000 ; 0=Normal Speed, 1=Double Speed (R) + KEY1F_PREPARE = 0b00000001 ; 0=No, 1=Prepare (R/W) + + .VBK = 0x4F ; VRAM bank + rVBK = 0xFF4F + + .HDMA1 = 0x51 ; DMA control 1 + rHDMA1 = 0xFF51 + + .HDMA2 = 0x52 ; DMA control 2 + rHDMA2 = 0xFF52 + + .HDMA3 = 0x53 ; DMA control 3 + rHDMA3 = 0xFF53 + + .HDMA4 = 0x54 ; DMA control 4 + rHDMA4 = 0xFF54 + + .HDMA5 = 0x55 ; DMA control 5 + rHDMA5 = 0xFF55 + + HDMA5F_MODE_GP = 0b00000000 ; General Purpose DMA (W) + HDMA5F_MODE_HBL = 0b10000000 ; HBlank DMA (W) + + HDMA5F_BUSY = 0b10000000 ; 0=Busy (DMA still in progress), 1=Transfer complete (R) + + .RP = 0x56 ; IR port + rRP = 0xFF56 + + RPF_ENREAD = 0b11000000 + RPF_DATAIN = 0b00000010 ; 0=Receiving IR Signal, 1=Normal + RPF_WRITE_HI = 0b00000001 + RPF_WRITE_LO = 0b00000000 + + .BCPS = 0x68 ; BG color palette specification + rBCPS = 0xFF68 + + BCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) + + .BCPD = 0x69 ; BG color palette data + rBCPD = 0xFF69 + + .OCPS = 0x6A ; OBJ color palette specification + rOCPS = 0xFF6A + + OCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) + + .OCPD = 0x6B ; OBJ color palette data + rOCPD = 0xFF6B + + .SVBK = 0x70 ; WRAM bank + rSVBK = 0xFF70 + rSMBK = 0xFF70 + + rPCM12 = 0xFF76 + + rPCM34 = 0xFF77 + + .IE = 0xFF ; Interrupt enable + rIE = 0xFFFF + + .VBL_IFLAG = 0x01 + .LCD_IFLAG = 0x02 + .TIM_IFLAG = 0x04 + .SIO_IFLAG = 0x08 + .JOY_IFLAG = 0x10 + + IEF_HILO = 0b00010000 ; Transition from High to Low of Pin number P10-P13 + IEF_SERIAL = 0b00001000 ; Serial I/O transfer end + IEF_TIMER = 0b00000100 ; Timer Overflow + IEF_STAT = 0b00000010 ; STAT + IEF_VBLANK = 0b00000001 ; V-Blank + + ;; Flags common to multiple sound channels + + AUDLEN_DUTY_12_5 = 0b00000000 ; 12.5% + AUDLEN_DUTY_25 = 0b01000000 ; 25% + AUDLEN_DUTY_50 = 0b10000000 ; 50% + AUDLEN_DUTY_75 = 0b11000000 ; 75% + + AUDENV_UP = 0b00001000 + AUDENV_DOWN = 0b00000000 + + AUDHIGH_RESTART = 0b10000000 + AUDHIGH_LENGTH_ON = 0b01000000 + AUDHIGH_LENGTH_OFF = 0b00000000 + + ;; OAM related constants + + OAM_COUNT = 40 ; number of OAM entries in OAM RAM + + OAMF_PRI = 0b10000000 ; Priority + OAMF_YFLIP = 0b01000000 ; Y flip + OAMF_XFLIP = 0b00100000 ; X flip + OAMF_PAL0 = 0b00000000 ; Palette number; 0,1 (DMG) + OAMF_PAL1 = 0b00010000 ; Palette number; 0,1 (DMG) + OAMF_BANK0 = 0b00000000 ; Bank number; 0,1 (GBC) + OAMF_BANK1 = 0b00001000 ; Bank number; 0,1 (GBC) + + OAMF_PALMASK = 0b00000111 ; Palette (GBC) + + OAMB_PRI = 7 ; Priority + OAMB_YFLIP = 6 ; Y flip + OAMB_XFLIP = 5 ; X flip + OAMB_PAL1 = 4 ; Palette number; 0,1 (DMG) + OAMB_BANK1 = 3 ; Bank number; 0,1 (GBC) + + ;; SGB packets + .PAL_01 = 0x00 + .PAL_23 = 0x01 + .PAL_03 = 0x02 + .PAL_12 = 0x03 + .ATTR_BLK = 0x04 + .ATTR_LIN = 0x05 + .ATTR_DIV = 0x06 + .ATTR_CHR = 0x07 + .SOUND = 0x08 + .SOU_TRN = 0x09 + .PAL_SET = 0x0A + .PAL_TRN = 0x0B + .ATRC_EN = 0x0C + .TEST_EN = 0x0D + .ICON_EN = 0x0E + .DATA_SND = 0x0F + .DATA_TRN = 0x10 + .MLT_REQ = 0x11 + .JUMP = 0x12 + .CHR_TRN = 0x13 + .PCT_TRN = 0x14 + .ATTR_TRN = 0x15 + .ATTR_SET = 0x16 + .MASK_EN = 0x17 + .OBJ_TRN = 0x18 + + ;; CPU detection + .DMG_TYPE = 0x01 ; Original GB or Super GB + .MGB_TYPE = 0xFF ; Pocket GB or Super GB 2 + .CGB_TYPE = 0x11 ; Color GB + + ;; GBDK library screen modes + + .G_MODE = 0x01 ; Graphic mode + .T_MODE = 0x02 ; Text mode (bit 2) + .T_MODE_OUT = 0x02 ; Text mode output only + .T_MODE_INOUT = 0x03 ; Text mode with input + .M_NO_SCROLL = 0x04 ; Disables scrolling of the screen in text mode + .M_NO_INTERP = 0x08 ; Disables special character interpretation + + ;; Status codes for IO + .IO_IDLE = 0x00 + .IO_SENDING = 0x01 + .IO_RECEIVING = 0x02 + .IO_ERROR = 0x04 + + ;; Type of IO data + .DT_IDLE = 0x66 + .DT_RECEIVING = 0x55 + + ;; Table of routines for modes + .MODE_TABLE = 0x01E0 + + ;; C related + ;; Overheap of a banked call. Used for parameters + ;; = ret + real ret + bank + + .if .NEAR_CALLS + .BANKOV = 2 + + .else + .BANKOV = 6 + + .endif + + .globl __current_bank + .globl __shadow_OAM_base + + ;; Global variables + .globl .mode + + .globl __cpu + .globl __is_GBA + + ;; Global routines +; .globl .set_mode ;; don't link mode.o by default + + .globl .reset + + .globl .display_off + + .globl .wait_vbl_done + + ;; Interrupt routines + .globl .add_VBL +; .globl .add_LCD ;; don't link LCD.o by default +; .globl .add_TIM ;; don't link TIM.o by default +; .globl .add_SIO ;; don't link serial.o by default +; .globl .add_JOY ;; don't link JOY.o by default + + ;; Symbols defined at link time + .globl .STACK + .globl _shadow_OAM + .globl .refresh_OAM + + ;; Main user routine + .globl _main + + ;; Macro definitions + +.macro WAIT_STAT ?lbl +lbl: LDH A, (.STAT) + AND #STATF_BUSY ; Check if in LCD modes 0 or 1 + JR NZ, lbl +.endm + +.macro ADD_A_REG16 regH regL + ADD regL + LD regL, A + ADC regH + SUB regL + LD regH, A +.endm + +.macro SIGNED_ADD_A_REG16 regH regL ?lbl + ; If A is negative, we need to subtract 1 from upper byte of 16-bit value + BIT 7, A ; set z if a signed bit is 0 + JR Z, lbl ; if z is set jump to positive + dec regH ; if negative decrement upper byte +lbl: + ADD_A_REG16 regH, regL +.endm + +.macro SIGNED_SUB_A_REG16 regH regL ?lbl + ; negate A then add to 16-bit value + CPL + INC A + SIGNED_ADD_A_REG16 regH, regL +.endm + +.macro MUL_DE_BY_A_RET_HL ?lbl1 ?lbl2 ?lbl3 + ; Multiply DE by A, return result in HL; preserves: BC + LD HL, #0 +lbl1: + SRL A + JR NC, lbl2 + ADD HL, DE +lbl2: + JR Z, lbl3 + SLA E + RL D + JR lbl1 +lbl3: +.endm + diff --git a/gbdk-lib/libc/targets/gbz80/duck/sfr.s b/gbdk-lib/libc/targets/sm83/duck/sfr.s diff --git a/gbdk-lib/libc/targets/gbz80/emu_debug.s b/gbdk-lib/libc/targets/sm83/emu_debug.s diff --git a/gbdk-lib/libc/targets/gbz80/emu_debug_printf.s b/gbdk-lib/libc/targets/sm83/emu_debug_printf.s diff --git a/gbdk-lib/libc/targets/gbz80/f_ibm_full.s b/gbdk-lib/libc/targets/sm83/f_ibm_full.s diff --git a/gbdk-lib/libc/targets/gbz80/f_ibm_sh.s b/gbdk-lib/libc/targets/sm83/f_ibm_sh.s diff --git a/gbdk-lib/libc/targets/gbz80/f_italic.s b/gbdk-lib/libc/targets/sm83/f_italic.s diff --git a/gbdk-lib/libc/targets/gbz80/f_min.s b/gbdk-lib/libc/targets/sm83/f_min.s diff --git a/gbdk-lib/libc/targets/gbz80/f_spect.s b/gbdk-lib/libc/targets/sm83/f_spect.s diff --git a/gbdk-lib/libc/targets/gbz80/far_ptr.s b/gbdk-lib/libc/targets/sm83/far_ptr.s diff --git a/gbdk-lib/libc/targets/gbz80/fill_rect.s b/gbdk-lib/libc/targets/sm83/fill_rect.s diff --git a/gbdk-lib/libc/targets/gbz80/fill_rect_bk.s b/gbdk-lib/libc/targets/sm83/fill_rect_bk.s diff --git a/gbdk-lib/libc/targets/gbz80/fill_rect_wi.s b/gbdk-lib/libc/targets/sm83/fill_rect_wi.s diff --git a/gbdk-lib/libc/targets/gbz80/font.s b/gbdk-lib/libc/targets/sm83/font.s diff --git a/gbdk-lib/libc/targets/gbz80/font_color.s b/gbdk-lib/libc/targets/sm83/font_color.s diff --git a/gbdk-lib/libc/targets/sm83/gb/Makefile b/gbdk-lib/libc/targets/sm83/gb/Makefile @@ -0,0 +1,47 @@ +# GB specific Makefile + +TOPDIR = ../../../.. + +THIS = gb +PORT = sm83 + +CSRC = crlf.c digits.c gprint.c gprintf.c gprintln.c gprintn.c + +ASSRC = cgb.s cgb_palettes.s cgb_compat.s \ + cpy_data.s \ + drawing.s drawing_isr.s color.s \ + f_ibm_full.s f_ibm_sh.s f_italic.s f_min.s f_spect.s \ + get_bk_t.s get_data.s get_tile.s \ + get_wi_t.s get_xy_t.s \ + get_addr.s \ + hiramcpy.s init_tt.s input.s \ + pad.s \ + serial.s set_bk_t.s set_tile.s \ + set_data.s set_prop.s set_spr.s set_wi_t.s set_xy_t.s \ + set_1bit_data.s \ + sgb.s font.s font_color.s delay.s \ + emu_debug.s emu_debug_printf.s \ + nowait.s far_ptr.s \ + lcd.s joy.s tim.s tim.s tim_nested.s tim_common.s \ + crash_handler.s \ + ___sdcc_bcall_ehl.s ___sdcc_bcall.s \ + mv_spr.s \ + pad_ex.s \ + mode.s clock.s \ + get_t.s set_t.s init_vram.s \ + fill_rect.s fill_rect_bk.s fill_rect_wi.s \ + metasprites.s metasprites_flip.s metasprites_hide.s metasprites_hide_spr.s \ + set_tile_submap.s set_win_tile_submap.s \ + gb_decompress.s gb_decompress_tiles.s \ + rle_decompress.s \ + heap.s \ + sfr.s \ + crt0.s + +CRT0 = crt0.s + +include $(TOPDIR)/Makefile.common + +AS = $(AS_SM83) + +include ../../../Makefile.platform diff --git a/gbdk-lib/libc/targets/gbz80/gb/crash_handler.s b/gbdk-lib/libc/targets/sm83/gb/crash_handler.s diff --git a/gbdk-lib/libc/targets/gbz80/gb/crt0.s b/gbdk-lib/libc/targets/sm83/gb/crt0.s diff --git a/gbdk-lib/libc/targets/sm83/gb/global.s b/gbdk-lib/libc/targets/sm83/gb/global.s @@ -0,0 +1,532 @@ + .NEAR_CALLS = 1 ; <near_calls> - tag so that sed can change this + + _VRAM = 0x8000 ; $8000->$9FFF + _VRAM8000 = 0x8000 + _VRAM8800 = 0x8800 + _VRAM9000 = 0x9000 + _SCRN0 = 0x9800 ; $9800->$9BFF + _SCRN1 = 0x9C00 ; $9C00->$9FFF + _SRAM = 0xA000 ; $A000->$BFFF + _RAM = 0xC000 ; $C000->$CFFF / $C000->$DFFF + _RAMBANK = 0xD000 ; $D000->$DFFF + _OAMRAM = 0xFE00 ; $FE00->$FE9F + _IO = 0xFF00 ; $FF00->$FF7F,$FFFF + _AUD3WAVERAM = 0xFF30 ; $FF30->$FF3F + _HRAM = 0xFF80 ; $FF80->$FFFE + + ;; MBC Equates + + .MBC1_ROM_PAGE = 0x2000 ; Address to write to for MBC1 switching + .MBC_ROM_PAGE = 0x2000 ; Default platform MBC rom switching address + + rRAMG = 0x0000 ; $0000->$1fff + rROMB0 = 0x2000 ; $2000->$2fff + rROMB1 = 0x3000 ; $3000->$3fff - If more than 256 ROM banks are present. + rRAMB = 0x4000 ; $4000->$5fff - Bit 3 enables rumble (if present) + + ;; Keypad + .UP = 0x04 + .DOWN = 0x08 + .LEFT = 0x02 + .RIGHT = 0x01 + .A = 0x10 + .B = 0x20 + .SELECT = 0x40 + .START = 0x80 + + .P14 = 0x10 + .P15 = 0x20 + + ;; Screen dimensions + .MAXCURSPOSX = 0x13 ; In tiles + .MAXCURSPOSY = 0x11 + + .SCREENWIDTH = 0xA0 + .SCREENHEIGHT = 0x90 + .MINWNDPOSX = 0x07 + .MINWNDPOSY = 0x00 + .MAXWNDPOSX = 0xA6 + .MAXWNDPOSY = 0x8F + + ;; Hardware registers + + .P1 = 0x00 ; Joystick: 1.1.P15.P14.P13.P12.P11.P10 + rP1 = 0xFF00 + + P1F_5 = 0b00100000 ; P15 out port, set to 0 to get buttons + P1F_4 = 0b00010000 ; P14 out port, set to 0 to get dpad + P1F_3 = 0b00001000 ; P13 in port + P1F_2 = 0b00000100 ; P12 in port + P1F_1 = 0b00000010 ; P11 in port + P1F_0 = 0b00000001 ; P10 in port + + P1F_GET_DPAD = 0b00100000 + P1F_GET_BTN = 0b00010000 + P1F_GET_NONE = 0b00110000 + + .SB = 0x01 ; Serial IO data buffer + rSB = 0xFF01 + + .SC = 0x02 ; Serial IO control register + rSC = 0xFF02 + + .DIV = 0x04 ; Divider register + rDIV = 0xFF04 + + .TIMA = 0x05 ; Timer counter + rTIMA = 0xFF05 + + .TMA = 0x06 ; Timer modulo + rTMA = 0xFF06 + + .TAC = 0x07 ; Timer control + rTAC = 0xFF07 + + TACF_START = 0b00000100 + TACF_STOP = 0b00000000 + TACF_4KHZ = 0b00000000 + TACF_16KHZ = 0b00000011 + TACF_65KHZ = 0b00000010 + TACF_262KHZ = 0b00000001 + + .IF = 0x0F ; Interrupt flags: 0.0.0.JST.SIO.TIM.LCD.VBL + rIF = 0xFF0F + + .NR10 = 0x10 ; Sound register + rNR10 = 0xFF10 + rAUD1SWEEP = 0xFF10 + + AUD1SWEEP_UP = 0b00000000 + AUD1SWEEP_DOWN = 0b00001000 + + .NR11 = 0x11 ; Sound register + rNR11 = 0xFF11 + rAUD1LEN = 0xFF11 + + .NR12 = 0x12 ; Sound register + rNR12 = 0xFF12 + rAUD1ENV = 0xFF12 + + .NR13 = 0x13 ; Sound register + rNR13 = 0xFF13 + rAUD1LOW = 0xFF13 + + .NR14 = 0x14 ; Sound register + rNR14 = 0xFF14 + rAUD1HIGH = 0xFF14 + + .NR21 = 0x16 ; Sound register + rNR21 = 0xFF16 + rAUD2LEN = 0xFF16 + + .NR22 = 0x17 ; Sound register + rNR22 = 0xFF17 + rAUD2ENV = 0xFF17 + + .NR23 = 0x18 ; Sound register + rNR23 = 0xFF18 + rAUD2LOW = 0xFF18 + + .NR24 = 0x19 ; Sound register + rNR24 = 0xFF19 + rAUD2HIGH = 0xFF19 + + .NR30 = 0x1A ; Sound register + rNR30 = 0xFF1A + rAUD3ENA = 0xFF1A + + .NR31 = 0x1B ; Sound register + rNR31 = 0xFF1B + rAUD3LEN = 0xFF1B + + .NR32 = 0x1C ; Sound register + rNR32 = 0xFF1C + rAUD3LEVEL = 0xFF1C + + .NR33 = 0x1D ; Sound register + rNR33 = 0xFF1D + rAUD3LOW = 0xFF1D + + .NR34 = 0x1E ; Sound register + rNR34 = 0xFF1E + rAUD3HIGH = 0xFF1E + + .NR41 = 0x20 ; Sound register + rNR41 = 0xFF20 + rAUD4LEN = 0xFF20 + + .NR42 = 0x21 ; Sound register + rNR42 = 0xFF21 + rAUD4ENV = 0xFF21 + + .NR43 = 0x22 ; Sound register + rNR43 = 0xFF22 + rAUD4POLY = 0xFF22 + + .NR44 = 0x23 ; Sound register + rNR44 = 0xFF23 + rAUD4GO = 0xFF23 + + .NR50 = 0x24 ; Sound register + rNR50 = 0xFF24 + rAUDVOL = 0xFF24 + + AUDVOL_VIN_LEFT = 0b10000000 ; SO2 + AUDVOL_VIN_RIGHT = 0b00001000 ; SO1 + + .NR51 = 0x25 ; Sound register + rNR51 = 0xFF25 + rAUDTERM = 0xFF25 + + AUDTERM_4_LEFT = 0b10000000 + AUDTERM_3_LEFT = 0b01000000 + AUDTERM_2_LEFT = 0b00100000 + AUDTERM_1_LEFT = 0b00010000 + AUDTERM_4_RIGHT = 0b00001000 + AUDTERM_3_RIGHT = 0b00000100 + AUDTERM_2_RIGHT = 0b00000010 + AUDTERM_1_RIGHT = 0b00000001 + + .NR52 = 0x26 ; Sound register + rNR52 = 0xFF26 + rAUDENA = 0xFF26 + + AUDENA_ON = 0b10000000 + AUDENA_OFF = 0b00000000 ; sets all audio regs to 0! + + .LCDC = 0x40 ; LCD control + rLCDC = 0xFF40 + + LCDCF_OFF = 0b00000000 ; LCD Control Operation + LCDCF_ON = 0b10000000 ; LCD Control Operation + LCDCF_WIN9800 = 0b00000000 ; Window Tile Map Display Select + LCDCF_WIN9C00 = 0b01000000 ; Window Tile Map Display Select + LCDCF_WINOFF = 0b00000000 ; Window Display + LCDCF_WINON = 0b00100000 ; Window Display + LCDCF_BG8800 = 0b00000000 ; BG & Window Tile Data Select + LCDCF_BG8000 = 0b00010000 ; BG & Window Tile Data Select + LCDCF_BG9800 = 0b00000000 ; BG Tile Map Display Select + LCDCF_BG9C00 = 0b00001000 ; BG Tile Map Display Select + LCDCF_OBJ8 = 0b00000000 ; OBJ Construction + LCDCF_OBJ16 = 0b00000100 ; OBJ Construction + LCDCF_OBJOFF = 0b00000000 ; OBJ Display + LCDCF_OBJON = 0b00000010 ; OBJ Display + LCDCF_BGOFF = 0b00000000 ; BG Display + LCDCF_BGON = 0b00000001 ; BG Display + LCDCF_B_ON = 7 + LCDCF_B_WIN9C00 = 6 + LCDCF_B_WINON = 5 + LCDCF_B_BG8000 = 4 + LCDCF_B_BG9C00 = 3 + LCDCF_B_OBJ16 = 2 + LCDCF_B_OBJON = 1 + LCDCF_B_BGON = 0 + + .STAT = 0x41 ; LCD status + rSTAT = 0xFF41 + + STATF_LYC = 0b01000000 ; LYC=LY Coincidence (Selectable) + STATF_MODE10 = 0b00100000 ; Mode 10 + STATF_MODE01 = 0b00010000 ; Mode 01 (V-Blank) + STATF_MODE00 = 0b00001000 ; Mode 00 (H-Blank) + STATF_LYCF = 0b00000100 ; Coincidence Flag + STATF_HBL = 0b00000000 ; H-Blank + STATF_VBL = 0b00000001 ; V-Blank + STATF_OAM = 0b00000010 ; OAM-RAM is used by system + STATF_LCD = 0b00000011 ; Both OAM and VRAM used by system + STATF_BUSY = 0b00000010 ; When set, VRAM access is unsafe + STATF_B_LYC = 6 + STATF_B_MODE10 = 5 + STATF_B_MODE01 = 4 + STATF_B_MODE00 = 3 + STATF_B_LYCF = 2 + STATF_B_VBL = 0 + STATF_B_OAM = 1 + STATF_B_BUSY = 1 + + .SCY = 0x42 ; Scroll Y + rSCY = 0xFF42 + + .SCX = 0x43 ; Scroll X + rSCX = 0xFF43 + + .LY = 0x44 ; LCDC Y-coordinate + rLY = 0xFF44 + + .LYC = 0x45 ; LY compare + rLYC = 0xFF45 + + .DMA = 0x46 ; DMA transfer + rDMA = 0xFF46 + + .BGP = 0x47 ; BG palette data + rBGP = 0xFF47 + + .OBP0 = 0x48 ; OBJ palette 0 data + rOBP0 = 0xFF48 + + .OBP1 = 0x49 ; OBJ palette 1 data + rOBP1 = 0xFF49 + + .WY = 0x4A ; Window Y coordinate + rWY = 0xFF4A + + .WX = 0x4B ; Window X coordinate + rWX = 0xFF4B + + .KEY1 = 0x4D ; CPU speed + rKEY1 = 0xFF4D + rSPD = 0xFF4D + + KEY1F_DBLSPEED = 0b10000000 ; 0=Normal Speed, 1=Double Speed (R) + KEY1F_PREPARE = 0b00000001 ; 0=No, 1=Prepare (R/W) + + .VBK = 0x4F ; VRAM bank + rVBK = 0xFF4F + + .HDMA1 = 0x51 ; DMA control 1 + rHDMA1 = 0xFF51 + + .HDMA2 = 0x52 ; DMA control 2 + rHDMA2 = 0xFF52 + + .HDMA3 = 0x53 ; DMA control 3 + rHDMA3 = 0xFF53 + + .HDMA4 = 0x54 ; DMA control 4 + rHDMA4 = 0xFF54 + + .HDMA5 = 0x55 ; DMA control 5 + rHDMA5 = 0xFF55 + + HDMA5F_MODE_GP = 0b00000000 ; General Purpose DMA (W) + HDMA5F_MODE_HBL = 0b10000000 ; HBlank DMA (W) + + HDMA5F_BUSY = 0b10000000 ; 0=Busy (DMA still in progress), 1=Transfer complete (R) + + .RP = 0x56 ; IR port + rRP = 0xFF56 + + RPF_ENREAD = 0b11000000 + RPF_DATAIN = 0b00000010 ; 0=Receiving IR Signal, 1=Normal + RPF_WRITE_HI = 0b00000001 + RPF_WRITE_LO = 0b00000000 + + .BCPS = 0x68 ; BG color palette specification + rBCPS = 0xFF68 + + BCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) + + .BCPD = 0x69 ; BG color palette data + rBCPD = 0xFF69 + + .OCPS = 0x6A ; OBJ color palette specification + rOCPS = 0xFF6A + + OCPSF_AUTOINC = 0b10000000 ; Auto Increment (0=Disabled, 1=Increment after Writing) + + .OCPD = 0x6B ; OBJ color palette data + rOCPD = 0xFF6B + + .SVBK = 0x70 ; WRAM bank + rSVBK = 0xFF70 + rSMBK = 0xFF70 + + rPCM12 = 0xFF76 + + rPCM34 = 0xFF77 + + .IE = 0xFF ; Interrupt enable + rIE = 0xFFFF + + .VBL_IFLAG = 0x01 + .LCD_IFLAG = 0x02 + .TIM_IFLAG = 0x04 + .SIO_IFLAG = 0x08 + .JOY_IFLAG = 0x10 + + IEF_HILO = 0b00010000 ; Transition from High to Low of Pin number P10-P13 + IEF_SERIAL = 0b00001000 ; Serial I/O transfer end + IEF_TIMER = 0b00000100 ; Timer Overflow + IEF_STAT = 0b00000010 ; STAT + IEF_VBLANK = 0b00000001 ; V-Blank + + ;; Flags common to multiple sound channels + + AUDLEN_DUTY_12_5 = 0b00000000 ; 12.5% + AUDLEN_DUTY_25 = 0b01000000 ; 25% + AUDLEN_DUTY_50 = 0b10000000 ; 50% + AUDLEN_DUTY_75 = 0b11000000 ; 75% + + AUDENV_UP = 0b00001000 + AUDENV_DOWN = 0b00000000 + + AUDHIGH_RESTART = 0b10000000 + AUDHIGH_LENGTH_ON = 0b01000000 + AUDHIGH_LENGTH_OFF = 0b00000000 + + ;; OAM related constants + + OAM_COUNT = 40 ; number of OAM entries in OAM RAM + + OAMF_PRI = 0b10000000 ; Priority + OAMF_YFLIP = 0b01000000 ; Y flip + OAMF_XFLIP = 0b00100000 ; X flip + OAMF_PAL0 = 0b00000000 ; Palette number; 0,1 (DMG) + OAMF_PAL1 = 0b00010000 ; Palette number; 0,1 (DMG) + OAMF_BANK0 = 0b00000000 ; Bank number; 0,1 (GBC) + OAMF_BANK1 = 0b00001000 ; Bank number; 0,1 (GBC) + + OAMF_PALMASK = 0b00000111 ; Palette (GBC) + + OAMB_PRI = 7 ; Priority + OAMB_YFLIP = 6 ; Y flip + OAMB_XFLIP = 5 ; X flip + OAMB_PAL1 = 4 ; Palette number; 0,1 (DMG) + OAMB_BANK1 = 3 ; Bank number; 0,1 (GBC) + + ;; SGB packets + .PAL_01 = 0x00 + .PAL_23 = 0x01 + .PAL_03 = 0x02 + .PAL_12 = 0x03 + .ATTR_BLK = 0x04 + .ATTR_LIN = 0x05 + .ATTR_DIV = 0x06 + .ATTR_CHR = 0x07 + .SOUND = 0x08 + .SOU_TRN = 0x09 + .PAL_SET = 0x0A + .PAL_TRN = 0x0B + .ATRC_EN = 0x0C + .TEST_EN = 0x0D + .ICON_EN = 0x0E + .DATA_SND = 0x0F + .DATA_TRN = 0x10 + .MLT_REQ = 0x11 + .JUMP = 0x12 + .CHR_TRN = 0x13 + .PCT_TRN = 0x14 + .ATTR_TRN = 0x15 + .ATTR_SET = 0x16 + .MASK_EN = 0x17 + .OBJ_TRN = 0x18 + + ;; CPU detection + .DMG_TYPE = 0x01 ; Original GB or Super GB + .MGB_TYPE = 0xFF ; Pocket GB or Super GB 2 + .CGB_TYPE = 0x11 ; Color GB + + ;; GBDK library screen modes + + .G_MODE = 0x01 ; Graphic mode + .T_MODE = 0x02 ; Text mode (bit 2) + .T_MODE_OUT = 0x02 ; Text mode output only + .T_MODE_INOUT = 0x03 ; Text mode with input + .M_NO_SCROLL = 0x04 ; Disables scrolling of the screen in text mode + .M_NO_INTERP = 0x08 ; Disables special character interpretation + + ;; Status codes for IO + .IO_IDLE = 0x00 + .IO_SENDING = 0x01 + .IO_RECEIVING = 0x02 + .IO_ERROR = 0x04 + + ;; Type of IO data + .DT_IDLE = 0x66 + .DT_RECEIVING = 0x55 + + ;; Table of routines for modes + .MODE_TABLE = 0x01E0 + + ;; C related + ;; Overheap of a banked call. Used for parameters + ;; = ret + real ret + bank + + .if .NEAR_CALLS + .BANKOV = 2 + + .else + .BANKOV = 6 + + .endif + + .globl __current_bank + .globl __shadow_OAM_base + + ;; Global variables + .globl .mode + + .globl __cpu + .globl __is_GBA + + ;; Global routines +; .globl .set_mode ;; don't link mode.o by default + + .globl .reset + + .globl .display_off + + .globl .wait_vbl_done + + ;; Interrupt routines + .globl .add_VBL +; .globl .add_LCD ;; don't link LCD.o by default +; .globl .add_TIM ;; don't link TIM.o by default +; .globl .add_SIO ;; don't link serial.o by default +; .globl .add_JOY ;; don't link JOY.o by default + + ;; Symbols defined at link time + .globl .STACK + .globl _shadow_OAM + .globl .refresh_OAM + + ;; Main user routine + .globl _main + + ;; Macro definitions + +.macro WAIT_STAT ?lbl +lbl: LDH A, (.STAT) + AND #STATF_BUSY ; Check if in LCD modes 0 or 1 + JR NZ, lbl +.endm + +.macro ADD_A_REG16 regH regL + ADD regL + LD regL, A + ADC regH + SUB regL + LD regH, A +.endm + +.macro SIGNED_ADD_A_REG16 regH regL ?lbl + ; If A is negative, we need to subtract 1 from upper byte of 16-bit value + BIT 7, A ; set z if a signed bit is 0 + JR Z, lbl ; if z is set jump to positive + dec regH ; if negative decrement upper byte +lbl: + ADD_A_REG16 regH, regL +.endm + +.macro SIGNED_SUB_A_REG16 regH regL ?lbl + ; negate A then add to 16-bit value + CPL + INC A + SIGNED_ADD_A_REG16 regH, regL +.endm + +.macro MUL_DE_BY_A_RET_HL ?lbl1 ?lbl2 + ; Multiply DE by A, return result in HL; preserves: BC + LD HL, #0 +lbl1: + SRL A + JR NC, lbl2 + ADD HL, DE +lbl2: + SLA E + RL D + OR A + JR NZ, lbl1 +.endm + diff --git a/gbdk-lib/libc/targets/gbz80/gb/sfr.s b/gbdk-lib/libc/targets/sm83/gb/sfr.s diff --git a/gbdk-lib/libc/targets/gbz80/gb_decompress.s b/gbdk-lib/libc/targets/sm83/gb_decompress.s diff --git a/gbdk-lib/libc/targets/gbz80/gb_decompress_tiles.s b/gbdk-lib/libc/targets/sm83/gb_decompress_tiles.s diff --git a/gbdk-lib/libc/targets/gbz80/get_addr.s b/gbdk-lib/libc/targets/sm83/get_addr.s diff --git a/gbdk-lib/libc/targets/gbz80/get_bk_t.s b/gbdk-lib/libc/targets/sm83/get_bk_t.s diff --git a/gbdk-lib/libc/targets/gbz80/get_data.s b/gbdk-lib/libc/targets/sm83/get_data.s diff --git a/gbdk-lib/libc/targets/gbz80/get_t.s b/gbdk-lib/libc/targets/sm83/get_t.s diff --git a/gbdk-lib/libc/targets/gbz80/get_tile.s b/gbdk-lib/libc/targets/sm83/get_tile.s diff --git a/gbdk-lib/libc/targets/gbz80/get_wi_t.s b/gbdk-lib/libc/targets/sm83/get_wi_t.s diff --git a/gbdk-lib/libc/targets/gbz80/get_xy_t.s b/gbdk-lib/libc/targets/sm83/get_xy_t.s diff --git a/gbdk-lib/libc/targets/gbz80/gprint.c b/gbdk-lib/libc/targets/sm83/gprint.c diff --git a/gbdk-lib/libc/targets/gbz80/gprintf.c b/gbdk-lib/libc/targets/sm83/gprintf.c diff --git a/gbdk-lib/libc/targets/gbz80/gprintln.c b/gbdk-lib/libc/targets/sm83/gprintln.c diff --git a/gbdk-lib/libc/targets/gbz80/gprintn.c b/gbdk-lib/libc/targets/sm83/gprintn.c diff --git a/gbdk-lib/libc/targets/gbz80/heap.s b/gbdk-lib/libc/targets/sm83/heap.s diff --git a/gbdk-lib/libc/targets/gbz80/hiramcpy.s b/gbdk-lib/libc/targets/sm83/hiramcpy.s diff --git a/gbdk-lib/libc/targets/gbz80/init_tt.s b/gbdk-lib/libc/targets/sm83/init_tt.s diff --git a/gbdk-lib/libc/targets/gbz80/init_vram.s b/gbdk-lib/libc/targets/sm83/init_vram.s diff --git a/gbdk-lib/libc/targets/gbz80/input.s b/gbdk-lib/libc/targets/sm83/input.s diff --git a/gbdk-lib/libc/targets/gbz80/joy.s b/gbdk-lib/libc/targets/sm83/joy.s diff --git a/gbdk-lib/libc/targets/gbz80/lcd.s b/gbdk-lib/libc/targets/sm83/lcd.s diff --git a/gbdk-lib/libc/targets/gbz80/metasprites.s b/gbdk-lib/libc/targets/sm83/metasprites.s diff --git a/gbdk-lib/libc/targets/gbz80/metasprites_flip.s b/gbdk-lib/libc/targets/sm83/metasprites_flip.s diff --git a/gbdk-lib/libc/targets/gbz80/metasprites_hide.s b/gbdk-lib/libc/targets/sm83/metasprites_hide.s diff --git a/gbdk-lib/libc/targets/gbz80/metasprites_hide_spr.s b/gbdk-lib/libc/targets/sm83/metasprites_hide_spr.s diff --git a/gbdk-lib/libc/targets/gbz80/mode.s b/gbdk-lib/libc/targets/sm83/mode.s diff --git a/gbdk-lib/libc/targets/gbz80/mv_spr.s b/gbdk-lib/libc/targets/sm83/mv_spr.s diff --git a/gbdk-lib/libc/targets/gbz80/nowait.s b/gbdk-lib/libc/targets/sm83/nowait.s diff --git a/gbdk-lib/libc/targets/gbz80/pad.s b/gbdk-lib/libc/targets/sm83/pad.s diff --git a/gbdk-lib/libc/targets/gbz80/pad_ex.s b/gbdk-lib/libc/targets/sm83/pad_ex.s diff --git a/gbdk-lib/libc/targets/gbz80/rle_decompress.s b/gbdk-lib/libc/targets/sm83/rle_decompress.s diff --git a/gbdk-lib/libc/targets/gbz80/serial.s b/gbdk-lib/libc/targets/sm83/serial.s diff --git a/gbdk-lib/libc/targets/gbz80/set_1bit_data.s b/gbdk-lib/libc/targets/sm83/set_1bit_data.s diff --git a/gbdk-lib/libc/targets/gbz80/set_bk_t.s b/gbdk-lib/libc/targets/sm83/set_bk_t.s diff --git a/gbdk-lib/libc/targets/gbz80/set_data.s b/gbdk-lib/libc/targets/sm83/set_data.s diff --git a/gbdk-lib/libc/targets/gbz80/set_prop.s b/gbdk-lib/libc/targets/sm83/set_prop.s diff --git a/gbdk-lib/libc/targets/gbz80/set_spr.s b/gbdk-lib/libc/targets/sm83/set_spr.s diff --git a/gbdk-lib/libc/targets/gbz80/set_t.s b/gbdk-lib/libc/targets/sm83/set_t.s diff --git a/gbdk-lib/libc/targets/gbz80/set_tile.s b/gbdk-lib/libc/targets/sm83/set_tile.s diff --git a/gbdk-lib/libc/targets/gbz80/set_tile_submap.s b/gbdk-lib/libc/targets/sm83/set_tile_submap.s diff --git a/gbdk-lib/libc/targets/gbz80/set_wi_t.s b/gbdk-lib/libc/targets/sm83/set_wi_t.s diff --git a/gbdk-lib/libc/targets/gbz80/set_win_tile_submap.s b/gbdk-lib/libc/targets/sm83/set_win_tile_submap.s diff --git a/gbdk-lib/libc/targets/gbz80/set_xy_t.s b/gbdk-lib/libc/targets/sm83/set_xy_t.s diff --git a/gbdk-lib/libc/targets/gbz80/sgb.s b/gbdk-lib/libc/targets/sm83/sgb.s diff --git a/gbdk-lib/libc/targets/gbz80/tim.s b/gbdk-lib/libc/targets/sm83/tim.s diff --git a/gbdk-lib/libc/targets/gbz80/tim_common.s b/gbdk-lib/libc/targets/sm83/tim_common.s diff --git a/gbdk-lib/libc/targets/gbz80/tim_nested.s b/gbdk-lib/libc/targets/sm83/tim_nested.s diff --git a/gbdk-lib/tools/astorgb.pl b/gbdk-lib/tools/astorgb.pl @@ -1,297 +0,0 @@ -#!/usr/bin/perl -$module = "unknown"; -$modsub = 1; -$area = "CODE"; - -%dir_conv = ( - '.org' => 'ORG', - '.include' => 'INCLUDE', - '.byte' => 'DB', - '.db' => 'DB', - '.dw' => 'DW', - '.ds' => 'DS', - '.blkw' => 'DS', - '.globl' => 'GLOBAL', - '.word' => 'DW' -); -%dir_drop = ( - '.title' => 'x', - '.module' => 'x' -); -%dir_notab = ( - '.if' => 'IF', - '.endif' => 'ENDC', - '.else' => 'ELSE' -); -%area_conv = ( - '_HEADER' => 'HOME', - '_HEADER[ABS]' => 'HOME', - '_CODE' => 'CODE', - '_BSS' => 'BSS', - '_HOME' => 'HOME', - '_BASE' => 'HOME', - '_LIT', => 'HOME', - '_GSINIT' => 'HOME', - '_GSINITTAIL' => 'HOME', - '_GSFINAL' => 'HOME', - '_DATA' => 'BSS', - '_HEAP' => 'BSS', - '_SFR' => 'HRAM' -); -%label_conv = ( - 'A' => 'PAD_A', - 'B' => 'PAD_B', - 'DIV' => 'R_DIV', - 'IF' => 'R_IF' -); - -# Take a guess at the module name -$file = @ARGV[0]; -if (defined($file)) { - $module = `basename $file`; - chomp $module; -} - -# Emit the header -print "\t; Automagically from \"$module\" by $PROGRAM_NAME\n"; - -sub getnum { - my($asc) = @_; - if ($asc =~ /^0x(\w+)/) { - $ret = "\$$1"; - } - elsif ($asc =~ /^0b(\d+)/) { - $ret = "\%$1"; - } - else { - $ret = $asc; - } - return $ret; -}; - -sub labelswap { - my($label) = @_; - my($ret); - $ret = $label_conv{$label}; - if (not defined $ret) { - $ret = getnum $label; - } - return $ret; -} - -sub labelconv { - my($op) = @_; - my($ret); - $ret = $op; - if ($op =~ /^\.(\w+)(\S*)/) { - $ret = labelswap $1 . $2; - } - elsif ($op =~ /^(\w+)\$/) { - $ret = ".l$1"; - } - else { - $ret = getnum $op; - } - return $ret; -} - -sub splitarith { - my($op) = @_; - my($ret, @parts, @newparts, $part, $t); - # Dont know how to do this so fake it - $t = $op; - $t =~ s/([\+\-\*\/\&\|]+)/ \1 /g; - - @parts = split / /, $t; - foreach $part (@parts) { - $t = labelconv($part); - push @newparts, $t; - } - $t = join /\@/, @newparts; - return $t; -} - -sub convert { - my($op) = @_; - my($ret, $t); - if ($op =~ /^\#(\S+)/) { - $t = $1; - if ($t =~ /^\>(\S+)/) { - $ret = "(" . labelconv($1) . ">>8)"; - } - elsif ($t =~ /^\<(\S+)/) { - $ret = "(" . labelconv($1) . "&\$FF)"; - } - # PC relative - elsif ($t =~ /^\.([\+\-\d]+)/) { - $ret = "\@$1"; - } - else { - $ret = splitarith $1; - } - } - elsif ($op =~ /(\S*)\((\S+)\)/) { - if ($op !~ /^BANK\(/) { - $ret = "$1\[" . splitarith($2) . "]"; - } - else { - $ret = $op; - } - } - else { - $ret = splitarith $op; - } - return $ret; -} - -while (<>) { - # First strip off any comments - ($_, $comments) = split /;+/; - chomp; - if (defined($comments)) { - $comments = "; $comments"; - chomp $comments; - } - - if (/^\S/) { - ($label, $op, @operands) = split; - } - else { - ($op, @operands) = split; - $label = undef; - } - $operand = $operands[0]; - - # Mangle the operand - $newoperand = undef; - foreach $op1 (split /,/, $operand) { - $new = convert $op1; - if (not defined($newoperand)) { - $newoperand = $new; - } - else { - $newoperand = "$newoperand,$new"; - } - } - $operand = $newoperand; - - # Handle A = 5 - if ($operand =~ /^\=/) { - # Covert the name - $op = convert $op; - if ($op eq '__RGBDS__') { - $operands[1] = '1'; - } - print "$op\tEQU\t" . convert($operands[1]) . "\n"; - } - # Handle directives - elsif ($op =~ /^\./) { - if ($op eq '.org') { - $org = convert($operand); - print "\tSECTION \"$module\_$modsub\",$area\[$org\]\n"; - $modsub++; - } - elsif ($op eq '.area') { - $area = $area_conv{$operand}; - if (not defined $area) { - die "Couldnt convert area \"$operand\"\n"; - } - print "\tSECTION \"$module\_$modsub\",$area\n"; - $modsub++; - } - elsif ($op eq '.asciz') { - # Note the @operands. - print "\tDB\t@operands\,0\n"; - } - elsif ($op eq '.ascii') { - # Note the @operands. - print "\tDB\t@operands\n"; - } - elsif ($op eq '.module') { - $module = $operand; - # And drop - } - elsif ($op eq '.include') { - # Mangle the included file name - # We use .asm for rgbds, and .s for asxxx - if ($operand =~ /\"(\w+)\.s\"/) { - print "\tINCLUDE \"$1.asm\"\n"; - } - else { - print "\tINCLUDE $operand\n"; - } - } - elsif (defined $dir_drop{$op}) { - print "\t; Dropping $op $operand\n"; - } - elsif (defined $dir_notab{$op}) { - $conv = $dir_notab{$op}; - print "$conv\t$operand\t$comments\n"; - } - else { - $conv = $dir_conv{$op}; - if (not defined $conv) { - die "Couldnt convert $op ($conv)\n"; - } - print "\t$conv\t$operand\t$comments\n"; - } - } - else { - # Convert any labels - if ($label =~ /^\.(\S+)/) { - $label = $1; - } - elsif ($label =~ /^(\w+)\$\:/) { - $label = ".l$1:"; - } - # Convert the op to uppercase - $op = uc $op; - # Convert any special op-codes - if ($op eq 'LDH') { - $op = 'LD'; - $operand = uc $operand; - ($first, $rest) = split /,/, $operand; - if ($first =~ /^\[(\S+)\]/) { - if ($1 eq 'C') { - # Do nothing - } - else { - $first = "\[\$FF00+$1\]"; - } - } - if ($rest =~ /^\[(\S+)\]/) { - if ($1 eq 'C') { - # Do nothing - } - else { - $rest = "\[\$FF00+$1\]"; - } - } - $operand = "$first\,$rest"; - } - elsif ($op eq 'LDA') { - $operand = uc $operand; - if ($operand =~ /^(\w+)\,([+-]*)(\S+)\[SP\]/) { - $op = 'LD'; - $plusmin = $2; - if ($plusmin == 0) { - $plusmin = "+"; - } - if ($1 eq 'SP') { - $op = 'ADD'; - $operand = "$1,$plusmin" . convert $3; - } - else { - $operand = "$1,[SP$plusmin" . convert $3 . "]"; - } - } - } - if ($label eq "" && $op eq "" && $operand eq "") { - print "\t$comments\n"; - } - else { - print "$label\t$op\t$operand\t$comments\n"; - } - } -} - diff --git a/gbdk-support/lcc/gb.c b/gbdk-support/lcc/gb.c @@ -28,7 +28,7 @@ static struct { const char *val; } _tokens[] = { // expandable string tokens used in "CLASS" command strings - { "port", "gbz80" }, // if default class is ever changed from Game Boy, this default (and plat) may need to be changed to match + { "port", "sm83" }, // if default class is ever changed from Game Boy, this default (and plat) may need to be changed to match { "plat", "gb" }, { "sdccdir", "%bindir%"}, { "cpp", "%sdccdir%sdcpp" }, @@ -276,7 +276,7 @@ int option(char *arg) { exit(-1); } } else { - fprintf(stderr, "Error: -m requires both/only PORT and PLATFORM values (ex: -mgbz80:gb) : %s\n", arg); + fprintf(stderr, "Error: -m requires both/only PORT and PLATFORM values (ex: -msm83:gb) : %s\n", arg); exit(-1); } diff --git a/gbdk-support/lcc/lcc.c b/gbdk-support/lcc/lcc.c @@ -767,7 +767,7 @@ static void help(void) { "-Idir add `dir' to the beginning of the list of #include directories\n", "-K don't run ihxcheck test on linker ihx output\n", "-lx search library `x'\n", -"-m select port and platform: \"-m[port]:[plat]\" ports:gbz80,z80 plats:ap,duck,gb,sms,gg\n", +"-m select port and platform: \"-m[port]:[plat]\" ports:sm83,z80 plats:ap,duck,gb,sms,gg\n", "-N do not search the standard directories for #include files\n", "-n emit code to check for dereferencing zero pointers\n", "-no-crt do not auto-include the gbdk crt0.o runtime in linker list\n", diff --git a/gbdk-support/lcc/targets.c b/gbdk-support/lcc/targets.c @@ -39,7 +39,7 @@ arg_entry llist0_defaults_msxdos[] = { // $3 is the output file CLASS classes[] = { // GB - { "gbz80", // port + { "sm83", // port "gb", // plat "gb", // default_plat EXT_GB, // ROM file extension @@ -55,7 +55,7 @@ CLASS classes[] = { llist0_defaults_gb, ARRAY_LEN(llist0_defaults_gb), }, // Analogue Pocket - { "gbz80", // port + { "sm83", // port "ap", // plat "ap", // default_plat EXT_AP, // ROM file extension @@ -71,7 +71,7 @@ CLASS classes[] = { llist0_defaults_gb, ARRAY_LEN(llist0_defaults_gb), // Use GB linker list defaults }, // Megaduck - { "gbz80", // port + { "sm83", // port "duck", // plat "duck", // default_plat EXT_DUCK, // ROM file extension diff --git a/gbdk-support/png2asset/png2asset.cpp b/gbdk-support/png2asset/png2asset.cpp @@ -28,15 +28,15 @@ struct Tile unsigned char pal; Tile(size_t size = 0) : data(size), pal(0) {} - bool operator==(const Tile& t) const + bool operator==(const Tile& t) const { return data == t.data && pal == t.pal; } - - const Tile& operator=(const Tile& t) + + const Tile& operator=(const Tile& t) { - data = t.data; - pal = t.pal; + data = t.data; + pal = t.pal; return *this; } @@ -56,7 +56,7 @@ struct Tile ret[j * 2 + 1] |= BIT(col, 1) << (7 - i); } } - } + } else if(pack_mode == SGB) { for(int j = 0; j < tile_h; ++j) { @@ -135,6 +135,7 @@ bool includeTileData = true; bool includedMapOrMetaspriteData = true; PNGImage source_tileset_image; bool use_source_tileset = false; +bool keep_duplicate_tiles = false; typedef vector< MTTile > MetaSprite; vector< Tile > tiles; @@ -236,17 +237,27 @@ void GetMetaSprite(int _x, int _y, int _w, int _h, int pivot_x, int pivot_y) size_t idx; unsigned char props; unsigned char pal_idx = image.data[y * image.w + x] >> 2; //We can pick the palette from the first pixel of this tile - if(!FindTile(tile, idx, props)) + + if(keep_duplicate_tiles) { - if (use_source_tileset) { - printf("found a tile not in the source tileset at %d,%d. The target tileset has %d extra tiles.\n", x, y,extra_tile_count+1); - extra_tile_count++; - includeTileData = true; - } tiles.push_back(tile); idx = tiles.size() - 1; props = props_default; } + else + { + if(!FindTile(tile, idx, props)) + { + if (use_source_tileset) { + printf("found a tile not in the source tileset at %d,%d. The target tileset has %d extra tiles.\n", x, y,extra_tile_count+1); + extra_tile_count++; + includeTileData = true; + } + tiles.push_back(tile); + idx = tiles.size() - 1; + props = props_default; + } + } props |= pal_idx; @@ -254,7 +265,7 @@ void GetMetaSprite(int _x, int _y, int _w, int _h, int pivot_x, int pivot_y) idx *= 2; mt_sprite.push_back(MTTile(x - last_x, y - last_y, (unsigned char)idx, props)); - + last_x = x; last_y = y; } @@ -270,33 +281,43 @@ void GetMap() { Tile tile(8 * 8); image.ExtractGBTile(x, y, 8, tile); - + size_t idx; unsigned char props; - if(!FindTile(tile, idx, props)) + + if(keep_duplicate_tiles) { - if (use_source_tileset) { - printf("found a tile not in the source tileset at %d,%d. The target tileset has %d extra tiles.\n", x, y, extra_tile_count + 1); - extra_tile_count++; - includeTileData = true; - } tiles.push_back(tile); idx = tiles.size() - 1; props = props_default; + } + else + { + if(!FindTile(tile, idx, props)) + { + if (use_source_tileset) { + printf("found a tile not in the source tileset at %d,%d. The target tileset has %d extra tiles.\n", x, y, extra_tile_count + 1); + extra_tile_count++; + includeTileData = true; + } + tiles.push_back(tile); + idx = tiles.size() - 1; + props = props_default; - if(tiles.size() > 256 && pack_mode != Tile::SMS) - printf("Warning: found more than 256 tiles on x:%d,y:%d\n", x, y); + if(tiles.size() > 256 && pack_mode != Tile::SMS) + printf("Warning: found more than 256 tiles on x:%d,y:%d\n", x, y); - if(((tiles.size() + tile_origin) > 256) && (pack_mode != Tile::SMS)) - printf("Warning: tile count (%d) + tile origin (%d) exceeds 256 at x:%d,y:%d\n", (unsigned int)tiles.size(), tile_origin, x, y); + if(((tiles.size() + tile_origin) > 256) && (pack_mode != Tile::SMS)) + printf("Warning: tile count (%d) + tile origin (%d) exceeds 256 at x:%d,y:%d\n", (unsigned int)tiles.size(), tile_origin, x, y); + } } map.push_back((unsigned char)idx + tile_origin); - + if(use_map_attributes) { unsigned char pal_idx = image.data[y * image.w + x] >> bpp; //We can pick the palette from the first pixel of this tile - if(pack_mode == Tile::SGB) + if(pack_mode == Tile::SGB) { props = props << 1; //Mirror flags in SGB are on bit 7 props |= (pal_idx + 4) << 2; //Pals are in bits 2,3,4 and need to go from 4 to 7 @@ -309,7 +330,7 @@ void GetMap() props |= 1; map.push_back(props); } - else + else { props |= pal_idx; map_attributes.push_back(props); @@ -471,7 +492,7 @@ bool GetSourceTileset(bool keep_palette_order, unsigned int max_palettes, vector { int* color_ptr = (int*)&source_tileset_image.palette[p * pal_size * 4]; - //TODO: if palettes[p].size() != pal_size we should probably try to fill the gaps based on grayscale values + //TODO: if palettes[p].size() != pal_size we should probably try to fill the gaps based on grayscale values for (SetPal::iterator it = palettes[p].begin(); it != palettes[p].end(); ++it, color_ptr++) { @@ -499,6 +520,11 @@ bool GetSourceTileset(bool keep_palette_order, unsigned int max_palettes, vector image = source_tileset_image; use_source_tileset = false; GetMap(); + + // Our source tileset shouldn't build the map arrays up + // Clear anything from the previous 'GetMap' call + map.clear(); + map_attributes.clear(); use_source_tileset = true; // Change the image variable back @@ -506,8 +532,8 @@ bool GetSourceTileset(bool keep_palette_order, unsigned int max_palettes, vector source_tileset_size = tiles.size(); - printf("Got %d tiles from the source tileset.\n", tiles.size()); - printf("Got %d palettes from the source tileset.\n", source_tileset_image.palettesize/4); + printf("Got %d tiles from the source tileset.\n", (unsigned int)tiles.size()); + printf("Got %d palettes from the source tileset.\n", (unsigned int)source_tileset_image.palettesize/4); return true; @@ -517,7 +543,7 @@ bool GetSourceTileset(bool keep_palette_order, unsigned int max_palettes, vector void Export(const PNGImage& image, const char* path) { lodepng::State state; - state.info_png.color.colortype = LCT_PALETTE; + state.info_png.color.colortype = LCT_PALETTE; state.info_png.color.bitdepth = 8; state.info_raw.colortype = LCT_PALETTE; state.info_raw.bitdepth = 8; @@ -529,7 +555,7 @@ void Export(const PNGImage& image, const char* path) unsigned char* c = &image.palette[p * 4]; ADD_PALETTE(c[0], c[1], c[2], c[3]); } - + std::vector<unsigned char> buffer; lodepng::encode(buffer, image.data, image.w, image.h, state); lodepng::save_file(buffer, path); @@ -558,17 +584,17 @@ int main(int argc, char* argv[]) printf("-use_structs Group the exported info into structs (default: false) (used by ZGB Game Engine)\n"); printf("-bpp bits per pixel: 2, 4 (default: 2)\n"); printf("-max_palettes maximum number of palettes allowed (default: 2)\n"); - printf("-pack_mode gb, sgb or sms (default:GB)\n"); - printf("-tile_origin tile index offset for maps (instead of zero)\n"); - + printf("-pack_mode gb, sgb or sms (default: gb)\n"); + printf("-tile_origin tile index offset for maps (default: 0)\n"); - printf("-tiles_only should only tile data be exported\n"); - printf("-maps_only should only map data be exported\n"); - printf("-metasprites_only should only metasprite data be exported\n"); - printf("-source_tileset source tileset\n"); + printf("-tiles_only export tile data only\n"); + printf("-maps_only export map tilemap only\n"); + printf("-metasprites_only export metasprite descriptors only\n"); + printf("-source_tileset use source tileset (image with common tiles)\n"); + printf("-keep_duplicate_tiles do not remove duplicate tiles (default: not enabled)\n"); - printf("-bin Should a .bin file be written?"); - printf("-transposed Should be map items be written column-by-column, instead of row-by-row?"); + printf("-bin export to binary format\n"); + printf("-transposed export transposed (column-by-column instead of row-by-row)\n"); return 0; } @@ -687,6 +713,10 @@ int main(int argc, char* argv[]) { includedMapOrMetaspriteData = false; } + else if (!strcmp(argv[i], "-keep_duplicate_tiles")) + { + keep_duplicate_tiles = true; + } else if (!strcmp(argv[i], "-source_tileset")) { use_source_tileset = true; @@ -766,7 +796,7 @@ int main(int argc, char* argv[]) // Make sure these two values match when keeping palette order if (image.palettesize != source_tileset_image.palettesize) { - printf("error: The the number of color palette's for your source tileset (%d) and target image (%d) do not match.", source_tileset_image.palettesize, image.palettesize); + printf("error: The number of color palette's for your source tileset (%d) and target image (%d) do not match.", (unsigned int)source_tileset_image.palettesize, (unsigned int)image.palettesize); return 1; } @@ -851,13 +881,13 @@ int main(int argc, char* argv[]) // If we are using a sourcetileset and have more palettes than it defines if (use_source_tileset && image.palettesize > source_palette_count) { - printf("Found %d extra palette(s) for target tilemap.\n", (image.palettesize - source_palette_count) / 4); + printf("Found %d extra palette(s) for target tilemap.\n", (unsigned int)(image.palettesize - source_palette_count) / 4); } for(size_t p = 0; p < palettes.size(); ++p) { int *color_ptr = (int*)&image.palette[p * pal_size * 4]; - //TODO: if palettes[p].size() != pal_size we should probably try to fill the gaps based on grayscale values + //TODO: if palettes[p].size() != pal_size we should probably try to fill the gaps based on grayscale values for(SetPal::iterator it = palettes[p].begin(); it != palettes[p].end(); ++ it, color_ptr ++) { @@ -947,7 +977,7 @@ int main(int argc, char* argv[]) fprintf(file, "#define %s_WIDTH %d\n", data_name.c_str(), sprite_w); fprintf(file, "#define %s_HEIGHT %d\n", data_name.c_str(), sprite_h); fprintf(file, "#define %s_TILE_COUNT %d\n", data_name.c_str(), ((unsigned int)tiles.size() - source_tileset_size) * (tile_h >> 3)); - fprintf(file, "#define %s_PALETTE_COUNT %d\n", data_name.c_str(), image.palettesize / 4); + fprintf(file, "#define %s_PALETTE_COUNT %d\n", data_name.c_str(), (unsigned int)image.palettesize / 4); if (includedMapOrMetaspriteData) { @@ -1017,7 +1047,7 @@ int main(int argc, char* argv[]) printf("Error writing file"); return 1; } - + if (bank) fprintf(file, "#pragma bank %d\n\n", bank); fprintf(file, "//AUTOGENERATED FILE FROM png2asset\n\n"); @@ -1031,10 +1061,10 @@ int main(int argc, char* argv[]) // Are we not using a source tileset, or do we have extra colors if (image.palettesize - source_palette_count > 0||!use_source_tileset) { - + // Subtract however many palettes we had in the source tileset fprintf(file, "const palette_color_t %s_palettes[%d] = {\n", data_name.c_str(), (unsigned int)image.palettesize - source_palette_count); - + // Offset by however many palettes we had in the source ileset for (size_t i = source_palette_count/4; i < image.palettesize / 4; ++i) { @@ -1209,7 +1239,7 @@ int main(int argc, char* argv[]) fprintf(file, "\n"); } } - + fprintf(file, "};\n"); } @@ -1233,7 +1263,7 @@ int main(int argc, char* argv[]) } } } - + fclose(file); }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.