Skip to content

Commit

Permalink
Merge pull request #11 from matthewbloch/feature/mouse-integration
Browse files Browse the repository at this point in the history
OpenGL video back-end + updated mouse-integration branch
  • Loading branch information
pdjstone authored Dec 17, 2023
2 parents cd31ec5 + a750669 commit 579ac43
Show file tree
Hide file tree
Showing 25 changed files with 1,301 additions and 243 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build
run: docker run -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk make -j8 DEBUG=1 wasm
run: docker run -v $(pwd):/src emscripten/emsdk sh -c "apt update && apt -yy install xxd && make -j8 DEBUG=1 wasm"
native:
name: "Build native"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build
run: docker run -v $(pwd):/src debian sh -c "apt update && apt -yy install gcc make libsdl2-dev libz-dev && make -C /src -j8 DEBUG=1 native"
run: docker run -v $(pwd):/src debian sh -c "apt update && apt -yy install gcc xxd make libsdl2-dev libz-dev libglu1-mesa-dev && make -C /src -j8 DEBUG=1 native"
44 changes: 29 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
######################################################################

SERVE_IP ?= localhost
SERVE_PORT ?= 3010
SERVE_PORT ?= 3020

# Only "LINUX" tested for now
INCLUDE_LINUX := 1
Expand All @@ -11,30 +11,37 @@ INCLUDE_LINUX := 1
# Enable if you like, will fix this so dependencies are more automatic
#BUILD_PODULES := ultimatecdrom common_sound common_cdrom common_eeprom common_scsi

# Enable if you want to build a "full fat" version that includes ROMs, config and CMOS
# FULL_FAT := 1

######################################################################

SHELL := bash
BUILD_TAG := $(shell echo `git rev-parse --short HEAD`-`[[ -n $$(git status -s) ]] && echo 'dirty' || echo 'clean'` on `date --rfc-3339=seconds`)

