Stiggity:
I'm still here, had things to do and had a fight with the array search and create routine at $7cf4 which I lost. Couldn't get it to work.
About “jsrfar” ($ff6e):
It exits with lda #$00 sta $ff00. So to ROM. If you want to “jsrfar” to a BASIC-ROM routine from the RAM below, you must change the lda #00 to your own configuration, in your case to #$0e: lda #$0e, sta $02de. But now when you return to your BASIC program, it crashes. It seems BASIC also uses “jsrfar”. So before you return to BASIC you must restore “jsrfar” and put the zero back in: lda #$00, sta $02de. (See my code at $3f40 and $3f4f.)
About garbage collect:
All changed strings new and old are stored in new memory and old strings are marked as garbage, but stay in memory. Using the same string over and over therefore takes up new memory, until the top of the stringpool ($35/$36,53/54) reaches to top of variable space ($33/$34). Then a garbage collect is performed and all of the valid strings are moved to top of memory and top of stringpool is reset to fit those valid strings.
Here’s a demo that fills memory by using the same string over and over:
10 a$="good morning, how are you doing today?":t=t+1:printpeek(53)+peek(54)*256;t:goto10
After string 1606 you can see the garbage collect happen as a wait of one second.
memory #strings
1120 1604
1080 1605
1040 1606 ; now garbage collection
65200 1607
65160 1608
65120 1609
Putaray doesn’t check if memory is full and doesn’t perform a garbage collect. It will fail when memory is full.
Add the next code in putary after the code that subtracts length+2 from $35/$36:
sec ; test if $35/$36 smaller than $33/$34
lda $35
sbc $33
lda $36
sbc $34
bcs out ; jump when memory is sufficient
lda #$0f ; #0e=bank14=all rom without I/O, better #0f=bank15=all rom with I/O
sta $02
lda #$92
sta $03
lda #$ea
sta $04
jsr newfar ; jsr with your newfar to $92ea = garbage collect
out:
Your “strout” routine does the memory full/garbage collect job correctly because it uses System routines. I wanted to use your “strout” for the arrays. Therefore I had to replace the searchstring routine for a searcharray routine. The rest stayed the same.
I couldn’t get the searcharray system routine at $7cf4 to work. It uses the stack for the dimensions which is why I can’t jsrfar to it. But the create a new array routine was available.
So everything put together: string to buffer, buffer to string, array to buffer, buffer to array, create array, print buffer and “jsrfar” fixed gives the next demo + code:
I also put it on disk image: bufall.d64
drive.google.com/file/d/1BNFH5Cs47ghSQ-Q0x1_lxND-CTD2-kNj/view?usp=sharing
The routine jump table is at $3f00.
The routines are under BASIC-ROM from $4000-$4190
Buffer at $1500
list
100 bload"bufall.mac",b0,p(dec("3f00"))
110 hh$="hello there"
120 d$(4)="good morning"
130 sysdec("3f00"),asc("h"),asc("h")
140 sysdec("3f03"),asc("b"),asc("v")
150 sysdec("3f09"),asc("f"),asc("p"),4
160 print"hh$=";hh$
170 print"bv$=";bv$
180 print"fp$(4)=";fp$(4)
190 sysdec("3f06"),asc("d"),0,4
200 print"buffer=d$(4)=";
210 sysdec("3f0c")
ready.
run
hh$=hello there
bv$=hello there
fp$(4)=hello there
buffer=d$(4)=good morning
ready.
3f00 jmp $3f10 ;string to buffer
3f03 jmp $3f1c ;buffer to string
3f06 jmp $3f28 ;array to buffer
3f09 jmp $3f34 ;buffer to array
3f0c jmp $3f40 ;print buffer
3f0f nop
3f10 jsr $3f4f ;shut off BASIC-ROM
3f13 jsr $40c0 ;search string
3f16 jsr $4170 ;string to buffer
3f19 jmp $3f46 ;all ROMs on
3f1c jsr $3f4f
3f1f jsr $40c0 ;search string
3f22 jsr $4100 ;buffer to string
3f25 jmp $3f46
3f28 jsr $3f4f
3f2b jsr $4000 ;search array string
3f2e jsr $4170 ;string to buffer
3f31 jmp $3f46
3f34 jsr $3f4f
3f37 jsr $4000 ;search array string
3f3a jsr $4100 ;buffer to string
3f3d jmp $3f46
3f40 jsr $3f4f
3f43 jsr $40f1 ;print buffer
3f46 lda #$00
3f48 sta $02de ;restore "jsrfar"
3f4b sta $ff00 ;all roms on
3f4e rts
3f4f pha
3f50 lda #$0e
3f52 sta $02de ;set "jsrfar" to exit to RAM under BASIC-ROM
3f55 sta $ff00 ;select RAM under BASIC-ROM
3f58 pla
3f59 rts
--------------------------------
search array string:
4000 sta $47
4002 txa
4003 ora #$80
4005 sta $48
4007 sty index
$400a lda #$ff ; set string flag
400c sta $0f
400e lda #$01 ; array one dimention
4010 sta $0d
4012 lda #$00 ; this flag needs to be zero
4014 sta $0e
4016 lda $31 ; get start of array space
4018 sta $49
401a lda $32
401c sta $4a
$401e lda $33 ; test on end of array space
4020 ldx $34
4022 cmp $49
4024 bne $4045
4026 cpx $4a
4028 bne $4045
402a sta $61 ; $7d46=create new array
402c stx $62
402e lda #$01 ; here this flag needs to be not zero
4030 sta $0e
4032 lda #$0f
4034 sta $02
4036 lda #$7d
4038 sta $03
403a lda #$46
403c sta $04
403e jsr $ff6e ; jsrfar to $7d46
4041 lda #$00
4043 beq $400a ; search the new array
$4045 ldy #$00 ;test on variable name
4047 lda #$49
4049 ldx #$01
404b jsr $ff74
404e cmp $47
4050 bne $405e
4052 iny
4053 lda #$49
4055 ldx #$01
4057 jsr $ff74
405a cmp $48
405c beq $4082
$405e ldy #$02 ; get size of array
4060 lda #$49
4062 ldx #$01
4064 jsr $ff74
4067 sta $fb
4069 iny
406a lda #$49
406c ldx #$01
406e jsr $ff74
4071 sta $fc
4073 clc ; add size to find next array
4074 lda $49
4076 adc $fb
4078 sta $49
407a lda $4a
407c adc $fc
407e sta $4a
4080 bcc $401e ; next array
$4082 clc ;skip 7 bytes to get to index
4083 lda $49
4085 adc #$07
4087 sta $49
4089 lda $4a
408b adc #$00
408d sta $4a
408f ldx index ;load index
4092 beq $40a4
$4094 clc ;index * 3 (length+pointers)
4095 lda $49
4097 adc #$03
4099 sta $49
409b lda $4a
409d adc #$00
409f sta $4a
40a1 dex
40a2 bne $4094
$40a4 ldx $49 ; setup pointers for $87ca
40a6 ldy $4a
40a8 stx $24
40aa sty $25
40ac lda #$0f ; $87ca=get length+pointers to stringpool
40ae sta $02
40b0 lda #$87
40b2 sta $03
40b4 lda #$ca
40b6 sta $04
40b8 jmp $ff6e ; jsrfar to $87ca
-------------------------------------
search string:
40c0 sta $47
40c2 txa
40c3 ora #$80
40c5 sta $48
40c7 lda #$ff ; set string flag
40c9 sta $0f
40cb lda #$0f ; $7b0b=find the string in $47/$48
40cd sta $02
40cf lda #$7b
40d1 sta $03
40d3 lda #$0b
40d5 sta $04
40d7 jsr $ff6e ; jsrfar to $7b0b
40da ldx $49 ; setup pointers for $87ca
40dc ldy $4a
40de stx $24
40e0 sty $25
40e2 lda #$0f ; $87ca=get length+pointers to stringpool
40e4 sta $02
40e6 lda #$87
40e8 sta $03
40ea lda #$ca
40ec sta $04
40ee jmp $ff6e ; jsrfar to $87ca
-------------------------------------
print buffer:
40f1 ldy #$00
$40f3 lda buffer,y
40f6 beq $40fe
40f8 jsr $ffd2
40fb iny
40fc bne $40f3
40fe rts
---------------------------------------
buffer to string (strout):
4100 lda #$24 ; set stashfar to the string in the stringpool
4102 sta $02b9
4105 lda $06
4107 beq $4117
4109 tay ; set old stringtext in the stringpool to garbage
410a ldx #$01
410c jsr $ff77
410f iny
4110 lda #$ff
4112 ldx #$01
4114 jsr $ff77
$4117 lda #$0f ; $869a:reads buffer to stringpool
4119 sta $02
411b lda #$86
411d sta $03
411f lda #$9a
4121 sta $04
4123 lda #<buffer
4125 sta $06
4127 lda #>buffer
4129 sta $08
412b jsr $ff6e
412e dec $18
4130 dec $18
4132 dec $18
4134 lda #$49 ; set stashfar to the variable $49/$4a
4136 sta $02b9
4139 ldx #$01
413b ldy #$00
413d lda $63
413f jsr $ff77 ; set length
4142 ldx #$01
4144 iny
4145 lda $35
4147 jsr $ff77 ; set pointer low to stringpool
414a ldx #$01
414c iny
414d lda $36 ; set pointer high to stringpool
414f jsr $ff77
4152 lda #$35 ; set stashfar to $45/$36=stringpool
4154 sta $02b9
4157 ldx #$01 ; set pointers to variable space
4159 ldy $63
415b lda $49
415d jsr $ff77
4160 ldx #$01
4162 iny
4163 lda $4a
4165 jmp $ff77
----------------------------------
string to buffer:
4170 lda $06
4172 beq $418a
4174 ldy #$00
$4176 lda #$24
4178 ldx #$01
417a jsr $ff74 ; get stringbyte from stringpool
417d sta buffer,y ; store in buffer
4180 iny
4181 cpy $06
4183 bne $4176
4185 lda #$00 ; end buffer with a zero
4187 sta buffer,y
$418a rts
--------------------------------
$1500
index .byte
buffer .text ""