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
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

XORPLOT and line drawings in BASIC and MCODER II

Post by bola_dor »

Hi, I was inspired by a ZX LOGO I´ve found days ago and began experimenting with some drawing routines
I´ve first compared Bresenham´s line routine with the one found at Vickers´s chapter 18 manual,wich I baptized as Vickers´s :D as suspected Bresenham´s is not faster in basic using floating point variables, Vicker´s is even faster but depending on wich direction you are drawing.. so I kept with this last one as is faster in average. And when compiled with MCODER Is more than 100X faster!!!! :mrgreen: fast enough (numbers are frames)
vickersPLOT.bas..png
vickersPLOT.bas..png (3.83 KiB) Viewed 6406 times
vickersPLOT.MC2..png
vickersPLOT.MC2..png (3.85 KiB) Viewed 6406 times
Then I "developed" this XORPLOT routine,, I am not a master of BASIC as you can see :idea: but it works..

XORPLOTLIST..png
XORPLOTLIST..png (5.29 KiB) Viewed 6406 times
but it is really slow,,, ... :oops:
vickersXOR.bas..png
vickersXOR.bas..png (3.99 KiB) Viewed 6406 times
vickersXOR.MC2..png
vickersXOR.MC2..png (3.95 KiB) Viewed 6406 times
as you can see XORPLOT is 2.5 times slower than simply PLOT in BASIC but IS about 18 Times slower than PLOT with MCODER2, XORPLOT is only 14 times faster when compiled than interpreted BASIC..well is fast but I wonder if is there is any optimization to my code to the basic, or in front to MCODER2 ? :?: :?: :?: perhaps a completely different way? I am not good with assembler,, I may try with z88dk when finish with the basic project( I am not a fan of C but like the power of z88dk)
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by XavSnap »

Hi Bola_dor,

Try this code:
1 LET DF=PEEK 16396+256*PEEK 16397+1
2 LET D$="INT((43-B)/2)*33+INT(A/2)"
10 FOR A=1 TO 20
20 LET B=A+2
30 GOSUB 9520
40 NEXT A
50 FOR A=1 TO 20 STEP 2
60 LET B=A+2
70 GOSUB 9520
80 NEXT A
100 GOTO 10
9500 REM PLOT/xorPLOT
9510 REM UNPLOT
9520 LET S1= PEEK (DF+VAL D$)
9530 PLOT A,B
9540 IF S1=PEEK (DF+VAL D$) THEN UNPLOT A,B
9580 RETURN
It's better ?
I test de D_File like the df_cc generated by the PRINT AT command, but it avoid many lines in basic.
The "VAL D$" can be replaced by the numeric values to improve the speed, but it's more funny like that !
:lol:
UNPLOT.P
(1.26 KiB) Downloaded 215 times
Note in VB81, replace the line#2 by using @xx specials characters: (@CF=INT in the PRINT ou LET valeurs /cf. ASCII table/)
2 LET D$="@CF((43-B)/2)*33+@CF(A/2)"


Fast code: (D$ deleted)
UNPLOT2.P
(1.29 KiB) Downloaded 220 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by XavSnap »

Your code : (faster)
9500 REM PLOT/xorPLOT
9510 REM UNPLOT
9520 PRINT AT INT((43-B)/2),INT(A/2);
9525 LET S1= PEEK (PEEK 16398+256*PEEK 16399)
9530 PLOT A,B
9535 PRINT AT INT((43-B)/2),INT(A/2);
9540 IF S1=PEEK (PEEK 16398+256*PEEK 16399) THEN UNPLOT A,B
9580 RETURN
You had to keep less lines, and repeat calculations to avoid n/l jump wasting time per cycle.
LET command take time to execute and line reading take time in the loop process.

Have Fun.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by bola_dor »



You had to keep less lines, and repeat calculations to avoid n/l jump wasting time per cycle.
LET command take time to execute and line reading take time in the loop process.

Have Fun.
Xavier, I had to unfold those lines because of MCODER, I think it doesn't support arithmetics as parameters...
I think VAL is not supported either..

But you game something to play with in your earlier post.. perhaps print at is slower than your method to read D file... I will do may test and let you know..
I be put an eye on your VB81.. looks great!!! I ll test it too as EO Is slow in the old notebook I am using for this and it looks like VB81 as many usefull tools
Thank you!!!
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by bola_dor »

