JeremiahK Posted May 15, 2018 Share Posted May 15, 2018 I'm sure somebody else has been doing this already, but I just thought of it yesterday and wanted to share! I am currently working on the menu kernel for my game, and I had a "SLEEP 19" in the kernel. (I honestly can't believe I have that much wiggle room, but that is during the simplest point of the kernel!). Since here, SLEEP just inserts 8 NOP's and a "NOP 0" or "BIT VSYNC", that is 10 bytes of ROM. Of course, for longer sleep durations, you could set up a BNE loop, but I am using both index registers at this point. Instead, I am just using PLA, since I am not using the stack pointer. Since you are not writing to the stack, there is no danger of corrupting your TIA registers or any RAM. It uses 4 cycles, and only 1 byte of ROM, allowing me to save 4 bytes of ROM. Plus I am using it again later to save another single byte of ROM. Of course, when I have to reset the stack, it will take another 3 bytes, so it doesn't save much in this case, but it can surely be helpful if you need it. Quote Link to comment Share on other sites More sharing options...
TheHoboInYourRoom Posted May 15, 2018 Share Posted May 15, 2018 The Atari 2600 Advanced Programming Guide on the MiniDig has a nice section "Wasting Cycles" that describes compact ways of wasting between 1 and 12 cycles. It might be useful for you in the future. 1 Quote Link to comment Share on other sites More sharing options...
JeremiahK Posted May 15, 2018 Author Share Posted May 15, 2018 I love that guide, lots of handy stuff in there. It never mentions using PLA without a PHA, though, so I thought I would make a post about it. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted May 15, 2018 Share Posted May 15, 2018 (edited) It never mentions using PLA without a PHA, though, so I thought I would make a post about it.Yea, most programmers like to keep the stack pointer intact. Edited May 15, 2018 by Thomas Jentzsch Quote Link to comment Share on other sites More sharing options...
DirtyHairy Posted May 15, 2018 Share Posted May 15, 2018 (edited) Provided you have a RTS sticking around somewhere, you can use JSR to waste 12 cycles with three bytes; that’s four cycles per byte, too, but without messing up your stack Edited May 15, 2018 by DirtyHairy Quote Link to comment Share on other sites More sharing options...
JeremiahK Posted May 16, 2018 Author Share Posted May 16, 2018 (edited) Yea, most programmers like to keep the stack pointer intact. Yep. As I said, this only works if the situation allows, and you would need to reset the stack pointer afterwards. It's one of those ugly methods that is a terrible idea, but works well if you know what you're doing, which fits right in to the craziness of 2600 programming. Provided you have a RTS sticking around somewhere, you can use JSR to waste 12 cycles with three bytes; that’s four cycles per byte, too, but without messing up your stack :thumbsup: Another idea I've had that I've never actually used would be something like this: Sleep48 jsr Sleep12 ; sleep 12 cycles, then continue Sleep36 jsr Sleep12 ; sleep 12 cycles, then continue Sleep24 jsr Sleep12 ; sleep 12 cycles, then continue Sleep12 rts This would have to be its own subroutine, rather than just using the end of another one. It would probably almost never be worth using in actual code, unless you were writing a kernel that needed a ton of long SLEEP durations that couldn't be done with loops. But that seems unlikely, since usually you have the opposite problem of not having enough cycles. Edited May 16, 2018 by JeremiahK Quote Link to comment Share on other sites More sharing options...
JeremiahK Posted May 22, 2018 Author Share Posted May 22, 2018 It never mentions using PLA without a PHA, though, so I thought I would make a post about it. Took a closer look, turns out I was wrong, it does mention it: "You can use PHA/PHP (1 byte 3 cycles) or PLA/PLP (1 byte 4 cycles) alone but you have to be carefull not to mess up your stack (PLP/PHA would be usefull if you have no stack!" Quote Link to comment Share on other sites More sharing options...
Kiwi Posted May 22, 2018 Share Posted May 22, 2018 Yeah, if you have subroutines. It automatically push and pull from the stack. I have used 2 pla and a rts to avoid going back to the original sender, but to go back to the main game loop when it was 2 level deep. 2 Quote Link to comment Share on other sites More sharing options...
TheHoboInYourRoom Posted May 22, 2018 Share Posted May 22, 2018 Yeah, if you have subroutines. It automatically push and pull from the stack. I have used 2 pla and a rts to avoid going back to the original sender, but to go back to the main game loop when it was 2 level deep. Oh my gosh, that never occurred to me. That cracks the puzzle of one of my projects. Thank you! 1 Quote Link to comment Share on other sites More sharing options...
Sheddy Posted May 22, 2018 Share Posted May 22, 2018 If you're pla/plp ing the stack often enough for it to be worth it, you can always save the stack pointer first. It's not like the stack data dissappears by doing a pla/plp (but careful with any pha/php then!) 1 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.