diff --git a/edlin.asm b/edlin.asm index e4a4830..0c83b5f 100644 --- a/edlin.asm +++ b/edlin.asm @@ -236,7 +236,9 @@ setup_file_parameters: ; 01ec movw r_dx, r_cx add dx, file_buffer - mov [__0a96], dx + ; File buffer is actually 1 byte more than we load from the file + ; This is because we always place a ^Z after file contents + mov [last_file_buffer_byte], dx read_file: mov dx, psp_fcb_1 @@ -249,7 +251,7 @@ read_file: initialize_editor: ; 0240 cld - ; Put ^Z at the end of the file in memory + ; Place ^Z after the end of file in memory mov byte [di], 0x1a ; ^Z mov [__0a9a], di @@ -422,6 +424,12 @@ command_addresses: ; 034a dw command_w ; W dw command_q ; Q +; in: +; di = buffer +; cx = size of buffer +; out: +; cx = size of buffer upto and including the ^Z, or original passed size +; equals (zero) flag = was there a ^Z find_file_end_char: ; 035e push di push cx @@ -449,7 +457,7 @@ command_a: ; 0370 cmp word [__0a80], 0 jnz __0388 - cmp dx, [__0a96] + cmp dx, [last_file_buffer_byte] jnb find_file_end_char.ret __0388: @@ -479,10 +487,10 @@ __03ab: movw r_ax, r_di addw r_ax, r_cx - cmp ax, [__0a96] + cmp ax, [last_file_buffer_byte] jna __03ca - mov di, [__0a96] + mov di, [last_file_buffer_byte] movw r_cx, r_ax subw r_cx, r_di mov bx, 1 @@ -1377,7 +1385,7 @@ current_line resw 1 ; 0a90 __0a92 resw 1 __0a94 resw 1 -__0a96 resw 1 +last_file_buffer_byte resw 1 ; 0a96 last_valid_address resw 1 ; 0a98 __0a9a resw 1