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.
Detect which Microdrive a program is running from?
Re: Detect which Microdrive a program is running from?
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.
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.
- 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?
Yes, you can use the system variable D_STR1 (drive number), e.g.
Code: Select all
LET d=PEEK 23766: LOAD *"m";d;"somefile"
Re: Detect which Microdrive a program is running from?
Thank you @jpnz
Googling for an answer before posting here, I found many results. None made it seem quite this simple.
Re: Detect which Microdrive a program is running from?
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.
- 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?
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