10
20
30 :
40 OSBYTE=&FFF4:OSARGS=&FFDA
50 OSFIND=&FFCE:OSFILE=&FFDD
60 OSBPUT=&FFD4:OSWORD=&FFF1
70 addr=&AA
80 mcode%=&FFFF08C0
90 :
100 FOR P=0 TO 1
110 P%=mcode%
120 [OPT P*3
130 .palette
140 .error
150 BRK:EQUB 220:EQUS "Syntax: ScrSave <fsp>":BRK
160 .start%
170 LDA #1:LDY #0:LDX #&A8
180 JSR OSARGS
190 LDA (&A8),Y:CMP #13:BEQ error
200 LDA &A8:STA blk:LDA &A9:STA blk+1
210 LDA #0:LDX #255:JSR OSBYTE
220 CPX #2:BEQ notShad:BCS Master
230 LDA #34:LDX #128:JSR OSBYTE
240 LDA #111:LDX #128:JSR OSBYTE
250 LDA #1:BNE notShad
260 .Master
270 LDA &D0:AND #16:BEQ notShad
280 LDA #108:LDX #1:JSR OSBYTE
290 LDA #2
300 .notShad
310 STA ScrFlag
320 \LDA #135:\JSR OSBYTE:\\STY blk+6
330 LDY &355
340 LDA himems,Y:STA blk+11:STA addr+1
350 TYA:LDX #6:LDY #3:JSR pall1
360 LDA &360:CMP #4:BCC less4
370 LDA #3:LDX #2:LDY #7:JSR pall1
380 LDA #0:STA addr:JSR pall2
390 .less4
400 LDA #0:JSR try_to_save_block
410 LDA new_end+1:BPL shorter
420 LDA #&80:STA new_end+1:LDA #0:STA new_end
430 JSR CallOsfile:JMP SaveFinish
440 .shorter
450 LDA blk+11:PHA
460 LDA #0:STA blk+8:STA blk+9
470 JSR CallOsfile:\ Create file
480 PLA:STA blk+11
490 LDX blk:LDY blk+1
500 LDA #&80:JSR OSFIND:\ Openout
510 JSR try_to_save_block
520 JSR CloseFile
530 \ Rewrite addresses
540 LDX #3:.push_lp
550 LDA blk+6,X:PHA:DEX:BPL push_lp
560 LDA #2:JSR CallOsfile
570 LDX #&FC:.pull_lp
580 PLA:STA blk+6-&FC,X:INX:BNE pull_lp
590 LDA #3:JSR CallOsfile
600 .SaveFinish
610 LDA ScrFlag:BEQ EndAll
620 CMP #2:BEQ EndMaster
630 LDA #111:LDX #192:JSR OSBYTE
640 LDA #34:LDX #192:JMP OSBYTE
650 .EndAll:RTS
660 .EndMaster
670 LDA #108:LDX #0:JMP OSBYTE
680 :
690 .CloseFile
700 LDA #0:JMP OSFIND
710 :
720 .CallOsfile
730 LDX #blk AND 255:LDY #blk DIV 256
740 JMP OSFILE
750 \
760 \ Find length and create a file
770 .try_to_save_block
780 PHA:\ Save handle
790 LDA blk+11:STA addr+1
800 STA new_end+1
810 LDA #0:STA new_end:STA addr
820 .save_loop
830 LDY #0:LDX #0:LDA (addr),Y
840 .save4
850 INC addr:BNE save5
860 INC addr+1:BMI save_end
870 .save5
880 INX:BEQ save7
890 CMP (addr),Y:BEQ save4
900 .save7
910 STA A_temp:PLA:TAY:LDA A_temp
920 JSR save_do_output:TYA:PHA
930 JMP save_loop
940 .save_end
950 STA A_temp:PLA:TAY:LDA A_temp
960 INX:JSR save_do_output
970 RTS
980 .save_do_output
990 CPY #0:BEQ save_do_out2
1000 JSR OSBPUT:TXA:JSR OSBPUT
1010 .save_do_out2
1020 LDA new_end:CLC:ADC #2
1030 STA new_end:LDA new_end+1
1040 ADC #0:STA new_end+1:RTS
1050 :
1060 .osword11
1070 LDX #palette AND 255:LDY #palette DIV 256
1080 LDA #11:JSR OSWORD
1090 LDA palette+1:RTS
1100 .pall1
1110 STA blk,X
1120 .pall1a
1130 ASL blk,X:ROL blk+1,X
1140 ASL blk,X:ROL blk+1,X
1150 ASL blk,X:ROL blk+1,X
1160 TXA:PHA:STY palette
1170 JSR osword11:PLA:TAX
1180 LDA palette+1:AND #7
1190 ORA blk,X:STA blk,X
1200 LDY palette:DEY:TYA
1210 AND #3:CMP #3:BNE pall1a:RTS
1220 :
1230 .pall2
1240 LDA #8:STA palette:.pall2lp
1250 JSR osword11:LDY #0:STA (addr),Y
1260 INC palette:JSR osword11
1270 ASL A:ASL A:ASL A:ASL A:LDY #0
1280 ORA (addr),Y:STA (addr),Y
1290 INC palette:INC addr
1300 LDA palette:CMP #16:BNE pall2lp
1310 RTS
1320 \
1330 .newbrk
1340 JSR swapbrk:JSR SaveFinish
1350 JMP (&202)
1360 :
1370 .swapbrk
1380 LDA &202:LDX oldbrk:STX &202:STA oldbrk
1390 LDA &203:LDX oldbrk+1:STX &203:STA oldbrk+1
1400 RTS
1410 :
1420 .blk
1430 EQUW 0
1440 EQUD &FFFF3000:EQUD &FFFF0000
1450 EQUD &FFFF3000
1460 .new_end
1470 EQUD &FFFF8000
1480 .himems
1490 EQUB &30:EQUB &30:EQUB &30
1500 EQUB &40:EQUB &58:EQUB &58
1510 EQUB &60:EQUB &7C
1520 .ScrFlag:EQUB 0
1530 .A_temp:EQUB 0
1540 .oldbrk
1550 EQUW newbrk
1560 EQUS "v1.06":BRK
1570 ]NEXT
1580 PRINT"*SAVE ScrSave ";~mcode%;" ";~P%;" ";~start%OR&FFFF0000