From ed88644ded82008577804c590bec7188ef0da011 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Mon, 27 Apr 2020 00:22:27 -0400 Subject: Added support for including source files to the emulator's assembler. And removed three pointers, and the linewrap table from zero page, in SuBEditor. I moved the linewrap table to address $1000. And because of finally adding include support to the assembler, I can now start work on SuBAsm! --- programs/subeditor.s | 342 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 205 insertions(+), 137 deletions(-) (limited to 'programs') diff --git a/programs/subeditor.s b/programs/subeditor.s index 8eec46a..1842b5a 100644 --- a/programs/subeditor.s +++ b/programs/subeditor.s @@ -35,6 +35,13 @@ bits: .byte $02 .byte $01 + +; Linewrap table. +.org $1000 +bitabl: + .qword 0 + .qword 0 + ; Input buffer. .org $2000 buffer: @@ -43,7 +50,7 @@ buffer: cmd_buf: -; Initalize some variables. +; Screen variables. .org 0 scr_row: .byte 0 @@ -57,7 +64,10 @@ scr_ptr: .word 0 scr_ptr2: .word 0 -; Registers. +scr_ptr3: + .word 0 + +; Pseudo registers. a: .byte 0 b: @@ -70,17 +80,17 @@ e: .byte 0 f: .byte 0 -; This register is always zero. +g: + .byte 0 +; This pseudo register is always zero. zero: .qword 0 -; End of registers. +; End of pseudo registers. + end: - .byte 0 + .word 0 bitmask: .byte 0 -bitabl: - .qword 0 - .qword 0 scr_str: .byte 0 scr_end: @@ -95,16 +105,6 @@ ptr2: .qword 0 ptr3: .qword 0 -ptr4: - .qword 0 -ptr5: - .qword 0 -ptr6: - .qword 0 -scr_ptr3: - .word 0 -g: - .byte 0 ; Main program .org $8000 @@ -117,84 +117,63 @@ reset: tyx ; Reset the X register. 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. - lda.w #cmd_buf ; Place the address for the command buffer - sta.q ptr6 ; into one of the pointers. tya ; Reset the Accumulator. 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. + lda.w #$1FFF ; Set the clear count to $1FFF. + sta.w scr_ptr ; + lda.w #buffer ; Set the array to be cleared to the screen buffer. + jsl clr_arr ; Clear the screen buffer. jmp start ; Goto the start of the main program. -clr_buf: +clr_arr: phb #1 ; Preserve whatever was in B. ldb #0 ; Clear B. - lda.w #buffer+8 ; - sta.q ptr4 ; + jsl set_ptr ; Set the first pointer to the parameter. + adc #8 ; Set the second pointer to the parameter, plus eight. + inb ; Tell set_ptr to set the second pointer. + jsl set_ptr ; + deb ; Set B back to zero. tba ; -clr_buf_st: - cpy.w #$1FFF ; Did we clear all of the screen buffer? - bcs clr_buf_end ; Yes, so we're done. - sta.q (ptr5), y ; No, so clear eight bytes. - sta.q (ptr4), y ; Clear eight more bytes. - tya ; Copy the buffer index. +clr_arr_st: + cpy.w scr_ptr ; Did we clear all of the array? + bcs clr_arr_end ; Yes, so we're done. + sta.q (ptr), y ; No, so clear eight bytes. + sta.q (ptr2), y ; Clear eight more bytes. + tya ; Copy the array index. adc #$10 ; Increment the index by 16. tay ; Update the index. tba ; Reset the Accumulator. - sta.q (ptr5), y ; Do this one more time, to clear 32 bytes. - sta.q (ptr4), y ; + sta.q (ptr), y ; Do this one more time, to clear 32 bytes. + sta.q (ptr2), y ; tya ; adc #$10 ; tay ; tba ; - jmp clr_buf_st ; Keep looping. -clr_buf_end: + jmp clr_arr_st ; Keep looping. +clr_arr_end: ldy.w zero ; Set the index back to zero. plb #1 ; Get whatever was in the B register, back. - rtl ; End of clr_buf. + rtl ; End of clr_arr. start: lda #0 ; TODO: Update this for the Super VIA. - sta status ; Clear the controll register of the I/O adapter. + sta status ; Clear the control register of the I/O adapter. tax ; Reset X. phy #2 ; Save the cursor index for later. tay ; Reset the cursor index. - jsl clr_cbuf ; Clear the command buffer. + lda.w #$3FF ; Set the clear count to $3FF. + sta.w scr_ptr ; + lda.w #cmd_buf ; Set the array to be cleared to the command buffer. + jsl clr_arr ; Clear the command buffer. ply #2 ; Get back the cursor index. lda.w #string ; Print the startup message. jsl print_str ; - lda.w zero ; Reset the Accumulator. + lsr #$10 ; 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; 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. - sta.q (ptr6), y ; No, so clear eight bytes. - sta.q (ptr4), y ; Clear eight more bytes. - tya ; Copy the buffer index. - adc #$10 ; Increment the index by 16. - tay ; Update the index. - tba ; Reset the Accumulator. - sta.q (ptr6), y ; Do this one more time, to clear 32 bytes. - sta.q (ptr4), y ; - tya ; - adc #$10 ; - tay ; - tba ; - jmp clr_cbuf_st ; Keep looping. -clr_cbuf_nd: - plb #1 ; End of callee preservation. - rtl ; End of clr_cbuf. - read: lda #0 ; Reset the Accumulator. sta end ; Disable the dummy flag. @@ -206,12 +185,19 @@ read: jmp read ; No, so keep looping. print_str: - sta.q ptr ; Place the string pointer into the main pointer. + sta.w end ; Save the parameter. +print_str2: + lda.w end ; Get the parameter. ldb #0 ; Clear the B register. + jsl set_ptr ; Set the first pointer to the parameter. tba ; Clear the Accumulator. inb ; Enable replace mode. stb b ; pntstr_lp: + lda.w ptr ; Get the first pointer. + cmp.w end ; Did the pointer change? + bne print_str2 ; Yes, so set it back. + lsr #$10 ; No, reset the accumulator. phy #2 ; Save the cursor index. txy ; Copy the string index into Y. lda (ptr), y ; Are we at the end of the string? @@ -236,34 +222,61 @@ getbt0: adc scr_str ; Add the screen offset to it. tax ; Use it as the wrap index. getbt1: + pha #1 ; Save the parameter. + ldb #1 ; Make sure that set_ptr sets the second pointer. + lda.w #bitabl ; Set the second pointer to the linewrap table. + jsl set_ptr ; + lsr #$10 ; Clear the Accumulator. + pla #1 ; Get the return byte back. jsl bitpos ; Get the bit, and byte position. - ldb bitabl, x ; Get one byte of the wrap table. + phy #2 ; Save the screen index. + txy ; Get the byte position. + ldb (ptr2), y ; Get one byte of the wrap table. + ply #2 ; Get the screen index back. aba ; Mask out the bit of the current line number. cmp #1 ; Set the carry flag, if true. jmp bitout ; We are done. clrbit: + pha #1 ; Save the parameter. + ldb #1 ; Make sure that set_ptr sets the second pointer. + lda.w #bitabl ; Set the second pointer to the linewrap table. + jsl set_ptr ; + lsr #$10 ; Clear the Accumulator. + pla #1 ; Get the return byte back. jsl bitpos ; Get the bit, and byte position. xor #$FF ; Invert the bitmask. - ldb bitabl, x ; Get one byte of the wrap table. + phy #2 ; Save the screen index. + txy ; Get the byte position. + ldb (ptr2), y ; Get one byte of the wrap table. aba ; Clear the bit of the current line number. bitsav: - sta bitabl, x ; Update the wrap table. + sta (ptr2), y ; Update the wrap table. + ply #2 ; Get the screen index back. bitout: ldx bitmask ; Return the bitmask. rtl ; We are done. setbit: + pha #1 ; Save the parameter. + ldb #1 ; Make sure that set_ptr sets the second pointer. + lda.w #bitabl ; Set the second pointer to the linewrap table. + jsl set_ptr ; + lsr #$10 ; Clear the Accumulator. + pla #1 ; Get the return byte back. jsl bitpos ; Get the bit, and byte position. - ldb bitabl, x ; Get one byte of the wrap table. + phy #2 ; Save the screen index. + txy ; Get the byte position. + ldb (ptr2), y ; Get one byte of the wrap table. oab ; Set the bit of the current line number. jmp bitsav ; Save the bit. bitpos: pha #1 ; Save the parameter. - lda.w #bits ; Place the address of the bitmask table, - sta.q ptr3 ; in the third pointer. - lda.w zero ; Clear the Accumulator. + ldb #0 ; Make sure that set_ptr sets the first pointer. + lda.w #bits ; Set the first pointer to the bitmask table. + jsl set_ptr ; + lsr #$10 ; Clear the Accumulator. pla #1 ; Get the parameter back. stx bitmask ; Make the line number the bitmask. txa ; Copy it to the Accumulator. @@ -271,7 +284,7 @@ bitpos: phy #2 ; Save the cursor index. tay ; Use the bit position as the index. tax ; Copy it into X. - lda (ptr3), y ; Get the bitmask. + lda (ptr), y ; Get the bitmask. ply #2 ; Get back the cursor index. pha #1 ; Save the bitmask. lda bitmask ; Get the line number. @@ -288,7 +301,8 @@ getchar: 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. + bne getchar_pnt ; No, so just print the character. + jsl cmd_cpy ; Yes, so start copying the line to the command buffer. getchar_pnt: ply #2 ; Get back the cursor index. pla #1 ; Get back the character. @@ -311,10 +325,26 @@ reset_row1: reset_row2: stb scr_row ; Set the row position. jmp getchar_pt1 ; Print the character. +getchar_ln: + lda #0 ; Return zero. + jmp getchar_end ; We are done. +getchar_chr: + lda #1 ; Return one. +getchar_end: + rtl ; End of get char. + + cmd_cpy: lda scr_row ; Get the row position. sta scr_trow ; Save it for later. jsl findend ; Find the end of the line. + ldb scr_str ; Has the screen been scrolled? + beq cmd_cpy3 ; No, so don't subtract the screen's starting point from the line number. +cmd_cpy2: + sec ; Yes, so make sure that we don't subtract by the starting point, plus one. + sbc scr_str ; Offset the row position, back by the screen's starting point. + clc ; Clear the carry flag, so that nothing odd occurs. +cmd_cpy3: 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. @@ -324,13 +354,21 @@ cmd_cpy: 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. + ldb #0 ; Make sure that set_ptr sets the first pointer. + lda.w #buffer ; Set the first pointer to the start of the screen buffer. + jsl set_ptr ; + inb ; Make sure that set_ptr sets the second pointer. + lda.w #cmd_buf ; Set the second pointer to the start of the command buffer. + jsl set_ptr ; + deb ; Set B back to zero. + tba ; Set the accumulator to zero. cmd_cpy_lp: ldb #0 ; Reset the B register. - lda.q (ptr5), y ; Get eight bytes from the current line. + lda.q (ptr), 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. + sta (ptr2), 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. @@ -347,14 +385,10 @@ cmd_cpy_lp1: 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 ; Return zero. - jmp getchar_end ; We are done. -getchar_chr: - lda #1 ; Return one. -getchar_end: - rtl ; End of get char. + rtl ; End of cmd_cpy. + + + findst: lda #0 ; @@ -373,9 +407,15 @@ findst_done: rtl ; fndend: + phb #1 ; Save the contents of the B register. + ldb #0 ; Make sure that set_ptr sets the first pointer. + lda.w #buffer ; Set the first pointer to the start of the screen buffer. + jsl set_ptr ; + tba ; Set the Accumulator to zero. + plb #1 ; Restore the contents of the B register. phy #2 ; fndend_lp: - lda (ptr5), y ; Are we at the end of the string? + lda (ptr), y ; Are we at the end of the string? beq fndend_done ; Yes, so we're done. iny ; No, so increment the cursor index. jmp fndend_lp ; Keep looping. @@ -400,26 +440,31 @@ parse: jmp result ; print_char: - sta a ; - cmp #$1B ; - beq esc ; - cmp #10 ; - beq nl ; Did the user type a newline? - cmp #$C ; - beq clr_scr ; - cmp #19 ; - beq en_step ; - cmp #18 ; - beq dis_step ; - cmp #8 ; - beq bs ; Did the user type a backspace? - cmp #$7F ; - beq bs ; Did the user type a backspace? - sta a ; + sta a ; Save the typed character for now. + ldb #2 ; Make sure that set_ptr sets the third pointer. + lda.w #buffer ; Set the third pointer to the start of the screen buffer. + jsl set_ptr ; + ldb #0 ; Set B to zero. + tba ; Set the Accumulator to zero. + lda a ; Get back the character. + cmp #$1B ; Did the user type an escape character? + beq esc ; Yes, so go check the escape code. + cmp #10 ; No, but did the user type a newline? + beq nl ; Yes, so handle the newline. + cmp #$C ; No, but did the user type Ctrl+L? + beq clr_scr ; Yes, so clear the screen. + cmp #19 ; No, but did the user type Ctrl+S? + beq en_step ; Yes, so enable clock/instruction stepping. + cmp #18 ; No, but did the user type Ctrl+R? + beq dis_step ; Yes, so disable clock/instruction stepping. + cmp #8 ; No, but did the user type a backspace? + beq bs ; Yes, so handle the backspace. + cmp #$7F ; No, but did they type Delete? + beq bs ; Yes, so treat it as a backspace. printc: - lda #0 ; + lda #0 ; No, so start trying to print a character. sta d ; - lda (ptr5), y ; Are we at the end of the string? + lda (ptr3), y ; Are we at the end of the string? beq printc_save ; Yes, so just print the character. lda b ; No, but was the flag set? bne printc_save ; Yes, so don't shift the line. @@ -456,7 +501,7 @@ prntc_movln: ldb #1 ; stb d ; lda a ; - sta (ptr5), y ; store typed character into the input buffer. + sta (ptr3), y ; store typed character into the input buffer. lda scr_row ; sta scr_trow ; jmp prntc_updt ; @@ -465,7 +510,7 @@ printc_save: bne prntc_updt ; printc_sav1: lda a ; - sta (ptr5), y ; store typed character into the input buffer. + sta (ptr3), y ; store typed character into the input buffer. printc_inc: inc scr_col ; Increment the cursor's x coordinate. iny ; @@ -517,9 +562,9 @@ printc_end: nl: lda #0 ; - ldb (ptr5), y ; + ldb (ptr3), y ; bne nl1 ; - sta (ptr5), y ; Store said terminator into the input buffer. + sta (ptr3), y ; Store said terminator into the input buffer. nl1: sta scr_col ; lda scr_row ; @@ -544,9 +589,15 @@ clr_scr: sta.q bitabl ; sta.q bitabl+8 ; tay ; - jsl clr_buf ; + lda.w #$1FFF ; Set the clear count to $1FFF. + sta.w scr_ptr ; + lda.w #buffer ; Set the array to be cleared to the command buffer. + jsl clr_arr ; Clear the screen buffer. tay ; - jsl clr_cbuf ; + lda.w #$3FF ; Set the clear count to $3FF. + sta.w scr_ptr ; + lda.w #buffer ; Set the array to be cleared to the command buffer. + jsl clr_arr ; Clear the screen buffer. sta scr_col ; sta scr_row ; jsl update_pos ; @@ -589,7 +640,7 @@ back0: back1: dey ; Decrement the buffer's offset. lda #0 ; Place a null terminator - sta (ptr5), y ; into the buffer. + sta (ptr3), y ; into the buffer. tyx ; Copy the current cursor index to X. iny ; Increment cursor index. ldb #0 ; @@ -646,7 +697,6 @@ backwrp: tax ; Transfer that into X. backwrp2: dec scr_row ; Move up by one row. -; jsl clrbit ; Clear the wrap bit for this row. ldb #maxcol+1 ; Move the cursor to the absolute right of the screen. stb scr_col ; jsl update_pos ; Update the cursor's position. @@ -659,7 +709,7 @@ shftln: jmp shftln_lp0 ; No, so shift, and increment. shftln_neg: ldy.w zero ; Set the source poition to 0. - stb (ptr5), y ; Clear the character that is in the source. + stb (ptr3), y ; Clear the character that is in the source. jmp shftln_end ; We are done. shftln_lp0: sty.w scr_ptr2 ; Save the source position for later. @@ -669,26 +719,26 @@ shftln_lp0: bcs shftln_end ; No, so we're done. shftln_lp01: ldy.w scr_ptr2 ; Get the source position. - lda (ptr5), y ; Get the character from the source position. + lda (ptr3), y ; Get the character from the source position. phy #2 ; Save the source position for later. txy ; Set our position to the destination. - sta (ptr5), y ; Place the character from the source position, to the destination position. + sta (ptr3), y ; Place the character from the source position, to the destination position. ply #2 ; Set our position back to the source. - stb (ptr5), y ; Clear the character that is in the source. + stb (ptr3), y ; Clear the character that is in the source. bng shftln_neg ; The source underflowed, so set it back to zero, dey ; Decrement the source position. dex ; Decrement the destination position. jmp shftln_lp0 ; Keep looping. shftln_lp1: stx.w scr_ptr2 ; Save the destination position for later. - lda (ptr5), y ; Is the character at the source position, a null terminator? + lda (ptr3), y ; Is the character at the source position, a null terminator? beq shftln_end1 ; Yes, so we're done. phy #2 ; No, so save the source position for later. txy ; Set our position to the destination. - sta (ptr5), y ; Place the character from the source position, to the destination position. + sta (ptr3), y ; Place the character from the source position, to the destination position. inx ; Increment the destination position. ply #2 ; Set our position back to the source. - stb (ptr5), y ; Clear the character that is in the source. + stb (ptr3), y ; Clear the character that is in the source. iny ; Increment the source position. jmp shftln_lp1 ; Keep looping. shftln_wrap: @@ -700,18 +750,18 @@ shftln_wrp1: jsl clrbit ; Clear the wrap bit of the ending line. jmp shftln_end2 ; We are done. shftln_end: - lda (ptr5), y ; Is this character a null terminator? + lda (ptr3), y ; Is this character a null terminator? bne shftln_nd0 ; No, so just find the end of the line. lda #$20 ; Yes, so convert it to a space for now. - sta (ptr5), y ; + sta (ptr3), y ; shftln_nd0: jsl findend ; Find the ending line. sta d ; Save ending line for later. - lda (ptr5), y ; Is this character a space? + lda (ptr3), y ; Is this character a space? cmp #$20 ; bne shftln_nd1 ; No, so skip the conversion. lda #0 ; Yes, so convert it back to zero. - sta (ptr5), y ; + sta (ptr3), y ; shftln_nd1: lda d ; Get the ending line. cmp scr_row ; Is the ending line greater than the starting line? @@ -1068,12 +1118,12 @@ rdrw_row: sta scr_col ; jsl update_pos ; rdrow_st: - lda (ptr5), y ; + lda (ptr3), y ; beq rdrow_inc ; sta scr ; rdrow_inc: inc scr_col ; - lda (ptr5), y ; + lda (ptr3), y ; beq rdrow_skip ; rdrow_inc1: iny ; @@ -1103,18 +1153,22 @@ rset_x: jmp print_buf ; Print the input buffer. dabbed: - ldb #0 ; - lda.w #tok ; - sta.q ptr2 ;i - tba ; + ldb #0 ; Make sure that set_ptr is setting the first pointer. + lda.w #cmd_buf ; Set the first pointer to the start of the command buffer. + jsl set_ptr ; + inb ; Make set_ptr set the second pointer. + lda.w #tok ; Set the second pointer to the start of the token string. + jsl set_ptr ; + deb ; Set B back to zero. + tba ; Also set the accumulator back to zero. dab_st: phy #2 ; txy ; - lda (ptr6), y ; Get a character from the input buffer. - beq dab_pend ; Are we done with printing the buffer? - cmp (ptr2), y ; - beq chk_str ; - jmp dab_pend ; + lda (ptr), y ; Are we at the end of the string? + beq dab_pend ; Yes, so return false. + cmp (ptr2), y ; No, but is this character the same as the character in the token string? + beq chk_str ; Yes, so increment the character count. + jmp dab_pend ; No, so return false. chk_str: ply #2 ; inx ; @@ -1124,7 +1178,6 @@ chk_str: pnt_msg: lda.w #msg ; ldx #0 ; - stx.q ptr ; jsl print_str ; jmp dab_peqnd ; dab_pend: @@ -1140,7 +1193,7 @@ dab_end: print_buf: lda.w #cmd_buf ; jsl print_str ; - lda.w zero ; + lsr #$10 ; Clear the Accumulator. cmd_clr: lda #10 ; jsl print_char ; @@ -1175,6 +1228,21 @@ rdrwln_done: sta f ; rtl ; +set_ptr: + cpb #1 ; Are we setting the second pointer? + beq set_ptr2 ; Yes, so start setting it. + cpb #2 ; No, but are we setting the third pointer? + beq set_ptr3 ; Yes, so start setting it. +set_ptr1: + sta.q ptr ; No, so set the first pointer. + jmp setptr_end ; We are done. +set_ptr2: + sta.q ptr2 ; Set the second pointer. + jmp setptr_end ; We are done. +set_ptr3: + sta.q ptr3 ; Set the third pointer. +setptr_end: + rtl ; End of set_ptr. .org $FFC0 .qword reset -- cgit v1.2.3-13-gbd6f