68k/Z80 communication: Difference between revisions

From NeoGeo Development Wiki
Jump to navigation Jump to search
m (BIOS -> system ROM)
mNo edit summary
Line 1: Line 1:
== 68k to Z80 (request) ==
Inter-CPU communication is done through a byte-wide bi-directional register.


Writes to the Z80 are byte-wide and made through {{Reg|REG_SOUND}}.<br>
=68k to Z80 (request)=
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.
Writes to the {{Chipname|Z80}} are made through {{Reg|REG_SOUND}}.
Any byte can be sent, its meaning is only determined by the way the Z80 code handles it (except for '''3 special cases''', as seen below).


(What chip is used on first gen chipset?)
When a byte is sent, the corresponding value is latched in {{Chipname|NEO-C1}} ({{Chipname|NEO-SUD}} in CD systems ?), and an NMI is triggered on the Z80 if enabled. The value can then be read on the Z80's port $00.


== Z80 to 68k (answer) ==
(What chip is used on first gen chipset ?)


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.
=Z80 to 68k (answer)=
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.
The Z80's port $0C is used to reply to the {{Chipname|68k}}. The value is also buffered in the same chips, but there are no interrupts generated.
The value can be read by using the same register, {{Reg|REG_SOUND}}.


== Special commands ==
Many [[sound driver]]s acknowledge sound commands by echoing them back with bit 7 set to 1 when they are processed.
Commands $01 and $03 are always expected to be implemented as they are used by the [[System ROM]] for initialization purposes.
 
=Special commands=
Commands $01 and $03 are always expected to be implemented in the Z80 code, as they are used by the [[System ROM]] 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.
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===
==Command $01==
It is sent by the system ROM 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 system ROM can then switch slot without crashing the Z80.
It is sent by the system ROM when the [[slot]] is switched. As the {{Chipname|M1 ROM}} will be swapped, all sounds need to be stopped, NMI need 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 the reply, the system ROM can then switch slots without crashing the Z80.


===Command $02===
==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.
It is used by cartridge systems to play the [[eye catcher]] 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===
==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.
It is used to ask for a soft reset of the Z80, which needs to be done under 100ms. No reply is expected.


=Minimal command handlers=
These are sufficient handlers for both init commands:
These are sufficient handlers for both init commands:


<pre>
<pre>
;"MAKOTO V3" style handler
;"MAKOTO V3" style handler
Command01_Handler: ; with the command in A
Command01_Handler:
di ; disable interrupts
di ; Disable interrupts
         xor  a
         xor  a
         out  ($0C),a
         out  ($0C),a
Line 41: Line 44:
         ld  hl,stayinram
         ld  hl,stayinram
         push hl
         push hl
         retn                    ; retn to stayinram
         retn                    ; RETN to stayinram


stayinram:
stayinram:
Line 53: Line 56:


<pre>
<pre>
Command03_Handler: ; with the command in A
Command03_Handler:
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
Line 62: Line 65:


[[Category:Audio system]]
[[Category:Audio system]]
[[Category:Code]]

Revision as of 02:11, 16 January 2016

Inter-CPU communication is done through a byte-wide bi-directional register.

68k to Z80 (request)

Writes to the Z80 are made through REG_SOUND. Any byte can be sent, its meaning is only determined by the way the Z80 code handles it (except for 3 special cases, as seen below).

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

(What chip is used on first gen chipset ?)

Z80 to 68k (answer)

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

Many sound 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 in the Z80 code, as they are used by the System ROM 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 system ROM when the slot is switched. As the M1 ROM will be swapped, all sounds need to be stopped, NMI need 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 the reply, the system ROM can then switch slots without crashing the Z80.

Command $02

It is used by cartridge systems to play the eye catcher 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.

Minimal command handlers

These are sufficient handlers for both init commands:

;"MAKOTO V3" style handler
Command01_Handler:
	di			; Disable interrupts
        xor  a
        out  ($0C),a
        out  ($00),a
        ; Init banks and stuff...
        ld   sp,#fffc
        ld   hl,stayinram
        push hl
        retn                    ; RETN to stayinram

stayinram:
        ld   hl,#fffd
        ld   (hl),#c3	        ; (FFFD)=C3, opcode for JP
        ld   (#fffe),hl	        ; (FFFE)=FFFD (JP FFFD)
        ld   a,#01
        out  (#0c),a            ; Tell 68k that we're ready
        jp   #fffd              ; Sit in RAM loop
Command03_Handler:
	di			; Disable interrupts
	ld   sp, $FFFF		; Clear call stack
	ld   hl,0
	push hl
	retn			; RETN to 0