ProcessCommand

Purpose: Execute a text string as a MIRTOS system command.
The string may be an internal system command or a command extension.
Any leading space(s) in the command string are discarded.
Assumes:   The very first BYTE at the address specified is the string length.
No command is executed if that first BYTE is zero.
The command string is NULL-terminated.
There are additional BYTEs available in the temporary buffer for command modification.
Passed: R25:R24   WORD *  wAddress   the SRAM address of the buffer containing one (1) string length BYTE followed by the text string for MIRTOS to interpret and execute.
Returns: Nothing.
Alters: Any of R0, R18 to R28 may change, depending on the command passed to it.
Possibly the contents of the command buffer passed to it.
    ########################################################
    ##                                                    ##
    ##   This webpage is incomplete ("Test it" section)   ##
    ##                                                    ##
    ########################################################

Example:  : In this example, a command is predefined in FLASH as an ASCIIZ string ("V+ 32",NULL) and stored after the code at address "Command". The 'Y' register pair (R29:R28) should always point to the first BYTE of the User variable array. If the Real-Time Clock minutes BYTE read is the same as the last time it was stored, then the second block of code, which begins with "STD" (STore with Displacement) is not executed.

When the minute value has changed, its new value is stored to check the next time, then the command string length and string (7 BYTEs total, including the first string length BYTE and the string-ending NULL) is copied from FLASH to SRAM. This command is executed without changing the contents of the system command buffer, into which someone might be typing a new command.
.ORG  0x1234
.INCLUDE "SystemSRAM328.Def"    ; or SystemSRAM1284.Def or SystemSRAM2560.Def
.INCLUDE "Addresses328.Def"     ; or Addresses1284.Def or Addresses2560.Def
.INCLUDE "Test_328.Ptr"

   LDS     R24, bRTC_Minute     ; Get the system minutes value (at 0x1D9 or
   LDD     R25, Y + 31          ;  0x2D9) then get its last saved value
   CP      R24, R25             ; If they're the same, don't do anything this
   BREQ    ADone                ;  time, but just skip down to the exit

   STD     Y + 31, R24          ; Save the new minute value
   MOVW    R24, R28             ; Specify the (always) 2-BYTE SRAM address at
   ADIW    R24, 32              ;  uVars.B[ 32 ] (in the user variables) as the
   LDI     R23, ACommand >> 8   ;  destination and the string below (in FLASH)
   LDI     R22, ACommand & 0xFF ;  as the source
.IFDEF bCOM2RxBuffer            ; Only 1284P & 2560 have a COM2 Receive Buffer
   LDI     R26, ACommand >> 16  ; For 1284P and 2560, strcpyPGM also needs R26
.ENDIF                          ; (Assumes: R26 doesn't need to be preserved)
   CALL    AstrcpyPGM           ; Copy ASCIIz string from FLASH to SRAM
   CALL    AProcessCommand      ; Make the system call to execute "V+ 32"

Done:
   RET                          ; Return to the caller

Command:   .BYTE ANextCmd - ACommand - 2    ; = strlen ("V 32") = 4 BYTEs
           .STRING "V+ 32"      ; Note: "V+ 32" is a command extension
NextCmd:
Test it:
>DES
EEPROM contents:
0000:  10 21 00 9F 01 00 84 FF-04 00 EB FF 18 7F 50 FF  .!............P.
0010:  C0 00 FF 7F 00 0B 03 67-FF 27 74 FF FF FF FF FF  .......g.'t.....
0020:  26 00 00 00 FF FF 2A FF-FF FF 14 20 00 40 FF FF  &.....*.... .@..
0030:  80 16 80 16 FF FF FF FF-90 00 B0 00 00 05 FF FF  ................
0040:  FF FF FF FF F0 01 00 F1-10 E2 FF FF FF FF FF FF  .. .............
>EW 0x42 = 0x1234  ; Specify the "Each Main" routine address
>E 1 ^ = 4         ; Toggle the "Each Main" routine function (on)
SRAM contents:
0360:  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
0370:  14 04   (more to show ...)
> ; Notice that the command buffer got changed before execution
>DES  ; The 2 changes are underlined below
EEPROM contents:
0000:  10 25 00 9F 01 00 84 FF-04 00 EB FF 18 7F 50 FF  .!............P.
0010:  C0 00 FF 7F 00 0B 03 67-FF 27 74 FF FF FF FF FF  .......g.'t.....
0020:  26 00 00 00 FF FF 2A FF-FF FF 14 20 00 40 FF FF  &.....*.... .@..
0030:  80 16 80 16 FF FF FF FF-90 00 B0 00 00 05 FF FF  ................
0040:  FF FF 34 12 F0 01 00 F1-10 E2 FF FF FF FF FF FF  ..0.............
>DP 0x1200  


>DS 0x360 24
SRAM contents:
0360:  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
0370:  15 04   (more to show ...)
SRAM contents:
0360:  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
0370:  16 04   (more to show ...)
>E 1 ^ = 4         ; Toggle the "Each Main" routine function (off)
>                                                                                        
Notes: Notice that the command was changed from "V+ 32" to "DS+ Depending on the command issued, this command might block.
Dropin: 
(setup
code)
;   Setup for the ProcessCommand() call:
; Passed:  R25:R24 BYTE bValue to print in binary format
; Returns: Nothing.
; Alters:  Varies; assume R0, R18 through R27, and the FLAGs, depending on the command
;          Possibly the contents of the command buffer passed to it
Also see:  -