summaryrefslogtreecommitdiff
path: root/programs/sub-suite/subeditor.s
diff options
context:
space:
mode:
Diffstat (limited to 'programs/sub-suite/subeditor.s')
-rw-r--r--programs/sub-suite/subeditor.s604
1 files changed, 263 insertions, 341 deletions
diff --git a/programs/sub-suite/subeditor.s b/programs/sub-suite/subeditor.s
index 387b5db..f6b647f 100644
--- a/programs/sub-suite/subeditor.s
+++ b/programs/sub-suite/subeditor.s
@@ -11,8 +11,8 @@ reset:
ldy #0 ; Reset Y.
tyx ; Reset X.
jsr init_heap ; Initialize the heap.
- tax ; Set the stack pointer to the end of RAM.
- txs ;
+ mov sp, a ; Set the stack pointer to the end of RAM.
+; txs ;
sub.d #STKSIZE ; Subtract the stack size, from the end of RAM.
sta.q heapend ; Save the end of the heap.
and #0 ; Reset A.
@@ -28,45 +28,39 @@ reset:
init_heap:
lea HEAPORG ; Get the heap's starting point.
ste.q heapptr ;
+ mov d, e ;
jsr findramend ; Find the end of the heap.
rts ; End of init_heap.
init_tables:
- and #0 ; Reset A.
- lda.w #SCRSIZE ; Allocate SCRSIZE bytes of RAM for the screen buffer.
+ lea d, SCRSIZE ; Allocate SCRSIZE bytes of RAM for the screen buffer.
jsr malloc ;
sta.q buffer ;
- and #0 ; Reset A.
- lda.w #CMDSIZE ; Allocate CMDSIZE bytes of RAM for the command buffer.
+ lea d, CMDSIZE ; Allocate CMDSIZE bytes of RAM for the command buffer.
jsr malloc ;
sta.q cmd_buf ;
- and #0 ; Reset A.
- lda.w #LWSIZE ; Allocate LWSIZE bytes of RAM for the linewrap table.
+ lea d, LWSIZE ; Allocate LWSIZE bytes of RAM for the linewrap table.
jsr malloc ;
sta.q bitabl ;
- and #0 ; Reset A.
rts ; End of init_tables.
;test_free:
; inc step ;
-; lda.q bitabl ;
+; mov.q d, bitabl ;
; jsr free ;
-; lda.q buffer ;
+; mov.q d, buffer ;
; jsr free ;
-; and #0 ; Reset A.
-; lda.w #LWSIZE ; Allocate LWSIZE bytes of RAM for the linewrap table.
+; lea d, LWSIZE ; Allocate LWSIZE bytes of RAM for the linewrap table.
; jsr malloc ;
; sta.q bitabl ;
-; lda.q cmd_buf ;
+; mov.q d, cmd_buf;
; jsr free ;
-; and #0 ; Reset A.
-; lda.w #SCRSIZE ; Allocate SCRSIZE bytes of RAM for the screen buffer.
+; lea d, SCRSIZE ; Allocate SCRSIZE bytes of RAM for the screen buffer.
; jsr malloc ;
; sta.q buffer ;
-; and #0 ; Reset A.
-; lda.w #CMDSIZE ; Allocate CMDSIZE bytes of RAM for the command buffer.
+; lea d, CMDSIZE ; Allocate CMDSIZE bytes of RAM for the command buffer.
; jsr malloc ;
; sta.q cmd_buf ;
; and #0 ; Reset A.
@@ -74,33 +68,38 @@ init_tables:
clr_arr:
- stz.q (e) ; Clear eight bytes.
- ade #8 ; Increment the pointer by 8.
- stz.q (e) ; Clear eight bytes.
- ade #8 ; Increment the pointer by 8.
- sub #$10 ; Subtract 16 from the size.
+ pha.q ; Preserve A.
+ and #0 ; Reset A.
+@loop:
+ mov.q (d), a ; Clear 16 bytes.
+ mov.q (d+8), a ;
+ add d, #$10 ; Increment the pointer by 16.
+ sub s, #$10 ; Subtract 16 from the size.
bcc @end ; We've reached the end of the array, so we're done.
beq @end ;
- bra clr_arr ; Keep looping.
+ bra @loop ; Keep looping.
@end:
+ pla.q ; Restore A.
rts ; End of clr_arr.
pnt_strt:
- lea ed_name ; Print the name of the editor.
+ lea d, ed_name ; Print the name of the editor.
jsr print_str ;
- lea ver_str ; Print the version text.
+ lea d, ver_str ; Print the version text.
jsr print_str ;
- lea ed_ver ; Print the version number.
+ lea d, ed_ver ; Print the version number.
jsr print_str ;
- lea ed_sver ; Print the sub version number.
+ lea d, ed_sver ; Print the sub version number.
jsr print_str ;
+ lea d, '\n' ; Print a newline.
lda #'\n' ; Print a newline.
jsr print_char ;
- lea made ; Print the "Created by" text.
+ lea d, made ; Print the "Created by" text.
jsr print_str ;
- lea author ; Print the name of the author.
+ lea d, author ; Print the name of the author.
jsr print_str ;
+ lea d, '\n' ; Print a newline.
lda #'\n' ; Print a newline.
jsr print_char ;
rts ; End of pnt_strt.
@@ -109,8 +108,8 @@ pnt_strt:
clr_cmd:
and #0 ; Reset A.
tay ; Reset Y.
- lda.w #CMDSIZE ; Set the clear count to CMDSIZE.
- lea (cmd_buf) ; Set the array to be cleared to the command buffer.
+ lea s, CMDSIZE ; Set the clear count to CMDSIZE.
+ lea d, (cmd_buf); Set the array to be cleared to the command buffer.
jsr clr_arr ; Clear the command buffer.
rts ; End of clr_cmd.
@@ -149,140 +148,68 @@ getchar:
print_str:
+ pha.q ; Preserve A.
+ phb.q ; Preserve B.
and #0 ; Reset A.
tba ; Reset B.
@loop:
- ldb #1 ; Enable replace mode.
- stb regb ;
- and #0 ; No, reset the accumulator.
- ldb (e) ; Are we at the end of the string?
+ mov regb, #1 ; Enable replace mode.
+ and #0 ; Reset A.
+ mov b, (d) ; Are we at the end of the string?
beq @end ; Yes, so we're done.
jsr update_ptr ; No, so get the screen buffer index.
tay ; Save it in Y.
tba ; Get the character back.
- ine ; Increment the string pointer.
+ inc d ; Increment the string pointer.
jsr print_char ; Print the character.
bra @loop ; Keep looping.
@end:
stz regb ; Enable insert mode.
and #0 ; Reset A.
tab ; Reset B.
+ pla.q ; Restore A.
+ plb.q ; Restore B.
rts ; End of print_str.
-;print_str:
-; ldx #0 ; Reset X.
-; sta.q end ; Save the parameter.
-;@reset:
-; lda.q end ; Get the parameter.
-; ldb #0 ; Clear the B register.
-; jsr set_ptr ; Set the first pointer to the parameter.
-; tba ; Clear the Accumulator.
-;@loop:
-; ldb #1 ; Enable replace mode.
-; stb regb ;
-; lda.q ptr ; Get the first pointer.
-; cmp.q end ; Did the pointer change?
-; bne @reset ; Yes, so set it back.
-; and #0 ; No, reset the accumulator.
-; txy ; Copy the string index into Y.
-; ldb (ptr), y ; Are we at the end of the string?
-; beq @end ; Yes, so we're done.
-; jsr update_ptr ; No, so get the screen buffer index.
-; tay ; Save it in Y.
-; tba ; Get the character back.
-; inx ; Increment the string index.
-; phx ; Preserve the string index.
-; jsr print_char ; Print the character.
-; plx ; Get the string index back.
-; bra @loop ; Keep looping.
-;@end:
-; stz regb ; Enable insert mode.
-; and #0 ; Reset A.
-; tab ; Reset B.
-; rts ; End of print_str.
-
getbit:
- clc ; Clear the carry flag.
- lda scr_str ; Has the screen been scrolled?
- bne getbt0 ; Yes, so add the screen offset to the current line number.
- ldx scr_row ; No, so just use the current line number.
- bra getbt1 ; Start getting the bit.
-getbt0:
- lda scr_row ; Get the current line number.
- adc scr_str ; Add the screen offset to it.
- tax ; Use it as the wrap index.
-getbt1:
- pha ; Save the parameter.
- ldb #1 ; Make sure that set_ptr sets the second pointer.
- lda.q bitabl ; Set the second pointer to the linewrap table.
- jsr set_ptr ;
- lsr #$10 ; Clear the Accumulator.
- pla ; Get the return byte back.
- jsr bitpos ; Get the bit, and byte position.
- phy.w ; Save the screen index.
- txy ; Get the byte position.
- ldb (ptr2), y ; Get one byte of the wrap table.
- ply.w ; Get the screen index back.
- and b ; Mask out the bit of the current line number.
- cmp #1 ; Set the carry flag, if true.
- bra bitout ; We are done.
+ des ; Create the stack frame.
+ add d, s ; Add the row position with the row offset position.
+ lea s, (sp+1) ; Get the address of the bitmask.
+ jsr bitpos ; Get the bit, and byte position.
+ ins ; Cleanup the stack frame.
+ mov a, (bitabl)+a ; Get the bit of the row position.
+ and a, (s) ; Return the masked bit.
+ rts ; End of getbit.
+
clrbit:
- pha ; Save the parameter.
- ldb #1 ; Make sure that set_ptr sets the second pointer.
- lda.q bitabl ; Set the second pointer to the linewrap table.
- jsr set_ptr ;
- and #0 ; Clear the Accumulator.
- pla ; Get the return byte back.
- jsr bitpos ; Get the bit, and byte position.
- xor #$FF ; Invert the bitmask.
- phy.w ; Save the screen index.
- txy ; Get the byte position.
- ldb (ptr2), y ; Get one byte of the wrap table.
- and b ; Clear the bit of the current line number.
-bitsav:
- sta (ptr2), y ; Update the wrap table.
- ply.w ; Get the screen index back.
-bitout:
- ldx bitmask ; Return the bitmask.
- rts ; We are done.
+ pha.q ; Preserve A.
+ des ; Create the stack frame.
+ lea s, (sp+1) ; Get the address of the bitmask.
+ jsr bitpos ; Get the bit, and byte position.
+ ins ; Cleanup the stack frame.
+ not (s) ; Invert the bitmask.
+ and (bitabl)+a, (s) ; Set the bit of the current row number to zero.
+ pla.q ; Restore A.
+ rts ; End of clrbit.
setbit:
- pha ; Save the parameter.
- ldb #1 ; Make sure that set_ptr sets the second pointer.
- lda.q bitabl ; Set the second pointer to the linewrap table.
- jsr set_ptr ;
- and #0 ; Clear the Accumulator.
- pla ; Get the return byte back.
- jsr bitpos ; Get the bit, and byte position.
- phy.w ; Save the screen index.
- txy ; Get the byte position.
- ldb (ptr2), y ; Get one byte of the wrap table.
- ora b ; Set the bit of the current line number.
- bra bitsav ; Save the bit.
+ pha.q ; Preserve A.
+ des ; Create the stack frame.
+ lea s, (sp+1) ; Get the address of the bitmask.
+ jsr bitpos ; Get the bit, and byte position.
+ ins ; Cleanup the stack frame.
+ or (bitabl)+a, (s) ; Set the bit of the current row number to one.
+ pla.q ; Restore A.
+ rts ; End of setbit.
bitpos:
- pha ; Save the parameter.
- ldb #0 ; Make sure that set_ptr sets the first pointer.
- lda.w #bits ; Set the first pointer to the bitmask table.
- jsr set_ptr ;
- and #0 ; Clear the Accumulator.
- pla ; Get the parameter back.
- stx bitmask ; Make the line number the bitmask.
- txa ; Copy it to the Accumulator.
- and #7 ; Get the bit position.
- phy.w ; Save the cursor index.
- tay ; Use the bit position as the index.
- tax ; Copy it into X.
- lda (ptr), y ; Get the bitmask.
- ply.w ; Get back the cursor index.
- pha ; Save the bitmask.
- lda bitmask ; Get the line number.
- lsr #3 ; Get the byte position.
- tax ; Copy it into X.
- pla ; Get back the bitmask.
- rts ; End of bitpos.
+ mov a, d ; Preserve the row number.
+ and d, #7 ; Get the bit position.
+ lsr #3 ; Return the byte position.
+ mov (s), (d+bits) ; Place the bitmask into the mask argument.
+ rts ; End of bitpos.
handle_char:
@@ -328,7 +255,10 @@ handle_char:
cmd_cpy:
lda scr_row ; Get the row position.
sta scr_trow ; Save it for later.
- jsr findend ; Find the end of the line.
+ lea d, (buffer) ; Get the screen buffer.
+ mov s, y ; Get the cursor index.
+ jsr find_end ; Find the end of the line.
+ div #maxcol+1 ; Get the ending line.
ldb scr_str ; Has the screen been scrolled?
beq @start ; No, so don't subtract the screen's starting point from the line number.
@offset:
@@ -388,48 +318,45 @@ cmd_cpy:
findst:
- lda #0 ; Reset A.
+; lda #0 ; Reset A.
+; xor d, d ; Reset D.
+; xor s, s ; Reset S.
+ mov d, scr_row ; Get the row position.
+ mov s, scr_str ; Get the row offset.
@loop:
- pha ; Save the current line number.
+; pha ; Save the current line number.
jsr getbit ; Is this the start of the line?
- pla ; Get the current line number back.
- bcc @end ; Yes, so we're done.
- inc ; No, so check the next physical line.
+; pla ; Get the current line number back.
+ beq @end ; Yes, so we're done.
+ inc d ; No, so check the next physical line.
dec scr_row ; Are we at the top of the screen?
bpo @loop ; No, so keep looping.
- dec ; Yes, so move back one line.
+ dec d ; Yes, so move back one line.
inc scr_row ; Put the row postiion back to zero.
@end:
- cmp #0 ; Update all the flags.
+ cmp d, #0 ; Update all the flags.
rts ; End of findst.
-fndend:
- phb ; Save the contents of the B register.
- ldb #0 ; Make sure that set_ptr sets the first pointer.
- lda.q buffer ; Set the first pointer to the start of the screen buffer.
- jsr set_ptr ;
- tba ; Set the Accumulator to zero.
- plb ; Restore the contents of the B register.
- phy.w ;
+find_end:
+ mov a, s ; Set the loop counter.
@loop:
- lda (ptr), y ; Are we at the end of the string?
- beq @end ; Yes, so we're done.
- iny ; No, so increment the cursor index.
- bra @loop ; Keep looping.
+ inc ; Increment the loop counter.
+ cmp (d+a-1), #0 ; Did we hit the null terminator?
+ bne @loop ; No, so keep looping.
@end:
- sty.w scr_ptr3 ;
- ply.w ;
- rts ; End of fndend.
-
-findend:
- jsr fndend ;
- lda.w scr_ptr3 ;
- div #maxcol+1 ;
- rts ;
+ rts ; End of find_end.
+
+
+get_endrow:
+ jsr find_end ; Find the end of the line.
+ div #maxcol+1 ; Get the ending row.
+ rts ; End of get_endrow
print_char:
+ phb.q ; Preserve B.
+ phx.q ; Preserve X.
phe.q ; Preserve E.
sta rega ; Preserve the character.
ldb #2 ; Make sure that set_ptr sets the third pointer.
@@ -441,15 +368,13 @@ print_char:
lda rega ; Get the character back.
jsr get_ctrlidx ; Get the control code jump table index.
lsl #1 ; Multiply the return value by two, to get the index.
- tax ;
- lea.w (ct_jtb, x); Get the address of the control code handler.
-; pha.q ;
-; ple.q ;
-; jsr set_ptr ; Set the second pointer to the control code handler.
+ lea.w e, (ct_jtb+a); Get the address of the control code handler.
deb ; Reset B.
tba ; Reset A.
jsr (e) ; Jump to the handler for that control code.
ple.q ; Restore E.
+ plx.q ; Restore X.
+ plb.q ; Restore B.
rts
printc:
lda #0 ; start trying to print a character.
@@ -458,18 +383,20 @@ printc:
beq @save ; Yes, so just print the character.
lda regb ; No, but was the flag set?
bne @save ; Yes, so don't shift the line.
- sty.w scr_ptr ; No, so save the cursor index for later.
- jsr fndend ; Find the end of the line.
+; sty.w scr_ptr ; No, so save the cursor index for later.
+; jsr fndend ; Find the end of the line.
bra @shift ; Start shifting the line right.
@update:
lda scr_col ; Save the current column position for later.
sta scr_tcol ;
@update1:
- jsr findend ; Find the end of the line.
- sta rege ; Use it for redrawing the line.
+ lea d, (buffer) ; Get the screen buffer.
+ mov s, y ; Get the cursor index.
+ jsr get_endrow ; Get the ending line.
+ mov d, a ;
+ mov s, scr_trow ; Get the current row position.
lda scr_trow ; Get the current row position.
@update2:
- sta regf ; Set the starting line, to the current row position.
jsr rdrw_ln ; Redraw the line.
lda scr_trow ; Get the real row position back.
sta scr_row ;
@@ -479,12 +406,15 @@ printc:
dec regd ;
bra @save1 ;
@shift:
- ldy.w scr_ptr3 ;
- inc scr_ptr3 ;
- tyx ;
- dey ;
- ldb #1 ;
- stb regd ;
+; ldy.w scr_ptr3 ;
+; inc scr_ptr3 ;
+; tyx ;
+; dey ;
+; ldb #1 ;
+; stb regd ;
+ lea d, (buffer) ; Get the screen buffer.
+ mov.w s, scr_ptr; Get the cursor index.
+ mov f, #1 ; Set the left flag to true.
jsr shftln ;
ldb #1 ;
stb regd ;
@@ -501,6 +431,7 @@ printc:
sta (ptr3), y ; store typed character into the input buffer.
@incr:
inc scr_col ; Increment the cursor's x coordinate.
+ inc.w scr_ptr ; Increment the screen index.
iny ;
@wrapped:
ldb #1 ;
@@ -536,13 +467,15 @@ printc:
@wrap1:
inc scr_row ;
@wrap2:
- phx.w ;
- clc ;
- lda scr_row ;
- adc scr_str ;
- tax ;
- jsr setbit ;
- plx.w ;
+; phx.w ;
+; clc ;
+; lda scr_row ;
+; adc scr_str ;
+; tax ;
+ mov d, scr_row ; Get the row position.
+ add d, scr_str ; Add the row offset to the row position.
+ jsr setbit ; Set the bit of that row.
+; plx.w ;
jsr update_pos ;
printc_end:
rts ;
@@ -573,11 +506,11 @@ clr_scr:
sta scr_end ;
stz scr_str ;
tay ;
- lda.w #LWSIZE ; Set the clear count to LWSIZE.
- lea (bitabl) ; Set the array to be cleared to the linewrap table.
+ lea s, LWSIZE ; Set the clear count to LWSIZE.
+ lea d, (bitabl) ; Set the array to be cleared to the linewrap table.
jsr clr_arr ; Clear the linewrap table.
- lda.w #SCRSIZE ; Set the clear count to SCRSIZE.
- lea (buffer) ; Set the array to be cleared to the screen buffer.
+ lea s, SCRSIZE ; Set the clear count to SCRSIZE.
+ lea d, (buffer) ; Set the array to be cleared to the screen buffer.
jsr clr_arr ; Clear the screen buffer.
; lda.w #CMDSIZE ; Set the clear count to CMDSIZE.
; lea (cmd_buf) ; Set the array to be cleared to the command buffer.
@@ -613,8 +546,10 @@ bs:
beq @wrap ; Yes, so check for a wrapped line.
bra back ; No, so add the backspace to the buffer.
@wrap:
+ mov d, scr_row ; Get the row position.
+ mov s, scr_str ; Get the row offset.
jsr getbit ; Is this line, a wrapped line?
- bcs @wrap1 ; Yes, so check if the cursor is at the top.
+ bne @wrap1 ; Yes, so check if the cursor is at the top.
rts ; No, so we're done.
@wrap1:
lda scr_row ; Are we at the top of the screen?
@@ -644,7 +579,9 @@ back:
stb regf ;
lda scr_row ; Save the current row position for later.
sta scr_trow ;
- jsr findend ; Find the end of the line.
+ lea d, (buffer) ; Get the screen buffer.
+ mov s, y ; Get the cursor index.
+ jsr get_endrow ; Get the ending line.
sta scr_row ; Set our row position to the end of the line.
@find_st:
jsr findst ; Does this line take up more than one real line?
@@ -660,14 +597,20 @@ back:
iny ; Increment cursor index.
ldb #0 ; Set shifting direction to left.
stb regd ;
+ lea d, (buffer) ; Get the screen buffer.
+ mov s, y ; Get the cursor index.
+ mov f, #0 ; Set the left flag to false.
jsr shftln ; Shift line back by one character.
lda #$7F ; Print a backspace to the screen.
sta scr ;
lda rege ; Are we updating more than one line?
beq @load ; No, so skip to the next step.
@find_end:
- jsr findend ; Yes, so find the end of the line.
- sta rege ; Set the end parameter to it.
+ lea d, (buffer) ; Get the screen buffer.
+ mov s, y ; Get the cursor index.
+ jsr get_endrow ; Yes, so Get the ending line.
+ mov d, a ;
+ mov s, scr_trow ; Get the current row position.
lda scr_col ; Save the current column position for now.
sta scr_tcol ;
jsr rdrw_ln ; Start redrawing the line.
@@ -683,88 +626,73 @@ back:
lda (ptr3), y ; Are we at the end of the line?
beq @shift ; Yes, so skip redrawing.
lda scr_trow ; No, so set the line to start redrawing, to the line that the cursor is on.
- sta regf ;
inc rege ; Set the redraw flag to true.
bra @shift ; Start shifting the line back.
shftln:
- ldb regd ; Is the flag not set?
- beq @dec_loop ; Yes, so shift, and decrement.
- ldb #0 ; Clear the B register.
- bra @inc_loop ; No, so shift, and increment.
+ pha.q ; Preserve A.
+ phb.q ; Preserve B.
+ and f, f ; Is the left flag not set?
+ beq @right ; Yes, so shift the line to the right.
+; txa ; Get the end of the line.
+ jsr find_end ; Find the end of the line.
+ dec ; Decrement the source position.
+ bra @left ; No, so shift the line to the left.
@minus:
- ldy.w zero ; Set the source poition to 0.
- stb (ptr3), y ; Clear the character that is in the source.
- bra @end ; We are done.
-@inc_loop:
- sty.w scr_ptr2 ; Save the source position for later.
- ldy.w scr_ptr ; Get the previous cursor index.
- cpy.w scr_ptr2 ; Is the source position, at, or below the cursor index?
- beq @inc_loop1 ; Yes, so keep looping.
- bcs @end ; No, so we're done.
-@inc_loop1:
- ldy.w scr_ptr2 ; Get the source position.
- lda (ptr3), y ; Get the character from the source position.
- phy.w ; Save the source position for later.
- txy ; Set our position to the destination.
- sta (ptr3), y ; Place the character from the source position, to the destination position.
- ply.w ; Set our position back to the source.
- stb (ptr3), y ; Clear the character that is in the source.
- bng @minus ; The source underflowed, so set it back to zero,
- dey ; Decrement the source position.
- dex ; Decrement the destination position.
- bra @inc_loop ; Keep looping.
-@dec_loop:
- stx.w scr_ptr2 ; Save the destination position for later.
- lda (ptr3), y ; Is the character at the source position, a null terminator?
- beq @end3 ; Yes, so we're done.
- phy.w ; No, so save the source position for later.
- txy ; Set our position to the destination.
- sta (ptr3), y ; Place the character from the source position, to the destination position.
- inx ; Increment the destination position.
- ply.w ; Set our position back to the source.
- stb (ptr3), y ; Clear the character that is in the source.
- iny ; Increment the source position.
- bra @dec_loop ; Keep looping.
+ and #0 ; Set the source poition to 0.
+ mov (d), a ; Clear the character that is in the source.
+ bra @lend ; We are done.
+@left:
+ cmp s, a ; Is the cursor index, at, or below the source position?
+ beq @left1 ; Yes, so keep looping.
+ bcs @lend ; No, so we're done.
+@left1:
+ cmp #0 ; Is the source position less than 0?
+ bcc @minus ; Yes, so set the source position to zero.
+ mov (d+a+1), (d+a) ; No, so shift the current character to the left by one.
+ mov (d+a), #0 ; Clear the current character.
+ dec ; Decrement the source position.
+ bra @left ; Keep looping.
+@right:
+ cmp (d+s), #0 ; Is this character a null terminator?
+ beq @rend ; Yes, so we're done.
+ mov (d+s-1), (d+s) ; No, so shift the current character to the right by one.
+ mov (d+s), #0 ; Clear the current character.
+ inc s ; Increment the source position.
+ bra @right ; Keep looping.
@wrap:
- tax ; Use the ending line as a parameter for setbit.
- jsr setbit ; Set the wrap bit of the ending line.
- bra @end5 ; We are done.
+ mov d, a ; Get the ending line.
+ jsr setbit ; Set the wrap bit of the ending line.
+ bra @end ; We are done.
@wrap1:
- tax ; Use the ending line as a parameter for clrbit.
- jsr clrbit ; Clear the wrap bit of the ending line.
- bra @end5 ; We are done.
+ mov d, a ; Get the ending line.
+ jsr clrbit ; Clear the wrap bit of the ending line.
+ bra @end ; We are done.
+@lend:
+ lea s, (a+2) ; Add 2 to the source position.
+ jsr find_end ; Find the end of the line.
+ dec ; Decrement the end of line position.
+ div #maxcol+1 ; Get the ending line.
+@lend2:
+ cmp scr_row ; Is the ending line greater than the starting line?
+ beq @end ; No, so we're done.
+ bcs @wrap ; Yes, so set the wrap bit.
+ bra @end ; No, so we're done.
+@rend:
+ jsr find_end ; Find the end of the line.
+ dec ; Decrement the end of line position.
+ div #maxcol+1 ; Get the ending line.
+ cpb #0 ; Is the remainder zero?
+ bne @end ; No, so we're done.
+@rend2:
+ cmp scr_row ; Is the ending line greater than the starting line?
+ beq @end ; No, so we're done.
+ bcs @wrap1 ; Yes, so clear the wrap bit.
@end:
- lda (ptr3), y ; Is this character a null terminator?
- bne @end1 ; No, so just find the end of the line.
- lda #$20 ; Yes, so convert it to a space for now.
- sta (ptr3), y ;
-@end1:
- jsr findend ; Find the ending line.
- sta regd ; Save ending line for later.
- lda (ptr3), y ; Is this character a space?
- cmp #$20 ;
- bne @end5 ; No, so skip the conversion.
- lda #0 ; Yes, so convert it back to zero.
- sta (ptr3), y ;
-@end2:
- lda regd ; Get the ending line.
- cmp scr_row ; Is the ending line greater than the starting line?
- beq @end5 ; No, so we're done.
- bcs @wrap ; Yes, so set the wrap bit.
- bra @end5 ; No, so we're done.
-@end3:
- jsr findend ; Find the ending line.
- cpb #0 ; Is the remainder zero?
- beq @end4 ; Yes, so check if the ending line is greater than the starting line.
- bra @end5 ; No, so we're done.
-@end4:
- cmp scr_row ; Is the ending line greater than the starting line?
- beq @end5 ; No, so we're done.
- bcs @wrap1 ; Yes, so clear the wrap bit.
-@end5:
- rts ; End of shftln.
+ plb.q ; Restore B.
+ pla.q ; Restore A.
+ rts ; End of shftln.
esc:
@@ -883,8 +811,10 @@ isright:
bra @right ; No, so move the cursor right, like normal.
@wrap:
inc scr_row ; Move down a row.
+ mov d, scr_row ; Get the row position.
+ mov s, scr_str ; Get the row offset.
jsr getbit ; Is the current line, a wrapped line?
- bcs @incr ; Yes, so leave the cursor where it is.
+ bne @incr ; Yes, so leave the cursor where it is.
dec scr_row ; No, so move the cursor back up a row.
bra @end2 ; We are done.
@scroll:
@@ -927,8 +857,10 @@ isleft:
beq @left ; Yes, so move the cursor left.
bra @end1 ; No, so we're done.
@wrap:
+ mov d, scr_row ; Get the row position.
+ mov s, scr_str ; Get the row offset.
jsr getbit ; Is the current line, a wrapped line?
- bcs @decr ; Yes, so wrap back up a line.
+ bne @decr ; Yes, so wrap back up a line.
bra @end1 ; No, so we're done.
@decr:
lda scr_row ; Is the cursor at the top of the screen?
@@ -999,12 +931,11 @@ isshftdown:
update_ptr:
- clc ; Clear the carry flag.
lda scr_row ; Add the cursor's line number,
- adc scr_str ; with the starting line number to get the absolute line number.
+ add scr_str ; with the starting line number to get the absolute line number.
mul #maxcol+1 ; Multiply the line number by the screen's max column count, plus 1.
- clc ; Clear the carry flag.
- adc scr_col ; Add the cursor's column number to get the screen index.
+ add scr_col ; Add the cursor's column number to get the screen index.
+ sta.w scr_ptr ; Save the screen index.
; cmp.w #$2000 ; Is the index greater than, or equal to the end of the screen buffer?
; bcc @end ; No, so we're done.
;@wrap:
@@ -1021,22 +952,21 @@ update_ptr:
update_pos:
+ phb.q ; Preserve B.
+ and #0 ; Reset A.
+ tab ; Reset B.
ldb #1 ; Set the F pseudo register to one, to fix some bugs.
stb regf ;
jsr update_ptr ; Update the screen buffer index.
tay ; Place the index into the Y register.
tba ; Reset A.
- lda #$1B ; Print an escape character
- sta scr ; to the screen.
- lda #'[' ; Print '['
- sta scr ; to the screen, and start the escape sequence.
+ mov scr, #$1B ; Print an escape character to the screen.
+ mov scr, #'[' ; Print '[' to the screen, and start the escape sequence.
jsr getrow ; Start printing the row number to the screen.
- lda #';' ; Print ';'
- sta scr ; to the screen.
+ mov scr, #';' ; Print ';' to the screen.
jsr getcol ; Start printing the column number to the screen.
- lda #'H' ; Print 'H'
- sta scr ; to the screen.
- ;inc step ;
+ mov scr, #'H' ; Print 'H' to the screen.
+ plb.q ; Restore B.
rts ; End of update_pos.
getrow:
@@ -1068,6 +998,7 @@ scrl_down:
lda wrapped ; Was the wrapped flag set?
beq @save ; Yes, so save the cursor position.
@redraw:
+ lea d, (buffer) ; Get the screen buffer.
jsr rdrw_row ; No, so redraw this row.
lda wrapped ; Was the wrapped flag set?
beq @load ; Yes, so load the previous cursor position back.
@@ -1103,6 +1034,7 @@ scrl_up:
pha ;
lda #0 ;
sta scr_row ;
+ lea d, (buffer) ; Get the screen buffer.
jsr rdrw_row ;
pla ;
sta scr_col ;
@@ -1112,64 +1044,54 @@ scrl_up:
@end:
rts ;
+
rdrw_row:
- lda #0 ;
- sta scr_col ;
- jsr update_pos ;
+ pha.q ; Preserve A.
+ phb.q ; Preserve B.
+ stz scr_col ; Reset the column position.
+ jsr update_pos ; Update the cursor position.
+ xor b, b ; Reset B.
+ tya ; Get the screen index.
+ tab ;
+ add b, #maxcol+1; Get the end of the row plus one.
@loop:
- lda (ptr3), y ;
- beq @incr ;
- sta scr ;
-@incr:
- inc scr_col ;
- lda (ptr3), y ;
- beq @skip ;
-@incr1:
- iny ;
-@incr2:
- lda scr_col ;
- cmp #maxcol+1 ;
- bcs @end ;
- bra @loop ;
-@skip:
- lda #' ' ;
- sta scr ; to the screen.
- bra @incr1 ;
+ cmp (d+a), #0 ; Is this a null terminator?
+ mne scr, (d+a) ; No, so print the character.
+ meq scr, #' ' ; Yes, so print a space.
+ inc ; Increment the screen index.
+ cmp b ; Is the column position at, or above the maximum column count?
+ bcc @loop ; No, so keep looping.
@end:
- lda #0 ;
- sta scr_col ;
- jsr update_pos ;
-@end1:
- rts ;
+ stz scr_col ; Reset the column position.
+ jsr update_pos ; Update the cursor position.
+ plb.q ; Restore B.
+ pla.q ; Restore A.
+ rts ; End of rdrw_row.
+
rdrw_ln:
- lda scr_row ;
- pha ;
- lda regf ;
- sta scr_row ;
- lda scr_col ;
- pha ;
- jsr update_pos ;
+ pha.q ; Preserve A.
+ psh scr_row ; Preserve the row position.
+ psh scr_col ; Preserve the column position.
+ mov scr_row, s ; Set the row position to the starting position.
+ jsr update_pos ; Update the cursor position.
+ mov a, d ; Get the ending position.
+ lea d, (buffer) ; Get the address of the screen buffer.
@loop:
- lda scr_row ;
- cmp rege ;
- beq @loop1 ;
- bcs @end ;
-@loop1:
- jsr rdrw_row ;
+ cmp scr_row, a ; Is the row position at, or below the ending position?
+ beq @redraw ; Yes, so redraw the row.
+ bcs @end ; No, so we're done.
+@redraw:
+ jsr rdrw_row ; Redraw the line.
@incr:
- inc scr_row ;
- bra @loop ;
+ inc scr_row ; Increment the row position.
+ bra @loop ; Keep looping
@end:
- pla ;
- sta scr_col ;
- pla ;
- sta scr_row ;
- jsr update_pos ;
- lda #0 ;
- sta rege ;
- sta regf ;
- rts ;
+ pul scr_col ; Restore the column position.
+ pul scr_row ; Restore the row position.
+ jsr update_pos ; Update the cursor position.
+ pla.q ; Restore A.
+ rts ; End of rdrw_ln.
set_ptr: