Can't make anything fit into 1K... or is it me?

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
User avatar
LoadError
Posts: 18
Joined: Thu Apr 29, 2021 12:45 pm

Can't make anything fit into 1K... or is it me?

Post by LoadError »

I'm trying to port a little dice program for the Commodores to the ZX81, and I've squeezed it as much as I could, but I can't seem to make it fit in 1K.
In the ASCII editor I'm using,it is under 800 characters including line numbers and spaces, but when I compile it with zxtext2p it grows to a 1.7 KB .p file, and when I try to load it in the emulator (sz81 with the "-u" switch, which is supposed to emulate a 1K machine) it fails to load (it takes me straight back to the prompt and LIST reveals it hasn't been loaded).
Am I missing something? Is it normal that less than 800 bytes become twice as much when compiled? It's a 21 line program and I can't think of a way to shrink it any further.
Thanks!
My Sinclair belongings:
- unexpanded, unmodified, unbackporched ZX81
- expanded (from 16K to 48K) rubber keyed ZX Spectrum
- a Cambridge Scientific pocket calculator
User avatar
1024MAK
Posts: 3629
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: Can't make anything fit into 1K... or is it me?

Post by 1024MAK »

You do know that the 1k byte (1024 bytes) has to include the screen display file, the input line, the system variable area, the BASIC program and the variables for the program, don’t you?

One hidden item in a BASIC program line, is any literal numbers that the system treats as expressions, have five hidden bytes to contain the floating point version of the number that the interpreter uses at run time.

Maybe you should show us your code?

Mark
User avatar
LoadError
Posts: 18
Joined: Thu Apr 29, 2021 12:45 pm

Re: Can't make anything fit into 1K... or is it me?

Post by LoadError »

It's the first time I try to do something on this machine, so I have everything to learn still.
So what is the actual amount of memory available to the BASIC program?
Here is my code in T2P format. Please don't laugh at it... again it's the first time I try to do something on this machine. :lol:
---
PRINT AT 1,11;"\BF\BD\A4\9d\::\A9\A6\A9\AE";AT 5,10;"PREMI \9D O \9E";AT 21,13;"FG SOFT"
@scelta:
IF INKEY$ <>"1" AND INKEY$ <>"2" THEN GOTO @scelta
LET D=VAL(INKEY$)
RAND
FOR C=11 TO 15
PRINT AT C,17;" "
NEXT C
FOR M=1 TO D
LET T=10+7*(M-1)
PRINT AT 11,T;"\..\..\..\..\..";AT 12,T;"\: \ :";AT 13,T;"\: \ :";AT 14,T;"\: \ :";AT 15,T;"\''\''\''\''\''"
LET X=INT(RND*6)+1
IF X=1 THEN PRINT AT 13,T+2;"*"
IF X=2 OR X=3 THEN PRINT AT 12,T+1;"*";AT 14,T+3;"*"
IF X=3 THEN PRINT AT 13,T+2;"*"
IF X=4 OR X=5 THEN PRINT AT 12,T+1;"* *";AT 14,T+1;"* *"
IF X=5 THEN PRINT AT 13,T+2;"*"
IF X=6 THEN PRINT AT 12,T+1;"***";AT 14,T+1;"***"
NEXT M
GOTO @scelta
---
For good measure, this is the regular version, running as expected on an expanded ZX81:
---
LET T=0
PRINT "\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::"
PRINT "\::\::\::\::\::\::\::\::\::\::\::\BF\BD\96\A4\9d\::\A9\A6\A9\AE\::\::\::\::\::\::\::\::\::\::\::"
PRINT "\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::\::"
PRINT AT 5,2;"PREMI \9D PER LANCIARE 1 DADO";AT 6,2;"PREMI \9E PER LANCIARE 2 DADI";AT 7,2;"PER CONCLUDERE PREMI \B8\B5\A6\BF\AE\B4"
PRINT AT 10,0;"\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96";AT 18,0;"\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96\96"
PRINT AT 21,9;"FG SOFT - 2021"
@scelta:
IF INKEY$ <>"1" AND INKEY$ <>"2" THEN GOTO @scelta
LET D=VAL(INKEY$)
RAND
IF T=17 THEN GOSUB @cancelladado2
FOR M=1 TO D
LET T=10+7*(M-1)
GOSUB @disegnadado
GOSUB @lanciadado
NEXT M
GOTO @scelta
@cancelladado2:
FOR C=12 TO 16
PRINT AT C,T;" "
NEXT C
RETURN
@disegnadado:
PRINT AT 12,T;"\..\..\..\..\.."
FOR C=13 TO 15
PRINT AT C,T;"\: \ :"
NEXT C
PRINT AT 16,T;"\''\''\''\''\''"
RETURN
@lanciadado:
FOR C=1 TO 6
LET X=INT (RND*6)+1
LET P$="*"
GOSUB @risultatolancio
IF C<6 THEN LET P$=" "
IF C<6 THEN GOSUB @risultatolancio
NEXT C
RETURN
@risultatolancio:
IF X=1 THEN PRINT AT 14,T+2;P$
IF X=2 OR X=3 THEN PRINT AT 13,T+1;P$;AT 15,T+3;P$
IF X=3 THEN PRINT AT 14,T+2
IF X=4 OR X=5 THEN PRINT AT 13,T+1;P$;" ";P$;AT 15,T+1;P$;" ";P$
IF X=5 THEN PRINT AT 14,T+2;P$
IF X=6 THEN PRINT AT 13,T+1;P$;P$;P$;AT 15,T+1;P$;P$;P$
RETURN
---
My Sinclair belongings:
- unexpanded, unmodified, unbackporched ZX81
- expanded (from 16K to 48K) rubber keyed ZX Spectrum
- a Cambridge Scientific pocket calculator
User avatar
Math123
Posts: 39
Joined: Sun May 11, 2008 11:14 pm
Location: Germany Wuppertal
Contact:

