Hornpipe2 Posted April 11, 2008 Share Posted April 11, 2008 (edited) Very pretentious title for a (should be) simple concept. My two players can choose their color from 8 available by hitting left and right at the menu screen. If the player moves too far left or right, they are wrapped to the other side. If the player attempts to choose the same color as what the other player is currently sitting on, it should skip and move to the next available. Here's an example: P0 0 1 2 3 4 5 6 7 P1 Here, P0 pushing 'left' should set his color to 7. Pushing Right should make him 2 since P1 is currently occupying 1. P1 'left' should skip 0 and set P1 to 7. P1 'right' sets P1 to 2. A's value must be the same before and after the block, so save it before any changes. Y contains #15 and if used will need to be restored at the end (e.g. LDY #15) Lots of free RAM, and cycles aren't as important here as saving ROM bytes. Here's the best I can do for when P1 pushes 'left': PHA DEC P1Color LDA P1Color AND #%00000111 CMP P0Color BNE SaveP1 DEC P1Color LDA P1Color AND #%00000111 SaveP1 STA P1Color PLA Edited April 11, 2008 by Hornpipe2 Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted April 11, 2008 Share Posted April 11, 2008 A and Y must be the same before and after the block. I don't understand what you mean by that. Copy A to Y after the routine, or restore A from Y after the routine? dec_P1Color DEC P1Color LDA #$07 AND P1Color STA P1Color CMP P0Color BEQ dec_P1Color TAY; ? ... or TYA ? RTS; ? inc_P1Color INC P1Color LDA #$07 AND P1Color STA P1Color CMP P0Color BEQ inc_P1Color TAY; ? ... or TYA ? RTS; ? dec_P0Color DEC P0Color LDA #$07 AND P0Color STA P0Color CMP P1Color BEQ dec_P0Color TAY; ? ... or TYA ? RTS; ? inc_P0Color INC P0Color LDA #$07 AND P0Color STA P0Color CMP P1Color BEQ inc_P0Color TAY; ? ... or TYA ? RTS; ? You might be able to consolidate these into two, or maybe even just one, routine if you use different static variables for the two colors (e.g., color1 and color2, where color1 would be set to either P0Color or P1Color, and color2 would likewise be set to the other color), so you don't need separate routines for P0Color and P1Color... and/or by using a variable set to either +1 or -1 (i.e., 255) so you can just add it to the color without having separate dec and inc routines. Michael Quote Link to comment Share on other sites More sharing options...
Hornpipe2 Posted April 11, 2008 Author Share Posted April 11, 2008 (edited) A and Y must be the same before and after the block. I don't understand what you mean by that. Copy A to Y after the routine, or restore A from Y after the routine? Sorry, I meant the values of both A and Y are useful. Actually only A is REALLY useful, Y can be reloaded from immediate at a cost of a couple bytes. EDIT: Good solution though! Edited April 11, 2008 by Hornpipe2 Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted April 11, 2008 Share Posted April 11, 2008 I think he just means that, like an interrupt routine, at the end A and Y must contain whatever value they began with. That's why he starts with a PHA and ends with a PLA (he doesn't touch Y in his routine). Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted April 11, 2008 Share Posted April 11, 2008 Okay, trying to consolidate them ends up costing more bytes just to set up the variables, so separate routines are better. This is revised from my previous code, assuming that X can be changed but you want A and Y to be unchanged. And I'm taking out the RTS because I figure the routines will be part of a series of ifs anyway, rather than called subroutines: TAX dec_P1Color DEC P1Color LDA #$07 AND P1Color STA P1Color CMP P0Color BEQ dec_P1Color TXA ; etc. TAX inc_P1Color INC P1Color LDA #$07 AND P1Color STA P1Color CMP P0Color BEQ inc_P1Color TXA ; etc. TAX dec_P0Color DEC P0Color LDA #$07 AND P0Color STA P0Color CMP P1Color BEQ dec_P0Color TXA ; etc. TAX inc_P0Color INC P0Color LDA #$07 AND P0Color STA P0Color CMP P1Color BEQ inc_P0Color TXA ; etc. Each routine uses 14 bytes of ROM. Michael Quote Link to comment Share on other sites More sharing options...
Hornpipe2 Posted April 11, 2008 Author Share Posted April 11, 2008 (edited) Each routine uses 14 bytes of ROM. Michael This is awesome, exactly what I need. Thanks so much! Edited April 11, 2008 by Hornpipe2 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.