Wrathchild Posted April 13, 2021 Share Posted April 13, 2021 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 Quote Link to comment Share on other sites More sharing options...
stepho Posted April 14, 2021 Share Posted April 14, 2021 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 ); 1 Quote Link to comment Share on other sites More sharing options...
ilmenit Posted April 14, 2021 Share Posted April 14, 2021 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. Quote Link to comment Share on other sites More sharing options...
sanny Posted April 14, 2021 Share Posted April 14, 2021 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. Quote Link to comment Share on other sites More sharing options...
stepho Posted April 15, 2021 Share Posted April 15, 2021 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". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.