MAMEWorld >> EmuChat
View all threads Index   Threaded Mode Threaded  

Pages: 1

Jfarro
MAME Fan
Reged: 02/24/14
Posts: 13
Send PM


Seeking info on making a mame plugin (mem:read_u8 over TCP/IP)
#370723 - 11/02/17 10:35 AM


A while ago I wrote a hack into UME's debug on a custom compile which allowed me to read memory, and then send it over TCPIP to a client every so many milliseconds. This allows for some incredible extensibility...I could, for instance, tell what character someone selected in MK, and list the moveset. I could put up maps of Zelda or Atari 2600 Adventure, and overlay where the person was on those maps (and then overlay the secrets for the Zelda one). I had dozens of ideas, but I wanted to release it in a way the community could build upon it. The hack I did into mame's source was sloppy, hurt perf, and required running under the debugger.

With the LUA plugins, I've been meaning to revisit this, and finally did. I have a basic proof of concept working, as far as I can get the memory address of the NES Zelda locations. My next step is to dump those off, ideally, to another application which would do the heavy lifting of the map display and such. Ideally I'd just have the LUA plugin in mame send the data over TCP/IP to my client, which could be on the same box or another. This technique could also be used for remote debugging.

Here's my challenge...I'm a bit of a LUA noob (though I learn fast). I want to import the socket library, but it appears that the version of LUA that is included with Mame doesn't have it (or I'm doing it wrong). Any LUA experts out there got a sec to help me out?

From the LUA console, I'm trying to call:
local socket=require("socket")

The error I'm getting back is:
error: plugins/socket.lua:13: module 'socket.core' not found:
no field package.preload['socket.core']
no file 'plugins/socket\core.lua'
no file 'plugins/socket\core/init.lua'
no file 'C:\Users\Joe\OneDrive\Mame91\socket\core.dll'
no file 'C:\Users\Joe\OneDrive\Mame91\..\lib\lua\5.3\socket\core.dll'
no file 'C:\Users\Joe\OneDrive\Mame91\loadall.dll'
no file '.\socket\core.dll'
no file 'C:\Users\Joe\OneDrive\Mame91\socket.dll'
no file 'C:\Users\Joe\OneDrive\Mame91\..\lib\lua\5.3\socket.dll'
no file 'C:\Users\Joe\OneDrive\Mame91\loadall.dll'
no file '.\socket.dll'


I'm following code from:
http://w3.impa.br/~diego/software/luasocket/tcp.html#receive

For those curious of what this would look like, or want to see the beginning of it, launch zelda with the -console option to bring up the lua console. Then start the game, and type:

print("x: " .. mem:read_u8(0x0070) .. " y: " .. mem:read_u8(0x0084))


You'll see your location on the screen in x/y.

If you type:
print("map location: ",string.format('%x',mem:read_u8(0x00Eb)))


you'll see 77...this means your 7 spaces 'down' and 7 over...this is hex, you can actually use mem:write_u8 to write in a new hex value (It wont kick in till you try to go to the next screen..but it does wonky stuff).

If I can read that out over TCP/IP, I can show an interactive map. Almost like the Microsoft Smartglass promised for xbox back in the day. I had this working, as I stated, back in the day, but I want to 'ship it' to the community.

My command line to start mame with the proper lua console was:

mame -plugins -console nes -cart [path to Zelda rom]

Thanks in advance for any help you can provide!



Jfarro
MAME Fan
Reged: 02/24/14
Posts: 13
Send PM


Re: Seeking info on making a mame plugin (mem:read_u8 over TCP/IP) new [Re: Jfarro]
#370878 - 11/09/17 11:46 AM


Updates:

The commands above are incorrect...I realized this when trying to dev on another box, so here's the correct commands from my console (note: the above work, but you have to define cpu before you try to access it)

[MAME]> cpu = manager:machine().devices[":maincpu"]
[MAME]> for k,v in pairs(cpu.spaces) do print(k) end
program
[MAME]> mem = cpu.spaces["program"]
[MAME]> print("map location: ",string.format('%x',mem:read_u8(0x00Eb)))
map location: 77


Further, I realize now that the version of LUA with mame is not compatable with luasocket (which installs based on the version of LUA you have on a system when using rocks). I tried to get a LUA 3.5 version of luasocket and couldn't get it to compile clean. I'm kinda tired of that rathole, and instead will try to do this via named pipes. I'll post here if I get that working, or if someone else has c# to mame's LUA communication working, that'd be golden.



crazyc
MAME Fan
Reged: 06/23/16
Posts: 31
Send PM


Re: Seeking info on making a mame plugin (mem:read_u8 over TCP/IP) new [Re: Jfarro]
#370886 - 11/09/17 08:35 PM


If you use

Code:

socket = emu.file("rwc") -- rwc for read, write, create
socket:open("socket.127.0.0.1:1234")
socket:read(50) -- read 50 bytes from socket
socket:write(data)


you can use the built in socket support. open will either connect to a listening port or listen on the given port.

If you want a complete example you can look at the gdbstub plugin.

Edited by crazyc (11/10/17 02:05 AM)



Jfarro
MAME Fan
Reged: 02/24/14
Posts: 13
Send PM


Re: Seeking info on making a mame plugin (mem:read_u8 over TCP/IP) new [Re: crazyc]
#370905 - 11/10/17 11:21 AM


OMG thankyou! I've burned three days trying to get luasocket compiled for 5.3 and spinning trying to get LUA stuff figured out, when all I really wanted was a way to get a socket so I could get the data into a space I could do some cool stuff with it.

And your code / pointer got me there! Thankyou! I've got the map coordinates coming out over a socket now, so I'll work on a client to do cool stuff with it. Hopefully in a few weeks I'll have something super slick to share



Jfarro
MAME Fan
Reged: 02/24/14
Posts: 13
Send PM


Re: Seeking info on making a mame plugin (mem:read_u8 over TCP/IP) new [Re: Jfarro]
#371107 - 11/22/17 04:51 AM


Video of Zelda demo

Quick demo of what Iím working on. I finally had some success and can now work on some scenarios, making it a framework, and releasing it for others. Please let me know if you think itís cool or worth the effort

Edited by Jfarro (11/22/17 09:32 AM)



Dullaron
Diablo III - Dunard #1884
Reged: 07/22/05
Posts: 5741
Loc: Fort Worth, Tx
Send PM


Re: Seeking info on making a mame plugin (mem:read_u8 over TCP/IP) new [Re: Jfarro]
#371287 - 11/22/17 03:27 PM


> Video of Zelda demo
>
> Quick demo of what Iím working on. I finally had some success and can now work on
> some scenarios, making it a framework, and releasing it for others. Please let me
> know if you think itís cool or worth the effort

Look like you open up dev mode from that game.



Windows 10 Pro 64-bit / Intel Core i5-4460 3.20 GHz / 8.00 GB RAM / AMD Radeon R9 200 Series
http://us.battle.net/d3/en/profile/Dunard-1884/
https://sites.google.com/site/o0kinghanco0o/mame_building_info (Updated on the 07/18/2017 at 9:49 PM.)


Pages: 1

MAMEWorld >> EmuChat
View all threads Index   Threaded Mode Threaded  

Extra information Permissions
Moderator:  redk9258, URherenow, Tafoid 
3 registered and 39 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 838