anago script file reference - flash mode

Script Files

Anago loads two script files - flashcore.nut and a spcified .af file. Please leave the flashcore.nut file unchanged.

.af file must define a variable and three functions. The variable is 'board', while the functions are 'initialize()', 'cpu_transfer()' and 'ppu_transfer()'. It's possible to define another function via brief scripting.

Sequence on Flash Programming Mode

Flash memory has a programming waiting period. During this period, the firmware can program another flash memory. Anago executes the following sequence:

  • intialize()
  • execute erase, wait until done
  • parallel execute cpu_tranfer() and ppu_transfer()

The most important function is initialize(), as it will configure an erase state once the initialize() function finishes.

  • Define command addresses by cpu_command() and ppu_command().
  • Locate command addresses by cpu_write()

In rare instances, it's possible to change command addresses on xxx_transfer().

The script file must be defined to transfer data sequentially. Anago switches programming threads automatically.

Needed functions and constants for .af file

board

  • mappernum: mapper number of iNES header when programming a NES file
  • cpu, ppu:
    • banksize: bank area length for xxx_program(). 0 is not a valid value.
    • maxsize: maximum manageable capacity for the target mapper.

The unit of both banksize and maxsize are in bytes.

initialize()

function initialize(d, cpu_banksize, ppu_banksize)

Arguments

  • d: userpointer
  • cpu_banksize: uses board.cpu.banksize
  • ppu_banksize: uses board.ppu.banksize

Returns

nothing

Description

This function defines and locates command addresses, which then configures an erase state when the initialize() function finishes.

cpu_transfer

function cpu_transfer(d, start, end, banksize)

Arguments

  • d: userpointer
  • start: Starting page number. This is used to substitute a variable for a loop.
  • end: Ending page number. This is used to define a term condition for the loop.
  • banksize: uses board.cpu.banksize. This is used to define an argument for cpu_program().

Returns

nothing

Description

This function is defined in order to transfer the ROM image to the CPU region. This transfers variable bank data by a defined loop, then transfers fixed bank data afterwards.

ppu_transfer

function ppu_transfer(d, start, end, banksize)

Arguments

  • d: userpointer
  • start: Starting page number. This is used to substitute a variable for a loop.
  • end: Ending page number. This is used to define a term condition for the loop.
  • banksize: uses board.ppu.banksize. This is used to define an argument for ppu_program()

Returns

nothing

Description

This function is defined to transfer ROM image to PPU region. All bank data is transferred by a defined loop.

Available functions for .af file

cpu_write()

function cpu_write(d, address, data) See decsription script_common_en

cpu_command()

function cpu_command(d, romoffset, memorymapoffset, banksize)

Arguments

  • d: userpointer
  • romoffset: flash memory command address (0, 0x02aa, 0x0555, 0x2aaa or 0x5555)
  • memorymapoffset: flash memory command address for CPU. Available range is 0x8000 to 0xffff.
  • banksize: target cpu memory address's banksize. 0x2000, 0x4000 or 0x8000.

Returns

nothing

Description

This function defines command addresses for the connected flash memory on the CPU region. It is defined via initialize(). In addition, it's possible to redefine this function during xxx_transfer().

ppu_command()

function ppu_command(d, romoffset, memorymapoffset, banksize)

Arguments

  • d: userpointer
  • romoffset: flash memory command address (0, 0x02aa, 0x0555, 0x2aaa or 0x5555)
  • memorymapoffset: flash memory command address for PPU. range is 0x0000 to 0x1fff:
  • banksize: target ppu memory address banksize. 0x0400, 0x0800, 0x1000 or 0x2000.

Returns

nothing

Description

Similar to the cpu_command(), this function defines command addresses for the connected flash memory on the PPU region.

cpu_program()

function cpu_program(d, address, length)

Arguments

  • d: userpointer
  • address: target address. Available range is 0x8000 to 0xffff.
  • length: writing length. Available range is 0x0100 to 0x3fff.

Returns

nothing

Description

This function programs data into the current CPU memory region. Anago switches threads automatically.

ppu_program()

function ppu_program(d, address, length)

Arguments

  • d: userpointer
  • address: target address. Available range is 0x0000 to 0x1fff.
  • length: writing length. Available range is 0x0100 to 0x3fff.

Returns

nothing

Description:

This function programs data into the current PPU memory region. Anago switches threads automatically.

cpu_erase(), ppu_erase()

function cpu_erase(d)
function ppu_erase(d)

Arguments

  • d: userpointer

Returns

nothing

Description

This function erases flash memory data on the current memory region. Since this function is already used in flashcore.nut, please do not use this function in an .af file.