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
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 » Sat Sep 21, 2019 5:03 am

There are some more suggestions from J.G. Hartson

His machine code approach is pretty versatile, and uses hook code 0x31 to initialize the IF1

It also traps for the non existence of the IF1 and will trigger a clean return to BASIC in either instance

There are other interfaces (Disciple and Plus D) that mirror the IF1 hook codes

Pretending I hadn't read what Seven.FFF had said about magic numbers(!),
you can potentially determine what interface (and version) has responded to hook code 0x31 by inspecting register pairs once control has returned to your own code...

For example, with an IF1 Version 2

de will be set at 0x0700 - the UNPAGE location that leaves the shadow ROM
hl will be set at 0x1e98 - the HOOK-31 location

With an IF1 Version 1, de will still be 0x0700, but hl will be set at a different location of 0x19a8 for HOOK-31
2 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 » Mon Sep 23, 2019 9:08 am

Wow, it doesn't seem that easy to retrieve that information from your Speccy..:-)

I'm still trying to make a test with pure Sinclair BASIC - maybe something from all your suggestions can be used. If that's really impossible, I'll give this or that method using some assembler a try - but that will be the last resort.

Thanks for all your suggestions and tips!
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 » Mon Sep 23, 2019 10:37 am

It is surprising to realise there's not a very easy IF PEEK xyz <> abc , or something similar like IF PEEK xyz = abc etc

Logic would say there should be, I can see it moves things about a bit, trouble is the contents of what has moved is variable anyway in its nature and content.

I don't *think* the following will be useful but...

23653-23654 STACKEND:
This system variable contains the address of where the spare part of memory starts. From reading this we can gain an idea of how much memory we have left by subtracting it from RAMtop
Try: PRINT PEEK 23730 + 256*PEEK 23731 - PEEK 23653 - 256*PEEK 23654 , with both an IF one connected *and* without it connected.

EDIT... No the above usually on a reset returns 41532 regardless and CLEAR is going to make that jump about. Hmm. There might be something similar that can be used. Have you looked at all the system variables in the Speccy Manual ?

RAMTOP is at 23730-23731

I don't (think) FLAGS at 23611 is going to be any help.

That's about as much erm 'sane' thoughts as I can put into this.
0 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 » Wed Sep 25, 2019 7:55 am

jpnz wrote:
Sat Sep 21, 2019 5:03 am
There are some more suggestions from J.G. Hartson
I tested Jonathan's rather short Sinclair BASIC variant - indeed a test in the system variable area:

Code: Select all

10 CLOSE#0:LET inf1=(PEEK 23734<>244)
20 IF inf1 THEN PRINT "ZX Interface 1 detected."
If I put that in the beginning of the BASIC program it seems rather reliable in detecting an attached ZX Interface 1. I tried it with some emulators and with my real ZX Spectrum 48K/128K and it works. So'll stick with that for the moment!
2 x
+/+/48K/128

Post Reply