Jump to content
IGNORED

PLOT and DRAWTO with CC65 in C? [solved]


Recommended Posts

Hi,

I'm trying to do just something like PLOT and DRAWTO with CC65 in C.
Seems difficult. Setting a graphics mode with "_graphics()" doesn't seem to be the way to go. I mean, what to do, if the graphics mode is set?
So far, I can run "tgidemo.c" from the CC65 examples. Seems to be a general purpose draw routine (for several systems). To make it work, I have to copy the driver files from "../cc65/target/atari/drv/tgi" to the Atari disk file. For compiling, I use the line:

cl65 -t atari -Wl -D__RESERVED_MEMORY__=0x2000 -o tgid.obj tgidemo.c


Well, that draws something. But I doubt, that's the way to do it. There must be a better way.

I can also compile and run this code, which is nice. It sets up a display list and scrolls a screen with letters. Interesting. It's not really plotting and drawing, but I think, setting up a custom display list would be a step in the process.

Can't you just poke in some values into a screen memory to set pixels?

So how would you plot and draw? In, let's say, this game mode with four colors and a resolution of 160x195? Ideal would be a little code example to reproduce. Thanks.

Edited by Pokeypy
Link to comment
Share on other sites

The TGI support for CC65 isn't the greatest as I recall (although it may have been updated since I last saw it). I can't remember if there's OS support for plot and drawto, but I think not, and that probably wouldn't be the fastest either.

I always plotted directly by writing to screen memory, and for drawto I dropped in a fast line algorithm. You can find them in asm or native C with a bit of googling or searching here.

 

*edit*

Actually, I think I recall that there are some graphic libraries that other people have done that you could find.

Edited by danwinslow
Link to comment
Share on other sites

46 minutes ago, Pokeypy said:

So far, I can run "tgidemo.c" from the CC65 examples. Seems to be a general purpose draw routine (for several systems). To make it work, I have to copy the driver files from "../cc65/target/atari/drv/tgi" to the Atari disk file. For compiling, I use the line:


cl65 -t atari -Wl -D__RESERVED_MEMORY__=0x2000 -o tgid.obj tgidemo.c

 

 

If you don't want the driver as separate file on the disk, you can include it into your program:

 

cl65 -t atari -Wl -D__RESERVED_MEMORY__=0x2000 -DDYN_DRV=0 -o tgid.obj tgidemo.c

 

Quote

Well, that draws something. But I doubt, that's the way to do it.

 

Well, that's the simplest way to do it. You can use the functions of the TGI interface, see https://cc65.github.io/doc/tgi.html.

 

Quote

There must be a better way.

I can also compile and run this code, which is nice. It sets up a display list and scrolls a screen with letters. Interesting. It's not really plotting and drawing, but I think, setting up a custom display list would be a step in the process.

Can't you just poke in some values into a screen memory to set pixels?

 

Sure. You can always write directly into screen memory.

 

 

Quote

So how would you plot and draw? In, let's say, this game mode with four colors and a resolution of 160x195? Ideal would be a little code example to reproduce. Thanks.

 

The tgidemo.c program by default uses the "default driver" of the platform, which happens to be GR8 on Atari. To use GR15, make the following change to tgidemo.c:

 

 

--- a/samples/tgidemo.c
+++ b/samples/tgidemo.c
@@ -200,7 +200,8 @@ int main (void)
     CheckError ("tgi_load_driver");
 #else
     /* Install the driver */
-    tgi_install (tgi_static_stddrv);
+    //tgi_install (tgi_static_stddrv);
+    tgi_install (atr15_tgi);
     CheckError ("tgi_install");
 #endif

 

regards,
chris

Edited by sanny
typo fix
  • Like 1
Link to comment
Share on other sites

2 hours ago, Wrathchild said:

[Edit] that listing uses an older tgi so have just updated it

Thank you very much! These days, I need my code in a Python-like format with four space characters for one level of indentation, otherwise I'm getting confused. So I changed the indentations and whitespace to my needs (attachment). I hope, you don't mind.

The drawing works, but it just shows a wall, I can't walk around in the maze. That's not much of a problem here though, because I just want to study the way the drawing is done.

I'll need some time to do that. But thanks again, that's a very good starting point.

3dmaze_4ind.c

Link to comment
Share on other sites

6 hours ago, Wrathchild said:

Keys seem to be I = forward, J = turn left and L = turn right

Right. I was stupid, only tested the cursor keys. :) Yeah, it works now.

 

So this is what I extracted. Instant DRAWTO. Nice. Works like a charm. Can even display text.

List of available functions would be here. Look for "tgi_...", further down on the page.

Is this the only "graphics mode" in tgi or are there others?

#include <tgi.h>

/* Compiling with:
   cl65 -t atari -Wl -D__RESERVED_MEMORY__=0x2000  -DDYN_DRV=0  -o hello.xex hello.c
*/

