4coder/4ed_system.h

192 lines
4.9 KiB
C
Raw Normal View History

2015-09-28 23:34:55 +00:00
/*
* Mr. 4th Dimention - Allen Webster
*
* 21.01.2014
*
* System functions for project codename "4ed"
*
*/
2015-11-14 04:42:06 +00:00
// TOP
struct Plat_Handle{
u32 d[4];
};
2015-11-02 01:04:37 +00:00
2015-09-28 23:34:55 +00:00
struct File_Info{
String filename;
2015-11-14 04:42:06 +00:00
b32 folder;
2015-09-28 23:34:55 +00:00
};
struct File_List{
void *block;
2016-01-06 15:39:15 +00:00
File_Info *infos;
i32 count, block_size;
2015-09-28 23:34:55 +00:00
};
2016-01-06 15:39:15 +00:00
#define Sys_File_Time_Stamp_Sig(name) u64 name(char *filename)
typedef Sys_File_Time_Stamp_Sig(System_File_Time_Stamp);
2015-09-28 23:34:55 +00:00
// TODO(allen): make directory a char* to signal that it must be null terminated
2016-01-06 15:39:15 +00:00
#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);
2015-09-28 23:34:55 +00:00
2015-11-16 16:15:45 +00:00
#define Sys_Post_Clipboard_Sig(name) void name(String str)
2015-11-14 04:42:06 +00:00
typedef Sys_Post_Clipboard_Sig(System_Post_Clipboard);
2015-09-28 23:34:55 +00:00
2016-01-06 15:39:15 +00:00
#define Sys_Time_Sig(name) u64 name()
2015-11-14 04:42:06 +00:00
typedef Sys_Time_Sig(System_Time);
2015-09-28 23:34:55 +00:00
2016-01-06 15:39:15 +00:00
// cli
2015-11-02 01:04:37 +00:00
struct CLI_Handles{
Plat_Handle proc;
Plat_Handle out_read;
Plat_Handle out_write;
u32 scratch_space[4];
2016-01-21 17:48:09 +00:00
i32 exit;
2015-11-02 01:04:37 +00:00
};
2016-01-06 15:39:15 +00:00
#define Sys_CLI_Call_Sig(name) b32 name(char *path, char *script_name, CLI_Handles *cli_out)
2015-11-14 04:42:06 +00:00
typedef Sys_CLI_Call_Sig(System_CLI_Call);
2015-11-02 01:04:37 +00:00
2015-11-14 04:42:06 +00:00
#define Sys_CLI_Begin_Update_Sig(name) void name(CLI_Handles *cli)
typedef Sys_CLI_Begin_Update_Sig(System_CLI_Begin_Update);
2015-11-02 01:04:37 +00:00
2015-11-14 04:42:06 +00:00
#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);
2015-11-02 01:04:37 +00:00
2015-11-14 04:42:06 +00:00
#define Sys_CLI_End_Update_Sig(name) b32 name(CLI_Handles *cli)
typedef Sys_CLI_End_Update_Sig(System_CLI_End_Update);
2015-11-02 01:04:37 +00:00
2016-01-06 15:39:15 +00:00
// thread
2015-09-28 23:34:55 +00:00
struct Thread_Context;
2015-11-14 04:42:06 +00:00
enum Lock_ID{
FRAME_LOCK,
2016-01-17 01:34:48 +00:00
INPUT_LOCK,
FONT_LOCK,
RENDER_LOCK,
2015-11-14 04:42:06 +00:00
CANCEL_LOCK0,
CANCEL_LOCK1,
CANCEL_LOCK2,
CANCEL_LOCK3,
CANCEL_LOCK4,
CANCEL_LOCK5,
CANCEL_LOCK6,
CANCEL_LOCK7,
LOCK_COUNT
2015-09-28 23:34:55 +00:00
};
enum Thread_Group_ID{
BACKGROUND_THREADS,
THREAD_GROUP_COUNT
};
2015-11-14 04:42:06 +00:00
struct Thread_Memory{
void *data;
i32 size;
i32 id;
};
2016-01-06 15:39:15 +00:00
struct Thread_Exchange;
struct System_Functions;
#define Job_Callback_Sig(name) void name( \
System_Functions *system, Thread_Context *thread, Thread_Memory *memory, \
Thread_Exchange *exchange, void *data[2])
2015-12-01 02:51:53 +00:00
typedef Job_Callback_Sig(Job_Callback);
2015-09-28 23:34:55 +00:00
struct Job_Data{
Job_Callback *callback;
void *data[2];
i32 memory_request;
};
2016-01-06 15:39:15 +00:00
struct Full_Job_Data{
Job_Data job;
u32 job_memory_index;
u32 running_thread;
b32 finished;
u32 id;
};
struct Work_Queue{
Full_Job_Data jobs[256];
Plat_Handle semaphore;
volatile u32 write_position;
volatile u32 read_position;
};
#define THREAD_NOT_ASSIGNED 0xFFFFFFFF
#define JOB_ID_WRAP (ArrayCount(queue->jobs) * 4)
#define QUEUE_WRAP (ArrayCount(queue->jobs))
2015-09-28 23:34:55 +00:00
2016-01-06 15:39:15 +00:00
struct Thread_Exchange{
Work_Queue queues[THREAD_GROUP_COUNT];
volatile u32 force_redraw;
};
2015-09-28 23:34:55 +00:00
2016-01-06 15:39:15 +00:00
#define Sys_Post_Job_Sig(name) u32 name(Thread_Group_ID group_id, Job_Data job)
2015-11-14 04:42:06 +00:00
typedef Sys_Post_Job_Sig(System_Post_Job);
2015-09-28 23:34:55 +00:00
2016-01-06 15:39:15 +00:00
#define Sys_Cancel_Job_Sig(name) void name(Thread_Group_ID group_id, u32 job_id)
2015-11-14 04:42:06 +00:00
typedef Sys_Cancel_Job_Sig(System_Cancel_Job);
#define Sys_Grow_Thread_Memory_Sig(name) void name(Thread_Memory *memory)
typedef Sys_Grow_Thread_Memory_Sig(System_Grow_Thread_Memory);
2015-09-28 23:34:55 +00:00
2015-11-14 04:42:06 +00:00
#define Sys_Acquire_Lock_Sig(name) void name(i32 id)
typedef Sys_Acquire_Lock_Sig(System_Acquire_Lock);
2015-09-28 23:34:55 +00:00
2015-11-14 04:42:06 +00:00
#define Sys_Release_Lock_Sig(name) void name(i32 id)
typedef Sys_Release_Lock_Sig(System_Release_Lock);
2015-09-28 23:34:55 +00:00
2016-01-06 15:39:15 +00:00
// debug
2015-11-14 04:42:06 +00:00
#define INTERNAL_Sys_Sentinel_Sig(name) Bubble* name()
typedef INTERNAL_Sys_Sentinel_Sig(INTERNAL_System_Sentinel);
2015-09-28 23:34:55 +00:00
2015-11-14 04:42:06 +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);
2015-09-28 23:34:55 +00:00
2015-12-01 02:51:53 +00:00
#define INTERNAL_Sys_Debug_Message_Sig(name) void name(char *message)
typedef INTERNAL_Sys_Debug_Message_Sig(INTERNAL_System_Debug_Message);
2015-11-14 04:42:06 +00:00
struct System_Functions{
2016-01-06 15:39:15 +00:00
// files: 2
2015-11-14 04:42:06 +00:00
System_File_Time_Stamp *file_time_stamp;
2016-01-06 15:39:15 +00:00
System_Set_File_List *set_file_list;
2015-11-14 04:42:06 +00:00
2016-01-06 15:39:15 +00:00
// file system navigation (4coder_custom.h): 2
Directory_Has_File *directory_has_file;
Directory_CD *directory_cd;
2015-11-14 04:42:06 +00:00
2016-01-06 15:39:15 +00:00
// clipboard: 1
2015-11-14 04:42:06 +00:00
System_Post_Clipboard *post_clipboard;
2016-01-06 15:39:15 +00:00
// time: 1
2015-11-14 04:42:06 +00:00
System_Time *time;
2016-01-06 15:39:15 +00:00
// cli: 4
2015-11-14 04:42:06 +00:00
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-01-06 15:39:15 +00:00
// threads: 5
2015-11-14 04:42:06 +00:00
System_Post_Job *post_job;
System_Cancel_Job *cancel_job;
System_Grow_Thread_Memory *grow_thread_memory;
System_Acquire_Lock *acquire_lock;
System_Release_Lock *release_lock;
2016-01-06 15:39:15 +00:00
// debug: 3
2015-11-14 04:42:06 +00:00
INTERNAL_System_Sentinel *internal_sentinel;
INTERNAL_System_Get_Thread_States *internal_get_thread_states;
2015-12-01 02:51:53 +00:00
INTERNAL_System_Debug_Message *internal_debug_message;
2015-11-14 04:42:06 +00:00
};
2015-09-28 23:34:55 +00:00
2015-11-14 04:42:06 +00:00
// BOTTOM
2015-09-28 23:34:55 +00:00