Repository navigation
Expand file tree
/
Copy pathtypes.h
More file actions
699 lines (545 loc) · 17.4 KB
/
Copy pathtypes.h
File metadata and controls
699 lines (545 loc) · 17.4 KB
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/*
This file is part of libswirl
*/
#include "license/bsd"
#pragma once
#include "build.h"
#if BUILD_COMPILER==COMPILER_VC
#define DECL_ALIGN(x) __declspec(align(x))
#else
#ifndef __forceinline
#define __forceinline inline
#endif
#define DECL_ALIGN(x) __attribute__((aligned(x)))
#ifndef _WIN32
#define __debugbreak
#endif
#endif
#if HOST_CPU == CPU_X86
#if BUILD_COMPILER==COMPILER_VC
#define DYNACALL __fastcall
#else
//android defines fastcall as regparm(3), it doesn't work for us
#undef fastcall
#define DYNACALL __attribute__((fastcall))
#endif
#else
#define DYNACALL
#endif
#if BUILD_COMPILER==COMPILER_VC
#ifdef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#endif
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#ifdef _CRT_SECURE_NO_DEPRECATE
#undef _CRT_SECURE_NO_DEPRECATE
#endif
#define _CRT_SECURE_NO_DEPRECATE
//unnamed struncts/unions
#pragma warning( disable : 4201)
//unused parameters
#pragma warning( disable : 4100)
#endif
#if BUILD_COMPILER==COMPILER_VC
//SHUT UP M$ COMPILER !@#!@$#
#ifdef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#endif
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#ifdef _CRT_SECURE_NO_DEPRECATE
#undef _CRT_SECURE_NO_DEPRECATE
#endif
#define _CRT_SECURE_NO_DEPRECATE
//Do not complain when i use enum::member
#pragma warning( disable : 4482)
//unnamed struncts/unions
#pragma warning( disable : 4201)
//unused parameters
#pragma warning( disable : 4100)
#endif
#include <stdint.h>
#include <stddef.h>
//basic types
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef float f32;
typedef double f64;
#ifdef _M_X64
#undef X86
#define X64
#endif
typedef ptrdiff_t snat;
typedef size_t unat;
#ifdef X64
typedef u64 unat;
#endif
typedef char wchar;
#define EXPORT extern "C" __declspec(dllexport)
#ifndef CDECL
#define CDECL __cdecl
#endif
//intc function pointer and enums
enum HollyInterruptType
{
holly_nrm = 0x0000,
holly_ext = 0x0100,
holly_err = 0x0200,
};
enum HollyInterruptID
{
// asic9a /sh4 external holly normal [internal]
holly_RENDER_DONE_vd = holly_nrm | 0, //bit 0 = End of Render interrupt : Video
holly_RENDER_DONE_isp = holly_nrm | 1, //bit 1 = End of Render interrupt : ISP
holly_RENDER_DONE = holly_nrm | 2, //bit 2 = End of Render interrupt : TSP
holly_SCANINT1 = holly_nrm | 3, //bit 3 = V Blank-in interrupt
holly_SCANINT2 = holly_nrm | 4, //bit 4 = V Blank-out interrupt
holly_HBLank = holly_nrm | 5, //bit 5 = H Blank-in interrupt
holly_YUV_DMA = holly_nrm | 6, //bit 6 = End of Transferring interrupt : YUV
holly_OPAQUE = holly_nrm | 7, //bit 7 = End of Transferring interrupt : Opaque List
holly_OPAQUEMOD = holly_nrm | 8, //bit 8 = End of Transferring interrupt : Opaque Modifier Volume List
holly_TRANS = holly_nrm | 9, //bit 9 = End of Transferring interrupt : Translucent List
holly_TRANSMOD = holly_nrm | 10, //bit 10 = End of Transferring interrupt : Translucent Modifier Volume List
holly_PVR_DMA = holly_nrm | 11, //bit 11 = End of DMA interrupt : PVR-DMA
holly_MAPLE_DMA = holly_nrm | 12, //bit 12 = End of DMA interrupt : Maple-DMA
holly_MAPLE_VBOI = holly_nrm | 13, //bit 13 = Maple V blank over interrupt
holly_GDROM_DMA = holly_nrm | 14, //bit 14 = End of DMA interrupt : GD-DMA
holly_SPU_DMA = holly_nrm | 15, //bit 15 = End of DMA interrupt : AICA-DMA
holly_EXT_DMA1 = holly_nrm | 16, //bit 16 = End of DMA interrupt : Ext-DMA1(External 1)
holly_EXT_DMA2 = holly_nrm | 17, //bit 17 = End of DMA interrupt : Ext-DMA2(External 2)
holly_DEV_DMA = holly_nrm | 18, //bit 18 = End of DMA interrupt : Dev-DMA(Development tool DMA)
holly_CH2_DMA = holly_nrm | 19, //bit 19 = End of DMA interrupt : ch2-DMA
holly_PVR_SortDMA = holly_nrm | 20, //bit 20 = End of DMA interrupt : Sort-DMA (Transferring for alpha sorting)
holly_PUNCHTHRU = holly_nrm | 21, //bit 21 = End of Transferring interrupt : Punch Through List
// asic9c/sh4 external holly external [EXTERNAL]
holly_GDROM_CMD = holly_ext | 0x00, //bit 0 = GD-ROM interrupt
holly_SPU_IRQ = holly_ext | 0x01, //bit 1 = AICA interrupt
holly_EXP_8BIT = holly_ext | 0x02, //bit 2 = Modem interrupt
holly_EXP_PCI = holly_ext | 0x03, //bit 3 = External Device interrupt
// asic9b/sh4 external holly err only error [error]
//missing quite a few ehh ?
//bit 0 = RENDER : ISP out of Cache(Buffer over flow)
//bit 1 = RENDER : Hazard Processing of Strip Buffer
holly_PRIM_NOMEM = holly_err | 0x02, //bit 2 = TA : ISP/TSP Parameter Overflow
holly_MATR_NOMEM = holly_err | 0x03, //bit 3 = TA : Object List Pointer Overflow
holly_ILLEGAL_PARAM = holly_err | 0x04 //bit 4 = TA : Illegal Parameter
//bit 5 = TA : FIFO Overflow
//bit 6 = PVRIF : Illegal Address set
//bit 7 = PVRIF : DMA over run
//bit 8 = MAPLE : Illegal Address set
//bit 9 = MAPLE : DMA over run
//bit 10 = MAPLE : Write FIFO over flow
//bit 11 = MAPLE : Illegal command
//bit 12 = G1 : Illegal Address set
//bit 13 = G1 : GD-DMA over run
//bit 14 = G1 : ROM/FLASH access at GD-DMA
//bit 15 = G2 : AICA-DMA Illegal Address set
//bit 16 = G2 : Ext-DMA1 Illegal Address set
//bit 17 = G2 : Ext-DMA2 Illegal Address set
//bit 18 = G2 : Dev-DMA Illegal Address set
//bit 19 = G2 : AICA-DMA over run
//bit 20 = G2 : Ext-DMA1 over run
//bit 21 = G2 : Ext-DMA2 over run
//bit 22 = G2 : Dev-DMA over run
//bit 23 = G2 : AICA-DMA Time out
//bit 24 = G2 : Ext-DMA1 Time out
//bit 25 = G2 : Ext-DMA2 Time out
//bit 26 = G2 : Dev-DMA Time out
//bit 27 = G2 : Time out in CPU accessing
};
struct vram_block
{
u32 start;
u32 end;
u32 len;
u32 type;
void* userdata;
};
enum ndc_error_codes
{
rv_ok = 0, //no error
rv_cli_finish=69, //clean exit after -help or -version , should we just use rv_ok?
rv_error=-2, //error
rv_serror=-1, //silent error , it has been reported to the user
};
//Simple struct to store window rect ;)
//Top is 0,0 & numbers are in pixels.
//Only client size
struct NDC_WINDOW_RECT
{
u32 width;
u32 height;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////
//******************************************************
//*********************** PowerVR **********************
//******************************************************
void libCore_vramlock_Unlock_block (vram_block* block);
void libCore_vramlock_Unlock_block_wb (vram_block* block);
vram_block* libCore_vramlock_Lock(u32 start_offset,u32 end_offset,void* userdata);
//******************************************************
//************************ GDRom ***********************
//******************************************************
enum DiscType
{
CdDA=0x00,
CdRom=0x10,
CdRom_XA=0x20,
CdRom_Extra=0x30,
CdRom_CDI=0x40,
GdRom=0x80,
NoDisk=0x1, //These are a bit hacky .. but work for now ...
Open=0x2, //tray is open :)
Busy=0x3 //busy -> needs to be automatically done by gdhost
};
enum DiskArea
{
SingleDensity,
DoubleDensity
};
enum DriveEvent
{
DiskChange=1 //disk ejected/changed
};
//******************************************************
//************************ AICA ************************
//******************************************************
void libCore_CDDA_Sector(s16* sector);
//passed on AICA init call
//Ram/Regs are managed by plugin , exept RTC regs (managed by main emu)
//******************************************************
//******************** ARM Sound CPU *******************
//******************************************************
//******************************************************
//****************** Maple devices ******************
//******************************************************
enum MapleDeviceCreationFlags
{
MDCF_None=0,
MDCF_Hotplug=1
};
struct maple_subdevice_instance;
struct maple_device_instance;
//buffer_out_len and responce need to be filled w/ proper info by the plugin
//buffer_in must not be edited (its direct pointer on ram)
//output buffer must contain the frame data , the frame header is generated by the maple routing code
//typedef u32 FASTCALL MapleSubDeviceDMAFP(void* device_instance,u32 Command,u32* buffer_in,u32 buffer_in_len,u32* buffer_out,u32& buffer_out_len);
typedef u32 MapleDeviceDMAFP(void* device_instance,u32 Command,u32* buffer_in,u32 buffer_in_len,u32* buffer_out,u32& buffer_out_len);
struct maple_subdevice_instance
{
//port
u8 port;
//user data
void* data;
//MapleDeviceDMA
MapleDeviceDMAFP* dma;
bool connected;
u32 reserved; //reserved for the emu , DO NOT EDIT
};
struct maple_device_instance
{
//port
u8 port;
//user data
void* data;
//MapleDeviceDMA
MapleDeviceDMAFP* dma;
bool connected;
maple_subdevice_instance subdevices[5];
};
//includes from CRT
#include <stdlib.h>
#include <stdio.h>
#if defined(TARGET_NACL32)
int nacl_printf(const wchar* Text,...);
#define printf nacl_printf
#define puts(X) printf("%s\n", X)
#endif
#if HOST_OS == OS_DARWIN
int darw_printf(const wchar* Text,...);
#define printf darw_printf
#define puts(X) printf("%s\n", X)
#endif
//includes from c++rt
#include <vector>
#include <string>
#include <map>
using namespace std;
//used for asm-olny functions
#if COMPILER_VC==BUILD_COMPILER
#define naked __declspec( naked )
#else
#define naked __attribute__((naked))
#endif
// NOTE: Always inline for macOS builds or it causes duplicate symbol linker errors
#if DEBUG && HOST_OS != OS_DARWIN
//force
#define INLINE
//sugest
#define SINLINE
#else
//force
#define INLINE __forceinline
//sugest
#define SINLINE __inline
#endif
//no inline -- fixme
#if BUILD_COMPILER == COMPILER_VC
#define NOINLINE __declspec(noinline)
#else
#define NOINLINE __attribute__ ((noinline))
#endif
#if BUILD_COMPILER == COMPILER_VC
#define likely(x) x
#define unlikely(x) x
#else
#define likely(x) __builtin_expect((x),1)
#define unlikely(x) __builtin_expect((x),0)
#endif
//basic includes
#include "stdclass.h"
#ifndef RELEASE
#define EMUERROR(format, ...) printf("Error in %20s:%s:%d: " format "\n", \
__FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
//strlen(__FILE__) <= 20 ? __FILE__ : __FILE__ + strlen(__FILE__) - 20,
#else
#define EMUERROR(format, ...)
#endif
#define EMUERROR2 EMUERROR
#define EMUERROR3 EMUERROR
#define EMUERROR4 EMUERROR
#ifndef NO_MMU
#define _X_x_X_MMU_VER_STR "/mmu"
#else
#define _X_x_X_MMU_VER_STR ""
#endif
#if DC_PLATFORM==DC_PLATFORM_DREAMCAST
#define VER_EMUNAME "reicast"
#elif DC_PLATFORM==DC_PLATFORM_DEV_UNIT
#define VER_EMUNAME "reicast-DevKit-SET5.21"
#elif DC_PLATFORM==DC_PLATFORM_NAOMI
#define VER_EMUNAME "reicast-Naomi"
#elif DC_PLATFORM==DC_PLATFORM_ATOMISWAVE
#define VER_EMUNAME "reicast-AtomisWave"
#else
#error unknown target platform
#endif
#define VER_FULLNAME VER_EMUNAME " git" _X_x_X_MMU_VER_STR " (built " __DATE__ "@" __TIME__ ")"
#define VER_SHORTNAME VER_EMUNAME " git" _X_x_X_MMU_VER_STR
void os_DebugBreak();
#define dbgbreak os_DebugBreak()
#if COMPILER_VC_OR_CLANG_WIN32
#pragma warning( disable : 4127 4996 /*4244*/)
#else
#define stricmp strcasecmp
#endif
#define verify(x) if((x)==false){ msgboxf("Verify Failed : " #x "\n in %s -> %s : %d \n",MBX_ICONERROR,(__FUNCTION__),(__FILE__),__LINE__); dbgbreak;}
#define die(reason) { msgboxf("Fatal error : %s\n in %s -> %s : %d \n",MBX_ICONERROR,(reason),(__FUNCTION__),(__FILE__),__LINE__); dbgbreak;}
#define fverify verify
//will be removed sometime soon
//This shit needs to be moved to proper headers
enum SmcCheckEnum {
NoCheck = -1,
FullCheck = 0,
FastCheck = 1,
FaultCheck = 2,
ValidationCheck = 3,
};
enum MTTAEnum {
TA_STTA = 0,
TA_MTTA = 1,
TA_MTTA_DECOUPLED = 2
};
struct settings_t
{
struct {
bool UseReios;
} bios;
struct {
string ElfFile;
} reios;
struct
{
bool Enable;
bool idleskip;
bool disable_nvmem;
bool opt_cyclecheck_backwards_only; // only poll for interrupts on blocks that can backwards
bool opt_div1_som; // match div1 for div32u/s
bool opt_sqw_on_pref; // on write before pref, assume SQW
bool opt_sqw_rewrite; // On rewrite to SQW, always assume SQW
bool opt_anchored_loops; // detect static loops from anchor blocks and compile them as regions (CompileLoop)
int opt_constprop; // 0 = 0ff, 1 = safe, 2 = include page constant
bool opt_readm_pairs; // fuse +0 and +4 addresses on same base reg
bool opt_fipr_w; // simplify fipr if w is provably 0 or 1
bool opt_self_loops; // keep regs live across a block's branch to itself
SmcCheckEnum SmcCheckLevel;
int ScpuEnable;
int DspEnable;
} dynarec;
struct
{
u32 run_counts;
} profile;
struct
{
u32 cable; // 0 -> VGA, 1 -> VGA, 2 -> RGB, 3 -> TV
u32 region; // 0 -> JP, 1 -> USA, 2 -> EU, 3 -> default
u32 broadcast; // 0 -> NTSC, 1 -> PAL, 2 -> PAL/M, 3 -> PAL/N, 4 -> default
u32 language; // 0 -> JP, 1 -> EN, 2 -> DE, 3 -> FR, 4 -> SP, 5 -> IT, 6 -> default
std::vector<std::string> ContentPath;
bool FullMMU;
// VMU save files are VmuPath/VmuName. VmuName may contain {port}
// (A1, A2, ...) and {game_id} (product number from the disc's IP.bin).
// An empty VmuPath means the user data dir.
std::string VmuPath;
std::string VmuName;
} dreamcast;
struct
{
bool LimitFPS; // defaults to true
u32 CDDAMute;
u32 GlobalMute;
u32 DSPEnabled; //0 -> no, 1 -> yes
bool OldSyncronousDma; // 1 -> sync dma (old behavior), 0 -> async dma (fixes some games, partial implementation)
bool NoBatch;
bool NoSound;
} aica;
struct
{
bool PatchRegion;
bool LoadDefaultImage;
char DefaultImage[512];
char LastImage[512];
} imgread;
struct
{
int MultithreadedTA;
u32 FPSTarget;
} pvr;
struct
{
u32 ClockSel;
bool AutoReset;
bool DumpOnLockup;
bool ShowStats; // stats bar in the top border band
} polly2;
struct {
// FillReadBuffer on the high-priority worker thread; off = legacy
// synchronous disc reads on the sh4 thread
bool async_dma;
} gdrom;
// slave the sh4 scheduler to wall clock time (CycloneV A9 global timer)
// instead of advancing it per executed timeslice
bool freerunning;
struct {
bool PrintTaErrors;
bool SerialConsole;
bool VirtualSerialPort;
string VirtualSerialPortFile;
} debug;
struct {
u32 MouseSensitivity;
u32 JammaSetup; // 0: standard, 1: 4-players, 2: rotary encoders, 3: Sega Marine Fishing,
// 4: dual I/O boards (4P), 5: Namco JYU board (Ninja Assault)
int maple_devices[4];
int maple_expansion_devices[4][2];
int VirtualGamepadVibration;
} input;
};
extern settings_t settings;
void InitSettings();
void LoadSettings(bool game_specific);
void SaveSettings();
extern u32 patchRB;
inline bool is_s8(u32 v) { return (s8)v==(s32)v; }
inline bool is_u8(u32 v) { return (u8)v==(s32)v; }
inline bool is_s16(u32 v) { return (s16)v==(s32)v; }
inline bool is_u16(u32 v) { return (u16)v==(u32)v; }
#define verifyc(x) verify(!FAILED(x))
static inline void do_nada(...) { }
#ifdef _ANDROID
#include <android/log.h>
#ifdef printf
#undef printf
#endif
#ifdef puts
#undef puts
#endif
#define LOG_TAG "reicast"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define puts LOGI
#define printf LOGI
#define putinf LOGI
#endif
#include "hw/sh4/sh4_if.h"
//more to come
extern SuperH4* sh4_cpu;
//sh4 thread
s32 plugins_Init();
void plugins_Term();
void plugins_Reset(bool Manual);
//PVR
void* libPvr_GetRenderTarget();
void* libPvr_GetRenderSurface();
//GDR
void libCore_gdrom_disc_change();
struct GDRomDisc {
virtual s32 Init() = 0;
virtual void Reset(bool M) = 0;
//IO
virtual void ReadSector(u8* buff, u32 StartSector, u32 SectorCount, u32 secsz) = 0;
virtual void ReadSubChannel(u8* buff, u32 format, u32 len) = 0;
virtual void GetToc(u32* toc, u32 area) = 0;
virtual u32 GetDiscType() = 0;
virtual void GetSessionInfo(u8* pout, u8 session) = 0;
virtual void Swap() = 0;
virtual ~GDRomDisc() { }
static GDRomDisc* Create();
};
// 0x00600000 - 0x006007FF [NAOMI] (modem area for dreamcast)
u32 libExtDevice_ReadMem_A0_006(u32 addr,u32 size);
void libExtDevice_WriteMem_A0_006(u32 addr,u32 data,u32 size);
//Area 0 , 0x01000000- 0x01FFFFFF [Ext. Device]
static inline u32 libExtDevice_ReadMem_A0_010(u32 addr,u32 size) { return 0; }
static inline void libExtDevice_WriteMem_A0_010(u32 addr,u32 data,u32 size) { }
//Area 5
static inline u32 libExtDevice_ReadMem_A5(u32 addr,u32 size){ return 0; }
static inline void libExtDevice_WriteMem_A5(u32 addr,u32 data,u32 size) { }
//ARM
#define ReadMemArrRet(arr,addr,sz) \
{if (sz==1) \
return arr[addr]; \
else if (sz==2) \
return *(u16*)&arr[addr]; \
else if (sz==4) \
return *(u32*)&arr[addr];}
#define WriteMemArr(arr,addr,data,sz) \
{if(sz==1) \
{arr[addr]=(u8)data;} \
else if (sz==2) \
{*(u16*)&arr[addr]=(u16)data;} \
else if (sz==4) \
{*(u32*)&arr[addr]=data;}}
#define WriteMemArrRet(arr,addr,data,sz) \
{if(sz==1) \
{arr[addr]=(u8)data;return;} \
else if (sz==2) \
{*(u16*)&arr[addr]=(u16)data;return;} \
else if (sz==4) \
{*(u32*)&arr[addr]=data;return;}}
struct OnLoad
{
typedef void OnLoadFP();
OnLoad(OnLoadFP* fp) { fp(); }
};
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif