Jump to content
IGNORED

command line processing in 6502 assembler.


Recommended Posts

Hey guys, am trying to think through the best way to do the command line interface for FujiNet NOS. I can probably hammer something very naive out, but wanted to talk it over with others who do asm a lot more often than I do...

 

Basically, I have a table of commands that I want to be able to parse, such as:

 

	;; Command Table
CMDTBL
	.BYTE	'CD '
	.BYTE	'COP'
	.BYTE	'DIR'
	.BYTE	'DEL'
	.BYTE	'LOA'
	.BYTE	'LOC'
	.BYTE	'MKD'
	.BYTE	'RMD'
	.BYTE	'UNL'
	.BYTE	$FF

and I want to basically parse for the first three chars, with anything extraneous after the first three chars to be ignored, with the pointer set to the beginning of the first non whitespace character, the resulting pointer set into an IOCB and passed as is into the requested CIO operation. 

 

Not very flexible, but it would be a start.

 

I initially thought about the old trick of making the last byte have the high byte set, but there's really no need for it as the commands are all basically the same length.

 

I also considered adding a fourth byte to each entry being the ICCOM to use...

 

Basically the NUP just needs to mirror the XIO commands that are exposed via the N: deivce to provide a dirt simple command processor to at the very least, navigate network filesystems, copy files, and load/save binary files. your basic utility package.

 

-Thom

Link to comment
Share on other sites

Hi!

6 hours ago, tschak909 said:

Hey guys, am trying to think through the best way to do the command line interface for FujiNet NOS. I can probably hammer something very naive out, but wanted to talk it over with others who do asm a lot more often than I do...

 

Basically, I have a table of commands that I want to be able to parse, such as:

 


	;; Command Table
CMDTBL
	.BYTE	'CD '
	.BYTE	'COP'
	.BYTE	'DIR'
	.BYTE	'DEL'
	.BYTE	'LOA'
	.BYTE	'LOC'
	.BYTE	'MKD'
	.BYTE	'RMD'
	.BYTE	'UNL'
	.BYTE	$FF

and I want to basically parse for the first three chars, with anything extraneous after the first three chars to be ignored, with the pointer set to the beginning of the first non whitespace character, the resulting pointer set into an IOCB and passed as is into the requested CIO operation. 

 

IMHO, code is shorter if you do the standard "high-bit-is-end" in the commands, this working code is 122 bytes, including the command input:

LDBUFA = $DA51
SKPSPC = $DBA1
CIX    = $F2
INBUFF = $F3

ICCOM = $342
ICBAL = $344
ICPTL = $346
ICBLL = $348

CIOV  = $E456

; Here you put your command codes - should be < 128
COMMAND_CD     = $31
COMMAND_COPY   = $32
COMMAND_DIR    = $33
COMMAND_DEL    = $34
COMMAND_LOAD   = $35
COMMAND_LOCK   = $36
COMMAND_MKDIR  = $37
COMMAND_RMDIR  = $38
COMMAND_UNLOCK = $39

input:
        ldx #0
        lda #$05
        sta ICBAL+1
        stx ICBLL+1
        sta ICCOM
        lda #$80
        sta ICBAL
        sta ICBLL
        jsr CIOV
        bmi ret_error
parse:
        ldy #0
        sty CIX
        jsr LDBUFA

        ; Skip WS
        jsr SKPSPC

        ; Compare words
next_char:
        lda (INBUFF), y
        and #$7F
        eor command, x
        iny

        asl
        beq char_ok

        ; Skip to next command
next_command:
        lda command, x
        asl
        inx
        bcc next_command
        ldy CIX
        cpx #command_size

char_ok:
        inx
        bcc next_char

        ; Check that the command has an argument
        sty CIX
        lda (INBUFF), y
        bmi ret
        cmp #' '
        bne ret_error

        ; Skip WS end end
        jmp SKPSPC

ret_error:
        ldx #command_size+1
ret:    rts


command:
        .byte 'C', 'D'+128,                COMMAND_CD
        .byte 'C', 'O', 'P', 'Y'+128,      COMMAND_COPY
        .byte 'D', 'I', 'R'+128,           COMMAND_DIR
        .byte 'D', 'E', 'L'+128,           COMMAND_DEL
        .byte 'L', 'O', 'A', 'D'+128,      COMMAND_LOAD
        .byte 'L', 'O', 'C', 'K'+128,      COMMAND_LOCK
        .byte 'M', 'K', 'D', 'I', 'R'+128, COMMAND_MKDIR
        .byte 'R', 'M', 'D', 'I', 'R'+128, COMMAND_RMDIR
        .byte 'U', 'N', 'L', 'C', 'K'+128, COMMAND_UNLOCK

command_size = * - command - 1
        .byte $FF

 

To use, you call "input" and then "lda command,x" to read the command code:

        jsr input
        lda command,x
        bmi show_error
        ; Now process the command in A

 

Now, I think that it would be better to simply parse the full command line in the ESP32, just add a SIO command "execute shell command", and then in the Atari you simply input the line and send the full line over SIO. That way you can add commands, show better errors (just receive the full result string over SIO), etc.

 

Have Fun!

 

  • Like 2
Link to comment
Share on other sites

15 hours ago, tschak909 said:

