Congrats, Stiggity, good work.
But Stiggity, it still bothered me that I could not get the array search system routine to work and other system routines. And the reason for that was that they all read bytes from the BASIC program. I found a way to execute those system routines. You don't need this anymore, but I still going to share this method with you, because you can execute other system routines with it.
I have a new "PUTARY" for you, using only system routines. I managed to get them to work by manipulating the BASIC textpointer. I now have a second buffer which I fill with the string (xy$) or array xy$(index), then I put the token "=" ($b2) in followed by the first buffer and then I perform a "LET". That gives me "strout" and "putary".
That buffer ($3d00) looks like this:
(Buffer nr1 holds: TOO MANY FILES0)
m 3d00
>03d00 41 35 24 b2 22 54 4f 4f :a5$="TOO ;strout
>03d08 20 4d 41 4e 59 20 46 49 : MANY FI
>03d10 4c 45 53 22 00 ff ff ff :LES"0...
>03d00 41 20 24 28 30 30 32 29 :a $(002) ;putary
>03d08 b2 22 46 49 4c 45 20 4e :="FILE N
>03d10 4f 54 20 4f 50 45 4e 22 :OT OPEN"
>03d18 00 ff ff ff ff ff ff ff:0....... :0
This is the routine which executes "LET":
(PUTARY and STROUT with this routine down below)
basbuf def $3d00
let def $53c6
;----perform LET ($53c6) on basbuf
let:
ldx #<let
ldy #>let
;----execute basic statement in basbuf
basexe:
lda $3e ;save basictextpointer
pha
lda $3d
pha
lda #<basbuf ;set basictextpointer to basbuf
sta $3d
lda #>basbuf
sta $3e
lda #$0f ;jsrfar to x,y (low,high), in this case to "LET"
sta $02
sty $03
stx $04
jsr $ff6e
pla ;restore basictextpointer
sta $3d
pla
sta $3e
rts
This routine executes just AFTER the keyword. I wanted more and now I can execute a full BASIC statement. Then: in one of your threads you asked about a GOTO from ML to BASIC. It wasn't needed to solve your thread problem, but I myself wanted to have such a GOTO. I got the GOTO working and then combined it with the Basic statement execute routine and now I have a sort of: GOSUB to BASIC from within ML. With this routine you can go from within a ML program to any BASIC linenumber, execute the BASIC statements on that line and automatically return to the ML program.
I made a demo with the new putary and strout and a demo for the ML gosub BASIC routine and put them on basexe.d64
drive.google.com/file/d/1GXUSqVE-o6uYl1gKeuiixze0fl4dRDOS/view?usp=sharingWell, stiggity, it seems our quest is over. Thank you too, I had great fun and I know a lot more now.
Here the code:
;To execute from ML: BASIC statements on a basiclinenumber and then continue with ML.
sta $16 ;basic line number low
stx $17 ;basic line number high
lda $3e ;save basic textpointer
pha
lda $3d
pha
lda #$80 ;set basic runtime flag
sta $7f
lda #$0f ;jsrfar to $59fb: search linenumber in $16/$17
sta $02
lda #$59
sta $03
lda #$fb
sta $04
jsr $ff6e
lda $3d ;add 5 to basic textpointer to get to first basic statement
clc
adc #$05
sta $3d
lda $3e
adc #$00
sta $3e
statem:
lda #$0f ;jsrfar to $0386: get the first byte
sta $02
lda #$03
sta $03
lda #$86
sta $04
jsr $ff6e
lda #$0f ;jsrfar to $4b3f: execute one basic statement, (from $0386: first byte in $06, processorstatus in $05)
sta $02
lda #$4b
sta $03
lda #$3f
sta $04
jsr $ff6e
lda #$0f ;jsrfar to $0386: getbyte
sta $02
lda #$03
sta 03
lda #$86
sta $04
jsr ff6e
inc 3d ;set basicpointer to next byte
bne stat1
inc 3e
stat1:
lda $06 ;byte from $0386
cmp #$3a ;if byte is ":" then execute next statement else exit
beq statem
pla ;restore basic textpointer
sta $3d
pla
sta $3e
rts
demo:
100 fort=0to93:reada:poke4864+t,a:next
110 sys4864,170,0:rem execute line 170
120 sys4864,160,0:rem execute line 160
130 sys4864,150,0:rem execute line 150
140 end
150 fort=0to9:print"yeah! victorious !!":next
160 print"good morning"
170 print"2346/3=";2346/3
180 data 133,22,134,23,165,62,72,165
190 data 61,72,169,128,133,127,169,15
200 data 133,2,169,89,133,3,169,251
210 data 133,4,32,110,255,165,61,24
220 data 105,5,133,61,165,62,105,0
230 data 133,62,169,3,133,3,169,134
240 data 133,4,32,110,255,169,75,133
250 data 3,169,63,133,4,32,110,255
260 data 169,3,133,3,169,134,133,4
270 data 32,110,255,230,61,208,2,230
280 data 62,165,6,201,58,240,211,104
290 data 133,61,104,133,62,96
run
2346/3= 782
good morning
yeah! victorious !!
yeah! victorious !!
yeah! victorious !!
yeah! victorious !!
yeah! victorious !!
yeah! victorious !!
yeah! victorious !!
yeah! victorious !!
yeah! victorious !!
yeah! victorious !!
------------------------------------------------------
Here the new "PUTARY" and "STROUT"
buffer to string:strout : sys start,var1,var2
buffer to array :putary : sys start+6,var1,var2,index
string print :strprn : sys start+12,var1,var2
array print :aryprn : sys start+18,var1,var2,index
basbuf def $3d00
buffer def $3e00
let def $53c6
print def $555b (not $5554 as in "mapping the c128")
;----make basbuf with xy$=buffer or xy$(index)="buffer" and perform "LET"
; or make basbuf with xy$ and perform "PRINT"
start:
sta $47 ;strout:start+0
lda #$01
bne j0
sta $47 ;putary:start+6
lda #$02
bne j0
sta $47 ;strprn:start+12
lda #$03
bne j0
sta $47 ;aryprn:start+18
lda #$04
j0:
sta $fa ;save mode 1=strout/2=putary/3=strprn
lda $47 ;var1
stx $48 ;var2
and #$7f
sta basbuf ;var1 without bit7
txa
and #$7f
bne j1
lda #$20
j1:
sta basbuf+1 ;var2 without bit7
lda #$24 ;"$" string
sta basbuf+2
ldx #$03 ;position after xy$
lda $fa ;mode
cmp #$01
beq bas2 ;strout: skip making array but copy buffer
cmp #$03
beq out2 ;strprn: only add the end zero
ldx #$04 ;put (xxx) in basbuf
j2:
lda array,x
sta basbuf+3,x
dex
bpl j2
;----index in y-reg to numberstring and put at xxx in (xxx) in basbuf
tya ;index to reg-a
sec
j3:
tax
sbc #$64
inc basbuf+4 ;how many times can 100 be subtracted
bcs j3
txa
sec
j4:
tax
sbc #$0a
inc basbuf+5 ;how many times can 10 be subtracted
bcs j4
txa
adc #$30
sta basbuf+6 ;the remains are the ones
;----transfer text from buffer to basbuf changing every quote to chr$(34)
bas:
ldx #$08 ;position 8 in basbuf for "putary"
lda $fa ;aryprn: skip buffer
cmp #$04
beq out2
bas2: ;position 3 in basbuf for "strout"
lda #$b2 ;"=" put equal token in basbuf
sta basbuf,x
inx
;--------lda #22 ;'"' put quote in basbuf
;--------here I made an error. The "$" before 22 was left out. Pointed out by Stiggity, thanks.
lda #$22 ; put quote ' " ' in basbuf
sta basbuf,x
inx
ldy #$00
tr1:
lda buffer,y
beq out ;endzero? then done.
tr2:
cmp #$22 ;is it a quote?
bne tobasb
sty $02 ;
tya
bne mid ;qoute on first position?
dex
ldy #$02 ;then skip first two chars of quote-string
bne tr3
mid:
ldy #$00 ;put quote string in basbuf:"+chr$(34)+", token for chr$=$c7
tr3:
lda quote,y
sta basbuf,x
inx
iny
cpy #09 ;quote string has length 9
bne tr3
ldy $02
iny
lda buffer,y ;quote on last position? Is position of quote +1 the end zero?
bne tr2
dex ;yes then skip last two chars of quote-string
dex
bne out2
tobasb:
sta basbuf,x ;copy byte from buffer to basbuf
inx
iny
bne tr1
out:
lda #$22 ;'"' put quote in basbuf
sta basbuf,x
inx
out2:
lda #$00 ;"0" put endzero in basbuf
sta basbuf,x
;----
lda $fa
cmp #$03
bcc let
;----perform PRINT ($555b) on basbuf
ldx #>print
ldy #<print
bne basexe
;----perform LET ($53c6) on basbuf
let:
ldx #<let
ldy #>let
;----execute basic statement in basbuf
basexe:
lda $3e ;save basictextpointer
pha
lda $3d
pha
lda #<basbuf ;set basictextpointer to basbuf
sta $3d
lda #>basbuf
sta $3e
lda #$0f ;jsrfar to x,y (low,high)
sta $02
sty $03
stx $04
jsr $ff6e
pla ;restore basictextpointer
sta $3d
pla
sta $3e
rts
;----
quote dat $22,$aa,$c7,$28,$33,$34,$29,$aa,$22 ;"+chr$(34)+"
array dat $28,$2f,$2f,$2f,$29 ;(xxx)