Well I had interesting results...
this listing basically avoid the PRINT AT
Lines are optimized for MCODERII,, a pure basic code may be optimized for less memory usage or to save some CPU cicles.
vickersXOR-XAV LIST..png
vickersXOR-XAV LIST..png (3.68 KiB) Viewed 6334 times
BASIC run is almost 10% slower than the one using PRINT AT (twice) but when compiled with MCODER2 is 4X faster !!: and only 4 times(x0.26) slower than PLOT... I think is fast enough,, surely a machine code algorithm may be faster or perhaps z88dk wich has a proper xplot function too...

compare with the numbers on the first post
vickersXOR-XAV.bas..png
vickersXOR-XAV.bas..png (4.02 KiB) Viewed 6334 times
vickersXOR-XAV.MC2..png
vickersXOR-XAV.MC2..png (4 KiB) Viewed 6334 times
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by XavSnap »

Hi,
You can increase the speed in case of setup all constants in the start of Basic program…

DF is the same at the start of program, and can be set once.
1 LET DF= PEEK 16396+256*PEEK 16397+1
10 GOSUB 9500
(…)
9500 REM DISPLAY ROUYINE...
It avoid to calculate the DF variable at any loop...
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by bola_dor »

XavSnap wrote: Fri Apr 17, 2020 10:13 pm Hi,
You can increase the speed in case of setup all constants in the start of Basic program…

DF is the same at the start of program, and can be set once.
1 LET DF= PEEK 16396+256*PEEK 16397+1
10 GOSUB 9500
(…)
9500 REM DISPLAY ROUYINE...
It avoid to calculate the DF variable at any loop...
thank you!!
that gave me another 10% +speed, now basic is similar to using print at and MC is about 40 frames faster completing this drawing

this happens to me because I don´t know how D File is managed,, when is it suposed to change? may it change any time once started the program? what does it depends on,? where can I red about?
this xorplot routine is called by the "line" routine that is called from the main routine.. so i can check DF at any point but of course out of any loop is better.
regards
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by bola_dor »

another question should be where can I store (POKE) the parameters to the "MCODED" function?
I mean, I plan to use this complied routine in a main basic routine that uses strings in 2dimensional variables like: DIM A$(X.Y) that MCODER can´t manage and rewrite it does not worth the speed gain as is not a time consuming task.
but I need to pass the parameters like A and B in this case,, and a few more for the line routine as the end of the line coordinantes, the plot,unplot or XORplot state... all of them as integers of course...
thanks
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
User avatar
XavSnap
Posts: 1941
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: XORPLOT and line drawings in BASIC and MCODER II

Post by XavSnap »

this happens to me because I don´t know how D File is managed
The D_File is the Video memory offset, placed after the Basic program.
This value is changed by adding chars in the Basic program.
In a saved basic program, this value don't change… and if the Basic is in a final release, the D_file offset a constant value.
another question should be where can I store (POKE) the parameters to the "MCODED" function?
Don't know about Mcoder, but the best way to store binaries is to set the Ram_Top to make room to the variable array.
You can use a part of memory up to the variable memory below the CPU stack room…
Or use the 8-16k memory room… on the Memotech 64k Ram pack.
all of them as integers of course...
No, a Byte value is better.
48x64 : Just code x,y to two byte values, and set b6 to do a XOR/NORMAL draw and reserve b5 for another purpose (xx110000)
Last edited by XavSnap on Sat Apr 18, 2020 1:05 am, edited 1 time in total.
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
bola_dor
Posts: 398
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 12:54 am
this happens to me because I don´t know how D File is managed
The D_File is the Video memory offset, placed after the Basic program.
This value is changed by adding chars in the Basic program.
In a saved basic program, this value don't change… and if the Basic is in a final release, the D_file offset a constant value.
another question should be where can I store (POKE) the parameters to the "MCODED" function?
Don't know about Mcoder, but the best way to store binaries is to set the Ram_Top to make room to the variable array.
You can use a part of memory up to the variable memory below the CPU stack room…
Or use the 8-16k memory room… on the Memotech 64k Ram pack.
many Thanks!!!!
I´ll search about that,, I don´thave a memotech,, just regular 16k rampack..
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
Post Reply