|
|
这是个 nesasm 3.2 入土教程, 感兴趣的可以研究下/ {& e5 ^7 f) l) v) V8 K+ z
2 L2 e/ }- I P/ B0 d* B
以下是主框架代码:
% c' P; U+ L( Y' A3 Q- ;======================================================================
& U. ?, E$ l' E5 R& w - ;文件头
4 C& `! F7 ^- p0 @. G% Z0 C' | - NES_16KB_PRG_SIZE = 8 ;16KB PRG大小数量8 x, i$ U. @( k5 Y& y
- NES_8KB_CHR_SIZE = 1 ;8KB CHR大小数量
1 `: ^" x- k. r' e% J1 { - BANK_DATA_MASK = NES_16KB_PRG_SIZE * 2 - 1 ;bank号掩码
6 M* o6 {, V- B9 Q) c7 x% C" E. R - ;======================================================================
! \8 H; N8 `9 y3 b, G/ `. B - PRG_DATA_BANK_C000 = NES_16KB_PRG_SIZE * 2 - 2( `7 |& Q* e) @ t i9 l
- PRG_DATA_BANK_E000 = NES_16KB_PRG_SIZE * 2 - 1
. n+ ^# x. n1 a2 a1 l$ g - ;======================================================================
( U# S8 Q& s& j3 X- Y - RESET_BANK = NES_16KB_PRG_SIZE * 2 - 1
5 }9 z, z2 Z" `: \, Y5 s. u/ `% n - RESET_ADDR = $E000 ;主程序起始地址
' C6 J) `' p. g- g( d* O - ;======================================================================1 c& J Q6 ~5 W
- .INESPRG NES_16KB_PRG_SIZE ;16KB PRG 数量, $01-$EF8(1-3832),即16-61,312 KB# |0 p' K7 G; d ^' s5 ]
- .INESCHR NES_8KB_CHR_SIZE ;8KB CHR 数量,$01-$EF8(1-3832),即0-30,656 KB
1 _/ w. D2 Y3 F - .INESMAP 4 ;Mapper号 (0-4095)$ E$ a4 O& X. ]6 V) Q% C4 `
- .INESSUBMAP 0 ;子Mapper号 (0-15)
5 v' V2 ^; U9 j& k' y$ }) M9 A! } - .INESMIR 0 ;命名表镜像 (0: 水平 1: 垂直 2: 四屏). P2 k; f7 t6 o6 k M$ Y) x
- .INESBAT 0 ;指定是否存在电池备份 (0: 不存在 1: 存在)
; H |6 Q' z1 C9 Q2 c: ~5 C2 N - .INESPRGRAM 0 ;指定 PRG RAM 大小 (大小 = 64字节 << 计数)
C& M3 n7 T, U7 K) C - .INESPRGNVRAM 0 ;指定 PRG NVRAM 大小(大小 = 64字节 << 计数)
% K5 ]) e4 [+ @: l - .INESCHRRAM 0 ;指定 CHR RAM 大小(大小 = 64字节 << 计数)
1 P( E$ U1 X9 c8 Z' V - .INESCHRNVRAM 0 ;指定 CHR NVRAM 大小(大小 = 64字节 << 计数)- N8 b1 h9 K, d+ b3 N' T! ^6 p
- .INESTIM 0 ;指定时序 (0: NTSC, 1: PAL, 2: 多区域, 3: Dendy)& p. t; o' i- {
- ;======================================================================
L- n6 ^: p1 f g- l8 K - .INCLUDE "fc_demo_config.asm" ;全局配置
# z3 ?+ e9 s. U T% P( Q - .INCLUDE "fc_demo_constant.asm" ;NES常量
8 N, U R8 f9 x) u) H* { - ;======================================================================
9 g9 l7 v* I; ~2 E' [" d - ;音乐配置
# ?# n/ Y! |. v* c9 y1 ]& f - .IF 0 = MUSIC_THEME # N9 j$ l8 N! {! h, e3 K
- .INCLUDE "data/music/Gremlin 2/config.asm"% L8 P3 f& l+ J" H8 V0 x0 w2 d
- .ENDIF
/ n0 d' ^7 v/ v - % B# O' U6 s3 R3 I) f7 Y6 u
- .IF 1 = MUSIC_THEME
; l) U- {+ ]1 u& M. i: ] - .INCLUDE "data/music/Raf World/config.asm"
! H. T2 r1 S% t7 u8 t - .ENDIF
D7 I# P/ n, Z6 R, b9 B - , m* Y' p5 P& a/ I/ ~' s) j; a
- .IF 2 = MUSIC_THEME * y( [3 |" P! h5 V6 `, {/ G7 y
- .INCLUDE "data/music/Ninja Gaiden 3/config.asm"
+ T4 m3 e+ G8 e# T - .ENDIF) p8 o3 s3 y0 T. i
- 0 \* l9 v( j ^5 M3 ~' g" R2 P
- ;======================================================================
9 C: p- }# D2 r7 B- v! Y - ;引用CHR图像数据! p" h& H8 ^. `! w2 B
- .BANK NES_16KB_PRG_SIZE * 2
+ {8 S# i" r2 r6 `6 ]* o6 o1 K - .ORG $0000- u1 p, `( U) G2 r
- .INCBIN "data/bkg.chr"/ s2 b% z6 d8 r
- .INCBIN "data/sp.chr"
, o8 i: \( _! D, I& _/ d+ f/ T -
. }# ]. u* q1 [+ o' b( c - ;======================================================================
+ A% C9 J1 G8 U - .BANK PRG_DATA_BANK_E000 & BANK_DATA_MASK;设置程序所在Bank1 a; C g Y+ \3 F
- .ORG RESET_ADDR% S4 C- Z/ U6 s+ o& D: Y7 \
- ;======================================================================8 |2 ^' d3 H5 a
- ;引用其他源文件7 L. ]# F0 l4 P* w6 p: [& _
- .INCLUDE "fc_demo_ppu.asm" ;PPU处理
" v" F7 ?6 G, b# v - .INCLUDE "fc_demo_joysitck.asm" ;手柄处理8 H+ P. b3 k3 u) R4 @, i
- .INCLUDE "fc_demo_static_text.asm" ;静态文本处理
6 }/ ~5 S/ L) x2 K: n) g - ;======================================================================4 m! |; _9 |: G5 @* [" S
- 5 q8 P: R( k- i0 i9 a4 I$ C
- ;======================================================================: {' }; Q9 c6 ] O! \# r/ V( A
- ;等待VBlank到来
7 ~; t4 S. L4 u; A* E - Wait_For_VBlank/ ~1 h$ x! e$ e/ A( ?- h0 v
- LDA PPU_STATUS
+ e% ^! F( _) ?; S. h/ v - BPL Wait_For_VBlank
& x" k R' Q$ ?! z) W; r9 X2 s; O - RTS
1 S4 q& O- D; K- v - # o5 T4 v2 @3 b
- ;======================================================================
' o! M) o. _9 H. T - ;调色板初始化
' ~3 |9 j( F I9 U" h, y- }4 o - Palette_Init: c. ^8 u' [. }* t$ X3 Z/ D$ ~9 R8 V
- LDA #$3F
+ @: h+ ]% p3 [8 ^* E - STA PPU_ADDRESS
) }8 a. j" g2 G& N! ]8 ] - LDA #$00+ Y% ]3 w. J- e5 z7 o; O
- STA PPU_ADDRESS
5 S+ L$ W$ ^4 ]* z2 e - LDX #$00" v) I/ Q/ ~* s s
- LDY #$20- S2 o- N1 I( |4 i
- .Write_Data
& X' ~% g9 N; o9 o% m) m - LDA Palette_Data,X
9 i0 e. i" ^5 w0 S6 V, q - STA FC_PPU_Pal_Addr,X0 A; f3 N2 ~3 y S
- INX3 f3 n7 X6 L+ @8 O) j" F% P
- DEY
, t3 ~# f' a' F6 o o - BNE .Write_Data
4 T4 s6 S, L0 {0 b7 o- k I - .End
' l' h' N, ~5 h2 c3 J - RTS7 \4 A( {8 F! H$ ]. d) m6 j% x
- ! f- C6 \4 ?; h. X! G- q H
- ;----------------------------------------) N" ]7 O: Y; `! V
- ;调色板数据4 X- V& T6 s2 P8 s) w- T
- Palette_Data) L8 n% p1 z7 _
- .HEX 0F 20 32 02 0F 20 32 0F 0F 20 32 26 0F 1B 0F 1B
4 R, r) L; y! q. B8 [' z - .HEX 0F 21 27 22 0F 24 24 24 0F 21 21 21 0F 22 22 22
5 `$ d2 C9 |; l& o' l6 b, ^5 { -
# K! H) c! M3 D- h! X' j - ;======================================================================
: X: c* s3 ]+ X$ ]9 Y - ;命名表清空
" Z5 W+ b; n1 C9 O% b; w( v - Nametable_Clear
6 T& e$ ^; c- A4 S* O - LDA #$20
P1 q; g" S( I' M' j - STA PPU_ADDRESS
3 h1 D1 [; c7 q; A8 j - LDA #$00, O% S4 c" Z( }' C, ~6 s( \+ r. R
- STA PPU_ADDRESS# W* m3 U; B. s" t! E; E$ y) s
- LDA #$00( I5 A' c! Q- {
- LDX #$001 A2 M; o2 X3 a8 I
- LDY #$08- Z/ v" _0 b& d# C5 M
- .Write_Data `' B: D2 f' f, D3 J
- STA PPU_DATA* M* q2 q7 [# f) n
- INX, b" v( P. | t ? D
- BNE .Write_Data+ x8 ~4 }# L7 z1 R3 \
- DEY/ C ]0 Y0 k {' E3 [
- BNE .Write_Data* R( C6 _( K5 b, Q! z( J
- .End
6 t1 @' v! v* O8 e4 j7 c7 m - RTS
: d) S/ M1 B q; {$ L S - ) Q; v# ?; c' R& S4 c4 t
- ;======================================================================
9 F5 Y, V+ n& ~( K1 g, c6 R - ;音乐曲目切换& i" @4 D1 z# r* s c
- Music_Select_Process
0 \; a* B. T# p, W* N. L - ' H1 r$ S2 m( o4 M/ @
- .Pre_Music;上一曲- V/ ^! { U |" X# ?% O
- LDA FC_Gamepad_Once" K; o+ }/ \# P/ L( K
- CMP #JOY_KEY_LEFT8 A2 g& ?, C; W8 {
- BNE .Next_Music
4 }9 m" t: B" E/ L - JSR Music_Play_Pre& h, c( [! t4 `5 o. y/ t) _
- .Next_Music;下一曲" h s0 X* b0 z7 U: p& t0 x4 F* |
- LDA FC_Gamepad_Once
5 p6 |2 |0 q% f, E9 M - CMP #JOY_KEY_RIGHT
* @& e( J, x$ }: L$ J/ Z- J - BNE .Next_10_Music
6 P Z/ `( U7 H - JSR Music_Play_Next
" |% o' F6 N; k) v: D - .Next_10_Music;上10曲
. d& e$ V. O7 F - LDA FC_Gamepad_Once
/ ]1 G9 }# ~) W* X; H - CMP #JOY_KEY_UP
" F7 m; m) k- M - BNE .Pre_10_Music
7 e" R! H$ i/ ^3 u - JSR Music_Play_Next_10" v, H4 p1 b2 Y0 K* p& t4 w/ B( H
- .Pre_10_Music;下10曲6 L: T# `7 b2 q; L% }8 ^2 u& d
- LDA FC_Gamepad_Once8 |$ P4 R' I. C8 _: z
- CMP #JOY_KEY_DOWN. _* \# z* `# H/ }! f
- BNE .Reset1 U6 ~8 m, S' p5 {3 u6 W+ d
- JSR Music_Play_Pre_10* K$ U! K" a2 `( s( q# c
- .Reset;重播当前曲目" S% n/ G# \( }* x3 }1 Z" M
- LDA FC_Gamepad_Once m- e/ f8 M: N1 {
- CMP #JOY_KEY_START; v* D; f& f7 H, {
- BNE .End% ~+ a/ R& m& c3 v- N: v
- LDA FC_Music_Index
* i9 A) a2 @6 \: r* b - JSR Music_Init_Process
" W: ^" c6 f+ f - .End
! J% H5 \5 B5 v! x: \0 J - RTS5 `! @9 c# B1 J+ g
- {' o& `2 z! [ l5 u- ;----------------------------------------------------------------------/ S9 \, R' Y0 Y/ ]
- ;播放上一曲4 z1 Z( U3 s8 \% C& Z
- Music_Play_Pre
0 b' l- q% ]2 u/ F; ^) ~2 ~9 O; x+ J - LDA FC_Music_Index1 s2 W! Y+ q3 M/ |
- BEQ .End* ]) k1 w( L: N$ v0 l
- DEC FC_Music_Index1 M3 _, Q7 X1 }2 H3 [. I
- LDA FC_Music_Index, s2 i) K) F' {' @0 [1 M
- JSR Music_Init_Process( u7 b6 Z; r4 A) `! _ y
- .End3 o% J3 K, n1 J, z
- RTS
3 V( F( C: u3 L - ;----------------------------------------------------------------------6 R' U2 b& m/ y
- ;播放下一曲
" G3 d! @8 w* O7 K+ T, C4 S; t - Music_Play_Next
9 e4 q2 N$ S% Z; N) | - LDA FC_Music_Index/ y$ Y4 @3 B4 n2 k6 B. | Y0 b
- CMP FC_Music_Max_Index
/ Y: C$ O9 p0 V7 B+ H) F, x - BCS .End
% ?6 z& k' k2 l4 l2 B$ i - INC FC_Music_Index
0 Q1 F+ |! y; c; s, Z# { - LDA FC_Music_Index9 w' N. U$ w/ u% \$ G& G/ a6 i
- JSR Music_Init_Process
}% s u5 H+ S7 d, f, l - .End" C9 c W9 p; x
- RTS( U6 P+ B1 j! ?
' q. Z3 Q8 `1 d( I8 H y2 K- ;----------------------------------------------------------------------% \) a3 k5 i0 n- e+ S5 T
- ;播放上10曲
" Z6 B1 @* G1 k9 x' O+ s/ f) W8 L0 o8 a - Music_Play_Pre_10
t$ T* O, D5 q9 `( l - LDA FC_Music_Index
% k1 K/ y( }+ n+ ^" X- ]8 V - BEQ .End2 f+ B( t5 a5 P
- SEC
! |2 Q; l, E. h2 G - SBC #10
1 B, R0 N1 S8 b - BCS .Pre_10# M& V% i- j* H' c2 \7 F X
- LDA #$00
" d; [; U0 C: d) X! {" k1 g - .Pre_10
2 P! w2 W T( z! R+ t, Q - STA FC_Music_Index' F4 W8 o; z0 `1 H( z0 M# A0 m! R6 D
- JSR Music_Init_Process% e6 _ _# |9 U: s4 @0 \: |
- .End9 J# u* y2 s- m5 V$ v
- RTS. e. w. ~, W+ M/ R, w: y
- ;----------------------------------------------------------------------
% h9 C$ S$ U8 n1 ` `1 ] - ;播放下10曲2 r8 a, o3 _: Z( p. Z; ~
- Music_Play_Next_10
5 \" ]3 i c4 }# i$ B8 p - LDA FC_Music_Index e8 M) C V+ i; Q) j
- CMP FC_Music_Max_Index$ `$ Y% D0 k' e8 g
- BCS .End
0 P8 ]& J) `+ a f4 f - CLC
( b4 a1 p* w) E: K' D5 Q - ADC #10
* o k$ l; d4 J' b) w1 D7 \% ] - CMP FC_Music_Max_Index
9 W7 k% ~& ^5 r: f' Q) a5 k' w1 L& r - BCC .Next_10
. a1 o& j( H, W, T& @ - LDA FC_Music_Max_Index$ o8 i+ W3 L. G4 f
- .Next_10
3 L2 V+ M5 O/ t5 e) y - STA FC_Music_Index
0 ]) W& G8 {$ y - JSR Music_Init_Process P5 G9 p, W1 w5 `) O+ ]% O
- .End
- a& U n) u/ X - RTS
8 [' \- H e6 @# X - 4 Q E2 z6 P$ M3 _' s& r" c
- ;----------------------------------------------------------------------
" u R7 J3 i# n( s* t' r0 p - ;8位十六进制转3位十进制制
7 N( ?/ e' A, S* v) Y - Hex8ToDec
) t2 h! [% n4 |8 i' E! v1 g) m: \ - STA FC_Dec_Data_1
& G" w/ _8 A1 S1 Z - LDA #$00
) y, n5 X: u. r/ u v - STA FC_Dec_Data_100
# E) _4 A# s" \( ~ a" x - STA FC_Dec_Data_10
+ q. {& ]) x0 R4 z - LDA FC_Dec_Data_1* I9 b) v# l2 _( p8 e
- .Convert_100
6 V- T& j* R: ?+ S5 M1 \2 v3 | - CMP #1001 ]* f: }! C) j+ c5 b c; e, `
- BCC .Convert_10$ c, i& _3 W& Q! F: p
- SEC
@2 _1 S$ y/ e) u. B4 [+ E - SBC #100/ v m# |' E) |+ F: _
- INC FC_Dec_Data_100' z/ u/ D. ~5 Q! B! a
- BNE .Convert_100
4 F/ s+ c. d( B$ H2 j - .Convert_10
# g' b' }) ~9 O- P# q% S - CMP #10( E4 S; V% _; w5 `8 {0 k
- BCC .End+ }& J3 f3 w G. D t8 L3 m4 W4 N
- SEC3 K d2 p) E+ N
- SBC #10
! P- \8 C- G' q6 d - INC FC_Dec_Data_10
1 u- @/ ~$ d) r$ z& e7 u - BNE .Convert_10, J- g3 T8 K1 d- K7 u: l; G- O t% D
- .End
$ l% O. {; t+ }3 m( R6 j - STA FC_Dec_Data_1; k/ f' L9 a7 @ X
- RTS- W' Y$ v" U/ I$ x$ P
- ( P: D7 V3 t0 u( O5 P; H4 a
- ;----------------------------------------------------------------------1 O/ L$ |3 b( z# Y9 W) V- L
- ;显示曲目信息+ q8 X0 j9 p2 b4 B# c2 D
- Music_Info_Display6 L) t* D! k& m, A+ h; w8 u" {
- LDX FC_PPU_Buf_Count& y7 T0 Z2 K% U5 `6 @ R J+ K1 ]
- LDA #PPU_WRITE_MODE_CNT_LINE
" W0 o3 p6 F" e, j/ Y2 j6 u! G - STA Use_PPU_Buffer,X
0 G3 P! g0 z$ E: J; j+ z - INX
8 n$ G; c( k% L% d2 B& r -
- ~4 A9 L# P1 {' ]% H - LDA #>MUSIC_INFO_POS# F4 F7 S+ a& C: g6 b- i
- STA Use_PPU_Buffer,X
4 x3 G. }4 J) ~& ` - INX3 O' d$ |6 z3 Q* s- W3 Q- Q
- * _, s$ Y' O! j+ S/ D/ Y% G3 X
- ;居中
' o4 F* {0 X) M# o0 x. H d/ Q - LDA #<(MUSIC_INFO_POS & $E0) + (32 - 5)/2
' e# g+ y0 b0 Z) X' R - STA Use_PPU_Buffer,X
* p8 A! G5 V, Y- q7 K7 F - INX/ p7 |3 y* ]* H2 D2 s2 c: [
- . Q4 @+ b9 u9 Q
- LDA #$05
. N$ M8 j6 ?$ [3 K( Y - STA Use_PPU_Buffer,X# a, a p! z4 M8 C$ k
- INX
2 `- Z/ O6 f# x* p -
5 _; T! V1 O A3 q1 B3 }3 C - LDA FC_Music_Index
7 Z4 i! ^' b% W( R: }1 o - CLC O6 b. B, Y- G7 @
- ADC #$01
2 c7 U. | D+ i: W% ? - JSR Hex8ToDec% g* _% M3 m" B; g V8 d' |
-
" M" O# a$ ?2 N( Y/ B1 B$ _ - LDA FC_Dec_Data_10+ \2 ?% d5 k9 m- i& W0 s4 e
- CLC# z% O# Q. o. t9 Y/ Z
- ADC #'0'
8 A) y* h& n2 F$ ` i5 Z) {: I6 e - STA Use_PPU_Buffer,X6 H& n. j. \2 u [5 e6 M" }
- INX
1 e* @1 `! H& i! S& `3 e% L -
5 K! b; U4 n! V1 } - LDA FC_Dec_Data_1+ x* b& O6 i% q) [ d
- CLC* @+ N# k6 ?6 e; U* y8 a& A
- ADC #'0'
: l! \0 k" k3 ^' Z* V. Q* f - STA Use_PPU_Buffer,X+ h. w$ ~. n# l. g: z/ d
- INX) f6 M5 s) `# z9 I1 d) R' R
-
7 C1 n; x/ h3 I3 N- | T; q - LDA #'/'
1 E; V2 [" A: u( O - STA Use_PPU_Buffer,X
8 G4 n/ y ]; O7 |) X" x" _+ ^# y - INX
' k, p( M0 e9 c; c -
" I( C1 s' N k! {7 a - LDA FC_Music_Max_Index
T% h) q% s0 B; d# [1 D( n - CLC5 n8 ?- K ?) ]9 k
- ADC #$01
/ E- o7 |! p+ q0 P& A - JSR Hex8ToDec9 `3 {, ^2 m3 ?4 y
- $ Y0 [) d5 q4 @0 a6 e- {
- LDA FC_Dec_Data_10
: K: x3 P2 Z' M5 s. `8 O$ Y/ D# T - CLC$ l: a( S6 G. P o) K/ E
- ADC #'0'
2 @- W2 T/ V0 |, B& [2 A3 ^- Z3 x8 ] - STA Use_PPU_Buffer,X
- W: j9 s2 ~: H- d* |4 h0 M - INX
4 N! i! y: h* N -
/ F, j8 N* W Z3 r" s9 q - LDA FC_Dec_Data_15 [8 K% z- P# k
- CLC8 X; o& w" z* ^. P& a* z4 z
- ADC #'0': [4 k! r- P' D& C( c l- d
- STA Use_PPU_Buffer,X
? q6 X% p2 l3 x" B4 h9 X7 K& d$ z - INX# k8 N; I, z& ]$ ]
-
$ i1 ^" D# _& w- L' | - .End
9 t5 c, R4 H. I v" y6 Y - STX FC_PPU_Buf_Count
0 s& K# }/ X, o; q' d% Y - RTS/ S8 m* Y' @8 @6 W9 K9 R% q
- q O% ^9 B% |( x1 i- ;----------------------------------------------------------------------8 w# E- r, m) J1 K! o8 S
- ;音乐曲目初始化处理6 @. P7 Z. b K; o+ Q, Y7 |
- Music_Init_Process8 ~1 ?# L. b& O7 J$ t u
- PHA" l6 I) a) i2 c5 k9 A. x
- JSR Music_Clear_Process6 Q7 `. \, |0 h9 p8 E) Y; p
- LDA #$1F5 m0 u0 v& v5 T& s: P# d q
- STA $4015
) N9 a. t0 g0 O - PLA
- a: f2 D; C z( b4 O6 f - JSR Music_Init_Addr/ p1 D) t9 ~$ P% |6 ^) x! p$ _4 k
- JSR Music_Info_Display
+ E6 j; j5 Q8 C7 v6 V - RTS
5 {$ {' e; ]' k5 Y. C7 l
- H. A! C! ?7 v. L) M- ;----------------------------------------------------------------------7 ~7 a* i2 K/ O" X- H: d% n% `
- ;音乐播放处理) R5 T1 u- |- ?; ]' L2 ^4 ^
- Music_Play_Process: i& M+ q& Z4 Q% V
- JSR Music_Play_Addr
" ^) O& h' n) e - RTS& H! Z; u8 C% A1 O
- " j% |% N# z/ d7 A! t2 b
- ;----------------------------------------------------------------------
3 e3 `, }8 ]3 A! U9 t - ;音乐播放处理
' e2 a. g0 {; h% s9 i, @0 A - Music_Clear_Process
( m; `7 F" D4 G6 v- c - .IF Music_Clear_Addr. n! S5 e7 x! z& B' S+ k3 y
- JSR Music_Clear_Addr: P5 d% H, ^. |* w4 M
- RTS+ N/ e* o2 e: }. Y7 c8 X
- .ELSE
! U- `* d* V! @! D( G - LDA #$1F
! v) T1 B1 e2 O/ \ - STA $4015
9 l* P' }) W: T8 O7 B - LDA #$00
4 _8 Q) v8 z9 R6 s# i - STA $4010$ w |5 ~* K1 k) @$ U' I) c8 ?
- LDX #$00$ r+ H) j' d9 L" c. j
- LDA #$00' s4 E/ y; e5 }; E1 o/ `# k
-
; ? h* B8 s0 J: y. k3 F! W - .Music_Clear_Zreo_Page_0
9 ^/ L. j X: z! h - STA $00,X' A! K2 r1 `5 Q$ t# b5 S8 I
- INX
6 r+ ?& L3 G9 p3 J# e+ K - CPX #Use_Zero_Page_Begin0 \- z. ?* f; H; j( |
- BCC .Music_Clear_Zreo_Page_0" q% N( Q+ W6 |! t2 w# v) E6 V
-
$ k) L) F* ^" x2 ]- G w - LDX #Use_Zero_Page_Begin + Use_Zero_Page_Size
: x) o9 }7 {9 ^) U9 i - .Music_Clear_Zreo_Page_1
`' R. K( @+ S0 ^2 M8 X0 z) t - STA $00,X" y0 j* H: Y' u- a# e2 ]1 T. P
- INX
+ m6 S& J5 D- Q; ]6 B1 J - BNE .Music_Clear_Zreo_Page_1
" S; i) n" A" C9 ?2 r -
" J1 U) a4 Y) T. Q1 P) ` - Music_Clear_Process_17 z. n# w4 c, p
- STA $0600,X0 g6 L; Z( v7 x; C8 _" F
- STA $0700,X$ b; u1 n0 `7 ]: ~: U, b' j' j( |7 t% q
- INX6 _# Y b, J7 g, U- @# g+ C
- BNE Music_Clear_Process_1
# k5 ]( ]2 B9 g: Y6 x - LDA #$10* E; r9 F- T; R; y# u2 }
- STA $4000 {0 a5 v1 V! C2 |+ }
- STA $4004
P. O( k$ a) G# K; ~ - STA $400C
* }3 A2 U8 g1 x, x2 X H7 ` - LDA #$00# a" Q; b1 }8 B$ d6 O- k* P! I
- STA $4008! S) u7 X& R/ N2 ]
- LDA #$0F# q; ]# \1 ^- N& i0 a8 n0 ] C+ d
- STA $4015/ o& J# P# s6 ^. |1 Z9 A
- .ENDIF
W! s! T; x0 W, X* W' d, k% u -
?4 _! O! [1 g# | - RTS8 ?; \6 \/ `! K, E$ \& p% x
- 0 H- n2 M" D6 Z
- ;======================================================================( @0 e4 X D6 e+ [
- ;重启处理
1 S2 ]/ n- K; I8 W& n! ?$ s0 b7 I& S- M - Reset_Program
3 s* X. Z4 c8 t - SEI
3 n; _2 E1 P4 i) M - CLD
/ }! h7 c1 V" T) t& h - LDA #$00
0 m4 b3 a7 g8 Z. @& G7 N - STA PPU_CTRL
( y K) O# g( X6 w9 U* L* X8 f4 R - STA PPU_MASK
7 [) `6 K: ~; M/ K F - STA JOY2_FRAME0 j+ A% E+ d) f6 d
- STA APU_STATUS3 y9 ^; `4 `, r: h' a
- 8 I! Y& V) Y. m$ m0 V6 x
- ;等待屏幕准备完毕
6 e9 q& p; Q( S$ m6 U* O% w+ B - LDX #$027 b& ~8 I9 p3 ?4 G# M
- .Wait_For_Screen_Ready9 e6 Q; l. |4 C, _% b. L `# R
- LDA PPU_STATUS# N8 E0 }# R/ M% {; K) [, }
- BPL .Wait_For_Screen_Ready
& t8 h/ J; [; K - DEX
2 g+ U v* D {/ m3 i - BNE .Wait_For_Screen_Ready5 F7 ?. a% ]8 ]3 e: c) o; K
-
e' K* ?% k! Q9 v: y; ?# Z - ;清空调色板
3 n7 f& ?8 u- x$ a7 @ - Palette_Clear
2 [3 L/ R. k/ c: n- b+ S, B' ]2 O - LDA #$3F3 o7 C8 g8 [5 Q) w! t
- STA PPU_ADDRESS
$ q5 Q+ m5 ^- d( f* ]' {5 q - LDA #$00: ?2 q- ^3 h4 ^3 E
- STA PPU_ADDRESS
/ b0 E, N6 h' q& ]7 t* F - LDX #$208 t F9 |, {2 J7 u) W) [" ?2 `
- LDA #$0F
$ K" R2 w1 [0 `' v" _ - .Write_Data
/ e/ O' s$ B- r0 W. ~- N/ l9 q/ C R - STA PPU_DATA2 P" w8 D7 n( l3 m* M
- DEX
( M- Q# B+ R8 B+ `# } - BNE .Write_Data
# E' D! L* \8 w+ O; s - & q4 N0 l/ ^3 `8 o
- ;清除声音 $4000-4013
8 W, f: z; w5 M& k0 Y/ ? - LDY #$14; w6 X8 E' Z3 r8 l* y0 D
- LDX #$00
( V# z9 v/ r, R1 r) F: @ - .Sound_Clear
" g2 s3 I/ l' M" G1 s - STA $4000,X3 {+ ^5 d9 O( |: _; l
- INX
" J3 L; H* v+ P - DEY) [' S, N. S0 K) g
- BNE .Sound_Clear
" r" d2 A5 u4 R$ b% V/ A2 |5 h+ S, E1 g - ; q0 Z/ Z; d2 u0 @# V
- ;清除 RAM $0000-07FF# x+ k! U6 c, b' m
- LDA #$00: _6 f' X; R( n9 c; O3 b5 D
- STA $00) h3 K* ~: ?' C; E
- STA $01' A' n4 S) L0 U) ~" S* ]
- TAY4 G I* d. b$ u! ]/ A
- LDX #$08
" Q5 x% T2 n9 s7 E9 { - .Memory_Clear$ {. |! s% s ]3 C( V; P
- STA [$00],Y
I: d! `. g6 j4 o4 E% ^. L* o - INY% i; c( e' f+ K; @ i' N
- BNE .Memory_Clear
; Y7 a' G+ v' ~ - INC $013 ?& Q, b8 }/ r- z, h) T
- DEX
5 L2 y* ^& U4 M4 g! {% r$ D2 B - BNE .Memory_Clear
: Y+ J* U3 G& |) u- _2 U -
! H8 [: K$ p1 l' t - ;精灵缓冲初始化1 C, v& h7 @" |. l) P% D
- LDX #$00) g8 R5 D- a0 v, t! n
- LDA #$F8, F ^5 v& j9 s; x
- .OAM_Clear
4 E) T6 i* W; {$ F% Q9 m( h' \ - STA OAM_DMA_Buffer,X6 [) e& w# @2 F2 g
- INX1 b! v3 Y/ d/ H4 {% s4 ~# [9 n
- BNE .OAM_Clear, x# T# U- y; w7 R
-
4 e7 g. z, v" k' W3 N, x - ;栈指针初始化
4 j$ B* O0 H; P, M" ]. r. F - LDX #$FF
) c( `3 E7 Q1 S9 t" v p# r5 i+ R - TXS
8 |- b2 j7 u) t+ U0 i( u - 4 y4 ?7 D ]7 `4 w* [5 F5 S
- JSR Nametable_Clear;命名表清空5 `2 k5 s4 b& }! _ W7 g- j
- JSR Palette_Init;初始化调色板缓冲
6 j7 g# { s8 E7 I - JSR Static_Text_Init;初始化静态文本
# U; l9 {# _& T, n -
: h' C& N9 a( I( x) P* v" [9 C - LDA #MUSIC_ITEM_TOTAL - 1- ?* R( p4 E5 `2 R/ M" A! t2 ]# K
- STA FC_Music_Max_Index
( c5 o, P! \) ^; s2 b8 M4 n2 w! s" q7 u6 P - ( \3 ]% ?$ f+ h
- LDA #$1F
! L6 H4 [0 z& ], J' ` - STA APU_STATUS' Z3 h+ a& o- T4 X2 u7 A
- LDA #MUSIC_BGM - 1' f' X# W8 J- M8 B
- STA FC_Music_Index
5 F4 |; \* h, E | - JSR Music_Init_Process;音乐播放+ I2 D6 b6 f9 T& }
-
. z1 P6 Q" I* e8 e2 E - ;设置屏幕显示状态缓冲(当NMI处理时控制屏幕显示状态)
% ?. q- k8 o Z" l! ]; T - LDA #$1E
8 c) g' Q! C9 U4 V - STA FC_PPU_Mask_Buf
0 V! ]( J2 Y2 Z3 L/ V. B8 D - ! L) p" l5 a4 ~, M+ R
- ;启用NMI处理
) k& C& Y6 D! \ - LDA #$800 J8 N, q7 _' f- t
- STA PPU_CTRL. n' p3 h8 ] G; x' w
- / J g5 `7 I+ y j$ Q$ S" C, \
- ;程序循环, 剩余工作交给 NMI 中断处理$ }+ N" o* [& N
- .Loop; t- h' `/ W) i- k4 b7 A
- JMP .Loop
0 ^( Z% z% h8 v! V# J2 ?; }0 c
; w2 W7 G8 N2 h- ;======================================================================
7 `! L- @2 L: i - ;不可屏蔽中断处理: y$ J2 N" }% T0 j8 h6 I- q
- Nmi_Program' g( U+ O0 n0 L6 i8 D. A
- PHA
5 Z$ J) H- j7 b - TXA
/ X& ~8 l* x. n; f2 P' z4 [" P1 c1 n - PHA: G R& @5 l# W+ _$ c) K' Y
- TYA0 j0 J* t' v7 y( a! Y; O* p
- PHA
9 ^0 o# ]. O! i5 ~7 f+ q -
1 |- \5 _0 H. J - LDA PPU_STATUS;读取使得 PPU状态寄存器复位
( v! K, s3 ^1 A0 O3 Y4 Q& x8 h - + y! B J- c8 h$ e
- JSR FC_PPU_Procrss;PPU处理% v0 l. r R' p" `9 A3 `0 a
-
$ \: h2 [' F; O( l - ;精灵内存更新
0 }% i$ N1 F( k# O# a* B - LDA #$00' m# S- T, _! C' v$ e+ Y
- STA PPU_OAM_ADDR# C" P' `# q7 _' d, X" d" v
- LDA #OAM_DMA_Buffer / $0100
( O, b' {* P, A. x5 s - STA OAM_DMA5 Z, t1 H6 s$ \
- 9 u$ V5 M% \1 G2 g' i, d6 G
- JSR FC_Gamepad_Process;手柄输入处理8 e" l' z& B. d" C7 E, b; b9 @
- JSR Music_Select_Process;音乐选曲处理
9 w# b/ i7 D3 O+ [& e - JSR Music_Play_Process;音乐播放处理
1 J% S) c5 V. l. F0 O c, D; X4 [ -
5 m4 }( S3 z/ q7 @8 t - PLA1 T; G, [$ G" c/ H# ^$ b) _6 T# b
- TAY: h% B- r, U' L3 v
- PLA/ c4 a( W, l* K# g, K8 R
- TAX1 i7 ]; N* D# ^% b# }1 C; `/ N
- PLA B( e3 t) {+ ~" [
- ' `9 K$ o' ]% l1 h) }
- RTI
: a# M- r1 ?; D. I7 x K: J
0 e. i2 [1 M1 S. Y% B0 x- ;======================================================================
/ l; e' C( N* M0 c- l* q - ;请求中断处理& U( k" J& p, A* f% i
- Irq_Program
# U0 C' \, }( z3 Z - RTI( C' E* Q2 J( u3 d+ e
* M1 f2 S1 X' w+ k' v- ;======================================================================" V" P, O# H5 z5 \: s, y
- ;中断向量表
$ ~; b3 p& }$ ?3 d3 ~$ N5 e - .ORG $FFFA2 q: K4 y1 `! r9 ^$ L7 K7 [. U
- .DW Nmi_Program ;NMI触发时执行 `' O. Q, N( s
- .DW Reset_Program ;载入ROM时最先执行/ s" L- T4 ?0 b7 }
- .DW Irq_Program ;IRQ触发时执行
( \0 b, q2 I1 W6 t, Z
复制代码 - Q. Z, L2 t/ \- R* m+ {
+ I1 L; Z' ?8 D! n7 _. `
$ d8 H( M5 L0 F! ghttps://gitee.com/flame_cyclone/nesasm_3_2 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
评分
-
1
查看全部评分
-
|