10
20
30
40 :
50 max%=HIMEM-TOP-2048:DIMctrl%20,mem%max%:X%=ctrl%:Y%=X%DIV256
60 in%=0:out%=0:INPUT"JSW file to split: "f$
70 in%=OPENIN(f$):IFin%=0:PRINT"'"f$"' not found":END
80 ON ERROR IFFNerr:END
90 ext%=EXT#in%:IF(ext%AND&FF)=&1B:base%=&421B ELSE ext%=ext%AND&3FFF:IFext%=&8000:base%=&200 ELSE base%=0
100 PROCsave("CODE",&8200,&9B00,&8400)
110 PROCsave("Sprites0",&9B00,&AB00,0)
120 PROCsave("Sprites128",&AB00,&C000,0)
130 PROCsave("Objects",&A3FF,&A600,0)
140 PROCsave("Rooms",&C000,&10000,0)
150 CLOSE#in%:in%=0:END
160 :
170 DEFFNerr:REPORT:IFin%:A%=in%:in%=0:CLOSE#A%
180 IFout%:A%=out%:out%=0:CLOSE#A%
190 PRINT:=TRUE
200 :
210 DEFPROCsave(A$,St%,En%,Ex%):Len%=En%-St%
220 IFSt%-&8200+base%>EXT#in% OR En%-&8200+base%>EXT#in%:ENDPROC
230 PRINT"Saving "A$;
240 PTR#in%=St%-&8200+base%:IFLen%<=max%:PROCrd(Len%) ELSE PROCrd(max%)
250 OSCLI"SAVE "+A$+" "+STR$~mem%+"+"+STR$~Len%+" "+STR$~(Ex%OR&FFFF0000)+" "+STR$~(St%OR&FFFF0000):IFLen%<=max%:PRINT:ENDPROC
260 Num%=max%:out%=OPENOUT(A$):PROCwr(Num%):REPEAT
270 Len%=Len%-Num%:Num%=Len%:IFLen%>max%:Num%=max%
280 PROCrd(Num%):UNTILNum%<=max%:CLOSE#out%:out%=0:PRINT:ENDPROC
290 :
300 DEFPROCrd(Num%):X%?0=in%:X%!1=mem%:X%!5=Num%:X%!9=PTR#in%:A%=4:CALL&FFD1
310 ENDPROC
320 :
330 DEFPROCwr(Num%):X%?0=out%:X%!1=mem%:X%!5=Num%:X%!9=PTR#in%:A%=2:CALL&FFD1
340 ENDPROC