ROOL Forum: Recent Posts

Parameters to module commands

Tue, 06 Jun 2023 22:41:36 -0000

That’s what I have been doing, and how I came up with the five rules (with a little reading in the CLI code).

I’m pretty sure it’s accurate, but the bug I’ve been chasing showed itself in another area (my GSTrans wasn’t doing the whole job).

I’ll leave it here, on the basis that the best way to get an answer to a question on the internet is to say something wrong!

Parameters to module commands

Tue, 06 Jun 2023 20:44:52 -0000

Well, gee, that’s a whole different entry point. ;)

Mod the code to provide a fake *command and dump out what it gets as input, then you can play with it and see what happens and if there are any weird edge cases to be aware of (like the line termination thing above).

Parameters to module commands

Tue, 06 Jun 2023 19:49:34 -0000

Thanks, both of you, but I’m not thinking of RMLoad/RMRun, rather *commands provided by a loaded module. Did I use the wrong terminology?

That code is passed a string in R0 and a count of parameters in R1. The OS will also GSTrans up to 8 of the first 8 parameters, according to bits 8-15 in the info word associated with the command.

Parameters to module commands

Tue, 06 Jun 2023 17:05:10 -0000

Here, play with this…

; EntryParms
; ==========
;
; by Rick Murray
;   Version: 0.01
;   Date   : Tuesday, 6th June 2023
;
;   hxxps://www.riscosopen.org/forum/forums/5/topics/17925
;    ^^ tt, but bloody Textile... 


; SWIs (to save including anything)
OS_Write0      * 2
OS_NewLine     * 3
OS_CLI         * 5
OS_Exit        * &11
OS_ConvertHex8 * &D4


; ===========
; Here we go!
; ===========

        AREA     |Module$Code|, CODE, DATA, PIC, A32bit
        ENTRY

entrypoint
        ; Standard RISC OS module header
        DCD      (start - entrypoint)        ; Start code
        DCD      (initialise - entrypoint)   ; Initialise code
        DCD      0                           ; no Finalise code
        DCD      0                           ; no Service call code
        DCD      (titlestring - entrypoint)  ; Module title string
        DCD      (helpstring - entrypoint)   ; Module help string
        DCD      0                           ; no help/command table
        DCD      0                           ; no SWI chunk
        DCD      0                           ; no SWI handler code
        DCD      0                           ; no SWI decoding table
        DCD      0                           ; no SWI decoding code
        DCD      0                           ; no Messages file
        DCD      (thirtytwo - entrypoint)    ; 32bit flag word


titlestring
        =        "EntryParms", 0
        ALIGN


helpstring
        =        "EntryParms", 9, "0.01", " (06 Jun 2023)", 0
        ALIGN


thirtytwo
        DCD      1                           ; Shiny!



; =====================
; MODULE INITIALISATION
; =====================
;
;   R3 = Non-zero for Init, Zero for Start
;   R4 = Envirostring pointer (R0 on entry)
;

initialise
        STR      R14, [R13, #-4]!
        ; Output "I", and set R3 to *non*-zero
        MOV      R4, R10          ; remember envirostring (in R10)
        MOV      R0, R10          ; and fudge it not being in R0 ;)
        SWI      256 + 'I'
        MOV      R3, #1
        B        do_the_rest

start
        ; Output "S", and set R3 to *zero*
        MOV      R4, R0           ; remember envirostring (in R0)
        SWI      256 + 'S'
        MOV      R3, #0
        ; fall through

do_the_rest
        ; Output ="<environment string> (following 'I' or 'S')
        SWI      256 + '='
        SWI      256 + 34 ; "
        SWI      OS_Write0        ; <-- corrupts R0
        SWI      256 + 34 ; "
        SWI      OS_NewLine

        ; Now make the address a hex string
        MOV      R0, R4           ; recall envirostring
        ADR      R1, addr
        MOV      R2, #10
        SWI      OS_ConvertHex8

        ; Output "@ &<address>"
        SWI      256 + '@'
        SWI      256 + ' '
        SWI      256 + '&'
        SWI      OS_Write0

        ; Replace terminull with a space so command works
        MOV      R0, #32
        STRB     R0, [R1]

        ; Now call the command to dump it in byte mode
        ADR      R0, cmnd
        SWI      OS_CLI
        SWI      OS_NewLine

        ; Now, how do we get out of here?
        CMP      R3, #0
        SWIEQ    OS_Exit        ; Start code MUST exit this way

        LDR      PC, [R13], #4  ; otherwise, exit this way

cmnd    ; Becomes: *Memory B <address> +20
        =        "Memory B "
addr    =        "          +20", 0
        ALIGN

When used, it looks like this:

*RMLoad EntryParms This is a LOAD op.
"="This is a LOAD op.
@ &205AB146
Address  :  6  7  8  9  A  B  C  D  E  F  0  1  2  3  4  5 :    ASCII Data
205AB146 : 54 68 69 73 20 69 73 20 61 20 4C 4F 41 44 20 6F : This is a LOAD o
205AB156 : 70 2E 0D 00 00 00 00 00 00 00 00 00 00 00 00 00 : p...............

