-
Notifications
You must be signed in to change notification settings - Fork 3
/
s1945ii.lua
254 lines (208 loc) · 5.82 KB
/
s1945ii.lua
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
local s1945ii = {}
local cpu = manager:machine().devices[":maincpu"]
local mem = cpu.spaces["program"]
local screen = manager:machine().screens[":screen"]
s1945ii.cpu = cpu
s1945ii.mem = mem
s1945ii.screen = screen
function s1945ii.cheat()
-- set infinite credit
mem:write_u8(0x600c3be, 09)
-- set P1 invincible
mem:write_u8(0x60103FA, 1)
-- set P1 infinite life
mem:write_u8(0x60103c1, 3)
end
function s1945ii.save_state(filename)
manager:machine():save(filename)
end
function s1945ii.load_state(filename)
manager:machine():load(filename)
end
function s1945ii.is_p1_dead()
return ((mem:read_u8(0x60103F8) == 128) and 1 or 0)
end
function s1945ii.is_p1_invincible()
return mem:read_u8(0x60103FA)
end
function s1945ii.get_p1_x()
return (mem:read_u32(0x60103a3) & 0xFFFF0) >> 8
end
function s1945ii.get_p1_y()
return (mem:read_u32(0x60103a7) & 0xFFFF0) >> 8
end
-- play-time in playing-stage, unit = 1/100 sec
function s1945ii.get_stage_time()
return mem:read_u32(0x600c4e0)
end
function s1945ii.get_stage_number()
return mem:read_u8(0x600c674) + 1
--mem:read_u8(0x600c553)
end
-- whole play-time, unit = 1/100 sec
function s1945ii.get_play_time()
return mem:read_u32(0x60103bc)
end
function s1945ii.get_p1_score()
return mem:read_u32(0x060103c4)
end
function s1945ii.get_p1_extra_weapon_gauge()
-- 0 ~ 48980000
return mem:read_u32(0x6010414)
end
function s1945ii.get_p1_number_of_bombs()
return mem:read_u8(0x60103C3)
end
function s1945ii.get_p1_number_of_lives()
return mem:read_u8(0x60103C1)
end
function s1945ii.get_p1_fire_power()
return mem:read_u8(0x60103e7)
end
function s1945ii.get_number_of_enemies()
return mem:read_u16(0x6018b46)
end
-- n(items) = n(gold) + n(power) + n(bomb)
function s1945ii.get_number_of_items()
return mem:read_u16(0x601c428)
end
function read_object(address)
local a_1 = mem:read_u32(address)
local a_2 = mem:read_u32(address+4)
local a_3 = mem:read_u32(address+8)
local a_4 = mem:read_u32(address+12)
local x = a_2 >> 16
if (x > 0x8000) then
x = x - 0xffff
end
local y = (a_2 & 0x7fff)
if (y > 0x8000) then
y = y - 0xffff
end
local width = a_3 >> 16
local height = a_3 & 0xffff
local _type = ""
local ref_adr = mem:read_u32(a_1)
if ref_adr == 0x6092a24 then
if width == 0x18 then
_type = "power"
elseif width == 0x1b then
_type = "bomb"
else
_type ="gold"
end
elseif ref_adr == 0x6091e48 then
_type = "p1"
else
_type = "enemy"
end
return { ["ref"]=a_1,
["x"] = x,
["y"] = y,
["height"] = height,
["width"] = width,
["child"] = a_4 & 0xffff,
["check"] = a_4 >> 16,
["type"] = _type}
end
function s1945ii.get_enemies()
local objects = {}
local adr = 0x6015f68
for i=1,s1945ii.get_number_of_enemies() do
local t = read_object(adr)
if t["ref"] == 0 then
break
end
objects[adr] = t
adr = adr + 0x10
end
return objects
end
function s1945ii.get_p1_collision()
local objects = {}
local adr = 0x6015f68 + s1945ii.get_number_of_enemies() * 0x10
for i = 1, 2 do
local t = read_object(adr)
if t["ref"] == 0 then
break
end
objects[adr] = t
adr = adr + 0x10
end
return objects
end
function s1945ii.get_flights()
local objects = {}
local adr = 0x6015f68
while (1) do
local t = read_object(adr)
if t["ref"] == 0 then
break
end
objects[adr] = t
adr = adr + 0x10
if (mem:read_u32(t["ref"]) == 0x6091e48 and t["child"] == 1) then
break
end
end
local cnt = 0
adr = 0x6018148
while (1) do
local t = read_object(adr)
if t["ref"] == 0 then
break
end
if (t["type"] == "bomb" or t["type"] == "gold" or t["type"] == "power") then
cnt = cnt + 1
objects[adr] = t
if (cnt >= s1945ii.get_number_of_items()) then break end
end
adr = adr + 0x10
end
return objects
end
function s1945ii.get_missiles()
local missiles = {}
local adr = 0x6016f68
n = mem:read_u16(0x6018ecc) + mem:read_u16(0x60190d0)
for i = 1, n do
t = read_object(adr)
missiles[adr] = t
adr = adr + 0x10
end
return missiles
end
-- draw
function s1945ii.draw_enemies()
s1945ii.draw_hitbox(s1945ii.get_enemies(), 0x80ff0030, 0x000000ff)
end
function s1945ii.draw_p1_collision(radius)
s1945ii.draw_hitbox(s1945ii.get_p1_collision(), 0x80ff0030, 0xffff00ff)
end
function s1945ii.draw_missiles()
s1945ii.draw_hitbox(s1945ii.get_missiles(),0, 0xff0000ff)
end
function s1945ii.draw_hitbox(objs, color_inside, color_border)
if objs == nil then return end
for k,v in pairs(objs) do
min_x = math.max(v["x"], 0)
min_y = math.max(v["y"], 0)
max_x = math.min(v["x"]+v["width"], v["x"]+screen:width())
max_y = math.min(v["y"]+v["height"], v["y"]+screen:height())
if (v["type"] == "power" or v["type"] == "bomb" or v["type"] == "gold") then
if (v["type"] == "power") then
screen:draw_box(min_y, min_x, max_y, max_x, 0, 0x000fffff)
elseif (v["type"] == "bomb") then
screen:draw_box(min_y, min_x, max_y, max_x, 0, 0x0f00ffff)
elseif (v["type"] == "gold") then
screen:draw_box(min_y, min_x, max_y, max_x, 0, 0xf000ffff)
end
else
screen:draw_box(min_y, min_x, max_y, max_x, color_inside, color_border)
end
end
end
function s1945ii.draw_messages(str)
screen:draw_text(40, 40, str)
end
return s1945ii