|
这是个 nesasm 3.2 入土教程, 感兴趣的可以研究下$ a8 K! y+ ~- _% [& S; p8 c/ e
5 f* ?$ }$ m8 U4 y
以下是主框架代码:
1 o o' H' h' u* {5 |; A% `; D- ;======================================================================
; X: r7 n6 c% O, B: Z - ;文件头
% l6 N7 G# T" u+ l8 {, R' z - NES_16KB_PRG_SIZE = 8 ;16KB PRG大小数量
8 u( u8 L, q9 o, ] - NES_8KB_CHR_SIZE = 1 ;8KB CHR大小数量4 L2 ^0 j0 X0 l) W) P. q; [, W
- BANK_DATA_MASK = NES_16KB_PRG_SIZE * 2 - 1 ;bank号掩码
: i# z% `% O6 s - ;======================================================================
# g* n3 A' | [) n5 F( B7 o - PRG_DATA_BANK_C000 = NES_16KB_PRG_SIZE * 2 - 2
/ [1 I S1 ^ I9 C! g3 t; ]9 h- H - PRG_DATA_BANK_E000 = NES_16KB_PRG_SIZE * 2 - 1
& Y. v) u# J4 \3 h" C - ;======================================================================
/ o7 C2 w9 B: o - RESET_BANK = NES_16KB_PRG_SIZE * 2 - 1
* x& \. l- G; A - RESET_ADDR = $E000 ;主程序起始地址
9 T8 w4 E% S& v8 S! a* D5 R1 X - ;======================================================================7 E' B* y! [4 T& Y
- .INESPRG NES_16KB_PRG_SIZE ;16KB PRG 数量, $01-$EF8(1-3832),即16-61,312 KB1 H! x2 B/ A$ z9 b$ H6 h
- .INESCHR NES_8KB_CHR_SIZE ;8KB CHR 数量,$01-$EF8(1-3832),即0-30,656 KB
* g) p4 A1 l$ g( \% C: s' Q4 r2 T4 Z - .INESMAP 4 ;Mapper号 (0-4095)
8 C$ W! O/ P0 @* x, U( F2 P - .INESSUBMAP 0 ;子Mapper号 (0-15)) j4 ?; |4 f& |* t
- .INESMIR 0 ;命名表镜像 (0: 水平 1: 垂直 2: 四屏)6 @ m* T7 {6 e0 Y
- .INESBAT 0 ;指定是否存在电池备份 (0: 不存在 1: 存在)' E! N$ M9 P1 ~) v
- .INESPRGRAM 0 ;指定 PRG RAM 大小 (大小 = 64字节 << 计数)
; n1 _( B1 e& z+ A- a, m6 w4 I8 C* t - .INESPRGNVRAM 0 ;指定 PRG NVRAM 大小(大小 = 64字节 << 计数)
* r4 h# Y+ H: F' L - .INESCHRRAM 0 ;指定 CHR RAM 大小(大小 = 64字节 << 计数)
6 o* L& I( s+ b7 S: Z0 o8 R - .INESCHRNVRAM 0 ;指定 CHR NVRAM 大小(大小 = 64字节 << 计数)6 A$ l: X$ t( w+ W; w+ L( c
- .INESTIM 0 ;指定时序 (0: NTSC, 1: PAL, 2: 多区域, 3: Dendy)- j7 b$ }9 @7 S- J/ }; P1 N, R- A
- ;======================================================================. X5 M4 T2 q& u5 u5 f
- .INCLUDE "fc_demo_config.asm" ;全局配置9 B8 H/ Y4 G0 X
- .INCLUDE "fc_demo_constant.asm" ;NES常量" |* J! F% }- o6 r' |. V. I
- ;======================================================================
+ H! O5 c3 v. l+ ]4 j - ;音乐配置7 u& `3 x% t, Y9 a8 H1 Z
- .IF 0 = MUSIC_THEME 3 i: D3 o. ]2 l+ `: _" I$ z& o
- .INCLUDE "data/music/Gremlin 2/config.asm"
4 k+ s' n5 m l( G5 z - .ENDIF2 k$ d4 \7 F' v0 T$ X& @/ j8 @
-
, Z) A; K9 C4 }2 U, X - .IF 1 = MUSIC_THEME
1 Y+ ?9 R) e. Q, O% k2 q' @: P2 ]$ i5 b - .INCLUDE "data/music/Raf World/config.asm"
4 Q. r E4 i/ a, p/ y - .ENDIF1 T% q3 y3 a% h8 Y5 `% T# h# L1 d6 u7 D
- " ~6 Z& i4 l, G! P8 D
- .IF 2 = MUSIC_THEME
( c. y# Y( T1 g- H5 ^, [4 E - .INCLUDE "data/music/Ninja Gaiden 3/config.asm"6 l2 s0 u" A1 q7 P0 z
- .ENDIF: Q) n0 U6 W2 J8 A4 q2 @0 f
- 6 H) }: }% o) C- u0 F! |/ Q& n
- ;======================================================================* N6 f9 D" U: _+ A1 B' I
- ;引用CHR图像数据
0 ^1 Z+ K: K' t/ Y7 [! Q - .BANK NES_16KB_PRG_SIZE * 2$ {, u. I2 C" O. C1 U' ?- b8 M: b
- .ORG $0000
7 E% c9 {* q# i7 J. b - .INCBIN "data/bkg.chr"
0 H3 K% ]5 G, d4 k3 Z8 z - .INCBIN "data/sp.chr"
4 u. z4 e* _0 a9 \ -
- n8 u% O* l/ n1 e- | - ;======================================================================
( S8 A6 k8 |& [9 Y - .BANK PRG_DATA_BANK_E000 & BANK_DATA_MASK;设置程序所在Bank
) @2 A! } I) e; j - .ORG RESET_ADDR
- N9 ? Z. L7 b. P r y - ;======================================================================; g$ s. \1 F7 b; v# P1 J- ~
- ;引用其他源文件
8 `3 g2 i7 [3 B; Z1 S - .INCLUDE "fc_demo_ppu.asm" ;PPU处理; x1 B6 L- o; `$ v
- .INCLUDE "fc_demo_joysitck.asm" ;手柄处理
8 @" ~- l) q3 c' h# V. i - .INCLUDE "fc_demo_static_text.asm" ;静态文本处理
' K, o" i" C- K" W: n0 w9 H - ;======================================================================
$ e7 ^! | |* ~" o* ]6 J% q! z - ! m! M V: F8 _# e, Q
- ;======================================================================! i5 g( J& t% D' l: L$ W
- ;等待VBlank到来
) a* {# e6 m% ? ]* M" W# e# b - Wait_For_VBlank
! U+ e5 [6 Q6 a7 q - LDA PPU_STATUS' [, S$ w# {: l9 B
- BPL Wait_For_VBlank
& z0 Y2 L9 I! O' |( f" A5 c2 M( m4 L - RTS) A+ a( G4 U7 W3 V7 { u" x% c
- \/ b# x( N! M1 Y2 g- ;======================================================================. Y% s+ I9 G. _7 C
- ;调色板初始化$ r) j, J8 S! g( `
- Palette_Init, E9 X7 @- V) f/ {$ a
- LDA #$3F
2 o3 q; a% \; a' O5 R - STA PPU_ADDRESS# C! |; C% H4 ?" O( H8 V) Q5 @
- LDA #$00
( ~! @0 {) C" Z% M - STA PPU_ADDRESS
p! o% x/ M5 F) H; L - LDX #$00
- c. E3 N9 R. O3 e - LDY #$20( P- g$ r* |( B: X
- .Write_Data# F- Q6 d* ~0 Q; {9 e( o4 w
- LDA Palette_Data,X
) o; r4 \) p; n" S - STA FC_PPU_Pal_Addr,X
2 N, w7 d& a& v5 d1 r4 F8 X. R c - INX
) `7 s" C) b7 z, k/ e0 s& h - DEY
. V5 [; W; k6 \0 g/ A5 G - BNE .Write_Data" A+ K s! L" L
- .End
! a ?! ]( G- v2 \4 [, C# b - RTS% G) p4 U! _) q! P# D
- , J8 c7 h3 p7 o* a n
- ;----------------------------------------
c) c/ Y: J2 K: I/ ]6 M: i - ;调色板数据
8 Q: a+ C' E m5 a: s5 K/ V6 |! S - Palette_Data: ]" O7 [: f/ ]8 I# z& `8 W
- .HEX 0F 20 32 02 0F 20 32 0F 0F 20 32 26 0F 1B 0F 1B
9 X$ U1 N1 i. t; G - .HEX 0F 21 27 22 0F 24 24 24 0F 21 21 21 0F 22 22 22
. P: @$ u( h8 h8 v -
1 j- z9 C/ T& I8 { - ;======================================================================
- Y& |( u) s1 k& c2 J! M - ;命名表清空( F2 x, p2 b+ u9 K& T
- Nametable_Clear0 x/ o5 A$ u/ v; w# S
- LDA #$20! x. W: v) G' g
- STA PPU_ADDRESS
. A+ q2 p [! [ - LDA #$007 s! O& j% [$ \* a) `4 K+ i/ Z2 M) X( u
- STA PPU_ADDRESS" x+ d- C) o- K( b
- LDA #$002 N& m( R& t5 H: ^
- LDX #$00
4 Z4 a! Y: c9 t3 _5 I, O - LDY #$087 A, {5 H0 v4 _6 v- m" F
- .Write_Data; }2 ^, v" [" ~5 \9 k+ U, Z' D
- STA PPU_DATA
) a3 w3 R, h8 [ - INX
& f5 Z. B( v; B: M8 G - BNE .Write_Data1 n* ~5 X8 ?# i$ W$ ~+ n4 R
- DEY
5 ~2 u' I L! m( c, m$ G( d) N0 @ - BNE .Write_Data; Y7 _/ ^. M- o! f. s
- .End
9 Z1 d& g! B7 s( ^ - RTS
6 g- y6 t2 F5 _' k9 n. {1 p
8 D: O& M3 L7 Y0 c3 G5 G$ s- ;======================================================================& [, ?1 c5 G6 h
- ;音乐曲目切换
4 P* O% ` ^7 y6 m - Music_Select_Process
- a" [. g% ]+ d+ V- F
0 t+ F$ u' s7 y; f+ e# o/ Q- .Pre_Music;上一曲
: f2 ~# H4 f' Q7 M2 q3 a - LDA FC_Gamepad_Once! u/ O$ c( o. [( K5 u
- CMP #JOY_KEY_LEFT- d* k% t6 w5 E
- BNE .Next_Music% _" v* {- U- a
- JSR Music_Play_Pre% U+ K( ~4 j4 C, x
- .Next_Music;下一曲; T. V) d: J1 p% n7 e
- LDA FC_Gamepad_Once' C8 _# \# b+ |4 |
- CMP #JOY_KEY_RIGHT
3 J! @ G( \+ S$ B# q - BNE .Next_10_Music+ l7 b/ Y# J% d: G( y
- JSR Music_Play_Next. T4 I2 t$ h* s
- .Next_10_Music;上10曲3 ^% [( c+ W7 J6 `
- LDA FC_Gamepad_Once
, \0 \& f0 h6 O8 g# Z - CMP #JOY_KEY_UP
& @3 i) a+ [1 f3 y" j# n. F - BNE .Pre_10_Music: V& E: p) U; q$ P3 g: y$ X W
- JSR Music_Play_Next_10
1 }1 L( |5 [9 F4 S6 j) A, ` - .Pre_10_Music;下10曲
- p/ G* o# g9 S+ A - LDA FC_Gamepad_Once
" L5 s, P# w4 P% }) T) V - CMP #JOY_KEY_DOWN
- `! ]$ o5 ]/ k! k3 q6 P - BNE .Reset
% w1 z' d2 P# G2 k/ p' U - JSR Music_Play_Pre_10
- B. d$ ^6 d+ u - .Reset;重播当前曲目
5 V5 T$ i2 {5 P& \) Y$ l/ \9 I - LDA FC_Gamepad_Once
5 D/ Q. M1 t; C - CMP #JOY_KEY_START
/ c) d; {& b: X) K N - BNE .End$ V' o5 R# c' O- H
- LDA FC_Music_Index# D- l* r: W' r; q
- JSR Music_Init_Process
/ Q9 M4 q5 [) ?6 P - .End
1 q/ {( v4 [' |! ? - RTS1 \8 p u: M. G' J) R: G* |
' n, X& {! Q6 g- s0 N& Q6 s/ z, n3 y- ;----------------------------------------------------------------------
% N- O5 J& f# \; R$ p& N) q: } - ;播放上一曲$ v; m8 J, g) p8 o
- Music_Play_Pre2 Q0 _# b% g% Z. v. A$ O
- LDA FC_Music_Index5 }& U9 E8 M+ T. X6 V. f! r1 n
- BEQ .End/ I7 ~! A) Z& ], p
- DEC FC_Music_Index! \" Q$ v$ c! z5 h
- LDA FC_Music_Index4 i" ]7 J# q3 I8 j2 N# r
- JSR Music_Init_Process4 X1 t. @. @$ r
- .End% j F- [) P* ~
- RTS, C# C/ B' L; E& B1 r, P9 O
- ;----------------------------------------------------------------------
1 C2 r" v1 ^+ J. E6 S - ;播放下一曲! r) ~" @3 z1 W9 U4 a
- Music_Play_Next1 Q$ P: c5 s: M2 X& t7 A" }4 K0 T
- LDA FC_Music_Index1 w0 ?$ P0 x; v5 {. K; E/ j* `
- CMP FC_Music_Max_Index" P8 @* p- h+ L* F, S- a
- BCS .End
0 v0 ^2 B7 L1 l! H8 i; h# b9 f3 K! o - INC FC_Music_Index
- W* v. n9 ]& `( ^. a/ c - LDA FC_Music_Index
/ n& ]4 q$ c; h - JSR Music_Init_Process \* c& C: `# E- {6 t
- .End
1 _8 c; p, |0 K8 H! ?$ j4 Z6 N - RTS
' j4 F4 m' p% X3 l
; H9 O0 K( l; i) u: R3 e# k' C f6 G- ;----------------------------------------------------------------------
( O( m( J k( ?! R, ` I. f/ l - ;播放上10曲
2 ]; y* g* h/ b( |; N6 g - Music_Play_Pre_10
2 m- `! p0 i7 j6 V' M) _9 l. K - LDA FC_Music_Index: |7 J8 y ?3 ~
- BEQ .End
! [% I! Z2 T4 f/ G; h: o) U - SEC
% z* B0 R1 h* [ - SBC #10
% o) H% j0 b% T% v. j6 I U4 ^9 N - BCS .Pre_10! U+ z9 T0 u& t+ | [& P Z. g
- LDA #$00# Y: x" D% f) o
- .Pre_10- \- S" [" x4 f) m
- STA FC_Music_Index. y. M& Y, U7 C0 k2 j. z
- JSR Music_Init_Process
8 ~ [! E ~) R; d# c5 w. M% y9 {+ G - .End
' W4 [- V3 M5 u# k - RTS
, I7 Q6 F# g" c, V9 h& O - ;----------------------------------------------------------------------
! G4 F& V3 [4 R& O - ;播放下10曲
6 Y* n5 l/ @- r" E# i - Music_Play_Next_10& e9 A) E6 Y# N! P$ ^
- LDA FC_Music_Index
: Y3 T! l+ g/ r6 W: Z! [ - CMP FC_Music_Max_Index- l7 I _' P. w9 T1 x
- BCS .End0 h3 V7 g- h2 y4 |! k
- CLC) k O2 H7 J# c0 u
- ADC #10* z; G/ G6 S9 e" f3 K7 c9 ? ~/ s2 g
- CMP FC_Music_Max_Index
6 S9 r$ A( {' W V$ D! n8 B - BCC .Next_10' O K( W# C( G! H. r! T
- LDA FC_Music_Max_Index
, P) {+ ^( {' Y+ v4 G& m" I0 ` - .Next_10
* u$ n; ^6 d% P" U' _& r - STA FC_Music_Index
3 P/ t6 i" u) s5 a, Y/ s - JSR Music_Init_Process
6 p; B, ]8 I) B0 E M - .End* g. n% |$ P2 j/ I$ c/ V. H
- RTS& b0 f" \. c0 J7 X8 ?6 ^4 r
. r1 E( M5 |7 _3 @2 _- ;----------------------------------------------------------------------
) { n1 E8 i( ^ b, v7 w - ;8位十六进制转3位十进制制0 r" K5 _# w& ^
- Hex8ToDec
" t7 q# L# t/ `, X- J% y) l6 {* O; F3 ? - STA FC_Dec_Data_1( h" n7 D. q: Z
- LDA #$00" \ h$ F0 Y; v! @( r) q! z1 U
- STA FC_Dec_Data_100
* L' @! N6 N! D& o - STA FC_Dec_Data_10
4 z. y( N+ @. D' z) Y/ z - LDA FC_Dec_Data_1. H) g! M( @) k9 b0 O8 {1 X( ` ]1 S$ F; m
- .Convert_100
8 M/ ]/ |) q6 m" f$ I* c4 [0 t - CMP #1006 ]7 s! C) a2 ^7 T3 Z
- BCC .Convert_10/ z. \2 r. s: V: S
- SEC
: X$ }3 m* L- x! k7 ^0 k9 k - SBC #100. Z+ D; n) T+ S( y
- INC FC_Dec_Data_100
& V+ k9 y$ T( L) p/ B - BNE .Convert_100
) F% ^: g* X5 K$ X* P5 N* c - .Convert_10; `: z" B/ E2 @$ P
- CMP #10: R) r8 l" O! i$ R! O& C7 x
- BCC .End+ b- t9 i7 H" l- r8 Y4 j1 E7 o9 w
- SEC
; V4 @1 F& X4 J) F - SBC #10+ f- j* j# _7 x0 l$ |+ v% ^
- INC FC_Dec_Data_10
# `; m/ A( `$ ]; b - BNE .Convert_10
0 }- G; q% @' @" g% K, @* ?1 ]2 W - .End
5 g. r! Q5 t- u1 ?- Y9 K0 P9 f - STA FC_Dec_Data_1
: }, \( o' W! q - RTS X( w' v9 D! z! v x& F3 z( N! N
- ) d. w) A; F' X& Y: X
- ;----------------------------------------------------------------------
. j$ d* g v& j H. U - ;显示曲目信息# Z; S- q h) n8 n8 }* y: y, w
- Music_Info_Display( w% \2 K% G0 R L
- LDX FC_PPU_Buf_Count
9 g+ h1 {( Z! u - LDA #PPU_WRITE_MODE_CNT_LINE+ A( S9 \( ^+ e z
- STA Use_PPU_Buffer,X8 A- X. Q: Z* z( f2 i% ?
- INX& w M4 x8 K, E9 y
-
; r& z: l) f8 G0 X ?* e - LDA #>MUSIC_INFO_POS
3 p2 A' A- ?( ]1 W/ v4 w - STA Use_PPU_Buffer,X5 \9 k# n4 B, M) O8 `
- INX6 Z$ ]* A }# U+ }$ o
-
9 s9 t$ `7 [& M# l5 J - ;居中8 N8 D2 K& ]" l0 |& t- Q% a
- LDA #<(MUSIC_INFO_POS & $E0) + (32 - 5)/2/ s* m1 _9 J' G: p
- STA Use_PPU_Buffer,X; G- S3 P4 }4 @ w6 E& L
- INX& t' x: `# C ]
-
' ?+ J/ g- [1 \- G1 v, n - LDA #$054 t& d& x7 \1 o0 z# V
- STA Use_PPU_Buffer,X
4 |# y; T: P z( k& | B6 a - INX0 K B9 M4 Y# }, ~+ N$ Y
- 0 d$ b7 I4 \% ?& }3 w1 Y; K f
- LDA FC_Music_Index3 A, ^) \- C& Y
- CLC
: x6 A5 V1 l( S+ n1 h& N - ADC #$01
4 x2 ?( c5 e( O F8 a - JSR Hex8ToDec
( Q; G! U1 E# i -
, ^+ Z+ N* O D - LDA FC_Dec_Data_10
) t+ ]6 s2 [' |6 g - CLC
5 B/ g& K) e& p0 D - ADC #'0'
& B. z0 m( e5 P9 T& ^+ E - STA Use_PPU_Buffer,X
* t3 J4 }+ Q7 J7 \0 L9 Y/ M$ @ - INX
$ o* ~0 c* X3 n' n, a- R* p( T - i3 d& k' f0 N+ \9 j; A0 m+ f5 d
- LDA FC_Dec_Data_1
& y$ y* E7 p) ` v: h - CLC
) V0 Q7 {- {6 ?: H - ADC #'0'
$ O3 }& Z Q/ Z9 E6 e - STA Use_PPU_Buffer,X# a4 {" p6 G# A0 ]# ]
- INX; q! P) a% l. U
-
" k/ k9 f' c/ h* t - LDA #'/'& n I* m+ \2 b% y
- STA Use_PPU_Buffer,X, v/ U6 \6 F3 T7 S
- INX
3 n y$ M; u: Y" n - / K+ ?! c" l3 Z7 G$ z
- LDA FC_Music_Max_Index: |6 p! \! g8 X1 E& Z, D \
- CLC
9 V4 q* C% W% f, Z6 U7 O - ADC #$01
# e; [9 B/ r4 D - JSR Hex8ToDec
0 _$ K, _" x. i1 D; |6 j) { -
# F" y4 R1 M! d - LDA FC_Dec_Data_10
7 j, @. I! F! M) i. F- ^; e+ G - CLC# o2 i3 t& u3 ]+ ?5 v
- ADC #'0'
! h/ Y: q* C4 N! Y- t) Y9 w - STA Use_PPU_Buffer,X
; a# E, q' V5 W- Y - INX2 [4 Q |& E3 i! O
-
+ U2 p# t8 \5 Q- J- z - LDA FC_Dec_Data_1
. d! M6 n7 |, j S/ b7 l5 z% {2 B - CLC: x2 ] u/ U4 e( C$ p
- ADC #'0'
- g& W1 D4 q c# z/ Z2 S+ n7 m - STA Use_PPU_Buffer,X/ N$ d( d" K4 x+ O
- INX
N/ C! q7 k1 K- F/ q -
+ c6 v' H( Z! ^9 q3 ` - .End
: y% Y% j" P+ u, |8 m - STX FC_PPU_Buf_Count9 Z2 m' f* |1 G) j D
- RTS; v6 T2 V! Z8 R) c9 Q2 W% X
- 7 f! }4 e/ A" }2 |
- ;----------------------------------------------------------------------* z; m4 Z. S3 r# |4 J0 ~! L* W
- ;音乐曲目初始化处理* v6 C. n3 O# Y- d1 I
- Music_Init_Process( C$ X2 I, w' p
- PHA
$ P! }5 F! t- c+ }9 Z - JSR Music_Clear_Process
' A/ _" X/ W R4 A - LDA #$1F
6 ~6 H/ D: C' x r2 x' Q - STA $4015
& O4 r h. @2 d7 s. Q - PLA
9 W" y: q' B, _1 x - JSR Music_Init_Addr; d4 o* V/ H+ s# P( v
- JSR Music_Info_Display
' Y5 W7 ~- |1 p' Y - RTS
* Z$ C9 Q! k* b" j9 Z
4 ?! p& M8 O! Y- ;----------------------------------------------------------------------
2 S( a$ z+ Z: Y; |2 D8 ~; b - ;音乐播放处理" X/ Y: _( b I% h+ C
- Music_Play_Process
: f9 U4 ^( y F) M - JSR Music_Play_Addr" Y2 M2 L6 o/ z8 l/ }
- RTS
5 q2 @8 S5 I" i U. F
8 J0 Z2 m" Q) G$ D- ;----------------------------------------------------------------------
3 u/ V# s9 j& B6 {, g$ { - ;音乐播放处理
4 I) B' d" W+ G" z9 r - Music_Clear_Process: C8 {% I B& N- C) k H
- .IF Music_Clear_Addr
1 W! q. K# n% C& R( E3 f - JSR Music_Clear_Addr, }1 S- ~6 r/ O/ m) {8 D
- RTS
* n. e- B7 a, z, S - .ELSE _( `) H& Z; [6 e+ R) l$ \' ]
- LDA #$1F# o& @& w& g) } S( }5 Q
- STA $4015! z4 m. x! y5 b# H
- LDA #$00
7 I3 s z S) a9 a; X8 H0 Z) e - STA $4010' ^3 Z: H& ]/ _
- LDX #$00
7 C% H8 i# v0 T+ X7 r$ o: q - LDA #$00
3 Z8 n) z: }, {5 M4 y. h5 L -
2 R" o9 p7 ^& u8 }5 m - .Music_Clear_Zreo_Page_0$ m; H; a! F, o' E0 Z
- STA $00,X
7 [$ W: R" p& @0 |/ l8 y - INX. }) }7 j& T8 P- c; N
- CPX #Use_Zero_Page_Begin, z! R" {0 j) n4 U- H3 L6 b
- BCC .Music_Clear_Zreo_Page_0
7 G2 ], s4 y: u( H% { - U9 C4 |3 J6 A5 p
- LDX #Use_Zero_Page_Begin + Use_Zero_Page_Size
/ h( Q) w a! x+ Z! q0 b - .Music_Clear_Zreo_Page_1
7 L% o$ P" ~+ q5 f, z - STA $00,X
! `& Y" L* P, ~, M; ? - INX" t/ I# r2 G& S: l! K
- BNE .Music_Clear_Zreo_Page_1
" G! d7 z# i0 a* _/ B6 Y -
* T4 L! l( V1 _, o% W) k, g) b$ q8 ^ - Music_Clear_Process_1" m7 n/ _- ~+ [" F8 y Q0 y& d
- STA $0600,X
' L2 n1 x3 I3 k - STA $0700,X
y8 m4 F! ]; O% |& O - INX( k- Q( ^7 X( L/ _! J/ ^
- BNE Music_Clear_Process_15 K, x, A6 f9 d3 \1 P, c+ ~1 u
- LDA #$10
: G& F l( H) j/ ?/ P - STA $4000) k; e0 a& I! `+ ^9 M* ^
- STA $4004
% l" y, Q. O- e: Q" a" @# [+ m' A& b - STA $400C
; i) H1 ]& w8 R$ f( j - LDA #$000 B! Q; k* I( { |6 ]+ O5 _3 [* j
- STA $4008. _( q# q; U K
- LDA #$0F
! M4 B! r. Q5 ]" ^ - STA $4015
9 J4 m6 v' B0 l$ C, y6 | - .ENDIF
, E |5 g; U/ g, [% K: A% K$ W -
8 r2 H0 z) R4 @6 } - RTS
0 t3 F% {, g" Q
6 ^9 Z5 } a- Q$ ^- ;======================================================================4 d) G5 G ?$ }7 P4 x- _( h
- ;重启处理
7 i. b% Q8 z; h! a% _ - Reset_Program: _* P, `% k* [
- SEI
5 {3 v: }6 k$ D, W( i, c3 q$ D - CLD
& ^. |) |6 ]& n/ r. b$ h! X - LDA #$000 H- r# ?6 s8 C1 x; a; n' o
- STA PPU_CTRL
! K: q+ H' B3 z+ p - STA PPU_MASK
* v8 G# ^8 k7 E1 b2 ~ - STA JOY2_FRAME2 s& I, ^( F( I) x E/ @& I
- STA APU_STATUS7 j h( a% i h; B* {
-
" N: S, P9 n4 R/ y. O" B - ;等待屏幕准备完毕, J$ _, f }" d2 N/ }, a
- LDX #$02) E4 j& x4 p0 @. g& n
- .Wait_For_Screen_Ready
C% s4 Q N" P& c& w' y - LDA PPU_STATUS* D) L0 U3 G5 }. h0 V. J T, t
- BPL .Wait_For_Screen_Ready
4 b/ I8 }0 [8 r6 y - DEX2 L' T7 f% Q8 V) L& {7 J3 K. {
- BNE .Wait_For_Screen_Ready! |2 |0 B/ e, h# Q- K- Q' S
- 2 r) l% {5 B Q
- ;清空调色板9 n8 U$ c) w; j% b- c2 k
- Palette_Clear. ~( W0 F4 M- U5 P: J/ Z* h
- LDA #$3F D& {* |6 H' J2 Q5 C9 C3 D" O! K% l
- STA PPU_ADDRESS
a5 w/ Z* Q- s5 P - LDA #$00
) v+ w, C- A( S8 R - STA PPU_ADDRESS4 [# b/ ]7 S9 ]
- LDX #$20* o( C6 w: S7 H0 U6 m
- LDA #$0F" K% F2 i3 t% S
- .Write_Data
y6 t, i. ?- H; x0 ~7 t" v, E5 _ - STA PPU_DATA
- p- M r" t! u4 C# z, M - DEX3 o3 X0 ^5 P, q# y( \- y
- BNE .Write_Data) H7 l: g3 D. j; J4 _- C4 I8 u
- : e/ G* H" G; f% I
- ;清除声音 $4000-4013
$ x7 N9 w u, }& m3 P8 c - LDY #$146 L; N$ w) A4 i5 H& c4 j1 d! Y a* @0 m
- LDX #$004 o) B; _! K1 L% q2 }2 @. U; S- z
- .Sound_Clear* w3 E' T2 y) u" W3 f
- STA $4000,X, _+ M; f: ]; w& q' w! Q
- INX; ^5 d4 n6 ^+ X- b4 L
- DEY: G2 y) o2 v5 b6 l; N1 p
- BNE .Sound_Clear$ ?6 Z* Y( D* [, e0 _
- q$ r5 O+ C% Q; s$ C0 s! a* D* K6 w
- ;清除 RAM $0000-07FF
! S b4 S9 y! y - LDA #$001 I# m1 z1 l& J, {( D+ {* e
- STA $00. g$ o# g" @; E7 B- w4 k0 T: U9 }
- STA $01/ r& V l( k+ G# }- s
- TAY
- T% y9 H6 T* S. e* P- j' w& o: M( o - LDX #$08
% M3 C# C( a/ d0 z; u, x" R4 I - .Memory_Clear; o4 M5 @1 O: A
- STA [$00],Y
4 y0 s* v/ ^& f - INY0 e! _$ \5 r% z- h6 O
- BNE .Memory_Clear' @# d( r9 V: c+ r; G- m
- INC $015 g% o _& @2 F8 V/ V2 q6 n& X
- DEX
7 i: ~8 O0 E- f" z: L W: J& w - BNE .Memory_Clear+ H' w! Y6 v6 D, W1 @" u* i- ?- ?! S
-
B/ C- F# A) @# I. d - ;精灵缓冲初始化
9 R3 p6 E5 O( q - LDX #$00
7 k* f1 p9 l* [9 q; j! @* o - LDA #$F81 E# T' d( G f8 C% t
- .OAM_Clear$ x6 V) t1 c2 W
- STA OAM_DMA_Buffer,X1 l6 B0 A7 E% P, E& t& t$ H
- INX
" p3 L9 X! I- _9 d0 d5 B - BNE .OAM_Clear6 C1 r2 c# z' `( k2 U: B
- / e0 H/ Q# [7 x. q
- ;栈指针初始化' N0 b' `6 L5 H0 r+ K, ^
- LDX #$FF
3 W) O5 _- v2 n& g' @ - TXS
' z8 F3 |6 Y" W4 Y: o% ?9 [! R; q - # {6 @; b! \4 S( w- x
- JSR Nametable_Clear;命名表清空
; r+ [1 c4 ~4 u5 U p0 o6 _6 H - JSR Palette_Init;初始化调色板缓冲. X) p1 L9 `2 a
- JSR Static_Text_Init;初始化静态文本
6 ]" @" \# y* G -
# g3 D0 i' Y! E2 a - LDA #MUSIC_ITEM_TOTAL - 12 l7 G I; t) H! ~; f- \
- STA FC_Music_Max_Index
) L' c( w8 m/ R8 a& v0 s' d9 T$ X - 9 Z# m$ D v C8 G' o/ z, Y
- LDA #$1F
5 k2 ~! ~& \4 o! F- `7 P+ X8 G - STA APU_STATUS6 F7 ]( \# Z2 T8 Y" a
- LDA #MUSIC_BGM - 19 @( X- t5 w; N ^* X! Z
- STA FC_Music_Index
; X0 _# M) T$ k9 y# A* C - JSR Music_Init_Process;音乐播放6 D+ ?; b1 N; v2 ?
- ' D ]- o5 M% S9 T
- ;设置屏幕显示状态缓冲(当NMI处理时控制屏幕显示状态)
$ x9 W, T8 H. c - LDA #$1E
( Q1 T/ L! ]# p. E7 U8 m - STA FC_PPU_Mask_Buf4 [8 S" ?4 M' [# W3 ^+ T F
- + j; \2 }5 p# X( t% a2 W3 o" f: B
- ;启用NMI处理- @- A+ Q" d0 {3 T3 Q2 m/ ^' {
- LDA #$80
: c- J: {: i7 O; ] - STA PPU_CTRL6 V4 W% v7 q2 B n" L. a
-
& z ^( x+ j- e* q# _, J - ;程序循环, 剩余工作交给 NMI 中断处理9 z! R9 |7 T5 _
- .Loop: Y6 @& J1 Z9 A' g
- JMP .Loop
. T N. V4 p! c" s - * H( i$ ~" E9 F
- ;======================================================================6 ~- V8 ?) S) `" @8 b" Y+ S' S
- ;不可屏蔽中断处理
& z1 w9 |4 J! F) _4 k - Nmi_Program7 l" e5 Y5 l+ u
- PHA
- } H: D8 o1 M6 v& \2 d' | - TXA2 ~- H, X, T7 c+ D
- PHA$ \6 T3 d! a$ ]) Y
- TYA
- h$ j" ?8 q8 N' Y- Q - PHA
: @" }. u# v+ z7 p+ O -
: v* p5 d# A: u1 V* Q - LDA PPU_STATUS;读取使得 PPU状态寄存器复位
& o- s1 j( U- f& V: M# {5 H -
# G5 {" x; h4 i4 E" { - JSR FC_PPU_Procrss;PPU处理2 H- [9 Y9 j7 B- s$ o* ^7 s( N
-
u7 D4 {9 }$ X. j* l: o - ;精灵内存更新
' P8 T% i3 y8 {0 s: C/ G% \/ L - LDA #$00
* A' W3 _5 ? s; _ - STA PPU_OAM_ADDR
$ r3 D; [. ~- F" L9 P- C - LDA #OAM_DMA_Buffer / $0100/ h3 C! B) l0 r
- STA OAM_DMA( A1 p/ Z* y1 e6 b4 h
-
& M' g6 f+ _& `* o, R, _ - JSR FC_Gamepad_Process;手柄输入处理6 S( N; u: x4 `
- JSR Music_Select_Process;音乐选曲处理8 k: d4 C! H9 M
- JSR Music_Play_Process;音乐播放处理 j/ F+ ?# p- \7 m
- ( t8 Y* F6 C& B
- PLA) ^; t! f9 ]1 {4 I7 r
- TAY
# h; K& A* {5 Q+ q# k" e - PLA1 Z5 H1 A7 v0 C& V! z$ V2 q) ` D
- TAX6 S2 ] V. h5 l1 y7 S
- PLA
& q. ~4 E- I) p# r8 P" t* u0 d - ; v9 ~7 \; F( n
- RTI
# f2 ?- z' g' ?% b: w5 ^* I - 3 d0 g! x) C8 g1 r3 `5 G1 T$ p# F
- ;======================================================================
) b T j, ?' T0 T% H6 K8 c; N - ;请求中断处理
# y: W4 p0 a1 O5 s5 h - Irq_Program
/ m. n1 [* W' `' i+ ^ - RTI2 k- h* x; B5 f* `1 H
, y5 b( P% R7 h4 t$ S# D0 v- ;======================================================================5 x' ]" `2 b" n) |8 u9 O R7 i
- ;中断向量表6 h9 J2 d/ o9 m: z4 l* _
- .ORG $FFFA
& _+ |3 {9 x9 W! f8 y - .DW Nmi_Program ;NMI触发时执行
3 S* b7 }# H; A x3 g1 j - .DW Reset_Program ;载入ROM时最先执行% f8 B, V4 K# p
- .DW Irq_Program ;IRQ触发时执行
5 h! k1 ~+ M! P: F6 @& K
复制代码 1 P9 z0 ~3 e+ u! j. @9 a& ~
5 U; y2 b) n. n% O, D% p) R& Q
" s+ j" f; V7 I- X/ ~' w U( {https://gitee.com/flame_cyclone/nesasm_3_2 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
1
查看全部评分
-
|