; SuBAsm ; The Sux Bootstrapped Assembler. ; ; by mr b0nk 500 subasm: ldb #0 ; Set the first pointer lda.d #cmd_buf ; to the command buffer. jsr set_ptr ; tba ; Reset A. tax ; Reset X. jsr chk_shcmd ; Did we get a shortend command? bne @cmd ; Yes, so skip everything else. jsr chk_cmd ; No, but did we get a full command? bne @cmd ; Yes, so skip everything else. jsr lex ; No, so start lexing this line. bra @end ; We are done. @cmd: ldb #1 ; Set the second pointer lda.d #cmd_srt ; to the command subroutine table. jsr set_ptr ; deb ; Reset B. tba ; Reset A. lda regf ; Get the command ID. cmp #8 ; Is the command ID greater than the command count? bcs @end ; Yes, so we're done. lsl #1 ; No, so multiply the command ID by two. tay ; Set the index to the offset that we just calculated. lda.w (ptr2), y ; Get the command subroutine, from the command subroutine table. ldb #2 ; Save it in the third pointer. jsr set_ptr ; ldb #0 ; Reset B. jsr (ptr3) ; Run the command's subroutine. @end: and #0 ; Reset A. jsr update_ptr ; Get the screen buffer index. tay ; Save it in Y. and #0 ; Reset A. rts ; End of subasm. chk_shcmd: tba ; Reset A. inb ; Set the second pointer lda.w #sh_cmds ; to the shortend command table. jsr set_ptr ; deb ; Reset B. tba ; Reset A. phy.w ; Preserve the screen buffer position. txy ; Set our index to zero. lda (ptr), y ; Is there nothing in the command buffer? 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. cmp b ; No, so did the character match? beq @found ; Yes, so check if there are any arguments. iny ; No, so check the next command. bra @loop ; Keep looping. @found: sty regf ; Save the command ID. ldy #1 ; Check the next character in the command buffer. lda (ptr), y ; Is this the end of the buffer? beq @true ; Yes, so return that we succeded. cmp #' ' ; No, but is this a space? beq @true ; Yes, so return that we succeded. bra @false ; No, so return that we failed. @true: lda #1 ; Return true. bra @end ; We are done. @false: ldb #0 ; Reset B. tba ; Return false. tax ; Reset X. @end: ply.w ; Get back the screen buffer position. 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.q ; Preserve the command string pointer. jsr strcaseg ; Is the command buffer, the same as the command string? pla.q ; 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. inc ; Add one to the length. 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. bra @loop ; Keep looping. @true: ldb idx1 ; Get the command ID. stb regf ; Return the command ID. ldb #1 ; Return true. bra @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. and #$F0 ; Clear the first four bits of the address. sta idx0 ; Overwrite the first byte, with the masked byte. lda #19 ; Move the cursor to the right, by 19 columns. sta scr_col ; jsr update_pos ; jsr print_lo ; Print the low nibble offsets. ldx #0 ; Reset X. ldb #0 ; Reset B. stb idx1 ; Reset the byte count. @loop: lda #'\n' ; Print a newline. jsr print_char ; jsr print_hi ; Place the address in the string buffer. jsr print_chunk ; Place the next 16 bytes in the string buffer. lda.d #strbuf ; Print the string buffer. jsr print_str ; inc idx1 ; Increment the chunk count. ldb idx1 ; Get the chunk count. cpb #$10 ; Did we print 16 chunks? beq @end ; Yes, so we're done. lda.q idx0 ; No, so get the address index. clc ; Prepare for a non carrying add. adc #$10 ; Add 16 to the address. sta.q idx0 ; Put it back into the address. and #0 ; Reset A. bra @loop ; Keep looping. @end: lda #'\n' ; Print a newline. jsr print_char ; and #0 ; Reset A. rts ; End of viewmem. list: nop ; @end: rts ; End of list. asm: nop ; @end: rts ; End of asm. help: nop ; @end: rts ; End of help. inst: nop ; @end: rts ; End of inst. run: nop ; @end: rts ; End of run. set: nop ; @end: rts ; End of set.