Corrected weird error text getting mixed into output; reformatted to use tabs; tweaked code to keep within 256 bytes.

This commit is contained in:
Rob Greene 2015-10-03 23:29:58 -05:00
parent f905feca72
commit 6ab8d6b7d6

View File

@ -4,131 +4,132 @@
; Copyright (c) 2015 Rob Greene. All rights reserved. ; Copyright (c) 2015 Rob Greene. All rights reserved.
; ;
.PC02 ; Enable 65C02 instructions .PC02 ; Enable 65C02 instructions
; ASCII string with high-bit set, terminated by a zero ; ASCII string with high-bit set, terminated by a zero
.macro asciizh string .macro asciizh string
.repeat .strlen(string),i .repeat .strlen(string),i
.byte .strat(string,i) | $80 .byte .strat(string,i) | $80
.endrep .endrep
.byte 0 .byte 0
.endmacro .endmacro
; ASCII string with high-bit set ; ASCII string with high-bit set
.macro asciih string .macro asciih string
.repeat .strlen(string),i .repeat .strlen(string),i
.byte .strat(string,i) | $80 .byte .strat(string,i) | $80
.endrep .endrep
.endmacro .endmacro
; Dextral (right-most) Character Inverted ; Dextral (right-most) Character Inverted
.macro dci string .macro dci string
.repeat .strlen(string),i .repeat .strlen(string),i
.if .strlen(string) = i .if .strlen(string) = i
.byte .strat(string,i) | $80 .byte .strat(string,i) | $80
.else .else
.byte .strat(string,i) & $7f .byte .strat(string,i) & $7f
.endif .endif
.endrep .endrep
.endmacro .endmacro
; BASIC.SYSTEM locations: ; BASIC.SYSTEM locations:
inbuf = $0200 inbuf = $0200
extrncmd = $be06 ; External command JMP vector extrncmd = $be06 ; External command JMP vector
xtrnaddr = $be50 ; Execution address of external command xtrnaddr = $be50 ; Execution address of external command
xlen = $be52 ; Length of command string-1 xlen = $be52 ; Length of command string-1
xcnum = $be53 ; BASIC cmd number (external command = 0) xcnum = $be53 ; BASIC cmd number (external command = 0)
pbits = $be54 ; Parameter bits allowed (2 bytes) pbits = $be54 ; Parameter bits allowed (2 bytes)
fbits = $be56 ; Parameter bits found fbits = $be56 ; Parameter bits found
vslot = $be61 vslot = $be61
vdriv = $be62 vdriv = $be62
gosystem = $be70 gosystem = $be70
xreturn = $be9e ; Guaranteed RTS instruction xreturn = $be9e ; Guaranteed RTS instruction
sonline = $bec6 ; BASIC.SYSTEM ONLINE parameter table sonline = $bec6 ; BASIC.SYSTEM ONLINE parameter table
sunitnum = $bec7 sunitnum = $bec7
sbufadr = $bec8 sbufadr = $bec8
getbufr = $bef5 getbufr = $bef5
; Parameter bits flags (note setup for two bytes and for lo/hi usage) ; Parameter bits flags (note setup for two bytes and for lo/hi usage)
pfix = $0080 ; Prefix needs fetching, pathname optional pfix = $0080 ; Prefix needs fetching, pathname optional
slot = $0040 ; No parameters to be processed slot = $0040 ; No parameters to be processed
rrun = $0020 ; Command only valid during program rrun = $0020 ; Command only valid during program
fnopt = $0010 ; Filename is optional fnopt = $0010 ; Filename is optional
crflg = $0008 ; CREATE allowed crflg = $0008 ; CREATE allowed
t = $0004 ; File type t = $0004 ; File type
fn2 = $0002 ; Filename #2 for RENAME fn2 = $0002 ; Filename #2 for RENAME
fn1 = $0001 ; Filename expected fn1 = $0001 ; Filename expected
ad = $8000 ; Address ad = $8000 ; Address
b = $4000 ; Byte b = $4000 ; Byte
e = $2000 ; End address e = $2000 ; End address
l = $1000 ; Length l = $1000 ; Length
line = $0800 ; '@' line number line = $0800 ; '@' line number
sd = $0400 ; Slot and drive numbers sd = $0400 ; Slot and drive numbers
f = $0200 ; Field f = $0200 ; Field
r = $0100 ; Record r = $0100 ; Record
v = $0000 ; Volume number ignored v = $0000 ; Volume number ignored
; MONITOR locations: ; MONITOR locations:
crout = $fd8e crout = $fd8e
prbyte = $fdda prbyte = $fdda
cout = $fded prhex = $fde3
cout = $fded
; Application stuff: ; Application stuff:
cptr = $0c ; Code pointer cptr = $0c ; Code pointer
dptr = $0e ; Data pointer dptr = $0e ; Data pointer
buffer = inbuf buffer = inbuf
codelen = (_CodeEndAddress - _CodeBeginAddress) codelen = (_CodeEndAddress - _CodeBeginAddress)
.org $2000 .org $2000
install: install:
; Requires 65C02 or later: ; Requires 65C02 or later:
sed sed
lda #$99 lda #$99
clc clc
adc #$01 adc #$01
cld cld
bpl @not6502 bpl @not6502
@6502: @6502:
jsr printz jsr printz
asciizh "ERR: MUST HAVE ENHANCED //E, //C, OR IIGS" asciizh "ERR: MUST HAVE ENHANCED //E, //C, OR IIGS"
rts rts
; Get address from BASIC.SYSTEM: ; Get address from BASIC.SYSTEM:
@not6502: @not6502:
lda #1 lda #1
jsr getbufr jsr getbufr
bcc @gotmem bcc @gotmem
@nomem: @nomem:
jsr printz jsr printz
asciizh "UNABLE TO ALLOCATE MEMORY" asciizh "UNABLE TO ALLOCATE MEMORY"
rts rts
@gotmem: @gotmem:
sta cptr+1 sta cptr+1
stz cptr stz cptr
; Move code to destination address: ; Move code to destination address:
ldy #0 ldy #0
: lda _CodeStartAddress,y : lda _CodeStartAddress,y
sta (cptr),y sta (cptr),y
iny iny
bne :- bne :-
; Patch code for new location - ASSUMES 1 PAGE ONLY! ; Patch code for new location - ASSUMES 1 PAGE ONLY!
ldy #0 ldy #0
@copy: @copy:
lda (cptr),y lda (cptr),y
jsr ilen ; calculate instruction length jsr ilen ; calculate instruction length
tax tax
cpx #3 cpx #3
bne :+ bne :+
@ -150,81 +151,82 @@ install:
; Setup BASIC.SYSTEM hooks: ; Setup BASIC.SYSTEM hooks:
; 1. Save EXTRNCMD ; 1. Save EXTRNCMD
lda extrncmd+2 lda extrncmd+2
ldy #<nextcmd+1 ldy #<nextcmd+2
sta (cptr),y sta (cptr),y
lda extrncmd+1 lda extrncmd+1
dey dey
sta (cptr),y sta (cptr),y
; 2. Place our hook into EXTRNCMD ; 2. Place our hook into EXTRNCMD
lda cptr+1 lda cptr+1
sta extrncmd+2 sta extrncmd+2
lda #<entry lda #<entry
sta extrncmd+1 sta extrncmd+1
; Notify user: ; Notify user:
jsr printz jsr printz
asciizh "ONLINE COMMAND INSTALLED" asciizh "ONLINE COMMAND INSTALLED"
rts rts
printz: printz:
pla pla
sta dptr sta dptr
pla pla
sta dptr+1 sta dptr+1
@L: inc dptr @L: inc dptr
bne :+ bne :+
inc dptr+1 inc dptr+1
: lda (dptr) : lda (dptr)
beq @X beq @X
jsr cout jsr cout
bra @L bra @L
@X: lda dptr+1 @X: lda dptr+1
pha pha
lda dptr lda dptr
pha pha
rts rts
.include "../shared/ilen.asm" .include "../shared/ilen.asm"
; ======================================= ; =======================================
_CodeStartAddress: _CodeStartAddress:
.org $6000 .org $6000
_CodeBeginAddress: _CodeBeginAddress:
entry: entry:
cld ; For BASIC.SYSTEM's happiness cld ; For BASIC.SYSTEM's happiness
ldx #6 ldx #cmdlen
: lda inbuf-1,x : lda inbuf-1,x
cmp #$e0 ; Force input to UPPERCASE for comparison cmp #$e0 ; Force input to UPPERCASE for comparison
bcc :+ bcc :+
and #$df and #$df
: cmp cmdtable-1,x : cmp cmdtable-1,x
bne notOurCommand bne notOurCommand
dex dex
bne :-- bne :--
; Setup for BASIC.SYSTEM to parse ; Setup for BASIC.SYSTEM to parse
opts = fnopt|sd ; Filename is optional (due to glitch) and slot and drive opts = fnopt|sd ; Filename is optional (due to glitch) and slot and drive
lda #cmdlen-1 lda #cmdlen-1
sta xlen sta xlen
lda #<online lda #<online
sta xtrnaddr sta xtrnaddr
jsr xreturn jsr xreturn
tsx tsx
lda $100,x ; Retrieve address from stack lda $100,x ; Retrieve address from stack
sta xtrnaddr+1 sta xtrnaddr+1
stz xcnum stz xcnum
lda #<opts lda #<opts
sta pbits sta pbits
lda #>opts lda #>opts
sta pbits+1 sta pbits+1
clc clc
rts rts
notOurCommand: notOurCommand:
sec sec
jmp (nextcmd) nextcmd:
jmp $0000 ; Filled in by installer
; ;
; Perform ONLINE command ; Perform ONLINE command
@ -242,116 +244,117 @@ notOurCommand:
; S5 D1 ERR=$57 (S7 D1) ; S5 D1 ERR=$57 (S7 D1)
; ;
online: online:
lda fbits+1 lda fbits+1
and #>sd and #>sd
beq @1 ; Bit was NOT set; Acc = 0 beq @1 ; Bit was NOT set; Acc = 0
lda vdriv ; 1 or 2, use 2nd bit to toggle drive (then drive 1 has bit off, drive 2 has bit on) lda vdriv ; 1 or 2, use 2nd bit to toggle drive (then drive 1 has bit off, drive 2 has bit on)
and #%00000010 and #%00000010
asl asl
asl asl
ora vslot ora vslot
asl asl
asl asl
asl asl
asl asl
@1: sta sunitnum @1: sta sunitnum
stz sbufadr stz sbufadr
lda #>buffer lda #>buffer
sta sbufadr+1 sta sbufadr+1
; Note: if we have a specific unit, the buffer will not be zero terminated -- fake it! ; Note: if we have a specific unit, the buffer will not be zero terminated -- fake it!
stz buffer+16 stz buffer+16
lda #$C5 ; ONLINE system command lda #$C5 ; ONLINE system command
jsr gosystem jsr gosystem
@continue: @continue:
ldx #0 jsr crout
ldx #0
@loop: @loop:
ldy buffer,x ldy buffer,x
beq @exit beq @exit
jsr printsd jsr printsd
jsr printspc jsr printspc
tya tya
and #$0f and #$0f
beq @deverr beq @deverr
tay tay
lda #'/'|$80 lda #'/'|$80
: jsr cout : jsr cout
inx inx
lda buffer,x lda buffer,x
ora #$80 ora #$80
dey dey
bpl :- bpl :-
@adjust: @adjust:
jsr crout jsr crout
txa txa
and #$0f ; Check if we advanced past this buffer and #$0f ; Check if we advanced past this buffer
beq @loop beq @loop
txa txa
and #$f0 and #$f0
clc clc
adc #$10 adc #$10
tax tax
bne @loop bne @loop
@exit: @exit:
jmp crout jsr crout
clc
rts
; A device error message ; A device error message
@deverr: @deverr:
ldy #0 ldy #0
: lda msgERR,y : lda msgERR,y
beq :+ beq :+
jsr cout jsr cout
iny iny
bne :- bne :-
: inx : inx
lda buffer,x lda buffer,x
tay ; short-term save tay ; short-term save
jsr prbyte jsr prbyte
tya tya
cmp #$57 ; duplicate volume error cmp #$57 ; duplicate volume error
bne @adjust bne @adjust
jsr printspc jsr printspc
lda #'('|$80 lda #'('|$80
jsr cout jsr cout
inx inx
ldy buffer,x ldy buffer,x
jsr printsd jsr printsd
lda #')'|$80 lda #')'|$80
jsr cout jsr cout
bra @adjust bra @adjust
printsd: printsd:
lda #'S'|$80 lda #'S'|$80
jsr cout jsr cout
tya tya
and #$70 and #$70
lsr lsr
lsr lsr
lsr lsr
lsr lsr
ora #'0'|$80 jsr prhex
jsr cout lda #','|$80
lda #','|$80 jsr cout
jsr cout lda #'D'|$80
lda #'D'|$80 jsr cout
jsr cout tya
tya and #$80
and #$80 asl ; Drive 2 will set carry...
asl ; Drive 2 will set carry... adc #'1'|$80 ; ... making the '1' a '2'
adc #'1'|$80 ; ... making the '1' a '2' bra _cout ; Saving 1 byte
jmp cout
printspc: printspc:
lda #' '|$80 lda #' '|$80
jmp cout _cout:
jmp cout
_CodeEndAddress: _CodeEndAddress:
msgERR: msgERR:
asciizh "ERR=$" asciizh "ERR=$"
cmdtable: cmdtable:
asciih "ONLINE" asciih "ONLINE"
cmdlen = *-cmdtable cmdlen = *-cmdtable
nextcmd: .word 0