Skip to content

Commit 39cbfcc

Browse files
committed
update misc includes
1 parent 73ed935 commit 39cbfcc

File tree

10 files changed

+26
-68
lines changed

10 files changed

+26
-68
lines changed

notes-to-self.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ malloc_unit_test() can't be called twice because cache mem tests don't clean up.
9898
some of the length printf tests are failing with optimization on. Why?
9999

100100
** existing API implementation improvements **
101+
add the ability to allow await to operate on a twr-wasm C function? (implement promises)
101102
bug in divcon -- long text doesn't wrap correctly.
102103
move twrConDrawSeq into jscon driver
103104
add buffer size to io_mbgets(stream1, buffer);

source/twr-c/draw2d.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <stdlib.h>
22
#include <assert.h>
33
#include <string.h>
4-
#include "twr-jsimports.h"
54
#include "twr-crt.h"
65
#include "twr-draw2d.h"
6+
#include <math.h> // ceil
77

88

99
static twr_ioconsole_t *__std2d;
@@ -645,7 +645,7 @@ unsigned long d2d_getimagedatasize(double width, double height) {
645645
const double bytes_per_pixel = colors_per_pixel * bytes_per_color;
646646
double pixels = width * height;
647647
double bytes = pixels * bytes_per_pixel;
648-
return (unsigned long)twrCeil(bytes);
648+
return (unsigned long)ceil(bytes);
649649
}
650650

