-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvramfill.asm
81 lines (77 loc) · 2.16 KB
/
vramfill.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
; FreeDiskSysROM
; Copyright (c) 2018 James Athey
;
; This program is free software: you can redistribute it and/or modify it under
; the terms of the GNU Lesser General Public License version 3 as published by
; the Free Software Foundation.
;
; This program is distributed in the hope that it will be useful, but WITHOUT
; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
; FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
; details.
;
; You should have received a copy of the GNU Lesser General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
; memset for VRAM.
; If A < $20, it fills pattern table data with the value in X for 16 * Y tiles,
; or Y * 256 bytes.
; If A >= $20, it fills the corresponding nametable with the value in X and
; attribute table with the value in Y.
; Parameters: A = High VRAM Address (aka tile row #), X = Fill value, Y = # of tile rows OR attribute fill data
; Affects: A, $00, $01, $02, $FF (aka PPUCTRL)
API_ENTRYPOINT $ea84
VRAMFill:
STY $02 ; preserve Y so it can be restored later
; every write to PPUADDR needs to ensure that the PPUADDR latch is clear
; one nice feature of TOP is that it reads without clobbering anything
TOP PPUSTATUS
; set the address
STA PPUADDR
LDA #0
STA PPUADDR
; set the correct VRAM increment mode of 1
LDA ZP_PPUCTRL
AND #%11111011
STA PPUCTRL
STA ZP_PPUCTRL
; pattern or nametable fill?
CMP #$20
BCS @VramNametableFill
@VramPatternFill:
CLC
; The address has been loaded, so now we can use A as a counter
; 16 tiles in a row, 16 bytes per tile = 256 bytes to write per row
LDA #0
@tile:
STX PPUDATA
ADC #1
BCC @tile
DEY
BNE @VramPatternFill
; restore Y (X never changed)
LDY $02
RTS
@VramNametableFill:
; fill the nametable with X for 960 bytes, or 4 * 240 bytes
STX $01 ; preserve X so it can be restored later
TXA
LDX #4
@quarterNT
LDY #240
@name:
STA PPUDATA
DEY
BNE @name
DEX
BNE @quarterNT
; restore the attr file value in Y
LDY $02
; then fill the attributes with Y for 64 bytes
LDX #64
@attr:
STY PPUDATA
DEX
BNE @attr
; restore X (Y is already restored)
LDX $01
RTS