-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathdisplay.sinc
186 lines (135 loc) · 2.29 KB
/
display.sinc
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
.importzp _oam_off ;make this ZP variable accessible to assembly code
.segment "CODE"
;void __fastcall__ oam_clear_fast(void);
.export _oam_clear_fast ;make this function accessible to C code
_oam_clear_fast:
lda #240
.repeat 64,I
sta OAM_BUF+I*4
.endrepeat
rts
;void __fastcall__ oam_meta_spr_pal(unsigned char x,unsigned char y,unsigned char pal,const unsigned char *metasprite);
.export _oam_meta_spr_pal
_oam_meta_spr_pal:
sta <PTR
stx <PTR+1
ldy #2 ;three popa calls replacement, performed in reversed order
lda (sp),y
dey
sta <SCRX
lda (sp),y
dey
sta <SCRY
lda (sp),y
sta <DST ;this is palette, just repurposing RAM variable name
ldx _oam_off
@1:
lda (PTR),y ;x offset
cmp #$80
beq @2
iny
clc
adc <SCRX
sta OAM_BUF+3,x
lda (PTR),y ;y offset
iny
clc
adc <SCRY
sta OAM_BUF+0,x
lda (PTR),y ;tile
iny
sta OAM_BUF+1,x
lda (PTR),y ;attribute
iny
and #$fc ;remove palette bits
ora <DST ;add new palette bits
sta OAM_BUF+2,x
inx
inx
inx
inx
jmp @1
@2:
stx _oam_off
lda <sp
adc #2 ;carry is always set here, so it adds 3
sta <sp
bcc @3
inc <sp+1
@3:
rts
;void __fastcall__ oam_meta_spr_clip(signed int x,unsigned char y,const unsigned char *metasprite);
.segment "ZEROPAGE"
SPR_XOFF: .res 1
SPR_YOFF: .res 1
.segment "CODE"
.export _oam_meta_spr_clip
_oam_meta_spr_clip:
sta <PTR
stx <PTR+1
jsr popa ;y
sta <SCRY
jsr popax ;x
sta <SCRX
stx <DST ;this is X MSB, repurposing RAM variable name
ldx _oam_off
ldy #0
@1:
lda (PTR),y ;x offset
cmp #$80
beq @2
iny
sta <SPR_XOFF+0
clc
adc <SCRX
sta <SPR_XOFF+1
lda <SPR_XOFF+0
ora #$7f
bmi :+
lda #0
:
adc <DST
bne @skip
lda <SPR_XOFF+1
sta OAM_BUF+3,x
lda (PTR),y ;y offset
iny
clc
adc <SCRY
sta OAM_BUF+0,x
lda (PTR),y ;tile
iny
sta OAM_BUF+1,x
lda (PTR),y ;attribute
iny
sta OAM_BUF+2,x
inx
inx
inx
inx
jmp @1
@skip:
iny
iny
iny
jmp @1
@2:
stx _oam_off
rts
; static unsigned char sx,sy,tile,pal,off;
; static signed int sxx;
; off=0;
; while(1)
; {
; sx=metasprite[off++];
; if(sx==128) return;
; sxx =x+(signed char)sx;
; sy =metasprite[off++]+y;
; tile=metasprite[off++];
; pal =metasprite[off++];
; if(!(sxx&0xff00))
; {
; oam_spr(sxx,sy,tile,pal,oam_off);
; oam_off+=4;
; }
; }