home *** CD-ROM | disk | FTP | other *** search
- 10 *= $c44a
- 20 ;crunch.src
- 30 .s
- 40 .d crunch
- 50 ;
- 60 txttab = $2b
- 70 vartab = $2d
- 80 arytab = $2f
- 90 strend = $30
- 100 ;
- 110 chrget = $73
- 120 txtptr = $7a
- 130 chrput = $81
- 140 putptr = $88
- 150 ;
- 160 maxlen = $50
- 170 max =$fa
- 180 length = $fb
- 190 sabuf = $fc
- 200 ;
- 210 warmst = $a002
- 220 linkprg = $a533
- 230 strout = $ab1e
- 240 ;
- 250 adc44a ldx #$17; save chrget, set up chrput routine
- 260 saveit lda chrget,x:sta savebuf,x:dex:bpl saveit:ldx #$07:clc
- 270 lda txttab:adc #$ff:sta chrget,x:inx:lda txttab+1:adc #$ff:sta chrget,x:inx
- 280 lda #$60:sta chrget,x
- 290 putit lda chrget,x:sta chrput,x:dex:bpl putit
- 300 lda #putptr:sta chrput+1:lda #putptr+1:sta chrput+5:lda #$8d:sta chrput+6
- 310 ;
- 320 ; initialize counter to end-of-line
- 330 lda #maxlen:sta max:sta length
- 340 ;
- 350 ;check for $ac in "*= $tart" line, skip over defs if found
- 360 ldy #$05:lda (txtptr),y:cmp #$ac:bne newfile:iny:iny:iny:iny:ldx #$00
- 370 ;
- 380 start1 lda (txtptr),y:sta sabuf,x:iny:inx:cpx #$04:bcc start1
- 390 ;
- 400 ;ascii hex digits now at sabuf, txtptr still at basic-1
- 410 dey:tya:clc:adc txtptr:sta txtptr:bcc start2:inc txtptr+1
- 420 ;
- 430 ;next call to chrget fetches the byte following the start address
- 440 ;now find the matching string in the first line of program code
- 450 start2 ldx #$00
- 460 start3 jsr chrget:bne start5:jsr chrget:jsr chrget:bne start4
- 470 ;
- 480 ;found third zero byte, no start-of-code so print message and quit
- 490 lda #<nocode:ldy #>nocode:jsr strout:ldx #$17:jmp done2
- 500 ;
- 510 ;found hibyte of line link so discard line number and fetch byte of line
- 520 start4 jsr chrget:jsr chrget:jmp start2
- 530 ;
- 540 start5 cmp sabuf,x:bne start2:inx:cpx #$04:bcc start3:lda #$0a:sta length
- 550 lda #<crunching:ldy #>crunching:jsr strout
- 560 ;
- 570 ;found, so set up chrput and fall through in midline
- 580 lda txtptr:sta putptr:lda txtptr+1:sta putptr+1
- 590 ;
- 600 midline jsr chrget:beq endline:bpl midline1:inc length; tokenized "or"
- 610 midline1 jsr chrput:inc length:bne midline
- 620 ;
- 630 ;step chrput back if at beginning of new file
- 640 newfile lda putptr:bne newfile1:dec putptr+1
- 650 newfile1 dec putptr
- 660 lda #<crunching:ldy #>crunching:jsr strout
- 670 ;
- 680 ;check to see if end of program
- 690 endline ldy #$02:lda (txtptr),y:bne endline1:jmp done
- 700 ;
- 710 ;check next line for pseudop, jump, rts/rti or label
- 720 endline1 ldy #$05:lda (txtptr),y:cmp #$2e:beq label1; "." pseudop
- 730 cmp #$3b:beq label1; ";" pseudop
- 740 cmp #$4a:beq endline2; j, check m
- 750 cmp #$52:bne endline3; r, check t
- 760 endline2 iny:lda (txtptr),y:cmp #$4d:beq stopline:cmp #$54:beq stopline
- 770 ; not jm/rt, can't be jt, rm, ja or ra so fall through
- 780 endline3 cmp #$41:bne endline4; if not "a" then not label
- 790 ;
- 800 ;check for "def" token (adefxx label) or "d" (adxxxx label)
- 810 iny:lda (txtptr),y:cmp #$96:beq label:cmp #$44:bne endline4
- 820 ;
- 830 ;check for space following adc instruction, otherwise it's a label
- 840 iny:iny:lda (txtptr),y:cmp #$20:bne label
- 850 endline4 jmp addline
- 860 ;
- 870 ;labelled lines may be .byte, rts/rti/jmp: leave in one line if found
- 880 label iny:lda (txtptr),y:cmp #$20:bne label; get past the label
- 890 iny:lda (txtptr),y:cmp #$2e:beq pseudop; .byte line
- 900 cmp #$4a:beq label0:cmp #$52:bne newline; j or r else simple label
- 910 label0 iny:lda (txtptr),y:cmp #$54:beq pseudop:cmp #$4d:bne newline; t or m
- 920 label1 beq pseudop; jmps to one-liners
- 930 ;
- 940 ;if unlabelled jmp/rts/rti found, stop line after adding this instruction
- 950 stopline iny:lda (txtptr),y:bne stopline:dey:dey:dey:tya:clc:adc length
- 960 cmp max:bcs pseudop:lda max:sta length:bne addline1
- 970 ;
- 980 ;start new line: move line links and number and (NULL) to midline
- 990 newline lda #$00:jsr chrput:ldx #$03:stx length; allow for line # expansion
- 1000 newline1 jsr chrget:jsr chrput:inc length:dex:bpl newline1:jmp midline
- 1010 ;
- 1020 pseudop lda #$00:jsr chrput:lda max:sta length:ldx #$03
- 1030 pseudop1 jsr chrget:jsr chrput:dex:bpl pseudop1
- 1040 pseudop2 jsr chrget:bne pseudop3:jmp endline
- 1050 pseudop3 jsr chrput:bne pseudop2
- 1060 ;
- 1070 addline iny:lda (txtptr),y:bne addline; .y-3 = length to add
- 1080 dey:dey:dey:tya:clc:adc length:cmp max:bcs newline;check for space
- 1090 ;
- 1100 ;append the line and discard the links and number
- 1110 addline1 lda #$3a:jsr chrput:inc length:ldx #$03
- 1120 addline2 jsr chrget:dex:bpl addline2:jmp midline
- 1130 ;
- 1140 done ldx #$03:lda #$00
- 1150 done1 jsr chrput:dex:bpl done1
- 1160 lda putptr:sta vartab:sta arytab:sta strend
- 1170 lda putptr+1:sta vartab+1:sta arytab+1:sta strend+1:ldx #$17
- 1180 done2 lda savebuf,x:sta chrget,x:dex:bpl done2
- 1190 jsr linkprg:lda #<crunched:ldy #>crunched:jsr strout:jmp (warmst)
- 1200 savebuf .byte 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 1210 nocode .byte "[147][213]nable to match hex digits of start":.byte 13
- 1220 .byte "address (*= $xxxx) to label of first":.byte 13
- 1230 .byte "line of code following definitions.":.byte 13
- 1240 .byte "[211]hould be ":.byte 34:.byte "ad0801":.byte 34:.byte "type label"
- 1250 .byte 13 0
- 1260 crunching .byte "[195]runching...":.byte 13 0
- 1270 crunched .byte "[145][195]runched! ":.byte 13 0 0 0
- 1280 ;
- 1290 .end crunch.src
-