Re: [stella] Re: Programming tricks guide

Subject: Re: [stella] Re: Programming tricks guide
From: Paul Slocum <paul-stella@xxxxxxxxxxxxxx>
Date: Thu, 06 Feb 2003 10:42:33 -0600

How about using the BRK vector? I was listening to Joe Decuir's keynote speech from CGE2K1 this morning and he mentioned using the BRK to avoid using JSR all over the place. It would shave off 3 bytes of ROM!

You mean something a little like this? :o)


==============================================================
BRK SUBROUTINE TRICK
Mark Lesser, Thomas Jentzch
==============================================================

Thomas found this trick in Mark Lesser's Lord of the Rings prototype: You can use BRK to call a subroutine that needs to be called often and save ROM space. If you aren't familiar with BRK, it pushes the flags and PC on the stack and jumps to wherever the vector $FFFE is pointing.

Thomas found BRK commands like this scattered through Lord of the Rings:

    brk
    .byte $0e        ; id-byte
    lda    $e3       ; <- here we will continue
    ora    #$04

And the BRK vector was pointing to this routine:

BrkRoutine:
    plp             ; remove flags from stack (not needed)
    tsx             ; load x with stackpointer
    inx             ; x++
    dec    $00,x    ; adjust return address
    lda    ($00,x)  ; read break-id...
    tay             ; ...and store in y
Subroutine:
    [subroutine code...]
    rts

So it ended up being the equivalent of passing a value to a subroutine similar to this:

   ldy     #value
   jsr     Subroutine

But it saves 3 bytes with each call and the overhead is only 8 bytes.
After only 3 subroutine calls (Lord of the Rings has about 20) you are saving ROM space.


In the case of Lord of the Rings, the subroutine was sound related code that selected the sound effect to be played based on a priority system.



----------------------------------------------------------------------------------------------
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/


Current Thread