int main() {
    int width;
    int height;
    tgi_install (tgi_static_stddrv);
    tgi_init();
    width  = tgi_getxres();
    height = tgi_getyres();
    tgi_setcolor(COLOR_WHITE);
    tgi_clear();
    tgi_outtextxy(10, 10, "Hello World");
    tgi_gotoxy(0, 10);
    tgi_lineto(320, 192);
    while (1) {
    }
    tgi_done();
    return 0;
}
Edited by Pokeypy
Link to comment
Share on other sites

13 minutes ago, Pokeypy said:

So this is what I extracted. Instant DRAWTO. Nice. Works like a charm. Can even display text.

List of available functions would be here. Look for "tgi_...", further down on the page.

Is this the only "graphics mode" in tgi or are there others?

 

Did you read my post (post #3), or not?

 

Link to TGI function page is there, and how to use a different graphics mode...

Link to comment
Share on other sites

32 minutes ago, sanny said:

Did you read my post (post #3), or not?

When I read your posting this afternoon, I wasn't yet ready to understand it regarding the tgi-drivers, because I didn't know, how tgi was used and you didn't show it. I could understand the advice from your posting though, how to put that option to the compile-line to avoid copying all those driver files to disk.

It also would have been nice, if you had posted a little code example, how to poke into screen memory to get a pixel from it, instead of just saying, that this can be done somehow, again without showing how.

Anyway. So tgi graphics modes can be selected by loading different tgi-drivers. Cool.

  • Like 1
Link to comment
Share on other sites

52 minutes ago, Pokeypy said:

It also would have been nice, if you had posted a little code example, how to poke into screen memory to get a pixel from it, instead of just saying, that this can be done somehow, again without showing how.

 

This is unresolved and left as an exercise for the reader. You'll learn much more by getting it done by yourself instead of using some code snippets of someone else.

 

?

 

(Hint: SAVMSC (asm), or OS.savmsc (C))

Edited by sanny
  • Like 1
Link to comment
Share on other sites

3 hours ago, Wrathchild said:

By 'thread' I would more say:

If you look at '.proc LINE' in the tgi drivers then as USE_CIO_LINE isn't typically* used they will be using the Bresenham's implementation in there.

https://github.com/cc65/cc65/blob/master/libsrc/atari/tgi/atari_tgi_common.inc

 

* - though has been mentioned here by @sanny

 

Not the wiki about bresenhams. The above is what I meant, although I don't see where Sanny mentioned it. I'll take your word for it.

Edited by danwinslow
Link to comment
Share on other sites

On 4/6/2021 at 8:00 AM, Pokeypy said:

I'm trying to do just something like PLOT and DRAWTO with CC65 in C.
Seems difficult. Setting a graphics mode with "_graphics()" doesn't seem to be the way to go. I mean, what to do, if the graphics mode is set?

I suppose another approach would be to use CIO and S: driver... And call PLOT and DRAWTO functions of S:..

 

I've done that from ASM to good effect.

 

  • Like 1
Link to comment
Share on other sites

6 minutes ago, bhall408 said:

I suppose another approach would be to use CIO and S: driver... And call PLOT and DRAWTO functions of S:..

 

I've done that from ASM to good effect.

Speaking of which, I already have those as a ca65 library, so I should really try calling my own ca65 code from cc65!

 

Link to comment
Share on other sites

On 4/6/2021 at 3:50 PM, Wrathchild said:

That's really a cool piece of code! Seems to be the basis of "Bard's Tale", which is probably my favourite game of all time (it's on the Amiga).

So the last few days, I tried to understand your code. Actually, I did a rewrite in Python/Pygame, integrating other people's library code for maze generation.

My script works now, it has 35K (about 1000 lines of code); it's not Atari 8 bit programming though, so it would be a bit off-topic here. As I don't have the limitations of classic computers, I can have rather large mazes, like 100x100 for example, where you really get lost. :)

My questions about your C-version would be:

- ".Border" seems to be initialized with just a "|=". So that's "....Border = ....Border | RIGHT;". Doesn't that mean, that ".Border" is undefined in the first place?

- These macros like

#define GoodDir( Cell, Dir )   ((g.Maze[ (Cell) ].Border & (Dir)) == 0)

replace functions, right? How would they be written as functions? (As functions, I could understand that kind of code more easily.)

- What do ".Walls", ".Border", ".Path" actually mean? They're just integers. How do they describe the properties of a maze cell?

- Unfortunately, I also didn't fully understand your maze generating algorithm. But I see, what you were going for, for something like this (seems to be a general problem in computer science), so I used that Python library instead.

I know, you wrote that code 11 years ago and probably don't have the time to answer everything in detail.

But I thank you very much for it anyway. It's cool!

Edited by Pokeypy
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...