From dc7ebb9d424bb39d59f09b8498746beb871c46f4 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 20 Nov 2020 11:50:47 -0500 Subject: - Cleaned up a bit of the code. - Made the debug print for the CPU flags more readable. - Started work on implementing line number support into SuBAsm. --- programs/sub-suite/declare.s | 24 ++++++++-- programs/sub-suite/lexer.s | 102 +++++++++++++++++++++++++++++++++++++---- programs/sub-suite/libc.s | 31 +++++++++++++ programs/sub-suite/subeditor.s | 4 +- programs/sub-suite/subsuite.s | 2 +- 5 files changed, 148 insertions(+), 15 deletions(-) (limited to 'programs') diff --git a/programs/sub-suite/declare.s b/programs/sub-suite/declare.s index 7b419e2..5828fdb 100644 --- a/programs/sub-suite/declare.s +++ b/programs/sub-suite/declare.s @@ -312,6 +312,10 @@ t_str: t_sym: .res 8 +; First token. +toks: + .res 8 + ; Current token. ctok: .res 8 @@ -320,6 +324,10 @@ ctok: ltok: .res 8 +; First line. +lines: + .res 8 + ; Current line. cline: .res 8 @@ -385,9 +393,19 @@ symbol: fixup: .res 8 +; Line number. +linenum: + .res 4 +ln: + .res 4 + +; Is line number flag. +islinenum: + .res 1 + ; ROM data declarations. -.org $A000 +.org $C000 ; String Literals/Constants. ;tok: ; .byte "dab" @@ -409,8 +427,8 @@ made: author: .byte "mr b0nk 500" -string2: - .byte "You typed, " +;string2: +; .byte "You typed, " asm_name: .byte "SuBAsm" diff --git a/programs/sub-suite/lexer.s b/programs/sub-suite/lexer.s index fc47f10..9c3cb87 100644 --- a/programs/sub-suite/lexer.s +++ b/programs/sub-suite/lexer.s @@ -5,6 +5,7 @@ lex: ldx #0 ; Reset X. txa ; Reset A. txy ; Reset Y. + sty.d ln ; Reset the temp line number. sty.q idx0 ; Clear the first index. sty.q idx1 ; Clear the second index. sty.q idx2 ; Clear the third index. @@ -13,19 +14,74 @@ lex: sty.q t_str ; Clear the token string. sty.q t_sym ; Clear the token symbol. sty regb ; Clear the isop flag. + sty islinenum ; Clear the islinenum flag. +; jsr init_lex ; Initialize the lexeme buffer. +;@checklnum: ; lda (ptr), y ; Get a character from the line. ; pha ; Preserve the character. ; jsr isdigit ; Is this character a digit? ; pla ; Get the character back. +; bne @checkidx ; No, so start checking the index. +; pha ; Preserve the character. +; jsr isdelm ; Yes, so get the delimiter type. +; and #$10 ; Is this character whitespace? +; pla ; Get the character back. +; beq @checkidx ; Yes, so start checking the index. +; sta (ptr3), y ; No, so copy the character into the lexeme buffer. +; iny ; Increment the string index. +; bra @checklnum ; Keep looping. +;@checkidx: +; sty.q idx0 ; Set the first index to the string index. +; sty islinenum ; Set the islinenum flag to the string index. +; tya ; Is the string index non-zero? +; beq @nolnum ; No, so treat it as a completly new line. +; and #0 ; Yes, so terminate the lexeme buffer. +; sta (ptr3), y ; +; lda.q ptr3 ; Setup arguments for strtoull. +; pha.q ; +; and #0 ; Reset A. +; lda #10 ; Set the base to 10. +; pha ; +; jsr strtoull ; +; sta.d ln ; Set the temp line number to the converted value. +; pla ; Cleanup the argument frame. +; pla.q ; +; and #0 ; Reset A. +; bra @getline ; Start getting the tokenized line. +;@nolnum: +; lda.d linenum ; Get the global line number. +; sta.d ln ; Set the temp line number to to global line number. +; and #0 ; Reset A. +; sta.q cline ; Reset the current line pointer. ;@getline: -; ldb #1 ; Set the second pointer -; lda.q lline ; to the last line. +; tay ; Reset Y. +; lda.q cline ; Is the current line NULL? +; bne @linepc ; No, so set the assembler's program counter to the line's address. +; lda #ln ; Yes, so create a new tokenized line. +; jsr malloc ; +; sta.q cline ; Set the current line to the new tokenized line. +; lda.q lline ; Is the last line NULL? +; beq @firstline ; Yes, so set the first line. +;@nextlline: +; ldb #1 ; No, so set the second pointer to the last line. +; jsr set_ptr ; +; ldy #ln.next ; Set the next last line to the current line. +; lda.q cline ; +; sta.q (ptr2), y ; +; bra @initline ; Initialize the line. +;@firstline: +; lda.q cline ; Set the first line to the current line. +; sta.q lines ; +;@initline: +; ldb #1 ; Set the second pointer to the current line. ; jsr set_ptr ; -; ldy #ln.next ; Set the index to the next line pointer. -; lda.q (ptr2), y ; Get the next line. -; jsr set_ptr ; Set the second pointer to the next line. -; sta.q cline ; Make it the current line. ; and #0 ; Reset A. +; ldy #ln.next ; Reset the next line. +; sta.q (ptr2), y ; +; ldy #ln.tok ; Reset the token. +; sta.q (ptr2), y ; +; ldy #ln.bline ; Reset the number of blank lines. +; sta.w (ptr2), y ; ; tay ; Reset Y. @loop: ldy.w idx0 ; Get the string index. @@ -255,8 +311,18 @@ ptok_dqu: lda #TOK_DQUOT ; Set the lexeme type to TOK_DQUOT. sta lex_type ; sta t_id ; Also set the token ID to TOK_DQUOT. - lda.d ptr3 ; Get the address of the lexeme buffer. +; lda.d ptr3 ; Get the address of the lexeme buffer. + lda.q idx1 ; Get the index of the lexeme buffer. + inc ; Increment it by one to get the size. + jsr malloc ; Make a new string. + ldb.q ptr3 ; Get the address of the lexeme buffer. + ldy.q idx1 ; Get the size of the lexeme buffer + 1. + iny ; + jsr memcpy ; Copy the string in the lexeme buffer into the new string. sta.q t_str ; Save it in the token string. + and #0 ; Reset A. + tab ; Reset B. + ldy.q idx0 ; Get the string index back. @end: jsr make_tok ; Create the token. rts ; End of parse_ptok. @@ -272,8 +338,17 @@ ptok_squ: lda #TOK_SQUOT ; Set the lexeme type to TOK_SQUOT. sta lex_type ; sta t_id ; Also set the token ID to TOK_SQUOT. - lda.d ptr3 ; Get the address of the lexeme buffer. + lda.q idx1 ; Get the index of the lexeme buffer. + inc ; Increment it by one to get the size. + jsr malloc ; Make a new string. + ldb.q ptr3 ; Get the address of the lexeme buffer. + ldy.q idx1 ; Get the size of the lexeme buffer + 1. + iny ; + jsr memcpy ; Copy the string in the lexeme buffer into the new string. sta.q t_str ; Save it in the token string. + and #0 ; Reset A. + tab ; Reset B. + ldy.q idx0 ; Get the string index back. @end: jsr make_tok ; Create the token. rts ; End of parse_ptok. @@ -291,8 +366,17 @@ ptok_scol: lda #TOK_SCOLN ; Set the lexeme type to TOK_SCOLN. sta lex_type ; sta t_id ; Also set the token ID to TOK_SCOLN. - lda.d ptr3 ; Get the address of the lexeme buffer. + lda.q idx1 ; Get the index of the lexeme buffer. + inc ; Increment it by one to get the size. + jsr malloc ; Make a new string. + ldb.q ptr3 ; Get the address of the lexeme buffer. + ldy.q idx1 ; Get the size of the lexeme buffer + 1. + iny ; + jsr memcpy ; Copy the string in the lexeme buffer into the new string. sta.q t_str ; Save it in the token string. + and #0 ; Reset A. + tab ; Reset B. + ldy.q idx0 ; Get the string index back. @end: jsr make_tok ; Create the token. rts ; End of parse_ptok. diff --git a/programs/sub-suite/libc.s b/programs/sub-suite/libc.s index 18c10db..74ad654 100644 --- a/programs/sub-suite/libc.s +++ b/programs/sub-suite/libc.s @@ -508,3 +508,34 @@ free: plb.q ; Restore B. pla.q ; Restore A. rts ; End of free. + + +; memcpy: memory to memory copy. +; Input: A = Destination pointer. B = Source pointer. Y = Number of bytes to copy. +; Output: A = Destination pointer. +; Caller preserved registers: none. +; Callie preserved registers: none. + +memcpy: + pha.q ; Preserve the return value. + pha.q ; Push the destination pointer on the stack. + phb.q ; Push the source pointer on the stack. + phy.q ; Push the size on the stack. + and #0 ; Reset A. + tab ; Reset B. + cpy #0 ; Is the size zero? + beq @end ; Yes, so we're done. +@loop: + lda (sp+9) ; Get a byte from the source. + sta (sp+17) ; Copy it to the destination. + inc.q sp+9 ; Increment the source pointer. + inc.q sp+17 ; Increment the destination pointer. + dey ; Decrement the size. + beq @end ; The size is zero, so we're done. + bra @loop ; Keep looping. +@end: + pla.q ; Clean up the stack frame. + pla.q ; + pla.q ; + pla.q ; Restore the return value. + rts ; End of memcpy. diff --git a/programs/sub-suite/subeditor.s b/programs/sub-suite/subeditor.s index 2676a93..bec3f41 100644 --- a/programs/sub-suite/subeditor.s +++ b/programs/sub-suite/subeditor.s @@ -364,7 +364,7 @@ cmd_cpy: sta (ptr2), y ; Copy one byte from the screen buffer, to the command buffer. inx ; Increment the command buffer index. ply.w ; Get back the screen index. - cpx.w #$3FF ; Are we at the end of the command buffer? + cpx.w #CMDSIZE ; Are we at the end of the command buffer? bcs @end ; Yes, so we're done. iny ; No, so increment the screen index. inb ; Increment the byte count. @@ -579,7 +579,7 @@ clr_scr: lda.q buffer ; Set the array to be cleared to the screen buffer. jsr clr_arr ; Clear the screen buffer. ; tay ; -; lda.w #$3FF ; Set the clear count to $3FF. +; lda.w #CMDSIZE ; Set the clear count to CMDSIZE. ; sta.w scr_ptr ; ; lda.d #cmd_buf ; Set the array to be cleared to the command buffer. ; jsr clr_arr ; Clear the screen buffer. diff --git a/programs/sub-suite/subsuite.s b/programs/sub-suite/subsuite.s index 0cfad1e..d28b4f2 100644 --- a/programs/sub-suite/subsuite.s +++ b/programs/sub-suite/subsuite.s @@ -17,7 +17,7 @@ .qword reset a ;l a -;.org $8FA0 +;.org reset ;v ;q d -- cgit v1.2.3-13-gbd6f