1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-09 16:29:09 +00:00

better error handling; rs232_params now uses its parameters

git-svn-id: svn://svn.cc65.org/cc65/trunk@1139 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cpg 2001-12-10 22:55:06 +00:00
parent d198ba0e26
commit b39cc5a3a9

View File

@ -18,9 +18,10 @@
.import __seterrno, __do_oserror, __oserror .import __seterrno, __do_oserror, __oserror
.import fddecusage .import fddecusage
.import fdtoiocb .import fdtoiocb
.import __inviocb
.import clriocb .import clriocb
.import newfd .import newfd
.import _close, pushax, popax .import _close, pushax, popax, popa
.importzp ptr1, tmp2, tmp3 .importzp ptr1, tmp2, tmp3
.export _rs232_init, _rs232_params, _rs232_done, _rs232_get .export _rs232_init, _rs232_params, _rs232_done, _rs232_get
@ -35,10 +36,10 @@ rdev: .byte "R:", ATEOL, 0
.bss .bss
RECVBUF_SZ = 256
; receive buffer ; receive buffer
RECVBUF_SZ = 256
recv_buf: .res RECVBUF_SZ recv_buf: .res RECVBUF_SZ
cm_run: .res 1 ; concurrent mode running? cm_run: .res 1 ; concurrent mode running?
.data .data
@ -119,33 +120,23 @@ cioerr: jsr fddecusage ; decrement usage counter of fd as open failed
;---------------------------------------------------------------------------- ;----------------------------------------------------------------------------
; ;
; unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity); ; unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity);
; /* Set the port parameters. Use a combination of the #defined values above. */
; ;
; Set communication parameters. ; Set communication parameters.
; ;
; @@@ C64 values @@@ fixit ; params contains baud rate, stop bits and word size
; baud rates stops word | parity ; parity contains parity
; --------------------- ----- ----- | --------- ;
; $00=50 $08=9600 $00=1 $00=8 | $00=none ; 850 manual documents restrictions on the baud rate (not > 300), when not
; $01=110 $09=19200 $80=2 $20=7 | $20=odd ; using 8 bit word size. So only 8 bit is currently tested.
; $02=134.5 $0a=38400 $40=6 | $60=even
; $03=300 $0b=57600 $60=5 | $A0=mark
; $04=600 $0c=115200 | $E0=space
; $05=1200 $0d=230400
; $06=2400 $0e=future
; $07=4800 $0f=future
; ;
; we don't support word sizes != 8 (will never)
; ignore parity for now, always none
; ignore baud rate for now, always 9600
; shouldn't this come from a "rs232.inc" ?? ; shouldn't this come from a "rs232.inc" ??
ErrNotInitialized = $01 ErrNotInitialized = $01
ErrNoData = $04 ErrNoData = $04
.proc _rs232_params .proc _rs232_params
sta tmp2
lda rshand lda rshand
cmp #$ff cmp #$ff
bne work ; work only if initialized bne work ; work only if initialized
@ -154,7 +145,7 @@ cioerr: jsr fddecusage ; decrement usage counter of fd as open failed
work: lda rshand work: lda rshand
ldx #0 ldx #0
jsr fdtoiocb ; get iocb index into X jsr fdtoiocb ; get iocb index into X
; bmi inverr ; !?!? bmi inverr ; shouldn't happen
tax tax
; set handshake lines ; set handshake lines
@ -170,30 +161,38 @@ work: lda rshand
sta ICBAH,x sta ICBAH,x
sta ICAX2,x sta ICAX2,x
jsr CIOV jsr CIOV
bmi cioerr
; set baud rate, word size, stop bits and ready monitoring ; set baud rate, word size, stop bits and ready monitoring
lda #36 ; xio 36, baud rate lda #36 ; xio 36, baud rate
sta ICCOM,x sta ICCOM,x
lda #14 ; 9600 baud jsr popa ; get parameter
sta ICAX1,x sta ICAX1,x
;ICAX2 = 0, monitor nothing ;ICAX2 = 0, monitor nothing
jsr CIOV jsr CIOV
bmi cioerr
; set translation and parity ; set translation and parity
lda #38 ; xio 38, translation and parity lda #38 ; xio 38, translation and parity
sta ICCOM,x sta ICCOM,x
lda #32 ; no translation, no parity lda tmp2
ora #32 ; no translation
sta ICAX1,x sta ICAX1,x
jsr CIOV jsr CIOV
bmi cioerr
lda #0 lda #0
done: ldx #0 done: ldx #0
rts rts
inverr: jmp __inviocb
.endproc ;_rs232_params .endproc ;_rs232_params
cioerr: jmp __do_oserror
;---------------------------------------------------------------------------- ;----------------------------------------------------------------------------
; ;
@ -209,12 +208,8 @@ done: ldx #0
lda rshand lda rshand
cmp #$ff cmp #$ff
; bne work
; lda rshand+1
; cmp #$ff
beq done beq done
work: lda rshand work: ldx rshand+1
ldx rshand+1
jsr pushax jsr pushax
jsr _close jsr _close
pha pha
@ -241,8 +236,6 @@ done: rts
; */ ; */
; ;
.import _cputc
.proc _rs232_get .proc _rs232_get
ldy rshand ldy rshand
@ -267,27 +260,12 @@ go: ; check whether there is any input available
lda #STATIS ; status request, returns bytes pending lda #STATIS ; status request, returns bytes pending
sta ICCOM,x sta ICCOM,x
jsr CIOV jsr CIOV
; bmi cioerr ; @@@ error handling bmi cioerr ; @@@ error handling
lda DVSTAT+1 ; get byte count pending lda DVSTAT+1 ; get byte count pending
ora DVSTAT+2 ora DVSTAT+2
beq nix_da ; no input waiting... beq nix_da ; no input waiting...
.ifdef DEBUG
pha
txa
pha
tya
pha
lda #'D'
jsr _cputc
pla
tay
pla
tax
pla
.endif
; input is available: get it! ; input is available: get it!
lda #GETCHR ; get raw bytes lda #GETCHR ; get raw bytes
@ -298,7 +276,7 @@ go: ; check whether there is any input available
sta ICBAL,x sta ICBAL,x
sta ICBAH,x sta ICBAH,x
jsr CIOV ; go get it jsr CIOV ; go get it
; bmi cioerr ; @@@ error handling bmi cioerr ; @@@ error handling
ldx #0 ldx #0
sta (ptr1,x) ; return received byte sta (ptr1,x) ; return received byte