-
Notifications
You must be signed in to change notification settings - Fork 0
/
yar_API.h
1735 lines (528 loc) · 24.5 KB
/
yar_API.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
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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
PUBLIC DOMAIN 2022
THIS CODE IS A HACKY MESS - READ IT AT YOUR OWN RISK!
https://github.com/gwald/yarmico
*
*/
#ifndef YARMICO_API
#define YARMICO_API
#include <stdlib.h>
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL (void*)0
#endif
#define YARMICO_MATH_COORDS_3D 0
#define YARMICO_MATH_COORDS_2D 1
// 32blit Background music, asset_bgm_00
// #define USE_BGM_00
// #define USE_BGM_01
// #define USE_BGM_02
// #define USE_BGM_04
// #define USE_BGM_05
// https://github.com/32blit/32blit-sdk/blob/master/docs/pico.md#board-specific-details
// 32blit PicoSystem VGA Board
//Screen 320x240 (160x120 lores) 240x240 (120x120 lores) 160x120 only
#define YARMICO_NATIVE_DISPLAY_320X240_640X480 0 // 320x240 scaling 640X480
#define YARMICO_NATIVE_DISPLAY_320X240 1 // 320x240 no up scaling
//256x240
#define YARMICO_NATIVE_DISPLAY_240x240 2 // 240x240 boarded widths
//upscalable
#define YARMICO_NATIVE_DISPLAY_160x120 3 // 160x120 boarded widths and heights
#define YARMICO_NATIVE_DISPLAY_120x120 4 // 120x120 boarded widths and heights
#define YARMICO_CONTROLLER_ANALOG_IGNORE 0
#define YARMICO_CONTROLLER_ANALOG_PROCESS_LEFT_STICK_AS_DPAD 1
#define YARMICO_CONTROLLER_ANALOG_PROCESS_LEFT_AND_RIGHT_STICK_AS_DPAD_AND_FACE_BUTTONS 2
#define YARMICO_CONTROLLER_ANALOG_RETURN_ANALOG_DATA 3 // u32 - each plain 8bit * 4
#define YARMICO_ANALOG_DEAD_ZONE 10
#include "yar_cfg.h" // build def's changed before different builds, easier then setting make param's PITA!
// #0 titles & date - ALL CAPS NO SPACES
#ifndef YARMICO_PROJECT_CODE_STRING
#define YARMICO_PROJECT_CODE_STRING "CODE"
#endif
#ifndef YARMICO_PROJECT_TITLE_STRING
#define YARMICO_PROJECT_TITLE_STRING "TITLE"
#endif
#ifndef YARMICO_PROJECT_DATE_STRING
#define YARMICO_PROJECT_DATE_STRING "2020-OCT-10"
#endif
// #1 set the TPAGES USED
//#define USE_TPAGE00
//#define USE_TPAGE01
//#define USE_TPAGE02
//#define USE_TPAGE03
//#define USE_TPAGE04
//#define USE_TPAGE05
// #2 set the font tpage
#ifdef USE_TPAGE00
#ifndef FONT_TPAGE
#define FONT_TPAGE 0 // TPAGE image used where 8x8 font is located
#endif
#ifndef FONT_Y_OFFSET
#define FONT_Y_OFFSET 0 // start Y - the starting Y pixel of the font
#endif
#endif ///USE_TPAGE00
// #3 set 32blit resolution and upscale
#ifndef YARMICO_NATIVE_DISPLAY
//Default set to SDL2
#define YARMICO_NATIVE_DISPLAY YARMICO_NATIVE_DISPLAY_120x120
// #define YARMICO_DEFAULT_DISPLAY_UPSCALE 1 // TRUE or FALSE - Default low res (160/120 width will be up scaled to 256 or 320)
#endif
// #4 set how the analog is handled in the controller function
#ifndef YARMICO_CONTROLLER_ANALOG_TYPE
#define YARMICO_CONTROLLER_ANALOG_TYPE YARMICO_CONTROLLER_ANALOG_PROCESS_LEFT_STICK_AS_DPAD
#endif
#if YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_320X240_640X480
#define YARMICO_SCREEN_WIDTH 320
#define YARMICO_SCREEN_HEIGHT 240
#define YARMICO_SCREEN_WIDTH_MID 160
#define YARMICO_SCREEN_HEIGHT_MID 120
#elif YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_320X240
#define YARMICO_SCREEN_WIDTH 320
#define YARMICO_SCREEN_HEIGHT 240
#define YARMICO_SCREEN_WIDTH_MID 160
#define YARMICO_SCREEN_HEIGHT_MID 120
#elif YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_240x240
#define YARMICO_SCREEN_WIDTH 240
#define YARMICO_SCREEN_HEIGHT 240
#define YARMICO_SCREEN_WIDTH_MID 120
#define YARMICO_SCREEN_HEIGHT_MID 120
#elif YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_160x120
#define YARMICO_SCREEN_WIDTH 160
#define YARMICO_SCREEN_HEIGHT 120
#define YARMICO_SCREEN_WIDTH_MID 80
#define YARMICO_SCREEN_HEIGHT_MID 60
#elif YARMICO_NATIVE_DISPLAY==YARMICO_NATIVE_DISPLAY_120x120
#define YARMICO_SCREEN_WIDTH 120
#define YARMICO_SCREEN_HEIGHT 120
#define YARMICO_SCREEN_WIDTH_MID 60
#define YARMICO_SCREEN_HEIGHT_MID 60
#endif
// #5 2D or 3D
#ifndef YARMICO_MATH_COORDS
//Default to 2D
#define YARMICO_MATH_COORDS YARMICO_MATH_COORDS_2D
#endif
// build types, defined via cmake, makefile, android.mk or in build.h static or changed via build scripts
#define HARDWARE_TARGET_NONE 0
#define HARDWARE_TARGET_NET_YAROZE 1
#define HARDWARE_TARGET_SDL2 2 // PC/Linux/Android/Ouya/HTML5
#define HARDWARE_TARGET_32BLIT_HANDHELD 3
#define HARDWARE_TARGET_PICOSYSTEM 4
#ifndef YARMICO_USE_TILEMAP
// no tilemap used
#define YARMICO_USE_TILEMAP FALSE
#endif
#ifndef HARDWARE_TARGET
//Default set to SDL2
#define HARDWARE_TARGET HARDWARE_TARGET_SDL2
#endif
#ifndef YARMICO_USE_BGM
#define YARMICO_PLAY_BGM FALSE // 1 YES 0 NO
#endif
#ifndef YARMICO_PICO_SOUND
#define YARMICO_PICO_SOUND FALSE // 1 YES 0 NO
#endif
#if 0 // SDL
#include <string.h>
#ifdef __ANDROID__
//https://stackoverflow.com/questions/10274920/how-to-get-printf-messages-written-in-ndk-application
#include <android/log.h>
extern int android_debugf( const char *format, ...);
#define LOG_TAG "yarmico"
#define ANDROID_LOG(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define printf yarmico_debugf
#endif // #ifdef __ANDROID__
//save location: ~/.local/share/
#endif
//-------------------------------------------------------------------------------------------------- #define's
#if 0
#define _RELEASE_
#else
#define _DEBUG_
#endif
#if 0
#ifdef UNIT_32BLIT
#undef _DEBUG_
#define _RELEASE_
#endif
#endif
#ifdef _RELEASE_
#undef _DEBUG_
#define MACRO_NO_SAVE_LOADING //return 0;
#else
#define MACRO_NO_SAVE_LOADING //return 0;
#endif
// #define LOG_DEBUG_COL
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef signed char s8;
// #define s8 signed char
typedef signed short s16;
typedef signed int s32;
// THIS IS HOW DEBUGGING IS MOSTLY DONE IN PSX - VIA TTY OUTPUT
// COULD BE FANCIER BUT SIMPLE IS FINE
#ifdef _DEBUG_
#define LOG_AUDIO // yarmico_debugf
#define LOG_TEXT // yarmico_debugf
#else
#define LOG_AUDIO //yarmico_debugf
#define LOG_TEXT //yarmico_debugf
#endif
#ifdef INSTANCE_YARMICO_API
#define INSTANCE_API
#else
#define INSTANCE_API extern
#endif
#define YARMICO_BUTTON_PRESS_TIME 8
// DPad (analogy) and AB/XY face buttons use the same binary checks
#define YARMICO_CONTROLER_BUT_NONE 0
#define YARMICO_CONTROLER_BUT_R 1 // 0b0001 // right 1
#define YARMICO_CONTROLER_BUT_L 2 // 0b0010 // left 2
#define YARMICO_CONTROLER_BUT_U 4 // 0b0100 // up 4
#define YARMICO_CONTROLER_BUT_D 8 // 0b1000 // down 8
//special buttons
#define YARMICO_CONTROLER_BUT_ANALOG_SHOULDERS 1 // 0b0001 // right 1
#define YARMICO_CONTROLER_BUT_HOME_SELECT 2 // 0b0010 // left 2
#define YARMICO_CONTROLER_BUT_MENU_START 4 // 0b0100 // up 4
//#define YARMICO_CONTROLER_BUT_NONE 8 // 0b1000 // down 8
#define YARMICO_CONTROLER_BUT_ALL_DIR 15
#define YARMICO_CONTROLER_BUT_UP_DOWN 12
#define YARMICO_CONTROLER_BUT_LEFT_RIGHT 3
// circle counter clockwise
#define YARMICO_CONTROLER_BUT_RR 1 // 0b0001 // right right 1
#define YARMICO_CONTROLER_BUT_RU 5 // 0b0101 // right up 5
#define YARMICO_CONTROLER_BUT_UU 4 // 0b0100 // up up 4
#define YARMICO_CONTROLER_BUT_LU 6 // 0b0110 // left up 6
#define YARMICO_CONTROLER_BUT_LL 2 // 0b0010 // left left 2
#define YARMICO_CONTROLER_BUT_LD 10 // 0b1010 // left down 10
#define YARMICO_CONTROLER_BUT_DD 8 // 0b1000 // down down 8
#define YARMICO_CONTROLER_BUT_RD 9 // 0b1001 // right down 9
#if 0
#define CONTROL_BUT_NONE 0
#define CONTROL_BUT_A 1 // 0b0001
#define CONTROL_BUT_B 2 // 0b0010
#define CONTROL_BUT_MENU 4 // 0b0100
#define CONTROL_BUT_HOME 8 // 0b1000
//#define CONTROL_BUT_X 0b0100
//#define CONTROL_BUT_Y 0b1000
#endif
// from PS1
#ifndef ONE
#define ONE 4096
#endif
#define ONE_SHIFT 12 // 4096 >> 12 = 1
//-------------------------------------------------------------------------------------------------- typedef's
//-------------------------------------------------------------------------------------------------- GLOBAL's
#ifdef __cplusplus
extern "C" {
#endif
#ifndef YARMICO_MAX_TILEMAP_WIDTH_SIZE
#define YARMICO_MAX_TILEMAP_WIDTH_SIZE 32
#endif
#ifndef YARMICO_MAX_TILEMAP_HEIGHT_SIZE
#define YARMICO_MAX_TILEMAP_HEIGHT_SIZE 32
#endif
// tile/map code inspired by:
// https://github.com/martincohen/Punity/blob/def395699e24670ae92d438f5b6b5e60aeec961c/punity.h#L814
typedef struct
{
u8 tile_cell_u; //x or row
u8 tile_cell_v; //y or column
}
yarmico_tile_data_t;
typedef union {
yarmico_tile_data_t cell;
u16 data;
} yarmico_tile_data_u;
typedef struct
{
u8 red,green,blue;
}
yarmico_RGB_t;
// populated via tilestudio menu: code -> project lists
typedef struct
{
u8 tpage; //image texture page
// u8 number_of_levels; // total maps, starting from zero
u32 map_width; // all maps have the same width height
u32 map_height;
u8 tile_size; // square cells - no rectangles
u32 current_level; // start level, set to zero
//extracted from map on each level load
u32 start_cell_pos_X, start_cell_pos_Y;
yarmico_tile_data_t* map_data;
yarmico_tile_data_t* cur_map_data;
yarmico_RGB_t background_colors;
}
yarmico_tilemap_t;
// based on the PS1 analog data
// max = 125 * ONE
// min = 1 * ONE
typedef struct{
s32 left_stick_x, // -left <- 0 -> +right
left_stick_y; // -down <- 0 -> +up
s32 right_stick_x, // -left <- 0 -> +right
right_stick_y; // -down <- 0 -> +up
}yarmico_analog_stick_t;
#define YARMICO_PICO_SOUND_SFX_NONE 0
#define YARMICO_PICO_SOUND_SFX1_ON_OFF 1
#define YARMICO_PICO_SOUND_SFX2_UP_DOWN 2
#define YARMICO_PICO_SOUND_SFX2_ALT_SIGN 4
#define YARMICO_PICO_SOUND_PLAYBACK_TRIGGER_ATTACK 0
#define YARMICO_PICO_SOUND_PLAYBACK_TRIGGER_DECAY 1
#define YARMICO_PICO_SOUND_PLAYBACK_TRIGGER_SUSTAIN 2
#define YARMICO_PICO_SOUND_PLAYBACK_TRIGGER_RELEASE 4
#define YARMICO_PICO_SOUND_PLAYBACK_OFF 8
#define YARMICO_PICO_SOUND_LOOP_REPEAT 2
#define YARMICO_PICO_SOUND_LOOP_TIMES 1
#define YARMICO_PICO_SOUND_LOOP_NONE 0
#define YARMICO_MACRO_SET_PICO_AUDIO(_FREQ, _ATT, _DEC, _SUS, _REL, _REPEAT ) g_yarmico_pico_play_sound.frequency =_FREQ; g_yarmico_pico_play_sound.attack_ms =_ATT; g_yarmico_pico_play_sound.decay_ms = _DEC; g_yarmico_pico_play_sound.sustain = _SUS; g_yarmico_pico_play_sound.release_ms = _REL; g_yarmico_pico_play_sound.time_frames_repeat = g_yarmico_pico_play_sound.time_frames = _REPEAT;
#if HARDWARE_TARGET == HARDWARE_TARGET_PICOSYSTEM
#define YARMICO_UPDATE_TIME_SHIFT 6
#elif HARDWARE_TARGET == HARDWARE_TARGET_NET_YAROZE
#define YARMICO_UPDATE_TIME_SHIFT 6
#else
#define YARMICO_UPDATE_TIME_SHIFT 6
#endif
typedef struct{
u32 time_frames; //frames to play sound
u32 time_frames_repeat; //frames to repeat play sound
//from 32blit sdk audio.hpp