-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.cpp
118 lines (105 loc) · 3.55 KB
/
kernel.cpp
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// kernel.cpp
//
// Circle - A C++ bare metal environment for Raspberry Pi
// Copyright (C) 2014-2021 R. Stange <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#include "kernel.h"
#include "msx2def.h"
#define TAG "kernel"
int msxPad1 = 0;
CKernel::CKernel(void) :
#ifdef MSX2_DISPLAY_HALF_HORIZONTAL
screen(320, 240),
#else
screen(640, 480),
#endif
timer(&interrupt),
logger(options.GetLogLevel(), &timer),
usb(&interrupt, &timer, TRUE),
vchiq(CMemorySystem::Get(), &interrupt),
sound(&vchiq, (TVCHIQSoundDestination)options.GetSoundOption()),
gamePad(nullptr)
{
led.Blink(5); // show we are alive
}
CKernel::~CKernel(void)
{
}
boolean CKernel::initialize(void)
{
boolean bOK = TRUE;
led.On();
if (bOK) {
bOK = screen.Initialize();
}
if (bOK) {
bOK = serial.Initialize(115200);
}
if (bOK) {
CDevice* target = deviceNameService.GetDevice(options.GetLogDevice(), FALSE);
if (target == 0) {
target = &screen;
}
bOK = logger.Initialize(target);
}
if (bOK) {
logger.Write(TAG, LogNotice, "init interrupt");
bOK = interrupt.Initialize();
}
if (bOK) {
logger.Write(TAG, LogNotice, "init timer");
bOK = timer.Initialize();
}
if (bOK) {
logger.Write(TAG, LogNotice, "init vchiq");
bOK = vchiq.Initialize();
}
if (bOK) {
logger.Write(TAG, LogNotice, "init usb");
bOK = usb.Initialize();
}
if (bOK) {
led.Off();
}
return bOK;
}
void CKernel::updateUsbStatus(void)
{
if (usb.UpdatePlugAndPlay()) {
if (!gamePad) {
gamePad = (CUSBGamePadDevice*)deviceNameService.GetDevice("upad1", FALSE);
if (gamePad) {
gamePad->RegisterStatusHandler([](unsigned index, const TGamePadState* state) {
msxPad1 = 0;
msxPad1 |= state->axes[0].value == state->axes[0].minimum ? MSX2_JOY_LE : 0;
msxPad1 |= state->axes[0].value == state->axes[0].maximum ? MSX2_JOY_RI : 0;
msxPad1 |= state->axes[1].value == state->axes[1].minimum ? MSX2_JOY_UP : 0;
msxPad1 |= state->axes[1].value == state->axes[1].maximum ? MSX2_JOY_DW : 0;
msxPad1 |= (state->buttons & 0x0001) ? MSX2_JOY_T2 : 0;
msxPad1 |= (state->buttons & 0x0002) ? MSX2_JOY_T1 : 0;
msxPad1 |= (state->buttons & 0x0100) ? MSX2_JOY_S2 : 0;
msxPad1 |= (state->buttons & 0x0200) ? MSX2_JOY_S1 : 0;
});
}
} else {
if (!(CUSBGamePadDevice*)deviceNameService.GetDevice("upad1", FALSE)) {
gamePad = nullptr;
msxPad1 = 0;
}
}
}
}