ZX Basic vs Commodore V2.00 (Vic 20)

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
User avatar
mrtinb
Posts: 1906
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: ZX Basic vs Commodore V2.00 (Vic 20)

Post by mrtinb »

Yes Sinclair Basic is more dynamic here. E.g. GOTO VARNAME works fine in Sinclair Basic, but gives an error in Commodore Basic, where GOTO and GOSUB can only be followed by a number.
Martin
https://zx.rtin.be
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: ZX Basic vs Commodore V2.00 (Vic 20)

Post by Shaun_B »

Moggy wrote: Mon Dec 10, 2018 4:09 pm Mathematical functions simple and complex can be defined within a string in zx81 basic and the evaluation of said function, after whatever values needed are entered, can be called by simply asking the strings value.
That would require a GOSUB or GOTO.

Regards,

Shaun.
Last edited by Shaun_B on Wed Dec 12, 2018 9:27 pm, edited 1 time in total.
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: ZX Basic vs Commodore V2.00 (Vic 20)

Post by Shaun_B »

mrtinb wrote: Mon Dec 10, 2018 4:14 pm Yes Sinclair Basic is more dynamic here. E.g. GOTO VARNAME works fine in Sinclair Basic, but gives an error in Commodore Basic, where GOTO and GOSUB can only be followed by a number.
A quirk of Microsoft (Commodore) BASIC is that you can do this:

Code: Select all

 100 GOSUB 1000 UPDATE SCORE:PRINT S
 999 END
1000 S=S+10:RETURN
i.e., The string after the number is ignored until the : marking the next statement, which means that if readability is important to your BASIC then you don't need the REM statement at the start of your sub routines.

Any variable length of more than two characters in Commodore BASIC will ignore everything after the 2nd char. So LET SCA = 100: LET SCB = 101: PRINT SCA will produce the result for the latter declaration (101).

Regards,

Shaun.
Moggy
Posts: 3231
Joined: Wed Jun 18, 2008 2:00 pm

Re: ZX Basic vs Commodore V2.00 (Vic 20)

Post by Moggy »

Shaun_B wrote: Wed Dec 12, 2018 9:03 pm
Moggy wrote: Mon Dec 10, 2018 4:09 pm Mathematical functions simple and complex can be defined within a string in zx81 basic and the evaluation of said function, after whatever values needed are entered, can be called by simply asking the strings value.
That would require a GOSUB or GOTO.

Regards,

Shaun.
Not sure what you're driving at but no GOSUB or GOTO is required when defining a function within a string or its later evaluation.


IE..

10 INPUT A
20 INPUT B
30 INPUT X
40 LET Z$="A*B/SIN X"
50 PRINT VAL Z$

Functioned defined within Z$ and evaluated in line 50 using the variables previously input and if the program is written in what was used to be termed the "call and fall" manner then I can't see where the GOTO etc fits in?

Or are you meaning a defined funtion pointing to a jump to a line number?
Shaun_B
Posts: 474
Joined: Wed Apr 22, 2009 10:22 am

Re: ZX Basic vs Commodore V2.00 (Vic 20)

Post by Shaun_B »

Moggy wrote: Wed Dec 12, 2018 10:19 pm
Not sure what you're driving at but no GOSUB or GOTO is required when defining a function within a string or its later evaluation.

IE..

10 INPUT A
20 INPUT B
30 INPUT X
40 LET Z$="A*B/SIN X"
50 PRINT VAL Z$

Functioned defined within Z$ and evaluated in line 50 using the variables previously input and if the program is written in what was used to be termed the "call and fall" manner then I can't see where the GOTO etc fits in?

Or are you meaning a defined funtion pointing to a jump to a line number?
CBM BASIC V2 can't do string functions for sure, but this:

Code: Select all

  0 DEF FN A(X) = X * X
100 PRINT FN A(10)
200 PRINT FN A(20)
300 PRINT FN A(30)
400 A=FN A(11)
500 PRINT A
Regards,

Shaun.
Crayon21
Posts: 348
Joined: Sun Nov 04, 2018 2:33 am

Re: ZX Basic vs Commodore V2.00 (Vic 20)

Post by Crayon21 »

have not posted in a while, forgot I was even still here, thought they had forgot about me. hope the rams win SB LIII :D
In Heck, there are two options for perpetual torment:

Eat the Puckerberry and suffer for eternity:
drink nothing but a cocktail of The Last Dab and Mexican Cake blended and served with
habanero slices
:twisted:
MOB-i-L
Posts: 62
Joined: Mon Apr 19, 2010 12:13 am
Location: Lund, Skåne/Scania, Sweden
Contact:

Re: ZX Basic vs Commodore V2.00 (Vic 20)

Post by MOB-i-L »

