|
这是个 nesasm 3.2 入土教程, 感兴趣的可以研究下# K$ s1 Y+ z8 W& \1 ]$ ~5 ], T, I8 X3 Y0 S
p, _$ \( x6 D以下是主框架代码:3 u2 R# `. k8 M& Q1 J* i* e4 z
- ;======================================================================8 q- v7 o/ s3 @1 g, X. o& v5 N
- ;文件头
% w2 \! y6 H# K# |6 t0 } - NES_16KB_PRG_SIZE = 8 ;16KB PRG大小数量
4 ~/ A# p a0 |% P Z. Y! _/ ^6 e - NES_8KB_CHR_SIZE = 1 ;8KB CHR大小数量, `+ q6 v( w* L _. X0 ~) z
- BANK_DATA_MASK = NES_16KB_PRG_SIZE * 2 - 1 ;bank号掩码
$ x+ _& ^1 G q/ X - ;======================================================================
; v, ?9 Q' u2 y) k/ Q - PRG_DATA_BANK_C000 = NES_16KB_PRG_SIZE * 2 - 2
0 L1 v, {. I" @ T2 l - PRG_DATA_BANK_E000 = NES_16KB_PRG_SIZE * 2 - 1
4 b0 |) [' R# d+ L3 T- q$ b - ;======================================================================- Q5 n, ?3 D6 h# M% Z8 V& G: G
- RESET_BANK = NES_16KB_PRG_SIZE * 2 - 1
/ c8 l4 _, Y2 y5 B# b. I - RESET_ADDR = $E000 ;主程序起始地址
# P( v: M/ P2 H% u4 A6 X, {/ d - ;======================================================================
9 _- O0 E6 N! [9 k' y. B b - .INESPRG NES_16KB_PRG_SIZE ;16KB PRG 数量, $01-$EF8(1-3832),即16-61,312 KB
! [5 }- X' m2 c' A& c - .INESCHR NES_8KB_CHR_SIZE ;8KB CHR 数量,$01-$EF8(1-3832),即0-30,656 KB
# y* g/ |* u8 s4 ]& V6 \' P9 u - .INESMAP 4 ;Mapper号 (0-4095)$ h9 U$ }$ g' R) } ~
- .INESSUBMAP 0 ;子Mapper号 (0-15)
# `) m9 {( p7 u! J% ~5 `7 I3 l - .INESMIR 0 ;命名表镜像 (0: 水平 1: 垂直 2: 四屏) h% R! v9 ^: d, j
- .INESBAT 0 ;指定是否存在电池备份 (0: 不存在 1: 存在)) g8 x1 @1 \& ^+ | ?' `
- .INESPRGRAM 0 ;指定 PRG RAM 大小 (大小 = 64字节 << 计数)
$ w: U1 n& i. I" K* ]; X6 w - .INESPRGNVRAM 0 ;指定 PRG NVRAM 大小(大小 = 64字节 << 计数)
2 D ?$ T" |( c# h" m - .INESCHRRAM 0 ;指定 CHR RAM 大小(大小 = 64字节 << 计数); }9 o1 C5 G( C% }
- .INESCHRNVRAM 0 ;指定 CHR NVRAM 大小(大小 = 64字节 << 计数)8 `) n/ z) h' Q( ~
- .INESTIM 0 ;指定时序 (0: NTSC, 1: PAL, 2: 多区域, 3: Dendy)
' j% G) }- }$ u/ F2 N - ;======================================================================3 m8 f U- s. G9 H0 m5 Q
- .INCLUDE "fc_demo_config.asm" ;全局配置# Z7 A/ D$ ]% @( E' P% D
- .INCLUDE "fc_demo_constant.asm" ;NES常量( q7 X* X: w; o; f: k S6 B
- ;======================================================================' _7 M& N7 S. H$ X0 L6 ~! t* ^
- ;音乐配置
% P: U& C8 m+ E9 n7 B - .IF 0 = MUSIC_THEME
5 y1 E- ^* h! U# F {# K' L2 O - .INCLUDE "data/music/Gremlin 2/config.asm"3 l) z1 S1 [5 |# X
- .ENDIF2 N' F& @6 a0 W4 s
- 1 Q( K7 s. A$ N: d% R' V' @. E
- .IF 1 = MUSIC_THEME' B7 Q/ c2 E) I: Q
- .INCLUDE "data/music/Raf World/config.asm"
) O) ?6 |" K3 T* [; F/ w* \ - .ENDIF
. p1 ~. a+ u1 W9 l6 Y -
. J8 M3 U4 P4 w }( m0 N3 A9 H - .IF 2 = MUSIC_THEME - J, e" X$ p( \5 L. X, f- i7 ~
- .INCLUDE "data/music/Ninja Gaiden 3/config.asm") Z* V& N. a; ~5 F5 ~6 k
- .ENDIF
4 p/ z+ E7 y/ v8 K! ~0 F - : Z6 J! Y- g7 w$ o* h
- ;======================================================================+ h* t0 U$ D; l; k
- ;引用CHR图像数据& {5 C+ q) Q- `; H& z
- .BANK NES_16KB_PRG_SIZE * 2
4 u8 u. t/ H% j- L6 g; J2 } - .ORG $00003 C7 C5 `0 O3 `* U5 R8 S: B
- .INCBIN "data/bkg.chr"& b% E: t( o. E/ O! Z/ w
- .INCBIN "data/sp.chr"
- \, B, N% C( I, z - , W5 L8 `+ {- u/ C
- ;======================================================================1 D4 ?* G& ^. j7 P
- .BANK PRG_DATA_BANK_E000 & BANK_DATA_MASK;设置程序所在Bank3 K% p- ^" t- |0 t
- .ORG RESET_ADDR
' n/ g5 t6 H& M" Y7 ^ - ;======================================================================
- Y' l, }5 t# M$ _- Y; { - ;引用其他源文件' [8 k- I; Q$ S+ f& h
- .INCLUDE "fc_demo_ppu.asm" ;PPU处理% U2 e9 Y; |" `* Y0 s' M5 h! r
- .INCLUDE "fc_demo_joysitck.asm" ;手柄处理
. F/ q8 {% A1 ]# B1 X2 i - .INCLUDE "fc_demo_static_text.asm" ;静态文本处理
/ {6 {. N; ]1 X+ W& y! G) M - ;======================================================================7 ^2 [3 Z, Y* \
- : L; t, I) L; J3 a) M
- ;======================================================================
2 x+ }4 {. k# R# o% P$ W - ;等待VBlank到来' f6 @( t3 J* I- x( q" k6 N
- Wait_For_VBlank1 ^7 f/ [: C( S Q
- LDA PPU_STATUS2 s4 ^" E2 q$ c: c& L" S
- BPL Wait_For_VBlank
Z$ q, E/ i3 A( q - RTS
3 u7 {2 W; ~! f1 A2 D - 0 ^$ a$ u$ p6 t Y
- ;======================================================================
2 v) s- b! ~) H3 p - ;调色板初始化
/ i# C. n1 d& b6 q - Palette_Init
4 k4 o: T. \. I! `) j - LDA #$3F
( F5 D- z6 f ?' r( ^: v5 _* y/ E - STA PPU_ADDRESS% s8 K, k8 N! H) U2 K
- LDA #$00
/ O# {& [2 z* L8 Q0 q - STA PPU_ADDRESS
1 b4 w1 s* R/ t% y: j9 h - LDX #$005 B- s# d; [! P: @( P: J! L
- LDY #$20; q( E! y! A. R- Z& n: W
- .Write_Data
' S6 `1 v( Y1 Z: C - LDA Palette_Data,X
' h- p5 v) x+ ~. |) C! p, E - STA FC_PPU_Pal_Addr,X l+ l( n3 J( w, r' a2 r
- INX
, S. o4 B x/ [ - DEY
% g+ E! f+ J- l* s% h - BNE .Write_Data* {3 a3 O$ d0 d% m8 ?( Z! g& F
- .End
& \0 N5 C' Q* u5 y' ` - RTS
5 D" |% c5 m% O$ V0 r
1 I7 e/ |/ k# |/ U/ p- ;----------------------------------------
3 D8 U9 \* x! v1 J$ n - ;调色板数据
, t, N8 e" E& q& C; Y2 N - Palette_Data/ ]# n# W) {0 J$ \) q0 D
- .HEX 0F 20 32 02 0F 20 32 0F 0F 20 32 26 0F 1B 0F 1B
& \, ^$ A1 |) J; p! h - .HEX 0F 21 27 22 0F 24 24 24 0F 21 21 21 0F 22 22 22; E( z1 `8 q! @
- ( ]- p5 O2 R6 M$ k
- ;======================================================================
7 ?3 ]6 F: A7 d' B2 M+ B5 l - ;命名表清空
( R; X! C. O$ S' U( ` - Nametable_Clear% ^ ? ?7 U/ H- @& A7 m4 a
- LDA #$20
6 H; e+ \- z+ ~3 }/ M M - STA PPU_ADDRESS
. Y/ b& o! d- B( s4 `( | - LDA #$00
/ }' F! N8 F4 c$ I3 Z% ` - STA PPU_ADDRESS
" S* j4 |* x+ x1 g' O% A' u - LDA #$00- t4 D5 h8 d0 A; V% D
- LDX #$00
. p! J$ Z: N% v: ~3 U - LDY #$08
0 G3 o" a: t D' R# Q- ?5 R - .Write_Data
. f: [' B' F0 q6 `* b' {; R) Q( ^; ^ - STA PPU_DATA# e3 Z2 K: r- W1 r5 |: n
- INX+ m9 n( T7 j0 }( F5 \
- BNE .Write_Data2 {! z9 I; c% g- I! a& r/ m
- DEY: e/ A0 f. M( s
- BNE .Write_Data: y& T+ m1 y4 `0 E0 b
- .End+ l3 N) o2 w4 _% F N8 }; T
- RTS
, e! l* R. d+ Q, h" H; \' | - 1 P+ U1 y, a/ ]
- ;======================================================================
% ]% ], d3 L/ l" J0 C - ;音乐曲目切换
- g% O% T! w0 R ^1 w, v# p - Music_Select_Process
5 {% w4 k. D- v( A1 E - / Q/ p; \0 e: D. G L/ D! l
- .Pre_Music;上一曲
( ]: v; B2 \3 \2 t7 x - LDA FC_Gamepad_Once
" U& _& @8 a* y. x% D* g7 N- C2 z - CMP #JOY_KEY_LEFT, c! m5 z+ K, p
- BNE .Next_Music
& O0 @3 n1 \+ @% u5 O6 ` - JSR Music_Play_Pre
# ?" d J4 [* q' z! X - .Next_Music;下一曲/ y& e" Z5 z, J5 p9 U9 l
- LDA FC_Gamepad_Once: V/ _4 I' E j3 l
- CMP #JOY_KEY_RIGHT
; P! R6 V. R: s9 M+ s3 | - BNE .Next_10_Music
0 y' A3 S# i6 O - JSR Music_Play_Next
* T& k3 o5 I$ X$ ? - .Next_10_Music;上10曲5 Y9 _2 I! c# }# M5 i* M2 b
- LDA FC_Gamepad_Once& M% M3 D Q4 Q/ `4 v: p
- CMP #JOY_KEY_UP% |+ k0 i/ U) \7 ?
- BNE .Pre_10_Music
4 u6 V3 |$ G) e1 Z+ p - JSR Music_Play_Next_10" ?- q$ ~( V& N& @6 u
- .Pre_10_Music;下10曲
* H( e) b! c6 d/ m - LDA FC_Gamepad_Once' X9 X. l, H5 r" R
- CMP #JOY_KEY_DOWN
) v, x2 ? i3 m( \; D1 p - BNE .Reset2 }( k9 I, R9 w# R; p6 C
- JSR Music_Play_Pre_10# L' x* h, M9 A
- .Reset;重播当前曲目
9 ~5 s, e* W) _# N/ q5 f - LDA FC_Gamepad_Once
* P9 V) @: q3 Z/ h - CMP #JOY_KEY_START# C; X0 P& h' S% _
- BNE .End
# x9 e% S0 o8 A$ c - LDA FC_Music_Index9 k0 e n& d8 j/ q0 L3 @# D8 i
- JSR Music_Init_Process
* }4 x- E* r+ D( ?/ m/ E - .End
) ?( w* d5 a# z" s- B! f - RTS
6 `1 G' N7 a8 e G3 ~# b
1 ?, T! B: T- z" N% P- ;----------------------------------------------------------------------
q- _% n; @! u4 t - ;播放上一曲7 w' L7 b h/ j1 R5 G k
- Music_Play_Pre
b* d, ~3 Y% S. r ?9 ^( j - LDA FC_Music_Index$ p6 X4 r( o7 y
- BEQ .End
! K! j) L$ O1 u8 _4 _6 X - DEC FC_Music_Index
' u/ w, Q/ \! [' R: T& T - LDA FC_Music_Index3 `$ Z# C) Y6 k$ c' {4 p
- JSR Music_Init_Process
" m0 Z8 P1 L$ C" t% P+ f) b - .End
% q& K4 ?1 [+ d. w2 c* M$ R1 \$ y6 g - RTS5 W0 ^3 Z' L H) c
- ;----------------------------------------------------------------------8 G% U( b# C9 l! y" G) w
- ;播放下一曲6 @9 t `1 {& Z
- Music_Play_Next
% Y2 v8 k% T$ G, Q0 q0 |4 G1 I3 D - LDA FC_Music_Index, W6 L- k& f0 _8 l! g
- CMP FC_Music_Max_Index. ]8 u0 n) p$ [1 V
- BCS .End
3 }, |, J# @0 l! t+ C7 M3 i$ H - INC FC_Music_Index
1 q- P8 h- C0 @% E, ] - LDA FC_Music_Index8 d/ h/ D9 {# G# c/ c2 ? p
- JSR Music_Init_Process
' z8 M" s" \/ F, S/ Q9 m1 w! n+ ^; Q# Q - .End
* }! r, I3 g. J4 v - RTS
7 @" p& c$ F$ U W
r" C$ E' @( g" p) g- ;----------------------------------------------------------------------$ B/ I8 a: k( d7 [
- ;播放上10曲6 d I' O s8 ^% Y% q. I% v8 K
- Music_Play_Pre_102 i2 K1 M% m R A* r" ?3 v
- LDA FC_Music_Index6 t4 u9 E* g; [" x0 L. [9 v. D
- BEQ .End; N8 z7 g6 S4 v* N" |2 z4 }; E
- SEC
9 u2 b! X, Y+ {2 t - SBC #10
' Z g: X* H7 `4 }" ^6 I6 O - BCS .Pre_10
, [: _# n! p4 P* x - LDA #$00
2 l1 M: d& X) G8 u5 {8 g - .Pre_10
& Q( ^3 G( A, G6 }$ @. i - STA FC_Music_Index' _ D! M0 o) f5 O& F" P
- JSR Music_Init_Process$ S) O. O4 O+ i. J6 p3 ~2 |
- .End
1 Y- I! k8 A- _6 h9 ] - RTS
, p S, F5 I9 J" [; t6 h7 q - ;----------------------------------------------------------------------
0 J, e' d8 ]1 B+ d- N - ;播放下10曲
S! [0 T: D) F& z( C - Music_Play_Next_10' _0 ]/ M1 Y& c. C6 q
- LDA FC_Music_Index
' S, l$ y* @9 S! j8 o1 u& v4 t7 J - CMP FC_Music_Max_Index
, I( L! ^8 p8 f9 H# \ _ - BCS .End
J) v: P- [4 G" M - CLC
5 w2 t5 F, g4 g9 f5 E - ADC #10( p, u, E, Q- F% f3 g
- CMP FC_Music_Max_Index6 `0 n! |! I' j" N" F; p% ^; p
- BCC .Next_10( ]0 C# f( {, N1 \
- LDA FC_Music_Max_Index
5 {+ A; m+ {- k M" p! d/ c - .Next_10
. k/ u% K* o$ f, ] - STA FC_Music_Index9 |2 A2 I0 h' R
- JSR Music_Init_Process
7 W2 q2 m) ?/ F0 r$ B - .End
; V% d Y# |' Q8 W( A - RTS* Z7 @! E3 h, |( F# l$ s8 l
- ; C, W4 ?1 J W1 {
- ;----------------------------------------------------------------------' {1 u/ c0 K' }' p% |) x9 @
- ;8位十六进制转3位十进制制2 ^, Z; y6 p8 U% g
- Hex8ToDec
& e+ u& W* D5 ^' _ - STA FC_Dec_Data_1
. N P( e5 n4 b# {6 E - LDA #$009 M, \5 H- J: B; ~5 j) U. `5 |
- STA FC_Dec_Data_100
. w0 D& ]' f/ q) x - STA FC_Dec_Data_103 I9 {! h6 `" n3 N0 K7 q o
- LDA FC_Dec_Data_1. P4 u+ T3 }! W1 L7 ^
- .Convert_100
8 A9 M% H9 \# Z8 O ?# o/ w+ Y - CMP #100% e5 a) ]7 J8 \. V! H2 }
- BCC .Convert_10: g1 d1 M& n$ i. G h
- SEC2 B" q( a1 @0 H& i
- SBC #100
+ x9 g d( L( t' r7 j5 Z - INC FC_Dec_Data_100
, @. l! e& w1 G1 K5 s! y5 A5 @) M( a - BNE .Convert_100
" `* b( y+ D. I6 E& m - .Convert_10. E. X3 {( E% v) n: @4 z$ N/ C6 A
- CMP #104 U: G( J* x/ Z8 U
- BCC .End, S& C4 Q- C7 O1 A4 [- ]8 m& o
- SEC
' g ?, P# W, z# l& p0 J - SBC #10
' w3 F% U6 S* D' d2 `/ ^: M! R# o - INC FC_Dec_Data_10
+ ]1 E- I$ @7 t m1 |2 E - BNE .Convert_10
& u5 C% k6 N( ~8 f3 O0 W1 ^; e - .End4 S2 I7 w& ?- ]
- STA FC_Dec_Data_14 Q; m5 L) t% H9 ]
- RTS' p9 K% | C5 e4 z; q& H- H, d. w
* }3 z# \* x7 ?1 E/ X2 D- ;----------------------------------------------------------------------
A7 j' W3 J9 A+ G6 \6 F' Z) o - ;显示曲目信息
/ v5 e4 i) U) R& _ - Music_Info_Display* p% ?7 t2 \) q* a% M$ g8 j
- LDX FC_PPU_Buf_Count
: v( W" A- C# v: @ - LDA #PPU_WRITE_MODE_CNT_LINE* J1 B4 V% m! i! w1 [+ W
- STA Use_PPU_Buffer,X
( W& D" {4 o( |/ w# c& d) w- ~4 [/ I - INX
; \, F6 @! ^, R% N) Z* ]" \0 R - 6 U* }( u: L5 y2 q( c, Z
- LDA #>MUSIC_INFO_POS- f* V2 N# k7 @$ Y9 K2 }
- STA Use_PPU_Buffer,X
8 R3 E1 b1 ] W - INX; Y' ?- J! F$ X! \8 v& Q8 f* u
- 6 a5 @ ~9 {$ ~
- ;居中/ d2 F4 x+ H" J- ^7 x. u
- LDA #<(MUSIC_INFO_POS & $E0) + (32 - 5)/2
, i5 ^! j+ ]" N" _$ M' u - STA Use_PPU_Buffer,X
- U6 r. H2 |: e8 X/ S% P* l# a; A - INX" O5 \. z6 k+ e m5 F
-
4 w' n$ S1 t% ~' p - LDA #$056 C/ c9 ? l: [1 z. P
- STA Use_PPU_Buffer,X
6 ?- `% O2 F, ] - INX
* a& C. \) j) b5 K7 z5 i - 9 \, U6 w% q. Y. {( i
- LDA FC_Music_Index
- A7 T# N0 V, v. w - CLC. w+ d$ K/ X8 i+ c
- ADC #$01% i! M# {5 \5 w; A0 a$ Z
- JSR Hex8ToDec5 A) w% @* }8 [! c
- 2 L4 W) N; ?/ @ E6 s5 h7 f9 R/ E
- LDA FC_Dec_Data_10% T& E8 E, d: o4 s! q2 p9 F& {
- CLC1 \# W A6 a6 F+ q
- ADC #'0'
/ r. o8 ~4 L- O2 Z& L) O0 u* F - STA Use_PPU_Buffer,X
& q( c2 }7 k& _$ O9 z - INX# u' @ ]! F5 W6 Q* y2 h
- 9 D) o0 X& o, B& z x2 p, C0 K! B
- LDA FC_Dec_Data_1
/ P' `. K; ^7 v& f - CLC
; ]1 w% e$ R7 k% l7 A @ - ADC #'0'
$ F: P ?7 `5 P% C# B8 ^1 r - STA Use_PPU_Buffer,X
' u1 p- }. c. m - INX
/ a3 @' `7 e2 W9 o: J - ' {5 v& j7 S8 V( I8 o9 V
- LDA #'/'
& g) g5 l% y0 ~; J - STA Use_PPU_Buffer,X
' }9 Q5 M, v" W3 S - INX; E" J d! Q c# E
-
, S5 Z3 P" u3 M7 S* V/ H) ^ - LDA FC_Music_Max_Index
* H$ o$ ~: ?) K5 v r - CLC
, K7 t2 ^4 F9 n0 ]$ q - ADC #$01
, E+ l% v- J4 E- I: @ - JSR Hex8ToDec
2 m8 C) m6 [: s5 q -
6 Q$ P+ q0 `" H - LDA FC_Dec_Data_10
! D1 k$ U( r* ^# i: H8 F: L5 H - CLC
H" Q/ t( E, H: P" a - ADC #'0'; F% G, w8 X; ]- T( W
- STA Use_PPU_Buffer,X/ o+ m% F8 u& P9 H2 e
- INX
7 J" H' f1 i% ^! P4 R3 j. J2 e# L8 W -
0 T4 k! ^4 ~, u' Z9 h - LDA FC_Dec_Data_1$ j2 E+ B! k) J
- CLC, C0 c* X- s( u6 a% a
- ADC #'0'
" u5 f k7 ^0 v* b$ _4 o# P - STA Use_PPU_Buffer,X
6 |2 \( g+ A2 H9 W! U7 {& j0 f6 \" y+ O - INX+ F" L/ Z% g) t* K6 _. ?
- & b4 w4 ^ i9 F& i2 P) e
- .End
" [! f, T5 a& [" d - STX FC_PPU_Buf_Count
8 w4 ~( j& d' P1 [" S% B5 ]6 f - RTS3 Q- e1 {0 b- b
, n$ T5 J8 h4 K+ `' b- ;----------------------------------------------------------------------. R8 f" P P3 u; V1 L) H
- ;音乐曲目初始化处理# D: Z% q! u ]9 ~
- Music_Init_Process
, T- V( Q1 t; g' r7 n - PHA0 w) x9 ]. m f( y4 w" E% {
- JSR Music_Clear_Process
% k# s) t/ i1 [5 B% ^4 d2 J - LDA #$1F
' g* u7 w- M5 B4 L - STA $4015
5 m6 V3 x+ r" f0 W6 d - PLA7 v) g& ~7 ~2 d& @1 {
- JSR Music_Init_Addr- E- r- a# q2 a& `: B% S
- JSR Music_Info_Display
. c. o4 g' q# A7 Q; T - RTS
2 B {: f7 S% O- ~9 q& H/ A8 `( ~ - % o8 Y+ C6 M* r e
- ;----------------------------------------------------------------------
7 y$ h' s G- [7 f: W/ U( y - ;音乐播放处理! v2 [# w! o: k F( W# T( M
- Music_Play_Process
# t0 |1 G2 m: w( M) y - JSR Music_Play_Addr# [. l2 w+ @9 z% |! X
- RTS0 V, w' ^0 |7 d
- - X' H" E- E- d! t1 \: A& J- v2 u7 \1 L
- ;---------------------------------------------------------------------- l9 I9 k" q2 R0 u
- ;音乐播放处理4 I1 C% b# O0 ^+ c1 E4 ?* i3 P5 ? D
- Music_Clear_Process
, \& r8 ]( i. v8 ~ - .IF Music_Clear_Addr/ c X" Z- e# t( l5 B- q7 B
- JSR Music_Clear_Addr/ }( `. v3 f8 v" U: j) t
- RTS# S4 i6 O+ b3 j9 e. Z
- .ELSE( B8 b+ T; o! H; X- x' H
- LDA #$1F
, s- g L3 \$ W, d: k( u# e; N& ]4 s - STA $4015
- |" K; Y5 Q( S0 R - LDA #$001 B# p0 F5 [0 `% ?. g
- STA $4010
: f: F( B) A6 D* B# ]7 B$ p - LDX #$00
0 ?# w6 {6 v% V. ^0 z8 x - LDA #$00
& ~6 A* f1 m; `4 d; h, e - : d# \ u6 I" i2 O
- .Music_Clear_Zreo_Page_0/ c5 I/ v7 _6 ]4 ]) J5 e8 o
- STA $00,X
7 a/ @4 g: I" D* [) J% p1 ~$ X - INX
" w" x, M$ K3 e+ E1 _7 ]" ]( } - CPX #Use_Zero_Page_Begin6 ]7 r9 E/ D: D0 s2 `
- BCC .Music_Clear_Zreo_Page_00 l/ c+ \( Q9 U3 @/ C$ r! ]- ^
- " P2 ~% G4 J( O. F* v+ D; s
- LDX #Use_Zero_Page_Begin + Use_Zero_Page_Size; X5 _$ d4 H& {( H7 c
- .Music_Clear_Zreo_Page_13 @) g! A0 R3 W0 u9 z9 [, z% l
- STA $00,X7 P3 p/ s; D: e4 h, W
- INX
{$ a5 z$ J+ ^' V - BNE .Music_Clear_Zreo_Page_1
* A! k$ n. P& q2 B. I* a G -
* E5 `) K0 }1 b* Z - Music_Clear_Process_1 E6 w$ g0 O% {. Y
- STA $0600,X
/ z* A# A9 n% F% i7 E- {3 q0 \ - STA $0700,X
8 Z! S6 F ~& }* ^- O2 x - INX: C( } n# R! x! K+ X ]3 N
- BNE Music_Clear_Process_16 D" `3 c+ P: `
- LDA #$105 {/ |. S5 Q$ ^$ V8 O
- STA $4000
6 y% M6 { m3 M2 r* e - STA $4004! T2 w6 G8 i; L+ a2 e- G
- STA $400C# \% r6 [3 f2 p) C
- LDA #$00
0 ~$ Y% K# x( [ g0 `6 ~; p - STA $4008
- r3 [# P& ~, d - LDA #$0F* M" M6 Z/ {& W" g$ o, ~
- STA $4015
5 T% x% D1 W0 U+ ^) o C4 S - .ENDIF+ I) v" X- C5 o9 ^5 O
- 7 {. k; U$ b2 A2 h' P5 ?0 @8 b
- RTS: k" L- {) ~$ l8 q1 z
+ i/ A8 E- q q- ;======================================================================
' J4 |" j6 j1 t2 g5 z - ;重启处理
! m7 E: h$ m5 l4 Q: ~& m5 |. a& N - Reset_Program
2 q' H: f' {# \! [1 z - SEI/ W, g0 ~3 t! `2 j$ G
- CLD
: K' \& r# B' u1 A0 d/ p: ]. Y) K! ` - LDA #$00% L9 }- E% E' m- o
- STA PPU_CTRL6 ]/ a! u" M+ S0 [4 j" k* [
- STA PPU_MASK$ f+ O8 X0 J3 `
- STA JOY2_FRAME! {1 O; ^9 U# X7 X
- STA APU_STATUS/ f) E& S" o' o7 r$ F: Y* O5 W; l9 M
-
4 ~' r D8 }( j+ F* {3 I% D4 O( b - ;等待屏幕准备完毕
5 m6 t$ R6 B, t - LDX #$023 R m. m' m4 s
- .Wait_For_Screen_Ready$ g% Y4 W% i: P" E, y4 [3 O
- LDA PPU_STATUS
& t$ g" w3 s- D7 I - BPL .Wait_For_Screen_Ready9 s7 [5 \$ z4 R4 b4 O& ~+ H9 \& h* z
- DEX) | x! _6 O# d M8 A: \- l% v2 m
- BNE .Wait_For_Screen_Ready
; H. r# l2 ?- L, y+ ]( u: q5 T -
( j1 z$ ~; J1 U# \, o' M( D- t8 @5 c - ;清空调色板
( N" |& T2 w. {8 U - Palette_Clear
6 \4 C, G2 }; b4 F - LDA #$3F
) r/ H* B+ m6 E, s+ ^, a - STA PPU_ADDRESS1 ^; l8 R) a. t
- LDA #$00% ~; F" |0 U6 A
- STA PPU_ADDRESS
! k+ |* v) d7 {1 C$ b" [ - LDX #$20; ^, I+ y; x7 M) h" ]
- LDA #$0F
( Z, M& g9 U1 u2 n, |7 c3 |' S5 j - .Write_Data, S; |/ p' C1 i* d" ?$ S k: O
- STA PPU_DATA/ ~: T& u" ~3 q% ^" r" h
- DEX. |4 P5 v1 l8 W# C
- BNE .Write_Data
- ^5 R" {. P6 c! p$ U5 R
6 a: e. }: o0 @' Q- ;清除声音 $4000-4013
4 M5 o3 O4 I1 a7 l: P - LDY #$143 D" T/ r8 b( K3 J2 g; U
- LDX #$00
. q$ X [: c" g/ [ - .Sound_Clear0 a% B$ f6 r" \" I: f
- STA $4000,X7 M! O# @9 o5 }5 l
- INX7 r w( m9 x' E& g) B; D0 K
- DEY
; z/ e: H+ B% G, ^6 r& p3 B - BNE .Sound_Clear
0 s: ?& i% }* t1 p/ n! ^ -
8 q; U5 J5 `* h1 G% n" [2 E! m - ;清除 RAM $0000-07FF
% u5 Y/ V1 X1 h - LDA #$00
% I9 V1 t9 s4 K) o: g" r - STA $00
3 t/ R/ ], ?* U1 ? - STA $011 e" w8 e7 s( L# G# a2 \% n
- TAY
" t* p r9 Y' {+ p - LDX #$08
+ A5 u! n) A/ I! P, b - .Memory_Clear
1 m" Q3 {5 p4 B+ W - STA [$00],Y
6 n/ U! Z# H: l6 ], N - INY
, V8 ~/ j( Q) l& U7 w0 g7 G - BNE .Memory_Clear2 v$ @% j% a/ X: _
- INC $01
$ t) ^. a- l' v% i( f3 \ - DEX
8 N6 A U% ]( |* W' K" r - BNE .Memory_Clear
* l8 b9 d. Z3 f- g3 c0 @) M - ' F$ k, W/ F& o( I0 j) P. p
- ;精灵缓冲初始化5 I7 y/ _2 o2 |2 G
- LDX #$009 q8 \0 \+ c2 |" J
- LDA #$F8
4 I+ J5 X# u. H2 b$ e o5 D6 D - .OAM_Clear
2 b% [" v& ~+ V" f - STA OAM_DMA_Buffer,X
2 z: K: L) E; }% E - INX; w% x, j+ R6 x5 n% {7 V
- BNE .OAM_Clear
@7 S: f3 Q: b. ]4 q6 P6 r -
4 v, d: d1 g' i- g" F - ;栈指针初始化 N4 r: _6 Y+ y" o+ S6 s
- LDX #$FF+ Z/ c. G( _7 T
- TXS
' W, `( G! S' x6 u - & E0 u2 \# G `8 f8 j
- JSR Nametable_Clear;命名表清空
! X7 j6 T g- L - JSR Palette_Init;初始化调色板缓冲
. c: q" }5 O0 E/ D1 Y1 u - JSR Static_Text_Init;初始化静态文本) j$ h/ J" s4 L) u0 p
-
& A3 m& P2 }3 _' E6 R J! | - LDA #MUSIC_ITEM_TOTAL - 1
, ]. ^6 ?8 L: }; M# ~% K - STA FC_Music_Max_Index& S0 B8 D; C; S' f; C1 W
-
7 [9 ^ I; d" E( U! c2 l: y - LDA #$1F: E$ }; P4 B% M! H6 T! J' {+ V; ~% V0 s
- STA APU_STATUS
* J0 t Z" ?! M3 J* Y# d - LDA #MUSIC_BGM - 1
1 A/ s9 w$ D7 ]' j3 G+ k2 O - STA FC_Music_Index
' P. {; X; j/ I# M# l - JSR Music_Init_Process;音乐播放5 f' Q8 u1 d3 P, ?9 y4 _
-
$ x6 @& B% `- S3 v/ r {. A - ;设置屏幕显示状态缓冲(当NMI处理时控制屏幕显示状态)
& h* o3 J& M) O o7 u - LDA #$1E/ p; Q. {# D+ N1 V( c" z4 N* t' o2 p
- STA FC_PPU_Mask_Buf
7 Z( e: _2 o$ y% |: g -
) m6 H7 p4 v* ]4 N) G - ;启用NMI处理; Y9 J# m- W. x0 }
- LDA #$80
" C8 `% ]& W/ |: ^7 W2 {% N$ U1 l' o - STA PPU_CTRL
. q, m* F, t: V2 p5 U" H. Y -
* x* Z; R8 ^' F" D8 U+ z4 J - ;程序循环, 剩余工作交给 NMI 中断处理
; w, i* i4 |: y, ]. I - .Loop* Y. y5 V& W/ y
- JMP .Loop
6 c8 J: y$ s$ h; T - + B5 b3 y3 n& B# D# c& d) ^& M" I
- ;======================================================================- x1 y2 `9 g- j2 m. n/ A! C
- ;不可屏蔽中断处理, q$ \1 k( \( S; q
- Nmi_Program
+ ~5 S4 Y9 ^9 M- l1 u8 n. l - PHA
' E, b+ [/ H+ v5 a P6 h% C5 r8 X - TXA
. v* l A! v) x* N& F: v6 g - PHA
6 i0 `8 b( G7 C( l/ ~0 W" i* p* n - TYA+ G# Z' P3 {6 R& ]- L0 A; V
- PHA9 t* y& s! r! v
- # b( p7 f" N: l5 |8 y, {3 R% b
- LDA PPU_STATUS;读取使得 PPU状态寄存器复位
5 w4 L/ v3 U+ \4 V2 ] -
% ~* A, S; W- E+ _3 n- \* U4 ~ - JSR FC_PPU_Procrss;PPU处理
9 J& U( Z j7 n% p% a. x7 w -
t$ J) W& \! W, e) ?% z2 x3 Q) i6 P - ;精灵内存更新
! o7 w$ L) m" V8 |2 B( \ - LDA #$00# g, B6 C: @& k
- STA PPU_OAM_ADDR' w J, n% z2 ?
- LDA #OAM_DMA_Buffer / $01007 d1 ^* W; l: I0 v- A1 a
- STA OAM_DMA' \# J8 n; r* `' Y7 I1 B
- t* f& t$ W! C$ ]
- JSR FC_Gamepad_Process;手柄输入处理
$ O9 q9 p. n/ {) b - JSR Music_Select_Process;音乐选曲处理
3 l1 a) Z+ x+ u/ h+ l+ r0 a - JSR Music_Play_Process;音乐播放处理
3 a: a. z! L) L3 w -
1 a: S6 Z& u8 A1 r; \ c- x - PLA
0 t% D* L) j5 P: b1 u; N6 c - TAY& [: _3 e1 j" I2 F# X
- PLA* s* Z7 w1 X% n; d# o y" d: j
- TAX' e8 r6 X, Z8 x1 f. B
- PLA
8 Q! ]5 b+ u* _; o+ Y6 ?
3 B% W: s, ?5 k4 d; f- s- RTI
. n5 U+ ^! H; s6 i- Y: o! T
: T( q8 @7 m1 K9 w- ;======================================================================4 v8 ?% m! s1 B# n; Z- n+ S
- ;请求中断处理% c4 ]' [: {. T) b7 F$ A
- Irq_Program1 I( l" ]. a& ~
- RTI
6 c) ?0 Q6 B- K1 @. g
4 }% S$ B) N( W( E6 D- ;======================================================================
) U, G7 B$ D+ p - ;中断向量表
* R$ Q% t3 \$ d% s2 m - .ORG $FFFA' z' M) y5 |; B) f& \( H) _9 d
- .DW Nmi_Program ;NMI触发时执行
9 k- {' o3 x; v) W5 G. v( |3 W - .DW Reset_Program ;载入ROM时最先执行
r9 t! r7 T w* X - .DW Irq_Program ;IRQ触发时执行
# a, x, e" ?/ V) r9 ]6 o$ E0 u
复制代码 $ y: b. Q4 H ]! |& V. x! T
! l6 w; ~5 i# z% L) }
: y8 P- N0 s! n' z
https://gitee.com/flame_cyclone/nesasm_3_2 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
1
查看全部评分
-
|