notes:comporg:spring2024:virconref
This is an old revision of the document!
Table of Contents
Vircon32 ASM Reference Guide
This document is based on Vircon32 DevTools v24.02.04; older versions will contain inconsistencies.
Token | Value |
---|---|
VirconVersion | 1 |
VirconRevision | 0 |
FramesPerSecond | 60 |
CyclesPerSecond | 15000000 |
CyclesPerFrame | CyclesPerSecond / FramesPerSecond |
ScreenWidth | 640 |
ScreenHeight | 360 |
ScreenPixels | ScreenWidth * ScreenHeight |
GPUTextureSize | 1024 |
GPUMaximumCartridgeTextures | 256 |
GPURegionsPerTexture | 4096 |
GPUPixelCapacityPerFrame | 9 * ScreenPixels |
GPUClearScreenPenalty | -0.50f |
GPUScalingPenalty | +0.15f |
GPURotationPenalty | +0.25f |
SPUMaximumCartridgeSounds | 1024 |
SPUMaximumCartridgeSamples | 1024 * 1024 * 256 |
SPUMaximumBiosSamples | 1024 * 1024 * 1 |
SPUSoundChannels | 16 |
SPUSamplingRate | 44100 |
SPUSamplesPerFrame | SPUSamplingRate / FramesPerSecond |
MaximumCartridgeProgramROM | 1024 * 1024 * 128 |
MaximumBiosProgramROM | 1024 * 1024 * 1 |
RAMSize | 1024 * 1024 * 4 |
MemoryCardSize | 1024 * 256 |
MemoryBusSlaves | 4 |
ControlBusSlaves | 8 |
GamepadPorts | 4 |
Assembler Data Directives (ROM)
keyword | description |
---|---|
integer | specify one or more integers |
float | specify one or more floats |
string | specify string sequence(s?) |
pointer | specify pointer(s?) |
datafile | specify datafile(s?) |
Use commas to separate values (create “array” of values)
Vircon32 Instruction Set
control | branch | compare | data | convert | logic | int arithmetic | float arithmetic | float math |
---|---|---|---|---|---|---|---|---|
HLT | JMP | IEQ | MOV | CIF | NOT | IADD | FADD | FLR |
WAIT | CALL | INE | LEA | CFI | AND | ISUB | FSUB | CEIL |
RET | IGT | PUSH | CIB | OR | IMUL | FMUL | ROUND | |
JT | IGE | POP | CFB | XOR | IDIV | FDIV | SIN | |
JF | ILT | IN | BNOT | IMOD | FMOD | ACOS | ||
ILE | OUT | SHL | ISGN | FSGN | ATAN2 | |||
FEQ | MOVS | IMIN | FMIN | LOG | ||||
FNE | SETS | IMAX | FMAX | POW | ||||
FGT | CMPS | IABS | FABS | |||||
FGE | ||||||||
FLT | ||||||||
FLE |
Vircon32 Memory Map
Name | Address/Range | Description |
---|---|---|
RAMFirstAddress | 0x00000000-0x003FFFFF | read/write memory (16MB) |
stack init address | 0x003FFFFF | default location of SP (last RAM address) |
BiosProgramROMFirstAddress | 0x10000000 | Vircon32 BIOS |
CartridgeProgramROMFirstAddress | 0x20000000 | Cartridge Data |
MemoryCardRAMFirstAddress | 0x30000000 | Memory Card Data |
Vircon32 I/O Port Layout
Port Address | Vircon32 ID | Description |
---|---|---|
0x000 | TIM_FirstPort | time related functionality |
0x100 | RNG_FirstPort | random number generator |
0x200 | GPU_FirstPort | graphics |
0x300 | SPU_FirstPort | sound processing |
0x400 | INP_FirstPort | input (game controllers) |
0x500 | CAR_FirstPort | cartridge interface |
0x600 | MEM_FirstPort | memory card |
IOPorts
TIME
Type | Port | Name | Description |
---|---|---|---|
IN | 0x000 | TIM_CurrentDate | retrieve current date |
IN | 0x001 | TIM_CurrentTime | retrieve current time |
IN | 0x002 | TIM_FrameCounter | retrieve current frame count |
IN | 0x003 | TIM_CycleCounter | retrieve current cycle count |
example: get current frame count
in R0, TIM_FrameCounter ; load current frame count into R0
RNG
Type | Port | Name | Description |
---|---|---|---|
IN | 0x100 | RNG_CurrentValue | obtain pseudorandom value |
OUT | 0x100 | RNG_CurrentValue | Seed random number generator |
GPU
Type | Port | Name | Description |
---|---|---|---|
OUT | 0x200 | GPU_Command | perform GPU operation |
??? | 0x201 | GPU_RemainingPixels | ??? |
OUT | 0x202 | GPU_ClearColor | color to clear the screen with |
??? | 0x203 | GPU_MultiplyColor | ??? |
??? | 0x204 | GPU_ActiveBlending | ??? |
OUT | 0x204 | GPU_SelectedTexture | texture ID to select (-1 for BIOS) |
OUT | 0x205 | GPU_SelectedRegion | region ID to select |
OUT | 0x206 | GPU_DrawingPointX | set X position to draw selected region |
OUT | 0x207 | GPU_DrawingPointY | set Y position to draw selected region |
??? | 0x208 | GPU_DrawingScaleX | sets X scaling with a float as input |
??? | 0x209 | GPU_DrawingScaleY | sets Y scaling with a float as input |
??? | 0x20A | GPU_DrawingAngle | ??? |
OUT | 0x20B | GPU_RegionMinX | set Min X coordinate for region |
OUT | 0x20C | GPU_RegionMinY | set Min Y coordinate for region |
OUT | 0x20D | GPU_RegionMaxX | set Max X coordinate for region |
OUT | 0x20E | GPU_RegionMaxY | set Max Y coordinate for region |
OUT | 0x20F | GPU_RegionHotspotX | set region Hotspot X coordinate |
OUT | 0x210 | GPU_RegionHotspotY | set region Hotspot Y coordinate |
Commands that can be issued to the GPU:
value | name | description |
---|---|---|
0x10 | GPUCommand_ClearScreen | clears the screen using current clear color |
0x11 | GPUCommand_DrawRegion | draws the selected region: Rotation off, Zoom off |
0x12 | GPUCommand_DrawRegionZoomed | draws the selected region: Rotation off, Zoom on |
0x13 | GPUCommand_DrawRegionRotated | draws the selected region: Rotation on , Zoom off |
0x14 | GPUCommand_DrawRegionRotozoomed | draws the selected region: Rotation on , Zoom on |
GPU Active Blending Port Commands
Active blending:
value | name | description |
---|---|---|
0x20 | GPUBlendingMode_Alpha | default rendering, uses alpha channel as transparency |
0x21 | GPUBlendingMode_Add | colors are added (light effect), also called linear dodge |
0x22 | GPUBlendingMode_Subtract | colors are subtracted (shadow effect), also called difference |
SPU
Type | Port | Name | Description |
---|---|---|---|
??? | 0x300 | SPU_Command | ??? |
??? | 0x301 | SPU_GlobalVolume | ??? |
??? | 0x302 | SPU_SelectedSound | ??? |
??? | 0x303 | SPU_SelectedChannel | ??? |
??? | 0x304 | SPU_SoundLength | ??? |
??? | 0x305 | SPU_SoundPlayWithLoop | ??? |
??? | 0x306 | SPU_SoundLoopStart | ??? |
??? | 0x307 | SPU_SoundLoopEnd | ??? |
??? | 0x308 | SPU_ChannelState | ??? |
??? | 0x309 | SPU_ChannelAssignedSound | ??? |
??? | 0x30A | SPU_ChannelVolume | ??? |
??? | 0x30B | SPU_ChannelSpeed | ??? |
??? | 0x30C | SPU_ChannelLoopEnabled | ??? |
??? | 0x30D | SPU_ChannelPosition | ??? |
SPU Commands
Commands for the SPU:
value | name | description |
---|---|---|
0x30 | SPUCommand_PlaySelectedChannel | if paused, it is resumed; if already playing, it is retriggered |
0x31 | SPUCommand_PauseSelectedChannel | no effect if the channel was not playing |
0x32 | SPUCommand_StopSelectedChannel | position is rewinded to sound start |
0x33 | SPUCommand_PauseAllChannels | same as applying PauseChannel to all channels |
0x34 | SPUCommand_ResumeAllChannels | same as applying PlayChannel to all paused channels |
0x35 | SPUCommand_StopAllChannels | same as applying StopChannel to all channels |
SPU Channel States
States of the sound channels:
value | name | description |
---|---|---|
0x40 | SPUChannelState_Stopped | channel is not playing, and will begin new reproduction on play |
0x41 | SPUChannelState_Paused | channel is paused, and will resume reproduction on play |
0x42 | SPUChannelState_Playing | channel is currently playing, until its assigned sound ends |
INPUT
Type | Port | Name | Description |
---|---|---|---|
IN | 0x400 | INP_SelectedGamepad | Which gamepad is selected (0-3) |
OUT | 0x400 | INP_SelectedGamepad | Select indicated gamepad (0-3) |
??? | 0x401 | INP_GamepadConnected | ??? |
??? | 0x402 | INP_GamepadLeft | ??? |
??? | 0x403 | INP_GamepadRight | ??? |
??? | 0x404 | INP_GamepadUp | ??? |
??? | 0x405 | INP_GamepadDown | ??? |
??? | 0x406 | INP_GamepadButtonStart | ??? |
??? | 0x407 | INP_GamepadButtonA | ??? |
??? | 0x408 | INP_GamepadButtonB | ??? |
??? | 0x409 | INP_GamepadButtonX | ??? |
??? | 0x40A | INP_GamepadButtonY | ??? |
??? | 0x40B | INP_GamepadButtonL | ??? |
??? | 0x40C | INP_GamepadButtonR | ??? |
Type | Port | Name | Description |
IN? | 0x500 | CAR_Connected | status of cartridge being connected |
IN? | 0x501 | CAR_ProgramROMSize | size of program ROM |
IN? | 0x502 | CAR_NumberOfTextures | number of cartridge textures |
IN? | 0x503 | CAR_NumberOfSounds | number of cartridge sounds |
MEMCARD
Type | Port | Name | Description |
---|---|---|---|
IN? | 0x600 | MEM_Connected | status of memory card being connected |
Instructions
There are 64 CPU opcodes, so instructions encode them in 6 bits. No invalid opcodes can exist. HLT is opcode 0 for safety: if an empty or invalid instruction is found, the CPU will stop execution.
opcode | mneumonic | category | description |
---|---|---|---|
0x00 | HLT | control | halt processing |
0x01 | WAIT | control | pause processing, wait for next frame |
0x02 | JMP | branch | unconditional jump to address |
0x03 | CALL | branch | call subroutine |
0x04 | RET | branch | return from subroutine |
0x05 | JT | branch | jump if true (1) |
0x06 | JF | branch | jump if false (0) |
0x07 | IEQ | compare | integer equal |
0x08 | INE | compare | integer not equal |
0x09 | IGT | compare | integer greater than |
0x0A | IGE | compare | integer greater than or equal |
0x0B | ILT | compare | integer less than |
0x0C | ILE | compare | integer less than or equal |
// float comparisons FEQ, // Float Equal FNE, // Float Not Equal FGT, // Float Greater Than FGE, // Float Greater or Equal FLT, // Float Less Than FLE, // Float Less or Equal // data movement MOV, // Move data LEA, // Load effective address of a memory position PUSH, // Save on top of the stack POP, // Load from top of the stack IN, // Read from an I/O port OUT, // Write to an I/O port // string operations MOVS, // Copy string (HW memcpy) SETS, // Set string (HW memset) CMPS, // Compare string (HW memcmp) // data conversion CIF, // Convert Integer to Float CFI, // Convert Float to Integer CIB, // Convert Integer to Boolean CFB, // Convert Float to Boolean // binary operations NOT, // Bitwise NOT AND, // Bitwise AND OR, // Bitwise OR XOR, // Bitwise XOR BNOT, // Boolean NOT SHL, // Bit shift left // integer arithmetic IADD, // Integer Addition ISUB, // Integer Subtraction IMUL, // Integer Multiplication IDIV, // Integer Division IMOD, // Integer Modulus ISGN, // Integer Sign change IMIN, // Integer Minimum IMAX, // Integer Maximum IABS, // Integer Absolute value // float arithmetic FADD, // Float Addition FSUB, // Float Subtraction FMUL, // Float Multiplication FDIV, // Float Division FMOD, // Float Modulus FSGN, // Float Sign change FMIN, // Float Minimum FMAX, // Float Maximum FABS, // Float Absolute value // extended float operations FLR, // Round down CEIL, // Round up ROUND, // Round to nearest integer SIN, // Sine ACOS, // Arc cosine ATAN2, // Arc Tangent from x and y LOG, // Natural logarithm POW // Raise to a Power }; // ----------------------------------------------------------------------------- enum class CPURegisters: int { // all 16 general-purpose registers Register00 = 0, Register01, Register02, Register03, Register04, Register05, Register06, Register07, Register08, Register09, Register10, Register11, Register12, Register13, Register14, Register15, // alternate names for specific registers CountRegister = 11, SourceRegister = 12, DestinationRegister = 13, BasePointer = 14, StackPointer = 15 }; // ----------------------------------------------------------------------------- enum class AddressingModes : unsigned int { RegisterFromImmediate = 0, // syntax: MOV R1, 25 RegisterFromRegister, // syntax: MOV R1, R2 RegisterFromImmediateAddress, // syntax: MOV R1, [25] RegisterFromRegisterAddress, // syntax: MOV R1, [R2] RegisterFromAddressOffset, // syntax: MOV R1, [R2+25] ImmediateAddressFromRegister, // syntax: MOV [25], R2 RegisterAddressFromRegister, // syntax: MOV [R1], R2 AddressOffsetFromRegister // syntax: MOV [R1+25], R2 }; // ----------------------------------------------------------------------------- enum class CPUErrorCodes: uint32_t { InvalidMemoryRead = 0, InvalidMemoryWrite, InvalidPortRead, InvalidPortWrite, StackOverflow, StackUnderflow, DivisionError, ArcCosineError, ArcTangent2Error, LogarithmError, PowerError }; }
notes/comporg/spring2024/virconref.1708378719.txt.gz · Last modified: 2024/02/19 16:38 by 127.0.0.1