Attribute VB_Name = "modRing"
Option Explicit

'Ring buffer

Public Enum key_kind
    K_CF = 1
    K_SP
    K_RL
    K_RB
    K_VB
    K_SW
    K_IP
    K_SI
    K_MK
    K_TRA
    K_TRB
    K_MKD
    K_MSS
End Enum
Public Type KeyStack
    keyKind As Integer
    keyIdx As Integer
End Type
Const RingMax = 11
Public kStack(RingMax) As KeyStack
Public kstST As Integer, kstSP As Integer

Public Function getKeyRing() As KeyStack
Dim kdt As KeyStack
If kstST = kstSP Then   'empty Ring
    kdt.keyKind = 0
    kdt.keyIdx = 0
Else
    kdt.keyIdx = kStack(kstST).keyIdx   'Get Ring
    kdt.keyKind = kStack(kstST).keyKind
    Debug.Print "GET RING>", kdt.keyKind, kdt.keyIdx, kstST
    kStack(kstST).keyIdx = 0            'Clear Ring
    kStack(kstST).keyKind = 0
    kstST = kstST + 1
    If kstST > RingMax Then
        kstST = 0
    End If
    getKeyRing = kdt
End If

End Function

Public Sub setKeyRing(kknd As Integer, kidx As Integer)
kStack(kstSP).keyIdx = kidx   'Set Ring
kStack(kstSP).keyKind = kknd
Debug.Print "SET RING>", kknd, kidx, kstST
kstSP = kstSP + 1
If kstSP > RingMax Then
    kstSP = 0
End If

End Sub
