evanbowman/BPCore-Engine

Print in emulator console with a dedicate memory address and a script

Opened this issue · 3 comments

So taking inspiration from here: https://www.mattgreer.dev/blog/mame-lua-for-better-retro-dev/
It will be cool to have this kind of debug.

TLDR:

  • Create a memory address specific to write debug messages
  • Call in the game
  • From the lua script in MAME get that memory aaddress and print the value

As in this case we are talking about a script engine there is anything as default to do that, but it will simplify a lot the development.

Great idea! The gba lua code allows you to write to two specific address ranges already, see here:

https://github.com/evanbowman/BPCore-Engine?tab=readme-ov-file#ram-readwrite

The _IWRAM variable is currently not a fixed address, it is placed by the linker, but you can print its contents to see what the address is.

All the required components should exist in the api, I can try it out sometime this week.

A really cool idea would be to use an emulator's lua api to put source code strings into gba memory, then read and eval() them on the gba, and write the result back to gba memory for the emulator's lua api to read. Then you'd have interactive development!

So I have this snippet for mgba and the Metal Slug Advance (https://drive.google.com/file/d/1FNTohgCTjEHrxzeDly0l3awPoti8W0nU/view):

function detectGame()
console:log(emu:getGameTitle())
end
count = 0
function updateBuffer()
count = count + 1
-- Wait around 2 seconds
if count == 120 then
console:log('Updating ammo')
-- Unlimited arms point
emu:write16(0x02000072, 0xFF)
count = 0
end
end
callbacks:add("start", detectGame)
callbacks:add("frame", updateBuffer)
if emu then
detectGame()
end

Mgba doc: https://mgba.io/docs/scripting.html
mgba-emu/mgba#2550
Various examples scripts: https://github.com/mgba-emu/mgba/tree/c541a79e9564310d7a81d9668f41317acf30dda1/res/scripts

I think that what are you looking to do is possible as the scripting UI has a textbox where you should be able to run lua commands.