1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-23 04:30:10 +00:00

Straighten checking of the initialized flag in both, the C64 and C128

versions of rs232.s.
New include file common/rs232.inc, use the constants from this file instead
of defining them separately in each platform specific rs232 module.


git-svn-id: svn://svn.cc65.org/cc65/trunk@1208 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-03-25 06:06:52 +00:00
parent f709fd679b
commit 7d11fa012c
4 changed files with 128 additions and 146 deletions

View File

@ -29,6 +29,7 @@
.include "atari.inc" .include "atari.inc"
.include "../common/errno.inc" .include "../common/errno.inc"
.include "../common/rs232.inc"
.rodata .rodata
@ -130,17 +131,13 @@ cioerr: jsr fddecusage ; decrement usage counter of fd as open failed
; using 8 bit word size. So only 8 bit is currently tested. ; using 8 bit word size. So only 8 bit is currently tested.
; ;
; shouldn't this come from a "rs232.inc" ??
ErrNotInitialized = $01
ErrNoData = $04
.proc _rs232_params .proc _rs232_params
sta tmp2 sta tmp2
lda rshand lda rshand
cmp #$ff cmp #$ff
bne work ; work only if initialized bne work ; work only if initialized
lda #ErrNotInitialized lda #RS_ERR_NOT_INITIALIZED
bne done bne done
work: lda rshand work: lda rshand
ldx #0 ldx #0
@ -241,7 +238,7 @@ done: rts
ldy rshand ldy rshand
cpy #$ff cpy #$ff
bne work ; work only if initialized bne work ; work only if initialized
lda #ErrNotInitialized lda #RS_ERR_NOT_INITIALIZED
bne nierr bne nierr
work: sta ptr1 work: sta ptr1
@ -267,7 +264,7 @@ go: ; check whether there is any input available
beq nix_da ; no input waiting... beq nix_da ; no input waiting...
; input is available: get it! ; input is available: get it!
lda #GETCHR ; get raw bytes lda #GETCHR ; get raw bytes
sta ICCOM,x ; in command code sta ICCOM,x ; in command code
lda #0 lda #0
@ -282,11 +279,11 @@ go: ; check whether there is any input available
sta (ptr1,x) ; return received byte sta (ptr1,x) ; return received byte
txa txa
rts rts
nierr: ldx #0 nierr: ldx #0
rts rts
nix_da: lda #ErrNoData nix_da: lda #RS_ERR_NO_DATA
ldx #0 ldx #0
rts rts
@ -307,7 +304,7 @@ nix_da: lda #ErrNoData
ldy rshand ldy rshand
cpy #$ff cpy #$ff
bne work ; work only if initialized bne work ; work only if initialized
lda #ErrNotInitialized lda #RS_ERR_NOT_INITIALIZED
bne nierr bne nierr
work: pha work: pha

View File