Re: Can't make anything fit into 1K... or is it me?

Post by Math123 »

If you use t2p then you must use switch -d with calling. This minimizes the DFILE. Very importsnt for 1k ZX81s.
Matthias
User avatar
Math123
Posts: 39
Joined: Sun May 11, 2008 11:14 pm
Location: Germany Wuppertal
Contact:

Re: Can't make anything fit into 1K... or is it me?

Post by Math123 »

I tried to run your program on EightyOne with 1k.
Can load it but it uses too much of the screen.
On a 16k setting it seems to run.

If you really want to program for the 1k Memory then you have to modify a lot.
Attachments
test.bat.txt
rename to test.bat
(621 Bytes) Downloaded 31 times
User avatar
LoadError
Posts: 18
Joined: Thu Apr 29, 2021 12:45 pm

Re: Can't make anything fit into 1K... or is it me?

Post by LoadError »

Thanks, it looks like I'll have to study a bit...
Not quite clear what the attached code does?
My Sinclair belongings:
- unexpanded, unmodified, unbackporched ZX81
- expanded (from 16K to 48K) rubber keyed ZX Spectrum
- a Cambridge Scientific pocket calculator
bola_dor
Posts: 275
Joined: Wed Oct 02, 2019 5:32 am

Re: Can't make anything fit into 1K... or is it me?

Post by bola_dor »

As said before.
ZX81 uses most part of this 1K to keep the screen Display File.. luckily if you are running in less than 3K zeddy will use a compressed frame opening it from top left hand. so if you keep it to that corner you will have enough RAM to run it.

Code: Select all

  10 PRINT "PREMI %1 O %2"
  30 IF INKEY$<>"1" AND INKEY$<>"2" THEN GOTO 20
  40 LET D=VAL (INKEY$)
  50 RAND 
  60 FOR C=1 TO 5
  70 PRINT AT C,7;" "
  80 NEXT C
  90 FOR M=1 TO D
 100 LET T=7*(M-1)
 110 PRINT AT 1,T;"\..\..\..\..\..";AT 2,T;"\:    \ :";AT 3,T;"\:    \ :";AT 4,T;"\:    \ :";AT 5,T;"\''\''\''\''\''"
 120 LET X=INT (RND*6)+1
 130 IF X=1 THEN PRINT AT 3,T+2;"*"
 140 IF X=2 OR X=3 THEN PRINT AT 2,T+1;"*";AT 4,T+3;"*"
 150 IF X=3 THEN PRINT AT 3,T+2;"*"
 160 IF X=4 OR X=5 THEN PRINT AT 2,T+1;"* *";AT 4,T+1;"* *"
 170 IF X=5 THEN PRINT AT 3,T+2;"*"
 180 IF X=6 THEN PRINT AT 2,T+1;"***";AT 4,T+1;"***"
 190 NEXT M
 200 GOTO 20
(I am sorry for the chopped parts :D )

ZX81 wastes lots of bytes using floating point variables, so next to do is convert most of the numbers in your listing to non numeric expressions so they are treated as integers.. ie: use NOT PI instead of 0 (cero) or CODE "\.'" (grphics shift T) instead of 6..

