diff --git a/apps/common/uvm32_target.h b/apps/common/uvm32_target.h index 90504b0..1998802 100644 --- a/apps/common/uvm32_target.h +++ b/apps/common/uvm32_target.h @@ -50,6 +50,7 @@ static uint32_t syscall(uint32_t id, uint32_t param1, uint32_t param2) { #define printbuf(x, y) syscall_cast(UVM32_SYSCALL_PRINTBUF, x, y) #define render(x, y) syscall_cast(UVM32_SYSCALL_RENDER, x, y) #define getkey() syscall_cast(UVM32_SYSCALL_GETKEY, 0, 0) +#define rand() syscall_cast(UVM32_SYSCALL_RAND, 0, 0) extern char _estack; diff --git a/apps/zigtris/src/main.zig b/apps/zigtris/src/main.zig index 0464a0c..d954e36 100644 --- a/apps/zigtris/src/main.zig +++ b/apps/zigtris/src/main.zig @@ -10,7 +10,7 @@ export fn main() void { var gameRunning = true; var lastUpdate:u32 = 0; - zigtris.gamesetup(console, uvm.millis()) catch |err| { + zigtris.gamesetup(console, uvm.rand()) catch |err| { _ = console.print("err {any}\n", .{err}) catch 0; _ = console.flush() catch 0; return; diff --git a/apps/zigtris/src/uvm.zig b/apps/zigtris/src/uvm.zig index cd73386..795e0bf 100644 --- a/apps/zigtris/src/uvm.zig +++ b/apps/zigtris/src/uvm.zig @@ -27,6 +27,10 @@ pub inline fn millis() u32 { return syscall(uvm32.UVM32_SYSCALL_MILLIS, 0, 0); } +pub inline fn rand() u32 { + return syscall(uvm32.UVM32_SYSCALL_RAND, 0, 0); +} + // dupeZ would be better, but want to avoid using an allocator // this is of course, unsafe... var termination_buf:[128]u8 = undefined; diff --git a/common/uvm32_common_custom.h b/common/uvm32_common_custom.h index 6d06b52..92787f2 100644 --- a/common/uvm32_common_custom.h +++ b/common/uvm32_common_custom.h @@ -14,4 +14,6 @@ #define UVM32_SYSCALL_GETKEY 0x00000009 #define UVM32_SYSCALL_RENDERAUDIO 0x0000000A #define UVM32_SYSCALL_CANRENDERAUDIO 0x0000000B +#define UVM32_SYSCALL_RAND 0x0000000C + diff --git a/hosts/host-sdl/host-sdl.c b/hosts/host-sdl/host-sdl.c index 3752410..9dc60c4 100644 --- a/hosts/host-sdl/host-sdl.c +++ b/hosts/host-sdl/host-sdl.c @@ -241,6 +241,8 @@ int main(int argc, char *argv[]) { return 1; } + srand(clock()); + uvm32_init(vmst); if (!uvm32_load(vmst, rom, romlen)) { @@ -374,6 +376,9 @@ int main(int argc, char *argv[]) { case UVM32_SYSCALL_MILLIS: { uvm32_arg_setval(vmst, &evt, RET, SDL_GetTicks()); } break; + case UVM32_SYSCALL_RAND: + uvm32_arg_setval(&vmst, &evt, RET, rand()); + break; case UVM32_SYSCALL_GETC: { uvm32_arg_setval(vmst, &evt, RET, 0xFFFFFFFF); } break; diff --git a/hosts/host/host.c b/hosts/host/host.c index 6aa8f05..9863c7c 100644 --- a/hosts/host/host.c +++ b/hosts/host/host.c @@ -190,6 +190,8 @@ int main(int argc, char *argv[]) { return 1; } + srand(clock()); + uvm32_init(&vmst); if (!uvm32_load(&vmst, rom, romlen)) { @@ -264,6 +266,9 @@ int main(int argc, char *argv[]) { case UVM32_SYSCALL_PRINTHEX: printf("%08x", uvm32_arg_getval(&vmst, &evt, ARG0)); break; + case UVM32_SYSCALL_RAND: + uvm32_arg_setval(&vmst, &evt, RET, rand()); + break; case UVM32_SYSCALL_MILLIS: { clock_t now = clock() / (CLOCKS_PER_SEC / 1000); uvm32_arg_setval(&vmst, &evt, RET, now - start_time);