From 59dc46ca8fe1eb6f98abb98fe8579aeaedd2ff15 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Thu, 2 Apr 2020 19:04:12 -0400 Subject: Made the emulator less bloated, and faster. --- programs/c-ports/subasm.c | 24 +- programs/c-ports/subeditor.c | 205 ++++++- programs/c-ports/subeditor.h | 19 +- programs/subeditor.s | 1266 ++++++++++++++++++++++-------------------- 4 files changed, 869 insertions(+), 645 deletions(-) (limited to 'programs') diff --git a/programs/c-ports/subasm.c b/programs/c-ports/subasm.c index 89d1507..73bb74c 100644 --- a/programs/c-ports/subasm.c +++ b/programs/c-ports/subasm.c @@ -1,18 +1,7 @@ #include "subeditor.h" -struct line { - uint8_t dir; - uint8_t mne; - uint8_t am; - uint8_t opbase; - uint16_t com; - uint16_t label; - uint64_t op; -}; -char *label[0x1000]; + uint64_t label_addr[0x1000]; -/*char *comment[0x1000];*/ -/*char *string[0x1000];*/ enum dir { DIR_ORG, @@ -52,9 +41,8 @@ enum base { }; -char lexeme[0x100]; +char lexeme[0x200]; uint8_t lex_type; -struct line tokline[0x1000]; uint16_t linenum = 10; static const char *mne_t[90] = { @@ -258,7 +246,7 @@ uint8_t lex(char *str) { uint16_t j = 0; lex_type = 0xFF; uint8_t k = 0; - int line = 40; + int line = 56; int16_t ln = -1; int y, x; char lnum[6]; @@ -333,12 +321,12 @@ uint8_t lex(char *str) { case ';': i++; while (str[i] != '\0') { - lexeme[j++] = str[i++]; + lexeme[j] = str[i]; /*comment[linenum][j] = str[i];*/ - /*j++, i++;*/ + j++, i++; } lexeme[j] = '\0'; - /*comment[linenum][j] = '\0';*/ + comment[linenum][j] = '\0'; lex_type = TOK_COMMENT; break; case '#': diff --git a/programs/c-ports/subeditor.c b/programs/c-ports/subeditor.c index 76ee544..44ca288 100644 --- a/programs/c-ports/subeditor.c +++ b/programs/c-ports/subeditor.c @@ -45,6 +45,7 @@ uint8_t scr_trow = 0; uint8_t scr_tcol = 0; uint16_t scr_ptr = 0; uint16_t scr_ptr2 = 0; +uint16_t scr_ptr3 = 0; uint8_t byte = 0; uint8_t mask = 0; @@ -141,6 +142,62 @@ void clr_cbuf() { } } +#define dir(a) tokline[a].dir +#define mne(a) tokline[a].mne +#define amo(a) tokline[a].am +#define opb(a) tokline[a].opbase +#define com(a) tokline[a].com +#define lab(a) tokline[a].label +#define opc(a) tokline[a].op + +#define tok(a) { \ + dir(a) = 0xFF; \ + mne(a) = 0xFF; \ + amo(a) = 0xFF; \ + opb(a) = 0xFF; \ + com(a) = 0xFFFF; \ + lab(a) = 0xFFFF; \ + opc(a) = 0xFF; \ +} +void clr_tokline() { + uint16_t i = 0; + for (; i < 0x2000;) { + tok(i+0x00); + tok(i+0x01); + tok(i+0x02); + tok(i+0x03); + tok(i+0x04); + tok(i+0x05); + tok(i+0x06); + tok(i+0x07); + tok(i+0x08); + tok(i+0x09); + tok(i+0x0A); + tok(i+0x0B); + tok(i+0x0C); + tok(i+0x0D); + tok(i+0x0E); + tok(i+0x0F); + tok(i+0x10); + tok(i+0x11); + tok(i+0x12); + tok(i+0x13); + tok(i+0x14); + tok(i+0x15); + tok(i+0x16); + tok(i+0x17); + tok(i+0x18); + tok(i+0x19); + tok(i+0x1A); + tok(i+0x1B); + tok(i+0x1C); + tok(i+0x1D); + tok(i+0x1E); + tok(i+0x1F); + i+=0x20; + } +} + void update_pos() { scr_ptr = (scr_row+scr_str)*80; scr_ptr += scr_col; @@ -163,12 +220,26 @@ void rdrw_row() { } scr_col++; if (!buffer[ptr+i]) { - update_pos(); + #if !debug + waddch(scr, ' '); + #endif } } scr_col = 0; } +void rdrw_ln(uint8_t start, uint8_t end) { + uint8_t tmp_row = scr_row; + uint8_t tmp_col = scr_col; + scr_row = start; + for (; scr_row <= end; ) { + rdrw_row(); + ++scr_row; + } + scr_row = tmp_row; + scr_col = tmp_col; +} + void scrl_down() { scr_str++; scr_end++; @@ -201,9 +272,6 @@ void bitpos(uint8_t row) { bit = row & 7; mask = bits[bit]; byte = bitmask >> 3; - #if debug - /*mvwprintw(scr, 2, 0, "bit: $%02X, row: $%02X, byte: $%02X, mask: $%02X, bitmask: $%02X\r", bit, row, byte, mask, bitmask);*/ - #endif } void clrbit (uint8_t row) { @@ -231,28 +299,68 @@ uint8_t getbit() { return (mask & bitabl[byte]); } -void findst() { +uint8_t findst() { + uint8_t line_count = 0; while (getbit()) { + line_count++; scr_row--; if ((int8_t)scr_row < 0) { + line_count--; scr_row++; + break; } } + return line_count; } +void fndend() { + uint16_t i = scr_ptr; + for (; buffer[i] != '\0'; i++); + scr_ptr3 = i; +} + +void findend() { + fndend(); + c = (uint16_t)(scr_ptr3/80); +} + + void shftln(uint16_t src, uint16_t dst, uint8_t flag) { if (!flag) { while (buffer[src] != '\0') { buffer[dst++] = buffer[src]; buffer[src++] = '\0'; } + scr_ptr2 = scr_ptr; + scr_ptr = src; + findend(); + scr_ptr = scr_ptr2; + if ((scr_ptr3 % 80 == 0) && (c > scr_row)) { + clrbit(c); + } } else { while (scr_ptr <= src) { - mvwprintw(scr, 2, 0, "buffer[0x%04X]: $%02X, buffer[0x%04X]: $%02X, src: $%04X, dst: $%04X, scr_ptr: $%04X\r", src, buffer[src], dst, buffer[dst], src, dst, scr_ptr); - wrefresh(scr); + if ((int16_t) src < 0) { + src = 0; + buffer[src] = '\0'; + break; + } buffer[dst--] = buffer[src]; buffer[src--] = '\0'; } + if (buffer[src+1] == '\0') { + buffer[src+1] = ' '; + } + scr_ptr2 = scr_ptr; + scr_ptr = src; + findend(); + scr_ptr = scr_ptr2; + if (buffer[src+1] == ' ') { + buffer[src+1] = '\0'; + } + if (c > scr_row) { + setbit(c); + } } } @@ -262,6 +370,8 @@ void print_char(char ch) { uint8_t is_esc = 0; uint8_t done = 0; uint16_t i = 0; + uint16_t x = 0; + uint16_t y = 0; a = ch; switch (ch) { case 0x1B: @@ -387,6 +497,7 @@ void print_char(char ch) { scr_str = 0; clr_bitabl(); clr_buf(); + clr_tokline(); clr_cbuf(); scr_row = 0; scr_col = 0; @@ -409,7 +520,6 @@ void print_char(char ch) { break; } } - clrbit(scr_row+scr_str); scr_row--; scr_col = 80; update_pos(); @@ -417,23 +527,52 @@ void print_char(char ch) { break; } } - scr_col--; - update_pos(); - buffer[scr_ptr] = 0; + e = 0; + scr_trow = scr_row; + findend(); + scr_row = c; + e = findst(); + buffer[--scr_ptr] = 0; shftln(scr_ptr+1, scr_ptr, 0); #if !debug - wdelch(scr); + int y, x; + getyx(scr, y, x); + if (x > 0) { + wmove(scr, y, x-1); + } + wdelch(scr); #endif + if (e) { + findend(); + scr_tcol = scr_col; + rdrw_ln(scr_row, c); + scr_col = scr_tcol; + } + scr_row = scr_trow; + scr_col--; + update_pos(); break; default: - if (buffer[scr_ptr] != '\0') { - for (i = scr_ptr; buffer[i] != '\0'; i++); - scr_ptr2 = scr_ptr-1; - shftln(i-1, i, 1); - i = 0; + d = 0; + if (buffer[scr_ptr] != '\0' && !b) { + fndend(); + scr_ptr3++; + shftln(scr_ptr3-2, scr_ptr3-1, 1); + scr_trow = scr_row; + scr_tcol = scr_col; + a = ch; + buffer[scr_ptr] = ch; + findend(); + scr_row = c; + findst(); + rdrw_ln(scr_row, c); + scr_row = scr_trow; + scr_col = scr_tcol; + update_pos(); + } else { + a = ch; + buffer[scr_ptr] = ch; } - a = ch; - buffer[scr_ptr] = ch; scr_col++; #if !debug waddch(scr, ch); @@ -457,19 +596,26 @@ void print_char(char ch) { uint8_t getkey(char ch) { e = 0; + b = 0; if (ch == '\n') { uint16_t i = 0; uint16_t ptr; + scr_trow = scr_row; + findend(); + scr_row = c; e = scr_row; - findst(scr_row); + findst(); ptr = (scr_row+scr_str)*80; for (;buffer[ptr+i] != '\0';i++) { cmd_buf[i] = buffer[ptr+i]; } + if (e <= 23) { + scr_row = e; + } else { + scr_row = 23; + } } - if (e) { - scr_row = e; - } + print_char(ch); wrefresh(scr); if (a == '\n') { @@ -481,9 +627,11 @@ uint8_t getkey(char ch) { void print_str(const char *str) { uint16_t i = 0; + b = 1; for (;str[i] != '\0'; i++) { print_char(str[i]); } + b = 0; } uint8_t dabbed() { @@ -525,6 +673,7 @@ int main() { cmd_buf = malloc(0x400); clr_bitabl(); clr_buf(); + clr_tokline(); uint8_t end = 0; uint8_t next = 1; char ch; @@ -541,6 +690,7 @@ int main() { #define maxline 24 #endif uint8_t ln = 0; + int row, col; mvwprintw(scr, ln++, 0, "scr_row: $%02X, scr_col: $%02X\r", scr_row, scr_col); mvwprintw(scr, ln++, 0, "scr_str: $%02X, scr_end: $%02X, scr_ptr: $%04X\r", scr_str, scr_end, scr_ptr); wmove(scr, ++ln, 0); @@ -550,6 +700,15 @@ int main() { for (uint16_t i = 0; i < maxline; i++) { for (uint16_t j = 0; j < 80; j++) { wprintw(scr, "%02x", buffer[(j+(i*80))]); + if (j == scr_col && i == scr_row) { + getyx(scr, row, col); + wmove(scr, ln++, 0); + wclrtoeol(scr); + wmove(scr, row+1, col-2); + wprintw(scr, "/\\\r"); + wmove(scr, row, col); + wrefresh(scr); + } } wprintw(scr, ", i: $%02X\r", i); wmove(scr, ln++, 0); diff --git a/programs/c-ports/subeditor.h b/programs/c-ports/subeditor.h index ddb8947..452dfb3 100644 --- a/programs/c-ports/subeditor.h +++ b/programs/c-ports/subeditor.h @@ -4,11 +4,12 @@ #include #include -#define debug 0 +#define debug 1 #define debug_cmd_buf 0 extern WINDOW *scr; +/* SuBEditor Stuff. */ extern char *buffer; extern char *cmd_buf; @@ -35,6 +36,22 @@ extern uint8_t scr_str; extern uint8_t scr_end; extern uint8_t wrapped; +/* SuBAsm Stuff. */ +struct line { + uint8_t dir; + uint8_t mne; + uint8_t am; + uint8_t opbase; + uint16_t com; + uint16_t label; + uint64_t op; +}; + +char *label[0x1000]; +char *comment[0x1000]; +char *str[0x1000]; +struct line tokline[0x1000]; + extern void print_str(const char *str); extern int str_cmp(const char *s0, const char *s1); extern uint8_t subasm(); diff --git a/programs/subeditor.s b/programs/subeditor.s index 1001f83..eaecab5 100644 --- a/programs/subeditor.s +++ b/programs/subeditor.s @@ -3,8 +3,8 @@ ; Writen in Sux assembly by ; mr b0nk 500 +.org $A000 ; String Literals/Constants. -.org $1000 tok: .byte "dab" msg: @@ -15,7 +15,6 @@ string2: .byte "You typed, " ; Linewrap bitmask table. -.org $1100 bits: .byte $80 .byte $40 @@ -73,11 +72,11 @@ bitabl: .qword $0 .qword $0 scr_str: -.byte $0 + .byte $0 scr_end: -.byte $0 + .byte $0 wrapped: -.byte $0 + .byte $0 ; Pointers ptr: @@ -92,471 +91,503 @@ ptr5: .qword $0 ptr6: .qword $0 +scr_ptr3: + .word $0 ; Main program .org $8000 reset: - cps - ldx.w #$FFFF - txs - ldy #0 - tyx - lda #23 - sta scr_end - lda.w #buffer - sta.q ptr5 - lda.w #cmd_buf - sta.q ptr6 - tya - sta scr_str - sta.q bitabl - sta.q bitabl+8 - jsl clr_buf - jmp start + cps ; Reset the processor status register. + ldx.w #$FFFF ; Reset the stack pointer. + txs ; + ldy #0 ; Reset the Y register. + tyx ; Reset the X register. + lda #23 ; Set the end of the screen back to 23. + 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. + jsl clr_buf ; Clear the screen buffer. + jmp start ; Goto the start of the main program. clr_buf: - phb #1 - ldb #0 + phb #1 ; Preserve whatever was in B. + ldb #0 ; Clear B. + lda.w #buffer+8 ; + sta.q ptr4 ; + tba ; clr_buf_st: - cpy.w #$1FFF - bcs clr_buf_end - sta.q (ptr5), y - tya - adc #8 - tay - tba - sta.q (ptr5), y - tya - adc #8 - tay - tba - sta.q (ptr5), y - tya - adc #8 - tay - tba - sta.q (ptr5), y - tya - adc #8 - tay - tba - jmp 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. + 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 ; + tya ; + adc #$10 ; + tay ; + tba ; + jmp clr_buf_st ; Keep looping. clr_buf_end: - ldy.w zero - plb #1 - rtl + ldy.w zero ; Set the index back to zero. + plb #1 ; Get whatever was in the B register, back. + rtl ; End of clr_buf. start: - lda #0 - sta $C000 - tax - phy #2 - tay - jsl clr_cbuf - ply #2 - ;lda #1 - ;sta $C010 - lda.w #string - jsl print_str - lda.w zero - jmp rset_a + lda #0 ; TODO: Update this for the Super VIA. + sta end ; + sta $C000 ; 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. + jsl clr_cbuf ; 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. + jmp read ; Start reading the keyboard. clr_cbuf: - phb #1 - ldb #0 + phb #1 ; Start of callee preservation. + ldb #0 ; Reset the B register. + lda.w #cmd_buf+8; + sta.q ptr4 ; + tba ; clr_cbuf_st: - cpy.w #$3FF - bcs clr_cbuf_end - sta.q (ptr6), y - tya - adc #8 - tay - tba - sta.q (ptr6), y - tya - adc #8 - tay - tba - sta.q (ptr6), y - tya - adc #8 - tay - tba - sta.q (ptr6), y - tya - adc #8 - tay - tba - jmp clr_cbuf_st -clr_cbuf_end: - plb #1 - rtl + 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. -pull_y: - ply #2 -rset_a: - lda #0 - sta $C000 - inc read: - lda $C000 ; Get control register. - beq rset_a ; Loop until we get a character. - jsl getchar ; We got a key. - beq parse ; We got a newline, so start parsing the line. - jmp rset_a ; We didn't get a newline, so keep getting more characters. + lda $C000 ; 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. + jmp read ; No, so keep looping. print_str: - sta.q ptr - ldb #0 - tba - inb - stb b + sta.q ptr ; Place the string pointer into the main pointer. + ldb #0 ; Clear the B register. + tba ; Clear the Accumulator. + inb ; Enable replace mode. + stb b ; pntstr_st: - phy #2 - txy - lda (ptr), y ; Get character at offset x. - beq pntstr_end ; Did we find a null terminator? - ply #2 - inx - jsl print_char - jmp pntstr_st + 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. + jsl print_char ; Print the character. + jmp pntstr_st ; Keep looping. pntstr_end: - ply #2 - ldb #0 - stb b - rtl - + ply #2 ; Get the cursor index back. + ldb #0 ; Enable insert mode. + stb b ; + rtl ; End of print_str. getbit: - clc - lda scr_str - bne getbt0 - ldx scr_row - jmp getbt1 + 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. + jmp getbt1 ; Start getting the bit. getbt0: - lda scr_row - adc scr_str - tax + 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: - jsl bitpos - ldb bitabl, x - aba - cmp #1 - jmp bitout + jsl bitpos ; Get the bit, and byte position. + ldb bitabl, x ; Get one byte of the wrap table. + aba ; Mask out the bit of the current line number. + cmp #1 ; Set the carry flag, if true. + jmp bitout ; We are done. clrbit: - jsl bitpos - xor #$FF - ldb bitabl, x - aba + jsl bitpos ; Get the bit, and byte position. + xor #$FF ; Invert the bitmask. + ldb bitabl, x ; Get one byte of the wrap table. + aba ; Clear the bit of the current line number. bitsav: - sta bitabl, x + sta bitabl, x ; Update the wrap table. bitout: - ldx bitmask - rtl + ldx bitmask ; Return the bitmask. + rtl ; We are done. setbit: - jsl bitpos - ldb bitabl, x - oab - jmp bitsav + jsl bitpos ; Get the bit, and byte position. + ldb bitabl, x ; Get one byte of the wrap table. + oab ; Set the bit of the current line number. + jmp bitsav ; Save the bit. bitpos: - pha #1 - lda.w #bits - sta.q ptr3 - lda.w zero - pla #1 - stx bitmask - txa - and #7 - phy #2 - tay - tax - lda (ptr3), y - ply #2 - pha #1 - lda bitmask - lsr #3 - tax - pla #1 - rtl - + 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. + pla #1 ; 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 #2 ; Save the cursor index. + tay ; Use the bit position as the index. + tax ; Copy it into X. + lda (ptr3), y ; Get the bitmask. + ply #2 ; Get back the cursor index. + pha #1 ; Save the bitmask. + lda bitmask ; Get the line number. + lsr #3 ; Get the byte position. + tax ; Copy it into X. + pla #1 ; Get back the bitmask. + 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 + ldb #0 ; + stb e ; + stb b ; + pha #1 ; + phy #2 ; + cmp #10 ; + beq cmd_cpy ; getchar_pnt: - ply #2 - pla #1 - ldb e - bne reset_row -getchar_pnt1: - jsl print_char - lda a - cmp #10 - beq getchar_line - jmp getchar_char + ply #2 ; + pla #1 ; + ldb e ; + bne reset_row ; +getchar_pt1: + jsl print_char ; + lda a ; + cmp #10 ; + beq getchar_ln ; + jmp getchar_chr ; reset_row: - ldb e - stb scr_row - jmp getchar_pnt1 - + ldb e ; + cpb #23 ; + beq reset_row2 ; + bcs reset_row1 ; + jmp reset_row2 ; +reset_row1: + ldb #23 ; +reset_row2: + stb scr_row ; + jmp getchar_pt1 ; cmd_cpy: - ldb scr_row - stb e - jsl findst - clc - lda scr_row - adc scr_str - mul #80 - tay - ldx.w #$0 -cmd_cpy_strt: - lda (ptr5), y - beq getchar_pnt - phy #2 - txy - sta (ptr6), y - inx - ply #2 - iny - jmp cmd_cpy_strt -getchar_line: - lda #0 - jmp getchar_end -getchar_char: - lda #1 + 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 ; +getchar_ln: + lda #0 ; + jmp getchar_end ; +getchar_chr: + lda #1 ; getchar_end: - rtl + rtl ; findst: - jsl getbit - bcc findst_done - dec scr_row - bpo findst - inc scr_row + lda #0 ; +findst_lp: + pha #1 ; + jsl getbit ; + pla #1 ; + bcc findst_done ; + inc ; + dec scr_row ; + bpo findst_lp ; + dec ; + inc scr_row ; findst_done: - rtl + cmp #0 ; + rtl ; + +fndend: + phy #2 ; +fndend_lp: + lda (ptr5), 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. +fndend_done: + sty.w scr_ptr3 ; + ply #2 ; + rtl ; End of fndend. + +findend: + jsl fndend ; + lda.w scr_ptr3 ; + div #80 ; + rtl ; parse: - lda #0 - tax - jsl dabbed - beq start - lda #0 - tax - jmp result + lda #0 ; + tax ; + jsl dabbed ; + beq start ; + lda #0 ; + tax ; + jmp result ; print_char: - sta a - cmp #$1B - beq esc - cmp #$A + sta a ; + cmp #$1B ; + beq esc ; + cmp #$A ; 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 + 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 + cmp #$7F ; beq bs ; Did the user type a backspace? - sta a + sta a ; printc: + lda #0 ; + sta d ; lda (ptr5), 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. sty.w scr_ptr ; No, so save the cursor index for later. -prntc_fndnd: - lda (ptr5), y ; Are we at the end of the string? - beq prntc_movln ; Yes, so make room for the next character. - iny ; No, so increment the cursor index. - jmp prntc_fndnd ; Keep looping. -printc_updt: - jmp prntc_updt2 -prntc_updt1: - pla #1 - clc - adc scr_row - sta scr_row - jsl update_pos + jsl fndend ; + jmp prntc_movln ; +prntc_updt: + lda scr_col ; + sta scr_tcol ; prntc_updt2: - lda scr_row - pha #1 - lda scr_col - pha #1 - jsl rdrw_row - pla #1 - sta scr_col - pla #1 - sta scr_row - jsl update_pos + jsl findend ; + sta e ; + sta scr_row ; + jsl findst ; + lda scr_row ; prntc_updt3: - ldb scr_row - lda scr_trow - sec - sab - pha #1 - tab - sec - sab - clc - sta scr_row -prntc_updt4: - jsl getbit - bcs prntc_updt1 - pla #1 - lda scr_trow - sta scr_row - jsl update_pos - dec d - jmp printc_sav1 + sta f ; + jsl rdrw_ln ; + lda scr_trow ; + sta scr_row ; + lda scr_tcol ; + sta scr_col ; + jsl update_pos ; + dec d ; + jmp printc_sav1 ; prntc_movln: - tyx - dey - ldb #1 - stb d - jsl shftln - ldb #1 - stb d - lda scr_row - sta scr_trow + ldy.w scr_ptr3 ; + inc scr_ptr3 ; + tyx ; + dey ; + ldb #1 ; + stb d ; + jsl shftln ; + ldb #1 ; + stb d ; + lda a ; + sta (ptr5), y ; store typed character into the input buffer. + lda scr_row ; + sta scr_trow ; + jmp prntc_updt ; printc_save: - ldb d - bne printc_updt + ldb d ; + bne prntc_updt ; printc_sav1: - lda a - sta (ptr5), y ; Store typed character into the input buffer. + lda a ; + sta (ptr5), y ; store typed character into the input buffer. printc_inc: inc scr_col ; Increment the cursor's x coordinate. - iny + iny ; printc_2: - ldb #1 - stb f - ldb scr_col - cpb #80 - bcs printc_4 + ldb #1 ; + stb f ; + ldb scr_col ; + cpb #80 ; + bcs printc_4 ; printc_3: sta $C001 ; Echo typed character. - ldb f - beq printc_wrap - jmp printc_end + ldb f ; + beq printc_wrap ; + jmp printc_end ; printc_4: - ldb scr_row - cpb #23 - bcs printc_scrl + ldb scr_row ; + cpb #23 ; + bcs printc_scrl ; printc_5: - ldb #0 - stb f - jmp printc_3 + ldb #0 ; + stb f ; + jmp printc_3 ; printc_scrl: sta $C001 ; Echo typed character. - clc - lda #1 - sta wrapped - jsl scrl_down + clc ; + lda #1 ; + sta wrapped ; + jsl scrl_down ; printc_wrap: - ldb #0 - stb scr_col - ldb scr_row - cpb #23 - bcs printc_wrap2 + ldb #0 ; + stb scr_col ; + ldb scr_row ; + cpb #23 ; + bcs printc_wrp2 ; printc_wrap1: - inc scr_row -printc_wrap2: - phx #2 - clc - lda scr_row - adc scr_str - tax - jsl setbit - plx #2 - jsl update_pos + inc scr_row ; +printc_wrp2: + phx #2 ; + clc ; + lda scr_row ; + adc scr_str ; + tax ; + jsl setbit ; + plx #2 ; + jsl update_pos ; printc_end: - rtl + rtl ; nl: - lda #0 - ldb (ptr5), y - bne nl1 + lda #0 ; + ldb (ptr5), y ; + bne nl1 ; sta (ptr5), y ; Store said terminator into the input buffer. nl1: - sta scr_col - lda scr_row - cmp #23 - bne nl_inc - jsl scrl_down - lda #10 - sta a - jmp printc_end + sta scr_col ; + lda scr_row ; + cmp #23 ; + bcc nl_inc ; + jsl scrl_down ; + lda #10 ; + sta a ; + jmp printc_end ; nl_inc: - inc scr_row - jsl update_pos - lda #10 - sta a - jmp printc_end + inc scr_row ; + jsl update_pos ; + lda #10 ; + sta a ; + jmp printc_end ; clr_scr: - lda #23 - sta scr_end - lda #0 - sta scr_str - sta.q bitabl - sta.q bitabl+8 - tay - jsl clr_buf - tay - jsl clr_cbuf - sta scr_col - sta scr_row - jsl update_pos - lda #$C - sta $C001 - jmp printc_end + lda #23 ; + sta scr_end ; + lda #0 ; + sta scr_str ; + sta.q bitabl ; + sta.q bitabl+8 ; + tay ; + jsl clr_buf ; + tay ; + jsl clr_cbuf ; + sta scr_col ; + sta scr_row ; + jsl update_pos ; + lda #$C ; + sta $C001 ; + jmp printc_end ; en_step: - lda $C010 - beq step_en - jmp stp_end + lda $C010 ; + beq step_en ; + jmp printc_end ; step_en: - lda #1 - sta $C010 - jmp stp_end + lda #1 ; + sta $C010 ; + jmp printc_end ; dis_step: - lda $C010 - bne step_dis - jmp stp_end + lda $C010 ; + bne step_dis ; + jmp printc_end ; step_dis: - lda #0 - sta $C010 -stp_end: - jmp printc_end + lda #0 ; + sta $C010 ; + jmp printc_end ; back: + ldb #0 ; + stb e ; + stb f ; + lda scr_row ; + sta scr_trow ; + jsl findend ; + sta scr_row ; +back0: + jsl findst ; + beq back1 ; + bcs back_updt ; + lda scr_trow ; + sta scr_row ; +back1: dey ; Decrement the buffer's offset. lda #0 ; Place a null terminator sta (ptr5), y ; into the buffer. tyx ; Copy the current cursor index to X. iny ; Increment cursor index. - ldb #0 - stb d - jsl shftln ; Move/Shift line back by one character. + ldb #0 ; + stb d ; + jsl shftln ; Shift line back by one character. lda #$7F ; Print a backspace to the screen. sta $C001 ; + lda e ; + beq back3 ; +back2: + jsl findend ; + sta e ; + lda scr_col ; + sta scr_tcol ; + jsl rdrw_ln ; + lda scr_tcol ; + sta scr_col ; +back3: + lda scr_trow ; + sta scr_row ; dec scr_col ; Move the cursor back by one column, jsl update_pos ; and update it's position. jmp printc_end ; We are done. +back_updt: + lda scr_row ; + sta f ; + inc e ; + jmp back1 ; bs: lda scr_col ; Are we at the far left of the screen? @@ -585,20 +616,20 @@ backwrp: tax ; Transfer that into X. backwrp2: dec scr_row ; Move up by one row. - jsl clrbit ; Clear the wrap bit for this row. +; jsl clrbit ; Clear the wrap bit for this row. ldb #80 ; 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. shftln: - ldb d ; Is the flag set? - beq shftln_lp1 ; Yes, so shift, and increment. - jmp shftln_lp0 ; No, so shift, and decrement. + ldb d ; Is the flag not set? + beq shftln_lp1 ; Yes, so shift, and decrement. + ldb #0 ; Clear the B register. + jmp shftln_lp0 ; No, so shift, and increment. shftln_neg: ldy.w zero ; Set the source poition to 0. - lda #0 ; Clear the character - sta (ptr5), y ; that is in the source. + stb (ptr5), 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. @@ -613,26 +644,61 @@ shftln_lp01: txy ; Set our position to the destination. sta (ptr5), y ; Place the character from the source position, to the destination position. ply #2 ; Set our position back to the source. - lda #0 ; Clear the character - sta (ptr5), y ; that is in the source. - dey ; Decrement the source position. + stb (ptr5), 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? - beq shftln_end ; Yes, so we're done. + 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. inx ; Increment the destination position. ply #2 ; Set our position back to the source. - lda #0 ; Clear the character - sta (ptr5), y ; that is in the source. + stb (ptr5), y ; Clear the character that is in the source. iny ; Increment the source position. jmp shftln_lp1 ; Keep looping. +shftln_wrap: + tax ; Use the ending line as a parameter for setbit. + jsl setbit ; Set the wrap bit of the ending line. + jmp shftln_end2 ; We are done. +shftln_wrp1: + tax ; Use the ending line as a parameter for clrbit. + jsl clrbit ; Clear the wrap bit of the ending line. + jmp shftln_end2 ; We are done. shftln_end: - rtl ; We are done. + lda (ptr5), 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 ; +shftln_nd0: + jsl findend ; Find the ending line. + sta d ; Save ending line for later. + lda (ptr5), 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 ; +shftln_nd1: + lda d ; Get the ending line. + cmp scr_row ; Is the ending line greater than the starting line? + beq shftln_end2 ; No, so we're done. + bcs shftln_wrap ; Yes, so set the wrap bit. + jmp shftln_end2 ; No, so we're done. +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. + jmp shftln_end2 ; No, so we're done. +shftln_nd01: + 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. +shftln_end2: + rtl ; End of shftln. esc: lda $C000 ; Get the next character. @@ -657,9 +723,9 @@ esc: bne esc_end ; Yes, so we're done. jsl isright ; No, so check if the user pressed right. esc_end: - lda #0 ; Set the D pseudo register to zero. + lda #0 ; Clear the D pseudo register. sta d ; - jmp printc_end ; Go back to getting user input. + jmp printc_end ; We are done. shftesc: lda $C000 ; Skip the '['. @@ -667,22 +733,22 @@ shftesc: beq printc_end ; We have an error, so discard it, and go back to getting user input. lda $C002 ; Get the escape code. sta c ; Store the escape code, until we need it. - lda #0 ; + lda #0 ; Use the D pseudo register as a skip flag. sta d ; jsl isshftup ; Check if the user pressed shift+up. - lda d ; - bne shftesc_end ; - jsl isshftdown ; Check if the user pressed shift+down. + lda d ; Was it successful? + bne shftesc_end ; Yes, so we're done. + jsl isshftdown ; No, so check if the user pressed shift+down. shftesc_end: - lda #0 ; + lda #0 ; Clear the D pseudo register. sta d ; - jmp printc_end ; Go back to getting user input. + jmp printc_end ; We are done. isup: lda c ; No, so load the escape code back into the accumulator. cmp #$41 ; Did the user press the up arrow key? - bne isup_done ; Yes, so we're done. - lda scr_row ; No, so is the cursor at the top of the screen? + bne isup_done ; No, so we're done. + lda scr_row ; Yes, but is the cursor at the top of the screen? beq isup_scrl ; Yes, so check if we need to scroll. isup_2: lda c ; No, so load the escape code back into the accumulator. @@ -693,16 +759,18 @@ isup_scrl: lda scr_str ; Are we at the top of the screen buffer? beq isup_done ; Yes, so we're done. jsl scrl_up ; No, so scroll up. + lda #1 ; Tell the escape routine that we were successful. + sta d ; isup_done: rtl ; End of isup. isdown: lda c ; No, so load the escape code back into the accumulator. cmp #$42 ; Did the user press the down arrow key? - bne isdown_done - lda scr_row ; Start checking the y coordinate of the cursor. + 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? - beq isdown_scrl ; Yes, so return. + 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? beq down ; Yes, so move the cursor down. @@ -717,6 +785,8 @@ isdown_scrl: sta scr_row ; lda scr_tcol ; Load the cursor's column number. sta scr_col ; + lda #1 ; Tell the escape routine that we were successful. + sta d ; isdown_done: rtl ; End of isdown. @@ -735,8 +805,8 @@ isright_wrp: dec scr_row ; No, so move the cursor back up a row. jmp isright_dne ; We are done. isright_scr: -; lda scr_str ; Are we at the top of the screen buffer? -; beq isright_end ; Yes, so we're done. + lda scr_str ; Are we at the top of the screen buffer? + beq isright_end ; Yes, so we're done. lda #1 ; No, so scroll down. sta wrapped ; Set the wrapped flag. jsl scrl_down ; Scroll down. @@ -748,7 +818,7 @@ wrap_inc: cmp #23 ; 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 ; We are done. + jmp isright_nd2 ; No, so we're done. isright_end: dec scr_row ; Move back up a row. isright_nd2: @@ -759,29 +829,29 @@ isright_dne: rtl ; End of isright. isleft: - lda c - cmp #$43 - beq isleft_done - lda scr_col ; Is the cursor at the far left of the screen? + lda c ; Get the saved character. + cmp #$43 ; Did the user press right? + beq isleft_done ; Yes, so we're done + lda scr_col ; No, but is the cursor at the far left of the screen? beq isleft_wrp ; Yes, so start checking if this is a wrapped line. lda c ; No, so load the escape code back into the accumulator. cmp #$44 ; Did the user press the left arrow key? beq left ; Yes, so move the cursor left. - jmp isleft_done ; We are done. + jmp isleft_done ; No, so we're done. isleft_wrp: jsl getbit ; Is the current line, a wrapped line? bcs wrap_dec ; Yes, so wrap back up a line. - jmp isleft_done ; No, so return. + jmp isleft_done ; No, so we're done. wrap_dec: lda scr_row ; Is the cursor at the top of the screen? - beq wrap_dec1 ; Yes, so don't move up a row. - lda #1 ; No, so move up a row. - sta wrapped ; Set the wrapped flag. - dec scr_row ; Move the cursor up by one row. + beq wrap_dec1 ; Yes, so don't move up a line. + lda #1 ; No, so set the wrapped flag. + 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. sta scr_col ; - lda #1 ; Tell the escape routine to stop after this. + lda #1 ; Tell the escape routine that we were successful. sta d ; lda scr_row ; Are we at the top of the screen? beq isleft_scrl ; Yes, so check if we need to scroll. @@ -801,81 +871,81 @@ isleft_done: rtl ; End of isleft. up: - dec scr_row - jsl update_pos - lda #1 - sta d - jmp isup_done + dec scr_row ; Move the cursor up a line. + jsl update_pos ; Update it's position. + lda #1 ; Tell the escape routine that we succeded. + sta d ; + jmp isup_done ; We are done. down: - inc scr_row - jsl update_pos - lda #1 - sta d - jmp isdown_done + inc scr_row ; Move the cursor down a line. + jsl update_pos ; Update it's position. + lda #1 ; Tell the escape routine that we succeded. + sta d ; + jmp isdown_done ; We are done. right: - inc scr_col - jsl update_pos - jmp isright_dne + inc scr_col ; Move the cursor right by one character. + jsl update_pos ; Update it's position. + jmp isright_dne ; We are done. left: - dec scr_col - jsl update_pos - lda #1 - sta d - jmp isleft_done + dec scr_col ; Move the cursor left a character. + jsl update_pos ; Update it's position. + lda #1 ; Tell the escape routine that we succeded. + sta d ; + jmp isleft_done ; We are done isshftup: lda c ; Load the escape code back into the accumulator. cmp #$41 ; Did the user press the up arrow key? - bne isshftup_done - lda #1 - sta d - lda scr_str - beq isshftup_done - jmp shftup -isshftup_done: - rtl + bne shftup_done ; + lda #1 ; + sta d ; + lda scr_str ; + beq shftup_done ; + jmp shftup ; +shftup_done: + rtl ; isshftdown: lda c ; Load the escape code back into the accumulator. cmp #$42 ; Did the user press the down arrow key? - bne isshftdown_done - lda #1 - sta d - lda scr_end - cmp #71 - bcs isshftdown_done - jmp shftdown -isshftdown_done: - rtl + bne shftdn_done ; + lda #1 ; + sta d ; + lda scr_end ; + cmp #71 ; + bcs shftdn_done ; + jmp shftdown ; +shftdn_done: + rtl ; shftup: - jsl scrl_up - lda #1 - sta d - jmp isshftup_done + jsl scrl_up ; + lda #1 ; + sta d ; + jmp shftup_done ; shftdown: - jsl scrl_down - lda #1 - sta d - jmp isshftdown_done + jsl scrl_down ; + lda #1 ; + sta d ; + jmp shftdn_done ; update_pos: - ldb #1 - stb f - clc - lda scr_row - adc scr_str - tay - clc - lsl #6 - tab - tya - lsl #4 - aab - clc - adc scr_col - tay + ldb #1 ; Set the F pseudo register to one, to fix some bugs. + stb f ; + 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. + 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. + 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. lda #$5B ; Print '[' @@ -911,190 +981,180 @@ getcol: rtl ; End of getrow. scrl_down: - inc scr_str - inc scr_end + 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. lda #$5B ; Print '[' sta $C001 ; to the screen, and start the escape sequence. lda #$54 ; Print 'T' sta $C001 ; to the screen, and end the escape sequence. - lda wrapped - beq scrldn_save + lda scr_row ; Get the cursor's line number. + pha #1 ; Save it in the stack. + lda wrapped ; Was the wrapped flag set? + beq scrldn_save ; Yes, so save the cursor position. scrldn1: - jsl rdrw_row - lda wrapped - beq scrldn_load - jmp scrldn_end + jsl rdrw_row ; Redraw this row. + lda wrapped ; Was the wrapped flag set? + beq scrldn_load ; Yes, so load the previous cursor position back. + jmp scrldn_end ; No, so we're done. scrldn_save: - lda scr_row - pha #1 - lda scr_col - pha #1 - jmp scrldn1 + lda scr_col ; Get the cursor's column number. + pha #1 ; Save it in the stack. + jmp scrldn1 ; Start redrawing the current row. scrldn_load: - pla #1 - sta scr_col - pla #1 - sta scr_row - jsl update_pos + pla #1 ; Get the cursor's previous column number back. + sta scr_col ; scrldn_end: - lda #0 - sta wrapped + pla #1 ; Get the cursor's previous line number back. + sta scr_row ; + jsl update_pos ; Update the cursor's position. + lda #0 ; Clear the wrapped flag. + sta wrapped ; scrldn_done: - rtl + rtl ; End of scrl_down. scrl_up: - dec scr_str - dec scr_end + dec scr_str ; + dec scr_end ; lda #$1B ; Print an escape character sta $C001 ; to the screen. lda #$5B ; Print '[' sta $C001 ; to the screen, and start the escape sequence. lda #$53 ; Print 'S' sta $C001 ; to the screen, and end the escape sequence. - lda scr_row - pha #1 - lda scr_col - pha #1 - lda #0 - sta scr_row - jsl rdrw_row - pla #1 - sta scr_col - pla #1 - sta scr_row - jsl update_pos + lda scr_row ; + pha #1 ; + lda scr_col ; + pha #1 ; + lda #0 ; + sta scr_row ; + jsl rdrw_row ; + pla #1 ; + sta scr_col ; + pla #1 ; + sta scr_row ; + jsl update_pos ; scrlup_done: - rtl + rtl ; rdrw_row: - lda #0 - sta scr_col - jsl update_pos + lda #0 ; + sta scr_col ; + jsl update_pos ; rdrow_st: - lda (ptr5), y - beq rdrow_inc - sta $C001 + lda (ptr5), y ; + beq rdrow_inc ; + sta $C001 ; rdrow_inc: - inc scr_col - lda (ptr5), y - beq rdrow_skip + inc scr_col ; + lda (ptr5), y ; + beq rdrow_skip ; rdrow_inc1: - iny + iny ; rdrow_inc2: - lda scr_col - cmp #80 - bcs rdrow_end - jmp rdrow_st + lda scr_col ; + cmp #80 ; + bcs rdrow_end ; + jmp rdrow_st ; rdrow_skip: - lda #$20 + lda #$20 ; sta $C001 ; to the screen. - jmp rdrow_inc1 + jmp rdrow_inc1 ; rdrow_end: - lda #0 - sta scr_col - jsl update_pos + lda #0 ; + sta scr_col ; + jsl update_pos ; rdrow_done: - rtl - -;rdrw_scr: -; lda scr_row -; sta e -; lda #0 -; sta scr_row -; lda scr_col -; sta f -; jsl update_pos -;rdscr_st: -; jsl rdrw_row -; lda scr_row -; cmp #23 -; beq rdscr_inc -; bcs rdscr_done -;rdscr_inc: -; inc scr_row -; jmp rdscr_st -;rdscr_done: -; lda e -; sta scr_row -; lda f -; sta scr_col -; jsl update_pos -; lda #0 -; sta e -; sta f -; rtl + rtl ; result: - lda.w #string2 - ldx.w zero - jsl print_str + lda.w #string2 ; + ldx.w zero ; + jsl print_str ; rset_x: lda #0 ; Reset a. tax ; Reset x. jmp print_buf ; Print the input buffer. dabbed: - ldb #0 - lda.w #tok - sta.q ptr2 - tba + ldb #0 ; + lda.w #tok ; + sta.q ptr2 ; + tba ; dab_st: - phy #2 - txy + 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 + cmp (ptr2), y ; + beq chk_str ; + jmp dab_pend ; chk_str: - ply #2 - inx - cpx #3 - bne dab_st - ldx #0 + ply #2 ; + inx ; + cpx #3 ; + bne dab_st ; + ldx #0 ; pnt_msg: - lda.w #msg - ldx #0 - stx.q ptr - jsl print_str - jmp dab_peqnd + lda.w #msg ; + ldx #0 ; + stx.q ptr ; + jsl print_str ; + jmp dab_peqnd ; dab_pend: - ply #2 - lda #1 - jmp dab_end + ply #2 ; + lda #1 ; + jmp dab_end ; dab_peqnd: - lda #0 - jmp dab_end + lda #0 ; + jmp dab_end ; dab_end: - rtl + rtl ; print_buf: - lda.w #cmd_buf - jsl print_str - lda.w zero + lda.w #cmd_buf ; + jsl print_str ; + lda.w zero ; cmd_clr: - lda #10 - jsl print_char - jmp start + lda #10 ; + jsl print_char ; + jmp start ; + +rdrw_ln: + lda scr_row ; + pha #1 ; + inc end ; + lda f ; + sta scr_row ; + lda scr_col ; + pha #1 ; + jsl update_pos ; +rdrwln_lp: + lda scr_row ; + cmp e ; + beq rdrwln_lp1 ; + bcs rdrwln_done ; +rdrwln_lp1: + jsl rdrw_row ; +rdrwln_inc: + inc scr_row ; + jmp rdrwln_lp ; +rdrwln_done: + pla #1 ; + sta scr_col ; + pla #1 ; + sta scr_row ; + jsl update_pos ; + lda #0 ; + sta e ; + sta f ; + dec end ; + rtl ; .org $FFC0 .qword reset r -;.org $8000 -;v -;.org $8100 -;v -;.org $8200 -;v -;.org $8300 -;v -;.org $8400 -;v -;.org $8500 -;v -;q done -- cgit v1.2.3-13-gbd6f