2016-02-07 21:15:58 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 21.01.2014
|
|
|
|
*
|
|
|
|
* System functions for project codename "4ed"
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
2017-03-12 01:20:24 +00:00
|
|
|
#if !defined(FCODER_SYSTEM_INTERFACE_H)
|
|
|
|
#define FCODER_SYSTEM_INTERFACE_H
|
|
|
|
|
|
|
|
// types
|
2016-02-07 21:15:58 +00:00
|
|
|
struct Plat_Handle{
|
|
|
|
u32 d[4];
|
|
|
|
};
|
|
|
|
|
2018-11-20 08:18:54 +00:00
|
|
|
static Plat_Handle null_plat_handle = {};
|
2016-03-20 22:43:28 +00:00
|
|
|
|
2019-01-31 13:06:42 +00:00
|
|
|
internal b32
|
2016-08-26 17:52:35 +00:00
|
|
|
handle_equal(Plat_Handle a, Plat_Handle b){
|
2017-03-12 01:20:24 +00:00
|
|
|
b32 result = (memcmp(&a, &b, sizeof(a)) == 0);
|
2016-03-11 03:33:19 +00:00
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2017-03-11 18:35:12 +00:00
|
|
|
// files
|
2017-02-12 06:01:01 +00:00
|
|
|
#define Sys_Set_File_List_Sig(name) void name(File_List *file_list, char *directory, char *canon_directory_out, u32 *canon_directory_size_out, u32 canon_directory_max)
|
2016-02-07 21:15:58 +00:00
|
|
|
typedef Sys_Set_File_List_Sig(System_Set_File_List);
|
|
|
|
|
2017-03-23 19:15:05 +00:00
|
|
|
#define Sys_Get_Canonical_Sig(name) u32 name(char *filename, u32 len, char *buffer, u32 max)
|
2016-08-26 17:52:35 +00:00
|
|
|
typedef Sys_Get_Canonical_Sig(System_Get_Canonical);
|
2016-05-27 17:11:38 +00:00
|
|
|
|
2017-03-11 18:35:12 +00:00
|
|
|
// file load/save
|
2016-08-26 17:52:35 +00:00
|
|
|
#define Sys_Load_Handle_Sig(name) b32 name(char *filename, Plat_Handle *handle_out)
|
|
|
|
typedef Sys_Load_Handle_Sig(System_Load_Handle);
|
2016-08-22 23:54:20 +00:00
|
|
|
|
2016-08-26 17:52:35 +00:00
|
|
|
#define Sys_Load_Size_Sig(name) u32 name(Plat_Handle handle)
|
|
|
|
typedef Sys_Load_Size_Sig(System_Load_Size);
|
2016-08-22 23:54:20 +00:00
|
|
|
|
2016-08-26 17:52:35 +00:00
|
|
|
#define Sys_Load_File_Sig(name) b32 name(Plat_Handle handle, char *buffer, u32 size)
|
2016-08-22 23:54:20 +00:00
|
|
|
typedef Sys_Load_File_Sig(System_Load_File);
|
|
|
|
|
2016-08-26 17:52:35 +00:00
|
|
|
#define Sys_Load_Close_Sig(name) b32 name(Plat_Handle handle)
|
|
|
|
typedef Sys_Load_Close_Sig(System_Load_Close);
|
|
|
|
|
2017-03-23 19:15:33 +00:00
|
|
|
#define Sys_Save_File_Sig(name) b32 name(char *filename, char *buffer, u32 size)
|
2016-08-22 23:54:20 +00:00
|
|
|
typedef Sys_Save_File_Sig(System_Save_File);
|
2016-05-27 17:11:38 +00:00
|
|
|
|
2017-03-11 18:35:12 +00:00
|
|
|
// file changes
|
|
|
|
#define Sys_Add_Listener_Sig(name) b32 name(char *filename)
|
|
|
|
typedef Sys_Add_Listener_Sig(System_Add_Listener);
|
|
|
|
|
|
|
|
#define Sys_Remove_Listener_Sig(name) b32 name(char *filename)
|
|
|
|
typedef Sys_Remove_Listener_Sig(System_Remove_Listener);
|
|
|
|
|
2018-12-15 09:10:42 +00:00
|
|
|
#define Sys_Get_File_Change_Sig(name) b32 name(char *buffer, i32 max, b32 *mem_too_small, i32 *required_size)
|
2017-03-11 18:35:12 +00:00
|
|
|
typedef Sys_Get_File_Change_Sig(System_Get_File_Change);
|
|
|
|
|
|
|
|
// time
|
2016-08-26 17:52:35 +00:00
|
|
|
#define Sys_Now_Time_Sig(name) u64 name()
|
|
|
|
typedef Sys_Now_Time_Sig(System_Now_Time);
|
2016-08-24 23:01:33 +00:00
|
|
|
|
2017-03-11 18:35:12 +00:00
|
|
|
// clipboard
|
2016-02-07 21:15:58 +00:00
|
|
|
#define Sys_Post_Clipboard_Sig(name) void name(String str)
|
|
|
|
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
|
|
|
|
|
|
|
|
// cli
|
|
|
|
struct CLI_Handles{
|
|
|
|
Plat_Handle proc;
|
|
|
|
Plat_Handle out_read;
|
|
|
|
Plat_Handle out_write;
|
2017-11-28 19:11:44 +00:00
|
|
|
Plat_Handle in_read;
|
|
|
|
Plat_Handle in_write;
|
2016-02-07 21:15:58 +00:00
|
|
|
u32 scratch_space[4];
|
|
|
|
i32 exit;
|
|
|
|
};
|
|
|
|
|
2017-11-28 19:11:44 +00:00
|
|
|
#define Sys_CLI_Call_Sig(n, path, script, cli_out) b32 n(char *path, char *script, CLI_Handles *cli_out)
|
|
|
|
typedef Sys_CLI_Call_Sig(System_CLI_Call, path, script, cli_out);
|
2016-02-07 21:15:58 +00:00
|
|
|
|
|
|
|
#define Sys_CLI_Begin_Update_Sig(name) void name(CLI_Handles *cli)
|
|
|
|
typedef Sys_CLI_Begin_Update_Sig(System_CLI_Begin_Update);
|
|
|
|
|
|
|
|
#define Sys_CLI_Update_Step_Sig(name) b32 name(CLI_Handles *cli, char *dest, u32 max, u32 *amount)
|
|
|
|
typedef Sys_CLI_Update_Step_Sig(System_CLI_Update_Step);
|
|
|
|
|
|
|
|
#define Sys_CLI_End_Update_Sig(name) b32 name(CLI_Handles *cli)
|
|
|
|
typedef Sys_CLI_End_Update_Sig(System_CLI_End_Update);
|
|
|
|
|
2016-02-26 05:50:19 +00:00
|
|
|
// coroutine
|
|
|
|
|
2017-07-19 20:07:50 +00:00
|
|
|
struct Coroutine_Head{
|
2016-02-26 05:50:19 +00:00
|
|
|
void *in;
|
|
|
|
void *out;
|
|
|
|
};
|
|
|
|
|
2017-07-19 20:07:50 +00:00
|
|
|
#define COROUTINE_SIG(n) void n(Coroutine_Head *coroutine)
|
|
|
|
typedef COROUTINE_SIG(Coroutine_Function);
|
|
|
|
|
|
|
|
#define Sys_Create_Coroutine_Sig(name) Coroutine_Head *name(Coroutine_Function *func)
|
2016-02-27 07:44:17 +00:00
|
|
|
typedef Sys_Create_Coroutine_Sig(System_Create_Coroutine);
|
|
|
|
|
2017-07-19 20:07:50 +00:00
|
|
|
#define Sys_Launch_Coroutine_Sig(name) Coroutine_Head *name(Coroutine_Head *head, void *in, void *out)
|
2016-02-26 05:50:19 +00:00
|
|
|
typedef Sys_Launch_Coroutine_Sig(System_Launch_Coroutine);
|
|
|
|
|
2017-07-19 20:07:50 +00:00
|
|
|
#define Sys_Resume_Coroutine_Sig(name) Coroutine_Head *name(Coroutine_Head *head, void *in, void *out)
|
2016-02-26 05:50:19 +00:00
|
|
|
typedef Sys_Resume_Coroutine_Sig(System_Resume_Coroutine);
|
|
|
|
|
2017-07-19 20:07:50 +00:00
|
|
|
#define Sys_Yield_Coroutine_Sig(name) void name(Coroutine_Head *head)
|
2016-02-26 05:50:19 +00:00
|
|
|
typedef Sys_Yield_Coroutine_Sig(System_Yield_Coroutine);
|
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
// thread
|
|
|
|
struct Thread_Context;
|
|
|
|
|
|
|
|
enum Lock_ID{
|
|
|
|
FRAME_LOCK,
|
|
|
|
CANCEL_LOCK0,
|
|
|
|
CANCEL_LOCK1,
|
|
|
|
CANCEL_LOCK2,
|
|
|
|
CANCEL_LOCK3,
|
|
|
|
CANCEL_LOCK4,
|
|
|
|
CANCEL_LOCK5,
|
|
|
|
CANCEL_LOCK6,
|
|
|
|
CANCEL_LOCK7,
|
|
|
|
LOCK_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Thread_Group_ID{
|
|
|
|
BACKGROUND_THREADS,
|
|
|
|
THREAD_GROUP_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Thread_Memory{
|
|
|
|
void *data;
|
2017-05-27 20:04:13 +00:00
|
|
|
u32 size;
|
|
|
|
u32 id;
|
2016-02-07 21:15:58 +00:00
|
|
|
};
|
2018-11-20 08:18:54 +00:00
|
|
|
global Thread_Memory null_thread_memory = {};
|
2016-02-07 21:15:58 +00:00
|
|
|
|
|
|
|
struct Thread_Exchange;
|
|
|
|
struct System_Functions;
|
|
|
|
|
2016-05-31 16:27:40 +00:00
|
|
|
#define Job_Callback_Sig(name) void name( \
|
2017-01-03 20:05:35 +00:00
|
|
|
System_Functions *system, \
|
|
|
|
Thread_Context *thread, \
|
|
|
|
Thread_Memory *memory, \
|
2017-05-19 23:55:50 +00:00
|
|
|
void *data[4])
|
2019-01-29 05:36:17 +00:00
|
|
|
|
|
|
|
typedef void Job_Callback(System_Functions *system, Thread_Context *thread, Thread_Memory *memory, void *data[4]);
|
2016-02-07 21:15:58 +00:00
|
|
|
|
|
|
|
struct Job_Data{
|
|
|
|
Job_Callback *callback;
|
2017-05-19 23:55:50 +00:00
|
|
|
void *data[4];
|
2016-02-07 21:15:58 +00:00
|
|
|
};
|
|
|
|
|
2016-07-19 23:47:27 +00:00
|
|
|
#define QUEUE_WRAP 256
|
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
#define THREAD_NOT_ASSIGNED 0xFFFFFFFF
|
|
|
|
|
|
|
|
#define Sys_Post_Job_Sig(name) u32 name(Thread_Group_ID group_id, Job_Data job)
|
|
|
|
typedef Sys_Post_Job_Sig(System_Post_Job);
|
|
|
|
|
|
|
|
#define Sys_Cancel_Job_Sig(name) void name(Thread_Group_ID group_id, u32 job_id)
|
|
|
|
typedef Sys_Cancel_Job_Sig(System_Cancel_Job);
|
|
|
|
|
2016-05-31 18:32:58 +00:00
|
|
|
#define Sys_Check_Cancel_Sig(name) b32 name(Thread_Context *thread)
|
|
|
|
typedef Sys_Check_Cancel_Sig(System_Check_Cancel);
|
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
#define Sys_Grow_Thread_Memory_Sig(name) void name(Thread_Memory *memory)
|
|
|
|
typedef Sys_Grow_Thread_Memory_Sig(System_Grow_Thread_Memory);
|
|
|
|
|
|
|
|
#define Sys_Acquire_Lock_Sig(name) void name(i32 id)
|
|
|
|
typedef Sys_Acquire_Lock_Sig(System_Acquire_Lock);
|
|
|
|
|
|
|
|
#define Sys_Release_Lock_Sig(name) void name(i32 id)
|
|
|
|
typedef Sys_Release_Lock_Sig(System_Release_Lock);
|
|
|
|
|
2017-06-30 22:54:06 +00:00
|
|
|
// memory
|
2017-03-23 22:45:32 +00:00
|
|
|
#define Sys_Memory_Allocate_Sig(name) void* name(umem size)
|
2017-01-23 06:19:43 +00:00
|
|
|
typedef Sys_Memory_Allocate_Sig(System_Memory_Allocate);
|
|
|
|
|
2017-03-23 22:45:32 +00:00
|
|
|
#define Sys_Memory_Set_Protection_Sig(name) bool32 name(void *ptr, umem size, u32 flags)
|
2017-01-23 06:19:43 +00:00
|
|
|
typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection);
|
|
|
|
|
2017-03-23 22:45:32 +00:00
|
|
|
#define Sys_Memory_Free_Sig(name) void name(void *ptr, umem size)
|
2017-01-23 06:19:43 +00:00
|
|
|
typedef Sys_Memory_Free_Sig(System_Memory_Free);
|
|
|
|
|
2017-06-30 22:54:06 +00:00
|
|
|
// file system
|
2017-03-23 19:14:39 +00:00
|
|
|
#define Sys_File_Exists_Sig(name) b32 name(char *filename, i32 len)
|
2017-01-23 06:19:43 +00:00
|
|
|
typedef Sys_File_Exists_Sig(System_File_Exists);
|
|
|
|
|
|
|
|
#define Sys_Directory_CD_Sig(name) bool32 name(char *dir, i32 *len, i32 cap, char *rel_path, i32 rel_len)
|
|
|
|
typedef Sys_Directory_CD_Sig(System_Directory_CD);
|
|
|
|
|
2017-07-19 16:33:12 +00:00
|
|
|
#define Sys_Get_Current_Path_Sig(name) int32_t name(char *out, i32 capacity)
|
|
|
|
typedef Sys_Get_Current_Path_Sig(System_Get_Current_Path);
|
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
#define Sys_Get_4ed_Path_Sig(name) int32_t name(char *out, i32 capacity)
|
|
|
|
typedef Sys_Get_4ed_Path_Sig(System_Get_4ed_Path);
|
|
|
|
|
2017-06-30 22:54:06 +00:00
|
|
|
// behavior and appearance options
|
2017-01-23 06:19:43 +00:00
|
|
|
#define Sys_Show_Mouse_Cursor_Sig(name) void name(i32 show)
|
|
|
|
typedef Sys_Show_Mouse_Cursor_Sig(System_Show_Mouse_Cursor);
|
|
|
|
|
2017-07-18 22:09:16 +00:00
|
|
|
#define Sys_Set_Fullscreen_Sig(name) b32 name(b32 full_screen)
|
|
|
|
typedef Sys_Set_Fullscreen_Sig(System_Set_Fullscreen);
|
2017-01-23 06:19:43 +00:00
|
|
|
|
|
|
|
#define Sys_Is_Fullscreen_Sig(name) bool32 name()
|
|
|
|
typedef Sys_Is_Fullscreen_Sig(System_Is_Fullscreen);
|
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
// debug
|
2017-06-12 17:40:54 +00:00
|
|
|
#define Sys_Log_Sig(name) void name(char *message, u32 length)
|
|
|
|
typedef Sys_Log_Sig(System_Log);
|
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
#define INTERNAL_Sys_Get_Thread_States_Sig(name) void name(Thread_Group_ID id, b8 *running, i32 *pending)
|
|
|
|
typedef INTERNAL_Sys_Get_Thread_States_Sig(INTERNAL_System_Get_Thread_States);
|
|
|
|
|
|
|
|
struct System_Functions{
|
2017-03-12 01:20:24 +00:00
|
|
|
Font_Functions font;
|
|
|
|
|
2016-08-26 21:30:08 +00:00
|
|
|
// files (tracked api): 10
|
2017-07-19 16:33:12 +00:00
|
|
|
System_Set_File_List *set_file_list;
|
|
|
|
System_Get_Canonical *get_canonical;
|
|
|
|
System_Add_Listener *add_listener;
|
2016-08-26 17:52:35 +00:00
|
|
|
System_Remove_Listener *remove_listener;
|
2016-08-26 21:30:08 +00:00
|
|
|
System_Get_File_Change *get_file_change;
|
2017-07-19 16:33:12 +00:00
|
|
|
System_Load_Handle *load_handle;
|
|
|
|
System_Load_Size *load_size;
|
|
|
|
System_Load_File *load_file;
|
|
|
|
System_Load_Close *load_close;
|
|
|
|
System_Save_File *save_file;
|
2016-08-26 17:52:35 +00:00
|
|
|
|
|
|
|
// time: 1
|
|
|
|
System_Now_Time *now_time;
|
2016-05-29 03:12:12 +00:00
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
// clipboard: 1
|
|
|
|
System_Post_Clipboard *post_clipboard;
|
2016-05-29 03:12:12 +00:00
|
|
|
|
2016-02-26 05:50:19 +00:00
|
|
|
// coroutine: 4
|
2016-02-27 07:44:17 +00:00
|
|
|
System_Create_Coroutine *create_coroutine;
|
2016-02-26 05:50:19 +00:00
|
|
|
System_Launch_Coroutine *launch_coroutine;
|
|
|
|
System_Resume_Coroutine *resume_coroutine;
|
2017-07-19 16:33:12 +00:00
|
|
|
System_Yield_Coroutine *yield_coroutine;
|
2016-02-26 05:50:19 +00:00
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
// cli: 4
|
2017-07-19 16:33:12 +00:00
|
|
|
System_CLI_Call *cli_call;
|
2016-02-07 21:15:58 +00:00
|
|
|
System_CLI_Begin_Update *cli_begin_update;
|
2017-07-19 16:33:12 +00:00
|
|
|
System_CLI_Update_Step *cli_update_step;
|
|
|
|
System_CLI_End_Update *cli_end_update;
|
2016-05-29 03:12:12 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
// threads: 6
|
2017-07-19 16:33:12 +00:00
|
|
|
System_Post_Job *post_job;
|
|
|
|
System_Cancel_Job *cancel_job;
|
|
|
|
System_Check_Cancel *check_cancel;
|
2016-02-07 21:15:58 +00:00
|
|
|
System_Grow_Thread_Memory *grow_thread_memory;
|
2017-07-19 16:33:12 +00:00
|
|
|
System_Acquire_Lock *acquire_lock;
|
|
|
|
System_Release_Lock *release_lock;
|
2016-05-29 03:12:12 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
// custom: 10
|
|
|
|
System_Memory_Allocate *memory_allocate;
|
|
|
|
System_Memory_Set_Protection *memory_set_protection;
|
|
|
|
System_Memory_Free *memory_free;
|
2017-11-30 15:44:08 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
System_File_Exists *file_exists;
|
|
|
|
System_Directory_CD *directory_cd;
|
2017-07-19 16:33:12 +00:00
|
|
|
System_Get_Current_Path *get_current_path;
|
2017-01-23 06:19:43 +00:00
|
|
|
System_Get_4ed_Path *get_4ed_path;
|
2017-11-30 15:44:08 +00:00
|
|
|
|
2017-01-23 06:19:43 +00:00
|
|
|
System_Show_Mouse_Cursor *show_mouse_cursor;
|
2017-07-18 22:09:16 +00:00
|
|
|
System_Set_Fullscreen *set_fullscreen;
|
2017-01-23 06:19:43 +00:00
|
|
|
System_Is_Fullscreen *is_fullscreen;
|
|
|
|
|
2016-12-18 20:42:11 +00:00
|
|
|
// debug: 1
|
2017-06-12 17:40:54 +00:00
|
|
|
System_Log *log;
|
2016-02-07 21:15:58 +00:00
|
|
|
INTERNAL_System_Get_Thread_States *internal_get_thread_states;
|
|
|
|
};
|
|
|
|
|
2017-03-12 01:20:24 +00:00
|
|
|
#endif
|
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
// BOTTOM
|
|
|
|
|