651651
void d2d_imagedatatoc(struct d2d_draw_seq* ds, long id, void* buffer, unsigned long buffer_len) {

source/twr-c/io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <ctype.h>
55
#include <assert.h>
66
#include <locale.h>
7-
#include <twr-jsimports.h>
7+
#include <twr-jsimports.h> // twrUnicodeCodePointToCodePage, twrCodePageToUnicodeCodePoint
88
#include "twr-io.h"
99
#include "twr-crt.h" //twr_vcbprintf
1010

source/twr-c/twr-draw2d.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,8 @@ struct d2d_2d_matrix {
426426
double a, b, c, d, e, f;
427427
};
428428

429+
__attribute__((import_name("twrConDrawSeq"))) void twrConDrawSeq(int jsid, struct d2d_draw_seq *);
430+
__attribute__((import_name("twrConLoadImage"))) bool twrConLoadImage(int jsid, const char* url, long id);
429431

430432
struct d2d_draw_seq* d2d_start_draw_sequence(int flush_at_ins_count);
431433
struct d2d_draw_seq* d2d_start_draw_sequence_with_con(int flush_at_ins_count, twr_ioconsole_t * con);

source/twr-c/twr-io.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ struct IoConsole {
8484
#define TRS80_GRAPHIC_MARKER_MASK 0xFF00
8585
#define TRS80_GRAPHIC_CHAR_MASK 0x003F // would be 0xC0 if we included the graphics marker bit 0x80
8686

87+
__attribute__((import_name("twrConCharOut"))) void twrConCharOut(int jsid, int c, int code_page);
88+
__attribute__((import_name("twrConPutStr"))) void twrConPutStr(int jsid, const char * str, int code_page);
89+
__attribute__((import_name("twrConCharIn"))) int twrConCharIn(int jsid);
90+
__attribute__((import_name("twrConGetProp"))) int twrConGetProp(int jsid, const char* prop_name);
91+
__attribute__((import_name("twrConCls"))) void twrConCls(int jsid);
92+
__attribute__((import_name("twrConSetC32"))) void twrConSetC32(int jsid, int location, int c32);
93+
__attribute__((import_name("twrConSetReset"))) void twrConSetReset(int jsid, int x, int y, bool isset);
94+
__attribute__((import_name("twrConPoint"))) int twrConPoint(int jsid, int x, int y);
95+
__attribute__((import_name("twrConSetCursor"))) void twrConSetCursor(int jsid, int position);
96+
__attribute__((import_name("twrConSetColors"))) void twrConSetColors(int jsid, unsigned long foreground, unsigned long background);
97+
__attribute__((import_name("twrConSetRange"))) void twrConSetRange(int jsid, int * chars, int start, int len);
98+
__attribute__((import_name("twrConSetFocus"))) void twrConSetFocus(int jsid);
99+
__attribute__((import_name("twrConGetIDFromName"))) int twrConGetIDFromName(const char* name);
100+
87101
/* ionull.c */
88102
twr_ioconsole_t* io_nullcon(void);
89103

source/twr-c/twr-jsimports.h

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define __TWR_JSIMPORTS_H__
33

44
#include <time.h>
5-
#include "twr-draw2d.h"
65
#include <twr-io.h>
76

87
/* WebAssembly.ModuleImports (Javascript/TypeScript functions callable by C code) */
@@ -13,22 +12,6 @@ extern "C" {
1312
#endif
1413

1514

16-
__attribute__((import_name("twrConCharOut"))) void twrConCharOut(int jsid, int c, int code_page);
17-
__attribute__((import_name("twrConPutStr"))) void twrConPutStr(int jsid, const char * str, int code_page);
18-
__attribute__((import_name("twrConCharIn"))) int twrConCharIn(int jsid);
19-
__attribute__((import_name("twrConGetProp"))) int twrConGetProp(int jsid, const char* prop_name);
20-
__attribute__((import_name("twrConCls"))) void twrConCls(int jsid);
21-
__attribute__((import_name("twrConSetC32"))) void twrConSetC32(int jsid, int location, int c32);
22-
__attribute__((import_name("twrConSetReset"))) void twrConSetReset(int jsid, int x, int y, bool isset);
23-
__attribute__((import_name("twrConPoint"))) int twrConPoint(int jsid, int x, int y);
24-
__attribute__((import_name("twrConSetCursor"))) void twrConSetCursor(int jsid, int position);
25-
__attribute__((import_name("twrConSetColors"))) void twrConSetColors(int jsid, unsigned long foreground, unsigned long background);
26-
__attribute__((import_name("twrConSetRange"))) void twrConSetRange(int jsid, int * chars, int start, int len);
27-
__attribute__((import_name("twrConDrawSeq"))) void twrConDrawSeq(int jsid, struct d2d_draw_seq *);
28-
__attribute__((import_name("twrConLoadImage"))) bool twrConLoadImage(int jsid, const char* url, long id);
29-
__attribute__((import_name("twrConSetFocus"))) void twrConSetFocus(int jsid);
30-
__attribute__((import_name("twrConGetIDFromName"))) int twrConGetIDFromName(const char* name);
31-
3215
__attribute__((import_name("twrTimeTmLocal"))) void twrTimeTmLocal(struct tm*, const time_t);
3316
__attribute__((import_name("twrUserLconv"))) void twrUserLconv(struct lconv *, int code_page);
3417
__attribute__((import_name("twrUserLanguage"))) char* twrUserLanguage(void);
@@ -58,18 +41,10 @@ __attribute__((import_name("twrSqrt"))) double twrSqrt(double arg);
5841
__attribute__((import_name("twrTrunc"))) double twrTrunc(double arg);
5942

6043
__attribute__((import_name("twrAtod"))) double twrAtod(const char* str, int len);
61-
__attribute__((import_name("twrToFixed"))) double twrToFixed(char* buffer, int buffer_size, double value, int dec_digits);
62-
__attribute__((import_name("twrToExponential"))) void twrToExponential(char* buffer, int buffer_size, double value, int dec_digits);
6344

64-
__attribute__((import_name("twrDtoa"))) void twrDtoa(char* buffer, int buffer_size, double value, int max_precision);
65-
__attribute__((import_name("twrFcvtS"))) int twrFcvtS(
66-
char* buffer,
67-
unsigned long sizeInBytes, //size_t
68-
double value,
69-
int fracpart_numdigits,
70-
int *dec,
71-
int *sign
72-
);
45+
// does not use locale information; it always uses . (a dot) as the decimal separator.
46+
// twr_localize_numeric_string() is available to convert buffer if needed
47+
__attribute__((import_name("twrDtoa"))) void twr_dtoa(char* buffer, int buffer_size, double value, int max_precision);
7348

7449
#ifdef __cplusplus
7550
}

source/twr-stdclib/cvtfloat.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,6 @@
55
#include "twr-crt.h"
66
#include "twr-jsimports.h"
77

8-
// does not use locale information; it always uses . (a dot) as the decimal separator.
9-
// twr_localize_numeric_string() is available to convert buffer if needed
10-
void twr_dtoa(char* buffer, int buffer_size, double value, int max_precision) {
11-
twrDtoa(buffer, buffer_size, value, max_precision);
12-
}
13-
14-
// does not use locale information; it always uses . (a dot) as the decimal separator.
15-
void twr_tofixed(char* buffer, int buffer_size, double value, int dec_digits) {
16-
twrToFixed(buffer, buffer_size, value, dec_digits);
17-
}
18-
19-
// does not use locale information; it always uses . (a dot) as the decimal separator.
20-
void twr_toexponential(char* buffer, int buffer_size, double value, int dec_digits) {
21-
twrToExponential(buffer, buffer_size, value, dec_digits);
22-
}
23-
24-
//The fcvt_s() function in C does not use locale information; it always uses . (a dot) as the decimal separator.
25-
int _fcvt_s(
26-
char* buffer,
27-
unsigned long sizeInBytes, //size_t
28-
double value,
29-
int fracpart_numdigits,
30-
int *dec,
31-
int *sign
32-
) {
33-
return twrFcvtS(buffer, sizeInBytes, value, fracpart_numdigits, dec, sign);
34-
}
35-
36-
/****************************************************************/
37-
/****************************************************************/
38-
/****************************************************************/
39-
408
// [whitespace] [sign] [digits] [.digits] [ {e | E }[sign]digits]
419
// also allow (fortran style) d/D instead of e/E
4210
// use locale-specific decimal separators.

source/twr-ts/twrlibmath.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export default class twrLibMath extends twrLibrary {
6161
twrFMod(callingMod:IWasmModule|twrWasmBase, x:number, y:number) {return x%y}
6262
twrPow(callingMod:IWasmModule|twrWasmBase, x:number, y:number ) {return Math.pow(x,y);}
6363

64-
// TODO!! remove unnecessary level of indirection in below functions
6564
twrAtod(callingMod:IWasmModule|twrWasmBase, ...p:[number, number]) {return this.atod(callingMod.wasmMem, ...p)}
6665
twrDtoa(callingMod:IWasmModule|twrWasmBase, ...p:[number, number, number, number]) {this.dtoa(callingMod.wasmMem, ...p)}
6766
twrToFixed(callingMod:IWasmModule|twrWasmBase, ...p:[number, number, number, number]) {this.toFixed(callingMod.wasmMem, ...p)}

source/twr-ts/twrlibrary.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ import {twrEventQueueReceive} from "./twreventqueue.js"
1010

1111
// fix example/lib/out and .gitignore so correct build artifacts are checked in
1212
// add test cases for twr_timer_single_shot, twr_timer_repeat, and twr_timer_cancel
13-
// add the ability to allow await to operate on a twr-wasm C function? (implement promises)
1413
// resolve fact that libraries with interfaces are passed in the "io" option. Eg Allow "libs" or other synonym.
1514
// current implementation has no libs: (akin to io:).
16-
// remove twrXX names from math lib and unwind the layer of indirection
1715
// remove twrcondummy hack. Search for TODO, there are multiple places needing fixing. Possible solutions:
1816
// (a) merge imports,
1917
// (b) require each function in interface in list each import correctly (either add isUnused or add dummy functions with exception)
2018
// changed conterm example to use debug -- either change back, or change index description
21-
// deal with twrConGetIDFromNameImpl
19+
// deal with twrConGetIDFromNameImpl. Note that twr_register_callback and twrConGetIDFromNameImpl are added in two different places. Unify?
2220
// change callingMod:IWasmModule|IWasmModuleAsync to IWasmBase ?
2321
// add IWasmBase instead of using twrWasmBase
2422
// add IWasmModuleBase ?

twr-wasm.code-workspace

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@
100100
"uchar.h": "c",
101101
"type_traits": "c",
102102
"twr-ex.h": "c",
103-
"twr-library.h": "c"
103+
"twr-library.h": "c",
104+
"twr-audio.h": "c"
104105
},
105106
//"C_Cpp.default.compilerPath": "C:/msys64/ucrt64/bin/gcc.exe",
106107
//"C_Cpp.default.compilerPath": "C:/msys64/ucrt64/bin/clang",

0 commit comments

Comments
 (0)