Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix WASM font signature #1971

Merged
merged 3 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,12 +972,12 @@ M3Result linkTicAPI(IM3Module module)
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "exit", "v()", &wasmtic_exit)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "fget", "i(ii)", &wasmtic_fget)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "fset", "v(iii)", &wasmtic_fset)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "font", "i(*iiiiiii)", &wasmtic_font)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "font", "i(*iiiiiiiii)", &wasmtic_font)));
soxfox42 marked this conversation as resolved.
Show resolved Hide resolved
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "key", "i(i)", &wasmtic_key)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "keyp", "i(iii)", &wasmtic_keyp)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "line", "v(ffffi)", &wasmtic_line)));
// TODO: needs a lot of help for all the optional arguments
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "map", "v(iiiiiiiiii)", &wasmtic_map)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "map", "v(iiiiiiiiii)", &wasmtic_map)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "memcpy", "v(iii)", &wasmtic_memcpy)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "memset", "v(iii)", &wasmtic_memset)));
_ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "mget", "i(ii)", &wasmtic_mget)));
Expand Down
6 changes: 3 additions & 3 deletions templates/d/src/tic80.d
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ void exit();
void elli(int x, int y, int a, int b, int color);
void ellib(int x, int y, int a, int b, int color);
bool fget(int id, ubyte flag);
int font(char* text, int x, int y, ubyte transcolors, int colorcount, int width, int height, bool fixed, int scale);
int font(const char* text, int x, int y, uint* transcolors, int colorcount, int width, int height, bool fixed, int scale, bool alt);
Copy link
Collaborator

@joshgoebel joshgoebel Jul 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you SURE this is const char*? Is there a reason non-const values can't be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really to be honest, I've never really done much with D. I added const because 1. that's what print and trace use and 2. it made my test compile.

I think const here just means the function won't be able to change the value, not that a constant value has to be passed.

bool fset(int id, ubyte flag, bool value);
bool key(int keycode);
bool keyp(int keycode, int hold, int period);
void line(float x0, float y0, float x1, float y1, byte color);
void map(int x, int y, int w, int h, int sx, int sy, ubyte transcolors, int colorcount, int scale, int remap);
void map(int x, int y, int w, int h, int sx, int sy, uint* transcolors, int colorcount, int scale, int remap);
void memcpy(uint copyto, uint copyfrom, uint length);
void memset(uint addr, ubyte value, uint length);
int mget(int x, int y);
Expand All @@ -93,7 +93,7 @@ void sfx(int id, int note, int octave, int duration, int channel, int volumeLeft
void spr(int id, int x, int y, uint* transcolors, uint colorcount, int scale, int flip, int rotate, int w, int h);
void sync(int mask, int bank, bool tocart);
void trace(const char* txt, int color);
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, int texsrc, ubyte transcolors, int colorcount, float z1, float z2, float z3, bool persp);
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, int texsrc, uint* transcolors, int colorcount, float z1, float z2, float z3, bool persp);
void tri(float x1, float y1, float x2, float y2, float x3, float y3, int color);
void trib(float x1, float y1, float x2, float y2, float x3, float y3, int color);
float time();
Expand Down
7 changes: 4 additions & 3 deletions templates/zig/src/tic80.zig
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub const raw = struct {
pub extern fn elli(x: i32, y: i32, a: i32, b: i32, color: i32) void;
pub extern fn ellib(x: i32, y: i32, a: i32, b: i32, color: i32) void;
pub extern fn fget(id: i32, flag: u8) bool;
pub extern fn font(text: [*:0]u8, x: u32, y: i32, trans_colors: ?[*]const u8, color_count: i32, char_width: i32, char_height: i32, fixed: bool, scale: i32) i32;
pub extern fn font(text: [*:0]u8, x: u32, y: i32, trans_colors: ?[*]const u8, color_count: i32, char_width: i32, char_height: i32, fixed: bool, scale: i32, alt: bool) i32;
pub extern fn fset(id: i32, flag: u8, value: bool) bool;
pub extern fn key(keycode: i32) bool;
pub extern fn keyp(keycode: i32, hold: i32, period: i32 ) bool;
Expand Down Expand Up @@ -297,7 +297,8 @@ const FontArgs = struct {
char_width: u8,
char_height: u8,
fixed: bool = false,
scale: u8 = 1
scale: u8 = 1,
alt: bool = false
};

fn sliceToZString(text: []const u8, buff: [*:0]u8, maxLen: u16) void {
Expand All @@ -323,7 +324,7 @@ pub fn font(text: []const u8, x: u32, y: i32, args: FontArgs) i32 {
const colors = args.transparent.ptr;
var buff : [MAX_STRING_SIZE:0]u8 = undefined;
sliceToZString(text, &buff, MAX_STRING_SIZE);
return raw.font(&buff, x, y, colors, color_count, args.char_width, args.char_height, args.fixed, args.scale);
return raw.font(&buff, x, y, colors, color_count, args.char_width, args.char_height, args.fixed, args.scale, args.alt);
}


Expand Down