-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsprites.asm
163 lines (148 loc) · 2.72 KB
/
sprites.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
*=* "Sprite Routines"
//
// These routines can be used to move and manipulate the sprites on the 64.
//
#if REGISTER_MODE
//
// Position a sprite anywhere on the screen
// This variant uses hardware registers instead of pseudo registers
//
// X sprite number (0-7)
// A,Y x pos (0-319)
// $02 y pos (0-199)
//
PositionSprite:
pha
tya
pha
txa
mult2
tay
lda $02
sta vic.SP0Y, y
pla
sta $02
pla
sta r6L
lda $02
adc #$00
sta r6H
stb r6L:vic.SP0X, y
ldx r3L
lda BitMaskPow2, x
eor #$ff
and vic.MSIGX
tay
lda #$01
and r6H
beq !no_msb+
tya
ora BitMaskPow2, x
tay
!no_msb:
sty vic.MSIGX
!return:
rts
//
// Change one of a sprite's attributes
// This variant uses hardware registers instead of pseudo registers
//
// X sprite number (0-7)
// Y attribute to change (SPR_VISIBLE, SPR_X_EXPAND, SPR_Y_EXPAND, SPR_HMC, SPR_PRIORITY)
// A value for the attribute
// - Sprite visibility (SPR_SHOW, SPR_HIDE)
// - X/Y expansion (SPR_NORMAL, SPR_EXPAND)
// - Priority (SPR_FG, SPR_BG)
// - Hires or Multicolor (SPR_HIRES, SPR_MULTICOLOR)
//
ChangeSpriteAttribute:
pha
lda BitMaskPow2, x
sta $02
pla
tax
lda $02
cpx #ENABLE
beq !set_flag+
eor #$ff
and vic.SP0X, y
jmp !clear_flag+
!set_flag:
ora vic.SP0X, y
!clear_flag:
sta vic.SP0X, y
rts
#else
//
// Position a sprite anywhere on the screen
// This variant uses the zeropage pseudo registers, which may not be compatible with BASIC or the Kernal
//
// r3L sprite number (0-7)
// r4 x pos (0-319)
// r5L y pos (0-199)
//
PositionSprite:
lda r3L
mult2
tay
stb r5L:vic.SP0Y, y
stb r4L:r6L
lda r4H
adc #$00
sta r6H
stb r6L:vic.SP0X, y
ldx r3L
lda BitMaskPow2, x
eor #$ff
and vic.MSIGX
tay
lda #$01
and r6H
beq !no_msb+
tya
ora BitMaskPow2, x
tay
!no_msb:
sty vic.MSIGX
!return:
rts
//
// Change one of a sprite's attributes
// This variant uses the zeropage pseudo registers, which may not be compatible with BASIC or the Kernal
//
// r3L sprite number (0-7)
// r3H attribute to change (SPR_VISIBLE, SPR_X_EXPAND, SPR_Y_EXPAND, SPR_HMC, SPR_PRIORITY)
// r4L value for the attribute
// - Sprite visibility (SPR_SHOW, SPR_HIDE)
// - X/Y expansion (SPR_NORMAL, SPR_EXPAND)
// - Priority (SPR_FG, SPR_BG)
// - Hires or Multicolor (SPR_HIRES, SPR_MULTICOLOR)
//
ChangeSpriteAttribute:
ldy r3H
ldx r3L
lda BitMaskPow2, x
ldx r4L
cpx #ENABLE
beq !set_flag+
eor #$ff
and vic.SP0X, y
jmp !clear_flag+
!set_flag:
ora vic.SP0X, y
!clear_flag:
sta vic.SP0X, y
rts
#endif
//
// This allows us to translate sprite numbers into bit masks
//
BitMaskPow2:
.byte %00000001
.byte %00000010
.byte %00000100
.byte %00001000
.byte %00010000
.byte %00100000
.byte %01000000
.byte %10000000