forked from coopzone-dc/xmodem80
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
106 lines (93 loc) · 2.55 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
SHELL = /bin/bash
EMULATIONBAUD= 9600
ESPPORT ?= /dev/ttyUSB0
ESPTOOL = /opt/esptool/esptool.py
ASM = /usr/bin/z80asm
SERIAL = minicom -b -D $(ESPPORT) $(EMULATIONBAUD)
SED = /bin/sed
TARGET1 = XR
target1_lower = xr
TARGET2 = XS
target2_lower = xs
DRIVE = J:
INTERACTIVE:=$(shell [ -t 0 ] && echo 1)
all: $(TARGET1).hex $(TARGET2).hex
full: clean flash
$(TARGET1).hex: $(target1_lower).z80
@echo [Z80ASM] $<
@$(ASM) $(FLAGSHEX) $< -l$(basename $<).lst -o tmp1.tmp
@srec_cat tmp1.tmp -binary -offset 0x100 -o tmp2.tmp -intel
@tail -n +2 tmp2.tmp > $@
@sed -i '/:......000000000000000000000000000000000000000000000000000000000000000000..$$/d' $@
$(TARGET2).hex: $(target2_lower).z80
@echo [Z80ASM] $<
@$(ASM) $(FLAGSHEX) $< -l$(basename $<).lst -o tmp1.tmp
@srec_cat tmp1.tmp -binary -offset 0x100 -o tmp2.tmp -intel
@tail -n +2 tmp2.tmp > $@
@sed -i '/:......000000000000000000000000000000000000000000000000000000000000000000..$$/d' $@
prepare:
@echo -n Reset..
@$(ESPTOOL) --baud $(EMULATIONBAUD) --port $(ESPPORT) --chip esp8266 --no-stub --after soft_reset read_mac > /dev/null
@sleep 0.5
@echo -n Autobaud..
@echo -n -e "\x0d" > $(ESPPORT)
@sleep 0.25
@echo -n -e "\x0d" > $(ESPPORT)
@sleep 0.25
@echo -n -e "\x0d" > $(ESPPORT)
@sleep 0.25
@echo -n -e "\x0d" > $(ESPPORT)
@sleep 0.25
@echo -n Boot..
@echo "B" > $(ESPPORT)
@sleep 0.25
@echo -n CD..
@echo $(DRIVE) > $(ESPPORT)
@sleep 0.25
xfer:
@echo -n ERA..
@echo "ERA $(THEFILE)" > $(ESPPORT)
@sleep 0.25
@echo -n PIP..
@echo "A:PIP $(DRIVE)$(THEFILE)=CON:" > $(ESPPORT)
@sleep 0.25
ifdef INTERACTIVE
@echo -n UPLOAD ---%
@$(eval LINES=$(shell cat $(THEFILE) | wc -l))
@cnt=0; \
cat $(THEFILE) | \
$(SED) -e '/INCLUDE/s/\"//g' | \
while IFS= read -r line;do \
cnt=$$(( cnt+100)); \
printf "\b\b\b\b%3d%%" $$(( $$cnt/$(LINES) )); \
echo -n "$$line" > $(ESPPORT); \
echo -n -e "\r\n" > $(ESPPORT); \
sleep 0.01; \
done
@echo -n " "
else
@echo -n UPLOAD..
@cat $(THEFILE) | \
$(SED) -e '/INCLUDE/s/\"//g' | \
while IFS= read -r line;do \
echo -e "$$line\r" > $(ESPPORT); \
sleep 0.01; \
done
endif
@echo -e "\x1A" > $(ESPPORT)
flash: $(TARGET1).hex $(TARGET2).hex
@echo -n "[UPLOAD $@] "
@$(MAKE) --no-print-directory prepare
@echo
@$(MAKE) --no-print-directory xfer THEFILE=$(TARGET1).hex
@sleep 2
@$(MAKE) --no-print-directory xfer THEFILE=$(TARGET2).hex
@sleep 2
@echo HEX2COM...
@echo "A:LOAD $(TARGET1)" > $(ESPPORT)
@echo "A:LOAD $(TARGET2)" > $(ESPPORT)
@$(SERIAL)
clean:
@echo "[clean]"
@rm -rf *~
@rm -rf *.{cap,log,tmp,rom,bin,hex,lst,com}