Browse Source

Add dubiously helpful macros

master
Forest Belton 3 years ago
parent
commit
c7ff4eb46c
1 changed files with 41 additions and 7 deletions
  1. +41
    -7
      inc/util.inc

+ 41
- 7
inc/util.inc View File

@ -1,4 +1,5 @@
; 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)
@ -6,11 +7,44 @@ MACRO STORE16
ld [hl], LOW(\1)
ENDM
; Stores an 8-bit value into memory
; \1 Write address
; \2 8-bit value
MACRO SET8
ld h, HIGH(\1)
ld l, LOW(\1)
ld [hl], \2
; 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
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

Loading…
Cancel
Save