1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-27 00:29:31 +00:00
cc65/libsrc/atari/shadow_ram_handlers.s

1122 lines
25 KiB
ArmAsm
Raw Normal View History

;
; Atari XL shadow RAM handlers
;
; Christian Groessler, chris@groessler.org, 2013
;
2013-10-01 09:32:08 +00:00
;DEBUG = 1
CHKBUF = 1 ; check if bounce buffering is needed (bounce buffering is always done if set to 0)
2013-06-10 12:22:30 +00:00
.ifdef __ATARIXL__
2013-10-01 09:32:08 +00:00
SHRAM_HANDLERS = 1
.include "atari.inc"
2013-09-27 20:01:54 +00:00
.include "save_area.inc"
.include "zeropage.inc"
.include "romswitch.inc"
2013-09-27 20:01:54 +00:00
.import __CHARGEN_START__
2013-09-27 20:01:54 +00:00
.export sram_init
.export KEYBDV_handler
.export CIO_handler
.export SIO_handler
.export SETVBV_handler
.export XMOVE_handler
2013-10-01 09:32:08 +00:00
BUFSZ = 128 ; bounce buffer size
2013-09-27 20:01:54 +00:00
BUFSZ_SIO = 256
2013-06-10 12:22:30 +00:00
.segment "ONCE"
; Turn off ROMs, install system and interrupt wrappers, set new chargen pointer
sram_init:
; disable all interrupts
2013-09-27 20:01:54 +00:00
ldx #0
stx NMIEN ; disable NMI
sei
; disable ROMs
2013-09-27 20:01:54 +00:00
disable_rom
; setup interrupt vectors
2013-09-27 20:01:54 +00:00
lda #<my_IRQ_han
sta $fffe
lda #>my_IRQ_han
sta $ffff
2013-09-27 20:01:54 +00:00
lda #<my_RESET_han
sta $fffc
lda #>my_RESET_han
sta $fffd
2013-09-27 20:01:54 +00:00
lda #<my_NMI_han
sta $fffa
lda #>my_NMI_han
sta $fffb
; enable interrupts
2013-09-27 20:01:54 +00:00
cli
lda #$40
sta NMIEN
2013-09-27 20:01:54 +00:00
rts
.segment "EXTZP" : zeropage
2013-09-27 20:01:54 +00:00
zpptr1: .res 2
2013-10-16 16:15:17 +00:00
.segment "LOWBSS"
2013-06-10 12:22:30 +00:00
; bounce buffers for CIO and SIO calls
2013-09-27 20:01:54 +00:00
bounce_buffer: .res BUFSZ_SIO
2013-06-10 12:22:30 +00:00
.segment "LOWCODE"
2013-06-10 12:22:30 +00:00
; Interrupt handlers
; ------------------
; The interrupt handlers don't look at the current state of PORTB and
; unconditionally disable the ROMs on exit.
; Please note that this works, since if the ROMs are enabled we anyway
; aren't being called here because the vectors are pointing to their
; original ROM locations.
2013-09-27 20:01:54 +00:00
.macro int_wrap orgvec
.local ret
pha
enable_rom_quick
lda #>ret
pha
lda #<ret
pha
php
jmp (orgvec)
ret: disable_rom_quick
pla
rti
.endmacro
my_IRQ_han:
.ifdef DEBUG
2013-09-27 20:01:54 +00:00
php
pha
tya
pha
ldy #0
lda (SAVMSC),y
clc
adc #1
sta (SAVMSC),y
pla
tay
pla
plp
.endif
2013-09-27 20:01:54 +00:00
int_wrap $FFFE
my_NMI_han:
.ifdef DEBUG
2013-09-27 20:01:54 +00:00
php
pha
tya
pha
ldy #39
lda (SAVMSC),y
clc
adc #1
sta (SAVMSC),y
pla
tay
pla
plp
.endif
; set I bit to interrupted value
2013-09-27 20:01:54 +00:00
pha
txa
pha
tsx
lda $103,x
pha
plp
pla
tax
pla
int_wrap $FFFA
my_RESET_han:
2013-09-27 20:01:54 +00:00
enable_rom
jmp ($FFFC)
2013-06-10 12:22:30 +00:00
; System request handlers
; -----------------------
; for filenames we assume they will fit into our bounce buffer
; one filename, terminated by "invalid character", located at ICBAL/ICBAH
CIO_filename:
.if CHKBUF
2013-09-27 20:01:54 +00:00
jsr chk_CIO_buf_fn
bcc CIO_call_a
.endif
2013-09-27 20:01:54 +00:00
jsr setup_zpptr1_y0
jsr copy_filename
CIO_fn_cont:
2013-09-27 20:01:54 +00:00
jsr bncbuf_to_iocb
ldy CIO_y
jsr CIO_call_a ; call CIO (maybe A isn't needed, then we could call CIO_call)
php
pha
jsr restore_icba ; restore original ICBAL/ICBAH
pla
plp
rts ; back to application
; two filenames, terminated and separated by "invalid character", located at ICBAL/ICBAH
CIO_filename2:
.if CHKBUF
2013-09-27 20:01:54 +00:00
jsr chk_CIO_buf_fn2
bcc CIO_call_a
.endif
2013-09-27 20:01:54 +00:00
jsr setup_zpptr1_y0
jsr copy_filename
iny
jsr copy_filename
jmp CIO_fn_cont
2013-06-10 12:22:30 +00:00
; CIO handler
; We have buffer pointer and length entries in the IOCB, but their
; usage depends on the function.
; Some functions don't care about any of them (pointer and length),
; and some only use the pointer (like e.g. OPEN), and some use both.
2013-06-10 12:22:30 +00:00
; So we need function specific handlers to correctly deal with
; buffers which are overlapping with the ROM area.
;
; FIXME: Currently only the requests used by the runtime lib are handled.
CIO_handler:
2013-06-10 12:22:30 +00:00
; @@@ TODO: check X for valid IOCB index ((X < $80) and ((X & $F) == 0))
2013-09-27 20:01:54 +00:00
sta CIO_a
sty CIO_y
stx CIO_x
lda ICCOM,x ; get function
cmp #OPEN
beq CIO_filename ; filename as input parameter in buffer, length not used
cmp #PUTREC
bcc CIO_read ; input (GETREC or GETCHR)
cmp #CLOSE
bcc CIO_write_jmp ; output (PUTREC or PUTCHR)
beq CIO_call_a ; pass through, buffer not used
cmp #RENAME ; 2 filenames as input parameters in buffer, length not used
beq CIO_filename2
cmp #GETCWD
bcc CIO_filename ; filename as input parameter in buffer, length not used
beq CIO_invalid ; GETCWD not supported yet
bcs CIO_call_a ; other commands: assume no buffer
; not reached
; enable ROM, call CIO, disable ROM
CIO_call_a:
2013-09-27 20:01:54 +00:00
lda CIO_a
CIOV_call:
2013-09-27 20:01:54 +00:00
pha
lda PORTB
sta cur_CIOV_PORTB
enable_rom
pla
jsr CIOV_org
php
pha
disable_rom_val cur_CIOV_PORTB
pla
plp
rts
2013-06-12 22:54:03 +00:00
CIO_write_jmp:
2013-09-27 20:01:54 +00:00
jmp CIO_write
2013-06-12 22:54:03 +00:00
CIO_invalid:
2013-09-27 20:01:54 +00:00
lda CIO_a
ldy #DINVCM
rts
2013-06-12 22:54:03 +00:00
; READ handler
; ------------
2013-06-10 12:22:30 +00:00
CIO_read:
2013-09-27 20:01:54 +00:00
lda ICBLL,x
ora ICBLH,x
beq CIO_call_a ; special I/O through A register in case buffer length is 0
.if CHKBUF
2013-09-27 20:01:54 +00:00
jsr chk_CIO_buf
bcc CIO_call_a
.endif
2013-06-12 22:54:03 +00:00
; If the data length is larger than our bounce buffer, we have to split the request into smaller ones.
; Otherwise we can get away with one call and a copy to the final destination afterwards.
2013-06-10 12:22:30 +00:00
2013-09-27 20:01:54 +00:00
lda ICBLH,x ; get high byte of length
bne big_read ; not zero -> data too large for our buffers
; CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES
lda #<BUFSZ
cmp ICBLL,x
bcc big_read
2013-06-10 12:22:30 +00:00
; Data size fits into bounce buffer
2013-06-10 12:22:30 +00:00
2013-09-27 20:01:54 +00:00
jsr setup_zpptr1
jsr bncbuf_to_iocb
jsr CIO_call_a ; call CIO
php
bpl @no_err
cpy #EOFERR
beq @no_err
pha
jsr restore_icba
pla
plp
rts ; return with error
2013-06-12 22:54:03 +00:00
@no_err:
2013-09-27 20:01:54 +00:00
sta CIO_a
sty CIO_y
2013-09-27 20:01:54 +00:00
jsr copy_to_user ; copy data into user buffer
jsr restore_icba
2013-09-27 20:01:54 +00:00
lda CIO_a
ldy CIO_y
plp
rts ; return with success
; Data size does not fit into bounce buffer
big_read:
2013-09-27 20:01:54 +00:00
lda #0
sta retlen ; initialize return length
sta retlen+1
jsr iocblen_to_orig_len
jsr iocbptr_to_orig_ptr
jsr setup_zpptr1
jsr bncbuf_to_iocb ; let ICBAL/ICBAH point to bounce buffer
br_loop:
2013-09-27 20:01:54 +00:00
jsr cmp_orig_len_bnc_bufsz ; is transfer length > bounce buffer size?
bcs br_last ; no, last transfer, use remaining size
2013-09-27 20:01:54 +00:00
lda #>BUFSZ
sta ICBLH,x ; set data length
lda #<BUFSZ
sta ICBLL,x
bne br_cont
br_last:
2013-09-27 20:01:54 +00:00
lda orig_len+1
sta ICBLH,x ; set data length
lda orig_len
sta ICBLL,x
br_cont:
2013-09-27 20:01:54 +00:00
sta req_len ; remember length of this request
lda ICBLH,x
sta req_len+1
jsr CIO_call_a ; do the request
php
bpl br_no_err
cpy #EOFERR
beq br_no_err
pha
jsr restore_icba
pla
plp
rts ; return with error
2013-06-10 12:22:30 +00:00
br_no_err:
2013-09-27 20:01:54 +00:00
sta CIO_a
sty CIO_y
pla
sta CIO_p
jsr copy_to_user
; update retlen
2013-09-27 20:01:54 +00:00
clc
lda retlen
adc ICBLL,x
sta retlen
lda retlen+1
adc #0
sta retlen+1
; if the request read less bytes than requested, we're done
2013-09-27 20:01:54 +00:00
lda ICBLL,x
cmp req_len
bne br_done
lda ICBLH,x
cmp req_len+1
bne br_done
; update user buffer pointer (zpptr1)
2013-09-27 20:01:54 +00:00
clc
lda zpptr1
adc ICBLL,x
sta zpptr1
lda zpptr1+1
adc #0
sta zpptr1+1
; update remaining length
2013-09-27 20:01:54 +00:00
sec
lda orig_len
sbc ICBLL,x
sta orig_len
lda orig_len+1
sbc #0
sta orig_len+1
; still something left to do (remaining length != 0)?
2013-09-27 20:01:54 +00:00
lda orig_len
ora orig_len+1
beq br_done
jmp br_loop
; done, write original buffer pointer and total transfer length to IOCB and return to application
br_done:
2013-09-27 20:01:54 +00:00
lda retlen
sta ICBLL,x
lda retlen+1
sta ICBLH,x
jsr orig_ptr_to_iocbptr
lda CIO_p
pha
lda CIO_a
ldy CIO_y
plp
rts ; return with success
2013-06-10 12:22:30 +00:00
2013-06-12 22:54:03 +00:00
CIO_call_a_jmp:
2013-09-27 20:01:54 +00:00
jmp CIO_call_a
2013-06-12 22:54:03 +00:00
; WRITE handler
; -------------
CIO_write:
2013-09-27 20:01:54 +00:00
lda ICBLL,x
ora ICBLH,x
beq CIO_call_a_jmp ; special I/O through A register in case buffer length is 0
2013-06-12 22:54:03 +00:00
.if CHKBUF
2013-09-27 20:01:54 +00:00
jsr chk_CIO_buf
bcc CIO_call_a_jmp
.endif
2013-06-12 22:54:03 +00:00
; If the data length is larger than our bounce buffer, we have to split the request into smaller ones.
; Otherwise we can get away with a copy to the bounce buffer and the call.
2013-09-27 20:01:54 +00:00
lda ICBLH,x ; get high byte of length
bne big_write ; not zero -> data too large for our buffers
; CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES
lda #<BUFSZ
cmp ICBLL,x
bcc big_write
2013-06-12 22:54:03 +00:00
; Data size fits into bounce buffer
2013-09-27 20:01:54 +00:00
jsr setup_zpptr1
jsr bncbuf_to_iocb
jsr copy_from_user
ldy CIO_y
jsr CIO_call_a
php
pha
jsr restore_icba
pla
plp
rts ; return to application
2013-06-12 22:54:03 +00:00
; Data size does not fit into bounce buffer
big_write:
2013-09-27 20:01:54 +00:00
lda #0
sta retlen ; initialize return length
sta retlen+1
jsr iocblen_to_orig_len
jsr iocbptr_to_orig_ptr
jsr setup_zpptr1
jsr bncbuf_to_iocb ; let ICBAL/ICBAH point to bounce buffer
2013-06-12 22:54:03 +00:00
bw_loop:
2013-09-27 20:01:54 +00:00
jsr cmp_orig_len_bnc_bufsz ; is transfer length > bounce buffer size?
bcs bw_last ; no, last transfer, use remaining size
2013-06-12 22:54:03 +00:00
2013-09-27 20:01:54 +00:00
lda #>BUFSZ
sta ICBLH,x ; set data length
lda #<BUFSZ
sta ICBLL,x
bne bw_cont
2013-06-12 22:54:03 +00:00
bw_last:
2013-09-27 20:01:54 +00:00
lda orig_len+1
sta ICBLH,x ; set data length
lda orig_len
sta ICBLL,x
2013-06-12 22:54:03 +00:00
bw_cont:
2013-09-27 20:01:54 +00:00
sta req_len ; remember length of this request
lda ICBLH,x
sta req_len+1
jsr copy_from_user
jsr CIO_call_a ; do the request
php
bpl bw_no_err
2013-06-12 22:54:03 +00:00
2013-09-27 20:01:54 +00:00
plp
rts ; error return
2013-06-12 22:54:03 +00:00
bw_no_err:
2013-09-27 20:01:54 +00:00
sta CIO_a
sty CIO_y
pla
sta CIO_p
2013-06-12 22:54:03 +00:00
; update retlen
2013-09-27 20:01:54 +00:00
clc
lda retlen
adc ICBLL,x
sta retlen
lda retlen+1
adc #0
sta retlen+1
2013-06-12 22:54:03 +00:00
; if the request wrote less bytes than requested, we're done
2013-09-27 20:01:54 +00:00
lda ICBLL,x
cmp req_len
bne bw_done
lda ICBLH,x
cmp req_len+1
bne bw_done
2013-06-12 22:54:03 +00:00
; update user buffer pointer (zpptr1)
2013-09-27 20:01:54 +00:00
clc
lda zpptr1
adc ICBLL,x
sta zpptr1
lda zpptr1+1
adc #0
sta zpptr1+1
2013-06-12 22:54:03 +00:00
; update remaining length
2013-09-27 20:01:54 +00:00
sec
lda orig_len
sbc ICBLL,x
sta orig_len
lda orig_len+1
sbc #0
sta orig_len+1
2013-06-12 22:54:03 +00:00
; still something left to do (remaining length != 0)?
2013-09-27 20:01:54 +00:00
lda orig_len
ora orig_len+1
beq bw_done
jmp bw_loop
2013-06-12 22:54:03 +00:00
bw_done:
2013-09-27 20:01:54 +00:00
lda retlen
sta ICBLL,x
lda retlen+1
sta ICBLH,x
jsr orig_ptr_to_iocbptr
lda CIO_p
pha
lda CIO_a
ldy CIO_y
plp
rts ; return with success
2013-06-12 22:54:03 +00:00
; check if length is larger than bounce buffer size
; input: orig_len - length
; output: A - destroyed
; CF - 0/1 for larger/not larger
2013-08-22 12:47:50 +00:00
cmp_orig_len_bnc_bufsz:
2013-09-27 20:01:54 +00:00
sec
lda #<BUFSZ
sbc orig_len
lda #>BUFSZ
sbc orig_len+1
rts
; copy data from bounce buffer into user buffer
; input: X - IOCB index
; zpptr1 - pointer to user buffer
; output: A - destroyed
2013-09-27 20:01:54 +00:00
; Y - 0
copy_to_user:
2013-09-27 20:01:54 +00:00
ldy ICBLL,x ; get # of bytes read (CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES)
beq @copy_done
@copy: dey
lda bounce_buffer,y
sta (zpptr1),y
cpy #0
bne @copy
2013-06-12 22:54:03 +00:00
@copy_done:
2013-09-27 20:01:54 +00:00
rts
2013-06-12 22:54:03 +00:00
; copy data from user buffer into bounce buffer
; input: X - IOCB index
; zpptr1 - pointer to user buffer
; output: A - destroyed
2013-09-27 20:01:54 +00:00
; Y - 0
2013-06-12 22:54:03 +00:00
copy_from_user:
2013-09-27 20:01:54 +00:00
ldy ICBLL,x ; get # of bytes to write (CHANGE HERE TO SUPPORT BOUNCE BUFFERS > 255 BYTES)
beq @copy_done
@copy: dey
lda (zpptr1),y
sta bounce_buffer,y
cpy #0
bne @copy
2013-06-12 22:54:03 +00:00
@copy_done:
2013-09-27 20:01:54 +00:00
rts
; copy ICBLL/ICBLH to 'orig_len'
; input: X - IOCB index
; output: A - destroyed
iocblen_to_orig_len:
2013-09-27 20:01:54 +00:00
lda ICBLL,x
sta orig_len
lda ICBLH,x
sta orig_len+1
rts
; copy ICBAL/ICBAH to 'orig_ptr'
; input: X - IOCB index
; output: A - destroyed
iocbptr_to_orig_ptr:
2013-09-27 20:01:54 +00:00
lda ICBAL,x
sta orig_ptr
lda ICBAH,x
sta orig_ptr+1
rts
2013-06-10 12:22:30 +00:00
; copy 'orig_ptr' to ICBAL/ICBAH
; input: X - IOCB index
; output: A - destroyed
orig_ptr_to_iocbptr:
2013-09-27 20:01:54 +00:00
lda orig_ptr
sta ICBAL,x
lda orig_ptr+1
sta ICBAH,x
rts
2013-06-10 12:22:30 +00:00
; restore original contents of ICBAL/ICBAH from 'zpptr1'
; input: X - IOCB index
; output: A - destroyed
restore_icba:
2013-09-27 20:01:54 +00:00
lda zpptr1
sta ICBAL,x
lda zpptr1+1
sta ICBAH,x
rts
2013-06-10 12:22:30 +00:00
; put bounce buffer address into ICBAL/ICBAH
; input: X - IOCB index
; output: A - destroyed
2013-08-22 12:47:50 +00:00
bncbuf_to_iocb:
2013-09-27 20:01:54 +00:00
lda #<bounce_buffer
sta ICBAL,x
lda #>bounce_buffer
sta ICBAH,x
rts
2013-06-10 12:22:30 +00:00
2013-08-22 12:47:50 +00:00
; copy file name pointed to by 'zpptr1' to 'bounce_buffer'
; input: Y - index into file name buffer and bounce_buffer
; output: Y - points to first invalid byte after file name
; A - destroyed
copy_filename:
2013-09-27 20:01:54 +00:00
lda (zpptr1),y
sta bounce_buffer,y
beq copy_fn_done
iny
cmp #ATEOL
bne copy_filename
dey
copy_fn_done:
2013-09-27 20:01:54 +00:00
rts
2013-06-10 12:22:30 +00:00
; write IOCB buffer address into zpptr1
; input: X - IOCB index
; output: Y - 0 (for setup_zpptr1_y0, else unchanged)
; A - destroyed
setup_zpptr1_y0:
2013-09-27 20:01:54 +00:00
ldy #0
setup_zpptr1:
2013-09-27 20:01:54 +00:00
lda ICBAL,x ; put buffer address into zp pointer
sta zpptr1
lda ICBAH,x
sta zpptr1+1
rts
.if CHKBUF
; get length of file name pointed to by 'zpptr1'
; input: Y - index into file name
; output: Y - length
; A - destroyed
get_fn_len:
2013-09-27 20:01:54 +00:00
lda (zpptr1),y
beq @done
iny
cmp #ATEOL
bne get_fn_len
dey
@done:
2013-09-27 20:01:54 +00:00
rts
chk_CIO_buf_fn2:
2013-09-27 20:01:54 +00:00
tya
pha
lda ICBLL,x
pha
lda ICBLH,x
pha
jsr setup_zpptr1_y0
jsr get_fn_len
iny ; include terminating zero
bne fn_cont
chk_CIO_buf_fn:
2013-09-27 20:01:54 +00:00
tya
pha
lda ICBLL,x
pha
lda ICBLH,x
pha
jsr setup_zpptr1_y0
fn_cont:jsr get_fn_len
iny ; include terminating zero
tya
sta ICBLL,x
lda #0
sta ICBLH,x
jsr chk_CIO_buf
pla
sta ICBLH,x
pla
sta ICBLL,x
pla
tay
rts
; check if a CIO input/output buffer overlaps with ROM area (>= $C000)
; input: X - IOCB index
2013-09-27 20:01:54 +00:00
; ICBAL/ICBAH/ICBLL/ICBLH - buffer address and length
; output: CF - 1/0 for overlap/no overlap
; A - destroyed
chk_CIO_buf:
2013-09-27 20:01:54 +00:00
lda ICBAH,x
cmp #$c0
bcc @cont
@ret:
.ifdef DEBUG
2013-09-27 20:01:54 +00:00
jsr CIO_buf_noti
.endif
2013-09-27 20:01:54 +00:00
rts
@cont: lda ICBAL,x
clc
adc ICBLL,x
lda ICBAH,x
adc ICBLH,x
bcs @ret ; ??? wraparound
cmp #$c0
.ifdef DEBUG
2013-09-27 20:01:54 +00:00
jsr CIO_buf_noti
.endif
2013-09-27 20:01:54 +00:00
rts
.ifdef DEBUG
; write to screen memory on 2nd line:
; pos 0: # of accesses without buffering
; pos 1: # of accesses with buffering
CIO_buf_noti:
2013-09-27 20:01:54 +00:00
php
pha
tya
pha
bcc @nobuf
inc CIObnval_dobuf
jmp @cont
@nobuf: inc CIObnval_nobuf
@cont: ldy #40
lda CIObnval_nobuf
sta (SAVMSC),y
ldy #41
lda CIObnval_dobuf
sta (SAVMSC),y
pla
tay
pla
plp
rts
CIObnval_dobuf:
2013-09-27 20:01:54 +00:00
.byte 0
CIObnval_nobuf:
2013-09-27 20:01:54 +00:00
.byte 0
.endif
2013-09-27 20:01:54 +00:00
.endif ; .if CHKBUF
;---------------------------------------------------------
2013-06-10 12:22:30 +00:00
2013-08-22 12:47:50 +00:00
; SIO handler
; We only handle SIO_STAT, SIO_READ, SIO_WRITE, and SIO_WRITEV.
; These are the only functions used by the runtime library currently.
; For other function we return NVALID status code.
SIO_handler:
2013-09-27 20:01:54 +00:00
lda DCOMND ; get command
cmp #SIO_STAT
beq SIO_stat
cmp #SIO_READ
beq SIO_read
cmp #SIO_WRITE
beq SIO_write
cmp #SIO_WRITEV
beq SIO_write
; unhandled command
lda #NVALID
SIO_err:sta DSTATS
rts
2013-08-22 12:47:50 +00:00
; SIO_STAT is always called with a low buffer (by the runtime)
SIO_stat:
2013-09-27 20:01:54 +00:00
; fall thru
2013-08-22 12:47:50 +00:00
SIO_call:
2013-09-27 20:01:54 +00:00
lda PORTB
sta cur_SIOV_PORTB
enable_rom
jsr SIOV_org
php
pha
disable_rom_val cur_SIOV_PORTB
pla
plp
rts
2013-08-22 12:47:50 +00:00
; SIO read handler
; ----------------
SIO_read:
.if CHKBUF
2013-09-27 20:01:54 +00:00
jsr chk_SIO_buf
bcc SIO_call
.endif
2013-08-22 12:47:50 +00:00
; we only support transfers <= bounce buffer size
2013-09-27 20:01:54 +00:00
jsr cmp_sio_len_bnc_bufsz
bcs sio_read_len_ok
2013-08-22 12:47:50 +00:00
2013-09-27 20:01:54 +00:00
lda #DERROR ; don't know a better status code for this
bne SIO_err
2013-08-22 12:47:50 +00:00
sio_read_len_ok:
2013-09-27 20:01:54 +00:00
lda DBUFLO
sta zpptr1 ; remember destination buffer address
lda DBUFHI
sta zpptr1+1
2013-08-22 12:47:50 +00:00
2013-09-27 20:01:54 +00:00
jsr bncbuf_to_dbuf ; put bounce buffer address to DBUFLO/DBUFHI
2013-08-22 12:47:50 +00:00
2013-09-27 20:01:54 +00:00
jsr SIO_call ; do the operation
pha
lda DSTATS ; get status
bmi sio_read_ret ; error
2013-08-22 12:47:50 +00:00
2013-09-27 20:01:54 +00:00
; copy data to user buffer
2013-08-22 12:47:50 +00:00
sio_read_ok:
2013-09-27 20:01:54 +00:00
lda DBYTHI ; could be 1 for 256 bytes
beq srok1
ldy #0
beq srok2
srok1: ldy DBYTLO
srok2: dey
2013-08-22 12:47:50 +00:00
sio_read_copy:
2013-09-27 20:01:54 +00:00
lda bounce_buffer,y
sta (zpptr1),y
dey
cpy #$ff
bne sio_read_copy
2013-08-22 12:47:50 +00:00
sio_read_ret:
2013-09-27 20:01:54 +00:00
jsr orgbuf_to_dbuf
2013-08-22 12:47:50 +00:00
2013-09-27 20:01:54 +00:00
pla
rts ; success return
2013-08-22 12:47:50 +00:00
; SIO write handler
; -----------------
SIO_write:
.if CHKBUF
2013-09-27 20:01:54 +00:00
jsr chk_SIO_buf
bcc SIO_call
.endif
2013-08-22 12:47:50 +00:00
; we only support transfers <= bounce buffer size
2013-09-27 20:01:54 +00:00
jsr cmp_sio_len_bnc_bufsz
bcs sio_write_len_ok
2013-08-22 12:47:50 +00:00
2013-09-27 20:01:54 +00:00
lda #DERROR ; don't know a better status code for this
jmp SIO_err
2013-08-22 12:47:50 +00:00
sio_write_len_ok:
2013-09-27 20:01:54 +00:00
lda DBUFLO
sta zpptr1 ; get source buffer address
lda DBUFHI
sta zpptr1+1
; copy data from user buffer to bounce buffer
lda DBYTHI ; could be 1 for 256 bytes
beq swok1
ldy #0
beq swok2
swok1: ldy DBYTLO
swok2: dey
2013-08-22 12:47:50 +00:00
sio_write_copy:
2013-09-27 20:01:54 +00:00
lda (zpptr1),y
sta bounce_buffer,y
dey
cpy #$ff
bne sio_write_copy
2013-08-22 12:47:50 +00:00
2013-09-27 20:01:54 +00:00
jsr bncbuf_to_dbuf ; put bounce buffer address to DBUFLO/DBUFHI
2013-08-22 12:47:50 +00:00
2013-09-27 20:01:54 +00:00
jsr SIO_call ; do the operation
pha
jsr orgbuf_to_dbuf
pla
rts
2013-08-22 12:47:50 +00:00
; check if SIO length is larger than bounce buffer size
; input: orig_len - length
; output: A - destroyed
; CF - 0/1 for larger/not larger
cmp_sio_len_bnc_bufsz:
2013-09-27 20:01:54 +00:00
sec
lda #<BUFSZ_SIO
sbc DBYTLO
lda #>BUFSZ_SIO
sbc DBYTHI
rts
2013-08-22 12:47:50 +00:00
; put bounce buffer address into DBUFLO/DBUFHI
; input: (--)
; output: A - destroyed
bncbuf_to_dbuf:
2013-09-27 20:01:54 +00:00
lda #<bounce_buffer
sta DBUFLO
lda #>bounce_buffer
sta DBUFHI
rts
2013-08-22 12:47:50 +00:00
; put original buffer address into DBUFLO/DBUFHI
; input: zpptr1 - original pointer
; output: A - destroyed
orgbuf_to_dbuf:
2013-09-27 20:01:54 +00:00
lda zpptr1
sta DBUFLO
lda zpptr1+1
sta DBUFHI
rts
2013-08-22 12:47:50 +00:00
.if CHKBUF
; check if a SIO input/output buffer overlaps with ROM area (>= $C000)
; input: DBUFLO/DBUFHI/DBYTLO/DBYTHI - buffer address and length
; output: CF - 1/0 for overlap/no overlap
; A - destroyed
chk_SIO_buf:
2013-09-27 20:01:54 +00:00
lda DBUFHI
cmp #$c0
bcc @cont
@ret:
.ifdef DEBUG
2013-09-27 20:01:54 +00:00
jsr SIO_buf_noti
.endif
2013-09-27 20:01:54 +00:00
rts
@cont: lda DBUFLO
clc
adc DBYTLO
lda DBUFHI
adc DBYTHI
bcs @ret ; ??? wraparound
cmp #$c0
.ifdef DEBUG
2013-09-27 20:01:54 +00:00
jsr SIO_buf_noti
.endif
2013-09-27 20:01:54 +00:00
rts
.ifdef DEBUG
; write to screen memory on 2nd line:
; pos 38: # of accesses without buffering
; pos 39: # of accesses with buffering
SIO_buf_noti:
2013-09-27 20:01:54 +00:00
php
pha
tya
pha
bcc @nobuf
inc SIObnval_dobuf
jmp @cont
@nobuf: inc SIObnval_nobuf
@cont: ldy #78
lda SIObnval_nobuf
sta (SAVMSC),y
ldy #79
lda SIObnval_dobuf
sta (SAVMSC),y
pla
tay
pla
plp
rts
SIObnval_dobuf:
2013-09-27 20:01:54 +00:00
.byte 0
SIObnval_nobuf:
2013-09-27 20:01:54 +00:00
.byte 0
.endif
2013-09-27 20:01:54 +00:00
.endif ; .if CHKBUF
;---------------------------------------------------------
2013-06-10 12:22:30 +00:00
KEYBDV_handler:
2013-06-10 12:22:30 +00:00
2013-09-27 20:01:54 +00:00
lda #>(kret-1)
pha
lda #<(kret-1)
pha
lda PORTB
sta cur_KEYBDV_PORTB
enable_rom
lda KEYBDV+5
pha
lda KEYBDV+4
pha
2013-09-27 20:01:54 +00:00
rts ; call keyboard handler
kret: pha
disable_rom_val cur_KEYBDV_PORTB
pla
rts
;---------------------------------------------------------
SETVBV_handler:
2013-09-27 20:01:54 +00:00
pha
lda PORTB
sta cur_SETVBV_PORTB
enable_rom
pla
jsr SETVBV_org
php
pha
disable_rom_val cur_SETVBV_PORTB
pla
plp
rts
;---------------------------------------------------------
XMOVE_handler:
pha
lda PORTB
sta cur_XMOVE_PORTB
enable_rom
pla
jsr XMOVE_org
php
pha
disable_rom_val cur_XMOVE_PORTB
pla
plp
rts
2013-09-27 20:01:54 +00:00
CIO_a: .res 1
CIO_x: .res 1
CIO_y: .res 1
CIO_p: .res 1
cur_CIOV_PORTB: .res 1
cur_SIOV_PORTB: .res 1
cur_KEYBDV_PORTB: .res 1
cur_SETVBV_PORTB: .res 1
cur_XMOVE_PORTB: .res 1
2013-09-27 20:01:54 +00:00
orig_ptr: .res 2
orig_len: .res 2
req_len: .res 2
retlen: .res 2
.endif ; .ifdef __ATARIXL__