10REM > AS/SRC
20REM J.G.Harston, 15-Feb-1990
30REM Save BASIC program with embedde
d filename
40REM Demonstrates writing code in BA
SIC workspace
50REM Up to 256 bytes will fit in str
ing buffer at &600-&6FF
60:
70REM Based on CSAVER, Micro User, Ap
r 1988
80REM and *AS, Micro User, No
v 1989
90:
100DIM mcode% &200 :REM memory to as
semble to
110load%=&600 :REM Address to l
oad to
120osbyte=&FFF4
130ptr=&70:cr=&0D:rem=&F4
140FOR L%=4 TO 7 STEP 3
150P%=load%:O%=mcode%
160[OPT L%
170.exec%
180½ Header identifies this as 6502 co
de
190JMP start:BRK:BRK:BRK :½ Entr
y point
200EQUB &42:EQUB copy-exec% :½ &42=
6502 code
210EQUB &01:EQUS "AutoSave" :½ Titl
e
220EQUB &00:EQUS "1.00 (15 Feb 1990)"
230.copy
240EQUB &00:EQUS "(C) J.G.Harston"
250EQUB &00
260
270.start
280½ Check that BASIC is the current l
anguage
290LDA #187:JSR rdbyte:STA ptr :½ Read
BASIC ROM number
300LDA #252:JSR rdbyte:CMP ptr :½ Read
current language ROM number
310BEQ basicok :½ They
match
320BRK:EQUB 249:EQUS "Not in BASIC":BR
K
330.rdbyte
340LDX #0:LDY #255:JSR osbyte :½ Read
an OSBYTE variable
350TXA:AND #63:RTS :½ Retu
rn it in X without b7-b6
360
370.basicok
380LDA #21:LDX #0:JSR osbyte :½ Clea
r keyboard buffer
390LDA &18:STA ptr+1
400LDY #0:STY ptr+0 :½ ptr=
>PAGE
410LDA (ptr),Y
420CMP #13:BNE noprog :½ No p
rogram in memory
430INY:LDA (ptr),Y
440CMP #&FF:BEQ noprog :½ Empt
y program
450LDY #3
460.remloop
470INY:LDA (ptr),Y :½ Get
byte from line
480CMP #cr:BEQ norem :½ Foun
d <cr>, no REM
490CMP #rem:BNE remloop :½ Loop
until REM found
500.spaceloop
510INY:LDA (ptr),Y
520CMP #32:BEQ spaceloop :½ Step
past any spaces
530CMP #ASC">":BEQ foundname :½ REM
> filename
540CMP #34:BEQ foundname :½ REM
"filename
550DEY :½ No p
refix, step back
560.foundname
570TYA:PHA:LDX #0 :½ Reme
mber offset to filename
580.loop
590LDY save,X:JSR osbyte138 :½ Inse
rt characters from
600INX:CPX #4:BNE loop :½ DELE
TEBGET <quote>
610PLA:TAY :½ Get
back offset to filename
620.getname
630INY:TYA:PHA:LDA (ptr),Y :½ Get
filename character
640CMP #cr:BEQ addcr :½ End
of line
650CMP #34:BEQ addcr :½ Term
inating quote
660TAY:JSR osbyte138 :½ Inse
rt the character
670PLA:TAY:BNE getname
680.addcr
690PLA
700LDY #34:JSR osbyte138 :½ Inse
rt terminating quote
710LDY #cr :½ Inse
rt <cr>
720.osbyte138
730TXA:PHA :½ Save
X
740LDA #138:LDX #0:JSR osbyte :½ Inse
rt Y into kbd buffer
750PLA:TAX:RTS :½ Rest
ore X
760.noprog
770BRK:BRK:EQUS "No program"
780.norem
790BRK:BRK:EQUS "No REM"
800BRK
810.save
820EQUS "SA."""
830]:NEXT
840A$="*SAVE AS "+STR$÷mcode%+" "+STR$
÷O%+" "+STR$÷exec%+" "+STR$÷load%
850PRINTA$;:OSCLIA$:PRINT