diff --git a/bin/basic_generic.rom b/bin/basic_generic.rom index 908d3719..2d4664ac 100644 Binary files a/bin/basic_generic.rom and b/bin/basic_generic.rom differ diff --git a/bin/basic_ultimate64.rom b/bin/basic_ultimate64.rom index f0967126..1d45b875 100644 Binary files a/bin/basic_ultimate64.rom and b/bin/basic_ultimate64.rom differ diff --git a/bin/kernal_generic.rom b/bin/kernal_generic.rom index 4e44e9be..cf478ede 100644 Binary files a/bin/kernal_generic.rom and b/bin/kernal_generic.rom differ diff --git a/bin/kernal_ultimate64.rom b/bin/kernal_ultimate64.rom index 7126d2b9..666837c7 100644 Binary files a/bin/kernal_ultimate64.rom and b/bin/kernal_ultimate64.rom differ diff --git a/bin/mega65.rom b/bin/mega65.rom index 09a7addc..cbdb8191 100644 Binary files a/bin/mega65.rom and b/bin/mega65.rom differ diff --git a/bin/mega65_pxlfont.rom b/bin/mega65_pxlfont.rom index d5b3b234..14f258b2 100644 Binary files a/bin/mega65_pxlfont.rom and b/bin/mega65_pxlfont.rom differ diff --git a/src/aliases/,aliases_ram_lowmem.s b/src/aliases/,aliases_ram_lowmem.s index b6e5dbed..eb492b70 100644 --- a/src/aliases/,aliases_ram_lowmem.s +++ b/src/aliases/,aliases_ram_lowmem.s @@ -32,7 +32,7 @@ .label LASTPT = $17 // $17-$18 pointer to the last used slot in the temporary string descriptor .label TEMPST = $19 // $19-$21 temporary string stack descriptors .label INDEX = $22 // $22-$25 temporary variables, [!] our usage might be different - .label RESHO = $26 // $26-$2A -- NOT IMPLEMENTED -- + .label RESHO = $26 // $26-$2A temporary variables, [!] our usage might be different .label TXTTAB = $2B // $2B-$2C start of BASIC code .label VARTAB = $2D // $2D-$2E end of BASIC code, start of variables .label ARYTAB = $2F // $2F-$30 -- NOT IMPLEMENTED -- @@ -235,15 +235,15 @@ // IRQs are disabled when doing such accesses, and a default NMI handler only increments // a counter, so that if an NMI occurs, it does not crash the machine, but can be captured. - .label missed_nmi_flag = $2A7 - .label tiny_nmi_handler = $2A8 - .label peek_under_roms = tiny_nmi_handler + peek_under_roms_routine - tiny_nmi_handler_routine - .label poke_under_roms = tiny_nmi_handler + poke_under_roms_routine - tiny_nmi_handler_routine - .label memmap_allram = tiny_nmi_handler + memmap_allram_routine - tiny_nmi_handler_routine - .label memmap_normal = tiny_nmi_handler + memmap_normal_routine - tiny_nmi_handler_routine + .label missed_nmi_flag = $2A7 + .label tiny_nmi_handler = $2A8 + .label peek_under_roms = tiny_nmi_handler + peek_under_roms_routine - tiny_nmi_handler_routine + .label poke_under_roms = tiny_nmi_handler + poke_under_roms_routine - tiny_nmi_handler_routine + .label memmap_allram = tiny_nmi_handler + memmap_allram_routine - tiny_nmi_handler_routine + .label memmap_normal = tiny_nmi_handler + memmap_normal_routine - tiny_nmi_handler_routine #if SEGMENT_BASIC - .label shift_mem_up = tiny_nmi_handler + shift_mem_up_routine - tiny_nmi_handler_routine - .label shift_mem_down = tiny_nmi_handler + shift_mem_down_routine - tiny_nmi_handler_routine + .label shift_mem_up_internal = tiny_nmi_handler + shift_mem_up_routine - tiny_nmi_handler_routine + .label shift_mem_down_internal = tiny_nmi_handler + shift_mem_down_routine - tiny_nmi_handler_routine #endif #endif // CONFIG_MEMORY_MODEL_60K diff --git a/src/basic/basic_commands_CC/cmd_merge.s b/src/basic/basic_commands_CC/cmd_merge.s index 43c8cd17..42f3b1ed 100644 --- a/src/basic/basic_commands_CC/cmd_merge.s +++ b/src/basic/basic_commands_CC/cmd_merge.s @@ -22,7 +22,7 @@ cmd_merge_got_params: // Make sure VARTAB is correctly set - jsr calculate_VARTAB + jsr update_VARTAB_do_clr // Perform loading - just for a different address @@ -42,17 +42,9 @@ cmd_merge_got_params: cmd_merge_no_error: - // Store last loaded address + // Relink loaded program, clear variables - stx VARTAB+0 - sty VARTAB+1 - - // Clear the variables - jsr do_clr - - // Now relink the loaded program, line links supplied are almost certainly wrong - - jsr LINKPRG + jsr update_LINKPRG_VARTAB_do_clr // XXX when number parsing is done, change to continue execution diff --git a/src/basic/basic_commands_CC/cmd_old.s b/src/basic/basic_commands_CC/cmd_old.s index 210ed801..9b816edf 100644 --- a/src/basic/basic_commands_CC/cmd_old.s +++ b/src/basic/basic_commands_CC/cmd_old.s @@ -17,8 +17,7 @@ cmd_old: tya sta (TXTTAB),y - jsr LINKPRG - jsr calculate_VARTAB + jsr update_LINKPRG_VARTAB_do_clr // Quit diff --git a/src/basic/basic_shift_mem_down.s b/src/basic/basic_shift_mem_down.s deleted file mode 100644 index 791446f2..00000000 --- a/src/basic/basic_shift_mem_down.s +++ /dev/null @@ -1,76 +0,0 @@ -// #LAYOUT# STD * #TAKE -// #LAYOUT# * BASIC_0 #TAKE -// #LAYOUT# * * #IGNORE - - -// -// Shift the BASIC program down to cover the area of removed line -// - - -basic_shift_mem_down_and_relink: - - // Destination is OLDTXT - - lda OLDTXT+0 - sta memmove__dst+0 - lda OLDTXT+1 - sta memmove__dst+1 - - // Source is OLDTXT + .X - - clc - txa - - adc OLDTXT+0 - sta memmove__src+0 - lda OLDTXT+1 - adc #$00 - sta memmove__src+1 - - // Size is distance from source (OLDTXT) to the end of BASIC text (VARTAB) - - lda VARTAB+0 - sec - sbc memmove__src+0 - sta memmove__size+0 - lda VARTAB+1 - sbc memmove__src+1 - sta memmove__size+1 - - // The copy routine is simplified, so that it is fast and (for memory model 60K) - // can fit in a small RAM area - therefore it requires to pre-set .Y, so that - // the copy ends when it reaches 0; so if copying one byte we want .Y = $FF - - sec - lda #$00 - sbc memmove__size+0 - tay - sty __tokenise_work3 - - // Now we have to move down the memmove_src and memmove_dst pointers - // to compensate for .Y not being 0 - - sec - lda memmove__src+0 - sbc __tokenise_work3 - sta memmove__src+0 - bcs !+ - dec memmove__src+1 -!: - sec - lda memmove__dst+0 - sbc __tokenise_work3 - sta memmove__dst+0 - bcs !+ - dec memmove__dst+1 -!: - // Perform the copy XXX add more documentation inside the copy routine! - - inc memmove__size+1 - jsr shift_mem_down - - // Now fix program linkage and calculate VARTAB - - jsr LINKPRG - jmp calculate_VARTAB diff --git a/src/basic/basic_shift_mem_up.s b/src/basic/basic_shift_mem_up.s deleted file mode 100644 index 9b203555..00000000 --- a/src/basic/basic_shift_mem_up.s +++ /dev/null @@ -1,211 +0,0 @@ -// #LAYOUT# STD * #TAKE -// #LAYOUT# * BASIC_0 #TAKE -// #LAYOUT# * * #IGNORE - - -basic_shift_mem_up_and_relink: - // Shift memory up from OLDTXT - // X bytes. - - // NOTE: Pointers need to be reduced by one, due to the way - // the copyroutine works, so we do that here. - // Work out end point of destination - txa - clc - adc VARTAB+0 - sta memmove__dst+0 - lda VARTAB+1 - adc #0 - sta memmove__dst+1 - lda memmove__dst+0 - sec - sbc #1 - sta memmove__dst+0 - lda memmove__dst+1 - sbc #0 - sta memmove__dst+1 - - // End point of source is just current end of BASIC text - lda VARTAB+0 - sec - sbc #1 - sta memmove__src+0 - lda VARTAB+1 - sbc #0 - sta memmove__src+1 - - // Work out size of region to copy - lda VARTAB+0 - sec - sbc OLDTXT+0 - sta memmove__size+0 - lda VARTAB+1 - sbc OLDTXT+1 - sta memmove__size+1 - - // jsr printf - // .text "TOP OF BASIC = $" - // .byte $f1,VARTAB - // .byte $f0,VARTAB - // .byte $0d - // .text "SHIFTING UP $" - // .byte $f1,memmove__size - // .byte $f0,memmove__size - // .text " BYTES FROM $" - // .byte $f1,memmove__src - // .byte $f0,memmove__src - // .text " TO $" - // .byte $f1,memmove__dst - // .byte $f0,memmove__dst - // .byte $0d,0 - - // To make life simple for the copy routine that lives in RAM, - // we have to adjust the end pointers down one page and set Y to the low - // byte of the copy size. - lda memmove__src+0 - sec - sbc memmove__size+0 - sta memmove__src+0 - lda memmove__src+1 - sbc #0 - sta memmove__src+1 - - lda memmove__dst+0 - sec - sbc memmove__size+0 - sta memmove__dst+0 - lda memmove__dst+1 - sbc #0 - sta memmove__dst+1 - - // Now make exit easy, by being able to check for zero on size high byte when done - inc memmove__size+1 - - // Then set Y to the number offset required - ldy memmove__size+0 - iny - - stx __tokenise_work3 - - // jsr printf - // .text "REVISED BOUNDS $" - // .byte $f1,memmove__size - // .byte $f0,memmove__size - // .text " BYTES FROM $" - // .byte $f1,memmove__src - // .byte $f0,memmove__src - // .text " TO $" - // .byte $f1,memmove__dst - // .byte $f0,memmove__dst - // .byte $0d,0 - - // Do the copy - jsr shift_mem_up - - // Now fix the pointer to the next line - - // First, we need to point the current BASIC line - // pointer to itself, so that we can add the shift - // to make it end up pointing to the next line - ldy #0 - - lda OLDTXT+0 - -#if CONFIG_MEMORY_MODEL_60K - ldx #VARTAB - // .byte $f0,VARTAB - // .text $d," BEFORE = $" - // .byte $f1,memmove__dst - // .byte $f0,memmove__dst - // .text ", AFTER = $" - // .byte $f1,memmove__src - // .byte $f0,memmove__src - // .byte $d - // .byte 0 - - // Write memmove__src back to current line pointer - ldy #0 - lda memmove__src+0 - -#if CONFIG_MEMORY_MODEL_60K - ldx #OLDTXT // .byte $f0,OLDTXT // .byte $0d,0 - - lda OLDTXT+0 - pha - lda OLDTXT+1 - - pha // Get number of bytes in tokenised line after line number lda __tokenise_work2 sec sbc __tokenise_work1 - // Add on the four bytes space we need + // Add on the five bytes space we need (2 bytes for linkage, 2 bytes for line number, 1 byte for terminator) clc - adc #5 - pha + adc #$05 tax // Make the space - jsr basic_shift_mem_up_and_relink + jsr shift_txt_up - // Now increase top of BASIC mem - pla - clc - adc VARTAB+0 - sta VARTAB+0 - lda VARTAB+1 - adc #0 - sta VARTAB+1 - - // Get pointer back - pla - sta OLDTXT+1 - pla - sta OLDTXT+0 - - // Write the line number - ldy #2 - lda LINNUM+0 + // Put dummy linkage, we will correct it later + ldy #$01 + tya #if CONFIG_MEMORY_MODEL_60K ldx # memmove__src + // + // This means we have to copy from the back end down. + // This routine assumes the pointers are already pointed to the end of the areas, and that .Y is correctly initialized + + php +!: + lda (memmove__src),y + sta (memmove__dst),y + iny + bne !- + inc memmove__src+1 + inc memmove__dst+1 + dec memmove__size+1 + bne !- + plp + rts + +#else + + jmp shift_mem_down_internal + +#endif diff --git a/src/basic/memory/shift_mem_down_38k.s b/src/basic/memory/shift_mem_down_38k.s deleted file mode 100644 index 583fe3c7..00000000 --- a/src/basic/memory/shift_mem_down_38k.s +++ /dev/null @@ -1,28 +0,0 @@ -// #LAYOUT# STD * #TAKE -// #LAYOUT# * BASIC_0 #TAKE -// #LAYOUT# * * #IGNORE - - -#if CONFIG_MEMORY_MODEL_38K - -shift_mem_down: - - // Move memmove__size bytes from memmove__src to memmove__dst, where memmove__dst > memmove__src - // - // This means we have to copy from the back end down. - // This routine assumes the pointers are already pointed to the end of the areas, and that .Y is correctly initialized - - php -!: - lda (memmove__src),y - sta (memmove__dst),y - iny - bne !- - inc memmove__src+1 - inc memmove__dst+1 - dec memmove__size+1 - bne !- - plp - rts - -#endif diff --git a/src/basic/memory/shift_mem_up.s b/src/basic/memory/shift_mem_up.s new file mode 100644 index 00000000..320c01db --- /dev/null +++ b/src/basic/memory/shift_mem_up.s @@ -0,0 +1,56 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +// +// Copies the memory up +// +// Input: +// - memmove__src - pointer to the last byte of source +// - memmove__dst - pointer to the last byte of destination +// - memmove__size - number of bytes to copy +// +// All the input variables, .A, and .Y register, are destroyed. Also uses RESHO+4 variable. +// + + +shift_mem_up: + + // The copy routine is simplified, so that it is fast and (for memory model 60K) + // can fit in a small RAM area - therefore it requires to pre-set .Y, so that + // the copy ends when it reaches 0; so if copying one byte we want .Y = $01 + + ldy memmove__size+0 + + // Now we have to move down the memmove_src and memmove_dst pointers to compensate for .Y not being 0 + + jsr shift_mem_adapt_pointers + +#if CONFIG_MEMORY_MODEL_38K + +shift_mem_up_internal: + + // Move memmove__size bytes from memmove__src to memmove__dst, where memmove__dst > memmove__src + // + // This means we have to copy from the back end down. + // This routine assumes the pointers are already pointed to the end of the areas, and that .Y is correctly initialized + + php +!: + lda (memmove__src),y + sta (memmove__dst),y + dey + bne !- + dec memmove__src+1 + dec memmove__dst+1 + dec memmove__size+1 + bne !- + plp + rts + +#else + + jmp shift_mem_up_internal + +#endif diff --git a/src/basic/memory/shift_mem_up_38k.s b/src/basic/memory/shift_mem_up_38k.s deleted file mode 100644 index 81c0d9f3..00000000 --- a/src/basic/memory/shift_mem_up_38k.s +++ /dev/null @@ -1,28 +0,0 @@ -// #LAYOUT# STD * #TAKE -// #LAYOUT# * BASIC_0 #TAKE -// #LAYOUT# * * #IGNORE - - -#if CONFIG_MEMORY_MODEL_38K - -shift_mem_up: - - // Move memmove__size bytes from memmove__src to memmove__dst, where memmove__dst > memmove__src - // - // This means we have to copy from the back end down. - // This routine assumes the pointers are already pointed to the end of the areas, and that .Y is correctly initialized - - php -!: - lda (memmove__src),y - sta (memmove__dst),y - dey - bne !- - dec memmove__src+1 - dec memmove__dst+1 - dec memmove__size+1 - bne !- - plp - rts - -#endif diff --git a/src/basic/memory/under_rom_routines_46k_50k.s b/src/basic/memory/under_rom_routines_46k_50k.s index d7f7beef..261ae7da 100644 --- a/src/basic/memory/under_rom_routines_46k_50k.s +++ b/src/basic/memory/under_rom_routines_46k_50k.s @@ -70,7 +70,7 @@ peek_under_roms_via_FAC1_PLUS_1: -shift_mem_up: +shift_mem_up_internal: // Move memmove__size bytes from memmove__src to memmove__dst, where memmove__dst > memmove__src // @@ -96,13 +96,13 @@ shift_mem_up: bne !- #if HAS_OPCODES_65C02 - bra shift_mem_finalize + bra shift_mem_internal_finalize #else - jmp shift_mem_finalize + jmp shift_mem_internal_finalize #endif -shift_mem_down: +shift_mem_down_internal: // Move memmove__size bytes from memmove__src to memmove__dst, where memmove__dst > memmove__src // @@ -126,9 +126,10 @@ shift_mem_down: inc memmove__dst+1 dec memmove__size+1 bne !- + // FALLTROUGH -shift_mem_finalize: +shift_mem_internal_finalize: // Restore memory mapping and quit