10
20
30
40 OSARGS=&FFDA:OSFIND=&FFCE
50 OSBGET=&FFD7:OSBYTE=&FFF4
60 OSFILE=&FFDD:OSWRCH=&FFEE
70 mcode%=&FFFF0900
80 :
90 lptr=&A8:colour=&A8:
100 handle=&A8
110 addr=&AA:
120 mode=&AA
130 ScrFlag=&AC:addbyte=&AD
140 :
150 FOR P=0 TO 1
160 P%=mcode%
170 [OPT P*3
180 .ctrl
190 .errSyntax
200 BRK:EQUB 220:EQUS "Syntax: ScrLoad <afsp>"
210 .errNotFound
220 BRK:EQUB 214:EQUS "File not found":BRK
230 :
240 .start%
250 LDA #1:LDY #0:LDX #lptr:JSR OSARGS
260 LDA (lptr),Y:CMP #13:BEQ errSyntax
270 LDA lptr:STA ctrl:LDA lptr+1:STA ctrl+1
280 LDA #5:JSR DoOsfile:CMP #1:BNE errNotFound
290 :
300 TAX:LDA #0:JSR OSBYTE :\ Get MOS type
310 TXA:PHA:LDA #135:JSR OSBYTE :\ Get screen mode
320 LDA ctrl+7
330 LSR A:LSR A:LSR A:LSR A:STA mode
340 PLA:TAX:CPY mode:BEQ ModeSame :\ Same mode, don't change mode
350 LDA #22:JSR OSWRCH
360 LDA #0:CPX #2:BEQ ModeSelect :\ B+, don't use shadow mode
370 LDA &D0:ASL A:ASL A:ASL A:AND #128
380 .ModeSelect
390 ORA mode:JSR OSWRCH :\ Change screen mode
400 .ModeSame
410 CPX #2:BEQ NotShad:BCS Master
420 LDA #34:JSR osbyte128
430 LDA #111:JSR osbyte128
440 LDA #1:BNE NotShad
450 .Master
460 LDA &D0:AND #16:BEQ NotShad
470 LDA #108:LDX #1:JSR OSBYTE
480 LDA #2
490 .NotShad
500 STA ScrFlag
510 LDX mode:LDA himems,X:PHA:TAY :\ Push HIMEMhi
520 LDA ctrl+9:BEQ ld_compr
530 LDX #0:STX ctrl+2:STX ctrl+6
540 STY ctrl+3
550 DEX:STX ctrl+4:STX ctrl+5
560 TXA:JSR DoOsfile
570 JMP set_palette
580 .DoOsfile
590 LDX #ctrl AND 255:LDY #ctrl DIV 256:JMP OSFILE
600 :
610 \ Now actually load the compressed file:
620 .ld_compr
630 STA addr:STY addr+1 :\ Screen start
640 LDA ctrl+8:CMP #2:BCC ld_off
650 LDA #7:.ld_off:STA addbyte :\ Offset between bytes-1
660 LDX ctrl+0:LDY ctrl+1:LDA #&40
670 JSR OSFIND:STA handle :\ Open file
680 :
690 LDA addr+1:PHA:LDA addr:PHA
700 .ld_lp
710 LDY handle:BIT &FF:BMI ld_end2
720 JSR OSBGET:BCS ld_end2
730 PHA:JSR OSBGET:BCS ld_end
740 TAX:PLA:.ld_lp2
750 LDY #0:STA (addr),Y:TAY
760 \ Now inc pointer by required amount
770 LDA addbyte:SEC:ADC addr:STA addr
780 LDA addr+1:ADC #0:STA addr+1
790 BPL no_overflow
800 \ Wrap back to beginning
810 PLA:STA addr:PLA:STA addr+1:PHA
820 INC addr:LDA addr:PHA
830 .no_overflow
840 TYA:DEX:BNE ld_lp2:BEQ ld_lp
850 :
860 .ld_end
870 PLA
880 .ld_end2
890 PLA:PLA:\ Screen address
900 LDA #0:JSR OSFIND
910 :
920 .set_palette
930 PLA:STA addr+1:LDX #0:STX addr:\ Start of screen
940 LDA ctrl+6:STA colour:LDA ctrl+7:STA colour+1
950 LDY &360:\ ?&360=num of colours
960 .pal_lp
970 JSR vdu19:LDA colour:AND #7:JSR OSWRCH
980 JSR vdu0:JSR divide8
990 INX:CPX #8:BEQ pal8
1000 CPX #4:BNE pal4
1010 LDA ctrl+2:STA colour:LDA ctrl+3:STA colour+1
1020 .pal4
1030 DEY:BPL pal_lp:BMI pal_end
1040 .pal8
1050 DEY:BMI pal_end
1060 DEX:LDY #0
1070 .pal8lp
1080 JSR vdu19x:LDA (addr),Y:AND #15:JSR OSWRCH
1090 JSR vdu0:JSR vdu19x:LDA (addr),Y
1100 LSR A:LSR A:LSR A:LSR A:JSR OSWRCH:JSR vdu0
1110 INY:CPX &360:BCC pal8lp
1120 TYA:CLC:ADC addr:STA colour
1130 LDA addr+1:STA colour+1:DEY
1140 .pal16lp
1150 LDA (colour),Y:STA (addr),Y
1160 DEY:BPL pal16lp
1170 .pal_end:\ Screen Off
1180 LDA ScrFlag:BEQ EndAll
1190 CMP #2:BEQ EndMaster
1200 LDA #111:JSR osbyte192
1210 LDA #34:BNE osbyte192
1220 .EndMaster
1230 LDA #108:LDX #0:BEQ CallOsbyte
1240 :
1250 .divide8
1260 ROR colour+1:ROR colour
1270 ROR colour+1:ROR colour
1280 ROR colour+1:ROR colour
1290 .EndAll
1300 RTS
1310 :
1320 .vdu19x
1330 INX
1340 .vdu19
1350 LDA #19:JSR OSWRCH
1360 TXA:JMP OSWRCH
1370 .vdu0
1380 LDA #0:JSR OSWRCH:JSR OSWRCH:JMP OSWRCH
1390 .osbyte192:LDX #192:BNE CallOsbyte
1400 .osbyte128:LDX #128
1410 .CallOsbyte:JMP OSBYTE
1420 :
1430 .himems
1440 EQUB &30:EQUB &30:EQUB &30
1450 EQUB &40:EQUB &58:EQUB &58
1460 EQUB &60:EQUB &7C
1470 EQUS "v1.08"
1480 BRK
1490 ]NEXT
1500 PRINT"*SAVE ScrLoad ";~mcode%;" ";~P%;" ";~start%OR&FFFF0000