-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathkey.go
81 lines (72 loc) · 1.54 KB
/
key.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"ndsemu/emu/hw"
"ndsemu/emu/hwio"
log "ndsemu/emu/logger"
)
type HwKey struct {
KeyIn hwio.Reg16 `hwio:"bank=0,offset=0x0,reset=0x3FF,readonly,rcb"`
KeyCnt hwio.Reg16 `hwio:"bank=0,offset=0x2,wcb"`
ExtKeyIn hwio.Reg16 `hwio:"bank=1,offset=0x6,reset=0x7F,readonly,rcb"`
penDown bool
}
func NewHwKey() *HwKey {
key := new(HwKey)
hwio.MustInitRegs(key)
return key
}
func (key *HwKey) SetPenDown(value bool) {
key.penDown = value
}
func (key *HwKey) WriteKEYCNT(_, val uint16) {
if val&(1<<14) != 0 {
log.ModInput.FatalZ("key interrupt not implemented").End()
}
}
func (key *HwKey) ReadKEYIN(val uint16) uint16 {
if KeyState[hw.SCANCODE_Z] != 0 {
val &^= 1 << 0
}
if KeyState[hw.SCANCODE_X] != 0 {
val &^= 1 << 1
}
if KeyState[hw.SCANCODE_RSHIFT] != 0 {
val &^= 1 << 2
}
if KeyState[hw.SCANCODE_RETURN] != 0 {
val &^= 1 << 3
}
if KeyState[hw.SCANCODE_RIGHT] != 0 {
val &^= 1 << 4
}
if KeyState[hw.SCANCODE_LEFT] != 0 {
val &^= 1 << 5
}
if KeyState[hw.SCANCODE_UP] != 0 {
val &^= 1 << 6
}
if KeyState[hw.SCANCODE_DOWN] != 0 {
val &^= 1 << 7
}
if KeyState[hw.SCANCODE_A] != 0 {
val &^= 1 << 8
}
if KeyState[hw.SCANCODE_S] != 0 {
val &^= 1 << 9
}
log.ModInput.InfoZ("read KEYIN").Hex16("val", val).End()
return val
}
func (key *HwKey) ReadEXTKEYIN(val uint16) uint16 {
if KeyState[hw.SCANCODE_D] != 0 {
val &^= 1 << 0
}
if KeyState[hw.SCANCODE_C] != 0 {
val &^= 1 << 1
}
if key.penDown {
val &^= 1 << 6
}
log.ModInput.InfoZ("read EXTKEYIN").Hex16("val", val).End()
return val
}