* * Code to convert Buddy +/- labels to a more sensible format. * * May or may not work! :) * * SLJ 9/99 * * * Idea: 2-passes. On first pass, search label field for + or - symbols * When found, add address to an address list, and replace symbol with * an appropriate local label. * On second pass, search operand fields for + and - references, and * fix accordingly. * * * To use: load text to $0800, sys $c000 * NOTE: text must end with 00! *  org $c000 text = $0800 pluschar = 'p' minchar = 'm' tempx = $f9 textend = $fb count = $ff temp = $fd Start  jsr init :l1 lda text,x ;Find end of text  beq :eot  inx  bne :l1  jmp Done :eot stx textend pass1  ldx #00  dfb 00 ;Kludge -- .X = 16-bit :loop  lda text,x  cmp #'+'  beq :add  cmp #'-'  bne :c1 :add jsr AddText  lda #' ' :c1 and #$7f  cmp #' '  beq :next  lda #$30  sta count :next jsr Nextline  bne :loop pass2  jsr init p2loop  lda text,x  cmp #'*'  beq :next  cmp #';'  beq :next  jsr Nextfield  bcs :next  jsr Nextfield  bcs :next  lda text,x  cmp #'+'  beq :fixplus  cmp #'-'  beq :fixminus :next jsr Nextline  bne p2loop  bra Done :fixplus lda #'+'  jsr CountChar  jsr AddText  txy :pl2 jsr Nextline  lda text,x  cmp #':'  bne :pl2  lda text+1,x  cmp #pluschar  bne :pl2  dec temp  beq :found  bne :pl2 :fixminus  lda #'-'  jsr CountChar  jsr AddText  txy :ml2 jsr Lastline  lda text,x  cmp #':'  bne :ml2  lda text+1,x  cmp #minchar  bne :ml2  dec temp  bne :ml2 :found lda text,x  sta text,y  lda text+1,x  sta text+1,y  lda text+2,x  sta text+2,y  tyx  bne :next Done  sec  xce  rts CountChar  stx tempx  stz temp  sta temp+1 :pl1 lda #32  sta text,x ;Space out +'s  inc temp  inx  lda text,x  cmp temp+1  beq :pl1  ldx tempx  rts AddText ;Move text forwards  cmp #'+' ;use p for plus,  bne :minus ;m for minus  lda #pluschar  dfb $2c :minus lda #minchar  xba  stx tempx  ldx textend  inx  inx  stx textend  dex  dex :loop lda text,x  sta text+2,x  dex  cpx tempx  bne :loop  lda #':' ;Add label :ma etc.  sta text,x  xba  sta text+1,x  lda count  sta text+2,x  inc count ;0-9, a-z  lda count  cmp #':'  bne :rts  lda #$41  sta count :rts rts Lastline  dex ;Back up to end of prev. line  lda text-1,x  cmp #13  bne Lastline  rts Nextline  lda text,x  beq :done  inx  cmp #13  bne Nextline :done and #$7f  rts * Find next space, then next char. * c set -> hit end of line Nextfield  lda text,x  and #$7f  cmp #' '  beq :nextchar  cmp #13  beq Nextline  inx  bne Nextfield :nextchar  inx  lda text,x  and #$7f  cmp #' '  beq :nextchar  cmp #';'  beq Nextline  cmp #13  beq Nextline  and #$7f  clc  rts init  clc  xce  rep #$10 ;16-bit X/Y  sep #$20  ldx #$0000  txy  rts  do 0 debug  sta 1164  stx 1164+40  sty 1164+80  lda $01  xba  lda #$77  sta $01  lda #0  sta $dc00 :l1 lda $dc01  cmp #$ff  beq :l1 :l2 cmp $dc01  beq :l2  xba  sta $01  lda 1164  rts  fin