Jump to content

Photo

Using PLA for sleeping


5 replies to this topic

#1 JeremiahK OFFLINE  

JeremiahK

    Chopper Commander

  • 147 posts
  • Location:Indiana, USA

Posted Tue May 15, 2018 10:12 AM

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.



#2 TheHoboInYourRoom OFFLINE  

TheHoboInYourRoom

    Moonsweeper

  • 366 posts
  • Whackadoo thingamajig
  • Location:Illinois

Posted Tue May 15, 2018 12:12 PM

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



#3 JeremiahK OFFLINE  

JeremiahK

    Chopper Commander

  • Topic Starter
  • 147 posts
  • Location:Indiana, USA

Posted Tue May 15, 2018 12:31 PM

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.

#4 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!, Boulder Dash, THREE·S, Star Castle

  • 23,139 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany, Europe, Earth

Posted Tue May 15, 2018 2:13 PM

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 by Thomas Jentzsch, Tue May 15, 2018 2:14 PM.


#5 DirtyHairy ONLINE  

DirtyHairy

    Moonsweeper

  • 366 posts
  • Location:Germany

Posted Tue May 15, 2018 3:08 PM

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 by DirtyHairy, Tue May 15, 2018 3:14 PM.


#6 JeremiahK OFFLINE  

JeremiahK

    Chopper Commander

  • Topic Starter
  • 147 posts
  • Location:Indiana, USA

Posted Tue May 15, 2018 11:04 PM

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

 

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: :thumbsup: :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 by JeremiahK, Tue May 15, 2018 11:07 PM.





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users