Hey guys, am trying to think through the best way to do the command line interface for FujiNet NOS. I can probably hammer something very naive out, but wanted to talk it over with others who do asm a lot more often than I do...

 

Basically, I have a table of commands that I want to be able to parse...

Similar problem, command line parsing of the DUP of Dos++, where I had the constraint that everything has to fit into very limited ROM space. The trick is here to transpose the command table:

 


    ldx #NumCommands-1
    ldy #3            ; command starts now again at the zero offset
scanloop:
    lda CmdChar1,x
    cmp DupBuffer,y
    bne nextcmd
    lda CmdChar2,x
    cmp DupBuffer+1,y
    bne nextcmd
    lda CmdChar3,x
    cmp DupBuffer+2,y
    beq foundcmd
nextcmd:
    dex
    bpl scanloop
    ;; The command is unknown. Signal this condition
    lda DupError
    jmp ReportError        ; signal the error
repeat2:
    rts
foundcmd:
    stx DupTmp        ; keep the command index
    jsr FindEndOfToken    ; advance to the end of the token. There could be an argument here

...

    ;;; Commands sorted by character position for easy comparison
CmdChar1:    .byte "DDRLUCFCRSCLN"
CmdChar2:    .byte "IEEONAOLUAOOE"
CmdChar3:    .byte "RLNCLRRENVPAW"
NumCommands    =    *-CmdChar3

Commands are all 3 bytes each, and read (in the above table) top to bottom (not left to right).

  • Like 1
Link to comment
Share on other sites

On 6/23/2020 at 9:24 PM, dmsc said:

Hi!

 

IMHO, code is shorter if you do the standard "high-bit-is-end" in the commands, this working code is 122 bytes, including the command input:


LDBUFA = $DA51
SKPSPC = $DBA1
CIX    = $F2
INBUFF = $F3

ICCOM = $342
ICBAL = $344
ICPTL = $346
ICBLL = $348

CIOV  = $E456

; Here you put your command codes - should be < 128
COMMAND_CD     = $31
COMMAND_COPY   = $32
COMMAND_DIR    = $33
COMMAND_DEL    = $34
COMMAND_LOAD   = $35
COMMAND_LOCK   = $36
COMMAND_MKDIR  = $37
COMMAND_RMDIR  = $38
COMMAND_UNLOCK = $39

input:
        ldx #0
        lda #$05
        sta ICBAL+1
        stx ICBLL+1
        sta ICCOM
        lda #$80
        sta ICBAL
        sta ICBLL
        jsr CIOV
        bmi ret_error
parse:
        ldy #0
        sty CIX
        jsr LDBUFA

        ; Skip WS
        jsr SKPSPC

        ; Compare words
next_char:
        lda (INBUFF), y
        and #$7F
        eor command, x
        iny

        asl
        beq char_ok

        ; Skip to next command
next_command:
        lda command, x
        asl
        inx
        bcc next_command
        ldy CIX
        cpx #command_size

char_ok:
        inx
        bcc next_char

        ; Check that the command has an argument
        sty CIX
        lda (INBUFF), y
        bmi ret
        cmp #' '
        bne ret_error

        ; Skip WS end end
        jmp SKPSPC

ret_error:
        ldx #command_size+1
ret:    rts


command:
        .byte 'C', 'D'+128,                COMMAND_CD
        .byte 'C', 'O', 'P', 'Y'+128,      COMMAND_COPY
        .byte 'D', 'I', 'R'+128,           COMMAND_DIR
        .byte 'D', 'E', 'L'+128,           COMMAND_DEL
        .byte 'L', 'O', 'A', 'D'+128,      COMMAND_LOAD
        .byte 'L', 'O', 'C', 'K'+128,      COMMAND_LOCK
        .byte 'M', 'K', 'D', 'I', 'R'+128, COMMAND_MKDIR
        .byte 'R', 'M', 'D', 'I', 'R'+128, COMMAND_RMDIR
        .byte 'U', 'N', 'L', 'C', 'K'+128, COMMAND_UNLOCK

command_size = * - command - 1
        .byte $FF

 

To use, you call "input" and then "lda command,x" to read the command code:


        jsr input
        lda command,x
        bmi show_error
        ; Now process the command in A

 

Now, I think that it would be better to simply parse the full command line in the ESP32, just add a SIO command "execute shell command", and then in the Atari you simply input the line and send the full line over SIO. That way you can add commands, show better errors (just receive the full result string over SIO), etc.

 

Have Fun!

 

Question, what is the LDBUFA entry point? It's in the math pack, but I can't find official docs for what it does.

-Thom

Link to comment
Share on other sites

48 minutes ago, tschak909 said:

Question, what is the LDBUFA entry point? It's in the math pack, but I can't find official docs for what it does.

-Thom

LOADOUTBUFF $da51

    Initialize the "inbuff" zero page registers ($f3 and $f4) to point to the floating point output buffer at $580. Used by BASIC and MAC/65.

Link to comment
Share on other sites

Hi!

5 hours ago, selgus said:

LOADOUTBUFF $da51

    Initialize the "inbuff" zero page registers ($f3 and $f4) to point to the floating point output buffer at $580. Used by BASIC and MAC/65.

 

Note that, as it is used from BASIC, you can assume that all compatible math-packs must have that entry point, so you are free to also use it. It is only one byte less than the two "STA", but if each byte counts....

 

Have Fun!

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...