ZX Spectrum: Rebuilding boot.com

User avatar
JamesH
Posts: 56
Joined: Sat Dec 26, 2020 11:41 am
Has thanked: 5 times
Been thanked: 15 times

ZX Spectrum: Rebuilding boot.com

Unread post by JamesH »

Hello everybody!

I was wondering if it may be possible to rebuild the ZX Spectrum's boot.rom file and replace certain portions? Are those modified in any way or is it just a collection of vanilla ROMs (doesn't really look like this at a glance or at least they aren't split at 16k boundary). 4th 16k fragment seems to be FUSE's 128-1.rom and the last two are mf.rom and 48.rom, but I failed to identify other chunks.

I was wondering it if it possible to use +3e DOS -- we have divmmc implemented already. And that means replacing +3 ROM. But how do I do this?

Thanks.

jordi
Posts: 282
Joined: Thu Jun 11, 2020 10:11 am
Has thanked: 112 times
Been thanked: 87 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by jordi »

JamesH wrote: Sun May 21, 2023 9:47 am

Hello everybody!

I was wondering if it may be possible to rebuild the ZX Spectrum's boot.rom file and replace certain portions? Are those modified in any way or is it just a collection of vanilla ROMs (doesn't really look like this at a glance or at least they aren't split at 16k boundary). 4th 16k fragment seems to be FUSE's 128-1.rom and the last two are mf.rom and se.rom, but I failed to identify other chunks.

I was wondering it if it possible to use +3e DOS -- we have divmmc implemented already. And that means replacing +3 ROM. But how do I do this?

Thanks.

Kyp told me he might port to Mister a +3 specific core he did.

That core has direct support for +3e.

User avatar
Chris23235
Top Contributor
Posts: 983
Joined: Sun May 24, 2020 8:45 pm
Has thanked: 127 times
Been thanked: 197 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by Chris23235 »

At least on Sorgelig's original core for the MiST FPGA (which I think was ported by him over to the MiSTer) it was possible to change the roms. The documentation for the MiST says:

ROM Format:

You can create your own spectrum.rom, for example to replace +3 ROMs with +3e. The format is: Boot (GLUK) + TRDOS + 128 ROM0 + 128 ROM1 + +3 ROM0/1/2/3 + PlusD + MF128 + MF3 + 48K ROM + GS(low) + GS(high). Each part is 16k.

https://github.com/sorgelig/ZX_Spectrum-128K_MIST

So I think it is worth a try to just replace the +3 ROM with the +3e ROM.

User avatar
JamesH
Posts: 56
Joined: Sat Dec 26, 2020 11:41 am
Has thanked: 5 times
Been thanked: 15 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by JamesH »

Interesting, that answers the second part of my question. Thanks a lot! Although it means I'll have to wait :) I am not good for any FPGA development work, so I cannot participate, sadly :(

Speaking of the first part, what I think is the order of the ROMs in boot.rom, based on a string search (I was doing exact byte to byte comparison earlier),in 16k blocks:

  1. GLUCK

  2. TR DOS 5.04T -- unofficial version? I thought 5.03 was the last one

  3. 128, part 1

  4. 128 part 2 -- this one exactly matches 128-1.rom from FUSE

  5. +3, part 1 - 4.1

  6. +3, part 2 - 4.1

  7. +3, part 3 - 4.1

  8. +3, part 4 - 4.1

  9. +D

  10. Multiface 128

  11. Multiface -- corresponds to mf3.rom and mf1.rom from FUSE, but no exact match

  12. 48 -- exact match for FUSE's 48.rom

That seems to match MIST core, except the GeneralSound (?) part. Could someone please confirm this? Or, perhaps, it is actually documented somewhere and I just failed to find it?

Thanks.

User avatar
JamesH
Posts: 56
Joined: Sat Dec 26, 2020 11:41 am
Has thanked: 5 times
Been thanked: 15 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by JamesH »

Alright, I was able to replace +3 portions with +3e ROMs ("dvm" prefix) and it seems to be [sort of] working. Octocom's Workbench boots and works. I wasn't able to launch CP/M from ZX Uno, but it fails the same way in FUSE (works with ZEsarUX, somehow). Thus, it is possible to use pre-built +3e images.

