aboutsummaryrefslogtreecommitdiff
path: root/src/game.c
AgeCommit message (Collapse)Author
2026-10-29Implement Cart ShutdownNicholas Rodrigues Lordello
2026-10-29Support the Shutdown OptionNicholas Rodrigues Lordello
It looks like the `SHUTDOWN` menu option shows up when the `-run` CLI argument is passed, so pass it. There is a catch though, in that PICO-8 does not properly report shutdown requests in those cases, so read Wasm memory directly to detect the shutdown request.
2026-10-28Implement Remaining SyscallsNicholas Rodrigues Lordello
2026-10-27Refactor Embedded Cart LoadingNicholas Rodrigues Lordello
2026-10-27Multicart Loading with BBSNicholas Rodrigues Lordello
2026-10-26Implement Audio Device and Remaining ASM ConstsNicholas Rodrigues Lordello
We abstract over SDL's audio subsystem and implement an audio device that fits into PICO-8's model. We fixed the implementation for the PICO-8 window focus and key buffer and can now actually boot into PICO-8 games with working sounds and controls! There are a few issues that remain: 1. There is no "exit" option in the pause menu, I think it thinks that we are on the BBS, and maybe there is someway to fix this? 2. The clipboard textarea is not implemented at all; we should keep a text buffer in `pw_input` and interact with SDL's clipboard system 3. Multicart's don't always work; in particular Undune II tries to download from the BBS, I would like to shim this somehow to support both `LOAD("FOO.P8")` and `LOAD("#FOO")` forms transparently.
2026-10-24Improve Gamepad HandlingNicholas Rodrigues Lordello
There were a few cases where we would have stale input information becaues the `pw_input` only receives events while the game is running. This fixes that by: - Reseting the player count on game start - Clearing button states for disconnected players - Improve handling of the POOM player 2 support in case a second player connects
2026-10-23Various Small Bug FixesNicholas Rodrigues Lordello
2026-10-23Implement IO SyscallsNicholas Rodrigues Lordello
Now that we implemented our file-system, we can implement IO-related syscalls and ASM constants and get further into the boot. For now, we just use an in-memory userdat storage, but eventually, I want to persist this to disk. We can now boot to the point where we try to `invoke_vii`, which, AFAIU, is the whole setjmp/longjmp machinery that I have to figure out.
2026-10-21More ASM ConstantsNicholas Rodrigues Lordello
We also implement some additional mouse functionality for pointer locking and for reading the mouse wheel (although, that is currently not hooked up over the ASM constants quite yet).
2026-10-19Started Implementing ASM ConstantsNicholas Rodrigues Lordello
2026-10-19Refactor Multicart LoadingNicholas Rodrigues Lordello
When starting to implement the ASM constants, I noticed that the multicart support would be _WAYYYYY_ easier if all the multicarts are just passed in as embedded cart data. Here, we modify the cart module to introduce a new "cartdat" type that represents a cart export (either a single cart, for the regular case, or multiple carts for the multicart case). This simplifies lots of code, and allows us to use the ASM constants for passing in cart data without additional glue logic. It mimics how the PICO-8 export works for multi-cart code as well. Lastly, cart names now include the `.p8` extension in the name, to match how they work with the multicart export. I'm not sure how this will interact with splore multi-cart loading (i.e. `LOAD("#SOMECART")`).
2026-10-19Implement Many Host FunctionsNicholas Rodrigues Lordello
Implemented many of the missing host functions, but some things are still unimplemented: 1. Audio, because I have _no_ idea how that works. 2. Syscalls, they look hairy and will look into them separately. 3. ASM constants, we need to go over the array in the the exported JS module and understand how each one maps to our host. The other functions are _mostly_ straightforward to implement, and I did so with some caveats (for example, only supporting the single format the PICO-8 uses for `strftime`) which is good enough for us. Next, I need to refactor how we load carts: in particular, all carts need to come from the `_cartdat` mechanism, so the "embedded" carts instead of loading them ad-hoc. This requires us to refactor how we do the multicart loading to pre-load the entire `.p8.dir` when a cart is selected (instead of just keeping their names and lazy-loading them in).
2026-10-18Minor Bug FixesNicholas Rodrigues Lordello
2026-10-18Stubbed ALL ImportsNicholas Rodrigues Lordello
Now the cart fails to boot (we trap on unimplemented stubs), but a lot of small functionv have been setup. Now the marathon begins for trying to understand what each of the stubs do...
2026-10-17Add GlobalsNicholas Rodrigues Lordello
Note that we fail to build on linking errors - we have a lot of missing `env` functions to implement since moving away from the stub. Now the real fun begins...
2026-10-17Add Trap HandlingNicholas Rodrigues Lordello
We implemented trap handing with setjmp/longjmp. This _should_ be very widely supported, but it was _one_ nicety of WAMR: it did not rely on this mechanism and would instead return errors on runtime calls in case of a trap. The implementation is fairly straightforward: we set a global `jmp_buf` when installing a handler and longjmp in case of a trap. Note that the handler also keeps the trap code, because the C standard only requires `if (setjmp(buf))` to be supported, i.e. "the entire controlling expression of `if`", meaning even if it does return the code passed to `longjmp`, we can't really do anything with it. Added a `Esc` key handler in the PICO-8 stub to check traps work, and they do :).
2026-10-17Use `wasm2c` instead of WAMRNicholas Rodrigues Lordello
Instead of interpreting Wasm, compile it ahead of time to C and run that instead: - it is much faster (no interpreter overhead) - it is easier to implement host functions, they are just C calls This works well for us since we only ever load a single Wasm blob (the PICO-8 runtime that `picow` is built with). There was some fun figuring out how big-endian stuff works (WRT memory layout), but otherwise it was pretty straight forward. Note that traps are still not working, I need to figure that out still...
2026-10-15wire up SDL eventsNicholas Rodrigues Lordello
2026-10-13Added Debug StatsNicholas Rodrigues Lordello
We now print debug stats (ATM, just FPS) overlaying the actual game. We use the PICO-8 font to keep things consistent; I probable should choose a better color though...
2026-10-12Fix Byte Order for Surface PixelsNicholas Rodrigues Lordello
I went down a deep rabbithole to understand the pixel order, and it turns out that the Emscripten library code is setting the wrong `format` value for what it actually uses, which threw me off. We now set the correct pixel format tag, and handle pixel byte ordering correctly on the host. Some other minor fixes.
2026-10-12Implement Partial Emscripten SDL APINicholas Rodrigues Lordello
Start implementing the surface-specific SDL API so that we can get our stub PICO-8 engine to draw a mouse crosshairs to screen. The Emscripten runtime still needs its own file, and we need to convert everything over to `wasm2c`.
2026-10-10Support Different Scaling ModesNicholas Rodrigues Lordello
We now support pixel perfect scaling (what existed before) as well as new scaling modes: - `fill`: Fill fit to output, but keep aspect ratio - `stretch`: Fill every pixel in the output, may look OK on certain displays that are close to 1:1 aspect ratio We also fixed a small mouse position computation bug (we would jump to the next pixel too early).
2026-10-10Fix Some BugsNicholas Rodrigues Lordello
2026-10-10Separate Scene LogicNicholas Rodrigues Lordello
We now have two separate "scenes": - cart selection - game In their own modules. Instead of implementing some scene management logic, we just hardcode the scene logic directly in the `picow` main module - I don't forsee more scenes and there is no need to over-engineer at this point.