-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory_layout.asm
157 lines (137 loc) · 3.43 KB
/
memory_layout.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
.export MemoryLayoutInit
.export MemoryLayoutFillChrRam
.export MemoryLayoutLoadNametable
.exportzp GAMEPLAY0_MEMORY_LAYOUT
.exportzp GAMEPLAY1_MEMORY_LAYOUT
.exportzp BOSS_MEMORY_LAYOUT
.exportzp TITLE_MEMORY_LAYOUT
.include "include.branch-macros.asm"
.include "include.mov-macros.asm"
.include "include.sys.asm"
.include "general_mapper.h.asm"
.include "gfx.h.asm"
.importzp memory_layout_index
.importzp pointer
.importzp values
.import gameplay0_bg_chr_data, gameplay1_bg_chr_data
.import chars_spr_chr_data, chars_boss_spr_chr_data
.import boss_bg_chr_data
.import title_bg_chr_data
preserve_x = values + $00
preserve_y = values + $01
MEMORY_LAYOUT_BANK_GAMEPLAY_CHR = 0
MEMORY_LAYOUT_BANK_SCREEN_CHR = 1
MEMORY_LAYOUT_BANK_LEVEL_DAT = 1
MEMORY_LAYOUT_BANK_MAIN_CODE = 2
GAMEPLAY0_MEMORY_LAYOUT = <(gameplay0_info - all_memory_layout_info)
GAMEPLAY1_MEMORY_LAYOUT = <(gameplay1_info - all_memory_layout_info)
BOSS_MEMORY_LAYOUT = <(boss_info - all_memory_layout_info)
TITLE_MEMORY_LAYOUT = <(title_info - all_memory_layout_info)
.segment "BOOT"
.proc MemoryLayoutInit
jsr GeneralMapperInit
lda #MEMORY_LAYOUT_BANK_MAIN_CODE
jsr GeneralMapperPrg8000ToC000
rts
.endproc
; X = gameplay, gameplay_chr + chars_chr
; X = boss, boss_chr + chars_chr
; X = title, title_chr + title_chr
.proc MemoryLayoutFillChrRam
stx memory_layout_index
Loop:
lda all_memory_layout_info,x
cmp #$ff
beq Done
; Bank
jsr GeneralMapperPrg8000ToC000
inc memory_layout_index
; pointer
ldx memory_layout_index
lda all_memory_layout_info,x
sta pointer+0
inx
lda all_memory_layout_info,x
sta pointer+1
inx
; ppu addr
bit PPU_STATUS
lda all_memory_layout_info,x
sta PPU_ADDR
inx
lda all_memory_layout_info,x
sta PPU_ADDR
inx
stx memory_layout_index
; load $1000
ldx pointer+0
ldy pointer+1
jsr LoadChrRamCompressed
ldx memory_layout_index
bne Loop
Done:
; Restore bank.
lda #MEMORY_LAYOUT_BANK_MAIN_CODE
jsr GeneralMapperPrg8000ToC000
rts
.endproc
all_memory_layout_info:
gameplay0_info:
.byte MEMORY_LAYOUT_BANK_GAMEPLAY_CHR ; bank_num
.word gameplay0_bg_chr_data ; pointer
.byte $00, $00 ; ppu addr
.byte MEMORY_LAYOUT_BANK_GAMEPLAY_CHR ; bank_num
.word chars_spr_chr_data ; pointer
.byte $10, $00 ; ppu addr
.byte $ff
gameplay1_info:
.byte MEMORY_LAYOUT_BANK_GAMEPLAY_CHR ; bank_num
.word gameplay1_bg_chr_data ; pointer
.byte $00, $00 ; ppu addr
.byte MEMORY_LAYOUT_BANK_GAMEPLAY_CHR ; bank_num
.word chars_spr_chr_data ; pointer
.byte $10, $00 ; ppu addr
.byte $ff
boss_info:
.byte MEMORY_LAYOUT_BANK_GAMEPLAY_CHR ; bank_num
.word boss_bg_chr_data ; pointer
.byte $00, $00 ; ppu addr
.byte MEMORY_LAYOUT_BANK_GAMEPLAY_CHR ; bank_num
.word chars_boss_spr_chr_data ; pointer
.byte $10, $00 ; ppu addr
.byte $ff
title_info:
.byte MEMORY_LAYOUT_BANK_SCREEN_CHR ; bank_num
.word title_bg_chr_data ; pointer
.byte $00, $00 ; ppu addr
.byte MEMORY_LAYOUT_BANK_SCREEN_CHR ; bank_num
.word title_bg_chr_data ; pointer
.byte $10, $00 ; ppu addr
.byte $ff
.proc MemoryLayoutLoadNametable
stx preserve_x
sty preserve_y
; Also contains GFX.
lda #MEMORY_LAYOUT_BANK_GAMEPLAY_CHR
jsr GeneralMapperPrg8000ToC000
ldx preserve_x
ldy preserve_y
jsr LoadGraphicsCompressed
lda #MEMORY_LAYOUT_BANK_MAIN_CODE
jsr GeneralMapperPrg8000ToC000
rts
.endproc
;;X = $80 or $a0
;.proc LoadChrRam
; ldx #$10
; ldy #0
;Loop:
; lda (pointer),y
; sta PPU_DATA
; iny
; bne Loop
; inc pointer+1
; dex
; bne Loop
; rts
;.endproc