1
0
Fork 0
mirror of https://github.com/notwa/mm synced 2024-05-17 21:23:22 -07:00

hook debug printing in OoT debug rom

This commit is contained in:
Connor Olding 2015-12-26 19:06:50 -08:00
parent bb5c778b0f
commit 488aeb9bd0
3 changed files with 85 additions and 1 deletions

View File

@ -23,6 +23,12 @@ local injection_points = {
ow_addr = 0x0A19C8,
ow_before = 0x0C0283EE,
},
['O EUDB MQ'] = {
inject_addr = 0x700000,
inject_maxlen = 0x100000,
ow_addr = 0x0C6940,
ow_before = 0x0C03151F,
},
}
local header = [[
@ -89,10 +95,13 @@ function inject(fn)
assemble(asm_path, write, {unsafe=true, offset=true_offset + length})
printf("length: %i words", length/4)
--[[
-- FIXME: this only works properly when the asm doesn't use any .orgs
if length > inject_maxlen then
print("Assembly too large!")
return
end
--]]
for pos, val in pairs(inject_bytes) do
W1(pos, val)
@ -114,7 +123,11 @@ function inject(fn)
end
if oot then
inject('spawn oot.asm')
if version == 'O EUDB MQ' then
inject('print.asm')
else
inject('spawn oot.asm')
end
else
if version == 'M JP10' or version == 'M JP11' then
inject('spawn mm early.asm')

40
Lua/inject/print.asm Normal file
View File

@ -0,0 +1,40 @@
// translates calls to 800021F8
// to copy strings to memory instead
// for Lua to later pick up on
// reset buffer position in our per-frame hook
la t0, buffer
sw t0, buffer_pos
// and set the string to null
sb r0, 0(t0)
jr
nop
// keep track of where we are in the buffer
buffer_pos:
.word 0
// set up 2048 bytes of text buffer
// each line is 32 words, or 128 bytes
// i don't think this is enough, actually
.align 8
buffer:
.word 0
// overwrite (not hook) the debug printing function
.org 0x800021B0
// a0: unknown
// a1: char *msg
// a2: size_t len
lw t0, buffer_pos
copy_loop:
lb t1, 0(a1)
sb t1, 0(t0)
addi t0, t0, 1
addi a1, a1, 1
subi a2, a2, 1
bne a2, r0, copy_loop
sb r0, 0(t0) // null terminate
sw t0, buffer_pos
jr
nop

31
Lua/print.lua Normal file
View File

@ -0,0 +1,31 @@
require = require "depend"
require "boilerplate"
local buffer = 0x700070
local vfc = A(0x168960, 4)
while true do
local pos = buffer
local str = ''
while true do
local b = R1(pos)
pos = pos + 1
if b == 0 then
break
end
if b < 0x80 then
str = str..string.char(b)
else
str = str..'?'
end
end
print(str)
local old = vfc()
for i=1,30 do
emu.frameadvance()
local new = vfc()
if new ~= old then break end
end
console.clear() -- delete this if you want
end