SGC problem with QL ROM emulation

Nagging hardware related question? Post here!
Post Reply
User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

SGC problem with QL ROM emulation

Post by Peter »

Hi,

I was thinking about a Q68-like ROM emulation hardware for the QL. Which means a loader (which is initially visible at $0) retrieves the ROM binary from SD card, writes it to a RAM device mapped to $0 (overwriting itself) and restarts the machine. For the normal QL and the GC this is straightforward with a suitable piece of hardware. But how could this work with the SGC?

Problem: The SGC (unlike the GC) does not see the QL-side ROM at $0 on powerup, but its own EPROM. First issue is, SGC won't recognize the loader as a known QL ROM, so I'm not sure it would even start the loader code (as it can not apply its various patches and might get confused). Assuming the SGC starts the loader anyway. The loader could then check for running on SGC and write the ROM binary to where the SCG has remapped the original ROM. But after that, the SGC would need to reboot from it's own EPROM, so it can then handle (patch etc.) whatever QL ROM is emulated. I wonder if there is a mechanism to trigger that kind of SGC reboot without pressing the reset button or patching the SGC EPROM itself?

Peter


User avatar
janbredenbeek
Super Gold Card
Posts: 629
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: SGC problem with QL ROM emulation

Post by janbredenbeek »

Peter wrote:Hi,

I was thinking about a Q68-like ROM emulation hardware for the QL. Which means a loader (which is initially visible at $0) retrieves the ROM binary from SD card, writes it to a RAM device mapped to $0 (overwriting itself) and restarts the machine. For the normal QL and the GC this is straightforward with a suitable piece of hardware. But how could this work with the SGC?

Problem: The SGC (unlike the GC) does not see the QL-side ROM at $0 on powerup, but its own EPROM. First issue is, SGC won't recognize the loader as a known QL ROM, so I'm not sure it would even start the loader code (as it can not apply its various patches and might get confused). Assuming the SGC starts the loader anyway. The loader could then check for running on SGC and write the ROM binary to where the SCG has remapped the original ROM. But after that, the SGC would need to reboot from it's own EPROM, so it can then handle (patch etc.) whatever QL ROM is emulated. I wonder if there is a mechanism to trigger that kind of SGC reboot without pressing the reset button or patching the SGC EPROM itself?
As you already noticed, there have been more people thinking about this! :)
Basically, my loader copies the ROM to RAM at $0 (only the first 8 bytes containing the boot SSP and PC vectors are write-protected) and then jumps into the SGC ROM which patches the QL ROM, thereby 'fooling' the SGC with a remapped ROM address in RAM rather than the original $400000. Of course, this will be on an already running system.

If you want to cold boot from SD card, I think Marcel's QL-SD ROM might be the solution when it's ready...

Jan


User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

Re: SGC problem with QL ROM emulation

Post by Peter »

janbredenbeek wrote:Basically, my loader copies the ROM to RAM at $0 (only the first 8 bytes containing the boot SSP and PC vectors are write-protected) and then jumps into the SGC ROM which patches the QL ROM, thereby 'fooling' the SGC with a remapped ROM address in RAM rather than the original $400000.
I did not consider this approach, because knowing how to correctly restart the patching was simply beyond my level of expertise. ;)
In my case, remapping the ROM address would not even be needed, as the QL ROM area would actually contain the emulated ROM in hardware after the loader did it's job.
Looks like all I need is to recognize the SGC and doing the same magic jump after the emulated ROM is in place...

The question is just where to locate the loader in the QL side map so the SGC actually runs it. Normally, it would be at $0, but I'm not sure the SGC would boot something that is not a known QL ROM.
janbredenbeek wrote:If you want to cold boot from SD card, I think Marcel's QL-SD ROM might be the solution when it's ready...
SD-card based ROM emulation in RAM has two advantages: First, I find it convenient to just have the ROM image as a file on SD card. I'm used to have one SD card for QDOS, one for Minerva, one for SMSQ/E.
(By the way, the Q40/Q60 have ROM emulation, but I kind of miss the Q68-like loader from SD card there, which is nicer and faster than a double boot.)

Second, some RAM at $0 would allow an SMSQ/E port to the QL. It's sort of an irony that the original machine, which would benefit most from the faster SMSQ/E Basic, can not run the OS.

To be clear: I have not decided to actually design a ROM emulator for the QL. But the issue re-occurs even when I discuss other people's hardware projects, and I try to understand the challenges.


