parkfun101 Posted March 12, 2015 Author Share Posted March 12, 2015 Well, I'm still working on figuring out the issue. I wanted to be able to display 7 digits for the score like the Arcade game has, but my function for doing this seemed to be part of the problem. Also I had 3 arrays for storing the scores that I did as the long datatype and after changing those to int, the game allowed me to go from 55 to 85 levels before blacking out . It also gave me 2,590 bytes back! So I guess using the long datatype in a Colecovision game is not such a good idea. Understand that when I say levels, I mean the same 10 levels repeated over and over so 1 level is just a level you complete. I still think I have some variables I can modify that may help the game even further. So, I guess for this game, I'll keep the score at 5 digits, but that will help fix some of the issues I was having. Quote Link to comment Share on other sites More sharing options...
parkfun101 Posted March 12, 2015 Author Share Posted March 12, 2015 (edited) Ok, I think I figured out the problem with my game. I just tested and I could get to level 201 and I stopped testing at that point. Here is what seems to have caused the issue and it is not something I thought would cause this behavior. Just a recap for those Googling to figure out the problem and fix: The issue: Play Colecovision game for a long time and then it freezes, the game just restarts, or the game blacks out. The cause: In my case, some global variable arrays were not being used and therefore also not being initialized. For example: SCORE[1] was for P1 and SCORE[2] was for P2 and both are integers, I had them as long earlier, but changed it to integer. I wasn't using SCORE[0] and therefore it wasn't being initialized. I also did this with some other variables as well. The fix: I changed it so SCORE[0] is for P1 and SCORE[1] is for P2 and initialized all other unused variables to 0 at the start of the game just so they had an initial value. I immediately assumed the issue was caused by the nmi since it is a source for many headaches, but not in this case. Variables declared in a function get caught by the compiler and it will give you a Warning message, but Global variables are not caught and it gives no warning that they are not declared, at least not in CCI3.Now, I'm just going to clean up the rest of the variables and make sure I don't break anything trying to do that. Oh, and I thought of a "SNEAKY" way to allow for 6 digit scores, but only use a an integer. Basically, I will fake the scores like this: Bike = 500 points so I make the bike worth 50 points and always leave an extra "0" displayed for the score so it looks like 500. As long as none of the scores are single digits, this should work fine. Edited March 12, 2015 by parkfun101 1 Quote Link to comment Share on other sites More sharing options...
+Tarzilla Posted March 13, 2015 Share Posted March 13, 2015 Ok, I think I figured out the problem with my game. I just tested and I could get to level 201 and I stopped testing at that point. Here is what seems to have caused the issue and it is not something I thought would cause this behavior. Just a recap for those Googling to figure out the problem and fix: The issue: Play Colecovision game for a long time and then it freezes, the game just restarts, or the game blacks out. The cause: In my case, some global variable arrays were not being used and therefore also not being initialized. For example: SCORE[1] was for P1 and SCORE[2] was for P2 and both are integers, I had them as long earlier, but changed it to integer. I wasn't using SCORE[0] and therefore it wasn't being initialized. I also did this with some other variables as well. The fix: I changed it so SCORE[0] is for P1 and SCORE[1] is for P2 and initialized all other unused variables to 0 at the start of the game just so they had an initial value. I immediately assumed the issue was caused by the nmi since it is a source for many headaches, but not in this case. Variables declared in a function get caught by the compiler and it will give you a Warning message, but Global variables are not caught and it gives no warning that they are not declared, at least not in CCI3.Now, I'm just going to clean up the rest of the variables and make sure I don't break anything trying to do that. Oh, and I thought of a "SNEAKY" way to allow for 6 digit scores, but only use a an integer. Basically, I will fake the scores like this: Bike = 500 points so I make the bike worth 50 points and always leave an extra "0" displayed for the score so it looks like 500. As long as none of the scores are single digits, this should work fine. If you now think uninitialized variables might be the culprit, could you not try putting the scores back to long type? Quote Link to comment Share on other sites More sharing options...
Kiwi Posted March 13, 2015 Share Posted March 13, 2015 Long type variable are 32-bit variable right? I think it is a bit too much for the 8-bit z80 processor to handle. Quote Link to comment Share on other sites More sharing options...
Pixelboy Posted March 13, 2015 Share Posted March 13, 2015 Long type variable are 32-bit variable right? I think it is a bit too much for the 8-bit z80 processor to handle. Technically, the Z80 can handle integers of any length, it's just a question of giving it enough time to do the required calculations. Quote Link to comment Share on other sites More sharing options...
parkfun101 Posted March 13, 2015 Author Share Posted March 13, 2015 I actually do think that it was a combination of using the long datatype and having uninitialized variables. It's not like I just have the score variable, I also had a variable for storing each score for all of the modes which were all stored as long. This is so on the Title screen when you are selecting the modes, so you can see what the different scores and hiscores are. Tarzilla, you would probably have to play for several hours without having to continue in order to get even a 6 digit score. That would be extremely difficult due to the randomness of the game with the teleports and A.I. design. I do have it setup to use my "Faked" 6 digit score method where 0 is more like a placeholder so visually if you destroy a bike you get 500pts., however, in code, you are only getting 50pts. This allows me to avoid using the long datatype and still get a 6 digit score. I tried this yesterday and it worked great. Another note about taking out the long datatype. After doing this, it gave me over 2,000 bytes back because I had all of those long variables. That means I could add either 20+ more levels than originally planned or put that into more sounds, graphics etc. All this because I took out the long datatype for those variables. From a gamer's point of view, I would prefer more levels rather 1 extra digit score, don't you agree? I also have a feeling that if I use the long datatype I will still have the issue I was having before and nobody wants to go for a hiscore and then have the game freeze up on them. Quote Link to comment Share on other sites More sharing options...
parkfun101 Posted March 13, 2015 Author Share Posted March 13, 2015 As a test, I went back to my older version of the game that still had the long variables. I initialized all the variables and ran the test and the game would indeed black out or freeze at the 85 level mark. So long variables were the main culprit here. Perhaps the Z80 can't handle long variables so well. Also a note, long variables are not in the documentation for creating Colecovision games by Daniel Bienvenu. He also warns not to use floating point variables. Perhaps there should be a similar warning for using the long datatype. Quote Link to comment Share on other sites More sharing options...
NIAD Posted March 13, 2015 Share Posted March 13, 2015 I vote for added sounds and enhanced graphics over more levels especially seeing how many levels are already in the game. 1 Quote Link to comment Share on other sites More sharing options...
+Tarzilla Posted March 13, 2015 Share Posted March 13, 2015 As a test, I went back to my older version of the game that still had the long variables. I initialized all the variables and ran the test and the game would indeed black out or freeze at the 85 level mark. So long variables were the main culprit here. Perhaps the Z80 can't handle long variables so well. Also a note, long variables are not in the documentation for creating Colecovision games by Daniel Bienvenu. He also warns not to use floating point variables. Perhaps there should be a similar warning for using the long datatype. Good to know, I've made a personal not to use long or float. Quote Link to comment Share on other sites More sharing options...
+Tarzilla Posted March 13, 2015 Share Posted March 13, 2015 I actually do think that it was a combination of using the long datatype and having uninitialized variables. It's not like I just have the score variable, I also had a variable for storing each score for all of the modes which were all stored as long. This is so on the Title screen when you are selecting the modes, so you can see what the different scores and hiscores are. Tarzilla, you would probably have to play for several hours without having to continue in order to get even a 6 digit score. That would be extremely difficult due to the randomness of the game with the teleports and A.I. design. I do have it setup to use my "Faked" 6 digit score method where 0 is more like a placeholder so visually if you destroy a bike you get 500pts., however, in code, you are only getting 50pts. This allows me to avoid using the long datatype and still get a 6 digit score. I tried this yesterday and it worked great. Another note about taking out the long datatype. After doing this, it gave me over 2,000 bytes back because I had all of those long variables. That means I could add either 20+ more levels than originally planned or put that into more sounds, graphics etc. All this because I took out the long datatype for those variables. From a gamer's point of view, I would prefer more levels rather 1 extra digit score, don't you agree? I also have a feeling that if I use the long datatype I will still have the issue I was having before and nobody wants to go for a hiscore and then have the game freeze up on them. I vote for using the reclaimed space for some of the extra obstacles we discussed. I use the same fake 0 at the end of the score in my Intellivision games. I also experimented with using two integers. Simplistic Pseudo code Player1Tens=0 Player1Thousands=0 Player1Tens=Player1Tens+500 If Player1Tens>10000 then Player1Thousands=Player1Thousands+1 Player1Tens=Player1Tens-10000 End if Print Player1Thousands,Player1Tens Quote Link to comment Share on other sites More sharing options...
parkfun101 Posted March 13, 2015 Author Share Posted March 13, 2015 That's cool that other people have used that idea. It's probably in a bunch of 80's games and we think we were the first ones to think of it. Quote Link to comment Share on other sites More sharing options...
Kiwi Posted March 13, 2015 Share Posted March 13, 2015 I usually have an array of bytes that holds the digits of the scores. If I want a 6 digits score, I can do byte digits[6]. To add to the score, I do digits[4]++; and then do a addscore routine that checks if that digit is more than 10 then increase digits[3]++ then subtract digits[4] by 10. I display the score using the put_char(x,y,digits[0]+48); to put_char(x+5,y,digits[5]+48); Spunky's Supercar and PONG uses this routine. I think this is easier on the z80 processor to do this method and can have longer score value if you wish. Only draw back, high score comparison is a bit hard to figure out to do. Quote Link to comment Share on other sites More sharing options...
parkfun101 Posted March 13, 2015 Author Share Posted March 13, 2015 Here is the modified code I'm using for Light Grid Racing formerly Light Cycle Racing (changed due to trademarked name "Light Cycle"). ----------------------------------//Used for score or points up to 6 digits - Right Aligned//Ex: PrintInt(8,7, 3, 1);//NOTE: When using Fake6Digit, the 1's digit will always be 0 so don't expect to display 1-9, use Fake6Digit = 0 for that.void PrintInt(byte x, byte y, int L, byte Fake6Digit){ byte digits; char* s = str(L); digits = 1; if (L >= 10000) digits = 5; if (L <= 9999) digits = 4; if (L <= 999) digits = 3; if (L <= 99) digits = 2; if (L <= 9) digits = 1; if (Fake6Digit==1){ print_at(x, y, "0"); //Fakes 6 digits by starting with a 0 if (digits > 1){ print_at(x-digits, y, &s[5-digits]); } } else { //Just display a regular 5 digit number x=x+1; print_at(x-digits, y, &s[5-digits]); }}//PrintInt ---------------------------------- If you want a level select from 1-10 you could do like PrintInt (0,0, 1, 0); //Don't display the Fake 6th Digit If you want to have the 6th digit available for a score or something PrintInt (0,0, SCOREP1, 1); //Allow up to 6 digits. You could just use str(SCOREP1), but that prints the score like this 00005, I'd rather it just be 5. Again, my code works fine unless you need to put a value other than 0 in the 1st digit's place. Another good thing about this method is that it doesn't need to call any special header files besides the ones you are probably using for the game anyhow. I had made some others that did and it really added to the filesize due to the functions I was calling. That is why I'm not using any str_len() type functions so I can avoid having to use the string.h include file. I'm sure this could be tweaked so if the value is < 10, to automatically skip the printing of the "0"....Hey, I like that, I might change that so you don't have to specify whether or not to fake the digit, it will just figure it out on its own. Quote Link to comment Share on other sites More sharing options...
parkfun101 Posted March 15, 2015 Author Share Posted March 15, 2015 I'm at a loss right now. The game Black Out issue has never really been fixed. Sometimes, using my cheat test (pressing 3, 4, and 5 to destroy enemy bikes), I can get to level 93, sometimes 87, etc. When I try to play the game normally, the level number is usually around 63 or so before it blacks out . I've changed a bunch of variables to byte and tried commenting out 1 or 2 functions at a time and then playing again to see if I can get any further. If this continues, the only way I could release this game is to perhaps remove the Continue feature so you can't easily get to those levels numbers....it would be VERY difficult to get that far ....even to level 40. I would also have to force the user to press the RESET button on the game console so they can refresh everything, otherwise, you may continue and the game could freeze in the first few rounds. If anyone wants to take a look at my code, please PM me, I've been working on this issue since 2 Fridays ago and I've given up trying to figure out this issue. Hopefully, this is just something stupid that I've missed, otherwise, this will be my last Colecovision game I work on. Quote Link to comment Share on other sites More sharing options...
+Tarzilla Posted March 15, 2015 Share Posted March 15, 2015 I'm sure you'll get a couple of people offering to help. No one should be pressuring you to release it so take a break. A fresh pair of eyes and a break can do wonders. I had a logic issue in a game I worked on all fall I parked it, worked on another. When I went back to it I had forgotten enough that as I was refamiliarizing myself my problem jumped right out at me. This game is one of the best homebrews (for any system) in the last while. Hang in there. You'll figure it out. Quote Link to comment Share on other sites More sharing options...
Pixelboy Posted March 15, 2015 Share Posted March 15, 2015 Are you testing your game on real hardware only? Does the problem occur under emulation as well? Quote Link to comment Share on other sites More sharing options...
parkfun101 Posted March 15, 2015 Author Share Posted March 15, 2015 Well, I've worked on a bunch of games in Klik N Play, The Games Factory, VB5, a few in .Net, and I've never had an issue like this before. Tank Challenge was a bit different because we could play that for a good 45 minutes, there could have been a Black Out issue with that, but if it did happen, it was after the match and you weren't trying to go for a high score, so it wouldn't have been noticeable. Worst case, I can always remove the Continue feature. You'd still be able to play against a friend in 1P vs 2P mode on any level. If I resort to removing the Continue feature, I may add an option to start off at a certain area so you can play against the CPU on the higher areas. The area number doesn't seem to be the problem....I only have 10 levels right now that just repeat. I thought maybe it had to do with redisplaying the level, but the 1P vs 2P mode lets you preview the level before you play it (like Tank Challenge). I tried that and I could NEVER get that to fail, so that's not the issue.I love working on these games, it is very challenging. I'm just stuck on this issue. Quote Link to comment Share on other sites More sharing options...
parkfun101 Posted March 15, 2015 Author Share Posted March 15, 2015 Are you testing your game on real hardware only? Does the problem occur under emulation as well? I'm testing using BlueMSX. I haven't tested this issue on a CV yet since I wanted to try to fix the issue first. Quote Link to comment Share on other sites More sharing options...
parkfun101 Posted March 15, 2015 Author Share Posted March 15, 2015 I think what might be good to have, for any Colecovision programmer, would be a list of What NOT to do when making CV games. That way if you get an issue, you could check the list to make sure you're not doing that. Quote Link to comment Share on other sites More sharing options...
Pixelboy Posted March 15, 2015 Share Posted March 15, 2015 I'm testing using BlueMSX. I haven't tested this issue on a CV yet since I wanted to try to fix the issue first. If you can reproduce this bug in blueMSX, have you been able to see which part of the code is running in circles when the game freezes, via the debugger? Quote Link to comment Share on other sites More sharing options...
Kiwi Posted March 15, 2015 Share Posted March 15, 2015 See if your functions are returning to the main program.You might have forgotton to put } or put a goto in it to jump back to another function. I had this issue with Computer Space where I forgot to put a } in one of the function. I think the next function code after it made it return back to the program. It would bug out once I put more and more stuff into that program. I'm thinking there might be a stack overflow in this game. Quote Link to comment Share on other sites More sharing options...
+Tarzilla Posted March 15, 2015 Share Posted March 15, 2015 Another question is, what are using using for a code editor? A good C aware editor like Brackets will also help find issues like missing } thanks to it having syntax hi-lighting. I also second the use of BlueMSXs debugger, it should help trace where the black screen is coming from. Quote Link to comment Share on other sites More sharing options...
parkfun101 Posted March 15, 2015 Author Share Posted March 15, 2015 The CCI3 compiler seems to catch all of the syntax issues like missing brackets. I use Notepad++ to do all my code. It's free and has very nice features like I can highlight a word and it highlights that same word throughout the code. It also color codes things like ifs and for loops, etc. Notepad++ is great for missing brackets since you can highlight the starting or ending bracket and it highlights the opposite bracket for you. We even use this at work. Oh, I don't use goto statements in my code, I just use function calls with return values. Pixelboy, I've never actually used the Debugger in BlueMSX before. I'm going to have to try that. If you have any tips on using it, feel free to share. Quote Link to comment Share on other sites More sharing options...
Pixelboy Posted March 15, 2015 Share Posted March 15, 2015 Pixelboy, I've never actually used the Debugger in BlueMSX before. I'm going to have to try that. If you have any tips on using it, feel free to share. I've never used it either sorry... But once I learn Z80 assembly, I'm sure I'll get around to using it, eventually. Quote Link to comment Share on other sites More sharing options...
+Tarzilla Posted March 15, 2015 Share Posted March 15, 2015 The CCI3 compiler seems to catch all of the syntax issues like missing brackets. I use Notepad++ to do all my code. It's free and has very nice features like I can highlight a word and it highlights that same word throughout the code. It also color codes things like ifs and for loops, etc. Notepad++ is great for missing brackets since you can highlight the starting or ending bracket and it highlights the opposite bracket for you. We even use this at work. Oh, I don't use goto statements in my code, I just use function calls with return values. Pixelboy, I've never actually used the Debugger in BlueMSX before. I'm going to have to try that. If you have any tips on using it, feel free to share. I actually use Notepad ++ myself, I was just introduced to Brackets at a recent conference. Free and much more robust than Notepad ++ and has better support for specific languages and themes for color coding. 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.