-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.src
178 lines (154 loc) · 3.75 KB
/
app.src
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
; todo: figure out how to not make this look like jquery
public app
public _appMainStart
macro @ez80.word size*, @value*
local value, offset, rel_addr
value := @value
offset := $
if offset relativeto $.app.data.relocation_base
rel_addr := offset - $.app.data.relocation_base + $.app.data - $.app.code.relocation_base
assert rel_addr relativeto $.app.data - $.app.code.relocation_base
else if offset relativeto $.app.data
rel_addr := offset - $.app.code.relocation_base
else
assert offset relativeto 0
end if
if value relativeto $.app.code.relocation_base
@ez80.word size, -1
$.app.relocations equ rel_addr, value - $.app.code.relocation_base
else if value relativeto $.app.data.relocation_base
@ez80.word size, -1
$.app.relocations equ rel_addr, (value - $.app.data.relocation_base) or $800000
else
assert value relativeto 0
@ez80.word size, value
end if
end macro
section .app.header
app:
.start:
db $81,$0f
dd (.signature_offset1) bswap 4
.signature_offset1 := .signature - $
db $81,$12,$13,$0f
db $81,$2d,lengthof __app_version + 1,__app_version,$00
db $81,$32,$59,$00
db $81,$40 or lengthof __app_name,__app_name
db $81,$a1,$07
db $03,$26,$09,$04
db $21,$bb,$6e,$dc
.freespace := 247 - ($-app.start)
db $00,$0d,.freespace
db .freespace dup $ff
db $81,$7f
dd (.signature_offset2) bswap 4
.signature_offset2 := .signature - $
.header_start:
db 'eZ8'
.exe:
dq __app_name
db 0,3
db 0,0
dl 0
dl .code - .header_start
dl .data - .header_start
dl .data_end - .data
dl .code - .header_start ; entry point
dl 0
dl 0 ; todo: library table
dl .info_string - .header_start
dl 0
postpone
virtual
irpv relocation, $.app.relocations
dl relocation
end irpv
.num_relocations = ($-$$) / 6
; sort stuff
rb .num_relocations * 6
.width = 1
while .width < .num_relocations
.run_start = 0
while .run_start < .num_relocations
.iLeft = .run_start
.iRight = .run_start + .width
if .iRight > .num_relocations
.iRight = .num_relocations
end if
.iEnd = .run_start + 2 * .width
if .iEnd > .num_relocations
.iEnd = .num_relocations
end if
.i = .iLeft
.j = .iRight
.k = .iLeft
while .k < .iEnd
load .a_i : 6 from $$ + 6 * .i
load .a_j : 6 from $$ + 6 * .j
load .aa_i : 3 from $$ + 6 * .i
load .aa_j : 3 from $$ + 6 * .j
if .i < .iRight & (.j >= .iEnd | .aa_i <= .aa_j)
store .a_i : 6 at $$ + 6 * .num_relocations + 6 * .k
.i = .i + 1
else
store .a_j : 6 at $$ + 6 * .num_relocations + 6 * .k
.j = .j + 1
end if
.k = .k + 1
end while
.run_start = .run_start + 2 * .width
end while
load .B : .num_relocations * 6 from $$ + .num_relocations * 6
store .B : .num_relocations * 6 at $$
.width = 2 * .width
end while
load relocation_table: 6 * .num_relocations from $$
end virtual
end postpone
db relocation_table
app.code:
$.app.code.relocation_base = app.code
private app.code
private app.relocations
extern __app_name
extern __app_version
section .app.info_string
app.info_string:
db __app_desc,0
app.data:
$.app.data:
private app.data
extern __app_desc
section .app.footer
app.data_end:
app.signature:
db $02,$3e,$01,$00
db 256 dup $ff
app.end:
private app.signature
private app.end
private app.data_end
section .app.init
_appMainStart:
call prgm_init
ld de,($D0118C) ; $asm_prgm_size
ld hl,$D1A881 ; userMem
call $20590 ; DelMem
or a,a
sbc hl,hl
ld ($D0118C),hl ; $asm_prgm_size
ld a, $09 ; kClear
jp $20164 ; JForceCmd
prgm_init:
section .fini
fini_base:
$.app.data.relocation_base:
private fini_base
section .init.clock
post_libs:
private post_libs
section .jp_fini
jp fini_base
section .jp_post_libs
nop ; glares at Mateo
jp post_libs