+3e menu
+3e menu
loader.png (28 KiB) Viewed 7472 times
Workbench loading screen
Workbench loading screen
wb.png (29.81 KiB) Viewed 7472 times

UPD: CP/M seems to work fine [with divmmc, of course] when using LOADERD.BAS by Spirax. Unfortunately, I do not understand Spanish, but online translation was good enough to get it working :) I must mention that ZEsarUX does not need any force-enabling of the divmmc (which is what LOADERD.BAS does, if I understand it correctly), but it's an extremely unusual use case -- running CP/M from +3e DOS "drive" on Spectrum. For the most intents and purposes +3e + divmmc may be supported, I guess. Any thoughts?

CP/M via divmmc under +3e DOS
CP/M via divmmc under +3e DOS
cp-m.png (41.03 KiB) Viewed 7383 times
User avatar
pgimeno
Top Contributor
Posts: 710
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by pgimeno »

See viewtopic.php?p=60600#p60600 and the post after that

User avatar
JamesH
Posts: 56
Joined: Sat Dec 26, 2020 11:41 am
Has thanked: 5 times
Been thanked: 15 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by JamesH »

pgimeno wrote: Sun May 21, 2023 1:17 pm

See viewtopic.php?p=60600#p60600 and the post after that

That's great, thanks a lot for confirming. I guess a pull request or an issue is in order to get that recorded properly at https://github.com/MiSTer-devel/ZX-Spec ... /README.md

I'll try to submit one, unless, well, "life happens" :)

UPD: Submitted issue/39

Thanks.

User avatar
Chris23235
Top Contributor
Posts: 983
Joined: Sun May 24, 2020 8:45 pm
Has thanked: 127 times
Been thanked: 197 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by Chris23235 »

Sorgelig answered, according to him the info in

viewtopic.php?p=60600#p60600

should be correct.

User avatar
JamesH
Posts: 56
Joined: Sat Dec 26, 2020 11:41 am
Has thanked: 5 times
Been thanked: 15 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by JamesH »

Yep, going to file a pull request as soon as I am able to revive my github account.

User avatar
JamesH
Posts: 56
Joined: Sat Dec 26, 2020 11:41 am
Has thanked: 5 times
Been thanked: 15 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by JamesH »

For the record, I spent some time trying to track the relevant ROMs and understand the changes. Here is what I found.

For the reference, here is the boot.rom file map pgimeno was able to create:

Code: Select all

Offs. Len. File name
00000 4000 GLUK661.ROM
04000 4000 TRDOS-5.04T
08000 4000 128p-0.rom
0C000 4000 128-1.rom
10000 4000 plus3-41-0.rom
14000 4000 plus3-41-1.rom
18000 4000 plus3-41-2.rom
1C000 4000 plus3-41-3.rom
20000 2000 plusd-patched.rom
22000 2000 plusd-sys.bin
24000 2000 MF128_36_3C.ROM
26000 2000 disasm.rom
28000 2000 mf3.rom
2A000 2000 zeros.bin
2C000 4000 48.rom

GLUCK661.ROM can be found on the author’s page, the actual ROM file name in the archive is glukpen.rom (it’s for Pentagon?). Source code is also available.

TR-DOS 5.04T seems to be an unofficial version which introduces some sort of “Turbo” format without modifying much else, so I assume it should be safe to replace it with 5.03 since we don’t really have real floppy drives and I doubt that “Turbo” format, which I presume is just a clever way to interleave sectors on disk, is going to speed up anything.

128p-0.rom and 128-1.rom can be found in many places (FUSE, for example). The interesting thing here is the use of the Pentagon’s first half.

+3 version 4.1 can also be found in many places. According to my experiments, it can be replaced with +3e, if necessary.

plusd ROM with a patch in an interesting beast, but I believe the “patch” is actually a dump error. The modification always forces “building bitmap at 0A6B” but all code belongs to “SCAN CATALOGUE SUBROUTINE, so the modification is likely not needed. I think it should be safe to replace it with vanilla plusd.rom I think this modification is required, please see all details in the following post.

