From 94fd86135077db5979af3694cf427dff6ff4df0c Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Tue, 12 Dec 2023 06:59:32 +0200 Subject: [PATCH] Z80/snd init --- .gitignore | 1 + Makefile | 20 ++++++++++++++++++++ src/hwregs.h | 16 ++++++++++++++++ src/intr.s | 5 +++++ src/libc/inttypes.h | 12 ++++++++++++ src/main.c | 4 ++++ src/z80.c | 24 ++++++++++++++++++++++++ src/z80.h | 15 +++++++++++++++ src/z80/main.asm | 36 ++++++++++++++++++++++++++++++++++++ src/z80/sndregs.inc | 20 ++++++++++++++++++++ src/z80prog.s | 10 ++++++++++ z80.ld | 20 ++++++++++++++++++++ 12 files changed, 183 insertions(+) create mode 100644 src/hwregs.h create mode 100644 src/libc/inttypes.h create mode 100644 src/z80.c create mode 100644 src/z80.h create mode 100644 src/z80/main.asm create mode 100644 src/z80/sndregs.inc create mode 100644 src/z80prog.s create mode 100644 z80.ld diff --git a/.gitignore b/.gitignore index d11753f..95a7ed6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ *.bin *.elf *.map +*.z80 diff --git a/Makefile b/Makefile index 002cba4..e6043d4 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,10 @@ aSsrc = $(wildcard src/*.S) obj = $(asrc:.s=.o) $(aSsrc:.S=.o) $(csrc:.c=.o) dep = $(csrc:.c=.d) +z80src = $(wildcard src/z80/*.asm) +z80obj = $(z80src:.asm=.z80) +z80bin = z80.bin + name = life elf = $(name).elf bin = $(name).bin @@ -27,17 +31,32 @@ ASFLAGS = -m68000 $(inc) LDFLAGS = -T megadrive.ld -print-gc-sections \ -L/usr/lib/gcc-cross/m68k-linux-gnu/11 -lgcc +Z80AS = vasmz80_oldstyle +Z80ASFLAGS = -Fvobj +Z80LD = vlink +Z80LDFLAGS = -T z80.ld -b rawbin1 + + $(bin): $(elf) $(OBJCOPY) -O binary $< $@ $(elf): $(obj) $(LD) -o $@ $(obj) -Map link.map $(LDFLAGS) +$(z80bin): $(z80obj) + $(Z80LD) -o $@ $(Z80LDFLAGS) $(z80obj) + +src/z80prog.o: src/z80prog.s $(z80bin) + -include $(dep) +%.z80: %.asm + $(Z80AS) -o $@ $(Z80ASFLAGS) $< >/dev/null + .PHONY: clean clean: rm -f $(obj) $(elf) $(bin) + rm -f $(z80obj) $(z80bin) .PHONY: cleandep cleandep: @@ -57,3 +76,4 @@ install: $(bin) mount /media/usbmass [ -f /media/usbmass/MEGA/MEGA.RBF ] || cp $(bin) /media/usbmass/MEGA/MEGA.BIN umount /media/usbmass + diff --git a/src/hwregs.h b/src/hwregs.h new file mode 100644 index 0000000..834be05 --- /dev/null +++ b/src/hwregs.h @@ -0,0 +1,16 @@ +#ifndef HWREGS_H_ +#define HWREGS_H_ + +#include + +#define REG16PTR(addr) (*(volatile uint16_t*)(addr)) + +#define Z80_MEMMODE REG16PTR(0xa11000) +#define Z80_BUSREQ REG16PTR(0xa11100) +#define Z80_RESET REG16PTR(0xa11200) +#define Z80_MEM ((uint8_t*)0xa00000) + +#define VDP_PORT_DATA REG16PTR(0xc00000) +#define VDP_PORT_CTL REG16PTR(0xc00004) + +#endif /* HWREGS_H_ */ diff --git a/src/intr.s b/src/intr.s index 8f4f01e..6dc8433 100644 --- a/src/intr.s +++ b/src/intr.s @@ -72,6 +72,7 @@ | from here on we continue in the regular .text section since we don't care | where this code ends up. .text + .include "vdpdefs.inc" .global enable_intr enable_intr: @@ -90,6 +91,7 @@ intr_fatal: | .extern vblank_handler intr_hblank: +| move.l %d0, -(%sp) | move.l #0xc0020000, VDP_PORT_CTL | | move.w testcol, %d0 @@ -97,8 +99,11 @@ intr_hblank: | rol.b #4, %d0 | move.w %d0, testcol | +| move.l (%sp)+, %d0 rte +|testcol: .word 0 + intr_vblank: | jsr vblank_handler rte diff --git a/src/libc/inttypes.h b/src/libc/inttypes.h new file mode 100644 index 0000000..fcbf7e1 --- /dev/null +++ b/src/libc/inttypes.h @@ -0,0 +1,12 @@ +#ifndef INTTYPES_H_ +#define INTTYPES_H_ + +typedef signed char int8_t; +typedef short int16_t; +typedef long int32_t; + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned long uint32_t; + +#endif /* INTTYPES_H_ */ diff --git a/src/main.c b/src/main.c index 31dbf45..34f8626 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,8 @@ +#include "z80.h" + int main(void) { + z80_init(); + return 0; } diff --git a/src/z80.c b/src/z80.c new file mode 100644 index 0000000..32ce82e --- /dev/null +++ b/src/z80.c @@ -0,0 +1,24 @@ +#include "z80.h" + +extern unsigned char z80prog[]; +extern long z80proglen; + +void z80_init(void) +{ + int i; + unsigned char *src, *dest; + + z80_grab_bus(); + z80_reset(0); + while(!z80_have_bus()); + + src = z80prog; + dest = Z80_MEM; + for(i=0; i