- ; Stores a 16-bit value into the address stored in HL
- ; 5 bytes, 24 clocks
- ; \1 The value to store (immediate or register)
- MACRO STORE16
- ld [hl], HIGH(\1)
- inc hl
- ld [hl], LOW(\1)
- ENDM
-
- ; Reads a 16-bit value into HL
- ; \1 The address to read
- MACRO LOAD16
- ld a, [\1]
- ld l, a
- ld a, [\1 + 1]
- ld h, a
- ENDM
-
- ; Copies bytes to a memory location
- ; 7 bytes, 48*N-4 clocks
- ; \1 Destination address (16-bit register)
- ; \2 Source address (16-bit register)
- ; \3 Number of bytes (8-bit register)
- MACRO MEMCPY
- .loop\@:
- ld a, [\2] ; 8
- inc \2 ; 8
- ld [\1], a ; 8
- inc \1 ; 8
- dec \3 ; 4
- jr nz, .loop\@ ; 12/8
- ENDM
-
- ; Adds A to a 16-bit register
- ; \1 Destination register
- ; 5 * 4 = 20 cycles
- MACRO ADD16
- add LOW(\1)
- ld LOW(\1), a
- adc HIGH(\1)
- sub LOW(\1)
- ld HIGH(\1), a
- ENDM
-
- ; Load between two 16-bit registers
- ; \1 Destination register
- ; \2 Source register
- MACRO LD16
- ld HIGH(\1), HIGH(\2)
- ld LOW(\1), LOW(\2)
- ENDM
-
- ; Performs SRL on a register N times
- ; \1 8-bit register
- ; \2 Number of shifts (1-7)
- MACRO srln
- ASSERT \2 >= 1 && \2 <= 7
- REPT \2
- srl \1
- ENDR
- ENDM
-
- ; SLA on a 16-bit register
- MACRO SLA16
- sla LOW(\1)
- rl HIGH(\1)
- ENDM
-
- ; Check \1 - \2
- ; \1 16-bit register
- ; \2 16-bit immediate/register
- MACRO CP16
- ld a, HIGH(\1)
- cp HIGH(\2)
- jr nz, .done\@
- ld a, LOW(\1)
- cp LOW(\1)
- .done\@
- ENDM
-
- ; A = MIN(A, x)
- ; \1 Other value
- MACRO MIN
- cp \1
- jr c, .skip\@
- ld a, \1
- .skip\@:
- ENDM
|