-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontroller.prg
More file actions
53 lines (45 loc) · 846 Bytes
/
controller.prg
File metadata and controls
53 lines (45 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define XHB_BITOP // Habilita das operações | & ^^
#include "xhb.ch"
#include "common.ch"
#include "hbclass.ch"
/*
const (
ButtonA = iota
ButtonB
ButtonSelect
ButtonStart
ButtonUp
ButtonDown
ButtonLeft
ButtonRight
)
*/
CREATE CLASS Controller
VAR buttons INIT {.f.,.f.,.f.,.f.,.f.,.f.,.f.,.f.} //[8]bool
VAR index INIT 0
VAR strobe INIT 0
METHOD New()
METHOD SetButtons(buttons)
METHOD Read()
METHOD Write(value)
END CLASS
METHOD New() CLASS Controller
Return Self
METHOD SetButtons(buttons) CLASS Controller
::buttons = buttons
return
METHOD Read() CLASS Controller
value := 0
if ::index < 8 .and. ::buttons[::index+1]
value = 1
end if
::index++
if (::strobe & 1) == 1
::index = 0
end if
return value
METHOD Write(value) CLASS Controller
::strobe = value
if (::strobe & 1) == 1
::index = 0
end if