@ -25,9 +25,10 @@
.importzp ptr1, ptr2, tmp1, tmp2 .importzp ptr1, ptr2, tmp1, tmp2
.import popa, popax .import popa, popax
.export _rs232_init, _rs232_params, _rs232_done, _rs232_get .export _rs232_init, _rs232_params, _rs232_done, _rs232_get
.export _rs232_put, _rs232_pause, _rs232_unpause, _rs232_status .export _rs232_put, _rs232_pause, _rs232_unpause, _rs232_status
.include "c128.inc" .include "c128.inc"
.include "../common/rs232.inc"
NmiExit = $ff33 ;exit address for nmi NmiExit = $ff33 ;exit address for nmi
@ -73,12 +74,6 @@ RegCommand = 2 ; Command register
RegControl = 3 ; Control register RegControl = 3 ; Control register
RegClock = 7 ; Turbo232 external baud-rate generator RegClock = 7 ; Turbo232 external baud-rate generator
; Error codes. Beware: The codes must match the codes in the C header file
ErrNotInitialized = $01
ErrBaudTooFast = $02
ErrBaudNotAvail = $03
ErrNoData = $04
ErrOverflow = $05
.code .code
@ -170,11 +165,12 @@ _rs232_init:
lda #$06 lda #$06
sta BaudCode sta BaudCode
;** return ; Done
lda #$ff
sta Initialized ldx #$ff
lda #$00 stx Initialized
tax inx ; X = 0
txa ; A = 0
rts rts
;---------------------------------------------------------------------------- ;----------------------------------------------------------------------------
@ -197,9 +193,9 @@ _rs232_init:
; ;
_rs232_params: _rs232_params:
jsr CheckInitialized ;** check initialized bit Initialized
bcc @L1 bmi @L1
rts jmp NotInitialized ; Return an error code
; Save new parity ; Save new parity
@ -221,8 +217,8 @@ _rs232_params:
beq @L3 beq @L3
cpx #4 cpx #4
bcs @L3 bcs @L3
@L2: lda #ErrBaudTooFast @L2: lda #RS_ERR_BAUD_TOO_FAST
bne @L9 bne @L9
; Set baud/parameters ; Set baud/parameters
@ -235,16 +231,16 @@ _rs232_params:
lda HackBauds,x lda HackBauds,x
@L4: cmp #$ff @L4: cmp #$ff
bne @L5 bne @L5
lda #ErrBaudNotAvail lda #RS_ERR_BAUD_NOT_AVAIL
bne @L9 bne @L9
@L5: tax @L5: tax
and #$30 and #$30
beq @L6 beq @L6
bit Turbo232 bit Turbo232
bmi @L6 bmi @L6
lda #ErrBaudNotAvail lda #RS_ERR_BAUD_NOT_AVAIL
bne @L9 bne @L9
@L6: lda tmp1 @L6: lda tmp1
and #$0f and #$0f
@ -262,7 +258,7 @@ _rs232_params:
beq @L7 beq @L7
lsr lsr
lsr lsr
lsr lsr
lsr lsr
eor #%00000011 eor #%00000011
sta ACIA+RegClock sta ACIA+RegClock
@ -322,7 +318,7 @@ _rs232_done:
@L9: lda #$00 @L9: lda #$00
sta Initialized sta Initialized
tax tax
rts rts
;---------------------------------------------------------------------------- ;----------------------------------------------------------------------------
@ -334,15 +330,14 @@ _rs232_done:
; ;
_rs232_get: _rs232_get:
jsr CheckInitialized ; Check if initialized bit Initialized
bcc @L1 bpl NotInitialized ; Jump if not initialized
rts
; Check for bytes to send ; Check for bytes to send
@L1: sta ptr1 @L1: sta ptr1
stx ptr1+1 ; Store pointer to received char stx ptr1+1 ; Store pointer to received char
ldx SendFreeCnt ldx SendFreeCnt
cpx #$ff cpx #$ff
beq @L2 beq @L2
lda #$00 lda #$00
@ -353,7 +348,7 @@ _rs232_get:
@L2: lda RecvFreeCnt @L2: lda RecvFreeCnt
cmp #$ff cmp #$ff
bne @L3 bne @L3
lda #ErrNoData lda #RS_ERR_NO_DATA
ldx #0 ldx #0
rts rts
@ -362,7 +357,7 @@ _rs232_get:
@L3: ldx Stopped @L3: ldx Stopped
beq @L4 beq @L4
cmp #63 cmp #63
bcc @L4 bcc @L4
lda #$00 lda #$00
sta Stopped sta Stopped
lda RtsOff lda RtsOff
@ -374,12 +369,21 @@ _rs232_get:
@L4: ldx RecvHead @L4: ldx RecvHead
lda RecvBuf,x lda RecvBuf,x
inc RecvHead inc RecvHead
inc RecvFreeCnt inc RecvFreeCnt
ldx #$00 ldx #$00
sta (ptr1,x) sta (ptr1,x)
txa ; Return code = 0 txa ; Return code = 0
rts rts
;----------------------------------------------------------------------------
;
; RS232 module not initialized
NotInitialized:
lda #<RS_ERR_NOT_INITIALIZED
ldx #>RS_ERR_NOT_INITIALIZED
rts
;---------------------------------------------------------------------------- ;----------------------------------------------------------------------------
; ;
; unsigned char __fastcall__ rs232_put (char B); ; unsigned char __fastcall__ rs232_put (char B);
@ -390,9 +394,8 @@ _rs232_get:
; ;
_rs232_put: _rs232_put:
jsr CheckInitialized ; Check initialized bit Initialized
bcc @L1 bpl NotInitialized ; Jump if not initialized
rts
; Try to send ; Try to send
@ -402,14 +405,14 @@ _rs232_put:
pha pha
lda #$00 lda #$00
jsr TryToSend jsr TryToSend
pla pla
; Put byte into send buffer & send ; Put byte into send buffer & send
@L2: ldx SendFreeCnt @L2: ldx SendFreeCnt
bne @L3 bne @L3
lda #ErrOverflow lda #RS_ERR_OVERFLOW
ldx #$00 ldx #$00
rts rts
@L3: ldx SendTail @L3: ldx SendTail
@ -429,10 +432,8 @@ _rs232_put:
; ;
_rs232_pause: _rs232_pause:
; Check initialized bit Initialized
jsr CheckInitialized bpl NotInitialized ; Jump if not initialized
bcc @L1
rts
; Assert flow control ; Assert flow control
@ -442,7 +443,7 @@ _rs232_pause:
; Delay for flow stop to be received ; Delay for flow stop to be received
ldx BaudCode ldx BaudCode
lda PauseTimes,x lda PauseTimes,x
jsr DelayMs jsr DelayMs
@ -472,17 +473,15 @@ PauseTimes:
; ;
_rs232_unpause: _rs232_unpause:
; Check initialized bit Initialized
jsr CheckInitialized bpl NotInitialized ; Jump if not initialized
bcc @L1
rts
; Re-enable rx interrupts & release flow control ; Re-enable rx interrupts & release flow control
@L1: lda #$00 @L1: lda #$00
sta Stopped sta Stopped
lda RtsOff lda RtsOff
ora #%00001000 ora #%00001000
sta ACIA+RegCommand sta ACIA+RegCommand
; Poll for stalled char & exit ; Poll for stalled char & exit
@ -500,17 +499,18 @@ _rs232_unpause:
; ;
_rs232_status: _rs232_status:
sta ptr2 sta ptr2
stx ptr2+1 stx ptr2+1
jsr popax jsr popax
sta ptr1 sta ptr1
stx ptr1+1 stx ptr1+1
jsr CheckInitialized bit Initialized
bcs @L9 bmi @L1
jmp NotInitialized
; Get status ; Get status
lda ACIA+RegStatus @L1: lda ACIA+RegStatus
ldy #0 ldy #0
sta (ptr1),y sta (ptr1),y
jsr PollReceive ; bug-recovery hack jsr PollReceive ; bug-recovery hack
@ -535,14 +535,14 @@ _rs232_status:
; Because of the C128 banking, the NMI handler must go into the non banked ; Because of the C128 banking, the NMI handler must go into the non banked
; memory, since the ROM NMI entry point will switch to a configuration where ; memory, since the ROM NMI entry point will switch to a configuration where
; only the lowest 16K of RAM are visible. We will place the NMI handler into ; only the lowest 16K of RAM are visible. We will place the NMI handler into
; it's own segment and map this segment into the lower 16K in the linker ; it's own segment and map this segment into the lower 16K in the linker
; config. ; config.
.segment "NMI" .segment "NMI"
NmiHandler: NmiHandler:
lda #CC65_MMU_CFG ;(2) lda #CC65_MMU_CFG ;(2)
sta MMU_CR ;(4) sta MMU_CR ;(4)
lda ACIA+RegStatus ;(4) ;status ;check for byte received lda ACIA+RegStatus ;(4) ;status ;check for byte received
and #$08 ;(2) and #$08 ;(2)
beq @L9 ;(2*) beq @L9 ;(2*)
@ -580,28 +580,10 @@ NmiHandler:
@L4: jmp NmiExit @L4: jmp NmiExit
@L9: jmp NmiContinue @L9: jmp NmiContinue
.code .code
;----------------------------------------------------------------------------
;
; CheckInitialized - internal check if initialized
; Set carry and an error code if not initialized, clear carry and do not
; change any registers if initialized.
;
CheckInitialized:
bit Initialized
bmi @L1
lda #ErrNotInitialized
ldx #0
sec
rts
@L1: clc
rts
;---------------------------------------------------------------------------- ;----------------------------------------------------------------------------
; Try to send a byte. Internal routine. A = TryHard ; Try to send a byte. Internal routine. A = TryHard

