10
20
30
40 :
50 MODE&87:PRINT" Collect *Commands into a ROM"'
60 DIM mcode% &3FFF, ctrl% 31, name% 79:X%=ctrl%:Y%=X%DIV256
70 OSNEWL=&FFE5:OSASCI=&FFE3:OSBYTE=&FFF4
80 zp0=&A8:zp1=zp0+1:zp2=zp0+2:zp3=zp0+3
90 zp4=zp0+4:zp5=zp0+5:zp6=zp0+6:zp7=zp0+7
100 :
110 INPUT"ROM title: "title$
120 INPUT"ROM version number: &"A$:version%=EVAL("&"+A$)
130 INPUT"ROM version string: "version$
140 INPUT"ROM copyright string: (C)"copyright$:copyright$="(C)"+copyright$
150 INPUT"ROM help string: "help$
160 :
170 PROCROMHeader:PRINT
180 PRINT"Enter filenames, terminated with RETURN":REPEAT
190 PRINT"Space left: &";~mcode%+&4000-here%;" (";mcode%+&4000-here%;" bytes)"
200 INPUT"File: "f$:IF f$<>"" PROCROMAdd
210 UNTILf$="" OR here%>mcode%+&3FFE:here%=here%+1
220 INPUT"Save filename: "f$
230 IFf$<>"":PRINT"Saving";:OSCLI"Save "+f$+" "+STR$~mcode%+" "+STR$~here%+" 8000 8000"
240 PRINT
250 END
260 :
270 DEFPROCROMHeader
280 FORP=0TO1:P%=&8000:O%=mcode%
290 [OPT P*2+4
300 BRK:BRK:BRK
310 .L8003:JMP L801C
320 .L8006:EQUB &82
330 .L8007
340 EQUB Copyright-&8000
350 EQUB version%:EQUS title$
360 EQUS LEFT$(CHR$0+version$,version$<>"")
370 .Copyright
380 EQUB 0:EQUS copyright$:EQUB 0
390 :
400 .L8015
410 CLC:BCC L801C :\ Marks entry for *RLIST
420 EQUW L8149 :\ Pointer to HELP string
430 EQUW L814F :\ Pointer to commands
440 :
450 .L801C
460 PHA:TYA:PHA
470 TSX:LDA &0102,X
480 CMP #&09:BNE L806C
490 :
500 \ *Help
510 JSR OSNEWL
520 LDA L8003+1:CLC:ADC #&03:STA zp2
530 LDA L8003+2:ADC #&00:STA zp3:\ (zp2)=>pointer to Help string
540 LDY #&00:LDA (zp2),Y:STA zp0
550 INY:LDA (zp2),Y:STA zp1:\ (zp0)=>Help string
560 LDY #&00
570 .L804D
580 LDA (zp0),Y:BEQ L8062
590 CMP #&23:BNE L8057
600 LDA #&0D
610 .L8057
620 JSR OSASCI
630 INC zp0:BNE L804D
640 INC zp1:BNE L804D
650 .L8062
660 JSR OSNEWL
670 :
680 .L8065
690 LDX &F4:PLA:TAY:PLA
700 RTS
710 :
720 .L806C
730 CMP #&04:BNE L8065
740 :
750 \ *Command
760 STY zp5
770 LDA L8003+1:CLC:ADC #&05:STA zp0
780 LDA L8003+2:ADC #&00:STA zp1:\ (zp0)=>pointer to commands
790 LDY #&00:LDA (zp0),Y:STA zp2
800 INY:LDA (zp0),Y:STA zp3:\ (zp2)=>commands
810 .L8090
820 LDA zp2:STA zp0
830 LDA zp3:STA zp1
840 LDA zp5:STA zp4
850 .L809C
860 LDY #&00:LDA (zp0),Y
870 BEQ L8065:BMI L80D4
880 LDY zp4:CMP (&F2),Y:BEQ L80B0
890 EOR #&20:CMP (&F2),Y:BNE L80BB
900 .L80B0
910 INC zp4
920 INC zp0:BNE L80B8:INC zp1
930 .L80B8
940 CLC:BCC L809C
950 :
960 .L80BB
970 LDY #&00
980 .L80BD
990 INC zp0:BNE L80C3:INC zp1
1000 .L80C3
1010 LDA (zp0),Y:BPL L80BD
1020 INY:LDA (zp0),Y:STA zp2
1030 INY:LDA (zp0),Y:STA zp3
1040 CLC:BCC L8090
1050 :
1060 .L80D4
1070 PHA:LDX #&00
1080 .L80D6
1090 INY:LDA (zp0),Y:STA zp2,X
1100 INX:CPX #&06:BNE L80D6:\ zp2/3=>next, zp4/5=load, zp6/7=exec
1110 PLA:PHA:CMP #&FE:BNE L80E0
1120 LDA #&83:JSR OSBYTE:\ Read OSHWM
1130 STX zp4:STY zp5
1140 .L80E0
1150 LDA zp0:CLC:ADC #&07:STA zp0
1160 LDA zp1:ADC #&00:STA zp1:\ zp0=>data
1170 LDY #&00
1180 .L80EF
1190 LDA (zp0),Y:STA (zp4),Y:\ Copy data
1200 INC zp0:BNE L80F9:INC zp1
1210 .L80F9
1220 INC zp4:BNE L80FF:INC zp5
1230 .L80FF
1240 LDA zp2:CMP zp0:BNE L80EF
1250 LDA zp3:CMP zp1:BNE L80EF
1260 PLA:CMP #&FE:BEQ L8114:\ BASIC
1270 JSR JumpMC
1280 PLA:PLA:LDA #&00:RTS:\ Claim
1290 .JumpMC
1300 JMP (zp6)
1310
1320 .L8114 :\ BASIC
1330 LDA #&8A:LDX #&00
1340 LDY #&4F:JSR OSBYTE:LDY #&4C:JSR OSBYTE
1350 LDY #&44:JSR OSBYTE:LDY #&0D:JSR OSBYTE
1360 LDY #&52:JSR OSBYTE:LDY #&55:JSR OSBYTE
1370 LDY #&4E:JSR OSBYTE:LDY #&0D:JSR OSBYTE
1380 LDA #&BB:LDX #&00:LDY #&FF:JSR OSBYTE:\ Read BASIC ROM num
1390 LDA #&8E:JMP OSBYTE:\ Enter BASIC
1400 :
1410 .L8149
1420 EQUS help$:EQUB 0
1430 .L814F
1440 \ EQUS <command name>
1450 \ EQUB &FF - M/C, &FE - BASIC
1460 \ EQUW <address of next item>
1470 \ EQUW <load address>
1480 \ EQUW <exec address>
1490 \ Contents of file
1500 \ EQUS <command name> or &00 end marker
1510 ]:NEXT:here%=O%:ENDPROC
1520 :
1530 DEFPROCROMAdd
1540 IFLEFT$(f$,1)="*":OSCLIf$:ENDPROC
1550 A%=FNfile(f$,5):IFA%<>1:PRINT"File '"f$"' not found":ENDPROC
1560 IFX%!10>(mcode%+&4000-here%):PRINT"No more space":ENDPROC
1570 INPUT"Command name: "name$
1580 PRINT"BASIC or M/C? ";:REPEATtype%=INSTR("MmBb",GET$):UNTILtype%
1590 $here%=name$:here%=here%+LENname$
1600 ?here%=255-(type%-1)DIV2:here%=here%+1
1610 !here%=here%+X%!10+6-mcode%+&8000
1620 here%!2=X%!2:here%!4=X%!6
1630 here%=here%+6
1640 OSCLI"LOAD "+f$+" "+STR$~here%
1650 here%=here%+X%!10:?here%=0
1660 ENDPROC
1670 :
1680 DEFFNfile(A$,A%):$name%=A$:?X%=name%:X%?1=name%DIV256:=(USR&FFDD)AND&FF