The KARNAK mapper is only used in some Pocket Challenge V2 edutainment cartridges.
It is believed to be a revision of [[Bandai 2003]]. The RTC interface is removed, and a timer IRQ/hardware ADPCM decoder is added in its place.
While present in the programming interface, it is unclear if the GPO and Self-Flash registers are exposed by the chip physically.
{| class="wikitable"
! Category
! Port
! Description
! Bits
! Type
! Notes
|-
! rowspan="2" | GPO
! $CC
| GPO Data Direction
| style="text-align: right" | 0000 oooo
| RW8
| 1 = output, 0 = high-impedance (weak pull-down)
|-
! $CD
| GPO Data
| style="text-align: right" | 0000 dddd
| RW8
| 1 = 3V, if enabled by data direction
|-
! Self-Flash
! $CE
| Self-Flash Control
| style="text-align: right" | 0000 000r
| RW8
| 1 = ROM is accessible at segment 0x1000;
0 = RAM instead.
|-
! rowspan="4" | Extended bankswitching
! $CF
| ROM Linear (EX) Bank
| style="text-align: right" | 00bb bbbb
| RW8
| Selects a 1MiB bank accessed via segments 0x4000 through 0xF000. Identical to the register at 0xC0.
|-
! $D0
| RAM(/ROM) Bank
| style="text-align: right" | 0000 00bb bbbb bbbb
| RW16
| Selects a 64KiB bank accessed via segment 0x1000. Lower 8 bits are identical to the register at 0xC1.
|-
! $D2
| ROM0 Bank
| style="text-align: right" | 0000 00bb bbbb bbbb
| RW16
| Selects a 64KiB bank accessed via segment 0x2000. Lower 8 bits are identical to the register at 0xC2.
|-
! $D4
| ROM1 Bank
| style="text-align: right" | 0000 00bb bbbb bbbb
| RW16
| Selects a 64KiB bank accessed via segment 0x3000. Lower 8 bits are identical to the register at 0xC3.
|-
! rowspan=3|Timer/ADPCM
! $D6
| Timer/ADPCM Control
| style="text-align: right" | eppp pppp
| RW8
| Enable (e); Period (p). Units are the 384kHz clock to the cartridge.
|-
! $D8
| Sample input
| style="text-align: right" | aaaa bbbb
| W8
| Write one of two ADPCM nibbles, in order
|-
! $D9
| Sample output
| style="text-align: right" | ssss ssss
| R8
| Read current sample output
|}
== Timer ==
If enabled, the timer will emit a [[Interrupts|cartridge interrupt]] every ((period + 1) * 2) cartridge clocks, where "one cartridge clock" = 384KHz = 1/8th CPU clock.
== ADPCM ==
The ADPCM interface has been reverse engineered by Fredrik Ahlström.
The ADPCM decoder uses the same algorithm as found on the NEC uPD775x family of chips, with hardware saturation clamping.
Writing to $D8 advances the decoder by one sample. On the first write after reset, the top nybble is decoded, while the bottom nybble is ignored; on the second write, the bottom nybble is decoded. This pattern then repeats.
The $D9 port can be used to query the sample output. The internal accumulator is 10 bits long, with the middle 8 bits (1 .. 8) used as output. In addition, hardware saturation handling is performed: when the internal accumulator is between $200 and $2FF, $FF is output on the port; when it is between $300 and $3FF, $00 is output on the port. The initial accumulator value is $100 (reading $D9 returns $80), and the initial step index is $0.
== I/O ports ==
=== Timer/ADPCM Control ($D6, read/write) ===
7 bit 0 ---- ---- eppp pppp |||| |||| |+++-++++- Timer period +--------- Timer/ADPCM decoder enableWhen the timer and ADPCM decoder are disabled, the internal state is reset and is not affected by writes to $D8 === ADPCM Sample Input ($D8, write) ===
7 bit 0 ---- ---- aaaa bbbb |||| |||| |||| ++++- Second ADPCM input nibble ++++------ First ADPCM input nibble=== ADPCM Sample Output ($D9, read) ===
7 bit 0
---- ----
sSSSS SSSSs
|||| ||||
++++-++++- ADPCM sample output
(bits 1-8 of 10-bit accumulator)
== Links ==
* [https://github.com/FluBBaOfWard/KarnakTest KarnakTest] - test ROM and source of Karnak ADPCM documentation