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.
 
 
 
 

51 lines
976 B

; 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