From 020fe4028ac2a3c4ca56aa16cca9ca290e91392d Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Wed, 5 Mar 2025 18:26:13 +0100 Subject: [PATCH] Fix RANGE ERROR STOPPED AT 8214 On a 48k Apple II, the BLTU2 call throws an error, even when there is nothing to copy in the LC segment. Add an alternative LC copy, based on memcpy, to an extra file that the user can link in as with iobuf-0800. This memcpy-based version allows our programs to run on Integer ROM apple2. It costs 21 bytes in binary size, plus memcpy (60 bytes in binary size + RAM use) if it wasn't already linked in. --- libsrc/apple2/crt0.s | 4 +++- libsrc/apple2/extra/lc-copy-memcpy.s | 33 ++++++++++++++++++++++++++++ libsrc/apple2/lc-copy-applesoft.s | 9 ++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 libsrc/apple2/extra/lc-copy-memcpy.s create mode 100644 libsrc/apple2/lc-copy-applesoft.s diff --git a/libsrc/apple2/crt0.s b/libsrc/apple2/crt0.s index 42e26c27b..4b9a59153 100644 --- a/libsrc/apple2/crt0.s +++ b/libsrc/apple2/crt0.s @@ -10,6 +10,7 @@ .import initlib, _exit .import zerobss, callmain + .import bltu2 .import __ONCE_LOAD__, __ONCE_SIZE__ ; Linker generated .import __LC_START__, __LC_LAST__ ; Linker generated @@ -93,6 +94,7 @@ basic: lda HIMEM ; Call the module constructors. jsr initlib + ; Copy the LC segment to its destination ; Switch in LC bank 2 for W/O. bit $C081 bit $C081 @@ -120,7 +122,7 @@ basic: lda HIMEM ; Call into Applesoft Block Transfer Up -- which handles zero- ; sized blocks well -- to move the content of the LC memory area. - jsr $D39A ; BLTU2 + jsr bltu2 ; BLTU2 ; Switch in LC bank 2 for R/O and return. bit $C080 diff --git a/libsrc/apple2/extra/lc-copy-memcpy.s b/libsrc/apple2/extra/lc-copy-memcpy.s new file mode 100644 index 000000000..c4dc8d8ef --- /dev/null +++ b/libsrc/apple2/extra/lc-copy-memcpy.s @@ -0,0 +1,33 @@ +; +; Colin Leroy-Mira, 06.03.2025 +; +; Copy the LC segment from the end of the binary to the Language Card +; using _memcpy. This allows running apple2 programs on the original +; Integer ROM Apple ][. +; + + .export bltu2 + + .import _memcpy, pushax + .import __ONCE_LOAD__, __ONCE_SIZE__ ; Linker generated + .import __LC_START__, __LC_LAST__ ; Linker generated + + .segment "ONCE" + +bltu2: + ; Get the destination start address. + lda #<__LC_START__ + ldx #>__LC_START__ + jsr pushax + + ; Get the source start address. + lda #<(__ONCE_LOAD__ + __ONCE_SIZE__) + ldx #>(__ONCE_LOAD__ + __ONCE_SIZE__) + jsr pushax + + ; Set the length + lda #<(__LC_LAST__ - __LC_START__) + ldx #>(__LC_LAST__ - __LC_START__) + + ; And do the copy + jmp _memcpy diff --git a/libsrc/apple2/lc-copy-applesoft.s b/libsrc/apple2/lc-copy-applesoft.s new file mode 100644 index 000000000..70a04431d --- /dev/null +++ b/libsrc/apple2/lc-copy-applesoft.s @@ -0,0 +1,9 @@ +; +; Oliver Schmidt, 15.09.2009 +; +; Copy the LC segment from the end of the binary to the Language Card +; using AppleSoft's BLTU2 routine. +; + .export bltu2 + +bltu2 := $D39A