CC ?= gcc
CFLAGS := -D_REENTRANT -DARCWEB -Wall -Werror -DBUILD_TAG="${BUILD_TAG}" -Isrc
CFLAGS_WASM := -sUSE_ZLIB=1 -sUSE_SDL=2
LINKFLAGS := -lz -lSDL2 -lm
LINKFLAGS_WASM := -sUSE_SDL=2 -sALLOW_MEMORY_GROWTH=1 -sFORCE_FILESYSTEM -sEXPORTED_RUNTIME_METHODS=[\"ccall\"] -lidbfs.js
DATA := ddnoise
CFLAGS := -D_REENTRANT -DARCWEB -Wall -Werror -DBUILD_TAG="${BUILD_TAG}" -Isrc -Ibuild/generated-src
CFLAGS_WASM := -sUSE_ZLIB=1 -sUSE_SDL=2 -Ibuild/generated-src
LINKFLAGS := -lz -lSDL2 -lm -lGL -lGLU
LINKFLAGS_WASM := -sUSE_SDL=2 -sALLOW_MEMORY_GROWTH=1 -sTOTAL_MEMORY=32768000 -sFORCE_FILESYSTEM -sUSE_WEBGL2=1 -sEXPORTED_RUNTIME_METHODS=[\"ccall\"] -lidbfs.js -lz
DATA := ddnoise
ifdef DEBUG
CFLAGS += -D_DEBUG -DDEBUG_LOG -O0 -g3
LINKFLAGS_WASM += -gsource-map
BUILD_TAG += (DEBUG)
$(info ❗BUILD_TAG="${BUILD_TAG}")
DATA += roms/riscos311/ros311 roms/arcrom_ext cmos arc.cfg
FULL_FAT = 1
else
CFLAGS += -O3 -flto
LINKFLAGS += -flto
$(info ❗BUILD_TAG="${BUILD_TAG}")
$(info ❗Re-run make with DEBUG=1 if you want a debug build)
endif

ifdef FULL_FAT
DATA += roms/riscos311/ros311 roms/arcrom_ext cmos arc.cfg
endif

######################################################################

OBJS := 82c711 82c711_fdc \
Expand All @@ -48,7 +55,7 @@ OBJS := 82c711 82c711_fdc \
input_sdl2 ioc ioeb joystick keyboard \
lc main mem memc podules printer \
riscdev_hdfc romload sound sound_sdl2 \
st506 st506_akd52 timer vidc video_sdl2 wd1770 \
st506 st506_akd52 timer vidc video_sdl2gl wd1770 \
wx-sdl2-joystick \
emscripten_main emscripten-console emscripten_podule_config podules-static

Expand Down Expand Up @@ -79,9 +86,17 @@ all: native wasm
clean:
rm -rf build

serve: build/wasm/arculator.html
@echo "Now open >> http://${SERVE_IP}:${SERVE_PORT}/build/wasm/arculator.html << in your browser"
@python3 -mhttp.server -b ${SERVE_IP} ${SERVE_PORT}
serve: wasm web/serve.js
node web/serve.js ${SERVE_IP} ${SERVE_PORT}

######################################################################

build/native/video_sdl2gl.o: build/generated-src/video.vert.c build/generated-src/video.frag.c
build/wasm/video_sdl2gl.o: build/generated-src/video.vert.c build/generated-src/video.frag.c

build/generated-src/%.c: src/%.glsl
@mkdir -p $(@D)
xxd -i $< $@

######################################################################

Expand Down Expand Up @@ -136,9 +151,8 @@ build/native/podules/ultimatecdrom/%.o: podules/ultimatecdrom/src/%.c
wasm: $(addprefix build/wasm/arculator.,html js wasm data data.js)

build/wasm/arculator.wasm build/wasm/arculator.js: build/wasm/arculator.html
build/wasm/arculator.html: ${OBJS_WASM}
emcc ${LINKFLAGS_WASM} ${OBJS_WASM} -o $@
sed -e "s/<script async/<script async type=\"text\/javascript\" src=\"arculator.data.js\"><\/script>&/" build/wasm/arculator.html >build/wasm/arculator_fix.html && mv build/wasm/arculator_fix.html build/wasm/arculator.html
build/wasm/arculator.html: ${OBJS_WASM} web/shell.html
emcc ${LINKFLAGS_WASM} ${OBJS_WASM} --shell-file web/shell.html -o $@

build/wasm/arculator.data.js: build/wasm/arculator.data
build/wasm/arculator.data: ${DATA}
Expand Down Expand Up @@ -178,5 +192,5 @@ arc.cfg:
######################################################################
roms/arcrom_ext: roms/riscos311/ros311
roms/riscos311/ros311:
curl -s http://b-em.bbcmicro.com/arculator/Arculator_V2.1_Linux.tar.gz | tar xz roms
curl -Ls https://b-em.bbcmicro.com/arculator/Arculator_V2.2_Linux.tar.gz | tar xz roms

9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ What works:

Not working or tested:

* Podules
* Podules (WIP, can be compiled statically)
* Hard drives

To build and test the Emscripten version:

* Install [Emscripten](https://emscripten.org/docs/getting_started/downloads.html) which contains all the tools to build the WebAssembly version.
* Activate Emscripten with e.g. `EMSDK_QUIET=1 source ~/emsdk/emsdk_env.sh`
* Run `make -j8 serve`
* (or `make -j8 serve DEBUG=1` if you want a slower debug build)
* Open [http://localhost:8000/build/wasm/arculator.html](http://localhost:8000/build/arculator.html) to see the default Emscripten front-end which should boot RISC OS 3.
* Run `make -j8 FULL_FAT=1 serve` (or `make -j8 DEBUG=1 serve` for a slower debug build)
* Open [http://localhost:3020/](http://localhost:3020/) to see the default Emscripten front-end which should boot RISC OS 3.

You can also build a native equivalent by running `make -j8 native DEBUG=1`.
You can also build a native equivalent by running `make -j8 DEBUG=1 native`.

We're working on a better front-end at the [Archimedes Live](https://github.com/pdjstone/archimedes-live) project. Join us!
6 changes: 3 additions & 3 deletions src/Makefile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ CC = gcc.exe
WINDRES = windres.exe
WXVERSION = 31
WXINCLUDE = E:/mingwget/include/wx-3.0
CFLAGS = -O3 -fomit-frame-pointer -Wall -Werror -fno-strict-aliasing
CFLAGS = -O3 -fomit-frame-pointer -Wall -Werror -fno-strict-aliasing $(shell wx-config --cppflags)
OBJ = 82c711.o 82c711_fdc.o arm.o bmu.o cmos.o colourcard.o config.o cp15.o ddnoise.o debugger.o debugger_swis.o disc.o disc_adf.o disc_apd.o disc_fdi.o disc_hfe.o disc_jfd.o disc_mfm_common.o disc_scp.o ds2401.o eterna.o fdi2raw.o fpa.o g16.o g332.o hostfs.o hostfs-win.o ide.o ide_a3in.o ide_config.o ide_idea.o ide_riscdev.o ide_zidefs.o ide_zidefs_a3k.o input_sdl2.o ioc.o ioeb.o joystick.o keyboard.o lc.o main.o mem.o memc.o podules.o podules-win.o printer.o riscdev_hdfc.o romload.o sound.o sound_sdl2.o st506.o st506_akd52.o timer.o vidc.o video_sdl2.o wd1770.o wx-app.o wx-config.o wx-config_sel.o wx-hd_conf.o wx-console.o wx-hd_new.o wx-joystick-config.o wx-main.o wx-podule-config.o wx-resources.o wx-sdl2-joystick.o wx-win32.o arculator.res

LIBS = -Wl,--subsystem,windows -mthreads -mwindows -lwxmsw31u_xrc -lwxmsw31u_html -lwxmsw31u_adv -lwxbase31u_xml -lwxmsw31u_core -lwxbase31u -lwxtiff -lwxjpeg -lwxpng -lwxzlib -lwxregexu -lwxexpat -lkernel32 -lcomdlg32 -lwinspool -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lmingw32 -lopengl32 -lstdc++ -lSDL2main -lSDL2 -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc -luxtheme -loleacc -lshlwapi -lz
LIBS = -Wl,--subsystem,windows -mthreads -mwindows -lkernel32 -lcomdlg32 -lwinspool -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lmingw32 -lopengl32 -lstdc++ -lSDL2main -lSDL2 -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc -luxtheme -loleacc -lshlwapi -lz $(shell wx-config --libs)

Arculator.exe: $(OBJ)
$(CPP) $(OBJ) -o "Arculator.exe" $(LIBS)
Expand All @@ -27,7 +27,7 @@ clean :

wx-resources.o : arculator.xrc
-wxrc -c arculator.xrc -o wx-resources.cc
$(CPP) $(CXXFLAGS) -c wx-resources.cc
$(CPP) $(CFLAGS) -c wx-resources.cc

arculator.res: arculator.rc
$(WINDRES) -i arculator.rc --input-format=rc -o arculator.res -O coff
15 changes: 10 additions & 5 deletions src/arc.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include "debugger.h"

/*Misc*/
extern void rpclog(const char *format, ...);
#define rpclog(...) rpclog_impl(__FILE__, __LINE__, __VA_ARGS__)
extern void rpclog_impl(char *file, int line, const char *format, ...);
extern void error(const char *format, ...);
extern void fatal(const char *format, ...);
void arc_print_error(const char *format, ...);
Expand Down Expand Up @@ -80,8 +81,7 @@ void arc_print_error(const char *format, ...);
extern void arc_set_cpu(int cpu, int memc);
extern void updatewindowsize(int x, int y);

extern int updatemips,inssec;
extern float inssecf;
extern int update_status_text,inssec;

/*ARM*/
extern uint32_t armregs[16];
Expand Down Expand Up @@ -192,8 +192,13 @@ extern int fdctype;
extern int readflash[4];


/*Causes a databort during RISC OS 3.11 startup*/
#define mousehack 0
/* normal mouse input using relative movements send via keyboard controller */
#define MOUSE_MODE_RELATIVE 1

/* absolute mouse coordinates poked directly into OS memory, and mouse SWIs intercepted */
#define MOUSE_MODE_ABSOLUTE 2

extern int mouse_mode;

extern char exname[512];

Expand Down
25 changes: 14 additions & 11 deletions src/arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2536,18 +2536,18 @@ static void opSWI(uint32_t opcode)
if (debugon)
debug_trap(DEBUG_TRAP_SWI, opcode);

if (mousehack)
if ((opcode&0x1FFFF)==7 && armregs[0]==0x15 && (readmemb(armregs[1])==1))
{
// SWI 7 == OS_Word
if ((opcode&0x1FFFF)==7 && armregs[0]==0x15 && (readmemb(armregs[1])==1))
{
// OS_Word 21,1 - Define mouse coordinate bounding box
setmouseparams(armregs[1]);
}
else if ((opcode&0x1FFFF)==7 && armregs[0]==0x15 && (readmemb(armregs[1])==4))
setmousebounds(armregs[1]);
}

if (mouse_mode == MOUSE_MODE_ABSOLUTE)
{

if ((opcode&0x1FFFF)==7 && armregs[0]==0x15 && (readmemb(armregs[1])==4))
{
// OS_Word 21,4 - Read unbuffered mouse position
getunbufmouse(armregs[1]);
//getunbufmouse(armregs[1]);
}
else if ((opcode&0x1FFFF)==7 && armregs[0]==0x15 && (readmemb(armregs[1])==3))
{
Expand All @@ -2558,6 +2558,9 @@ static void opSWI(uint32_t opcode)
{
// OS_Word 21,5 - Set pointer position
setmousepos(armregs[1]);
} else if ((opcode&0x1FFFF)==6 && armregs[0]==106) {
// OS_Byte 106 - Select pointer/activate mouse
setmousecursor(armregs[1]);
}
}

Expand All @@ -2571,11 +2574,11 @@ static void opSWI(uint32_t opcode)
hostfs(&state);
memmode = templ;
}
else if ((opcode&0xFFFF)==0x1C && mousehack)
/*else if ((opcode&0xFFFF)==0x1C && mouse_mode == MOUSE_MODE_ABSOLUTE)
{
getosmouse();
armregs[15]&=~VFLAG;
}
}*/
else
EXCEPTION_SWI();
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ void loadconfig()
machine[0] = 0;
machine_type = get_machine_type(machine);
soundena = config_get_int(CFG_GLOBAL, NULL, "sound_enable", 1);
display_mode = config_get_int(CFG_MACHINE, NULL, "display_mode", DISPLAY_MODE_NO_BORDERS);
display_mode = config_get_int(CFG_MACHINE, NULL, "display_mode", DISPLAY_MODE_NATIVE_BORDERS);
arm_cpu_type = config_get_int(CFG_MACHINE, NULL, "cpu_type", 0);
memc_type = config_get_int(CFG_MACHINE, NULL, "memc_type", 0);
fpaena = config_get_int(CFG_MACHINE, NULL, "fpa", 0);
Expand Down
Loading

0 comments on commit 579ac43

Please sign in to comment.