Jump to content
IGNORED

Clever or interesting uses of the BRK instruction?


AkashicRecord

Recommended Posts

It can be used for calling a subroutine with an argument. The BRK instruction takes an extra padding byte after the instruction. References frequently list BRK as being a 1 byte instruction, but it actually uses 2 bytes. I'm using it in my game for a generalized way to call subroutines in other banks with 1 byte argument.

 

It can be used to quickly strobe two bytes on RESx. That's also mentioned in the link above.

 

It can also be used to implement cooperative multi-tasking by placing task switching code in the interrupt handler.

  • Like 3
Link to comment
Share on other sites

That's exactly along the lines of how I thought it could be utilized. The sound driver code example in the link is certainly interesting as well.

 

Nice to see you back on here, Akashic. :waving: Have you had any time to work on your Tetris game lately? I used to enjoy reading your postings on that thread even though I'm not that technically-minded (it always made me feel smarter when I understood a little of it. :dunce:)

  • Like 1
Link to comment
Share on other sites

Nice to see you back on here, Akashic. :waving: Have you had any time to work on your Tetris game lately? I used to enjoy reading your postings on that thread even though I'm not that technically-minded (it always made me feel smarter when I understood a little of it. :dunce:)

Thanks!

 

Yep, I'm back to developing it (as of just a few days ago.)

 

I'll be updating it's main thread in the near future. :)

  • Like 2
Link to comment
Share on other sites

It can be used for calling a subroutine with an argument.

 

 

Wow! I'm new-ish at this stuff, and that's the first time I've seen the "cookbook" at that link. There's some seriously great stuff there.

 

It looks like there were more ideas planned that were yet-to-be collected in it. Did it ever get finished or more fleshed-out?

Link to comment
Share on other sites

 

Hi Joe, I went here:

 

http://atariage.com/forums/topic/195210-very-early-wip-of-something-ive-been-working-on-for-ages/?p=2482601

 

And it says something about this being used to have more than one color per line on a sprite. Would that eat up a lot of memory resources and/or increase flicker? I ask because there is a homebrew game currently in development that this might possibly be useful for. Thanks!

Link to comment
Share on other sites

It can be used for calling a subroutine with an argument. The BRK instruction takes an extra padding byte after the instruction. References frequently list BRK as being a 1 byte instruction, but it actually uses 2 bytes. I'm using it in my game for a generalized way to call subroutines in other banks with 1 byte argument.

I was just listening to the "Stella at 20" interviews yesterday, and I believe I heard Joe Decuir mentioning using the BRK vector to replace JSR calls in order to save like 3 or 4 bytes in order to get under 2K at some point...

Link to comment
Share on other sites

I was experimenting with BRK this evening by pointing the IRQ vector to RIOT RAM and setting the stack pointer over COLUPF and then fixing up a 16-bit pointer in RAM (following a JMP instruction) to function as a sort of faux RTS for the BRK. I see some possible use for this, even though it is somewhat limiting. Changing 3 colors in 7 cycles is kind of sweet. :) Adding 3 cycles for the RAM JMP is still 5-8 cycles less than "standard" color changes.

Edited by AkashicRecord
Link to comment
Share on other sites

  • 2 weeks later...

I thought of an implementation where the stack would be set to point to HMOVE preceding a BRK.

 

In this case, both RESMP0 and RESMP1 would also be written to during the 7 cycles. Setting the SP to point to ENABL afterward would allow a following BRK to reenable the ball and missiles. (This same trick could also be used to disable the ball and missiles by BRKing over ENABL...)

 

Of course, certain bits / flags have to be set or cleared for these things to be possible.

 

I also wonder how the timing of HMOVE is affected here, because the timing of the strobed write should be at least 2/3rds of a cycle faster(?) via BRK rather than via STA.

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