|
|
这是个 nesasm 3.2 入土教程, 感兴趣的可以研究下' }% C' v0 S' k

$ ?) X: k1 p' N8 N1 _0 v6 T8 I1 w以下是主框架代码:. C) F8 ~* w2 h1 P' ^( Y3 j1 \
- ;======================================================================0 k/ h8 v h3 r& K
- ;文件头
1 }5 J1 ]7 ^" d: d - NES_16KB_PRG_SIZE = 8 ;16KB PRG大小数量
* t9 T) o _( [5 Y" l [" I4 @" W - NES_8KB_CHR_SIZE = 1 ;8KB CHR大小数量
- B% ]# b# Y& M/ C A) @ - BANK_DATA_MASK = NES_16KB_PRG_SIZE * 2 - 1 ;bank号掩码
: c* ]1 n$ y4 _: g - ;======================================================================
( ]' S5 d! B9 J8 y6 l K7 c - PRG_DATA_BANK_C000 = NES_16KB_PRG_SIZE * 2 - 2
. s# c( Z: O* l) W5 O! J k - PRG_DATA_BANK_E000 = NES_16KB_PRG_SIZE * 2 - 1
5 z# F4 ~& C" J# S/ X1 ~; L! V: K - ;======================================================================
$ R# ^/ \* q3 G4 e7 e! }7 y+ i - RESET_BANK = NES_16KB_PRG_SIZE * 2 - 1: Q ^/ `8 a g$ v7 F$ P: ]9 y0 Q
- RESET_ADDR = $E000 ;主程序起始地址
2 D3 Q0 ?5 G- @( f - ;======================================================================
+ a! x8 g# `. U, l. S# f - .INESPRG NES_16KB_PRG_SIZE ;16KB PRG 数量, $01-$EF8(1-3832),即16-61,312 KB' P2 F( B+ _" \+ Z u$ ^3 k2 y& x
- .INESCHR NES_8KB_CHR_SIZE ;8KB CHR 数量,$01-$EF8(1-3832),即0-30,656 KB9 k( P3 u) Y& {# s! T% o
- .INESMAP 4 ;Mapper号 (0-4095)
" X/ s3 F) R( ` - .INESSUBMAP 0 ;子Mapper号 (0-15)5 [. G: k! N. r+ R5 {3 \
- .INESMIR 0 ;命名表镜像 (0: 水平 1: 垂直 2: 四屏)8 ^# {# H( a- A
- .INESBAT 0 ;指定是否存在电池备份 (0: 不存在 1: 存在)
, \) W) f+ |6 a - .INESPRGRAM 0 ;指定 PRG RAM 大小 (大小 = 64字节 << 计数)% M+ ~& X3 N+ }( \' u5 X) w3 g- F
- .INESPRGNVRAM 0 ;指定 PRG NVRAM 大小(大小 = 64字节 << 计数)* E" Q1 N- u: \" Q+ L" n
- .INESCHRRAM 0 ;指定 CHR RAM 大小(大小 = 64字节 << 计数)
# L& i6 d. e6 g' |) Q - .INESCHRNVRAM 0 ;指定 CHR NVRAM 大小(大小 = 64字节 << 计数)- O0 r U# _3 _; C
- .INESTIM 0 ;指定时序 (0: NTSC, 1: PAL, 2: 多区域, 3: Dendy)
7 E. f s# X4 u/ O( i' ? - ;======================================================================7 C g3 O, ~7 T
- .INCLUDE "fc_demo_config.asm" ;全局配置
' n5 P! z7 a* U. U! w0 H Q - .INCLUDE "fc_demo_constant.asm" ;NES常量
) Z* u/ B# c9 M) X! g, T - ;======================================================================- l5 }7 N$ \, f) a7 ^$ v$ q
- ;音乐配置
w7 j' O9 t5 B' R2 W. X - .IF 0 = MUSIC_THEME 6 J: D& a3 y3 T
- .INCLUDE "data/music/Gremlin 2/config.asm"" C- {" R. m5 @2 Z
- .ENDIF2 F5 @# l0 Q: \8 m2 X
-
- }# }/ q9 Q+ k - .IF 1 = MUSIC_THEME
+ ~6 [, f6 @( p- q+ S/ K - .INCLUDE "data/music/Raf World/config.asm"+ y6 L5 A1 g7 K
- .ENDIF4 D+ r# q4 s: f3 F; ^* X6 ?; H
-
+ ]( B2 x1 x/ A0 H9 c9 H ~ - .IF 2 = MUSIC_THEME
# z+ m8 v4 k$ g - .INCLUDE "data/music/Ninja Gaiden 3/config.asm"
# U: h. v& P, h. ~7 g4 b! J - .ENDIF6 ~( i7 k) l( B7 `
- * D8 G/ N% N6 W3 _3 I0 X/ W
- ;======================================================================7 _5 Y! D. m3 l- @4 j
- ;引用CHR图像数据8 S, q5 O% ]) S- c3 W x. Z: g
- .BANK NES_16KB_PRG_SIZE * 2 ^( M9 A- @ i1 M
- .ORG $0000
) Q& ^+ \5 G5 I - .INCBIN "data/bkg.chr"
- E! ^! Y' p1 _ - .INCBIN "data/sp.chr"
: M* {3 ?) d' P& F - 6 B4 m1 D8 T% d* H& p
- ;======================================================================6 S: i3 E; d( ~
- .BANK PRG_DATA_BANK_E000 & BANK_DATA_MASK;设置程序所在Bank' D$ H0 k# {. @+ I8 d, O
- .ORG RESET_ADDR' q7 i" }( q0 N2 i- o: g* M# Y
- ;======================================================================
; ?( ~6 z' J+ ?3 E) |$ G8 P - ;引用其他源文件7 L, O2 \" U3 o+ q g; d
- .INCLUDE "fc_demo_ppu.asm" ;PPU处理
3 o* S3 J5 @3 @1 a- q" c8 b - .INCLUDE "fc_demo_joysitck.asm" ;手柄处理9 M+ e A \ S9 o- a
- .INCLUDE "fc_demo_static_text.asm" ;静态文本处理6 Q$ D, Z5 U' s% f# U3 b
- ;======================================================================; G5 n$ _# d) T
- . I/ I7 u, O/ Z- Z$ c/ c- h
- ;======================================================================# q2 P2 h+ ]" j8 j
- ;等待VBlank到来
2 d+ j, y% _ ?/ U( D* x/ ? - Wait_For_VBlank
" F3 o9 _) I/ F5 h - LDA PPU_STATUS
" O6 p, W* ]1 Y- O! }7 G4 ? - BPL Wait_For_VBlank, A* J8 j6 Z8 y8 ^, B# ~
- RTS+ e$ e/ ]- d" M' j+ l$ c2 T
- ) B* w/ z6 S* _) H6 l2 i. R6 h
- ;======================================================================
- p7 l( O+ n* D" E/ v0 ? - ;调色板初始化
5 ?, t# s1 v, E9 J! }5 s - Palette_Init- [9 y8 M1 }: i" d* a; C
- LDA #$3F
7 `% b [* j% c) W8 }; v - STA PPU_ADDRESS" ~) r% W' z; p9 K8 U
- LDA #$00' t8 ]2 H7 w! X1 h/ t
- STA PPU_ADDRESS( I7 d* _) i6 e/ K
- LDX #$00/ w" Q) i/ G1 W$ G
- LDY #$20+ _/ k' }- W8 t7 O% ~
- .Write_Data* C/ E' E6 A& U( M
- LDA Palette_Data,X4 p0 [. u" f+ v7 J
- STA FC_PPU_Pal_Addr,X
& P' d& v. s: A- F; P$ F$ | - INX
) y8 G, n. x4 Q - DEY
( r4 Z! E6 t. e% S; T% }2 Q" ^ - BNE .Write_Data
( [) j g& Q' g; _ - .End m0 `* j9 n* @; y1 O! [6 P
- RTS
7 N* ?6 G; \9 G- X/ v
4 a0 o% i) e4 d. N( c E$ s6 D% t- ;----------------------------------------% r5 P5 \5 g$ m6 z l3 ]
- ;调色板数据9 }* X" I8 A, \+ Z
- Palette_Data' \* c$ G& W- [' b: @
- .HEX 0F 20 32 02 0F 20 32 0F 0F 20 32 26 0F 1B 0F 1B) D, I6 L+ a+ I! O/ z
- .HEX 0F 21 27 22 0F 24 24 24 0F 21 21 21 0F 22 22 22
' y& a* B7 p, ]! t -
" ^# g( u: p& l+ g" V$ i" F* E - ;======================================================================
! q9 j* t" I: ]+ p% T' P# R - ;命名表清空# i$ V: Q$ ?) i+ n
- Nametable_Clear
# z2 N& \1 Q. A; U8 L: |( C - LDA #$20" C K1 k# R' t# B: O
- STA PPU_ADDRESS- q( C" R P, K2 P8 _
- LDA #$00+ W+ M r2 r2 _8 h P, V( [
- STA PPU_ADDRESS4 y* Q- N' X8 H0 a7 Y
- LDA #$00; d- {6 F2 Z; L2 R$ l( U
- LDX #$008 f. x9 Y {, ^' ]" u- W6 I
- LDY #$08, z5 V# m8 J1 p6 Z
- .Write_Data
+ J6 x0 R2 B4 l7 Q& j% |* B - STA PPU_DATA/ F9 W, C3 A2 u3 ^% S
- INX8 `5 ^! x" w. A7 T' \
- BNE .Write_Data
1 @+ Q% ~! ]6 N8 _4 v+ | - DEY+ O8 a( I4 S4 @/ U7 n: F
- BNE .Write_Data
* D( s- ?& A/ [3 G' ?1 x" e4 E - .End
7 _/ Z2 ]8 _* F& Y1 o* h( y - RTS7 d1 v' D( ^* \8 l" o# I
2 J3 z h) C4 ~- ;======================================================================/ D* m; z0 Y* l7 H& E' m
- ;音乐曲目切换
# U$ V( `' m7 {) R* b6 V8 I - Music_Select_Process" v0 W% z0 G6 m4 H% Z* _7 L" e
4 k# ^1 ?/ u' P! y- .Pre_Music;上一曲
5 ^1 J1 ?5 ^* ?- A& e, ?2 ` - LDA FC_Gamepad_Once7 ~ K! P+ c) `: z
- CMP #JOY_KEY_LEFT
7 {; d. ^8 f' e* x - BNE .Next_Music. c' {: G- l( ^- ?: t3 d
- JSR Music_Play_Pre
9 M3 V" s8 U4 n4 W/ b) q7 A - .Next_Music;下一曲. `" D* i' o @0 r J. N! @
- LDA FC_Gamepad_Once% M" w6 _) ~8 f4 L
- CMP #JOY_KEY_RIGHT
9 v- x4 n O8 d% X& p - BNE .Next_10_Music2 T7 p2 L( N/ D3 n" X* O b/ H2 j4 d
- JSR Music_Play_Next
- p- i" ?" G4 w - .Next_10_Music;上10曲
8 W# c8 t5 I3 S: J9 D: J; M Z8 d - LDA FC_Gamepad_Once
( w& i! o* p* X - CMP #JOY_KEY_UP
0 o* {. u& P& u$ g% ^4 {$ ]1 L - BNE .Pre_10_Music* G0 U# p4 n; K3 g6 c
- JSR Music_Play_Next_10
, |) i/ o& C6 R$ R3 F$ T0 M - .Pre_10_Music;下10曲
" S1 a# f$ C7 w% f) |, Q - LDA FC_Gamepad_Once, n- W! y/ \1 g& O8 y0 D7 N
- CMP #JOY_KEY_DOWN1 I, i0 u: C6 L) v1 T/ g, k
- BNE .Reset! L* v4 F( B4 }8 T
- JSR Music_Play_Pre_10
) Q" \5 {: h; A! s! G' G: u8 X - .Reset;重播当前曲目
9 l4 C: _, Y8 V% |" s2 X9 C - LDA FC_Gamepad_Once
: y; F- j- f* I - CMP #JOY_KEY_START
8 F5 T3 ?: z3 [4 q* r+ L - BNE .End
; Y9 X! S3 l/ I+ s8 Q0 [0 H - LDA FC_Music_Index
# G* X4 K6 @, L/ e. t/ } - JSR Music_Init_Process
8 Q. W; R( z$ O* `' m4 l - .End
% j" X$ ?2 n9 {0 q( v# N - RTS
* x) p- I$ B- n. Q8 k: T
+ M5 W- q% I5 \9 k* |- ;----------------------------------------------------------------------
" D$ W( K8 q" P, y3 \ - ;播放上一曲
8 x- T0 Q X) M" x. N/ `2 b - Music_Play_Pre
- k+ h% S9 v+ l! ~2 r2 U7 S" Z - LDA FC_Music_Index$ e0 w0 j4 ~1 b0 D0 x, \) }
- BEQ .End
2 ^* ~! n; N0 E1 k4 c - DEC FC_Music_Index+ H, \+ y1 d# K" c/ Z8 g
- LDA FC_Music_Index
/ S# q' s" T, u+ }% G6 U - JSR Music_Init_Process. q& Q0 m6 g2 L* O
- .End# G) ^! {+ X7 `5 v3 [* {8 h
- RTS- W W! V/ _) w9 Z- a
- ;----------------------------------------------------------------------
" v' w+ }& R; g8 R5 l - ;播放下一曲 T1 R# a$ F$ D: B: |" ?4 N1 p' F; j' b
- Music_Play_Next4 T) F2 T/ F( Q$ ]
- LDA FC_Music_Index, M- D" @( M3 N4 o; U
- CMP FC_Music_Max_Index
) L' W+ }1 P+ M7 P - BCS .End3 N8 S+ x0 ]. _- Z. x
- INC FC_Music_Index7 ~: k) ]' p0 X# H# `/ a8 k3 l
- LDA FC_Music_Index" n- c) g8 L2 Q4 Z9 j) ^
- JSR Music_Init_Process# _* a* ?& u0 t
- .End
; Q3 Y: k9 f, _" S - RTS
6 a3 y1 U4 y& I$ a/ F) i" z
- f* {/ W/ ]" s' k' f; f- ;----------------------------------------------------------------------
; _" y" `. d q - ;播放上10曲6 `, n' }( S, G# t
- Music_Play_Pre_100 C4 u9 ^! ], v4 B2 R8 v
- LDA FC_Music_Index( j. u9 Q) N- E% A) G* j
- BEQ .End
. U0 O( w0 [* Y3 K - SEC2 k# h4 \- A# s& v4 k$ Q
- SBC #105 ^& {5 E: L0 X/ q2 R
- BCS .Pre_10, @: e& w( d: _5 U
- LDA #$00
% i( N4 S1 f6 l% d - .Pre_10
8 P) T$ k! p4 q7 W/ y - STA FC_Music_Index
2 s9 n% a9 z1 } - JSR Music_Init_Process) B3 U6 c, i9 a% q
- .End
- P, P/ u j- k( y( { - RTS
7 h$ m! I2 c$ j - ;----------------------------------------------------------------------
4 ]: Z: x$ g3 O$ M* E; T7 G - ;播放下10曲7 F1 n) s T8 ^$ d* M
- Music_Play_Next_10( N0 _3 ]' A5 b" c- ]3 z
- LDA FC_Music_Index
% t n' ?0 q8 W$ x1 G9 v - CMP FC_Music_Max_Index! B" a3 a4 a/ |" r( g. {; F
- BCS .End/ k' B2 ^! O/ J& y8 W4 S
- CLC
4 @8 \( B2 D- {+ P' n" w - ADC #10: n3 H \* ^3 o8 Q4 v# J, W: O* C! g% E
- CMP FC_Music_Max_Index# M- I, d7 z$ Y+ k1 N/ P# o
- BCC .Next_10
# o8 {2 G7 |) b/ C& u - LDA FC_Music_Max_Index G+ ?6 x# P, [- } |# e5 l
- .Next_10. \% T0 M4 H+ b% j$ p- b. r( G0 X
- STA FC_Music_Index
. | O' Q; ]- K' @' |/ x8 Z5 C; u - JSR Music_Init_Process
& ]5 _' S/ B9 i1 O - .End
# `5 |" f! O4 v3 I/ R; w - RTS
8 f& d8 k. z7 @" d' x - 9 q% T" @5 A8 U2 V- p( M6 j4 I; w) S
- ;----------------------------------------------------------------------+ ]9 S( K9 w2 R+ K8 ^2 U$ z
- ;8位十六进制转3位十进制制. r7 Z+ X8 x% {0 c7 y, L
- Hex8ToDec
0 I( c" g, F' F+ V5 s - STA FC_Dec_Data_12 `. K! ?4 `+ R; g7 I H% o6 _
- LDA #$00" E7 o/ M/ [ |6 X- e0 [+ P
- STA FC_Dec_Data_100
2 N& d6 y5 T- o - STA FC_Dec_Data_10% U' Q4 L" c0 f+ }
- LDA FC_Dec_Data_18 ~/ F" v$ ^3 s9 C2 L
- .Convert_100
]: h$ y/ W% N" Y - CMP #100
* x5 f/ Y& Y: L4 d1 k0 |; Z% A9 c) z - BCC .Convert_10$ y6 R3 T7 P' k c: V, \ G
- SEC
& Y% Q+ x- s& _2 y1 ?" ? - SBC #1007 m3 P E6 @) c8 o. J
- INC FC_Dec_Data_1002 ~+ s- s5 i! A2 Z
- BNE .Convert_100- U$ Q2 k6 N4 M1 F* G$ ?) a
- .Convert_10
0 U+ L; E2 U0 a9 w, i+ d3 I( ? - CMP #10% L/ P6 @; z. Y# J' }
- BCC .End
4 D8 J# r5 `, s' z - SEC
- Z- g1 p& k. I5 l0 U - SBC #10! ]3 T) [3 N( b2 j6 j& V
- INC FC_Dec_Data_104 v3 d5 l: G/ Y. O
- BNE .Convert_10
0 d3 i8 k0 O, u/ K - .End
$ e' q( L$ U7 _; \9 L - STA FC_Dec_Data_1# V! C, s$ D* y: w/ R0 E
- RTS
j; r8 r$ d! c4 N1 T% ^% N; ]1 B - " C- b4 Z3 h* n
- ;----------------------------------------------------------------------
" o3 T9 i9 d' k, l* `" W - ;显示曲目信息
$ B$ p# S# t& @+ e- K - Music_Info_Display, \3 m; D! R2 V& k9 E# I
- LDX FC_PPU_Buf_Count
M* \6 q3 c2 s) q. e' o, c - LDA #PPU_WRITE_MODE_CNT_LINE
1 n+ G) Y- u& K6 c+ t - STA Use_PPU_Buffer,X
8 X1 j* r) G: t8 @3 R. J! x# m - INX
. v! W3 e; f7 O6 N- ^% J - # E: z6 ^9 U. o2 c- I6 h- u2 D* |
- LDA #>MUSIC_INFO_POS/ J; g4 g3 @: N$ K
- STA Use_PPU_Buffer,X" [6 f( B# j7 Q2 ?
- INX/ M `' C' Y# ?# q( }
-
5 }. Z. S. r9 y3 s/ |; a - ;居中1 T+ D9 I, ^; s" g: C8 G
- LDA #<(MUSIC_INFO_POS & $E0) + (32 - 5)/28 T" b# N: s; W9 y9 a
- STA Use_PPU_Buffer,X& I: }9 J3 F/ ]$ [$ ~
- INX: R9 V" P+ J6 U) e4 Q( E
- 8 [0 |( {( c: Q; l4 `1 \/ W
- LDA #$05$ v7 @. z$ F1 i7 v0 u) J* m
- STA Use_PPU_Buffer,X
, ?5 v" h) w! I& Y - INX- s$ p8 M/ M8 _5 X/ n" I' D3 ]) F+ M# M
-
5 K2 b& ^: u0 s- Y0 l; e' b - LDA FC_Music_Index
6 o& ~( e5 w: D - CLC1 u) a. Z6 h3 @2 a2 {
- ADC #$01
8 o% t9 R; r' g7 U - JSR Hex8ToDec
1 K# m8 c2 O1 U- ] - 9 \' L2 j0 v5 A/ n/ N7 G
- LDA FC_Dec_Data_10
$ P* j2 f# C* P* k5 x3 V - CLC
: T6 t" m" u0 c3 \ - ADC #'0'2 {2 N) a7 f" g4 M9 I1 f$ X8 D
- STA Use_PPU_Buffer,X
, V: h. ?' W! m. u) @- R& } - INX
4 [, [0 \3 o4 ]2 _5 @ - ) o" C; x; L& I: E- C
- LDA FC_Dec_Data_17 W5 w. @* A' {; Z u5 M! C
- CLC
" d+ n9 Q, z, M2 x$ s" d; Z) t - ADC #'0'9 j, o, I! \( ~+ y
- STA Use_PPU_Buffer,X
( M ^4 _1 P/ q* O- x# O - INX
2 p" S1 S* ], @6 ], R p -
@8 R& f& I9 V% _* H. x" t4 r - LDA #'/'5 v( O. t$ U, H9 _- I
- STA Use_PPU_Buffer,X% {; e7 g6 C$ e9 ]0 d2 I
- INX3 C# d- X) G; R! l4 k6 B" H& {2 ?
-
% }, X0 F V) ?8 p& P4 E! A$ I - LDA FC_Music_Max_Index. s! r* _4 k0 O' [8 j3 p
- CLC
8 t" V. l# q: M2 h% N7 v2 b* R J% G - ADC #$01
, h0 `% L8 K$ W - JSR Hex8ToDec2 {" \$ C1 R" T; e1 L" N
-
Y8 S6 S' J3 E( V$ u, ]' R' S) \- p - LDA FC_Dec_Data_10, J( Y& b; L2 g0 _4 ~
- CLC! s+ K# Q5 S! E; k W
- ADC #'0'
2 W7 R1 _% P) i6 {) | - STA Use_PPU_Buffer,X
, i; n$ F7 P% A" U6 B, k5 m - INX
7 h+ P* B6 H$ @3 \# _/ D -
4 E, q. E$ `: } [- C' X+ y - LDA FC_Dec_Data_1
2 K) {7 w7 x" }' F4 {# s - CLC3 }0 C1 X3 ]$ l( J: R# f
- ADC #'0'
, t) J$ l( b! v4 x. m - STA Use_PPU_Buffer,X9 J% H9 q4 e) c4 `
- INX/ h+ L* q% f2 V1 f
- 7 S6 u( c% [4 @
- .End
: L2 u7 M0 h0 R- s' O( ^6 \ - STX FC_PPU_Buf_Count X! J* {* q9 s+ p/ A3 c
- RTS3 q2 X$ \, p7 @! q1 H- C5 E
- , i' K+ Y- }9 _. v1 i8 T g6 U
- ;----------------------------------------------------------------------+ O1 q7 B2 N+ W q6 _
- ;音乐曲目初始化处理. D# @. W8 o& S9 V4 S) ?5 ]* C
- Music_Init_Process
) ~" F3 N2 B/ I8 S( ]* P' @ - PHA2 P/ I7 U4 e% o- M% P/ L
- JSR Music_Clear_Process; D* V4 T" n0 E
- LDA #$1F. _* v7 h6 N+ Y+ H
- STA $4015
- W( v( A4 E- f - PLA5 Z; w* O( l: L% c. C0 q* P% W
- JSR Music_Init_Addr% i+ u+ S' C! `( C6 \
- JSR Music_Info_Display
4 S1 v& t; l- y - RTS% J0 e: L8 g. d2 B8 y
* I: |, f8 H5 l+ A0 y6 ?& q- ;----------------------------------------------------------------------
1 m+ W! z/ c; E1 y- ?* _- x - ;音乐播放处理! n+ \( e" b B. t# U
- Music_Play_Process
6 V9 F. G% }+ z4 c7 T" ? - JSR Music_Play_Addr4 R' v4 |, \8 C+ ^: f( m
- RTS
3 P0 R- d6 ?4 j' W9 d
& h# K3 t5 T) L- ;----------------------------------------------------------------------
( Z2 L7 g) l1 j7 } - ;音乐播放处理5 u- ]/ g* d% J& z
- Music_Clear_Process
+ s! g" h3 d: a$ f0 l - .IF Music_Clear_Addr% H3 X- @/ }; ?! S8 Z+ m. J
- JSR Music_Clear_Addr
2 d' }7 ?8 d, u5 o% h' T/ N - RTS/ A) G& d3 a& k8 R) k) _2 `% J) E
- .ELSE
. E, k' G0 D0 P. g5 K - LDA #$1F! \ j+ @* X6 N: y$ w [
- STA $40158 k [. E3 I: O. J& X% q
- LDA #$00
0 e9 ^- T0 s. ~. g. Q; U( i - STA $4010
`0 ?1 P5 \7 m% P! B - LDX #$00
3 a5 A- k9 S' n$ T, t% T - LDA #$004 {3 m- A; _6 ]( H: w! p0 b0 `" A8 v
-
# {' {! u2 P3 P/ e" O% l6 ~& O - .Music_Clear_Zreo_Page_0 H- l7 C% [: o
- STA $00,X7 \3 \" g: n' G2 U! C8 d4 ?+ H
- INX3 ?: m% w* i U }( I. r
- CPX #Use_Zero_Page_Begin3 Y5 ~# H1 C1 S
- BCC .Music_Clear_Zreo_Page_0* j' ~3 l( t% X
-
- @& I( o) f/ \; ?4 L - LDX #Use_Zero_Page_Begin + Use_Zero_Page_Size3 o4 L) b+ d& ^- l. e7 _' w
- .Music_Clear_Zreo_Page_1
% h5 S' i! H( |4 ~' k* b3 T - STA $00,X8 Y' B" d5 r5 d
- INX
- y+ R5 i5 x4 _, ^# \5 n( r" m% ] - BNE .Music_Clear_Zreo_Page_1
+ W k3 A2 l# g5 t! w/ o -
7 Z {4 E1 d# Z7 e: m( a+ B - Music_Clear_Process_1& ^3 P6 t4 n* z
- STA $0600,X
1 b& D- `% Q$ e% l. Q9 A - STA $0700,X! f# m. D0 _' ^( |# r$ q& [1 a
- INX
; ~/ l: ~6 m6 C& a$ g - BNE Music_Clear_Process_1 y- ?6 D: T' e' e0 G
- LDA #$10
, w. w5 i$ o* a& f; O1 {8 i - STA $40006 x0 D* j+ }1 v$ N3 R9 X4 @
- STA $4004
8 u4 }4 w- ^7 C+ ^- p, J - STA $400C# {0 c5 Q6 J9 d \; [/ w
- LDA #$00
" V2 V% ~0 a# i* R. z7 b - STA $4008
* E/ i; ]- r |0 O. d$ J% \! ] - LDA #$0F
) W7 r/ a1 Y! f+ X" N2 ] - STA $4015- y U# y+ r, i. o5 v" a; f' B
- .ENDIF
: G! Q4 |* \" T5 {, f9 y - 9 t: {' R$ x+ J
- RTS3 e7 F( D2 U: K, m5 |
- @$ N3 r0 I( ?( x; ]- }4 m
- ;======================================================================
7 F) x! c' A' u. H/ u; c: B- h$ u - ;重启处理
# N7 w3 L0 b- d" q' o2 Q - Reset_Program: `0 @. A3 J6 N" s1 R1 _/ j
- SEI
$ j; g7 u7 k, z' |# k3 d - CLD
* U2 G2 H8 c( Q9 W1 m9 S6 t+ @ - LDA #$00
, `8 j+ u# D7 F3 ]% v% a* J8 W - STA PPU_CTRL
! ~% d) F) O9 [3 H: d2 b9 k$ b - STA PPU_MASK
. K- Z, w: O5 H# f! a5 q! W$ c - STA JOY2_FRAME
4 X9 b. ~/ ^8 q- d) F1 n! }& v) a - STA APU_STATUS
4 K J: ^! C& H- n2 D+ u, K - 0 S0 k& v W3 [! c9 s
- ;等待屏幕准备完毕0 J+ L0 H p- `
- LDX #$025 o6 m% u8 N4 l7 ~/ {' }1 {) l, L
- .Wait_For_Screen_Ready% U2 Q0 h: B! v! A8 @4 g
- LDA PPU_STATUS
# @, ] V" T$ R" B - BPL .Wait_For_Screen_Ready! a- ` l) M% P; H
- DEX
5 }0 Q; o4 Z7 b: m - BNE .Wait_For_Screen_Ready
3 o+ o; V" U0 L# c; w% B - 4 N# T+ ^, \! @! A3 y
- ;清空调色板) p7 z0 x+ S$ e# x
- Palette_Clear
) F; y% @: U: {; m - LDA #$3F
. a& y- \7 D' V - STA PPU_ADDRESS% n% ~! m1 c! V: R0 W% _
- LDA #$00
/ m. p9 D! c0 [ - STA PPU_ADDRESS
" y3 g- C- e0 J$ a" e9 ? - LDX #$20
/ b# h+ p- W; R" i - LDA #$0F" h0 z4 t. S& l$ k7 d( M
- .Write_Data' d6 e* R1 W ]. J4 ~$ U
- STA PPU_DATA
9 u; x( G$ u% n! z' ~" ^ - DEX2 L. z" K T" X$ r, M. J
- BNE .Write_Data
' m# K# [8 U" U* _+ N: y - 8 |0 m+ T7 u ?. q
- ;清除声音 $4000-40138 s% {& U9 E& n* d e+ s9 \$ p/ o
- LDY #$14
* ^: z) j" |0 v! F - LDX #$00
: j' J: T9 T$ \" _% C7 w% l - .Sound_Clear
" b& I6 S3 e3 H" {, H# l - STA $4000,X5 |+ s; ]& Y$ |1 J
- INX l/ ^9 U; c6 f. t: B; \' [" ^
- DEY4 X+ m X3 a9 g" j# g
- BNE .Sound_Clear
9 t6 u O* F _. ]9 G$ L0 G- E - 2 ~ O p$ w+ G$ s; X' D
- ;清除 RAM $0000-07FF
2 W1 \4 Q' T' |' s1 ?# G - LDA #$000 Q( j6 a+ N8 Y$ f2 m; l
- STA $00
( |3 T5 I/ q$ X S: x! l8 U - STA $01+ Y, e$ d, x j) w
- TAY
/ J1 B# o3 k' i# s$ Q9 K" {% `$ U - LDX #$08
, c0 J: e8 S! _: D& }- U3 s - .Memory_Clear$ ^7 L# Q5 w% b& \
- STA [$00],Y
) e; Z1 q# {8 ?$ i5 [ - INY
, d! `1 W8 n6 i6 f! V - BNE .Memory_Clear
+ v6 [5 n! o; a& c- R, E% \. x - INC $014 i) _2 V2 _3 Q. p. d z3 R
- DEX
, G" g. y4 R. u |- g U U - BNE .Memory_Clear
; v/ g& W1 C# a+ w - & p1 \: ?! l2 N7 g
- ;精灵缓冲初始化# H" t* p5 z4 e* N u
- LDX #$00
* i/ J4 `1 ?6 Q- ]2 Q& w, |( f. @ - LDA #$F8
* L; K' c( }1 ?- ^ - .OAM_Clear
! z0 I; } h4 y- i4 t2 h- H - STA OAM_DMA_Buffer,X
$ O' M/ t# D6 E - INX7 S( I5 d$ [& s
- BNE .OAM_Clear
n" c% c$ K: Z -
, B7 |1 h- m$ }! o, {' k) |" } - ;栈指针初始化
! h6 m; R5 ~% o: o. @# W8 { - LDX #$FF) J4 p4 {. j% f: W
- TXS3 N; Y% {( i% w( Z: u" C" B
- " D# d6 t( j7 J9 d, u+ ?
- JSR Nametable_Clear;命名表清空' S. ~! l4 S8 K
- JSR Palette_Init;初始化调色板缓冲# I5 P6 `) W [, y7 _0 d6 g) g
- JSR Static_Text_Init;初始化静态文本
7 q1 d9 g& o _- }5 B -
5 X9 T# u$ {" ?, u3 s4 r! `3 ?+ d - LDA #MUSIC_ITEM_TOTAL - 17 J5 ?3 P5 H v4 ^- ^7 i0 n
- STA FC_Music_Max_Index% }* H" N" \0 k: N
- ) }1 }6 Y4 |% z/ ?7 E s
- LDA #$1F
D9 U& r O4 K0 g# b9 e1 u- u - STA APU_STATUS8 N+ h, E! q8 M+ Q h
- LDA #MUSIC_BGM - 1
5 b& \# S* X- s- b# O" | - STA FC_Music_Index
1 t! Q j% v' q - JSR Music_Init_Process;音乐播放) z. P* d2 E# a( y
- 0 G' X* x, {5 }& z0 U, S$ U
- ;设置屏幕显示状态缓冲(当NMI处理时控制屏幕显示状态)3 \' t; E! j- k2 E; w- W+ B4 p
- LDA #$1E
8 w8 h" i1 ^' ] - STA FC_PPU_Mask_Buf2 u1 o- o$ A" b( D
- # j7 I+ S S/ b" w! J
- ;启用NMI处理/ f, D3 f- o( R- d4 o5 Y
- LDA #$80& c. Q0 R: m; [" I: {; t. u. N9 Q5 ]
- STA PPU_CTRL
$ D: d0 k( s! Z - ! k. l, V4 V) t. e" k
- ;程序循环, 剩余工作交给 NMI 中断处理; w# N4 B+ s0 l0 i% d1 N' y9 B
- .Loop1 f# ?+ f- v0 H- z3 `5 t4 F! d$ ~/ f
- JMP .Loop
- `4 C' G+ R! d* {& z+ ^ - ) M; l* j3 G; L" v
- ;======================================================================
1 @: o5 s7 w# p - ;不可屏蔽中断处理. C! k! j5 l: D
- Nmi_Program( ~* D& A7 \9 l1 [) X7 J; B& [
- PHA
2 O7 w8 i. t" R6 j1 [" h) E4 T- Z5 a - TXA
" n# K7 \( g& }) q& b - PHA
( P% q: e0 X7 H2 a8 B- Q% b - TYA
$ m: }6 ]5 a0 I4 }) T: } - PHA! M* i$ s1 _; l& n4 R/ U
- # ?) \4 U! Z- g$ E! g- o
- LDA PPU_STATUS;读取使得 PPU状态寄存器复位
3 x( O" W, e* l) e) ^5 y* @2 G7 ] - * {6 K* |1 ]! y
- JSR FC_PPU_Procrss;PPU处理
: l5 T7 s; N! P9 k+ ?2 f - ( N1 b. n; h) K2 |/ z0 G; W
- ;精灵内存更新
, b, I) g9 ?/ i7 K7 D9 |: V - LDA #$00( I# `, f& Y$ H, ?5 `$ F9 ]
- STA PPU_OAM_ADDR
1 K* `6 p+ A( @+ w - LDA #OAM_DMA_Buffer / $0100
3 P- k! L& n0 L" O; _2 w - STA OAM_DMA
- d! s& r3 O( w: h; Q - + B7 R) V+ p1 M8 o6 h- K+ C8 ?
- JSR FC_Gamepad_Process;手柄输入处理
' t# ]+ y; Y1 F" C8 V+ Q. M - JSR Music_Select_Process;音乐选曲处理: E9 Q* |1 Z; h
- JSR Music_Play_Process;音乐播放处理4 ]+ t: V2 {* s) k- j5 n% c" H
- 0 ]- C7 x0 o- s1 w
- PLA) h7 Q) H" |7 R X4 m
- TAY
6 H6 ?$ ?. m6 V0 J - PLA
/ N3 d( d( Z- j* t - TAX' G: g+ z" E. p+ _& w: @( {: Y
- PLA
: L/ R1 Y5 Z0 \* e) y) \
Q' V6 S, ~7 T* ~! b( ^- RTI
2 l% o/ L6 B& D# n - 2 M6 }0 L+ |# k/ M8 F5 E+ e6 d
- ;======================================================================
3 P6 e7 V: a* O/ _$ D$ H - ;请求中断处理6 C9 ?( j6 K3 s8 u' J% n' Z( u4 K& f
- Irq_Program
5 E7 f: ^8 [* q/ w1 m - RTI
* D6 g' ^9 x0 S; S1 } - . X- b; U7 X* p7 V3 u; }
- ;======================================================================
! @9 J2 q1 I% \& ^ - ;中断向量表
. x. Q M$ z8 b# M - .ORG $FFFA9 a N- O4 h. N- k. v4 g
- .DW Nmi_Program ;NMI触发时执行$ K( P9 }& n1 z% l) d
- .DW Reset_Program ;载入ROM时最先执行4 z+ J. x: O( c$ E: j I& s
- .DW Irq_Program ;IRQ触发时执行; C l7 L! T1 `- D) w. v+ N
复制代码
; W' v. Y, u! e4 A$ v+ y) ?! T$ i" t: R$ w* L6 j" p
. w; K$ ?& a l& y& J7 }9 ~+ V# ahttps://gitee.com/flame_cyclone/nesasm_3_2 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
1
查看全部评分
-
|