2016-02-07 21:15:58 +00:00
|
|
|
/*
|
|
|
|
* Mr. 4th Dimention - Allen Webster
|
|
|
|
*
|
|
|
|
* 21.01.2014
|
|
|
|
*
|
|
|
|
* System functions for project codename "4ed"
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// TOP
|
|
|
|
|
|
|
|
struct Plat_Handle{
|
|
|
|
u32 d[4];
|
|
|
|
};
|
|
|
|
|
2016-03-20 22:43:28 +00:00
|
|
|
inline int
|
|
|
|
handle_equal(Plat_Handle a, Plat_Handle b){
|
|
|
|
int result = (memcmp(&a, &b, sizeof(a)) == 0);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2016-03-03 04:18:13 +00:00
|
|
|
struct Unique_Hash{
|
|
|
|
u32 d[4];
|
|
|
|
};
|
|
|
|
|
2016-03-11 03:33:19 +00:00
|
|
|
inline Unique_Hash
|
|
|
|
uhash_zero(){
|
|
|
|
Unique_Hash r = {0};
|
|
|
|
return(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
|
|
|
uhash_equal(Unique_Hash a, Unique_Hash b){
|
|
|
|
int result = (memcmp(&a, &b, sizeof(a)) == 0);
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
// TODO(allen): make directory a char* to signal that it must be null terminated
|
|
|
|
#define Sys_Set_File_List_Sig(name) void name(File_List *file_list, String directory)
|
|
|
|
typedef Sys_Set_File_List_Sig(System_Set_File_List);
|
|
|
|
|
2016-08-22 23:54:20 +00:00
|
|
|
enum{
|
|
|
|
TrackFileFlag_ExistingOrFail = 0x0,
|
|
|
|
TrackFileFlag_NewOrFail = 0x1,
|
|
|
|
TrackFileFlag_NewAlways = 0x2,
|
|
|
|
TrackFileFlag_ExistingOrNew = 0x3,
|
|
|
|
};
|
2016-02-24 16:52:18 +00:00
|
|
|
|
2016-08-22 23:54:20 +00:00
|
|
|
#define Sys_Track_File_Sig(name) Unique_Hash name(char *filename, u32 flags)
|
|
|
|
typedef Sys_Track_File_Sig(System_Track_File);
|
2016-05-03 16:15:08 +00:00
|
|
|
|
2016-08-22 23:54:20 +00:00
|
|
|
#define Sys_Untrack_File_Sig(name) i32 name(Unique_Hash index)
|
|
|
|
typedef Sys_Untrack_File_Sig(System_Untrack_File);
|
2016-05-03 16:15:08 +00:00
|
|
|
|
2016-08-22 23:54:20 +00:00
|
|
|
#define Sys_Get_File_Index_Sig(name) i32 name(char *filename, Unique_Hash *index)
|
|
|
|
typedef Sys_Get_File_Index_Sig(System_Get_File_Index);
|
2016-05-27 17:11:38 +00:00
|
|
|
|
2016-08-22 23:54:20 +00:00
|
|
|
#define Sys_Get_File_Time_Sig(name) i32 name(Unique_Hash index, u64 *time)
|
|
|
|
typedef Sys_Get_File_Time_Sig(System_Get_File_Time);
|
2016-05-27 17:11:38 +00:00
|
|
|
|
2016-08-22 23:54:20 +00:00
|
|
|
#define Sys_Now_File_Time_Sig(name) void name(u64 *time)
|
|
|
|
typedef Sys_Now_File_Time_Sig(System_Now_File_Time);
|
|
|
|
|
|
|
|
#define Sys_Get_Changed_File_Sig(name) i32 name(Unique_Hash *index)
|
|
|
|
typedef Sys_Get_Changed_File_Sig(System_Get_Changed_File);
|
|
|
|
|
|
|
|
#define Sys_File_Size_Sig(name) u32 name(Unique_Hash index)
|
|
|
|
typedef Sys_File_Size_Sig(System_File_Size);
|
|
|
|
|
|
|
|
#define Sys_Load_File_Sig(name) i32 name(Unique_Hash index, char *buffer, i32 size)
|
|
|
|
typedef Sys_Load_File_Sig(System_Load_File);
|
|
|
|
|
|
|
|
#define Sys_Save_File_Sig(name) i32 name(Unique_Hash index, char *buffer, i32 size)
|
|
|
|
typedef Sys_Save_File_Sig(System_Save_File);
|
2016-05-27 17:11:38 +00:00
|
|
|
|
2016-08-24 23:01:33 +00:00
|
|
|
#define Sys_Save_File_By_Name_Sig(name) i32 name(char *filename, char *buffer, i32 size)
|
|
|
|
typedef Sys_Save_File_By_Name_Sig(System_Save_File_By_Name);
|
|
|
|
|
2016-05-27 17:11:38 +00:00
|
|
|
|
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;
|
|
|
|
u32 scratch_space[4];
|
|
|
|
i32 exit;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define Sys_CLI_Call_Sig(name) b32 name(char *path, char *script_name, CLI_Handles *cli_out)
|
|
|
|
typedef Sys_CLI_Call_Sig(System_CLI_Call);
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
#define Coroutine_Function_Sig(name) void name(struct Coroutine *coroutine)
|
|
|
|
typedef Coroutine_Function_Sig(Coroutine_Function);
|
|
|
|
|
|
|
|
struct Coroutine{
|
|
|
|
Plat_Handle plat_handle;
|
|
|
|
Coroutine_Function *func;
|
|
|
|
void *yield_handle;
|
|
|
|
void *in;
|
|
|
|
void *out;
|
|
|
|
};
|
|
|
|
|
2016-02-27 07:44:17 +00:00
|
|
|
#define Sys_Create_Coroutine_Sig(name) Coroutine *name(Coroutine_Function *func)
|
|
|
|
typedef Sys_Create_Coroutine_Sig(System_Create_Coroutine);
|
|
|
|
|
|
|
|
#define Sys_Launch_Coroutine_Sig(name) Coroutine *name(Coroutine *coroutine, void *in, void *out)
|
2016-02-26 05:50:19 +00:00
|
|
|
typedef Sys_Launch_Coroutine_Sig(System_Launch_Coroutine);
|
|
|
|
|
2016-02-26 17:40:51 +00:00
|
|
|
#define Sys_Resume_Coroutine_Sig(name) Coroutine *name(Coroutine *coroutine, void *in, void *out)
|
2016-02-26 05:50:19 +00:00
|
|
|
typedef Sys_Resume_Coroutine_Sig(System_Resume_Coroutine);
|
|
|
|
|
2016-02-26 17:40:51 +00:00
|
|
|
#define Sys_Yield_Coroutine_Sig(name) void name(Coroutine *coroutine)
|
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;
|
|
|
|
i32 size;
|
|
|
|
i32 id;
|
|
|
|
};
|
2016-05-12 17:41:52 +00:00
|
|
|
inline Thread_Memory
|
|
|
|
thread_memory_zero(){
|
|
|
|
Thread_Memory memory={0};
|
|
|
|
return(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( \
|
|
|
|
System_Functions *system, \
|
|
|
|
Thread_Context *thread, \
|
|
|
|
Thread_Memory *memory, \
|
|
|
|
void *data[2])
|
2016-02-07 21:15:58 +00:00
|
|
|
typedef Job_Callback_Sig(Job_Callback);
|
|
|
|
|
|
|
|
struct Job_Data{
|
|
|
|
Job_Callback *callback;
|
|
|
|
void *data[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Full_Job_Data{
|
|
|
|
Job_Data job;
|
|
|
|
|
|
|
|
u32 running_thread;
|
|
|
|
u32 id;
|
|
|
|
};
|
|
|
|
|
2016-07-19 23:47:27 +00:00
|
|
|
struct Unbounded_Work_Queue{
|
|
|
|
Full_Job_Data *jobs;
|
|
|
|
i32 count, max, skip;
|
|
|
|
|
|
|
|
u32 next_job_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define QUEUE_WRAP 256
|
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
struct Work_Queue{
|
2016-07-19 23:47:27 +00:00
|
|
|
Full_Job_Data jobs[QUEUE_WRAP];
|
2016-02-07 21:15:58 +00:00
|
|
|
Plat_Handle semaphore;
|
|
|
|
volatile u32 write_position;
|
|
|
|
volatile u32 read_position;
|
|
|
|
};
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
|
|
|
// debug
|
|
|
|
#define INTERNAL_Sys_Sentinel_Sig(name) Bubble* name()
|
|
|
|
typedef INTERNAL_Sys_Sentinel_Sig(INTERNAL_System_Sentinel);
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
|
|
|
#define INTERNAL_Sys_Debug_Message_Sig(name) void name(char *message)
|
|
|
|
typedef INTERNAL_Sys_Debug_Message_Sig(INTERNAL_System_Debug_Message);
|
|
|
|
|
|
|
|
struct System_Functions{
|
2016-08-22 23:54:20 +00:00
|
|
|
|
2016-08-24 23:01:33 +00:00
|
|
|
// files (tracked api): 11
|
2016-02-07 21:15:58 +00:00
|
|
|
System_Set_File_List *set_file_list;
|
2016-08-22 23:54:20 +00:00
|
|
|
System_Track_File *track_file;
|
|
|
|
System_Untrack_File *untrack_file;
|
|
|
|
System_Get_File_Index *get_file_index;
|
|
|
|
System_Get_File_Time *get_file_time;
|
|
|
|
System_Now_File_Time *now_file_time;
|
|
|
|
System_Get_Changed_File *get_changed_file;
|
|
|
|
System_File_Size *file_size;
|
|
|
|
System_Load_File *load_file;
|
|
|
|
System_Save_File *save_file;
|
2016-08-24 23:01:33 +00:00
|
|
|
System_Save_File_By_Name *save_file_by_name;
|
2016-05-29 03:12:12 +00:00
|
|
|
|
2016-07-11 16:15:37 +00:00
|
|
|
// 4coder_custom.h: 7
|
|
|
|
Memory_Allocate_Function *memory_allocate;
|
|
|
|
Memory_Set_Protection_Function *memory_set_protection;
|
|
|
|
Memory_Free_Function *memory_free;
|
2016-02-28 20:30:51 +00:00
|
|
|
File_Exists_Function *file_exists;
|
|
|
|
Directory_CD_Function *directory_cd;
|
2016-05-17 02:22:57 +00:00
|
|
|
Get_4ed_Path_Function *get_4ed_path;
|
2016-06-29 19:11:37 +00:00
|
|
|
Show_Mouse_Cursor_Function *show_mouse_cursor;
|
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;
|
|
|
|
System_Yield_Coroutine *yield_coroutine;
|
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
// cli: 4
|
|
|
|
System_CLI_Call *cli_call;
|
|
|
|
System_CLI_Begin_Update *cli_begin_update;
|
|
|
|
System_CLI_Update_Step *cli_update_step;
|
|
|
|
System_CLI_End_Update *cli_end_update;
|
2016-05-29 03:12:12 +00:00
|
|
|
|
2016-05-31 18:32:58 +00:00
|
|
|
// threads: 7
|
2016-02-07 21:15:58 +00:00
|
|
|
System_Post_Job *post_job;
|
|
|
|
System_Cancel_Job *cancel_job;
|
2016-05-31 18:32:58 +00:00
|
|
|
System_Check_Cancel *check_cancel;
|
2016-02-07 21:15:58 +00:00
|
|
|
System_Grow_Thread_Memory *grow_thread_memory;
|
|
|
|
System_Acquire_Lock *acquire_lock;
|
|
|
|
System_Release_Lock *release_lock;
|
2016-05-29 03:12:12 +00:00
|
|
|
|
2016-02-07 21:15:58 +00:00
|
|
|
// debug: 3
|
|
|
|
INTERNAL_System_Sentinel *internal_sentinel;
|
|
|
|
INTERNAL_System_Get_Thread_States *internal_get_thread_states;
|
|
|
|
INTERNAL_System_Debug_Message *internal_debug_message;
|
2016-02-23 03:14:23 +00:00
|
|
|
|
|
|
|
// non-function details
|
|
|
|
char slash;
|
2016-02-07 21:15:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// BOTTOM
|
|
|
|
|