aboutsummaryrefslogtreecommitdiff
path: root/src/cynic.h
blob: 66659ff357c073cefa4ffb1d0fd050c70e1f71b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#if !defined(CYNIC_H)
#   define CYNIC_H
/*
    Cynic - platform layer for games and programs.

    LICENSE:

    Copyright (C) 2025 Bogdan Masyutin (bonmas14)

    This software is provided 'as-is', without any express or implied
    warranty.  In no event will the authors be held liable for any damages
    arising from the use of this software.

    Permission is granted to anyone to use this software for any purpose,
    including commercial applications, and to alter it and redistribute it
    freely, subject to the following restrictions:

      1. The origin of this software must not be misrepresented; you must not
         claim that you wrote the original software. If you use this software
         in a product, an acknowledgment in the product documentation would be
         appreciated but is not required.
      2. Altered source versions must be plainly marked as such, and must not be
         misrepresented as being the original software.
      3. This notice may not be removed or altered from any source distribution.

    Bogdan Masyutin - bonmas14@gmail.com
*/

#include <ungrateful.h>

#define CYN_FS_MAX_FILE_SIZE (256)

#if defined(__cplusplus)
extern "C" {
#endif

extern void cyn_init(void);

/* ---- Library loading API ---- */
/* ------- Threading API ------- */
/* -------- Logging API -------- */

typedef enum {
    CYN_LOG_TRACE,
    CYN_LOG_DEBUG,
    CYN_LOG_INFO,
    CYN_LOG_WARNING,
    CYN_LOG_ERROR,
    CYN_LOG_FATAL,
    CYN_LOG_RAW
} Log_Level;

extern Log_Level cyn_current_log_level;

extern void cyn_log_write(Log_Level level, String format, ...);
extern void cyn_log_write_cstring(Log_Level level, u8 *format, ...);

/* --------- Timer API --------- */
/* ------ Filesystem API ------- */

typedef enum {
    CYN_FS_ATRIB_NONE = 0,
} FS_Attributes;

typedef struct {
    u64 size;
    u8 data[1];
} FS_File;

typedef struct {
    u64 attributes;
    u64 file_size;

    struct {
        u32 size;
        u8  data[CYN_FS_MAX_FILE_SIZE];
    } name;

    u8 data[1];
} FS_File_Header;

typedef struct {
    u8 signature[4];
    u16 reserved_a;
    u16 reserved_b;

    u64 attributes;
    u64 file_count;

    u8 content[1];
} FS_Header;

/* --------- File API ---------- */

typedef enum {
    CYN_FILE_OK,
    CYN_FILE_ERROR_MAX_PATH,
    CYN_FILE_ERROR_NULL_FILENAME,
    CYN_FILE_ERROR,
} File_Status;

typedef enum {
    CYN_FILE_CREATE        = 1 << 2,

    CYN_FILE_ACCESS_READ   = 1 << 3,
    CYN_FILE_ACCESS_WRITE  = 1 << 4,

    CYN_FILE_SHARE_DELETE  = 1 << 5,
    CYN_FILE_SHARE_READ    = 1 << 6,
    CYN_FILE_SHARE_WRITE   = 1 << 7,

    CYN_FILE_OPEN_NEW      = 1 << 8,
    CYN_FILE_OPEN_EXISTING = 1 << 9,
} File_Open_Flags;

// extern File_Handle *cyn_file_open(String path, File_Open_Flags flags, File_Status *status);
extern struct File_Handle *cyn_file_open(String path, File_Status *status);
/* path   - could be partial or full, should be always with '/'
 * status - is optional,
 * returns NULL on error and writes error into a `status`.
 * */
extern void         cyn_file_close(struct File_Handle *handle);

/* --------- Config API -------- */

/* --------- Library load --------- */

struct CInterface;


extern struct CInterface* cyn_lib_interface_create(void);
extern void               cyn_lib_interface_destroy(struct CInterface *interface);
extern void               cyn_lib_interface_register(struct CInterface *interface, void *fp, String name);




#if defined(__cplusplus)
}
#endif

#endif // CYNIC_H