forked from alpyre/Sevgi_Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay_creator.c
More file actions
1465 lines (1293 loc) · 53.6 KB
/
Copy pathdisplay_creator.c
File metadata and controls
1465 lines (1293 loc) · 53.6 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
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
/******************************************************************************
* DisplayCreator *
******************************************************************************/
///Defines
#define MUIA_Enabled 0 //Not a real attribute, just a value to make reading easier
#define MUIM_DisplayCreator_OpenPaletteSelector 0x80430C0B
#define MUIM_DisplayCreator_SetPalette 0x80430C0C
#define MUIM_DisplayCreator_CheckValidity 0x80430C0D
#define MUIM_DisplayCreator_Create 0x80430C0E
#define MUIM_DisplayCreator_Reset 0x80430C0F
///
///Includes
#include <string.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/utility.h> // <-- Required for tag redirection
#include <libraries/mui.h>
#include <proto/muimaster.h>
#include <clib/alib_protos.h> // <-- Required for DoSuperMethod()
#include <SDI_compiler.h> // Required for
#include <SDI_hook.h> // <-- multi platform
#include <SDI_stdarg.h> // compatibility
#include "dosupernew.h"
#include "utility.h"
#include "integer_gadget.h"
#include "palette_selector.h"
#include "display_creator.h"
///
///Globals
extern APTR g_MemoryPool;
extern struct FileRequester* g_FileReq;
extern struct Project {
STRPTR directory;
STRPTR settings_header;
STRPTR assets_header;
STRPTR palettes_header;
STRPTR data_drawer;
STRPTR assets_drawer;
ULONG screen_depth;
}g_Project;
extern Object* App;
extern struct MUI_CustomClass *MUIC_PopASLString;
extern struct MUI_CustomClass *MUIC_Integer;
extern struct MUI_CustomClass *MUIC_AckString;
extern struct MUI_CustomClass* MUIC_DisplayCreator;
STRPTR black_list[] = {
"level",
"loading",
"menu",
"splash",
NULL
};
static struct {
STRPTR str_name;
STRPTR scr_width;
STRPTR scr_height;
STRPTR scr_depth;
STRPTR palette;
STRPTR AGA;
STRPTR interleaved;
STRPTR hires;
STRPTR interlaced;
STRPTR layer;
STRPTR tmpras;
STRPTR area;
STRPTR maxvectors;
STRPTR pltOnCL;
STRPTR implMouse;
STRPTR create;
STRPTR cancel;
}help_string = {
"Name for your new display.\nThis string will be used in filenames, defines and\nfunction names in proper letter casing.\nYou can use either snake or camel case if your\ndisplay name consists of more than one word.",
"Width of your display.",
"Height of your display.",
"Color depth of your display.",
"The color palette to be used for this display.\nIt must match the color depth selected.",
"Enable AGA features for this display.",
"Selecting this will allocate an interleaved bitmap for this display.",
"Enable 640 pixel horizontal resolution.",
"Enable 512 pixel vertical resolution.\nWill flicker on Amigas without a flicker fixer",
"Allocate a Layer struct for your display's RastPort.",
"Allocate a TempRas for your display's RastPort.",
"Allocate an Area struct for your dispay's RastPort.\nThis makes possible using the Area functions\nfrom the API for drawing.",
"Size of the vector buffer for Area functions.",
"Creates a section of MOVE instructions for the color registers\non the CopperList created for this display.\nThis mandates the use of color functions named with the \"_CLP\"\ntag for color assignments and fade in/out effects.\nAn access pointer pointing to this section named CL_PALETTE\nwill also be defined.",
"Implement the basics for a mouse pointer on this display.\nThe global g_mouse_pointer gameobject and hardware sprite 0 will be used.",
"Create new display.",
"Close this window."
};
//Code:
struct {
STRPTR includes;
STRPTR include_AGA;
STRPTR define_1;
STRPTR define_2;
STRPTR define_2_interleaved;
STRPTR define_3;
STRPTR define_3_AGA_0;
STRPTR define_end;
STRPTR define_3_hires;
STRPTR define_3_laced;
STRPTR define_3_AGA_1;
STRPTR define_3_AGA_2;
STRPTR globals;
STRPTR copperlist_0;
STRPTR copperlist_1;
STRPTR copperlist_1_laced;
STRPTR copperlist_CLP;
STRPTR copperlist_CLP_laced;
STRPTR copperlist_2;
STRPTR copperlist_2_disp;
STRPTR copperlist_2_AGA;
STRPTR copperlist_bitplanes;
STRPTR copperlist_2_laced;
STRPTR copperlist_3;
STRPTR colors;
STRPTR protos;
STRPTR protos_mouse;
STRPTR protos_2;
STRPTR vblank;
STRPTR vblank_laced;
STRPTR color_table;
STRPTR color_table_CLP;
STRPTR color_table_CLP_laced;
STRPTR screen;
STRPTR copperlist_functions;
STRPTR copperlist_functions_laced;
STRPTR display;
STRPTR display_loop_1;
STRPTR display_loop_1_moused;
STRPTR display_loop_2;
STRPTR switch_functions;
STRPTR switch_functions_laced;
STRPTR show;
STRPTR set_sprite_1;
STRPTR set_sprite_2;
STRPTR set_sprite_2_laced;
STRPTR convert_hsr;
STRPTR header_file;
}code_string = {
"///includes\n%s" // includes
"#include <stdio.h>\n"
"#include <string.h>\n\n"
"#include <exec/exec.h>\n"
"#include <intuition/screens.h>\n"
"#include <graphics/gfx.h>\n"
"#include <graphics/display.h>\n"
"#include <hardware/custom.h>\n"
"#include <hardware/cia.h>\n"
"#include <hardware/dmabits.h>\n"
"#include <hardware/intbits.h>\n"
"#include <proto/exec.h>\n"
"#include <proto/graphics.h>\n"
"#include <proto/intuition.h>\n\n"
"#include \"system.h\"\n"
"#include \"color.h\"\n"
"#include \"cop_inst_macros.h\"\n"
"#include \"input.h\"\n"
"#include \"keyboard.h\"\n"
"#include \"diskio.h\"\n"
"#include \"fonts.h\"\n"
"#include \"palettes.h\"\n"
"#include \"settings.h\"\n\n"
"#include \"display.h\"\n"
"#include \"display_%s.h\"\n"
"///\n",
"#define ECS_SPECIFIC\n\n", // include_AGA
"///defines (private)\n" // define_1
"#define %s_SCREEN_WIDTH %lu\n"
"#define %s_SCREEN_HEIGHT %lu\n"
"#define %s_SCREEN_DEPTH %lu\n"
"#define %s_SCREEN_COLORS (1 << %s_SCREEN_DEPTH)\n\n"
"#define %s_BITMAP_WIDTH %s_SCREEN_WIDTH\n"
"#define %s_BITMAP_HEIGHT %s_SCREEN_HEIGHT\n"
"#define %s_BITMAP_DEPTH %s_SCREEN_DEPTH\n\n"
"#define DDFSTRT_V DEFAULT_DDFSTRT_LORES\n"
"#define DDFSTOP_V DEFAULT_DDFSTOP_LORES\n"
"#define DIWSTRT_V DEFAULT_DIWSTRT\n"
"#define DIWSTOP_V DEFAULT_DIWSTOP\n\n",
"#define BPLXMOD_V ((%s_BITMAP_WIDTH / 8) & 0xFFFF)\n\n", // define_2
"#define BPLXMOD_V ((%s_BITMAP_WIDTH / 8 * (%s_BITMAP_DEPTH%s - 1)) & 0xFFFF)\n\n", // define_2_interleaved
"#define BPLCON0_V ((%s%s%s_SCREEN_DEPTH * BPLCON0_BPU0) | BPLCON0_COLOR%s%s%s)\n" // define_3
"#define MAXVECTORS %lu\n",
"#define SPR_FMODE %lu\n" // define_3_AGA_0
"#define BPL_FMODE %lu\n\n"
"#if BPL_FMODE == 1\n"
" #define BPL_FMODE_V 0x0\n"
"#elif BPL_FMODE == 2\n"
" #define BPL_FMODE_V FMODE_BLP32\n"
"#elif BPL_FMODE == 4\n"
" #define BPL_FMODE_V FMODE_BLP32 | FMODE_BPAGEM\n"
"#endif\n\n"
"#if SPR_FMODE == 1\n"
" #define FMODE_V (BPL_FMODE_V)\n"
"#elif SPR_FMODE == 2\n"
" #define FMODE_V (BPL_FMODE_V | FMODE_SPR32)\n"
"#elif SPR_FMODE == 4\n"
" #define FMODE_V (BPL_FMODE_V | FMODE_SPR32 | FMODE_SPAGEM)\n"
"#endif\n",
"///\n", // define_end
" | BPLCON0_HIRES", // define_3_hires
" | BPLCON0_LACE", // define_3_laced
"_SCREEN_DEPTH == 8 ? BPLCON0_BPU3 : ", // define_3_AGA_1
" | USE_BPLCON3", // define_3_AGA_2
"///globals\n" // globals
"// imported globals\n"
"extern struct Custom custom;\n"
"extern struct CIA ciaa, ciab;\n"
"extern volatile LONG new_frame_flag; // from system.o\n"
"extern volatile ULONG g_frame_counter; // from system.o\n"
"extern UWORD NULL_SPRITE_ADDRESS_H; // from display.o\n"
"extern UWORD NULL_SPRITE_ADDRESS_L; // from display.o\n"
"extern struct SpriteBank* g_mouse_sprites; // from display.o\n"
"extern struct GameObject g_mouse_pointer; // from display.o\n"
"extern struct TextFont* textFonts[NUM_TEXTFONTS]; // from fonts.o\n"
"extern struct GameFont* gameFonts[NUM_GAMEFONTS]; // from fonts.o\n"
"// private globals\n"
"STATIC struct RastPort* rastPort = NULL;\n"
"STATIC struct BitMap* bitmap = NULL;\n"
"///\n",
"///copperlist\n" // copperlist_0
"STATIC UWORD* CopperList = (UWORD*) 0;\n\n",
"%sSTATIC UWORD* CL_BPL1PTH = (UWORD*) 0;\n" // copperlist_1
"STATIC UWORD* CL_SPR0PTH = (UWORD*) 0;\n"
"STATIC UWORD* CL_SPR0POS = (UWORD*) 0;\n\n",
"STATIC UWORD* CopperList1 = (UWORD*) 0;\n" // copperlist_1_laced
"STATIC UWORD* CopperList2 = (UWORD*) 0;\n\n"
"%sSTATIC UWORD* CL_BPL1PTH_1 = (UWORD*) 0;\n"
"STATIC UWORD* CL_BPL1PTH_2 = (UWORD*) 0;\n"
"STATIC UWORD* CL_COP2LCH_1 = (UWORD*) 0;\n"
"STATIC UWORD* CL_COP2LCH_2 = (UWORD*) 0;\n"
"STATIC UWORD* CL_COP2LCL_1 = (UWORD*) 0;\n"
"STATIC UWORD* CL_COP2LCL_2 = (UWORD*) 0;\n"
"STATIC UWORD* CL_SPR0PTH_1 = (UWORD*) 0;\n"
"STATIC UWORD* CL_SPR0PTH_2 = (UWORD*) 0;\n"
"STATIC UWORD* CL_SPR0POS_1 = (UWORD*) 0;\n"
"STATIC UWORD* CL_SPR0POS_2 = (UWORD*) 0;\n\n",
"STATIC UWORD* CL_PALETTE = (UWORD*) 0;\n", // copperlist_CLP
"STATIC UWORD* CL_PALETTE_1 = (UWORD*) 0;\n" // copperlist_CLP_laced
"STATIC UWORD* CL_PALETTE_2 = (UWORD*) 0;\n",
"STATIC ULONG copperList_Instructions[] = {\n" // copperlist_2
" // Access Ptr: Action:\n",
" MOVE(BPLCON0, BPLCON0_V), // Set display properties\n"// copperlist_2_disp
" MOVE(BPLCON1, 0), // Set h_scroll register\n"
" MOVE(BPLCON2, 0x264), // Set sprite priorities\n"
" MOVE(BPL1MOD, BPLXMOD_V), // Set bitplane mods\n"
" MOVE(BPL2MOD, BPLXMOD_V), // \" \" \"\n"
" MOVE(DIWSTRT, DIWSTRT_V), // Set Display Window Start\n"
" MOVE(DIWSTOP, DIWSTOP_V), // Set Display Window Stop\n"
" MOVE(DDFSTRT, DDFSTRT_V), // Set Data Fetch Start to fetch early\n"
" MOVE(DDFSTOP, DDFSTOP_V), // Set Data Fetch Stop\n",
" MOVE(FMODE, FMODE_V), // Set Sprite/Bitplane Fetch Modes\n",
" #define BPLI_DEPTH %s_SCREEN_DEPTH\n"
" #include \"bpli.c\" // CL_BPL1PTH Set bitplane addresses\n",
" MOVE_PH(COP2LCH, 0), // CL_COP2LCH Points to the other copper...\n"
" MOVE_PH(COP2LCL, 0), // CL_COP2LCL ...for auto jump every other frame\n",
" WAIT(0, (DIWSTRT_V >> 8) - 1), // Wait for top of display\n"
" #define SPRI_DDFSTRT DDFSTRT_V // CL_SPR0PTH Set sprite pointers\n"
" #include \"spri.c\" // CL_SPR0POS Set sprite pointers\n"
" END\n"
"};\n"
"///\n",
"///colors\n" // colors
"STATIC struct ColorTable* color_table = NULL;\n"
"///\n",
"///protos (private)\n" // protos
"STATIC VOID closeScreen(VOID);\n"
"STATIC VOID closeDisplay(VOID);\n",
"STATIC INLINE VOID %s(struct GameObject* go);\n", // protos_mouse
"///\n\n", // protos_2
"///vblankEvents()\n" // vblank
"STATIC VOID vblankEvents(VOID)\n"
"{\n%s%s"
"}\n"
"///\n",
"///vblankEvents()\n" // vblank_laced
"STATIC VOID vblankEvents(VOID)\n"
"{\n"
" if (CopperList == CopperList2) {\n"
" CopperList = CopperList1;\n"
" }\n"
" else {\n"
" CopperList = CopperList2;\n"
" }\n%s%s"
"}\n"
"///\n",
" setColorTable(color_table);\n", // color_table
" waitVBeam(8);\n" // color_table_CLP
" setColorTable_CLP(color_table, CL_PALETTE, 0, color_table->colors);\n",
" if (CopperList == CopperList1)\n" // color_table_CLP_laced
" setColorTable_CLP(color_table, CL_PALETTE_1, 0, color_table->colors);\n"
" else\n"
" setColorTable_CLP(color_table, CL_PALETTE_2, 0, color_table->colors);\n",
"///openScreen()\n" // screen
"/******************************************************************************\n"
" * Albeit the name, this one does not open a screen. It just allocates a *\n"
" * bitmap and sets up a RastPort for it. A bitmap and a copperlist is enough *\n"
" * for all our displays (except the null_display of course). *\n"
" ******************************************************************************/\n"
"STATIC struct RastPort* openScreen(VOID)\n"
"{\n"
" rastPort = allocRastPort(%s_BITMAP_WIDTH, %s_BITMAP_HEIGHT, %s_BITMAP_DEPTH,\n"
" BMF_STANDARD | BMF_DISPLAYABLE | BMF_CLEAR%s, 0,\n"
" RPF_BITMAP%s%s%s, MAXVECTORS);\n\n"
" if (rastPort) {\n"
" bitmap = rastPort->BitMap;\n"
" }\n\n"
" return rastPort;\n"
"}\n"
"///\n"
"///closeScreen()\n"
"STATIC VOID closeScreen(VOID)\n"
"{\n"
" freeRastPort(rastPort, RPF_ALL);\n"
" rastPort = NULL;\n"
" bitmap = NULL;\n"
"}\n"
"///\n"
"///drawScreen()\n"
"STATIC VOID drawScreen(VOID)\n"
"{\n"
" //DRAW THE INITIAL SCREEN FEATURES HERE!\n\n"
"}\n"
"///\n",
"///createCopperList()\n" // copperlist_functions
"STATIC UWORD* createCopperList(VOID)\n"
"{\n"
" if (allocCopperList(copperList_Instructions, CopperList, CL_SINGLE)) {\n"
" UWORD* wp;\n"
" ULONG i;\n\n"
" //Set copperlist bitmap instruction point to screen bitmap\n"
" for (wp = CL_BPL1PTH, i = 0; i < %s_SCREEN_DEPTH; i++) {\n"
" *wp = (WORD)((ULONG)bitmap->Planes[i] >> 16); wp += 2;\n"
" *wp = (WORD)((ULONG)bitmap->Planes[i] & 0xFFFF); wp += 2;\n"
" }\n\n"
" //Set all sprite pointers to null_sprite\n"
" resetSprites(CL_SPR0PTH, CL_SPR0POS);\n"
" }\n"
" else\n"
" puts(\"Couldn't allocate %s CopperList!\");\n\n"
" return CopperList;\n"
"}\n"
"///\n"
"///disposeCopperList()\n"
"STATIC VOID disposeCopperList(VOID)\n"
"{\n"
" if (CopperList) {\n"
" freeCopperList(CopperList);\n"
" CopperList = NULL;\n"
" }\n"
"}\n"
"///\n",
"///createCopperList()\n" // copperlist_functions_laced
"STATIC UWORD* createCopperList()\n"
"{\n"
" if (allocCopperList(copperList_Instructions, CopperList, CL_DOUBLE)) {\n"
" UWORD* wp;\n"
" ULONG i;\n\n"
" //Set copperlist bitmap instructions point to screen bitmap\n"
" for (wp = CL_BPL1PTH_1, i = 0; i < %s_SCREEN_DEPTH; i++) {\n"
" *wp = (WORD)((ULONG)bitmap->Planes[i] >> 16); wp += 2;\n"
" *wp = (WORD)((ULONG)bitmap->Planes[i] & 0xFFFF); wp += 2;\n"
" }\n\n"
" for (wp = CL_BPL1PTH_2, i = 0; i < %s_SCREEN_DEPTH; i++) {\n"
" *wp = (WORD)(((ULONG)bitmap->Planes[i] + %s_BITMAP_WIDTH%s%s%s / 8) >> 16); wp += 2;\n"
" *wp = (WORD)(((ULONG)bitmap->Planes[i] + %s_BITMAP_WIDTH%s%s%s / 8) & 0xFFFF); wp += 2;\n"
" }\n\n"
" //Set all sprite pointers to null_sprite\n"
" resetSprites(CL_SPR0PTH_1, CL_SPR0POS_1);\n"
" resetSprites(CL_SPR0PTH_2, CL_SPR0POS_2);\n\n"
" //Set both copperlists to point to each other (interlaced copper)\n"
" *CL_COP2LCH_1 = (WORD)((ULONG)CopperList2 >> 16);\n"
" *CL_COP2LCL_1 = (WORD)((ULONG)CopperList2 & 0xFFFF);\n"
" *CL_COP2LCH_2 = (WORD)((ULONG)CopperList1 >> 16);\n"
" *CL_COP2LCL_2 = (WORD)((ULONG)CopperList1 & 0xFFFF);\n"
" }\n"
" else\n"
" puts(\"Couldn't allocate %s CopperList!\");\n\n"
" return CopperList;\n"
"}\n"
"///\n"
"///disposeCopperList()\n"
"STATIC VOID disposeCopperList()\n"
"{\n"
" if (CopperList) {\n"
" freeCopperList(CopperList1);\n"
" CopperList = NULL; CopperList1 = NULL; CopperList2 = NULL;\n"
" }\n"
"}\n"
"///\n",
"///openDisplay()\n" // display
"STATIC BOOL openDisplay(VOID)\n"
"{\n"
" if ((color_table = newColorTable(%s, CT_DEFAULT_STEPS, 0))) {\n"
" color_table->state = CT_FADE_IN;\n"
" if (openScreen()) {\n"
" if (createCopperList()) {\n"
" return TRUE;\n"
" }\n"
" else closeDisplay();\n"
" }\n"
" else closeDisplay();\n"
" }\n\n"
" return FALSE;\n"
"}\n"
"///\n"
"///closeDisplay()\n"
"STATIC VOID closeDisplay(VOID)\n"
"{\n"
" disposeCopperList();\n"
" closeScreen();\n"
" if (color_table) {\n"
" freeColorTable(color_table); color_table = NULL;\n"
" }\n"
"}\n"
"///\n\n",
"///displayLoop()\n" // display_loop_1
"STATIC VOID displayLoop(VOID)\n"
"{\n"
" UWORD exiting = FALSE;\n\n"
" while(TRUE) {\n"
" new_frame_flag = 1;\n\n"
" doKeyboardIO();\n\n",
"///displayLoop()\n" // display_loop_1_moused
"STATIC VOID displayLoop(VOID)\n"
"{\n"
" UWORD exiting = FALSE;\n\n"
" while(TRUE) {\n"
" struct MouseState ms;\n"
" new_frame_flag = 1;\n\n"
" doKeyboardIO();\n"
" UL_VALUE(ms) = readMouse(0);\n\n"
" if (UL_VALUE(ms)) {\n"
" moveGameObjectClamped(&g_mouse_pointer, ms.deltaX, ms.deltaY, 0, 0, %s_SCREEN_WIDTH - 1, %s_SCREEN_HEIGHT - 1);\n"
" }\n\n",
" if (keyState(RAW_ESC) && !exiting) {\n" // display_loop_2
" exiting = TRUE;\n"
" color_table->state = CT_FADE_OUT;\n"
" }\n"
" if (exiting == TRUE && color_table->state == CT_IDLE) {\n"
" break;\n"
" }\n\n"
" updateColorTable(color_table);\n%s"
" waitTOF();\n"
" }\n"
"}\n"
"///\n",
"///switchTo%sCopperList()\n" // switch_functions
"STATIC VOID switchTo%sCopperList(VOID)\n"
"{\n"
" custom.cop2lc = (ULONG)CopperList;\n"
" setVBlankEvents(vblankEvents);\n"
" new_frame_flag = 1;\n"
" waitTOF();\n"
"}\n"
"///\n",
"///switchTo%sCopperList()\n" // switch_functions_laced
"STATIC VOID switchTo%sCopperList(VOID)\n"
"{\n"
" WaitVBeam(299); // We have to wait Copper to set cop2lc on an interlaced display!\n"
" custom.dmacon = DMAF_COPPER; // Disable copperlist DMA so it does not reset our lace bit below!\n"
" custom.bplcon0 = BPLCON0_LACE; // Set LACE bit\n"
" waitTOF(); // Wait until you get a vertical blank\n"
" new_frame_flag = 1;\n\n"
" if (custom.vposr & VPOS_LOF) { // Check if this frame is a long frame or a short frame!\n"
" CopperList = CopperList1;\n"
" custom.cop2lc = (ULONG)CopperList1;\n"
" }\n"
" else {\n"
" CopperList = CopperList2;\n"
" custom.cop2lc = (ULONG)CopperList2;\n"
" }\n\n"
" custom.dmacon = DMAF_SETCLR | DMAF_COPPER; // Reactivate copperlist DMA!\n\n"
" setVBlankEvents(vblankEvents);\n"
" waitTOF();\n"
"}\n"
"///\n",
"///show%sDisplay()\n" // show
"VOID show%sDisplay(VOID)\n"
"{\n"
" if(openDisplay()) {\n"
" drawScreen();\n"
" switchTo%sCopperList();\n"
" displayLoop();\n"
" switchToNullCopperList();\n"
" closeDisplay();\n"
" }\n"
"}\n"
"///\n",
"\n///%s(gameobject)\n" // set_sprite_1
"STATIC INLINE VOID %s(struct GameObject* go)\n"
"{\n"
" LONG x = go->x%s\n"
" LONG y = go->y%s\n\n",
// set_sprite_2
" setSprite((struct SpriteImage*)go->image, x, y, CL_SPR0PTH, CL_SPR0POS, DIWSTRT_V, 0, %s_SCREEN_HEIGHT, 0, SPR_FMODE);\n"
"}\n"
"///",
" if (CopperList == CopperList1)\n" // set_sprite_2_laced
" setSprite((struct SpriteImage*)go->image, x, y, CL_SPR0PTH_1, CL_SPR0POS_1, DIWSTRT_V, 0, %s_SCREEN_HEIGHT, 0, SPR_FMODE);\n"
" else\n"
" setSprite((struct SpriteImage*)go->image, x, y, CL_SPR0PTH_2, CL_SPR0POS_2, DIWSTRT_V, 0, %s_SCREEN_HEIGHT, 0, SPR_FMODE);\n"
"}\n"
"///",
" / 2; // Convert to hardware sprite resolution", // convert_hsr
"#ifndef %s_DISPLAY_H\n" // header_file
"#define %s_DISPLAY_H\n\n"
"VOID show%sDisplay(VOID);\n\n"
"#endif /* %s_DISPLAY_H */"
};
///
///Structs
struct PaletteItem {
STRPTR name;
UBYTE* palette;
};
struct cl_ObjTable
{
Object* str_name;
Object* int_scrWidth;
Object* int_scrHeight;
Object* int_scrDepth;
Object* txt_palette;
Object* pop_palette;
Object* int_sprFetchMode;
Object* int_bplFetchMode;
Object* chk_AGA;
Object* chk_interleaved;
Object* chk_hires;
Object* chk_interlaced;
Object* chk_Layer;
Object* chk_TmpRas;
Object* chk_Area;
Object* int_maxvectors;
Object* chk_pltOnCL;
Object* chk_implMouse;
Object* btn_create;
Object* btn_cancel;
};
struct cl_Data
{
struct cl_ObjTable obj_table;
Object* AGACheck;
Object* CLPCheck;
UBYTE* palette;
Object* palette_selector;
BOOL subscribed_to_palette_selector;
};
struct cl_Msg
{
ULONG MethodID;
//<SUBCLASS METHOD MESSAGE PAYLOAD HERE>
};
struct cl_Msg3
{
ULONG MethodID;
struct PaletteItem* palette_item;
};
///
///isCamelCase(str)
BOOL isCamelCase(STRPTR str)
{
BOOL upper_case_found = FALSE;
BOOL lower_case_found = FALSE;
UBYTE* c = str;
while (*c) {
if (*c >= 'A' && *c <= 'Z') upper_case_found = TRUE;
if (*c >= 'a' && *c <= 'z') lower_case_found = TRUE;
c++;
}
return upper_case_found && lower_case_found;
}
///
///isBlackListed(str)
BOOL isBlackListed(STRPTR str)
{
STRPTR* bl_item = black_list;
while (*bl_item) {
STRPTR c = str;
STRPTR b = *bl_item;
while (*c) {
UBYTE ch = *c;
if (ch >= 'A' && ch <= 'Z') ch += 32;
if (ch != *b) goto next;
c++;
b++;
}
if (*b == NULL) return TRUE;
next:
bl_item++;
}
return FALSE;
}
///
///createPaletteSection(file_handle, num_colors, aga)
/******************************************************************************
* Creates a literal CLP section. *
******************************************************************************/
VOID createPaletteSection(BPTR fh, ULONG num_colors, BOOL aga)
{
if (aga) {
ULONG num_banks = (num_colors + 31) / 32;
ULONG c, r, b;
for (b = 0, c = 0; b < num_banks; b++) {
if (b == 0)
FPrintf(fh, " MOVE_PH(BPLCON3, BPLCON3_V), // CL_PALETTE Palette Colors AGA (bank 0)\n");
else
FPrintf(fh, " MOVE(BPLCON3, BPLCON3_V | (%lu << 13)), // bank %lu\n", b, b);
for (r = 0; r < 32 && c < num_colors; r++, c++) {
FPrintf(fh, " MOVE(COLOR%02lu, 0x0), //\n", r);
}
}
for (b = 0, c = 0; b < num_banks; b++) {
if (b == 0)
FPrintf(fh, " MOVE(BPLCON3, BPLCON3_V | BPLCON3_LOCT), // bank 0 LOCT\n");
else
FPrintf(fh, " MOVE(BPLCON3, BPLCON3_V | BPLCON3_LOCT | (%lu << 13)), // bank %lu LOCT\n", b, b);
for (r = 0, c = 0; r < 32 && c < num_colors; r++, c++) {
FPrintf(fh, " MOVE(COLOR%02lu, 0x0), //\n", r);
}
}
}
else {
ULONG c;
FPrintf(fh, " MOVE_PH(COLOR00, 0x0), // CL_PALETTE Palette Colors OCS/ECS\n");
for (c = 1; c < num_colors; c++) {
FPrintf(fh, " MOVE(COLOR%02lu, 0x0), //\n", c);
}
}
}
///
///m_CheckValidity()
STATIC ULONG m_CheckValidity(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
STRPTR name;
ULONG depth;
UBYTE* palette = data->palette;
get(data->obj_table.str_name, MUIA_String_Contents, &name);
get(data->obj_table.int_scrDepth, MUIA_Integer_Value, &depth);
if (name && strlen(name) && *name != ' ' && !(*name >= '0' && *name <= '9') &&
!isBlackListed(name) && palette && *palette + 1 == 1 << depth) {
DoMethod(data->obj_table.btn_create, MUIM_Set, MUIA_Disabled, FALSE);
}
else {
DoMethod(data->obj_table.btn_create, MUIM_Set, MUIA_Disabled, TRUE);
}
return 0;
}
///
///m_OpenPaletteSelector()
STATIC ULONG m_OpenPaletteSelector(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
DoMethod(obj, MUIM_Set, MUIA_Window_Sleep, TRUE);
data->subscribed_to_palette_selector = TRUE;
DoMethod(data->palette_selector, MUIM_Set, MUIA_Window_Open, TRUE);
return 0;
}
///
///m_SetPalette()
STATIC ULONG m_SetPalette(struct IClass* cl, Object* obj, struct cl_Msg3* msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
if (data->subscribed_to_palette_selector) {
DoMethod(data->obj_table.txt_palette, MUIM_Set, MUIA_Text_Contents, msg->palette_item->name);
data->palette = msg->palette_item->palette;
DoMethod(data->obj_table.int_scrDepth, MUIM_Set, MUIA_Integer_Value, colors2depth((*data->palette + 1)));
m_CheckValidity(cl, obj, (Msg)msg);
data->subscribed_to_palette_selector = FALSE;
}
return 0;
}
///
///m_Create()
STATIC ULONG m_Create(struct IClass* cl, Object* obj, Msg msg)
{
struct cl_Data *data = INST_DATA(cl, obj);
STRPTR null = (STRPTR)"";
STRPTR str_name;
ULONG scr_width;
ULONG scr_height;
ULONG scr_depth;
STRPTR palette;
ULONG spr_fmode;
ULONG bpl_fmode;
ULONG AGA;
ULONG interleaved;
ULONG hires;
ULONG interlaced;
ULONG layer;
ULONG tmpras;
ULONG area;
ULONG maxvectors;
ULONG pltOnCL;
ULONG implMouse;
ULONG project_AGA;
STRPTR name;
STRPTR Name;
STRPTR NAME;
STRPTR filename;
STRPTR filename_c;
STRPTR filename_h;
STRPTR setSpriteFuncName;
STRPTR setSpriteFuncCall;
BPTR fh;
ULONG file_mode_c = MODE_NEWFILE;
ULONG file_mode_h = MODE_NEWFILE;
BOOL failure = FALSE;
get(data->obj_table.str_name, MUIA_String_Contents, &str_name);
get(data->obj_table.int_scrWidth, MUIA_Integer_Value, &scr_width);
get(data->obj_table.int_scrHeight, MUIA_Integer_Value, &scr_height);
get(data->obj_table.int_scrDepth, MUIA_Integer_Value, &scr_depth);
get(data->obj_table.txt_palette, MUIA_Text_Contents, &palette);
get(data->obj_table.int_sprFetchMode, MUIA_Integer_Value, &spr_fmode);
get(data->obj_table.int_bplFetchMode, MUIA_Integer_Value, &bpl_fmode);
get(data->obj_table.chk_AGA, MUIA_Selected, &AGA);
get(data->obj_table.chk_interleaved, MUIA_Selected, &interleaved);
get(data->obj_table.chk_hires, MUIA_Selected, &hires);
get(data->obj_table.chk_interlaced, MUIA_Selected, &interlaced);
get(data->obj_table.chk_Layer, MUIA_Selected, &layer);
get(data->obj_table.chk_TmpRas, MUIA_Selected, &tmpras);
get(data->obj_table.chk_Area, MUIA_Selected, &area);
get(data->obj_table.int_maxvectors, MUIA_Integer_Value, &maxvectors);
get(data->obj_table.chk_pltOnCL, MUIA_Selected, &pltOnCL);
get(data->obj_table.chk_implMouse, MUIA_Selected, &implMouse);
get(data->AGACheck, MUIA_Selected, &project_AGA);
if (str_name) {
UBYTE name_initial[2] = {0};
DoMethod(obj, MUIM_Set, MUIA_Window_Sleep, TRUE);
//Prepare name strings
str_name = makeString(str_name);
replaceChars(str_name, " ", '_');
name = makeString(str_name);
Name = makeString(str_name);
NAME = makeString(str_name);
if (isCamelCase(str_name)) {
if (*str_name >= 'a') *Name -= 32;
toLower(name);
toUpper(NAME);
}
else {
toLower(name);
toLower(Name); *Name -= 32;
toUpper(NAME);
}
*name_initial = *Name;
filename = makeString2("display_", name);
filename_c = makePath(g_Project.directory, filename, ".c");
filename_h = makePath(g_Project.directory, filename, ".h");
if (implMouse) {
setSpriteFuncName = makeString2(name_initial, "D_setSprite");
setSpriteFuncCall = makeString3(" ", name_initial, "D_setSprite(&g_mouse_pointer);\n");
}
else {
setSpriteFuncName = "";
setSpriteFuncCall = "";
}
//Open .c file for output
if (Exists(filename_c)) {
if (!MUI_Request(App, obj, NULL, "Display Creator", "*_Overwrite|_Cancel", "A display with this name exists!")) {
goto cancel;
}
file_mode_c = MODE_OLDFILE;
if (Exists(filename_h)) file_mode_h = MODE_OLDFILE;
}
fh = Open(filename_c, file_mode_c);
if (fh) {
//Write includes
FPrintf(fh, code_string.includes, (LONG)(AGA ? code_string.include_AGA : null), (LONG)name);
//Write defines
FPrintf(fh, code_string.define_1, (LONG)NAME, (LONG)scr_width, (LONG)NAME, (LONG)scr_height, (LONG)NAME, (LONG)scr_depth,
(LONG)NAME, (LONG)NAME, (LONG)NAME, (LONG)NAME, (LONG)NAME, (LONG)NAME, (LONG)NAME, (LONG)NAME);
if (interleaved)
FPrintf(fh, code_string.define_2_interleaved, (LONG)NAME, (LONG)NAME, (LONG)(interlaced ? (STRPTR)" * 2" : null));
else {
if (interlaced)
FPrintf(fh, code_string.define_2, (LONG)NAME);
else
FPrintf(fh, "#define BPLXMOD_V 0\n\n");
}
FPrintf(fh, code_string.define_3, (LONG)(AGA ? NAME : null), (LONG)(AGA ? code_string.define_3_AGA_1 : null), (LONG)NAME,
(LONG)(hires ? code_string.define_3_hires : null),
(LONG)(interlaced ? code_string.define_3_laced : null),
(LONG)(AGA ? code_string.define_3_AGA_2 : null),
(LONG)maxvectors);
if (AGA)
FPrintf(fh, code_string.define_3_AGA_0, spr_fmode, bpl_fmode);
FPrintf(fh, code_string.define_end);
//Write globals
FPrintf(fh, code_string.globals);
//Write Copperlist
FPrintf(fh, code_string.copperlist_0);
if (interlaced) FPrintf(fh, code_string.copperlist_1_laced, pltOnCL ? (LONG)code_string.copperlist_CLP_laced : (LONG)"");
else FPrintf(fh, code_string.copperlist_1, pltOnCL ? (LONG)code_string.copperlist_CLP : (LONG)"");
//Write Copperlist array
FPrintf(fh, code_string.copperlist_2);
if (pltOnCL) {
if (AGA != project_AGA)
createPaletteSection(fh, 1 << scr_depth, AGA);
else
FPrintf(fh," #define CLP_DEPTH %s_SCREEN_DEPTH\n #include \"clp.c\"\n", (LONG)NAME);
}
if (AGA) FPrintf(fh, code_string.copperlist_2_AGA);
FPrintf(fh, code_string.copperlist_2_disp);
FPrintf(fh, code_string.copperlist_bitplanes, (LONG)NAME);
if (interlaced) FPrintf(fh, code_string.copperlist_2_laced);
FPrintf(fh, code_string.copperlist_3);
//Write color table
FPrintf(fh, code_string.colors);
//Write protos
FPrintf(fh, code_string.protos);
if (implMouse) FPrintf(fh, code_string.protos_mouse, (LONG)setSpriteFuncName);
FPrintf(fh, code_string.protos_2);
//Write vblankEvents function
if (interlaced) {
if (pltOnCL) FPrintf(fh, code_string.vblank_laced, (LONG)"", (LONG)setSpriteFuncCall);
else FPrintf(fh, code_string.vblank_laced, (LONG)code_string.color_table, (LONG)setSpriteFuncCall);
}
else {
if (pltOnCL) FPrintf(fh, code_string.vblank, (LONG)"", (LONG)setSpriteFuncCall);
else FPrintf(fh, code_string.vblank, (LONG)code_string.color_table, (LONG)setSpriteFuncCall);
}
//Write screen functions
FPrintf(fh, code_string.screen, (LONG)NAME, (LONG)NAME, (LONG)NAME,
(LONG)(interleaved ? (STRPTR)" | BMF_INTERLEAVED" : null),
(LONG)(layer ? (STRPTR)" | RPF_LAYER" : null),
(LONG)(tmpras ? (STRPTR)" | RPF_TMPRAS" : null),
(LONG)(area ? (STRPTR)" | RPF_AREA" : null));
//Write copperlist functions
if (interlaced)
FPrintf(fh, code_string.copperlist_functions_laced, (LONG)NAME, (LONG)NAME,
(LONG)NAME, (LONG)(interleaved ? (STRPTR)" * " : null),
(LONG)(interleaved ? NAME : null),
(LONG)(interleaved ? (STRPTR)"_BITMAP_DEPTH" : null),
(LONG)NAME, (LONG)(interleaved ? (STRPTR)" * " : null),
(LONG)(interleaved ? NAME : null),
(LONG)(interleaved ? (STRPTR)"_BITMAP_DEPTH" : null),
(LONG)Name);
else
FPrintf(fh, code_string.copperlist_functions, (LONG)NAME, (LONG)Name);
//Write display functions
FPrintf(fh, code_string.display, (LONG)palette);
//Write displayLoop() function
if (implMouse)
FPrintf(fh, code_string.display_loop_1_moused, (LONG)NAME, (LONG)NAME);
else
FPrintf(fh, code_string.display_loop_1);
FPrintf(fh, code_string.display_loop_2, pltOnCL ? (interlaced ? (LONG)code_string.color_table_CLP_laced : (LONG)code_string.color_table_CLP) : (LONG)"");
//Write switch function
FPrintf(fh, interlaced ? code_string.switch_functions_laced : code_string.switch_functions, (LONG)Name, (LONG)Name);
//Write show function
FPrintf(fh, code_string.show, (LONG)Name, (LONG)Name, (LONG)Name);
if (implMouse) {
FPrintf(fh, code_string.set_sprite_1, (LONG)setSpriteFuncName, (LONG)setSpriteFuncName, hires ? (LONG)code_string.convert_hsr : (LONG)";",
interlaced ? (LONG)code_string.convert_hsr : (LONG)";");
if (interlaced)
FPrintf(fh, code_string.set_sprite_2_laced, (LONG)NAME, (LONG)NAME);
else
FPrintf(fh, code_string.set_sprite_2, (LONG)NAME);
}
SetFileSize(fh, 0, OFFSET_CURRENT);
Close(fh);
fh = Open(filename_h, file_mode_h);
if (fh) {
FPrintf(fh, code_string.header_file, (LONG)NAME, (LONG)NAME, (LONG)Name, (LONG)NAME);
SetFileSize(fh, 0, OFFSET_CURRENT);
Close(fh);
}
else {
DeleteFile(filename_c);
failure = TRUE;
}
}