From da4cc3a89bc727dc780c05bd6875854b7d840b93 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Fri, 19 Jul 2019 17:23:11 +0200 Subject: [PATCH] refactored LOAD routine so that it's parts are reuseable --- c64/aliases/,aliases_ram_lowmem.s | 105 +++++++++++++++---- c64/basic/,aliases.s | 32 +----- c64/basic/basic_execute_line.s | 2 +- c64/basic/cmd_list.s | 2 +- c64/basic/cmd_load.s | 4 +- c64/basic/cmd_sys.s | 18 ++-- c64/kernal/,aliases.s | 28 ----- c64/kernal/load.s | 169 +++++++----------------------- c64/kernal/lvs_helpers.s | 128 ++++++++++++++++++++++ c64/kernal/scan_keyboard.s | 2 +- c64/kernal/setnam.s | 6 +- c64/kernal/stop.s | 4 +- 12 files changed, 269 insertions(+), 231 deletions(-) create mode 100644 c64/kernal/lvs_helpers.s diff --git a/c64/aliases/,aliases_ram_lowmem.s b/c64/aliases/,aliases_ram_lowmem.s index a024d66f..60c67bb4 100644 --- a/c64/aliases/,aliases_ram_lowmem.s +++ b/c64/aliases/,aliases_ram_lowmem.s @@ -1,33 +1,92 @@ ;; -;; Names of ZP and low memory locations (only the implemented ones) +;; Names of ZP and low memory locations ;; (https://www.c64-wiki.com/wiki/Zeropage) ;; - ;; $000-$001 - 6502 CPU registers + ;; $00-$01 - 6502 CPU registers are here + ;; + ;; Page 0 - BASIC area ($02-$8F) + ;; + + .alias TXTTAB $2B + + ;; + ;; Page 0 - Kernal area ($90-$FF) + ;; + + .alias IOSTATUS $90 + .alias STKEY $91 ; Keys down clears bits. STOP - bit 7, C= - bit 6, SPACE - bit 4, CTRL - bit 2 + + .alias VERCK $93 ; 0 = LOAD, 1 = VERIVY + + .alias C3PO $94 ; flag - is BSOUR content valid + .alias BSOUR $95 ; serial bus buffered output byte + + .alias LDTND $98 ; number of entries in LAT / FAT / SAT tables + .alias DFLTN $99 + .alias DFLTO $9A + + .alias MSGFLG $9D ; bit 6 = error messages, bit 7 = control message + + .alias TIME $A0 ; $A0-$A2, jiffy clock + + ;; 2-byte location below seems to be a good place for temporary storage, + ;; it seems used for timing during tape reads only - see: + ;; - 'C64 Programmer's Reference Guide', page 314 + ;; - 'Compute's Mapping the Commodore 64', page 32 + .alias CMP0 $B0 ; $B0-$B1 + + .alias FNLEN $B7 ; current file name length + + .alias STAL $C1 ; $C1-$C2 LOAD/SAVE start address + + ;; + ;; Other low memory addresses + ;; + + ;; Kernal tables for opened files, 10 entries each + .alias LAT $259 ; logical file numbers + .alias FAT $263 ; device numbers + .alias SAT $26D ; secondary addresses + + .alias MEMSTR $281 + .alias MEMSIZ $283 ; NOTE: Mapping the 64 erroniously has the hex as $282, while the DEC is correct + + .alias HIBASE $288 ; high byte of start of screen + + .alias RSSTAT $297 ; RS-232 status + + .alias PALNTSC $2A6 ; 0 = NTSC, 1 = PAL + + ;; Registers for SYS call - .alias sys_reg_a $30c - .alias sys_reg_x $30d - .alias sys_reg_y $30e - .alias sys_reg_p $30f - .alias sys_jmp $310 + .alias SAREG $30C + .alias SXREG $30D + .alias SYREG $30E + .alias SPREG $30F + .alias USRPOK $310 ; JMP instruction + .alias USRADD $311 ; $311 - $312 + ;; Kernal vectors - interrupts - .alias CINV $0314 - .alias CBINV $0316 - .alias NMINV $0318 + .alias CINV $314 + .alias CBINV $316 + .alias NMINV $318 ;; Kernal vectors - routines - .alias IOPEN $031A - .alias ICLOSE $031C - .alias ICHKIN $031E - .alias ICKOUT $0320 - .alias ICLRCH $0322 - .alias IBASIN $0324 - .alias IBASOUT $0326 - .alias ISTOP $0328 - .alias IGETIN $032A - .alias ICLALL $032C - .alias USRCMD $032E - .alias ILOAD $0330 - .alias ISAVE $0331 + .alias IOPEN $31A + .alias ICLOSE $31C + .alias ICHKIN $31E + .alias ICKOUT $320 + .alias ICLRCH $322 + .alias IBASIN $324 + .alias IBASOUT $326 + .alias ISTOP $328 + .alias IGETIN $32A + .alias ICLALL $32C + .alias USRCMD $32E + .alias ILOAD $330 + .alias ISAVE $331 + + .alias TBUFFR $33C ; $33C-$3FB, tape buffer diff --git a/c64/basic/,aliases.s b/c64/basic/,aliases.s index d3b76eab..6f98fbf4 100644 --- a/c64/basic/,aliases.s +++ b/c64/basic/,aliases.s @@ -52,33 +52,13 @@ .alias memmove_dst $6b .alias memmove_size $6d - .alias TXTTAB $2B - .alias IOSTATUS $90 - ; Keys down clears bits. STOP=bit 7, C= bit 6, SPACE bit 4, CTRL bit 2 - .alias BUCKYSTATUS $91 - .alias load_or_verify_flag $93 - .alias C3PO $94 ; flag - is BSOUR content valid - .alias BSOUR $95 ; serial bus buffered output byte .alias current_file_num $98 - .alias LDTND $98 ; number of entries in LAT / FAT / SAT tables - .alias DFLTN $99 - .alias input_device_number DFLTN - .alias MSGFLG $9D ; bit 6 = error messages, bit 7 = control message - .alias jiffy_clock_24bits $a0 .alias cassette_buffer_bytes_used $A6 .alias load_or_scroll_temp_pointer $AC ;; We also use the following for temp colour pointer when scrolling .alias load_save_verify_end_address $AE - ;; 2-byte location below seems to be a good place for temporary storage, - ;; it seems used for timing during tape reads only - see: - ;; - 'C64 Programmer's Reference Guide', page 314 - ;; - 'Compute's Mapping the Commodore 64', page 32 - .alias CMP0 $B0 ;; $B0-$B1 - - .alias cassette_buffer_ptr $B2 - .alias current_filename_length $B7 .alias current_logical_filenum $B8 .alias current_secondary_address $B9 .alias current_device_number $BA @@ -112,19 +92,11 @@ .alias rs232_tx_buffer_ptr $F9 .alias basic_input_buffer $0200 - - ;; Kernal tables for opened files, 10 entries each - .alias LAT $0259 ; logical file numbers - .alias FAT $0263 ; device numbers - .alias SAT $026D ; secondary addresses - + ; "Compute's Mapping the 64" book .alias keyboard_buffer $0277 - .alias MEMSTR $0281 - .alias MEMSIZ $0283 ; NOTE: Mapping the 64 erroniously has the hex as $282, while the DEC is correct .alias text_colour $0286 ; p55 .alias colour_under_cursor $0287 ; p56 - .alias HIBASE $0288 ; p56 (high byte of start of screen) .alias key_buffer_size $0289 ; p57 ;; 0 = cursor keys, insert, delete and space repeat, but nothing else @@ -140,8 +112,6 @@ .alias keyboard_decoding_ptr $028F .alias enable_case_switch $0291 .alias screen_scroll_disable $0292 - .alias RSSTAT $0297 ; RS-232 status - .alias pal_or_ntsc $02A6 ;; BASIC uses some extra bytes for memory access under ROMs located at $2A7 onwards ;; IRQs are disabled when doing such accesses, and a default NMI handler only increments diff --git a/c64/basic/basic_execute_line.s b/c64/basic/basic_execute_line.s index 749935cb..5ea0aafb 100644 --- a/c64/basic/basic_execute_line.s +++ b/c64/basic/basic_execute_line.s @@ -29,7 +29,7 @@ no_space_to_skip: basic_execute_statement: ;; Check for RUN/STOP - lda BUCKYSTATUS + lda STKEY bpl basic_do_break ;; Skip over any white space and : diff --git a/c64/basic/cmd_list.s b/c64/basic/cmd_list.s index f93ee033..d58af209 100644 --- a/c64/basic/cmd_list.s +++ b/c64/basic/cmd_list.s @@ -22,7 +22,7 @@ list_loop: jmp basic_main_loop list_more_lines: - lda BUCKYSTATUS + lda STKEY bmi + jmp basic_do_break * diff --git a/c64/basic/cmd_load.s b/c64/basic/cmd_load.s index 5eb5b7f0..22b648eb 100644 --- a/c64/basic/cmd_load.s +++ b/c64/basic/cmd_load.s @@ -26,7 +26,7 @@ cmd_load: ;; Set filename and length lda #$00 - sta current_filename_length + sta FNLEN ;; Without tape support, LOAD must have a filename ;; (This also skips any leading spaces) @@ -57,7 +57,7 @@ getting_filename: jmp got_filename * - inc current_filename_length + inc FNLEN jmp getting_filename got_filename: diff --git a/c64/basic/cmd_sys.s b/c64/basic/cmd_sys.s index 86830bd0..2328a0a4 100644 --- a/c64/basic/cmd_sys.s +++ b/c64/basic/cmd_sys.s @@ -10,22 +10,22 @@ cmd_sys: jsr basic_parse_line_number ;; setup call - lda #$4c ;JMP - sta sys_jmp + lda #$4C ;JMP + sta USRPOK lda basic_line_number+0 - sta sys_jmp+1 + sta USRADD+0 lda basic_line_number+1 - sta sys_jmp+2 + sta USRADD+1 ;; Setup the register values - lda sys_reg_p + lda SPREG pha - ldy sys_reg_y - ldx sys_reg_x - lda sys_reg_a + ldy SYREG + ldx SXREG + lda SAREG plp ;; Call the routine. - jsr sys_jmp + jsr USRPOK jmp basic_execute_statement diff --git a/c64/kernal/,aliases.s b/c64/kernal/,aliases.s index 0c30eca1..b769b149 100644 --- a/c64/kernal/,aliases.s +++ b/c64/kernal/,aliases.s @@ -3,30 +3,18 @@ ; (And only those for now that we feel the need to implement initially) ; (https://www.c64-wiki.com/wiki/Zeropage) - .alias TXTTAB $2B - .alias IOSTATUS $90 - ; Keys down clears bits. STOP=bit 7, C= bit 6, SPACE bit 4, CTRL bit 2 - .alias BUCKYSTATUS $91 .alias kernal_load_or_verify_flag $93 - .alias C3PO $94 ; flag - is BSOUR content valid - .alias BSOUR $95 ; serial bus buffered output byte .alias current_file_num $98 - .alias LDTND $98 ; number of entries in LAT / FAT / SAT tables - .alias DFLTN $99 .alias input_device_number DFLTN - .alias MSGFLG $9D ; bit 6 = error messages, bit 7 = control message - .alias jiffy_clock_24bits $a0 .alias cassette_buffer_bytes_used $A6 .alias load_or_scroll_temp_pointer $AC ;; We also use the following for temp colour pointer when scrolling .alias load_save_verify_end_address $AE .alias cassette_buffer_ptr $B2 - .alias current_filename_length $B7 .alias current_logical_filenum $B8 .alias current_secondary_address $B9 .alias current_device_number $BA .alias current_filename_ptr $BB - .alias load_save_start_ptr $C1 .alias load_save_end_ptr $C3 .alias last_key_matrix_position $C5 .alias keys_in_key_buffer $C6 @@ -53,25 +41,11 @@ .alias keyboard_decoding_table_ptr $F5 .alias rs232_rx_buffer_ptr $F7 .alias rs232_tx_buffer_ptr $F9 - - ;; 2-byte location below seems to be a good place for temporary storage, - ;; it seems used for timing during tape reads only - see: - ;; - 'C64 Programmer's Reference Guide', page 314 - ;; - 'Compute's Mapping the Commodore 64', page 32 - .alias CMP0 $B0 ;; $B0-$B1 - - ;; Kernal tables for opened files, 10 entries each - .alias LAT $0259 ; logical file numbers - .alias FAT $0263 ; device numbers - .alias SAT $026D ; secondary addresses ; "Compute's Mapping the 64" book .alias keyboard_buffer $0277 - .alias MEMSTR $0281 - .alias MEMSIZ $0283 ; NOTE: Mapping the 64 erroniously has the hex as $282, while the DEC is correct .alias text_colour $0286 ; p55 .alias colour_under_cursor $0287 ; p56 - .alias HIBASE $0288 ; p56 (high byte of start of screen) .alias key_buffer_size $0289 ; p57 ;; 0 = cursor keys, insert, delete and space repeat, but nothing else @@ -87,8 +61,6 @@ .alias keyboard_decoding_ptr $028F .alias enable_case_switch $0291 .alias screen_scroll_disable $0292 - .alias RSSTAT $0297 ; RS-232 status - .alias pal_or_ntsc $02A6 ;; Under-ROM routines ;; (BASIC also includes them. XXX - We should de-duplicate them in a safe manner) diff --git a/c64/kernal/load.s b/c64/kernal/load.s index ce355cfc..d5f8553a 100644 --- a/c64/kernal/load.s +++ b/c64/kernal/load.s @@ -19,7 +19,7 @@ ;; Searching through Compute's Mapping the 64, we find the following ;; things are used: - ;; $93 = kernal_load_or_verify_flag + ;; $93 = VERCK ;; $AC = current pointer for loading/verifying ;; $C1 = similar to the above. @@ -30,11 +30,11 @@ load: ;; Are we loading or verifying? - sta kernal_load_or_verify_flag + sta VERCK ;; Store start address of LOAD - stx load_save_start_ptr+0 - sty load_save_start_ptr+1 + stx STAL+0 + sty STAL+1 ;; Reset status jsr kernalstatus_reset @@ -43,21 +43,8 @@ load: jsr install_ram_routines ;; Display SEARCHING FOR + filename - lda MSGFLG - bpl + - jsr printf - .byte $0D,"SEARCHING FOR ",0 - ldy #$00 -print_filename_loop: + jsr lvs_display_searching_for - cpy current_filename_length - beq + - ldx #