From cd6982e5da1f5facdc1e0154b3a27c01e8b076c9 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Wed, 27 Jan 2021 13:42:57 -0500 Subject: - Fixed some bugs in the emulator. - Started work on implementing the Super VIA emulation. - Added support for disabling disassembly per instruction, when in debug mode. - Did some more work on rewriting the SuB Suite to work with the new calling convention. - Rewrote the symbol handling code in the emulator's assembler, to make it both simpler, and to add support for arbitrarily deep symbol scopes. - Added support for arbitrarily deep local symbol scopes. For example, to declare a symbol of depth 2, you add two '@' characters to the start of the symbol name. In other words, the number of '@' characters before the symbol name is what determines the scope of that symbol. And to use a symbol thats outside the current scope, you would use the same syntax as using a struct member, so you would do `global.local`. --- programs/sub-suite/utils.s | 312 +++++++++++++++++++-------------------------- 1 file changed, 131 insertions(+), 181 deletions(-) (limited to 'programs/sub-suite/utils.s') diff --git a/programs/sub-suite/utils.s b/programs/sub-suite/utils.s index 3813a05..6479099 100644 --- a/programs/sub-suite/utils.s +++ b/programs/sub-suite/utils.s @@ -1,141 +1,125 @@ ; Utility subroutines for SuBAsm. print_hi: - and #0 ; Reset A. - sta idx3 ; Clear the string index. - tax ; Reset X. - lda #'$' ; Print the hex delimiter. - sta strbuf, x ; Save it in the string buffer. - lda.q idx0 ; Get the masked address. - ldx #$10 ; Set digit count to 16. - jsr print_hex ; Print the address. - lda.q hex_str ; Get the lower half of the string. - sta.q strbuf+1 ; Save it in the string buffer. - lda.q hex_str+8 ; Get the upper half of the string. - sta.q strbuf+9 ; Save it in the string buffer. - ldx #$11 ; Add 16 to the index. - stx idx3 ; - lda.w #': ' ; Print a space. - sta.w strbuf, x ; Save it in the string buffer. - inc idx3 ; Increment the string index twice. - inc idx3 ; - and #0 ; Reset A. - rts ; End of print_hi. + phb.q ; Preserve B. + sbs #$10 ; Make room for the hex string buffer. + and #0 ; Reset A. + mov b, d ; Get the string buffer pointer. + mov (b), #'$' ; Print the hex delimiter to the string buffer. + inb ; Increment the string buffer pointer. + lea d, (sp+1) ; Get the address of the hex string buffer. + mov f, #$10 ; Set digit count to 16. + jsr print_hex ; Print the address. + mov.q (b), (a) ; Print the lower half of the hex string to the string buffer. + mov.q (b+8), (a+8) ; Print the upper half of the hex string to the string buffer. + add b, #$10 ; Add 16 to the index. + mov.w (b), #': ' ; Print a colon, and space to the string buffer. + add b, #2 ; Add two to the string buffer pointer. + tba a ; Return the string buffer pointer after the printed string. + ads #$10 ; Cleanup the stack frame. + plb.q ; Restore B. + rts ; End of print_hi. print_lo: - and #0 ; Reset A. - sta idx3 ; Clear the string index. + pha.q ; Preserve A. + phb.q ; Preserve B. + phx.q ; Preserve X. + sbs #$33 ; Make room for the hex string buffer, and the normal string buffer. + and #0 ; Reset A. + tab ; Reset B. + lea d, (sp+1) ; Get the address of the hex string buffer. + lea x, (sp+3) ; Get the address of the string buffer. @loop: - ldx #2 ; Set digit count to 2. - pha ; Preserve the nibble offset. - jsr print_hex ; Print the low nibble offset. - lda.w (ptr3) ; Get the two digits. - ldx idx3 ; Get the string index. - sta.w strbuf, x ; Save it in the string buffer. - inc idx3 ; Increment the string index twice. - inc idx3 ; - ldx idx3 ; Get the string index. - pla ; Get the nibble offset back. - inc ; Increment the offset. - cmp #$10 ; Are we at the last offset? - bcs @end ; Yes, so we're done. + lea f, 2 ; Set the digit count to two. + mov s, b ; Get the low nibble offset. + jsr print_hex ; Print the low nibble offset. + mov.w (x), (a) ; Place the hex digits in the string buffer. + add x, #2 ; Add two to the string buffer pointer. + inb ; Increment the nibble offset. + cpb #$10 ; Are we at the last offset? + bcs @end ; Yes, so we're done. @loop1: - pha ; No, so preserve the nibble offset. - lda #' ' ; Add a space to the string buffer. - sta strbuf, x ; Save it in the string buffer. - inc idx3 ; Increment the string index. - pla ; Get the nibble offset back. - bra @loop ; Keep looping. + mov (x), #' ' ; No, so add a space to the string buffer. + inx ; Increment the string buffer pointer. + bra @loop ; Keep looping. @end: - and #0 ; Reset A. - sta strbuf, x ; Null terminate the string buffer. - tax ; Reset X. - lea strbuf ; Print the string buffer. -; jsr print_str ; - jsr print_sfast ; Use the faster, but less robust print string routine. - rts ; End of print_lo. -;@end: -; lda #0 ; Null terminate the string buffer. -; sta strbuf, x ; -; tax ; Reset X. -; lea strbuf ; Print the string buffer. -; jsr print_str ; -; rts ; End of print_lo. + mov (x), #0 ; Null terminate the string buffer. + lea d, (sp+3) ; Get the address of the string buffer. + lea s, (buffer)+y ; Get the address of the screen buffer, at the current cursor position. +; jsr print_str ; Print the string buffer. + jsr print_sfast ; Use the faster, but less robust print string routine. + ads #$33 ; Cleanup the stack frame. + plx.q ; Restore X. + plb.q ; Restore B. + pla.q ; Restore A. + rts ; End of print_lo. print_chunk: - ldx #0 ; Reset X. - phy.w ; Preserve the screen buffer index. - txy ; Copy the byte index to it. + pha.q ; Preserve A. + phb.q ; Preserve B. + phx.q ; Preserve X. + phy.q ; Preserve Y. + sbs #2 ; Make room for the hex string buffer. + and #0 ; Reset A. + tab ; Reset B. + mov x, d ; Get the address of the string buffer. + mov y, s ; Get the starting address. + lea d, (sp+1) ; Get the address of the hex string buffer. + xor s, s ; Reset S. @loop: - and #0 ; Reset A. - ldx #2 ; Set the digit count to 2. - lda (idx0), y ; Get the byte at that address. - jsr print_hex ; Print the byte. - lda.w (ptr3) ; Get the two digits. - ldx idx3 ; Get the string index. - sta.w strbuf, x ; Save it in the string buffer. - inc idx3 ; Increment the string index twice. - inc idx3 ; - ldx idx3 ; Get the string index. - iny ; Increment the byte index. - cpy #$10 ; Have we read 16 bytes? - beq @end ; Yes, so we're done. - lda #' ' ; No, so add a soace to the string buffer. - sta strbuf, x ; Save it in the string buffer. - inc idx3 ; Increment the string index. - bra @loop ; Keep looping. + lea f, 2 ; Set the digit count to two. + mov s, (y+b) ; Get the byte at that address. + jsr print_hex ; Print the byte. + mov.w (x), (a) ; Print the hex string to the string buffer. + add x, #2 ; Add two to the string buffer pointer. + inb ; Increment the byte index. + cpb #$10 ; Have we read 16 bytes? + beq @end ; Yes, so we're done. + mov (x), #' ' ; No, so print a space to the string buffer. + inx ; Increment the string buffer pointer. + bra @loop ; Keep looping. @end: - ply.w ; Get the screen buffer index back. - inx ; Increment the index by one. - and #0 ; Null terminate the string. - sta strbuf, x ; - tax ; Reset X. - sta idx3 ; Clear the string index. - rts ; End of print_chunk. + mov (x), #0 ; Null terminate the string. + ads #2 ; Cleanup the stack frame. + ply.q ; Restore Y. + plx.q ; Restore X. + plb.q ; Restore B. + pla.q ; Restore A. + rts ; End of print_chunk. print_hex: - pha.q ; Preserve the hex value. - and #0 ; Reset A. - ldb #1 ; Set the second pointer - lda.w #hex_char ; to the start of hex character table. - jsr set_ptr ; - inb ; Set the third pointer - lda.d #hex_str ; to the end of hex string buffer. - clc ; Do a non carrying add. - adc #$10 ; - jsr set_ptr ; - ldb #0 ; Reset B. - pla.q ; Get the hex value back. + phb.q ; Preserve B. + phx.q ; Preserve X. + phy.q ; Preserve Y. + lea b, hex_char ; Get the address of the hex character table. + and f, f ; Is the digit count zero? + set x, eq ; Set the auto digit count flag if so. + mne f, #$10 ; Also set the digit count to 16 if the digit count is zero. + mov a, f ; Get the digit count. + add a, d ; Add the string pointer with the digit count. @loop: - pha.q ; Preserve the hex value. - and #$F ; Mask the lowest nibble. - phy.w ; Preserve the screen buffer position. - tay ; Get the index for the hex digit. - lda (ptr2), y ; Get the hex digit. - dec ptr3 ; Decrement the string pointer. - sta (ptr3) ; Save the hex digit character in the string. - ply.w ; Get back the screen buffer position. - pla.q ; Get the hex value back. + mov y, s ; No, so mask the low nibble of the value. + and y, #$F ; + dec ; Decrement the string pointer. + mov (a), (b+y) ; Place the hex digit character in the string. + lsr s, #4 ; Is the next nibble zero? + bne @loop1 ; No, so decrement the digit count. @isauto: - cpx #1 ; Is the digit count less than one? - bcc @auto ; Yes, so don't decrement the digit count. - dex ; No, but was the digit count zero, when decremented? - beq @end ; Yes, so we're done. - bra @next ; No, so get the next nibble. -@auto: - ldb #1 ; Enable auto digit count. -@next: - lsr #4 ; Is the next nibble, a zero? - beq @isauto1 ; Yes, so check if auto digit count is enabled. - bra @loop ; No, so print the next digit. -@isauto1: - cpb #1 ; Is auto digit count enabled? - beq @end ; Yes, so we're done. - bra @loop ; No, so keep printing more digits. + and x, x ; Is the auto digit count flag set? + bne @end ; Yes, so we're done. +@loop1: + cpx #1 ; Is the auto digit count flag set? + sbc f, #0 ; Decrement the digit count if not. + mov y, f ; Get the digit count. + or y, x ; Are both the digit count, and the auto digit count flag zero? + bne @loop ; No, so keep looping. @end: + ply.q ; Restore Y. + plx.q ; Restore X. + plb.q ; Restore B. rts ; End of print_hex. @@ -147,26 +131,18 @@ charcpy: strcmpg: - ldb.w #strcmp ; Get the address of strcmp. - phb.q ; Use it for an indirect call. - ldb.q ptr ; Get the first pointer. + lea strcmp ; Get the address of strcmp. + mov.q d, ptr ; Get the first pointer. bra gargs ; Jump to the argument handler. strcaseg: - ldb.w #strccmp ; Get the address of strcasecmp. - phb.q ; Use it for an indirect call. - ldb.q ptr ; Get the first pointer. + lea strcasecmp ; Get the address of strcasecmp. + mov.q d, ptr ; Get the first pointer. bra gargs ; Jump to the argument handler. gargs: - phb.q ; Use the pointer in B as the first arg. - pha.q ; Use the value in A as the second arg. - and #0 ; reset a. - tab ; reset b. - jsr (sp+17) ; call the pushed routine. - tab ; Preserve the return value. - pla.q ; Get the second arg back. - pla.q ; Get the first arg back. - pla.q ; Get the pushed routine back. - tba ; Get the return value back. + mov s, a ; Use the value in A as the second arg. + and #0 ; Reset a. + tab ; Reset b. + jsr (e) ; Call the pushed routine. rts ; End of gargs. @@ -310,11 +286,6 @@ get_ptok: get_ctrlidx: -; phe.q ; Preserve E. -; cmp #$7F ; Is this a delete character? -; beq @del ; Yes, so return the same value as backspace. -; sec ; Do a non borrowing subtract. -; sbc #8 ; Subtract 8 from the character, to get the index. sub #8 ; Subtract 8 from the character, to get the index. tax ; Copy the index to X. and #0 ; Reset A. @@ -324,62 +295,41 @@ get_ctrlidx: leq (e) ; cmp #$7F ; Is this a delete character? leq #2 ; Return 2 if this is the delete character. -; bcc @get_rtval ; Yes, so get the return value from the table. -; beq @get_rtval ; -; ple.q ; Restore E. rts ; End of get_ctrlidx. -;@get_rtval: -; lda ct_rtb, x ; Get the return value from the table. -; rts ; End of get_ctrlidx. -;@del: -; lda #2 ; Return 2. -; rts ; End of get_ctrlidx. findramend: - phx.q ; Preserve X. and #0 ; Reset A. - lda #MAGIC ; Set A to a magic number. @loop: - ldx (e) ; Preserve the value. - sta (e) ; Write the magic number to the current end of RAM. - cmp (e) ; Is the value in RAM, the same as the magic number we wrote? + mov a, (d) ; Preserve the value. + mov (d), #MAGIC ; Write the magic number to the current end of RAM. + cmp (d), #MAGIC ; Is the value in RAM, the same as the magic number we wrote? bne @moveback ; No, so move back until we find the last writable memory location. - stx (e) ; Yes, so restore the previous value. - ade.w #$4000 ; Increment the end of RAM pointer by 16K. + mov (d), a ; Yes, so restore the previous value. + add.w d, #$4000 ; Increment the end of RAM pointer by 16K. bra @loop ; Keep looping. @moveback: - dee ; Decrement the end of RAM pointer. - ldx (e) ; Preserve the value. - sta (e) ; Write the magic number to the current end of RAM. - cmp (e) ; Is the value in RAM, the same as the magic number we wrote? + dec d ; Decrement the end of RAM pointer. + mov a, (d) ; Preserve the value. + mov (d), #MAGIC ; Write the magic number to the current end of RAM. + cmp (d), #MAGIC ; Is the value in RAM, the same as the magic number we wrote? bne @moveback ; No, so keep looping. - stx (e) ; Yes, so restore the previous value. + mov (d), a ; Yes, so restore the previous value. @end: - phe.q ; Return the end of RAM pointer. - pla.q ; - plx.q ; Restore X. + mov a, d ; Return the end of RAM pointer. rts ; End of findramend. print_sfast: -; inc step ; - pea (buffer), y ; Push the address of the cursor's postion in the screen buffer to the stack. + pha.q ; Preserve A. + and #0 ; Reset A. @loop: - lda (e) ; Get the character. - beq @end ; We've hit the end of the string, so we're done. - cmp #'\n' ; Did we get a newline? - beq @nl ; Yes, so move the cursor to the next line. - sta (sp+1) ; Print the character to the screen buffer. - sta scr ; Print the character to the screen. - inc scr_col ; Move the cursor left by one character. - ine ; Increment the string pointer. - inc.q sp+1 ; Increment the screen buffer pointer. - bra @loop ; Keep looping. -@nl: - stz scr_col ; Move the cursor to the start of the line. - inc scr_row ; Move the cursor down by one line. - bra @loop ; Keep looping. + inc ; Increment the index. + cmp (d+a-1), #0 ; Did we hit the end of the string? + beq @end ; Yes, so we're done. + mov (s+a-1), (d+a-1) ; No, so print the character to the buffer. + mov scr, (d+a-1) ; Print the character to the screen. + bra @loop ; Keep looping. @end: - ads #8 ; Cleanup the stack frame. - rts ; End of print_sfast. + pla.q ; Restore A. + rts ; End of print_sfast. -- cgit v1.2.3-13-gbd6f