Chip32-vm

OpcodeActionFlagsDescription
ADJFS Rx,Ry

FileSize[Rx] < = Ry

Adjusts file size of file #Rx to value Ry from the JSON.

Rx is the ID of the file to update, and Ry is the new size.

The file size is used when the system saves a file to the SD card (i.e. save RAM), and when using the LOADF instruction to load a file into the FPGA.

ADJFO Rx,Ry

FileOffset[Rx] < = Ry

Adjusts file offset of file #Rx to value Ry from the JSON.

Rx is the ID of the file to update, and Ry is the new offset.

The offset is where in the file loading begins when using LOADF. This allows skipping headers and other data that we do not wish to send to the FPGA.

ADJLP Rx,Ry

LoadAdd[Rx] < = Ry

Adjusts the loading point of file #Rx to address Ry from the JSON.

Rx is the ID of the file to update, and Ry is the new address.

The loading point is the start address in FPGA space where the file will be loaded using LOADF.

LOADF Rx

RX ← ID, Z ← 1 if success, Z ← 0 If failed

Z

Loads file ID Rx as specified in the JSON file.

The file is loaded into the FPGA using the parameters specified in the JSON file.

If these parameters are not correct or need updated, they can be updated using the ADJxx instructions.

Z is updated depending on success/failure.

Success means the file was loaded, and a failure would indicate it wasn't, due to some reason. i.e. the file does not exist, or it could not be opened.

Attempting to LOADF while a file is already OPEN will throw an error. (see the file commands below).

Before loading any data, LOADF will send a Host: Request Write with the slot ID and expected size of the data transfer in a similar way to a non-Chip32 load.

GETEXT Rx, Ry

MEM[Ry] ← Extension [Rx]

Gets the extension of file ID Rx and puts it into RAM starting at Ry.

A maximum of 256 characters should be allocated for the target string.

The file's extension is loaded into RAM starting at Ry. The “.” character is not included.

GETNAME Rx, Ry

MEM[Ry] ← Filename [Rx]

Gets the file name of file ID Rx and puts it into RAM starting at Ry.

A maximum of 256 characters should be allocated for the target string. The file&apo;s name and extension is loaded into RAM starting at Ry

QUERYSLOT Rx

Z ← Slot Result

Z

Queries a slot to see if there is a valid file present. Register Rx holds the ID of the slot to check. If a valid file is present (i.e. the file exists, and the slot ID is correct) Z will be set.

This is useful for checking if i.e. a save file is present so it can be loaded. Attempting to OPEN a non existent file will cause the file browser to appear, so we need a way to determine if a file exists or not without OPENing it.

OPEN Rx,Ry

File ← Rx, If Success Z ← 1 and Ry ← Filesize, If Fail Z ← 0

Z

Opens file ID Rx from the JSON.

This will open the file as indicated by the slot ID in Rx. If it was successful, the filesize in bytes will be loaded into Ry.

If the Z flag will be set if the open was successful, and clear if the file could not be opened (i.e. the file does not exist, no SD card, etc).

Attempting to open a file that does not exist will cause the file browser to open, and allow the user to select a new file, i.e. a palette file.

If you attempt to OPEN a file with another file already open, it will throw an error.

CLOSE

PC ← Error Location

Closes the opened file.

If a file was not open, this will throw an error.

It is not strictly required to close the file when exiting the VM, but it's a good idea to do it.

Exiting the VM will close any open file for you.

SEEK Rx

File Pointer ← Rx, If Success Z ← 1, If Fail Z ← 0

Z

Seeks to byte Rx in the file.

Z flag will return success or failure on if the seek worked or not. Seeking past the end of a file is not possible, and if it is attempted, will result in Z being cleared and no seek will happen.

Attempting to seek without opening a file first will throw an error.

READ Rx,Ry

RAM[Rx] ← File [Length of Ry], If Success Z ← 1, If Fail Z ← 0

Z

Reads data from the file.

Ry bytes will be read into RAM starting at Rx. The current position in the file is modified after either a READ, COPY, or SEEK instruction.

A maximum of 4K can be read at one time, and attempts to read past0x1fff will end at this point and not wrap around or go past the end of memory.

Z will be set on success and clear on failure like usual.

Attempting to READ a file without opening one first will throw an error.

COPY Rx,Ry

FPGA PMP[Rx] ← File [Length of Ry], If Success Z ← 1, If Fail Z ← 0

Z

Copies data from the file to the FPGA directly. Rx is the address on the FPGA to write to and Ry is how many bytes to copy. There's no restriction on size. Z is set on success and cleared on failure. Attempting to COPY from a file without opening one first will throw an error. Note that all addresses MUST BE 32 bit word aligned, and length must be a multiple of 32 bits. The address and length will have their lower two bits cleared before use to enforce this.