This, as we all know, messes with some BASIC end-of-things pointers and causes out of memory errors and other ill effects. Traditionally, the user is expected to fix this with NEW after loading.
I'd like the user's BASIC program, if any, to remain untouched, so the utility can be loaded without trepidation or extra steps. My current solution is the code below, which scans for three consecutive bytes and sets start of variables, start of arrays, and end of arrays to this address.
This code seems to work, but it seems like the kind of thing that there might be a BASIC routine for, instead of doing it the hard way. Is this the most efficient way to accomplish this task? I'm willing to put 48 bytes into this, but, you know...
Code: Select all
Install: lda IGONE+1 ; If the wedge is aleady installed, skip
cmp #>main ; the memory adjustment. Otherwise, set BASIC
beq installed ; pointers as a courtesy
lda $2b ; Copy start-of-basic to start-of-variables
sta $2d ; to be the starting point for search
lda $2c ; ,,
sta $2e ; ,,
ldy #$00
reset_c0c: ldx #$00 ; Reset consecutive-zero count
adv_sov: lda ($2d),y
inc $2d ; Advance start-of-variables pointer after
bne check_0 ; reading, because we want the final value to
inc $2e ; be the third zero location + 1
check_0: cmp #$00 ; If the current value is not a zero, then
bne reset_c0c ; reset the consecutive-zero count
inx ; A zero was found
cpx #$03 ; Is it the third?
bne adv_sov ; If not, search the next character
lda $2d ; Copy the newly-found start-of-variables
sta $2f ; into end-of-everthing-elses
sta $31 ; ,,
lda $2e ; ,,
sta $30 ; ,,
sta $32 ; ,,
installed: etc...