XORPLOT and line drawings in BASIC and MCODER II

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
User avatar
XavSnap
Posts: 892
Joined: Sat May 10, 2008 4:23 pm

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by XavSnap »

Hi,
In this point, don't store your values in integer format (DIM TABLE(x,y)), but in chars values to preserve memory !
1 DIM T$(10,2)
; 10 values, and 2 chars by value
10 LET X=CODE T$(1,1)
20 LET Y=CODE T$(1,2)
Use CHR$(x) or CHR$(y) to set the value !

In integer format, each value take 6 bytes…
In character format, only 1 byte per value.
Xavier

bola_dor
Posts: 120
Joined: Wed Oct 02, 2019 5:32 am

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by bola_dor »

XavSnap wrote:
Sat Apr 18, 2020 1:14 am
Hi,
In this point, don't store your values in integer format (DIM TABLE(x,y)), but in chars values to preserve memory !
1 DIM T$(10,2)
; 10 values, and 2 chars by value
10 LET X=CODE T$(1,1)
20 LET Y=CODE T$(1,2)
Use CHR$(x) or CHR$(y) to set the value !

In integer format, each value take 6 bytes…
In character format, only 1 byte per value.
yes,,sadly ZX81 can´t define variables as integers,, I miss something like LET A%...
sadly 2 MCODER is not able to mange strings like basic.. I could use REM statements but 126 and 118 values are troublesome... do you know if is there something written about?
I think I can use 32 bytes at PRBUFF to store parameters,, do you think is safe enough? i am not planing to use a printer,, and parameters may be cleared when routines are not called,,, but as you may notice I have just discovered it... :D

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

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by XavSnap »

Try this:

Code: Select all

1 DIM T$(50,2)
2 LET CNT=1
5 PRINT "BUILD ARRAY"
10 FOR A=-3.14 TO 3.14 STEP ((3.14)/25)
20 LET X=INT(SIN (A)*10)+20
30 LET Y=INT(COS (A)*10)+20
40 LET T$(CNT)=CHR$ X+  CHR$ Y
50 LET CNT=CNT+1
60 REM PLOT X,Y
70 IF CNT<51 THEN NEXT A
80 CLS
90 REM DISPLAY
100 FOR A=1 TO 50
110 LET X=CODE T$(A,1)
120 LET Y=CODE T$(A,2)
130 PLOT X-7,Y+5
132 PLOT X+13,Y+5
134 PLOT X+33,Y+5
136 PLOT X+23,Y-10
138 PLOT X+4,Y-10
140 NEXT A
datas.JPG
Xavier

bola_dor
Posts: 120
Joined: Wed Oct 02, 2019 5:32 am

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by bola_dor »

cool!!
olympics array.png
olympics array.png (4.6 KiB) Viewed 495 times
I am working on this but I whant to keep an aray with SIN and COS in degrees ( not in radians) to avoid recalculations, as SIN and /or COS are values from -1.00 to +1.00, I plan to store values in one char$ from 1 to 90 *100 and +100 to fit values in a range from 000 to 200,, then 640 values can be calculated as needed upon wich cuadrant do you need.. i haven´t tested speeds yet,, I´m not avoiding the division and .. i havent determined the resolution/precision I will need... to have 640 values in floating point arrays is fast but eats lots of memmory...

solar penguin
Posts: 5
Joined: Wed Apr 19, 2017 8:29 pm

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by solar penguin »

You probably worked this out already, but you only need to store one set of values for both SIN and COS because SIN X is COS(90-X) and vice versa. That might save a few bytes.

bola_dor
Posts: 120
Joined: Wed Oct 02, 2019 5:32 am

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by bola_dor »

solar penguin wrote:
Thu Apr 30, 2020 9:38 am
You probably worked this out already, but you only need to store one set of values for both SIN and COS because SIN X is COS(90-X) and vice versa. That might save a few bytes.
Thanks.. yes .. my idea was to store just 90dgrees of values and then shift and chance sign to get both 360.. but now I am lackin of any time

Post Reply