Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/Assets/Lua/NES/Simons Quest.lua
2 views
1
--Author Pasky13
2
3
-- Toggles
4
local show_hud = true
5
local show_elife = true -- Enemy life
6
7
-- Player
8
local px = 0x348
9
local py = 0x324
10
local pl = 0x80
11
local ph = 0x48
12
local pe = 0x46
13
local pt = 0x85
14
15
-- Enemy
16
local el = 0x4C2
17
local ex = 0x348
18
local ey = 0x324
19
local oob = 0x3C6
20
local point = 0x3FC
21
22
local xm
23
local ym
24
25
local function hex(val)
26
val = string.format("%X",val)
27
return val
28
end
29
30
function findbit(p)
31
return 2 ^ (p - 1)
32
end
33
34
function hasbit(x, p)
35
return x % (p + p) >= p
36
end
37
38
memory.usememorydomain("PRG ROM")
39
40
local function formatstring(adr)
41
local str
42
if string.len(string.format("%X",mainmemory.read_u8(adr+1))) == 1 then
43
str = "0" .. string.format("%X", mainmemory.read_u8(adr+1))
44
else
45
str = string.format("%X", mainmemory.read_u8(adr+1))
46
end
47
if adr == pt then
48
str = str .. ":"
49
end
50
if string.len(string.format("%X",mainmemory.read_u8(adr))) == 1 then
51
str = str .. "0" .. string.format("%X",mainmemory.read_u8(adr))
52
else
53
str = str .. string.format("%X", mainmemory.read_u8(adr))
54
end
55
return str
56
end
57
58
local function buildbox(i)
59
local offset1 = mainmemory.read_u8(0x3B4 + i) * 2
60
local pointer1 = memory.read_u8(0x4AC0 + offset1) + (memory.read_u8(0x4AC1 + offset1) * 0x100)
61
local offset2 = mainmemory.read_u8(0x3FC + i)
62
63
if offset2 > 0 then
64
offset2 = offset2 - 1
65
end
66
67
local offset3 = memory.read_u8(pointer1 + offset2 - 0x4000)
68
local offset3 = ((offset3 * 2) + offset3) % 0x100
69
local box = { memory.read_s8(0x4B7E + offset3), memory.read_u8(0x4B7F + offset3),memory.read_u8(0x4B80 + offset3) } -- yoff/yrad/xrad
70
71
return box
72
end
73
74
local function player()
75
local x = mainmemory.read_u8(px)
76
local y = mainmemory.read_u8(py)
77
78
gui.drawBox(x - 6,y + 3 - 0x0A,x + 6,y + 3 + 0x0A,0xFF0000FF,0x400000FF)
79
80
-- Whip
81
if mainmemory.read_u8(0x445) == 3 then
82
local wxoff = 0x16
83
local wyoff = -4
84
local wxrad
85
local wyrad = 4
86
local woff = mainmemory.read_u8(0x434)
87
if mainmemory.read_u8(0x420) == 0 then
88
wxoff = wxoff * -1
89
end
90
wxrad = memory.read_u8(0x4BDD + woff)
91
gui.drawBox(x+wxoff-wxrad,y+wyoff-wyrad,x+wxoff+wxrad,y+wyoff+wyrad,0xFFFFFFFF,0x40FFFFFF)
92
end
93
94
end
95
96
local function objects()
97
local x
98
local y
99
local l
100
local box
101
local active
102
local fill
103
local outl
104
local isoob
105
local etype
106
for i = 2,19,1 do
107
active = mainmemory.read_u8(0x3D8 + i)
108
isoob = mainmemory.read_u8(oob + i)
109
etype = mainmemory.read_u8(0x3B4 + i)
110
111
if etype > 0 and etype ~= 0x43 and etype ~= 0x1E and etype ~= 0x2A then
112
box = buildbox(i)
113
x = mainmemory.read_u8(ex + i)
114
y = mainmemory.read_u8(ey + i)
115
l = mainmemory.read_u8(el + i)
116
if hasbit(active,findbit(1)) and not hasbit(active,findbit(8)) then -- Enemy
117
118
if bit.rshift(bit.band(isoob,0xF0),4) ~= 8 and bit.rshift(bit.band(isoob,0xF0),4) ~= 4 then -- If not offscreen
119
if show_elife == true then
120
gui.text((x-8) * xm,(y-28) * ym,"HP: " .. l)
121
end
122
end
123
fill = 0x40FF0000
124
outl = 0xFFFF0000
125
elseif hasbit(active,findbit(8)) and hasbit(active,findbit(1)) then -- Hidden enemy, no active box
126
outl = 0x40FF0000
127
fill = 0x00FF0000
128
129
if bit.rshift(bit.band(isoob,0xF0),4) ~= 8 and bit.rshift(bit.band(isoob,0xF0),4) ~= 4 then -- If not offscreen
130
if show_elife == true then
131
gui.text((x-8) * xm,(y-28) * ym,"HP: " .. l)
132
end
133
end
134
elseif hasbit(active,findbit(8)) and hasbit(active,findbit(2)) then -- Simon's projectiles
135
outl = 0xFF00FFFF
136
fill = 0x4000FFFF
137
elseif not hasbit(active,findbit(8)) and hasbit(active,(2)) then -- Enemy projectile
138
outl = 0xFFFFFF00
139
fill = 0x40FFFF00
140
elseif hasbit(active,findbit(8)) and not hasbit(active,findbit(2)) then -- Inactive box
141
outl = 0
142
fill = 0
143
elseif hasbit(active,findbit(7)) then -- NPC
144
outl = 0xFFFF00FF
145
fill = 0x40FF00FF
146
elseif hasbit(active,findbit(3)) then -- Item pickups
147
outl = 0xFFFFA500
148
fill = 0x40FFA500
149
end
150
if bit.rshift(bit.band(isoob,0xF0),4) ~= 8 and bit.rshift(bit.band(isoob,0xF0),4) ~= 4 then -- If not offscreen
151
gui.drawBox(x - box[3],y+box[1]+box[2],x+box[3],y+box[1]-box[2],outl,fill)
152
end
153
154
end
155
156
end
157
158
end
159
160
local function HUD()
161
local l = mainmemory.read_u8(pl)
162
local h = 0
163
local e = 0
164
local t = 0
165
166
-- Hearts
167
h = formatstring(ph)
168
-- Experience
169
e = formatstring(pe)
170
-- Time
171
t = formatstring(pt)
172
173
gui.text(14 * xm, 9 * ym, l)
174
gui.text((256 - 40) * xm, 9 * ym,"H: " .. h)
175
gui.text((256 - 40) * xm, 17 * ym,"E: " .. e)
176
gui.text((256 - 85) * xm, 9 * ym, "T: " .. t)
177
end
178
179
local function scaler()
180
xm = client.screenwidth() / 256
181
ym = client.screenheight() / 224
182
end
183
184
while true do
185
scaler()
186
if show_hud == true then
187
HUD()
188
end
189
player()
190
objects()
191
emu.frameadvance()
192
end
193