Connect to a PC

Discuss game and other programming topics not specifically covered in another forum

Moderator: Programming Moderators

User avatar
Maziac
Posts: 110
Joined: Sun Jul 09, 2017 5:56 am

Re: Connect to a PC

Postby Maziac » Mon Dec 23, 2019 12:16 pm

DIVMMC is a good idea.
Assuming that the IM1 is enabled, is it possible that DIVMMC "catches" it, switch to it's own routine, checks for the UART and then
switches back to the original bank (ROM)?
What do you mean by "However you are still not avoiding having to modify the running program"? As I see it this wouldn't touch the running program at all and the running program doesn't have to be aware of it.
The only impact would be a slightly (hopefully acceptable) longer execution of the interrupt

Of course also the NMI button would be an option (although not so appealing as doing it all remote).

Do you have a pointer to some documentation of the DIVMMC. I.e. what addresses it watches and how to program those (if possible).

(Sorry, I am not on Facebook so I can't view the link you posted)

@SevenFFF: Thanks for the code snippets.

Ped7g
Posts: 256
Joined: Mon Jul 16, 2018 7:11 pm

Re: Connect to a PC

Postby Ped7g » Mon Dec 23, 2019 2:51 pm

if some app starts and it does set up IM2 interrupt (like most of my apps do), then the IM1 in DivMMC will lose control. And you need to patch the app code to not start im2 mode, but to figure out where its IM2 handler is supposed to be. (I guess patching the `im 2` instruction to `im 1` will probably work in your favour quite reliably, and you can then read `i` register in your interrupt handler to figure out where the app had `im 2` vector table. And it may be a bit tricky to jump from divMMC to the im2 handler ... hmm... probably not that big problem, by patching the stack a bit.)

But with Next it is actually quite tempting for the app itself to use im1 mode with custom handler either mapped by MMU or by the new read-over mapping feature of Layer 2 port, then if I recall correctly my discussion with Allen, the divMMC paging will have greater priority, so you will catch the interrupt, but I'm not sure if/how you can post-run also the original app handler, except some really convoluted schemes like copying most of it into divMMC memory and patching it there/etc ... I'm really just guessing here.

Honestly, I would first aim at providing good support for cooperating apps, which are built to support your tools by using your stub, as it's completely impossible to resolve this for any (in the absolute math sense) Z80 code (for example Kev keeps using `sp` as regular data register and his apps are running with interrupts disabled, and my old ZX demos used to be extremely sensitive to interrupt handler duration, as I was using `push/pop` fillers often even without the `di/ei` guardian, just counting on the total timing to not hit interrupt during memory fill/copy stage) ... and for anything non-tricky the im2->im1 patch sounds to me really promising, unless some major blocker is eluding my imagination.

Alcoholics Anonymous
Posts: 777
Joined: Mon May 29, 2017 7:00 pm

Re: Connect to a PC

Postby Alcoholics Anonymous » Fri Dec 27, 2019 7:30 am

Yes as Ped mentioned, most programs will probably be using im2 mode so changing to im1 and finding out where the isr is is an intrusive change to the running program.

I also forgot to mention something relatively new and that is the altrom feature. You have two 16k roms that normally behave as 48k ram 1 and 128k ram 0 as in a 128k machine but you can also lock one or the other roms in place so they aren't affected by writes to port 7ffd. Anyway, you can write whatever you want into these altroms and therefore replace the normal roms with your own code.

There isn't a whole lot of info about programming the divmmc. This link is probably the only real one:

https://velesoft.speccy.cz/zx/divide/divide-memory.htm

The divide is a related device that connects to ide devices instead of mmc as in the divmmc.

============
== DIVMMC ==
============

0xE3 Divmmc control
bit 7 = conmem = 1 to map in divmmc, 0K-8K will contain the esxdos rom, 8K-16K will contain the selected divmmc bank
bit 6 = mapram = 1 to replace the esxdos rom with divmmc bank 3
bits 3:0 = bank = selected divmmc ram bank for 8K-16K region
* conmen can be used to manually control divmmc mapping.
* divmmc automatically maps itself in when instruction fetches hit specific addresses in the rom. When this happens, the esxdos rom (or divmmc bank 3 if mapram is set) appears in 0K-8K and the selected divmmc bank appears as ram in 8K-16K.
* bit 6 can only be set, once set only a power cycle can reset it. nextreg 0x09 bit 3 can be set to reset this bit.

divmmc automapping is normally disabled by NextZXOS see nextreg 0x06 bit 4.

In the next, the divmmc is controlled by a few additional bits in the nextreg. One will disable the automap mode (the feature that watches for memory addresses and pages itself in) and the other will unlock the mapram bit which you can't normally do on a divmmc device.

Anyway the function is pretty simple. You can turn on the divmmc which will take over the bottom 16k by writing a '1' to conmem. Then the bottom 8k will be read-only and will contain the esxdos rom (not modifiable by the programmer) or divmmc bank 3 if the mapram bit is set. Bits 3:0 control which of 16 8k banks will appear as ram in the 8k-16k area. divmmc bank 3 is special and is not touched by nextzxos. However if you intend to return to nextzxos (ie not via a reset) then you should request a free divmmc bank from the operating system rather than grabbing anything.

If the automap is on, the divmmc will also page itself into the bottom 16k if you execute an instruction from a specific list of rom addresses. And it pages itself out if you do an instruction fetch from a certain range.

Late page in:

0x0000
0x0008
0x0038 (im1)
0x0066 (divmmc nmi)
0x04C6 (tape)
0x0562 (tape)

Instant page in:

0x3DXX (trdos traps)

Late disable:

0x1FF8 - 0x1FFF

"Late" means one byte is fetched from regular rom before the divmmc memory is paged in.
"Instant" means the page in is immediate for the indicated address.

The divmmc automap and the multiface cannot co-exist so if the divmmc automap is to be used, disable the multiface to make it work.

The next is probably going to get a divmmc control register that will individually enable or disable each trap address but that is not in yet.

User avatar
Maziac
Posts: 110
Joined: Sun Jul 09, 2017 5:56 am

Re: Connect to a PC

Postby Maziac » Thu Jan 02, 2020 6:31 pm

SevenFFF wrote:
Sat Dec 21, 2019 3:07 pm
So for example CSpect can be configured for COM1, your PC program for COM2, then you can use a virtual COM port loopback utility to cross-connect COM1 To COM2.
Do you know if/how this would be usable on macos or linux?

User avatar
SevenFFF
Posts: 565
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Connect to a PC

Postby SevenFFF » Thu Jan 02, 2020 6:42 pm

I only use Windows, sorry. Someone told me that Wine can map Windows COM ports to physical Linux ports, but I have no idea if you can make that work with mono.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins

User avatar
Maziac
Posts: 110
Joined: Sun Jul 09, 2017 5:56 am

Re: Connect to a PC

Postby Maziac » Thu Jan 02, 2020 7:06 pm

Maybe it would be easier to write a plugin that writes/reads the UART data from a socket.
(But then I would have to setup a mono dev environment for macOS first.)

Does one exists maybe, already.

User avatar
Maziac
Posts: 110
Joined: Sun Jul 09, 2017 5:56 am

Re: Connect to a PC

Postby Maziac » Mon Jan 06, 2020 4:34 pm

I started to implement a UART-to-socket plugin for CSpect, please see here: https://github.com/maziac/cspect-plugin-uart-socket

The plugin is started correctly as far as I can see (i.e. Init is called), my logs appear in the console.
But for some reason the plugin (i.e. "Write(eAccess _type, int _port, byte _value)") is not called when the Z80 writes to the UART.

Here is the simple Z80 code:

Code: Select all

loop:
  ld bc,0x133b
  ld a,0
  out (c),a
  jr loop
Maybe someone with a better knowledge of CSpect plugins can have a look.

User avatar
SevenFFF
Posts: 565
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Connect to a PC

Postby SevenFFF » Mon Jan 06, 2020 6:20 pm

I wrote a UART logger plugin here, and didn’t have any issues with Read or Write not being called. Perhaps you can use mine to debug yours, or maybe even just use mine?

https://github.com/Threetwosevensixseve ... ART-Logger
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins

User avatar
Maziac
Posts: 110
Joined: Sun Jul 09, 2017 5:56 am

Re: Connect to a PC

Postby Maziac » Mon Jan 06, 2020 6:31 pm

That's actually what I did. I copied the relevant parts but it seems I'm missing something.

User avatar
SevenFFF
Posts: 565
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Connect to a PC

Postby SevenFFF » Mon Jan 06, 2020 6:49 pm

That's interesting. Chris Kirby also said he had issues with Read and Write not being called. (I presume you are a different person from Chris Kirby!).

There clearly is a problem, I wonder what it is. Did you write a Visual Studio solution or something on MacOS? If VisualStudio, can you zip up the whole thing and post it here?
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins


Who is online

Users browsing this forum: No registered users and 3 guests