Last active
May 23, 2026 18:43
-
-
Save klumsy/c48144eced89f5e79a159196b2975eea to your computer and use it in GitHub Desktop.
ReadyBASIC command example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; Signature and command IDs. | |
| ; Signature selects the resident parser shape. | |
| ; Command ID is the registry command identity. | |
| SIG_ZADD16 = 2 | |
| CMD_ZADD16 = 2 | |
| ; 32-byte descriptor macro for a command whose worker lives in LOWPACK. | |
| ; LOWPACK code is copied from REU bank $45 into the low overlay area. | |
| .macro CMD_LOW id, sig, label, endlabel, name | |
| .byte id, RB_CMD_F_LOW ; descriptor[0]=id, [1]=low-overlay flag | |
| .word label - __LOWPACK_RUN__ ; descriptor[2-3]=code offset in bank $45 | |
| .word endlabel - label ; descriptor[4-5]=number of bytes to copy | |
| .word 0 ; descriptor[6-7]=no hidden code offset | |
| .word 0 ; descriptor[8-9]=no hidden code size | |
| .word label - __LOWPACK_RUN__ ; descriptor[10-11]=entry offset from $A900 | |
| .word 0 ; descriptor[12-13]=no hidden entry offset | |
| .byte sig, .strlen(name) ; descriptor[14]=parser signature, [15]=name len | |
| .byte name ; descriptor[16..]=uppercase command name | |
| .res 16 - .strlen(name), 0 ; pad descriptor name field to 16 bytes | |
| .endmacro | |
| ; Registry entry: publishes !ZADD16 and binds it to its parser signature | |
| ; plus this exact LOWPACK worker byte range. | |
| CMD_LOW CMD_ZADD16, SIG_ZADD16, cmd_zadd16_low, cmd_zadd16_low_end, "ZADD16" | |
| ; Resident parser dispatch sees SIG_ZADD16 and calls this parser. | |
| ; Syntax shape: two numeric expressions, then OUT integer variable. | |
| parse_sig_zadd16: | |
| jsr rb_parse_num0 ; parse/evaluate first numeric expr -> CF_NUM0_LO/HI | |
| jsr rb_parse_num1 ; parse/evaluate second numeric expr -> CF_NUM1_LO/HI | |
| jsr rb_parse_out_int ; require OUT and capture/clear output integer var | |
| rts | |
| ; LOWPACK worker implementation. | |
| ; Inputs are already staged in the call frame by the resident parser. | |
| ; Result is written to the result frame for later commit to the OUT variable. | |
| cmd_zadd16_low: | |
| clc ; start 16-bit addition with carry clear | |
| lda CF_NUM0_LO ; low byte of first input | |
| adc CF_NUM1_LO ; add low byte of second input | |
| sta RF_VAL_LO ; result low byte | |
| lda CF_NUM0_HI ; high byte of first input | |
| adc CF_NUM1_HI ; add high byte plus carry from low-byte add | |
| sta RF_VAL_HI ; result high byte | |
| lda #0 | |
| sta RF_STATUS ; success status | |
| lda #RB_VAL_INT | |
| sta RF_TAG ; result type is integer | |
| rts | |
| cmd_zadd16_low_end: ; assembler marker used for copy-size math |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment