Page 1 of 4

Plot function in z88dk

Posted: Mon Jan 29, 2018 4:37 pm
by RobertK
Sorry for this beginner’s question, but how would you implement a Plot() function in z88dk, allowing you to set or clear each block of the 64x48 screen?

The trick is obviously to fill the right parts of the screen memory.

I have made my first little experiments with Z88DK, and the speed of the resulting program (compared to Basic) gives me motivation for further work...

Re: Plot function in Z88DK

Posted: Mon Jan 29, 2018 7:28 pm
by siggi
If you want to plot in LOWRES, you could call the BASIC PLOT routine from Z88DK to plot using BASIC:
an expample for PLOT is here:

https://www.z88dk.org/wiki/doku.php?id= ... 1&s[]=plot


If you want to plot in HIRES, use the "graphic"-library:

https://www.z88dk.org/wiki/doku.php?id= ... []=graphic

HTH Siggi

Re: Plot function in Z88DK

Posted: Mon Jan 29, 2018 10:39 pm
by RobertK
Thanks. I have tried the first method and it works, but unfortunately its speed is exactly the same as if it was done entirely in BASIC. About six seconds for plotting a border around the screen like this:

Code: Select all

10 FOR X=0 TO 63
20 PLOT X,43
30 PLOT X,0
40 NEXT X
50 FOR Y=1 TO 42
60 PLOT 0,Y
70 PLOT 63,Y
80 NEXT Y
Is there a more efficient way to implement PLOT() in low-res? Maybe by writing directly to the appropriate address of the video memory?

The hires functions in graphics.h look very interesting as well, but I assume that this requires WRX, right?

Re: Plot function in Z88DK

Posted: Tue Jan 30, 2018 7:36 am
by mrtinb
Seems there is MID-RES if you have UDG capable hardware. Unfortunately it seems pseudo HIRES is not supported.

Re: Plot function in Z88DK

Posted: Tue Jan 30, 2018 9:24 am
by siggi
RobertK wrote: Mon Jan 29, 2018 10:39 pm The hires functions in graphics.h look very interesting as well, but I assume that this requires WRX, right?
Yes, your hardware (or EO ;-) ) needs to support a HIRES modification. WRX is one of the easiest modifications:

https://www.z88dk.org/wiki/doku.php?id= ... ersion_1.8

Re: Plot function in Z88DK

Posted: Tue Jan 30, 2018 10:09 am
by RobertK
Thanks, I will try writing WRX programs later, but back to my initial question: the target machine for my first program would be an unmodified 16K ZX81/TS1000, and I would like to plot/unplot blocks in low-res 64x48 mode. Any suggestions how this could be achieved efficiently in Z88DK?

I had a look at the source of the Z8048 game, and there the drawGrid() function fills the appropriate parts of the screen memory to display the grid, however using "text mode". Maybe the same can be achieved in low-res graphics?

Re: Plot function in Z88DK

Posted: Tue Jan 30, 2018 10:22 am
by Andy Rea
It can be done fairly quickly BUT... you have to ensure that the d-file is fully expanded i.e. 24 rows of 33 bytes each, that way the screen position can be calculated quite easily and the. Some jiggery pokery with bit manipulation can set / unset a quarter block for you.... Will sort out some assembler code later for you.

Re: Plot function in Z88DK

Posted: Tue Jan 30, 2018 10:58 pm
by Andy Rea
right then.... as promised.... i dont really do the Z88dk thing.... but i know that you can run native Z80 code so you should be able to adapt this code.

anyway HTH

Andy
fastplot.zip
(47.96 KiB) Downloaded 466 times

p.s just re-read previous post.... working on unplot now hahaha

Re: Plot function in Z88DK

Posted: Wed Jan 31, 2018 3:53 pm
by RobertK
Thanks Andy, the speed is impressive!
I may seem entirely hopeless, but can anyone please assist me in wrapping this ASM code into a C function? I know that you need to put the ASM code between #asm and #endasm, but everything else regarding ASM in z88dk is currently trial and error for me.

I should have checked the z88dk forums first, because here is a discussion on exactly this PLOT topic. I have tried using the final "CALLEE" function from there, and it compiles ok, but for some reason the plotted blocks just don't appear on the screen. Maybe I will post that later as well.

Re: Plot function in z88dk

Posted: Wed Jan 31, 2018 9:44 pm
by Andy Rea
i'll have a look with the Z88dk thing....