*RMRun EntryParms This is a RUN op.
"="This is a RUN op.
@ &205AB145
Address  :  5  6  7  8  9  A  B  C  D  E  F  0  1  2  3  4 :    ASCII Data
205AB145 : 54 68 69 73 20 69 73 20 61 20 52 55 4E 20 6F 70 : This is a RUN op
205AB155 : 2E 0D 0D 0D 00 00 00 00 00 00 00 00 00 00 00 00 : ................

"="This is a RUN op.
@ &205AB145
Address  :  5  6  7  8  9  A  B  C  D  E  F  0  1  2  3  4 :    ASCII Data
205AB145 : 54 68 69 73 20 69 73 20 61 20 52 55 4E 20 6F 70 : This is a RUN op
205AB155 : 2E 0D 0D 0D 00 00 00 00 00 00 00 00 00 00 00 00 : ................

*

The tail ‘"’ is at the start of the line (overwriting the I or S) because it’s being called from the command line, and OS_Write0 obeys the carriage return.
Using OS_Module from BASIC doesn’t do this as the string is null terminated.

Wifi audible alerter

Tue, 06 Jun 2023 17:02:44 -0000

A casual glance at the spec docs suggests it’s a more platform specific implementation of the same device to device comms idea as in ZeroMQ
Any good idea will happen repeatedly until someone’s brain takes notice :) Each brain will translate differently.

Parameters to module commands

Tue, 06 Jun 2023 17:00:11 -0000

Each parameter is space terminated (including the last).

No. The parameters are literally the tail of the command line. Warning – there is no difference in behaviour if you put a string in quotes. If you use spaces to separate, you’ll need to track this yourself.
I suspect you’re supposed to use OS_ReadArgs or something…

There is no final control character terminator.

Yes, and it is not fixed. If you start up a module by calling OS_Module from a bit of BASIC, it’ll be null terminated. However if you do an RMLoad/RMRun from the command line, the terminator appears to be &0D, [&0D, [&0D,]] &00. Not sure where it’s getting the CRs from, but it looks like “two or three” is what I’m seeing.

As tabs could be validly in the string, in this case, I’d be inclined to treat CR=NULL=termination (and probably just discard anything else <32 or =127).

The “number of parameters” is effectively the number of space-to-non-space transitions

Nope. Try: *RMRun EntryParms One Two Three Four
Now try *RMRun EntryParms "One Two Three Four"

If any parameter is to be GSTrans’d by the OS CLI,

I tried passing |@ and <32> and it passed those literal. I think the environment string is “anything and everything passed after the module name, exactly as written”.

the value of a parameter expanded by GSTrans is not permitted to contain CHR$127 or any spaces or control characters.

SYS "OS_Module", 1, "EntryParms", "one"+CHR$(127)+"two"
Gave, exactly, “one<delete>two” as the environment string.

Parameters to module commands

Tue, 06 Jun 2023 14:50:39 -0000

Can someone please confirm to me that the command tail passed to a module command has the following structure:

  1. Each parameter is space terminated (including the last).
  2. There is no final control character terminator.
  3. The “number of parameters” is effectively the number of space-to-non-space transitions in the command line (including one at the start of the tail)
  4. If any parameter is to be GSTrans’d by the OS CLI, sequences of spaces will be replaced by single spaces in the string passed to the module
  5. the value of a parameter expanded by GSTrans is not permitted to contain CHR$127 or any spaces or control characters.

Reminder - Coding on RISC OS meetup this coming Saturday

Tue, 06 Jun 2023 11:03:22 -0000

Thanks for organising it Andrew. Interesting and useful. It gave me the KUTP I needed to get PIP working and install the new python toolbox.

Wifi audible alerter

Tue, 06 Jun 2023 07:41:13 -0000

There’s also the little matter of working out how to interface into the sending end of KDE Connect, to get it to do something that it wasn’t designed to do.

Wifi audible alerter

Tue, 06 Jun 2023 06:54:48 -0000

perhaps KDE Connect

Can’t help but feel that sort of thing is vastly overkill.

The beauty of rolling your own solution is that it can be as simple as it needs to be, doesn’t have to rely on brokers, third party servers, or the cloud… and can maybe even do something sensible in the event of a connection failure (unlike, say, those smart door locks that failed when the server crashed).

The unbeautiful part is, of course, rolling your own means building it and coding it, but, then again, you know what is going on so your hardware isn’t a data collection point for a Chinese company, and it won’t be feeding your SSID and password to the mothership (cheap cameras are notorious for doing stuff like this, as an http connection too!).

Wifi audible alerter

Mon, 05 Jun 2023 21:01:55 -0000

perhaps KDE Connect or something similar

A cursory glance at KDE Connect’s docs suggests that I would need something like a Linux box between the BeagleBoard and the phone.