SAIFIINDUSTRIES's picture
Add repo: GideonZ_1541ultimate
c7436b1 verified
Raw
History Blame Contribute Delete
7.35 kB
;-------------------------------------------------
; Command Interface I/O Module Tester
;
; Programmed by Gideon Zweijtzer
;
; Copyright (c) 2011 - Gideon Zweijtzer
;
;-------------------------------------------------
;
; This module is a resident 8K rom at $8000 that installs some basic extensions.
; the @ command is added, which sends a command to the Ultimate through the
; command interface channel. The @ statement also prints the result.
; the <- statement (arrow left) prints the current remaining data and status,
; and aborts any command currently active on the Ultimate.
*= $8000 ;base address of cartridge
AT_TOKEN = $40
CMD_IF_CONTROL = $DF1C
CMD_IF_COMMAND = $DF1D
CMD_IF_RESULT = $DF1E
CMD_IF_STATUS = $DF1F
CMD_PUSH_CMD = $01
CMD_NEXT_DATA = $02
CMD_ABORT = $04
CMD_STATE_BITS = $30
CMD_STATE_IDLE = $00
CMD_STATE_BUSY = $10
CMD_STATE_LAST_DATA = $20
CMD_STATE_MORE_DATA = $30
.byte <start ;cold start vector
.byte >start
.byte <startNMI ;nmi vector
.byte >startNMI
.byte "C"|$80,"B"|$80,"M"|$80,"8","0"
.text $00, 'Test routines for Command Interface I/O Module. Copyright (c) 2013 - Gideon Zweijtzer', $00
startNMI jmp $fe5e
;**************************************************************************
;*
;* NAME clone_fd50
;*
;* DESCRIPTION
;* Clone the memory init at $fd50 without memtest.
;*
;******
clone_fd50
lda #0
tay
cfd50_lp1
; sta $0002,y
sta $0003,y ;Make sure flag_zp ($02) is preserved.
sta $0200,y
sta $0300,y
iny
bne cfd50_lp1
ldx #$03
lda #$3c
sta $b2
stx $b3
ldx #$00
ldy #$80
jmp $fd8c ;Set MemBounds
;**************************************************************************
;*
;* NAME clone_fd15
;*
;* DESCRIPTION
;* Clone the vector setup at $fd15 without trashing memory below kernal
;*
;******
clone_fd15
ldy #$1f
cfd15_lp1
lda $fd30,y
sta $0314,y
dey
bpl cfd15_lp1
rts
;**************************************************************************
;*
;* NAME start
;*
;* DESCRIPTION
;* Start address of the cartridge
;*
;******
start sei
jsr $ff84 ; init I/O devices / CIA timers
; jsr $ff87 ; init RAM, tape buffer, screen
; jsr $ff8a ; restore default IO vectors
jsr clone_fd50
jsr clone_fd15
jsr $ff81 ;(init screen and VIC-Chip the normal way)
jsr $e453 ; copy BASIC vectors to RAM
jsr $e3bf ; initialize basic
jsr $e422 ; print BASIC start up messages
lda #$0d
jsr $ffd2
jsr get_status
lda #<execute
ldy #>execute
sta $0308
sty $0309
cli
ldx #$80
jmp ($0300)
still_busy ldx #$02 ; file open error
jmp ($0300)
execute
jsr $0073
sta $fc
cmp #AT_TOKEN
beq send_command
cmp #$5F
beq send_command
+ jmp $a7e7
send_command
lda CMD_IF_CONTROL
and #CMD_STATE_BITS
cmp #CMD_STATE_IDLE
bne still_busy
; start forwarding string expression
jsr $0073
jsr $ad9e ; Evaluate Expression
bit $0d ; String?
bmi _copy_string_to_cmdif
; jmp _syntax
jsr $bddd ; Process numeric parameter
jsr $b487
_copy_string_to_cmdif ; equivalent of routine at AB21, but then outputs to I/O
jsr $b6a6 ; Fetch string parameters
tax
ldy #$00
inx
- dex
beq _str_done
lda ($22),y
cmp #$24
beq _hex
_wrcmdbyte sta CMD_IF_COMMAND
iny
jmp -
_hex iny
dex
beq _syntax ; should have a parameter!
lda ($22),y
sec
sbc #$30
cmp #$0A
bpl _no_digit1
- asl
asl
asl
asl
sta $fb
jmp _digit2
_no_digit1 sbc #$11
bmi _syntax
cmp #$06
bpl _syntax
adc #$0A
jmp -
_digit2 iny
dex
beq _syntax ; should have a parameter!
lda ($22),y
sec
sbc #$30
cmp #$0A
bpl _no_digit2
- ora $fb
jmp _wrcmdbyte
_no_digit2 sbc #$11
bmi _syntax
cmp #$06
bpl _syntax
adc #$0A
jmp -
_str_done
lda #CMD_PUSH_CMD
sta CMD_IF_CONTROL
; wait until command done OR until there is data to return
; in other words: wait as long as ultimate is processing
- jsr wait_while_busy
jsr print_result
jsr get_status
lda #CMD_NEXT_DATA
sta CMD_IF_CONTROL
lda CMD_IF_CONTROL
and #CMD_STATE_BITS
cmp #CMD_STATE_BUSY
beq -
_next_statement
jsr $0079
beq +
cmp #$3a
bne _syntax
+ jmp $a7ae
_syntax ldx #$0b
jmp ($0300)
print_result .proc
lda $fc
cmp #$5F
beq _print_hex
- lda CMD_IF_CONTROL
bpl +
lda CMD_IF_RESULT
jsr $ffd2
jmp -
+ lda #$0D
jmp $ffd2
_print_hex
- lda CMD_IF_CONTROL
bpl +
lda CMD_IF_RESULT
pha
and #$F0
lsr
lsr
lsr
lsr
tax
lda hex_chars,x
jsr $ffd2
pla
and #$0f
tax
lda hex_chars,x
jsr $ffd2
lda #$20
jsr $ffd2
jmp -
+ lda #$0D
jmp $ffd2
hex_chars .text "0123456789ABCDEF"
.pend
wait_while_busy .proc
- lda CMD_IF_CONTROL
and #CMD_STATE_BITS
cmp #CMD_STATE_BUSY
beq -
rts
.pend
get_status .proc
bit CMD_IF_CONTROL
bvs +
rts
+ lda #<status_string
ldy #>status_string
jsr $ab1e
- bit CMD_IF_CONTROL
bvc +
lda CMD_IF_STATUS
jsr $ffd2
jmp -
+ lda #$0d
jmp $ffd2
status_string .text "STATUS: ", $00
.pend
print_busy .proc
lda #<busy_string
ldy #>busy_string
jsr $ab1e
lda #$0d
jmp $ffd2
busy_string .text "?DEVICE BUSY", $00
.pend
print_abort .proc
lda #<busy_string
ldy #>busy_string
jsr $ab1e
lda #$0d
jmp $ffd2
busy_string .text "PENDING COMMAND ABORTED.", $00
.pend
.align $a000, $55