-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprite.inc
executable file
·145 lines (130 loc) · 4.57 KB
/
sprite.inc
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
;* sprite.inc
;* sprite defs
;
;* by John Harrison (so far)
;* 2008-Mar-31 --- V1.0
;* 2008-Apr-15 --- V1.1
;* added ability to read/write to sprites by sprite # as well
;* as by name.
;* added SetSpriteTileNum
;* added version checking macro
;* 2008-May-01 --- V1.1a
;* fixed check for register or # in GetSpriteXAddr and friends
IF !DEF(SPRITE_INC)
SPRITE_INC SET 1
;***************************************************************************
REV_CHECK_SPRITE_INC: MACRO
;NOTE: REVISION NUMBER CHANGES MUST BE ADDED
;TO SECOND PARAMETER IN FOLLOWING LINE.
IF \1 > 1.1a ;PUT REVISION NUMBER HERE
FAIL "Version \1 or later of 'sprite.inc' is required."
ENDC
ENDM
include "standard-defs.inc"
;***************************************************************************
;*
;* SPRITE DEFINITIONS
;*
;***************************************************************************
RSSET OAMDATALOC
SpriteAttr: MACRO
\1YAddr RB 1
\1XAddr RB 1
\1TileNum RB 1
\1Flags RB 1
ENDM
;***************************************************************************
; _FIND_SPRITE - locate sprite in memory by sprite #
; input: \1 is sprite #
; intended for internal use, so has a push without a pop
; output: hl = memory location pointing to sprite #
;***************************************************************************
_FIND_SPRITE: MACRO
push hl
ld l,\1 ; get sprite #
sla l
sla l ; multiply by 4
ld h,OAMDATALOCBANK
ENDM
;***************************************************************************
;set XAddr of sprite.
;format:
; PutSpriteXAddr SpriteName,r8
; PutSpriteXAddr SpriteName,n8
PutSpriteXAddr: MACRO
push af
ld a,\2
add 8
IF ((STRIN("0123456789$",STRSUB("\1",1,1))==0) && (STRIN("a",STRLWR("\1"))==0) && (STRIN("b",STRLWR("\1"))==0) && (STRIN("c",STRLWR("\1"))==0) && (STRIN("d",STRLWR("\1"))==0) && (STRIN("e",STRLWR("\1"))==0) && (STRIN("h",STRLWR("\1"))==0) && (STRIN("l",STRLWR("\1"))==0)) ; not a # or an 8-bit register
ld [\1XAddr],a
ELSE
_FIND_SPRITE \1
inc hl ; point to X Addr
ld [hl],a
pop hl
ENDC
pop af
ENDM
;***************************************************************************
;set YAddr of sprite.
;format:
; PutSpriteYAddr SpriteName,r8
; PutSpriteYAddr SpriteName,n8
PutSpriteYAddr: MACRO
push af
ld a,\2
add 16
IF ((STRIN("0123456789$",STRSUB("\1",1,1))==0) && (STRIN("a",STRLWR("\1"))==0) && (STRIN("b",STRLWR("\1"))==0) && (STRIN("c",STRLWR("\1"))==0) && (STRIN("d",STRLWR("\1"))==0) && (STRIN("e",STRLWR("\1"))==0) && (STRIN("h",STRLWR("\1"))==0) && (STRIN("l",STRLWR("\1"))==0)) ; not a # or an 8-bit register
ld [\1YAddr],a
ELSE
_FIND_SPRITE \1
ld [hl],a
pop hl
ENDC
pop af
ENDM
;***************************************************************************
;set TileNum of sprite.
;format:
; SetSpriteTileNum SpriteName,r8
; SetSpriteTileNum SpriteName,n8
;SpriteName may be either a SpriteName set with SpriteAttr or may be a
;sprite number, 0 being the sprite at $OAMDATALOC, 1 at $OAMDATALOC+4, etc.
SetSpriteTileNum: MACRO
push af
ld a,\2
IF ((STRIN("0123456789$",STRSUB("\1",1,1))==0) && (STRIN("a",STRLWR("\1"))==0) && (STRIN("b",STRLWR("\1"))==0) && (STRIN("c",STRLWR("\1"))==0) && (STRIN("d",STRLWR("\1"))==0) && (STRIN("e",STRLWR("\1"))==0) && (STRIN("h",STRLWR("\1"))==0) && (STRIN("l",STRLWR("\1"))==0)) ; not a # or an 8-bit register
ld [\1TileNum],a
ELSE
_FIND_SPRITE \1
inc hl
inc hl ; point to the tile number
ld [hl],a
pop hl
ENDC
pop af
ENDM
;***************************************************************************
GetSpriteXAddr: MACRO
IF ((STRIN("0123456789$",STRSUB("\1",1,1))==0) && (STRIN("a",STRLWR("\1"))==0) && (STRIN("b",STRLWR("\1"))==0) && (STRIN("c",STRLWR("\1"))==0) && (STRIN("d",STRLWR("\1"))==0) && (STRIN("e",STRLWR("\1"))==0) && (STRIN("h",STRLWR("\1"))==0) && (STRIN("l",STRLWR("\1"))==0)) ; not a # or an 8-bit register
ld a,[\1XAddr]
ELSE
_FIND_SPRITE \1
inc hl ; point to the X addr
ld a,[hl]
pop hl
ENDC
sub 8
ENDM
;***************************************************************************
GetSpriteYAddr: MACRO
IF ((STRIN("0123456789$",STRSUB("\1",1,1))==0) && (STRIN("a",STRLWR("\1"))==0) && (STRIN("b",STRLWR("\1"))==0) && (STRIN("c",STRLWR("\1"))==0) && (STRIN("d",STRLWR("\1"))==0) && (STRIN("e",STRLWR("\1"))==0) && (STRIN("h",STRLWR("\1"))==0) && (STRIN("l",STRLWR("\1"))==0)) ; not a # or an 8-bit register
ld a,[\1YAddr]
ELSE
_FIND_SPRITE \1
ld a,[hl] ; hl already points to y addr
pop hl
ENDC
sub 16
ENDM
ENDC