BASIC: Find out if an Interface 1 is attached.

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
cha05e90
Berk
Posts: 33
Joined: Sun Nov 19, 2017 7:02 pm

BASIC: Find out if an Interface 1 is attached.

Post by cha05e90 » Thu Sep 19, 2019 3:24 pm

My rather naive idea is to PEEK some system variable(s) to find out if there's a ZX Interface 1 attached or not. Is there any reliable candidate for such a test?
0 x
+/+/48K/128

User avatar
spider
Microbot
Posts: 112
Joined: Wed May 01, 2019 9:59 am
Location: UK
Contact:

Re: BASIC: Find out if an Interface 1 is attached.

Post by spider » Thu Sep 19, 2019 4:19 pm

I either asked about this or meant to ask and forgot. Assuming the IF1 is vaguely alive you can try this for now although it is not what you wanted I know:

Do a NEW or reset then just enter RUN as the first direct command. Don't type anything else in first.

If it just comes back as "0 OK" , its not present or detected. If it comes back with "Program Finished" or "Microdrive Not Present", then it is half alive at least.

There is or probably should be an easy way to PEEK a value to determine if its there or not though. Unsure if differing values would be needed if said PEEK was tried on say a +3 (or model that does not support an IF1) etc
0 x

User avatar
spider
Microbot
Posts: 112
Joined: Wed May 01, 2019 9:59 am
Location: UK
Contact:

Re: BASIC: Find out if an Interface 1 is attached.

Post by spider » Thu Sep 19, 2019 6:37 pm

Additional bit of info: I think on a real machine you get the 'Program Finished' error almost straight away if there are no Microdrive's actually connected. Otherwise you get a Microdrive not present if you have one or more and there's no cart in the first one, I think. :)

I do recall the former message on my 48K with the IF1 attached, the latter I've seen under emulation but that would include a minimum of one drive 'attached'
0 x

User avatar
jpnz
Berk
Posts: 35
Joined: Tue Nov 14, 2017 4:07 pm
Location: Hamilt[r]on - City Of The Future - NZ

Re: BASIC: Find out if an Interface 1 is attached.

Post by jpnz » Thu Sep 19, 2019 7:42 pm

cha05e90 wrote:
Thu Sep 19, 2019 3:24 pm
My rather naive idea is to PEEK some system variable(s) to find out if there's a ZX Interface 1 attached or not. Is there any reliable candidate for such a test?
There is a rudimentary method of checking NMIADD
1 x

User avatar
cha05e90
Berk
Posts: 33
Joined: Sun Nov 19, 2017 7:02 pm

Re: BASIC: Find out if an Interface 1 is attached.

Post by cha05e90 » Fri Sep 20, 2019 8:03 am

Ah, thanks for the hints.

The use case is to check for a attached Interface 1 from inside a running BASIC program. So I might try (or alter...) the NMIADD stuff from Andrew. AFAIK the system variable area is different for a ZX Spectrum 48/128 with and without an Interface 1, so I thought there might be a simple check for something in that area to determine the existence of that interface.
1 x
+/+/48K/128

User avatar
spider
Microbot
Posts: 112
Joined: Wed May 01, 2019 9:59 am
Location: UK
Contact:

Re: BASIC: Find out if an Interface 1 is attached.

Post by spider » Fri Sep 20, 2019 11:49 am

I would of thought so too but I've not seen anything posted.

I wonder although tis a pain perhaps to do a FOR/NEXT loop and print out all the values of the system variables (do a CLEAR then RUN) and then repeat with an IF1 attached, and then compare the results. Obviously under emulation for convenience. Would suspect a couple of them will of changed, Just a question of not mistaking anything "program related"

In theory it should be as simple as IF PEEK xyz <> (something) THEN... type of thing but in reality...

EDIT... I wonder if any of the ports behave completely different if an IF1 is there or not , as in say IN (xyz) ? Slight advantage of that is you can easily use it from Basic or Assembly.
0 x

Pobulous
Berk
Posts: 21
Joined: Wed Nov 15, 2017 12:51 pm

Re: BASIC: Find out if an Interface 1 is attached.

Post by Pobulous » Fri Sep 20, 2019 3:40 pm

I thought Interface I and II replaced the spectrum ROM with their own ROMs.

I remember when using interrupt vectors, a quick hack was to put a JR at location 65535, which would use the first byte of the ROM to pick the location to jump back to, and this value apparently would vary based on whether Interface I or II was connected.

So address 0 of ROM could be a place to check.
0 x

User avatar
spider
Microbot
Posts: 112
Joined: Wed May 01, 2019 9:59 am
Location: UK
Contact:

Re: BASIC: Find out if an Interface 1 is attached.

Post by spider » Fri Sep 20, 2019 3:53 pm

I thought it was just paged in as and when ? I don't have (at this moment) time to check :(

I did think oddly enough about the Sweevo Editor (yes I know) as the RobCandy tips (tape) had some kind of microdrive only program on it for saving to that, I think there was some kind of check for IF1/Microdrive present maybe in that code. I don't have time to research this until tomorrow though. If you examine the instructions for said tape it may make sense but as I say I've not looked into it.
0 x

User avatar
Seven.FFF
Manic Miner
Posts: 340
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: BASIC: Find out if an Interface 1 is attached.

Post by Seven.FFF » Fri Sep 20, 2019 4:10 pm

The extra sysvars are listed in the IF1 manual, but I can’t see anything obvious that would definitively indicate that BASIC has been extended for microdrives. The variables are, after all, intended to be variable. And there are many other ways that BASIC (or the hardware) can be extended.

The usual advice in these general situations is to test for features rather than versions or magic numbers. In this case, that would involve making a microdrive API call, either from BASIC or more likely from asm, and treating anything but a definitive success result as a failure. The trick here is to pick something that had no bad side effects, doesn’t depend on a formatted cart being inserted, is unlikely to give a false negative if there is an IF1 but a bad cart, and doesn’t completely crash in the standard unexpanded scenario. And, hopefully, doesn’t crash if some other unexpected interface or BASiC extension is installed.

This is all quite a tall order, and when not done properly can be more disruptive and counterproductive than a simple manual option for the user to select microdrive operation.

For example, the Multiface 1 menu has manual entries for microdrive, Opus, Wafa, Betadisk etc, rather than jumping through all the hoops to do 100% reliable detection.
2 x
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
seven-fff.com/blog

User avatar
1024MAK
Manic Miner
Posts: 514
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: BASIC: Find out if an Interface 1 is attached.

Post by 1024MAK » Fri Sep 20, 2019 11:16 pm

Don’t forget that the interface 1 also has a RS232 port and network ports.

The interface 1 is only paged in when certain circumstances occur, one is when the BASIC ROM error handler is called (so that the interface 1 can ‘trap’ all the new commands). Hence trying to peek it from BASIC is not very practical.

I think reading the I/O ports is most likely to be the simplest way, if the value can help identify if it (or something similar) is present (I say this, because there are other hardware devices that support some of the interface 1 features).

Mark
1 x

Post Reply