|
这是个 nesasm 3.2 入土教程, 感兴趣的可以研究下7 j7 x* n* S: s( l U
6 Z; v7 }6 a# S9 |5 U6 _1 C- Z/ e
以下是主框架代码:- L* e3 s, F' @8 ?
- ;======================================================================
* _8 \, {/ k1 I; c P+ ] - ;文件头% V. e6 ?$ u3 F, ^7 f( l8 x8 \1 E( ]8 b) p
- NES_16KB_PRG_SIZE = 8 ;16KB PRG大小数量! o/ e/ M. J5 `
- NES_8KB_CHR_SIZE = 1 ;8KB CHR大小数量- @ n6 O; n6 |" z. {
- BANK_DATA_MASK = NES_16KB_PRG_SIZE * 2 - 1 ;bank号掩码
2 B4 E/ T- x! b2 g( z/ w8 ] - ;======================================================================& o2 p% _; S' l" ~. @# n2 s4 C# u
- PRG_DATA_BANK_C000 = NES_16KB_PRG_SIZE * 2 - 2$ F% L$ L( l6 y# {! B
- PRG_DATA_BANK_E000 = NES_16KB_PRG_SIZE * 2 - 1
3 _( o8 W& ]1 U& y0 K- F7 { - ;======================================================================
, K9 R' b1 l# ]. j5 c- t7 B - RESET_BANK = NES_16KB_PRG_SIZE * 2 - 11 c2 S: \9 x1 l2 |* {( W! B
- RESET_ADDR = $E000 ;主程序起始地址
+ k- D ?5 I% b5 V4 W - ;======================================================================. u8 a: q% U) e \
- .INESPRG NES_16KB_PRG_SIZE ;16KB PRG 数量, $01-$EF8(1-3832),即16-61,312 KB
5 U. r2 `3 H/ D6 |3 g* w! n/ [ - .INESCHR NES_8KB_CHR_SIZE ;8KB CHR 数量,$01-$EF8(1-3832),即0-30,656 KB
* z8 y# E8 @3 f3 X i - .INESMAP 4 ;Mapper号 (0-4095)
) N/ A1 r( a/ C9 A& n& b4 v - .INESSUBMAP 0 ;子Mapper号 (0-15) V' g; H9 C0 L, n5 ~0 V
- .INESMIR 0 ;命名表镜像 (0: 水平 1: 垂直 2: 四屏)
/ v( A: t4 s h! _ - .INESBAT 0 ;指定是否存在电池备份 (0: 不存在 1: 存在)8 b1 D. N D- _5 v- W
- .INESPRGRAM 0 ;指定 PRG RAM 大小 (大小 = 64字节 << 计数)
0 k4 L3 ^2 ?) [1 \6 g" c* d% {9 j4 \9 r - .INESPRGNVRAM 0 ;指定 PRG NVRAM 大小(大小 = 64字节 << 计数)
; c; k8 M& h% p2 ]' h: y - .INESCHRRAM 0 ;指定 CHR RAM 大小(大小 = 64字节 << 计数)$ w2 k; y) g" k7 C3 T# j
- .INESCHRNVRAM 0 ;指定 CHR NVRAM 大小(大小 = 64字节 << 计数)
+ w( E# @- `8 Y+ B - .INESTIM 0 ;指定时序 (0: NTSC, 1: PAL, 2: 多区域, 3: Dendy)
! g$ q1 K0 p& o( E0 E6 s: J5 i - ;======================================================================
) L* ^' B4 y G9 u9 q - .INCLUDE "fc_demo_config.asm" ;全局配置, i+ R' r4 u, e/ }+ X+ u& @
- .INCLUDE "fc_demo_constant.asm" ;NES常量9 I) \" T/ H: K" [# ?; R
- ;======================================================================" k1 D+ c* p3 @6 z }( `
- ;音乐配置
2 l: q/ f+ k% ~& d. i, a( \ - .IF 0 = MUSIC_THEME
7 q1 W# S3 H4 z% b( @ - .INCLUDE "data/music/Gremlin 2/config.asm"8 B- P- q: s& h
- .ENDIF
) g. |4 l1 S5 D( c% F3 D -
3 ]* Z) `- I6 _3 _, N3 i# ^ - .IF 1 = MUSIC_THEME, u8 ~. `9 _ L) [/ y4 l
- .INCLUDE "data/music/Raf World/config.asm"
& p7 C: \1 _$ s/ V! h - .ENDIF
/ X2 A; H' U) H/ F# X' T7 y -
# T! R' c' @3 C/ k6 O, }& H - .IF 2 = MUSIC_THEME
9 ?- v _, R, I, @- l; t! }" {. } - .INCLUDE "data/music/Ninja Gaiden 3/config.asm"
$ \ f, k4 a% u- @. o - .ENDIF
! ~% F# i, F' s r1 B; ]- E M - : o- |5 W% x) D6 Q# j7 o9 h
- ;======================================================================
3 U) t# q& M! P8 p1 f - ;引用CHR图像数据# k! f- O1 n% Z* S* _8 t5 S
- .BANK NES_16KB_PRG_SIZE * 22 R# ?( v% ~0 n/ [+ }
- .ORG $0000
6 R' I1 ?* Q& k m& O - .INCBIN "data/bkg.chr"* J9 h+ J' q4 h/ {
- .INCBIN "data/sp.chr"" c" k* d5 D1 h/ p) n
- % m5 c( X7 T% N& ^& X2 d7 m0 }7 N
- ;======================================================================
' P+ m0 }# c, [& P- |2 m4 v- r - .BANK PRG_DATA_BANK_E000 & BANK_DATA_MASK;设置程序所在Bank
6 e9 Q) a U2 o& y - .ORG RESET_ADDR: T5 l2 } P- `$ b! y& P
- ;======================================================================
* m+ l1 X8 O" [8 i/ v; ^ - ;引用其他源文件" j; |. \# q+ y* X/ ]$ x, A
- .INCLUDE "fc_demo_ppu.asm" ;PPU处理1 Q/ n/ o/ T) E; G' ?' D! e
- .INCLUDE "fc_demo_joysitck.asm" ;手柄处理
6 ~. q0 h4 z+ E) j3 M4 ` - .INCLUDE "fc_demo_static_text.asm" ;静态文本处理
; }" r v$ Q" P4 U1 k& K - ;======================================================================
# T! ?) i( @) i% n: o - * C* l% J; h! X' L
- ;======================================================================: ^1 Z" R5 N: T& c
- ;等待VBlank到来
$ r- U' g" A& }6 t- d- C7 d - Wait_For_VBlank
, n. \: f x3 K* O) B$ {6 u - LDA PPU_STATUS* E F& o6 E0 a- }: e' u
- BPL Wait_For_VBlank
8 H' m+ |! q: N# v' E5 l8 D# ?* B4 e - RTS" W( f/ z- P; O8 Y& @. r. c3 s
- 4 d1 ~" p4 K7 h' c4 A
- ;======================================================================/ ^% Z) f( v8 m, O
- ;调色板初始化9 J/ s% b" t- D& l* ?
- Palette_Init
7 L; h* C( V y2 A - LDA #$3F
5 r( V, _* u% ?3 G - STA PPU_ADDRESS
9 r) O# ^4 x3 E7 ~ - LDA #$00
4 ?4 ?- W) z: D6 k5 W$ i - STA PPU_ADDRESS! J+ s5 F2 n' C% a) @+ T
- LDX #$00
+ P- c) k$ a* X6 ^7 o% I - LDY #$20/ y3 S) c0 `3 o0 C5 q7 W5 H
- .Write_Data/ _* P1 ~1 U( i% K
- LDA Palette_Data,X
, \" D9 C8 e c" W - STA FC_PPU_Pal_Addr,X
0 J% W3 \7 A% b7 V0 h5 E% h - INX( @/ Y j p( A% h6 O
- DEY% [$ r1 r2 l+ U# r0 L) E
- BNE .Write_Data3 R4 g4 J8 g% y% t! {" h, H* O( v
- .End! W# p+ W! s0 Q, p8 V5 k# f
- RTS6 z" d: G' B5 N; k* P6 u8 [3 {' Q
/ G; Y0 W4 P& y+ e; n% @- ;----------------------------------------" `5 p b2 Q) C+ Q9 k7 j* Y5 e
- ;调色板数据4 j0 h) H& ?7 f1 A, {
- Palette_Data) S N" d( Y9 e; i
- .HEX 0F 20 32 02 0F 20 32 0F 0F 20 32 26 0F 1B 0F 1B
' [2 x& R0 _9 @) n - .HEX 0F 21 27 22 0F 24 24 24 0F 21 21 21 0F 22 22 22" C# p% ~5 ~$ e3 f
-
: R0 `% N. n$ @6 M - ;======================================================================
% Q# r; b6 r+ X) O/ E - ;命名表清空8 Y0 m& F+ i9 I- C: X7 R$ n. [/ G
- Nametable_Clear
4 p$ \- }: [3 `; o8 T - LDA #$20
+ }% T% }) U" w8 s - STA PPU_ADDRESS
1 [6 F& C9 P4 i) ?! x - LDA #$00
9 `! ^4 S4 g, T& h) ?* \" h - STA PPU_ADDRESS
b3 `5 ]: N5 N- g. p `. `/ M# U& } - LDA #$00
& ]" m1 v c5 i. i4 u( A - LDX #$00- g$ q" d% e( ^% v' A- ^/ C8 ?. G
- LDY #$08
0 R4 J$ T: n3 H - .Write_Data
6 R; y9 k5 V5 ?. C - STA PPU_DATA, N5 [' t$ ~1 [- ?' |
- INX
- T# C, y8 y P9 d - BNE .Write_Data
: X( C: m6 J* Y" Q - DEY
. m/ Y0 O% g1 n5 l - BNE .Write_Data! k& j( ~. }* q2 c/ E4 Z9 X
- .End
, E- M+ L: x! `& h7 ~/ Q" L - RTS" J8 A$ S5 N4 X6 S+ \4 J
- e- I5 I# w- Q F. e, u! ^1 F: |* H8 @5 D
- ;======================================================================! ]) }' I* O# M* z7 |' P! A
- ;音乐曲目切换
! t- ~' y: d: p. \- ~& P, h9 v - Music_Select_Process/ r2 ~4 m6 a0 v+ t( ^( b
- ( h2 P! Y* ^& |8 \: C% `. O6 l
- .Pre_Music;上一曲" ?- | `* ]! Q& e5 W( g
- LDA FC_Gamepad_Once
3 ?! V% I; U2 E9 O# F* E, y- r - CMP #JOY_KEY_LEFT
8 W+ }" ~/ ^& Y3 R- S - BNE .Next_Music6 \. _/ @* Z- K- Z
- JSR Music_Play_Pre
! C2 Q) k7 v2 o - .Next_Music;下一曲+ D, B9 u0 I" e' k
- LDA FC_Gamepad_Once5 x& X* z7 }( W5 ~, R* [
- CMP #JOY_KEY_RIGHT" q' g+ ]# ?6 J/ ]4 ~3 S# h, A3 K
- BNE .Next_10_Music
& K8 c- R5 T( R% f - JSR Music_Play_Next4 C$ v# N% C U; z1 i9 v
- .Next_10_Music;上10曲
7 L) W# _+ K. c: d1 _ - LDA FC_Gamepad_Once
) f; B2 n$ i& P - CMP #JOY_KEY_UP& w9 r2 k( J4 H
- BNE .Pre_10_Music
% H4 V; e* \- ?/ ]$ y, I - JSR Music_Play_Next_102 {7 C' R5 L5 t/ t$ L# C
- .Pre_10_Music;下10曲
! q* ]# K7 f3 `9 K1 G6 S - LDA FC_Gamepad_Once
* g! R; a! i* ]- y4 P9 s% c - CMP #JOY_KEY_DOWN5 r3 i# r% b! n- s' B% ~1 G' R
- BNE .Reset+ g3 S6 ?/ U1 b7 D
- JSR Music_Play_Pre_10; n6 h' e5 s) I8 V& |! o: X
- .Reset;重播当前曲目6 ~: n' p3 F% |) x% d
- LDA FC_Gamepad_Once [! A2 [6 g2 k# Z3 O
- CMP #JOY_KEY_START+ W7 O7 s1 X! ?) [
- BNE .End. n% O) u0 l, E9 `
- LDA FC_Music_Index
+ s! h* y3 E7 F2 h6 M9 V3 S - JSR Music_Init_Process
2 d, B) L& b" g5 ~- f% T ^6 _( S - .End! M7 T4 g1 [* }; U
- RTS
]' i/ W) a9 e h) I
* v9 {' U: ~% F* `. c4 ^- ;----------------------------------------------------------------------
; v. Y$ H [$ h' W1 A, K. x - ;播放上一曲' v" ^$ x. W0 d! w
- Music_Play_Pre0 R5 a! C! w$ n$ T8 X$ b' X+ h
- LDA FC_Music_Index
8 q# S6 b: b3 }: W; o/ L - BEQ .End
5 n `+ I1 p, r- _. N, R0 O5 M: { - DEC FC_Music_Index
$ @) a1 ~5 }5 M7 m - LDA FC_Music_Index
$ @* }+ t* m G; t: N' E - JSR Music_Init_Process
, d/ N3 G- O* R/ N( F - .End
7 @" Y5 J& c+ C c0 ~ P& q - RTS
- F7 Q0 w. L0 i, P/ X y+ y - ;----------------------------------------------------------------------
6 u; p9 e4 }( u J - ;播放下一曲; A3 M1 S( J5 _+ o
- Music_Play_Next+ l& x) i, N" l% X* r R
- LDA FC_Music_Index5 {; f0 S% J. _
- CMP FC_Music_Max_Index- D3 B- {/ q4 S% j- V+ w/ x. u1 G
- BCS .End6 j( |2 A+ L4 M4 F" D
- INC FC_Music_Index) t6 T$ }2 D3 J# W& F
- LDA FC_Music_Index: v m% c: Z5 m3 K( N! t
- JSR Music_Init_Process
( D% K' ]8 {) \/ h- W# a' w - .End& Y7 ~, M4 h, ]3 z7 V
- RTS/ ?; E/ ?+ i6 Y
, r* @" b. r6 A- g- ;----------------------------------------------------------------------) J: L, l; F! | V' b8 G
- ;播放上10曲
( q% J6 c4 Z' }: \+ N - Music_Play_Pre_10
: r, f- |1 Q& V- A- q) X/ w5 i - LDA FC_Music_Index+ N2 e+ C# B! }# s& C2 `
- BEQ .End0 Z4 L6 U4 [7 s: x) X- u0 w( m
- SEC. \( k9 v2 I2 W$ N7 l
- SBC #10
# T5 A/ l3 O) g& N y0 O( | - BCS .Pre_10
# l1 w2 C4 T1 b5 P) ]# k& ` - LDA #$00) O8 R: \7 B, O ?
- .Pre_10/ @8 d% U p5 O
- STA FC_Music_Index: m$ H$ @% x% @- B& v- @' v" L( ~
- JSR Music_Init_Process
9 W: G( d" g; @# r# i - .End- c$ X5 j" ^' K1 [0 G6 o% l6 S
- RTS
) f2 o* K, E, l- y - ;----------------------------------------------------------------------/ T3 W, j/ A+ P4 }, a
- ;播放下10曲5 a4 l: k6 Z$ q6 G& h* b
- Music_Play_Next_10; s" ^! m3 j: H* G. u' T; {& V
- LDA FC_Music_Index% H9 t3 }% W |+ g' d
- CMP FC_Music_Max_Index$ z1 a2 ~ j: `" m
- BCS .End3 p7 @' t8 e/ D" I/ Q; V; C4 J k n
- CLC
/ |; i& T$ h3 ] - ADC #10" ~( [+ b4 b9 u S. m6 L
- CMP FC_Music_Max_Index
# ^6 e- F9 K: J3 \ - BCC .Next_10
4 l( g8 X/ \; \4 d - LDA FC_Music_Max_Index( N/ v7 j7 e% i5 E; c' ?9 h1 M
- .Next_10" \1 v4 E* F5 {" s( z1 N3 o& A
- STA FC_Music_Index: `3 a5 F: \ _
- JSR Music_Init_Process
+ v$ D+ n1 n- z; p9 ~& j - .End" _5 G# B7 ~0 q5 M
- RTS
. l9 t' c& l' {. S: l* T. r - 9 v5 y3 u& K' s. @1 X
- ;----------------------------------------------------------------------) J8 G: s; @% k6 S# j; S
- ;8位十六进制转3位十进制制$ {8 K: r% N2 y e; m: H
- Hex8ToDec
# L( m. N k" ~0 Z7 R* s - STA FC_Dec_Data_1
! N9 M) G3 d1 v+ x% t T* V; P - LDA #$00
" [& y. D" ~. A% h - STA FC_Dec_Data_100) W8 c6 B- n; N6 g+ c
- STA FC_Dec_Data_10# X4 ^& q+ k }3 ^; H
- LDA FC_Dec_Data_1" C6 l4 E# V. V/ D
- .Convert_100, `8 M* m9 z5 G* u" f+ G7 r! Y. D
- CMP #100
" \( i# l1 f2 t# D - BCC .Convert_10
% m* V% f- d! a; O' _% q6 V/ b - SEC
2 ^. n5 c& J9 `' z& P1 m - SBC #100, `2 c8 C3 B7 F8 E$ O
- INC FC_Dec_Data_100
/ n2 w8 C+ R* K - BNE .Convert_1008 {6 x: }. W. r# B$ K9 e' d( T* P" Y
- .Convert_10
# m5 ?; J4 V# \& l - CMP #100 |; |" P2 @6 A; m w
- BCC .End
/ [- Y% b: k- A - SEC
: Q" |8 f$ m/ ~; [1 T& X. P0 w; R - SBC #109 y: r0 U$ m, Q) W- Z
- INC FC_Dec_Data_10, e0 G$ t" |6 P" R. _" \% G
- BNE .Convert_10
' b5 D- l. W0 N k( V5 t( l6 } - .End
: B: j6 L8 c6 s; q9 i0 f - STA FC_Dec_Data_1
5 E8 C/ @: ^# q. v W8 h - RTS
3 I0 G1 C5 R$ r3 r - % G6 o& u) l# A9 J9 T! Y2 `
- ;----------------------------------------------------------------------% u- A B7 L; w. ]: L
- ;显示曲目信息5 L5 N, V, c! W& O+ J
- Music_Info_Display R: i: h; }: A) J1 G
- LDX FC_PPU_Buf_Count
( Q; T+ t7 q9 t/ x/ e+ N. _ - LDA #PPU_WRITE_MODE_CNT_LINE
. Y8 q; D6 Q4 z3 O: Z5 N5 n' x - STA Use_PPU_Buffer,X% J' f* L9 q0 A9 k- y
- INX
! b& J, ~9 f S# W% _8 t - " [' _( c, ?, c. R6 D8 F& S
- LDA #>MUSIC_INFO_POS! p' a+ ?" T% b& A0 S
- STA Use_PPU_Buffer,X
R+ Q8 W1 U% J9 w$ J v - INX
6 H+ a/ Y2 |$ A- O! I -
8 r3 }: ~ z# p- B& e- T - ;居中
: S3 j0 U1 N3 x6 W P* I - LDA #<(MUSIC_INFO_POS & $E0) + (32 - 5)/2
8 b! J* \& r- f - STA Use_PPU_Buffer,X
" r% n" W0 [3 I4 _ - INX# D- Z# ?+ M- _4 z
- 2 B6 N8 L* E! j5 r' Q7 m% l
- LDA #$05. g4 {1 q* d$ X; U
- STA Use_PPU_Buffer,X
( I5 [4 Z% B: Y1 P* d# j6 i( C - INX
5 }4 C! r. y0 a. h/ D2 m& y - ) k2 ^2 X- e5 w+ C
- LDA FC_Music_Index' q3 g2 n4 g3 P
- CLC% i1 S5 T0 H! R! Z6 u9 J F
- ADC #$01
4 C) U" x0 t* _! o. j' |: y - JSR Hex8ToDec
6 j# y( \$ k* t, X. i: _( Y5 S: s -
; y* [* @# D1 E3 |/ l - LDA FC_Dec_Data_10
" S5 y5 B- W$ l& h0 M - CLC
) j4 p5 i/ l) F( U - ADC #'0'
% s0 Y# N# c$ E9 y - STA Use_PPU_Buffer,X# h6 K2 q8 `; j( ]7 Q8 A0 |
- INX
* e; ~7 M. d* b# j" ^ - 5 F; ]4 Q5 d5 q" W1 H3 L) K7 i
- LDA FC_Dec_Data_1
2 [) `9 |1 e! {0 S; v9 I, Q - CLC
! s( j8 p% i& s: Z/ m - ADC #'0'& U% Q# T+ Q }* J( M% D3 P2 e
- STA Use_PPU_Buffer,X
# y" f. z- D+ _7 [ - INX$ V; j: B; J5 j4 Y& x
-
$ F) P8 ]" }$ o! x$ }7 q - LDA #'/'
7 m. i/ V" J) S% C$ { - STA Use_PPU_Buffer,X8 m3 N$ {% {8 K4 v) D
- INX7 \0 F6 ~4 f' j
-
/ H2 U" a A' J) R! A* h" ] - LDA FC_Music_Max_Index3 k* y8 Q* g+ A
- CLC$ p0 G8 a- _- B+ ]3 s
- ADC #$01
/ T1 m# G6 D" S, T ]* n - JSR Hex8ToDec
2 @: J* h3 Y% X) x' I W6 {0 R - + R; G3 p/ `6 ]+ V$ [3 P% V
- LDA FC_Dec_Data_10
" u* P4 w; ^; O% Y5 |( E - CLC' ~% ?- D! T3 E, s- m, y# y
- ADC #'0'
1 b/ [' q: i, h# e - STA Use_PPU_Buffer,X
- f, C, ~/ D% B - INX
- l& H4 L- P, F2 x1 u2 q% G -
9 O2 w" y( A/ K1 _* H9 ^* p# `9 y - LDA FC_Dec_Data_1' i! S$ }0 }2 D# K# _& Y
- CLC- v2 y+ ~5 u D# ~2 o& n
- ADC #'0'; I& H% h6 M Z! t4 ^
- STA Use_PPU_Buffer,X
% G" k5 Y# o1 S | - INX& [+ D& k: T& r2 m5 P
-
/ m3 c: R$ m7 W( n& @ - .End
0 o7 O& W: M' f5 T* h - STX FC_PPU_Buf_Count
* o! G! Y( ]- p6 ]: D - RTS
6 P5 U1 [, x n& W
% q1 t' H* K; @( B# Q- ;----------------------------------------------------------------------: d0 `8 N6 v% P: M/ O
- ;音乐曲目初始化处理
2 Q" p4 G/ ~0 q, u - Music_Init_Process+ T* Y8 j* \! s# }9 B) J+ @, @" M- c
- PHA
u9 S% c; K; z: N7 K. N% f - JSR Music_Clear_Process& j+ X% P) e; N( w; H. }. q
- LDA #$1F
& [7 ?9 M) ]& `' y# a/ y - STA $40158 h, H' W9 Q9 g, ?, Z. G: h
- PLA
, i1 w; J$ K1 l, Y3 o' u2 E - JSR Music_Init_Addr
) t; W5 i7 S. R. b) D0 i - JSR Music_Info_Display( ]" M: Y' {) @* ~# j+ ^7 p
- RTS
; k+ e6 B* z$ h - ( f& x. H, e& P9 c8 t& [( T2 d
- ;----------------------------------------------------------------------
3 I* z" q8 o$ g% E( M& H - ;音乐播放处理
" b2 r& u; h3 w2 ^5 Q% ]* Q - Music_Play_Process
' n: Q4 z' w- `! t; [/ o - JSR Music_Play_Addr; V! ^4 t. o# \0 I$ `! E
- RTS
2 K8 Z9 Z7 a. I2 ^' g" X9 ?
5 U, x& m, B6 f" y- ;----------------------------------------------------------------------6 K+ l$ a3 b) e* w5 e8 j) r
- ;音乐播放处理: ~" R# D& D# l }
- Music_Clear_Process, E/ E$ a, |' s* Z
- .IF Music_Clear_Addr0 m5 @' [5 I! b( b4 V
- JSR Music_Clear_Addr& Y9 x: s( O% `& x" R
- RTS
. I& J3 R* q* _/ ^" e" U - .ELSE
" T+ X1 n, E9 d1 d& w( }* ? - LDA #$1F
6 N5 x" ^" j2 Q7 s& w: N& e. A - STA $40156 G% `" o d; u. U# i
- LDA #$00
6 H' J+ X, J! B6 P! V% P4 Z - STA $4010
4 e) U# O2 \* o: h! S: Q; H8 c - LDX #$00" Q+ W* K5 b8 c4 \
- LDA #$00- T% Y$ F S( W& i4 e
- , ?" @: ~; a. q) @
- .Music_Clear_Zreo_Page_0. f0 T7 {$ Q5 H% Q
- STA $00,X
& W6 z# r t/ h+ e - INX# W/ {, }" W- ]2 V1 V4 ^( H) c
- CPX #Use_Zero_Page_Begin
* H, ?6 m M9 L" e* e) g: L! ? - BCC .Music_Clear_Zreo_Page_0
7 x$ e9 O9 \9 D, e7 {" ?0 a, H" l8 h - 6 Q: Z7 s% Y3 v4 C: q- Q
- LDX #Use_Zero_Page_Begin + Use_Zero_Page_Size: N8 x+ c( ^2 j$ x
- .Music_Clear_Zreo_Page_1+ ~3 y! I! H; {2 y; ~ z% x5 U
- STA $00,X
; x0 h/ Q' ]# O' B- t - INX
# J# E, o2 h) V0 a- s, u - BNE .Music_Clear_Zreo_Page_1" y4 {2 E" ?, t
-
5 D/ L' J% b4 i3 f) O6 ]0 y - Music_Clear_Process_1$ {0 ~/ w2 U7 Q3 ~0 a4 i1 s
- STA $0600,X" x8 H2 C8 |. Y+ L. L
- STA $0700,X5 X- ~1 f7 B# t* m$ j2 t
- INX+ f, O$ I( ~6 d# p V7 C8 {
- BNE Music_Clear_Process_16 ]# g& \* P& q4 g: z
- LDA #$10. @+ e6 |/ U9 I% }
- STA $4000
% N2 G) l$ x7 A$ v6 x - STA $40049 \2 \6 M4 k* f4 z1 o
- STA $400C* X" t& L& @7 k
- LDA #$00
( [' X$ @7 t! B& I1 P - STA $4008
3 j' _4 ?" u+ q/ Z4 d, e# H1 f - LDA #$0F
- p7 C2 R# c; `' e9 {! x: C) O - STA $4015
6 ]) E( Y2 K' _3 h# j" } - .ENDIF; v0 m* C, }, Z6 R+ i; z# e
-
, V& P) C* { C - RTS q g7 |+ a9 _* Z
- + z; X' V8 ~! v; m. k7 h3 O
- ;======================================================================
' E- R1 ~ E: J - ;重启处理3 j- V1 i* P/ o7 ^+ E
- Reset_Program( U4 j- _9 m0 r% B# A" {3 b% Z
- SEI
4 B7 z+ d: L) N# W1 s4 n& j8 M - CLD0 b$ r% _2 n. S, Y
- LDA #$00
( C$ E( U3 u6 ]& W6 f+ Z - STA PPU_CTRL8 B; e/ K- { V2 ^$ y
- STA PPU_MASK1 o I0 K! q; D. t! d3 y. Q/ c
- STA JOY2_FRAME: p# e& r- i6 |5 ~
- STA APU_STATUS
Y+ m9 f3 G) t! I$ p# \9 i -
0 d1 ^- y T+ o" [3 V9 t - ;等待屏幕准备完毕
$ S0 \4 K; n# ] - LDX #$02
- t, {( {+ l! h8 s7 w8 m' O+ } - .Wait_For_Screen_Ready' K6 K5 s/ B0 a5 s2 B1 S) r
- LDA PPU_STATUS
4 d. o: h' w7 ]( G; T. j/ c - BPL .Wait_For_Screen_Ready( ~& X9 |+ }; o; _0 n: f
- DEX
) Z! v# V1 L* y- v* Q3 s$ ? - BNE .Wait_For_Screen_Ready( j3 l& q0 ?" _
-
, o" o+ U/ U) \/ N' p( h% w - ;清空调色板
, ^4 `! E9 B- g$ _5 y% ]/ j - Palette_Clear3 A5 J C- ^6 h
- LDA #$3F% t! w: Z t5 b: w, O5 o/ |# S1 D n
- STA PPU_ADDRESS
! V- N- f5 R2 r1 j: Z - LDA #$001 }- K- d, |5 e4 k) ~
- STA PPU_ADDRESS
7 o/ R! P( C3 G. U0 V7 {# u - LDX #$20
2 ?4 Y2 w' W% E6 f) Z* i/ Z - LDA #$0F+ t# r7 u- p) c* W6 s/ L: l* ?% r0 I
- .Write_Data0 O. v- ]# e- b( d5 j" V
- STA PPU_DATA, K& s) y; D/ L. _0 u
- DEX. d. z: G0 N1 [% o
- BNE .Write_Data
6 a2 B2 g% `$ z
- k8 r( j1 ^. X8 M- M- q; J/ c- ;清除声音 $4000-40132 {7 L1 D4 ?% o( V' y2 z
- LDY #$14
2 w4 Y+ ~" o! m" G$ U - LDX #$00
8 F, N' H0 r2 z% D/ |& L( ]8 o9 ` - .Sound_Clear
: q+ J" W1 X; e/ n; n* ^ - STA $4000,X7 y. C' C7 x6 O& W
- INX
8 z; T9 I- U" T' s) b) c# z, R) b - DEY
5 i4 J B4 Z( @, l; n3 p* R - BNE .Sound_Clear w4 E. v; X5 |; H+ ^
-
2 z( \! `' W& E. [/ ` - ;清除 RAM $0000-07FF4 k. c$ Z7 `- Q" T# l6 N. M
- LDA #$00- t2 J6 D p+ j) z
- STA $00
, O9 c) q$ D# K: j - STA $01
U, O7 L+ m1 c- `: a" J7 s: q - TAY
0 f1 k# _7 M, [3 _; o - LDX #$08
# i$ ]* o% n8 C D0 O - .Memory_Clear
% Z2 K; p; ?( A% N - STA [$00],Y% a U+ \' D& B5 Q& m/ o
- INY
4 J+ R, o3 V# } - BNE .Memory_Clear
4 |/ E/ q U9 |& e0 @+ y' Y5 p - INC $01
' L$ J7 t( {4 \ - DEX8 n0 M- E X0 ^& k9 Z
- BNE .Memory_Clear, n6 H$ W$ l F
-
4 B6 p0 ~0 c( {+ Y6 p1 ] - ;精灵缓冲初始化
. \. N/ x- w5 q' v - LDX #$00" L, F F& b1 v0 j# L
- LDA #$F8
8 b7 T8 r- [3 E4 m2 X2 m - .OAM_Clear
0 ^( V' T9 \6 k" M1 k/ v - STA OAM_DMA_Buffer,X
4 d$ X; m9 n' W1 F - INX
! N) T) g3 O2 i4 R, h, N) y' v - BNE .OAM_Clear
! }' q* s, `' h9 Q: u) q - ! T5 U% I/ ~1 Z# C
- ;栈指针初始化
1 k7 v3 T, x$ c3 _+ q( ]2 ^( m - LDX #$FF( v; A$ F4 Z- J9 o- s% f' n
- TXS
! g$ c8 S6 N3 X9 P7 O. Q -
^6 ?0 y; S. B - JSR Nametable_Clear;命名表清空
( Q$ S1 ~4 I# k6 l X' ]( B9 i - JSR Palette_Init;初始化调色板缓冲
* N; p* j# }% L' E% I4 [# Z - JSR Static_Text_Init;初始化静态文本$ R/ ]' J7 l$ K1 x( V
-
/ x& V' K9 V) r& `9 q3 G% F - LDA #MUSIC_ITEM_TOTAL - 14 Q7 y4 y6 y) j" C' M8 d7 J
- STA FC_Music_Max_Index
& ?3 [9 Q. a0 ^' u- G1 h3 u -
! M Y* {: d9 Y1 N& Q7 p( R - LDA #$1F
8 H2 a( v2 L: i3 A/ ^) }# N" ] - STA APU_STATUS
& t2 r2 l0 K" ]1 k6 N$ z( O - LDA #MUSIC_BGM - 1- B0 l" g' `4 x# x
- STA FC_Music_Index9 E# L3 X# G! W1 g) A6 R( p+ N
- JSR Music_Init_Process;音乐播放
6 \* @6 M8 _! C -
/ E8 h& S9 |; ~) `* S) L - ;设置屏幕显示状态缓冲(当NMI处理时控制屏幕显示状态); x0 e3 z' A" o* r# l' L
- LDA #$1E
; D+ A6 J; V) S* J7 L$ @8 s - STA FC_PPU_Mask_Buf' c( ^: e- c% d# O! M
- + u2 D# f2 j, h
- ;启用NMI处理
& M0 x+ g4 D3 D+ w4 \" h, N i5 G% @ - LDA #$805 o; @$ Y2 S1 f6 ?" h2 B4 q- `
- STA PPU_CTRL
$ t& G2 A: {0 ], E& d& I - " O9 N$ s4 ? X, f5 C1 {
- ;程序循环, 剩余工作交给 NMI 中断处理
7 O' x2 }# D. Z0 c m - .Loop' P0 P: f6 v) M& ~5 s A( \ V
- JMP .Loop
7 Z( n9 y ~, `7 o - # `, x) `1 P7 y: f8 x" s
- ;======================================================================& [0 m# o; n$ T- o" g1 j
- ;不可屏蔽中断处理2 G, P' T7 p1 X, j
- Nmi_Program% {6 k* a: f# G* Q! q
- PHA
% x2 ?/ }: Z* p& r3 { - TXA9 e5 E0 k: x# s) ~1 ]
- PHA$ [5 t3 b6 [% d; }6 C
- TYA7 p- i! n! n5 V$ }, C3 J! J
- PHA0 j: {1 }8 Y; f: `
-
+ U: s( R; M9 N- |- q$ S5 Z& r - LDA PPU_STATUS;读取使得 PPU状态寄存器复位
8 h* U& z0 ? L; K) P -
! x/ J' J% R1 w h8 R- Y - JSR FC_PPU_Procrss;PPU处理7 ]. D. @, H8 ]9 |4 v; F
- 1 s R6 a# n4 A5 T
- ;精灵内存更新7 B* k3 O" q" v8 a3 K! n2 z7 e
- LDA #$00
$ ?- H# a$ X, A; g - STA PPU_OAM_ADDR
5 N1 E6 f1 I& K. K( X3 f. Z - LDA #OAM_DMA_Buffer / $0100) L2 Q& g( Y" |1 p
- STA OAM_DMA) r& {, e/ |4 Q5 s- x9 B
-
1 X: }- E/ I5 Q$ Z4 ^3 s2 l - JSR FC_Gamepad_Process;手柄输入处理% l2 r2 I& k; P+ l S
- JSR Music_Select_Process;音乐选曲处理
9 |( }1 x/ l' N9 z6 e - JSR Music_Play_Process;音乐播放处理7 K! G; w! H; o: j q
- _8 @& t# \3 _, R @, Q/ q6 B
- PLA; @" p9 G; I1 c. j6 {
- TAY# F$ S! U8 T, r8 I9 f [
- PLA
. R; H( _" p+ J1 ] - TAX
$ Y N! l: _+ \2 _7 l+ I - PLA" w+ a9 f7 C* o* X- W
- & D1 `! c8 Z6 u. z9 A
- RTI
9 c) M3 F# F% X1 x j
+ d- k0 b- {5 M/ L. @6 g- ;======================================================================
1 o S1 w( n8 v4 y# V/ L! x* F - ;请求中断处理. o. _, s4 {+ S; F1 k0 [
- Irq_Program
0 k1 A& N4 b! q2 S( P - RTI
! M) w9 X9 U# Z$ L - $ h; v' u6 D- g* x0 J8 @- a
- ;======================================================================6 C% U, Q+ d3 x
- ;中断向量表
) L: {$ f: X$ P' B+ n - .ORG $FFFA& Z# W3 |5 F# D# K2 Z4 k, k4 Q5 c
- .DW Nmi_Program ;NMI触发时执行
1 P2 w0 s& D6 d1 e/ m - .DW Reset_Program ;载入ROM时最先执行% D4 }, B! I' C M5 m
- .DW Irq_Program ;IRQ触发时执行# J0 M, s1 x% D$ C; l4 V8 c
复制代码
$ A ^' X% {) M6 K! e6 y2 m0 j
, f" C+ G! @: l0 ^% _4 ]# f* a5 b% Y5 o0 t( r
https://gitee.com/flame_cyclone/nesasm_3_2 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
1
查看全部评分
-
|