Z80: Difference between revisions

From NeoGeo Development Wiki
Jump to navigation Jump to search
mNo edit summary
(Merged Z80 pages about memory)
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[File:cd2_z80.jpg|right|thumb|Z80 in a surface mount package, as found in the MVS and CD hardware.]]
[[File:cd2_z80.jpg|right|thumb|Z80 in a surface mount package, as found on some MVS and CD boards.]]


The Z80 is an 8bit CPU designed by Zilog.
The Z80 is a 8-bit little-endian CPU designed by Zilog.


All NeoGeo systems use it as a coprocessor to handle "tracker music" playback. It only has access to the YM2610, M1 ROM or .Z80 files, and its RAM.
It is used in NeoGeo systems as a sub-CPU to handle sound and music playback. It runs at [[clock|4MHz]] and only has access to the {{Chipname|YM2610}}, the {{Chipname|M1 ROM}} (or [[Z80 file]]s), and its [[Z80 RAM|own RAM]]. It communicates with the {{Chipname|68k}} CPU via a [[68k/Z80 communication|single-byte channel]].


See [[68k/Z80 communication]].
Because it doesn't share a RAM area with the 68k CPU like on the Sega Genesis, it can't be used efficiently to offload game computation tasks from the main CPU.


Since it doesn't share any direct memory zones with the [[68k]], it can't be used to perform or speed up gameplay-related tasks.
Also see:
* [[Z80 port map]]
* [[Z80 bankswitching]]


See [[Z80 Memory Map]].
[[File:aes_z80.jpg|right|thumb|Z80 in DIP package, as found on AES boards.]]
 
=Interrupts=
 
* IRQs (address $38) are triggered by the YM2610 timers, if enabled.
* An NMI (address $66) is triggered when the 68k sends a byte.
 
=Memory map=
 
