[stella] 1 cycle!

Subject: [stella] 1 cycle!
From: "Fabrizio Zavagli" <rasty@xxxxxxxxx>
Date: Mon, 17 Mar 2003 22:08:58 +0100
Hi everyone!

With Space Treat Deluxe on its way to release, I've resumed work on
"Bounce!" and its crazy kernel :)

First of all, I've definitely realized that using 83 bytes of ram to store
the level data left too little room (I used to copy the level data from ROM
to RAM for a number of reasons), and chose to keep the level data in rom at
all times.
Of course indirect LDAs in rom eat up cycles much faster than indexed
zero-page ones, and since the kernel has no WSYNCs, I have to adjust it
every time.. and ended up with one cycle in excess that I don't seem to be
able to get rid of!

And here here I am in big need for your help!

The sub that I'm trying to get squeezed by 1 machine cycle is called
"NextRow". It has to be 150 cycles in total at the end of its execution,
whatever branches are taken inside of it.. This is because NextRow loads the
pointer data for the next row of sprites and must take exactly 2 scanlines
(minus 2 cycles for the jump to it).
Currently it's 151 :(

So, any idea on saving up cycles in that function is welcome.. I'm willing
to use Illegal/Undocumented opcodes too, if required!

I'm attaching the latest source and binary, and quoting the function at the
end of the message (if you don't have time to read throu all the source :))

Thanks in advance!
Regards,
Fabrizio.-

; We have 2 blank lines minus 2 cycles here for a total of 150 cycles
; ************ MUST REMOVE 1 CYCLE FROM NextRow !!! ***************
NextRow  ; 76 cycles -2 from the jump to here
 DEC RowsNumber ; 5
 BEQ EndScreen ; 2
 LDA #0  ; 2
 STA HMOVE ; 3
 STA COLUP0 ; 3
 STA COLUP1 ; 3

; --- Draw Ball ---
 DEC ScanCount ; 5
 LDA ScanCount ; 3
 SEC  ; 2
 SBC BallY ; 3
 ADC #BALL_HEIGHT; 2
 BCS DrawBall2 ; 2/3
 LDA #0  ; 2
 STA ENABL ; 3
 SLEEP 22
 JMP SkipDrawBall2 ; 3 47
DrawBall2
 LDY BallTabPtr ; 3
 LDA BallSizeTab,Y ; 4
 STA CTRLPF ; 3
 LDA BallEnableTab,Y ; 4
 STA ENABL ; 3
 LDA BallShiftTab,Y ; 4
 STA HMBL ; 3
 DEC BallTabPtr ; 5 ; 47
SkipDrawBall2

; --- Load pointers with next row of level data (62 cycles)
 LDY LevelDataPtr
; Unrolling loop to save some cycles...
 LDA (LevelPtrLo),Y ; 5
 STA ptr0 ; 3
 DEY ; 2
 LDA (LevelPtrLo),Y ; 5
 STA ptr1 ; 3
 DEY ; 2
 LDA (LevelPtrLo),Y ; 5
 STA ptr2 ; 3
 DEY ; 2
 LDA (LevelPtrLo),Y ; 5
 STA ptr3 ; 3
 DEY ; 2
 LDA (LevelPtrLo),Y ; 5
 STA ptr4 ; 3
 DEY ; 2
 LDA (LevelPtrLo),Y ; 5
 STA ptr5 ; 3
 DEY ; 2
 STY LevelDataPtr ; 3
; ---

 LDY #7  ; 2
 STY LoopCount ; 3

 LDA TilesColor,Y ; 4
 LDX ScanNumber ; 3 Next line: tiles or ball?
 BNE BgLine2 ; 2
 BIT $00  ; 3
 JMP NormalLine ; 3 13
BgLine2
 NOP  ; 2+1
 JMP X3  ; 3 13 76

Attachment: balls.bin
Description: Binary data

Attachment: balls_src.zip
Description: Zip compressed data

Current Thread