verz

setzerobit

Feb 26th, 2022 (edited)
1,171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; val: zeropage location for the value
  2. ; y: source bit
  3. ; x: destination bit
  4.  
  5. lda val         ; could be "sta val" if value is already in .A
  6. and setbit,y
  7. beq zeroit
  8. setit:
  9.     lda val
  10.     ora setbit,x
  11.     rts
  12. zeroit:
  13.     lda val
  14.     and voidbit,x
  15.     rts
  16.  
  17. setbit:
  18. byte 1,2,4,8,16,32,64,128               ; values with only one bit set
  19. voidbit:
  20. byte 254,253,251,247,239,223,191,127    ; values with only one bit clear
  21.  
  22.  
  23.  
  24.  
  25. ; Shorter version, just one table
  26. lda setbit,y
  27. and val
  28. beq zeroit
  29. setit:
  30.     lda setbit,x
  31.     ora val
  32.     rts
  33. zeroit:
  34.     lda setbit,x
  35.     eor #$ff
  36.     and val
  37.     rts
  38.  
  39. setbit:
  40. byte 1,2,4,8,16,32,64,128               ; values with only one bit set
  41.  
Add Comment
Please, Sign In to add comment