User:Zzo38/Mapper 768
I am reserving mapper 768 for my own use.
In all cases, the NES 2.0 file is arranged like (some parts may be omitted, depending on the header):
- Header
- Trainer
- PRG ROM
- CHR ROM
- INST-ROM
- PROM
- 128-byte null-terminated ASCII title
- Extra data for mapper 768 (depending on submapper number)
Submapper 0
The extra data stores the code for a virtual machine, to control the mapper. The commands are sixteen bits in small endian format, and are split into subroutine blocks. At the beginning of each block tells how many sixteen-bit commands are in this subroutine block.
The first block is always the initialization block.
Anything other than what is written in the codes acts like NROM (iNES mapper 0).
There is sixteen registers, with sixteen bits each. R0 and R1 are local to a subroutine call, and the R2 to R15 are global registers (all general purpose). There is also two more local registers, called W (working register) and W' (shadow working register).
Subroutine numbers are eight bits long. Each subroutine takes two parameters which is the initial assignment of R0 and R1 registers, and returns a sixteen bit number.
Commands
- 0000 0000 xxxx yyyy = Call a subroutine indicated in the low eight bits of Rx, with this call's R0 and R1 as its parameters, and store the result in Ry (leave Ry alone if the result is open bus or CIRAM).
- 0000 0001 0000 xxxx = Copy W to Rx.
- 0000 0001 0001 xxxx = Copy Rx to W.
- 0000 0001 0010 xxxx = Add W to Rx.
- 0000 0001 0011 xxxx = Add Rx to W.
- 0000 0001 0100 xxxx = Subtract W from Rx.
- 0000 0001 0101 xxxx = Subtract Rx from W.
- 0000 0001 0110 xxxx = Bitwise AND W to Rx.
- 0000 0001 0111 xxxx = Bitwise AND Rx to W.
- 0000 0001 1000 xxxx = Bitwise OR W to Rx.
- 0000 0001 1001 xxxx = Bitwise OR Rx to W.
- 0000 0001 1010 xxxx = Bitwise XOR W to Rx.
- 0000 0001 1011 xxxx = Bitwise XOR Rx to W.
- 0000 0001 1100 xxxx = Bitwise NAND W to Rx.
- 0000 0001 1101 xxxx = Bitwise NAND Rx to W.
- 0000 0001 1110 xxxx = Copy NOT W to Rx.
- 0000 0001 1111 xxxx = Copy NOT Rx to W.
- 0000 0010 0000 xxxx = Return the value in Rx from this subroutine.
- 0000 0010 0001 0000 = Return open bus from this subroutine.
- 0000 0010 0001 0010 = Return CIRAM bank 0 from this subroutine. (Returning CIRAM banks is the same as open bus unless the PPU is accessing this memory.)
- 0000 0010 0001 0011 = Return CIRAM bank 1 from this subroutine.
- 0000 0010 0001 1xxx = Return the literal value x (all other bits zero) from this subroutine.
- 0000 0011 0000 0000 = Swap W with W'.
- 0000 0011 0001 xxxx = Store an immediate value into Rx. The condition flag is set to if the value changed.
- 0000 0011 0010 xxxx = Shift left Rx. The shifted out bit is stored in the condition flag.
- 0000 0011 0011 xxxx = Add an immediate value to Rx. The condition flag is set to if there is the signed overflow.
- 0000 0011 0100 xxxx = Arithmetic shift right Rx. The shifted out bit is stored in the condition flag.
- 0000 0011 0110 xxxx = Rotate right Rx.
- 0000 0011 0111 xxxx = Bitwise AND an immediate value to Rx. The condition flag is set to if the value changed.
- 0000 0011 1001 xxxx = Bitwise OR an immediate value to Rx. The condition flag is set toif the value changed.
- 0000 0011 1010 xxxx = Logical shift right Rx. The shifted out bit is stored in the condition flag.
- 0000 0011 1011 xxxx = Bitwise XOR an immediate value to Rx. The condition flag is set to if the value changed.
- 0000 0011 1100 xxxx = Bitwise invert Rx.
- 0000 0011 1101 xxxx = Bitwise NAND an immediate value to Rx. The condition flag is set if and only if the value changed.
- 0000 0011 1110 xxxx = Set the condition flag if Rx is zero, or clear the condition flag otherwise.
- 0000 0011 1111 xxxx = Set the condition flag if the immediate value is equal to Rx, or clear the condition flag otherwise.
- 0000 0100 000x xxxx = Skip x+1 instructions (counting immediate values as instructions) if the condition flag is set.
- 0000 0100 001x xxxx = Skip x+1 instructions (counting immediate values as instructions) if the condition flag is clear.
- 0000 0100 0100 0000 = Trigger IRQ.
- 0000 0100 0101 0000 = Force battery RAM to be write-protected.
- 0000 0100 0101 0001 = Turn off the forced write-protection of battery RAM.
- 0001 0000 xxxx xxxx = Using W as a start address, W' as a end address, and R15 as a mask (any set bits in the mask correspond to address bits that must match that of the start address), set the subroutine calls for reading PRG memory to the subroutine x.
- 0001 0001 xxxx xxxx = Set the subroutine calls for writing PRG memory to the subroutine x.
- 0001 0010 xxxx xxxx = Set the subroutine calls for reading CHR memory to the subroutine x.
- 0001 0011 xxxx xxxx = Set the subroutine calls for writing CHR memory to the subroutine x.
- 0001 0011 xxxx xxxx = Set the subroutine calls for writing CHR memory to the subroutine x.
- 0001 1000 xxxx xxxx = Set the subroutine calls for reset to the subroutine x.
- 0001 1001 xxxx xxxx = Set the subroutine calls for FDS IRQ to the subroutine x.
- 0100 xxxx yyyy yyyy = Set a timer for Rx CPU clocks to call subroutine y (just once, when the timer expires). If Rx is -1 then it is turned off.
- 0101 xxxx yyyy yyyy = Set a timer for Rx PPU reads to call subroutine y (just once, when the timer expires). If Rx is -1 then it is turned off.
- 1000 xxxx yyyy yyyy = Call subroutine y with this subroutine's W and W' as parameters, and store the result in Rx (leave Rx alone if the result is open bus or CIRAM).
- 1001 0000 xxxx yyyy = Read from the NSF interface, address in Rx, into Ry.
- 1001 0001 xxxx yyyy = Write to the NSF interface, address Rx, value Ry.
- 1001 0010 xxxx yyyy = Read from the PRG ROM, address Rx, into Ry.
- 1001 0100 xxxx yyyy = Read from the CHR ROM, address Rx, into Ry.
- 1001 0110 xxxx yyyy = Read from the trainer ROM, address Rx, into Ry.
- 1001 1000 xxxx yyyy = Read from non-battery PRG RAM, address in Rx, into Ry.
- 1001 1001 xxxx yyyy = Write to non-battery PRG RAM, address Rx, value Ry.
- 1001 1010 xxxx yyyy = Read from non-battery CHR RAM, address Rx, into Ry.
- 1001 1011 xxxx yyyy = Write to non-battery CHR RAM, address Rx, value Ry.
- 1001 1100 xxxx yyyy = Read from battery PRG RAM, address Rx, into Ry.
- 1001 1101 xxxx yyyy = Write to battery PRG RAM, address Rx, value Ry.
- 1001 1110 xxxx yyyy = Read from battery CHR RAM, address Rx, into Ry.
- 1001 1111 xxxx yyyy = Write to battery CHR RAM, address Rx, value Ry.
When a subroutine call is triggered due to CPU or PPU read/write, R0 will be the address, and R1 will be the data for writing (R1 is undefined if reading). Returning CIRAM bank 0 or CIRAM bank 1 from PPU read routines causes it to read the CIRAM instead of the cartridge. Returning CIRAM banks from PPU write routines causes it to write to the CIRAM of the specified bank (the routine can do other things too). Returning open bus or any number from any write routine, or any CIRAM bank from any PRG write routine, does nothing.
NSF Interface
- $0000-$00FF: General purpose RAM (stored in the cartridge; not the same as the CPU RAM, or the cartridge PRG RAM and CHR RAM mentioned in the header; this is only accessible by the NSF interface).
- $2000,$2001: Sixteen bit CPU clock counter; can be written as well.
- $2002,$2003: Sixteen bit PPU read counter; can be written as well.
- $2008: Clear the low bit to force battery RAM to be write-protected.
- $2009: Write-only. If low bit is set, 2A03 audio is muted.
- $200C: Non-battery PRG RAM bank select.
- $200D: Battery PRG RAM bank select.
- $200E: Non-battery CHR RAM bank select.
- $200F: Battery CHR RAM bank select.
- $4020-$4092: FDS registers. All registers (including audio) are available, although bit3 of $4025 has no effect.
- $4800,$F800: Namco 163 audio.
- $5000-$5015: MMC5 audio. The read mode acts on CPU memory, not NSF memory.
- $5205,$5206: MMC5 hardware multiplication register.
- $9000-$9003,$A000-$A002,$B000-$B002: VRC6 audio.
- $9010,$9030: VRC7 audio.
- $C000,$E000: Sunsoft 5B audio.
Submapper 1
Extra data is not used. There is expected to be a file with .nes.v extension (otherwise having the same name), which contains a Verilog code for implementing the mapper.
The first sixty I/O ports of the main module of the Verilog code must correspond to the pins 01 to 60 of the 60-pin Famicom cartridge, in that order. This is followed by the pins for the PRG ROM, CHR ROM, non-battery PRG RAM, non-battery CHR RAM, battery PRG RAM, and battery CHR RAM.
The ROM/RAM pins are only for the ROM/RAM which are existing, and is as follows:
- Chip enable (low to enable)
- Write enable (low to enable; not exist for ROM)
- Address pins (the exact number of pins needed for the ROM/RAM of the size specified in the NES 2.0 header)
- Data pins (always eight)
The commands with $ at front might not be implemented, but should be safely ignored if not implemented. However, if there is a trainer ROM, there will be an additional command $trainer to access 8-bit numbers given the 9-bit address, and $battery_init which tell you if you need to initialize the battery RAM.
Analog commands may be used with the audio signals.