10
20
30
40 :
50 PROCassem(0):CLEAR:PROCassem(2):PROCsm_table
60 A$="*SAVE "+fname$+" "+STR$~(mcode%+M%)+" "+STR$~O%+" FFFF0000 FFFBBC00"
70 PRINTA$;:OSCLIA$:PRINT
80 END
90 :
100 DEFPROCassem(pass%)
110 file$ ="TEST" :
120 title$="ROMTITLE" :
130 vers$ ="0.01 (01 Jan 2015)" :
140 copy$ ="(C)J.G.Harston" :
150 :
160 ver%=VALvers$*10
170 DIM mcode% &1800,L% -1
180 OSASCI=&FFE3:OSNEWL=&FFE7:OSWRCH=&FFEE
190 :
200 FOR pass%=pass% TO pass%+1
210 opt%=FNsm_pass(pass%)
220 [OPT opt%
230 .RomStart
240 BRK:EQUW RelocTable
250 JMP Service
260 EQUB &82:EQUB Copyright-RomStart
270 .RomTitle
280 EQUB ver%:EQUS title$
290 EQUB &00 :EQUS vers$
300 .Copyright
310 EQUB &00:EQUS copy$
320 EQUB &00
330 :
340 .Service
350 CMP #4:BEQ Serv4 :\ *command
360 CMP #9:BNE NotServ9 :\ Not *Help
370 LDA (&F2),Y
380 CMP #13:BNE Serv9Skip :\ Not *Help <cr>
390 JSR OSNEWL:LDX #0
400 .Serv9Lp
410 LDA RomTitle+1,X :\ Print ROM title
420 BNE P%+4:LDA #ASC" " :\ Convert &00 to <spc>
430 CMP #ASC"(":BEQ Serv9Done :\ End at '('
440 JSR OSWRCH:INX:BNE Serv9Lp
450 .Serv9Done
460 JSR OSNEWL
470 .Serv9Skip
480 LDA #9
490 .NotServ9
500 RTS
510 :
520 .Serv4
530 TYA:PHA:DEY:LDX #&FF
540 .Serv4Lp
550 INX:INY:LDA (&F2),Y
560 CMP #ASC".":BEQ Serv4Dot
570 CMP #ASC"!":BCC Serv4End
580 CMP RomTitle+1,X:BEQ Serv4Lp :\ Match with ROM title
590 EOR #&20 :\ Change case
600 CMP RomTitle+1,X:BEQ Serv4Lp :\ Match with ROM title
610 .Serv4Quit
620 PLA:TAY :\ Restore Y
630 .Serv4Exit
640 LDA #4:RTS :\ Restore A and return unclaimed
650 .Serv4End
660 LDA RomTitle+1,X:BNE Serv4Quit
670 DEY
680 .Serv4Dot
690 INY:LDA (&F2),Y :\ Step past '.'
700 CMP #ASC" ":BEQ Serv4Dot :\ Skip any spaces
710 PLA :\ Drop saved Y
720 :
730 \ (&F2),Y => any parameters
740 :
750 \ Demo code, just print the command line
760 .DemoLp
770 LDA (&F2),Y:JSR OSASCI
780 INY:CMP #13:BNE DemoLp
790 :
800 :
810 LDA #0:RTS :\ Claim call and return
820 ]:RelocTable=P%
830 NEXT:ENDPROC
840 :
850 DEFFNsm_pass(pass%)
860 IFpass%=0:M%=0
870 IFpass%=1:M%=O%-mcode%
880 P%=&8100-128*(pass%AND2)
890 O%=mcode%+M%*(pass%AND2)DIV2
900 IFpass%=1:IF O%+M%*2.125>L%:PRINT"Code overrun":END
910 =VALMID$("4647",pass%+1,1)
920 :
930 DEFPROCsm_table
940 base80%=mcode%+M%:base81%=mcode%:byte%=0:count%=0:off%=0:REPEAT
950 byte80%=base80%?off%:byte81%=base81%?off%:IF off%>=M%:byte80%=&80:byte81%=&80
960 IF ((byte81%-byte80%) AND &FE)<>0 THEN PRINT "ERROR: Offset by more than one page at &";~&8000+off%
970 IF (byte80% AND &C0)=&80:byte%=byte%DIV2+128*(byte81%-byte80%):count%=count%+1
980 IF count%=8:?O%=byte%:O%=O%+1:byte%=0:count%=0
990 off%=off%+1:UNTILoff%>=M% AND count%=0
1000 ENDPROC