forked from sylverb/game-and-watch-retro-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.common
1194 lines (1027 loc) · 44.3 KB
/
Makefile.common
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
######################################
# building variables
######################################
# debug build?
DEBUG ?= 1
# optimization
OPT ?= -Og
# Set to 0 to suppress dirty submodule warning
CHECK_DIRTY_SUBMODULE ?= 1
# Set to 0 to skip tools check
CHECK_TOOLS ?= 1
# Set to 1 to enable 16MB external flash support. (deprecated, use EXTFLASH_SIZE_MB instead!)
LARGE_FLASH ?= 0
# Configure where data is stored in the external flash by
# setting EXTFLASH_OFFSET. Useful if the first 1MB are to be preserved.
EXTFLASH_OFFSET ?= 0
ifneq ($(shell echo "$$(( $(EXTFLASH_OFFSET) % 4096 ))"), 0)
$(error Invalid EXTFLASH_OFFSET, should be aligned to a 4KB sector)
endif
# Configure Game & Watch target device mario|zelda
ifneq ($(findstring flash,$(MAKECMDGOALS)),flash)
GNW_TARGET ?= mario
endif
OFF_SAVESTATE = 0
ifeq ($(SHARED_HIBERNATE_SAVESTATE),1)
OFF_SAVESTATE = 1
endif
# Configure Game & Watch target device mario|zelda
# Set the preprocessor options
ifeq ($(GNW_TARGET),mario)
GNW_TARGET_ZELDA = 0
GNW_TARGET_MARIO = 1
else ifeq ($(GNW_TARGET),zelda)
GNW_TARGET_ZELDA = 1
GNW_TARGET_MARIO = 0
else
$(error Missing or invalid GNW_TARGET option. Valid values {mario|zelda})
endif
# Disable system logos splash screen at startup
DISABLE_SPLASH_SCREEN ?= 0
# Default NES emulator is fceumm
FORCE_NOFRENDO ?= 0
NOFRENDO_PARAM := --nofrendo=$(FORCE_NOFRENDO)
# Configure external flash size by setting EXTFLASH_SIZE
ifeq ($(LARGE_FLASH),1)
# 16MB
EXTFLASH_SIZE_MB ?= 16
else
# 4MB for Zelda otherwise 1MB
ifeq ($(GNW_TARGET),zelda)
EXTFLASH_SIZE_MB ?= 4
else
EXTFLASH_SIZE_MB ?= 1
endif
endif
# Configure INTFLASH_BANK and INTFLASH_ADDRESS
ifdef INTFLASH_ADDRESS
INTFLASH_ADDRESS_DECIMAL = $(shell printf "%d" $(INTFLASH_ADDRESS))
ifdef INTFLASH_BANK
# defined INTFLASH_ADDRESS INTFLASH_BANK
# Sanity check that INTFLASH_ADDRESS and INTFLASH_BANK agree
ifeq ($(shell [ $(INTFLASH_ADDRESS_DECIMAL) -ge 134217728 -a $(INTFLASH_ADDRESS_DECIMAL) -lt 135266304 ] && echo true),true)
# INTFLASH_ADDRESS is in range [0x08000000, 0x08100000)
ifneq ($(INTFLASH_BANK),1)
$(error Inconsistent INTFLASH_BANK=$(INTFLASH_BANK) and INTFLASH_ADDRESS=$(INTFLASH_ADDRESS))
endif
else
ifneq ($(INTFLASH_BANK),2)
$(error Inconsistent INTFLASH_BANK=$(INTFLASH_BANK) and INTFLASH_ADDRESS=$(INTFLASH_ADDRESS))
endif
endif
else # ifdef INTFLASH_BANK
# defined INTFLASH_ADDRESS; not defined INTFLASH_BANK
# Derive flashbank from INTFLASH_ADDRESS
ifeq ($(shell [ $(INTFLASH_ADDRESS_DECIMAL) -ge 134217728 -a $(INTFLASH_ADDRESS_DECIMAL) -lt 135266304 ] && echo true),true)
# INTFLASH_ADDRESS is in range [0x08000000, 0x08100000)
INTFLASH_BANK = 1
else
INTFLASH_BANK = 2
endif
endif
else # ifdef INTFLASH_ADDRESS
ifdef INTFLASH_BANK
# not defined INTFLASH_ADDRESS; defined INTFLASH_BANK
ifeq ($(INTFLASH_BANK),1)
INTFLASH_ADDRESS = 0x08000000
else
INTFLASH_ADDRESS = 0x08100000
endif
else # ifdef INTFLASH_BANK
# not defined INTFLASH_ADDRESS INTFLASH_BANK
INTFLASH_ADDRESS = 0x08000000
INTFLASH_BANK = 1
endif
endif
# Configure external flash size in MB (Megabytes)
EXTFLASH_SIZE_MB ?= 1
BIG_BANK ?= 1
EXTFLASH_SIZE ?= $(shell echo "$$(( $(EXTFLASH_SIZE_MB) * 1024 * 1024 ))")
ifneq ($(shell echo "$$(( $(EXTFLASH_SIZE) % 4096 ))"), 0)
$(error Invalid EXTFLASH_SIZE, should be aligned to a 4KB sector)
endif
EXTFLASH_FORCE_SPI ?= 0
# Set to 0 to remove state saving support (uses less space)
STATE_SAVING ?= 1
ifeq ($(STATE_SAVING),0)
SAVE_PARAM := --no-save
endif
# Screenshot support allocates 150kB of external flash. Disabled by default.
ENABLE_SCREENSHOT ?= 0
# Set to 1 to add game genie support
CHEAT_CODES ?= 0
ifeq ($(GAME_GENIE),1)
CHEAT_CODES = 1
endif
# Compress supported ROMs by default. Set to 0 to disable.
COMPRESS ?= lzma
ifeq ($(COMPRESS),0)
COMPRESS_PARAM :=
else
COMPRESS_PARAM := --compress=$(COMPRESS)
endif
# Reset the DBGMCU configuration register (DBGMCU_CR) after flashing
# Set to 0 to keep the clocks running when suspended (makes debugging easier)
RESET_DBGMCU ?= 1
ifeq ($(RESET_DBGMCU),1)
RESET_DBGMCU_CMD = $(MAKE) reset_dbgmcu
else
RESET_DBGMCU_CMD = $(MAKE) reset_mcu
endif
PYTHON3 ?= /usr/bin/env python3
#######################################
# paths
#######################################
# Build path
BUILD_DIR ?= build
#######################################
# i18n Codepage
#######################################
CODEPAGE ?= 1252
ES_ES ?= 1
PT_PT ?= 1
FR_FR ?= 1
IT_IT ?= 1
RU_RU ?= 1
DE_DE ?= 1
ZH_CN ?= 0
ZH_TW ?= 0
KO_KR ?= 0
JA_JP ?= 0
SCODEPAGE = "ascii"
ifeq ($(CODEPAGE), 936)
SCODEPAGE = "gbk"
ZH_CN = 1
else ifeq ($(CODEPAGE), 950)
SCODEPAGE = "big5"
ZH_TW = 1
else ifeq ($(CODEPAGE), 932)
SCODEPAGE = "eucjp"
JA_JP = 1
else ifeq ($(CODEPAGE), 949)
KO_KR = 1
SCODEPAGE = "euckr"
else ifeq ($(CODEPAGE), 12511)
RU_RU = 1
SCODEPAGE = "windows-1251"
else ifeq ($(CODEPAGE), 12521)
ES_ES = 1
SCODEPAGE = "iso-8859-1"
else ifeq ($(CODEPAGE), 12522)
PT_PT = 1
SCODEPAGE = "iso-8859-1"
else ifeq ($(CODEPAGE), 12523)
FR_FR = 1
SCODEPAGE = "iso-8859-1"
else ifeq ($(CODEPAGE), 12524)
IT_IT = 1
SCODEPAGE = "iso-8859-1"
else ifeq ($(CODEPAGE), 12521)
RU_RU = 1
SCODEPAGE = "iso-8859-5"
else ifeq ($(CODEPAGE), 12525)
DE_DE = 1
SCODEPAGE = "iso-8859-1"
else
SCODEPAGE = "iso-8859-1"
endif
UICODEPAGE ?= CODEPAGE
ifeq ($(UICODEPAGE), 936)
ZH_CN = 1
else ifeq ($(UICODEPAGE), 950)
ZH_TW = 1
else ifeq ($(UICODEPAGE), 932)
JA_JP = 1
else ifeq ($(UICODEPAGE), 949)
KO_KR = 1
else ifeq ($(UICODEPAGE), 12521)
ES_ES = 1
else ifeq ($(UICODEPAGE), 12522)
PT_PT = 1
else ifeq ($(UICODEPAGE), 12523)
FR_FR = 1
else ifeq ($(UICODEPAGE), 12524)
IT_IT = 1
else ifeq ($(UICODEPAGE), 12521)
RU_RU = 1
else ifeq ($(UICODEPAGE), 12525)
DE_DE = 1
endif
ROMINFOCODE ?= $(SCODEPAGE)
CODEPAGE_PARAM := --codepage=$(ROMINFOCODE)
#######################################
# MSX
#######################################
MSX_USE_BANK_2 ?= 0
#######################################
# cover flow
#######################################
COVERFLOW ?= 0
ifdef COVERFLOW
COVERFLOW_PARAM := --coverflow=$(COVERFLOW)
endif
JPG_QUALITY ?= 90
JPG_QUALITY_PARAM := --jpg_quality=$(JPG_QUALITY)
# Common C sources
C_SOURCES += \
retro-go-stm32/retro-go/main/gui.c \
Core/Src/porting/gw_alloc.c \
Core/Src/retro-go/rg_main.c \
Core/Src/retro-go/rg_rtc.c \
Core/Src/retro-go/rg_emulators.c \
Core/Src/retro-go/rom_manager.c \
Core/Src/porting/odroid_settings.c \
Core/Src/retro-go/i18n/rg_i18n.c \
Core/Src/retro-go/rg_logos.c
# Version and URL for the STM32CubeH7 SDK
SDK_VERSION ?= v1.8.0
SDK_URL ?= https://raw.githubusercontent.com/STMicroelectronics/STM32CubeH7
# Local path for the SDK
SDK_DIR ?= Drivers
# SDK C sources
SDK_C_SOURCES = \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dac_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dac.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma2d.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_jpeg.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ospi.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sai_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sai.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_wwdg.c \
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c \
# SDK ASM sources
SDK_ASM_SOURCES = \
Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h7b0xx.s \
Core/Src/memcpy-armv7m.s
# SDK headers
SDK_HEADERS = \
Drivers/CMSIS/Device/ST/STM32H7xx/Include/stm32h7b0xx.h \
Drivers/CMSIS/Device/ST/STM32H7xx/Include/stm32h7xx.h \
Drivers/CMSIS/Device/ST/STM32H7xx/Include/system_stm32h7xx.h \
Drivers/CMSIS/Include/cmsis_compiler.h \
Drivers/CMSIS/Include/cmsis_gcc.h \
Drivers/CMSIS/Include/cmsis_version.h \
Drivers/CMSIS/Include/core_cm7.h \
Drivers/CMSIS/Include/mpu_armv7.h \
Drivers/STM32H7xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_adc.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_cortex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_dac_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_dac.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_def.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_dma_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_dma.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_dma2d.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_exti.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_flash_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_flash.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_gpio_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_gpio.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_hsem.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_i2c_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_i2c.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_jpeg.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_ltdc_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_ltdc.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_mdma.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_ospi.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_pwr_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_pwr.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_rcc_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_rcc.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_rtc_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_rtc.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_sai_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_sai.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_spi_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_spi.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_tim.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_tim_ex.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_wwdg.h \
Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal.h \
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
# either it can be added to the PATH environment variable.
ifdef GCC_PATH
CC = $(GCC_PATH)/$(PREFIX)gcc
AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp
CP = $(GCC_PATH)/$(PREFIX)objcopy
SZ = $(GCC_PATH)/$(PREFIX)size
GDB = $(GCC_PATH)/$(PREFIX)gdb
DUMP = $(GCC_PATH)/$(PREFIX)objdump
else
CC = $(PREFIX)gcc
AS = $(PREFIX)gcc -x assembler-with-cpp
CP = $(PREFIX)objcopy
SZ = $(PREFIX)size
GDB = $(PREFIX)gdb
DUMP = $(PREFIX)objdump
endif
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
ECHO = echo
TOUCH = touch
#######################################
# CFLAGS
#######################################
# cpu
CPU = -mcpu=cortex-m7 -mtune=cortex-m7
# fpu
FPU = -mfpu=fpv5-d16
# float-abi
FLOAT-ABI = -mfloat-abi=hard
# mcu
MCU = $(CPU) -mthumb -mno-unaligned-access $(FPU) $(FLOAT-ABI)
# macros for gcc
# AS defines
AS_DEFS +=
# C defines
C_DEFS += \
-D_GNU_SOURCE \
-DINTFLASH_BANK=$(INTFLASH_BANK) \
-DINTFLASH_ADDRESS=$(INTFLASH_ADDRESS) \
-DBIG_BANK=$(BIG_BANK) \
-DEXTFLASH_SIZE=$(EXTFLASH_SIZE) \
-DMSX_USE_BANK_2=$(MSX_USE_BANK_2) \
-DOFF_SAVESTATE=$(OFF_SAVESTATE) \
-DCODEPAGE=$(CODEPAGE) \
-DUICODEPAGE=$(UICODEPAGE) \
-DINCLUDED_ES_ES=$(ES_ES) \
-DINCLUDED_PT_PT=$(PT_PT) \
-DINCLUDED_FR_FR=$(FR_FR) \
-DINCLUDED_IT_IT=$(IT_IT) \
-DINCLUDED_DE_DE=$(DE_DE) \
-DINCLUDED_RU_RU=$(RU_RU) \
-DINCLUDED_ZH_CN=$(ZH_CN) \
-DINCLUDED_ZH_TW=$(ZH_TW) \
-DINCLUDED_KO_KR=$(KO_KR) \
-DINCLUDED_JA_JP=$(JA_JP) \
-DLANG=$(LANG) \
-DCOVERFLOW=$(COVERFLOW) \
-DEXTFLASH_FORCE_SPI=$(EXTFLASH_FORCE_SPI) \
-DUSE_HAL_DRIVER \
-DSTM32H7B0xx \
-DIS_LITTLE_ENDIAN \
-DMINIZ_NO_MALLOC \
-DMINIZ_NO_ZLIB_APIS \
-DDEBUG_RG_ALLOC \
-DSTATE_SAVING=$(STATE_SAVING) \
-DENABLE_SCREENSHOT=$(ENABLE_SCREENSHOT) \
-DGNW_TARGET_MARIO=$(GNW_TARGET_MARIO) \
-DGNW_TARGET_ZELDA=$(GNW_TARGET_ZELDA) \
-DCHEAT_CODES=$(CHEAT_CODES) \
-DFORCE_NOFRENDO=$(FORCE_NOFRENDO) \
-DDISABLE_SPLASH_SCREEN=$(DISABLE_SPLASH_SCREEN) \
-DTARGET_GNW \
-DNO_EMBEDDED_SAMPLES \
-D__LIBRETRO__ \
-DZ80_CUSTOM_CONFIGURATION \
-DMSX_NO_ZIP \
-DMSX_NO_FILESYSTEM \
-DMSX_NO_MALLOC \
-DMAX_VIDEO_WIDTH_320 \
-DPIXEL_WIDTH=8 \
-DMSX_NO_STEREO \
-DFCEU_VERSION_NUMERIC=9813 \
-DFCEU_LOW_RAM \
-DFCEU_NO_MALLOC \
# AS includes
AS_INCLUDES +=
# C includes
C_INCLUDES += \
-ICore/Inc \
-ICore/Inc/porting \
-ICore/Inc/porting/gb \
-ICore/Inc/porting/nes \
-ICore/Inc/porting/nes_fceu \
-ICore/Inc/porting/smsplusgx \
-ICore/Inc/porting/pce \
-ICore/Inc/porting/msx \
-ICore/Inc/porting/wsv \
-ICore/Inc/porting/gw \
-ICore/Inc/porting/gwenesis \
-ICore/Inc/porting/a7800 \
-ICore/Inc/porting/amstrad \
-ICore/Inc/porting/zelda3 \
-ICore/Inc/porting/smw \
-ICore/Inc/porting/tama \
-ICore/Inc/retro-go \
-IDrivers/STM32H7xx_HAL_Driver/Inc \
-IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32H7xx/Include \
-IDrivers/CMSIS/Include \
-Iretro-go-stm32/components/lupng \
# Force include the configuration
CFLAGS += $(CFLAGS_EXTRA) -include $(BUILD_DIR)/config.h
# compile gcc flags
ASFLAGS += $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2
endif
CFLAGS += -fstack-usage -Wstack-usage=20480
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
LDFLAGS += -Wl,--defsym=__EXTFLASH_OFFSET__=$(EXTFLASH_OFFSET)
LDFLAGS += -Wl,--defsym=__EXTFLASH_TOTAL_LENGTH__=$(EXTFLASH_SIZE)
LDFLAGS += -Wl,--defsym=ENABLE_SCREENSHOT=$(ENABLE_SCREENSHOT)
LDFLAGS += -Wl,--defsym=__INTFLASH__=$(INTFLASH_ADDRESS)
ifeq ($(BIG_BANK), 1)
FLASH_LENGTH = 256k
else
FLASH_LENGTH = 128k
endif
LDFLAGS += -Wl,--defsym=__FLASH_LENGTH__=$(FLASH_LENGTH)
#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT ?= STM32H7B0VBTx_FLASH.ld
# libraries
LIBS = -lc -lm -lnosys
LIBDIR +=
LDFLAGS += $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
# default action: build all
all: CheckTools CheckDirtySubmodules $(BUILD_DIR) $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET)_extflash.bin $(BUILD_DIR)/$(TARGET)_intflash.bin $(BUILD_DIR)/$(TARGET)_intflash2.bin
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/core/,$(notdir $(C_SOURCES:.c=.o) $(SDK_C_SOURCES:.c=.o)))
GNUBOY_OBJECTS = $(addprefix $(BUILD_DIR)/gnuboy/,$(notdir $(GNUBOY_C_SOURCES:.c=.o)))
NES_OBJECTS = $(addprefix $(BUILD_DIR)/nes/,$(notdir $(NES_C_SOURCES:.c=.o)))
NES_FCEU_OBJECTS = $(addprefix $(BUILD_DIR)/nes_fceu/,$(notdir $(NES_FCEU_C_SOURCES:.c=.o)))
SMSPLUSGX_OBJECTS = $(addprefix $(BUILD_DIR)/smsplusgx/,$(notdir $(SMSPLUSGX_C_SOURCES:.c=.o)))
PCE_OBJECTS = $(addprefix $(BUILD_DIR)/pce/,$(notdir $(PCE_C_SOURCES:.c=.o)))
GW_OBJECTS = $(addprefix $(BUILD_DIR)/gw/,$(notdir $(GW_C_SOURCES:.c=.o)))
MSX_OBJECTS = $(addprefix $(BUILD_DIR)/msx/,$(notdir $(MSX_C_SOURCES:.c=.o)))
WSV_OBJECTS = $(addprefix $(BUILD_DIR)/wsv/,$(notdir $(WSV_C_SOURCES:.c=.o)))
MD_OBJECTS = $(addprefix $(BUILD_DIR)/md/,$(notdir $(MD_C_SOURCES:.c=.o)))
A7800_OBJECTS = $(addprefix $(BUILD_DIR)/a7800/,$(notdir $(A7800_C_SOURCES:.c=.o)))
AMSTRAD_OBJECTS = $(addprefix $(BUILD_DIR)/amstrad/,$(notdir $(AMSTRAD_C_SOURCES:.c=.o)))
ZELDA3_OBJECTS = $(addprefix $(BUILD_DIR)/zelda3/,$(notdir $(ZELDA3_C_SOURCES:.c=.o)))
SMW_OBJECTS = $(addprefix $(BUILD_DIR)/smw/,$(notdir $(SMW_C_SOURCES:.c=.o)))
TAMA_OBJECTS = $(addprefix $(BUILD_DIR)/tama/,$(notdir $(TAMA_C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES) $(NES_C_SOURCES) $(NES_FCEU_C_SOURCES) $(GNUBOY_C_SOURCES) $(SMSPLUSGX_C_SOURCES) $(PCE_C_SOURCES) $(MSX_C_SOURCES) $(GW_C_SOURCES) $(WSV_C_SOURCES) $(MD_C_SOURCES) $(A7800_C_SOURCES) $(AMSTRAD_C_SOURCES) $(ZELDA3_C_SOURCES) $(SMW_C_SOURCES) $(TAMA_C_SOURCES) $(SDK_C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(SDK_ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(SDK_ASM_SOURCES)))
OBJECTS += $(addprefix $(BUILD_DIR)/,roms.a)
# function used to generate prerequisite rules for SDK objects
define sdk_obj_prereq_gen
$(BUILD_DIR)/$(patsubst %.c,%.o,$(patsubst %.s,%.o,$(notdir $1))): $1
endef
# note: the blank line above is intentional
# generate all object prerequisite rules
$(eval $(foreach obj,$(SDK_C_SOURCES) $(SDK_ASM_SOURCES),$(call sdk_obj_prereq_gen,$(obj))))
FORCE:
Core/Inc/githash.h: FORCE | $(BUILD_DIR)
$(V)./scripts/update_githash.sh $@
$(BUILD_DIR)/core/main.o: Core/Inc/githash.h
$(BUILD_DIR)/core/flashapp.o: Core/Inc/githash.h
$(BUILD_DIR)/core/rg_main.o: Core/Inc/githash.h
# Run parse_roms.py to generate information about the roms
$(BUILD_DIR)/rom_files.txt: FORCE | $(BUILD_DIR)
$(V)$(ECHO) [ BASH ] Checking for updated roms
$(V)./scripts/update_rom_files.sh build/rom_files.txt roms/gb roms/nes roms/sms roms/gg roms/col roms/pce roms/sg roms/msx roms/gw roms/wsv roms/md roms/a7800 roms/amstrad roms/tama
$(BUILD_DIR)/roms.a: $(BUILD_DIR)/rom_files.txt parse_roms.py
$(V)$(ECHO) [ PYTHON3 ] $(notdir $<)
$(V)$(PYTHON3) parse_roms.py --flash-size $(EXTFLASH_SIZE) $(SAVE_PARAM) $(COMPRESS_PARAM) $(CODEPAGE_PARAM) $(COVERFLOW_PARAM) $(JPG_QUALITY_PARAM) $(NOFRENDO_PARAM) --off_saveflash=$(OFF_SAVESTATE)
$(BUILD_DIR)/config.h $(BUILD_DIR)/saveflash.ld $(BUILD_DIR)/cacheflash.ld $(BUILD_DIR)/offsaveflash.ld &: $(BUILD_DIR)/roms.a
$(V)/bin/sh -c true
STM32H7B0VBTx_FLASH.ld: $(BUILD_DIR)/offsaveflash.ld $(BUILD_DIR)/saveflash.ld $(BUILD_DIR)/cacheflash.ld
# rom_manager.c depends on the different *_roms.c files but they only change when roms.a changes
$(BUILD_DIR)/core/rom_manager.o: Core/Src/retro-go/rom_manager.c $(BUILD_DIR)/roms.a
ifeq (${CHECK_DIRTY_SUBMODULE},1)
CheckDirtySubmodules:
$(V)git submodule foreach "git diff --quiet" 2> /dev/null || \
(echo -e "\n\n\nYou have changes in the submodule. This is not normal.\nPlease clean the submodule by running 'git submodule update --init'\n\n(You may set CHECK_DIRTY_SUBMODULE=0 to suppress this warning)\n\n\n" && exit 1)
$(V)git submodule status | grep -v '+' 2> /dev/null > /dev/null || \
(echo -e "\n\n\nYou are using a submodule that is not updated.\nPlease sync the submodules by running 'git submodule update --init'\n\n(You may set CHECK_DIRTY_SUBMODULE=0 to suppress this warning)\n\n\n" && exit 1)
else
CheckDirtySubmodules:
endif
.PHONY: CheckDirtySubmodules
ifeq (${CHECK_TOOLS},1)
CheckTools:
@# Check that the tools in the toolchain exist
$(V)/usr/bin/env bash -c " \
for tool in $(CC) $(CP) $(SZ) $(GDB) $(DUMP); do \
which \$$tool 2> /dev/null > /dev/null || \
( \
echo -e \"\nCannot find \$$tool\n\" && \
exit 1 \
) \
done"
@# Check that GCC version 10 or higher is used
$(V)$(CC) -v 2>&1 | grep "gcc version 1[0-9]" > /dev/null || \
( \
echo -e "\n\n\nPlease use GCC version 10 or higher.\n\n\nYou are using:" && \
$(CC) -v 2>&1 | grep "gcc version" ; \
echo -e "\n\n\n" && \
exit 1 \
)
$(V)$(CP) --info | grep "elf32-littlearm" > /dev/null || \
( \
echo -e "\n\n\n$(CP) does not suport elf32-littlearm.\nPlease install a toolchain that supports elf32-littlearm and armv7e-m.\n\n\n" && \
exit 1 \
)
$(V)$(DUMP) --help | grep "armv7e-m" > /dev/null || \
( \
echo -e "\n\n\nobjdump does not suport armv7e-m.\nPlease install a toolchain that supports elf32-littlearm and armv7e-m.\n\n\n" && \
exit 1 \
)
$(V)$(PYTHON3) scripts/python_version_check.py
else
CheckTools:
endif
.PHONY: CheckTools
$(BUILD_DIR)/%.o: %.s Makefile.common Makefile $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ AS ] $(notdir $<)
$(V)$(AS) -c $(CFLAGS) $< -o $@
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) $(A7800_OBJECTS) $(NES_OBJECTS) $(NES_FCEU_OBJECTS) $(GNUBOY_OBJECTS) $(SMSPLUSGX_OBJECTS) $(PCE_OBJECTS) $(MSX_OBJECTS) $(GW_OBJECTS) $(WSV_OBJECTS) $(MD_OBJECTS) $(AMSTRAD_OBJECTS) $(ZELDA3_OBJECTS) $(SMW_OBJECTS) $(TAMA_OBJECTS) Makefile.common Makefile $(LDSCRIPT)
$(V)$(ECHO) [ LD ] $(notdir $@)
$(V)$(CC) $(OBJECTS) $(A7800_OBJECTS) $(NES_OBJECTS) $(NES_FCEU_OBJECTS) $(GNUBOY_OBJECTS) $(SMSPLUSGX_OBJECTS) $(PCE_OBJECTS) $(MSX_OBJECTS) $(GW_OBJECTS) $(WSV_OBJECTS) $(MD_OBJECTS) $(AMSTRAD_OBJECTS) $(ZELDA3_OBJECTS) $(SMW_OBJECTS) $(TAMA_OBJECTS) $(LDFLAGS) -o $@
$(V)./scripts/extflash_size.sh $@
$(BUILD_DIR)/core/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC core ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/core/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/nes/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC nes ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(NES_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/nes/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/nes_fceu/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC nes-fceu ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(NES_FCEU_C_INCLUDES) -Wno-sequence-point -Wno-parentheses -Wa,-a,-ad,-alms=$(BUILD_DIR)/nes_fceu/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/gnuboy/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC gb ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(GNUBOY_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/gnuboy/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/smsplusgx/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC sms ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(SMSPLUSGX_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/smsplusgx/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/pce/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC pce ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(PCE_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/pce/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/msx/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC msx ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(MSX_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/msx/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/gw/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC gw ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(GW_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/gw/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/wsv/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC wsv ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(WSV_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/wsv/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/md/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC md ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(MD_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/md/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/a7800/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC a7800 ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(A7800_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/a7800/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/amstrad/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC amstrad CPC ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(AMSTRAD_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/amstrad/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/tama/%.o: %.c Makefile.common Makefile $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR)
$(V)$(ECHO) [ CC tama ] $(notdir $<)
$(V)$(CC) -c $(CFLAGS) $(TAMA_C_INCLUDES) -Wa,-a,-ad,-alms=$(BUILD_DIR)/tama/$(notdir $(<:.c=.lst)) $< -o $@
# Zelda3 configuration
# Limit to 30 fps for improved stability
ZELDA3_LIMIT_30FPS ?= 1
# Increase UI speed (item menu, etc.)
ZELDA3_FASTER_UI ?= 1
# Display battery indicator in item menu
ZELDA3_BATTERY_INDICATOR ?= 1
# Item switch on L/R. Also allows reordering of items in inventory by pressing Y+direction.
# Hold X, L, or R inside of the item selection screen to assign items to those buttons.
# If X is reassigned, Select opens the map. Push Select while paused to save or quit.
# When L or R are assigned items, those buttons will no longer cycle items.
ZELDA3_FEATURE_SWITCH_LR ?= 0
# Allow turning while dashing
ZELDA3_FEATURE_TURN_WHILE_DASHING ?= 0
# Allow mirror to be used to warp to the Dark World
ZELDA3_FEATURE_MIRROR_TO_DARK_WORLD ?= 0
# Collect items (like hearts) with sword instead of having to touch them
ZELDA3_FEATURE_COLLECT_ITEMS_WITH_SWORD ?= 0
# Level 2-4 sword can be used to break pots
ZELDA3_FEATURE_BREAK_POTS_WITH_SWORD ?= 0
# Disable the low health beep
ZELDA3_FEATURE_DISABLE_LOW_HEALTH_BEEP ?= 0
# Avoid waiting too much at the start
ZELDA3_FEATURE_SKIP_INTRO_ON_KEYPRESS ?= 1
# Display max rupees/bombs/arrows with orange/yellow color
ZELDA3_FEATURE_SHOW_MAX_ITEMS_IN_YELLOW ?= 0
# Allows up to four bombs active at a time instead of two.
ZELDA3_FEATURE_MORE_ACTIVE_BOMBS ?= 0
# Can carry 9999 rupees instead of 999
ZELDA3_FEATURE_CARRY_MORE_RUPEES ?= 0
# Enable various zelda bug fixes
ZELDA3_FEATURE_MISC_BUG_FIXES ?= 0
# Allow bird travel to be cancelled by hitting the X key
ZELDA3_FEATURE_CANCEL_BIRD_TRAVEL ?= 0
# Enable some more advanced zelda bugfixes that change game behavior
ZELDA3_FEATURE_GAME_CHANGING_BUG_FIXES ?= 0
# Enable this to limit the ItemSwitchLR item cycling to the first 4 items.
ZELDA3_FEATURE_SWITCH_LR_LIMIT ?= 0
ZELDA3_FEATURES := 0
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_SWITCH_LR) << 1 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_TURN_WHILE_DASHING) << 2 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_MIRROR_TO_DARK_WORLD) << 3 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_COLLECT_ITEMS_WITH_SWORD) << 4 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_BREAK_POTS_WITH_SWORD) << 5 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_DISABLE_LOW_HEALTH_BEEP) << 6 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_SKIP_INTRO_ON_KEYPRESS) << 7 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_SHOW_MAX_ITEMS_IN_YELLOW) << 8 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_MORE_ACTIVE_BOMBS) << 9 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_CARRY_MORE_RUPEES) << 11 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_MISC_BUG_FIXES) << 12 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_CANCEL_BIRD_TRAVEL) << 13 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_GAME_CHANGING_BUG_FIXES) << 14 ))")
ZELDA3_FEATURES := $(shell echo "$$(( $(ZELDA3_FEATURES) | $(ZELDA3_FEATURE_SWITCH_LR_LIMIT) << 15 ))")
# Support multiple languages
ZELDA3_LOCALIZED_ROM=$(wildcard roms/zelda3/zelda3_*.sfc)
ifneq ("$(ZELDA3_LOCALIZED_ROM)","")
ZELDA3_DIALOGUES_LANGUAGE="$(patsubst roms/zelda3/zelda3_%.sfc,%,$(ZELDA3_LOCALIZED_ROM))"
else
ZELDA3_DIALOGUES_LANGUAGE=us
endif
# C defines for zelda3
C_DEFS_ZELDA3 = \
-DHEADLESS \
-DLIMIT_30FPS=$(ZELDA3_LIMIT_30FPS) \
-DDIALOGUES_LANGUAGE=$(ZELDA3_DIALOGUES_LANGUAGE) \
-DFEATURES=$(ZELDA3_FEATURES) \
-DFASTER_UI=$(ZELDA3_FASTER_UI) \
-DBATTERY_INDICATOR=$(ZELDA3_BATTERY_INDICATOR) \
# function used to generate prerequisite rules for zelda3 objects
define zelda3_obj_prereq_gen
$$(BUILD_DIR)/zelda3/$(patsubst %.c,%.o,$(notdir $1)): $1 Makefile.common Makefile $$(SDK_HEADERS) $$(BUILD_DIR)/config.h | $$(BUILD_DIR)
$$(V)$$(ECHO) [ CC zelda3 CPC ] $$(notdir $$<)
$$(V)$$(CC) -c $$(CFLAGS) $$(C_DEFS_ZELDA3) $$(ZELDA3_C_INCLUDES) -Wa,-a,-ad,-alms=$$(BUILD_DIR)/zelda3/$$(notdir $$(<:.c=.lst)) $$< -o $$@
$$(CP) --redefine-syms=zelda3_redefines $$@
endef
# note: the blank line above is intentional
# generate all zelda3 object prerequisite rules
$(eval $(foreach obj,$(ZELDA3_C_SOURCES),$(call zelda3_obj_prereq_gen,$(obj))))
Core/Src/porting/zelda3/zelda_assets.c: scripts/zelda3/update_assets.py zelda3/tables/zelda3_assets.dat | $(BUILD_DIR)
$(PYTHON3) ./scripts/zelda3/update_assets.py
ifneq ("$(ZELDA3_LOCALIZED_ROM)","")
zelda3/tables/zelda3_assets.dat: roms/zelda3/zelda3.sfc $(ZELDA3_LOCALIZED_ROM) | $(BUILD_DIR)
$(ECHO) "Extracting dialogues from localized ROM: $<"
cd zelda3/tables; $(PYTHON3) restool.py --extract-dialogue -r ../../$(ZELDA3_LOCALIZED_ROM)
$(ECHO) "Extracting game resources"
cd zelda3/tables; $(PYTHON3) restool.py --extract-from-rom --languages=$(ZELDA3_DIALOGUES_LANGUAGE) -r ../../roms/zelda3/zelda3.sfc
else
zelda3/tables/zelda3_assets.dat: roms/zelda3/zelda3.sfc | $(BUILD_DIR)
$(ECHO) "Extracting game resources"
cd zelda3/tables; $(PYTHON3) restool.py --extract-from-rom -r ../../$<
endif
# SMW configuration
# Limit to 30 fps for improved stability
SMW_LIMIT_30FPS ?= 1
# Controller bindings
# A physical button (or combination of buttons) is assigned for each SNES controller button
# Each nibble represents a physical button assignment
# Order of assignments (SNES buttons) from most-significant to least-significant nibble: Select,Start,A,B,X,Y,L,R
# Values for physical buttons mapping: GAME modifier (MSB) + 3-bits physical button index (0=A, 1=B, 2=Select, 3=Start, 4=Time)
# A value of 0xf means no assignment
# Binding "A" for zelda consoles: Use Reserve Item: TIME / Pause Game: GAME + TIME / Spin Jump: A / Regular Jump: B / Dash/Shoot: SELECT or START / Scroll Left: GAME + B / Scroll Right: GAME + A
SMW_BINDINGS_ZELDA_A = 0x4c012398
# Binding "B" for zelda consoles: Use Reserve Item: TIME / Pause Game: START / Spin Jump: SELECT / Regular Jump: A / Dash/Shoot: B / Scroll Left: GAME + B / Scroll Right: GAME + A
SMW_BINDINGS_ZELDA_B = 0x43201198
# Binding "A" for mario consoles: Use Reserve Item: GAME + A / Pause Game: GAME + TIME / Spin Jump: A / Regular Jump: B / Dash/Shoot: TIME / Scroll Left: Unassigned / Scroll Right: Unassigned
SMW_BINDINGS_MARIO_A = 0x8c0144ff
# Binding "B" for mario consoles: Use Reserve Item: TIME / Pause Game: GAME + TIME / Spin Jump: GAME + A / Regular Jump: A / Dash/Shoot: B / Scroll Left: Unassigned / Scroll Right: Unassigned
SMW_BINDINGS_MARIO_B = 0x4c8011ff
# Replace with the binding of your choice
ifeq ($(GNW_TARGET_ZELDA),1)
SMW_CONTROLLER_BINDINGS = $(SMW_BINDINGS_ZELDA_B)
else
SMW_CONTROLLER_BINDINGS = $(SMW_BINDINGS_MARIO_B)
endif
# Save to SRAM after each beaten level (instead of saving after castle is beaten).
# SRAM save remains valid/compatible with emulators.
SMW_FEATURE_SAVE_AFTER_EACH_BEATEN_LEVEL ?= 0
SMW_FEATURES := 0
SMW_FEATURES := $(shell echo "$$(( $(SMW_FEATURES) | $(SMW_FEATURE_SAVE_AFTER_EACH_BEATEN_LEVEL) << 0 ))")
# C defines for smw
C_DEFS_SMW = \
-DHEADLESS \
-DLIMIT_30FPS=$(SMW_LIMIT_30FPS) \
-DCONTROLLER_BINDINGS=$(SMW_CONTROLLER_BINDINGS) \
-DFEATURES=$(SMW_FEATURES) \
# function used to generate prerequisite rules for smw objects
define smw_obj_prereq_gen
$$(BUILD_DIR)/smw/$(patsubst %.c,%.o,$(notdir $1)): $1 Makefile.common Makefile $$(SDK_HEADERS) $$(BUILD_DIR)/config.h | $$(BUILD_DIR)
$$(V)$$(ECHO) [ CC smw CPC ] $$(notdir $$<)
$$(V)$$(CC) -c $$(CFLAGS) $$(C_DEFS_SMW) $$(SMW_C_INCLUDES) -Wa,-a,-ad,-alms=$$(BUILD_DIR)/smw/$$(notdir $$(<:.c=.lst)) $$< -o $$@
$$(CP) --redefine-syms=smw_redefines $$@
endef
# note: the blank line above is intentional
# generate all smw object prerequisite rules
$(eval $(foreach obj,$(SMW_C_SOURCES),$(call smw_obj_prereq_gen,$(obj))))
Core/Src/porting/smw/smw_assets.c: scripts/smw/update_assets.py smw/smw_assets.dat | $(BUILD_DIR)
$(PYTHON3) ./scripts/smw/update_assets.py
smw/smw_assets.dat: roms/smw/smw.sfc | $(BUILD_DIR)
cp $< smw/assets/smw.sfc
$(MAKE) -C smw smw_assets.dat
$(BUILD_DIR):
$(V)mkdir $@
$(V)mkdir $@/core
$(V)mkdir $@/nes
$(V)mkdir $@/nes_fceu
$(V)mkdir $@/gnuboy
$(V)mkdir $@/smsplusgx
$(V)mkdir $@/pce
$(V)mkdir $@/msx
$(V)mkdir $@/gw
$(V)mkdir $@/wsv
$(V)mkdir $@/md
$(V)mkdir $@/a7800
$(V)mkdir $@/amstrad
$(V)mkdir $@/zelda3
$(V)mkdir $@/smw
$(V)mkdir $@/tama
#######################################
# Flashing
#######################################
OPENOCD ?= openocd
ADAPTER ?= stlink
FLASH_MULTI ?= scripts/flash_multi.sh
FLASHTEST ?= scripts/flashapp.sh --test
# Starts openocd and attaches to the target. To be used with 'flash_intflash_nc' and 'gdb'
openocd:
$(OPENOCD) -f scripts/interface_$(ADAPTER).cfg -c "init; halt"
.PHONY: openocd
reset:
$(OPENOCD) -f scripts/interface_$(ADAPTER).cfg -c "init; reset; exit"
.PHONY: reset
erase_intflash_1:
$(OPENOCD) -f scripts/interface_$(ADAPTER).cfg -c "init; halt; flash erase_address 0x08000000 131072; resume; exit"
.PHONY: erase_intflash_1
erase_intflash_2:
$(OPENOCD) -f scripts/interface_$(ADAPTER).cfg -c "init; halt; flash erase_address 0x08100000 131072; resume; exit"
.PHONY: erase_intflash_2
erase_extflash: flash_intflash
$(V)./scripts/extflash_erase.sh $(EXTFLASH_SIZE)
.PHONY: erase_extflash
start_bank_1:
$(OPENOCD) -f scripts/interface_$(ADAPTER).cfg \
-c 'init; reset halt' \
-c 'set MSP 0x[string range [mdw 0x08000000] 12 19]' \
-c 'set PC 0x[string range [mdw 0x08000004] 12 19]' \
-c 'echo "Setting MSP -> $$MSP"' \
-c 'echo "Setting PC -> $$PC"' \
-c 'reg msp $$MSP' \
-c 'reg pc $$PC' \
-c 'resume;exit'
.PHONY: start_bank_1
start_bank_2:
$(OPENOCD) -f scripts/interface_$(ADAPTER).cfg \
-c 'init; reset halt' \
-c 'set MSP 0x[string range [mdw 0x08100000] 12 19]' \
-c 'set PC 0x[string range [mdw 0x08100004] 12 19]' \
-c 'echo "Setting MSP -> $$MSP"' \
-c 'echo "Setting PC -> $$PC"' \
-c 'reg msp $$MSP' \
-c 'reg pc $$PC' \
-c 'resume;exit'
.PHONY: start_bank_2
start: # Start code located at INTFLASH_ADDRESS
$(OPENOCD) -f scripts/interface_$(ADAPTER).cfg \
-c 'init; reset halt' \
-c 'set MSP 0x[string range [mdw $(INTFLASH_ADDRESS)] 12 19]' \
-c 'set PC 0x[string range [mdw [format 0x%x [expr {$(INTFLASH_ADDRESS) + 0x4}]]] 12 19]' \
-c 'echo "Setting MSP -> $$MSP"' \
-c 'echo "Setting PC -> $$PC"' \
-c 'reg msp $$MSP' \
-c 'reg pc $$PC' \
-c 'resume;exit'
.PHONY: start
# Programs the internal flash using a new OpenOCD instance
flash_intflash: $(BUILD_DIR)/$(TARGET)_intflash.bin
$(OPENOCD) -f scripts/interface_$(ADAPTER).cfg -c "program $< $(INTFLASH_ADDRESS) verify reset exit"
.PHONY: flash_intflash
# Flashes using an existing openocd instance
flash_intflash_nc: $(BUILD_DIR)/$(TARGET)_intflash.bin
echo "program $< $(INTFLASH_ADDRESS) verify reset" | nc -c localhost 4444
.PHONY: flash_intflash_nc
flash_extflash: $(BUILD_DIR)/$(TARGET)_extflash.bin
$(FLASH_MULTI) $(BUILD_DIR)/$(TARGET)_extflash.bin $(EXTFLASH_OFFSET)
.PHONY: flash_extflash
flash_test: flash_intflash
$(FLASHTEST)
.PHONY: flash_test
# Programs both the external and internal flash.
flash: CheckTools CheckDirtySubmodules
$(V)$(MAKE) flash_intflash
$(V)$(MAKE) flash_extflash
$(V)$(RESET_DBGMCU_CMD)
.PHONY: flash
monitor:
$(V)$(PYTHON3) tools/logpoll.py
.PHONY: monitor
flash-monitor: flash
$(V)$(MAKE) monitor
.PHONY: flash-monitor