[stella] Abusing JSR and BRK

Subject: [stella] Abusing JSR and BRK
From: Christopher Tumber <christophertumber@xxxxxxxxxx>
Date: Tue, 08 Jul 2003 18:30:48 -0400
I was reading through Atari Age and came accross a post from Thomas. It's from a while ago and was an aside in a thread so thought I'd bring it up here.

Thomas wrote:

>BTW: To feed two continous registers as fast a possible (only 6 cycles) you can abuse JSR (stack points at those registers). And 3 registers with BRK (7 cycles). Still not fast enough for hires graphics, but better than nothing. 

Okay, I'm a sucker for this kind of stuff. So how do you propose it would work? It's cool as hell, but I can't see how we could derive any benefit from it. For example:

   ldx #GRP1    ;2
   txs          ;2
   jsr wherever ;6

Will put PC-1 into GRP1 and GRP0, however, our options with respect to setting PC to an arbitrary value are rather limited. Now this was part of a conversation about a super-cart with an onboard microcontroller creating code on the fly, so we could maybe have something like this:

  jmp value    ;3
value:
   ldx #GRP1    ;2
   txs          ;2
   jsr wherever ;6

That's 13 cycles to set 2 registers. Hardly a bargain.

If we're doing it in order to say keep changing two colour registers

  jmp value    ;3
value:
   ldx #COLUP1    ;2
   txs            ;2
   jsr value2   ;6
value2:
   ldx #COLUP1    ;2
   txs            ;2
   jsr value3   ;6
value3:
   ldx #COLUP1    ;2
   txs            ;2
   jsr done   ;6

That's still, at best 10 cycles per 2 register writes. Which is no better than:

  lda #10
  sta COLUP0
  lda #20
  sta COLUP1
  <repeated>

Except that abusing jsr seems a lot more awkward.


Now maybe if we went through a sequence of several registers, it might become usefull:

  jmp value    ;3
value:
   ldx #PF2    ;2
   txs            ;2
   jsr value2   ;6
value2:
   jsr value3   ;6
value3:
   jsr value4   ;6
value4:
   jsr value5   ;6
value5:
   jsr value6   ;6
value6:
   jsr done   ;6

Which writes all registers from NUSIZ1 to PF2 quite quickly. Except how often do you really need to change CTRLPF, REFP0, REFP1 and NUSIZ1 mid-scanline?

The only possibly usefull version I can come up with is:

  jmp value    ;3
value:
   ldx #COLUBK    ;2
   txs            ;2
   jsr value2   ;6
value2:
   jsr done   ;6

Which writes all 4 colour registers in 19 cycles, which saves 1 cycle over:

   lda #10
   sta COLUP0
   lda #10
   sta COLUP1
   lda #10
   sta COLUPF
   lda #10
   sta COLUBK


Using BRK may add some efficiency given that it could be used to affect 3 registers in 7 cycles, but, there's going to be added overhead in setting the processor flags, which are awkward to set directly (PLP?)


Soooo.. Am I missing something here? Even given the (magical) ability to have code appear for us wherever we set the program counter to, I don't see how this is of any real benefit.

Or maybe I'm missing the forest for the trees. Maybe you'd just use this as a one-shot "burst mode" to change two registers really quickly. Hmm, say by squeezing in a change to COLUP0 and COLUP1 in the middle of the 6-digit display (doing all the set-up overhead beforehand where it doesn't matter). Or something similar

Or something else???


Chris...

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


Current Thread