Jump to content
IGNORED

Best way to mirror a byte?


Recommended Posts

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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...