ringbuffer: Fixed a few bugs.

This commit is contained in:
Martin Preuss
2023-01-22 00:16:42 +01:00
parent aeee0c6f64
commit 962d7c18a0

View File

@@ -68,15 +68,12 @@ RingBuffer_Alloc_l1:
mov r16, r20
; preset first byte (this is the length byte in COM module) with 0
push yl
push yh
clr r17
add yl, r16
adc yh, r17
std y+RINGBUFFER_OFFS_DATA, r17 ; (length byte in COM module)
std y+RINGBUFFER_OFFS_DATA+1, r17 ; (flags byte in COM module)
pop yh
pop yl
push r16
mov r18, r16
clr r16
rcall RingBuffer_Write
rcall RingBuffer_Write
pop r16
out SREG, r21 ; restore global interrupt enable bit in SREG
sec
@@ -113,7 +110,7 @@ RingBuffer_DeallocRead:
mov r20, r19 ; readpos
add r20, r16 ; readpos + to_dealloc
cp r20, r17 ; new readpos > max?
brcc RingBuffer_DeallocRead_l1 ; no, rjmp
brcs RingBuffer_DeallocRead_l1 ; no, rjmp
sub r20, r17 ; wrap around
RingBuffer_DeallocRead_l1:
std y+RINGBUFFER_OFFS_READPOS, r20
@@ -193,8 +190,8 @@ RingBuffer_Write:
pop yl
pop yh
inc r18
cp r18, r19
brcc RingBuffer_Write_end
cp r18, r19 ; r19 > r18; yes: CF set
brcs RingBuffer_Write_end
sub r18, r19
RingBuffer_Write_end:
@@ -230,7 +227,7 @@ RingBuffer_Read:
pop yh
inc r18
cp r18, r19
brcc RingBuffer_Read_end
brcs RingBuffer_Read_end
sub r18, r19
RingBuffer_Read_end: