Ringpuffer
Verfasst: Di 27. Aug 2019, 11:28
Hallo,
hat schon ein mal jemand so etwas Programmiert?
hat schon ein mal jemand so etwas Programmiert?
Retro Style Eigenbau Computer mit Parallax Propeller
https://www.hive-project.de/board/
Sowas steckt vermutlich in jedem seriellen Objekt mit Sende-/Empfangspuffer.PIC18F2550 hat geschrieben:hat schon ein mal jemand so etwas Programmiert?
Code: Alles auswählen
CON
BUFFER_LENGTH = 2048 'Recommended as 64 or higher, but can be 2, 4, 8, 16, 32, 64, 128 256.
BUFFER_MASK = BUFFER_LENGTH - 1
VAR
long head
long tail
byte buffer[BUFFER_LENGTH]
PUB Start
longfill(@head, 0, 2)
PUB CharOut(a)
repeat until (tail <> ((head + 1) & BUFFER_MASK)) ' Warten auf Platz im Buffer
buffer[head] := a
head := (head + 1) & BUFFER_MASK
PUB CharIn : a
repeat while (a := Check) < 0
PRI Check : a
a~~
if tail <> head
a := buffer[tail]
tail := (tail + 1) & BUFFER_MASK
PUB Count : a
a := head - tail
a -= BUFFER_LENGTH*(a < 0)