Expansive expansions

Blogs & guides and tales of woo by forum members.
SpacedCowboy
Posts: 43
Joined: Sat Oct 14, 2023 5:43 am

Re: Expansive expansions

Post by SpacedCowboy »

stephen_usher wrote: Wed Oct 18, 2023 7:41 pm Erm, what standard of C is that? GCC 2.95.2 won't compile it as there are variable definitions interspersed with the code. That's not valid for ANSI C (C89?).
Looks like my projects default to C11 (with GNU extensions) these days
Screen Shot 2023-10-18 at 11.47.04 AM.png
Screen Shot 2023-10-18 at 11.47.04 AM.png (6.51 KiB) Viewed 264 times
You're right in that changing back to C89 doesn't work, but C99 does (-std=c99 or -std=gnu99). It has been a couple of decades now :)
stephen_usher
Posts: 5004
Joined: Mon Nov 13, 2017 7:19 pm
Location: Oxford, UK.
Contact:

Re: Expansive expansions

Post by stephen_usher »

Yeah, but my TT and MiNT set-up predates 1999 by about 5 years! :-)
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
SpacedCowboy
Posts: 43
Joined: Sat Oct 14, 2023 5:43 am

Re: Expansive expansions

Post by SpacedCowboy »

That's fair :)

Badwolf reposted the code above with changes that seemed to fix (actually, I'm going to use "fix") the issues, reading through it earlier. I noticed he'd declared loop variables outside the for() statement etc.
User avatar
Badwolf
Posts: 2199
Joined: Tue Nov 19, 2019 12:09 pm

Re: Expansive expansions

Post by Badwolf »

SpacedCowboy wrote: Wed Oct 18, 2023 7:55 pm That's fair :)

Badwolf reposted the code above with changes that seemed to fix (actually, I'm going to use "fix") the issues, reading through it earlier. I noticed he'd declared loop variables outside the for() statement etc.
I was using gcc 4.6.4 which doesn't allow declarations in loops, but does within code blocks.

I hadn't quite twigged what you were doing with the transparent option, so I ended up commenting that out and not implementing the lines to the bottom. Easy to put back.

Also I was running in ST Low so I restricted it to one pass in the upper 320x200.

Anyway, all pretty trivial little tweaks if you'd like to do it properly, @stephen_usher.

BW

PS. I think the parameter order in your implementation of vt_justified was wrong, but I ended up going with gtext anyway.
DFB1 Open source 50MHz 030 and TT-RAM accelerator for the Falcon
DSTB1 Open source 16Mhz 68k and AltRAM accelerator for the ST
Smalliermouse ST-optimised USB mouse adapter based on SmallyMouse2
FrontBench The Frontier: Elite 2 intro as a benchmark
stephen_usher
Posts: 5004
Joined: Mon Nov 13, 2017 7:19 pm
Location: Oxford, UK.
Contact:

Re: Expansive expansions

Post by stephen_usher »

OK, not tried it on a real machine yet but this should hopefully be C89 compliant:

Code: Select all

/*/
//  main.c
//  aspiral
//
//  Created by ThrudTheBarbarian on 10/17/23.
/*/

#include <unistd.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
 
#include "gem.h"

#ifdef QGEM
#include "gemio.h"
#include "gemmsg.h"
#include "rscfile.h"
#include "vdi.h"
#endif

/*****************************************************************************\
|* Forward declarations
\*****************************************************************************/

void plotArchimedesSpiral(int handle, int offX, int offY, int transparent);

/*****************************************************************************\
|* Archimedes spiral as a line-drawing demo
\*****************************************************************************/

int main(int argc, const char * argv[])
{
	int16_t workIn[16];
	int16_t workOut[128];
	int16_t handle;
	
	for (int i=0; i<16; i++)
		workIn[i] = -1;
	workIn[0] = 1;
	workIn[2] = 2;
	
	/*************************************************************************\
	|* Connect to the display, clear it, and ensure we're in graphics mode
	\*************************************************************************/

	v_opnvwk(workIn, &handle, workOut);
	v_clrwk();
	vq_exit_cur(handle);
	
	plotArchimedesSpiral(handle, 0,0, 1);
	plotArchimedesSpiral(handle, 320,0, 0);
}

/*****************************************************************************\
|* Plot algorithm
\*****************************************************************************/

void plotArchimedesSpiral(int handle, int offX, int offY, int transparent)
{
	struct timeval stt, end, dt;
	
	/*************************************************************************\
	|* Set up the parameters
	\*************************************************************************/

	const  int kSize 	= 144;
	int xp				= kSize;
	float xr			= 4.71238905f;
	float xf			= xr / xp;

	float zt, zs, xl, xt, yy, x1, y1;

	int zi, xi;

	int16_t pxy[4];
	
	int16_t black[3] = {0,0,0};

	char buf[128];

	gettimeofday(&stt, NULL);

	vsl_color(handle, 0);
	
	/*************************************************************************\
	|* Draw the plot
	\*************************************************************************/

	for (zi = -64; zi < 64; zi++)
	{
		zt = zi * 2.25f;
		zs = zt * zt;
		xl = (int)(sqrtf(kSize * kSize - zs) + 0.5f);
		
		for (xi = -xl; xi<xl; xi++)
		{
			xt = sqrt(xi*xi + zs) * xf;
			yy = (sin(xt) + sin(xt*3) * 0.4) * 56;
			x1 = offX + xi + zi + 160;
			y1 = offY + 90 - yy + zi;
			
			vs_pixrgb(handle, x1, y1, black);
			
			if (transparent == 0)
			{
				pxy[0] = (int16_t)x1
				pxy[1] = (int16_t)(y1+1)
				pxy[2] = (int16_t)x1;
				pxy[3] = 191};

				v_pline(handle, 2, pxy);
			}
		}
	}
	
	/*************************************************************************\
	|* Show how long it took
	\*************************************************************************/

	gettimeofday(&end, NULL);

	timersub(&end, &stt, &dt);

	sprintf(buf, "Time taken: %d.%06d secs", (int)dt.tv_sec, (int)dt.tv_usec);
	
	vst_alignment(handle, ALGN_CENTER, ALGN_BASELINE, NULL, NULL);
	v_justified(handle, offX, offY + 220, 320, 0,0, buf);
}

I'll have to de-ansify it so as to try to compile it with Sozobon C. ;-)
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
SpacedCowboy
Posts: 43
Joined: Sat Oct 14, 2023 5:43 am

Re: Expansive expansions

Post by SpacedCowboy »

stephen_usher wrote: Wed Oct 18, 2023 10:38 pm OK, not tried it on a real machine yet but this should hopefully be C89 compliant:
Badwolf wrote: Wed Oct 18, 2023 8:16 pm I was using gcc 4.6.4 which doesn't allow declarations in loops, but does within code blocks.
So I tried to take what you did and what Stephen did, set my compiler to be C89 and the version checked in now compiles for me. I'm not sure just how C89-like clang is, but it did throw up some warnings which I fixed. I also added

Code: Select all

/*****************************************************************************\
|* Define a constant so we know it's our version of GEM 
\*****************************************************************************/
#ifndef QGEM
#  define QGEM 1
#endif
so the extraneous headers don't get included. I'll get around to tidying all that up at some point, so the only includes are the same as a native C compiler...
Badwolf wrote: Wed Oct 18, 2023 8:16 pm I hadn't quite twigged what you were doing with the transparent option, so I ended up commenting that out and not implementing the lines to the bottom. Easy to put back.
Yeah, it's just the original algorithm from Analog - it overdraws in white from the next line down to the bottom of the screen, which has the effect of "hidden line removal".
Badwolf wrote: Wed Oct 18, 2023 8:16 pm PS. I think the parameter order in your implementation of vt_justified was wrong, but I ended up going with gtext anyway.
Whoops - thanks, good catch - fixed. I also removed the hackery that allowed a direct pixel-set with an RGB value (since I always have a 1080p @ 32-bit screen, being able to plot a pixel without a bunch of setup was nice, and avoiding several round-trips because of each function call was nice too :)) - anyway, the new figures I get are:

