-
Notifications
You must be signed in to change notification settings - Fork 2
/
ass.h
481 lines (438 loc) · 17.1 KB
/
ass.h
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
#define array_size(x) ((sizeof(x) / sizeof(*x)) / !(sizeof(x) % sizeof(*x)))
//For Visual Studio's sake
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed long int32_t;
typedef signed long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long uint64_t;
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
#define printf interface->textLibrary->Write
#define vbl interface->miscLibrary->WaitForVBlank
#define malloc interface->miscLibrary->HeapAlloc
#define free interface->miscLibrary->HeapFree
#define realloc interface->miscLibrary->HeapReAlloc
#define calloc interface->miscLibrary->HeapCAlloc
#define strftime interface->miscLibrary->FormatTime
#define gmtime interface->miscLibrary->TimeToCalendar
#define mktime interface->miscLibrary->CalendarToTime
//-----------------
//ASSPULL REGISTERS
//-----------------
#define MEM_VRAM 0x0E000000
#define MEM_DEVS 0x02000000
#define MEM_IO 0x0D000000
#define TEXTMAP ((uint16_t*)(MEM_VRAM))
#define BITMAP ((uint8_t*)(MEM_VRAM))
#define MAP1 ((uint16_t*)(MEM_VRAM))
#define MAP2 ((uint16_t*)(MEM_VRAM + 0x4000))
#define MAP3 ((uint16_t*)(MEM_VRAM + 0x8000))
#define MAP4 ((uint16_t*)(MEM_VRAM + 0xC000))
#define TILESET ((uint8_t*)(MEM_VRAM + 0x50000))
#define PALETTE ((uint16_t*)(MEM_VRAM + 0x60000))
#define TEXTFONT ((uint8_t*)(MEM_VRAM + 0x60400))
#define OBJECTS_A ((uint16_t*)(MEM_VRAM + 0x64000))
#define OBJECTS_B ((uint32_t*)(MEM_VRAM + 0x64200))
#define REG_INTRMODE *(int8_t*)(MEM_IO + 0x0000)
#define REG_SCREENMODE *(int8_t*)(MEM_IO + 0x0001)
#define REG_LINE *(volatile uint16_t*)(MEM_IO + 0x0002)
#define REG_TICKCOUNT *(volatile uint32_t*)(MEM_IO + 0x0004)
#define REG_SCREENFADE *(int8_t*)(MEM_IO + 0x0008)
#define REG_MAPSET *(uint8_t*)(MEM_IO + 0x0009)
#define REG_MAPBLEND *(uint8_t*)(MEM_IO + 0x000A)
#define REG_MAPSHIFT *(uint8_t*)(MEM_IO + 0x000B)
#define REG_SCROLLX1 *(uint16_t*)(MEM_IO + 0x0010)
#define REG_SCROLLY1 *(uint16_t*)(MEM_IO + 0x0012)
#define REG_SCROLLX2 *(uint16_t*)(MEM_IO + 0x0014)
#define REG_SCROLLY2 *(uint16_t*)(MEM_IO + 0x0016)
#define REG_SCROLLX3 *(uint16_t*)(MEM_IO + 0x0018)
#define REG_SCROLLY3 *(uint16_t*)(MEM_IO + 0x001A)
#define REG_SCROLLX4 *(uint16_t*)(MEM_IO + 0x001C)
#define REG_SCROLLY4 *(uint16_t*)(MEM_IO + 0x001E)
#define REG_WINMASK *(uint16_t*)(MEM_IO + 0x0020)
#define REG_WINLEFT *(uint16_t*)(MEM_IO + 0x0022)
#define REG_WINRIGHT *(uint16_t*)(MEM_IO + 0x0024)
#define REG_CARET *(uint16_t*)(MEM_IO + 0x0054)
#define REG_TIMET *(volatile int32_t*)(MEM_IO + 0x0060)
#define REG_DMASOURCE *(volatile uint32_t*)(MEM_IO + 0x0100)
#define REG_DMATARGET *(volatile uint32_t*)(MEM_IO + 0x0104)
#define REG_DMALENGTH *(volatile uint32_t*)(MEM_IO + 0x0108)
#define REG_DMACONTROL *(volatile uint8_t*)(MEM_IO + 0x010A)
#define REG_HDMACONTROL ((uint32_t*)(MEM_IO + 0x0180))
#define REG_HDMASOURCE ((uint32_t*)(MEM_IO + 0x01A0))
#define REG_HDMATARGET ((uint32_t*)(MEM_IO + 0x01C0))
#define REG_BLITCONTROL *(uint32_t*)(MEM_IO + 0x0200)
#define REG_BLITSOURCE *(uint32_t*)(MEM_IO + 0x0204)
#define REG_BLITTARGET *(uint32_t*)(MEM_IO + 0x0208)
#define REG_BLITLENGTH *(uint32_t*)(MEM_IO + 0x020C)
#define REG_BLITKEY *(uint32_t*)(MEM_IO + 0x0210)
#define INP_KEYIN *(volatile uint8_t*)(MEM_DEVS + 0x0002)
#define INP_KEYSHIFT *(volatile uint8_t*)(MEM_DEVS + 0x0003)
#define INP_JOYSTATES *(uint8_t*)(MEM_DEVS + 0x0010)
#define INP_JOYPAD1 *(volatile uint16_t*)(MEM_DEVS + 0x0012)
#define INP_JOYSTK1H *(volatile int8_t*)(MEM_DEVS + 0x0014)
#define INP_JOYSTK1V *(volatile int8_t*)(MEM_DEVS + 0x0015)
#define INP_JOYPAD2 *(volatile uint16_t*)(MEM_DEVS + 0x0016)
#define INP_JOYSTK2H *(volatile int8_t*)(MEM_DEVS + 0x0017)
#define INP_JOYSTK2V *(volatile int8_t*)(MEM_DEVS + 0x0018)
#define INP_MOUSE *(uint16_t*)(MEM_DEVS + 0x0020)
#define INP_KEYMAP ((volatile uint8_t*)(MEM_DEVS + 0x0040))
#define REG_MIDIOUT *(volatile uint8_t*)(MEM_DEVS + 0x0004)
#define REG_OPLOUT *(volatile int16_t*)(MEM_DEVS + 0x0005)
#define REG_PCM1OFFSET *(int32_t*)(MEM_DEVS + 0x0010)
#define REG_PCM2OFFSET *(int32_t*)(MEM_DEVS + 0x0014)
#define REG_PCM1LENGTH *(int32_t*)(MEM_DEVS + 0x0018)
#define REG_PCM2LENGTH *(int32_t*)(MEM_DEVS + 0x001C)
#define REG_PCM1VOLUMEL *(int8_t*)(MEM_DEVS + 0x0020)
#define REG_PCM1VOLUMER *(int8_t*)(MEM_DEVS + 0x0021)
#define REG_PCM2VOLUMEL *(int8_t*)(MEM_DEVS + 0x0022)
#define REG_PCM2VOLUMER *(int8_t*)(MEM_DEVS + 0x0023)
#define PCMOFFSET ((int32_t*)(MEM_DEVS + 0x0010))
#define PCMLENGTH ((int32_t*)(MEM_DEVS + 0x0018))
#define PCMVOLUME ((int8_t*)(MEM_DEVS + 0x0020))
#define DMA_BYTE 0
#define DMA_SHORT 1
#define DMA_INT 2
#define DMA_ENABLE 0x01
#define HDMA_DOUBLE 0x80
#define SMODE_TEXT 0 // Specifies PC CGA-style text mode.
#define SMODE_BMP16 1 // Specifies a linear-addressed 16-color four bits per pixel bitmap mode.
#define SMODE_BMP256 2 // Specifies a linear-addressed 256-color eight bits per pixel bitmap mode.
#define SMODE_TILE 0x63 // Specifies a tilemap system. Forces 320x240 resolution.
#define SMODE_BOLD 8 // Specifies that text mode should use a bold font.
#define SMODE_BLINK 0x10 // Specifies that instead of bright background colors, text mode cells should blink.
#define SMODE_240 0x20 // Specifies that instead of 480 lines, the screen height should be halved to 240.
#define SMODE_320 0x40 // Specifies that the screen width should be halved from 640 to 320.
#define SMODE_1610 0x80 // Specifies that bitmap modes should be 200 or 400 lines, and text mode 25 or 50 lines.
#define IMODE_DISABLE 0x80 // Enable interrupts.
#define IMODE_INVBLANK 0x04 // VBlank is active.
#define IMODE_INHBLANK 0x02 // HBlank is active.
#define PCM_REPEAT 0x80000000
#define BLIT_COPY (1 << 0)
#define BLIT_SET (2 << 0)
#define BLIT_INVERT (3 << 0)
#define BLIT_STRIDESKIP (1 << 4)
#define BLIT_COLORKEY (1 << 5)
#define BLIT_BYTE (0 << 6)
#define BLIT_SHORT (1 << 6)
#define BLIT_INT (2 << 6)
#define BLIT_SOURCESTRIDE(x) ((x) << 8)
#define BLIT_TARGETSTRIDE(x) ((x) << 20)
#define BLIT_8TO8 (0x00) //why would you use this?
#define BLIT_4TO4 (0x40 | 0x80)
#define TEXTFONT_THIN8 (TEXTFONT + 0x0000)
#define TEXTFONT_BOLD8 (TEXTFONT + 0x0800)
#define TEXTFONT_THIN16 (TEXTFONT + 0x1000)
#define TEXTFONT_BOLD16 (TEXTFONT + 0x2000)
#define CARTRIDGE_MARKER 0x41535321
#define DEVICE_ID_LINEPRINTER 0x4C50
#define DEVICE_ID_DISKDRIVE 0x0144
#define DEVICE_ID_INPUTOUTPUT 0x499F
typedef struct
{
int32_t identifier; // Should always be "AIMG".
uint8_t bitDepth; // Should be equal to 4 or 8, for 16 or 256 colors respectively.
uint8_t flags; // Specifies if the image is compressed, among other things.
uint16_t width; // The pixel width of the image.
uint16_t height; // The pixel height of the image.
uint16_t stride; // Specifies how many bytes make up a full line. Should be half the width for a 4bpp image.
int32_t byteSize; // The total amount of bytes making up the full image. Should be equal to stride times height.
int32_t colorOffset; // The offset from the start of the structure to the color data.
int32_t imageOffset; // The offset from the start of the structure to the image data.
int32_t hdmaOffset; // The offset from the start of the structure to the HDMA gradient data.
} TPicFile;
typedef enum
{
PIC_RLE = 1, // Picture data is RLE compressed.
PIC_HDMA = 2, // Picture has HDMA gradients. hdmaOffset may be null or missing.
PIC_NOPAL = 4, // Picture has no palette. colorOffset is null.
} EPicFlags;
typedef struct
{
char code[6]; // Locale name
char wday_name[32]; // "Sun"..."Sat"
char mon_name[64]; // "Jan"..."Dec"
char wday_nameF[64]; // "Sunday"..."Saturday"
char mon_nameF[106]; // "January"..."December"
char shortDateFmt[16]; // Format for "1983-06-26"
char longDateFmt[16]; // Format for "Sunday, June 26, 1983"
char shortTimeFmt[16]; // Format for "17:42:07"
char longTimeFmt[16]; // Format for "17:42:07"
char thousands; // What to put between clusters of three digits, ','
char decimals; // What to put between an integer and decimals, '.'
char thousandsCt; // How many digits per cluster, 3
char currency[4]; // Currency symbol, '$'
bool currencyAfter; // Is it "10$" or "$10"?
char reserved[16];
char sctoasc[256]; // Scancode map
} TLocale;
typedef enum
{
LC_CODE,
LC_DAYS,
LC_MONS,
LC_DAYF,
LC_MONF,
LC_DATES,
LC_DATEL,
LC_TIMES,
LC_TIMEL,
LC_CURR,
} ELocale;
typedef struct {
int8_t fs_type; // File system type (0: N/A)
int8_t drv; // Physical drive number
int8_t n_fats; // Number of FATs (1 or 2)
int8_t wflag; // win[] flag (b0: dirty)
int8_t fsi_flag; // FSINFO flags (b7: disabled, b0: dirty)
int16_t id; // File system mount ID
int16_t n_rootdir; // Number of root directory entries (FAT12/16)
int16_t csize; // Cluster size [sectors]
int32_t last_clst; // Last allocated cluster
int32_t free_clst; // Number of free clusters
int32_t cdir; // Current directory start cluster (0: root)
int32_t n_fatent; // Number of FAT entries (number of clusters + 2)
int32_t fsize; // Size of a FAT [sectors]
int32_t volbase; // Volume base sector
int32_t fatbase; // FAT base sector
int32_t dirbase; // Root directory base sector/cluster
int32_t database; // Data base sector
int32_t winsect; // Current sector appearing in the win[]
int8_t win[512]; // Disk access window for directory and FAT
} FATFS;
typedef struct
{
unsigned char attribs;
char numDrives;
char diskToDev[4];
FATFS firstDisk;
} TIOState;
typedef struct {
FATFS* fs; // Pointer to the owner file system object
int16_t id; // Owner file system mount ID
int8_t attr; // Object attribute
int8_t stat; // Object chain status (b1-0: =0:not contiguous, =2:contiguous (no data on FAT), =3:got fragmented, b2:sub-directory stretched)
int32_t sclust; // Object start cluster (0:no cluster or root directory)
int32_t objsize; // Object size (valid when sclust != 0)
} _FDID;
typedef struct {
_FDID obj; // Object identifier (must be the 1st member to detect invalid object pointer)
int8_t flag; // File status flags
int8_t err; // Abort flag (error code)
int32_t fptr; // File read/write pointer (Zeroed on file open)
int32_t clust; // Current cluster of fpter (invalid when fprt is 0)
int32_t sect; // Sector number appearing in buf[] (0:invalid)
int32_t dir_sect; // Sector number containing the directory entry
int8_t* dir_ptr; // Pointer to the directory entry in the win[]
int8_t buf[512]; // File private data read/write window
} TFileHandle;
typedef struct {
_FDID obj; // Object identifier
int32_t dptr; // Current read/write offset
int32_t clust; // Current cluster
int32_t sect; // Current sector
int8_t* dir; // Pointer to the directory item in the win[]
int8_t fn[12]; // SFN (in/out) {body[8],ext[3],status[1]}
const int8_t* pat; // Pointer to the name matching pattern
} TDirHandle;
typedef struct {
int32_t fsize; // File size
int16_t fdate; // Modified date
int16_t ftime; // Modified time
int8_t fattrib; // File attribute
char fname[13]; // File name
} TFileInfo;
#define FILE TFileHandle
#define DIR TDirHandle
#define FILEINFO TFileInfo
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#define FA_READ 0x01
#define FA_WRITE 0x02
#define FA_OPEN_EXISTING 0x00
#define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
#define FA_OPEN_APPEND 0x30
#define AM_READONLY 0x01
#define AM_HIDDEN 0x02
#define AM_SYSTEM 0x04
#define AM_DIRECTORY 0x10
#define AM_ARCHIVE 0x20
typedef enum {
FE_NoError, //0. Succeeded
FE_DiskError, //1. Hard error in IO layer
FE_IntError, //2. Assert fail
FE_NoDisk, //3. Drive cannot work -- no disk?
FE_NoFile, //4. File not found
FE_NoPath, //5. Path not found
FE_InvalidPath, //6. Invalid path name format
FE_Denied, //7. Access denied or directory full
FE_Denied2, //8. Access denied
FE_InvalidHnd, //9. Invalid handle
FE_Protected, //10. Drive is write-protected
FE_InvalidDrive, //11. Invalid drive number
FE_NotEnabled, //12. No work area
FE_NoFS, //13. No FAT file system
FE_MKFSAbort, //14. Format aborted
FE_Timeout, //15. Timed out
FE_Locked, //16. File is in use
FE_NoLFN, //17. Not enough space for LFN buffer
FE_TooMany, //18. Too many open files
FE_InvalidParm, //19. Parameter is invalid
} EFileError;
//--------------
//ASS-RT SUPPORT
//--------------
typedef int32_t time_t;
typedef struct {
int tm_sec; //0-59
int tm_min; //0-59
int tm_hour; //0-23
int tm_mday; //1-31
int tm_mon; //0-11
int tm_year; //
int tm_wday; //0-6
int tm_yday; //0-356
int tm_isdst; //
} tm;
extern int strcpy_s(char*, size_t, const char*);
extern int strcat_s(char*, size_t, const char*);
extern size_t strnlen_s(const char*, size_t);
extern int strncmp(const char*, const char*, size_t);
extern char *strchr(const char*, int);
extern char *strrchr(const char*, int);
extern int strkitten_s(char*, size_t, char);
extern int isgraph(int);
extern int isprint(int);
extern int isalpha(int);
extern int isdigit(int);
extern int isalnum(int);
extern int isspace(int);
extern int isupper(int);
extern int ispunct(int);
extern int isblank(int);
extern int isxdigit(int);
extern int iscntrl(int);
extern int isascii(int);
extern int islower(int);
extern int toupper(int);
extern int tolower(int);
extern int toascii(int);
extern char* strcpy(char*, const char*);
extern char* strdup(const char*);
extern int atoi(char*);
extern void* memcpy(void*, const void*, size_t);
extern void* memset(void*, int, size_t);
//---------
//INTERFACE
//---------
//Text
typedef struct
{
int(*Write)(const char* format, ...);
int(*Format)(char* buffer, const char* format, ...);
int(*VFormat)(char* buffer, const char* format, va_list args);
void(*WriteChar)(char ch);
void(*SetCursorPosition)(int left, int top);
void(*SetTextColor)(int back, int fore);
void(*ClearScreen)(void);
} ITextLibrary;
typedef struct
{
void(*ResetPalette)(void);
void(*DisplayPicture)(const TPicFile* picData);
void(*Fade)(bool in, bool toWhite);
void(*SetupDrawChar)(int(*dcCallback)(unsigned char, int, int, int));
void(*DrawString)(const char* str, int x, int y, int color);
void(*DrawFormat)(const char* format, int x, int y, int color, ...);
int(*DrawChar)(char ch, int x, int y, int color);
void(*DrawLine)(int x0, int y0, int x1, int y1, int color, uint8_t* dest);
void(*FloodFill)(int x, int y, int color, uint8_t* dest);
} IDrawingLibrary;
typedef struct
{
void(*WaitForVBlank)(void);
void(*WaitForVBlanks)(int vbls);
void(*DmaCopy)(void* dst, const void* src, size_t size, int step);
void(*DmaClear)(void* dst, int src, size_t size, int step);
void(*MidiReset)(void);
void(*OplReset)(void);
void(*RleUnpack)(int8_t* dst, int8_t* src, size_t size);
char*(*GetLocaleStr)(ELocale category, int item);
void*(*HeapAlloc)(size_t size);
void(*HeapFree)(void* ptr);
void*(*HeapReAlloc)(void* ptr, size_t size);
void*(*HeapCAlloc)(size_t nelem, size_t elsize);
size_t(*FormatTime)(char*, size_t, const char*, const tm*);
tm*(*TimeToCalendar)(const time_t*);
time_t(*CalendarToTime)(tm*);
} IMiscLibrary;
typedef struct
{
EFileError(*OpenFile)(TFileHandle* handle, const char* path, char mode);
EFileError(*CloseFile)(TFileHandle* handle);
int(*ReadFile)(TFileHandle* handle, void* target, size_t length);
int(*WriteFile)(TFileHandle* handle, void* source, size_t length);
uint32_t(*SeekFile)(TFileHandle* handle, uint32_t offset, int origin);
EFileError(*TruncateFile)(TFileHandle* handle);
EFileError(*FlushFile)(TFileHandle* handle);
uint32_t(*FilePosition)(TFileHandle* handle);
bool(*FileEnd)(TFileHandle* handle);
size_t(*FileSize)(TFileHandle* handle);
EFileError(*OpenDir)(TDirHandle* handle, const char* path);
EFileError(*CloseDir)(TDirHandle* handle);
EFileError(*ReadDir)(TDirHandle* handle, TFileInfo* info);
EFileError(*FindFirst)(TDirHandle* handle, TFileInfo* info, const char* path,const char* pattern);
EFileError(*FindNext)(TDirHandle* handle, TFileInfo* info);
EFileError(*FileStat)(const char* path, TFileInfo* info);
EFileError(*UnlinkFile)(const char* path);
EFileError(*RenameFile)(const char* from, const char* to);
EFileError(*FileTouch)(const char* path, TFileInfo* dt);
EFileError(*FileAttrib)(const char* path, char attrib);
EFileError(*MakeDir)(const char* path);
EFileError(*ChangeDir)(const char* path);
EFileError(*GetCurrentDir)(char* buffer, size_t buflen);
EFileError(*GetLabel)(char disk, char* buffer, uint32_t*);
const char*(*FileErrStr)(EFileError error);
uint32_t(*GetFree)(char disk);
} IDiskLibrary;
typedef struct
{
const long assBang;
const int16_t biosVersion;
const int16_t extensions;
void(*exception)(void);
void(*vBlank)(void);
void(*hBlank)(void);
int(*drawChar)(unsigned char, int, int, int);
const ITextLibrary* textLibrary;
const IDrawingLibrary* drawingLibrary;
const IMiscLibrary* miscLibrary;
const IDiskLibrary* diskLibrary;
char* drawCharFont;
uint16_t drawCharHeight;
uint8_t* linePrinter;
TIOState io;
TLocale locale;
} IBios;
#define TEXT interface->textLibrary
#define DRAW interface->drawingLibrary
#define MISC interface->miscLibrary
#define DISK interface->diskLibrary
extern IBios* interface;
#ifdef __cplusplus
}
#endif