1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 23:29:39 +00:00

Merge pull request #2166 from colinleroy/rfc-serial-optimisation

Possible serial driver optimisations
This commit is contained in:
Bob Andrews 2023-09-08 18:42:39 +02:00 committed by GitHub
commit caf8186565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 113 additions and 124 deletions

View File

@ -26,6 +26,7 @@
.include "ser-error.inc"
.macpack module
.macpack cpu
; ------------------------------------------------------------------------
; Header. Includes jump table
@ -57,9 +58,13 @@
;----------------------------------------------------------------------------
; I/O definitions
.if (.cpu .bitand CPU_ISET_65C02)
ACIA = $C088
.else
Offset = $8F ; Move 6502 false read out of I/O to page $BF
ACIA = $C088-Offset
.endif
ACIA_DATA = ACIA+0 ; Data register
ACIA_STATUS = ACIA+1 ; Status register
ACIA_CMD = ACIA+2 ; Command register
@ -200,7 +205,9 @@ SER_OPEN:
asl
asl
asl
.if .not (.cpu .bitand CPU_ISET_65C02)
adc #Offset ; Assume carry to be clear
.endif
tax
; Check if the handshake setting is valid
@ -284,14 +291,9 @@ InvBaud:lda #SER_ERR_BAUD_UNAVAIL
SER_GET:
ldx Index
ldy SendFreeCnt ; Send data if necessary
iny ; Y == $FF?
beq :+
lda #$00 ; TryHard = false
jsr TryToSend
; Check for buffer empty
: lda RecvFreeCnt ; (25)
lda RecvFreeCnt ; (25)
cmp #$FF
bne :+
lda #SER_ERR_NO_DATA
@ -315,7 +317,11 @@ SER_GET:
inc RecvHead
inc RecvFreeCnt
ldx #$00 ; (59)
.if (.cpu .bitand CPU_ISET_65C02)
sta (ptr1)
.else
sta (ptr1,x)
.endif
txa ; Return code = 0
rts
@ -328,20 +334,21 @@ SER_PUT:
; Try to send
ldy SendFreeCnt
iny ; Y = $FF?
cpy #$FF ; Nothing to flush
beq :+
pha
lda #$00 ; TryHard = false
jsr TryToSend
pla
; Put byte into send buffer & send
: ldy SendFreeCnt
; Reload SendFreeCnt after TryToSend
ldy SendFreeCnt
bne :+
lda #SER_ERR_OVERFLOW
ldx #0 ; return value is char
rts
; Put byte into send buffer & send
: ldy SendTail
sta SendBuf,y
inc SendTail
@ -404,19 +411,19 @@ SER_IRQ:
and #$08
beq Done ; Jump if no ACIA interrupt
lda ACIA_DATA,x ; Get byte from ACIA
ldy RecvFreeCnt ; Check if we have free space left
ldx RecvFreeCnt ; Check if we have free space left
beq Flow ; Jump if no space in receive buffer
ldy RecvTail ; Load buffer pointer
sta RecvBuf,y ; Store received byte in buffer
inc RecvTail ; Increment buffer pointer
dec RecvFreeCnt ; Decrement free space counter
ldy RecvFreeCnt ; Check for buffer space low
cpy #33
cpx #33 ; Check for buffer space low
bcc Flow ; Assert flow control if buffer space low
rts ; Interrupt handled (carry already set)
; Assert flow control if buffer space too low
Flow: lda RtsOff
Flow: ldx Index
lda RtsOff
sta ACIA_CMD,x
sta Stopped
sec ; Interrupt handled
@ -427,12 +434,13 @@ Done: rts
TryToSend:
sta tmp1 ; Remember tryHard flag
Again: lda SendFreeCnt
NextByte:
lda SendFreeCnt
cmp #$FF
beq Quit ; Bail out
; Check for flow stopped
lda Stopped
Again: lda Stopped
bne Quit ; Bail out
; Check that ACIA is ready to send
@ -449,4 +457,4 @@ Send: ldy SendHead
sta ACIA_DATA,x
inc SendHead
inc SendFreeCnt
jmp Again
jmp NextByte

