ZX BASIC: Test for 48/128k system

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

ZX BASIC: Test for 48/128k system

Post by cha05e90 » Mon Jul 29, 2019 12:11 pm

Hello,

is there any way I can test from standard ZX BASIC whether I'm running on a 48K or 128K machine? For example by PEEKing a special system variable or the like?

(I found some tips for this but all of them use some kind of additional assembler routine or are somewhat "destructive".)

Regards, Frank
1 x
+/+/48K/128

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1224
Joined: Mon Nov 13, 2017 3:16 pm

Re: ZX BASIC: Test for 48/128k system

Post by Ast A. Moore » Mon Jul 29, 2019 1:01 pm

PRINT PEEK 23611. Returns 221 for 128 BASIC and 204 for 48K.

Not foolproof, but should be okay if you test it early enough in your code.

Note: it doesn’t really test for the actual hardware—just the currently running OS.

P.S. And it’s officially called Sinclair BASIC, not ZX BASIC. ;)
2 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

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

Re: ZX BASIC: Test for 48/128k system

Post by cha05e90 » Mon Jul 29, 2019 1:15 pm

Ast A. Moore wrote:
Mon Jul 29, 2019 1:01 pm
PRINT PEEK 23611. Returns 221 for 128 BASIC and 204 for 48K.
Oh, thank you very much. That should do it!
Ast A. Moore wrote:
Mon Jul 29, 2019 1:01 pm
P.S. And it’s officially called Sinclair BASIC, not ZX BASIC. ;)
Whaaaaaaat? Ok, I'll try to internalize that - I used that "ZX BASIC" term for >30 years ... :o
0 x
+/+/48K/128

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1224
Joined: Mon Nov 13, 2017 3:16 pm

Re: ZX BASIC: Test for 48/128k system

Post by Ast A. Moore » Mon Jul 29, 2019 2:15 pm

cha05e90 wrote:
Mon Jul 29, 2019 1:15 pm
I used that "ZX BASIC" term for >30 years ... :o
I’m sorry for ruining your life, pal. :lol:
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

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

Re: ZX BASIC: Test for 48/128k system

Post by spider » Mon Jul 29, 2019 4:48 pm

As a random sidenote the PEEK above also returns correctly *if* it was a 128K machine in USR0 , as in the 128 'bits' still there and not locked out, by correctly saying it is in 48K mode (which it is) :)
0 x

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

Re: ZX BASIC: Test for 48/128k system

Post by 1024MAK » Mon Jul 29, 2019 4:56 pm

Which “ZX BASIC”?
The ZX80 BASIC (“old ROM”)
The ZX80 BASIC (“new ROM”, actually ZX81 BASIC)
The ZX81 BASIC
The ZX Spectrum 16K/48K/Plus BASIC?
The ZX Spectrum 128K BASIC?
......

They all have differences.

Mark
1 x

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

Re: ZX BASIC: Test for 48/128k system

Post by spider » Mon Jul 29, 2019 6:33 pm

I think it might get annoying if you wanted to be really specific such as:

Is this machine:

48K

128K in 128K mode ?

128K in 48K (USR0 so 128 bits enabled) mode ?

Then...

128K +2 (grey) , although aside from the (c) messages this might 'test' the same as the original 128.

128K +2A/B

128K +3A/B

... and repeat the above for USR0 mode! :oops: as well as 48K mode.
1 x

User avatar
Alessandro
Manic Miner
Posts: 509
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: ZX BASIC: Test for 48/128k system

Post by Alessandro » Mon Jul 29, 2019 8:38 pm

Some years ago I asked the same to Einar. He suggested me this method, which I have been employing ever since:

Code: Select all

PRINT PEEK 2899
Returns 165 for a 48K, 159 for a 128K/+2 (under 128 as well as 48 BASIC) and 126 for a +2A/+2B/+3 (ditto).
2 x

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

Sinclair BASIC: Test for 48/128k system

Post by cha05e90 » Tue Jul 30, 2019 7:42 am

Alessandro wrote:
Mon Jul 29, 2019 8:38 pm
Some years ago I asked the same to Einar. He suggested me this method, which I have been employing ever since:

Code: Select all

PRINT PEEK 2899
Returns 165 for a 48K, 159 for a 128K/+2 (under 128 as well as 48 BASIC) and 126 for a +2A/+2B/+3 (ditto).
Hm, another one. I must admit my first (simple) idea was to distinguish between a *real* 48k and a *real* 128k machine. I totally forgot that someone can use the 128K as a 48K ZX Spectrum (USR 0) ...;-). Thanks to @spider and @Alessandro ! My use case is (up to now) rather simple: Is there a "silicon disc" or not?

[Later I maybe want to know whether there's a +3 (disk drive) or not...:-)]
1 x
+/+/48K/128

User avatar
Alessandro
Manic Miner
Posts: 509
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: ZX BASIC: Test for 48/128k system

Post by Alessandro » Tue Jul 30, 2019 12:30 pm

The silicon disk is only accessible on the 128K models. The syntax to do that is different however:
  • On the 128K/+2, commands must be followed by an exclamation mark, e.g. SAVE! "program" LINE 10, LOAD! "code" CODE etc.
  • On the +2A/+3, filenames must be preceded by m:, e.g. SAVE "m:program" LINE 10, LOAD "m:code" CODE etc. Alternatively, and for SAVE/LOAD operations only (no VERIFY or MERGE), you can switch the default drive to the silicon disk by entering a SAVE m: or LOAD m: command respectively. All subsequent SAVE or LOAD operations, depending on what you entered before, will deal with the silicon disk. To switch back to tape, enter SAVE "t:" (or LOAD "t:").
For more information, refer to page 9 of the Spectrum 128 introductive manual and to Chapter 8, part 20 of the +3 manual.
2 x

Post Reply