Merge pull request #15 from theverygaming/main

Allow build with emscripten
This commit is contained in:
Ry 2023-02-13 17:47:49 -08:00 committed by GitHub
commit 2235d2f5b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

5
.gitignore vendored
View File

@ -7,3 +7,8 @@ fox32
fox32.exe fox32.exe
SDL2.dll SDL2.dll
fox32.html
fox32.wasm
fox32.js
fox32.data

View File

@ -2,8 +2,11 @@ SDL2_CONFIG = sdl2-config
CFLAGS = -g -Ofast -std=c99 -Wall -Wextra `$(SDL2_CONFIG) --cflags --libs` CFLAGS = -g -Ofast -std=c99 -Wall -Wextra `$(SDL2_CONFIG) --cflags --libs`
CC_WIN = x86_64-w64-mingw32-gcc CC_WIN = x86_64-w64-mingw32-gcc
CFLAGS_WIN = -g -Ofast -std=c99 -Wall -Wextra -lmingw32 -lSDL2main -lSDL2 CFLAGS_WIN = -g -Ofast -std=c99 -Wall -Wextra -lmingw32 -lSDL2main -lSDL2
CC_WASM = emcc
CFLAGS_WASM = -O3 -std=c99 -Wall -Wextra -s TOTAL_MEMORY=70057984 -sALLOW_MEMORY_GROWTH=1 -sUSE_SDL=2 --preload-file fox32os.img
TARGET=fox32 TARGET=fox32
TARGET_WIN=fox32.exe TARGET_WIN=fox32.exe
TARGET_WASM=fox32.html
CFILES = src/main.c \ CFILES = src/main.c \
src/bus.c \ src/bus.c \
@ -29,5 +32,10 @@ $(TARGET_WIN): $(CFILES)
sed -i -e 's/fox32_rom/fox32rom/' fox32rom.h sed -i -e 's/fox32_rom/fox32rom/' fox32rom.h
$(CC_WIN) -o $@ $(filter %.c, $^) $(CFLAGS_WIN) $(CC_WIN) -o $@ $(filter %.c, $^) $(CFLAGS_WIN)
$(TARGET_WASM): $(CFILES) $(FOX32ROM_IN)
xxd -i $(FOX32ROM_IN) $(FOX32ROM_OUT)
sed -i -e 's/fox32_rom/fox32rom/' fox32rom.h
$(CC_WASM) -o $@ $(filter %.c, $^) $(CFLAGS_WASM)
clean: clean:
rm -rf fox32 fox32.exe rm -rf $(TARGET) $(TARGET_WIN) $(TARGET_WASM)

View File

@ -8,6 +8,10 @@
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/html5.h>
#endif
#include "bus.h" #include "bus.h"
#include "cpu.h" #include "cpu.h"
@ -50,6 +54,7 @@ int main(int argc, char *argv[]) {
memcpy(vm.memory_rom, fox32rom, sizeof(fox32rom)); memcpy(vm.memory_rom, fox32rom, sizeof(fox32rom));
size_t disk_id = 0; size_t disk_id = 0;
#ifndef __EMSCRIPTEN__
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--help") == 0) { if (strcmp(argv[i], "--help") == 0) {
fprintf(stderr, fprintf(stderr,
@ -87,6 +92,9 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
} }
#else
new_disk("fox32os.img", disk_id++);
#endif
if (!vm.headless) { if (!vm.headless) {
if (SDL_Init(SDL_INIT_VIDEO) != 0) { if (SDL_Init(SDL_INIT_VIDEO) != 0) {
@ -116,6 +124,10 @@ int main(int argc, char *argv[]) {
tick_start = SDL_GetTicks(); tick_start = SDL_GetTicks();
tick_end = SDL_GetTicks(); tick_end = SDL_GetTicks();
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(main_loop, FPS, 1);
#endif
while (!done && !bus_requests_exit) { while (!done && !bus_requests_exit) {
main_loop(); main_loop();
@ -132,6 +144,11 @@ int main(int argc, char *argv[]) {
} }
void main_loop(void) { void main_loop(void) {
#ifdef __EMSCRIPTEN__
if (done || bus_requests_exit) {
emscripten_cancel_main_loop();
}
#endif
int dt = SDL_GetTicks() - tick_start; int dt = SDL_GetTicks() - tick_start;
tick_start = SDL_GetTicks(); tick_start = SDL_GetTicks();
if (!dt) if (!dt)