View File

@ -227,14 +227,8 @@ InvBaud:lda #<SER_ERR_BAUD_UNAVAIL
; returned.
SER_GET:
ldy SendFreeCnt ; Send data if necessary
iny ; Y == $FF?
beq :+
lda #$00 ; TryHard = false
jsr TryToSend
; Check for buffer empty
: lda RecvFreeCnt ; (25)
lda RecvFreeCnt ; (25)
cmp #$FF
bne :+
lda #SER_ERR_NO_DATA
@ -269,20 +263,21 @@ SER_GET:
SER_PUT:
; Try to send
ldy SendFreeCnt
iny ; Y = $FF?
cpy #$FF ; Nothing to flush
beq :+
pha
lda #$00 ; TryHard = false
jsr TryToSend
pla
; Put byte into send buffer & send
: ldy SendFreeCnt
; Reload SendFreeCnt after TryToSend
ldy SendFreeCnt
bne :+
lda #SER_ERR_OVERFLOW
ldx #0 ; return value is char
rts
; Put byte into send buffer & send
: ldy SendTail
sta SendBuf,y
inc SendTail
@ -329,19 +324,19 @@ SER_IRQ:
and #$08
beq Done ; Jump if no ACIA interrupt
lda ACIA::DATA,x ; Get byte from ACIA
ldy RecvFreeCnt ; Check if we have free space left
ldx RecvFreeCnt ; Check if we have free space left
beq Flow ; Jump if no space in receive buffer
ldy RecvTail ; Load buffer pointer
sta RecvBuf,y ; Store received byte in buffer
inc RecvTail ; Increment buffer pointer
dec RecvFreeCnt ; Decrement free space counter
ldy RecvFreeCnt ; Check for buffer space low
cpy #33
cpx #33
bcc Flow ; Assert flow control if buffer space low
rts ; Interrupt handled (carry already set)
; Assert flow control if buffer space too low
Flow: lda RtsOff
Flow: ldx Index ; Reload port
lda RtsOff
sta ACIA::CMD,x
sta Stopped
sec ; Interrupt handled
@ -352,12 +347,13 @@ Done: rts
TryToSend:
sta tmp1 ; Remember tryHard flag
Again: lda SendFreeCnt
NextByte:
lda SendFreeCnt
cmp #$FF
beq Quit ; Bail out
; Check for flow stopped
lda Stopped
Again: lda Stopped
bne Quit ; Bail out
; Check that ACIA is ready to send
@ -374,4 +370,4 @@ Send: ldy SendHead
sta ACIA::DATA
inc SendHead
inc SendFreeCnt
jmp Again
jmp NextByte

View File

@ -314,15 +314,10 @@ SER_CLOSE:
;
SER_GET:
ldx SendFreeCnt ; Send data if necessary
inx ; X == $FF?
beq @L1
lda #$00
jsr TryToSend
; Check for buffer empty
@L1: lda RecvFreeCnt ; (25)
lda RecvFreeCnt ; (25)
cmp #$ff
bne @L2
lda #SER_ERR_NO_DATA
@ -362,21 +357,23 @@ SER_PUT:
; Try to send
ldx SendFreeCnt
inx ; X = $ff?
cpx #$FF ; Nothing to flush
beq @L2
pha
lda #$00
jsr TryToSend
pla
; Put byte into send buffer & send
; Reload SendFreeCnt after TryToSend
@L2: ldx SendFreeCnt
bne @L3
ldx SendFreeCnt
bne @L2
lda #SER_ERR_OVERFLOW ; X is already zero
rts
@L3: ldx SendTail
; Put byte into send buffer & send
@L2: ldx SendTail
sta SendBuf,x
inc SendTail
dec SendFreeCnt
@ -466,25 +463,25 @@ NmiHandler:
sta tmp1 ; Remember tryHard flag
@L0: lda SendFreeCnt
cmp #$ff
beq @L3 ; Bail out
beq @L2 ; Bail out
; Check for flow stopped
@L1: lda Stopped
bne @L3 ; Bail out
bne @L2 ; Bail out
; Check that swiftlink is ready to send
@L2: lda ACIA_STATUS
lda ACIA_STATUS
and #$10
bne @L4
bne @L3
bit tmp1 ;keep trying if must try hard
bmi @L0
@L3: rts
bmi @L1
@L2: rts
; Send byte and try again
@L4: ldx SendHead
@L3: ldx SendHead
lda SendBuf,x
sta ACIA_DATA
inc SendHead

