First steps into Z88DK...and many more to come!

Discuss game and other programming topics not specifically covered in another forum

Moderator: Programming Moderators

Post Reply
SamusDrake
Posts: 252
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

First steps into Z88DK...and many more to come!

Post by SamusDrake » Sun Aug 20, 2017 7:35 pm

NOTE: Please check the newest posts on this thread for the latest updates.

I've spent this weekend going over the basics of Z88DK and really enjoying it. In the abscence of a "Z88DK for Dummies" book, I am going through the provided Spectrum examples. The only real headache was setting the path environment variables as I still struggle with Linux even after using it for two years...

Anyway, if its all right with the forum moderation, I would like to use this thread to record my progress with learning Z88DK and to get feedback. With enough entries, I would then like to revise the content here to place on my website so hopefully I can provide a beginners guide for those at least familiar with C.

Using gfx.c as a guide, this is my first attempt at Spectrum programming...

Code: Select all

/*********************************************************
 * "intro.c" by S.A.Ray (SamusDrake)				 
 *							 
 * This is a simple animation demo for the  		 
 * ZX Spectrum 48K, with a circle moving from left to 
 * the right-hand side of the screen.  
 *
 * Written using z88dk.
 *
 * Many thanks to the good eggs at the ZX Spectrum Next
 * forum. ^_^					 
 *							 
 * Speccy screen resolution: 256×192 pixels              
 *********************************************************/ 
#include <graphics.h>

main()
{
	int count;
	int x = 20, y = 100;
	int size   = 30;
	int speed  = 4;
	int last_x = x;

	// Clear the screen
	clg();

	// Animate the circle...
	for( count = 0; count < 50; count++ )
	{
		// "remove" previously drawn circle
		uncircle( last_x, y, size, 1);

		// now draw the circle in its updated position
		circle( x, y, size, 1);

		// Record the current position(x coordinate) of the circle
		last_x = x;

		// Now update the circle's position...
		x += speed;
	}
}
Last edited by SamusDrake on Sat Jan 27, 2018 10:23 am, edited 1 time in total.

SamusDrake
Posts: 252
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First steps into Z88DK...and many more to come!

Post by SamusDrake » Tue Aug 22, 2017 7:19 pm

I'll be posting up new code on the weekends as thats when I get time to do so. For this upcoming weekend I'll be looking at creating functions( just getting errors at the moment ), floating point variables and hopefully the basics of trigonometry.

I' wrote a software raycaster in Java a few years ago, and I'll be using that as a starting point for creating a "landscaping" demo. So thats the eventual goal...

JoeZX
Posts: 574
Joined: Mon May 29, 2017 9:11 pm
Location: Slovakia

Re: First steps into Z88DK...and many more to come!

Post by JoeZX » Wed Aug 23, 2017 7:57 am

SamusDrake wrote:
Tue Aug 22, 2017 7:19 pm
I'll be posting up new code on the weekends as thats when I get time to do so. For this upcoming weekend I'll be looking at creating functions( just getting errors at the moment ), floating point variables and hopefully the basics of trigonometry.

I' wrote a software raycaster in Java a few years ago, and I'll be using that as a starting point for creating a "landscaping" demo. So thats the eventual goal...
will watch your effort ..

Alcoholics Anonymous
Posts: 511
Joined: Mon May 29, 2017 7:00 pm

Re: First steps into Z88DK...and many more to come!

Post by Alcoholics Anonymous » Wed Aug 23, 2017 1:56 pm

SamusDrake wrote:
Sun Aug 20, 2017 7:35 pm
I'll be posting up new code on the weekends as thats when I get time to do so. For this upcoming weekend I'll be looking at creating functions( just getting errors at the moment ), floating point variables and hopefully the basics of trigonometry.
I look forward to seeing what you come up with!

Just keep in mind, there is no fp unit so floats are done in software and that's a lot slower. Using fixed point would be the way to go in the end for fractional numbers. There are a number of new instructions in the Next to do with multiplication and 32-bit math; the compilers are not using them yet but you can do your matrices (if you go that way) in asm using those instructions. z88dk's assembler will accept the new instructions now and CSPect will emulate them.

For code snippets, maybe include the compile line so people can just cut and paste to compile. And maybe make note if the compile is using the classic library -- people are often not aware that there are two libraries (the zxn target is in the newlib).

Stefan has also started doing some low level routines for graphics in layer 2 for the zxn.
viewtopic.php?f=15&t=710

SamusDrake
Posts: 252
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First steps into Z88DK...and many more to come!

Post by SamusDrake » Wed Aug 23, 2017 8:14 pm

Thank you both for the encouragement.

AA, I remember reading about fixed point in Andre Lamothe's tricks books and therefore shall be revisiting them. Didn't see the point in it at the time( computers were so powerful! ), but I knew it might come in handy at some point. ^_^

Good point about the compile instructions. I'm surprised I overlooked that one... o_O Cheers!

User avatar
Timbucus
Posts: 230
Joined: Tue May 30, 2017 7:43 pm

Re: First steps into Z88DK...and many more to come!

Post by Timbucus » Thu Aug 24, 2017 11:44 am

Looking forward to reading it - I have only briefly experimented with the C as most of my codebase is ASM but, it is in Z800DK assembler now so I can think about stitching them together...
I'm Infinite Imaginations when not in work... PAWS for thought.

SamusDrake
Posts: 252
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First steps into Z88DK...and many more to come!

Post by SamusDrake » Fri Aug 25, 2017 8:31 pm

Cheers, Timbucus.

Spent today setting up an SDL app to work on a Landscape "prototype". Was tempted to use Java but since I'm using C for the final spectrum demo then it made sense to stick with C. Actually found a serious bug in my existing graphics library in the process - my line drawing code got its x'n'y coordinates mixed up! Its typical, because it produced some strange results, and was exactly something I was trying to do ages ago but couldn't figure it out...hmmm. What goes around comes around, and all that jazz!

For the record I'm using Chris Wild's "Art of Landscaping" tutorial on IceMark to better understand landscaping, but for the moment I'm a bit lost with it - hence the SDL prototype. But I do like that because I believe in figuring things out for ourselves...or at least give it a damn good try.

Anyway, should have the next source ready by sunday evening. ^_^

JoeZX
Posts: 574
Joined: Mon May 29, 2017 9:11 pm
Location: Slovakia

Re: First steps into Z88DK...and many more to come!

Post by JoeZX » Fri Aug 25, 2017 9:06 pm


SamusDrake
Posts: 252
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First steps into Z88DK...and many more to come!

Post by SamusDrake » Fri Aug 25, 2017 9:20 pm

LOL! I wish I could work such miracles Joe! ^_^

JoeZX
Posts: 574
Joined: Mon May 29, 2017 9:11 pm
Location: Slovakia

Re: First steps into Z88DK...and many more to come!

Post by JoeZX » Fri Aug 25, 2017 9:28 pm

SamusDrake wrote:
Fri Aug 25, 2017 9:20 pm
LOL! I wish I could work such miracles Joe! ^_^
Okey, okey ..
http://www.abandonwaredos.com/public/ab ... nter-5.jpg

Post Reply