Sinclair ZX81 BASIC has GOTO N and GOSUB N, where N can be an expression; this doesn't work in CBM BASIC V2 for VIC20/C64, but it has ON N GOTO n1,n2,n3,... and ON N GOSUB n1,n2,n3,..., where N is an expression and n1,n2,n3 etc. are fixed numbers. One can simulate ON N GOTO/GOSUB in ZX81 BASIC with e.g.:
4080 GOTO (S=1)*1560+(S=2)*2780+(S=3)*3630+(S=4)*3680+(S=5)*3730
corresponds to:
4080 ON S GOTO 1560,2780,3630,3680,3730

In BASIC V2 if S>5 it goes to the next line, but that could also be simulated in ZX81 BASIC by adding +(S>5)*4081 to the line above.

In ZX81 BASIC logical expressions are 0 and 1 (with exception for short circuit AND), but in BASICV2 they are 0 and -1 and the logical/boolean operators (NOT, AND, OR) are bitwise, but in ZX81 BASIC they are not.

The ZX81 screen doesn't scroll by itself so you have to do SCROLL, otherwise you get a screen full error when PRINT:ing on the next line after the last, but then you can CONT:inue.

ZX81 has PRINT AT R,C, but BASIC V2 has cursor control codes; you can PRINT a code for HOME and then PRINT codes for DOWN and RIGHT several times, alternatively there is a VIC20 Kernal (i.e. ROM) routine for cursor positioning, but that requires POKEs and calling ROM.

INPUT is always on the last line in ZX81 BASIC and that is a disadvantage, but you can write your own input subroutines using INKEY$.

In ZX81 BASIC in VAL A$, A$ can be an INPUT:ed expression in a string that evaluate to a number, but that doesn't work in BASIC V2 and DEF FN can not be changed to INPUT:ed strings. In ZX Spectrum BASIC VAL$ was added.

Some variable names in ZX81 can only be one character long, e.g. AB$, AB(), AB$(), FOR AB are not allowed, but in BASIC V2 all variables can have long names, but only the two first characters matters, the rest are just a sort of comment, but in ZX81 all characters in long variable names matters. Also in ZX81 e.g. A$ and A$() are the same variable and not different as in V2, this is because ZX uses array index notation to pick a character e.g. A$(N), and not MID$(A$,N,1).

The Sinclair developed ZX81 BASIC was slow, but the later, fan developed, versions are much faster and fully compatible.

ZX81 BASIC is only 7.5 KiB since the character font is stored in the ROM (last 0.5 KiB). I believe ZX81 only costed 1/3 of the VIC20 and had a higher profit margin. It took a long time after the sale of ZX81 stopped before it was possible to buy a new computer system with keyboard, power supply, screen, and secondary storage that costed as little as Sinclair ZX81 with a B/W TV and cassette player.
Last edited by MOB-i-L on Sat Feb 05, 2022 9:27 pm, edited 2 times in total.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: ZX Basic vs Commodore V2.00 (Vic 20)

Post by XavSnap »

Some variable names in ZX81 can only be one character long, e.g. AB$, AB(), AB$(), FOR AB is not allowed.
There's five variables type on the Zx81 Basic...

1- Boolean. (can be an integer or a floating point value)

Characters:
2- Free length string = 1 LET A$="HELLO WORD"
3- Fix length string = 1 DIM A$(1,32) Where "HELLO WORD" will take 32 characters... A$=""HELLO WORD"+22 spaces.

Numerics:
4- INTEGER: 1 FOR a=0 TO 10 (only 1 character in the variable name!)
5- Floating point: 1 LET A=1 ("open bar" in the variable name)


Variable name length:
Numeric Array = Only one character : "1 DIM a(1)"
Next/FOR integer = Only one character
Numeric LET = x character (memory room): "1 LET ABCDEFGHIJKLMNOPQRSTUVWXYZ=1"
Characters = Only one character: "1 LET A$="ABC""

In case of " LET PRINT=0" ; "LET THEN=1"; "LET TO=0";"LET NOT=0";"LET CODE=1"... it's working, but you had to type the variable name using alphanumeric letters.
"LET ABC12345=0" working too.

Note: It work on a true computer, on an emulator or a generic "TEXT2P", you had to choose another variables name to avoid to get a token instead of an alphanumeric name.

Due to a memory room problem, it's recommended to use only one character ... or two ... in a variable name !

1 LET ABCDEFGHIJKLMNOPQRSTUVWXYZ=1
2 LET ABCDEFGHIJKLMNOPQRSTUVWXYZ=ABCDEFGHIJKLMNOPQRSTUVWXYZ+1

Is correct...But...

;)
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
1024MAK
Posts: 5102
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX Basic vs Commodore V2.00 (Vic 20)

Post by 1024MAK »

FOR variable
FOR variable
Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: ZX Basic vs Commodore V2.00 (Vic 20)

Post by XavSnap »

4- INTEGER: 1 FOR a=0 TO 10 (only 1 character in the variable name!)
or a floating point too... :mrgreen:

Without the boolean, 3 kinds of variables...

You win Mark...
:lol:
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply