|
|
这是个 nesasm 3.2 入土教程, 感兴趣的可以研究下1 B, h$ X9 [5 K( l9 C; O$ W

) l+ p/ g6 E! u# J. q以下是主框架代码:+ W8 v( g. g* o; W+ l) g
- ;======================================================================
% C( O* {% t2 r - ;文件头
3 O0 l( L/ Y5 q6 z# Z; T - NES_16KB_PRG_SIZE = 8 ;16KB PRG大小数量8 K! s$ I/ a" Y8 C( ?6 r
- NES_8KB_CHR_SIZE = 1 ;8KB CHR大小数量
* e; T1 g8 ?& [! E - BANK_DATA_MASK = NES_16KB_PRG_SIZE * 2 - 1 ;bank号掩码
/ Q0 v# r- P5 B$ |+ c6 g - ;======================================================================. g% g+ T5 A/ ]) ^9 Q8 N
- PRG_DATA_BANK_C000 = NES_16KB_PRG_SIZE * 2 - 2
6 D! ?4 {- i# M: z2 v& y4 S" P3 e - PRG_DATA_BANK_E000 = NES_16KB_PRG_SIZE * 2 - 1 b7 [; T5 `; a. l
- ;======================================================================
T5 m* `7 `7 l0 q5 J - RESET_BANK = NES_16KB_PRG_SIZE * 2 - 1
6 h6 r! w8 L% G: t/ S i - RESET_ADDR = $E000 ;主程序起始地址8 z* H- |9 U- b$ j
- ;======================================================================
) g1 I* V, s5 o: O6 T# t- @2 M - .INESPRG NES_16KB_PRG_SIZE ;16KB PRG 数量, $01-$EF8(1-3832),即16-61,312 KB6 K1 p7 e2 G- X. A4 i
- .INESCHR NES_8KB_CHR_SIZE ;8KB CHR 数量,$01-$EF8(1-3832),即0-30,656 KB
, o8 o' F9 K1 x/ F2 ^ m' x - .INESMAP 4 ;Mapper号 (0-4095)
( ~/ A) `- ^! A! W - .INESSUBMAP 0 ;子Mapper号 (0-15)( v8 `8 z: H" ?9 m) E+ ~1 Z
- .INESMIR 0 ;命名表镜像 (0: 水平 1: 垂直 2: 四屏)0 i& I6 S( _4 O, ~
- .INESBAT 0 ;指定是否存在电池备份 (0: 不存在 1: 存在)
, P2 h1 w) W# e - .INESPRGRAM 0 ;指定 PRG RAM 大小 (大小 = 64字节 << 计数)& E x/ _+ e5 q! x4 t
- .INESPRGNVRAM 0 ;指定 PRG NVRAM 大小(大小 = 64字节 << 计数)
' W: S+ Z( [# z6 ~6 {4 Z8 D- j - .INESCHRRAM 0 ;指定 CHR RAM 大小(大小 = 64字节 << 计数); d" I# I6 B( v( N. ~0 ^, C7 l
- .INESCHRNVRAM 0 ;指定 CHR NVRAM 大小(大小 = 64字节 << 计数); {3 A8 Q7 C6 j+ s" z
- .INESTIM 0 ;指定时序 (0: NTSC, 1: PAL, 2: 多区域, 3: Dendy)
1 ]& ?% D0 `7 `; P* d" w4 B3 u - ;======================================================================
8 x5 S( s( T `0 ` - .INCLUDE "fc_demo_config.asm" ;全局配置
; Y0 k! M1 ?' x' t4 W8 Q2 p - .INCLUDE "fc_demo_constant.asm" ;NES常量2 J* c, a6 V3 F( d5 N0 X
- ;======================================================================
8 Y2 `% |3 f& C2 H4 j - ;音乐配置1 t5 `. c2 u- q8 V$ F+ G
- .IF 0 = MUSIC_THEME
! K W. A' l: \. l0 @ - .INCLUDE "data/music/Gremlin 2/config.asm"
$ p" d9 S7 ?' D' K - .ENDIF
E: F0 D& z% q$ U- ~# { -
, E$ d$ b# i0 w" s" k0 ? - .IF 1 = MUSIC_THEME9 F3 V. r4 O/ ?( q/ r" \5 Y
- .INCLUDE "data/music/Raf World/config.asm"
9 _8 i' q) ]6 {( A: O% }8 W - .ENDIF
; s" B, k! W% U -
% A" y3 ^3 e$ c5 J, h - .IF 2 = MUSIC_THEME
, S! i2 i) R! D1 w7 n" ] - .INCLUDE "data/music/Ninja Gaiden 3/config.asm", P2 w" q. K3 {4 X' F! H
- .ENDIF
# ?0 g9 M; w# y' X$ K2 Y; A6 E
. T. Z! h( P5 s" G/ M4 d- ;======================================================================
$ T7 z7 F' |2 z y* ` - ;引用CHR图像数据
( ^9 g' V; H8 G - .BANK NES_16KB_PRG_SIZE * 2
$ v( i2 T/ ^3 w4 z+ H8 W& Z - .ORG $0000$ g8 |, a2 F! ]4 U `& {
- .INCBIN "data/bkg.chr"
! b: j; V5 [. O& I: D - .INCBIN "data/sp.chr"8 d! N4 I7 M: n T
- ) E- y9 [8 c$ N
- ;======================================================================
2 r! V* c7 B: {! b$ Q7 j - .BANK PRG_DATA_BANK_E000 & BANK_DATA_MASK;设置程序所在Bank
4 w/ { t2 [; h3 ^# j' [) v8 V - .ORG RESET_ADDR
5 @# f9 y; ?8 N0 e; X - ;======================================================================
4 ^ Y( ]) E4 c1 V0 n3 p - ;引用其他源文件/ g1 m' l* V9 x0 J9 r& y# M
- .INCLUDE "fc_demo_ppu.asm" ;PPU处理
6 Y5 w! X& f3 n: v0 N& C. E8 X/ p - .INCLUDE "fc_demo_joysitck.asm" ;手柄处理. a' l6 f7 g" W! |
- .INCLUDE "fc_demo_static_text.asm" ;静态文本处理8 ?( c5 \ e/ ]
- ;======================================================================
/ @! {& V* a& P% d- g
* q+ I* @, y/ a$ t- ;======================================================================6 H/ A9 }( V! \* x/ q4 m0 |9 m
- ;等待VBlank到来
9 m1 x8 ~7 [. b" X - Wait_For_VBlank
+ I5 Z: J9 U) q7 h - LDA PPU_STATUS
) P- `* l8 @! S z - BPL Wait_For_VBlank
- f- N# E8 d8 l2 Z3 c; ~ - RTS
/ L. h& I$ ~8 A/ M+ a0 _
! f1 T4 E$ {6 L# _$ d# Q- ;======================================================================; M* g3 T+ I" }- |8 b: s; \
- ;调色板初始化
A: d. H- z' \# U& r: F - Palette_Init" [ K) h& }0 }9 \& ?+ K, q; z/ a
- LDA #$3F, ?8 R7 Z5 H! M; ]0 b% o! W! V. W3 {
- STA PPU_ADDRESS
7 ?. p. f1 q) |1 L. m u# x - LDA #$00
4 N0 R# w0 y+ V - STA PPU_ADDRESS
6 `- r A, l4 e% u- W9 N - LDX #$00% }" R" K/ e0 e) }
- LDY #$20, S2 h4 j) S% M8 H3 p
- .Write_Data* F; c2 B) f$ V/ ?0 f4 F, G
- LDA Palette_Data,X
+ {2 j+ [2 n4 N8 p3 I# D - STA FC_PPU_Pal_Addr,X
" r; p7 l. Q# O* x - INX
6 Y2 n; h' I U7 h3 G( x- K9 s' ` - DEY
Q$ l- ?$ {( B; ]6 i& m - BNE .Write_Data
0 L s, P1 ~) F! e: C - .End& \5 x7 x! p$ @5 W- h( Y1 W% F" W
- RTS" I8 h8 x. F$ D. ^$ n
. I$ ]/ n+ w4 S- ;----------------------------------------
% v3 h4 x8 L, ~# R - ;调色板数据
' S; ~4 k: v r5 q% y - Palette_Data
& L- ~2 v4 ~) S( n6 t' H - .HEX 0F 20 32 02 0F 20 32 0F 0F 20 32 26 0F 1B 0F 1B
& M' z( u3 }0 i3 p! o - .HEX 0F 21 27 22 0F 24 24 24 0F 21 21 21 0F 22 22 22
3 X. X- m# G. _ S: T2 L5 t3 \ - $ o8 @* `) z, _/ P/ S- z! M$ q
- ;======================================================================
2 j' G j1 Y+ G5 t" l - ;命名表清空
/ l) h t8 T# D: R; Y! E: \ - Nametable_Clear
! ~2 y+ A3 e0 v9 R v - LDA #$206 A( [' X" Q0 R( ]
- STA PPU_ADDRESS
5 N% C; s1 v, j - LDA #$00# B; ]% Q& D0 L& [9 p! N
- STA PPU_ADDRESS, p& a, ?& |% O9 C' U! j
- LDA #$00
( x& G% t4 T# i5 w. q3 @& T - LDX #$00" }' V2 F# D; |# B
- LDY #$08- m3 _) J" [5 x4 X2 E. A
- .Write_Data
7 L7 V" A9 n4 i3 b. }1 j+ e - STA PPU_DATA- X+ p/ d& j- j! f
- INX$ W) u- f7 c/ Y* S( A$ V' r
- BNE .Write_Data
: U. R+ i; f7 |6 Q1 {* w7 U - DEY8 o9 ~+ L6 L4 H0 a
- BNE .Write_Data t$ I* C$ i! K% a: f( M
- .End
9 ~- s6 Z& I( m# t, R- u; S* O - RTS. `) H+ {( @4 B' h2 |# m# o
7 p ` `/ T& C, D$ a3 g- ;======================================================================
* W: k' w0 _8 {3 p$ M - ;音乐曲目切换
+ P" X8 }3 C" C: H) v9 W - Music_Select_Process
% ]4 j/ o: u* R* V - ( ?; Q3 M0 |* [2 |" n" r- x. o
- .Pre_Music;上一曲
0 M+ s' Q: F2 @ - LDA FC_Gamepad_Once0 t5 {' l5 f) Z- T! K3 M
- CMP #JOY_KEY_LEFT
5 ?/ o4 c* ?2 S5 U7 p8 [' Q - BNE .Next_Music) U7 n2 W* `5 r1 |; v
- JSR Music_Play_Pre4 q, Y0 ?( T5 a4 [4 [
- .Next_Music;下一曲. `8 U9 x! L+ F# h6 L) T7 J7 W
- LDA FC_Gamepad_Once
n x3 L' T# Z7 R y3 R - CMP #JOY_KEY_RIGHT
8 v/ [* L$ D r/ X1 a( y+ V$ O( r8 n - BNE .Next_10_Music# Y$ L$ s2 A$ ^7 O2 P; Y/ ?( s
- JSR Music_Play_Next9 z. [! j$ t6 l9 }
- .Next_10_Music;上10曲
3 Z7 Q9 M! s2 O! s/ T - LDA FC_Gamepad_Once
, E; K( P$ C3 u0 s8 B( s+ u& o - CMP #JOY_KEY_UP
# r* g# S; l/ u, p. _ - BNE .Pre_10_Music
; t4 ~7 u% }; G2 T. ~ - JSR Music_Play_Next_10$ D+ x) d0 u6 M! q+ A0 l" [( N
- .Pre_10_Music;下10曲
! Y9 [5 s6 |8 a9 ? k - LDA FC_Gamepad_Once4 i/ Z5 C% e$ w/ Z" k& k; k
- CMP #JOY_KEY_DOWN
9 s2 W" K; ~. Q- r& D0 z( Z/ E3 l - BNE .Reset
, k+ y7 F& z6 j1 | - JSR Music_Play_Pre_103 ?3 \* t8 U+ v$ c. c O
- .Reset;重播当前曲目4 n# [, t* x9 D3 Q- A
- LDA FC_Gamepad_Once
& q2 @2 f; d1 ^6 g8 ?1 j3 u - CMP #JOY_KEY_START, D! l" w! `8 I" `0 {
- BNE .End- h+ R2 R U) J5 R1 }
- LDA FC_Music_Index- C6 `# c0 j$ _# ~( |
- JSR Music_Init_Process; R6 x: U' L7 ~+ S
- .End3 n- e' } w7 ^: a+ f" w3 |
- RTS% X/ u8 f- B$ ^, G- A/ e7 ^% }
$ v7 z4 C8 X# u3 U- ;----------------------------------------------------------------------
2 P, K: L) h/ { x - ;播放上一曲
& a4 S: _% ]* r- A; y - Music_Play_Pre+ g/ f7 k! j. y
- LDA FC_Music_Index2 E, ]& Y1 ^- I% W
- BEQ .End
* s! f8 U. Z( l - DEC FC_Music_Index' H% G0 G; G) r2 Y: y6 F
- LDA FC_Music_Index% ?% k: j" o% x( S- K) M8 _
- JSR Music_Init_Process
& `9 @+ J/ C5 W/ K4 g3 J* S% P# u - .End+ C, |5 \3 [3 E/ o% M1 E7 C- T2 i
- RTS/ C0 e+ S5 ]: l9 B5 E
- ;----------------------------------------------------------------------& u) v( z+ s. N! M% |$ o
- ;播放下一曲1 V: g4 @2 y. o/ _9 R
- Music_Play_Next
) U: ]% R4 X* _6 ]( j- \ - LDA FC_Music_Index2 J% @ Q3 ^( {+ W% |3 _, z& U7 |
- CMP FC_Music_Max_Index4 f* B1 k) A M3 J2 I9 }1 h; B
- BCS .End3 m8 X: P" ?, r3 e; R1 X' M
- INC FC_Music_Index
0 O0 Z- y, s) L& a4 B) y9 G% c3 [ [ - LDA FC_Music_Index% [* Z+ k% Y% `3 l# K8 f
- JSR Music_Init_Process0 d' s: m' D* p
- .End
( z: Y7 x4 j: M4 g5 t - RTS9 I" G* |) R! W+ b. M/ I
$ G* O/ j! q: T4 i% \1 C3 _- ;----------------------------------------------------------------------+ S, U' m2 D' A6 q
- ;播放上10曲: f( L ?% W- \* @' K3 v
- Music_Play_Pre_10
% a$ n2 H! ^3 }. @/ O, N - LDA FC_Music_Index, a: W0 w1 r1 w, ~/ ?) G3 Z% ?
- BEQ .End z5 Y1 C: g' w6 Y1 m
- SEC
* S% V& w( W& k - SBC #10
4 P9 ^9 C" N( A8 Q - BCS .Pre_10
% K, K1 K* [: e4 G, c - LDA #$00
' m. J# q9 k; G - .Pre_10% d% s* O: ~1 S3 p" K3 y
- STA FC_Music_Index4 S. h4 }. I2 q
- JSR Music_Init_Process
/ f3 J# U/ [; n+ k9 y - .End# G9 R. E" O* \6 z
- RTS
9 m" M( i2 U9 f3 l# n - ;----------------------------------------------------------------------
1 f& ^1 h/ O! q1 g - ;播放下10曲
( s/ I* K1 X; T! M' j - Music_Play_Next_10
; K$ ]7 g: _/ z1 }$ b8 h4 O - LDA FC_Music_Index
7 X6 T$ V) S/ o, c+ L9 z - CMP FC_Music_Max_Index
- O: C' x! o) }6 U* \ s5 A - BCS .End
. U; O9 i% U3 b! u7 h - CLC' Q- O1 }7 k$ G
- ADC #106 v$ w5 ?! E p
- CMP FC_Music_Max_Index
# _/ o1 Q5 ^0 Z' U) ^0 R1 n - BCC .Next_10
5 N3 @# f# B4 @6 J, R - LDA FC_Music_Max_Index
C# x3 K, {& B$ f# |/ j5 w - .Next_10. v$ R j& _! s9 r. p2 x# Y* c( M
- STA FC_Music_Index- @ v& M9 N" [. J1 ?& H
- JSR Music_Init_Process
# a6 o8 I) M0 v" Z& W - .End5 m- Z# `, {+ s& q
- RTS0 h0 Y' s- i |( j5 h9 S$ z% t1 K7 [
- 7 ]# {( s) o3 r0 ?: f, ~- w
- ;----------------------------------------------------------------------, j* I6 l3 _/ p( ~
- ;8位十六进制转3位十进制制
; E8 v& t- E. A+ y, ?' e. O/ ? - Hex8ToDec, F) t9 }$ {: Z$ K* |
- STA FC_Dec_Data_1
4 e& ^" J) \) x; ]7 |/ } - LDA #$00( f8 P* ^1 l) H+ G: w
- STA FC_Dec_Data_1004 @1 l3 P. n$ c" b( h9 o6 z0 P# j m
- STA FC_Dec_Data_10" J0 V ^- W( t" C
- LDA FC_Dec_Data_1; p; }5 i$ \6 V h+ b( h. ~
- .Convert_100
9 k( E, S! c& K- W+ H - CMP #1005 a |' d7 v7 B3 k$ T$ `' j$ m+ Q
- BCC .Convert_10
# C7 _5 t V% W6 A - SEC
m8 d+ n3 o" n$ ^; ? - SBC #100
8 c; |) m( A5 R V - INC FC_Dec_Data_100+ `. o. o. n% q' ?8 G, B, `
- BNE .Convert_100
% j4 g) U* ~' x- Y - .Convert_10
$ e! O3 c1 [- @& |& c - CMP #10
0 C; g3 E! d9 L9 W5 O0 g: I - BCC .End
1 e9 ~9 @. X6 q& }) M/ L% U - SEC6 i5 u, j* _7 W; W- m5 G% o! K
- SBC #103 {; D, t9 t8 _% s
- INC FC_Dec_Data_10
# K) c' l7 b- O1 R8 g. t% G - BNE .Convert_10
" M( E- V% f/ l# M$ h - .End
$ }( G* k( v1 d. T - STA FC_Dec_Data_15 v" a2 e% {. u! j
- RTS
7 K5 h" ^7 D6 \) @
- Q4 v. m9 n: @5 T- ;----------------------------------------------------------------------- I+ H6 `1 Z" g2 f
- ;显示曲目信息
$ Y2 m, e1 O, z3 p7 I" ]7 ^# y - Music_Info_Display2 `+ v2 U; Q: d$ Z
- LDX FC_PPU_Buf_Count" K, f$ c) G9 l9 R( c" z
- LDA #PPU_WRITE_MODE_CNT_LINE: b7 t4 [% U6 Q
- STA Use_PPU_Buffer,X. ^- D- J, ^7 l- a `. Q% D
- INX G$ E7 l P, h- I- ?7 |! R; M
-
& X+ I: G. O0 V, ]/ ]4 F1 ? - LDA #>MUSIC_INFO_POS, K2 `$ F2 r" i- w
- STA Use_PPU_Buffer,X
% R$ S$ \& a4 B. s. `3 w - INX7 ^% U, Y- `# D' P0 D9 n
-
# r' e. r- P$ t; c' f - ;居中% R7 ]# \: \: h! b* O' G
- LDA #<(MUSIC_INFO_POS & $E0) + (32 - 5)/2$ M& f; l9 M2 @0 B; `
- STA Use_PPU_Buffer,X! v. q- G$ D( I) |: Z
- INX9 l+ r& }, z2 q0 w
- ' p3 A s7 F6 \3 K/ `
- LDA #$055 [5 k8 M; q4 W& u% V1 I& E1 ^( ~
- STA Use_PPU_Buffer,X
( ^/ X/ Z% k: x3 I0 l/ { - INX7 t* U/ G4 F0 g- `2 ~ _
- ) N2 t* A. ?/ b+ R8 B$ d
- LDA FC_Music_Index
* E4 @% I Z0 `1 v - CLC
2 Q \1 A7 q* D/ m* B - ADC #$01
& r+ H5 R3 E1 M9 A' m/ A; z/ _$ i# o* _ - JSR Hex8ToDec9 @# e1 n; R/ M- L% F
-
7 x0 P2 @' T( d( j S - LDA FC_Dec_Data_10, w+ I' c0 i3 v, n/ l) S
- CLC
" W, R4 p! C, B& e; a* r - ADC #'0'6 A5 ~% Y7 H. p8 X
- STA Use_PPU_Buffer,X0 s# h$ @; ^/ Z% `" Z
- INX
1 |! T: b& O- z6 t - : {# W! N. [/ r. N" Q& _
- LDA FC_Dec_Data_1
& s- c7 v. X7 `2 h6 ^( T5 U - CLC
( ]& x) v8 U$ m7 g% ~ - ADC #'0'
3 J8 N; y3 q& Q2 S9 H( v/ C6 _' m - STA Use_PPU_Buffer,X) K. |/ _4 H7 C2 l9 Y9 w* n
- INX. \8 x2 O+ s3 \ q4 Q
-
& F; C8 P. D0 x9 E - LDA #'/'
- O+ L0 k3 k/ p: ?6 V - STA Use_PPU_Buffer,X
$ \9 Y, G; n: M1 k: ?$ e - INX
# h1 K; y% r$ [* C( m; Q8 m -
, ]/ b: E0 D* e - LDA FC_Music_Max_Index
7 j+ m, e0 Y9 K" {! l7 I - CLC8 h6 H; ?9 F, a5 [
- ADC #$01; u0 T: p) d% o. j$ R
- JSR Hex8ToDec
( ^. Q. l) K( | - , A, t; L6 w& f: @2 u I
- LDA FC_Dec_Data_104 k) r, L r! D3 K/ Y) B
- CLC! s W: q& o6 h g- l
- ADC #'0'
3 Q; T, E' }- R6 _: L - STA Use_PPU_Buffer,X
! y* o( w2 L- R: t' N( C - INX8 v& \. K) ?: I
- * | `2 l4 X: ~" ^5 {8 }
- LDA FC_Dec_Data_1
$ p- {* P* ?& L6 u - CLC
$ l/ i9 z% b( p - ADC #'0'
a+ E3 m T: x# ~% n/ W3 y( C - STA Use_PPU_Buffer,X
! r8 S9 W- Z' p - INX! i/ J3 v. e6 d1 ~6 ] h
- 7 U$ A7 K2 v( {
- .End
1 x7 @) L }* t9 n# D! n9 f& w/ ^# ~ - STX FC_PPU_Buf_Count
& n* D$ c5 _6 e0 W* F! f1 V/ Q% O& M - RTS7 |" q( L$ B; S+ S" R& g
- : ^. K7 h4 F5 h& K( v( W
- ;----------------------------------------------------------------------! o3 v9 B- y& D' |& {5 P
- ;音乐曲目初始化处理7 \+ b; k Y' e/ w! r$ N5 g
- Music_Init_Process
- k7 t/ c* F, [9 i - PHA
3 x, o' R) y1 e" _ - JSR Music_Clear_Process
% `' `3 H0 ^9 \ O1 F; r - LDA #$1F3 Y( ^8 q( o: P5 }/ ]
- STA $4015. l: q5 c$ P B8 f9 ~
- PLA
. M0 G8 N8 V6 N9 O2 I' g; [. ] - JSR Music_Init_Addr1 U- v7 u8 I. U' A3 F& w
- JSR Music_Info_Display
( R: Y i* r* x8 f3 m9 ]' D - RTS1 i& C) x8 V+ E. Z/ Y* c
3 l( O" v) |4 E* }5 t R. F* `( D- ;----------------------------------------------------------------------6 m- @0 V! k# D N
- ;音乐播放处理
& k. R) o6 w( f- z/ S - Music_Play_Process* a7 \" f2 g7 O& g6 ~6 E( u1 \- V
- JSR Music_Play_Addr- C# v8 m8 K! T5 a8 t9 j
- RTS
5 f, t) k5 \. n# x- l7 Q
% X. z \3 ?0 Z# Q+ _ q' _& I- ;----------------------------------------------------------------------
) _% y: |) R4 J+ p9 c% \ - ;音乐播放处理
) p- @9 B: e: J$ u3 p& N - Music_Clear_Process
; H s6 F, u. N, S+ d) a0 D$ C - .IF Music_Clear_Addr' m4 N7 N8 M4 D3 m/ x/ r- d
- JSR Music_Clear_Addr5 w' u8 \3 \; B: i7 Q
- RTS- S Q E: d# t4 C; N& g2 }
- .ELSE
/ m7 T3 a$ Q3 r7 [9 a8 O - LDA #$1F
& A1 C4 W |% j1 V1 F$ G+ k% w - STA $4015
( s; X! h7 J' r6 Q - LDA #$00
. ~/ [( r( f$ X/ o& E9 f- U) S - STA $40101 h2 U( R) h6 k6 e6 ^: H7 J
- LDX #$00, Q4 O7 _5 k6 Z* y+ p
- LDA #$00
$ I2 `8 L* z5 o2 n' M6 {9 k* c - 8 \9 A2 b& p5 m) p5 r
- .Music_Clear_Zreo_Page_0$ u1 |9 i9 P3 p1 d0 h* J7 a
- STA $00,X8 m* v8 l$ B/ `# a! w
- INX
8 G) I! m* n. K" ~" _4 C - CPX #Use_Zero_Page_Begin+ Z$ x8 E" y4 ~9 L- l' i& E3 T
- BCC .Music_Clear_Zreo_Page_0
# o v% g# W% ^( B, p8 p' |" { -
3 z+ h& M' `# Z& @' p9 r - LDX #Use_Zero_Page_Begin + Use_Zero_Page_Size
- O7 A# S* ]: w* t% o( t% Y - .Music_Clear_Zreo_Page_14 d7 S& A$ J) o
- STA $00,X
. [) o. m) C' h; b2 D/ M0 B - INX
5 }, S ~% O7 F" S+ v; P - BNE .Music_Clear_Zreo_Page_1. x$ ^9 W5 y1 G1 a) }1 V
- / J& u1 K8 j2 |& A6 T; B X
- Music_Clear_Process_1; }8 j7 l! C3 [- H2 |
- STA $0600,X
7 c. z9 n/ W( K* `3 C - STA $0700,X- L M1 k# i, K
- INX
( O) a% J8 S# P/ y" V( X - BNE Music_Clear_Process_1* B4 h, F4 D2 ~& o
- LDA #$10( } `) K+ Q8 @ {! x
- STA $40004 i$ f* n" B# X' u6 s \
- STA $4004
9 u: {. x4 X, |2 o { - STA $400C
a- L* Q. a) L - LDA #$003 L, |/ M; s$ b, |7 q1 k
- STA $4008
' c' J( \9 [4 N, E5 w4 O' y% I7 [ - LDA #$0F6 }3 v3 g2 }1 T* }3 C0 n' h
- STA $4015
' F9 k1 ^) `, ?! y# {( d - .ENDIF
8 p/ {$ w) G& j/ m - % n9 U" ?$ x; v% z9 i1 F! Z
- RTS
% ]. h# V& \* x2 q- K! y3 H5 P. P
) Y% B! w- L7 [) P9 _0 ^6 @- ;======================================================================! `' p; B) n, b. A0 f" o& U
- ;重启处理. n- h& x/ F" C- ^! Q ^5 ~+ c1 G
- Reset_Program, Q- Q9 @6 U* _1 B/ D
- SEI
; W% r! \ i: ~% e3 D- s - CLD. s, N" o+ f. b/ z
- LDA #$00
. W( X6 a3 G; j6 _3 ~! c( U4 u - STA PPU_CTRL
8 f4 |% _9 ~4 t! m0 U7 K - STA PPU_MASK
) ^9 d0 [9 j' R% L1 j - STA JOY2_FRAME. P0 S A2 E8 a4 t( q
- STA APU_STATUS
* ~# F/ ^5 @' R* \* ] - 5 ]! s1 S- Y4 ]; `
- ;等待屏幕准备完毕
+ Y7 l' o( O4 w! q8 O/ [/ _. K - LDX #$026 X8 K5 n8 _/ G9 s
- .Wait_For_Screen_Ready1 j; z) _* s3 ^
- LDA PPU_STATUS. m5 h+ `2 p$ q3 J6 l
- BPL .Wait_For_Screen_Ready
# b& E: Z" [* Z7 x - DEX6 y) U1 W* @8 T" N
- BNE .Wait_For_Screen_Ready
8 O' P( Z/ H8 x, M$ n - 8 M. f& L& { o) B$ }
- ;清空调色板
+ N& [& x6 n/ r2 Y6 n! i$ R - Palette_Clear
2 U% D2 Z ?9 ]& j: T' F/ c. g3 ^ - LDA #$3F
2 Q1 }6 N5 z; }! Y" b! k6 Z - STA PPU_ADDRESS Z3 Y0 L5 K1 Q7 I; ` x
- LDA #$00% V& E% D/ ~) l+ |; S
- STA PPU_ADDRESS. @* B, t5 q" ^1 L* C# K! Z' S
- LDX #$20! U& a( c" H* ^' L$ `( E
- LDA #$0F( \3 x; [, R9 [4 t; ]
- .Write_Data; L u g/ ~. }! |' n4 \
- STA PPU_DATA8 o- y/ j- L2 C+ x; ~
- DEX
% J ~# S5 E6 J' v2 Q6 b# j - BNE .Write_Data* m$ x0 `% X7 l! K- l
$ \. K! j$ Q6 g+ V' A- ;清除声音 $4000-4013+ ?9 r5 L. g9 W% N
- LDY #$14$ {# [( f( N% E: m2 }% N
- LDX #$00, f1 s4 }5 R1 u3 G7 R
- .Sound_Clear! G, H8 q! l5 e+ x4 A
- STA $4000,X9 y) L: l- B* p3 a( o4 M
- INX! P1 n* r! \! l2 m u) p
- DEY; h ?2 r) a, R
- BNE .Sound_Clear
) {/ B/ a$ `( I- W1 L& s -
5 k5 g1 h$ B/ j w d - ;清除 RAM $0000-07FF- k) N& f* \/ f9 W: V5 w
- LDA #$00
/ f) \* `. ^; l0 W- ^& L - STA $008 i; b# F' @' y$ a" k
- STA $01+ Z' n/ N, F( h5 b! M6 E/ w
- TAY
9 i( s/ n) v; Z - LDX #$084 @8 j# [& P f% v: L. ^0 D
- .Memory_Clear% D3 J: `. o3 f( N2 c
- STA [$00],Y8 r+ e1 N6 F8 v# U0 C* z, V1 F
- INY
. T0 e5 }2 }3 ^) ?7 B4 F - BNE .Memory_Clear
8 j0 w8 e$ F$ V- y* Q. t0 j- ` - INC $01
/ b, Q( x# A8 y0 K3 { - DEX
! G" z$ k2 _& @- x9 n! g& {. i - BNE .Memory_Clear( x5 b ?( ]3 S/ w
- H' L% k) P7 i. o! \, X/ [
- ;精灵缓冲初始化
: e( b4 \$ k6 k9 I# c - LDX #$00
2 N% w, G7 h* A/ I8 D" ] - LDA #$F8
+ R* ^2 r4 x5 R3 F. x - .OAM_Clear
3 U8 D8 b# w% N/ c" _ - STA OAM_DMA_Buffer,X# C$ L0 }3 w7 V" S% c0 M$ Q7 \
- INX
9 \# P% s3 l9 j; r, C - BNE .OAM_Clear6 v7 N( X5 b7 b( T
-
1 q6 t3 Q j# n J - ;栈指针初始化; e/ g1 J2 H; p7 }' V, C
- LDX #$FF8 f% L0 Q; `' i9 I6 ^! ?. D5 R
- TXS
7 x* U0 E$ C& W" n& H! x7 { -
( J8 ^4 ?" L' d - JSR Nametable_Clear;命名表清空
0 ?, G( `' E) s( [2 O9 r9 T" r - JSR Palette_Init;初始化调色板缓冲
4 ~, U V. f1 A3 V0 l8 \6 v7 c - JSR Static_Text_Init;初始化静态文本
" f; w- F8 f. r -
& e: P* H* ^, p+ C( ^ - LDA #MUSIC_ITEM_TOTAL - 1
7 c; D- R9 Q9 Z# w - STA FC_Music_Max_Index
" ^6 [# h: r# P7 G -
5 `0 n( Z) \* L/ B2 Z - LDA #$1F6 r6 @8 F2 g* R. F, _2 a
- STA APU_STATUS' u0 `5 `( k; G c! G& p" r
- LDA #MUSIC_BGM - 1
1 A% q# P- ?1 q3 {4 d. k - STA FC_Music_Index
0 E% X& j2 m& Y k - JSR Music_Init_Process;音乐播放2 H, V/ g: I& L" G& P
- : M0 b# h: N& X; z* q- a9 ]( m
- ;设置屏幕显示状态缓冲(当NMI处理时控制屏幕显示状态)
2 E& I: o/ J# o' ] E - LDA #$1E. P5 D2 a" K* X+ L, G8 t* _
- STA FC_PPU_Mask_Buf
7 _9 e! f8 y1 D0 |# I - # V$ R" x' z# w. c/ F! s6 q
- ;启用NMI处理
: U) c# b& a. o4 F! P3 n - LDA #$80
* F. `. N4 l- T4 E z- ~ - STA PPU_CTRL
4 F& \0 q [4 o -
; w8 ?, } E" O/ ~/ L) L6 [% c - ;程序循环, 剩余工作交给 NMI 中断处理
( f5 k" u: v& {) r# i' t3 z; u! D1 h! K - .Loop" T F% w% d, l" o/ @' a
- JMP .Loop
9 C# a! ~$ d+ m& g) D3 y' X8 e
( s3 a4 f6 {) y- ;======================================================================# x' ?/ S3 H; b6 f! N
- ;不可屏蔽中断处理" M7 {% g/ H+ N% r
- Nmi_Program
5 t" M* E( c) M, R. q* S - PHA
" U+ P5 u3 E0 e; | - TXA
& z: r2 A: ]: ~6 B - PHA% A4 @+ h% c2 z9 d- C. z( G
- TYA
d# {( z& d1 ]2 u q3 H6 p8 U" l1 L3 b - PHA/ o% e: H% @% g3 X1 h* A
- % c$ Q7 A+ H1 k% ?5 t4 \
- LDA PPU_STATUS;读取使得 PPU状态寄存器复位
3 x, V+ ?: @, y -
3 l3 R( ~* x) _8 F* ? - JSR FC_PPU_Procrss;PPU处理
. M7 W' P% s1 g0 t M6 u; r -
7 l4 Y# O0 g# [: b" P" G - ;精灵内存更新5 K! H" h7 @' s& e/ X7 B
- LDA #$005 R( ]5 v# Q0 p! Z s0 \
- STA PPU_OAM_ADDR
- t( v! v& R7 ~, I+ f# L" w. e; k - LDA #OAM_DMA_Buffer / $01008 [0 P: W5 C) X( x2 a$ ]
- STA OAM_DMA1 v# e* c V0 l! I
- 9 g) ]: Q" U0 x7 Y
- JSR FC_Gamepad_Process;手柄输入处理, Q* G6 s J1 D. {+ ^! B+ d
- JSR Music_Select_Process;音乐选曲处理& Q6 J2 a+ A" f7 ?
- JSR Music_Play_Process;音乐播放处理" R6 J3 h9 O9 K8 y5 T% M4 o! u
-
, E8 f3 X& L& D* D9 `8 X+ C o7 T - PLA9 P- d/ x( p) K |$ S
- TAY
) ]2 [& V2 d" c - PLA
b/ a' \) d3 d0 [ - TAX
5 J! t+ a; L+ x+ { - PLA! v: p1 ^! D9 o2 o6 }( ~7 T) M
2 O- J4 v# Q1 r* x, F* Q+ H4 |- RTI* ^0 H B) p. h! h$ d
- 7 c8 [( M! [; H0 k9 Q! L
- ;======================================================================
% U' U# k2 W6 z! v& @ - ;请求中断处理% ^1 s1 L9 T9 C
- Irq_Program
! k7 Y1 ^4 O9 n2 b/ a8 [* |) ]5 E' _ - RTI
& `* A- f+ Y' d& [$ P - ; l7 V1 d& b! Q5 C
- ;======================================================================
+ z: a9 m8 S0 g3 Y7 p) I9 x - ;中断向量表
* {7 G. z) ^- Q0 B( \% b - .ORG $FFFA5 O/ q" o* q. P: [
- .DW Nmi_Program ;NMI触发时执行8 ]3 q9 ]; _: J% f
- .DW Reset_Program ;载入ROM时最先执行
. c3 N! U, c' f" G* k# |) u% w - .DW Irq_Program ;IRQ触发时执行! e1 g w# y, ~. Z! s
复制代码 . H" P) ]1 d6 ~7 G4 i+ C ?- D
: |- T9 |. R/ r9 Y% `( ?
& p0 q3 r- @( G
https://gitee.com/flame_cyclone/nesasm_3_2 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
1
查看全部评分
-
|