|
- [code];[FC音乐][MMC3 IRQ]
/ i! @* W0 h! o' q - ;FlameCyclone 20230710/ G: q9 d6 K4 k0 `7 m" Z* ^# r
- % f2 M1 ~! D9 E! E! k! W( D9 R5 ]! ?: }
- ;文件头
, v n" T$ D: H( B% T - ;======================================================================
9 Y9 M3 S! `, e9 H0 v9 P8 t. b - .INESPRG 4 ;16KB PRG 数量/ t C. d7 z6 H. B3 x7 d! U
- .INESCHR 1 ;8KB CHR 数量 O5 E# y0 W+ y" s8 u
- .INESMAP 4 ;mapper 49 G* p! R. ~ w- y! v: X, ^- _2 P
- .INESMIR 1 ;命名表镜像 0水平 1垂直
, p/ |6 ~3 w' R
7 Z* e9 ^6 p' B, @5 R9 ]- ;必要条件# E9 K) X* Y i: Y' A/ k7 r+ Q
- ;1.持有CHR ROM
/ m# G# c/ t' c- V" ~1 J - ;2.背景Tile和精灵Tile必须使用不同的图案表, 如背景图案$0000, 精灵图案$1000/ L& d: V: j2 G) `5 Z
- ;3.精灵内存(OAM)不为空
( ~* J2 ^. _$ A# e3 \2 g
. `0 n( n' z2 e: e% u- ;==================================================
% N. G, c8 A- q - ;NES端口常量; ], m1 ~. w# @; k2 M7 t! }$ U% L) A: m
- PPU_CTRL = $2000 ;PPU控制寄存器
& ?9 P! a5 T- a, J- ^; V - PPU_MASK = $2001 ;PPU掩码寄存器
1 G! t7 w# `& A, E+ w3 |2 o - PPU_STATUS = $2002 ;PPU状态寄存器:读取后PPU_SCROLL和PPU_ADDRESS被复位,下一个写到PPU_SCROLL的数据是水平的,写到PPU_ADDRESS的数据是高位5 O# V1 J# G) I' K \( K
- PPU_OAM_ADDR = $2003 ;精灵RAM地址:用来设置通过PPU_OAM_DATA访问的256字节精灵RAM地址。每次访问PPU_OAM_DATA后该地址增加1
: v8 t7 C* A! |3 ]9 U; X' U - PPU_OAM_DATA = $2004 ;精灵RAM数据:用来读/写精灵内存。地址通过PPU_OAM_ADDR来设置,每次访问后地址增加11 l. D8 ~- I3 r* O
- PPU_SCROLL = $2005 ;屏幕滚动偏移:第一个写的值会进入垂直滚动寄存器(若>239,被忽略)。第二个值出现在水平滚动寄存器 3 k8 H' Q! C$ ~' @# b: {2 }
- PPU_ADDRESS = $2006 ;VRAM地址:设置PPU_DATA访问的VRAM地址。第一个写地址的高6位。第二个写低8位。每次访问PPU_DATA后地址增加
& Y. n+ h3 B; s* O# }, l9 H$ Z; H+ c - PPU_DATA = $2007 ;VRAM数据:用来访问VRAM数据,通过PPU_ADDRESS设置的地址在每次访问之后会增加1或32 - A' G \- e+ t0 s( x% ~) q
- OAM_DMA = $4014 ;DMA访问精灵RAM:通过写一个值xx到这个端口,引起CPU内存地址为$xx00-$xxFF的区域传送到精灵内存5 k5 c+ {0 ?7 k" C* y& c3 K
- APU_STATUS = $4015 ;声音通道切换2 w% s5 L2 P( @* O6 ~" z$ Y( H
- JOY1_FRAME = $4016 ;手柄1 + 选通! n2 `, s2 \; h7 h" r
- JOY2_FRAME = $4017 ;手柄2 + 选通
I$ @( }" x8 P8 u( b
3 \# w/ ?2 o" q a8 J% l- ;==================================================) |" n7 ?9 k) J9 c' G
- ;MMC3端口常量
9 S, |1 V8 d+ i; V, b - MMC3_BANK_CTRL = $8000, H* R! W* p8 }8 z6 l3 ?5 P( ]
- MMC3_BANK_DATA = $80016 ~3 N& U3 E) N6 z' d
- MMC3_MIRRORING = $A000
) J1 h$ g9 N5 ~2 A3 O- q% U l% { - MMC3_PRG_RAM_PROTECT = $A001
9 W- ]% C; ^* z: ]5 F2 s A. H9 G - MMC3_IRQ_LATCH = $C000, l; J* z5 D! K* [$ N4 o$ J
- MMC3_IRQ_RELOAD = $C001% f$ }1 y& V! U& n" i
- MMC3_IRQ_DISABLE = $E000# V. U' q. c. L( B9 _
- MMC3_IRQ_ENABLE = $E001
6 v! ?) v( C7 F; h1 M4 q
' s/ A. Q) }# X& [+ V; w* d Z; R- ;==================================================
9 A' n( s' e: a: M! J' f - ;程序块配置3 c o; q# `; Z* s! ~$ g9 [ H
- BANK_DATA_MASK = $07) y) w% m. f% B0 j i% v
- ;--------------------------------------------------
( H0 Q* e6 T9 n6 B2 b - RESET_BANK = $07
4 T7 x' j* S( }3 ?' P* g - RESET_ADDR = $FC00
) i$ l: [! V) S& J - 2 [* X6 ^. L! e
- ;==================================================* z: r- q& F" |5 H; I! c
- ;图像块配置
% n* M0 l1 u/ `$ [ - CHR_DATA_BANK = $08
+ J3 i) z' b0 e7 k6 ]1 E1 w4 M, P, b - / x) n2 S8 q% A% ]$ y" L" [( K0 l$ j
- ;==================================================
# V, ^' |% `4 Q+ Z) K - ;零页内存地址配置6 }) m" E$ B* e. V4 S/ e
- Use_Ram_Addr = $80: Q! k1 N% T. {: h' n
- PPU_Ctrl_Buf = Use_Ram_Addr: A# \) a3 ^. E; H) Y+ |2 q
- PPU_Msak_Buf = PPU_Ctrl_Buf + $01) f# S9 {# I$ S! r, ?1 l4 m
- PPU_Scroll_H = PPU_Msak_Buf + $01" S- B! E( u2 {5 ~/ d: [6 h
- PPU_Scroll_V = PPU_Scroll_H + $01
; L2 I8 c ], {0 v - FC_Data_L = PPU_Scroll_V + $01
6 a1 q3 \ A# |0 Z - FC_Data_H = FC_Data_L + $01) h7 }( g. H+ E2 p9 ^" K, H# ~
- FC_Data_Buf = FC_Data_H + $01
$ g& v9 j2 O- `. I - ;==================================================
" h% g) p, a0 s, \$ H X - , n9 D0 ^8 x$ N: d: h
- GAMEPAD_MERGE_FLAG = $04! @3 T" ~' Z* u) e3 R9 `5 L8 D
$ v: A1 c+ q: J- Gamepad_Keep = FC_Data_Buf + 1 ^3 j0 r0 p# d9 Z9 }5 V; A
- Gamepad_Once = Gamepad_Keep + 2
/ c( @' J+ Z1 L) p0 U - Gamepad_Temp = Gamepad_Once + 2( g6 D' A8 B2 _$ M) Y
-
' o) U4 x# d! s - Gamepad_0_State = Gamepad_Temp + 2
( f! ?; V1 [! B8 C$ o- J6 F, b - Gamepad_1_State = Gamepad_0_State + 14 @$ Q- H+ I" J6 | P) K0 b
- Gamepad_0_Value = Gamepad_1_State + 1. \+ s5 J! L- s2 Y5 ^7 u
- Gamepad_1_Value = Gamepad_0_Value + 1$ v$ W5 B1 q Y8 |
- Gamepad_Port_Value = Gamepad_1_Value + 1$ k& K. p5 L8 d, s0 s
- Gamepad_Merge = Gamepad_Port_Value + 1
$ W9 N; P: y$ D8 J/ R: [ - 4 T& P; p. N2 n9 p
- ;==================================================
|5 S4 ]2 a6 ?( N, s) X - IRQ_Index = Gamepad_Merge + $01
0 ]( y2 M, H: v - ;==================================================
r$ b" ^9 m. x. Y - 0 n8 F1 k3 b: F# [1 E
- ;CHR图形数据( W& k& X$ n' H+ V# }+ e
- ;==================================================2 M" O! [/ [: b% K
- .BANK CHR_DATA_BANK4 D' k5 W) n) G3 `" [6 V4 {5 T
- .INCBIN "chr_bank/chr_data.chr"
" K- f+ L3 z) k6 B0 h -
* M. x4 l4 k3 U' ~8 i - .BANK RESET_BANK & BANK_DATA_MASK( C' T7 _+ D% C' a) z6 y" Z" E
- .ORG RESET_ADDR' s1 w7 g& S& m
-
. [, }" t4 \& |& z5 |/ l6 ^! j - ;--------------------------------------------------2 }3 Z$ f9 \0 l! ~! q% {
- Attributes_Data# l/ t9 `; b- E; v7 n) u8 w
- ;命名表属性' G# D8 v7 R% H' U0 K8 D2 b
- .DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
1 k: E1 X$ o* C7 R - .DB $50,$50,$50,$50,$50,$50,$50,$50,$FF,$FF,$FF,$FF,$BB,$AA,$AA,$AA
3 B$ `# K5 l: Y6 P7 Z% ? - .DB $0F,$0F,$0F,$0F,$0B,$0A,$0A,$0A,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA! @' A! ]* a3 \6 |9 U
- .DB $AA,$AA,$AA,$AA,$AA,$AA,$AA,$55,$55,$55,$55,$55,$55,$55,$55,$55
" }( v! v7 m" ~+ u: _: k' A X - ;--------------------------------------------------
+ g- O! [3 N+ n3 a$ m - ;调色板数据
3 A" ~) N b: ~* U- b% H - Palette_Data# h2 [* A2 U8 K9 J8 ]
- .DB $0F,$27,$20,$0F,$0F,$24,$20,$0F,$0F,$21,$20,$0F,$0F,$25,$20,$0F$ O3 l. g5 b6 Q* U+ H1 ~
- .DB $0F,$24,$20,$0F,$0F,$24,$20,$0F,$0F,$24,$20,$0F,$0F,$24,$20,$0F
7 ~; x) M2 P/ h& w
' ]3 I) E" f6 E( o- ;==================================================4 Q. M2 K1 L2 |6 T9 ^
- ;命名表初始化
" Q I& S& R4 ]4 V7 ?( u - Init_Name_Table: R5 i" F8 A1 Q: X/ q
- LDA #$20
4 _% \( e- F; k5 J5 H/ B - STA PPU_ADDRESS! B7 S0 p: P: ]2 k
- LDA #$00# |% P6 _8 D. B2 O x
- STA PPU_ADDRESS
- O, A1 X& g2 S% H* Q% Y5 u - LDA #$00
' j% Y8 i' c; N& [' K# N - LDY #$00
! W, |3 F3 S6 J- w6 ^ - LDX #$10
6 B# s8 j' n6 l1 Y - Init_Name_Table_Write
& p8 R$ e7 L% l+ U6 J6 M6 x5 M# x) X4 O - STA PPU_DATA/ Q0 Q2 s+ @0 t/ b
- INY; }9 d, {4 [, F# S/ Y- g! h
- BNE Init_Name_Table_Write+ O& e& H* o, u X
- DEX
3 Z5 _/ g/ R4 r% w4 k$ J. E& q - BNE Init_Name_Table_Write& `" V( j! c/ D8 L5 a0 p
- RTS
* s( p8 j! n0 m0 P5 K* _2 K) z -
9 h, ?9 d! {' f) x - ;==================================================) V$ i9 j7 T( k
- ;调色板初始化
2 O' W+ C! O2 I9 z Z - Init_Palette, L( f' b1 U2 a
- BIT PPU_STATUS
, [2 a7 @1 t8 a6 k1 i( E - LDA #$3F
# n+ I' X0 u. j2 Y( N" A- C - STA PPU_ADDRESS$ |# L# k" a* b& Z& g) n9 c
- LDA #$00
( v" _8 I+ c) y0 C - STA PPU_ADDRESS$ C9 s5 H1 ?4 ?- @+ ~
- LDX #$001 J/ w4 }$ @& S. r" }, M; K
- Init_Palette_Write* d4 ]4 W' T6 e
- LDA Palette_Data,X, C$ h8 P9 w; f+ Q
- STA PPU_DATA
) b( A3 T; W4 V( }2 r# N, E- G M+ H - INX
! ]: G) ]$ b3 b+ I) r4 T0 x# w - CPX #$20
* j6 n' s; ?5 N8 N4 M - BCC Init_Palette_Write; r* w% h0 P+ }' D
- RTS# W" R- H! E) L: \# d
- 8 Y9 F) [* z- @, a& F% ]
- ;==================================================
9 b* X" O. I- i0 F - ;设置命名表属性
, J* v8 e2 s9 x8 R* W - Init_NameTable_Attributes; ~* ]; j3 z3 A" R. Y3 v
- BIT PPU_STATUS
/ ?7 ]7 c' U4 `* S6 p6 j1 w - LDA #$23 t0 S# K r% n& R3 H% @
- STA PPU_ADDRESS
" u$ z0 n# Q: F9 ]4 N - LDA #$C0% V U8 f4 T9 P% X
- STA PPU_ADDRESS
/ H: o5 u6 g- A( z8 S - LDX #$00
4 B! M0 ]; C: p$ H( A6 d) q - Init_NameTable_Attributes_Write7 b! T3 q& e* A( r3 ~6 `& w& {- X4 F5 l
- LDA Attributes_Data,X$ e9 `( J8 R+ K" I- a
- STA PPU_DATA
( c, ~! a5 I, D! C - INX
) _; H* z- q7 K @ - CPX #$40! [, h/ B% ~. P# h- @1 g3 N
- BCC Init_NameTable_Attributes_Write
1 V5 b% `, H0 J8 [ - RTS0 J2 V+ Z! n$ f* K, K
- % h6 @3 V, p9 o- J& I1 p4 L
- ;==================================================% I* @: b3 m; v1 y/ U' b
- ;初始化命名表文本* t/ B1 m' O' j" h
- Init_Name_Table_Text" a: `/ [. u7 J! a( r# U3 F
- BIT PPU_STATUS
D' u+ h; b( t7 R4 h - LDA #$208 V+ n, S1 x% @
- STA PPU_ADDRESS8 X' M2 s5 F$ T' P. l3 j: `5 H
- LDA #$00
8 M: u9 A2 q/ u1 E8 U, s2 E - STA PPU_ADDRESS3 Y8 Y7 S1 o& u1 f
- LDA #$00
9 o3 ^8 B% d9 _6 M7 K' U" n: r - STA FC_Data_Buf0 M4 W- R2 l4 S m7 v& D8 D4 m6 v
- LDY #309 x; Z# c: s0 l( L6 `$ t
- Init_Name_Table_Text_Write$ f. s$ _) `! O
- LDX #32% _5 z0 D* Z& I: {* z
- Init_Name_Table_Text_Write_Char
8 ^5 C! S" u' n1 ] - LDA #'0'$ H/ J4 |" ]8 z' i
- CLC
* B. A8 O& |# Z! Q( ` - ADC FC_Data_Buf
0 _+ ~( Q$ ?+ m( h; D - STA PPU_DATA
$ c4 e2 y& S ^ - DEX+ k7 ^7 Q1 B' u- \2 g
- LDA #$14& Y$ \/ Z: F, o6 o
- STA PPU_DATA+ E+ B- ^ ^: T
- DEX' P& i9 z8 V' `# j$ S
- BNE Init_Name_Table_Text_Write_Char
6 }. r+ R, t1 t M6 b - INC FC_Data_Buf8 L! P3 `! I+ n5 P7 P5 F
- DEY4 U: c" x1 Q7 \% y- l: {5 S
- BNE Init_Name_Table_Text_Write: K! ]' e4 k R! _7 W
- RTS
: n* H( ^4 k( ?. E- F. Y - o: I4 s5 N/ R' R
- ;==============================
1 Y% O( V+ ~: X( U - Init_OAM_Ram;初始化精灵内存( j" }; X* x3 f- C& U
- LDX #$002 X; W4 b/ @: N3 v
- LDA #$00
. l: o) g- X% ~2 n! S; f - STA PPU_OAM_ADDR: C! C. i5 x, y2 J; ?( ], Z
- LDA #$F85 I0 _8 Z: {: w8 W4 G/ ?# Q/ |1 J
- Init_OAM_Ram_Write; @ K K+ j# z
- STA PPU_OAM_DATA
+ m; T5 L1 @) L% p/ u7 A* c4 L - INX: V1 H( b5 A: r8 M3 y
- BNE Init_OAM_Ram_Write$ f. X6 s- X4 D& T; @6 N
- RTS6 T9 n/ ], F. O1 q: K" c
- ( d& j( w: w' r* x" K. l/ O
- GamepadProcess;手柄处理0 V6 G* x( k% A: \" ?9 v2 C k' [
- JSR GamepadDatacan
% L1 w5 ?' P* m. ^$ ]% _% g- W& b - LDA <Gamepad_0_Value8 t i3 q- T$ w- Z' f6 f
- STA <Gamepad_0_State! h, l( A2 H a
- LDA <Gamepad_1_Value
4 a1 p; q$ |) Y' Y6 K- f$ j - STA <Gamepad_1_State
6 n# W1 y; N$ q( ~+ ` x5 ` - JSR GamepadDatacan; s9 F3 `& H; ]; {8 f+ x
- LDX #$01. R, g; j4 n1 c) }2 K
- GamepadMergeCheck;合并手柄输入检查
0 A9 t6 {0 T& f7 }+ x) o+ M - LDA <Gamepad_0_Value,X
; z( {# E1 e" ^2 B- z) e" _' M - CMP <Gamepad_0_State,X
9 F# E$ d7 J" `8 u$ w: q$ X - BEQ GamepadMergeInput
! K8 h; O# K- {( A. @ - LDA <Gamepad_Temp,X6 \$ j( b' w& v& W
- STA <Gamepad_0_Value,X
6 O: z0 L% w: h3 s3 p) M. U - GamepadMergeInput;合并手柄输入- C4 u' g; ?& a, w
- DEX
& A# t) R4 |2 [6 l* L5 V& H - BPL GamepadMergeCheck
9 v2 p9 z. i1 e8 z! r/ E: ]" X# N - LDA <Gamepad_Merge- N, R/ c* }* g, }4 l
- AND #GAMEPAD_MERGE_FLAG
5 b" k5 L4 H8 l - BNE GamepadStateProcess
, d7 ?/ C) P( v; O. ?" i$ Z" ^ - LDA <Gamepad_0_Value% U/ M' K5 d V) b W
- ORA <Gamepad_1_Value, j4 Y) r: I; I; I' I: a
- STA <Gamepad_0_Value$ J( j7 p$ T8 B, k9 r' [7 T' _
- GamepadStateProcess;手柄状态处理
* u3 A; `0 Y, L5 [) {1 R* f - LDX #$01
" X4 I9 Q# E4 ^) m: C- g - GamepadStateSave;手柄状态保存
9 ^" l. k% C( x - LDA <Gamepad_0_Value,X
* ~3 F2 N3 ? q! z- @) S3 o3 j - TAY$ e4 X# E( s/ F8 h! Q& D
- EOR <Gamepad_Temp,X" a+ X7 h; `5 R0 q, w1 \* {
- AND <Gamepad_0_Value,X
7 i$ V5 I6 A. w. Y: @- S6 G+ E - STA <Gamepad_Once,X
9 _ `0 U( V. _' c7 Z6 y - STY <Gamepad_Keep,X7 \5 E' _4 B% t7 X7 h5 h$ o
- STY <Gamepad_Temp,X
3 B9 N9 a2 L. Q' i6 q1 P - DEX( z l6 S z' Y" [6 y7 B z
- BPL GamepadStateSave6 S' L. ?. D E/ y+ |
- RTS
- Y2 V2 f. ]; D& ^7 o/ t7 }
" ]) y. t6 `4 O! Q2 C$ C! I- O- GamepadDatacan;手柄数据扫描9 A _0 P% J( N
- LDX #$01
+ }4 v6 q% O) Q7 @6 L - STX $4016; L8 x& W) ?; X# z( t( i2 w3 D' W( W
- DEX
2 }/ L6 A9 r0 c, t - STX $40160 c# s% n8 w: H4 u2 r0 i! v& \5 z
- LDY #$08) N' A5 w7 I$ U3 u$ U8 J( @
- GamepadPortScan;手柄端口扫描
0 N* @3 b+ F6 y; J. ] - LDA $4016* L7 i& o& Z8 [8 }5 i
- STA <Gamepad_Port_Value8 f+ G6 O* K/ }$ K6 b
- LSR A
$ _ l+ U2 T$ C7 Y - ORA <Gamepad_Port_Value
; x- w7 C! W5 k) r$ C7 V9 v0 A3 V - LSR A: [$ r" @7 m. N' L7 i
- ROL <Gamepad_0_Value* u2 e9 A- c/ R) b0 V- F: n
- LDA $4017! h |7 d- O' q1 |9 U5 e) k1 d
- STA <Gamepad_Port_Value3 V# x6 A, o5 R- Q7 ~9 t$ a
- LSR A
7 r: E9 L" U& u4 b, d - ORA <Gamepad_Port_Value* Z" `/ e5 N ]0 A9 ?- D
- LSR A3 N& }+ Q& p: j/ u, R% E$ ]3 W
- ROL <Gamepad_1_Value6 z& @3 J0 ?7 \7 I! E4 N
- DEY
4 |% n ?7 @& Q ^ - BNE GamepadPortScan0 X- G( [1 |1 S, |& t' d
- RTS
P6 ?( K; P, c( r6 e4 g2 c" H! Q -
% b& _: ]9 x- j$ I - ;==================================================
9 z( ?- m! P8 ^; K. d4 {2 } - ;PPU处理
( M5 M; f0 f- Q - PPU_Process
+ }4 L2 a: `1 x& T6 k - LDA #$00. V3 j$ A0 r6 I; ^
- STA PPU_MASK+ |1 m+ Q, r* i3 t7 O# o$ l& S/ f X
-
1 a, v6 l o( g0 d - BIT PPU_STATUS4 J4 N3 _3 X$ ~; i0 z, D
- LDA #$202 d R$ v3 u9 `8 e! B4 Q
- STA PPU_ADDRESS
* ^( Q% h* A; r- q - LDA #$00+ X) o5 }, k# r' A% j' u& \
- STA PPU_ADDRESS; c% {5 k, B3 K. v* Y7 ]! ]
- & ~5 h3 L5 h& c! f; ?" y) P. T* _
- STA PPU_SCROLL
' |$ b- K y# X. Y0 t, i - STA PPU_SCROLL
* ~8 n7 M5 {4 F9 g - t3 V! |' b. e1 ?; v. T3 V( i P
- LDA PPU_Msak_Buf( A9 W2 X/ y; M
- STA PPU_MASK5 \ M# x6 u2 K. L
9 `/ L$ ^# |2 {5 M$ g- RTS( L8 A% Z Z7 V' ~6 W/ ]
- 3 P; e' K/ ~0 B+ k, ?
- ;==============================
# A7 I5 Y5 I' B9 L4 v* K) } - Time_For_Vblank;延时等待
% W, m2 ^ Q& P: | - LDA PPU_STATUS1 |& r# t0 K/ r# \8 I4 [
- BPL Time_For_Vblank
. G% n l9 h' i# c/ b# v - RTS2 S$ X8 I8 @/ t" Z* ~ y
-
1 ], E1 o: O3 j' ?* N* L* n - ;==================================================" f! q" V9 ^6 V/ @7 Q/ q+ N
- ;初始化MMC3
, v: c2 ]3 z% q9 { - Init_MMC3
! Q5 {8 I# D/ `) ?. ~- I/ c - STA MMC3_IRQ_DISABLE
. i6 V3 v: _& D1 p6 \2 R: @) @ - ' N7 {" R% E: G/ J- \- I
- ;设置MMC3水平镜像
3 b6 k) z. V) P# n' x- H2 o) O - LDA #$01
2 ^8 D9 d" y, [ - STA MMC3_MIRRORING
+ Z+ U, Q$ k/ G+ h5 W# G1 G! U -
* z0 \" j2 n/ A7 c* z - LDX #$05
8 ]* Z" l, s" W( C8 e( R - Init_MMC3_Chr_Bank_Write
6 S7 _# i0 W+ N' u, o6 b8 P - STX MMC3_BANK_CTRL" d, d! r5 I6 i: O% e' u0 s' O5 f( n; U
- LDA MMC3_Chr_Bank_Data,X
/ G `4 M, d9 y: |% U0 d9 J - STA MMC3_BANK_DATA
" }+ h- Y/ o: s* K7 _ - DEX
" }1 s3 w, E. b) b$ B - BPL Init_MMC3_Chr_Bank_Write
- _9 l" V$ j: _6 E' X - RTS1 K7 T3 a, g# \- i
- ;--------------------------------------------------5 V8 R. e( {6 l. L6 A @
- MMC3_Chr_Bank_Data4 f) Y) J/ X" y- Q- B7 P
- .DB $00,$02,$04,$05,$06,$07' b) D% a+ M# l
) B. Z" Q0 u% }0 d- ;==================================================
, c& d) s/ a& y1 Z! M7 i. l - ;重置中断处理
' M' k/ j0 z7 _( z - ResetProgram2 h" m0 x% H5 [* k
- SEI
% V- ]8 Z. O- R6 _3 C - CLD5 ?9 p' _: f7 ^2 h3 H
- LDA #$00& K6 H5 m v( F- Y. A# Q: N0 a+ F# y& k
- STA PPU_CTRL
& I$ j, p' c8 I$ s - STA PPU_MASK: r, g5 V p- Z; @
- STA PPU_STATUS
) L h, A+ ?1 r) l0 W F! y- n5 C - STA JOY2_FRAME
R- g2 J) z8 |. z - STA APU_STATUS
. L8 a ?1 a/ E -
( ~4 n5 d; ]* h4 ]0 L - LDA #$C0% a8 i- _' D, q) D
- STA JOY2_FRAME d( }* |' ^! u+ x
-
+ O( j3 b1 I0 |; F) ]& K5 D - ;等待vblank
4 A0 m, Z9 N) j1 v( c8 w - LDX #$02
! `# p' Y- `! p; d$ ] - Vblank_Wait_1
" V# t6 I: y3 p/ @! t - BIT PPU_STATUS
% ~& r- m8 L. i - BPL Vblank_Wait_1
" V( }3 z9 S2 E; k7 K - Vblank_Wait_2
) ~; B0 s& j4 ?/ ] - BIT PPU_STATUS) |7 H e x0 H( B8 N% B1 j" [- B
- BMI Vblank_Wait_2" i$ J( |" u" z, ]3 n
- DEX$ T" Y7 Q' v8 }- D2 A! x2 `
- BNE Vblank_Wait_1
1 w8 h( u/ q0 j- O9 y2 U* B -
- H8 p# v; r& J7 X - LDX #$FF5 t% P& v, v x/ L# \2 M
- TXS
7 P" {, K4 S: O - . W7 ?9 u* c7 X1 g) ~# c
- ;初始化MMC3
' r" A& Y: ~7 Q - JSR Init_MMC38 Y, F( J5 P0 [( m! ~
-
; P* e$ z5 U# b4 u- Z& l - ;==============================
8 ?7 g/ D2 `( _ - ;RAM初始化* g" B9 J/ u" a) Z! ^) I
- Nes_Ram_Init# ]* G0 _, ^! g
- LDY #$00/ C) a, E9 L: R6 N8 U3 Y* b
- LDX #$08
" k z& R/ t" ~) E: j- | - LDA #$00: m. T/ n" y* g! G& ~( ~
- STA <$000 r z8 k* x. B1 u6 [( X
- STA <$01
! H% f4 B9 h: W3 r5 Z - Nes_Ram_Init_Write q7 \: I' s) Q! o$ M
- STA [$00],Y4 n/ ~6 h5 T$ Z4 {
- INY
, }# I0 s) b) E) h- R; c - BNE Nes_Ram_Init_Write
- U' J5 T7 p' M) `+ ^; [ - INC <$01
& w6 p: p7 j4 \- Q& K - DEX
+ K( u9 i: R: y) X, e6 l% z - BNE Nes_Ram_Init_Write
, K! m: E! E* i) r" N - & C% x! E* s! q a4 F
- ;初始化命名表
$ }3 A9 A% o$ f' o) |; A - JSR Init_Name_Table
1 ^ a& k+ ]* g) m -
$ W8 a( n7 Y; {3 i- A$ W4 I - ;初始化调色板
+ R# i& D3 m# X, \- b5 [) B - JSR Init_Palette( h( Z7 l/ a& m6 B7 n: O+ T
- & @2 b; r5 J' T, d# I$ [# g5 F
- ;初始化命名表属性1 p7 T% K' H; V. v6 e$ ?! P
- JSR Init_NameTable_Attributes) F" S' [" Z6 x" f
-
: g$ G8 t1 F O N - ;初始化精灵内存4 S* F& k/ d% [/ y" _7 i7 Q4 P
- JSR Init_OAM_Ram/ O9 b6 ^' _% d* |7 C
-
" h9 V' v3 p/ g6 E( \ - ;在屏幕上写点东西
5 y U$ W2 q m4 e6 _, w0 |! k - JSR Init_Name_Table_Text
5 Q, P& f D A( h1 s; k - . w* p* M' L; u3 e& {
- JSR Time_For_Vblank
+ h! n( m1 H7 B( d - ;开启PPU控制2 B6 b C( ~2 O7 L2 e
- LDA #$A8
: K. k8 j; `, ~ v+ F - STA PPU_Ctrl_Buf! A* m$ E* {# ~ |) ^& c
- STA PPU_CTRL3 j6 W1 E. f8 [1 `; o0 @
-
: P: Y1 ~, C% | - ;开启PPU显示+ ~: ]! ^' K) ^
- LDA #$1E. O& `( T2 s1 b3 N4 p: F# |$ A
- STA PPU_Msak_Buf
. L4 T) l% U$ [' a - ( O3 A/ H V, K& |( M* c
- CLI
\1 [6 p' K5 p - JMP Loop# v- C7 `: |% o) ~- V
-
/ w8 D" D0 G& F7 U! k3 b - ;==============================
! V0 Q( q- u2 n$ K9 n - ;死循环, 等待NMI中断
7 c" h/ `5 R+ S; W - Loop2 f5 E' n, g4 L) {
- JMP Loop
; F# J: f1 c0 R1 l! _: F* Z0 N+ c
/ M8 o ?4 W4 J/ T- ;==================================================
7 L& c" N- F% W+ [; m! l( M# E - ;NMI中断处理
7 r2 P7 E; G/ h" K, l, Q - NmiProgram
; A+ G; E$ U7 F' q; m9 f2 B - PHA3 ^* q2 {0 W* E$ V3 I
- TXA/ `0 N; Q! _* v5 n4 a
- PHA
r" ^2 s% Q5 K) \8 h3 v - TYA
, y9 K" ?& p Y - PHA
' R/ R2 X; x' y9 F- R6 l7 E -
, n9 n, }& {8 s- t. {$ K/ J - BIT PPU_STATUS( F1 U0 ]" w$ N! h: M$ I/ q
-
& X7 ^8 d$ e" W4 k. V/ q) U S5 T - ;关闭PPU控制
3 u# O9 K( }( f8 N9 R - LDA #$00
, G' M8 n0 S/ \% } - STA PPU_CTRL1 Y# [ A8 S3 s% b+ M/ m5 K! U2 K$ R
-
8 Y6 O/ [6 H& k" E5 l& }9 r8 E - ;处理PPU' I2 N7 y" ?! w
- JSR PPU_Process
% ?+ Y' `! N; g9 [2 \6 j -
, [$ O% W# k% F1 m$ i6 V - ;开启PPU控制, Y. l, z7 _4 ^2 T# {8 ^
- LDA PPU_Ctrl_Buf
& l" ]- r( t- @; |& d/ b - STA PPU_CTRL ^! `5 |- u) e1 v5 [
-
1 G' D; {9 V3 y: H/ I - ;手柄处理
8 @$ |( H8 w1 _5 T9 U1 b5 t2 }9 { - JSR GamepadProcess- Z7 Q6 C6 R$ L$ L8 M" N/ U; o1 P
- . k3 T1 _5 ~. B
- LDA #$00
& m, W; N/ y; _" D7 w% Y0 M7 T; H7 N - STA IRQ_Index$ J+ B3 _7 I" E0 \7 V! _) E( ]9 B
-
, |& m/ _: [9 Z/ \! T2 M) [ - ;启动IRQ中断, 第15条扫描线触发) {, @% B" h% u |
- LDA #15 + 1( Q/ D' V0 f# ~; l$ |# _1 F
- STA MMC3_IRQ_LATCH
* h5 j! C9 O" R5 \4 Q; _ - STA MMC3_IRQ_RELOAD
4 M0 C5 Z/ B9 o - STA MMC3_IRQ_ENABLE
6 y' A2 m! G6 O: d6 ^ - CLI
7 O8 R1 J* Z+ T4 X. T" a: r -
; Y7 P; ~# \3 z7 a- q - PLA: F# l( U# |# u; e! z# K# f
- TAY" F# L6 l0 z* o# ]* E
- PLA R! b `" j8 F) R8 G9 I
- TAX6 _3 S0 T7 H6 \/ u
- PLA8 T8 F \8 @7 Q: W/ K
- RTI
; F; l' I2 ~+ W5 U1 j# ~* D" K - : h' s: Y7 F( y& E- O4 ]) Y( a
- ;==================================================2 J/ M, ] G, e3 k8 K
- ;IRQ中断处理
+ \/ T% R& q: w' i* ~- J. W - IrqProgram& Y7 A7 l' ?1 }/ u" z7 i
- PHA
& _+ ?2 D. \+ d& ], W" T" O - TXA
2 Z3 Q/ c6 O- @) u4 y - PHA, C+ }- p6 S8 y6 a. B+ S, M) ?( {7 T" p
- TYA. }2 |: E3 {" S6 u7 w
- PHA$ q" M) |% u6 S
-
% I; m. n5 ]2 K - ;关闭IRQ3 H/ v4 |8 G* p) L% L) X
- STA MMC3_IRQ_DISABLE
+ M9 l e) z% X% v -
* q; @9 y* _8 Z+ F. F* }$ x5 e$ | - ;允许下个IRQ触发# i: [. k- C5 z7 x" q
- STA MMC3_IRQ_ENABLE7 h% J* G8 J* B1 ~1 ]7 s% Q2 d8 A
- ' V; y( r2 z* M' f, ]3 T" S; m
- ;IRQ处理, 15线后继续触发# @5 B0 c0 j6 b& i( W$ ^' [4 I- R
- LDA #15+ i: r0 t$ S$ }* i$ K# M9 W
- STA MMC3_IRQ_LATCH; q1 l1 v2 q2 L- U& E& w; U- |" P
-
[% G' O5 z$ Y3 ]- o - LDA <IRQ_Index6 [: h5 ?+ k J1 P
- BNE * + 4
, [+ F' c2 L$ I: y' F - INC <PPU_Scroll_H2 v2 l3 C# X* v% E1 y
-
# B" e* E' G o7 S1 J+ \. U5 ? - ;设置屏幕滚动- r3 }* d9 ~4 A
- LDA <IRQ_Index$ S9 F/ `0 H U4 _# T' e
- AND #$01" b6 K V8 ^9 r9 ^' {
- BEQ Irq_Scroll_Right
, I) c8 Q2 E; I+ k) ^; `6 d
/ ]& p! s o" ]$ t" Z2 ~- Irq_Scroll_Left: k1 g' _0 U+ f+ r6 g# L3 U4 O# W3 K
- BIT PPU_STATUS
0 l+ w8 T3 |4 [4 a - LDA <PPU_Scroll_H' i+ P7 O) @2 H3 \, U% Q
- STA PPU_SCROLL& `/ E1 y# u1 p4 H5 Z% K% \
- STA PPU_SCROLL
/ D. j1 G' _+ n |$ z, O - JMP Irq_Scroll_Over# j' y& A) N5 |4 z, Z* _, v( P! m
- ' Q9 [1 F7 x4 r) f5 G0 J
- Irq_Scroll_Right8 D" g7 j9 k# K% D# k& Z
- SEC
( c b# V5 J0 Z" s. V9 r) ?4 U - SBC <PPU_Scroll_H
% `( n$ e5 l2 G* U- X9 `" b# _ - STA PPU_SCROLL5 R3 | U Z: ? C! P; ]# T
- STA PPU_SCROLL
9 w6 ^* W+ o0 J- g* M2 i6 r - Irq_Scroll_Over, q6 W4 s4 j" [% Z: k
-
" W: n: r9 ^6 w% q4 o - INC <IRQ_Index
: S1 d3 i I/ q - 1 N5 g8 p. ^2 ~
- LDA <IRQ_Index. y% M/ ~# e: y4 B( s. T
- CMP #14- c( w/ E# X+ `( \, J& \
- BCC * + 51 |; Z4 j9 a8 Q0 ~6 @$ w9 X
- ;关闭IRQ
+ p) n& |! o1 L - STA MMC3_IRQ_DISABLE
0 y4 _8 S( S4 M/ i -
: p4 @# G& O1 h4 t$ F9 G, r4 a - IrqProgramEnd3 c# t j( h+ l7 p: L; W) i
- PLA
# B! Q: E% a+ Z0 b - TAY
' N9 k" ~/ A4 D+ |1 B$ F. |8 H - PLA3 M$ \, T7 t" s9 l+ _- p& w4 l) m4 E9 j
- TAX
' S) B7 N0 ?, L5 D, a5 v5 |& P - PLA# W5 q9 }$ m/ j7 D" H3 }. m
- RTI5 ~9 P- s9 w* B
- # x1 m n. ]" b, Q2 p: m- f
- ;==================================================, Z# @/ e/ j5 Y, K, S! g, `
- ;中断表! l' V% p; Z. e* Q( l3 q6 T; [) n H& G9 V
- .ORG $FFFA! g4 \5 V" W0 P5 G7 P4 t
- .WORD NmiProgram
! s' `# R3 ?( g( l - .WORD ResetProgram
o5 F% f' y* V5 r9 r - .WORD IrqProgram
复制代码 [/code]
( V, c1 P# h& G" `7 B |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|