Circle() Function in Graphics.h

Other misc things
Post Reply
RobertK
Well known member
Posts: 199
Joined: Mon Feb 26, 2018 12:58 pm

Circle() Function in Graphics.h

Post by RobertK »

void circle(int x, int y, int radius, int skip)

A few questions/issues:

1. What is the purpose of the "skip" parameter? There is no description on the wiki page.

2. Can circles, lines, etc. be somehow drawn XORed?
(I don't need that urgently, I would just like to know if this is already possible)

3. Circle() crashes on the Bandai RX-78 target. Here is a test program to reproduce this.

Code: Select all

/* Circle() Test by RobertK, 2018-12-26

   Compile command for the following targets:
  
   === ZX81 (64?48) === (ok)
   zcc +zx81 -startup=2 -o circletest_ZX81 -create-app circletest.c

   === ZX81 WRX (256?192) === (ok)
   zcc +zx81 -subtype=wrx -clib=wrxansi -startup=4 -o circletest_ZX81_wrx -create-app circletest.c
   
   === Casio PV-2000 === (ok)
   zcc +pv2000 -create-app -o circletest_pv2000 circletest.c 
   
   === Bandai RX-78 ===
   zcc +rx78 -create-app -o circletest_rx78 circletest.c 

*/

#include <stdio.h>        // required for printf()
#include <graphics.h>        // contains plot() and point() functions


void myCls()
{
#if defined(__OSBORNE1__) || defined(__KAYPRO84__) || defined(__ATTACHE__)
        printf("\032");
#else
        printf("%c",12);
        // printf("\x0c");  // the "\x0c" (0x0c character) resets the cursor position to the top left corner
#endif
}

void main()
{ 
  int xMax,yMax;
  
  // determine the screen dimensions for this system
  // coordinates go from 0 to this max value
  xMax=getmaxx();
  yMax=getmaxy();
  
  myCls(); // clear the screen  
  printf("\n\n\n\n\n*** circle test ***\n(%d x %d)\n\n",xMax+1,yMax+1);
  
  printf("press any key to plot and unplot\n\n");
  fgetc_cons();        // wait for keypress
  msleep(250);        // wait a quarter of a second
  
  #if defined(__ABC80__) || defined(__EG2000__) || defined(__SORCERER__) || defined(__VZ200__) || defined(__VG5000__) || defined(__P2000__) || defined(__MULTI8__) || defined(__SC3000__) || defined(__MSX__) || defined (__MTX__) || defined(__KAYPRO84__) || defined(__PACMAN__) // || defined(__CPC__)
        clg();  // activate graphics mode
  #endif
  
  plot(1,1);
  plot(3,3);
  plot(40,4);
  plot(5,5);
  unplot(5,5);
  plot(7,7);

  printf("press any key to draw circle\n\n");
  fgetc_cons();        // wait for keypress
  msleep(250);        // wait a quarter of a second

  circle(20,20,7,1);
  
  printf("\npress any key to clear screen\n");
  fgetc_cons();        // wait for keypress
  msleep(250);        // wait a quarter of a second

  myCls(); // clear the screen 

}
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Circle() and expecially fill() were not broadly ported and tested, Dom recently put a bit of his high quality effort on the GFX stuff and this fixed already the circle() aspect on some target and, sorted out the files which enabled me on revising the graphics library ('callee' parameter passing, gfx cursor positioning and similar minor changes).
xorcircle() does not exist, but should be feasible, I'll try soon.
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Ok, circle() is now fixed, please wait for the next nightly build.

New features:
- 'callee' parameter passing, it will help in saving memory when the same function is used 2 or more times.
- xorcircle()
- rx78 fixed

the "skip" parameter is a but useless, it permits to draw a 'dithered' circle with values >1. The effect is close to the one obtained with "xorborder". It could be of some use if used with xorcircle() to highlight a round shape, e.g. as an option on a graphical user interface to toggle between different screen areas.
This made me notice that also "xorbox()" is missing on all the targets. I preferred xorborder() which looked fancier, but probably we should have both.

The graphics on the RX78 is still not fully working, it seems that also the line drawing code has to be fixed.
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

For the DRAW problems I suspect this is connected to the ROM format and the sections declaration:


SECTION bss_graphics
PUBLIC __gfx_coords


__gfx_coords: defw 0
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

No it wasn't, it is the PLOT code not saving the current position :)
RobertK
Well known member
Posts: 199
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

Circle() on the RX78 works now, thanks. And thank you for xorcircle(), it is certainly good to have this function.
RobertK
Well known member
Posts: 199
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

Please check circle() on the KC85/2-5 as well.
On the 2 and 3 model, it only plots a "diamond" consisting of four dots.
On the 4 and 5 model, the screen gets broken.

Compile the test program like this:
zcc +kc -lndos -pragma-redirect:fputc_cons=fputc_cons_generic -create-app circletest.c -o circletest_KC85_2-5
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

ok I'll check, a possible hint comes from the recent fix Dom did on maths
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Problem found, when I created the "callee" structures I used the AF' register pair, this harms the KC target.
I wonder whether the CPC target is safe :(
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Nope, it is a much less critical problem, swapgfxbk() destroys the A register which is used as a parameter.
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

Solved, the only impacted functions were the circle related ones in "wide" mode only (>256 dots).
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

I'm also moving the temp variables of the dcircle() functions in wide mode from stack to bss. it reduces the code of 100 bytes, runs faster and preserves one of the two index regs
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

ready, hope everything builds tonight you
RobertK
Well known member
Posts: 199
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

Hmm, I don't notice any difference on the KC85/2-5 with the current nightly build, the above mentioned problems are still there.
User avatar
dom
Well known member
Posts: 1194
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

The build failed last night due to a missing zlib-dev package for the native sdcc build so new packages weren't produced.

The build tonight should be good unless anything else breaks.
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

thank you Dom for having answered, Robert, apologies for my parallel answer on the smc70 thread. .
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

for those feeling adventurous, the first nightly build (pre--?? 1.99D ? 1.9periodic ? :) ) is built
RobertK
Well known member
Posts: 199
Joined: Mon Feb 26, 2018 12:58 pm

Post by RobertK »

*Now* that I'm using the new build I can confirm that the KC circle problem is fixed, thank you Stefano.

The new build seems to be working fine, no side-effects so far.

@Dom: thanks for the new Pasopia 7 target, what's available now works great. Console output is quite fast compared to other machines. Joysticks and screen mode switching work correctly.
stefano
Well known member
Posts: 1534
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

great, thank you for testing and encouragement ..I couldn't answer immediately because I was still astonished for the massive quantity of improvements Dom was able to stuff in so little time :)
Post Reply