/
main.s
145 lines (122 loc) · 3.54 KB
/
main.s
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
.include "global.i"
; the code
.segment "CODE"
.proc reset
InitializeSNES
; forced blank
seta8
lda #$8f
sta PPUBRIGHT
lda #$01
sta BGMODE ; mode 0 (four 2-bit BGs) with 8x8 tiles
stz BGCHRADDR ; bg planes 0-1 CHR at $0000
lda #$4000 >> 13
sta OBSEL ; sprite CHR at $4000, sprites are 8x8 and 16x16
lda #>$6000
sta NTADDR+0 ; plane 0 nametable at $6000
sta NTADDR+1 ; plane 1 nametable also at $6000
; Copy background palette to the S-PPU.
; We perform the copy using DMA (direct memory access), which has
; four steps:
; 1. Set the destination address in the desired area of memory,
; be it CGRAM (palette), OAM (sprites), or VRAM (tile data and
; background maps).
; 2. Tell the DMA controller which area of memory to copy to.
; 3. Tell the DMA controller the starting address to copy from.
; 4. Tell the DMA controller how big the data is in bytes.
; ppu_copy uses the current data bank as the source bank
; for the copy, so set the source bank.
seta8
stz CGADDR ; Seek to the start of CGRAM
setaxy16
lda #DMAMODE_CGDATA
ldx #palette & $FFFF
ldy #palette_size-palette
jsr ppu_copy
; Copy background tiles to PPU.
; PPU memory is also word addressed because the low and high bytes
; are actually on separate SRAM chips.
; In background mode 0, all background tiles are 2 bits per pixel,
; which take 16 bytes or 8 words per tile.
setaxy16
stz PPUADDR ; we will start video memory at $0000
lda #DMAMODE_PPUDATA
ldy #font_size-font
ldx #font & $FFFF
jsr ppu_copy
lda #$6000|NTXY(0,1)
sta PPUADDR
ldx #$00
: seta8
lda message, x
cpa #$ff
beq done
seta16
and #$ff ; clear higher bit
sta PPUDATA
inx
jmp :-
done:
seta8
lda #%00000001 ; enable sprites and plane 0
sta BLENDMAIN
lda #$0F
sta PPUBRIGHT
?forever:
jmp ?forever
.endproc
; we'll need this at some point ;3
zero_fill_byte:
.byte $00
message:
;12345678901234567890123456789012
.byte "hello, snes! i am nicklausw! "
.byte " you know, back in my day, we "
.byte " always played the snes. "
.byte " "
.byte "as in 2007. i was a 2000's kid. "
.byte " a retro one regardless. "
.byte " "
.byte "anyway, this is my first "
.byte " program for this system ever! "
.byte " YEAH! and you know something? "
.byte " "
.byte "back when i first started on "
.byte " this system, i was using, yep, "
.byte " wla-dx. now i proudly use "
.byte " ca65 instead! "
.byte " "
.byte "quick hello to tepples, koitsu, "
.byte " dougeff, espozo, bazz, ramsis, "
.byte " kannagi, and whoever else "
.byte " helped in the creation of "
.byte " this rom. thank you all! "
.byte " "
.byte " -nicklausw "
.byte " "
.byte "(and yes, the overdone "
.byte "enthusiasm is on purpose).", $ff
; palette macro
.define bgr(cb, g, r) ((cb<<10)|(g<<5)|r)
palette:
.word bgr(0, 0, 0)
.word bgr(31, 31, 31)
palette_size:
font:
.incbin "font.chr"
font_size:
.proc ppu_copy
php
setaxy16
sta DMAMODE
stx DMAADDR
sty DMALEN
seta8
phb
pla
sta DMAADDRBANK
lda #%00000001
sta COPYSTART
plp
rts
.endproc