From 344a1b9eb8691af52de15a44ec70d8f41ae8a870 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 4 Feb 2024 11:35:09 +0100 Subject: [PATCH] cx16: added cx16.get_program_args() and cx16.set_program_args() --- compiler/res/prog8lib/cx16/syslib.p8 | 41 ++++++++++++++++++++++++++++ docs/source/libraries.rst | 13 +++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/compiler/res/prog8lib/cx16/syslib.p8 b/compiler/res/prog8lib/cx16/syslib.p8 index bc8971235..2d7d2f3f4 100644 --- a/compiler/res/prog8lib/cx16/syslib.p8 +++ b/compiler/res/prog8lib/cx16/syslib.p8 @@ -1172,6 +1172,47 @@ sub search_x16edit() -> ubyte { }} } + sub set_program_args(uword args_ptr, ubyte args_size) { + ; Set the inter-program arguments. + ; standardized way to pass arguments between programs is in ram bank 0, address $bf00-$bfff. + ; see https://github.com/X16Community/x16-docs/blob/master/X16%20Reference%20-%2007%20-%20Memory%20Map.md#bank-0 + sys.push(getrambank()) + rambank(0) + sys.memcopy(args_ptr, $bf00, args_size) + if args_size<255 + @($bf00+args_size) = 0 + rambank(sys.pop()) + } + + asmsub get_program_args(uword buffer @R0, ubyte buf_size @R1, bool binary @Pc) { + ; Retrieve the inter-program arguments. If binary=false, it treats them as a string (stops copying at first zero). + ; standardized way to pass arguments between programs is in ram bank 0, address $bf00-$bfff. + ; see https://github.com/X16Community/x16-docs/blob/master/X16%20Reference%20-%2007%20-%20Memory%20Map.md#bank-0 + %asm {{ + lda #0 + rol a + sta P8ZP_SCRATCH_REG + lda $00 + pha + stz $00 + stz P8ZP_SCRATCH_W1 + lda #$bf + sta P8ZP_SCRATCH_W1+1 + ldy #0 +- lda (P8ZP_SCRATCH_W1),y + sta (cx16.r0),y + beq + +_continue iny + cpy cx16.r1L ; max size? + bne - + beq ++ ++ lda P8ZP_SCRATCH_REG ; binary? + bne _continue ++ pla + sta $00 + }} + } + } sys { diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index af249bb18..31730b885 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -106,7 +106,6 @@ sys (part of syslib) including the uninitialized ones ("BSS" variables) and the uninitialized memory blocks reserved by the `memory()` function. Can be used to load dynamic data after the program, instead of hardcoding something. - ``wait (uword jiffies)`` wait approximately the given number of jiffies (1/60th seconds) Note: the regular system irq handler has run for this to work as it depends on the system jiffy clock. @@ -527,9 +526,13 @@ The compiler needs it for various built-in system routines. cx16 ---- This is available on *all targets*, it is always imported as part of syslib. -On the Commander X16 this module contains a whole bunch of things specific to that machine. +On the Commander X16 this module contains a *whole bunch* of things specific to that machine. +It's way too much to include here, you have to study the +`source code `_ +to see what is there. + On the other targets, it only contains the definition of the 16 memory mapped virtual registers -(cx16.r0 - cx16.r15) and the following two utility routines: +(cx16.r0 - cx16.r15) and the following utility routines: ``save_virtual_registers()`` save the values of all 16 virtual registers r0 - r15 in a buffer. Might be useful in an IRQ handler to avoid clobbering them. @@ -537,6 +540,10 @@ On the other targets, it only contains the definition of the 16 memory mapped vi ``restore_virtual_registers()`` restore the values of all 16 virtual registers r0 - r15 from the buffer. Might be useful in an IRQ handler to avoid clobbering them. +``cpu_is_65816()`` + Returns true if the CPU in the computer is a 65816, false otherwise (6502 cpu). + + bmx (cx16 only) ---------------- Routines to load and save "BMX" files, the CommanderX16 bitmap file format.