From 460832c13c9d476d71e626a0c42de4eeff3feb63 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Thu, 11 Jun 2020 21:39:59 -0400 Subject: Did some more stuff. - Fix some bugs with strings. - Started to refactor the instruction functions. - Added support for using RS prefixes on the memory based increment, and decrement instructions. - Started work on SuBAsm's lexer. Have fun looking at this, BieHDC. :) --- programs/subasm.s | 92 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 31 deletions(-) (limited to 'programs/subasm.s') diff --git a/programs/subasm.s b/programs/subasm.s index 4cec219..3c8e767 100644 --- a/programs/subasm.s +++ b/programs/subasm.s @@ -5,6 +5,7 @@ MAX_SYM = $800 ; Max symbol size. +.include "lexer.s" .include "utils.s" .org incl @@ -16,7 +17,7 @@ asm_ver: ; Directives. dir: - .byte "org", + .byte "org" .byte "byte" .byte "word" .byte "dword" @@ -152,8 +153,8 @@ cmd_srt: .word run .word set -; Data entry point for utility subroutines. -util_data: +; Data entry point for the lexer. +lexer_data: ; Token table. @@ -185,27 +186,25 @@ idx2: idx3: .qword 0 +; Current token line. +ctok: + .word 0 + +; Last token line. +ltok: + .word 0 + ; Lexeme string. lexeme: -; Symbol tables. +; Symbol table. .org lexeme+$100 -sym_val: -.org sym_val+$4000 -sym_id: -.org sym_id+$1000 -sym_def: -.org sym_def+$100 -sym_name: +sym: ; Fixup table. ; Fixups are unresolved symbols. -.org sym_name+$1000 -fix_sym: -.org fix_sym+$1000 -fix_ln: -.org fix_ln+$1000 -fix_val: +.org sym+$8000 +fix: ; Start of program code. @@ -217,16 +216,12 @@ subasm: tba ; Reset A. tax ; Reset X. jsr chk_shcmd ; Did we get a shortend command? - bne parse_cmd ; Yes, so skip everything else. - jmp @end ; + bne @cmd ; Yes, so skip everything else. jsr chk_cmd ; No, but did we get a full command? - bne parse_cmd ; Yes, so skip everything else. - jsr lexer ; No, so start lexing this line. -@end: -subasm_end: - rts ; End of subasm. - -parse_cmd: + bne @cmd ; Yes, so skip everything else. + jsr lex ; No, so start lexing this line. + jmp @end ; We are done. +@cmd: ldb #1 ; Set the second pointer lda.d #cmd_srt ; to the command subroutine table. jsr set_ptr ; @@ -234,7 +229,7 @@ parse_cmd: tba ; Reset A. lda f ; Get the command ID. cmp #8 ; Is the command ID greater than the command count? - bcs subasm_end ; Yes, so we're done. + bcs @end ; Yes, so we're done. lsl #1 ; No, so multiply the command ID by two. phy #2 ; Preserve the screen buffer position. tay ; Set the index to the offset that we just calculated. @@ -244,7 +239,8 @@ parse_cmd: jsr set_ptr ; ldb #0 ; Reset B. jsr (ptr3) ; Run the command's subroutine. - jmp subasm_end ; We are done. +@end: + rts ; End of subasm. chk_shcmd: tba ; Reset A. @@ -259,6 +255,7 @@ chk_shcmd: beq @false ; Yes, so return that we failed. cmp #' ' ; No, but is this character, a space? beq @false ; Yes, so return that we failed. + jsr tolower ; No, so convert it to lowercase. @loop: ldb (ptr2), y ; Are we at the end of the table? beq @false ; Yes, so return that we failed. @@ -286,6 +283,41 @@ chk_shcmd: rts ; End of chk_shcmd. +chk_cmd: + tba ; Reset A. + tax ; Reset X. + sta.q idx0 ; Reset the first index. + sta.q idx1 ; Reset the second index. +@loop: + lda.w #cmds ; Get pointer to the start of the command table. + clc ; Prepare for a non carrying add. + adc.w idx0 ; Offset the pointer, by the length of the previous string. + pha #8 ; Preserve the command string pointer. + jsr strcasecmp ; Is the command buffer, the same as the command string? + pla #8 ; Get the command string pointer back. + beq @true ; Yes, so return true. + ldb idx1 ; No, so Get the command ID. + cpb #7 ; Have we reached the end of the command table? + beq @false ; Yes, so return false. + inc idx1 ; No, so increment the command ID. +@getlen: + jsr strlen ; Get the string's length. + inx ; Add one to the length. + txa ; Place it in the accumulator. + clc ; Prepare for a non carrying add. + adc.w idx0 ; Add the string offset to the current length + sta.w idx0 ; Save the offset in the first index. + jmp @loop ; Keep looping. +@true: + ldb idx1 ; Get the command ID. + stb f ; Return the command ID. + ldb #1 ; Return true. + jmp @end ; We are done. +@false: + ldb #0 ; Return false. +@end: + rts ; End of chk_cmd. + viewmem: lda.q prg_cnt ; Get the program counter. sta.q idx0 ; Save the address in the first index. @@ -347,7 +379,5 @@ set: @end: rts ; End of set. - ; Entry point for utility subroutines. -utils: - +lexer: -- cgit v1.2.3-13-gbd6f