Overview
Romasm includes special opcodes for drawing directly on an HTML5 Canvas. These opcodes allow you to create graphics, plots, and visualizations entirely from Romasm assembly code.
Drawing Opcodes
CLEAR
Clears the entire canvas.
CLEAR
Opcode: CLR
Operands: None
MOVE
Moves the drawing cursor to a position without drawing.
MOVE R0, R1 ; Move to (x, y) where R0=x, R1=y
Opcode: MOV
Operands: reg_x, reg_y
Note: Coordinates are typically in graph space (scaled by 100), which is converted to screen pixels automatically.
DRAW
Draws a line from the current position to a new position.
DRAW R0, R1 ; Draw line to (x, y) where R0=x, R1=y
Opcode: DRW
Operands: reg_x, reg_y
Note: The line is added to the current path but not rendered until STROKE is called.
STROKE
Renders (strokes) the current path, making all drawn lines visible.
STROKE
Opcode: STR
Operands: None
Note: You must call STROKE after drawing lines to make them visible.
Complete Example
Drawing a Line
; Draw a line from (-5, -5) to (5, 5)
CLEAR
; Start point: (-5, -5) scaled by 100
LOAD R0, -500 ; x1
LOAD R1, -500 ; y1
MOVE R0, R1 ; Move to start point
; End point: (5, 5) scaled by 100
LOAD R0, 500 ; x2
LOAD R1, 500 ; y2
DRAW R0, R1 ; Draw line
STROKE ; Render it
Drawing a Square
; Draw a square from (-3, -3) to (3, 3)
CLEAR
; Bottom-left
LOAD R0, -300
LOAD R1, -300
MOVE R0, R1
; Top-left
LOAD R0, -300
LOAD R1, 300
DRAW R0, R1
; Top-right
LOAD R0, 300
LOAD R1, 300
DRAW R0, R1
; Bottom-right
LOAD R0, 300
LOAD R1, -300
DRAW R0, R1
; Close square
LOAD R0, -300
LOAD R1, -300
DRAW R0, R1
STROKE
Coordinate Systems
Graph Coordinates
In the calculator console, coordinates are in graph space (scaled by 100):
500= 5.0 in graph units-300= -3.0 in graph units
These are automatically converted to screen pixels based on the graph window settings.
Screen Coordinates
If drawing directly (not through calculator), coordinates are in screen pixels:
0, 0= top-left cornerwidth, height= bottom-right corner
Usage in Calculator
In the Romasm Calculator console, drawing opcodes automatically:
- Convert graph coordinates to screen pixels
- Respect the current graph window settings
- Render on the graph canvas
You can use drawing opcodes in console scripts to create custom visualizations alongside plotted functions.
Related Documentation
- Romasm Calculator - Using drawing in the calculator
- Instruction Set - All Romasm instructions
- Virtual Machine - How drawing opcodes are executed