flag_action.asm 665 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. FlagActionPredef:
  2. call GetPredefRegisters
  3. FlagAction:
  4. ; Perform action b on bit c
  5. ; in the bitfield at hl.
  6. ; 0: reset
  7. ; 1: set
  8. ; 2: read
  9. ; Return the result in c.
  10. push hl
  11. push de
  12. push bc
  13. ; bit
  14. ld a, c
  15. ld d, a
  16. and 7
  17. ld e, a
  18. ; byte
  19. ld a, d
  20. srl a
  21. srl a
  22. srl a
  23. add l
  24. ld l, a
  25. jr nc, .ok
  26. inc h
  27. .ok
  28. ; d = 1 << e (bitmask)
  29. inc e
  30. ld d, 1
  31. .shift
  32. dec e
  33. jr z, .shifted
  34. sla d
  35. jr .shift
  36. .shifted
  37. ld a, b
  38. and a
  39. jr z, .reset
  40. cp 2
  41. jr z, .read
  42. .set
  43. ld b, [hl]
  44. ld a, d
  45. or b
  46. ld [hl], a
  47. jr .done
  48. .reset
  49. ld b, [hl]
  50. ld a, d
  51. xor $ff
  52. and b
  53. ld [hl], a
  54. jr .done
  55. .read
  56. ld b, [hl]
  57. ld a, d
  58. and b
  59. .done
  60. pop bc
  61. pop de
  62. pop hl
  63. ld c, a
  64. ret