Sendraz Posted July 9, 2020 Share Posted July 9, 2020 Hello, i'm trying to make a 4 digit playfield score. I know it's probably not the best way to do this, but it's more difficult for me to make it as player sprite. While my code works, it looks like the every second line on playfield is missing, i tried to fix this myself, but i can't do that. So i decided to ask here if somebody can help me. This is my score rendering loop code: ldx #8 ScoreLoop: txa pha pha pha .DrawScoreOnes: adc Digit1Offset tay lda DigitsReversed,y and #$F0 sta temp .DrawScoreHund: pla adc Digit3Offset tay lda Digits,y and #$0F sta temp2 .DrawScoreThous: pla adc Digit4Offset tay lda Digits,y and #$F0 ora temp2 sta WSYNC sta PF1 .DrawScoreTens: pla adc Digit2Offset tay lda DigitsReversed,y and #$0F ora temp sta PF2 sleep 20 lda #0 sta PF1 sta PF2 dex bne ScoreLoop Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted July 9, 2020 Share Posted July 9, 2020 Its very important to put cycle counts in your kernel. Notation I use is optional_label: instruction ; c t where c = cycles for that instruction and t = total so far for the 76 cycle scanline. A new scanline starts whenever you sta WSYNC or when you go past 76 like the lda DigitsReversed,y which ends on cycle 1 of the next scanline. ldx #8 ; 2 ?? ScoreLoop: ; - 57 from bne ScoreLoop txa ; 2 59 pha ; 3 62 pha ; 3 65 pha ; 3 68 .DrawScoreOnes: adc Digit1Offset ; 3 71 assuming in RAM tay ; 2 73 lda DigitsReversed,y ; 4 77/1 ;---------------- start of new scanline and #$F0 ; 2 2 sta temp ; 3 5 .DrawScoreHund: pla ; 4 9 adc Digit3Offset ; 3 12 assuming in RAM tay ; 2 14 lda Digits,y ; 4 18 and #$0F ; 2 20 sta temp2 ; 3 23 .DrawScoreThous: pla ; 4 27 adc Digit4Offset ; 3 30 assuming in RAM tay ; 2 32 lda Digits,y ; 4 36 and #$F0 ; 2 38 ora temp2 ; 3 40 sta WSYNC ; 3 43/0 ;---------------- start of new scanline sta PF1 ; 3 3 .DrawScoreTens: pla ; 4 7 adc Digit2Offset ; 3 10 assuming in RAM tay ; 2 12 lda DigitsReversed,y ; 4 16 and #$0F ; 2 18 ora temp ; 3 21 sta PF2 ; 3 24 sleep 20 ;20 44 lda #0 ; 2 46 sta PF1 ; 3 49 sta PF2 ; 3 52 dex ; 2 54 bne ScoreLoop ; 2 56, 3 57 when taken 1 Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted July 9, 2020 Share Posted July 9, 2020 Check this topic for more info: Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted July 9, 2020 Share Posted July 9, 2020 You can use the Stella debugger to count cycles between two points, too. Put a breakpoint on the first, another breakpoint on the second. Run to the first. Run to the second. The "Delta" value is the # cycles between them. Very useful for timing whole blocks of code. Quote Link to comment Share on other sites More sharing options...
CapitanClassic Posted July 9, 2020 Share Posted July 9, 2020 There is a doc for the debugger here https://stella-emu.github.io/docs/debugger.html#HowToDebugger Quote Link to comment Share on other sites More sharing options...
Sendraz Posted July 17, 2020 Author Share Posted July 17, 2020 But how can i make the code shorter? Is there a way to make my code use less clock cycles? Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted July 17, 2020 Share Posted July 17, 2020 1 hour ago, Sendraz said: But how can i make the code shorter? Is there a way to make my code use less clock cycles? Indeed. That's pretty much what programming the '2600 is about. As you build your experience, understanding, and skills, you will find ways to make things harder, better, faster... stronger There's no easy answer to your question. Move any calculations outside of the draw loop. Use lookup tables where possible. Use faster code. Unroll your loops. Unroll your loops again. That last one is the best... looping during screen draws is costly. These are the challenges that make the machine so interssting. 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.