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