From 0a7a2a7a8f95730811117bd2aa904f1843f65071 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 17 Apr 2020 22:07:14 -0400 Subject: Made both the assembly language monitor, and the emulator smaller, and faster. I am also starting to make SuBEditor's source code more readable. --- programs/subeditor.s | 290 +++++++++++++++++++++++++++------------------------ 1 file changed, 156 insertions(+), 134 deletions(-) (limited to 'programs') diff --git a/programs/subeditor.s b/programs/subeditor.s index 5e6ce08..fddc729 100644 --- a/programs/subeditor.s +++ b/programs/subeditor.s @@ -3,6 +3,16 @@ ; Writen in Sux assembly by ; mr b0nk 500 +; I/O constants. +status = $C000 ; Keyboard status. +scr = $C001 ; Character that is to be printed. +kbd = $C002 ; Character from the Keyboard. +step = $C010 ; Enables clock stepping, when set. + +; Screen constants. +maxrow = 23 ; Screen's row count. +maxcol = 79 ; Screen's column count. + .org $A000 ; String Literals/Constants. tok: @@ -72,27 +82,29 @@ bitabl: .qword 0 .qword 0 scr_str: - .byte $0 + .byte 0 scr_end: - .byte $0 + .byte 0 wrapped: - .byte $0 + .byte 0 ; Pointers ptr: - .qword $0 + .qword 0 ptr2: - .qword $0 + .qword 0 ptr3: - .qword $0 + .qword 0 ptr4: - .qword $0 + .qword 0 ptr5: - .qword $0 + .qword 0 ptr6: - .qword $0 + .qword 0 scr_ptr3: - .word $0 + .word 0 +g: + .byte 0 ; Main program .org $8000 @@ -101,8 +113,9 @@ reset: ldx.w #$FFFF ; Reset the stack pointer. txs ; ldy #0 ; Reset the Y register. + sty end ; tyx ; Reset the X register. - lda #23 ; Set the end of the screen back to 23. + lda #maxrow ; Set the end of the screen to the screen's max row count. sta scr_end ; lda.w #buffer ; Place the address for the screen buffer sta.q ptr5 ; into one of the pointers. @@ -112,6 +125,7 @@ reset: sta scr_str ; Set the start of the screen back to zero. sta.q bitabl ; Reset the first half of the linewrap table. sta.q bitabl+8 ; Reset the second half of the linewrap table. + inc end ; jsl clr_buf ; Clear the screen buffer. jmp start ; Goto the start of the main program. clr_buf: @@ -143,8 +157,7 @@ clr_buf_end: start: lda #0 ; TODO: Update this for the Super VIA. - sta end ; - sta $C000 ; Clear the controll register of the I/O adapter. + sta status ; Clear the controll register of the I/O adapter. tax ; Reset X. phy #2 ; Save the cursor index for later. tay ; Reset the cursor index. @@ -153,14 +166,15 @@ start: lda.w #string ; Print the startup message. jsl print_str ; lda.w zero ; Reset the Accumulator. + sta end ; jmp read ; Start reading the keyboard. clr_cbuf: phb #1 ; Start of callee preservation. ldb #0 ; Reset the B register. - lda.w #cmd_buf+8; - sta.q ptr4 ; - tba ; + lda.w #cmd_buf+8; Place the address of the command buffer, plus eight + sta.q ptr4 ; into the fourth pointer. + tba ; Set the Accumulator back to zero. clr_cbuf_st: cpy.w #$3FF ; Did we clear all of the command buffer? bcs clr_cbuf_nd ; Yes, so we're done. @@ -182,7 +196,10 @@ clr_cbuf_nd: rtl ; End of clr_cbuf. read: - lda $C000 ; Did we get a key? + lda #0 ; Reset the Accumulator. + sta end ; Disable the dummy flag. + inc end ; Enable the dummy flag. + lda status ; Did we get a key? beq read ; No, so try again. jsl getchar ; Yes, and was it a newline? beq parse ; Yes, so start parsing the line. @@ -194,17 +211,16 @@ print_str: tba ; Clear the Accumulator. inb ; Enable replace mode. stb b ; -pntstr_st: +pntstr_lp: phy #2 ; Save the cursor index. txy ; Copy the string index into Y. - lda (ptr), y ; Are we at the end of the string? - beq pntstr_end ; Yes, so we're done. - ply #2 ; No, so get the cursor index back. - inx ; Increment the string index. + lda (ptr), y ; Are we at the end of the string? + ply #2 ; Get the cursor index back. + beq pntstr_end ; Yes, so we're done. + inx ; No, so increment the string index. jsl print_char ; Print the character. - jmp pntstr_st ; Keep looping. + jmp pntstr_lp ; Keep looping. pntstr_end: - ply #2 ; Get the cursor index back. ldb #0 ; Enable insert mode. stb b ; rtl ; End of print_str. @@ -265,67 +281,80 @@ bitpos: rtl ; End of bitpos. getchar: - lda $C002 ; Get typed character. - ldb #0 ; - stb e ; - stb b ; - pha #1 ; - phy #2 ; - cmp #10 ; - beq cmd_cpy ; + lda kbd ; Get the character that was typed from the keyboard. + ldb #0 ; Reset the B register. + stb e ; Set the temporary row position to zero, in case we get a newline. + stb b ; Enable insert mode. + pha #1 ; Save the character. + phy #2 ; Save the cursor index. + cmp #10 ; Was the character that was typed, a newline? + beq cmd_cpy ; Yes, so start copying the line to the command buffer. getchar_pnt: - ply #2 ; - pla #1 ; - ldb e ; - bne reset_row ; + ply #2 ; Get back the cursor index. + pla #1 ; Get back the character. + ldb e ; Is the temporary row position non zero? + bne reset_row ; Yes, so reset the row positon. getchar_pt1: - jsl print_char ; - lda a ; - cmp #10 ; - beq getchar_ln ; - jmp getchar_chr ; + jsl print_char ; No, so print the character. + lda a ; Get the return value. + cmp #10 ; Is the return value, a newline? + beq getchar_ln ; Yes, so return 0. + jmp getchar_chr ; No, so return 1. reset_row: - ldb e ; - cpb #23 ; - beq reset_row2 ; - bcs reset_row1 ; - jmp reset_row2 ; + ldb e ; Get the temporary row position. + cpb #maxrow ; Is temporary row position, at, or above the bottom of the screen? + beq reset_row2 ; Yes, so leave it as is. + bcs reset_row1 ; No, so set it to the bottom of the screen. + jmp reset_row2 ; Yes, so leave it as is. reset_row1: - ldb #23 ; + ldb #maxrow ; Set the row position to the bottom of the screen. reset_row2: - stb scr_row ; - jmp getchar_pt1 ; - + stb scr_row ; Set the row position. + jmp getchar_pt1 ; Print the character. cmd_cpy: - lda scr_row ; - sta scr_trow ; - jsl findend ; - sta scr_row ; - sta e ; - jsl findst ; - clc ; - lda scr_row ; - adc scr_str ; - mul #80 ; - tay ; - ldx.w #$0 ; -cmd_cpy_st: - lda (ptr5), y ; - beq getchar_pnt ; - phy #2 ; - txy ; - sta (ptr6), y ; - inx ; - ply #2 ; - iny ; - jmp cmd_cpy_st ; + lda scr_row ; Get the row position. + sta scr_trow ; Save it for later. + jsl findend ; Find the end of the line. + sta scr_row ; Set the row position to the end of the line. + sta e ; Save it into the temporary row posiition. + jsl findst ; Find the start of the line. + clc ; Clear the carry flag. + lda scr_row ; Get the row position. + adc scr_str ; Add it with the screen's starting row. + mul #maxcol+1 ; Multiply it with the width of the screen, plus one. + tay ; Place it into the index. + ldx.w #0 ; Reset the X register. +cmd_cpy_lp: + ldb #0 ; Reset the B register. + lda.q (ptr5), y ; Get eight bytes from the current line. +cmd_cpy_lp1: + phy #2 ; Save the screen index. + txy ; Get the command buffer index. + sta (ptr6), y ; Copy one byte from the screen buffer, to the command buffer. + inx ; Increment the command buffer index. + ply #2 ; Get back the screen index. + iny ; Increment the screen index. + inb ; Increment the byte count. + lsr #8 ; Shift in the next byte. + stb g ; Save the byte count. + tab ; Save the string buffer. + and #$FF ; Is this byte of the buffer, a null terminator? + beq cmd_cpy_nd ; Yes, so we're done. + tba ; No so get back the string buffer. + ldb g ; Get back the byte count. + cpb #7 ; Did we shift in eight bytes? + beq cmd_cpy_lp ; Yes, so get eight more bytes. + jmp cmd_cpy_lp1 ; No, so keep shifting in more bytes. +cmd_cpy_nd: + tab ; The B register is zero, so clear the Accumulator. + jmp getchar_pnt ; Go back to printing the character. getchar_ln: - lda #0 ; - jmp getchar_end ; + lda #0 ; Return zero. + jmp getchar_end ; We are done. getchar_chr: - lda #1 ; + lda #1 ; Return one. getchar_end: - rtl ; + rtl ; End of get char. findst: lda #0 ; @@ -358,7 +387,7 @@ fndend_done: findend: jsl fndend ; lda.w scr_ptr3 ; - div #80 ; + div #maxcol+1 ; rtl ; parse: @@ -374,7 +403,7 @@ print_char: sta a ; cmp #$1B ; beq esc ; - cmp #$A ; + cmp #10 ; beq nl ; Did the user type a newline? cmp #$C ; beq clr_scr ; @@ -444,32 +473,33 @@ printc_2: ldb #1 ; stb f ; ldb scr_col ; - cpb #80 ; + cpb #maxcol+1 ; bcs printc_4 ; printc_3: - sta $C001 ; Echo typed character. + sta scr ; Echo typed character. ldb f ; beq printc_wrap ; jmp printc_end ; printc_4: ldb scr_row ; - cpb #23 ; + cpb #maxrow ; bcs printc_scrl ; printc_5: ldb #0 ; stb f ; jmp printc_3 ; printc_scrl: - sta $C001 ; Echo typed character. + sta scr ; Echo typed character. clc ; lda #1 ; sta wrapped ; jsl scrl_down ; + jmp printc_wrap ; printc_wrap: - ldb #0 ; + ldb #0 stb scr_col ; ldb scr_row ; - cpb #23 ; + cpb #maxrow ; bcs printc_wrp2 ; printc_wrap1: inc scr_row ; @@ -493,7 +523,7 @@ nl: nl1: sta scr_col ; lda scr_row ; - cmp #23 ; + cmp #maxrow ; bcc nl_inc ; jsl scrl_down ; lda #10 ; @@ -507,7 +537,7 @@ nl_inc: jmp printc_end ; clr_scr: - lda #23 ; + lda #maxrow ; sta scr_end ; lda #0 ; sta scr_str ; @@ -521,25 +551,25 @@ clr_scr: sta scr_row ; jsl update_pos ; lda #$C ; - sta $C001 ; + sta scr ; jmp printc_end ; en_step: - lda $C010 ; + lda step ; beq step_en ; jmp printc_end ; step_en: lda #1 ; - sta $C010 ; + sta step ; jmp printc_end ; dis_step: - lda $C010 ; + lda step ; bne step_dis ; jmp printc_end ; step_dis: lda #0 ; - sta $C010 ; + sta step ; jmp printc_end ; back: @@ -566,7 +596,7 @@ back1: stb d ; jsl shftln ; Shift line back by one character. lda #$7F ; Print a backspace to the screen. - sta $C001 ; + sta scr ; lda e ; beq back3 ; back2: @@ -617,7 +647,7 @@ backwrp: backwrp2: dec scr_row ; Move up by one row. ; jsl clrbit ; Clear the wrap bit for this row. - ldb #80 ; Move the cursor to the absolute right of the screen. + ldb #maxcol+1 ; Move the cursor to the absolute right of the screen. stb scr_col ; jsl update_pos ; Update the cursor's position. jmp back ; Delete the previous character. @@ -691,9 +721,9 @@ shftln_nd1: shftln_end1: jsl findend ; Find the ending line. cpb #0 ; Is the remainder zero? - beq shftln_nd01 ; Yes, so check if the ending line is greater than the starting line. + beq shftln_nd2 ; Yes, so check if the ending line is greater than the starting line. jmp shftln_end2 ; No, so we're done. -shftln_nd01: +shftln_nd2: cmp scr_row ; Is the ending line greater than the starting line? beq shftln_end2 ; No, so we're done. bcs shftln_wrp1 ; Yes, so clear the wrap bit. @@ -701,13 +731,13 @@ shftln_end2: rtl ; End of shftln. esc: - lda $C000 ; Get the next character. - lda $C002 ; + lda status ; Get the next character. + lda kbd ; cmp #$1B ; Is this character an escape character? beq shftesc ; Yes, so check the other set of escape routines. - lda $C000 ; No, so wait for the next character. + lda status ; No, so wait for the next character. beq printc_end ; We have an error, so discard it, and go back to getting user input. - lda $C002 ; Get the escape code. + lda kbd ; Get the escape code. sta c ; Store the escape code, until we need it. lda #0 ; Set the D pseudo register to zero. sta d ; @@ -728,10 +758,11 @@ esc_end: jmp printc_end ; We are done. shftesc: - lda $C000 ; Skip the '['. - lda $C000 ; Get the next character. + lda status ; Skip the '['. + lda kbd ; + lda status ; Wait for the next character. beq printc_end ; We have an error, so discard it, and go back to getting user input. - lda $C002 ; Get the escape code. + lda kbd ; Get the escape code. sta c ; Store the escape code, until we need it. lda #0 ; Use the D pseudo register as a skip flag. sta d ; @@ -769,7 +800,7 @@ isdown: cmp #$42 ; Did the user press the down arrow key? bne isdown_done ; No, so we're done. lda scr_row ; Yes, so start checking the y coordinate of the cursor. - cmp #23 ; Is the cursor at the bottom of the screen? + cmp #maxrow ; Is the cursor at the bottom of the screen? beq isdown_scrl ; Yes, so scroll down. lda c ; No, so load the escape code back into the accumulator. cmp #$42 ; Did the user press the down arrow key? @@ -795,7 +826,7 @@ isright: cmp #$43 ; Did the user press the right arrow key? bne isright_dne ; No, so we're done. lda scr_col ; Yes, so start checking the x coordinate of the cursor. - cmp #79 ; Is the cursor at the far right of the screen? + cmp #maxcol ; Is the cursor at the far right of the screen? beq isright_wrp ; Yes, so check if this is a wrapped line. jmp right ; No, so move the cursor right, like normal. isright_wrp: @@ -815,7 +846,7 @@ wrap_inc: lda #0 ; Set the cursor to the far left of the screen. sta scr_col ; lda scr_row ; Get the current row number. - cmp #23 ; Are we at the bottom of the screen? + cmp #maxrow ; Are we at the bottom of the screen? beq isright_nd2 ; No, so we're done. bcs isright_scr ; Yes, so check if we are scrolling down. jmp isright_nd2 ; No, so we're done. @@ -849,7 +880,7 @@ wrap_dec: sta wrapped ; dec scr_row ; Move the cursor up one line. wrap_dec1: - lda #79 ; Move the Cursor to the far right of the screen. + lda #maxcol ; Move the Cursor to the far right of the screen. sta scr_col ; lda #1 ; Tell the escape routine that we were successful. sta d ; @@ -937,58 +968,52 @@ update_pos: lda scr_row ; Add the cursor's line number, adc scr_str ; with the starting line number to get the absolute line number. tay ; Place it in the Y regster for now. - clc ; Clear the carry flag. - lsl #6 ; Multiply the absolute line number by 64. - tab ; Use it as a second operand. - tya ; Place the absolute line number back into the Accumulator - lsl #4 ; Multiply the absolute line number by 16. - aab ; Add both the Accumulator, and the B register together, to multiply the line number by 80. - clc ; Clear the carry flag. + mul #maxcol+1 ; Multiply the line number by the screen's max column count, plus 1. adc scr_col ; Add the cursor's column number to get the screen index. tay ; Place the index into the Y register. lda #$1B ; Print an escape character - sta $C001 ; to the screen. + sta scr ; to the screen. lda #$5B ; Print '[' - sta $C001 ; to the screen, and start the escape sequence. + sta scr ; to the screen, and start the escape sequence. jsl getrow ; Start printing the row number to the screen. jsl getcol ; Start printing the column number to the screen. lda #$48 ; Print 'H' - sta $C001 ; to the screen. + sta scr ; to the screen. rtl ; End of update_pos. getrow: lda scr_row ; Get the cursor's y coordinate. div #10 ; Divide A by 10. adc #$30 ; Convert it to ascii, and - sta $C001 ; print to the screen. + sta scr ; print to the screen. tba ; Get the remainder. adc #$30 ; Convert it to ascii, and - sta $C001 ; print to the screen. + sta scr ; print to the screen. rtl ; End of getrow. getcol: lda #$3B ; Print ';' - sta $C001 ; to the screen. + sta scr ; to the screen. lda scr_col ; Get the cursor's x coordinate. div #10 ; Divide A by 10. clc adc #$30 ; Convert it to ascii, and - sta $C001 ; print to the screen. + sta scr ; print to the screen. tba ; Get the remainder. clc adc #$30 ; Convert it to ascii, and - sta $C001 ; print to the screen. + sta scr ; print to the screen. rtl ; End of getrow. scrl_down: inc scr_str ; Increment the starting line of the screen. inc scr_end ; Increment the ending line of the screen. lda #$1B ; Print an escape character - sta $C001 ; to the screen. + sta scr ; to the screen. lda #$5B ; Print '[' - sta $C001 ; to the screen, and start the escape sequence. + sta scr ; to the screen, and start the escape sequence. lda #$54 ; Print 'T' - sta $C001 ; to the screen, and end the escape sequence. + sta scr ; to the screen, and end the escape sequence. lda scr_row ; Get the cursor's line number. pha #1 ; Save it in the stack. lda wrapped ; Was the wrapped flag set? @@ -1018,11 +1043,11 @@ scrl_up: dec scr_str ; dec scr_end ; lda #$1B ; Print an escape character - sta $C001 ; to the screen. + sta scr ; to the screen. lda #$5B ; Print '[' - sta $C001 ; to the screen, and start the escape sequence. + sta scr ; to the screen, and start the escape sequence. lda #$53 ; Print 'S' - sta $C001 ; to the screen, and end the escape sequence. + sta scr ; to the screen, and end the escape sequence. lda scr_row ; pha #1 ; lda scr_col ; @@ -1045,7 +1070,7 @@ rdrw_row: rdrow_st: lda (ptr5), y ; beq rdrow_inc ; - sta $C001 ; + sta scr ; rdrow_inc: inc scr_col ; lda (ptr5), y ; @@ -1054,12 +1079,12 @@ rdrow_inc1: iny ; rdrow_inc2: lda scr_col ; - cmp #80 ; + cmp #maxcol+1 ; bcs rdrow_end ; jmp rdrow_st ; rdrow_skip: lda #$20 ; - sta $C001 ; to the screen. + sta scr ; to the screen. jmp rdrow_inc1 ; rdrow_end: lda #0 ; @@ -1080,7 +1105,7 @@ rset_x: dabbed: ldb #0 ; lda.w #tok ; - sta.q ptr2 ; + sta.q ptr2 ;i tba ; dab_st: phy #2 ; @@ -1124,7 +1149,6 @@ cmd_clr: rdrw_ln: lda scr_row ; pha #1 ; - inc end ; lda f ; sta scr_row ; lda scr_col ; @@ -1149,13 +1173,11 @@ rdrwln_done: lda #0 ; sta e ; sta f ; - dec end ; rtl ; .org $FFC0 .qword reset - a done -- cgit v1.2.3-13-gbd6f