"ô > Crunch/s v1.05 08-Dec-2016 ô Crunch Basic Program Bô v1..0 02-Aug-1999 JGH: Start by dropping REMs - WOW, FAST!!! (9ô v1.01 18-Aug-1999 JGH: Remove colons and null lines 2?ô v1.02 20-Sep-1999 JGH: Remove | comments at start of line <9ô v1.03 15-Feb-2000 JGH: Move code to BASIC workspace F<ô Skips leading spaces and colons PAô Skips spaces before and after tokens Z7ô Removes assembler comments d8ô v1.04 07-Dec-2016 JGH: Skips embedded line numbers n8ô v1.05 08-Dec-2016 JGH: Strips assembler ; comments x: ‚$ver$="1.05 (08-Dec-2016)":ver%=5 Œ0lptr=&70:dptr=&72:tmpX=&74:tmpY=&75:flag=&76 –+lomem=&00:vartop=&02:top=&12:PageHi=&18  &TknREM=&F4:TknTHEN=&8C:TknELSE=&8B ªosbyte=&FFF4 ´: ¾Þ mcode% &200:load%=&0500 Èã P=0 ¸ 1:opt%=P*2+4 ÒP%=load%:O%=mcode% Ü [OPT opt% æ .exec% ð5JMP start:BRK:BRK:BRK :\ Header identifies ú5EQUB &62 :EQUB copy-exec% :\ this as 6502 code 0EQUB ver%:EQUS "Crunch" :\ Program name 3EQUB &00 :EQUS ver$ :\ Program version  .copy "*EQUB &00 :EQUS "(C)J.G.Harston":EQUB 0 ,EQUD load% 6: @ .start J*TSX:LDY &102,X:INY:CPY #&F9:BCC NoTube T@LDA &103,X:STA &EE:STA &F2 :\ Restore caller's environment ^LDA &104,X:STA &EF:STA &F3 h .NoTube rCLDA #187 :\ Check BASIC is current language | .ChkBasic †'STX lptr:LDX #0:LDY #255:JSR osbyte ‚ #71:CMP #187:BNE ChkBasic š'TXA:‚ lptr:€ #63:BEQ RunningInBasic ¤(BRK:EQUB 249:EQUS "Not in BASIC":BRK ®: ¸.RunningInBasic Â>LDA #0:STA lptr+0:STA dptr+0 :\ Point to start of prog ÌDLDA PageHi:STA lptr+1:STA dptr+1 :\ Set up src and dest pointers Ö: à7\ Everything prior to here can be used as workspace ê: ô.ScanNewLine þILDY #0:LDX #0 :\ Point to start of line, clear flag 5JSR CopyChar:JSR CopyChar :\ Copy CR, NumHi 6CMP #&FF:BNE P%+5:JMP EndOfProg :\ No more program GJSR CopyChar:JSR CopyChar:PHA :\ Copy NumLo, Len, save source len &.ScanStatementStart 09DEY:LDA #0:STA flag :\ Clear statement flag :.ScanStatement DINY:LDA (lptr),Y N8CMP #—" ":BEQ ScanStatement :\ Remove leading spaces X8CMP #—":":BEQ ScanStatement :\ Remove leading colons b:CMP #TknREM:BEQ RemoveREM :\ REM marks end of line l/CMP #—"*":BNE ScanLine :\ Not *command v.CopyCommand €JSR CopyChar Š8CMP #13:BNE CopyCommand :\ Copy whole *command ”JMP UpdateLineLength ž.RemoveREM ¨BEQ ScanLineEnd ².ScanLineNum ¼>JSR CopyChar:JSR CopyChar :\ Copy embedded line number ÆJSR CopyChar Ð .ScanLine Ú9LDA (lptr),Y :\ Get source character ä0CMP #13:BEQ ScanLineEnd :\ End of line îCMP #34:BNE ScanLineStore ø=ASL A:‚ flag:STA flag :\ Toggle quote flag in bit 6  LDA #34  .ScanLineStore DJSR StoreChar :\ Copy character to crunched line  @BIT flag:BVS ScanLine :\ Within quotes, keep copying *9CMP #&8D:BEQ ScanLineNum :\ Embedded line number 4=CMP #—"\":BEQ ScanComment :\ Probable assembler comment >=CMP #—";":BEQ ScanComment :\ Possible assembler comment H=CMP #—":":BEQ ScanSpaces :\ Remove spaces before colon RHCMP #&80:BCC ScanLine :\ Not a token, continue scanning line \@.ScanSpaces :\ Remove spaces around tokens f?PHA :\ Save character just stored p>LDY tmpX :\ Point to stored character zCASL A:BPL SkipPreSpace :\ Not a command token if &80-&BF „FROL flag:SEC:ROR flag :\ Set flag bit 7=command token seen Ž.SkipPreSpace ˜?DEY:CPY #4:BCC SkipSpaceDone :\ Backed up to start of line ¢ALDA (dptr),Y :\ Get character before current ¬GCMP #—" ":BEQ SkipPreSpace :\ Skip spaces before current character ¶.SkipSpaceDone À4INY:TYA:TAX:LDY tmpY :\ Update pointers ÊDPLA:JSR StoreChar :\ Copy character to crunched line Ô=CMP #—":" :\ Check for end of statement Þ.JumpToStart èABEQ ScanStatementStart :\ Scan from start of statement ò CMP #TknTHEN:BEQ JumpToStart ü CMP #TknELSE:BEQ JumpToStart .SkipPostSpace LDA (lptr),Y:INY :CMP #—" ":BEQ SkipPostSpace :\ Skip spaces after token $@DEY:BNE ScanLine :\ Continue scanning statement .: 8.ScanComment B=BIT flag:BMI ScanLine :\ Not an assembler comment LBDEX:DEY :\ Point to '\' or ';' character V.ScanCommentLp `2INY:LDA (lptr),Y :\ Get character j6CMP #13:BEQ ScanLineEnd :\ Found end of line tsource , X=>dest location for œSTY tmpY:TXA:TAY ¦M.DropColons :\ Now move back and drop colons and spaces °9CPY #5:BCC MoveToNextLine :\ Null line, ignore it º?DEC tmpY:DEY:LDA (dptr),Y :\ Look at previous character Ä7CMP #—":":BEQ DropColons :\ Move back if a colon Î7CMP #—" ":BEQ DropColons :\ Move back if a space Ø!INC tmpY:INY:TYA:TAX:LDY tmpY âELDA #13:JSR StoreChar :\ Point back to where CR should be ì.UpdateLineLength öDEX BTXA:LDY #3:STA (dptr),Y :\ Ensure (dptr),len points to Y  DJSR AddAtoDPTR :\ Bump dest to point to next line .MoveToNextLine DPLA :\ Get saved length of source line (MJSR AddAtoLPTR:JMP ScanNewLine:\ Update source pointer, loop to next line 2: <.EndOfProg F>TXA:JSR AddAtoDPTR :\ Update EndOfProg pointers PLDA dptr+0:STA top+0 ZLDA dptr+1:STA top+1 d-RTS :\ Finished n: x .CopyChar ‚9LDA (lptr),Y :\ Get from source line Œ.StoreChar –STY tmpY:STX tmpX:LDY tmpX  ;STA (dptr),Y:LDY tmpY :\ Store in crunched line ª4INX:INY:RTS :\ Update pointers ´: ¾.AddAtoLPTR È0LDX #lptr:BNE AddAtoPTR :\ Update lptr Ò.AddAtoDPTR Ü0LDX #dptr :\ Update dptr æ.AddAtoPTR ðCLC:ADC 0,X:STA 0,X úLDA #0:ADC 1,X:STA 1,X RTS : ]í "@A$="*Save Crunch "+Ã~mcode%+" "+Ã~O%+" "+Ã~exec%+" "+Ã~load% ,ñ"Saving: "A$;:ÿA$:ñ ÿ