spirals v2.png
spirals v2.png (43.09 KiB) Viewed 223 times
stephen_usher
Posts: 5004
Joined: Mon Nov 13, 2017 7:19 pm
Location: Oxford, UK.
Contact:

Re: Expansive expansions

Post by stephen_usher »

Just a note that setting the values in an array at definition is allowed even in K&R C so your black array can be set up in one line. i.e.

Code: Select all

	int16_t black[3] = { 0, 0, 0 };
At the moment you have a bug where the black value is set to whatever black[0] happens to have in it and this is not set.
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
SpacedCowboy
Posts: 43
Joined: Sat Oct 14, 2023 5:43 am

Re: Expansive expansions

Post by SpacedCowboy »

Huh - yeah I'm not sure how I managed to miss off the "=0" at the end of the statement...

Still, we're not actually using that variable any more - I was using it as the RGB value for the pixel in the GEM-extension call vs_pixrgb() call I added that plots a pixel in a given RGB colour. Since the code now uses the same draw-a-polyline-for-a-point approach as "normal" GEM, I just got rid of all the references to 'black' completely. We use the default pen-1 to draw and pen-0 to clear now.

Thanks for pointing it out though, vestigial code annoys me :)
stephen_usher
Posts: 5004
Joined: Mon Nov 13, 2017 7:19 pm
Location: Oxford, UK.
Contact:

Re: Expansive expansions

Post by stephen_usher »

Trying to compile now...

ALGN_CENTER and ALGN_BASELINE undefined. Should be TA_CENTER and TA_BASE from the header files.

Needs <sys/types.h> to be included.

Too few arguments to v_clrwrk(), needs a handle.

Undefined symble vq_exit_cur
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
stephen_usher
Posts: 5004
Joined: Mon Nov 13, 2017 7:19 pm
Location: Oxford, UK.
Contact:

Re: Expansive expansions

Post by stephen_usher »

The times have been printed in the wrong locations, so swap them,

Screenshot_2023-10-19_21-31-01.png
Screenshot_2023-10-19_21-31-01.png (666.33 KiB) Viewed 164 times

(Edit: Added sleep(60); to the end of main() so as to give time to capture screen and replaced image in post.)
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
Post Reply

Return to “MEMBER BLOGS”