View File

@ -288,15 +288,10 @@ SER_CLOSE:
;
SER_GET:
ldx SendFreeCnt ; Send data if necessary
inx ; X == $FF?
beq @L1
lda #$00
jsr TryToSend
; Check for buffer empty
@L1: lda RecvFreeCnt ; (25)
lda RecvFreeCnt ; (25)
cmp #$ff
bne @L2
lda #SER_ERR_NO_DATA
@ -336,21 +331,23 @@ SER_PUT:
; Try to send
ldx SendFreeCnt
inx ; X = $ff?
cpx #$FF ; Nothing to flush
beq @L2
pha
lda #$00
jsr TryToSend
pla
; Put byte into send buffer & send
; Reload SendFreeCnt after TryToSend
@L2: ldx SendFreeCnt
bne @L3
ldx SendFreeCnt
bne @L2
lda #SER_ERR_OVERFLOW ; X is already zero
rts
@L3: ldx SendTail
; Put byte into send buffer & send
@L2: ldx SendTail
sta SendBuf,x
inc SendTail
dec SendFreeCnt
@ -443,25 +440,25 @@ NmiHandler:
sta tmp1 ; Remember tryHard flag
@L0: lda SendFreeCnt
cmp #$ff
beq @L3 ; Bail out
beq @L2 ; Bail out
; Check for flow stopped
@L1: lda Stopped
bne @L3 ; Bail out
bne @L2 ; Bail out
; Check that swiftlink is ready to send
@L2: lda ACIA_STATUS
lda ACIA_STATUS
and #$10
bne @L4
bne @L3
bit tmp1 ;keep trying if must try hard
bmi @L0
@L3: rts
bmi @L1
@L2: rts
; Send byte and try again
@L4: ldx SendHead
@L3: ldx SendHead
lda SendBuf,x
sta ACIA_DATA
inc SendHead

View File

@ -244,15 +244,10 @@ InvBaud:
;
SER_GET:
ldx SendFreeCnt ; Send data if necessary
inx ; X == $FF?
beq @L1
lda #$00
jsr TryToSend
; Check for buffer empty
@L1: lda RecvFreeCnt
lda RecvFreeCnt
cmp #$ff
bne @L2
lda #SER_ERR_NO_DATA
@ -292,21 +287,23 @@ SER_PUT:
; Try to send
ldx SendFreeCnt
inx ; X = $ff?
cpx #$FF ; Nothing to flush
beq @L2
pha
lda #$00
jsr TryToSend
pla
; Put byte into send buffer & send
; Reload SendFreeCnt after TryToSend
@L2: ldx SendFreeCnt
bne @L3
ldx SendFreeCnt
bne @L2
lda #SER_ERR_OVERFLOW ; X is already zero
rts
@L3: ldx SendTail
; Put byte into send buffer & send
@L2: ldx SendTail
sta SendBuf,x
inc SendTail
dec SendFreeCnt
@ -395,31 +392,31 @@ SER_IRQ:
sta IndReg ; Switch to the system bank
@L0: lda SendFreeCnt
cmp #$ff
beq @L3 ; Bail out
beq @L2 ; Bail out
; Check for flow stopped
@L1: lda Stopped
bne @L3 ; Bail out
bne @L2 ; Bail out
; Check that swiftlink is ready to send
@L2: ldy #ACIA::STATUS
ldy #ACIA::STATUS
lda (acia),y
and #$10
bne @L4
bne @L3
bit tmp1 ; Keep trying if must try hard
bmi @L0
bmi @L1
; Switch back the bank and return
@L3: lda ExecReg
@L2: lda ExecReg
sta IndReg
rts
; Send byte and try again
@L4: ldx SendHead
@L3: ldx SendHead
lda SendBuf,x
ldy #ACIA::DATA
sta (acia),y

