Jump to content
IGNORED

refactoring long routines in vbi or overscan


tschak909

Recommended Posts

As can be inevitable while developing a VCS game, I'm finding that some of my routines (particularly the joystick and collision routines) are becoming too big to loop. I've managed to mitigate this by breaking the routines up into functional subroutines, but each JSR/RTS pair takes 13 cycles each time...is there a more sane/better pattern to use?

 

(for background, as I am working on Dodgeball, I am adding a very pivotal play case, the ability for an opponent to catch the other player's ball, so that they can potentially be carrying it, and their own ball...right now, this is involving lots of checking of the opposing ball flags for each player (I copy to a temp var and BIT check it, to try and save some space, oh how I wish BIT had an indexed address mode), and depending on how it's set, to flip my X register (which carries the current player being acted upon) to deal with the opposite player's missile, instead... this quickly creates a big ol' bowl of pasta...and blows up the size of the loop to quickly be too big to branch...)

 

-Thom

Link to comment
Share on other sites

For the interim you can inline it all (macros or no macros) and then check a condition to break the loop with a jump behind it to re-loop.

.loopChecking:

;....code here

    bne .exit
    jmp .loopChecking

.exit:

That's the simple way of handling code blocks which span over half a page. From there it is refactoring until you can use a branch instead of a jump which would save 3 bytes in this case ( you wouldn't need the "bne .exit" or "jmp .loopChecking", just "beq .loopChecking".

 

You will find a lot of times during refactoring that it is possible to move code around so that the branches take less then a page. Something like this:

.earlyBranch:
    ; more code
    
    bne .rejoinRoutine

RoutineEntry:
    ; some code
    bcs .earlyBranch
    
.rejoinRoutine:
    ; remaining code

That works good when you are JSRing to the whole routine.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...