-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADTF_Map.s
187 lines (151 loc) · 3.33 KB
/
ADTF_Map.s
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
.file "ADTF_Map.s"
# short_name, long_name, event_ptr, is_discovered
.macro map_entry name:req
.long shrt_\()\name, lng_\()\name, ev_\()\name, 0
.endm
.macro map_strings ev_name:req long_name:req short_name:req
shrt_\()\ev_name: .string "\short_name"
lng_\()\ev_name: .string "\long_name"
.endm
.macro map_record_getter member_name:req member_index:req
get_map_\()\member_name:
frame
#arg0 = x
#arg1 = y
#return = member
call_3 get_map_record_member, 8(%ebp), 12(%ebp), \member_index
leave
ret
.endm
.text
is_in_map_bounds:
frame
#arg0 = x
#arg1 = y
#return = boolean, is in bounds
call_3 is_between, 8(%ebp), $0, map_size_x
cmpl $0, %eax
je LM2_false
call_3 is_between, 12(%ebp), $0, map_size_y
cmpl $0, %eax
je LM2_false
movl $1, %eax
jmp LM2_end
LM2_false:
movl $0, %eax
LM2_end:
leave
ret
get_map_record_ptr:
frame
#arg0 = x
#arg1 = y
#return = pointer to event, or 0
pushl %esi #save
movl 12(%ebp), %esi #load y
imul map_size_y, %esi #mul with map size
addl 8(%ebp), %esi #add x
shll $2, %esi #mul eax by 4 (4 entries per record)
movl $map_table, %eax
leal (%eax, %esi, 4), %eax
popl %esi #restore
leave
ret
#get_map_...
map_record_getter short_name, $0
map_record_getter long_name, $1
map_record_getter event_ptr, $2
map_record_getter is_discovered, $3
get_map_record_member:
frame
#arg0 = x
#arg1 = y
#arg2 = member index
#return = pointer to member
call_2 get_map_record_ptr, 8(%ebp), 12(%ebp)
call_2 get_member, %eax, 16(%ebp)
leave
ret
set_discovered:
frame
#arg0 = x
#arg1 = y
call_2 get_map_record_ptr, 8(%ebp), 12(%ebp)
call_3 set_member, %eax, $3, $1
leave
ret
#pseudo message event
print_map:
frame
pushl $0
pushl $0
LM3_start:
movl map_size_y, %eax
cmpl %eax, 4(%esp)
jge LM3_end
movl $0, (%esp)
LM3_i_start:
movl map_size_x, %eax
cmpl %eax, (%esp)
jge LM3_i_end
movl (%esp), %eax
movl 4(%esp), %ebx
call_2 get_map_is_discovered, %eax, %ebx
cmpl $0, %eax
je LM3_i_unknown
movl (%esp), %eax
movl 4(%esp), %ebx
call_2 get_map_short_name %eax, %ebx
print %eax
jmp LM3_i_continue
LM3_i_unknown:
print $map_undiscovered
LM3_i_continue:
movl (%esp), %eax
incl %eax
cmpl map_size_x, %eax
jge LM3_i_incl
print $map_x_devider
LM3_i_incl:
incl (%esp)
jmp LM3_i_start
LM3_i_end:
print $newline
movl 4(%esp), %eax
incl %eax
cmpl map_size_y, %eax
jge LM3_incl
movl $0, (%esp)
LM3_j_start:
movl map_size_x, %eax
cmpl %eax, (%esp)
jge LM3_j_end
print $map_y_devider
movl (%esp), %eax
incl %eax
cmpl map_size_x, %eax
jge LM3_j_incl
print $map_y_spaces
LM3_j_incl:
print $newline
incl (%esp)
jmp LM3_j_start
LM3_j_end:
LM3_incl:
incl 4(%esp)
jmp LM3_start
LM3_end:
leave
ret
.data
map_index_out_of_bounds: .string "Map index out of bounds"
map_size_x: .long 1
map_size_y: .long 1
map_x_devider: .string "-----"
map_y_devider: .string " | "
map_y_spaces: .string " "
map_undiscovered: .string " ? "
map_table:
map_entry shack
map_table_size: .long ((. - map_table) / 4) / 4
map_strings shack, Shack, shk