Page 3 of 4
Re: Expansive expansions
Posted: 18 Oct 2023 19:49
by SpacedCowboy
stephen_usher wrote: 18 Oct 2023 19:41
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
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 :)
Re: Expansive expansions
Posted: 18 Oct 2023 19:51
by stephen_usher
Yeah, but my TT and MiNT set-up predates 1999 by about 5 years! :-)
Re: Expansive expansions
Posted: 18 Oct 2023 19:55
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.
Re: Expansive expansions
Posted: 18 Oct 2023 20:16
by Badwolf
SpacedCowboy wrote: 18 Oct 2023 19:55
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.
Re: Expansive expansions
Posted: 18 Oct 2023 22:38
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. ;-)
Re: Expansive expansions
Posted: 19 Oct 2023 00:46
by SpacedCowboy
stephen_usher wrote: 18 Oct 2023 22:38
OK, not tried it on a real machine yet but this should hopefully be C89 compliant:
Badwolf wrote: 18 Oct 2023 20:16
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: 18 Oct 2023 20:16
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: 18 Oct 2023 20:16
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
Re: Expansive expansions
Posted: 19 Oct 2023 08:23
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.
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.
Re: Expansive expansions
Posted: 19 Oct 2023 16:13
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 :)
Re: Expansive expansions
Posted: 19 Oct 2023 20:57
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
Re: Expansive expansions
Posted: 19 Oct 2023 21:18
by stephen_usher
The times have been printed in the wrong locations, so swap them,
Screenshot_2023-10-19_21-31-01.png
(Edit: Added sleep(60); to the end of main() so as to give time to capture screen and replaced image in post.)