Previous Thread
Next Thread
Print Thread
Page 1 of 2 1 2
#124639 06/17/25 01:50 PM
Joined: Feb 2014
Posts: 1,225
Likes: 224
G
Very Senior Member
Very Senior Member
G Offline
Joined: Feb 2014
Posts: 1,225
Likes: 224
I was trying to use install_write_tap in lua to watch writes to an io port,

the novag savant (driver name is savant) writes to 0xc1 and I wanted to watch this:

manager.machine.devices[":maincpu"].spaces["io"]:install_write_tap(0xc1,0xc1,"hi",function(offset,data,mask)print("testing",offset,data,mask) end)

It will run it a single time, then I don't see any more output.

testing 193 0 255




Am I doing something wrong?


(so every time you move a piece, the savant will write to c1 (which connects to an external clock timer))

Last edited by Golden Child; 06/17/25 07:24 PM.
Joined: Feb 2004
Posts: 2,641
Likes: 351
Very Senior Member
Very Senior Member
Joined: Feb 2004
Posts: 2,641
Likes: 351
Write taps work properly in Lua. I’ve used them extensively for debugging the IGS gambling games. Think about what you’re neglecting.

Joined: Feb 2014
Posts: 1,225
Likes: 224
G
Very Senior Member
Very Senior Member
G Offline
Joined: Feb 2014
Posts: 1,225
Likes: 224
ok, got it. understood.

The z80 io bus is weird, you can't just look at the low 8 bits, you have to consider 16bits and the data seems to get written to the high 8 bits.



so in the io map, when we look at c1 there's a mirror:

map(0xc1, 0xc1).mirror(0xff38).lw8([this](u8 data){printf("c1 data = %x %s\n", data, machine().describe_context().c_str());
}, "c1 write"); // printer



and adjusting the write tap to look at any IO address, now I see the writes to c1:

Code
m_maincpu->space(AS_IO).install_write_tap(
    0x0,0xffff,
    "maincpu_ext_w",
    [this] (offs_t offset, u8 &data, u8 mem_mask)
    {
	if ((offset & 0xff) == 0xc1)
	printf("WRITE TAP CPP = %x, %x\n",(u8) offset, (u8) data);
    });

Last edited by Golden Child; 06/17/25 07:18 PM.
Joined: Feb 2014
Posts: 1,225
Likes: 224
G
Very Senior Member
Very Senior Member
G Offline
Joined: Feb 2014
Posts: 1,225
Likes: 224
ok, so if I run this:

./mame savant


sp = manager.machine.devices[":maincpu"].spaces["io"] sp:install_write_tap(0x0,0xffff,"hi5",function(offset,data) print(string.format("%x",offset),data)end)


It will run for awhile, then abruptly stop.



If I launch colecovision with

./mame coleco timeplt

and do

sp = manager.machine.devices[":maincpu"].spaces["io"] sp:install_write_tap(0x0,0xff,"hi5",function(offset,data) print(string.format("%x",offset),data)end)

(coleco has an address mask of 0xff)


it will run for awhile then just stop. I can start it up again with the same command line, but it will stop soon.

Shouldn't it keep running?

Joined: Feb 2004
Posts: 2,641
Likes: 351
Very Senior Member
Very Senior Member
Joined: Feb 2004
Posts: 2,641
Likes: 351
It works. You’re neglecting something important.

Joined: Feb 2014
Posts: 1,225
Likes: 224
G
Very Senior Member
Very Senior Member
G Offline
Joined: Feb 2014
Posts: 1,225
Likes: 224
ok, so I call install_write_tap and it stops working, I put a printf in the remove routine and I can see where it gets removed.

Code
    void remove()
        {
                ++m_installing;
                try
                {
                        printf("removing  passthrough %s   \n",name().c_str());
                        m_handler.remove();
                }
                catch (...)
                {
                        --m_installing;
                        throw;
                }
                --m_installing;
        }

Code

function d (offset,data) c=c or 0  c=c+1 print("FUNCTION D",string.format("%x",offset),data,c,emu.time()) end

sp = manager.machine.devices[":maincpu"].spaces["io"] sp:install_write_tap(0x0,0xffff,"hi6",d)



[MAME]> function d (offset,data)c=c or 0 c=c+1 print("FUNCTION D",string.format("%x",offset),data,c,emu.time()) end
[MAME]> sp = manager.machine.devices[":maincpu"].spaces["io"] sp:install_write_tap(0x0,0xffff,"hi6",d)
INSTALLING WRITE TAP 0
[MAME]>

FUNCTION D c5 0 1 0.00012799999999949
WRITE_TAP_EXECUTEd offset=c5 data=0
...
FUNCTION D 1fc0 31 232 0.56272483333108
WRITE_TAP_EXECUTEd offset=1fc0 data=1f
FUNCTION D 1fc0 31 233 0.56648099999773
WRITE_TAP_EXECUTEd offset=1fc0 data=1f
removing passthrough hi6

I don't understand why it gets removed. I have another tap installed in the savant.cpp machine_start that continues to run along without any problems.

Joined: Feb 2004
Posts: 2,641
Likes: 351
Very Senior Member
Very Senior Member
Joined: Feb 2004
Posts: 2,641
Likes: 351
It’s something fundamental.

Joined: Jun 2001
Posts: 539
Likes: 45
O
Senior Member
Senior Member
O Offline
Joined: Jun 2001
Posts: 539
Likes: 45
He's getting GC-ed into oblivion? One has to admit the documentation is quite unclear on the fact that the lua install_*_tap returns something, even less something important.

1 member likes this: Golden Child
Joined: Feb 2014
Posts: 1,225
Likes: 224
G
Very Senior Member
Very Senior Member
G Offline
Joined: Feb 2014
Posts: 1,225
Likes: 224
Ahhhh, ok. That makes sense.

function d (offset,data)c=c or 0 c=c+1 print("FUNCTION D",string.format("%x",offset),data,c,emu.time()) end
sp = manager.machine.devices[":maincpu"].spaces["io"]

holdit=sp:install_write_tap(0x0,0xffff,"hi6",d)


[MAME]> print(holdit)
sol.sol::d::u<lua_engine::tap_helper>: 0x561c31740048




so as long as holdit holds the value, it doesn't get GC'd!

and then holdit=nil will allow it to get GC'd.

thanks for the pointer, OG!


(you know I was thinking that it got GC'd possibly, didn't think to "grab" a handle to prevent that)

Last edited by Golden Child; 06/27/25 07:04 PM.
Joined: Feb 2004
Posts: 2,641
Likes: 351
Very Senior Member
Very Senior Member
Joined: Feb 2004
Posts: 2,641
Likes: 351
Originally Posted by Olivier Galibert
He's getting GC-ed into oblivion? One has to admit the documentation is quite unclear on the fact that the lua install_*_tap returns something, even less something important.
Hey, it actually has a clickable link to the documentation for the class of the thing it returns!

Page 1 of 2 1 2

Link Copied to Clipboard
Who's Online Now
4 members (AJR, box, Kale, Cpt. Pugwash), 223 guests, and 3 robots.
Key: Admin, Global Mod, Mod
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics9,381
Posts122,711
Members5,085
Most Online1,529
Jun 7th, 2025
Our Sponsor
These forums are sponsored by Superior Solitaire, an ad-free card game collection for macOS and iOS. Download it today!

Superior Solitaire
Powered by UBB.threads™ PHP Forum Software 8.0.0