as it is now loads and run on 1K but listing is shown in a compressed screen, only top lines are used....
Lines 60 to 80 may be deleted and you will be able to edit from the listing editor itself
Ernesto
ZX80, TK83, CZ1000, CZ1500, TK85, CZ2000, CZ1000Plus, CZ Spectrum, TK90X 16Kb, CZ Spectrum Plus, TS2068, Sinclair QL. TS 1016, TS1040. And more to come :D
User avatar
LoadError
Posts: 18
Joined: Thu Apr 29, 2021 12:45 pm

Re: Can't make anything fit into 1K... or is it me?

Post by LoadError »

With these hints, I've managed to accomplish the task.
This is what I came up with:
---
LET Q=1
LET W=Q+Q
LET E=W+Q
LET R=E+Q
LET T=R+Q
LET Y=T+Q
PRINT AT NOT PI,NOT PI;"\::\BF\BD\A4\9d\::\A9\A6\A9\AE\::";AT Q,NOT PI;"PREMI \9D O \9E"
@scelta:
IF INKEY$ <>"1" AND INKEY$ <>"2" THEN GOTO @scelta
LET D=VAL(INKEY$)
RAND
FOR C=W TO Y
PRINT AT C,Y;" "
NEXT C
FOR C=Q TO D
LET P=(NOT PI)+Y*(C-Q)
PRINT AT W,P;"\..\..\..\..\..";AT E,P;"\: \ :";AT R,P;"\: \ :";AT T,P;"\: \ :";AT Y,P;"\''\''\''\''\''"
LET X=INT(RND*Y)+Q
IF X=Q THEN PRINT AT R,P+W;"O"
IF X=W OR X=E THEN PRINT AT E,P+Q;"O";AT T,P+E;"O"
IF X=E THEN PRINT AT R,P+W;"O"
IF X=R OR X=T THEN PRINT AT E,P+Q;"O O";AT T,P+Q;"O O"
IF X=T THEN PRINT AT R,P+W;"O"
IF X=Y THEN PRINT AT E,P+Q;"OOO";AT T,P+Q;"OOO"
NEXT C
GOTO @scelta
---
Fits in 1K.
My Sinclair belongings:
- unexpanded, unmodified, unbackporched ZX81
- expanded (from 16K to 48K) rubber keyed ZX Spectrum
- a Cambridge Scientific pocket calculator
bola_dor
Posts: 275
Joined: Wed Oct 02, 2019 5:32 am

Re: Can't make anything fit into 1K... or is it me?

Post by bola_dor »

LoadError wrote: Sun May 02, 2021 5:52 pm With these hints, I've managed to accomplish the task.
This is what I came up with:
---
LET Q=1
LET W=Q+Q
LET E=W+Q
LET R=E+Q
LET T=R+Q
LET Y=T+Q
PRINT AT NOT PI,NOT PI;"\::\BF\BD\A4\9d\::\A9\A6\A9\AE\::";AT Q,NOT PI;"PREMI \9D O \9E"
@scelta:
IF INKEY$ <>"1" AND INKEY$ <>"2" THEN GOTO @scelta
LET D=VAL(INKEY$)
RAND
FOR C=W TO Y
PRINT AT C,Y;" "
NEXT C
FOR C=Q TO D
LET P=(NOT PI)+Y*(C-Q)
PRINT AT W,P;"\..\..\..\..\..";AT E,P;"\: \ :";AT R,P;"\: \ :";AT T,P;"\: \ :";AT Y,P;"\''\''\''\''\''"
LET X=INT(RND*Y)+Q
IF X=Q THEN PRINT AT R,P+W;"O"
IF X=W OR X=E THEN PRINT AT E,P+Q;"O";AT T,P+E;"O"
IF X=E THEN PRINT AT R,P+W;"O"
IF X=R OR X=T THEN PRINT AT E,P+Q;"O O";AT T,P+Q;"O O"
IF X=T THEN PRINT AT R,P+W;"O"
IF X=Y THEN PRINT AT E,P+Q;"OOO";AT T,P+Q;"OOO"
NEXT C
GOTO @scelta
---
Fits in 1K.
You can still take off the

Code: Select all

FOR C=W TO Y
PRINT AT C,Y;" "
NEXT C
Part..
Those LET will save Bytes IF the variables are used several times.. the extra lines are adding bytes .. I didn't make the account. You can use VAL, CODE .. etc in single lines..
There is another very good emulator by XavSnap in this forum that tells yo how are you consuming your RAM..
http://zx81.vb81.free.fr/
Ernesto
ZX80, TK83, CZ1000, CZ1500, TK85, CZ2000, CZ1000Plus, CZ Spectrum, TK90X 16Kb, CZ Spectrum Plus, TS2068, Sinclair QL. TS 1016, TS1040. And more to come :D
Post Reply