User avatar
janbredenbeek
Super Gold Card
Posts: 629
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: SGC problem with QL ROM emulation

Post by janbredenbeek »

Peter wrote: I did not consider this approach, because knowing how to correctly restart the patching was simply beyond my level of expertise. ;)
In my case, remapping the ROM address would not even be needed, as the QL ROM area would actually contain the emulated ROM in hardware after the loader did it's job.
Looks like all I need is to recognize the SGC and doing the same magic jump after the emulated ROM is in place...
You would either have to patch the QL ROM to include a boot loader (unlikely to be possible in a few spare Kbytes) or have the boot loader in the extension ROM area at $C000. In the latter case, it will be executed after the normal boot sequence (so a SGC would have to boot twice and a GC three times).
Unfortunately the 'magic jump' is SGC-ROM dependent and the boot loader will have to make various checks on ROM version (earlier versions are GC-only and have different patch code, it's not just a question of simply scanning for specific instructions).
The question is just where to locate the loader in the QL side map so the SGC actually runs it. Normally, it would be at $0, but I'm not sure the SGC would boot something that is not a known QL ROM.
Basically there are version-dependent patches (for Sinclair ROMs) and version-independent patches (for Minerva) but there are various checks for known code patterns like the MDV driver and so on. It will be difficult if not impossible to include a SD-card boot loader in a QL ROM and still have it accepted by the SGC since you cannot just leave obsolete parts like the MDV driver out. On AH/JM ROMs there is about 4.5KB unused which may be used as loader if you manage to get the low level code in that space (and make the boot vector at $0004 point to it). Of couse this requires a hardware mod, unlike the extension ROM approach.
Second, some RAM at $0 would allow an SMSQ/E port to the QL. It's sort of an irony that the original machine, which would benefit most from the faster SMSQ/E Basic, can not run the OS.
SMSQ/E for the SGC does its own relocating and RAM setup, it's not just a copy-to-RAM operation. That makes it somewhat simpler (just load it into RAM and execute it like LRESPR) but you would still need a QL ROM and loader, also SMSQ/E for SGC probably requires a fully operational system to boot so you still need an additional boot cycle.

Jan


User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

Re: SGC problem with QL ROM emulation

Post by Peter »

janbredenbeek wrote:It will be difficult if not impossible to include a SD-card boot loader in a QL ROM and still have it accepted by the SGC since you cannot just leave obsolete parts like the MDV driver out.
Many thanks for your assessment, I suspected something like that. :(
janbredenbeek wrote:On AH/JM ROMs there is about 4.5KB unused which may be used as loader if you manage to get the low level code in that space (and make the boot vector at $0004 point to it).
I'll have to look again, but vaguely remember that a mini loader I once wrote for the Q68 (no screen output etc.) was below 4 KB. Still this QDOS bundle sounds quite unsatisfactory to me besides the copyright issue.
janbredenbeek wrote:SMSQ/E for the SGC does its own relocating and RAM setup, it's not just a copy-to-RAM operation. That makes it somewhat simpler (just load it into RAM and execute it like LRESPR) but you would still need a QL ROM and loader, also SMSQ/E for SGC probably requires a fully operational system to boot so you still need an additional boot cycle.
When I mentioned the idea of SMSQ/E for the QL, I meant a specific QL port - not an attempt to get the (S)GC version running. I think it would require some extra thought anyway as memory is sparse.


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: SGC problem with QL ROM emulation

Post by mk79 »

It's not impossible to rewrite SMSQ/E to not need RAM "down there". I wrote a version that is ROMable in theory 3 years ago, but hesitated to actually try it because debugging such a thing can be very cumbersome and time consuming. With QL-SD ROM and quick flash turnaround times I might give it another shot.


User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

Re: SGC problem with QL ROM emulation

Post by Peter »

A hardware design with RAM at $0 is probably less work than debugging a fundamental OS change. Some sort of RAM expansion is needed for SMSQ/E anyway, and also for QL-SD.


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: SGC problem with QL ROM emulation

Post by mk79 »

Probably, but then I don't see much advantage to the GoldCard, which is available. But hey, I'm all for more hardware ;)


User avatar
Peter
QL Wafer Drive
Posts: 1953
Joined: Sat Jan 22, 2011 8:47 am

Re: SGC problem with QL ROM emulation

Post by Peter »

Yes. But then it's the question if a QL with just some sort of RAM expansion makes sense at all.
Looks like Tetroid GoldCard costs only little more than anything providing the necessary RAM for SD card.


Post Reply