|
这是个 nesasm 3.2 入土教程, 感兴趣的可以研究下' r* N& _" {' t
' C% t" ^/ @" T% K l0 V9 o1 S以下是主框架代码:
/ \, v! Z+ d' K+ P1 Z4 X- ;======================================================================2 f! H2 i/ `7 A& d: m
- ;文件头
0 c F( D3 q. w# f! y- G; C; K - NES_16KB_PRG_SIZE = 8 ;16KB PRG大小数量
8 S# @9 z$ K+ y S; @ - NES_8KB_CHR_SIZE = 1 ;8KB CHR大小数量2 ]0 ]/ h8 `" a/ i, S" i
- BANK_DATA_MASK = NES_16KB_PRG_SIZE * 2 - 1 ;bank号掩码
$ k8 T9 A/ Z1 j+ b - ;======================================================================" m f" p) e+ ^. r+ R$ }" K# j
- PRG_DATA_BANK_C000 = NES_16KB_PRG_SIZE * 2 - 2/ W1 _2 f; w0 _6 w# l0 p7 O7 g
- PRG_DATA_BANK_E000 = NES_16KB_PRG_SIZE * 2 - 1
9 M% G0 [. N2 `9 c& Q2 |2 y* h4 h - ;======================================================================
4 Q: C0 k( t p7 N7 _ - RESET_BANK = NES_16KB_PRG_SIZE * 2 - 1! H0 |- n" {& M. F+ \
- RESET_ADDR = $E000 ;主程序起始地址& m$ `2 `; `) |; `
- ;======================================================================
4 Y% c8 P% _$ p" i) m7 z- J - .INESPRG NES_16KB_PRG_SIZE ;16KB PRG 数量, $01-$EF8(1-3832),即16-61,312 KB/ H' N) ]9 d- f4 h5 p, F
- .INESCHR NES_8KB_CHR_SIZE ;8KB CHR 数量,$01-$EF8(1-3832),即0-30,656 KB
8 t0 I) [$ k, B) @/ t - .INESMAP 4 ;Mapper号 (0-4095)7 j% g" J6 C" z( ^; l5 `
- .INESSUBMAP 0 ;子Mapper号 (0-15)
3 v( X8 N- H% f7 u) `" r- q& m) f - .INESMIR 0 ;命名表镜像 (0: 水平 1: 垂直 2: 四屏)! N" o3 e, [ ]; T% l! w
- .INESBAT 0 ;指定是否存在电池备份 (0: 不存在 1: 存在)3 r! u" b0 F8 x, f+ Z7 k* z' J1 }
- .INESPRGRAM 0 ;指定 PRG RAM 大小 (大小 = 64字节 << 计数)) L3 k: r- B: o
- .INESPRGNVRAM 0 ;指定 PRG NVRAM 大小(大小 = 64字节 << 计数)5 C; a, H# r% q' T
- .INESCHRRAM 0 ;指定 CHR RAM 大小(大小 = 64字节 << 计数)
) E& D0 `0 h1 i5 e - .INESCHRNVRAM 0 ;指定 CHR NVRAM 大小(大小 = 64字节 << 计数)
: I3 s3 [' }" w0 o; t# Y - .INESTIM 0 ;指定时序 (0: NTSC, 1: PAL, 2: 多区域, 3: Dendy)) C+ ?9 Z, m# G6 ]. c) H. F6 @
- ;======================================================================( q2 c0 Z3 d5 k" _& r
- .INCLUDE "fc_demo_config.asm" ;全局配置1 j8 l+ C- `# \
- .INCLUDE "fc_demo_constant.asm" ;NES常量/ Y% q7 A7 Z( l$ z
- ;======================================================================
# G6 g% Z' u8 p* x& Y& g - ;音乐配置: ^6 o- U- X: ?( J
- .IF 0 = MUSIC_THEME
/ k( S# _3 r: {1 y - .INCLUDE "data/music/Gremlin 2/config.asm": h! \; J. m7 X$ }0 o! D
- .ENDIF
! j3 g! D9 k' d. Y- f -
: R9 Y* U1 K4 C+ L$ I7 L- Z8 x6 Q' D - .IF 1 = MUSIC_THEME' A0 W2 f, @8 }1 Y- o
- .INCLUDE "data/music/Raf World/config.asm"
7 }# b8 }* }8 m$ \ - .ENDIF0 b z1 X4 I+ C- s7 v2 k
-
/ @4 m1 N* N& H! M5 a+ `- y; P - .IF 2 = MUSIC_THEME
9 I/ G8 P( d! S( j* p& F - .INCLUDE "data/music/Ninja Gaiden 3/config.asm"+ x$ I- y" T* Z3 U9 k, T5 T( }
- .ENDIF- X3 L% @" Z" K. D i
/ V' K& T- e) x# R( |* F/ S# f7 w- ;======================================================================4 z1 v( d! Q9 d$ P
- ;引用CHR图像数据. ]8 y9 P) _6 n( ^: M, {8 m" ~
- .BANK NES_16KB_PRG_SIZE * 2
5 ?5 C( Y: [* W8 h) L `: ^7 W - .ORG $0000
+ P+ H" ^4 W# w) A5 [ - .INCBIN "data/bkg.chr"
, [- d* r& v& |3 m. N - .INCBIN "data/sp.chr"
1 f0 |2 n1 q6 C7 \# x1 M, d; j3 g - ! B% [! f6 o8 z' i# J1 D, R& T
- ;======================================================================
3 Z, V8 U$ Z; s7 d2 Q e Q - .BANK PRG_DATA_BANK_E000 & BANK_DATA_MASK;设置程序所在Bank
9 m) K! [* `" E8 J' R - .ORG RESET_ADDR
$ _; _% G3 A' D3 Z4 C: ?0 ~/ j - ;======================================================================
& o+ O( X7 I9 |4 E - ;引用其他源文件
5 E- J6 ^* |" j6 n6 `) d- I1 } - .INCLUDE "fc_demo_ppu.asm" ;PPU处理' X4 V# p8 m! E1 c8 L
- .INCLUDE "fc_demo_joysitck.asm" ;手柄处理" b0 X% s/ C" w; ]' o( s' O! x3 z+ x
- .INCLUDE "fc_demo_static_text.asm" ;静态文本处理
9 L8 Z! s) z( c% y5 F$ Z - ;======================================================================
' C2 m( F) N$ }7 P
5 Y9 l5 x0 j9 L9 m0 x- ;======================================================================4 F% \) V7 p$ w+ h# B
- ;等待VBlank到来
* @) d: z$ B+ U - Wait_For_VBlank
$ }+ ~5 D5 q8 x8 @' m' j - LDA PPU_STATUS# ^* o1 b F1 [& K3 T2 N' s
- BPL Wait_For_VBlank* G# z3 t) y; }2 J! } C) M! d) `
- RTS% A; T' D8 i5 w9 I- u4 S/ ?
- 3 I1 i* u9 R% y, r) O. |
- ;======================================================================( w% e/ f S1 F- H
- ;调色板初始化& Q" T! ~$ h% a+ W9 T
- Palette_Init1 s" w" f1 }8 L* L
- LDA #$3F" G4 m+ R% _% Y3 o
- STA PPU_ADDRESS
, ~$ E" K, K9 ?9 n; S2 T - LDA #$00
3 k, ?, O, R2 \0 I - STA PPU_ADDRESS w" W6 F2 N0 g) s, E% l8 M
- LDX #$00 C. h2 T( d8 v# m8 N% H1 m
- LDY #$209 K9 L; M" D5 _
- .Write_Data
* r6 F/ {9 ^" u - LDA Palette_Data,X
+ ^5 D" }- W6 S+ C - STA FC_PPU_Pal_Addr,X9 e! v: v/ \7 x- S
- INX- f9 j ]0 o2 T+ X: v) \% Z
- DEY
, G! [9 V6 N4 O4 H1 t - BNE .Write_Data
6 p; m/ Z" m1 w - .End/ o! h- P s* n6 K3 x; v
- RTS( U" r" L* f' o
- 5 k9 c! g( }! B; V, W- Q
- ;----------------------------------------
1 D3 n; B5 O1 L2 C, m" T) E - ;调色板数据
4 S; q% `' G' a - Palette_Data
' g) R. c- G# p! q$ E - .HEX 0F 20 32 02 0F 20 32 0F 0F 20 32 26 0F 1B 0F 1B
- J& J; L8 T- ~. l8 Y - .HEX 0F 21 27 22 0F 24 24 24 0F 21 21 21 0F 22 22 22
' Z6 t2 H( y8 R' o+ c8 T - ' x J# K- l. A+ P$ X
- ;======================================================================# s& H" I1 q" B$ `9 [! y3 R3 g; _
- ;命名表清空
: T) P! }9 i; b$ q$ X - Nametable_Clear5 P7 _& O2 A: o8 Q7 v4 @" q) B0 z, a3 e
- LDA #$20
: e& u7 D5 ^& B2 ]. u' t$ g - STA PPU_ADDRESS
, S% S, v. Y6 O+ n$ W% e - LDA #$00
6 N" `& L6 O. M, Y' y/ j1 o - STA PPU_ADDRESS
+ p7 [6 e3 v: @6 B8 j9 i( k3 R4 s - LDA #$00
- c/ I& V. ?) ^: [7 t1 O - LDX #$005 x, m; k3 F9 [2 Y5 H* d# k4 r
- LDY #$08
6 A1 d$ X8 J% ^' j2 H - .Write_Data0 b/ s8 f; x; T2 P+ {, B
- STA PPU_DATA5 [7 }- |& n( R! f! A
- INX; Z$ G* T8 N" N" T5 f, j0 W" q- c( Y
- BNE .Write_Data
; \8 L! g Z0 w H, K - DEY( T( N' ~) W/ C! S
- BNE .Write_Data
2 R; O0 n0 q/ N7 P - .End; v/ b m( V* n! D$ q7 f/ @
- RTS
* a7 D: W; [# ~: j& o5 I' D
2 O9 [$ ?: `8 X @- ;======================================================================
1 M1 C/ r1 C& U- T8 j - ;音乐曲目切换. D6 O; k1 o8 l( d# |
- Music_Select_Process
. d% S/ j: d* s
% Z8 `( d1 y& x- p; @1 U* H7 T' l- .Pre_Music;上一曲
+ y7 M; o# C9 V - LDA FC_Gamepad_Once7 v+ O$ `7 ]: A' S5 R2 [
- CMP #JOY_KEY_LEFT
( `) o* L/ x. Y - BNE .Next_Music% n' I9 U D9 [: k
- JSR Music_Play_Pre
, j+ _" b& C5 P. \ - .Next_Music;下一曲2 J9 L; S9 l! `0 o+ m
- LDA FC_Gamepad_Once5 k% y) J3 B, G! G
- CMP #JOY_KEY_RIGHT1 i( S5 Z! t4 a. i; ^. V* L
- BNE .Next_10_Music( o- r% P, J9 E# d
- JSR Music_Play_Next
; c% B {* N9 Q+ H - .Next_10_Music;上10曲4 C5 P2 y. u7 ~, l: q
- LDA FC_Gamepad_Once
( ~" B* [; z7 s) T4 K- M- F - CMP #JOY_KEY_UP, V+ M2 E5 P& c- s
- BNE .Pre_10_Music
6 W$ t T( R! G4 i - JSR Music_Play_Next_10
2 W. c, `, i) O) @ - .Pre_10_Music;下10曲
0 B8 u/ @$ q8 s - LDA FC_Gamepad_Once1 P8 W7 G4 T% c0 H5 A; C0 p
- CMP #JOY_KEY_DOWN: j0 U9 P2 Q; w2 O
- BNE .Reset
, L+ {+ U0 E1 B& q2 D2 U - JSR Music_Play_Pre_10
7 x% a/ h t* N! j! }1 ? - .Reset;重播当前曲目
$ H- _; ?! ]5 g( ?9 w T - LDA FC_Gamepad_Once$ l% Z" V# J' n+ F/ i
- CMP #JOY_KEY_START
8 u$ ?7 |( M1 A. H1 S7 z g - BNE .End
0 X" z: A2 R3 }) T* F; J - LDA FC_Music_Index
. k2 W8 G$ S( Z2 V - JSR Music_Init_Process5 O* |& k" P4 b/ n
- .End
- v v" ]( l# ]1 U" U# `5 T& X - RTS
8 M" ]3 Q7 G8 y# s
' O2 A3 \ U4 _: g* `- ;----------------------------------------------------------------------
1 z' C X2 J8 {- S - ;播放上一曲& l% ^8 r1 l1 [4 b j3 m3 \" h3 T
- Music_Play_Pre
' l1 D; D1 U) _* k% ~ - LDA FC_Music_Index- m1 E: h) [8 x7 p% G- H# U
- BEQ .End. C/ Q3 Z3 j6 ^% r+ z, a
- DEC FC_Music_Index
O* x, r" `5 f0 l# H - LDA FC_Music_Index) w; {' ^& T# f
- JSR Music_Init_Process
! k; U! y$ H: ?% d" `! e - .End
7 N: `) k" i4 V - RTS
; u+ D* x: b) X: w0 P% R - ;----------------------------------------------------------------------
0 M6 u" K; U* b* `& W5 p - ;播放下一曲
! g" C3 B) Z! [4 n& `) [ - Music_Play_Next
7 X; [8 ^1 Q7 L: Z) d7 U - LDA FC_Music_Index3 q- Y0 d8 h% z
- CMP FC_Music_Max_Index- f! q9 I6 [7 {% i( f
- BCS .End
$ w( O2 b8 Y$ ~+ D: [" [: a - INC FC_Music_Index3 z2 l8 u9 K B4 U6 U ]
- LDA FC_Music_Index. {5 j6 s% x9 S; r Z# W! j
- JSR Music_Init_Process
9 I6 ~0 G+ r: x# x - .End
" V( o" t9 Q% j1 C - RTS
; s! b( ~$ H+ N) x$ ]9 |$ D) O
) Y6 m6 `9 J9 o' t2 o' N- ;----------------------------------------------------------------------
! ^* O1 R) z! t3 L% R$ @3 c- `' i - ;播放上10曲# |+ n8 B/ d: i7 {
- Music_Play_Pre_10
# h7 I, |4 _* N5 m - LDA FC_Music_Index5 I& X. M2 B) o4 }* l; x0 g
- BEQ .End
$ o' g% n R: Z, O; W4 v# a4 l - SEC/ @# k2 r/ Y' |" c
- SBC #10
8 n1 B6 }) P; I4 ? - BCS .Pre_106 q$ s" k: g7 j
- LDA #$00, B& r% j$ \8 ^8 r: |
- .Pre_10: @% E! o( j: x! k( }7 q* v
- STA FC_Music_Index {% q1 I! G0 A4 X1 ?
- JSR Music_Init_Process
3 J D' ]) e2 E3 M* b' P - .End
3 R. B T" L. f5 I3 ? - RTS4 T8 N* W: h! Y/ r q
- ;----------------------------------------------------------------------
1 W. c" y) Z4 S, M+ T% @6 H- O - ;播放下10曲5 ]# }- H* Z+ m% P( ?. b. F
- Music_Play_Next_10
# x/ q1 J0 V! [2 Q+ l - LDA FC_Music_Index7 K6 \* N/ j7 Q, h+ X0 ?
- CMP FC_Music_Max_Index
6 e4 f, U4 f+ |# K - BCS .End
; e: t. w7 X0 n - CLC+ }- |- ~( T! X6 J4 a. x
- ADC #10
6 \1 L7 C# i3 |& z3 p - CMP FC_Music_Max_Index
- g( K- A1 D9 F% t& ^1 N3 i( L+ C - BCC .Next_10
0 p8 {7 p" C* e& ? - LDA FC_Music_Max_Index+ z6 o# V, }. Q: t
- .Next_10
6 @4 S* P: t' g' w5 { - STA FC_Music_Index
* I) y, ?; r5 o8 Y* ]3 c$ w - JSR Music_Init_Process
% ~2 _- n$ H" |$ }# i0 k" m - .End
& m- Q( f. N$ ~ - RTS0 v1 R$ b) H3 X3 n- b f& E4 d* ~. C
- 1 {4 M+ ^9 s% `1 u9 l
- ;----------------------------------------------------------------------) N9 R2 v& `9 x, {: {* G
- ;8位十六进制转3位十进制制
5 H+ |' ^. i2 @3 w; B - Hex8ToDec
; ^0 c% _/ T" K! g - STA FC_Dec_Data_1
+ G" f. a* \' C2 q$ ~# x7 B - LDA #$001 ?' |$ }) M) N1 i( }
- STA FC_Dec_Data_100" b4 Q* k* c) N; [3 J
- STA FC_Dec_Data_103 v+ F9 m* Q0 i5 _% i0 C0 V' k
- LDA FC_Dec_Data_1
1 s" }) W* I& D" l - .Convert_100
$ p5 c* [. _5 K% ^ y0 F - CMP #1007 T/ i; w+ v, k( ^# ^" r
- BCC .Convert_10
& D3 F$ \2 c. C* f - SEC A) F3 P" A: o" R g
- SBC #100
9 M9 S7 i2 \4 h# n6 u0 n0 I! k - INC FC_Dec_Data_100% M) D+ ]; K" {/ j
- BNE .Convert_100% r/ K: E4 k% k/ w: t
- .Convert_100 f9 w- l/ V$ b# W) r5 A
- CMP #10
/ P! C6 K; D3 V9 I% Y+ Q - BCC .End: o% \7 }$ a( Z
- SEC
( Z1 b- W/ C: a! j$ l2 K" z4 d - SBC #10) u( X$ ~4 p" \7 X' T
- INC FC_Dec_Data_10; r; g( j# j' _4 O+ R" `: c, ^
- BNE .Convert_103 d* s! y2 P: N" y. s
- .End
. i! Y/ Q+ [5 e4 m- l! g - STA FC_Dec_Data_1
. B( Y' z2 D6 V - RTS
7 ]9 z" v' Q: L" | - - a. [$ Y8 k6 `1 p) p
- ;----------------------------------------------------------------------
% u: V r: P0 \: Y; J* s% R2 D - ;显示曲目信息6 u1 E/ w8 O6 O
- Music_Info_Display+ j7 W6 h2 s! ~/ S/ p+ N
- LDX FC_PPU_Buf_Count
& C- H/ Z" g, d3 `0 ?# _' S - LDA #PPU_WRITE_MODE_CNT_LINE& \+ L) P2 b7 D1 N1 j
- STA Use_PPU_Buffer,X
) t1 A/ f6 a4 x5 A3 T - INX1 s# Z& A5 @1 p& h! _8 l9 B
- |$ _* j; P, T* j+ L% j
- LDA #>MUSIC_INFO_POS# {$ n, V' S% c' m* W; x
- STA Use_PPU_Buffer,X5 T, m/ S1 L# ?2 I/ W2 t
- INX4 F0 R1 v* q; v0 o7 o
- ' i+ k y5 S2 O* r. f3 j/ L' L
- ;居中! V t% [3 c- e. {- V% {
- LDA #<(MUSIC_INFO_POS & $E0) + (32 - 5)/2+ A5 R; j/ y) e( x& l; u5 n% d
- STA Use_PPU_Buffer,X
' H% Q. n; x. ?% o - INX
0 S$ V* ^: I* z3 [4 _/ Z( Q - 2 M5 h* r2 Y3 q! m9 H
- LDA #$05
+ |9 {2 ]; P7 G( K" q - STA Use_PPU_Buffer,X
! R1 j2 D( f% c) @- T - INX
" B+ o* [' u g - ! n; p3 M8 Y1 F! `( T) f& U
- LDA FC_Music_Index
. N7 `2 E2 y% y) p) Z6 k - CLC, ]2 n1 s) F7 e- U: U
- ADC #$01- g, g1 W K2 [9 f7 v$ X! W( m; y
- JSR Hex8ToDec$ q7 V; {4 u6 _2 L4 Q" ~
-
* V- l+ x+ O: Y, f2 V9 O - LDA FC_Dec_Data_10
+ x' s5 G# o5 z* Y% w+ s - CLC
; }" c4 R2 l0 ^ - ADC #'0'
6 ~" l: f# N8 r9 k# J8 M - STA Use_PPU_Buffer,X
$ D7 h7 H( F* }" y$ @6 A7 i - INX
8 `& T. g' }0 e' z( @6 J! U7 W; C -
6 c l7 A$ _5 u* F2 L1 |# ~ - LDA FC_Dec_Data_1
( m1 `; J: W* w% g; Q6 K - CLC) |, m' K9 L3 K/ l% y: b
- ADC #'0'
^; S! _1 U( _$ Y8 { t - STA Use_PPU_Buffer,X
/ ^: F- |* A1 A/ Y" F) H) @' r - INX
# j2 ~4 Q6 i+ p- j -
2 c3 b! W( ^/ W6 H( z* |8 L5 P6 B4 x - LDA #'/'
1 ?3 L9 C* _3 `7 i2 K! S" ?0 g - STA Use_PPU_Buffer,X. Y% a6 f; c& }) E& n5 s& P
- INX
( H8 c# a+ ` A: U8 V$ q* z - / _, u8 F; L/ S& Y P3 N
- LDA FC_Music_Max_Index: Z0 A3 E. D8 h7 D' q7 _: n$ |
- CLC- X' u. s- f7 o
- ADC #$01
- c0 v9 M& M s5 D - JSR Hex8ToDec
( k: F4 q+ U- V% j+ V -
1 Y/ {0 M( } c; W( m; O - LDA FC_Dec_Data_10: L4 s- a) H( d0 k- o6 u) b2 v4 x# R& ?. B
- CLC/ H: g* Q9 S9 U9 I/ e
- ADC #'0'
" } D/ z: J' x0 x- L- r! _, u - STA Use_PPU_Buffer,X1 T c: H8 I7 A) j: q% ?
- INX
6 D4 R/ D: I" C; ~; s - $ }! A7 D+ I. x
- LDA FC_Dec_Data_1+ n% [( F* g: g( @8 y
- CLC3 x, T. }. I( Z3 ^1 {0 K
- ADC #'0'
" M e0 d( u# h& g) S - STA Use_PPU_Buffer,X' _( }0 D, j$ y
- INX
! L# X9 _3 B8 j1 H9 p9 N3 T* t O -
% e3 l4 m# K n. | - .End- B* ]2 I i( {6 y% _+ K# w
- STX FC_PPU_Buf_Count
+ m1 f Z/ r, Z n - RTS
' z. r+ g8 n& D( l# [ ?
: b; n8 J ?! H) G' [2 f9 n- ;----------------------------------------------------------------------
* o" K$ l' n$ x/ \8 J - ;音乐曲目初始化处理0 \: |; }% g s& p
- Music_Init_Process; C" \% C( [5 W4 N" _+ e
- PHA) S9 U! f1 |8 f- G. p
- JSR Music_Clear_Process
) g8 i( F: @. {; Q3 n - LDA #$1F1 u# E7 [$ @1 B) o. t
- STA $4015+ E# o- P# `- M
- PLA4 _" a! _+ P4 T. `
- JSR Music_Init_Addr' |5 k8 M& _& H) e6 @, s
- JSR Music_Info_Display
2 \4 d" L3 K3 w! ~ - RTS0 `. c9 k$ g! W
) Q$ f u6 M7 p5 S- ;----------------------------------------------------------------------3 T D1 D5 Z+ B' e8 z. e: s
- ;音乐播放处理
# f5 [5 {- o. Y3 L! {! I - Music_Play_Process
' H9 X1 O( Y7 b. j/ J% q - JSR Music_Play_Addr
( I3 `/ v6 g# Q) b1 J, X' C! H( x: n - RTS
) {' u5 w" l) x- G
4 V0 j$ g( B! [$ a- ;----------------------------------------------------------------------
6 {; E0 ]7 J7 S4 J# l0 e) J4 u; i - ;音乐播放处理
8 D- t: L. ~0 j) ^+ C3 X& t - Music_Clear_Process- t3 q9 }) ], Y+ a
- .IF Music_Clear_Addr
8 T6 k; f+ R. D9 v - JSR Music_Clear_Addr( z! u) k$ G0 C @0 ?0 m( W6 V
- RTS& M3 u6 S' O! E
- .ELSE1 R( u, w) n8 `5 d! g" a0 i4 D5 }8 u
- LDA #$1F
9 _% S% O' G% ?, M9 ]- P+ ~ - STA $4015
7 ~8 d: y: M; y - LDA #$00
0 ~: x; a1 @" ^ - STA $4010" }- O8 \9 U: E: L! i
- LDX #$004 Q3 h2 w& @! |
- LDA #$001 f9 e& z/ H& D& Z: m; A k% b
- 7 z9 Q M* l# B- v' O
- .Music_Clear_Zreo_Page_0
. M$ h2 F7 V- R% I* D+ m+ G( F - STA $00,X
& O; Y; W/ x. \* x0 k - INX! c8 a% A/ B' i9 Q
- CPX #Use_Zero_Page_Begin
8 ], g. m% F( V/ Z- a - BCC .Music_Clear_Zreo_Page_0/ n# R3 U2 W3 @
- ! f1 ?+ z V9 }% X; W0 u
- LDX #Use_Zero_Page_Begin + Use_Zero_Page_Size- w/ D+ V6 F5 n( W
- .Music_Clear_Zreo_Page_1! P; p- W+ H# H8 ?$ ^
- STA $00,X, e$ G* m% q% X* E* H
- INX& J# p% |1 o4 _, j1 a
- BNE .Music_Clear_Zreo_Page_17 T. z* F' z7 v4 g% O( [* s' O
-
5 [* X- Z& Y; S+ @4 _1 G7 g h - Music_Clear_Process_1+ k5 ~4 k% S( B$ _3 h
- STA $0600,X) V! c. N# O+ C& L6 ~2 K3 y# V8 ]
- STA $0700,X
9 W/ Z8 Y' `/ Z# h - INX. v0 ^0 @! _- A$ | p+ T
- BNE Music_Clear_Process_1
" \; B8 c0 u6 i8 C! z5 J, d5 M - LDA #$10. B! b T. j8 \
- STA $4000
# l8 K4 c) S* a+ ` X! X8 M/ H - STA $4004
2 I6 c! _! z8 O) B% F - STA $400C
3 q; Q, r- E' T - LDA #$005 |8 s5 N- P! L8 A5 T. ~# S% ^
- STA $4008, z+ h8 ~7 A3 @" K2 h& ]
- LDA #$0F G% i! B! z6 l4 P8 M) d+ Q
- STA $4015
1 S" R) ^1 ~- J+ G# n - .ENDIF" r- o4 {5 S: s- g
-
8 i" b2 P$ ?( v+ G. {. |% w - RTS+ Q# b. j+ d. m0 R# T' u4 B. O
, z" H b' m* ?3 V- ;======================================================================$ p: {* n! R2 _4 _- j; N* S) k
- ;重启处理
4 n# S; V, S |7 F7 R - Reset_Program9 u! U$ F5 w5 W! N, B, e- @
- SEI: g1 n: `5 y6 A# {7 n1 E" {
- CLD7 T2 K$ E$ V3 E; h! X
- LDA #$00
6 u1 R/ v: r2 u+ M2 D9 i - STA PPU_CTRL3 l# Z3 W: e6 |" l b# q& ^
- STA PPU_MASK
2 @3 D1 B" z. ]+ k' ^( J+ \ - STA JOY2_FRAME' e0 i, v: n0 O* q8 n; E
- STA APU_STATUS. Z& Q3 B: L( [; Z+ @, ?
-
+ _% z7 c" A/ L/ ]; G8 w - ;等待屏幕准备完毕, D) b' q: j* p3 e
- LDX #$02+ O9 s a% z) D; h
- .Wait_For_Screen_Ready/ Q) k! o% W# E V/ |7 y3 X
- LDA PPU_STATUS- C; k, @* U: M2 n/ W
- BPL .Wait_For_Screen_Ready
$ ~( Y* n ?1 s- Y4 w3 O - DEX
; S: X" L* ^( S) N# e - BNE .Wait_For_Screen_Ready
: X' G, H0 c( I* [ -
; U O0 Y# ?7 {" z3 X) h - ;清空调色板
5 @5 Y( E% `) F4 A - Palette_Clear
u6 l7 U8 \$ T3 |6 k - LDA #$3F5 P' L; \0 X7 ], }- Z
- STA PPU_ADDRESS
. W5 f6 U6 o0 \ - LDA #$00) ?* ?0 _' ?( j Y% Q* v
- STA PPU_ADDRESS! N8 e* u) b2 f
- LDX #$20/ r( H& p& F9 ?/ r
- LDA #$0F. m- `3 X$ z Z3 q$ A
- .Write_Data
5 Z' O0 b7 t7 g$ D - STA PPU_DATA9 n# ~. {$ A4 {5 W8 c, o
- DEX
; W* l, H* e3 |# g" x/ n, O - BNE .Write_Data
6 B- h! p( ]( ^& Z$ n2 g - 1 D2 m- i3 z& `+ `2 O
- ;清除声音 $4000-4013
- J& w' V! M3 G# X - LDY #$14
) M1 f; ]& F& R3 h - LDX #$00- I, H8 f( k& }, c2 B
- .Sound_Clear7 D& x" b# Y; F) {7 @" J. X
- STA $4000,X6 ~% E$ S/ t) X y. G$ U! W
- INX7 ?" m# _3 \$ y# r* r& P. t M5 S
- DEY# y% c/ Q9 {) e# e! R
- BNE .Sound_Clear
7 D0 H* Z7 A0 ]* ~/ T/ `6 D - & r- |. }0 `& T/ a
- ;清除 RAM $0000-07FF
* l+ ~# P$ B. a - LDA #$00
# }$ a! e1 C/ q" {/ c7 o" o* ^ - STA $009 ~: K8 A5 L0 w- p
- STA $01
/ M+ u" z1 j# P4 N - TAY) Y1 C5 d1 u5 u8 e+ I
- LDX #$08- p8 B, g, Y* Q2 x, h
- .Memory_Clear
* v, j: i9 G* s - STA [$00],Y5 S/ x( {; V8 E5 n- d
- INY; g& V$ _' Z' p1 l1 Z
- BNE .Memory_Clear
' W6 U' ~; a8 i9 W1 F8 v - INC $01
8 e# @( q* g/ ~) l. z; A+ U - DEX
7 U3 J/ z/ A# A' Q7 E% F6 | - BNE .Memory_Clear
' O! m+ b, P2 Z; P, q -
- m, p9 c/ g6 P - ;精灵缓冲初始化
* S+ ?- W8 M j8 X' Q& j - LDX #$001 Z- n2 W$ a/ S5 j1 s- y" Y( Y
- LDA #$F8
6 o% y& `, _/ p( ]: L - .OAM_Clear
~% R" W, y& ?2 ~ - STA OAM_DMA_Buffer,X5 t6 I! x5 A6 F- l! W {1 ]
- INX, g, j% G- l) b4 U- {9 j7 |
- BNE .OAM_Clear
4 k; X3 h6 Y6 ` w - 2 b6 m H/ t; E+ D/ E8 w. z9 \! S L
- ;栈指针初始化
) H; ^# q% i9 `3 ^9 x8 }; m, f2 i( M - LDX #$FF3 p, q1 s, L1 W
- TXS
) n( I4 n' | ]+ I9 D! A1 E8 G, n -
3 l' ~, n0 B" ] - JSR Nametable_Clear;命名表清空4 p. B- \" C! O4 Y) ~/ ]
- JSR Palette_Init;初始化调色板缓冲
7 u4 b, Q3 n! x T5 o - JSR Static_Text_Init;初始化静态文本
! U7 [, w2 F; W -
% d* b/ t* y$ H, T! v - LDA #MUSIC_ITEM_TOTAL - 1
- f1 ^' ?- b% T- E - STA FC_Music_Max_Index) L. X8 n$ p- g; F
- " E$ K3 h4 b5 @: O8 v# K: K
- LDA #$1F$ J# D6 @$ S/ q( w9 f
- STA APU_STATUS' ]$ W1 l) t7 J' _) I7 `
- LDA #MUSIC_BGM - 1
6 @) w* w- F) e* Y" x+ n - STA FC_Music_Index0 Y, h+ d! B0 I8 L' _: }
- JSR Music_Init_Process;音乐播放
# a% R% k( t4 i* m! b% r% Z# _* p - 8 V4 V+ r+ [4 U! x) y' P8 v j. Y
- ;设置屏幕显示状态缓冲(当NMI处理时控制屏幕显示状态)" k) G" S6 a+ I7 m) L$ u9 j. [9 g
- LDA #$1E$ ~3 A. r2 L0 ]# R. U( I! [" W" d2 x
- STA FC_PPU_Mask_Buf
; E6 A+ {* V5 ^. j -
* [! ^! s/ ]2 \: ?5 y# S$ V: V0 D - ;启用NMI处理
; t- v( r2 ?) U; P: J# n - LDA #$80, o5 d+ O* v2 E. K1 L
- STA PPU_CTRL
1 r* I) _0 U. O0 O; v; Z _4 o - 3 l7 W, U3 r1 X3 S
- ;程序循环, 剩余工作交给 NMI 中断处理
/ d) q+ m+ k3 b% O* u* N$ q - .Loop9 G# b, l3 n0 k+ V" F& Q6 X
- JMP .Loop
5 {# P7 k) d5 r - , _, z$ P5 ~1 {' B
- ;======================================================================# c9 W$ |( Z- H$ K
- ;不可屏蔽中断处理 [/ D1 F5 L: s0 M9 ?) Y, f
- Nmi_Program
6 l/ X( k" w5 Q4 u( k1 ~ - PHA0 D* `& G, J! C! M
- TXA
8 F F8 g1 T/ \2 c. | - PHA8 e# n$ y# a1 r9 m5 {( T7 j, ?
- TYA
. z6 ]0 g/ q- n3 ] - PHA
j% ?: w2 S, l% t& F. P -
6 t* |; Z& Q1 V) F - LDA PPU_STATUS;读取使得 PPU状态寄存器复位
& X1 M5 c# Q# y p1 X; c -
$ h% k, h7 q! z% o0 o' w - JSR FC_PPU_Procrss;PPU处理 S3 r: l3 I3 z& d- L; N
- - c$ `3 Q* n+ c* m
- ;精灵内存更新
: l4 \# y' c+ P/ h( P Z - LDA #$00
# g( d# c% m* u4 ]3 \, c' J- ?1 V - STA PPU_OAM_ADDR: X; ~1 j [# p9 |/ g
- LDA #OAM_DMA_Buffer / $0100
. n3 C! `7 y9 H( ^, T - STA OAM_DMA) F1 I. _8 ^! N1 l2 t, V# C& H
-
, H7 t! j: U( |, C - JSR FC_Gamepad_Process;手柄输入处理) i( W% D3 B T
- JSR Music_Select_Process;音乐选曲处理
, p: P- L, z" J# X9 B: T - JSR Music_Play_Process;音乐播放处理
; v, |5 p& J* q+ V2 H0 o ] - 3 Q9 o1 ?. D" |! b; m
- PLA
) e9 P& Z# \5 h q - TAY# n! H( O( T1 A. j( S
- PLA
" c5 H9 j1 i. ^' N2 d. h. G - TAX% a' v3 g" W4 g6 E
- PLA2 h c" g. {& g! b$ ]9 J
- U4 C( c0 ^, _/ t
- RTI% H! [. y) m$ T5 ?; {1 d
& c5 r9 _ j8 g2 A, I- ;======================================================================
& O4 K& c0 B/ | `. J2 ^1 u - ;请求中断处理
v! i5 m/ c& r4 X- l7 q - Irq_Program
7 P- `" s' D; V% V/ ~ - RTI/ Q/ T* U2 ^4 K2 o! \
! `* Y% |+ h7 w$ p& L( o- ;======================================================================+ U1 w1 \. k- F. i2 g {+ Z$ l( U, ]
- ;中断向量表' Z- l. z8 d% l' Z3 y% z+ m
- .ORG $FFFA4 s5 Z7 i6 i* a
- .DW Nmi_Program ;NMI触发时执行$ ]6 d; W& v9 x' k
- .DW Reset_Program ;载入ROM时最先执行
* s2 ]4 x) L# ^1 D1 H0 R - .DW Irq_Program ;IRQ触发时执行
2 t4 u' Z& s% }# D/ {( O
复制代码
$ g% }+ q8 \: a8 V
" t; N S7 B7 q! k. v" [! {( i5 h4 L9 p
https://gitee.com/flame_cyclone/nesasm_3_2 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
1
查看全部评分
-
|