-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.bat
155 lines (142 loc) · 4.89 KB
/
build.bat
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
@if {%1} == {} (
@echo Calculator not specified, building for TI-86.
@set MODEL=86
@set CODELOC=0xD748
@set CALC=ti86
@set EXT=86p
) else if {%1} == {86} (
@echo Building for TI-86.
@set MODEL=86
@set CODELOC=0xD748
@set CALC=ti86
@set EXT=86p
) else if {%1} == {84pse} (
@echo Building for TI-84 Plus Silver Edition.
@set MODEL=8402
@set CODELOC=0x9D95
@set CALC=ti84pse
@set EXT=8xp
) else (
@echo Unsupported calculator specified: %1
@echo Supported model options: 86 84pse
@exit /b
)
@rem Check on prerequisites, sdcc >3.4.0 and python
@if not {%PYTHONDIR%} == {} (
@if exist %PYTHONDIR%\python.exe (
@goto :pythonfound
)
)
@rem Python dir not set or python.exe not found, look in PATH
@for %%p in (python.exe) do @set PYTHONDIR="%%~dp$PATH:p"
@if {%PYTHONDIR%} == {""} (
@echo Could not find Python on your PATH or in PYTHONDIR!
@echo Please set PYTHONDIR to the full python folder, or add this to PATH.
@echo Example: set "PATH=%%PATH%%;C:\Program Files (x86)\Python"
@echo Example: set PYTHONDIR="C:\Program Files (x86)\Python"
@exit /b
)
:pythonfound
@echo Found python.exe at %PYTHONDIR%
@rem Look for SDCC
@if not {%SDCCDIR%} == {} (
@if exist %SDCCDIR%\sdcc.exe (
@goto :sdccfound
)
)
@rem SDCC dir not set or sdcc.exe not found, look in PATH
@for %%s in (sdcc.exe) do @set SDCCDIR="%%~dp$PATH:s"
@if {%SDCCDIR%} == {""} (
@echo Could not find SDCC on your PATH or in SDCCDIR!
@echo Please set SDCCDIR to the full path to SDCC\bin, or add this to PATH.
@echo Example: set "PATH=%%PATH%%;C:\Program Files (x86)\SDCC\bin"
@echo Example: set SDCCDIR="C:\Program Files (x86)\SDCC\bin"
@exit /b
)
:sdccfound
@rem Parse the output of "sdcc --version" and look for an X.Y.Z version string
@for /f "usebackq tokens=1-10" %%a in (`call %SDCCDIR%\sdcc.exe -v`) do @(
@for %%m in (%%a %%b %%c %%d %%e %%f %%g %%h %%i %%j) do @(
@echo %%m | findstr /r "[0-9]*\.[0-9]*\.[0-9]" > NUL 2>&1
@if not ERRORLEVEL 1 (
@set SDCCVER=%%m
@goto :sdccversion
)
)
)
@echo Found sdcc.exe, but could not determine version!
@echo This program depends on SDCC 3.4.0 or newer.
@echo The sdcc.exe in question is in %SDCCDIR%
@exit /b
:sdccversion
@echo Found sdcc.exe version %SDCCVER% in %SDCCDIR%
@rem From version X.Y.Z, make sure X is at least 3.
@rem If it is exactly 3, make sure Y is at least 4.
@for /f "tokens=1-3 delims=." %%a in ("%SDCCVER%") do @(
@if %%a geq 3 (
@if %%a equ 3 (
@if %%b lss 4 (
@echo Detected SDCC minor version less than 4.
@goto :sdcctooold
)
)
) else (
@echo Detected SDCC major version less than 3.
@goto :sdcctooold
)
@goto :sdccok
)
:sdcctooold
@echo This program requires a minimum of SDCC 3.4.0.
@exit /b
:sdccok
@set SDCC=%SDCCDIR%\sdcc.exe
@set SDAS=%SDCCDIR%\sdasz80.exe
@set SDLD=%SDCCDIR%\sdldz80.exe
@set PYTHON=%PYTHONDIR%\python.exe
@set CRT=Build\%CALC%_crt0.rel
@set LINKS=%CRT%
@set BUILD=@call :build
@set COMPILE=@call :compile
@set FAKE=@call :fake
@set SDCCBASE=%SDCC% -mz80 --nostdlib --no-std-crt0 --reserve-regs-iy --opt-code-speed --max-allocs-per-node 30000 -ISource -DCALCULATOR_MODEL=%MODEL%
@mkdir Build > NUL 2>&1
%SDAS% -p -g -o %CRT% Source\calc\%CALC%\crt0.s || goto :failed
%COMPILE% Source\bitmap.c || goto :failed
%COMPILE% Source\camera.c || goto :failed
%COMPILE% Source\game.c || goto :failed
%COMPILE% Source\kibble.c || goto :failed
%COMPILE% Source\kitty.c || goto :failed
%COMPILE% Source\lander.c || goto :failed
%COMPILE% Source\menu.c || goto :failed
%COMPILE% Source\moon.c "--max-allocs-per-node 3000" || goto :failed
%COMPILE% Source\physics.c || goto :failed
%COMPILE% Source\calc\%CALC%\%CALC%.c || goto :failed
%COMPILE% Source\main.c || goto :failed
%BUILD% Build\Source\main.ihx
@rem SDCC generates main.ihx instead of main.c.ihx?
%PYTHON% Tools\ihxtobin.py Build\Source\main.ihx
@rem Patch the binary to initialize globals. Usually SDCC expects this to be
@rem done in the startup code, but this is not necessary on a TI.
%PYTHON% Tools\trim.py Build\Source\main.map Build\Source\main.ihx.bin %CODELOC%
@copy /y Build\Source\main.ihx.bin Build\Source\catlandr.bin
%PYTHON% Tools\binto86p.py %CALC% Build\Source\catlandr.bin
@copy /y Build\Source\catlandr.%EXT% catlandr.%EXT%
@goto :done
:compile
@mkdir Build\%1 > NUL 2>&1
@rmdir Build\%1 > NUL 2>&1
%SDCCBASE% %2 --compile-only %1 -o Build\%1.rel
@set LINKS=%LINKS% Build\%1.rel
@goto :done
:fake
@set LINKS=%LINKS% Build\%1.rel
@goto :done
:build
@mkdir Build\%1 > NUL 2>&1
@rmdir Build\%1 > NUL 2>&1
%SDLD% -m -w -x -i -b _CODE=%CODELOC% -b _DATA=0x0000 %1 %LINKS%
@goto :done
:failed
@echo Build failed!
:done