|
这是个 nesasm 3.2 入土教程, 感兴趣的可以研究下1 V- m6 o. j0 _9 K
; g9 c: M, Z$ \( X" Y+ E) L2 W
以下是主框架代码:
V- L5 _( [1 L) z$ K/ x/ q- @" o- ;======================================================================
9 l4 B F( q. _& U% @( v - ;文件头 H8 f4 k. [" k& c4 |1 U# {% _
- NES_16KB_PRG_SIZE = 8 ;16KB PRG大小数量4 j# y2 X2 q" S' t1 A- G5 w
- NES_8KB_CHR_SIZE = 1 ;8KB CHR大小数量
) a" N8 G, O1 f4 [ q) ? - BANK_DATA_MASK = NES_16KB_PRG_SIZE * 2 - 1 ;bank号掩码. q' I6 ~3 Y/ Y; d+ E
- ;======================================================================
* `2 j9 C. } ? - PRG_DATA_BANK_C000 = NES_16KB_PRG_SIZE * 2 - 2
+ h1 R5 J M3 V1 R8 j - PRG_DATA_BANK_E000 = NES_16KB_PRG_SIZE * 2 - 18 Z% O! T) V) X6 h' V6 n4 E4 o
- ;======================================================================: }9 j9 [5 C" M7 m9 D/ w
- RESET_BANK = NES_16KB_PRG_SIZE * 2 - 1
5 W2 ]- O( ?& S) e. k - RESET_ADDR = $E000 ;主程序起始地址
3 i2 v7 K3 o) T$ [' _9 e& d% D/ l - ;======================================================================2 c0 _. o! q4 t
- .INESPRG NES_16KB_PRG_SIZE ;16KB PRG 数量, $01-$EF8(1-3832),即16-61,312 KB+ x/ q$ B. Q9 p' _) c. j
- .INESCHR NES_8KB_CHR_SIZE ;8KB CHR 数量,$01-$EF8(1-3832),即0-30,656 KB
$ { z$ G4 K% }+ u) G* x3 t9 I - .INESMAP 4 ;Mapper号 (0-4095)
' t" p, T8 I3 R5 u; S - .INESSUBMAP 0 ;子Mapper号 (0-15)
0 z! z4 a: z- n; j/ P - .INESMIR 0 ;命名表镜像 (0: 水平 1: 垂直 2: 四屏)4 {1 l2 y& @5 R9 d3 ~7 j f
- .INESBAT 0 ;指定是否存在电池备份 (0: 不存在 1: 存在)
6 E; j9 v9 C: b e1 R: f! I6 j - .INESPRGRAM 0 ;指定 PRG RAM 大小 (大小 = 64字节 << 计数)
3 P# o n m) S: ^3 o! Z - .INESPRGNVRAM 0 ;指定 PRG NVRAM 大小(大小 = 64字节 << 计数)2 y( C6 _4 l/ }8 v0 B4 f; w
- .INESCHRRAM 0 ;指定 CHR RAM 大小(大小 = 64字节 << 计数)% ^9 s3 D- N) R: a+ P
- .INESCHRNVRAM 0 ;指定 CHR NVRAM 大小(大小 = 64字节 << 计数): N; z; K+ h6 h$ B# L
- .INESTIM 0 ;指定时序 (0: NTSC, 1: PAL, 2: 多区域, 3: Dendy)* {$ b6 v# {: L5 w6 I
- ;======================================================================6 Z* n# L6 J0 s
- .INCLUDE "fc_demo_config.asm" ;全局配置( L" \3 X+ X; Y5 W6 [5 W
- .INCLUDE "fc_demo_constant.asm" ;NES常量. W9 a/ D8 K3 ~0 ?0 H' e
- ;======================================================================8 L+ K2 ~$ T& k( V
- ;音乐配置
' R2 n. D; p0 [! \" {4 W - .IF 0 = MUSIC_THEME 9 @+ m' t, X( j/ ], a
- .INCLUDE "data/music/Gremlin 2/config.asm"
+ a" H4 k8 C% H) o, S5 H+ Q/ T8 F - .ENDIF
0 o1 T% {7 d* R5 q0 R6 S2 e7 ] -
H, M/ [ w4 y) F5 [% F - .IF 1 = MUSIC_THEME+ h, S4 l' |) ^9 D- s) n; ^
- .INCLUDE "data/music/Raf World/config.asm"3 C- p( T+ t- \7 [' t: ^
- .ENDIF1 H! r) K. y* `
-
5 l; D2 B( T/ Q& e - .IF 2 = MUSIC_THEME
! `7 @3 |5 Y) N: m7 i, ~$ M9 a: C - .INCLUDE "data/music/Ninja Gaiden 3/config.asm"
/ a }& |( q" m7 x! u( s: R - .ENDIF7 `5 X3 k3 ~* O; q$ T* I
- $ l) y* @' }; n( d! R
- ;======================================================================
0 N4 t3 X, i, C6 @2 K - ;引用CHR图像数据" j' i! }/ L$ |) t( D$ |) t
- .BANK NES_16KB_PRG_SIZE * 2- H: o' @5 h$ ?& N0 W
- .ORG $0000
+ \' i4 W0 I( B1 Y9 t8 s - .INCBIN "data/bkg.chr"6 m- s' k; ~ _. E" H j; y
- .INCBIN "data/sp.chr"
* Y# g6 k- }+ v3 E; T; k' j -
/ u( `& Z6 P4 T8 _2 k3 I/ x - ;======================================================================( O. X, s: K( J5 t
- .BANK PRG_DATA_BANK_E000 & BANK_DATA_MASK;设置程序所在Bank) g) h4 w4 T( B+ a& v
- .ORG RESET_ADDR1 i2 r) j' _* M h8 o) v" ?
- ;======================================================================
! A! H" }8 d% |' x& d! X - ;引用其他源文件; B. w/ P( R9 U, Q \9 `, N! D3 f
- .INCLUDE "fc_demo_ppu.asm" ;PPU处理4 x( p$ s: f( p* S7 Z
- .INCLUDE "fc_demo_joysitck.asm" ;手柄处理( Z! J/ X e& e/ Y) J0 F8 f6 }
- .INCLUDE "fc_demo_static_text.asm" ;静态文本处理
6 l' N1 N& E' i9 ~/ z3 A" d6 v - ;======================================================================
! [5 T2 X, [* G/ q9 W# k4 @
7 r; C% l" C+ M. Q. P/ V- ;======================================================================
$ N$ a% r; w* l1 e2 o" M - ;等待VBlank到来
; }7 J* K; l5 o4 b7 @ `$ o. z Z - Wait_For_VBlank0 _; M2 h4 |: n2 I! o9 r. h$ p
- LDA PPU_STATUS7 }0 ?, E, P4 _3 {% U1 ]
- BPL Wait_For_VBlank& B6 G1 H. I! @9 C0 t1 u3 c
- RTS
( Y+ a J3 Z! f* i
3 p5 Y+ K" J9 e, _3 R) a- ;======================================================================
# M1 }# k2 w) O# j% O - ;调色板初始化
, r, n: b a. F7 g9 Z; _ - Palette_Init
7 z/ y/ P z8 j; Y1 s - LDA #$3F
; O5 A! o2 |8 U* h {' a - STA PPU_ADDRESS8 _, M! x3 |' h1 `
- LDA #$00
5 K/ h5 }- x/ i - STA PPU_ADDRESS; V! \) z% y4 i1 _" H* W8 h
- LDX #$00' ^; |: `! k2 M3 s# s; \$ O% p9 s
- LDY #$20& ]! C' n1 ]: q6 M' t
- .Write_Data- K# [ G7 b0 q3 [8 L6 r& {
- LDA Palette_Data,X
8 G/ ~" s% Z% {# J2 V - STA FC_PPU_Pal_Addr,X
0 Y6 o/ e6 V1 Q B z - INX
" z/ {0 q9 \2 `1 k2 a, x" H - DEY1 H6 v: ]) S1 M: P& _, _, Z
- BNE .Write_Data
]+ e H1 ^1 O2 ] - .End4 @9 ` L) E' _. w: {, p
- RTS
4 P: ]3 i7 G. R8 P4 d' H5 ?; k - " d, w3 E$ Z7 B: ~% N4 |; j6 ?
- ;----------------------------------------! `# w5 j- l, \6 V
- ;调色板数据% x. p- W( j' O
- Palette_Data
0 ]; _! A4 S! @+ R9 F - .HEX 0F 20 32 02 0F 20 32 0F 0F 20 32 26 0F 1B 0F 1B7 S" d D2 w' H# p7 D; k
- .HEX 0F 21 27 22 0F 24 24 24 0F 21 21 21 0F 22 22 22- z2 e* [8 A: F+ v, c/ p
-
2 `2 `3 y" d# _' V" X/ ^ F - ;======================================================================6 b4 L5 Q0 z) I9 m0 q+ ?, {4 p
- ;命名表清空" w; x4 |: v! |9 ^* S% u6 p
- Nametable_Clear% @/ ~8 S y: P! ?8 M3 e3 I
- LDA #$20/ `/ J) {& O8 |# x, {
- STA PPU_ADDRESS- I$ J Y& U/ E2 X* A6 ?
- LDA #$00, I' g4 z& d' Y9 [; Y$ L$ U
- STA PPU_ADDRESS
! F& n, ? }! R8 l& x! \ - LDA #$00( M* W6 }2 {: {/ y1 @
- LDX #$00! ?4 n* \& Z. O m
- LDY #$08
( ?- i) j8 o* r4 _7 ~ - .Write_Data6 b3 Y5 R2 K+ V7 x" D& @
- STA PPU_DATA: J3 G/ c/ f4 C2 [) O
- INX+ x3 B' u" Y( X
- BNE .Write_Data
5 a6 h! a* r: K4 R - DEY' `6 f$ i* j. T0 g1 c4 A3 ]
- BNE .Write_Data9 m: K! L( e# S& N' r7 a: B
- .End
- M/ v" D5 j3 H/ [( l - RTS
* n# {, p3 A- K0 V/ }0 h% R6 E7 k - 6 W: M( x8 ^5 n. z4 g
- ;======================================================================5 Y% l/ A% j) c1 B1 h& a9 t6 u
- ;音乐曲目切换
% a( u0 [6 m# {) G# ]% Q. D - Music_Select_Process) I2 f% I2 f2 d0 z& L$ \! L
+ G$ I' L3 U8 q u7 E* S: l* z i7 ^- .Pre_Music;上一曲
4 n5 q3 n6 n6 ~2 U+ } - LDA FC_Gamepad_Once& r. Z" f5 C) s% M, Q' H- P
- CMP #JOY_KEY_LEFT/ D( b' j, _1 o5 P7 C" X: q
- BNE .Next_Music
9 L( t& ~5 _6 Y+ g3 K+ ` - JSR Music_Play_Pre
" O; e" K# {: \9 \, ?* i4 @- D - .Next_Music;下一曲
, `" M1 |& G: |8 u - LDA FC_Gamepad_Once8 H9 r9 t) w* g5 K* j
- CMP #JOY_KEY_RIGHT
8 {, G7 S/ }, B - BNE .Next_10_Music! \0 k( R1 M# S2 X
- JSR Music_Play_Next: [0 }* u7 ]5 S8 R% ~
- .Next_10_Music;上10曲* U B4 E8 Z' I k4 O
- LDA FC_Gamepad_Once# T2 P: U2 w/ P9 U
- CMP #JOY_KEY_UP) Y- {) q4 O. Q" v. ~9 K
- BNE .Pre_10_Music
Z# M4 W! Y5 c. P - JSR Music_Play_Next_10
7 R/ u" N, M/ t6 O& H4 S% ]& P - .Pre_10_Music;下10曲" L7 G" z0 B; n" z
- LDA FC_Gamepad_Once
, G2 _' A5 w0 s9 X6 k8 Y4 @ - CMP #JOY_KEY_DOWN+ W* b7 ^6 s9 Y8 p* T3 \8 [8 g3 |
- BNE .Reset
9 N, O/ L6 W! Q. x* C/ H4 I% t - JSR Music_Play_Pre_10$ @7 U7 s3 X- x7 L+ A8 p8 a4 E" i
- .Reset;重播当前曲目/ ~& i+ o0 E0 G" B! Z* P
- LDA FC_Gamepad_Once
9 X# x- K7 |4 w; S; O - CMP #JOY_KEY_START
/ x! s5 G6 s6 d* I8 L - BNE .End6 b0 Z [' x. Y/ i2 ~: G
- LDA FC_Music_Index
6 F& s3 y8 t, Q: o7 p - JSR Music_Init_Process. T' V8 B5 F: [8 K8 M
- .End
5 x2 w' Q% x1 _' }) b2 E - RTS3 B$ e& @ F/ }! V! c
. {8 R2 J( @3 A+ M! l* Y( x- ;----------------------------------------------------------------------
) g K5 J( G# A2 a4 B* v - ;播放上一曲- a4 P, Q- q, C( W$ u. F
- Music_Play_Pre
* z1 q w" P3 i. e } - LDA FC_Music_Index% _' H T n Q% X
- BEQ .End
9 N& s0 Q0 u' P" J. G4 y7 z0 }! q - DEC FC_Music_Index' D5 f0 g2 ]: b, C
- LDA FC_Music_Index
: r: _( I) L' ^1 S' t - JSR Music_Init_Process
" H( K2 X$ L+ t9 ?4 F* U7 w: z - .End5 I) R& w6 U( a1 \! b: I
- RTS; }# h, O: w" U% x+ H% o
- ;----------------------------------------------------------------------
7 T: M5 H, U- @" X - ;播放下一曲
0 d; y+ }2 U6 C4 H" e! ^/ r - Music_Play_Next
( n: Q# k1 n1 W7 T( a: E( \ - LDA FC_Music_Index
% j8 x( k0 E4 s - CMP FC_Music_Max_Index
) J! Q) U0 O n" _! B/ _( s9 R - BCS .End4 G) ], p8 m) s
- INC FC_Music_Index; Q+ Q% s( _. X0 h
- LDA FC_Music_Index
* |( K* A. R7 b1 p2 L r - JSR Music_Init_Process
- L! f* ^$ u( ? f - .End
\4 W6 C6 g( Q" Q- C$ F0 U. q7 J - RTS9 w9 J- N. y. m( C/ Z
9 d7 g% [1 w0 \" H1 ~- ;----------------------------------------------------------------------
- P H" Y! a F8 ]" D - ;播放上10曲
1 m9 o& F8 G6 X' F7 e7 K: b J* W - Music_Play_Pre_103 j8 K8 \- Y8 V" f. w
- LDA FC_Music_Index; t. ~: _" t5 N( N P+ T) R
- BEQ .End P' z( H& Q) Z/ }
- SEC( } g, p2 d& o: W5 T% Q
- SBC #10
1 D9 R. v* L0 } Z! W6 X - BCS .Pre_10+ K& ^1 I3 H- A! }. D; B
- LDA #$00
: h, Y* P I" p R, H- ?! Y+ H - .Pre_10
1 M0 q% Q4 }8 \" }5 U - STA FC_Music_Index
% ?1 g: l" a3 d2 A - JSR Music_Init_Process
; W# f0 T+ s* d: k J" `/ {) q - .End
+ n" p) G9 ^7 Q6 n5 V. k$ ^4 V - RTS2 A" ` J, V# o: B
- ;----------------------------------------------------------------------) O# y3 T! @; g v- i7 k/ k' `
- ;播放下10曲) ^" z/ b2 o; G$ v1 J }' q7 @
- Music_Play_Next_10
+ \8 B+ v, m1 J/ C - LDA FC_Music_Index& j$ [2 e8 \: }% ~( A5 P
- CMP FC_Music_Max_Index7 g3 U. ]0 j# s9 w8 J8 l
- BCS .End& [6 Z# K+ K" a3 t
- CLC
9 H! F; H$ o% Y5 _4 I' H - ADC #10( j- d) \' |8 C
- CMP FC_Music_Max_Index
' n2 w6 j6 U5 r/ i2 F5 W% \& g - BCC .Next_10
, C& q' K% `! [ - LDA FC_Music_Max_Index
- l( }1 R; M& J( ^4 h+ Z - .Next_10, C: \2 m) `6 @
- STA FC_Music_Index
! c) [$ z3 z! b/ [, Z& j) G y0 u - JSR Music_Init_Process
f) J- X: d/ s4 q - .End
" C) V, S6 Y- {7 A3 }6 Q - RTS7 r( [0 u5 p8 V6 ?
. T& Q8 {. E; N+ I- q/ K% h, v- ;----------------------------------------------------------------------
; m6 {0 y% d4 f: k4 a: ^$ u9 L - ;8位十六进制转3位十进制制
5 }, G, l$ N/ i - Hex8ToDec3 y4 K# o) S, U6 R
- STA FC_Dec_Data_1& E; j+ V7 N4 F2 Q! V9 @
- LDA #$00* t7 g' M3 F: M! ^; y; r
- STA FC_Dec_Data_100
% G/ { w8 k' B2 _: ] - STA FC_Dec_Data_10' r0 W5 ~" u% M
- LDA FC_Dec_Data_1& {4 o a/ n" w d! ^' C
- .Convert_100
9 z% i+ F% G& C Q - CMP #100, a. T: }1 s, u
- BCC .Convert_10$ |: O9 T4 g0 n/ j
- SEC
% g) { K3 T- ]) G8 L - SBC #100
- H3 ?6 M) H, l - INC FC_Dec_Data_100
' T8 N" z8 D- e6 {5 L+ w* ` - BNE .Convert_100
d* @2 t9 y9 B* V6 i1 ` - .Convert_10
/ q8 W) f! S* P+ M) G* q - CMP #10
2 Z6 [9 ^/ z! q0 v0 V - BCC .End2 T- \6 I' p9 |4 u- w5 d7 f$ k
- SEC
) O% Z& Z, g. F8 I$ | - SBC #10
* [! |: g4 n( j* I4 K! O- i - INC FC_Dec_Data_104 q# v; ` u$ r, k
- BNE .Convert_10& ^2 ?/ |& @7 E! I+ F
- .End. v2 @, B( b8 M* |8 x7 v
- STA FC_Dec_Data_1
9 j: C" [# B! u D4 X6 J/ b - RTS
% |6 X& r: h* f- Q - S& s* C" I! f% M- y2 ]
- ;----------------------------------------------------------------------
5 Y$ i w$ u2 x' k; k - ;显示曲目信息/ [9 a& i6 F, N+ T+ H7 D U8 I
- Music_Info_Display
. V; b" K% q1 F; d" ` - LDX FC_PPU_Buf_Count
3 h& h# u% q1 x4 ?+ ? - LDA #PPU_WRITE_MODE_CNT_LINE2 Y$ i- z- O, n9 r
- STA Use_PPU_Buffer,X: O: C- X8 d# q! _
- INX
$ c, {. {0 P) y- u* V/ p$ z6 f -
4 u+ c$ {; N" Q3 C& ? - LDA #>MUSIC_INFO_POS' I* e7 w/ C$ L1 C r7 I
- STA Use_PPU_Buffer,X
q# C3 X0 C6 ~7 t- ^* Y5 j7 E6 H - INX+ m$ o: z! Y3 p7 [6 ]
- $ V$ ?; ~2 L7 ~" k8 D ]! a5 N
- ;居中
1 f( w5 K- Q5 v w$ _ - LDA #<(MUSIC_INFO_POS & $E0) + (32 - 5)/29 ~% Q9 K! X; \) t7 {
- STA Use_PPU_Buffer,X
( X8 f5 o3 F( z+ \$ Y! E - INX
2 a* E: _6 z9 W3 K( n/ U6 t - $ C, q. }/ D8 _ v
- LDA #$058 h% [+ S) \: p% m3 ?& U2 I) W
- STA Use_PPU_Buffer,X
1 [5 ]( M/ @( h1 j5 `& f: u, j" k - INX
3 K" J" j, F; W. ? - ! C+ ]4 A f% i6 L
- LDA FC_Music_Index
! ?! j" ]. d0 t# o# H: o7 O - CLC
1 V0 S- m* o! @- ^, X; q2 @ - ADC #$01
& l) ^, f7 Y2 h$ F' b. q - JSR Hex8ToDec1 x4 ]9 }1 B* p; C
- ) _7 o5 P( s {7 I3 H
- LDA FC_Dec_Data_106 ^( k) D& f9 B8 h. R
- CLC
6 z8 r" }9 J; R1 x f( v - ADC #'0'
7 b0 E1 M# i# d$ V- a - STA Use_PPU_Buffer,X
+ J' h7 n" E" {0 \ - INX
1 q/ ~) e& h. t6 L7 ` -
3 R+ P1 Y% u* e* I - LDA FC_Dec_Data_1
1 C' F9 E9 R6 o. H, C# l! U - CLC2 W9 W5 q# X% x
- ADC #'0'
3 g O, L/ f$ U8 J - STA Use_PPU_Buffer,X5 g& L) Q3 |" B2 C- T" U7 m r
- INX
7 e1 j" E% M8 P% Z -
. J, ]+ Z3 h7 \. u! b - LDA #'/'' w$ [) z4 S+ M
- STA Use_PPU_Buffer,X5 y* x4 o/ i& `! A) k8 S! a) B
- INX
+ F E( L1 {6 C" x0 O -
N6 Q4 P6 H c/ q1 \1 B6 Q - LDA FC_Music_Max_Index
2 p* ~# F3 U1 v3 a) f - CLC# I0 u. L6 t) p7 z8 N
- ADC #$01
2 s% E- V5 h3 y+ Y E6 J- W9 p - JSR Hex8ToDec" Y6 H W8 x/ _* e$ Z3 N j8 E
-
+ E! V! ]+ I3 h8 O Q9 s7 _. g - LDA FC_Dec_Data_103 D% s) m! f/ G2 v0 S3 Z
- CLC
8 F) n+ c5 ^) x' c/ P - ADC #'0'5 i& j4 S- ]# }2 U
- STA Use_PPU_Buffer,X8 m& G0 z: d1 t
- INX
/ ?( Z1 H9 L0 @# z- {3 N -
3 C; A' ~' E8 f2 u2 ?+ E' R - LDA FC_Dec_Data_1
3 I' f/ A! U+ ^: X4 Y( ?+ @& { - CLC
& b" Q: U8 C4 {4 p - ADC #'0'
# q$ ~+ C( {( m2 a6 q - STA Use_PPU_Buffer,X
2 u% y9 O/ \; H3 R - INX
" x* \ o# W) Q7 ]. L5 B% V6 B1 {, |0 w - 7 D G& O7 I7 i/ L+ G- B& m, z/ I
- .End! d0 K( f: ^- t/ V3 Q$ g9 G7 f5 I
- STX FC_PPU_Buf_Count
9 m) w) F8 `0 S0 q, o - RTS$ b6 [8 q- w7 u, P8 ]8 M
- V5 [3 K* |( t" H1 u
- ;----------------------------------------------------------------------, R, g- U4 V7 Z; m
- ;音乐曲目初始化处理
% B; f% @& m- _1 u - Music_Init_Process
: Z( c! g* G( T2 y* }" o( r0 P - PHA
o2 B6 L' o9 I ?# W - JSR Music_Clear_Process
0 z. V/ d" m: K2 K* |6 a - LDA #$1F$ b" i3 y9 Q% i3 H& _7 p
- STA $40152 J7 L: s& R Z$ P* W
- PLA2 N/ {1 r3 e" K) ^) L* a# r
- JSR Music_Init_Addr5 r5 Z4 E* z9 \( l) S/ h
- JSR Music_Info_Display
/ f4 K9 I2 `3 y7 r0 ~; J - RTS
6 d; O. C* Q- Y t g5 g - - a& C& W# A! \) f z8 X+ j
- ;----------------------------------------------------------------------# k) v2 Q' ~8 }; i. N
- ;音乐播放处理
8 t2 P' D) @+ Z O/ p l8 T - Music_Play_Process7 D4 w k9 E) `
- JSR Music_Play_Addr
8 k; E: J, l5 G8 ] - RTS3 x; ^" c" [/ ^/ I
- 0 S: D1 V% l: u& R" x! t" t9 e
- ;----------------------------------------------------------------------
# m( [& Z) `; _" L! S - ;音乐播放处理" A- ^: M9 H7 `9 X0 e: q
- Music_Clear_Process
3 C% n- r6 V7 f - .IF Music_Clear_Addr5 Y0 Q5 ^1 A9 d, [/ M/ i* z3 N, o
- JSR Music_Clear_Addr
* Z6 r& d( o8 y. r0 P! ]5 G0 p - RTS
% d8 J3 Z* |- f. l2 r; R# k - .ELSE
: R- Q. V$ T: R, a( n. s/ s - LDA #$1F
4 Q- d. C% f0 U- ~. c8 D - STA $4015 f @, a6 @: v8 ^( ~7 w
- LDA #$00% C0 W5 l% D9 C3 N7 E
- STA $4010
2 d' m O, z) v+ m i" \5 `1 I5 o# J+ ] - LDX #$00
/ |* D* _# y' t& c3 v7 D5 s - LDA #$00) f1 _3 B' Y& v1 c O+ ]7 ^' g
-
& W8 ]; R4 q6 ]" I0 s1 D - .Music_Clear_Zreo_Page_0
9 f& ]: k/ [; n. g4 {6 C. H* T: k - STA $00,X
9 \" b2 s: U7 T& p - INX4 O `7 k' t! C3 d# r1 H3 f, `
- CPX #Use_Zero_Page_Begin
: z7 B. g: C+ R/ m+ D6 ?* M - BCC .Music_Clear_Zreo_Page_0
1 }6 }1 `9 `& G, A O2 w* A* ] -
v/ ~ |3 ]2 K$ ^ - LDX #Use_Zero_Page_Begin + Use_Zero_Page_Size
8 J9 N |: c% d1 z1 C9 }* e - .Music_Clear_Zreo_Page_1" M& W$ F5 p% X( s# V
- STA $00,X
* V5 X3 Q/ k. M - INX
+ U) s; X% b8 Y9 M( x0 B - BNE .Music_Clear_Zreo_Page_1
5 [7 ?- W" P F& [ -
% I7 A3 Y. d8 ~4 E - Music_Clear_Process_1$ D6 V# i; f9 e7 G
- STA $0600,X
v/ V$ E( }* G; R \/ w: }3 c - STA $0700,X
6 Y8 |7 W) e+ M0 C [9 | - INX& x& I7 |# M |% B; r/ z& ^) D2 S
- BNE Music_Clear_Process_1
* Y+ g2 [0 s& R. |2 ~4 k! T6 Q6 m - LDA #$10$ B$ U/ A f, }! b# M/ m- [/ i/ K# t
- STA $40009 E* ]' V8 X& k
- STA $4004
1 V7 N* t1 b; y" r6 } - STA $400C& t- x. C0 @5 G, W2 I7 J
- LDA #$00/ ~" e- _1 ?) y( [7 S5 s4 r
- STA $4008
8 F8 E- y, K6 D# ~7 V+ [" V - LDA #$0F$ T- U- E6 C# J, f4 E
- STA $40159 E6 o9 j% s9 N, V9 b/ z
- .ENDIF
( x( P3 k2 ^" p8 n% K$ [ -
$ A6 _$ B* Y8 Q1 J2 x - RTS( d5 c! o8 H3 O! g
- 8 |) [- L/ R6 R A+ q' y- I0 [" [% o
- ;======================================================================' _ c$ t% b0 x3 X" T) I
- ;重启处理5 Y/ J2 r9 m8 |# O/ j' D- e
- Reset_Program4 H9 g5 C# O( c% [
- SEI2 H2 C4 M% ], q9 X G1 `1 D$ ]
- CLD! p7 J/ l9 T3 Y1 k
- LDA #$00; R5 ~ D' O$ b* |' I7 l
- STA PPU_CTRL
4 A( `- z2 V) x: |" J, \# o - STA PPU_MASK
9 g& ?1 M# s4 u9 A8 X1 K* D' S - STA JOY2_FRAME/ b. h9 _4 F E6 d& B
- STA APU_STATUS7 `) _" Y# C9 r4 ?+ y4 a7 \. T' _
- , v8 e# f" R: g: W3 a
- ;等待屏幕准备完毕
! j' a- o! y1 c( d. H - LDX #$02; V/ d# [8 H' b* j5 Z
- .Wait_For_Screen_Ready ]% @- o' K0 f+ T
- LDA PPU_STATUS2 }! V s, e6 H$ G
- BPL .Wait_For_Screen_Ready
2 `- b+ R0 L, m& \ - DEX# y2 Y) o3 z* r4 V7 a7 b4 S, w+ L6 d1 l
- BNE .Wait_For_Screen_Ready, T$ y* p2 P& _ ^
- ' d9 G( F$ J2 Y4 C9 K
- ;清空调色板* R- x3 F9 w8 E+ S8 ?. y* N
- Palette_Clear7 z6 O& V' T: W' B c8 l
- LDA #$3F
8 t) d6 k0 V) o' N e* Y1 x - STA PPU_ADDRESS
& E0 D3 y" _& Q* l# [* G; |! y - LDA #$00
0 [$ ~6 R3 y9 n/ i+ V1 R! |: z0 O - STA PPU_ADDRESS5 p( r& j8 y( B; K" X- l' F- f8 Y" U
- LDX #$20* }- \7 |4 G8 _! j( s/ O4 B( ^
- LDA #$0F: Y1 X. D9 r5 c. R2 g
- .Write_Data9 d r+ I# q5 W& s3 s
- STA PPU_DATA
. s+ @4 p1 z2 y1 S% D: b0 t+ Z - DEX
5 L* t& n2 P. ^6 e* G9 G/ X! y0 h - BNE .Write_Data
]* {1 w' P( S - }8 D( [) K* [- ]
- ;清除声音 $4000-4013
! w9 E( I( `+ Z' y) z" ?! J - LDY #$14
" ~- k/ k! w& C q7 u - LDX #$00
`3 z2 K# b/ M8 I% r - .Sound_Clear
0 ^1 x& U% {3 ]8 W7 B# x: g1 N k2 T - STA $4000,X
7 R; |# F3 H6 Z& t m' ~ - INX3 n5 C. G1 {9 M
- DEY
+ a/ B1 ~# t. W* s0 _ - BNE .Sound_Clear" v2 n/ j! _% Z* ?
-
* a K- n9 e0 E$ k1 c- j% C2 I4 r - ;清除 RAM $0000-07FF4 S+ D* v2 k. N
- LDA #$00( h( z4 F t6 Z; H; t
- STA $00
i0 v7 c& f2 W# m. k" t - STA $01
+ `( a$ ]3 f- k6 h: w, J - TAY
+ q' @$ m( y' Y% a7 E - LDX #$08
9 ~; P- y6 T+ @# i. G% Y - .Memory_Clear1 T$ `7 ]7 a' p# R7 N0 X. v% w; `7 w u
- STA [$00],Y+ {4 _- N! `2 U0 S
- INY
* b, F6 E( H7 d) \% g4 D - BNE .Memory_Clear2 z- y* Y) K! p; `" c0 J- {
- INC $01
9 R3 o# y. V/ ^" S- d - DEX
. H3 g5 a0 u& p7 k) D - BNE .Memory_Clear
& x9 s% n* n+ C6 @8 G& V - 9 w* x! }3 B0 e! l5 E0 t6 U; T M
- ;精灵缓冲初始化' {/ P1 r3 J5 d5 a$ |# e
- LDX #$00
C5 N9 e% i& a$ q - LDA #$F88 q4 G, h/ y$ S8 m9 w
- .OAM_Clear. t- n; i$ \# o( {* }) e- s
- STA OAM_DMA_Buffer,X/ y/ R+ \! N$ k* [; R
- INX
. ^% x+ B; \: S3 W, x0 e - BNE .OAM_Clear# s5 q' c/ f2 f: s
- ' q' u+ z* [: a; f* j& Z, E' Z e
- ;栈指针初始化
" z' M6 d6 u, K0 F - LDX #$FF
& V/ b) A. W9 T0 L( c* \; o- _8 _$ ? - TXS
+ P& P. j2 X& P6 R, r l -
$ S' M# X5 @) d - JSR Nametable_Clear;命名表清空: n6 f! q* j0 u6 |9 m, Z
- JSR Palette_Init;初始化调色板缓冲4 y' O: x( [9 b. [# K. g7 x- i
- JSR Static_Text_Init;初始化静态文本
7 o7 h6 B/ O. g' j% }& J5 v7 E -
. V; t4 D7 q+ S% z& v; W - LDA #MUSIC_ITEM_TOTAL - 1
- U X1 w4 D, u- ]! x$ A% J - STA FC_Music_Max_Index
: @% J H1 N8 s& z - 2 Z0 M& T" e* @; `9 z: c# f
- LDA #$1F
* b; Y M: K% N; @ - STA APU_STATUS
- f& X3 Y' k& J - LDA #MUSIC_BGM - 1
G: t7 D( `5 j+ y0 A3 ^( S: Q - STA FC_Music_Index4 G1 N/ Z& M, Z% S, n) {
- JSR Music_Init_Process;音乐播放9 T. O* @' W! E9 d* D) m; C/ C; |
-
, F* f! g1 A4 ~7 p$ E( w - ;设置屏幕显示状态缓冲(当NMI处理时控制屏幕显示状态)
9 K v% `9 N( ^ - LDA #$1E
' d' `! W3 r: X5 E! m" [; C5 Y6 m - STA FC_PPU_Mask_Buf
8 X' \# G5 m% G& m: _- L -
8 m( u; m6 S M, ^$ \! `% j1 N - ;启用NMI处理* |# H" @( ]8 Y; W
- LDA #$80
9 Q3 _+ g9 q4 h, W6 \0 a - STA PPU_CTRL3 ^0 t# _6 P: l& S
- + n# ^" Q0 O. H( [
- ;程序循环, 剩余工作交给 NMI 中断处理
& n; _% c- Z2 [/ X! X - .Loop
3 o; s6 ] P$ p) ~. P+ N - JMP .Loop
/ m6 [3 n- b: M' }$ L
- S5 q! t$ I4 N$ O2 ]1 D; `- ;======================================================================
9 \0 f& u- E! y& @5 q - ;不可屏蔽中断处理. W T2 t" `' K" v
- Nmi_Program; U, a$ w# a- c7 Q& d: E
- PHA
+ `; U4 F7 T2 }* B9 W - TXA2 |0 i5 }6 V" t7 L ]) l, u
- PHA% H; P# I$ g7 n7 e' p
- TYA3 ^- l/ q0 N# T+ t
- PHA
/ {3 y+ E3 f8 | I -
; d# q# y8 I7 A6 ?# j" J0 @ - LDA PPU_STATUS;读取使得 PPU状态寄存器复位
& K4 t t: F# z/ `4 c- h) ` - 7 ?7 x8 f3 L+ V P# F: I$ p; C: O
- JSR FC_PPU_Procrss;PPU处理
# _1 ~& W0 o$ y2 X3 ]3 u - 7 b" b8 O# o7 ]7 [- k+ ~
- ;精灵内存更新$ W8 J- r% U9 {/ N3 R1 R0 l
- LDA #$00
+ U. w. Y. W/ v6 ^+ S* P$ R - STA PPU_OAM_ADDR
0 Y2 k6 ~4 F6 D" } - LDA #OAM_DMA_Buffer / $0100& c: f" ]1 J1 `2 p: S
- STA OAM_DMA
& B1 @ ^/ A" t* B Q -
, W* b- Y6 b' w7 F3 a - JSR FC_Gamepad_Process;手柄输入处理+ [3 _* a5 D. @& D
- JSR Music_Select_Process;音乐选曲处理
4 ?. h. r7 ~0 A! f0 i: c - JSR Music_Play_Process;音乐播放处理0 [2 V7 G8 U# p2 M% u/ a
-
" y8 y& b6 ^7 u9 w, o - PLA- P( d0 n2 R) T1 y
- TAY
$ x+ r0 d5 Z; q S# P/ J - PLA
6 [/ o" B8 R- v/ M - TAX
( C o) x6 Y" A2 P0 z' ? - PLA
; J9 A' @, x. t
( F- |4 _6 e$ W& s; l( |) c( d- RTI, x- P# l6 R0 X: `
( }5 |7 m8 M' N! U- ;======================================================================8 @4 J0 F0 \* `( X
- ;请求中断处理
7 P( F# e7 \8 S0 i7 |2 D, B) T$ M - Irq_Program" X# @# R) o& R( \
- RTI
( \9 s: d' |7 z& O4 M/ V8 b - 3 h8 R! t" |2 S# E! h
- ;======================================================================
: U1 ?8 \6 w: u( h5 U* s* t, q' O X; E - ;中断向量表& d2 b3 F) A! @2 ?% R6 _7 D2 D
- .ORG $FFFA' p4 k* l" |7 [; R! q9 M; k
- .DW Nmi_Program ;NMI触发时执行
+ Q4 U ]7 z* t$ ~ - .DW Reset_Program ;载入ROM时最先执行: W+ N1 c! u# S, V: U4 d
- .DW Irq_Program ;IRQ触发时执行
3 j) J/ W3 E+ U8 F0 N# e
复制代码 ' w/ U' {9 {: M; O0 |' v8 T
* l! ? b9 O7 u! } ?
6 O) c; E$ n L. a& c/ Uhttps://gitee.com/flame_cyclone/nesasm_3_2 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
1
查看全部评分
-
|