Skip to content

Commit ccdffb4

Browse files
committed
Replace SioInit impl with call to SioReset.
- move SioReset up near SioInit - move buffer clear impls into SioReset
1 parent 63e5ea1 commit ccdffb4

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

unbricked/serial-link/sio.asm

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,9 @@ SECTION "SioCore Impl", ROM0
9696
; NOTE: Enables the serial interrupt.
9797
; @mut: AF, [IE]
9898
SioInit::
99+
call SioReset
99100
ld a, SIO_IDLE
100101
ld [wSioState], a
101-
ld a, 0
102-
ld [wSioTimer], a
103-
ld [wSioCount], a
104-
ld [wSioBufferOffset], a
105-
call SioClearBufferRx
106-
call SioClearBufferTx
107102

108103
; enable serial interrupt
109104
ldh a, [rIE]
@@ -112,20 +107,31 @@ SioInit::
112107
ret
113108

114109

110+
; Completely reset Sio. Any active transfer will be stopped.
111+
; Sio will return to the `SIO_IDLE` state on the next call to `SioTick`.
115112
; @mut: AF, C, HL
116-
SioClearBufferRx:
117-
ld hl, wSioBufferRx
113+
SioReset::
114+
; bring the serial port down
115+
ldh a, [rSC]
116+
res SCB_START, a
117+
ldh [rSC], a
118+
; reset Sio state variables
119+
ld a, SIO_RESET
120+
ld [wSioState], a
121+
ld a, 0
122+
ld [wSioTimer], a
123+
ld [wSioCount], a
124+
ld [wSioBufferOffset], a
125+
; clear the Tx/Rx buffers
126+
ld hl, wSioBufferTx
118127
ld c, SIO_BUFFER_SIZE
119128
ld a, SIO_BUFFER_CLEAR
120-
jr SioMemFill
121-
122-
123-
; @mut: AF, C, HL
124-
SioClearBufferTx:
125-
ld hl, wSioBufferTx
129+
call SioMemFill
130+
ld hl, wSioBufferRx
126131
ld c, SIO_BUFFER_SIZE
127132
ld a, SIO_BUFFER_CLEAR
128-
jr SioMemFill
133+
call SioMemFill
134+
ret
129135

130136

131137
; Fill a contiguous block of memory with the same value.
@@ -177,20 +183,6 @@ SioAbort::
177183
res SCB_START, a
178184
ldh [rSC], a
179185
ret
180-
181-
182-
SioReset::
183-
ldh a, [rSC]
184-
res SCB_START, a
185-
ldh [rSC], a
186-
ld a, SIO_RESET
187-
ld [wSioState], a
188-
ld a, 0
189-
ld [wSioTimer], a
190-
ld [wSioCount], a
191-
ld [wSioBufferOffset], a
192-
call SioClearBufferRx
193-
jp SioClearBufferTx
194186
; ANCHOR_END: sio-tick
195187

196188

0 commit comments

Comments
 (0)