Now, plusd-sys.bin dump, is a modified version of the CONFIG2 code from the “MGT System Tape”. Three areas are modified, two appear to be dump errors. The actual functional change is the one related to screen selection when taking snapshot on 128:
SNP128_2 routine updated code:

Code: Select all

21BF:	LD BC, #DFFE	LD BC, DFBF	; poll keyboard row ?? Instead Y-P does DFBF port exist?
21C4:	BIT 4,E	->	BIT 7,E
21C6	JR Z, +17	->	JR NZ, +17	; CHANGED
…
21CE:	JR Z, +20	->	JR +20		; SNP128_2

UPD 2023-05-30: Alright, I think I found mysterious port #DFBF. Comment says "read video page. available for MF128 and PlusD(patched)." So the screen page configuration is available via bit 7, and the code snippet makes sense.

I believe the following changes are safe to ignore.

SYSTEM VARIABLES block:

Code: Select all

        ORIG    NEW     ID      COMMENT
2003:   06      0C      STPRAT  "Steprate" 6 msec. (0C for MiSTer)
2008:   00      01      LFEED   Number of line feeds after CR 1 ; default 1 no sure why CONFIG2 has 0 there, perhaps it’s updated by the BASIC programme

PRINTER CODES block, these definitely do not affect anything

Code: Select all

2012:   0d      1B      INIT_PRT
2013:   80      40      INIT_PRT+1

201B:   4D      50      CHAR_PITCH+1

202B:   2a      4B      GRAPH_DPI+1
202C:   05      80      GRAPH_DPI+2 

The boot.rom section also contains something after 3a00 (that plusd-sys.bin is loaded at 2000), area which is not used by the known source. Perhaps a dump from a live system? it may be necessary to avoid +D initialisation from a disk.

Multiface 128 ROM is available here as MF128 vs.87.2.rom

disasm.rom is a funny creature. I think it’s a replacement for Multiface’s Genie debugger/disassembler. Disassembler this is actually the second half of the 16k ROM "Genie 128 Disassembler" available here.

Multiface 3 ROM available here as mf3 (kio-2006-07-13).rom

And, finally, 48 ROM is a regular, original, 48K rom available from many places.

Now, practical conclusion. It should be safe to replace almost all portions of the boot.com except the plusd-sys.bin. Based on the text above you should be able to take the CONFIG2 block and modify the code to handle screen snapshots for 128, but I am not sure about the code after 3a00. disasm.rom, well, anybody knows how to access it? Maybe it can be replaced with the original Genie disassembler. Disclaimer: I am not the core's developer, so this is my own conclusion based on the fact that all ROMs (except +D system code) are not modified in any way.

User avatar
JamesH
Posts: 56
Joined: Sat Dec 26, 2020 11:41 am
Has thanked: 5 times
Been thanked: 15 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by JamesH »

And, finally, I was able to map all ROM components to their originals. SHA1 hashes of the [assumed] originals, match known versions listed here:
https://sinclair.wiki.zxnet.co.uk/wiki/ROM_images
https://x128.speccy.cz/multiface/multiface.htm

Code: Select all

Offs. Len. File name
00000 4000 glukpen.rom		5f40f5af51c4c1e9083eac095349d7518545b0e0 (version 6.61)
04000 4000 TR-DOS-5.04T*		??? (doesn't match known 5.04t or 5.04t-bugfixed)
08000 4000 128p-0.rom		d07fcdeca892ee80494d286ea9ea5bf3928a1aca
0C000 4000 128-1.rom		80080644289ed93d71a1103992a154cc9802b2fa
10000 4000 plus3-41-0.rom	62ec15a4af56cd1d206d0bd7011eac7c889a595d
14000 4000 plus3-41-1.rom	1a7812c383a3701e90e88d1da086efb0c033ac72
18000 4000 plus3-41-2.rom	8df145d10ff78f98138682ea15ebccb2874bf759
1C000 4000 plus3-41-3.rom	be365f331942ec7ec35456b641dac56a0dbfe1f0
20000 2000 plusd-1.A.rom	6b841dc5797ef7eb219ad455cd1e434ca3b9d30d original but it has to be patched!
22000 2000 plusd-sys.bin	N/A, patched CONFIG2_C chunk from the MGT System Tape and pre-populated variables and buffers area
24000 2000 MF128-87.2.ROM	8df204ab490b87c389971ce0c7fb5f9cbd281f14 (CRC32: 78ec8cfd)
26000 2000 genie128-2.rom	926425b3e84180683f0872aee9ebf6f4b9dfaf5f
28000 2000 mf3-3.C.rom		5d74d2e2e5a537639da92ff120f8a6d86f474495 (CRC32: 2d594640)
2A000 2000 zeroes.bin		N/A
2C000 4000 48.rom		5ea7c2b824672e914525d1d5c419d71b84a426a2

The two exceptions are the TR-DOS, but I am sure that unofficial 5.04T can be replaced with the original 5.03. And +D ROM and system code has to be patched, so make sure you copy it from the original boot.rom

The difference between 128p-0.rom and original 128-0.rom seems to be the "TR-DOS" menu item in place of the "Tape Tester" menu item. Wild guess: if you need better compatibility with original 128k, original ROM may work, although I have not tested it yet.

User avatar
JamesH
Posts: 56
Joined: Sat Dec 26, 2020 11:41 am
Has thanked: 5 times
Been thanked: 15 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by JamesH »

Well, the weather was nice today and I had time to spend on looking at the +D stuff :) It looks like my initial conclusion was wrong. Here is what I think about the changes:

+D ROM file, only two bytes changed, NOP'ing the following code:

Code: Select all

0A69            JR   Z,#0A88,SCAN_NEXT   Jump if no disk map wanted.

changed and JR is zeroed out, so jump never happens. I believe it is the part that makes “preloaded G+DOS has been patched to allow disk change on-the-fly” possible.

Hence, modifications of the plusd.com file are required for the +D snapshots to work. You can apply that change to the original plusd-1.A.rom (SHA1: 6b841dc5797ef7eb219ad455cd1e434ca3b9d30d) using the following command:

Code: Select all

echo '0a69: 0000' | xxd -r - plusd.com

Now, the SYS code. Based on the excellent +D disassembly pages, area above 03A0 indeed contains various +D variables and buffers. And I believe these should also be pre-populated for +D snapshots to work.

So, the following changes are required to the CONFIG2_C chunk from the MGT System Tape:

  1. Patch the 128 screen page selection code, e.g. with

    Code: Select all

    echo '000001c0: bfdf ed58 cb7b 200f 067f ed58 cb5b 1812' | xxd -r - CONFIG2_C

    (technically, only 4 bytes change, it's just easier to feed entire line to the xxd tool). I believe this is the part responsible for "Included ROM has been pre-patched to automatically detect the [128k] screen."

  2. A pre-populated variables and buffer area must be added (since CONFIG2_C is only 6656 bytes long, you'll need 1536 bytes from the current image).

It would be nice if someone familiar with the core and/or +D snapshot can chime in and confirm/correct this. Thanks!

User avatar
Sorgelig
Site Admin
Posts: 890
Joined: Thu May 21, 2020 9:49 pm
Has thanked: 2 times
Been thanked: 214 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by Sorgelig »

I don't remember details already as it was long time ago. +D and +3 support originally was written by Gyurco. After some time MF3 was added which is bound to +D as it's the only way to write snapshots. When that patch for +D was appeared i don't remember already. Sorry :)

User avatar
pgimeno
Top Contributor
Posts: 710
Joined: Thu Jun 11, 2020 9:44 am
Has thanked: 277 times
Been thanked: 226 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by pgimeno »

Amazing research work, JamesH! Thanks a lot for filling in all these blanks.

Nice find about Genie 128, I didn't know that one. I wonder if it's a leftover from a time where it was used to debug the core, and when it stopped being needed, only half of it was replaced with another ROM and the other half remained.

User avatar
JamesH
Posts: 56
Joined: Sat Dec 26, 2020 11:41 am
Has thanked: 5 times
Been thanked: 15 times

Re: ZX Spectrum: Rebuilding boot.com

Unread post by JamesH »

Yeah, surprisingly, Genie seems to be working just fine and accessible via RShift+F11. In that "Genie 128" image the first half appears to be MF 128 firmware dump. I am not wondering what are "Genie DOS.rom" and "Genie DOS +D.rom", but that will have to wait...

Post Reply