-
Notifications
You must be signed in to change notification settings - Fork 3
/
taus-test.lua
154 lines (143 loc) · 4.59 KB
/
taus-test.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
require("ypcall") -- must be first, as it changes globals
require("asm")
require("testing")
local labels = asm.loadlabels("build/taus.lbl")
local ntsc = labels["demoButtonsTable_indexIncr"] == 0x9DE8
function assertbyte (label, expected)
local b = memory.readbyte(labels[label])
if b ~= expected then
error(label .. " expected: " .. expected .. " actual: " .. b)
end
end
function assertbyteoff (label, off, expected)
local b = memory.readbyte(labels[label] + off)
if b ~= expected then
error(label .. "+" .. off .. " expected: " .. expected .. " actual: " .. b)
end
end
function test_demo ()
asm.waitexecute(0x823F)
joypad.set(1, {start=true}) -- skip legal
asm.waitbefore()
joypad.set(1, {start=nil})
asm.waitexecute(0x828D)
local startFrame = emu.framecount()
memory.writebyte(labels.frameCounter+1, 5) -- force title screen timeout
asm.waitexecute(0x8158) -- wait for demo to end
if emu.framecount() - startFrame ~= (ntsc and 4760 or 3825) then
error("frame count changed: " .. (emu.framecount()-startFrame))
end
assertbyteoff("score", 0, ntsc and 0x90 or 0x85)
assertbyteoff("score", 1, ntsc and 0x42 or 0x21)
assertbyteoff("score", 2, 0x00)
assertbyteoff("DHT", 0, ntsc and 0x01 or 0x00)
assertbyteoff("DHT", 1, 0x00)
assertbyteoff("BRN", 0, ntsc and 0x02 or 0x04)
assertbyteoff("BRN", 1, 0x00)
assertbyteoff("EFF", 0, ntsc and 0x88 or 0x24)
assertbyteoff("EFF", 1, 0x01)
assertbyteoff("TRT", 0, ntsc and 0x57 or 0x30)
assertbyteoff("TRT", 1, 0x00)
assertbyteoff("TRNS", 0, ntsc and 0x86 or 0x43)
assertbyteoff("TRNS", 1, ntsc and 0x40 or 0x19)
assertbyteoff("TRNS", 2, 0x00)
assertbyteoff("levelEffs", 0, math.floor((ntsc and 195 or 147)/2/3.125))
assertbyteoff("levelEffs", 1, 0x00)
end
function test_divmod ()
asm.waitexecute(0x813B) -- cmp gameModeState in @mainLoop
asm.jsr(labels.disableNmi)
local tests = {
{1234, 43},
{0, 1},
{234, 234},
{255*255, 255},
}
for _, test in ipairs(tests) do
local dividend = test[1]
local divisor = test[2]
memory.writebyte(labels.tmp1, dividend % 256)
memory.writebyte(labels.tmp2, dividend / 256)
memory.setregister("a", divisor)
local startcycles = debugger.getcyclescount()
asm.jsr(labels.divmod)
local cycles = debugger.getcyclescount() - startcycles
print("cycles: " .. cycles)
assertbyte("tmp1", math.floor(dividend / divisor))
assertbyte("tmp2", dividend % divisor)
end
end
function test_binaryToBcd ()
asm.waitexecute(0x813B) -- cmp gameModeState in @mainLoop
asm.jsr(labels.disableNmi)
local tests = {
{0, 0x00},
{10, 0x10},
{999, 0x999},
{454, 0x454},
{134, 0x134},
}
for _, test in ipairs(tests) do
local bin = test[1]
local bcd = test[2]
memory.writebyte(labels.tmp1, bin % 256)
memory.setregister("a", bin / 256)
local startcycles = debugger.getcyclescount()
asm.jsr(labels.binaryToBcd)
local cycles = debugger.getcyclescount() - startcycles
print("cycles: " .. cycles)
local a = memory.getregister("a")
assert(a == (bcd % 256), "a: " .. a)
assertbyte("tmp2", math.floor(bcd / 256))
end
end
function test_multiplyBy100 ()
asm.waitexecute(0x813B) -- cmp gameModeState in @mainLoop
asm.jsr(labels.disableNmi)
local tests = {
{0, 0},
{3, 300},
{100, 10000},
{655, 65500},
}
for _, test in ipairs(tests) do
local bin = test[1]
local bcd = test[2]
memory.writebyte(labels.tmp1, test[1] % 256)
memory.writebyte(labels.tmp2, test[1] / 256)
local startcycles = debugger.getcyclescount()
asm.jsr(labels.multiplyBy100)
local cycles = debugger.getcyclescount() - startcycles
print("cycles: " .. cycles)
assertbyte("tmp1", math.floor(test[2] % 256))
assertbyte("tmp2", math.floor(test[2] / 256))
end
end
function test_benchdoDiv ()
asm.waitbefore()
asm.waitbefore()
local score = 7656 / 2
local lines = 33 -- result = 232
memory.writebyte(labels.tmp1, score % 256)
memory.writebyte(labels.tmp2, score / 256)
memory.setregister("a", lines)
memory.setregister("pc", labels.doDiv)
local startcycles = debugger.getcyclescount()
asm.waitexecute(labels.statsPerLineClearDone)
local cycles = debugger.getcyclescount() - startcycles
print("cycles: " .. cycles)
assertbyteoff("EFF", 0, 0x32)
assertbyteoff("EFF", 1, 0x02)
end
-- If repeated, this can produce different results, because it doesn't sanitize
-- the current stats values.
function test_benchstatsPerLineClear ()
asm.waitexecute(0x813B) -- cmp gameModeState in @mainLoop
asm.jsr(labels.disableNmi)
memory.writebyte(labels.completedLines, 3)
local startcycles = debugger.getcyclescount()
asm.jsr(labels.statsPerLineClear)
local cycles = debugger.getcyclescount() - startcycles
print("cycles: " .. cycles)
end
testing.run()