View File

@ -245,15 +245,10 @@ InvBaud:
;
SER_GET:
ldx SendFreeCnt ; Send data if necessary
inx ; X == $FF?
beq @L1
lda #$00
jsr TryToSend
; Check for buffer empty
@L1: lda RecvFreeCnt
lda RecvFreeCnt
cmp #$ff
bne @L2
lda #SER_ERR_NO_DATA
@ -293,21 +288,23 @@ SER_PUT:
; Try to send
ldx SendFreeCnt
inx ; X = $ff?
cpx #$ff ; Nothing to flush
beq @L2
pha
lda #$00
jsr TryToSend
pla
; Put byte into send buffer & send
; Reload SendFreeCnt after TryToSend
@L2: ldx SendFreeCnt
bne @L3
ldx SendFreeCnt
bne @L2
lda #SER_ERR_OVERFLOW ; X is already zero
rts
@L3: ldx SendTail
; Put byte into send buffer & send
@L2: ldx SendTail
sta SendBuf,x
inc SendTail
dec SendFreeCnt
@ -395,31 +392,31 @@ SER_IRQ:
sta IndReg ; Switch to the system bank
@L0: lda SendFreeCnt
cmp #$ff
beq @L3 ; Bail out
beq @L2 ; Bail out
; Check for flow stopped
@L1: lda Stopped
bne @L3 ; Bail out
bne @L2 ; Bail out
; Check that swiftlink is ready to send
@L2: ldy #ACIA::STATUS
ldy #ACIA::STATUS
lda (acia),y
and #$10
bne @L4
bne @L3
bit tmp1 ; Keep trying if must try hard
bmi @L0
bmi @L1
; Switch back the bank and return
@L3: lda ExecReg
@L2: lda ExecReg
sta IndReg
rts
; Send byte and try again
@L4: ldx SendHead
@L3: ldx SendHead
lda SendBuf,x
ldy #ACIA::DATA
sta (acia),y

View File

@ -252,15 +252,10 @@ InvBaud:
;
SER_GET:
ldx SendFreeCnt ; Send data if necessary
inx ; X == $FF?
beq @L1
lda #$00
jsr TryToSend
; Check for buffer empty
@L1: lda RecvFreeCnt ; (25)
lda RecvFreeCnt ; (25)
cmp #$ff
bne @L2
lda #SER_ERR_NO_DATA
@ -300,21 +295,23 @@ SER_PUT:
; Try to send
ldx SendFreeCnt
inx ; X = $ff?
cpx #$ff ; Nothing to flush
beq @L2
pha
lda #$00
jsr TryToSend
pla
; Put byte into send buffer & send
; Reload SendFreeCnt after TryToSend
@L2: ldx SendFreeCnt
bne @L3
ldx SendFreeCnt
bne @L2
lda #SER_ERR_OVERFLOW ; X is already zero
rts
@L3: ldx SendTail
; Put byte into send buffer & send
@L2: ldx SendTail
sta SendBuf,x
inc SendTail
dec SendFreeCnt
@ -387,25 +384,25 @@ SER_IRQ:
sta tmp1 ; Remember tryHard flag
@L0: lda SendFreeCnt
cmp #$ff
beq @L3 ; Bail out
beq @L2 ; Bail out
; Check for flow stopped
@L1: lda Stopped
bne @L3 ; Bail out
bne @L2 ; Bail out
; Check that swiftlink is ready to send
@L2: lda ACIA_STATUS
lda ACIA_STATUS
and #$10
bne @L4
bne @L3
bit tmp1 ;keep trying if must try hard
bmi @L0
@L3: rts
bmi @L1
@L2: rts
; Send byte and try again
@L4: ldx SendHead
@L3: ldx SendHead
lda SendBuf,x
sta ACIA_DATA
inc SendHead