Advertisement
EmanueleBonin

asm 6502 Copy Bit x on Y

Feb 26th, 2022
3,637
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. ; Zero page free bytes
  3. ZPFB    = $FB
  4. ZPFC    = $FC
  5.  
  6.  
  7.  
  8. *=$0801
  9.  
  10.     BYTE    $0E, $08, $0A, $00, $9E, $20, $28,  $32, $30, $36, $34, $29, $00, $00, $00
  11.  
  12.         ; Test
  13.         lda #%11111110          ; Value
  14.         ldx #1                  ; Source bit 1
  15.         ldy #0                  ; Target bit 0
  16.         jsr CopyBitXOnY         ; Call Generic copy bit routine
  17.         sta $0400               ; print raw result code  255
  18.         rts
  19.  
  20. Mask
  21.         byte %11111110          ; 0
  22.         byte %11111101          ; 1
  23.         byte %11111011          ; 2
  24.         byte %11110111          ; 3
  25.         byte %11101111          ; 4
  26.         byte %11011111          ; 5
  27.         byte %10111111          ; 6
  28.         byte %01111111          ; 7
  29.  
  30. ;******************************************************************************
  31. ; CopyBitXOnY
  32. ; A = Value
  33. ; X = Source bit
  34. ; Y = Target bit
  35. ; return
  36. ; A with Target bit equal to Source Bit
  37. ;******************************************************************************
  38. CopyBitXOnY
  39.         sta ZPFB                ; Save value
  40.         lda Mask,y              ; load target reset Mask
  41.         and ZPFB                ; reset target bit
  42.         sta ZPFB                ; save Value
  43.         lda Mask,x              ; Load source reset Mask
  44.         eor #$ff                ; change it on source set mask
  45.         and ZPFB                ; test source bit
  46.         beq CB_Exit             ; if zero then exit        
  47.         lda Mask,y              ; load target reset Mask
  48.         eor #$ff                ; change it on target set mask
  49.         ora ZPFB                ; set target bit    
  50.         rts
  51.        
  52. CB_Exit
  53.         lda ZPFB                ; load value
  54.         rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement