Skip to content

Free games for graphing calculators: NumWorks, TI-Nspire CX, Casio fx-CG50 and soon TI-84 Plus CE. Balatro, Celeste, Hollow Knight, Minecraft and more.

ce_emu: frames by marker, drawn marker or LCD swap, time asleep, the floats' share

Mason36390149545d5ea
diff --git a/tools/ce_emu.py b/tools/ce_emu.py
index 6ee60fa4..13628de7 100644
--- a/tools/ce_emu.py
+++ b/tools/ce_emu.py
@@ -22,6 +22,8 @@ Options:
--profile N the N functions the CPU was found in most
--vars-out DIR the appvars and programs at the end, as files
--rev m|i|pre-a the hardware revision (m, every CE since 2019)
+ --float-scale X TI's float routines' cost times X (their cycles are estimates: TI's boot
+ code isn't public; the report says how much time went to them)
--trace every OS call
--json the full report
@@ -44,7 +46,9 @@ EXE = os.path.join(HERE, "build", "ce_emu")
LIBS_DIR = os.path.expanduser("~/Documents/Assets/toolchains/ce-libs/v15.0")
LIBS_URL = "https://github.com/CE-Programming/libraries/releases/download/v15.0/clibs.8xg"
LIBS_SHA = "450bdefb41fe263f8d2d161b7cf431bbf99711f2ef78f02f796d530ed12dfbf0"
-FRAME_SYMBOLS = ("_eadk_display_wait_for_vblank", "_eadk_keyboard_scan")
+# a frame: NumPlay's per-frame call when it's there (exact), else its key scan once the screen changed
+FRAME_SYMBOLS = (("_eadk_display_wait_for_vblank", False), ("_eadk_keyboard_scan", True))
+IDLE_SYMBOLS = ("_ticksleep", "_msleep", "_delay")
def build():
@@ -104,19 +108,20 @@ def profile_lines(samples, syms, n):
def run(files, keys="", shots="", ms=5000, out=".", ram="", lib=None, frame=None, rev="m", trace=False,
- vars_out=None, profile=0):
+ vars_out=None, profile=0, float_scale=1.0):
"""One run; its report (a dict)."""
build()
prog = next(f for f in files if f.lower().endswith(".8xp"))
syms = symbols(prog)
- addr = None
+ addr, drawn = None, False
if frame:
addr = int(frame, 0) if re.match(r"0x|\d", frame) else syms.get("_" + frame.lstrip("_"))
if addr is None:
raise SystemExit(f"ce_emu: no symbol {frame} in {os.path.splitext(prog)[0]}.obj")
else:
- frame = next((s for s in FRAME_SYMBOLS if s in syms), None)
+ frame, drawn = next(((s, d) for s, d in FRAME_SYMBOLS if s in syms), (None, False))
addr = syms.get(frame) if frame else None
+ idle = next((syms[s] for s in IDLE_SYMBOLS if s in syms), None)
with tempfile.TemporaryDirectory() as tmp:
rep = os.path.join(tmp, "report.json")
cmd = [EXE, "--rom", os.path.join(HERE, "build", "rom.bin"), "--names", os.path.join(HERE, "build", "ti84pceg.inc"),
@@ -124,8 +129,10 @@ def run(files, keys="", shots="", ms=5000, out=".", ram="", lib=None, frame=None
cmd += ["--keys", keys] if keys else []
cmd += ["--shots", shots] if shots else []
cmd += ["--ram", ram] if ram else []
- cmd += ["--frame", hex(addr)] if addr else []
+ cmd += ["--frame", hex(addr)] + (["--frame-drawn"] if drawn else []) if addr else []
+ cmd += ["--idle", hex(idle)] if idle else []
cmd += ["--trace"] if trace else []
+ cmd += ["--float-scale", str(float_scale)] if float_scale != 1 else []
cmd += ["--vars-out", vars_out] if vars_out else []
cmd += ["--profile", os.path.join(tmp, "profile")] if profile else []
cmd += files + ([lib] if lib else [])
@@ -134,7 +141,7 @@ def run(files, keys="", shots="", ms=5000, out=".", ram="", lib=None, frame=None
if not os.path.exists(rep):
raise SystemExit(f"ce_emu: {r.stderr.strip() or 'no report'}")
report = json.load(open(rep))
- report["frame_symbol"] = frame.lstrip("_") if frame and addr else None
+ report["frame_symbol"] = (frame.lstrip("_") + (" once drawn" if drawn else "")) if frame and addr else None
report["stderr"] = r.stderr
if profile:
report["profile"] = profile_lines(os.path.join(tmp, "profile"), syms, profile)
@@ -145,10 +152,12 @@ def summary(rep):
s = f"{rep['program']}: {rep['status']}" + (f" ({rep['detail']})" if rep["detail"] else "")
s += f"\n {rep['ms'] / 1000:.2f} s in {rep['wall_s']:.2f} s ({rep['speed']:.1f}x)"
if rep["frames"] > 1:
- s += (f", {rep['fps']:.1f} fps ({rep['frame_symbol']}): {rep['frame_ms']:.1f} ms a frame, 95% under "
- f"{rep['frame_ms_p95']:.1f}, slowest {rep['frame_ms_max']:.1f}, {rep['cycles_per_frame'] / 1e6:.2f} M cycles")
- elif rep["lcd_base_writes"] > 2:
- s += f", {rep['lcd_base_writes']} buffer swaps"
+ how = rep["frame_symbol"] if rep["frame_kind"].startswith("marker") else "LCD buffer swaps"
+ s += (f"\n {rep['fps']:.1f} fps ({how}): {rep['frame_ms']:.1f} ms a frame, 95% under "
+ f"{rep['frame_ms_p95']:.1f}, slowest {rep['frame_ms_max']:.1f}; {rep['work_ms_per_frame']:.1f} ms of work "
+ f"a frame ({rep['cycles_per_frame'] * rep['work_ms_per_frame'] / max(rep['frame_ms'], 1e-9) / 1e6:.2f} M cycles)")
+ if rep["float_ms"] >= 1:
+ s += f"\n {rep['float_ms'] / 1000:.2f} s ({100 * rep['float_ms'] / max(rep['ms'], 1):.0f}%) in TI's float routines (estimated)"
s += f"\n stack {rep['stack_bytes']} of 4096 bytes, {rep['free_ram']} bytes of RAM free, {rep['screen_changes']} screen changes"
if rep["text"]:
s += "\n home screen: " + rep["text"].replace("\n", " / ")
@@ -220,7 +229,7 @@ def main():
print(__doc__)
return 1
opts = {"keys": "", "shots": "", "ms": "5000", "out": ".", "ram": "", "libs": None, "frame": None, "rev": "m",
- "vars-out": None, "profile": "0", "j": "6"}
+ "vars-out": None, "profile": "0", "j": "6", "float-scale": "1"}
flags = {"trace": False, "json": False}
pos = []
i = 0
@@ -249,7 +258,7 @@ def main():
raise SystemExit("ce_emu: no .8xp to run")
lib = None if opts["libs"] == "none" else opts["libs"] or libs()
rep = run(files, keys=opts["keys"], shots=opts["shots"], ms=int(opts["ms"]), out=opts["out"], ram=opts["ram"],
- lib=lib, frame=opts["frame"], rev=opts["rev"], trace=flags["trace"], vars_out=opts["vars-out"],
+ lib=lib, frame=opts["frame"], rev=opts["rev"], trace=flags["trace"], vars_out=opts["vars-out"], float_scale=float(opts["float-scale"]),
profile=int(opts["profile"]))
if rep["stderr"]:
sys.stderr.write(rep["stderr"])
diff --git a/tools/ce_emu/ce_emu.c b/tools/ce_emu/ce_emu.c
index 76e9c960..e30dffe9 100644
--- a/tools/ce_emu/ce_emu.c
+++ b/tools/ce_emu/ce_emu.c
@@ -75,7 +75,8 @@ static struct {
int nshots;
char ram[64][9];
int nram;
- uint32_t frame_addr;
+ uint32_t frame_addr, idle_addr;
+ bool frame_drawn;
} opt = {.ms = 5000, .out = ".", .rev = "m"};
/* ---- the run's state ---- */
@@ -90,9 +91,38 @@ static char console_err[512];
static char text_log[8192];
static size_t text_len;
static bool held[8][8], on_held;
-static uint64_t key_reads, os_calls, frames, screen_changes, upbase_writes;
-static uint64_t frame_cycles[100000];
-static uint64_t last_frame_cycle;
+static uint64_t key_reads, os_calls, screen_changes;
+/* frames: a marker reached (--frame), or the LCD's base set (a double-buffered program's swap) */
+typedef struct {
+ uint64_t n, at[50000];
+} frames_t;
+static frames_t marks, swaps;
+static uint32_t drawn_hash;
+/* time asleep (--idle: a function the program waits in, ticksleep): from its call to its return */
+static struct {
+ uint64_t from, to;
+} idle[200000];
+static int nidle;
+static uint32_t idle_ret;
+static uint64_t idle_from;
+static double idle_total;
+static double idle_between(uint64_t a, uint64_t b) {
+ double t = 0;
+ for (int i = 0; i < nidle; i++) {
+ uint64_t x = idle[i].from > a ? idle[i].from : a, y = idle[i].to < b ? idle[i].to : b;
+ if (y > x) t += y - x;
+ }
+ return t;
+}
+static int cmp_double(const void *a, const void *b) {
+ double x = *(const double *)a, y = *(const double *)b;
+ return x < y ? -1 : x > y;
+}
+static void add_frame(frames_t *f) {
+ if (!started) return;
+ if (f->n < sizeof f->at / sizeof f->at[0]) f->at[f->n] = sched_total_cycles();
+ f->n++;
+}
static uint32_t last_hash;
static uint32_t *samples;
@@ -130,7 +160,6 @@ void emu_program_started(void) {
started = true;
started_cycles = cycles_now();
start_ms = now_ms;
- last_frame_cycle = 0;
debug_watch(0x000000, DBG_MASK_EXEC, true);
}
void emu_program_exited(uint32_t code) {
@@ -170,12 +199,28 @@ void gui_debug_open(int reason, uint32_t data) {
switch (reason) {
case DBG_BREAKPOINT:
if (data == opt.frame_addr && opt.frame_addr) {
- uint64_t c = cycles_now();
- if (frames < sizeof frame_cycles / sizeof frame_cycles[0]) frame_cycles[frames] = c;
- frames++;
- last_frame_cycle = c;
+ if (opt.frame_drawn) { /* only when what the LCD shows changed since the last one */
+ uint32_t n = (lcd.control >> 1 & 7) == 3 ? LCD_SIZE : LCD_SIZE * 2;
+ uint8_t *p = mem_at(lcd.upbase, n);
+ uint32_t h = p ? crc32(0, p, n) : 0;
+ if (h == drawn_hash) return;
+ drawn_hash = h;
+ }
+ add_frame(&marks);
+ return;
+ }
+ if (data == opt.idle_addr && opt.idle_addr && !idle_ret) {
+ idle_ret = rd24(sp), idle_from = cycles_now();
+ if (idle_ret != opt.frame_addr) debug_watch(idle_ret, DBG_MASK_EXEC, true);
return;
}
+ if (data == idle_ret && idle_ret) {
+ if (idle_ret != opt.frame_addr && idle_ret != opt.idle_addr) debug_watch(idle_ret, DBG_MASK_EXEC, false);
+ idle_ret = 0;
+ if (nidle < (int)(sizeof idle / sizeof idle[0])) idle[nidle].from = idle_from, idle[nidle++].to = cycles_now();
+ idle_total += cycles_now() - idle_from;
+ if (data != opt.frame_addr) return;
+ }
if (data == 0x000000) {
emu_stop("crash", "the reset vector: an invalid instruction or a jump to 0, returning to %06X",
rd24(sp));
@@ -194,7 +239,7 @@ void gui_debug_open(int reason, uint32_t data) {
return;
case DBG_WATCHPOINT_WRITE:
if (data >= 0xE30010 && data < 0xE30013) {
- upbase_writes++;
+ if (data == 0xE30010) add_frame(&swaps); /* (graphx's gfx_SwapDraw: one a frame) */
return;
}
if (started) emu_stop("crash", "a write to unmapped memory at %06X (pc %06X)", data, pc);
@@ -348,7 +393,10 @@ int main(int argc, char **argv) {
else if (!strcmp(a, "--names") && v) opt.names = v, i++;
else if (!strcmp(a, "--rev") && v) opt.rev = v, i++;
else if (!strcmp(a, "--frame") && v) opt.frame_addr = (uint32_t)strtoul(v, NULL, 0), i++;
+ else if (!strcmp(a, "--frame-drawn")) opt.frame_drawn = true;
+ else if (!strcmp(a, "--idle") && v) opt.idle_addr = (uint32_t)strtoul(v, NULL, 0), i++;
else if (!strcmp(a, "--trace")) os_trace = true;
+ else if (!strcmp(a, "--float-scale") && v) os_float_scale = atof(v), i++;
else if (!strcmp(a, "--screen-memory")) from_memory = true;
else if (!strcmp(a, "--profile") && v) opt.profile = v, i++;
else if (!strcmp(a, "--ram") && v) {
@@ -416,6 +464,7 @@ int main(int argc, char **argv) {
if (rd8(a) == 0xC9) debug_watch(a, DBG_MASK_EXEC, true);
debug_watch(0x66, DBG_MASK_EXEC, true);
if (opt.frame_addr) debug_watch(opt.frame_addr, DBG_MASK_EXEC, true);
+ if (opt.idle_addr) debug_watch(opt.idle_addr, DBG_MASK_EXEC, true);
for (uint32_t a = 0xF50010; a < 0xF50020; a++) debug_watch(a, DBG_MASK_READ, true);
for (uint32_t a = 0xE30010; a < 0xE30013; a++) debug_watch(a, DBG_MASK_WRITE, true);
for (uint32_t a = 0xD00000; a < 0xE00000; a++)
@@ -456,7 +505,7 @@ int main(int argc, char **argv) {
/* hangs */
if (cpu.halted && !cpu.IEF1) emu_stop("hang", "halt with interrupts off at %06X", cpu.registers.PC);
uint32_t pc = cpu.registers.PC;
- uint64_t act = frames + screen_changes + key_reads + os_calls + upbase_writes;
+ uint64_t act = marks.n + swaps.n + screen_changes + key_reads + os_calls;
if (act != activity) activity = act, last_activity = now_ms;
if (pc - stuck_pc > 64 && stuck_pc - pc > 64) stuck_pc = pc, stuck_since = now_ms;
uint64_t quiet = now_ms - (stuck_since > last_activity ? stuck_since : last_activity);
@@ -483,25 +532,23 @@ int main(int argc, char **argv) {
if (pf) fclose(pf);
}
- /* frames: the time from each to the next, past the first */
- uint64_t nf = frames < sizeof frame_cycles / sizeof frame_cycles[0] ? frames : sizeof frame_cycles / sizeof frame_cycles[0];
- double fps = 0, mean_ms = 0, max_ms = 0, p95 = 0;
+ /* frames: the marker's, else the buffer swaps'; the time from each to the next */
+ frames_t *fr = marks.n >= 2 || swaps.n < 2 ? &marks : &swaps;
+ const char *frame_kind = fr == &swaps ? "lcd-swap" : opt.frame_drawn ? "marker-drawn" : opt.frame_addr ? "marker" : "none";
+ uint64_t nf = fr->n < sizeof fr->at / sizeof fr->at[0] ? fr->n : sizeof fr->at / sizeof fr->at[0];
+ double fps = 0, mean_ms = 0, max_ms = 0, p95 = 0, work_ms = 0;
uint64_t over33 = 0;
if (nf >= 2) {
double *d = malloc((nf - 1) * sizeof *d);
for (uint64_t i = 1; i < nf; i++) {
- d[i - 1] = (frame_cycles[i] - frame_cycles[i - 1]) / CPU_HZ * 1000;
- mean_ms += d[i - 1];
+ d[i - 1] = (fr->at[i] - fr->at[i - 1]) / CPU_HZ * 1000;
if (d[i - 1] > max_ms) max_ms = d[i - 1];
if (d[i - 1] > 33.4) over33++;
}
- mean_ms /= nf - 1;
+ mean_ms = (fr->at[nf - 1] - fr->at[0]) / CPU_HZ * 1000 / (nf - 1);
fps = 1000 / mean_ms;
- for (uint64_t i = 1; i < nf - 1; i++) /* (insertion sort: a few thousand at most) */
- for (uint64_t j = i; j > 0 && d[j] < d[j - 1]; j--) {
- double t = d[j];
- d[j] = d[j - 1], d[j - 1] = t;
- }
+ work_ms = mean_ms - idle_between(fr->at[0], fr->at[nf - 1]) / CPU_HZ * 1000 / (nf - 1);
+ qsort(d, nf - 1, sizeof *d, cmp_double);
p95 = d[(uint64_t)((nf - 2) * 0.95)];
free(d);
}
@@ -516,12 +563,13 @@ int main(int argc, char **argv) {
json_str(f, stopping ? detail : "");
fprintf(f, ",\n \"ms\": %llu,\n \"exit_code\": %d,\n \"wall_s\": %.3f,\n \"speed\": %.2f,\n",
(unsigned long long)now_ms, exited ? (int)exit_code : -1, wall, wall > 0 ? emu_s / wall : 0);
- fprintf(f, " \"cycles\": %llu,\n \"frames\": %llu,\n \"fps\": %.2f,\n \"frame_ms\": %.2f,\n \"frame_ms_p95\": %.2f,\n"
- " \"frame_ms_max\": %.2f,\n \"frames_over_33ms\": %llu,\n \"cycles_per_frame\": %.0f,\n",
- (unsigned long long)cycles_now(), (unsigned long long)frames, fps, mean_ms, p95, max_ms,
- (unsigned long long)over33, mean_ms * CPU_HZ / 1000);
- fprintf(f, " \"lcd_base_writes\": %llu,\n \"screen_changes\": %llu,\n \"key_reads\": %llu,\n",
- (unsigned long long)upbase_writes, (unsigned long long)screen_changes, (unsigned long long)key_reads);
+ fprintf(f, " \"cycles\": %llu,\n \"frames\": %llu,\n \"frame_kind\": \"%s\",\n \"fps\": %.2f,\n \"frame_ms\": %.2f,\n"
+ " \"frame_ms_p95\": %.2f,\n \"frame_ms_max\": %.2f,\n \"frames_over_33ms\": %llu,\n"
+ " \"cycles_per_frame\": %.0f,\n \"work_ms_per_frame\": %.2f,\n \"idle_ms\": %.0f,\n",
+ (unsigned long long)cycles_now(), (unsigned long long)fr->n, frame_kind, fps, mean_ms, p95, max_ms,
+ (unsigned long long)over33, mean_ms * CPU_HZ / 1000, work_ms, idle_total / CPU_HZ * 1000);
+ fprintf(f, " \"lcd_swaps\": %llu,\n \"screen_changes\": %llu,\n \"key_reads\": %llu,\n",
+ (unsigned long long)swaps.n, (unsigned long long)screen_changes, (unsigned long long)key_reads);
os_report(f);
fprintf(f, " \"vars_saved\": %d,\n \"text\": ", saved);
json_str(f, text_log);
@@ -533,8 +581,8 @@ int main(int argc, char **argv) {
printf("ce_emu: %s %s%s%s\n", prog, status, stopping ? ": " : "", stopping ? detail : "");
printf("ce_emu: %.2f s emulated in %.2f s (%.1fx) at %.0f MHz", emu_s, wall, wall > 0 ? emu_s / wall : 0,
sched_get_clock_rate(CLOCK_CPU) / 1e6);
- if (frames) printf(", %llu frames, %.1f fps, %.1f ms a frame (95%%: %.1f, slowest %.1f)", (unsigned long long)frames, fps,
- mean_ms, p95, max_ms);
+ if (nf >= 2) printf(", %llu frames (%s), %.1f fps, %.1f ms a frame (95%%: %.1f, slowest %.1f)", (unsigned long long)fr->n,
+ frame_kind, fps, mean_ms, p95, max_ms);
printf("\n");
if (text_len) printf("ce_emu: home screen: %s\n", text_log);
if (warn_len) printf("ce_emu: warnings: %s\n", warnings);
diff --git a/tools/ce_emu/ce_emu.h b/tools/ce_emu/ce_emu.h
index 085f2bab..fcb7d0cf 100644
--- a/tools/ce_emu/ce_emu.h
+++ b/tools/ce_emu/ce_emu.h
@@ -67,6 +67,8 @@ const char *os_name(uint32_t addr);
void os_report(FILE *f);
int os_save_vars(const char *dir);
extern bool os_trace;
+extern double os_float_scale;
+extern uint64_t os_float_cycles;
/* ce_emu.c, for os.c */
void emu_stop(const char *status, const char *fmt, ...);
diff --git a/tools/ce_emu/os.c b/tools/ce_emu/os.c
index b4e8fde3..afbc7ec2 100644
--- a/tools/ce_emu/os.c
+++ b/tools/ce_emu/os.c
@@ -486,7 +486,15 @@ static int ce_format(char *out, size_t cap, uint32_t fmt, int argi) {
return (int)o;
}
-/* ---- floats: TI's boot code works on A:UBC and E:UHL ---- */
+/* ---- floats: TI's boot code works on A:UBC and E:UHL. Their cost is an estimate (TI's code isn't public):
+ * --float-scale changes it, and the report says how much of the time went to them ---- */
+double os_float_scale = 1;
+uint64_t os_float_cycles;
+static void float_charge(uint32_t cycles) {
+ uint32_t c = (uint32_t)(cycles * os_float_scale + 0.5);
+ os_float_cycles += c;
+ emu_charge(c);
+}
static float as_float(uint32_t b) {
float f;
memcpy(&f, &b, 4);
@@ -681,14 +689,14 @@ bool os_trap(uint32_t pc) {
emu_charge(3000 + 400 * n);
return true;
}
- case 0x270: set_abc(bits_of(f_abc() + f_ehl())), emu_charge(350); return true; /* __fadd */
- case 0x274: fcmp(f_abc(), f_ehl()), emu_charge(110); return true; /* __fcmp */
- case 0x278: set_abc(bits_of(f_abc() / f_ehl())), emu_charge(1100); return true; /* __fdiv */
- case 0x27C: set_abc((uint32_t)ftol(f_abc())), emu_charge(170); return true; /* __ftol */
- case 0x284: set_abc(bits_of(ltof((int32_t)((uint32_t)R.A << 24 | (R.BC & 0xFFFFFF))))), emu_charge(150); return true;
- case 0x288: set_abc(bits_of(f_abc() * f_ehl())), emu_charge(450); return true; /* __fmul */
- case 0x290: set_abc(bits_of(f_abc() - f_ehl())), emu_charge(370); return true; /* __fsub */
- case 0x298: ret_float(sqrtf(as_float(arg32(0)))), emu_charge(2500); return true;
+ case 0x270: set_abc(bits_of(f_abc() + f_ehl())), float_charge(350); return true; /* __fadd */
+ case 0x274: fcmp(f_abc(), f_ehl()), float_charge(110); return true; /* __fcmp */
+ case 0x278: set_abc(bits_of(f_abc() / f_ehl())), float_charge(1100); return true; /* __fdiv */
+ case 0x27C: set_abc((uint32_t)ftol(f_abc())), float_charge(170); return true; /* __ftol */
+ case 0x284: set_abc(bits_of(ltof((int32_t)((uint32_t)R.A << 24 | (R.BC & 0xFFFFFF))))), float_charge(150); return true;
+ case 0x288: set_abc(bits_of(f_abc() * f_ehl())), float_charge(450); return true; /* __fmul */
+ case 0x290: set_abc(bits_of(f_abc() - f_ehl())), float_charge(370); return true; /* __fsub */
+ case 0x298: ret_float(sqrtf(as_float(arg32(0)))), float_charge(2500); return true;
case 0x374: vram_fill(0, 240, 0xFFFF), emu_charge(200000); return true; /* boot.ClearVRAM */
case 0x378: R.HL = put_string(R.HL, true); return true; /* boot.PutS */
case 0x384: case 0x388: return true; /* Initialize/TurnOffHardware */
@@ -868,8 +876,8 @@ bool os_trap(uint32_t pc) {
return true;
/* the C library's float functions in the OS */
- case 0x220D8: { int ex; float m = frexpf(as_float(arg32(0)), &ex); if (arg(2)) wr24(arg(2), (uint32_t)ex); ret_float(m); emu_charge(300); return true; }
- case 0x220DC: ret_float(ldexpf(as_float(arg32(0)), (int)((arg(2) ^ 0x800000) - 0x800000))), emu_charge(300); return true;
+ case 0x220D8: { int ex; float m = frexpf(as_float(arg32(0)), &ex); if (arg(2)) wr24(arg(2), (uint32_t)ex); ret_float(m); float_charge(300); return true; }
+ case 0x220DC: ret_float(ldexpf(as_float(arg32(0)), (int)((arg(2) ^ 0x800000) - 0x800000))), float_charge(300); return true;
case 0x220E0: case 0x22110: { /* strtof, atof */
char s[128];
int k = 0;
@@ -879,28 +887,28 @@ bool os_trap(uint32_t pc) {
char *end;
float v = strtof(s, &end);
if (pc == 0x220E0 && arg(1)) wr24(arg(1), p + (uint32_t)(end - s));
- ret_float(v), emu_charge(4000);
+ ret_float(v), float_charge(4000);
return true;
}
- case 0x220E4: ret_float(logf(as_float(arg32(0)))), emu_charge(5000); return true;
- case 0x220E8: ret_float(log10f(as_float(arg32(0)))), emu_charge(5500); return true;
- case 0x220EC: { float ip, fr = modff(as_float(arg32(0)), &ip); if (arg(2)) { uint32_t b = bits_of(ip); wr24(arg(2), b & 0xFFFFFF), wr8(arg(2) + 3, b >> 24); } ret_float(fr); emu_charge(300); return true; }
- case 0x220F0: ret_float(fabsf(as_float(arg32(0)))), emu_charge(60); return true;
- case 0x220F4: ret_float(floorf(as_float(arg32(0)))), emu_charge(300); return true;
- case 0x220F8: ret_float(powf(as_float(arg32(0)), as_float(arg32(2)))), emu_charge(12000); return true;
- case 0x220FC: ret_float(fmodf(as_float(arg32(0)), as_float(arg32(2)))), emu_charge(1500); return true;
- case 0x22100: ret_float(acosf(as_float(arg32(0)))), emu_charge(6000); return true;
- case 0x22104: ret_float(asinf(as_float(arg32(0)))), emu_charge(6000); return true;
- case 0x22108: ret_float(atanf(as_float(arg32(0)))), emu_charge(5000); return true;
- case 0x2210C: ret_float(atan2f(as_float(arg32(0)), as_float(arg32(2)))), emu_charge(6000); return true;
- case 0x22114: ret_float(ceilf(as_float(arg32(0)))), emu_charge(300); return true;
- case 0x22118: ret_float(sinf(as_float(arg32(0)))), emu_charge(5000); return true;
- case 0x2211C: ret_float(cosf(as_float(arg32(0)))), emu_charge(5000); return true;
- case 0x22120: ret_float(tanf(as_float(arg32(0)))), emu_charge(9000); return true;
- case 0x22124: ret_float(expf(as_float(arg32(0)))), emu_charge(5000); return true;
- case 0x22130: ret_float(sinhf(as_float(arg32(0)))), emu_charge(7000); return true;
- case 0x22134: ret_float(coshf(as_float(arg32(0)))), emu_charge(7000); return true;
- case 0x22138: ret_float(tanhf(as_float(arg32(0)))), emu_charge(8000); return true;
+ case 0x220E4: ret_float(logf(as_float(arg32(0)))), float_charge(5000); return true;
+ case 0x220E8: ret_float(log10f(as_float(arg32(0)))), float_charge(5500); return true;
+ case 0x220EC: { float ip, fr = modff(as_float(arg32(0)), &ip); if (arg(2)) { uint32_t b = bits_of(ip); wr24(arg(2), b & 0xFFFFFF), wr8(arg(2) + 3, b >> 24); } ret_float(fr); float_charge(300); return true; }
+ case 0x220F0: ret_float(fabsf(as_float(arg32(0)))), float_charge(60); return true;
+ case 0x220F4: ret_float(floorf(as_float(arg32(0)))), float_charge(300); return true;
+ case 0x220F8: ret_float(powf(as_float(arg32(0)), as_float(arg32(2)))), float_charge(12000); return true;
+ case 0x220FC: ret_float(fmodf(as_float(arg32(0)), as_float(arg32(2)))), float_charge(1500); return true;
+ case 0x22100: ret_float(acosf(as_float(arg32(0)))), float_charge(6000); return true;
+ case 0x22104: ret_float(asinf(as_float(arg32(0)))), float_charge(6000); return true;
+ case 0x22108: ret_float(atanf(as_float(arg32(0)))), float_charge(5000); return true;
+ case 0x2210C: ret_float(atan2f(as_float(arg32(0)), as_float(arg32(2)))), float_charge(6000); return true;
+ case 0x22114: ret_float(ceilf(as_float(arg32(0)))), float_charge(300); return true;
+ case 0x22118: ret_float(sinf(as_float(arg32(0)))), float_charge(5000); return true;
+ case 0x2211C: ret_float(cosf(as_float(arg32(0)))), float_charge(5000); return true;
+ case 0x22120: ret_float(tanf(as_float(arg32(0)))), float_charge(9000); return true;
+ case 0x22124: ret_float(expf(as_float(arg32(0)))), float_charge(5000); return true;
+ case 0x22130: ret_float(sinhf(as_float(arg32(0)))), float_charge(7000); return true;
+ case 0x22134: ret_float(coshf(as_float(arg32(0)))), float_charge(7000); return true;
+ case 0x22138: ret_float(tanhf(as_float(arg32(0)))), float_charge(8000); return true;
}
unknown_calls++;
emu_stop("unimplemented", "the program called %s %s at %06X, which ce_emu's OS doesn't do yet (from %06X)",
@@ -914,8 +922,9 @@ void os_report(FILE *f) {
for (uint32_t i = 0; i < sizeof calls / sizeof calls[0]; i++)
if (calls[i] && (i * 4 < HLE_BASE || i * 4 >= HLE_BASE + 4 * HLE_SLOTS))
fprintf(f, "%s\"%s\": %u", n++ ? ", " : "", os_name(i * 4), calls[i]);
- fprintf(f, "},\n \"stack_bytes\": %d,\n \"free_ram\": %u,\n \"archive_used\": %u,\n \"garbage_collects\": %d,\n",
- os_stack_used(), ram_free(), arc_free - ARC_START, arc_gcs);
+ fprintf(f, "},\n \"float_ms\": %.0f,\n \"stack_bytes\": %d,\n \"free_ram\": %u,\n \"archive_used\": %u,\n"
+ " \"garbage_collects\": %d,\n",
+ os_float_cycles / 48000.0, os_stack_used(), ram_free(), arc_free - ARC_START, arc_gcs);
}
/* the appvars and programs at the end, as .8xv/.8xp files */