Byte count required.

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Shaun_B
Posts: 451
Joined: Wed Apr 22, 2009 10:22 am

Byte count required.

Post by Shaun_B » Mon Feb 13, 2017 6:14 pm

Hey guys,

It's been a while (too long) since I've done anything remotely 8-bit but now I seem to be able to grab a few hours here and there.

I've entered some BASIC listings into Code Golf on Stack Exchange, and this one has received two votes. The only issue is that I'm not sure of the byte count, so if someone could help please (as well as pointing me to where I'd work this out in future)? The entries are as follows:

Code: Select all

1 PRINT "PRESS ANY KEY TO CONTINUE..."
2 GOTO (INKEY$<>"")+VAL "2"
and...

Code: Select all

1 PRINT "PRESS ANY KEY TO CONTINUE..."
2 PAUSE VAL "4E4"
Regards,

Shaun.

User avatar
PokeMon
Posts: 2225
Joined: Sat Sep 17, 2011 6:48 pm

Re: Byte count required.

Post by PokeMon » Mon Feb 13, 2017 10:28 pm

You can use the ZX-IDE for that purpose.
It can create mixed programs with ASSEMBLY and BASIC and when you generate a listing with CtrL-F8 you can see how the BASIC will be assembled (in bytes).

http://sinclairzxworld.com/viewtopic.php?f=6&t=1064

Code: Select all

0074: [407D] 00 0A 0F 00 F1 3B 14 20     10 LET V = 40000
             1C 1C 1C 1C 7E 90 1C 40    
             00 00 76                   
                                        
0087: [4090] 00 14 03 00 F5 3B 76        20 PRINT V
                                        
008E: [4097] 00 1E 0E 00 EA              30 REM _asm
0093: [409C] 2A 1C 40                       LD  HL,($401C)
0096: [409F] F5                             PUSH AF
0097: [40A0] C5                             PUSH BC
0098: [40A1] D5                             PUSH DE
0099: [40A2] 3A 34 40                       LD   A,(FRAMES)
009C: [40A5] CF                             RST $08
009D: [40A6] FF                             db  $ff
009E: [40A7] C9                             RET
009F: [40A8] 76                             END _asm
                                        
00A0: [40A9] 00 28 0E 00 F9 D4 1D 22     40 RAND USR #30#
             21 20 1C 7E 8F 01 38 00    
             00 76                      

User avatar
XavSnap
Posts: 761
Joined: Sat May 10, 2008 4:23 pm

Re: Byte count required.

Post by XavSnap » Tue Feb 14, 2017 1:04 am

Get the first code:
I prefer method 1 as on the ZX81, there is a screen flicker when PAUSE is called, and if you want long enough (providing the ZX81 doesn't overheat or crash) the pause will eventually come to an end, whereas method 1 is stuck in an infinite loop until a key is pressed, and no screen flicker.
2 [GOTO] ( [INKEY$] [<>] "")+ [VAL] "2"
4+ 1+1+1+1+1+1+1+1+1+1+1+1 +1=5+12= 17 bytes! -not approximately-

and

2 [PAUSE] [VAL] "4E4"
4+ 1+1+1+1+1+1+1 +1=5+7=12 bytes! -not approximately-

One byte per key + 4 for the header + 1 for the end of line (118).

a value use : [xxxxx] chars+ a 6 bytes encoded blocs.

10 [LET] V = 40000 [N/L]
4+ 1 +1+1+(1+1+1+1+1)+6+1 =19 bytes.

User avatar
mrtinb
Posts: 1068
Joined: Fri Nov 06, 2015 5:44 pm
Location: Denmark
Contact:

Re: Byte count required.

Post by mrtinb » Tue Feb 14, 2017 2:56 am

You can use the WHERE command of ZXTK to get address of line number.

Insert an empty line, so you know line where the program stops e.g.:

Code: Select all

3 STOP
Now run the WHERE command on line 1.
Run the WHERE command on line 3.
Subtract the two numbers.
Martin
ZX81, Lambda 8300, Commodore 64, Mac G4 Cube

Shaun_B
Posts: 451
Joined: Wed Apr 22, 2009 10:22 am

Re: Byte count required.

Post by Shaun_B » Thu Feb 16, 2017 5:24 pm

Thanks for the tips.

How do I find out how much actual system RAM I've used including things like var stack etc...?

Regards,

Shaun.

User avatar
PokeMon
Posts: 2225
Joined: Sat Sep 17, 2011 6:48 pm

Re: Byte count required.

Post by PokeMon » Thu Feb 16, 2017 7:49 pm

Well - see chapter 27 and 28 for more details.
http://otremolet.free.fr/otnet/otzx/zx8 ... index.html

The available memory is approx. ERR_SP-STKEND.
In BASIC:
10 LET TOP=PEEK 16386+256*PEEK 16387
20 LET BOTTOM=PEEK 16412+256*PEEK 16413
30 PRINT TOP,BOTTOM,TOP-BOTTOM
The stack pointer can not be found in BASIC but you can assume that normally not more than 20 bytes are required for a small stack.

User avatar
XavSnap
Posts: 761
Joined: Sat May 10, 2008 4:23 pm

Re: Byte count required.

Post by XavSnap » Thu Feb 16, 2017 7:53 pm

BYTEs count: (per line)

Code: Select all

1 LET NXT=PEEK(16426)*256+PEEK(16425)+5
2 REM this is my line.
3 PRINT (PEEK(VAL"16426")*VAL"256"+PEEK(VAL"16425"))-VAL"43"-NXT
OR

Code: Select all

1 PRINT PEEK(PEEK(16426)*256+PEEK(16425)+2)+256*PEEK((PEEK(16426)*256+PEEK(16425)+3))+4
2 REM this is my line.
Juste...
1 PRINT PEEK(PEEK(16426)*256+PEEK(16425)+2)+4
incase of the ligne lenght is lower than 256

Post Reply