-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCastlevania 2.lua
More file actions
154 lines (125 loc) · 5.45 KB
/
Castlevania 2.lua
File metadata and controls
154 lines (125 loc) · 5.45 KB
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
local debugFlag = 0
local outline = {
-- Air
[0x00] = function (tileX, tileY)
end,
-- vertical half block - right
[0x01] = function (tileX, tileY)
gui.box(tileX + 8, tileY, tileX + 15, tileY + 15, "clear", "green")
end,
-- Ceiling decreasing slope
[0x02] = function (tileX, tileY)
gui.line(tileX, tileY, tileX + 15, tileY, "green")
gui.line(tileX + 15, tileY, tileX + 15, tileY + 15, "green")
gui.line(tileX, tileY, tileX + 15, tileY + 15, "green")
end,
-- Transition block
[0x03] = function (tileX, tileY)
gui.box(tileX, tileY, tileX + 15, tileY + 15, "clear", "orange")
end,
-- Fake block
[0x05] = function (tileX, tileY)
gui.box(tileX, tileY, tileX + 15, tileY + 15, "clear", "cyan")
end,
-- Ceiling increasing slope
[0x08] = function (tileX, tileY)
gui.line(tileX, tileY, tileX + 15, tileY, "green")
gui.line(tileX, tileY, tileX, tileY + 15, "green")
gui.line(tileX, tileY + 15, tileX + 15, tileY, "green")
end,
--
[0x09] = function (tileX, tileY)
gui.box(tileX, tileY, tileX + 15, tileY + 15, "clear", "purple")
end,
-- Normal block
[0x0A] = function (tileX, tileY)
gui.box(tileX, tileY, tileX + 15, tileY + 15, "clear", "red")
end,
-- Vertical half block - left
[0x0B] = function (tileX, tileY)
gui.box(tileX, tileY, tileX + 7, tileY + 15, "clear", "green")
end,
-- Transition block
[0x0C] = function (tileX, tileY)
gui.box(tileX, tileY, tileX + 15, tileY + 15, "clear", "orange")
end,
-- No idea, like block Bh, but you can fall through the middle
[0x0D] = function (tileX, tileY)
gui.box(tileX, tileY, tileX + 15, tileY + 15, "clear", "purple")
end,
-- Like block Dh
[0x0E] = function (tileX, tileY)
gui.box(tileX, tileY, tileX + 15, tileY + 15, "clear", "purple")
end,
-- Lava
[0x0F] = function (tileX, tileY)
gui.box(tileX, tileY, tileX + 15, tileY + 15, "clear", "yellow")
end
}
while true do
-- Simon's quest map data is laid out as a quad-buffered 2d 16x15 layout
-- 0x0520..27 0x0610..17
-- : : : :
-- 0x0600..07 0x06F0..F7
-- 0x0528..2F 0x0618..1F
-- : : : :
-- 0x0608..0F 0x06F8..FF
-- Each tile is 4 bits, with the upper 4 bits corresponding with the left of the 2 tiles in a byte
-- Also note that the camera Y position actually jumps from 0x00DF to 0x0100 etc.
-- Camera position in blocks
local cameraX = memory.readword(0x0053)
local cameraY = memory.readword(0x0056)
cameraY = cameraY - SHIFT(cameraY, 8) * 0x20
for y=0,14 do
for x=0,8 do
local tileX = x * 16 * 2 - AND(cameraX, 0x001F)
local tileY = y * 16 - AND(cameraY, 0x000F) - 3
local blockX = SHIFT(cameraX, 5) + x
local blockY = SHIFT(cameraY, 4) + y - 1
--if SHIFT(blockY, 4) > SHIFT(cameraY, 8) or AND(blockY, 0xF) >= 0xF then
-- blockY = blockY + 1
--end
local tile = 0
if AND(blockX * 2, 0x1F) >= 0x10 then
tile = tile + 0xE8
end
if blockY >= 15 then
tile = tile + 0x08
end
-- get block's tile number
local a = tile + AND(blockX, 0xF) + blockY % 0xF * 0x10
-- clipdata of two blocks
local clipBoth = memory.readbyte(0x0520 + a)
-- clipdata of each block
local clip0 = SHIFT(clipBoth, 4)
local clip1 = AND(clipBoth, 0xF)
-- Process the block's clipdata nibble
local outlinefunction
outlinefunction = outline[clip0] or function(tileX, tileY) gui.box(tileX, tileY, tileX + 15, tileY + 15, "clear", "purple") end
outlinefunction(tileX, tileY)
outlinefunction = outline[clip1] or function(tileX, tileY) gui.box(tileX, tileY, tileX + 15, tileY + 15, "clear", "purple") end
outlinefunction(tileX + 16, tileY)
if debugFlag ~= 0 then
gui.text(tileX + 6, tileY + 4, string.format("%X", a + 0x520), "#FFFF00", "#00000000")
if clip0 ~= 0 then
gui.text(tileX + 4, tileY + 4, string.format("%X", clip0), "#FFFF00", "#00000000")
end
if clip1 ~= 0 then
gui.text(tileX + 16 + 4, tileY + 4, string.format("%X", clip1), "#FFFF00", "#00000000")
end
end
end
end
if debugFlag ~= 0 then
gui.text(0, 0, string.format(
"Screen X: %04X\nScreen Y: %04X",
cameraX,
cameraY
), "#00FFFF")
end
--local Layer1X, Layer2X, Layer2Scroll = memory.readshort(0x7E0911), memory.readshort(0x7E0917), memory.readbyte(0x7E091B)
--local Should = SHIFT(Layer2Scroll * Layer1X, 8)
--local Predicted = Should + Should
--gui.text(0, 0, string.format("Layer 1 X: %04X\nLayer 2 X: %04X\nLayer2Scroll: %02X\nShould: %04X\nPredicted: %04X", Layer1X, Layer2X, Layer2Scroll, Should, Predicted), "#00FFFF")
emu.frameadvance()
end