forked from LAK132/MegaWAT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
203 lines (153 loc) · 5.16 KB
/
Makefile
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
CC= gcc
COPT= -Wall -g -std=gnu99
SRCDIR= src
OBJDIR= obj
BINDIR= bin
ROMDIR= rom
TMPDIR= tmp
ASTDIR= assets
MKDIRS= $(SRCDIR) $(OBJDIR) $(BINDIR) $(ROMDIR)
DISK= $(BINDIR)/MEGAWAT.D81
PROGRAM= $(BINDIR)/megawat.prg
SERIAL= /dev/ttyUSB1
WGET= wget
CC65DIR= /c/cygwin0005/home/GurceI/Projects/cc65/
CBMCONVDIR= cbmconvert
FONTRSTDIR= c65gs-font-rasteriser
XEMUDIR= ../xemu
COREDIR= ../mega65-core
TOOLSDIR= ../mega65-tools
# CC65DIR= $(COREDIR)/cc65
# CBMCONVDIR= $(COREDIR)/cbmconvert
# FONTRSTDIR= ../c65gs-font-rasteriser
C65OPTS= -t c64 -O -Or -Oi -Os --cpu 65c02 -I$(CC65DIR)/include
L65OPTS= -C c64-m65.cfg --asm-include-dir $(CC65DIR)/asminc --lib-path $(CC65DIR)/lib
FILES= $(PROGRAM) \
$(BINDIR)/loader.prg \
autoboot.c65 \
c64-m65.cfg
C_SOURCE= $(SRCDIR)/main.c \
$(SRCDIR)/megastring.c \
$(SRCDIR)/editor.c \
$(SRCDIR)/videomodes.c \
$(SRCDIR)/memory.c \
$(SRCDIR)/f65.c \
$(SRCDIR)/globals.c \
$(SRCDIR)/fileio.c
S_SOURCE= $(SRCDIR)/fast_memory.s \
$(SRCDIR)/font_load.s \
$(SRCDIR)/charset.s \
$(SRCDIR)/romprotection.s
MEGAWAT_FILES= $(C_SOURCE:$(SRCDIR)/%.c=$(OBJDIR)/%.c.o) \
$(S_SOURCE:$(SRCDIR)/%.s=$(OBJDIR)/%.s.o)
C_TO_S_FILES=$(C_SOURCE:$(SRCDIR)/%.c=$(OBJDIR)/%.s)
SPLASH_FILES= $(OBJDIR)/fast_memory.s.o \
$(OBJDIR)/splash.s.o \
$(OBJDIR)/loader.c.o \
$(OBJDIR)/memory.c.o
HEADERS= Makefile \
c64-m65.cfg \
$(SRCDIR)/main.h \
$(SRCDIR)/megastring.h \
$(SRCDIR)/editor.h \
$(SRCDIR)/screen.h \
$(SRCDIR)/videomodes.h \
$(SRCDIR)/globals.h \
$(SRCDIR)/memory.h \
$(SRCDIR)/f65.h \
$(SRCDIR)/megaint.h \
$(SRCDIR)/serial.h \
$(SRCDIR)/fileio.h \
$(SRCDIR)/ascii.h
DATAFILES= ascii8x8.bin
CC65= cc65
CL65= cl65
CA65= ca65 --cpu 4510
LD65= ld65 -t none
CBMCONVERT= $(CBMCONVDIR)/cbmconvert
XC65= $(XEMUDIR)/build/bin/xc65.native
# But use local ROM file if present
F1_EXISTS=$(shell [ -e c65.rom ] && echo 1 || echo 0 )
ifeq ($(F1_EXISTS), 1)
C65SYSROM= c65.rom
else
C65SYSROM= $(ROMDIR)/911001.bin.rom
# C65SYSROM= $(ROMDIR)/911210.bin.rom
endif
MONLOAD= $(TOOLSDIR)/bin/m65
KICKUP= $(COREDIR)/bin/HICKUP.M65
BITSTRM= $(COREDIR)/bin/nexys4.bit
CHARROM= $(COREDIR)/bin/charrom.bin
TTFTOF65= $(FONTRSTDIR)/ttftof65
# FUNCTIONS
all: $(FILES) | $(MKDIRS)
clean: clean-obj clean-bin clean-font
clean-obj:
rm -rf $(OBJDIR)
clean-bin:
rm -rf $(BINDIR)
clean-rom:
rm -rf $(ROMDIR)
clean-font:
rm -f *.f65
# Run the program in XEMU
test: $(XC65) $(C65SYSROM) $(DISK)
$(XC65) -rom $(C65SYSROM) -8 $(DISK)
run: $(MONLOAD) $(C65SYSROM)
$(MONLOAD) -b $(BITSTRM) -l $(SERIAL)
# $(MONLOAD) -b $(BITSTRM) -R $(C65SYSROM) -k $(KICKUP) -C $(CHARROM) -l $(SERIAL)
# Load the program onto the MEGA65
load: $(MONLOAD) $(C65SYSROM) $(PROGRAM)
$(MONLOAD) -b $(BITSTRM) -4 -r $(PROGRAM) -l $(SERIAL)
# $(MONLOAD) -b $(BITSTRM) -R $(C65SYSROM) -k $(KICKUP) -C $(CHARROM) -4 -r $(PROGRAM) -l $(SERIAL)
# TEMPLATES
.PRECIOUS: $(OBJDIR)/%.s $(OBJDIR)/%.FPK %.f65 $(ROMDIR)/%.rom
%.f65: %.ttf Makefile $(TTFTOF65)
$(TTFTOF65) -A -P 8 -T $< -o $@
$(ROMDIR)/911210.zip: | $(ROMDIR)
$(WGET) -O $@ http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/c65/911210.zip || { rm -f $@ ; false; }
$(ROMDIR)/folder_911210/911210.bin: $(ROMDIR)/911210.zip
unzip -u $< -d $(ROMDIR)
$(ROMDIR)/911210.bin.rom: $(ROMDIR)/folder_911210/911210.bin
cp $< $@
$(ROMDIR)/%.rom: | $(ROMDIR)
$(WGET) -O $@ http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/c65/$* || { rm -f $@ ; false; }
$(OBJDIR)/%.FPK: Makefile $(ASTDIR)/*.ttf $(ASTDIR)/*.otf $(TTFTOF65) | $(ASTDIR) $(OBJDIR)
./makefonts.sh $@ > /dev/null
$(OBJDIR)/%.o: $(SRCDIR)/% $(HEADERS) $(DATAFILES) $(CC65) | $(OBJDIR)
$(CL65) $(C65OPTS) -o $@ -c $<
$(PROGRAM): $(MEGAWAT_FILES) $(HEADERS) c64-m65.cfg | $(BINDIR)
$(CL65) $(C65OPTS) $(L65OPTS) -vm -Ln [email protected] -m [email protected] -o $@ $(filter %.o, $^)
$(BINDIR)/loader.prg: $(SPLASH_FILES) $(HEADERS) $(ASTDIR)/megawat-splash.m65 | $(BINDIR)
$(CL65) $(C65OPTS) $(L65OPTS) -vm -m [email protected] -o $@ $(filter %.o, $^)
$(BINDIR)/%.fprg: Makefile $(OBJDIR)/%.FPK $(BINDIR)/%.prg $(C65SYSROM)
# Generate single binary with fonts and ROM in place
dd if=$(BINDIR)/$*.prg of=$@
dd if=/dev/zero bs=1024 count=12 of=$@ oflag=append conv=notrunc
dd if=$(ASTDIR)/dosram.bin bs=1024 count=8 of=$@ oflag=append conv=notrunc
dd if=/dev/zero bs=1024 count=56 of=$@ oflag=append conv=notrunc
dd if=$(C65SYSROM) bs=1024 count=128 of=$@ oflag=append conv=notrunc
dd if=$(OBJDIR)/$*.FPK bs=1024 count=128 of=$@ oflag=append conv=notrunc
$(BINDIR)/%.D81: $(CBMCONVERT) $(FILES) | $(BINDIR)
if [ -f $@ ]; then rm -f $@; fi
$(CBMCONVERT) -v2 -D8o $@ $(FILES)
define DIR_TEMPLATE =
$(1):
mkdir $(1)
endef
$(foreach dir,$(MKDIRS),$(eval $(call DIR_TEMPLATE,$(dir))))
# TOOLS
cbmconvert/cbmconvert:
# git submodule update --init cbmconvert
# ( cd cbmconvert && make -f Makefile.unix )
cc65/bin/cc65:
# git submodule update --init cc65
# ( cd cc65 && make -j8 )
$(TTFTOF65):
( cd $(FONTRSTDIR) && $(MAKE) )
$(TOOLSDIR)/%:
( cd $(TOOLSDIR) && $(MAKE) $(shell realpath --relative-to $(TOOLSDIR) $@) )
$(COREDIR)/%:
( cd $(COREDIR) && $(MAKE) $(shell realpath --relative-to $(COREDIR) $@) )
.DEFAULT:
$(error Could not find file $@)