-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatterns.asm
98 lines (84 loc) · 3.12 KB
/
patterns.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;====
; Manages patterns (graphic tiles) in the VDP
;
; Provided for example purposes to get you started. For an actual game you
; would want to compress pattern data using an algorithm such as zx7 or aPLib
; and use the appropriate lib to decompress and write to VRAM
;====
;====
; Settings
;
; Define these before including this file if you wish to override the defaults
;====
; Pattern address in VRAM
.ifndef patterns.VRAM_ADDRESS
.define patterns.VRAM_ADDRESS $0000
.endif
;====
; Constants
;====
.define patterns.ELEMENT_SIZE_BYTES 32
.define patterns.MAX_PATTERN_INDEX 511
;====
; Dependencies
;====
.ifndef utils.assert
.include "utils/assert.asm"
.endif
.ifndef utils.clobbers
.include "utils/clobbers.asm"
.endif
.ifndef utils.outiBlock
.include "utils/outiBlock.asm"
.endif
.ifndef utils.vdp
.include "utils/vdp.asm"
.endif
;====
; Write patterns (tile graphics) into VRAM
;
; @in dataAddress the address of the first byte of data
; @in count the number of patterns to write (1-based)
; @in [offset=0] the number of patterns to skip at the beginning of the data
;====
.macro "patterns.writeSlice" args dataAddress count offset
utils.assert.label dataAddress, "patterns.asm \.: Invalid dataAddress argument"
utils.assert.range count, 1, patterns.MAX_PATTERN_INDEX + 1, "patterns.asm \.: Invalid count argument"
.ifndef offset
utils.assert.equals NARGS, 2, "patterns.asm \. received the wrong number of arguments"
utils.outiBlock.writeSlice dataAddress, patterns.ELEMENT_SIZE_BYTES, count, 0
.else
utils.assert.equals NARGS, 3, "patterns.asm \. received the wrong number of arguments"
utils.assert.number offset, "patterns.asm \.: Invalid offset argument"
utils.outiBlock.writeSlice dataAddress, patterns.ELEMENT_SIZE_BYTES, count, offset
.endif
.endm
;====
; Write uncompressed patterns into VRAM
;
; @in dataAddress start address of the data
; @in size data size in bytes. Due to WLA-DX limitations this must be an
; immediate value, i.e. it can't be calculated from a size
; calculation like end - start. It can be a fsize label (such as
; using .incbin "file.bin" fsize size) so long as this label is
; defined before this macro is called.
;====
.macro "patterns.writeBytes" args dataAddress size
utils.assert.equals NARGS, 2, "patterns.asm \. received the wrong number of arguments"
utils.assert.label dataAddress, "patterns.asm \.: Invalid dataAddress argument"
utils.assert.number size, "patterns.asm \.: Invalid size argument"
utils.clobbers "hl"
ld hl, dataAddress
utils.outiBlock.write size
utils.clobbers.end
.endm
;====
; Set the current pattern index ready to write data into
;
; @in index the index number (0-512)
;====
.macro "patterns.setIndex" args index
utils.assert.equals NARGS, 1, "patterns.asm \. received the wrong number of arguments"
utils.assert.range index, 0, patterns.MAX_PATTERN_INDEX, "patterns.asm \.: Invalid size argument"
utils.vdp.prepWrite (patterns.VRAM_ADDRESS + (index * patterns.ELEMENT_SIZE_BYTES))
.endm