[[File:Z80mmap.png|thumb|Visualization of the Z80's memory map (proportional areas).]]
 
==Cartridge systems==
 
{| class="regdef"
|'''Start'''
|'''End'''
|'''Size'''
|'''Description'''
|-
|$0000
|$7FFF
|32KiB
|Static main code bank (start of the [[M1 ROM]])
|-
|$8000
|$BFFF
|16KiB
|Switching window 3
|-
|$C000
|$DFFF
|8KiB
|Switching window 2
|-
|$E000
|$EFFF
|4KiB
|Switching window 1
|-
|$F000
|$F7FF
|2KiB
|Switching window 0
|-
|$F800
|$FFFF
|2KiB
|[[Z80 RAM|Work RAM]]
|}
 
Having a 16-bit address bus, the {{Chipname|Z80}} CPU allows access to 64KiB of memory at most. In NeoGeo [[cartridges]], the {{Chipname|NEO-ZMC}} or {{Chipname|NEO-ZMC2}} chips provide a way to access more memory for [[M1 ROM]]s up to 4MiB. Four different switchable zones ("windows") are available.
 
The bank that appear in these windows are configured by '''reading''' from 4 of the Z80's [[Z80 port map|ports]] (see page for explanation).
 
Bank offsets numbering depend on the window sizes:
 
* Window 0 counts in 2KiB increments
* Window 1 in 4KiB
* Window 2 in 8KiB
* Window 3 in 16KiB
 
On cartridge systems, all windows are initialized to 0 (verified on hardware). Many [[sound driver]]s start up by initializing the windows properly like indicated above.
 
For example, this code simply maps the Z80 $0000~$F7FF address range to M1 ROM $0000~$F7FF linearly, with no gaps.
 
<pre>
ld    a,$1E
in    a,($08)    ; Set window 0 at $1E*$800 = $F000
ld    a,$0E
in    a,($09)    ; Set window 1 at $E*$1000 = $E000
ld    a,$06
in    a,($0A)    ; Set window 2 at $6*$2000 = $C000
ld    a,$02
in    a,($0B)    ; Set window 3 at $2*$4000 = $8000
</pre>
 
===Bank selection===
 
[[The King of Fighters '97]] does this:
 
<pre>
; 32KiB bank number in A
rlca
rlca
ld    e,a
ld    d,$00      ; DE = A * 4 (table entry size)
ld    hl,$289C  ; Table address, see below
add  hl,de
ld    a,(hl)
in    a,($08)    ; Set zone 0
inc  hl
ld    a,(hl)
in    a,($09)    ; Set zone 1
inc  hl
ld    a,(hl)
in    a,($0A)    ; Set zone 2
inc  hl
ld    a,(hl)
in    a,($0B)    ; Set zone 3
</pre>
 
The table at $289C is used to set the 4 zones like an unique $7800-bytes long one in 32KiB increments, meaning that $800 bytes are wasted at the end of each range (mapped to [[Z80 RAM]]).
 
<pre>
Data at $289C:
 
1E 0E 06 02  = F000,  E000,  C000,  8000  "Big bank 0": $8000~ $F7FF  ($F800~ $FFFF  is wasted)
2E 16 0A 04  = 17000, 16000, 14000, 10000  "Big bank 1": $10000~$177FF  ($177FF~$17FFF is wasted)
3E 1E 0E 06  = 1F000, 1E000, 1C000, 18000  "Big bank 2": $18000~$1F7FF  ($1F7FF~$1FFFF is wasted)
4E 26 12 08  = 27000, 26000, 24000, 20000  "Big bank 3": $20000~$277FF  ($277FF~$27FFF is wasted)
5E 2E 16 0A  = 2F000, 2E000, 2C000, 28000  "Big bank 4": $28000~$2F7FF  ($2F7FF~$2FFFF is wasted)
6E 36 1A 0C  = 37000, 36000, 34000, 30000  "Big bank 5": $30000~$377FF  ($377FF~$37FFF is wasted)
7E 3E 1E 0E  = 3F000, 3E000, 3C000, 38000  "Big bank 6": $38000~$3F7FF  ($3F7FF~$3FFFF is wasted)
</pre>
 
Note that the game has a 128KiB [[M1 ROM]], but the table is long enough to map up to 256KiB.
 
==CD systems==
 
CD systems only have 64KiB of RAM dedicated to the {{Chipname|Z80}}. There's no bankswitching.
 
It seems that {{Chipname|NEO-SUD}} allows loading [[Z80 file]]s accross the whole range, and locks $0000~$F7FF as read-only to simulate ROM during execution.


[[File:aes_z80.jpg|right|thumb|Z80 in DIP package, as found on AES boards.]]
=Pinout=
 
[[File:Z80_pinout.png|640px]]
 
=Datasheet=
 
Z8400 datasheet: [[http://www.datasheetcatalog.org/datasheets/restul/285906_DS.pdf]]


[[Category:Chips]]
[[Category:Chips]]
[[Category:Audio system]]
[[Category:Audio system]]
[[Category:CPUs]]
[[Category:Base system]]

Latest revision as of 08:21, 28 January 2024

Z80 in a surface mount package, as found on some MVS and CD boards.

The Z80 is a 8-bit little-endian CPU designed by Zilog.

It is used in NeoGeo systems as a sub-CPU to handle sound and music playback. It runs at 4MHz and only has access to the YM2610, the M1 ROM (or Z80 files), and its own RAM. It communicates with the 68k CPU via a single-byte channel.

Because it doesn't share a RAM area with the 68k CPU like on the Sega Genesis, it can't be used efficiently to offload game computation tasks from the main CPU.

Also see:

Z80 in DIP package, as found on AES boards.

Interrupts

  • IRQs (address $38) are triggered by the YM2610 timers, if enabled.
  • An NMI (address $66) is triggered when the 68k sends a byte.

Memory map

Visualization of the Z80's memory map (proportional areas).

Cartridge systems

Start End Size Description
$0000 $7FFF 32KiB Static main code bank (start of the M1 ROM)
$8000 $BFFF 16KiB Switching window 3
$C000 $DFFF 8KiB Switching window 2
$E000 $EFFF 4KiB Switching window 1
$F000 $F7FF 2KiB Switching window 0
$F800 $FFFF 2KiB Work RAM

Having a 16-bit address bus, the Z80 CPU allows access to 64KiB of memory at most. In NeoGeo cartridges, the NEO-ZMC or NEO-ZMC2 chips provide a way to access more memory for M1 ROMs up to 4MiB. Four different switchable zones ("windows") are available.

The bank that appear in these windows are configured by reading from 4 of the Z80's ports (see page for explanation).

Bank offsets numbering depend on the window sizes:

  • Window 0 counts in 2KiB increments
  • Window 1 in 4KiB
  • Window 2 in 8KiB
  • Window 3 in 16KiB

On cartridge systems, all windows are initialized to 0 (verified on hardware). Many sound drivers start up by initializing the windows properly like indicated above.

For example, this code simply maps the Z80 $0000~$F7FF address range to M1 ROM $0000~$F7FF linearly, with no gaps.

ld    a,$1E
in    a,($08)    ; Set window 0 at $1E*$800 = $F000
ld    a,$0E
in    a,($09)    ; Set window 1 at $E*$1000 = $E000
ld    a,$06
in    a,($0A)    ; Set window 2 at $6*$2000 = $C000
ld    a,$02
in    a,($0B)    ; Set window 3 at $2*$4000 = $8000

Bank selection

The King of Fighters '97 does this:

; 32KiB bank number in A
rlca
rlca
ld    e,a
ld    d,$00      ; DE = A * 4 (table entry size)
ld    hl,$289C   ; Table address, see below
add   hl,de
ld    a,(hl)
in    a,($08)    ; Set zone 0
inc   hl
ld    a,(hl)
in    a,($09)    ; Set zone 1
inc   hl
ld    a,(hl)
in    a,($0A)    ; Set zone 2
inc   hl
ld    a,(hl)
in    a,($0B)    ; Set zone 3

The table at $289C is used to set the 4 zones like an unique $7800-bytes long one in 32KiB increments, meaning that $800 bytes are wasted at the end of each range (mapped to Z80 RAM).

Data at $289C:

1E 0E 06 02  = F000,  E000,  C000,  8000   "Big bank 0": $8000~ $F7FF   ($F800~ $FFFF  is wasted)
2E 16 0A 04  = 17000, 16000, 14000, 10000  "Big bank 1": $10000~$177FF  ($177FF~$17FFF is wasted)
3E 1E 0E 06  = 1F000, 1E000, 1C000, 18000  "Big bank 2": $18000~$1F7FF  ($1F7FF~$1FFFF is wasted)
4E 26 12 08  = 27000, 26000, 24000, 20000  "Big bank 3": $20000~$277FF  ($277FF~$27FFF is wasted)
5E 2E 16 0A  = 2F000, 2E000, 2C000, 28000  "Big bank 4": $28000~$2F7FF  ($2F7FF~$2FFFF is wasted)
6E 36 1A 0C  = 37000, 36000, 34000, 30000  "Big bank 5": $30000~$377FF  ($377FF~$37FFF is wasted)
7E 3E 1E 0E  = 3F000, 3E000, 3C000, 38000  "Big bank 6": $38000~$3F7FF  ($3F7FF~$3FFFF is wasted)

Note that the game has a 128KiB M1 ROM, but the table is long enough to map up to 256KiB.

CD systems

CD systems only have 64KiB of RAM dedicated to the Z80. There's no bankswitching.

It seems that NEO-SUD allows loading Z80 files accross the whole range, and locks $0000~$F7FF as read-only to simulate ROM during execution.

Pinout

Datasheet

Z8400 datasheet: [[1]]