diff --git a/include/vm.h b/include/vm.h index b1bca0c..5992fcf 100644 --- a/include/vm.h +++ b/include/vm.h @@ -106,6 +106,7 @@ union vm_value vm_copy(union vm_value v, enum ain_data_type type); int vm_execute_ain(struct ain *program); void vm_call(int fno, int struct_page); int vm_time(void); +void vm_sleep(int ms); void hll_call(int libno, int fno); bool library_exists(int libno); diff --git a/src/asset_manager.c b/src/asset_manager.c index 3896cdd..f15dfb3 100644 --- a/src/asset_manager.c +++ b/src/asset_manager.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/src/hll/DrawDungeon.c b/src/hll/DrawDungeon.c index 6ecdd6e..db6a27f 100644 --- a/src/hll/DrawDungeon.c +++ b/src/hll/DrawDungeon.c @@ -408,6 +408,7 @@ HLL_LIBRARY(DrawDungeon, DRAW_DUNGEON_EXPORTS ); +HLL_WARN_UNIMPLEMENTED( , void, DrawDungeon14, SetRasterScroll, int surface, int type); HLL_WARN_UNIMPLEMENTED( , void, DrawDungeon14, SetRasterAmp, int nSurface, float fAmp); HLL_WARN_UNIMPLEMENTED( , void, DrawDungeon14, SetLapFilter, int surface, int type, int r, int g, int b); @@ -431,7 +432,7 @@ HLL_LIBRARY(DrawDungeon14, HLL_EXPORT(Init, DrawDungeon14_Init), DRAW_DUNGEON_EXPORTS, HLL_EXPORT(GetWalked, dungeon_get_walked), - HLL_TODO_EXPORT(SetRasterScroll, DrawDungeon14_SetRasterScroll), + HLL_EXPORT(SetRasterScroll, DrawDungeon14_SetRasterScroll), HLL_EXPORT(SetRasterAmp, DrawDungeon14_SetRasterAmp), HLL_EXPORT(SetLapFilter, DrawDungeon14_SetLapFilter), HLL_EXPORT(GetDrawMapObjectFlag, DrawDungeon14_GetDrawMapObjectFlag), diff --git a/src/hll/InputDevice.c b/src/hll/InputDevice.c index d39733a..cf3e4e6 100644 --- a/src/hll/InputDevice.c +++ b/src/hll/InputDevice.c @@ -14,12 +14,11 @@ * along with this program; if not, see . */ -#include - #include "system4/string.h" #include "hll.h" #include "input.h" +#include "vm.h" static void handle_events_throttled(void) { @@ -28,11 +27,7 @@ static void handle_events_throttled(void) static int count; if (++count == 30) { count = 0; - struct timespec ts = { - .tv_sec = 0, - .tv_nsec = 10000000L - }; - nanosleep(&ts, NULL); + vm_sleep(10); } handle_events(); } diff --git a/src/hll/Timer.c b/src/hll/Timer.c index 92964d6..dfd2598 100644 --- a/src/hll/Timer.c +++ b/src/hll/Timer.c @@ -17,6 +17,7 @@ #include #include "hll.h" +#include "vm.h" HLL_WARN_UNIMPLEMENTED(1, int, Timer, Init, void *imainsystem); @@ -28,11 +29,7 @@ static int Timer_Get(void) static void Timer_Wait(int time) { - struct timespec ts = { - .tv_sec = time / 1000, - .tv_nsec = (time % 1000) * 1000000L - }; - nanosleep(&ts, NULL); + vm_sleep(time); } static void Timer_GetDayTime(int *year, int *month, int *day_of_week, int *day, diff --git a/src/system4.c b/src/system4.c index 08cce96..b608634 100644 --- a/src/system4.c +++ b/src/system4.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -265,7 +264,7 @@ static bool config_init_with_ini(const char *ini_path) if (!config.ain_filename) ERROR("No AIN filename specified in %s", ini_path); char *tmp = strdup(ini_path); - config.game_dir = strdup(dirname(tmp)); + config.game_dir = strdup(path_dirname(tmp)); free(tmp); config_init(); return true; @@ -285,12 +284,8 @@ static bool config_init_with_dir(const char *dir) static void config_init_with_ain(const char *ain_path) { - char *basename_tmp = strdup(ain_path); - char *dirname_tmp = strdup(ain_path); - config.ain_filename = strdup(basename(basename_tmp)); - config.game_dir = strdup(dirname(dirname_tmp)); - free(basename_tmp); - free(dirname_tmp); + config.ain_filename = strdup(path_basename(ain_path)); + config.game_dir = strdup(path_dirname(ain_path)); config_init(); } diff --git a/src/vm.c b/src/vm.c index 78131ef..042a6e0 100644 --- a/src/vm.c +++ b/src/vm.c @@ -570,11 +570,7 @@ static void system_call(enum syscall_code code) } case SYS_SLEEP: {// system.Sleep(int nSleep) int ms = stack_pop().i; - struct timespec ts = { - .tv_sec = ms / 1000, - .tv_nsec = (ms % 1000) * 1000000L - }; - nanosleep(&ts, NULL); + vm_sleep(ms); break; } case SYS_RESUME_READ_COMMENT: {// system.ResumeReadComment(string szKeyName, string szFileName, ref array@string aszComment) @@ -2374,6 +2370,11 @@ int vm_time(void) return (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000); } +void vm_sleep(int ms) +{ + SDL_Delay(ms); +} + _Noreturn void vm_exit(int code) { vm_free(); diff --git a/subprojects/libsys4 b/subprojects/libsys4 index 481581b..187a463 160000 --- a/subprojects/libsys4 +++ b/subprojects/libsys4 @@ -1 +1 @@ -Subproject commit 481581b3b5833ec676d0578a044fa7c54b421089 +Subproject commit 187a463044a0b9b207f322796aa20c42322fed98