Skip to content
This repository was archived by the owner on Nov 15, 2026. It is now read-only.

Update_2025 08 28

Charles edited this page Mar 14, 2026 · 1 revision

OSLib for RISC OS 64

Quick update on the progress with OSLib... I've mentioned before the work that I've done towards creating the OSLib veneers for RISC OS 64 (and using them for other purposes). These are now complete, I believe - all the interfaces for OSLib should now be converted properly.

Previously, I'd not implemented the non- X-variants of the SWIs, and those calls that spilled arguments on to the caller stack were not generated properly. These issues have both now been fixed - I realised what the '!' means on the def file exit parameters, and these are now set up properly. Together with remembering that I'm working with more registers, the library is now more efficient than previously. Not that that matters really for these calls, but it's nice not to use as much stack.

.section .text.xcolourtrans_set_gcol

.global xcolourtrans_set_gcol

    signature xcolourtrans_set_gcol
xcolourtrans_set_gcol:
    // =>  R0 = colour (OS_Colour)
    //     R3 = flags (ColourTrans_GCOLFlags)
    //     R4 = action (OS_Action)

    // <=  R0 = gcol (OS_GCOL)
    //     R2 = log2_bpp (.Int)
    //     R3 corrupted
    STP     x29, x30, [sp, #-16]!
    MOV     x29, sp

// Prepare output registers
    MOV     x15, x3                             // output gcol
    MOV     x14, x4                             // output log2_bpp

// Prepare input registers
    MOV     x4, x2                              // action
    MOV     x3, x1                              // flags
    // x0 = colour

// Call SWI
    MOV     x10, #1859
    MOVK    x10, #6, LSL 16
    SVC     #0                                  // XColourTrans_SetGCOL (&40743)
    CSEL    x17, xzr, x0, VC

// Store output registers
    CBZ     x15, xcolourtrans_set_gcol_noreg_3
    STR     x0, [x15]                           // output gcol
xcolourtrans_set_gcol_noreg_3:
    CBZ     x14, xcolourtrans_set_gcol_noreg_4
    STR     w2, [x14]                           // output log2_bpp
xcolourtrans_set_gcol_noreg_4:

    MOV     x0, x17                             // Error pointer (or NULL)

    LDP     x29, x30, [sp], #16
    RET

and then there are fun ones like XOS_CreateDynamicArea for the Create (0) reason code:

.section .text.xosdynamicarea_create

.global xosdynamicarea_create

    signature xosdynamicarea_create
xosdynamicarea_create:
    // =>  R0 = &0 (constant)
    //     R1 = area (OS_DynamicAreaNo)
    //     R2 = size (.Int)
    //     R3 -> base_address (.Data)
    //     R4 = flags (.Bits)
    //     R5 = size_limit (.Int)
    //     R6 -> handler (.Asm)
    //     R7 = workspace (&Void)
    //     R8 -> description (.String)

    // <=  R1 = area_out (OS_DynamicAreaNo)
    //     R3 -> base_address_out (.Data)
    //     R5 = size_limit_out (.Int)
    STP     x29, x30, [sp, #-16]!
    MOV     x29, sp

// Prepare output registers
    // output area_out: arg 8 on caller stack at offset 0 * 8
    // output base_address_out: arg 9 on caller stack at offset 1 * 8
    // output size_limit_out: arg 10 on caller stack at offset 2 * 8

// Prepare input registers
    MOV     x8, x7                              // description
    MOV     x7, x6                              // workspace
    MOV     x6, x5                              // handler
    MOV     x5, x4                              // size_limit
    MOV     x4, x3                              // flags
    MOV     x3, x2                              // base_address
    MOV     x2, x1                              // size
    MOV     x1, x0                              // area
    MOV     x0, #0

// Call SWI
    MOV     x10, #102
    MOVK    x10, #2, LSL 16
    SVC     #0                                  // XOSDynamicArea_Create (&66)
    CSEL    x17, xzr, x0, VC

// Store output registers
    LDR     x10, [x29, #16 + 0 * 8]             // output area_out
    CBZ     x10, xosdynamicarea_create_noreg_8
    STR     x1, [x10]                           // output area_out
xosdynamicarea_create_noreg_8:
    LDR     x10, [x29, #16 + 1 * 8]             // output base_address_out
    CBZ     x10, xosdynamicarea_create_noreg_9
    STR     x3, [x10]                           // output base_address_out
xosdynamicarea_create_noreg_9:
    LDR     x10, [x29, #16 + 2 * 8]             // output size_limit_out
    CBZ     x10, xosdynamicarea_create_noreg_10
    STR     w5, [x10]                           // output size_limit_out
xosdynamicarea_create_noreg_10:

    MOV     x0, x17                             // Error pointer (or NULL)

    LDP     x29, x30, [sp], #16
    RET

All of which is to say... yay! I think I have finally got to the bottom of how the OSLib interface definitions work, and the parser is mostly able to handle them (still doesn't handle the comments so well... but there's always scope for improvement), and hopefully OSLib will be useable in some real things soon. I built DrawFile with it a little while back, but it crashed badly, so maybe this'll help.

OSLib for RISC OS 64 can be found here: https://github.com/gerph/riscos64-oslib


Original post

Clone this wiki locally