From 41affce8a9a4e21af13ec89eeae6ba961b59864e Mon Sep 17 00:00:00 2001 From: Gota7 Date: Tue, 12 Jul 2022 13:14:14 -0400 Subject: [PATCH 1/7] Add C template Implements a C WASM template and build system. --- templates/c/README.md | 49 +++++++++ templates/c/buildcart.sh | 6 ++ templates/c/buildwasm.sh | 4 + templates/c/src/main.c | 50 +++++++++ templates/c/src/tic80.h | 208 +++++++++++++++++++++++++++++++++++++ templates/c/wasmdemo.wasmp | 57 ++++++++++ 6 files changed, 374 insertions(+) create mode 100644 templates/c/README.md create mode 100755 templates/c/buildcart.sh create mode 100755 templates/c/buildwasm.sh create mode 100644 templates/c/src/main.c create mode 100644 templates/c/src/tic80.h create mode 100644 templates/c/wasmdemo.wasmp diff --git a/templates/c/README.md b/templates/c/README.md new file mode 100644 index 000000000..ac4bcb00c --- /dev/null +++ b/templates/c/README.md @@ -0,0 +1,49 @@ +# C Starter Project Template + +## Pre-requisites + +- [WASI SDK](https://github.com/WebAssembly/wasi-sdk) + +## Files in this template + +- ```buildcart.sh``` - convenience script to build and run the game cartridge +- ```buildwasm.sh``` - convenience script to build and run the Wasm program +- ```Makefile``` - convenience Makefile that builds the project +- ```wasmdemo.wasmp``` - TIC-80 Wasm 'script' file. Note the embedded game assets data at the end of the file. + +## Building your game + +Define the environment variable WASI_SDK_PATH; e.g., if you installed WASI +into ```$HOME/wasi-sdk```, then ```export WASI_SDK_PATH=$HOME/wasi-sdk```. + +Edit ```src/main.c``` to implement your game. You are of course free to +organize your code in more than one C source file. + +If you create sprites, map, music, etc., for your game, remember to +replace the game asset data at the end of ```wasmdemo.wasmp``` with +your creations. + +To build the Wasm file, execute ```make```. This generates ```cart.wasm``` +in the build directory. To run: + +``` +% tic80 --fs . --cmd 'load wasmdemo.wasmp & import binary cart.wasm & run & exit' +``` + +The script ```buildwasm.sh``` contains above steps as a convenience. + +To build a TIC-80 cartridge, first build the Wasm file, then build the +cartridge file: + +``` +% tic80 --fs . --cmd 'load wasmdemo.wasmp & import binary cart.wasm & save game.tic & exit' +``` + +You can then run your cartridge as follows: + +``` +% tic80 --fs . --cmd 'load game.tic & run & exit' +``` + +The script ```buildcart.sh``` does the above steps as a convenience. + diff --git a/templates/c/buildcart.sh b/templates/c/buildcart.sh new file mode 100755 index 000000000..a58437361 --- /dev/null +++ b/templates/c/buildcart.sh @@ -0,0 +1,6 @@ +#!/bin/sh +rm -f game.tic +make clean +make +tic80 --fs . --cmd 'load wasmdemo.wasmp & import binary build/cart.wasm & save game.tic & exit' +tic80 --fs . --cmd 'load game.tic & run & exit' diff --git a/templates/c/buildwasm.sh b/templates/c/buildwasm.sh new file mode 100755 index 000000000..5f5923d18 --- /dev/null +++ b/templates/c/buildwasm.sh @@ -0,0 +1,4 @@ +#!/bin/sh +make clean +make +tic80 --fs . --cmd 'load wasmdemo.wasmp & import binary build/cart.wasm & run & exit' diff --git a/templates/c/src/main.c b/templates/c/src/main.c new file mode 100644 index 000000000..48c6fc906 --- /dev/null +++ b/templates/c/src/main.c @@ -0,0 +1,50 @@ +#include "tic80.h" + +#define max(a, b) (a > b) ? a : b +#define min(a, b) (a < b) ? a : b + +// From WASI libc: +WASM_IMPORT("snprintf") +int snprintf(char* s, size_t n, const char* format, ...); + +int t, x, y; +const char* m = "HELLO WORLD FROM C!"; +int r = 0; +MouseData md; +uint8_t transcolors = { 14 }; + +WASM_EXPORT("BOOT") +void BOOT() { + t = 1; + x = 96; + y = 24; +} + +WASM_EXPORT("TIC") +void TIC() { + cls(13); + + // The standard demo. + if (btn(0) > 0) { y--; } + if (btn(1) > 0) { y++; } + if (btn(2) > 0) { x--; } + if (btn(3) > 0) { x++; } + + spr(1+t%60/30*2, x, y, &transcolors, 1, 3, 0, 0, 2, 2); + print(m, 60, 84, 15, 1, 1, 0); + t++; + + // Mouse example demonstrating use of libc function. + mouse(&md); + if (md.left) { r = r + 2; } + r--; + r = max(0, min(32, r)); + line(md.x, 0, md.x, 136, 11); + line(0, md.y, 240, md.y, 11); + circ(md.x, md.y, r, 11); + + const int BUFSIZ = 10; + char buf[BUFSIZ]; + snprintf(buf, BUFSIZ, "(%03d,%03d)", md.x, md.y); + print(buf, 3, 3, 15, 0, 1, 1); +} \ No newline at end of file diff --git a/templates/c/src/tic80.h b/templates/c/src/tic80.h new file mode 100644 index 000000000..dfefff63f --- /dev/null +++ b/templates/c/src/tic80.h @@ -0,0 +1,208 @@ +#pragma once + +#include +#include + +#define WASM_EXPORT(name) __attribute__((export_name(name))) +#define WASM_IMPORT(name) __attribute__((import_name(name))) + +typedef struct { + uint8_t SCREEN[16320]; + uint8_t PALETTE[48]; + uint8_t PALETTE_MAP[8]; + uint8_t BORDER_COLOR; + uint8_t SCREEN_OFFSET_X; + uint8_t SCREEN_OFFSET_Y; + uint8_t MOUSE_CURSOR; + uint8_t BLIT_SEGMENT; + uint8_t RESERVED[3]; +} VRAM; + +typedef struct { + short x; short y; + char scrollx; char scrolly; + bool left; bool middle; bool right; +} MouseData; + +const int32_t WIDTH = 240; +const int32_t HEIGHT = 136; + +// Constants. +const uint32_t TILES_SIZE = 8192; +const uint32_t SPRITES_SIZE = 8192; +const uint32_t MAP_SIZE = 32640; +const uint32_t GAMEPADS_SIZE = 4; +const uint32_t MOUSE_SIZE = 4; +const uint32_t KEYBOARD_SIZE = 4; +const uint32_t SFX_STATE_SIZE = 16; +const uint32_t SOUND_REGISTERS_SIZE = 72; +const uint32_t WAVEFORMS_SIZE = 256; +const uint32_t SFX_SIZE = 4224; +const uint32_t MUSIC_PATTERNS_SIZE = 11520; +const uint32_t MUSIC_TRACKS_SIZE = 408; +const uint32_t SOUND_STATE_SIZE = 4; +const uint32_t STEREO_VOLUME_SIZE = 4; +const uint32_t PERSISTENT_MEMORY_SIZE = 1024; +const uint32_t SPRITE_FLAGS_SIZE = 512; +const uint32_t SYSTEM_FONT_SIZE = 2048; +const uint32_t WASM_FREE_RAM_SIZE = 163840; // 160kb + +// Pointers. +VRAM* FRAMEBUFFER = (VRAM*)0; +uint8_t* TILES = (uint8_t*)0x04000; +uint8_t* SPRITES = (uint8_t*)0x06000; +uint8_t* MAP = (uint8_t*)0x08000; +uint8_t* GAMEPADS = (uint8_t*)0x0FF80; +uint8_t* MOUSE = (uint8_t*)0x0FF84; +uint8_t* KEYBOARD = (uint8_t*)0x0FF88; +uint8_t* SFX_STATE = (uint8_t*)0x0FF8C; +uint8_t* SOUND_REGISTERS = (uint8_t*)0x0FF9C; +uint8_t* WAVEFORMS = (uint8_t*)0x0FFE4; +uint8_t* SFX = (uint8_t*)0x100E4; +uint8_t* MUSIC_PATTERNS = (uint8_t*)0x11164; +uint8_t* MUSIC_TRACKS = (uint8_t*)0x13E64; +uint8_t* SOUND_STATE = (uint8_t*)0x13FFC; +uint8_t* STEREO_VOLUME = (uint8_t*)0x14000; +uint8_t* PERSISTENT_MEMORY = (uint8_t*)0x14004; +uint8_t* SPRITE_FLAGS = (uint8_t*)0x14404; +uint8_t* SYSTEM_FONT = (uint8_t*)0x14604; +uint8_t* WASM_FREE_RAM = (uint8_t*)0x18000; // 160kb + +// Functions. +WASM_IMPORT("btn") +int32_t btn(int32_t id); + +WASM_IMPORT("btnp") +bool btnp(int32_t id, int32_t hold, int32_t period); + +WASM_IMPORT("circ") +void circ(int32_t x, int32_t y, int32_t radius, int32_t color); + +WASM_IMPORT("circb") +void circb(int32_t x, int32_t y, int32_t radius, int32_t color); + +WASM_IMPORT("clip") +void clip(int32_t x, int32_t y, int32_t w, int32_t h); + +WASM_IMPORT("cls") +void cls(int32_t color); + +WASM_IMPORT("exit") +void exit(); + +WASM_IMPORT("elli") +void elli(int32_t x, int32_t y, int32_t a, int32_t b, int32_t color); + +WASM_IMPORT("ellib") +void ellib(int32_t x, int32_t y, int32_t a, int32_t b, int32_t color); + +WASM_IMPORT("fget") +bool fget(int32_t id, uint8_t flag); + +WASM_IMPORT("font") +int32_t font(const char* text, int32_t x, int32_t y, uint32_t* transcolors, int32_t colorcount, int32_t width, int32_t height, bool fixed, int32_t scale, bool alt); + +WASM_IMPORT("fset") +bool fset(int32_t id, uint8_t flag, bool value); + +WASM_IMPORT("key") +bool key(int32_t keycode); + +WASM_IMPORT("keyp") +bool keyp(int32_t keycode, int32_t hold, int32_t period); + +WASM_IMPORT("line") +void line(float x0, float y0, float x1, float y1, int8_t color); + +WASM_IMPORT("map") +void map(int32_t x, int32_t y, int32_t w, int32_t h, int32_t sx, int32_t sy, uint32_t* transcolors, int32_t colorcount, int32_t scale, int32_t remap); + +WASM_IMPORT("memcpy") +void memcpy_tic(uint32_t copyto, uint32_t copyfrom, uint32_t length); + +WASM_IMPORT("memset") +void memset_tic(uint32_t addr, uint8_t value, uint32_t length); + +WASM_IMPORT("mget") +int32_t mget(int32_t x, int32_t y); + +WASM_IMPORT("mouse") +void mouse(MouseData* data); + +WASM_IMPORT("mset") +void mset(int32_t x, int32_t y, bool value); + +WASM_IMPORT("music") +void music(int32_t track, int32_t frame, int32_t row, bool loop, bool sustain, int32_t tempo, int32_t speed); + +WASM_IMPORT("peek") +uint8_t peek(int32_t addr, int32_t bits); + +WASM_IMPORT("peek4") +uint8_t peek4(uint32_t addr4); + +WASM_IMPORT("peek2") +uint8_t peek2(uint32_t addr2); + +WASM_IMPORT("peek1") +uint8_t peek1(uint32_t bitaddr); + +WASM_IMPORT("pix") +void pix(int32_t x, int32_t y, int32_t color); + +WASM_IMPORT("pmem") +uint32_t pmem(uint32_t index, uint32_t value); + +WASM_IMPORT("poke") +void poke(int32_t addr, int8_t value, int8_t bits); + +WASM_IMPORT("poke4") +void poke4(int32_t addr4, int8_t value); + +WASM_IMPORT("poke2") +void poke2(int32_t addr2, int8_t value); + +WASM_IMPORT("poke1") +void poke1(int32_t bitaddr, int8_t value); + +WASM_IMPORT("print") +int32_t print(const char* txt, int32_t x, int32_t y, int32_t color, int32_t fixed, int32_t scale, int32_t alt); + +WASM_IMPORT("rect") +void rect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t color); + +WASM_IMPORT("rectb") +void rectb(int32_t x, int32_t y, int32_t w, int32_t h, int32_t color); + +WASM_IMPORT("reset") +void reset(); + +WASM_IMPORT("sfx") +void sfx(int32_t id, int32_t note, int32_t octave, int32_t duration, int32_t channel, int32_t volumeLeft, int32_t volumeRight, int32_t speed); + +WASM_IMPORT("spr") +void spr(int32_t id, int32_t x, int32_t y, uint8_t* transcolors, uint32_t colorcount, int32_t scale, int32_t flip, int32_t rotate, int32_t w, int32_t h); + +WASM_IMPORT("sync") +void sync(int32_t mask, int32_t bank, bool tocart); + +WASM_IMPORT("trace") +void trace(const char* txt, int32_t color); + +WASM_IMPORT("ttri") +void ttri(float x1, float y1, float x2, float y2, float x3, float y3, float u1, float v1, float u2, float v2, float u3, float v3, int32_t texsrc, uint32_t* transcolors, int32_t colorcount, float z1, float z2, float z3, bool persp); + +WASM_IMPORT("tri") +void tri(float x1, float y1, float x2, float y2, float x3, float y3, int32_t color); + +WASM_IMPORT("trib") +void trib(float x1, float y1, float x2, float y2, float x3, float y3, int32_t color); + +WASM_IMPORT("time") +float time(); + +WASM_IMPORT("tstamp") +int32_t tstamp(); + +WASM_IMPORT("vbank") +int32_t vbank(int32_t bank); \ No newline at end of file diff --git a/templates/c/wasmdemo.wasmp b/templates/c/wasmdemo.wasmp new file mode 100644 index 000000000..46fa1ab95 --- /dev/null +++ b/templates/c/wasmdemo.wasmp @@ -0,0 +1,57 @@ +-- desc: WASM Introduction +-- script: wasm + +""""""""""""""""""""""""""""""""""""""" +WASM is a binary format. The demo +binary code is embedded in this +cartridge, the source code is not. +Run the cart to see the demo. + +This demo exits for completeness, but +you can't (yet) develop WASM projects +using the built-in editor. + +The code used to build this project +can be found in the TIC-80 repo: + +https://github.com/nesbox/TIC-80/templates/c + +This demo was built with C, but many +languages are supported. You simply +build your project with your external +compiler, then import the final WASM +binary into your cartridge: + + import binary out.wasm + +See README.md for details. + +To learn more visit our Wiki and +the 'Getting Started with WASM' page. + +" +-- +-- 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc +-- 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c +-- 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc +-- 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c +-- 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec +-- 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee +-- 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec +-- 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee +-- + +-- +-- 000:00000000ffffffff00000000ffffffff +-- 001:0123456789abcdeffedcba9876543210 +-- 002:0123456789abcdef0123456789abcdef +-- + +-- +-- 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000 +-- + +-- +-- 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57 +-- + From 2d641d03440ed267ebd54d0bcd0f9026b73482db Mon Sep 17 00:00:00 2001 From: Gota7 Date: Wed, 13 Jul 2022 08:54:23 -0400 Subject: [PATCH 2/7] Remove TIC C functions These functions are already part of C. --- templates/c/src/tic80.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/templates/c/src/tic80.h b/templates/c/src/tic80.h index dfefff63f..06014fbda 100644 --- a/templates/c/src/tic80.h +++ b/templates/c/src/tic80.h @@ -117,12 +117,6 @@ void line(float x0, float y0, float x1, float y1, int8_t color); WASM_IMPORT("map") void map(int32_t x, int32_t y, int32_t w, int32_t h, int32_t sx, int32_t sy, uint32_t* transcolors, int32_t colorcount, int32_t scale, int32_t remap); -WASM_IMPORT("memcpy") -void memcpy_tic(uint32_t copyto, uint32_t copyfrom, uint32_t length); - -WASM_IMPORT("memset") -void memset_tic(uint32_t addr, uint8_t value, uint32_t length); - WASM_IMPORT("mget") int32_t mget(int32_t x, int32_t y); From f1338bd6f60899adc9b3f7f5cda14d8953a29b87 Mon Sep 17 00:00:00 2001 From: Gota7 Date: Wed, 13 Jul 2022 12:51:00 -0400 Subject: [PATCH 3/7] Add note about memset & memcpy --- templates/c/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/c/README.md b/templates/c/README.md index ac4bcb00c..973c5cbf5 100644 --- a/templates/c/README.md +++ b/templates/c/README.md @@ -47,3 +47,5 @@ You can then run your cartridge as follows: The script ```buildcart.sh``` does the above steps as a convenience. +## Additional Notes +The TIC functions that provide standard library features are not added here. You should use the `memcpy` and `memset` functions provided by the C standard library instead. \ No newline at end of file From 0b87d62ce6833da5b506b57c40c0939869481b6d Mon Sep 17 00:00:00 2001 From: Gota7 Date: Wed, 13 Jul 2022 23:21:42 -0400 Subject: [PATCH 4/7] Add C template Makefile Gitignore you are killing me. --- .gitignore | 3 +- templates/c/Makefile | 71 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 templates/c/Makefile diff --git a/.gitignore b/.gitignore index 00c31b7e6..306cc7b6e 100644 --- a/.gitignore +++ b/.gitignore @@ -134,6 +134,7 @@ Makefile !build/baremetalpi/Makefile !build/baremetalpi/boot/Makefile !build/baremetalpi/toolchain.cmake +!templates/c/Makefile build/android/.gradle/ build/android/app/.externalNativeBuild/ build/android/app/build/ @@ -176,4 +177,4 @@ tic_mruby_wasm_build_config.rb.lock build/mruby_vendor-prefix/ **/zig-cache **/zig-out -.cache \ No newline at end of file +.cache diff --git a/templates/c/Makefile b/templates/c/Makefile new file mode 100644 index 000000000..94f0a8bff --- /dev/null +++ b/templates/c/Makefile @@ -0,0 +1,71 @@ +ifndef WASI_SDK_PATH +$(error Download the WASI SDK (https://github.com/WebAssembly/wasi-sdk) and set $$WASI_SDK_PATH) +endif + +CC = "$(WASI_SDK_PATH)/bin/clang" --sysroot="$(WASI_SDK_PATH)/share/wasi-sysroot" +CXX = "$(WASI_SDK_PATH)/bin/clang++" --sysroot="$(WASI_SDK_PATH)/share/wasi-sysroot" + +# Optional dependency from binaryen for smaller builds +WASM_OPT = wasm-opt +WASM_OPT_FLAGS = -Oz --zero-filled-memory --strip-producers + +# Whether to build for debugging instead of release +DEBUG = 0 + +# Compilation flags +CFLAGS = -W -Wall -Wextra -Werror -Wno-unused -Wconversion -Wsign-conversion -MMD -MP -fno-exceptions +ifeq ($(DEBUG), 1) + CFLAGS += -DDEBUG -O0 -g +else + CFLAGS += -DNDEBUG -Oz -flto +endif + +# Linker flags +LDFLAGS = -Wl,-zstack-size=8192,--no-entry,--import-memory -mexec-model=reactor \ + -Wl,--initial-memory=262144,--max-memory=262144,--global-base=98304 +ifeq ($(DEBUG), 1) + LDFLAGS += -Wl,--export-all,--no-gc-sections +else + LDFLAGS += -Wl,--strip-all,--gc-sections,--lto-O3 -Oz +endif + +OBJECTS = $(patsubst src/%.c, build/%.o, $(wildcard src/*.c)) +OBJECTS += $(patsubst src/%.cpp, build/%.o, $(wildcard src/*.cpp)) +DEPS = $(OBJECTS:.o=.d) + +ifeq ($(OS), Windows_NT) + MKDIR_BUILD = if not exist build md build + RMDIR = rd /s /q +else + MKDIR_BUILD = mkdir -p build + RMDIR = rm -rf +endif + +all: build/cart.wasm + +# Link cart.wasm from all object files and run wasm-opt +build/cart.wasm: $(OBJECTS) + $(CXX) -o $@ $(OBJECTS) $(LDFLAGS) +ifneq ($(DEBUG), 1) +ifeq (, $(shell command -v $(WASM_OPT))) + @echo Tip: $(WASM_OPT) was not found. Install it from binaryen for smaller builds! +else + $(WASM_OPT) $(WASM_OPT_FLAGS) $@ -o $@ +endif +endif + +# Compile C sources +build/%.o: src/%.c + @$(MKDIR_BUILD) + $(CC) -c $< -o $@ $(CFLAGS) + +# Compile C++ sources +build/%.o: src/%.cpp + @$(MKDIR_BUILD) + $(CXX) -c $< -o $@ $(CFLAGS) + +.PHONY: clean +clean: + $(RMDIR) build + +-include $(DEPS) \ No newline at end of file From 256211f1f47181d2329c3206d61483ff4d6ac172 Mon Sep 17 00:00:00 2001 From: Gota7 Date: Wed, 13 Jul 2022 23:57:41 -0400 Subject: [PATCH 5/7] Update templates/c/README.md Co-authored-by: Josh Goebel --- templates/c/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/c/README.md b/templates/c/README.md index 973c5cbf5..32a00fd85 100644 --- a/templates/c/README.md +++ b/templates/c/README.md @@ -48,4 +48,4 @@ You can then run your cartridge as follows: The script ```buildcart.sh``` does the above steps as a convenience. ## Additional Notes -The TIC functions that provide standard library features are not added here. You should use the `memcpy` and `memset` functions provided by the C standard library instead. \ No newline at end of file +TIC-80 API functions that merely duplicate standard library functionality are not imported. Please use the `memcpy` and `memset` functions provided by the C standard library instead. \ No newline at end of file From e56351dc1cee8a2c1ed227552e164acc014c5665 Mon Sep 17 00:00:00 2001 From: Gota7 Date: Sat, 16 Jul 2022 11:22:50 -0400 Subject: [PATCH 6/7] Header Fixes --- templates/c/src/tic80.h | 112 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 3 deletions(-) diff --git a/templates/c/src/tic80.h b/templates/c/src/tic80.h index 06014fbda..03d46285d 100644 --- a/templates/c/src/tic80.h +++ b/templates/c/src/tic80.h @@ -6,6 +6,111 @@ #define WASM_EXPORT(name) __attribute__((export_name(name))) #define WASM_IMPORT(name) __attribute__((import_name(name))) +enum KEYCODES { + KEY_NULL, + KEY_A, + KEY_B, + KEY_C, + KEY_D, + KEY_E, + KEY_F, + KEY_G, + KEY_H, + KEY_I, + KEY_J, + KEY_K, + KEY_L, + KEY_M, + KEY_N, + KEY_O, + KEY_P, + KEY_Q, + KEY_R, + KEY_S, + KEY_T, + KEY_U, + KEY_V, + KEY_W, + KEY_X, + KEY_Y, + KEY_Z, + KEY_0, + KEY_1, + KEY_2, + KEY_3, + KEY_4, + KEY_5, + KEY_6, + KEY_7, + KEY_8, + KEY_9, + KEY_MINUS, + KEY_EQUALS, + KEY_LEFTBRACKET, + KEY_RIGHTBRACKET, + KEY_BACKSLASH, + KEY_SEMICOLON, + KEY_APOSTROPHE, + KEY_GRAVE, + KEY_COMMA, + KEY_PERIOD, + KEY_SLASH, + KEY_SPACE, + KEY_TAB, + KEY_RETURN, + KEY_BACKSPACE, + KEY_DELETE, + KEY_INSERT, + KEY_PAGEUP, + KEY_PAGEDOWN, + KEY_HOME, + KEY_END, + KEY_UP, + KEY_DOWN, + KEY_LEFT, + KEY_RIGHT, + KEY_CAPSLOCK, + KEY_CTRL, + KEY_SHIFT, + KEY_ALT +}; + +enum BUTTON_CODES +{ + BUTTON_CODE_P1_UP, + BUTTON_CODE_P1_DOWN, + BUTTON_CODE_P1_LEFT, + BUTTON_CODE_P1_RIGHT, + BUTTON_CODE_P1_A, + BUTTON_CODE_P1_B, + BUTTON_CODE_P1_X, + BUTTON_CODE_P1_Y, + BUTTON_CODE_P2_UP, + BUTTON_CODE_P2_DOWN, + BUTTON_CODE_P2_LEFT, + BUTTON_CODE_P2_RIGHT, + BUTTON_CODE_P2_A, + BUTTON_CODE_P2_B, + BUTTON_CODE_P2_X, + BUTTON_CODE_P2_Y, + BUTTON_CODE_P3_UP, + BUTTON_CODE_P3_DOWN, + BUTTON_CODE_P3_LEFT, + BUTTON_CODE_P3_RIGHT, + BUTTON_CODE_P3_A, + BUTTON_CODE_P3_B, + BUTTON_CODE_P3_X, + BUTTON_CODE_P3_Y, + BUTTON_CODE_P4_UP, + BUTTON_CODE_P4_DOWN, + BUTTON_CODE_P4_LEFT, + BUTTON_CODE_P4_RIGHT, + BUTTON_CODE_P4_A, + BUTTON_CODE_P4_B, + BUTTON_CODE_P4_X, + BUTTON_CODE_P4_Y +}; + typedef struct { uint8_t SCREEN[16320]; uint8_t PALETTE[48]; @@ -24,8 +129,9 @@ typedef struct { bool left; bool middle; bool right; } MouseData; -const int32_t WIDTH = 240; -const int32_t HEIGHT = 136; +#define TILE_SIZE 8 +#define WIDTH 240 +#define HEIGHT 136 // Constants. const uint32_t TILES_SIZE = 8192; @@ -124,7 +230,7 @@ WASM_IMPORT("mouse") void mouse(MouseData* data); WASM_IMPORT("mset") -void mset(int32_t x, int32_t y, bool value); +void mset(int32_t x, int32_t y, int32_t value); WASM_IMPORT("music") void music(int32_t track, int32_t frame, int32_t row, bool loop, bool sustain, int32_t tempo, int32_t speed); From a5e4eba48cd574a7e368e3e6d0bdb73e512d0314 Mon Sep 17 00:00:00 2001 From: Gota7 Date: Sat, 16 Jul 2022 17:35:14 -0400 Subject: [PATCH 7/7] Fix Indent --- templates/c/src/tic80.h | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/templates/c/src/tic80.h b/templates/c/src/tic80.h index 03d46285d..d237a9d81 100644 --- a/templates/c/src/tic80.h +++ b/templates/c/src/tic80.h @@ -45,34 +45,34 @@ enum KEYCODES { KEY_8, KEY_9, KEY_MINUS, - KEY_EQUALS, - KEY_LEFTBRACKET, - KEY_RIGHTBRACKET, - KEY_BACKSLASH, - KEY_SEMICOLON, - KEY_APOSTROPHE, - KEY_GRAVE, - KEY_COMMA, - KEY_PERIOD, - KEY_SLASH, - KEY_SPACE, - KEY_TAB, - KEY_RETURN, - KEY_BACKSPACE, - KEY_DELETE, - KEY_INSERT, - KEY_PAGEUP, - KEY_PAGEDOWN, - KEY_HOME, - KEY_END, - KEY_UP, - KEY_DOWN, - KEY_LEFT, - KEY_RIGHT, - KEY_CAPSLOCK, - KEY_CTRL, - KEY_SHIFT, - KEY_ALT + KEY_EQUALS, + KEY_LEFTBRACKET, + KEY_RIGHTBRACKET, + KEY_BACKSLASH, + KEY_SEMICOLON, + KEY_APOSTROPHE, + KEY_GRAVE, + KEY_COMMA, + KEY_PERIOD, + KEY_SLASH, + KEY_SPACE, + KEY_TAB, + KEY_RETURN, + KEY_BACKSPACE, + KEY_DELETE, + KEY_INSERT, + KEY_PAGEUP, + KEY_PAGEDOWN, + KEY_HOME, + KEY_END, + KEY_UP, + KEY_DOWN, + KEY_LEFT, + KEY_RIGHT, + KEY_CAPSLOCK, + KEY_CTRL, + KEY_SHIFT, + KEY_ALT }; enum BUTTON_CODES