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.

50 lines
956 B

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. MACRO ADD16
  34. add LOW(\1)
  35. ld LOW(\1), a
  36. adc HIGH(\1)
  37. sub LOW(\1)
  38. ld HIGH(\1), a
  39. ENDM
  40. ; Load between two 16-bit registers
  41. ; \1 Destination register
  42. ; \2 Source register
  43. MACRO LD16
  44. ld HIGH(\1), HIGH(\2)
  45. ld LOW(\1), LOW(\2)
  46. ENDM