Hello people.
My name is Paul. I have been working a renumber program for Commodore 64 basic
I am nearly complete. I parse the basic program and set the line numbers. I also have parsed the line to get GOTO GOSUB and THEN but I don't do anything with it yet. I need to add 1) a symbol table fix GOTO's etc. 2) a routine to add characters to a line of basic in case the new line is 3 digits and the old line is 2. I also have code but will not post yet, code to add the RENUM command to basic itself.
I was wondering if anyone is interested in helping me finish this project as I have been busy with my real job programming Windows in WPF in C#. I have been using a real commodore 64c and Abacus Assembler. I have a ZooomFloppy on order to remedy that thank God.
NOTE about the code: I am not done documenting yet. I am using the X register as a flag for in a quote
Cheers
Code:
; WRITTEN BY PAUL BAXTER
;
; .TITLE "RENUM"
.OPT N,OO : .SYM 2
;
*=$C000
;
;************
;* *
;* SYMBOLS *
;* *
;************
;
CHROUT = $FFD2
PLOT = $FFF0
BSTART = $2B ; START OF BASIC
TXTOFF = $04; OFFSET TEXT
LNOFF = $02 ; OFFSET LINE NUMBER
NXOFF = $00 ; OFFSET NEXT ADDRESS
;
; ZERO PAGE USAGE
;
NXTLN = $FC ; PTR NEXT STATEMENT
LNUM = $FE ; NEXT LINE NUM TO USE
INCR = $A3 ; LINE NUM INCREMENT
BNVAR = $4E ; NUM TO CONVERT TO BCD
BCDSTR = $57; BCD STRING RESULT
BCD = $5C
;
; BASIC TOKENS
;
GOTO = $89
GOSUB = $8D
THEN = $A7
QUOTE = $22
;
;************
;* *
;* STORE.W *
;* *
;************
;
STORE.W .MAC AD,NUM
LDA #<NUM
STA AD
LDA #>NUM
STA AD+1
.MEND
;
;************
;* *
;* MOVE.W *
;* *
;************
;
MOVE.W .MAC SRC,DST
LDA SRC,
STA DST,
LDA SRC+1
STA DST+1
.MEND
;
;************
;* *
;* ADD.W *
;* *
;************
;
ADD.W .MAC AD1,AD2,DST
CLC
LDA AD1
ADC AD2
STA DST
LDA AD1+1
ADC AD2+1
STA DST+1
.MEND
;
;************
;* *
;* STZPIY.W *
;* *
;************
;
STZPIY.W .MAC ZP,YVAL,AD
LDY #YVAL
LDA AD
STA (ZP),Y
LDA AD+1
INY
STA (ZP),Y
.MEND
;
;************
;* *
;* LDZPIY.W *
;* *
;************
;
LDZPIY.W .MAC ZP,YVAL
LDY #YVAL
LDA (ZP),Y
TAX
INY
LDA (ZP),Y
.MEND
;
;************
;* *
;* SHFT3BYT *
;* *
;************
;
SHFT3BYT .MAC SRC,DST
ASL SRC+0
ROL SRC+1
LDA DST+0
ADC DST+0
STA DST+0
LDA DST+1
ADC DST+1
STA DST+1
LDA DST+2
ADC DST+2
STA DST+2
.MEND
;
;************
;* *
;* BCD2STR *
;* *
;************
;
BCD2STR .MAC SRC,DST
LDA SRC
AND $F0
LSR
LSR
LSR
LSR
ORA #$30
STA DST
LDA SRC
AND #$0F
ORA #$30
STA DST+1
.MEND
;
;************
;* *
;* START *
;* *
;************
;
; INIT START OF BASIC PROGRAM
;
'MOVE.W BSTART,NXTLN
;
; INIT LINE NUMBER
'STORE.W LNUM,100
;
; INIT LINE NUMBER INCREMENT
'STORE.W INCR,10
;
; GET THE TEXT OF THE LINE
NEXTLN LDY #NXOFF
LDA (NXTLN),Y
BNE PRLN
INY
LDA (NXTLN),Y
BEQ GETLN
PRLN SEC
JSR PLOT
LDY #01
CLC
JSR PLOT
JSR PRNTLINE
;
GETLN LDY #TXTOFF -1
LDX #00
NXTCH INY
LDA (NXTLN),Y
BEQ STLN
;
; CHECK FOR QUOTE
CHKQUOTE CMP #QUOTE
BNE CHKTOK
CPX #00
BNE INQUOTE
LDX #01
BNE NXTCH
;
INQUOTE LDX #00
BEQ NXTCH
BNE CHKTOK ; NEVER SHOULD GET HERE? REMOVE
;
;************
;* *
;* BRANNEX *
;* *
;************
; BRANCH ISLAND
BRANNEX BNE NEXTLN
BEQ NEXTLN
;
; SEARCH FOR GOTO GOSUB THEN
CHKTOK CMP #GOTO
BNE CHKGOSUB
FINDLINE CLC
BCC NXTCH
;
CHKGOSUB CMP #GOSUB
BEQ FINDLINE
CMP #THEN
BEQ FINDLINE
BNE NXTCH
;
; SET NEW BASIC LINE NUMBER
STLN 'STZPIY.W NXTLN,LNOFF,LNUM
LDA #' '
JSR CHROUT
LDA #'='
JSR CHROUT
LDA #'>'
JSR CHROUT
JSR PRNTLINE
;
; INCRMENT LINE NUMBER
'ADD.W LNUM,INCR,NUM
;
; GET POINTER TO NEXT BASIC LINE
'LDZPIY.W NXTLN,NXOFF
;
; SAVE POINTER TO NEXT LINE
STX NXTLN
STA NXTLN+1
;
; CHECK FOR END OF PROGRAM
CPX #00
BNE BRANNEX
CMP #00
BNE BRANNEX
RTS
;
;************
;* *
;* PRNTLINE *
;* *
;************
;
PRNTLINE LDA #LNOFF ; CAN BE REMOVED
LDY #LNOFF
LDA (NXTLN),Y
STA BNVAR
INY
LDA (NXTLN),Y
STA BNVAR+1
JSR BINBCD16
LDY #00
PBCD LDA BCDSTR,Y
JSR CHROUT
INY
CPY #05
BNE PBCD
RTS
;
;************
;* *
;* BINBCD16 *
;* *
;************
;
BINBCD16 SED
LDA #00
STA BCD+0
STA BCD+1
STA BCD+2
LDY #16
CNVBIT 'SHFT3BYT BNVAR,BCD
DEY
BNE CNVBIT
CLD
'BCD2STR BCD+0,BCDSTR+3
'BCD2STR BCD+1,BCDSTR+1
LDA BCD+2
AND #$0F
ORA #$30
STA BCDSTR+0
RTS
.END