10
20
40 HW%=1
50 MODE&87:A%=HIMEM-LOMEM-20480:IFA%<0:PAGE=PAGE+A%:CHAIN$&600
60 MODE&82:DIMR%19,G%19,B%19,L%15:F$="":pal%=0:osb=&FFF4:wd%=20
70 PROCreset:PROCclr:PROCHELP
90 sm%=0:ONERROR:PROCclr:PRINTTAB(0,26);:REPORT:A%=INKEY(200):IFsm%:PROCload
100 C=0:REPEAT:PROCscrn:PRINT'CHR$8;:wd%=POS+1:PROCclr
110 IFF$<>"":PRINTTAB(0,26);SPCwd%;TAB(0,26);LEFT$(F$,wd%);
120 REPEAT:VDU23,1;0;0;0;0:REPEAT:REPEAT:N=L%?C
130 PRINTTAB(0,27);"COL:";~C;" R:"FNd(R%?N)" G:"FNd(G%?N)" B:"FNd(B%?N);
140 C$=GET$:U%=2*(INKEY-1)+1:IFC$>"_":C$=CHR$(ASCC$AND&DF)
150 IFC$=",":C=(C-1)AND15
160 IFC$=".":C=(C+1)AND15
170 UNTILINSTR(",.",C$)=0
180 IFC$="R":R%?N=R%?N+U%:IF(R%?N)AND-16:R%?N=R%?N-U%
190 IFC$="G":G%?N=G%?N+U%:IF(G%?N)AND-16:G%?N=G%?N-U%
200 IFC$="B":B%?N=B%?N+U%:IF(B%?N)AND-16:B%?N=B%?N-U%
210 IFINSTR("RGB",C$):PROCrgb(N,R%?N,G%?N,B%?N)
220 UNTILINSTR("CDLSPHQ*",C$):PROCclr
230 IFC$="C":INPUT"COLOUR: ";:C=GET:C=((CAND15)-9*(C>64))AND15
240 IFC$="D":PRINT"DEFAULT";:PROCreset
250 UNTILINSTR("LSPHQ*",C$)
260 IFC$="H":PROCHELP
270 IFC$="*":PROCCMD
280 IFC$="L":PROCLOAD
290 IFC$="S":PROCSAVE
300 IFC$="P":PROCPALL
310 UNTILC$="Q":END
330 DEFPROCmem(S%):DIMA%-1:IFHIMEM-A%-1024>S%:mem%=A%+512ELSEmem%=HIMEM
340 ENDPROC
350 DEFPROCclr:VDU26,23,1,1;0;0;0;:PRINTTAB(0,27);SPCwd%;TAB(0,27);:ENDPROC
360 DEFPROCerr(A$):PROCmsg(A$):A%=INKEY(200):ENDPROC
370 DEFPROCmsg(A$):PRINTTAB(0,27);SPCwd%;TAB(0,27);A$;:ENDPROC
380 DEFPROCreset:FORA%=0TO15:L%?A%=A%:R%?A%=15*(A%AND1):G%?A%=7.5*(A%AND2):B%?A%=3.75*(A%AND4):NEXT:R%!16=&F000000:G%!16=&F00:B%!16=&80F00:PROCclrs:VDU20:ENDPROC
390 DEFPROCclrs:FORA%=0TO15:PROCrgb(A%,R%?A%,G%?A%,B%?A%):NEXT:ENDPROC
400 DEFPROCload:IFF$<>"":IFsm%ORmem%=HIMEM:CLS:OSCLI"LDPIC "+F$:PROCclrs
410 ENDPROC
430 DEFPROCHELP:VDU23,1;0;0;0;0:PRINT"Colour RGB Default <> Load Save Palette"SPC(-(wd%>40))"Help Quit *"SPC(wd%-POS);:A%=GET:PROCclr:ENDPROC
450 DEFPROCCMD:VDU28,0,27,wd%-1,0:REPEATINPUTLINE"*"A$:sm%=TRUE:OSCLIA$
460 PRINT":";:C$=CHR$(GETAND&DF):VDU127:UNTILC$<>CHR$10:VDU26:PROCclr
470 IFINSTR("LSP",C$)=0:PROCload
480 ENDPROC
500 DEFPROCLOAD:INPUTLINE"LOAD: "A$
510 in%=OPENIN(A$):IFin%=0:PROCerr("File not found"):ENDPROC
520 ext%=EXT#in%:CLOSE#in%:in%=0:PROCmem(ext%):OSCLI"LOAD "+A$+" "+STR$~mem%
530 PROCmsg("Scanning"):IFFNscan=0:PROCerr("Not a LDPIC file"):ENDPROC
540 pal%=ptr%:ptr%=2:bits%=0:FORA%=15TO0STEP-1:L%?A%=FNget(4):NEXT
550 IFpal%<ext%:ptr%=pal%:FORA%=15TO0STEP-1:R%?A%=FNget(4):G%?A%=FNget(4):B%?A%=FNget(4):NEXTELSEPROCreset
560 OSCLI"LDPIC "+A$:F$=A$:ENDPROC
580 DEFPROCSAVE:IFF$="":PROCerr("No file"):ENDPROC
590 INPUTLINE"SAVE: "A$:OSCLI"LOAD "+F$+" "+STR$~mem%:ptr%=pal%
600 FORA%=15TO0STEP-2:mem%?ptr%=FNr(R%?A%)*16+FNr(G%?A%)
610 mem%?(ptr%+1)=FNr(B%?A%)*16+FNr(R%?(A%-1))
620 mem%?(ptr%+2)=FNr(G%?(A%-1))*16+FNr(B%?(A%-1)):ptr%=ptr%+3:NEXT
630 OSCLI"SAVE "+A$+" "+STR$~mem%+"+"+STR$~(pal%+24)+" 0 FFFFFD00"
640 F$=A$:PROCload:ENDPROC
660 DEFPROCPALL:PRINT"PALETTE ";:T%=GETAND&DF:IFINSTR("LS",CHR$T%)=0:ENDPROC
670 T%=T%=76:IFT%:PRINT"LOAD";ELSEPRINT"SAVE";
680 INPUTLINE": "A$:ch%=0:IFT%:ch%=OPENIN(A$):IFch%=0:PROCerr("File not found"):ENDPROC
690 IFch%:sz%=EXT#ch%:CLOSE#ch%:ch%=0:IFsz%>128:PROCerr("Not palette file"):ENDPROC
700 PROCPAL2:PROCload:ENDPROC
710 DEFPROCPAL2:PROCmem(128):ptr%=mem%:IFT%:OSCLI"LOAD "+A$+" "+STR$~ptr%:IF?ptr%<>19:PROCerr("Not palette file"):ENDPROC
720 IFNOTT%:FORA%=0TO19:?ptr%=19:ptr%?1=A%AND15:ptr%?2=16+(A%AND16)DIV2-(A%>16):ptr%?3=R%?A%*17:ptr%?4=G%?A%*17:ptr%?5=B%?A%*17:ptr%=ptr%+6:NEXT:OSCLI"SAVE "+A$+" "+STR$~mem%+" "+STR$~ptr%+" 0 FFFFED00":ENDPROC
730 FORA%=1TOsz%DIV6:IFptr%?1=16:C%=ptr%?2
740 IFptr%?1<16:C%=ptr%?1:IFptr%?2<>16:C%=16
750 IFC%<16:R%?C%=(ptr%?3)DIV16:G%?C%=(ptr%?4)DIV16:B%?C%=(ptr%?5)DIV16:PROCrgb(C%,R%?C%,G%?C%,B%?C%)
760 ptr%=ptr%+6:NEXT:ENDPROC
780 DEFPROCrgb(I%,D%,E%,F%):LOCALA%,X%,Y%,O%
790 IFHW%=0:VDU19,I%,16,D%*16,E%*16,F%*16:ENDPROC
800 IFHW%=1:A%=151:X%=35:Y%=I%*16+D%:CALLosb:Y%=E%*16+F%:CALLosb:VDU19,I%,L%?I%;0;19,E%,L%?E%;0;:ENDPROC
810 X%=96:Y%=&E0+I%:CALLosb:Y%=D%EOR15:CALLosb:Y%=(E%EOR15)+64:CALLosb:Y%=(F%EOR15)+128:CALLosb:ENDPROC
830 DEFPROCscrn
840 A%=135:A%=((USRosb)AND&FF0000)DIV65536
850 dx%=VALMID$("7264487264486464",2*A%+1,2)
860 VDU5:FORA%=0TO15:GCOL0,A%:MOVE160*(A%AND7),127-(A%DIV8)*64:PLOT0,0,-63
870 PLOT81,159,0:PLOT0,0,63:PLOT81,-159,0
880 GCOL0,7-(A%AND7):MOVE160*(A%AND7)+dx%,108-(A%DIV8)*64:PRINT;~A%;
890 NEXT:VDU4:ENDPROC
910 DEFFNd(A%)=LEFT$(STR$A%+" ",2)
920 DEFFNrev(A%):=FNr(A%DIV16)+16*FNr(A%AND15)
930 DEFFNr(A%):=VALMID$("00080412021006140109051303110715",A%*2+1,2)
940 DEFFNbit:IFbits%=0:data%=mem%?ptr%:ptr%=ptr%+1:bits%=8
950 data%=data%*2:bits%=bits%-1:=data%AND256
960 DEFFNget(N%):LOCALA%,B%:FORB%=1TON%:A%=(A%DIV2)ORFNbit:NEXT
970 REPEATA%=A%DIV2:N%=N%+1:UNTILN%>8:=A%
990 DEFFNscan
1000 dw%=FNrev(mem%?0):mode%=FNrev(mem%?1)AND7
1010 stp%=FNrev(mem%?10):cw%=FNrev(mem%?11):bits%=0
1020 num%=256*EVAL("&"+MID$("5050504028282004",mode%*2+1,2))
1030 IFdw%=0ORdw%>8ORcw%=0ORcw%>8ORstp%>8:=0
1040 PROCmc:!addr=mem%+12:!num=num%:?dw=dw%:?cw=cw%
1050 CALLscan:ptr%=!addr-mem%:IFptr%<ext%-32ORptr%>ext%:=0
1060 =TRUE
1080 DEFPROCmc:mc%=mc%:IFmc%:ENDPROC
1090 addr=&70:num=&72:data=&74:bits=&75:byte=&76:cw=&77:dw=&78:cnt=&79:add=&7A
1100 DIMmc%95:FORP=0TO1:P%=mc%:[OPT P*2
1110 .scan:LDY#0:STYbits
1120 .lp1:JSRbit:LDA#1:BCCnxt:LDXcw:JSRget
1130 .nxt:STAadd:LDXdw:JSRget:LDAnum:SEC:SBCadd:STAnum
1140 LDAnum+1:SBC#0:STAnum+1:ORAnum:BNElp1
1150 .alg:LDAbits:BEQret:JSRbit:JMPalg
1160 .get:STXcnt
1170 .lp2:JSRbit:RORbyte:DEX:BNElp2:LDAbyte:LDXcnt
1180 .lp3:CPX#8:BCSret:LSRA:INX:BNElp3
1190 .bit:LDAbits:BNElp4:LDA(addr),Y:STAdata:LDA#8:STAbits
1200 INCaddr:BNElp4:INCaddr+1
1210 .lp4:DECbits:ASLdata:.ret:RTS:]:NEXT:ENDPROC