home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_24_1988_Transactor_Publishing.d64
/
hexed.src
< prev
next >
Wrap
Text File
|
2023-02-26
|
21KB
|
693 lines
*------------------------------*
* c64 hex file editor *
* (c) 1987 bob kodadek *
* 3164 surrey lane *
* aston, pa 19014 *
*------------------------------*
* merlin-128 macro-assembler *
chrget = $73 ;character get routine
chrgot = $79 ;get character again
endadr = $fb ;pointer:highest address
ramptr = $fd ;pointer:to ram
temp = $51 ;temporary usage
flen = $b7 ;filename length
buffer = $0100 ;work area
buf = $0200 ;system input buffer
sa = $0800 ;start of usable ram
second = $ff93 ;kernal equates
tksa = $ff96
acptr = $ffa5
ciout = $ffa8
untlk = $ffab
unlsn = $ffae
listen = $ffb1
talk = $ffb4
readst = $ffb7
setlfs = $ffba
setnam = $ffbd
open = $ffc0
close = $ffc3
chkin = $ffc6
chkout = $ffc9
clrchn = $ffcc
chrin = $ffcf
chrout = $ffd2
stop = $ffe1
getin = $ffe4
plot = $fff0
* note: labels beginning with "]" are variables
* and are used for backward branching only.
org $c000
start jsr setpnt ;set ramptr
ldx #0 ;zero end address
stx endadr
sty endadr+1
stx sa ;zero load address
stx sa+1
stx $0286 ;black for text color
help lda #15 ;color code for grey
sta $d020 ;set border color
sta $d021 ;set background color
lda #$93 ;clr screen
jsr chrout
ldx #2 ;locate cursor
ldy #12
clc
jsr plot ;print menu screen
jsr primm
txt 'hex file editor'0d0d0d
txt ' menu (c) 1987 bob kodadek'0d0d
txt 'e-edit'0d
txt 'l-list'0d
txt 'p-print'0d
txt 'd-directory'0d
txt 'r-read file'0d
txt 'w-write file'0d
txt 'x-disk command'0d
txt '#-dec to hex'0d
txt '$-hex to dec'0d
txt 'c-columns'0d
txt 'm-menu'0d
txt 'q-exit'00
ldx #18 ;locate cursor
ldy #20
clc
jsr plot
jsr primm
txt 'load address:$'00
ldx sa
lda sa+1
jsr printhex ;print load address
ldx #19 ;locate cursor
ldy #20
clc
jsr plot
jsr primm
txt 'object:$'00
ldx #<sa
lda #>sa
jsr printhex ;print start address
jsr primm
txt '-$'00
ldx endadr
lda endadr+1
jsr printhex ;print ending address
* get command and execute
getcom jsr restore ;restore channels
lda #$f0 ;chrget restored always
sta $82
lda #$ef
sta $83
lda #$0d
jsr chrout ;print a cr
ldx #38 ;erase command line
ldy $d3
lda #$20
]erase sta ($d1),y
iny
dex
bne ]erase
lda #'>'
jsr chrout ;print command prompt
jsr input ;get input
jsr chrget ;read character
]loop cmp table,y ;compare to command table
beq docom ;if found, do it
iny ;else, get more
cpy #$0c ;tested all?
bne ]loop
jmp getcom ;not legal command
docom tya ;get index into a
asl ;mulitply x 2
tax
lda adr+1,x ;look up address
pha ;push it on stack
lda adr,x
pha
rts ;jump to command routine
table asc 'rwlexdmqp#$c'
adr da read-1 ;read file
da write-1 ;write file
da list-1 ;list to screen
da edit-1 ;full screen editor
da diskc-1 ;send disk command
da direct-1 ;read directory
da help-1 ;produce main menu
da quit-1 ;return to basic
da plist-1 ;list to printer
da dechex-1 ;convert decimal to hex
da hexdec-1 ;convert hex to decimal
da change-1 ;select number of columns
hex 00
*** command routines ***
read = *
* reads prg, seq, or usr file into ram
jsr fname ;input filename
jsr setlog ;set logical file
jsr setpnt ;point to $0800
ldx #$03
jsr chkin ;open input channel
ldy #$00
]loop jsr chrin ;input character
sta (ramptr),y ;store in ram
jsr incpnt ;increment ramptr
jsr readst ;read status byte
sta erbyt ;save it
cmp #64 ;test for eol
beq eof
lda erbyt ;test for error
bne rderr ;read error channel
jmp ]loop
eof sta (ramptr),y ;store eof marker ($40)
tya ;y=0
]loop iny
sta (ramptr),y ;and a few zero bytes
cpy #3
bne ]loop
lda ramptr ;move ramptr to endadr
sta endadr
lda ramptr+1
sta endadr+1
rderr jsr restore ;clear channels
lda $ba ;read error channel
jsr talk ;device 8 talks
lda #$6f ;from command channel
sta $b9
jsr tksa
lda #$0d
jsr chrout ;print a cr
]get jsr acptr ;input serial byte
cmp #$0d ;test for cr
beq enderr
jsr chrout ;print the byte
jmp ]get
enderr jsr chrout ;print the cr
jsr untlk ;stop talking
jsr prrt ;prompt "press return"
jsr chrin ;wait for <return>
jmp help ;display menu
prrt jsr primm
txt 'press return'00
rts
incpnt inc ramptr ;increment ram pointer
bne r1
inc ramptr+1
r1 rts
write = *
* writes a binary file in prg, seq, or usr format
jsr primm
txt 'type (p/s/u):'00
]get jsr input ;get user's file type
jsr chrget
sta ftyp ;save it
jsr fname ;get filename
ldx #$03
]loop lda wr,x
sta buf,y ;append file type
iny
dex
bpl ]loop
sty flen ;set file length
jsr setlog ;set up logical file
ldx #$03
jsr chkout ;open output channel
jsr setpnt ;point to start ($0800)
lda #$36 ;basic roms out
sta $01
]loop lda ramptr ;test for end
cmp endadr
bne w1
lda ramptr+1
cmp endadr+1
beq w2
w1 ldy #$00
lda (ramptr),y ;get ram byte
jsr ciout ;output byte
jsr incpnt ;increment ramptr
jmp ]loop
w2 jmp rderr ;read error channel
plist = *
* lists to screen and printer
lda #4 ;set device to #4
sta $ba
jsr listen ;printer listens
lda #$60
sta $b9
jsr second ;secondary address 0
jsr primm ;prompt "ready?"
dfb 13
txt 'ready? '00
jsr prrt ;prompt "press return"
lda #$0d
jsr senchr ;print a cr
]loop jsr ckstop ;test stop key
jsr $ffe4 ;wait for <return>
cmp #$0d
bne ]loop
list = *
* list to screen and a listener, if present
jsr calcln ;calculate line number
]loop jsr ckstop ;check stop key
jsr line ;output line
wait lda 653 ;check shift key status
cmp #$01 ;freeze listing if active
beq wait
jsr incln ;increment line number
jmp ]loop ;do more
diskc = *
* sends user command to drive
jsr primm ;prompt user
txt 'command:'00
jsr input ;get command
lda $ba ;device 8 listens
jsr listen
lda #$6f ;command channel
sta $b9
jsr second
ldy #$00
]loop lda buf,y ;read input buffer
beq d1
jsr ciout ;send command string
iny
bne ]loop
d1 jmp rderr ;read error channel
quit = *
* routine to exit back to basic
jsr primm ;prompt
db 13
txt 'exit? (y/n)'00
]loop jsr getin ;getkey
cmp #'n'
beq q1
cmp #'y'
bne ]loop
jmp 64738 ;system reset
q1 jmp help ;or return to menu
direct = *
* displays directory from current drive
lda #$01 ;setup filename "$"
ldx #<file
ldy #>file
jsr setnam
lda #$60
sta $b9
jsr $f3d5
lda $ba ;device 8 talks
jsr talk
lda $b9
jsr tksa
lda #$00 ;clear status byte
sta $90
ldy #$03
get sty $b7
jsr acptr ;get # blocks in file
sta $c3 ;save low byte
jsr acptr
sta $c4 ;and high byte
ldy $90 ;test status byte
bne dout ;if not 0 then exit
ldy $b7
dey
bne get
ldx $c3
lda $c4
jsr $bdcd ;print # blocks
lda #$20 ;print a space
jsr chrout
]loop jsr acptr ;read filename
ldx $90
bne dout ;test status
cmp #$00 ;test for new line
beq newln
jsr chrout ;print a character
jsr stop ;test stop key
beq dout
jsr getin ;get keypress
beq ]loop
cmp #$20 ;test for space bar
bne ]loop ;freeze if pressed
]wait jsr getin ;wait for keypress
beq ]wait
bne ]loop ;continue listing
newln lda #$0d ;print cr
jsr chrout
ldy #$02
bne get ;go do more
dout jsr $f642 ;restore channels
jmp getcom ;next command
file asc '$'
edit = *
* full screen editor routine
jsr calcln ;calculate line number
e1 lda #$0d ;print a cr
jsr chrout
jsr line ;print the line
ldy #34
]loop1 lda #157 ;reposition cursor
jsr chrout
dey
bpl ]loop1
lda #$00 ;input screen line
tay
]get jsr $f15d
cmp #$0d
beq g1
sta buf,y ;save in buffer
iny
bne ]get
g1 ldx #$ff ;point chrget to buf
ldy #$01
stx $7a
sty $7b
jsr calcln ;read line number
jsr chrgot ;get last char read
cmp #'-' ;compare to "-"
bne nothex ;exit if not
ldy #$00
]loop2 jsr edhex ;editor hex asc to binary
sta buffer,y ;save binary
jsr chrget ;get next character
iny
cpy col ;last column?
beq skip ;then skip test
cmp #$20 ;else, must be a space
beq ]loop2
nothex lda #'?' ;data error! exit
jsr chrout
jmp getcom
* if no errors, now store the data in ram
skip ldy #0
]loop3 lda buffer,y ;get binary value
sta (ramptr),y ;store it in ram
iny
cpy col ;done all columns?
bne ]loop3
jsr incln ;increment line number
jmp e1
hexdec = *
* outputs decimal from ascii hexadecimal input
jsr rdhex ;get high byte
tay ;save it
jsr rdhex ;get low byte
tax
tya
jsr $bdcd ;print in decimal
jmp getcom ;next command
dechex = *
* outputs hexadecimal number from ascii decimal input
jsr ascint ;asc to integer
lda #'$' ;print "$"
jsr chrout
ldx $14 ;get low byte integer
lda $15 ;then high byte
jsr printhex ;output number in hex
jmp getcom ;get next command
change = *
* user sets number of columns displayed (6-11)
jsr ascint ;asc to integer
lda $14 ;get low byte
cmp #$06 ;<6 columns?
bcc ch1 ;then exit
cmp #12 ;=>12 columns?
bcs ch1 ;also exit
sta col ;store if 6-11
ch1 jmp getcom ;get next command
**************** subroutines ****************
* c-64 print immediate routine allows imbedded string
primm pla ;remove return address
sta $22 ;save it as current pc
pla
sta $23
bne nxtchar ;branch always
pchr jsr chrout
nxtchar ldy #0
inc $22 ;increment position
bne nc
inc $23
nc lda ($22),y ;get text
bne pchr ;print until #$00
lda $23 ;new return address
pha
lda $22
pha
rts ;get next instruction
* outputs line to current channel or listener
line jsr tstend ;test for last line
ldy #$00
]loop lda linum,y
beq l1
jsr senchr ;send line number
iny
bne ]loop
l1 lda #'-'
jsr senchr
ldy #0
sty cnt ;zero counter
]jloop lda (ramptr),y ;read binary in ram
jsr prbyte ;output as hex
lda #$20
jsr senchr ;output space
inc cnt ;increment counter
ldy cnt ;compare to #columns
cpy col
bne ]jloop
lda #$0d
jsr senchr ;output cr
rts
* output hex string from two byte integer
printhex jsr prbyte ;print a reg
txa ;print x reg
prbyte pha ;save a
lsr ;shift high nibble down
lsr
lsr
lsr
jsr phex ;print it
pla ;pull original byte
prnib and #$0f ;mask low nibble
phex ora #$30
cmp #$3a ;decimal digit?
blt jco ;branch if so
adc #6 ;add offset for hex
jco jsr senchr
rts
incln ldx #$03 ;increments line number
]loop inc linum,x
lda linum,x
cmp #$3a
bne in1
lda #$30
sta linum,x
dex
bpl ]loop
in1 inc lnum
bne in2
inc lnum+1
in2 lda ramptr ;update ram pointer
adc col
sta ramptr
lda ramptr+1
adc #$00
sta ramptr+1
rts
tstend sec ;test for highest address
lda ramptr ;double-byte comparison
sbc endadr
sta temp
lda ramptr+1
sbc endadr+1
ora temp
bcs ts1 ;stop if greater
rts ;else ok
ts1 pla
pla
jmp getcom
senchr jsr ciout ;send byte to listener
jsr chrout ;send byte to screen
rts
setlog lda flen ;open logical file
ldx #$00
ldy #$02
jsr setnam
lda #$03
ldx #$08
ldy #$03
jsr setlfs
jsr open
rts
fname jsr primm ;prompt
txt 'file name:'00
jsr input ;get file name
]loop lda buf,y ;get length
beq out
iny
bne ]loop
out sty flen ;save it
ldy flen ;test for no file name
bne f1
pla
pla
jmp help
f1 rts
setpnt ldx #<sa ;reset ram pointer
ldy #>sa
stx ramptr
sty ramptr+1
rts
input jsr $a560 ;get user input
stx $7a ;point chrget
sty $7b
ldy #0
rts
* this routine translates an ascii line number into
* the needed location in ram and sets the pointer
* (ramptr) accordingly through incln.
calcln lda #$01 ;set integer line# to 1
sta lnum
lda #$00
sta lnum+1
jsr setpnt ;set ramptr to $0800
lda #$30 ;set asc line# to 0001
ldy #$03
]loop sta linum,y
dey
bpl ]loop
inc linum+3
jsr ascint ;get integer
lda $14 ;greater than 0?
bne cal1 ;yes, continue
lda $15 ;else, exit
beq cal3
cal1 lda lnum ;get line number
cmp $14 ;test low byte
bne cal2 ;same?
lda lnum+1
cmp $15 ;test high byte
beq cal3 ;same?
cal2 jsr incln ;increment # & build string
jmp cal1
cal3 rts
* this routine translates ascii hex into binary. the
* first entry point modifies the chrget routine to
* accept space characters for the screen editor.
edhex lda #$ea ;modify chrget for edit
sta $82 ;store two nop instr.
sta $83
rdhex jsr chrget ;get ascii character
jsr tsthex ;test for hex
stx hex1 ;store it
jsr chrget ;get next char.
jsr tsthex ;test for hex
stx hex1+1 ;store it
lda hex1 ;get first value
asl ;multiply by 16
asl
asl
asl
clc ;add second value
adc hex1+1 ;now we have binary
gothex rts
tsthex ldx #$00 ;test for hex 0-f
]loop cmp hex,x ;compare to table
beq gothex ;x reg returns 0-15
inx ;else, do more
cpx #$10 ;any more left?
bne ]loop ;not found
pla
pla ;pull 2 addresses
pla
pla
jmp nothex ;report error!
* this routine converts ascii into a two-byte integer
* as in the basic rom routine, but handles 0-65535.
ascint ldx #$00
stx $14
stx $15
]loop jsr chrget ;get asc character
bcs as1 ;set when not asc numeric
sbc #$2f ;includes carry
sta $07 ;save remainder (0-9)
lda $15 ;build two byte integer
sta $22 ;temp area
lda $14
asl
rol $22
asl
rol $22
adc $14
sta $14
lda $22
adc $15
sta $15
asl $14
rol $15
lda $14
adc $07
sta $14
bcc ]loop
inc $15
bne ]loop
as1 rts
ckstop jsr stop ;stop key pressed?
bne nostop ;if not, then continue
pla ;else remove return
pla ;address from stack
jmp getcom ;and jump to command
nostop rts ;routine.
restore jsr unlsn ;unlisten device
jsr clrchn ;clear channels
lda $b8 ;get file number
jsr close ;close logical file
lda #$08 ;set device to 8
sta $ba
lda #$37 ;basic rom's in
sta $01
rts
hex1 ds 2 ;storage
lnum ds 2 ;holds line number
cnt ds 1 ;counter
erbyt ds 1 ;holds status byte
col db 8 ;holds # columns
linum asc '0000'00 ;asc line #
hex asc '0123456789'
asc 'abcdef'
wr asc 'w,' ;file direction
ftyp asc 'p,' ;file type