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.

66 lines
1.2 KiB

2 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. MACRO SLA16
  49. sla LOW(\1)
  50. rl HIGH(\1)
  51. ENDM
  52. ; Performs SLA on a register N times
  53. ; \1 8-bit register
  54. ; \2 N, a value 1-8
  55. MACRO slan
  56. ASSERT 1 <= \2 && \2 <= 8
  57. REPT \2
  58. sla \1
  59. ENDR
  60. ENDM