Thank you for the clarification! You're absolutely right — I misunderstood the question initially.
What you're asking:
- RISC OS VDU 25 is the plotting command interface, where different codes select different actions, like:
- VDU 25,4 = Move (move the drawing cursor by relative coordinates)
- VDU 25,5 = Draw (draw line relative to current position)
- VDU 25,12 = Set plot operation (raster logical function)
- etc.
You want to convert these VDU 25-based plot operations (or commands) — MOVE, DRAW with relative pixel data — into SVG vector commands.
So you want a function that interprets VDU 25 codes + their parameters, applies relative or absolute coordinate transforms, and outputs corresponding SVG elements — e.g., <path>, <line>, or moveto/lineto commands.
Explanation:
- VDU 25 commands have sub-codes:
- 4 = Move relative (e.g.,
MOVE dx, dy)
- 5 = Draw relative (e.g., draw line from current point to relative dx, dy)
- 12 = Set plot operation (logical operation) — separate from movement
- Subsequent arguments after code specify pixel offsets or values
- Need to track current position (absolute)
- Need to output SVG vector commands (
M for moveto, l for relative lineto, etc.)
Approach:
// Start at (x0, y0)
- VDU 25,4 -> move relative by dx, dy => update current x += dx, y += dy
- Output "m dx dy" (relative moveto) in SVG path
- VDU 25,5 -> draw relative by dx, dy => update x += dx, y += dy
- Output "l dx dy" (relative lineto) in SVG path
Code Example in C
Below is a toy interpreter example to translate VDU 25,4 and VDU 25,5 commands into SVG path commands:
#include <stdio.h>
// structure to hold current pen position
typedef struct {
int x;
int y;
} Point;
void output_svg_path_from_vdu25(const int *codes, const int *params, int length) {
// codes: array of VDU commands (like 4 or 5)
// params: array of parameters relative to codes, 2 params per code: dx, dy for move or draw
// length: number of commands (each command has 2 params)
Point current = {0, 0};
int i;
printf("<path d=\"");
for (i = 0; i < length; i++) {
int code = codes[i];
int dx = params[i*2];
int dy = params[i*2 +1];
if (code == 4) {
// Move relative
current.x += dx;
current.y += dy;
// SVG relative moveto: m dx,dy
printf("m %d %d ", dx, dy);
} else if (code == 5) {
// Draw relative line
current.x += dx;
current.y += dy;
// SVG relative lineto: l dx,dy
printf("l %d %d ", dx, dy);
} else {
// Unhandled code
fprintf(stderr, "Warning: unhandled VDU 25 code %d\n", code);
}
}
printf("\" stroke=\"black\" fill=\"none\" />\n");
}
int main(void) {
// Example: Move 10 right, 0 down; Draw 0 right, 20 down; Draw -10 right, 0 down
int codes[] = {4, 5, 5};
int params[] = {10, 0, 0, 20, -10, 0};
int length = sizeof(codes)/sizeof(codes[0]);
printf("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"100\" height=\"100\">\n");
output_svg_path_from_vdu25(codes, params, length);
printf("</svg>\n");
return 0;
}
Explanation
- We interpret an array of VDU 25 codes (only 4 and 5 handled here).
- Each code takes two parameters (dx, dy) — movement offsets.
- We keep track of current absolute position, though we output relative SVG path commands (lowercase
m and l).
- The resulting SVG path draws the moves+lines accordingly.
BBC BASIC Example
REM VDU 25 commands to SVG example
DIM codes%(3)
DIM params%(6)
codes%(0) = 4 : params%(0) = 10 : params%(1) = 0
codes%(1) = 5 : params%(2) = 0 : params%(3) = 20
codes%(2) = 5 : params%(4) = -10 : params%(5) = 0
currentX% = 0
currentY% = 0
PRINT "<svg xmlns=""http://www.w3.org/2000/svg"" width=""100"" height=""100"">"
PRINT "<path d=""";
FOR i% = 0 TO 2
code% = codes%(i%)
dx% = params%(i%*2)
dy% = params%(i%*2 + 1)
IF code% = 4 THEN
currentX% = currentX% + dx%
currentY% = currentY% + dy%
PRINT "m"; dx%; dy%; " ";
ELSE IF code% = 5 THEN
currentX% = currentX% + dx%
currentY% = currentY% + dy%
PRINT "l"; dx%; dy%; " ";
ELSE
PRINT "REM Unhandled VDU25 code: "; code%
ENDIF
NEXT
PRINT """ stroke=""black"" fill=""none"" />"
PRINT "</svg>"
Run the above BBC BASIC script to generate an SVG path string from VDU 25 move/draw commands.
Additional Notes
- This simple interpreter does not handle absolute moves, or other VDU 25 codes like VDU 25,12 (plot operations).
- Handle plot operation changes (
VDU 25,12, plot_ops) separately — e.g., set stroke color, blend mode, etc.
- Coordinates are accumulated and reported as relative moves in SVG — could be converted to absolute by outputting
M x y and L x y, it's up to you.
- You will need more state handling to handle complex VDU sequences from RISC OS applications.
Summary
- VDU 25,4 = Move relative by dx, dy -> SVG
m dx dy
- VDU 25,5 = Draw relative line by dx, dy -> SVG
l dx dy
- Accumulate position for correctness.
- Use the approaches and code above to parse VDU 25 command sequences and output SVG path data.
If you'd like, I can help extend this to a full parser that handles additional VDU 25 operation codes or translates plot operation sets, just provide samples or details.