Skip to content

Commit 5383bf4

Browse files
committed
EMCC: Emscripten version wip
- implemented audio - update keyboard handling
1 parent 22f108b commit 5383bf4

8 files changed

Lines changed: 29 additions & 65 deletions

File tree

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2022-02-23 (12.24)
2+
EMCC: Implemented emscripten web version
3+
14
2022-02-23 (12.24)
25
COMMON: Fix array access with embedded strings #136
36

src/platform/emcc/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ sbasic_html_SOURCES = \
3737
../../ui/textedit.cpp \
3838
../../ui/image.cpp \
3939
../../ui/strlib.cpp \
40+
../../ui/audio.cpp \
4041
runtime.h runtime.cpp \
4142
canvas.h canvas.cpp \
4243
main.cpp

src/platform/emcc/canvas.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,3 @@ int maFontDelete(MAHandle maHandle) {
397397
}
398398
return RES_FONT_OK;
399399
}
400-
401-
//
402-
// not implemented
403-
//
404-
void maShowVirtualKeyboard(void) {
405-
}
406-
407-
void maHideVirtualKeyboard(void) {
408-
}
409-
410-
void maUpdateScreen(void) {
411-
}

src/platform/emcc/keymap.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,6 @@ const int SHIFT_KEYMAP[][2] = {
7979
{DOM_VK_9, '('},
8080
{DOM_VK_COLON, ':'},
8181
{DOM_VK_EQUALS, '+'},
82-
{DOM_VK_A, 'a'},
83-
{DOM_VK_B, 'b'},
84-
{DOM_VK_C, 'c'},
85-
{DOM_VK_D, 'd'},
86-
{DOM_VK_E, 'e'},
87-
{DOM_VK_F, 'f'},
88-
{DOM_VK_G, 'g'},
89-
{DOM_VK_H, 'h'},
90-
{DOM_VK_I, 'i'},
91-
{DOM_VK_J, 'j'},
92-
{DOM_VK_K, 'k'},
93-
{DOM_VK_L, 'l'},
94-
{DOM_VK_M, 'm'},
95-
{DOM_VK_N, 'n'},
96-
{DOM_VK_O, 'o'},
97-
{DOM_VK_P, 'p'},
98-
{DOM_VK_Q, 'q'},
99-
{DOM_VK_R, 'r'},
100-
{DOM_VK_S, 's'},
101-
{DOM_VK_T, 't'},
102-
{DOM_VK_U, 'u'},
103-
{DOM_VK_V, 'v'},
104-
{DOM_VK_W, 'w'},
105-
{DOM_VK_X, 'x'},
106-
{DOM_VK_Y, 'y'},
107-
{DOM_VK_Z, 'z'},
10882
{'`', '~'},
10983
{'-', '_'},
11084
{'=', '+'},

src/platform/emcc/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void init() {
5353
os_graf_my = 768;
5454
os_graphics = 1;
5555
os_color_depth = 16;
56+
opt_mute_audio = 0;
5657
}
5758

5859
int main(int argc, char* argv[]) {

src/platform/emcc/runtime.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
#include <emscripten.h>
1212
#include <emscripten/key_codes.h>
1313
#include "include/osd.h"
14+
#include "common/inet.h"
1415
#include "common/smbas.h"
1516
#include "lib/maapi.h"
16-
#include "ui/utils.h"
17+
#include "ui/audio.h"
1718
#include "ui/theme.h"
19+
#include "ui/utils.h"
1820
#include "platform/emcc/runtime.h"
1921
#include "platform/emcc/main_bas.h"
2022
#include "platform/emcc/keymap.h"
@@ -135,11 +137,11 @@ char *Runtime::loadResource(const char *fileName) {
135137
bool Runtime::handleKeyboard(int eventType, const EmscriptenKeyboardEvent *e) {
136138
int keyCode = e->keyCode;
137139
bool result = true;
140+
static bool capsLock = false;
138141
switch (e->keyCode) {
139142
case DOM_VK_SHIFT:
140143
case DOM_VK_CONTROL:
141144
case DOM_VK_ALT:
142-
case DOM_VK_CAPS_LOCK:
143145
// ignore press without modifier key
144146
result = false;
145147
break;
@@ -151,24 +153,25 @@ bool Runtime::handleKeyboard(int eventType, const EmscriptenKeyboardEvent *e) {
151153
result = false;
152154
break;
153155

156+
case DOM_VK_CAPS_LOCK:
157+
capsLock = !capsLock;
158+
break;
159+
154160
default:
155161
for (int i = 0; i < KEYMAP_LEN; i++) {
156162
if (keyCode == KEYMAP[i][0]) {
157163
keyCode = KEYMAP[i][1];
158164
break;
159165
}
160166
}
161-
162167
if (e->ctrlKey && e->altKey) {
163168
pushEvent(getKeyPressedEvent(SB_KEY_CTRL_ALT(keyCode)));
164169
} else if (e->ctrlKey && e->shiftKey) {
165170
pushEvent(getKeyPressedEvent(SB_KEY_SHIFT_CTRL(keyCode)));
166171
} else if (e->altKey && e->shiftKey) {
167172
pushEvent(getKeyPressedEvent(SB_KEY_ALT_SHIFT(keyCode)));
168173
} else if (e->ctrlKey) {
169-
if (keyCode >= 'A' && keyCode <= 'Z') {
170-
keyCode += ('a' - 'A');
171-
}
174+
keyCode = to_lower(keyCode);
172175
switch (keyCode) {
173176
case 'b':
174177
pushEvent(getMotionEvent(EVENT_TYPE_BACK, nullptr));
@@ -216,7 +219,7 @@ bool Runtime::handleKeyboard(int eventType, const EmscriptenKeyboardEvent *e) {
216219
pushEvent(getKeyPressedEvent(SB_KEY_SHIFT(keyCode)));
217220
}
218221
} else {
219-
pushEvent(getKeyPressedEvent(keyCode));
222+
pushEvent(getKeyPressedEvent(capsLock ? keyCode : to_lower(keyCode)));
220223
}
221224
break;
222225
}
@@ -337,6 +340,8 @@ void Runtime::processEvent(MAEvent &event) {
337340

338341
void Runtime::runShell() {
339342
logEntered();
343+
audio_open();
344+
net_init();
340345
while (1) {
341346
runMain(MAIN_BAS);
342347
}
@@ -605,10 +610,6 @@ bool System::getPen3() {
605610
return result;
606611
}
607612

608-
void System::completeKeyword(int index) {
609-
// empty
610-
}
611-
612613
//
613614
// sbasic implementation
614615
//
@@ -622,16 +623,10 @@ int osd_devrestore(void) {
622623
return 0;
623624
}
624625

625-
626-
void osd_audio(const char *path) {
627-
}
628-
629-
void osd_beep() {
630-
}
631-
632-
void osd_clear_sound_queue() {
633-
}
634-
635-
void osd_sound(int frequency, int millis, int volume, int background) {
636-
}
637-
626+
//
627+
// not implemented
628+
//
629+
void System::completeKeyword(int index) {}
630+
void maHideVirtualKeyboard(void) {}
631+
void maShowVirtualKeyboard(void) {}
632+
void maUpdateScreen(void) {}

src/ui/audio.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,15 @@ static void device_start() {
143143
bool audio_open() {
144144
bool result;
145145
ma_backend backends[] = {
146+
#if defined(_EMCC)
147+
ma_backend_webaudio
148+
#else
146149
ma_backend_alsa,
147150
ma_backend_jack,
148151
ma_backend_pulseaudio,
149152
ma_backend_wasapi,
150-
ma_backend_dsound
153+
ma_backend_dsound,
154+
#endif
151155
};
152156
if (ma_context_init(backends, sizeof(backends)/sizeof(backends[0]), NULL, &context) != MA_SUCCESS) {
153157
result = false;

src/ui/system.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,11 +1127,9 @@ void System::showMenu() {
11271127
items->add(new String(buffer));
11281128
_systemMenu[index++] = MENU_THEME;
11291129
}
1130-
#if !defined(_EMCC)
11311130
sprintf(buffer, MENU_STR_AUDIO, (opt_mute_audio ? MENU_STR_OFF : MENU_STR_ON));
11321131
items->add(new String(buffer));
11331132
_systemMenu[index++] = MENU_AUDIO;
1134-
#endif
11351133
#if !defined(_SDL) && !defined(_FLTK) && !defined(_EMCC)
11361134
if (!_mainBas && !_activeFile.empty()) {
11371135
items->add(new String(MENU_STR_SHORT));

0 commit comments

Comments
 (0)