|
|
这是个 nesasm 3.2 入土教程, 感兴趣的可以研究下
, u9 m1 m4 Z$ v0 b0 P% ^
, N8 g+ ]1 W8 b. [* i6 Z9 e以下是主框架代码:! _& k6 S" s0 m# f, f" z3 E* Z
- ;======================================================================) s% P; s* ?- J: M
- ;文件头
5 o" b4 A- E5 K$ v; G - NES_16KB_PRG_SIZE = 8 ;16KB PRG大小数量
2 C; J* L; `. `. b8 d% ^ - NES_8KB_CHR_SIZE = 1 ;8KB CHR大小数量2 [$ A+ U$ N7 n9 g
- BANK_DATA_MASK = NES_16KB_PRG_SIZE * 2 - 1 ;bank号掩码
" {$ ?- m9 v) [" N. \' y8 @ - ;======================================================================1 `" | }7 I8 O
- PRG_DATA_BANK_C000 = NES_16KB_PRG_SIZE * 2 - 2( E2 S, p D0 W" C5 c3 Q, g6 N
- PRG_DATA_BANK_E000 = NES_16KB_PRG_SIZE * 2 - 1/ F; O( U8 }* R7 l* x5 v
- ;======================================================================
8 F; i+ o4 g/ U8 J - RESET_BANK = NES_16KB_PRG_SIZE * 2 - 18 v! z1 o* Y: e' A( W
- RESET_ADDR = $E000 ;主程序起始地址# h4 x0 c1 z5 U
- ;======================================================================
: E. M/ o9 G- O - .INESPRG NES_16KB_PRG_SIZE ;16KB PRG 数量, $01-$EF8(1-3832),即16-61,312 KB
; j- k; Z; m5 @8 N3 ~8 Y# s - .INESCHR NES_8KB_CHR_SIZE ;8KB CHR 数量,$01-$EF8(1-3832),即0-30,656 KB
+ k+ E3 a: |# z* ^ - .INESMAP 4 ;Mapper号 (0-4095)
3 z. P- @/ q4 K0 I2 O - .INESSUBMAP 0 ;子Mapper号 (0-15)
( s/ E& G( n# g$ P$ \/ L* @( \ Z - .INESMIR 0 ;命名表镜像 (0: 水平 1: 垂直 2: 四屏)
9 G5 M9 _9 |7 L. O1 \ - .INESBAT 0 ;指定是否存在电池备份 (0: 不存在 1: 存在)- b) M' ?$ K3 O$ @5 W
- .INESPRGRAM 0 ;指定 PRG RAM 大小 (大小 = 64字节 << 计数)
1 y" ~# {2 J* S: ^ - .INESPRGNVRAM 0 ;指定 PRG NVRAM 大小(大小 = 64字节 << 计数)
3 M$ [0 c! j$ ^; E" ?/ j - .INESCHRRAM 0 ;指定 CHR RAM 大小(大小 = 64字节 << 计数)
3 _2 [6 K# n+ C% V - .INESCHRNVRAM 0 ;指定 CHR NVRAM 大小(大小 = 64字节 << 计数)( P y( f7 k" U* [6 O9 |% P
- .INESTIM 0 ;指定时序 (0: NTSC, 1: PAL, 2: 多区域, 3: Dendy). {/ B" A( M/ X. u8 ?
- ;======================================================================6 _3 v; M2 J* j3 ~
- .INCLUDE "fc_demo_config.asm" ;全局配置/ e# }" E+ u$ Y; m& h3 V/ y
- .INCLUDE "fc_demo_constant.asm" ;NES常量' q+ l6 G2 r( ?" B1 J9 e o. M
- ;======================================================================' T& Y4 \$ W: ^) d- s
- ;音乐配置
8 i; Z! T0 n4 q T6 } - .IF 0 = MUSIC_THEME 6 A5 \6 x4 k" N0 Y% [0 C( v3 \* n; R$ |
- .INCLUDE "data/music/Gremlin 2/config.asm" B$ |! W& g+ Z$ j
- .ENDIF
, H1 v$ P& K& a+ o' b -
' t M- H. \ @- c8 H/ f - .IF 1 = MUSIC_THEME4 ~' ~( k" h% ?
- .INCLUDE "data/music/Raf World/config.asm"& C. k! c$ a: g# H# Y) k
- .ENDIF- |. [4 h# z. n# T) g7 ]7 g
-
, S/ o2 m. Q( M6 V" e0 W/ P - .IF 2 = MUSIC_THEME
* i/ `- R& Z& s - .INCLUDE "data/music/Ninja Gaiden 3/config.asm"
! g1 @2 }$ S( r$ D" f8 _# E - .ENDIF
9 O. s$ a) c4 k* g' G2 F7 a; z( w - 6 N1 J" p- ~$ W, d, q0 j' c0 x# R$ d
- ;======================================================================4 W6 ^. ]7 T. V/ V& z$ A( ]; n
- ;引用CHR图像数据4 t2 S" Q! L& Y7 K' I% N& V7 @0 N
- .BANK NES_16KB_PRG_SIZE * 27 M/ b+ u; {0 l
- .ORG $00008 R/ d" A3 ^+ Z- I- B
- .INCBIN "data/bkg.chr"8 v/ M' c& i1 a* X; j
- .INCBIN "data/sp.chr"3 S# q, c5 C3 v' ~ t( Q
- # g6 J0 K8 O; U
- ;====================================================================== E0 x8 Y+ h. }+ N7 X
- .BANK PRG_DATA_BANK_E000 & BANK_DATA_MASK;设置程序所在Bank
. R$ F9 [4 G6 O0 i* } - .ORG RESET_ADDR
" e+ a3 f! Y! d# u" s# J3 k# x - ;======================================================================# L5 ]: N( E$ L9 f
- ;引用其他源文件# ?4 x1 h# E# V" ^" t( r+ A6 C! O
- .INCLUDE "fc_demo_ppu.asm" ;PPU处理
, }* n( W( E, I5 j - .INCLUDE "fc_demo_joysitck.asm" ;手柄处理
) U8 y3 m6 p. i. W1 b7 c7 d - .INCLUDE "fc_demo_static_text.asm" ;静态文本处理
* r- e4 f# i! e6 @ - ;======================================================================1 z; ^: Q, l6 A: `3 v8 {
- / x) T8 U L6 N) t
- ;======================================================================
% I$ h* D# g2 W5 C5 I- O6 T1 Y, _ - ;等待VBlank到来
% }+ r9 p8 l- ^, q. F" M m - Wait_For_VBlank
9 m" i& J% q- N. \) m) A% D - LDA PPU_STATUS
- A5 L y5 v+ O - BPL Wait_For_VBlank! e! {: h1 ]- n5 ]! J% F
- RTS' R4 i9 x( r" T) l+ r! g
- ; K. N; l8 x+ T. Q; ]) F( k+ S5 T- E7 L1 M
- ;======================================================================
( Q$ K$ p& I' f0 {$ D - ;调色板初始化
' A4 @! @( z/ B4 J - Palette_Init6 _' Q: x# |% @9 O! I4 ?2 P3 C
- LDA #$3F8 z* O) s2 L, W( Y
- STA PPU_ADDRESS
7 v; ^3 w+ |6 p2 \' C- M0 T8 [ - LDA #$008 ^7 f$ @! \: }$ N+ q0 C% \ D
- STA PPU_ADDRESS
. i: s& v) d A7 Q# f6 V+ W" y - LDX #$00
& p5 F% U' t/ Q8 C$ s* d - LDY #$202 t9 Q g' H& v# m/ X% z
- .Write_Data
$ b& m+ u+ Y6 N0 J - LDA Palette_Data,X
& p# o5 h, G' U. E1 ?& P V: D - STA FC_PPU_Pal_Addr,X
% L- @# p! f' i8 s! p' h: g - INX
1 r+ A3 k; j L2 e0 @8 M1 \ - DEY
3 ?) o8 S; ]$ w* W3 L/ N - BNE .Write_Data. O( q, S0 {2 e! Z$ e4 y
- .End4 f# C( z1 t2 ]( Q+ ]! ]1 w
- RTS
) N. P; l- d: `7 j3 Y& s8 o - " }) f3 O- `9 C& `7 [
- ;----------------------------------------; c/ h1 \; s: j3 P
- ;调色板数据
$ D! N/ O5 A; a- a; z4 r3 h - Palette_Data8 h! r0 [" w4 n5 ^% e* {7 ~. j
- .HEX 0F 20 32 02 0F 20 32 0F 0F 20 32 26 0F 1B 0F 1B
$ |5 o1 ~3 k h2 y5 T. _. z& q/ Z - .HEX 0F 21 27 22 0F 24 24 24 0F 21 21 21 0F 22 22 22/ x' x4 ^! |9 T7 p3 u
- 4 d" B1 C) M# k9 R/ K6 E* d8 R _
- ;======================================================================
8 N: e6 \1 M2 R9 @/ n% a h - ;命名表清空
% f6 R# l n: ~' }& F9 L: L - Nametable_Clear
' D: F: A( v- A! z# ]0 l: m1 L! p: @! ] - LDA #$20
! _+ c; f$ x0 L( N/ M/ c0 g* K% d - STA PPU_ADDRESS
/ [ J) M% s- r: B! l - LDA #$00
- X, C& e. Y4 O. W, |/ k' | - STA PPU_ADDRESS6 t/ C0 a+ i% @1 h$ D; x+ M+ v' ]* c
- LDA #$00
! {- M- r5 O2 `" V N% i - LDX #$00
; _' w- p5 \1 D0 ^3 @5 _ - LDY #$08
; _! M6 X4 `1 Y1 p9 l v& k1 R - .Write_Data4 t" d& j. b7 p+ @& ~
- STA PPU_DATA
0 n# ~% U2 S9 ?+ V9 e7 m: ^ - INX9 `8 P$ ]1 a7 Z, p% P9 S1 {
- BNE .Write_Data
, _6 @" m$ H9 f) h* T" p - DEY
8 g0 L, y, i( u' T - BNE .Write_Data' ~" u c" V# k# j: ]+ c
- .End @' h, B4 X4 r( q6 o: m1 A
- RTS
; m$ r8 s6 a5 ] z& K
) l' J& I! L9 ~5 S- ;======================================================================6 A5 x' R/ {& f; k! t
- ;音乐曲目切换
0 ]/ M1 j9 e& f2 q$ P7 l - Music_Select_Process
) z3 z( U7 {1 e" [# b0 n
/ o& N0 `3 r$ r j% g, D' {- .Pre_Music;上一曲
$ i8 M6 A# Z. E - LDA FC_Gamepad_Once5 S6 ~( b7 X5 g# }5 Z
- CMP #JOY_KEY_LEFT: J _& q% O3 s- s
- BNE .Next_Music
. @. w, Q: y5 g0 g/ Q) u - JSR Music_Play_Pre
( }5 b# n6 L3 y" b3 d - .Next_Music;下一曲
Q- p8 T. d5 z4 }2 R - LDA FC_Gamepad_Once
! H' d% O( d2 M7 {- y - CMP #JOY_KEY_RIGHT
' @1 B' K+ z( A/ u - BNE .Next_10_Music7 X( Y4 m& N5 b& x" x* S- n
- JSR Music_Play_Next$ F2 i% \5 B! o, b! ?" D& H
- .Next_10_Music;上10曲
) G& Z2 g! u, M, L - LDA FC_Gamepad_Once
( N: {% H* I' b, q# U1 L7 N9 h0 j - CMP #JOY_KEY_UP& A$ _# I; |5 v5 d5 V! P5 [% |
- BNE .Pre_10_Music
/ }& ]) J1 o4 x$ @) z5 E - JSR Music_Play_Next_10
& h8 S/ {( T# d - .Pre_10_Music;下10曲" I) s6 S' W" P+ I
- LDA FC_Gamepad_Once: G) e+ l" I/ a6 ]% w
- CMP #JOY_KEY_DOWN
, ~# f! Y' E1 v. L6 h3 Z0 g - BNE .Reset
" Q% [" r* Q' N- e0 ~ - JSR Music_Play_Pre_109 D& _4 c+ [$ o6 @ g( U$ D, H* f
- .Reset;重播当前曲目
! k" }! w% y7 z- y1 O; m: [" Y - LDA FC_Gamepad_Once$ d) [6 d* Q3 ^$ J2 A: l
- CMP #JOY_KEY_START4 Z- k$ ~: K0 K" |
- BNE .End& a- o9 Z$ Y B
- LDA FC_Music_Index
1 u) x4 J( S, y+ _ - JSR Music_Init_Process
8 R+ \' I6 _7 ]6 c - .End" h- C: M/ b& W
- RTS
. }; A5 M, m! S* c! @( Q - 7 x9 V( ]1 z. u) K( \" e
- ;----------------------------------------------------------------------
# Z3 _, }6 S o; X7 | - ;播放上一曲
% y6 A9 ?; W" }- K7 S - Music_Play_Pre6 r9 z0 Q. a; F
- LDA FC_Music_Index
6 b; q) q$ |1 z# C( v5 p8 P - BEQ .End
, h! ~- h2 g2 `% H6 [ - DEC FC_Music_Index. H( {8 v2 f& y; z
- LDA FC_Music_Index
5 f# f8 p M% c7 c+ E" f: ^ - JSR Music_Init_Process5 _/ W) R0 U+ j9 d( J' }
- .End2 y* l' ?# b+ T5 E) e
- RTS# U3 I+ n* G& {" {& [) \
- ;----------------------------------------------------------------------- ?$ |8 q' W4 e# i$ r& C; X
- ;播放下一曲! t7 @% v! n1 @* X3 _
- Music_Play_Next
; c; u( N7 X4 y' M - LDA FC_Music_Index
! \4 q8 G+ w5 F6 r' w - CMP FC_Music_Max_Index
9 J6 S- F* {3 _ - BCS .End
( q. i$ m, {2 R# Z" o! c: v* G* N - INC FC_Music_Index. |4 W0 P [) Z2 D0 `0 ^
- LDA FC_Music_Index
, `0 F( C$ n5 b _5 [ - JSR Music_Init_Process
5 n/ O$ G. u4 R: H; q& ]0 W" s" m - .End# D4 r1 E! u g+ D0 b' J
- RTS
- h9 H2 j4 v5 R
! {. f( Q" `8 i$ R5 F# {- ;----------------------------------------------------------------------
1 V% Y6 P7 `7 R0 _8 v - ;播放上10曲5 \' y9 t" s2 o$ W
- Music_Play_Pre_10; N- ?: r: c8 R' G/ |8 Z
- LDA FC_Music_Index
% \# @. q. E+ {$ y - BEQ .End! s- u- x4 u- k; P6 I, z
- SEC/ @# `5 ?* S* n. V1 E9 J* q5 N
- SBC #10
; ~% ^9 O4 S4 {2 k- ^& j) |. p - BCS .Pre_10: ?4 n0 O1 H3 } m( o' X8 L. ~
- LDA #$00! s Q+ w& F4 J/ v, t
- .Pre_10: ]3 w7 K* a! Y, ]: H
- STA FC_Music_Index* O( ^5 f8 W8 A
- JSR Music_Init_Process
1 c+ h7 N! Y0 Z) I/ n - .End
4 `: u+ a! o# }9 L; H, V: U9 ~ - RTS: ~9 U7 ?& q" Q
- ;----------------------------------------------------------------------
3 t% U! h0 ?" j7 C - ;播放下10曲
7 Q# v3 w# v9 j7 V - Music_Play_Next_101 d, D9 m- X/ C2 S9 G5 Z/ a( o
- LDA FC_Music_Index
: L2 ^# F2 ~1 U; Z - CMP FC_Music_Max_Index, b% A; Q; Z$ r! b% j& ^ q
- BCS .End6 j! o0 e# e% U" L7 o
- CLC
$ I ?& M* [0 ], I( X$ Q - ADC #10
. F2 Z+ Q z0 a# _( \ - CMP FC_Music_Max_Index$ Q" ]% ]- b, C0 i
- BCC .Next_10
' y5 S$ m/ b* v - LDA FC_Music_Max_Index
: L( q* h1 Y" {( S - .Next_10
* L2 _9 o% Z# K - STA FC_Music_Index
9 |- E/ n4 i: J; x! A4 a4 ? - JSR Music_Init_Process
* \' C+ w/ A4 L5 @, C - .End( H' \+ L$ {) c! s. d$ q Y1 C
- RTS. f) ~, @% _- s* j5 r- E
- 2 M# Q8 t3 q7 d' Q( r3 G3 E: o
- ;----------------------------------------------------------------------
) n( w' y. l* r/ ? - ;8位十六进制转3位十进制制
) F. R; [4 R, e i - Hex8ToDec: B3 k+ L/ I* Y7 N: H J3 h( Q$ @
- STA FC_Dec_Data_1) [- X& `8 w1 q7 @4 f: c
- LDA #$00* k2 @/ X7 o) D# B) f/ C
- STA FC_Dec_Data_100
( B" Q% m* |9 m - STA FC_Dec_Data_10. ]6 {) L& D( M/ R
- LDA FC_Dec_Data_1
8 A* u- g" Z1 v! b - .Convert_100
! a& C" Z$ n- K* e - CMP #100
9 V7 _! ]3 s: j. ] - BCC .Convert_10
+ a+ A5 q( b) }7 r' q. x; F% U% f - SEC w) w" U3 m h
- SBC #100
+ G( d; q. ]6 k; G2 O0 X! y3 R% G - INC FC_Dec_Data_100
7 a$ t2 j W/ X- k$ K' T - BNE .Convert_100
5 {$ o. v# H+ e7 `0 s - .Convert_10
4 K, K1 d/ Q$ Y5 ?0 e9 c - CMP #103 A1 N0 m$ n$ G a7 ?
- BCC .End
/ B% w- a* i+ K8 ^) c - SEC
. J! i- A3 ?" u6 a9 q- K - SBC #10) V% k6 }# a& W' e! }
- INC FC_Dec_Data_10
- k$ R v* Q# V4 ~2 \, }+ d' _2 ~& ` - BNE .Convert_10& B% A' ]5 p7 n6 k1 h
- .End5 ]9 Y3 j N+ C: V
- STA FC_Dec_Data_1
+ i( L2 l3 }7 C7 C8 j9 h! Q# x, n - RTS6 X/ n. ~; M, w+ K% s, r% N
- 2 w& F& q/ q p$ _4 T# k
- ;----------------------------------------------------------------------
. n( Z, T6 l3 Y$ i - ;显示曲目信息& V5 e; i3 u; C& b. {$ e, x
- Music_Info_Display
1 k$ z8 C. r* t2 J - LDX FC_PPU_Buf_Count
! |+ I4 u# y2 D. ~& |: o% Q - LDA #PPU_WRITE_MODE_CNT_LINE+ `+ X& S) g2 \, W$ ]: b6 y
- STA Use_PPU_Buffer,X
1 B# ]$ y) ]3 ?* d! B% K, e$ r - INX
& X+ l% |9 W$ s -
% g f8 H, D8 ~ X - LDA #>MUSIC_INFO_POS+ d/ ]( x3 ?6 C9 L; M
- STA Use_PPU_Buffer,X; K4 U" V/ P, ^. G6 O
- INX
' W3 N, {2 A/ F3 M& m - 5 H Y1 g9 e$ u3 k
- ;居中
5 O) ]8 l1 p' T$ L9 K - LDA #<(MUSIC_INFO_POS & $E0) + (32 - 5)/2
- H/ t7 f: L8 `9 H9 R# B1 J - STA Use_PPU_Buffer,X
$ v; R+ Z3 Z- J; I; b# | - INX
/ M0 Z( \) i+ N+ Q( ?3 O/ l# ~" Z2 T -
& a; w9 b, G; i* z: _ - LDA #$05
) {5 M% b! ~. o0 s; V$ ] - STA Use_PPU_Buffer,X
$ H t6 S( A& Z7 V) X% b - INX+ G. G. f6 o2 |. H' z s! M. e
- ; Z+ @6 a5 | N* L
- LDA FC_Music_Index
( S5 k) g4 q8 c' D' n1 Y. J. { - CLC8 i: B6 U# j' ] a2 y# O0 }/ z
- ADC #$011 S7 ~! d. v* R4 M
- JSR Hex8ToDec/ G7 p9 f0 Y% H2 X$ b# g* ]
-
. ^( I) E/ {$ p, l7 R2 n - LDA FC_Dec_Data_10
- x; ^, I. F3 R3 y( r - CLC
( H0 T2 q4 g4 J: @6 t1 M* R+ j1 \; B - ADC #'0'
0 c/ E( w Z# ] - STA Use_PPU_Buffer,X0 Z9 _8 S9 C" V1 F% F4 q- Y
- INX
) G) x6 r3 Z* W -
/ @5 }. P* x% a' j) j! U8 u* Z M - LDA FC_Dec_Data_17 c# g. u) v. T/ w$ D: n# v/ N) N; ^& |
- CLC( Z& @# x- O1 B
- ADC #'0'' E% r; e4 ?' S# ] V- N
- STA Use_PPU_Buffer,X3 s# I% H" F& S+ w0 X. L
- INX9 w6 E! x$ I" ^1 [
-
5 a+ ~( C/ t1 `5 d) F" H - LDA #'/'
* x3 ?% s5 g/ H- Y - STA Use_PPU_Buffer,X
9 L; {" P% v/ Y - INX& g3 f7 c! S9 J: { a5 M2 ?2 f
- 8 E4 h" _ w9 \6 d; F8 u8 K& l
- LDA FC_Music_Max_Index5 s1 ?1 I5 s) T& T
- CLC
% L O; e5 O/ @1 b6 Q. E - ADC #$01
0 T, k, O# D8 }1 D7 Y0 s, f - JSR Hex8ToDec
2 u2 g8 K# s J* L - ! i: i `' n- I+ O1 D8 }6 C
- LDA FC_Dec_Data_10
5 t7 F/ k6 u( { t7 M - CLC
. a- A. b9 q* }* f - ADC #'0'
: V* N) K% ]+ J5 J - STA Use_PPU_Buffer,X5 O' M2 h- I/ E) K
- INX I$ i& O4 s8 S2 x3 Q& |" S
-
! r: m' A* i5 U/ k4 A. k - LDA FC_Dec_Data_1
o7 x2 [2 [( [5 o - CLC4 X! d8 g( @9 [5 \0 p5 `8 ~& G% S* c
- ADC #'0'% @9 L9 g- i3 x2 w6 d
- STA Use_PPU_Buffer,X. X; u% N% L* r9 T4 g
- INX
/ n% L E7 R% Q5 i: V -
- G. N/ q4 D; r& O% H6 d3 x - .End4 Z6 f" b* E8 m4 X
- STX FC_PPU_Buf_Count
" e0 y, K: U: k9 `/ Y - RTS
/ y. \5 u) _- @- }
4 e' S+ C: E+ z. N6 _' p- ;----------------------------------------------------------------------/ {) ?- e E0 N1 p" ]1 [
- ;音乐曲目初始化处理0 D; A% Z" x1 q* |. q! C
- Music_Init_Process
) V2 {1 _* k; P1 {+ V- t) g6 E - PHA
# T2 d* ]( [. y - JSR Music_Clear_Process
) ^9 o/ ~/ q5 q* o! ^ - LDA #$1F
' R9 U9 o& G: H0 Y+ a( t s! O0 ]* s+ D - STA $4015 o+ U) ~! y/ b J5 H0 |( \2 p
- PLA
: L) S# r1 x$ p+ H - JSR Music_Init_Addr
# `5 [) {" ?0 S$ V& \3 o- A - JSR Music_Info_Display* x, ^- D* |6 }# J% \
- RTS; a0 O4 ~6 X; i# Y9 F( w: _% a
$ [# S. a! N3 |0 y* D; K- ;----------------------------------------------------------------------
4 q) D: Z1 K7 k; d$ H4 Y - ;音乐播放处理2 |5 ^: G, w9 L% {) O
- Music_Play_Process, b; h; l+ ~$ f
- JSR Music_Play_Addr
9 \" L5 }/ M, M* d, W4 ^ - RTS
: v2 p# T i( U" F( D - _) a4 S/ ^0 F) R, x; c
- ;----------------------------------------------------------------------
8 W6 C: }2 p' A$ c0 x4 T2 g - ;音乐播放处理
8 Q9 R+ }% W. J/ A* \$ `! t - Music_Clear_Process
5 T! \+ b2 O9 f7 F: y+ S. c - .IF Music_Clear_Addr
( ?, D: I5 m) c$ f. m- k6 E - JSR Music_Clear_Addr
1 q# v2 _0 h$ ? - RTS
: r; t% I. I1 Q& g% a+ z - .ELSE
- w% R$ o: S; m) Y - LDA #$1F
1 q! a) O* N3 t" }( W6 P - STA $4015" V0 W5 T) j7 k
- LDA #$009 t7 _/ Q0 b) I8 \& Z
- STA $4010: N9 o4 ~5 _0 x8 m. V" t6 v
- LDX #$004 m) j4 T1 \- Y, h& V# d! u
- LDA #$00
" I! ^8 F# b& \ e6 f, t' M - - h3 ?2 V2 `1 Q$ |- d, v
- .Music_Clear_Zreo_Page_0
9 L" \' Z" k* O - STA $00,X- R) }4 _- g0 u5 {8 X$ d
- INX
% w' u# k9 j6 ^' K. t f6 H - CPX #Use_Zero_Page_Begin
& k7 V7 ~( Y! o* e. w, C - BCC .Music_Clear_Zreo_Page_0# Q! ~ p& N- e% I
- , m/ r1 w0 Z! r% I4 ?. K; @1 s, s, c
- LDX #Use_Zero_Page_Begin + Use_Zero_Page_Size e- T$ M$ c% \+ w% C
- .Music_Clear_Zreo_Page_1
' `5 {1 P0 @$ b - STA $00,X
( ^7 M& V. K+ B - INX
# p$ }6 s3 X8 g5 ] - BNE .Music_Clear_Zreo_Page_1
; H {3 a1 H+ y1 j, D - : _. }( x1 C; H; y5 [! e0 a
- Music_Clear_Process_1! R2 I/ ?6 `& e
- STA $0600,X
' v4 O! U$ C/ m - STA $0700,X7 M# K; [* O% H& c) V0 ]. I
- INX
! q- s, H! g2 i, L5 H- P6 z: m - BNE Music_Clear_Process_1
- h7 y$ l9 h) h: E4 [ - LDA #$10
- m. f% N% R7 O2 J) c4 p) `- V - STA $4000
' ]" t3 F1 U, L9 u - STA $4004
V# I( S3 k9 ]" X v5 V - STA $400C
/ L4 {0 d# B/ U+ k2 L - LDA #$00$ @2 y* L, C( r0 M: T5 M: z, L
- STA $4008
* J, O1 g$ v. s - LDA #$0F M- q, E# u7 S) `; b8 J
- STA $4015
% v# @. u) ~7 a+ K) t9 ?# E - .ENDIF
/ m. ^1 Y, H; S5 B* j( H" d -
* E, _% B( P* {* s - RTS1 b! E8 ]4 f6 W$ W+ R6 a- F5 i
! R4 M& Z3 b" u G' d9 U/ G! X- ;======================================================================- o6 I+ n1 r. V% s6 H* J' R3 I
- ;重启处理
) c" `' l. P8 ]2 Y4 d/ Z; m - Reset_Program
7 `1 g. C/ e( Q - SEI
& e% h" ]# d( g$ k7 ^1 ^' N - CLD3 g% Y+ S$ ~1 |/ c; W
- LDA #$00
* ^5 \( g* \. t0 m - STA PPU_CTRL9 u8 t* [9 K6 F9 v+ j" L3 o \' \" h
- STA PPU_MASK( \; P3 ]4 i7 H) R4 n3 X& S. s
- STA JOY2_FRAME2 s2 H) e6 N2 I" f5 D/ C$ [& D+ w
- STA APU_STATUS( S" m+ H/ b2 |4 ?5 r, ?' E4 W. Q. ^
-
( q5 `( y. g W2 c+ |$ _+ p3 | - ;等待屏幕准备完毕
2 x% W( `9 _; {2 N1 \ - LDX #$02+ S9 M* F- g2 e8 R t @
- .Wait_For_Screen_Ready- p9 @+ a! j! c4 l( R4 K
- LDA PPU_STATUS
; U4 i5 x2 v) M2 g; V) O& X - BPL .Wait_For_Screen_Ready
4 _ V k, q1 u - DEX
& d! e; y: j7 Q7 D9 n3 L+ D - BNE .Wait_For_Screen_Ready
9 _9 i5 U0 _( _0 D4 J b -
# h( Y. Y9 J+ m* D - ;清空调色板
9 n$ d+ q% b# `- M! ` - Palette_Clear
. N( C8 _. u& y% L - LDA #$3F3 w' V7 K! L7 L- N9 j: Y9 p
- STA PPU_ADDRESS
2 C2 j9 C$ {- g) O& Y - LDA #$00) A& i* ? D/ D& |& c: _- U6 j
- STA PPU_ADDRESS- P' A; y7 m# i. _& J
- LDX #$20
4 r0 n( u: ~! f9 w/ B# K. X - LDA #$0F0 z5 c; ~, i/ N& T/ e
- .Write_Data
' ?+ }- H$ O9 J5 i* v: A - STA PPU_DATA! t1 i7 L2 ~ J& r7 v
- DEX/ r6 t9 \% r- S. \) G, t0 L6 i
- BNE .Write_Data- y) I. Q/ I# }5 j" f0 K1 I
0 E- O( ~- D) s M% h- ;清除声音 $4000-4013
- K, s- A D& l" ^0 g" O: @2 {3 \2 s3 [ - LDY #$14
" M X7 A+ d# g5 x( W( x - LDX #$00
6 m' \" H, v6 V+ v - .Sound_Clear
4 w' O( `3 z1 w9 w- a+ I/ M - STA $4000,X' {) Z1 N% ~) Q' S1 f$ O% e
- INX9 f/ I' e# j' u
- DEY
6 Y& |( s# n* Q2 O9 _ b/ l1 p - BNE .Sound_Clear: z; B5 i) Q, M( {% Y
-
* q: k8 n* U% a - ;清除 RAM $0000-07FF
* E6 c+ P+ `' X- a - LDA #$00- V3 b8 B7 ] D1 |. v' U( O
- STA $00
8 l2 s! \6 h6 L, W - STA $01
4 K) B% E' V% n, V% d \ - TAY
! q/ f3 L0 q& `" U - LDX #$08
: r0 T2 c: B$ k0 J9 Y, X6 } - .Memory_Clear
" E' e, w) a' k: l. [+ P3 W# { - STA [$00],Y
5 [8 _ \* ^8 [7 e8 K& h) W - INY- i2 D, C5 A( X) u+ _+ C. m
- BNE .Memory_Clear- [% g* ]% |* g* J* e
- INC $01
& O# a7 F# @2 l5 Y8 {! H3 a - DEX' O- v% {* r1 {5 c W
- BNE .Memory_Clear
' h: ~4 U- Z$ _9 B( ^! [ - 7 a6 Y0 B1 w# H3 `4 @2 v% ~6 H, u
- ;精灵缓冲初始化
+ D4 o. h5 ?: j - LDX #$00
) u& b; x) x: s r0 z# z - LDA #$F8" a* J0 v9 q4 e& h
- .OAM_Clear
- J4 q8 B4 U. V# |' J: M% T - STA OAM_DMA_Buffer,X
( U) n4 i1 g4 w8 g" c - INX5 _' g4 e% P. q
- BNE .OAM_Clear4 j0 p+ Z; ]& ?$ E
- 4 F/ b7 z0 v/ J
- ;栈指针初始化
: E7 ?/ C8 ~' o% P - LDX #$FF
% y/ V3 r, X8 D! v - TXS
/ @% \9 b; {' c& X4 ~; a- U O - & X2 X+ @. @& e9 f% i5 C
- JSR Nametable_Clear;命名表清空
' t6 K7 y) W' A& l# J6 {7 L - JSR Palette_Init;初始化调色板缓冲. ^: d% C4 O8 j0 [% Z
- JSR Static_Text_Init;初始化静态文本. n2 U" R) f5 L7 d
- 9 q0 m. M' l0 M$ g+ P f
- LDA #MUSIC_ITEM_TOTAL - 1
/ @* s; X6 J+ e - STA FC_Music_Max_Index$ y( k# N1 Y" V3 u, a0 C
- ' @, G6 d: Y* ?" N8 G# p
- LDA #$1F2 V% i2 v: p# ?: _( |1 q3 [
- STA APU_STATUS3 l" _- a/ G2 I# D. K8 Z
- LDA #MUSIC_BGM - 1
3 V n' C i/ o2 u( x4 c. a q - STA FC_Music_Index; T) n, u: l$ t/ w* w" S/ @
- JSR Music_Init_Process;音乐播放1 f5 I" J, J3 X3 K
-
* Q9 K5 k; G) W% p6 m- ]- v1 ~ - ;设置屏幕显示状态缓冲(当NMI处理时控制屏幕显示状态)
: Q' _( W1 _0 O" j: _ - LDA #$1E) ^* W' r) \% T
- STA FC_PPU_Mask_Buf
+ X* |- s+ h' r -
! ? ~9 P. l+ x1 O o% x( i - ;启用NMI处理
& W7 P6 W2 o: a; w( C+ o( n - LDA #$80
" G$ U) | M+ u, H& T) A - STA PPU_CTRL# E! @2 U$ b4 ^( W) ]/ V$ ?! m$ w2 E
-
; n0 h8 T- {$ d5 z% V, m8 }2 U1 [( v - ;程序循环, 剩余工作交给 NMI 中断处理$ v9 I2 c1 R3 x) |: L. M& b
- .Loop& L* @1 J" N, @; y
- JMP .Loop9 j- `3 m# _- J
0 w3 R6 Z% K& t; Q! C+ {" C$ P: R- ;======================================================================
; o1 Z1 Z) J; Z0 c3 z3 O# q3 a7 H8 b - ;不可屏蔽中断处理
. m7 |! K: v' m% ^ - Nmi_Program/ @4 u, r7 A) G. C0 R* f! g' L
- PHA
2 X0 |- a1 x- i( K: Y9 g2 N! Y - TXA' r4 C8 e3 f9 _' g! v- i( Q
- PHA* J" |* c0 `1 n0 Y% M' ~$ P
- TYA* q# D- a8 T& h/ `8 G# O3 h
- PHA: E! h% d+ n3 b7 p' U
- 9 b" N* y1 S' c" |0 O! a
- LDA PPU_STATUS;读取使得 PPU状态寄存器复位
% I1 q- D6 w3 s9 Y -
) n# n9 }. v& R' q$ p3 ~ - JSR FC_PPU_Procrss;PPU处理
" j$ k( M& T# S# s& L - , s( N2 X9 A: G6 Z G2 A
- ;精灵内存更新
0 i& z! C1 q7 m, o - LDA #$00
7 v5 n+ L! E( g' U# N3 R - STA PPU_OAM_ADDR' A' K9 c2 m1 |- f, e" y d& o
- LDA #OAM_DMA_Buffer / $0100
7 y7 r& N, E9 [! b4 {) B/ `: w - STA OAM_DMA
5 T. f% Q8 \6 e3 M# }7 w -
0 d) ~( E3 f- W7 v$ M Q - JSR FC_Gamepad_Process;手柄输入处理
1 o" F1 u4 J) U I - JSR Music_Select_Process;音乐选曲处理
6 n8 x( R3 r3 D* R% q - JSR Music_Play_Process;音乐播放处理! U2 m7 L/ f5 G0 b: @- m* X: v, {% Y( `
-
$ r# X3 k# X, A. J6 b3 L, u- B - PLA
$ z% p% s, b& {+ p' g$ G# G - TAY8 D( V, W2 N! T. E
- PLA
7 X3 {% H% s2 ]0 o" U - TAX' Y2 D) ^& Y1 H! V( [+ s X/ K7 P
- PLA9 Z% @/ n" d) Z1 l
- 9 w* i% |3 g/ W0 {! M
- RTI
" A8 z2 w3 H7 u3 F/ _5 g& N
3 N0 W5 e8 {' U: ~- ;======================================================================
. q7 d9 l% R% c3 @7 E - ;请求中断处理
& e$ ?3 y- Y# e8 p3 l - Irq_Program
6 w, n, u: @+ b. g s" }! T6 B/ n - RTI$ s* K& h' z) s& w# w5 r
- 6 n6 W/ W( q/ R7 _4 r3 B
- ;======================================================================
" L+ `) j# L* i- u3 A7 {: ]7 ~ - ;中断向量表
; A; R$ U+ J3 U7 R' D$ e - .ORG $FFFA
0 w" [: p2 {* F% V - .DW Nmi_Program ;NMI触发时执行. p# p% B' f% @. D6 I8 s; b) H
- .DW Reset_Program ;载入ROM时最先执行
/ B+ f$ D: a- w9 Q; B8 Y5 [$ f: I7 s; p - .DW Irq_Program ;IRQ触发时执行- L; R; y# T3 L' p
复制代码 6 s5 u; v# P; W$ n$ W! k% Z
. w" C$ e2 _# x# v I6 k, S' ^
/ e) A2 e) u# F6 o2 \3 Whttps://gitee.com/flame_cyclone/nesasm_3_2 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
1
查看全部评分
-
|