10
20
30 :
40 mcode%=&FFFF0900
50 OSFILE=&FFDD:OSFIND=&FFCE
60 OSBGET=&FFD7:OSARGS=&FFDA
70 Addr=&A8:Temp=&AA:Lptr=&AC
80 InitAddr=&8040:NextAddr=&8043
90 SkipToCR=&8046
100 FOR P=0 TO 1
110 P%=mcode%
120 [OPT P*3
130 .Error
140 BRK:EQUB 220:EQUS "Syntax: ADDCOM (-<rom>) <afsp> (<text>)"
150 .FileNotFound
160 BRK:EQUB 214:EQUS "File not found"
170 .BadRom
180 BRK:EQUB 254:EQUS "Bad ROM":BRK
190 .start%
200 LDA &F4:PHA
210 LDX #Lptr:LDY #0:LDA #1:JSR &FFDA
220 LDA (Lptr),Y:CMP #13:BEQ Error
230 CMP #ASC"-":BNE load_file
240 INY:LDA (Lptr),Y:CMP #ASC"A"
250 BCC get_hex:AND #&DF:SBC #7
260 .get_hex
270 AND #15:STA &F4:STA &FE30:INY
280 .load_file
290 LDA (Lptr),Y:INY:CMP #ASC" "
300 BEQ load_file:DEY
310 LDA &8040:CMP #&4C:BNE BadRom
320 TYA:CLC:ADC Lptr:STA Lptr
330 LDA Lptr+1:ADC #0:STA Lptr+1
340 LDA Lptr:STA ctrl
350 LDA Lptr+1:STA ctrl+1
360 LDX #ctrl AND255:LDY #ctrl DIV256
370 LDA #5:JSR OSFILE
380 CMP #1:BNE FileNotFound
390 LDA &8040:CMP #&4C:BNE BadRom
400 JSR InitAddr
410 .LookForEnd
420 LDA (Addr),Y:BEQ EndFound
430 JSR SkipToCR:JSR NextAddr
440 BEQ LookForEnd
450 .EndFound
460 LDA (Lptr),Y:STA (Addr),Y
470 INY:CMP #13:BNE EndFound
480 LDA ctrl+2:STA (Addr),Y:INY
490 LDA ctrl+3:STA (Addr),Y:INY
500 LDA ctrl+6:STA (Addr),Y:INY
510 LDA ctrl+7:STA (Addr),Y:INY
520 LDA ctrl+10:STA (Addr),Y:INY
530 LDA ctrl+11:STA (Addr),Y:INY
540 TYA:CLC:ADC Addr:STA Addr
550 LDA Addr+1:ADC #0:STA Addr+1
560 LDX ctrl:LDY ctrl+1:LDA #&40
570 JSR OSFIND:STA Temp+1:LDY #0
580 .LoadLoop
590 STY Temp:LDY Temp+1
600 JSR OSBGET:LDY Temp:BCS End
610 STA (Addr),Y:INY:BNE LoadLoop
620 INC Addr+1:BNE LoadLoop
630 .End
640 LDA #0:STA (Addr),Y
650 LDY Temp+1:JSR OSFIND
660 PLA:STA &F4:STA &FE30
670 RTS
680 .ctrl
690 ]NEXT
700 PRINT"*SAVE ADDCOM ";~mcode%;" ";~P%;" ";~start%OR&FFFF0000