Wickeycolumbus Posted April 15, 2020 Share Posted April 15, 2020 Hey guys, I was looking for a quick/cheap on ROM way to mirror the bit order in a byte. The input is a byte in the order 7 6 5 4 3 2 1 0, with the output 0 1 2 3 4 5 6 7. The intention is to use this function on playfield graphics to get over the hardware mirroring of PF0 and PF2. This is what I came up with: Mirror_Byte ldy #0 sty temp ldy #$88 sty temp2 tax Mirror_Loop jsr ROR_W_Carry and temp2 ora temp sta temp jsr ROR_W_Carry clc lsr temp2 bcc Mirror_Loop lda temp rts ROR_W_Carry txa clc and #$01 beq Mirror_D0_Not_Set sec Mirror_D0_Not_Set txa ror tax rts The value to be mirrored is passed to the subroutine in the accumulator, and returned mirrored in accumulator and temp. You just need to jsr Mirror_Byte to get the result. I don't really like that it uses another jsr to do the RORing, or the amount of time this all takes.. Im sure the loop can be altered to eliminate one instance of jsr ROR_W_Carry at a minimum. Anyone have a better way? Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted April 15, 2020 Share Posted April 15, 2020 Just off the top of my head REPEAT 8 asl ror temp REPEND Quote Link to comment Share on other sites More sharing options...
+grafixbmp Posted April 16, 2020 Share Posted April 16, 2020 Here is one using tables may run faster byte mirror flip.txt 1 Quote Link to comment Share on other sites More sharing options...
Wickeycolumbus Posted April 17, 2020 Author Share Posted April 17, 2020 Hey guys, thanks for the suggestions. I knew that there must be a simpler way. 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.