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
1024MAK
Posts: 5101
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 »

XavSnap wrote: Sat Feb 05, 2022 7:34 pm
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:
Well, you got the rest right :lol:

I must admit, the limitations of variable names for the Microsoft BASIC on the Commodore VIC-20 and 64 etc. are REALLY annoying. As it leads to hard to find errors. At least ZX81 BASIC has better syntax checking, which makes it less likely that a programmer will fall into the trap of having two different sections of code using what the computer thinks is the same variable, even though to the programmer, it looks like two different (independent) variables…

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.
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 »

Try this program on a ZX81 and VIC20:

Code: Select all

  10 DIM A$(3)
  20 LET A$="HEJ"
  25 PRINT A$
  30 LET A$(1)="ABCDEFGHIJK"
  40 LET A$(2)="LBCDEFGHIJK"
  50 LET A$(3)="ZBCDEFGHIJK"
  60 PRINT A$(1)
  70 PRINT A$(2)
  80 PRINT A$(3)
  90 PRINT A$
If you run this on ZX81 you get:

Code: Select all

HEJ
A
L
Z
ALZ
But if you run it on VIC20 you get:

Code: Select all

HEJ
ABCDEFGHIJK
LBCDEFGHIJK
ZBCDEFGHIJK
HEJ
In order to get the same result as on a VIC20 on a ZX81 you need to change the program to e.g.:

Code: Select all

  10 DIM A$(3,11)
  20 LET B$="HEJ"
  25 PRINT B$
  30 LET A$(1)="ABCDEFGHIJK"
  40 LET A$(2)="LBCDEFGHIJK"
  50 LET A$(3)="ZBCDEFGHIJK"
  60 PRINT A$(1)
  70 PRINT A$(2)
  80 PRINT A$(3)
  90 PRINT B$
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 »

To convert a fix array string value (A$) to a free length string (B$):

Code: Select all

  10 DIM A$(4,5)
  20 LET B$=""
  30 LET A$(1)="HEL*-"
  40 LET A$(2)="LO*--"
  50 LET A$(3)="WO*--"
  55 LET A$(4)="RLD*-"
  60 FOR A=1 TO 4
  65 LET C=0
  70 FOR B=1 TO 5
  75 IF A$(A,B)="*" THEN LET C=B-1
  80 NEXT B
  82 IF C=0 THEN LET C=5
  84 LET B$=B$+A$(A, TO C)
  86 IF A=2 THEN LET B$=B$+" "
  90 NEXT A
  100 PRINT A$(1);A$(2);A$(3);A$(4)
  110 PRINT ,,B$,LEN B$;" CHARS."
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
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 »

In ZX81 BASIC GOTO and GOSUB can jump to non existing lines and then goes to the next existing line; this does not work in VIC20 BASIC V2.

In ZX81 BASIC FOR...NEXT doesn't execute between FOR and NEXT if the condition is unfulfilled from the start, but in BASIC V2 it always executes at least once. The ZX BASIC behavior makes it possible to write code that doesn't depend on line-numbers with relative ease, e.g. if, else, else if, while, do...while etc. can be implemented using FOR...NEXT.

E.g. the Pascalated BASIC for ZX Spectrum can be adapted for ZX81. The example is translated automatically from ZX Spectrum BASIC to ZX81 BASIC:

Code: Select all

100 REM
103 REM (* FACTORIALS *)
106 REM (C) 1987, 2021 BY ZARSOFT
109 CLEAR
112 REM VAR - GLOBAL VARIABLES
115 GOSUB 9905
    REM CALL INIT PROC ADDRS
118 LET LIMIT = 0
    REM MAX ARGUMENT TO BUILD THE LIST
121 LET ARGUMENT = 0
    REM ARG TO CALCULATE FACTORIAL
124 LET RESULT = 0
    REM FACTORIAL OF ARG
127 LET W = 0
    REM AUXILIAR LEVEL 1 VAR
130 LET Y = 0
    REM AUXILIAR LEVEL 2 VAR
133 GOSUB MAIN ROUTINE
136 STOP
    REM FACTORIALS
200 REM
203 REM (* MAIN ROUTINE *)
206 LET MAIN ROUTINE = 207
    RETURN
    REM SET PROC ADDR
209 GOSUB INTRODUCTION
212 GOSUB GET LIMIT
215 GOSUB WRITE FACTORIALS
218 RETURN
    REM MAIN ROUTINE
300 REM
303 REM (* INTRODUCTION *)
306 LET INTRODUCTION = 307
    RETURN
    REM SET PROC ADDR
309 PRINT "FACTORIALS LIST"
312 PRINT "PASCALATED BASIC DEMONSTRATION"
315 PRINT
318 RETURN
    REM INTRODUCTION
