Detect which Microdrive a program is running from?

For experts to discuss very technical stuff and newbies to ask why the Spectrum they bought off ebay doesn't work.
Post Reply
User avatar
8BitSC
Microbot
Posts: 129
Joined: Mon Feb 13, 2023 1:23 am

Detect which Microdrive a program is running from?

Post by 8BitSC »

Is there a way to detect which drive number a program is loaded from, which works with both v1 and v2 IF1 ROMs?

I’ve been adding a loader to my virtual microdrive images, along the lines of:

10 LOAD *”m”;1;”MAIN”

However, the drive number is hard-coded, meaning the program will only chain the MAIN program, if the loader is run from drive 1.

It would be useful if I could change the loader could be made to work from any drive automatically.
cj7hawk
Manic Miner
Posts: 361
Joined: Sat Sep 25, 2021 9:11 am

Re: Detect which Microdrive a program is running from?

Post by cj7hawk »

It's not trivial, but you could use the microdrive sector map as a hash of sorts and see which drive matched it, but it would have to search the maps.

Or you could set an unusual name on the drive, and read the motors and once you had a sector header, see if it matched the cartridge name and then switch to that one as default.

Or you could just assume it's in Drive 1, and then load up the next program and go looking on other drives if you don't find it.
User avatar
jpnz
Manic Miner
Posts: 326
Joined: Tue Nov 14, 2017 4:07 pm
Location: Hamilt[r]on - City Of The Future - NZ

Re: Detect which Microdrive a program is running from?

Post by jpnz »

Yes, you can use the system variable D_STR1 (drive number), e.g.

Code: Select all

LET d=PEEK 23766: LOAD *"m";d;"somefile"
User avatar
8BitSC
Microbot
Posts: 129
Joined: Mon Feb 13, 2023 1:23 am

Re: Detect which Microdrive a program is running from?

Post by 8BitSC »

jpnz wrote: Fri Sep 15, 2023 9:04 am

Code: Select all

LET d=PEEK 23766: LOAD *"m";d;"somefile"
Thank you @jpnz

Googling for an answer before posting here, I found many results. None made it seem quite this simple.
equinox
Dynamite Dan
Posts: 1057
Joined: Mon Oct 08, 2018 1:57 am
Location: SE England

Re: Detect which Microdrive a program is running from?

Post by equinox »

8BitSC wrote: Fri Sep 15, 2023 8:45 am Is there a way to detect which drive number a program is loaded from, which works with both v1 and v2 IF1 ROMs?
I’ve been adding a loader to my virtual microdrive images, along the lines of: [...]
I was thinking about this recently — regarding tape and disk in general — as I have something (probably not ready until 2024, if I ever finish it) where I might want to release on tape, +3 disk, and Plus D disk. (Not a bloody microdrive! Life's too short.)
That is: LOAD "x", LOAD "a:x" (or "b:x"??) or LOAD d*"x"
(But it's not that easy, because if you are loading from tape on a +3, you need to write "t:x", or Christ knows what. That's the biggest issue for me: what if I have saved a file on tape that happens to be called "a:x" and then I want to load it? Really bad design.)
Anyway, there really isn't any way to check where the current program loaded from, is there? I'm sure it isn't stored anywhere.

One problem is: even if you know the medium (for example you are releasing a specific +3 or +D version) you might still not be sure which load routine to use. In the 1990s, demosceners and "porters" would usually leave mysterious spaces in their BASIC loaders, so that you could POKE the disk syntax in there, but yeah, even that isn't enough.

Gets even more fun with the bloody RAM disks. LOAD!"x" on a +2, LOAD "m:x" on a +3 (I think, I can't remember)...
Particularly hilarious that my routine only seems to work in 48K mode (at least not with 128K BASIC resident) so I can't use the RAM disk, although I would like to, because it would be very helpful if I could load the entire thing into memory. So you think: well, USR0 mode, but then I don't have the RAM disk, and would need to do crazy "OUT" commands. Since I can't write Z80.

No solutions, I just wanted to share the frustration.
User avatar
jpnz
Manic Miner
Posts: 326
Joined: Tue Nov 14, 2017 4:07 pm
Location: Hamilt[r]on - City Of The Future - NZ

Re: Detect which Microdrive a program is running from?

Post by jpnz »

8BitSC wrote: Sat Sep 16, 2023 1:41 am Thank you @jpnz

Googling for an answer before posting here, I found many results. None made it seem quite this simple.
Hope it works out for you - for reference, this was originally published in Master Your ZX Microdrive, page 21 - Chaining programs

The whole book is a good read
Post Reply