SEGA Genesis: Z80

Beside the main Motorola 68000 CPU, the SEGA Genesis has a Z80, often used for audio processing

Z80

https://zeptobars.com/en/read/Zilog-Z80-Z0840004PSC
- Resetting Z80
- Write to Z80 memory
Silence:
move.w #$0100,$00A11100 ; Request access to the Z80 bus,
; by writing $0100 into the BUSREQ port
.wait:
btst #$0,$00A11101 ; Test bit 0 of A11100 to see if the 68k
; has access to the Z80 bus yet
bne .wait ; If we don't yet have control, branch back up
;Now the 68000 has access to the Z80’s bus,and the chip is held in a reset state,so we can write the program data to its memory. This is mapped from $A000000.
move.b #$F,z80_memory+$100
move.w #$0000,$00A11100 ; Release control of bus
## Loading Z80 code
Z80Code:
incbin "..\..\roms\z80.bin"
Z80CodeEnd:
move.w #$0100,z80_busreq ; Request access to the Z80 bus,by writing $0100 into the BUSREQ port
move.w #$0100,z80_reset ; Hold the Z80 in a reset state,by writing $0100 into the RESET port
.wait:
btst #$0,z80_busreq ; Test bit 0 of A11100 to see if the 68k has access to the Z80 bus yet
bne .wait ; If we don't yet have control,branch back up to Wait
;Now the 68000 has access to the Z80’s bus,and the chip is held in a reset state,so we can write the program data to its memory. This is mapped from $A000000.
move.l #Z80Code,a0 ; Load address of data into a0
move.l #z80_memory,a1 ; Copy Z80 RAM address to a1
move.l #Z80CodeEnd-Z80Code-1,d0 ; 42 bytes of init data (minus 1 for counter)
.CopyZ80:
move.b (a0)+,(a1)+ ; Copy data,and increment the source/dest addresses
dbra d0,.CopyZ80
move.b #$1,z80_memory+$100 ; this works
move.w #$0000,z80_reset ; Release reset state
move.w #$0000,z80_busreq ; Release control of bus
move.w #$0100,z80_reset ; Reset Z80
## Playing a beep