View File

@ -28,6 +28,7 @@
.export _rs232_put, _rs232_pause, _rs232_unpause, _rs232_status .export _rs232_put, _rs232_pause, _rs232_unpause, _rs232_status
.include "c64.inc" .include "c64.inc"
.include "../common/rs232.inc"
NmiExit = $febc ;exit address for nmi NmiExit = $febc ;exit address for nmi
@ -73,12 +74,6 @@ RegCommand = 2 ; Command register
RegControl = 3 ; Control register RegControl = 3 ; Control register
RegClock = 7 ; Turbo232 external baud-rate generator RegClock = 7 ; Turbo232 external baud-rate generator
; Error codes. Beware: The codes must match the codes in the C header file
ErrNotInitialized = $01
ErrBaudTooFast = $02
ErrBaudNotAvail = $03
ErrNoData = $04
ErrOverflow = $05
.code .code
@ -167,11 +162,12 @@ _rs232_init:
lda #$06 lda #$06
sta BaudCode sta BaudCode
;** return ; Done
lda #$ff
sta Initialized ldx #$ff
lda #$00 stx Initialized
tax inx ; X = 0
txa ; A = 0
rts rts
;---------------------------------------------------------------------------- ;----------------------------------------------------------------------------
@ -194,9 +190,9 @@ _rs232_init:
; ;
_rs232_params: _rs232_params:
jsr CheckInitialized ;** check initialized bit Initialized
bcc @L1 bmi @L1
rts jmp NotInitialized ; Return an error code
; Save new parity ; Save new parity
@ -218,7 +214,7 @@ _rs232_params:
beq @L3 beq @L3
cpx #4 cpx #4
bcs @L3 bcs @L3
@L2: lda #ErrBaudTooFast @L2: lda #RS_ERR_BAUD_TOO_FAST
bne @L9 bne @L9
; Set baud/parameters ; Set baud/parameters
@ -232,7 +228,7 @@ _rs232_params:
lda HackBauds,x lda HackBauds,x
@L4: cmp #$ff @L4: cmp #$ff
bne @L5 bne @L5
lda #ErrBaudNotAvail lda #RS_ERR_BAUD_NOT_AVAIL
bne @L9 bne @L9
@L5: tax @L5: tax
@ -240,7 +236,7 @@ _rs232_params:
beq @L6 beq @L6
bit Turbo232 bit Turbo232
bmi @L6 bmi @L6
lda #ErrBaudNotAvail lda #RS_ERR_BAUD_NOT_AVAIL
bne @L9 bne @L9
@L6: lda tmp1 @L6: lda tmp1
@ -331,13 +327,12 @@ _rs232_done:
; ;
_rs232_get: _rs232_get:
jsr CheckInitialized ; Check if initialized bit Initialized
bcc @L1 bpl NotInitialized ; Jump if not initialized
rts
; Check for bytes to send ; Check for bytes to send
@L1: sta ptr1 sta ptr1
stx ptr1+1 ; Store pointer to received char stx ptr1+1 ; Store pointer to received char
ldx SendFreeCnt ldx SendFreeCnt
cpx #$ff cpx #$ff
@ -350,7 +345,7 @@ _rs232_get:
@L2: lda RecvFreeCnt @L2: lda RecvFreeCnt
cmp #$ff cmp #$ff
bne @L3 bne @L3
lda #ErrNoData lda #RS_ERR_NO_DATA
ldx #0 ldx #0
rts rts
@ -377,6 +372,15 @@ _rs232_get:
txa ; Return code = 0 txa ; Return code = 0
rts rts
;----------------------------------------------------------------------------
;
; RS232 module not initialized
NotInitialized:
lda #<RS_ERR_NOT_INITIALIZED
ldx #>RS_ERR_NOT_INITIALIZED
rts
;---------------------------------------------------------------------------- ;----------------------------------------------------------------------------
; ;
; unsigned char __fastcall__ rs232_put (char B); ; unsigned char __fastcall__ rs232_put (char B);
@ -387,13 +391,12 @@ _rs232_get:
; ;
_rs232_put: _rs232_put:
jsr CheckInitialized ; Check initialized bit Initialized
bcc @L1 bpl NotInitialized ; Jump if not initialized
rts
; Try to send ; Try to send
@L1: ldx SendFreeCnt ldx SendFreeCnt
cpx #$ff cpx #$ff
beq @L2 beq @L2
pha pha
@ -405,7 +408,7 @@ _rs232_put:
@L2: ldx SendFreeCnt @L2: ldx SendFreeCnt
bne @L3 bne @L3
lda #ErrOverflow lda #RS_ERR_OVERFLOW
ldx #$00 ldx #$00
rts rts
@ -426,14 +429,12 @@ _rs232_put:
; ;
_rs232_pause: _rs232_pause:
; Check initialized bit Initialized
jsr CheckInitialized bpl NotInitialized ; Jump if not initialized
bcc @L1
rts
; Assert flow control ; Assert flow control
@L1: lda RtsOff lda RtsOff
sta Stopped sta Stopped
sta ACIA+RegCommand sta ACIA+RegCommand
@ -469,10 +470,8 @@ PauseTimes:
; ;
_rs232_unpause: _rs232_unpause:
; Check initialized bit Initialized
jsr CheckInitialized bpl NotInitialized ; Jump if not initialized
bcc @L1
rts
; Re-enable rx interrupts & release flow control ; Re-enable rx interrupts & release flow control
@ -501,13 +500,14 @@ _rs232_status:
stx ptr2+1 stx ptr2+1
jsr popax jsr popax
sta ptr1 sta ptr1
stx ptr1+1 stx ptr1+1
jsr CheckInitialized bit Initialized
bcs @L9 bmi @L1
jmp NotInitialized
; Get status ; Get status
lda ACIA+RegStatus @L1: lda ACIA+RegStatus
ldy #0 ldy #0
sta (ptr1),y sta (ptr1),y
jsr PollReceive ; bug-recovery hack jsr PollReceive ; bug-recovery hack
@ -564,7 +564,7 @@ NmiHandler:
; Drop this char ; Drop this char
@L3: inc DropCnt+0 ;not time-critical @L3: inc DropCnt+0 ; not time-critical
bne @L4 bne @L4
inc DropCnt+1 inc DropCnt+1
bne @L4 bne @L4
@ -574,25 +574,7 @@ NmiHandler:
@L4: jmp NmiExit @L4: jmp NmiExit
@L9: pla @L9: pla
jmp NmiContinue jmp NmiContinue
;----------------------------------------------------------------------------
;
; CheckInitialized - internal check if initialized
; Set carry and an error code if not initialized, clear carry and do not
; change any registers if initialized.
;
CheckInitialized:
bit Initialized
bmi @L1
lda #ErrNotInitialized
ldx #0
sec
rts
@L1: clc
rts
;---------------------------------------------------------------------------- ;----------------------------------------------------------------------------
; Try to send a byte. Internal routine. A = TryHard ; Try to send a byte. Internal routine. A = TryHard

21
libsrc/common/rs232.inc Normal file
View File

@ -0,0 +1,21 @@
;
; rs232.inc
;
; (C) Copyright 2002 Ullrich von Bassewitz (uz@cc65.org)
;
; Assembler include file that makes the constants and structures from rs232.h
; available for asm code.
; Error codes returned by all functions
RS_ERR_OK = $00 ; Not an error - relax
RS_ERR_NOT_INITIALIZED = $01 ; Module not initialized
RS_ERR_BAUD_TOO_FAST = $02 ; Cannot handle baud rate
RS_ERR_BAUD_NOT_AVAIL = $03 ; Baud rate not available
RS_ERR_NO_DATA = $04 ; Nothing to read
RS_ERR_OVERFLOW = $05 ; No room in send buffer