|
|
这是个 nesasm 3.2 入土教程, 感兴趣的可以研究下! R- Q- Y% N2 d: A# _$ Y

: _0 y2 d: }: r+ \/ u, {以下是主框架代码:
3 M1 n Y' a+ Z" J8 P T- ;======================================================================! p& g: {6 { R, N
- ;文件头
6 O4 M2 |' K6 r1 Y% E* u% [ - NES_16KB_PRG_SIZE = 8 ;16KB PRG大小数量
1 j. L8 F# F1 F# w* y - NES_8KB_CHR_SIZE = 1 ;8KB CHR大小数量
. n1 H+ g0 Q* N - BANK_DATA_MASK = NES_16KB_PRG_SIZE * 2 - 1 ;bank号掩码3 v/ W4 Z- F2 i+ t' `( L; [
- ;======================================================================
/ b: s- l2 M" q - PRG_DATA_BANK_C000 = NES_16KB_PRG_SIZE * 2 - 22 }6 e. D4 C0 L
- PRG_DATA_BANK_E000 = NES_16KB_PRG_SIZE * 2 - 1
; g' a& x, {0 U2 U2 I# B - ;======================================================================
: y. n* N/ R$ E! a6 J2 ^ - RESET_BANK = NES_16KB_PRG_SIZE * 2 - 1& C j4 j+ r* H/ [8 E; z
- RESET_ADDR = $E000 ;主程序起始地址
5 a' _) Z e6 I' a: o - ;======================================================================
( V$ J' q# r, w* s( d - .INESPRG NES_16KB_PRG_SIZE ;16KB PRG 数量, $01-$EF8(1-3832),即16-61,312 KB: o, o3 d8 G4 l$ Y% J3 M; g
- .INESCHR NES_8KB_CHR_SIZE ;8KB CHR 数量,$01-$EF8(1-3832),即0-30,656 KB
5 B; L( t; f9 m! z0 C - .INESMAP 4 ;Mapper号 (0-4095)9 X: Z' E1 G3 L6 \& ], \* I
- .INESSUBMAP 0 ;子Mapper号 (0-15)
% F) E& n5 c: M/ Y4 g$ m# D - .INESMIR 0 ;命名表镜像 (0: 水平 1: 垂直 2: 四屏)
8 G: v# i) C- @2 K2 R0 ~- N" ? - .INESBAT 0 ;指定是否存在电池备份 (0: 不存在 1: 存在)
4 W9 n8 p5 c4 K$ B6 E - .INESPRGRAM 0 ;指定 PRG RAM 大小 (大小 = 64字节 << 计数)1 l. T! T6 r3 a/ `5 n- v
- .INESPRGNVRAM 0 ;指定 PRG NVRAM 大小(大小 = 64字节 << 计数)! L! A# [) c- b- N- \" z
- .INESCHRRAM 0 ;指定 CHR RAM 大小(大小 = 64字节 << 计数)
$ j( R8 m6 x5 o) i3 }! e - .INESCHRNVRAM 0 ;指定 CHR NVRAM 大小(大小 = 64字节 << 计数)6 {9 L. E, n9 `1 k) t5 y) X
- .INESTIM 0 ;指定时序 (0: NTSC, 1: PAL, 2: 多区域, 3: Dendy); R# `9 u3 `/ i
- ;======================================================================
l5 B# g% E7 x% f, {4 c - .INCLUDE "fc_demo_config.asm" ;全局配置* I' x% b: U3 S" O& A& E. k$ H$ t
- .INCLUDE "fc_demo_constant.asm" ;NES常量" I O1 C& b N
- ;======================================================================
+ H. ?2 N, i6 J" Y8 D - ;音乐配置
- _7 t$ ~3 o k e! X - .IF 0 = MUSIC_THEME # h" t2 b* `7 X# f( ?
- .INCLUDE "data/music/Gremlin 2/config.asm"
' S, {* N2 R) V - .ENDIF
+ D- R- L( C# A. I -
4 J% [+ J! A, k' V. f - .IF 1 = MUSIC_THEME
4 S! s- z9 U# S9 Q, E* C, Z - .INCLUDE "data/music/Raf World/config.asm"0 ]! p! u' L9 u' _0 ]6 S3 N
- .ENDIF' f6 `9 T8 m- ~/ {
- ! h6 J) b2 x, Y
- .IF 2 = MUSIC_THEME
" ~) |: }4 Q" d - .INCLUDE "data/music/Ninja Gaiden 3/config.asm"
+ i: K& @) a- u. N - .ENDIF2 [: ^. G D, k5 B2 K8 E9 B
3 n& g: H* [+ ]9 Y$ l$ ?# y- ;======================================================================* n0 K0 W" D* c4 q% M7 q
- ;引用CHR图像数据 ?( J4 {- @/ G7 `. @1 F) u, j5 F
- .BANK NES_16KB_PRG_SIZE * 2
5 j2 `: s) V. h+ }% K; d$ i - .ORG $0000
e9 d% @" Q' \- l% V$ g6 t( m9 r; p - .INCBIN "data/bkg.chr". m" n9 t6 j; i( q+ q. d
- .INCBIN "data/sp.chr"
( r, P6 J0 w+ ? -
1 n. @( F/ c$ t - ;======================================================================
% v4 l9 r2 Z# G r - .BANK PRG_DATA_BANK_E000 & BANK_DATA_MASK;设置程序所在Bank
) S( b/ T6 m4 \$ z# q - .ORG RESET_ADDR. \" h3 u1 E+ l1 n5 h( L
- ;======================================================================
( o- ~' V9 ]& H* {/ D' C* O - ;引用其他源文件
$ v$ m' R$ f7 y9 Z0 B/ o) d: u - .INCLUDE "fc_demo_ppu.asm" ;PPU处理
( y9 ]6 V: O5 O- ^ _ - .INCLUDE "fc_demo_joysitck.asm" ;手柄处理( P1 P+ b; N4 l' w& D/ w, k
- .INCLUDE "fc_demo_static_text.asm" ;静态文本处理
8 r4 `% f" O6 f8 h) E8 |7 O! _ - ;======================================================================( E! T7 G6 V; o0 N; c
3 ?2 K0 F+ v: ?/ S1 ?* V- ;======================================================================2 g/ X- }4 R& |/ Q6 ~8 b( @% R
- ;等待VBlank到来
; ]; r Z9 P) i - Wait_For_VBlank
* o+ s, ], n& m- _. F. g B- L - LDA PPU_STATUS
- G% U$ |$ N0 ` f( A# t+ }% j% Y8 l) z0 ` - BPL Wait_For_VBlank
% t8 T( p, X* x2 A% S Q1 D: e* ~ - RTS
8 Y" W+ C+ M( v& e* ^
3 }7 {' F& R' j, `, C6 Z6 f0 ^: g- ;======================================================================& ^2 i( S) `+ q/ Q3 f# y
- ;调色板初始化$ k% m) G" T+ N6 G: A, ^
- Palette_Init
2 ]7 b$ U2 j/ z3 y, w" C `1 f4 v - LDA #$3F. a6 I2 y, j0 p# f0 i+ H
- STA PPU_ADDRESS$ T9 P5 M( F: j- L8 Y
- LDA #$00
- A+ q' |5 r7 B* K - STA PPU_ADDRESS; ~! K" e! _* K: F4 s* C2 q; H8 M
- LDX #$00
5 e5 m, e6 X0 h- G; V - LDY #$20
- d: A4 e- h# }* c$ b2 w - .Write_Data
$ i1 Z. X$ n$ h1 B+ D; _- [ - LDA Palette_Data,X; o% ? u8 X% C7 z
- STA FC_PPU_Pal_Addr,X
0 u" i9 a9 V" x+ ~0 r% l - INX( \& f& j0 H4 ~/ I4 {
- DEY
5 R2 r- Q" M8 A# o' S - BNE .Write_Data
% B$ T( L/ m' o- ?' z - .End2 h. G. k' l& I' n
- RTS4 \+ k6 y3 F& n( E; }) Y$ Q& G
9 h. f- L$ Q# Z3 ?# V6 u7 P- ;----------------------------------------
, K0 a9 v* k9 C7 m( B! w - ;调色板数据- {! V' f$ {; c
- Palette_Data7 n) H1 M( }! E( }% H4 f, V) p
- .HEX 0F 20 32 02 0F 20 32 0F 0F 20 32 26 0F 1B 0F 1B; W j* ^( I3 W" p% a/ a
- .HEX 0F 21 27 22 0F 24 24 24 0F 21 21 21 0F 22 22 22; R2 H( C" ]8 n, Q: h- d t% U3 r
- 9 Y' i4 y z# u7 Z3 `: ~
- ;======================================================================
- d0 \0 a; Q: ? - ;命名表清空) @' E9 U7 E: x; g# h
- Nametable_Clear, s; t/ H- i2 h) d% |0 k. {
- LDA #$205 K+ Q" Q z1 e5 |
- STA PPU_ADDRESS/ X. o: a) u# d$ d9 j
- LDA #$00+ f! z$ o8 _2 A* @% d8 \% k
- STA PPU_ADDRESS
2 z" ^: X8 S) X- y/ N( c. k - LDA #$00
) B- E9 _# P1 e( u6 m; k9 Q - LDX #$00* p* ]2 h; |- n2 }9 Y- g
- LDY #$08
/ a( f4 T0 \% |/ R2 p - .Write_Data
) Y( P% F; i7 P; G+ q; x: g! H - STA PPU_DATA4 B' \; _, f9 ]8 k( g% O
- INX
% U3 i; y4 s) E- S - BNE .Write_Data5 \7 i6 k, p: `/ Q" t( u4 t
- DEY
# }- o8 _9 _' D4 q( |! N3 a - BNE .Write_Data
+ N* x( W* X6 V( X9 w - .End" l2 a4 e6 C% u. d% T6 y. m
- RTS/ N4 ^ [. W( ]5 b- k
* x9 [6 `2 N& Y" G; _* W- ;======================================================================8 V0 `( K% ~' [) @0 j
- ;音乐曲目切换
# K& X: u: B/ _. b$ f - Music_Select_Process
; Z/ q2 |0 T1 L% k - , m$ ?1 b: j6 U. c+ B
- .Pre_Music;上一曲: J& \/ c. o/ k1 m$ V& Z* i) M
- LDA FC_Gamepad_Once
K, i3 Y' W9 w% C8 }) ^5 K - CMP #JOY_KEY_LEFT
" t: ?) X/ @. v1 F: ?% S3 ` - BNE .Next_Music
. R2 y+ U" R0 B {( W - JSR Music_Play_Pre8 r! k1 z2 ?% w, f2 D
- .Next_Music;下一曲" o7 R# b8 n8 b# |
- LDA FC_Gamepad_Once
9 [# U, Z5 B" s' p - CMP #JOY_KEY_RIGHT# i* s! r* u* t2 p. c7 H. a
- BNE .Next_10_Music# A/ J+ u( X+ v, q" {
- JSR Music_Play_Next
4 y0 n) V7 N. P, A) w) w! f S" R - .Next_10_Music;上10曲1 a( t; S9 r0 M% T* B8 W
- LDA FC_Gamepad_Once5 W9 J$ {% w& m9 d r7 a6 y2 [
- CMP #JOY_KEY_UP0 R& |; s6 r4 h
- BNE .Pre_10_Music
* n P3 |% g4 y: P - JSR Music_Play_Next_10
4 X; C" I& @+ g( v, }3 G - .Pre_10_Music;下10曲# \; r# R/ |- G$ v9 x9 J3 i. D
- LDA FC_Gamepad_Once
+ M" U/ ^9 O( h( u" B: ^ - CMP #JOY_KEY_DOWN
% s( g. t9 Z# g y' ] - BNE .Reset- y. Q+ x! ?2 }6 M% @& p
- JSR Music_Play_Pre_10! N" Z* f/ h7 o; V
- .Reset;重播当前曲目
% P% [+ I; \. d- x) ]2 h# Y - LDA FC_Gamepad_Once
- @- J- x9 Z, v2 S: b) f - CMP #JOY_KEY_START
1 {) g& Q D+ S3 b, a+ G6 Y! z - BNE .End
# c7 N: ~: y3 G+ \$ { \ - LDA FC_Music_Index
, [6 A5 X0 ~, g - JSR Music_Init_Process
; z; e8 A4 s& L$ U7 D9 I - .End8 w8 m! {& B- G5 c8 i
- RTS L; y/ U8 H" r5 U! X' k" Y- [
- : ?- ]: o8 ^0 s3 j. c: t+ B: ^) C
- ;----------------------------------------------------------------------, o/ H, m5 A3 v4 W* K. X3 }! d
- ;播放上一曲
3 \9 Z% v8 ~* s" o; l8 W: g3 y - Music_Play_Pre+ M' _1 T- P: z) Q* p Y
- LDA FC_Music_Index7 L' b& F4 I% x5 K1 X/ X/ f% a) d8 a) k
- BEQ .End
2 I: \0 F0 P0 A& L - DEC FC_Music_Index
0 ~8 P, W" W, o' U f5 n( ~' Y; c9 p - LDA FC_Music_Index1 Y' X, ~) C7 F- u
- JSR Music_Init_Process
8 x0 t( g, x/ o% c! W6 f* B0 [ - .End
; W2 g8 S: o, e) | ^* \ - RTS3 u1 j5 `$ p9 T3 b
- ;----------------------------------------------------------------------* E5 o1 i% ]! v" M o' V
- ;播放下一曲* o# I# T0 K& J6 G7 t# j0 \2 c; e0 {
- Music_Play_Next
% S# {! B, }' X; k$ ^: ~ - LDA FC_Music_Index
* ?! P. G) |3 O/ f' O - CMP FC_Music_Max_Index/ u% G7 E% j3 T( a0 ], s4 e1 t
- BCS .End
' M- z3 b6 O0 y - INC FC_Music_Index3 y. S; @' H# M5 D
- LDA FC_Music_Index
1 [& h9 J' }2 o$ r! p - JSR Music_Init_Process- ]5 g- f0 z- U; y( a3 I, V: |
- .End' C ]; C* p# a" q; M; Q2 |* G
- RTS# F k2 k) Z; w' T* f2 L N
) q9 H3 j# @7 ?3 e/ {. G# f- ;----------------------------------------------------------------------
" F4 h* P7 B/ s. C+ `/ Q, |. G - ;播放上10曲4 g5 R3 Z6 n' g
- Music_Play_Pre_10# y; k: `0 X% C0 ?4 s) G
- LDA FC_Music_Index6 x# |2 X9 ^5 e6 O" R; i3 z3 i" ^6 a
- BEQ .End
" ?4 q: c/ f/ |1 V9 d - SEC
3 y, g4 w X7 `# g* r" [" e. X. U - SBC #10
* i' [5 Q* j( z6 }) t& h* W( |! @2 \ - BCS .Pre_10
' @% h# m2 ~. k \. }2 z - LDA #$005 P9 U0 ?3 V. a; {) {9 m4 t
- .Pre_105 A/ K% _) v& Z# p8 \
- STA FC_Music_Index. a" A& H& J4 V; t3 ^/ E$ S
- JSR Music_Init_Process) h5 w# D5 r+ S# @% \. U4 [$ f
- .End. }8 j6 O0 ?8 c7 r/ p+ w* i7 _, L
- RTS
- v) e! V2 [' f. P( A - ;----------------------------------------------------------------------: z+ f" d, i2 u# g1 q2 {
- ;播放下10曲
0 u+ d8 B. s4 Q; V& } - Music_Play_Next_10
; F1 A' `) m: g M: a! m- H - LDA FC_Music_Index3 x R2 F/ [6 I1 V
- CMP FC_Music_Max_Index3 {1 R4 @! ]$ f" |* v' t' n0 S
- BCS .End. i5 d( t7 a+ K6 i2 u
- CLC
# P9 t; K: h4 N" i9 X - ADC #10
! Y( o& [) o; C# g7 A0 G* t - CMP FC_Music_Max_Index$ a, l) Z" p6 E" A6 l7 ~# X8 t
- BCC .Next_10
- C4 }( g# n6 i! r' P, j - LDA FC_Music_Max_Index
! \2 ?9 [+ J$ B' b. p. Z8 r$ D- Q - .Next_10: P+ J9 V+ A( \6 V1 Q% Y& }5 \; J
- STA FC_Music_Index6 Z7 ~) e% V( J4 [0 N
- JSR Music_Init_Process$ p+ a8 b; {: {, i$ r1 E7 D
- .End _% X& m8 }) |# z6 x7 Y# @
- RTS" a2 f& l8 K/ W5 {
( V- r3 o) _1 Q; p1 U; o9 u9 m+ P- ;----------------------------------------------------------------------7 r2 Z- z4 Y/ B/ {7 @
- ;8位十六进制转3位十进制制
! q3 E4 }) F, _6 K3 r! W& [0 w - Hex8ToDec q+ ]* `2 H" v6 A& l
- STA FC_Dec_Data_16 O6 F' s' h ?* i/ l+ R9 {
- LDA #$00$ C# j$ Q M$ V8 M# b) V
- STA FC_Dec_Data_100( @; V7 ~: z/ ^
- STA FC_Dec_Data_10
. b3 S1 \7 P; _: G3 c) Z5 { - LDA FC_Dec_Data_10 \/ n; u! P# v
- .Convert_1006 v/ b- w* _/ K1 y# x! I
- CMP #100( U6 K( U5 Y, U3 K3 \
- BCC .Convert_10
1 J, k6 w* z% l% @; z0 Z! j S - SEC
/ |% k2 v$ \! {% n% m: y% }+ p - SBC #100
+ K# q8 Q# G5 l: w' x7 [5 F3 h - INC FC_Dec_Data_100) b8 D. [* d' N+ {9 E' p1 c
- BNE .Convert_100 g# ~ f' \( }8 u u
- .Convert_10: H5 G& q1 _# p* k O% R( s
- CMP #10
6 j* S* I+ A j' F: p - BCC .End. d% H4 B& C4 I, U% d
- SEC
7 [+ C* o0 b! B - SBC #10" q, o N" X4 B# l, E# c/ f
- INC FC_Dec_Data_10
- w( _. P5 \# n% a- B, }. U# @$ v - BNE .Convert_104 P4 N. j3 s' [! C4 q
- .End
$ k2 v2 ~$ T# v7 \ - STA FC_Dec_Data_1
/ D* W1 o9 N& u! e* {9 @4 A - RTS' v: c1 i0 ^' a2 H$ E
- # |3 C( M4 x# q0 }& S- N
- ;----------------------------------------------------------------------
3 g+ b5 l R" k& K8 d) @ - ;显示曲目信息: _6 g; g% n0 Q0 x; o+ O i$ ^7 Y
- Music_Info_Display& B' x# W# l: `. w- a! f- F
- LDX FC_PPU_Buf_Count
$ @. x3 g& m# C3 A. V* S - LDA #PPU_WRITE_MODE_CNT_LINE( k" L1 p9 R' \. k* j8 M9 I# p
- STA Use_PPU_Buffer,X1 V V+ G, f& V3 s6 H3 Z
- INX8 ~4 K9 G* R$ D" [
- . c0 A" o; \, \1 Z+ a
- LDA #>MUSIC_INFO_POS7 K/ m. K0 z5 f( p! _' ?; Z
- STA Use_PPU_Buffer,X# B7 [) n. @( D
- INX
# P9 Z" s1 C) W) d, _- L - ! F1 F: F+ b: a! U. \
- ;居中* z- J1 _) P4 }7 b, \: k
- LDA #<(MUSIC_INFO_POS & $E0) + (32 - 5)/2- B- W1 J2 o0 T
- STA Use_PPU_Buffer,X
* P( ^& [+ T5 z2 l - INX+ n$ ^- f4 W/ `/ T$ l
- 7 J9 o% ]) ]" U4 [& n; d
- LDA #$05
: K7 Y3 V; K; B - STA Use_PPU_Buffer,X4 Y$ P& m3 P& W$ H5 h6 b; J
- INX
0 [6 j8 X0 k! a - * {; H' [6 W' R+ [) x
- LDA FC_Music_Index
) `6 Y% k/ M6 z5 \ - CLC' E" d7 U& m O5 Y
- ADC #$01$ r3 Y3 y, M# F! J6 S% B
- JSR Hex8ToDec
8 Q' G, f6 d! V5 B) @: D - & f) @3 r* [6 U
- LDA FC_Dec_Data_102 i, s J; `9 @. \) `
- CLC- C! z" k6 |0 U) Z9 t3 q' Z
- ADC #'0'- @" k( \$ |2 Y* w
- STA Use_PPU_Buffer,X
$ j) g+ T, V5 H) K! Z2 x+ ? - INX
" w2 B1 |+ W2 |- M! f - 9 ~3 ?- R$ q2 L2 t! F- [/ A/ D
- LDA FC_Dec_Data_1# A% m- J4 f8 t- x
- CLC0 i% v4 `/ j4 f( v7 B" }
- ADC #'0'
4 l+ j) [" L3 ? - STA Use_PPU_Buffer,X. p; k8 E p5 L8 i' |$ c
- INX* j, M1 M s; l6 ]/ {
- 9 F# E8 O) O/ A: p' s
- LDA #'/'
/ J8 w5 Q6 k M I) n - STA Use_PPU_Buffer,X8 ` L5 a# h( r( W5 Q
- INX% |1 p8 D/ T- {' w9 G
- 2 H+ Y% W; F( m8 k& |4 I
- LDA FC_Music_Max_Index- r4 A6 x* w$ k3 Y* B* f/ h6 e
- CLC' K2 F- p3 x' \! q
- ADC #$01
8 j* V+ K3 {2 T( x - JSR Hex8ToDec
8 }, M: H6 |- R* p - x) d, S4 w. y% D+ {& E4 c
- LDA FC_Dec_Data_10
9 x( x0 }9 ~. O9 _ - CLC
0 S8 U. i; l3 a5 C+ X6 [ - ADC #'0'
# q0 k9 \8 h) R: a8 o6 ^7 C - STA Use_PPU_Buffer,X) G }0 Q5 V; A8 Z8 Z
- INX
" V" {7 s& n. d# X/ y, v5 s# l7 X -
# B! Z/ ^2 C9 `! `0 n: b% I9 h - LDA FC_Dec_Data_1 G+ E% |4 C, C3 W* _$ J
- CLC* `' _, J/ S3 u. U1 k
- ADC #'0'6 \0 l0 q3 ^7 S% n/ y6 v0 N' D
- STA Use_PPU_Buffer,X
6 D/ L4 f. f9 k0 X" t8 l: F% B - INX0 }; m& a2 o% t& j% T
-
' O& X0 c. q% f. d {9 x - .End- Y# D7 S+ q( g
- STX FC_PPU_Buf_Count
9 ^! p$ U# Z0 X* a - RTS
9 f% c$ `, x/ I& q
5 Q* H! p; U' C1 U2 c- ;----------------------------------------------------------------------
# v2 F7 p! b @7 I* }# X. z$ z9 n - ;音乐曲目初始化处理
+ e m) D' d9 M5 U% f$ h - Music_Init_Process
* `9 T0 R" t& S- c6 j0 m" J - PHA
! |. j% w7 ~9 B4 g+ N - JSR Music_Clear_Process3 C! f/ h/ ?/ H$ B$ @
- LDA #$1F
' ]- q# i9 X" J - STA $4015" `/ Y# K1 D, k5 K$ N2 D
- PLA
. y0 Q( j$ B; j& E/ w' ?- b8 v - JSR Music_Init_Addr
. W+ h, Z; C: B: P j1 ` [' [9 g2 S - JSR Music_Info_Display
9 q& H' @- d* j5 J - RTS; ^9 X' R: T- z( Z+ Y2 p m# e
0 R9 D6 b, X2 _' Z4 b- Z- ;----------------------------------------------------------------------+ I% d7 C- E" h4 K0 w$ j' J
- ;音乐播放处理 `& y: O/ c, ?
- Music_Play_Process
1 H0 j! m7 W+ U - JSR Music_Play_Addr& a4 W: e- f4 G% p
- RTS, U8 r" c0 `3 G: [$ n1 c
- : \9 O0 K, u$ }6 Q9 \; U; X
- ;----------------------------------------------------------------------
B, ]% c. C( j; z& B5 @; V - ;音乐播放处理
. G( h: E6 N$ i0 O- A - Music_Clear_Process
/ q; }% @7 g$ E1 t) {9 ~: `2 E - .IF Music_Clear_Addr
4 ?# A2 @$ S. d! |. J% W0 n; o0 N - JSR Music_Clear_Addr
5 B U: p h* w$ K) V - RTS$ o. ]! {5 w/ j: h' O3 I2 _
- .ELSE
" W0 f8 l' _: s6 n - LDA #$1F
9 L: S6 W- r& q - STA $40151 D+ \* k' J9 d5 v" M
- LDA #$00
/ k" L: d- z& N7 g2 X1 s* ~ - STA $4010
$ y! z; ?+ P: m2 f, D/ K5 d% a+ q - LDX #$00
; B/ T& Q2 o2 e6 \' { - LDA #$00! I) n8 p* f E" b4 r
- 0 Z9 O1 f+ U: {
- .Music_Clear_Zreo_Page_0
; ^+ k1 R. D+ \5 n9 B" p4 V - STA $00,X
2 U" Z9 k! E g% V/ ?( ^ - INX
& p% p8 N# Y( `' {# a7 w - CPX #Use_Zero_Page_Begin( U0 c) i7 _! c$ t+ O
- BCC .Music_Clear_Zreo_Page_00 a) y. [2 }% \- E5 m
-
# ~4 w; @0 A1 [% a+ Y+ F" _+ U - LDX #Use_Zero_Page_Begin + Use_Zero_Page_Size
) _0 b. ?8 s5 R* i" J U - .Music_Clear_Zreo_Page_1
& j9 C+ O3 O& p( @" B$ r7 \4 c2 k - STA $00,X
, f# ?6 Y. B1 | - INX
" z! Q" D9 |7 q5 H X - BNE .Music_Clear_Zreo_Page_1& G- m5 C% B6 y! ?! q# f; K( f: d
- 9 R2 `% B. M x0 h+ `5 h
- Music_Clear_Process_1, A* ]0 F' w7 c
- STA $0600,X: t4 z5 _3 ~. z) s! h
- STA $0700,X3 M$ J8 j4 s9 Y
- INX$ f7 Y: T8 X& E5 w2 m
- BNE Music_Clear_Process_1. ~5 s+ J/ K9 W$ {5 e
- LDA #$10; |5 {' E( g7 J9 a
- STA $4000$ h$ V5 f8 n* Q+ k1 d3 O
- STA $4004& m3 }. Y/ W6 O- A
- STA $400C+ S; D- K7 z; c9 G |
- LDA #$00, w# ^& _# K2 a& F- p
- STA $4008
) X% O+ E' {# B5 H s - LDA #$0F
3 o" k, Q6 F0 `( s - STA $4015) l' l! w! f9 U7 s5 V
- .ENDIF/ c1 q1 n) ?: M! s' }* _/ t
- 8 S: V9 [! M4 z9 S! a$ u5 J
- RTS: d+ T; x( x) Z; h
! P6 R! z/ f$ R3 v- u- I- ;======================================================================- b+ `3 P. l$ n& u
- ;重启处理! k2 l' D- h* z) y7 d
- Reset_Program5 l! _3 W4 L6 u# D) ~( Y/ h
- SEI
2 C' G1 b% Y- e" Z x1 K2 c - CLD
/ w, n. `1 I* l% H9 x" {: y - LDA #$002 G, r4 z7 Q2 b2 Q
- STA PPU_CTRL& s7 W( H5 }" b, {6 S
- STA PPU_MASK
* \+ s/ T* i$ h) J" Y& X6 n( T - STA JOY2_FRAME* z) [2 F' m5 b; s+ f
- STA APU_STATUS- v9 y" [8 q' e/ @
- / N+ z3 ?+ R$ ~
- ;等待屏幕准备完毕, q, H. C5 ~* @- v% {
- LDX #$02. h' T$ I! d: m! W4 `
- .Wait_For_Screen_Ready! ^6 P2 ^1 W; P& |) h
- LDA PPU_STATUS
9 p: s6 K( S+ j - BPL .Wait_For_Screen_Ready
' k$ z* `5 ]( p5 }% D - DEX f& ^8 y4 I2 B, B5 L
- BNE .Wait_For_Screen_Ready
8 s |5 K o% q, }6 I -
& t9 {, x5 R( R7 h3 [ - ;清空调色板
! q9 D5 }4 i/ V9 y9 C - Palette_Clear
8 i1 B: }: j% x8 w( W - LDA #$3F
5 |" [( C9 @ o+ P0 ?& [) E/ d - STA PPU_ADDRESS& N1 M: ?/ G0 V
- LDA #$009 v" [& d! W% B6 g9 w# x# m% |) p/ C0 j
- STA PPU_ADDRESS$ a# n) l- ~' x, u
- LDX #$20
# v2 U+ v' h h& U6 o1 _* L - LDA #$0F1 Q) e9 k1 o! A+ n
- .Write_Data
* E/ _8 G/ x. K# x6 P: h - STA PPU_DATA
; J) ^) D( g9 o - DEX
0 @3 g: U: C4 C3 Y$ s" G - BNE .Write_Data0 _8 U* }/ I4 B- a4 W- x
- ) e; H. v( R/ f/ @% e" J
- ;清除声音 $4000-4013
3 S: c' P" j1 T5 H - LDY #$14! j( ]1 O& d) z$ Y/ V) x1 X
- LDX #$00. N" F# S8 A' g0 M3 L6 f% x
- .Sound_Clear
; Y; k2 [* ?, `6 F0 Y0 O' r - STA $4000,X
9 T, G; H- t0 [: m! c, _ - INX6 L I8 Z" p+ i$ K k; q! R: e( B# w
- DEY
4 S! y' t: T! _0 }* @5 c - BNE .Sound_Clear
/ J" |* T- L2 I, i9 Y6 N - 6 Y' h4 D6 b s9 E4 `4 G8 z
- ;清除 RAM $0000-07FF4 Z! _) S8 t+ q. ^
- LDA #$00
8 Q6 Z% b4 l# U. V - STA $00
- N0 }5 |: v6 M/ D - STA $01
1 h6 }* C# I, T- o, @ - TAY) ?0 e) Y( r/ Z2 z
- LDX #$08 M; D" z6 n J" y
- .Memory_Clear
7 K. \; H( S! h% R - STA [$00],Y
( f" r/ K9 q' u/ H R) G2 r - INY5 X" n9 W1 N, f k
- BNE .Memory_Clear
: j) O! }' Z9 J$ V! w( y - INC $018 b; F2 \- w) F8 F+ T% B
- DEX5 u- z; @! \ m, ?/ X, Q
- BNE .Memory_Clear- \0 D% m3 N2 ?7 J
-
' u/ K5 l' S9 ~7 L- P& t4 g6 z - ;精灵缓冲初始化
( B' ~. E. z8 G( ?! o/ H# ]4 R - LDX #$002 `& h" K% b7 n% S
- LDA #$F8
: m! b) p6 @& I3 J$ d( { - .OAM_Clear8 R1 j! n- k1 f; D4 Q7 V7 Q* B
- STA OAM_DMA_Buffer,X
3 D' X/ [$ g1 {. Q- c6 { - INX
/ b* D/ x R& |& M5 G; B - BNE .OAM_Clear
( S5 [$ v+ j8 T' r$ L R0 D -
- L7 b2 @. B" R' q) A - ;栈指针初始化# \5 N! V9 s, `0 e. w8 f0 a
- LDX #$FF: N% h+ P# r' @6 b/ B9 F/ Q+ M
- TXS6 x- b7 A' ^7 p9 Q
-
* h, L6 f5 F' d* ~9 S% Z - JSR Nametable_Clear;命名表清空
! G+ ?0 ?- o! m9 o5 D6 f - JSR Palette_Init;初始化调色板缓冲
$ L7 Y( W6 {# |1 h9 f a0 S - JSR Static_Text_Init;初始化静态文本
% T ~- ~7 {! k: X3 p -
/ s G! P3 A. y! j) v# w - LDA #MUSIC_ITEM_TOTAL - 1
( g" w F& s7 z6 C' [2 G% j/ ^ - STA FC_Music_Max_Index
Q6 ?. h8 A6 u -
' u" H& z6 ~' b3 F; r$ `6 f - LDA #$1F8 A( o) ^# W( p! e
- STA APU_STATUS$ f: m l$ j" }4 L
- LDA #MUSIC_BGM - 1
" Q' ^/ L$ z5 ?7 [+ a - STA FC_Music_Index
" \/ N% D5 t: `0 c - JSR Music_Init_Process;音乐播放
& m0 n/ R' U1 u/ ]: K0 _$ J -
6 O3 t8 j9 K8 N' A7 y5 k% ~ - ;设置屏幕显示状态缓冲(当NMI处理时控制屏幕显示状态)
% `; a$ u* g9 f& J! Z - LDA #$1E( I+ J! a- G# t3 p$ v x# W
- STA FC_PPU_Mask_Buf* E# }' `- `1 A B$ q
-
7 R) ?+ e3 v" E7 ?3 E' t/ w - ;启用NMI处理3 n" v7 V5 P, x- T
- LDA #$80& p* x+ {) Q! x# ?! H* A3 [
- STA PPU_CTRL/ Y! a x# l: v/ I- w* V) p
-
. T- H! R% @3 x2 {' L! H4 T - ;程序循环, 剩余工作交给 NMI 中断处理
7 a* @# ?8 y) q. W" O, H, ~ - .Loop3 v* D& k+ K- c; _5 \
- JMP .Loop
8 s7 T/ W$ }/ u+ U; l - 6 r9 v1 |$ L( `
- ;======================================================================8 G* F/ m. v* e
- ;不可屏蔽中断处理
& J" ?, W+ a$ U& E* T; A/ r - Nmi_Program7 [: V1 w- F, d+ a! z& s
- PHA
$ B1 ^4 [% n( R! s1 ]0 F Q - TXA6 u8 B+ ^' a N0 _/ k
- PHA1 x" y$ a) g8 a: r9 Z
- TYA1 o9 F e4 |( D! P: i C( l. z
- PHA
0 J9 S" P) s8 U7 J5 c - , U& d0 K+ X' n5 ~ t/ O. Y: T- }
- LDA PPU_STATUS;读取使得 PPU状态寄存器复位; r/ H) J' N4 N$ k, K
- 8 s! O" L8 C5 t/ v2 n1 z% A
- JSR FC_PPU_Procrss;PPU处理9 z* N. Z4 G5 k: B. r
- 5 t! Y) ?& s4 @( o A) Z6 b
- ;精灵内存更新+ P6 E& R5 X. g7 D( ~
- LDA #$00
& T; R' A+ u3 E2 f - STA PPU_OAM_ADDR! E* I7 ~7 }( E4 a$ {7 A- P
- LDA #OAM_DMA_Buffer / $0100
8 _4 R0 |) g& h7 p: \. S - STA OAM_DMA$ R5 e' \: O) Z, C/ n7 W7 t
-
5 n+ \3 Z4 [ h8 g& Q1 f, u8 G, D - JSR FC_Gamepad_Process;手柄输入处理
( A U9 E+ O1 D, e6 S/ x& H0 n( W - JSR Music_Select_Process;音乐选曲处理$ n$ r- l; G& h, p0 N7 k
- JSR Music_Play_Process;音乐播放处理( U$ }' A; j4 k; E
-
0 F q" G; z$ n7 F9 T4 d - PLA( b, D7 G% V, [# T. h4 [
- TAY0 g1 x$ R" ~+ l
- PLA2 o& P" s2 p' J
- TAX
2 m. O4 ~3 L# G2 g! @, B - PLA; `+ D- @. F, p6 A P& B2 ]
- `- V/ G' \8 f" ]* ]3 k- RTI
7 E8 ]7 t+ p6 S+ s9 O( { - 6 M' S/ m% S1 l% m
- ;======================================================================$ H9 Y) _5 a8 M0 Y
- ;请求中断处理
5 x U: Q5 ^; C& V9 C0 a - Irq_Program
, {/ `* ]* W; m$ E* r/ s - RTI
# S/ z5 {6 [. P, R
6 U& ^' S8 P9 a W6 @. O2 s( b7 l- ;======================================================================
. c/ w; q1 i9 v1 Y- D0 p2 ] - ;中断向量表
8 E* e) M1 e S7 N - .ORG $FFFA3 @1 B/ G/ R8 J% ^' m- ~
- .DW Nmi_Program ;NMI触发时执行3 _6 l& l2 ?+ s+ _* @, a! C
- .DW Reset_Program ;载入ROM时最先执行8 }0 I9 \( c% a+ G% x! U8 E( y# v8 f
- .DW Irq_Program ;IRQ触发时执行
, w2 h2 N+ F/ k4 j/ w
复制代码 & r3 n+ E) n$ N" V( N
# e2 O, o2 K* x( p6 b" F2 h
: u+ S I- x, D: S
https://gitee.com/flame_cyclone/nesasm_3_2 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
1
查看全部评分
-
|