400 REM
403 REM (* GET LIMIT *)
406 LET GET LIMIT = 407
    RETURN
    REM SET PROC ADDR
409 FOR W = 0 TO 0.5 STEP 0
    REM REPEAT
412   PRINT "MAX ARGUMENT = ";
415   INPUT LIMIT
    PRINT LIMIT
418   LET Y = LIMIT >= 12
    REM IF-BEGIN
421   FOR Y = Y TO 0.5 STEP -2
    REM IF-BEGIN
424     PRINT
427     PRINT "MUST BE LOWER THAN 12."
430     PRINT "TRY AGAIN."
433     PRINT
436   NEXT Y
    REM ENDIF
439   LET Y = (Y<0)*-1 + (Y=0)*( LIMIT < 0 )
    REM ELSEIF
442   FOR Y = Y TO 0.5 STEP -2
    REM ELSEIF
445     PRINT
448     PRINT "MUST BE GREATER THAN 0."
451     PRINT "TRY AGAIN."
454     PRINT
457   NEXT Y
    REM ENDIF
460   LET Y = (Y=0)
    REM ELSE
463   FOR Y = Y TO 0.5 STEP -2
    REM ELSE
466     PRINT
469     PRINT "VALID INPUT."
472     PRINT
475   NEXT Y
    REM ENDIF
478   LET W = (LIMIT >= 0) AND (LIMIT <= 11)
    REM UNTIL
481 NEXT W
    REM UNTIL
484 RETURN
    REM GET LIMIT
500 REM
503 REM (* WRITE FACTORIALS *)
506 LET WRITE FACTORIALS = 507
    RETURN
    REM SET PROC ADDR
509 PRINT
512 FOR W = LIMIT TO 0 STEP -1
515   LET ARGUMENT = W
518   PRINT "FACT(";ARGUMENT;") = ";
521   GOSUB CALCULATE FACTORIAL
524   PRINT RESULT
527 NEXT W
530 RETURN
    REM WRITE FACTORIALS
600 REM
603 REM (* CALCULATE FACTORIAL *)
606 LET CALCULATE FACTORIAL = 607
    RETURN
    REM SET PROC ADDR
609 LET RESULT = 1
612 FOR Y = NOT (ARGUMENT > 1 ) TO 0.5 STEP 0
    REM WHILE
615   LET RESULT = RESULT * ARGUMENT
618   LET ARGUMENT = ARGUMENT-1
621   LET Y = NOT (ARGUMENT > 1 )
    REM ENDWHILE
624 NEXT Y
    REM ENDWHILE
627 RETURN
    REM CALCULATE FACTORIAL
9900 REM
9902 REM (* INIT PROC ADDRS *)
9904 LET W = 9999
    RETURN
9908 PRINT " "; AT 0,0;
9910 FOR W = 200 TO 9900 STEP 100
9912 GOSUB W
9914 NEXT W
9916 RETURN
    REM INIT PROC ADDRS
9918 REM CONVERTED FROM
9920 REM PASCALATED BASIC
9922 REM TO STRUCTURED BASIC
9924 REM AT WWW.ARCALUSITANA.FUN/MUSEUZX
9926 REM (C) 1987, 2021 BY ZARSOFT
It was translated in Linux using:

Code: Select all

cat factorials.bas | sed 's/\(^[0-9][0-9]*\) :/\1 REM/;s/ : /\n    /g' | sed 's/\\{vi}/(*/;s/\\{vn}/*)/;s/GO SUB/GOSUB/;s/FLASH 1;//;s/REM REM/REM/;s/ *$//' | tr a-z A-Z > factorials-zx81.bas
This was loaded using the emulator ZCE that can handle lines without line-numbers:

Code: Select all

./zce factorials-zx81.bas
The p-file is included.

It is not impossible to translate structured language without line-numbers to BASIC V2, but that requires another, probably larger, system:
https://github.com/mobluse/ratbas2
Attachments
factorials.p
(3.16 KiB) Downloaded 112 times
Crayon21
Posts: 346
Joined: Sun Nov 04, 2018 2:33 am

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

Post by Crayon21 »

Getting a graphics screen on the vic requires a ram expansion as 5k (3.5 for users) is nowhere near enough (thanks jack) then you need to POKE about 30 or so lines.

Here's the zx81 version with just 1k and no POKE
4 for x=1 to 10
5 let a$=inkey$
6 if inkey$="" then goto 6
7 if inkey$="x" then print at 10,4; (graphic space, shifted A x12)
8 scroll
9 goto 3
press x to scroll down and e or z to scroll up. V to isolate a section and C to scroll that segment
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:
Post Reply