The21zonz Posted September 7 Share Posted September 7 Whenever I use gosub it messes up my Atari screen! What do I do? Quote Link to comment Share on other sites More sharing options...
The21zonz Posted September 7 Author Share Posted September 7 Oh yeah, this is an NTSC rom. Quote Link to comment Share on other sites More sharing options...
r_chase Posted September 7 Share Posted September 7 How's that Kirby-like platformer coming along? It's been awhile since you posted anything about any of your projects. Quote Link to comment Share on other sites More sharing options...
The21zonz Posted September 7 Author Share Posted September 7 2 hours ago, r_chase said: How's that Kirby-like platformer coming along? It's been awhile since you posted anything about any of your projects. I’ve been busy… Quote Link to comment Share on other sites More sharing options...
LatchKeyKid Posted September 7 Share Posted September 7 (edited) Are you gosubing to another bank? Something similar happened with me the first time I did that by mistake without properly addressing which one. https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#bankswitching The proper way is detailed in the sidebar. Edited September 7 by LatchKeyKid Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted September 7 Share Posted September 7 I used to lean heavily on GOSUB and would run out of CPU time and roll the screen. Once you get really dangerous with bB game making you'll find other reasons to avoid GOSUB use. Currently I'm re-learning not to use GOSUBs the hard way. Just say no to GOSUBs. 1 Quote Link to comment Share on other sites More sharing options...
The21zonz Posted September 8 Author Share Posted September 8 14 hours ago, Gemintronic said: I used to lean heavily on GOSUB and would run out of CPU time and roll the screen. Once you get really dangerous with bB game making you'll find other reasons to avoid GOSUB use. Currently I'm re-learning not to use GOSUBs the hard way. Just say no to GOSUBs. How else do I clean up my code? Quote Link to comment Share on other sites More sharing options...
The21zonz Posted September 8 Author Share Posted September 8 15 hours ago, LatchKeyKid said: Are you gosubing to another bank? Something similar happened with me the first time I did that by mistake without properly addressing which one. https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#bankswitching The proper way is detailed in the sidebar. No. This is within the same bank Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 8 Share Posted September 8 16 hours ago, The21zonz said: How else do I clean up my code? It says this on the bB page: "But you should avoid using gosub in cases where it really isn't necessary, such as if the code in the subroutine is only called from one spot, or if the subroutine is so short that it would actually be more efficient to just duplicate that code wherever it's needed." Here is info about cycles and gosub: gosub + return = 12 cycles Here is info about cycles and goto: goto = 3 cycles Seems like a lot of new programmers will turn their code into tangled spaghetti by using gosub a billion times for no good reason. I treat gosub like it's radioactive. I only use it when I absolutely have to. When multiple areas of the program need to use the same large chunk of code, you basically have to use gosub to save space. I don't usually have a large chunk of code that needs to be used by multiple areas of a program, so I can avoid gosub most of the time. I learned an if…then trick from batari years ago. It's in the section called Relief for ENDIF Addicts. You keep a chunk of code between an if…then and a label. You can have multiple lines of code all contained in that if…then/label area. You can think of it as little packages of code. You just have a bunch of if…then/label packages instead of using gosub a billion times, so you end up saving cycles. I just updated the bB page with an adapted version of this post: https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#poap_subroutines You might need to refresh/reload the page for the changes to show up. 3 Quote Link to comment Share on other sites More sharing options...
+Gemintronic Posted September 9 Share Posted September 9 23 hours ago, The21zonz said: How else do I clean up my code? It's a matter of personal style. But, not using GOSUBs can force you to organize your code better. Here is something I may have used a GOSUB for before: main counter = counter + 1 : if counter = 255 then supercounter = supercounter + 1 temp2 = read_playtime : if temp2 > 0 then goto sound_event after_sound_event I deal with sound effects in one particular place in my main loop. So, I always return to immediately after this sound event code. Simple to debug. Less tempted to call the sound code from many places many more times. Game assets are stashed away in the last bank anyway. So, instead of GOSUB'ing to a fancy draw_playerbobo routine I just assign the sprite the first place I need it. Usually just before starting the main loop. main_begin lives = 160 statusbarlength = 194 lifecolor = _white rem //** Draggin C **// NUSIZ5 = $05 player5: %00111110 %11111101 %10001100 %10000110 %01111100 %00000110 %00111110 %00000111 %10101011 %11111111 %01011010 %00110110 end main 2 Quote Link to comment Share on other sites More sharing options...
The21zonz Posted September 13 Author Share Posted September 13 On 9/9/2024 at 12:52 AM, Random Terrain said: It says this on the bB page: "But you should avoid using gosub in cases where it really isn't necessary, such as if the code in the subroutine is only called from one spot, or if the subroutine is so short that it would actually be more efficient to just duplicate that code wherever it's needed." Here is info about cycles and gosub: gosub + return = 12 cycles Here is info about cycles and goto: goto = 3 cycles Seems like a lot of new programmers will turn their code into tangled spaghetti by using gosub a billion times for no good reason. I treat gosub like it's radioactive. I only use it when I absolutely have to. When multiple areas of the program need to use the same large chunk of code, you basically have to use gosub to save space. I don't usually have a large chunk of code that needs to be used by multiple areas of a program, so I can avoid gosub most of the time. I learned an if…then trick from batari years ago. It's in the section called Relief for ENDIF Addicts. You keep a chunk of code between an if…then and a label. You can have multiple lines of code all contained in that if…then/label area. You can think of it as little packages of code. You just have a bunch of if…then/label packages instead of using gosub a billion times, so you end up saving cycles. I just updated the bB page with an adapted version of this post: https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#poap_subroutines You might need to refresh/reload the page for the changes to show up. Guess I was doing a lot. (I only used GOSUB once!) 2 Quote Link to comment Share on other sites More sharing options...
Koji Kabuto Posted September 15 Share Posted September 15 On 9/8/2024 at 6:52 PM, Random Terrain said: It says this on the bB page: "But you should avoid using gosub in cases where it really isn't necessary, such as if the code in the subroutine is only called from one spot, or if the subroutine is so short that it would actually be more efficient to just duplicate that code wherever it's needed." Here is info about cycles and gosub: gosub + return = 12 cycles Here is info about cycles and goto: goto = 3 cycles Seems like a lot of new programmers will turn their code into tangled spaghetti by using gosub a billion times for no good reason. I treat gosub like it's radioactive. I only use it when I absolutely have to. When multiple areas of the program need to use the same large chunk of code, you basically have to use gosub to save space. I don't usually have a large chunk of code that needs to be used by multiple areas of a program, so I can avoid gosub most of the time. I learned an if…then trick from batari years ago. It's in the section called Relief for ENDIF Addicts. You keep a chunk of code between an if…then and a label. You can have multiple lines of code all contained in that if…then/label area. You can think of it as little packages of code. You just have a bunch of if…then/label packages instead of using gosub a billion times, so you end up saving cycles. I just updated the bB page with an adapted version of this post: https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#poap_subroutines You might need to refresh/reload the page for the changes to show up. Thanks for that explanation of the cycles, it's great to know that you can't abuse the GOSUBs and aim more at the GOTO, I'm having just problems with a sound and I think that's why, more or less what @Gemintronic wrote in his post.👌 1 Quote Link to comment Share on other sites More sharing options...
+Karl G Posted September 15 Share Posted September 15 gosub is extremely handy for structured programming, and saving on code size. The important part is not forgetting to return (this can happen if you might have a conditional goto that ends up skipping the return), or having too many levels of gosubs, which uses up RAM and could cause corruption. I would recommend never going over two levels of gosubs at any time. Quote Link to comment Share on other sites More sharing options...
Koji Kabuto Posted September 15 Share Posted September 15 Thanks Karl, and yes definitely the GOSUB with code in other banks is very useful both to use bytes from other banks and to structure the program and not have horrible spaghetti code hahahaha. 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.