68k/Z80 communication: Difference between revisions

From NeoGeo Development Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
== 68k to Z80 ==
== 68k to Z80 (request) ==


Writes to the Z80 are byte-wide and made through $320000.<br>
Writes to the Z80 are byte-wide and made through $320000 ('''REG_SOUND''').<br>
Any byte can be sent, their meaning are only determined by the way the Z80 code handles them except for 3 special cases, as seen below.
Any byte can be sent, their meaning are only determined by the way the Z80 code handles them (except for 3 special cases, as seen below).


When a byte is sent, the corresponding value is buffered in either the [[NEO-SUD]] or [[NEO-C1]] chip, and an NMI is generated on the Z80 if enabled. It can then be read on port $00.
When a byte is sent, the corresponding value is buffered in the [[NEO-C1]] chip ([[NEO-SUD]] in CD systems ), and an NMI is generated on the Z80 if enabled. It can then be read on the Z80's port $00.


(What chip is used on first gen chipset?)
(What chip is used on first gen chipset?)


== Z80 to 68k ==
== Z80 to 68k (answer) ==


Port $0C is used to reply to the 68K. The value is also buffered in the same chips, but there's no interrupts generated.
The Z80 port $0C is used to reply to the 68k. The value is also buffered in the same chips, but there's no interrupts generated.
The value can be read by using the same register, $320000.
The value can be read by using the same register, $320000.


Many drivers acknowledge sound commands by echoing them back with bit 7 set to 1 when they are processed.
Many drivers acknowledge sound commands by echoing them back with bit 7 set to 1 when they are processed.


== Special cases ==
== Special commands ==
Commands $01 and $03 are always expected to be implemented as they are used by the BIOSes for initialization purposes.
Commands $01 and $03 are always expected to be implemented as they are used by the [[BIOSes]] for initialization purposes.
Typically, if the Z80 doesn't reply to command $01 in time, the "[[Z80 ERROR]]" message is displayed and the system locks up.
During the MVS power up self-tests, if the Z80 doesn't reply to command $01 in time, the "[[Z80 ERROR]]" message is displayed and the system locks up.


Command $03 is then sent to ask for a soft reset of the Z80, but no replies are expected.
===Command $01===
It is sent by the BIOS when the [[slot]] is switched. As the Z80 rom will be swapped, all sounds need to be stopped, NMI needs to be activated, $01 needs to be sent back to the 68k and the Z80 code has to sit in a loop '''in RAM'''. After receiving that $01 reply, the BIOS can then switch slot without crashing the Z80.


Command $02 is used by cartridge systems to play the boot music. The pattern (melody) was certainly imposed by SNK, but developers often chose their own instruments parameters. [[Boot music]].
===Command $02===
It is used by cartridge systems to play the boot logo music. The pattern (melody) was certainly imposed by SNK, but developers often chose their own instruments parameters. [[Boot music]]. No reply is expected.
 
===Command $03===
It is used to ask for a soft reset of the Z80, which needs to be done under 100ms. No reply is expected.


These are sufficient handlers for both init commands:
These are sufficient handlers for both init commands:
Line 28: Line 33:
Command01_Handler: ; with the command in A
Command01_Handler: ; with the command in A
di ; disable interrupts
di ; disable interrupts
ld  sp, $FFFF ; clear call stack
ld  sp,$FFFF ; clear call stack
out ($0C),a ; echo the command
        ld  a,1
jr NMI_End ; usually POPs, then RETN
out ($0C),a ; echo the command back
jmp  $F800
.org $F800
lp:
        jr   lp
</pre>
</pre>


Line 37: Line 46:
di ; disable interrupts
di ; disable interrupts
ld  sp, $FFFF ; clear call stack
ld  sp, $FFFF ; clear call stack
ld hl,0
ld   hl,0
push hl
push hl
retn ; RETN to 0
retn ; RETN to 0

Revision as of 12:47, 8 October 2011

68k to Z80 (request)

Writes to the Z80 are byte-wide and made through $320000 (REG_SOUND).
Any byte can be sent, their meaning are only determined by the way the Z80 code handles them (except for 3 special cases, as seen below).

When a byte is sent, the corresponding value is buffered in the NEO-C1 chip (NEO-SUD in CD systems ), and an NMI is generated on the Z80 if enabled. It can then be read on the Z80's port $00.

(What chip is used on first gen chipset?)

Z80 to 68k (answer)

The Z80 port $0C is used to reply to the 68k. The value is also buffered in the same chips, but there's no interrupts generated. The value can be read by using the same register, $320000.

Many drivers acknowledge sound commands by echoing them back with bit 7 set to 1 when they are processed.

Special commands

Commands $01 and $03 are always expected to be implemented as they are used by the BIOSes for initialization purposes. During the MVS power up self-tests, if the Z80 doesn't reply to command $01 in time, the "Z80 ERROR" message is displayed and the system locks up.

Command $01

It is sent by the BIOS when the slot is switched. As the Z80 rom will be swapped, all sounds need to be stopped, NMI needs to be activated, $01 needs to be sent back to the 68k and the Z80 code has to sit in a loop in RAM. After receiving that $01 reply, the BIOS can then switch slot without crashing the Z80.

Command $02

It is used by cartridge systems to play the boot logo music. The pattern (melody) was certainly imposed by SNK, but developers often chose their own instruments parameters. Boot music. No reply is expected.

Command $03

It is used to ask for a soft reset of the Z80, which needs to be done under 100ms. No reply is expected.

These are sufficient handlers for both init commands:

Command01_Handler:		; with the command in A
	di			; disable interrupts
	ld   sp,$FFFF		; clear call stack
        ld   a,1
	out  ($0C),a		; echo the command back
	jmp  $F800
.org $F800
lp:
        jr   lp
Command03_Handler:		; with the command in A
	di			; disable interrupts
	ld   sp, $FFFF		; clear call stack
	ld   hl,0
	push hl
	retn			; RETN to 0