You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.4 KiB

3 years ago
  1. ; Stores a 16-bit value into the address stored in HL
  2. ; 5 bytes, 24 clocks
  3. ; \1 The value to store (immediate or register)
  4. MACRO STORE16
  5. ld [hl], HIGH(\1)
  6. inc hl
  7. ld [hl], LOW(\1)
  8. ENDM
  9. ; Reads a 16-bit value into HL
  10. ; \1 The address to read
  11. MACRO LOAD16
  12. ld a, [\1]
  13. ld l, a
  14. ld a, [\1 + 1]
  15. ld h, a
  16. ENDM
  17. ; Copies bytes to a memory location
  18. ; 7 bytes, 48*N-4 clocks
  19. ; \1 Destination address (16-bit register)
  20. ; \2 Source address (16-bit register)
  21. ; \3 Number of bytes (8-bit register)
  22. MACRO MEMCPY
  23. .loop\@:
  24. ld a, [\2] ; 8
  25. inc \2 ; 8
  26. ld [\1], a ; 8
  27. inc \1 ; 8
  28. dec \3 ; 4
  29. jr nz, .loop\@ ; 12/8
  30. ENDM
  31. ; Adds A to a 16-bit register
  32. ; \1 Destination register
  33. ; 5 * 4 = 20 cycles
  34. MACRO ADD16
  35. add LOW(\1)
  36. ld LOW(\1), a
  37. adc HIGH(\1)
  38. sub LOW(\1)
  39. ld HIGH(\1), a
  40. ENDM
  41. ; Load between two 16-bit registers
  42. ; \1 Destination register
  43. ; \2 Source register
  44. MACRO LD16
  45. ld HIGH(\1), HIGH(\2)
  46. ld LOW(\1), LOW(\2)
  47. ENDM
  48. ; Performs SRL on a register N times
  49. ; \1 8-bit register
  50. ; \2 Number of shifts (1-7)
  51. MACRO srln
  52. ASSERT \2 >= 1 && \2 <= 7
  53. REPT \2
  54. srl \1
  55. ENDR
  56. ENDM
  57. ; SLA on a 16-bit register
  58. MACRO SLA16
  59. sla LOW(\1)
  60. rl HIGH(\1)
  61. ENDM
  62. ; Check \1 - \2
  63. ; \1 16-bit register
  64. ; \2 16-bit immediate/register
  65. MACRO CP16
  66. ld a, HIGH(\1)
  67. cp HIGH(\2)
  68. jr nz, .done\@
  69. ld a, LOW(\1)
  70. cp LOW(\1)
  71. .done\@
  72. ENDM