Dump the Command Extension Parsing Buffer

This is the subroutine which formats and prints the contents of the parsing (or command) buffer to the COM1 console. It can be called directly from the MIRTOS command prompt in Manager or Admin mode, using an Indirect Subroutine Call to the .ORG address below. That has very limited use. It is intended to be called inside the Command Extensions logic at one or more selected points. This can really be a help when debugging a new Command Extension. DumpParsingBuffer.Asm is the name used for this source code file.

/******************************************************************************
*
*                        Subroutine "DumpParsingBuffer"
*
*  Purpose: Dump the contents of the command buffer to the console port.
*           It may be invoked by either a subroutine call or an indirect
*           call from the command line (using @ address.)
*
*  Assumes: The command buffer and parsing buffer are the same (may not be!)
*
*           The parsing buffer always occupies the same SRAM location:
*             0x230 through 0x27F in both the 328 and 1284
*             0x330 through 0x37F in the 2560
*           This may not always be true when called at the beginning of the
*           CommandExtensions() routine.  It may have been passed another
*           buffer, in which case it should begin at the address in R27:R26
*           instead.  This subroutine does not take that into account.
*
*  Passed:  Nothing.
*
*  Returns: Nothing.
*
*  Alters:  The COM1 output buffer, but not the command buffer being output.
*
*  Notes:   Generates the same output as this command:  DS+ 0x230 - 0x27F
*
******************************************************************************/

.IF PROCESSOR == 328
   .ORG  0x037C0
.ELSE
   .ORG  0x0EFB0
.ENDIF

.IFNDEF bParseBufferCount            ; The count is the first BYTE to display
   .WARNING "A SystemSRAM###.Def file should be included."
   bParseBufferCount = 0x230         ; bParseBufferCount is the BYTE which
   .IF PROCESSOR == 2560             ;  holds the buffered BYTE count before
      bParseBufferCount = 0x330      ;  the actual 79-BYTE buffer
   .ENDIF
.ENDIF
AHi_BufferStart =  bParseBufferCount >> 8
ALo_BufferStart =  bParseBufferCount & 0xFF
AHi_BufferEnd   =  AHi_BufferStart
ALo_BufferEnd   = (bParseBufferCount + 79) & 0xFF

.IFNDEF ACSZ_PBHeader
   .PRINT "Assemble again to define ACSZ_PBHeader."
   ACSZ_PBHeader = 0x1234
.ENDIF
BHH_PBHeader =  ACSZ_PBHeader >> 16
BHi_PBHeader = (ACSZ_PBHeader >> 8) & 0xFF
BLo_PBHeader =  ACSZ_PBHeader & 0xFF

The code in the source block below is the entry point to this subroutine. It first saves all of the Registers then prints the header string. One assumption is that the header string is located in the first 64 KBytes of codespace in the 1284P or 2560.

;------------

DumpParsingBuffer:
.IFDEF ACmdExt_PushAll
   RCALL   ACmdExt_PushAll           ; If the near call is defined, use it
.ELSE
   CALL    APushAll                  ; But if it isn't use the FAR version
.ENDIF

   LDI     R24, BLo_PBHeader         ; Set the starting address in R25:R24
   LDI     R25, BHi_PBHeader

.IF PROCESSOR == 328
   RCALL   ACmdExt_PrintASCIIz
.ELSE
   RCALL   ACmdExt_PrintASCIIz_0     ; The Header is in FLASH at about 0x0EFCC
.ENDIF

The code in this block sets up and makes the MIRTOS system call. It is a "blocking" function, that is, it doesn't return until all BYTEs to be output have been enbuffered. Although it restores all Registers used, it uses (or restores) the ZERO FLAG to report success to the caller. Since it is Dumping SRAM, there is never a 3-BYTE pointer issue.

;   Setup for the DumpMemory() call:
; Passed: R25:R24 byte * ¯ bPtrStart is the starting address
;         R23:R22 byte * ¯ bPtrEnd is the ending address
;             R20 byte   ¯ bType "E" (EEPROM) or "F" or "P" (FLASH), else SRAM
;             R18 byte   ¯ bFlags (type and BACKGROUND)
;     B00000001 is BIT_DM_FOREGROUND  (1: foreground, 0: background) output
;     B00000010 is BIT_DM_IHEX        (1: IntelHEX, 0: SYMDEB) format
;     B00000100 is BIT_DM_OMITHEADER  (1: do not print: 0: print) a header
;     B00001000 is BIT_DM_OMITIHEXSEG (1: do not print: 0: print) iHEX Segment
;     B00010000 is BIT_DM_OMITIHEXEOF (1: do not print: 0: print) iHEX EOF line
;     B00100000 is BIT_DM_IHEX_8_WIDE (1: 8 data bytes; 0: 16 data bytes)

R18_FLAGS = (1 << BIT_DM_FOREGROUND) | (1 << BIT_DM_OMITHEADER)

   LDI     R25, AHi_BufferStart      ; Put the starting address in R25:R24
   LDI     R24, ALo_BufferStart
   LDI     R23, AHi_BufferEnd        ; Set the ending address in R23:R22
   LDI     R22, ALo_BufferEnd
   LDI     R20, 0                    ; Select SRAM as the data source
   LDI     R18, R18_FLAGS            ; The '+' and omit header portion flags
   CALL    ADumpMemory               ; Let the System routine do the output
   SEZ                               ; Restore the caller's "Not handled" flag
   RJMP    ACmdExt_PopAll            ; MUST exit using a JUMP to PopAll()

CSZ_PBHeader:  .STRING  "Parsing Buffer contents:\r\n"

That's all there is to this subroutine. Again, the easy way to create the source code file is to open the file as shown then just copy and paste the three (3) code blocks above into the command console buffer. Use Control-Z (or F6) to end input and close DumpParsingBuffer.Asm.

C:\TestDir>Copy CON DumpParsingBuffer.Asm
   (copy and paste all three (3) code blocks above)
^Z
        1 file(s) copied.

C:\TestDir>                                                                     

Note that this code will not assemble as a stand-alone file as it stands. It can be modified to do that, but that is left to you as an exercise. Once it has been written to FLASH memory, however, it can be called indirectly (in a 328P-based device) using this command:

m>@ 0x37c0
Parsing Buffer contents:
0230:  08 40 20 30 78 33 37 63-30 00 00 00 00 00 00 00  .@ 0x37c0.......
0240:  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
0250:  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
0260:  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
0270:  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  ................
m>                                                                              

Of course, if you change the .ORG address above, or are using MIRTOS in a device with a 1284P or 2560 MCU, the address to specify will be different. Return to the main Command Extensions source code. It pulls this file into the Assembly.