Initial web build commit.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// These procs are the ones that will be called from `index.html`, which is
|
||||
// generated from `index_template.html`.
|
||||
|
||||
package main_web
|
||||
|
||||
import "base:runtime"
|
||||
import "core:c"
|
||||
import "core:mem"
|
||||
|
||||
import emu "../machine"
|
||||
import sim "../simulator"
|
||||
|
||||
@(private="file")
|
||||
web_context: runtime.Context
|
||||
|
||||
@export
|
||||
main_start :: proc "c" () {
|
||||
context = runtime.default_context()
|
||||
|
||||
// The WASM allocator doesn't seem to work properly in combination with
|
||||
// emscripten. There is some kind of conflict with how the manage memory.
|
||||
// So this sets up an allocator that uses emscripten's malloc.
|
||||
context.allocator = emscripten_allocator()
|
||||
runtime.init_global_temporary_allocator(1*mem.Megabyte)
|
||||
|
||||
// Since we now use js_wasm32 we should be able to remove this and use
|
||||
// context.logger = log.create_console_logger(). However, that one produces
|
||||
// extra newlines on web. So it's a bug in that core lib.
|
||||
context.logger = create_emscripten_logger()
|
||||
|
||||
web_context = context
|
||||
|
||||
// Init the emu 8 "cpu"
|
||||
system := emu.init()
|
||||
s := sim.Simulator {
|
||||
machine = &system,
|
||||
rom_loaded = false,
|
||||
paused = true,
|
||||
step = false,
|
||||
cpu_hz = 700,
|
||||
disasm_follow = true,
|
||||
}
|
||||
|
||||
sim.init(&s)
|
||||
}
|
||||
|
||||
@export
|
||||
main_update :: proc "c" () -> bool {
|
||||
context = web_context
|
||||
|
||||
// TODO
|
||||
sim.update()
|
||||
return sim.should_run()
|
||||
}
|
||||
|
||||
@export
|
||||
main_end :: proc "c" () {
|
||||
context = web_context
|
||||
// TODO
|
||||
sim.shutdown()
|
||||
}
|
||||
|
||||
@export
|
||||
web_window_size_changed :: proc "c" (w: c.int, h: c.int) {
|
||||
context = web_context
|
||||
// TODO
|
||||
game.parent_window_size_changed(int(w), int(h))
|
||||
}
|
||||
Reference in New Issue
Block a user