Jump to content
Pokeypy

PLOT and DRAWTO with CC65 in C? [solved]

Recommended Posts

26 minutes ago, Pokeypy said:

I tried to understand your code

 

It's not my code in afraid, just an example I found of the use of the tgi calls

 

28 minutes ago, Pokeypy said:

As I don't have the limitations of classic computers

 

You need to consider the likes of Telengard where the 100x100x100 maze is just the property of a function

 

    for(outer=0; outer<4; outer++) {
        for(inner=0; inner<4; inner++) {
            map[outer][inner] = whats_at(x_pos+inner-1,y_pos+outer-1,z_pos);
        }
    }

 

map.c

Share this post


Link to post
Share on other sites
14 hours ago, Pokeypy 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!

It's not my code either but I can answer some of your questions.

 

Most C compilers initialise variables to 0 (unless some other value is specifically given for a specific variable).
So all the borders are initialised to have no border walls and are later modified to have bit 0 and/or 1 turned on via |= RIGHT or |=BOTTOM.

 

Macro function can usually be converted to ordinary function in a mechanical fashion.

static int GoodDir( int Cell, int Dir )
{
    return (g.Maze[Cell].Border & Dir) == 0;
}

 

Called by 

bool flag;

flag = GoodDir( Cell, Dir );

  • Like 1

Share this post


Link to post
Share on other sites

This example code is a really good example of how not to write programs in CC65 ;-)

While it's a proper C, the generated code will be crazy inefficient and huge on the 6502.

Share this post


Link to post
Share on other sites
7 hours ago, stepho said:

Most C compilers initialise variables to 0 (unless some other value is specifically given for a specific variable)

 

Be careful. Local variables which aren't initialized have a random value.

(File-)Global variables which aren't initialized are defined to be 0 (by the C standard). I they aren't 0 in one compiler, it's a compiler bug.

Share this post


Link to post
Share on other sites
15 hours ago, sanny said:

 

Be careful. Local variables which aren't initialized have a random value.

(File-)Global variables which aren't initialized are defined to be 0 (by the C standard). I they aren't 0 in one compiler, it's a compiler bug.

True, I should have said "global variables".

Share this post


Link to post
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.

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...