gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/libc/targets/mos6502/nes/set_attribute.s
1 .module SetAttributeXY
2
3 .include "global.s"
4
5 .area GBDKOVR (PAG, OVR)
6 _set_bkg_attribute_xy_nes16x16_PARM_3::
7 _set_win_attribute_xy_nes16x16_PARM_3:: .ds 1
8 .x_odd: .ds 1
9 .y_odd: .ds 1
10 .val: .ds 1
11 .ifdef NES_WINDOW_LAYER
12 .winbit: .ds 1
13 .endif
14
15 .area _HOME
16
17 .macro WRITE_ATTRIBUTE ?lbl, ?lbl2
18 .ifdef NES_WINDOW_LAYER
19 bit *.winbit
20 bpl lbl
21 and _attribute_shadow_win,y
22 ora *.val
23 sta _attribute_shadow_win,y
24 jmp lbl2
25 .endif
26 lbl:
27 and _attribute_shadow,y
28 ora *.val
29 sta _attribute_shadow,y
30 lbl2:
31 .endm
32
33 .ifdef NES_WINDOW_LAYER
34 _set_win_attribute_xy_nes16x16::
35 sec
36 ror *.winbit
37 jmp _set_attribute_xy_nes16x16_impl
38 .endif
39
40 _set_bkg_attribute_xy_nes16x16::
41 .ifdef NES_WINDOW_LAYER
42 clc
43 ror *.winbit
44 .endif
45 _set_attribute_xy_nes16x16_impl::
46 lsr
47 ror *.x_odd
48 tay
49 txa
50 .ifne NT_2H
51 cmp #(NT_HEIGHT/2)
52 bcc 0$
53 sbc #(NT_HEIGHT/2) ; Assumes carry set by cmp
54 ora #2*AT_HEIGHT
55 0$:
56 .endif
57 lsr
58 ror *.y_odd
59 pha
60 asl
61 asl
62 asl
63 .ifne NT_2W
64 asl
65 .endif
66 and #(AT_SHADOW_WIDTH*AT_SHADOW_HEIGHT-1)
67 ora .identity,y
68 tay
69 lda *_set_bkg_attribute_xy_nes16x16_PARM_3
70 bit *.y_odd
71 bpl 1$
72 asl
73 asl
74 asl
75 asl
76 1$:
77 bit *.x_odd
78 bpl 2$
79 asl
80 asl
81 2$:
82 sta *.val
83 lda #0
84 asl *.y_odd
85 rol
86 asl *.x_odd
87 rol
88 tax
89 lda .mask_tab,x
90 WRITE_ATTRIBUTE
91 ; Set dirty bit for row.
92 ; Assume writing rows, as the potential to optimize column writing is limited anyway.
93 pla
94 .ifne NT_2H
95 and #AT_HEIGHT-1
96 .endif
97 tax
98 lda .bitmask_dirty_tab,x
99 ; Merge A with current attribute_row_dirty flag
100 .ifdef NES_TILEMAP_S
101 .ifdef NES_WINDOW_LAYER
102 bit *.winbit
103 bpl 9$
104 ora *_attribute_row_dirty_win
105 sta *_attribute_row_dirty_win
106 jmp 8$
107 9$:
108 ora *_attribute_row_dirty
109 sta *_attribute_row_dirty
110 8$:
111 .endif
112 .endif
113 .ifdef NES_TILEMAP_H
114 pha
115 ldx #0
116 .ifdef NES_WINDOW_LAYER
117 ; 2 nametables - window dirty byte is += 2 bytes
118 bit *.winbit
119 bpl 9$
120 inx
121 inx
122 9$:
123 .endif
124 tya
125 and #AT_WIDTH
126 beq 10$
127 inx
128 10$:
129 pla
130 ora *_attribute_row_dirty,x
131 sta *_attribute_row_dirty,x
132 .endif
133 .ifdef NES_TILEMAP_V
134 pha
135 ldx #0
136 .ifdef NES_WINDOW_LAYER
137 ; 2 nametables - window dirty byte is += 2 bytes
138 bit *.winbit
139 bpl 9$
140 inx
141 inx
142 9$:
143 .endif
144 tya
145 and #(AT_HEIGHT*AT_SHADOW_WIDTH)
146 beq 10$
147 inx
148 10$:
149 pla
150 ora *_attribute_row_dirty,x
151 sta *_attribute_row_dirty,x
152 .endif
153 .ifdef NES_TILEMAP_F
154 pha
155 ldx #0
156 .ifdef NES_WINDOW_LAYER
157 ; With 4 nametables, window dirty byte is += 4 bytes
158 bit *.winbit
159 bpl 9$
160 inx
161 inx
162 inx
163 inx
164 9$:
165 .endif
166 tya
167 and #AT_WIDTH
168 beq 10$
169 inx
170 10$:
171 cpy #(AT_HEIGHT*AT_SHADOW_WIDTH)
172 bcc 11$
173 inx
174 inx
175 11$:
176 pla
177 ora *_attribute_row_dirty,x
178 sta *_attribute_row_dirty,x
179 .endif
180 rts
181
182 .mask_tab:
183 .db 0b11111100
184 .db 0b11110011
185 .db 0b11001111
186 .db 0b00111111
187
188 .bitmask_dirty_tab:
189 .db 0b00000001
190 .db 0b00000010
191 .db 0b00000100
192 .db 0b00001000
193 .db 0b00010000
194 .db 0b00100000
195 .db 0b01000000
196 .db 0b10000000
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.