Port logging

Struggling with Fuse or trying to find an emulator with a specific feature. Ask your questions here.
Post Reply
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Port logging

Post by djnzx48 »

Which emulator allows logging the port and data operand of every OUT instruction to a file?
User avatar
Stefan
Manic Miner
Posts: 794
Joined: Mon Nov 13, 2017 9:51 pm
Location: Belgium
Contact:

Re: Port logging

Post by Stefan »

I would love to help - but since I do no Spectrum development, I just don't know.

I did download Zeus and was able to add a port breakpoint (addr=254 on the out tab on the breakpoints), and it seems like you should be able to output results of breakpoints to a file, but after some fiddling - with still no output file - I gave up, you may have more luck.

The manual is - read the release notes - so was a bit of a steep learning curve for me.

As an alternative - if you just want to monitor one port, you may be able to adjust that port to 254 and then configure the emulator to save to a tzx - and then disect the tzx file.

It may be even better to wait for a response that does point to an emulator that has this functionality.

I wanted something similar for my SAM MOD player, to verify that my timing is correct, but ran into the same wall. At some point I was using Audacity to capture audio output and then sending out repeated test "samples".
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Port logging

Post by Seven.FFF »

You can definitely do it in Zeus with databreakpoint expressions. I will post an example later.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
dfzx
Manic Miner
Posts: 673
Joined: Mon Nov 13, 2017 6:55 pm
Location: New Forest, UK
Contact:

Re: Port logging

Post by dfzx »

Fuse has port breakpoints, but it doesn't seem possible to do this. If you're up for recompiling the Fuse source it appears to be as simple as adding this printf() line in periph.c:

Code: Select all

/* Write a byte to a port, taking no time */
void
writeport_internal( libspectrum_word port, libspectrum_byte b )
{
  struct peripheral_data_t callback_info;

  /* Trigger the debugger if wanted */
  if( debugger_mode != DEBUGGER_MODE_INACTIVE )
    debugger_check( DEBUGGER_BREAKPOINT_TYPE_PORT_WRITE, port );

  callback_info.port = port;
  callback_info.value = b;
printf("Writing 0x%02X to port 0x%02X\n", b, port & 0xFF);
  g_slist_foreach( ports, write_peripheral, &callback_info );
}
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
User avatar
Lethargeek
Manic Miner
Posts: 734
Joined: Wed Dec 11, 2019 6:47 am

Re: Port logging

Post by Lethargeek »

maybe i will add some basic port logging in the next releases of my emulator, when i decide on the most convenient control method not interfering with the current memory logging system
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Port logging

Post by djnzx48 »

Thanks for the suggestions. I tried compiling Fuse using both MinGW and the Windows 10 Bash shell but ran into errors on both attempts.

Redirecting to port 254 and saving to a tzx file sounds like a good idea. The only problem is, it would only output one bit for each OUT (the bit corresponding to the MIC bit). That could still be potentially useful for basic logging.

If zeusdatabreakpoint can output logging information, that would be ideal, but I couldn't figure out how to do it by reading the documentation - an example would be appreciated.
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Port logging

Post by Seven.FFF »

The way I did it was to open Zeus, and do File >> New to create a blank file. Type the following:

Code: Select all

zeusemulate "48K"
zeusdatabreakpoint 14, "zeusprinthex(pc>=$4000, pc, addr, data)", $4000, $C000
Click Assemble button, which prompts you to save your source .asm file.

Make sure Enable Data Breakpoints is checked in the emulator panel.

Click Assemble Then Emulate, so that you get (c) 1982 on the emulator tab.

Do File >> Open TZX or TAP and choose a file. I tested with Manic Miner, which turned out to not be such a great example because the title screen music does a continuous stream of OUTs.

Type LOAD "" (symbol shift is left ctrl) and ENTER

Change speed to Flat Out in the emulator panel.

wait for loading.

Put speed back to Normal in the emulator panel.

All OUTs are logged in the panel to the right of the emulator screen.

I found logging all OUTs was too much in some games, and jams up the windows message pump. If you know which ports you want to log or exclude, you can tweak dbp expression, for example:

Code: Select all

zeusdatabreakpoint 14, "zeusprinthex(pc>=$4000 and addr=$7ffd, pc, addr, data)", $4000, $C000
would just log outs to port $7ffd. The more info you know about what you want to log, the more you can filter and the more manageable the results will be.

The example also only traps the expression on RAM addresses, as putting them in the ROM makes tape loading cumbersome.

Logging 128K programs is also possible, but needs further consideration as Zeus uses 24-bit addresses to absolutely reference addresses in different pages.

The documentation IS all there in the About >> History window.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Port logging

Post by djnzx48 »

Thanks for the explanation. I got it working, but the second example didn't work initially until I changed the 'and' operator to '&&'. Also it's kind of hard to stop the logging once it's begun. But otherwise it seems to do the trick.
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Port logging

Post by Seven.FFF »

Ha sorry. I added the “and” as a last minute thing without testing it.

CSpect (another dev emulator) also does this, btw. There is a log command you can type into the debugger, documented in the readme. This one goes to file, so doesn’t have the message pump issue if you log too much too quickly.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
XoRRoX
Manic Miner
Posts: 231
Joined: Wed Jul 11, 2018 6:34 am

Re: Port logging

Post by XoRRoX »

May I ask what you are needing it for? Music logging by any chance? If so, ZXSEC does YM logging.
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Port logging

Post by djnzx48 »

I just downloaded ZXSEC and it seems nice, but I don't think it does quite what I was looking for. I wanted to examine port writes in order to fix an issue I was having with a sample playback routine (individual samples were being output in the wrong order). Now those bugs have hopefully been fixed, so I don't need to do any port logging in the near future. Anyway, thanks for the suggestion!
Post Reply