|
- ;[FC][MMC3 精灵碰撞]
0 h4 w! v& t8 d' \1 Q5 ^5 [- Z - ;FlameCyclone 202307101 e1 f5 ` @* G6 J2 i) C9 x
- & g- n E6 h) X8 F8 F3 F
- ;文件头
7 C0 L8 U4 o3 P0 e3 @ - ;======================================================================
8 `6 t5 [' t! \' {2 d8 N - .INESPRG 4 ;16KB PRG 数量$ r# x) Q6 m/ U2 Q2 a
- .INESCHR 1 ;8KB CHR 数量* F' h" B9 Z! u* n
- .INESMAP 4 ;mapper 4) z+ L+ C' t& a6 S/ `
- .INESMIR 1 ;命名表镜像 0水平 1垂直
+ t: Q6 m: n3 x4 w4 `
8 b' T' J; ]' C; E' q. r1 q. \ ]6 h- ;必要条件7 M7 O& {3 J9 ?* t4 z
- ;1.持有CHR ROM' q ^" h. f" U6 O' T3 J
- ;2.背景Tile和精灵Tile必须使用不同的图案表, 如背景图案$0000, 精灵图案$1000
# Z# }- ]5 h4 T* ^/ E: x) K - ;3.精灵内存(OAM)不为空
. l% r0 J9 X" v$ b$ C3 Z/ z
' w1 U- u6 ]* d( ?$ T+ P7 O% W% [( }- ;==================================================
- e# Z8 m. w4 M- M& Y - ;NES端口常量
" l [$ p2 l: { - PPU_CTRL = $2000 ;PPU控制寄存器% m- T8 C6 k$ d8 i; ]0 ~
- PPU_MASK = $2001 ;PPU掩码寄存器
" l& g+ h! \9 l5 N! p9 ` - PPU_STATUS = $2002 ;PPU状态寄存器:读取后PPU_SCROLL和PPU_ADDRESS被复位,下一个写到PPU_SCROLL的数据是水平的,写到PPU_ADDRESS的数据是高位
7 t- x9 Q7 h/ E2 l" M1 _) O - PPU_OAM_ADDR = $2003 ;精灵RAM地址:用来设置通过PPU_OAM_DATA访问的256字节精灵RAM地址。每次访问PPU_OAM_DATA后该地址增加1: P/ Z. t! g. Z5 @) N7 U- r
- PPU_OAM_DATA = $2004 ;精灵RAM数据:用来读/写精灵内存。地址通过PPU_OAM_ADDR来设置,每次访问后地址增加16 W) V9 X. Z& e# d/ p
- PPU_SCROLL = $2005 ;屏幕滚动偏移:第一个写的值会进入垂直滚动寄存器(若>239,被忽略)。第二个值出现在水平滚动寄存器 8 x8 T7 [6 w, G2 Q7 L/ s
- PPU_ADDRESS = $2006 ;VRAM地址:设置PPU_DATA访问的VRAM地址。第一个写地址的高6位。第二个写低8位。每次访问PPU_DATA后地址增加
( i5 c6 T) ^- {: _( g - PPU_DATA = $2007 ;VRAM数据:用来访问VRAM数据,通过PPU_ADDRESS设置的地址在每次访问之后会增加1或32 : q/ ?" ^1 ^9 ^8 j
- OAM_DMA = $4014 ;DMA访问精灵RAM:通过写一个值xx到这个端口,引起CPU内存地址为$xx00-$xxFF的区域传送到精灵内存
4 C- @; ^0 |# C - APU_STATUS = $4015 ;声音通道切换2 j) S2 e* x; w) `) l
- JOY1_FRAME = $4016 ;手柄1 + 选通 Y- y, \1 q+ b$ l! D6 W8 q% S- u
- JOY2_FRAME = $4017 ;手柄2 + 选通+ D, w" K9 H- G) ]1 E5 l
) O8 z9 p Q$ Z1 K0 O4 i' c4 D- ;==================================================
1 U: s3 H4 h6 r4 ~/ \6 k - ;MMC3端口常量1 o) H3 T0 W: Q) }5 |0 a
- MMC3_BANK_CTRL = $8000
# O q/ Z: K9 ]$ G) f! Q& o - MMC3_BANK_DATA = $80017 c0 i1 ]" e6 k: n- [
- MMC3_MIRRORING = $A0007 J3 `: n! N, p( W) D
- MMC3_PRG_RAM_PROTECT = $A001+ l4 }1 v- y. _
- MMC3_IRQ_LATCH = $C000* {1 \$ g( h1 T! M
- MMC3_IRQ_RELOAD = $C001/ q# E4 d/ e5 F) }: o, J
- MMC3_IRQ_DISABLE = $E000
5 s7 z( f( t4 N - MMC3_IRQ_ENABLE = $E001
4 w) `2 l, U8 t' @' h* C3 O$ N - 2 ~' L1 j) I$ a4 D
- ;==================================================
( R# k4 o3 e5 K8 O9 y, F7 m - ;程序块配置
/ O7 J3 U# ^ Z3 N8 h0 m - BANK_DATA_MASK = $07
z% }7 K1 x; b5 n# x6 E - ;--------------------------------------------------! |2 c) T9 P0 h/ c8 Y( [
- RESET_BANK = $07
. e7 V. ?/ c9 M7 i ~/ k/ K - RESET_ADDR = $FC00
" k3 J1 x# q) p2 y1 A$ T/ O
- d5 b0 ]) D% H6 M) E- ;==================================================
. a- e. \$ ]; b; S - ;图像块配置% K; [( |, B. G, L, {( v
- CHR_DATA_BANK = $08
3 @9 p6 Z# E5 W) Y5 l/ w+ ` - . D+ Q# }) ]% m
- ;==================================================
6 X; b u x; F: ]; S8 x u, p - ;零页内存地址配置
5 V# Z& e R. d: A' q - Use_Ram_Addr = $80
. V- \" ~7 q) r. ]8 i - PPU_Ctrl_Buf = Use_Ram_Addr
8 Z. r' D/ i2 Q' D - PPU_Msak_Buf = PPU_Ctrl_Buf + $01) F# i/ ]$ S* {9 B6 F
- PPU_Scroll_H = PPU_Msak_Buf + $01+ p9 d: k- o' h, o
- PPU_Scroll_V = PPU_Scroll_H + $01
) z) t& K9 F0 q, Q - FC_Data_L = PPU_Scroll_V + $01
8 A" n9 r7 q+ g* @) o - FC_Data_H = FC_Data_L + $01' N. a2 e: s# ]
- FC_Data_Buf = FC_Data_H + $01- u9 s5 {& C* `8 Z, }
- ;==================================================
# m, A0 ]) @0 m2 `! m
' S: B) n& J( {$ C6 ?% U2 }- GAMEPAD_MERGE_FLAG = $042 d+ _4 Z, q$ V- ~# T+ G& u' @
- 6 {3 _" t* Z7 b
- Gamepad_Keep = FC_Data_Buf + 14 W- g* r# z, f3 K4 V% _; z
- Gamepad_Once = Gamepad_Keep + 2. s. ~5 ~5 e$ R/ z
- Gamepad_Temp = Gamepad_Once + 2
# x0 O! W0 s; [/ W% @: J - ' U1 s/ G% v2 ?3 d
- Gamepad_0_State = Gamepad_Temp + 2' n. Q: N% J: x' k/ _% J
- Gamepad_1_State = Gamepad_0_State + 1
1 x3 K8 Y# X" G: L# @% B - Gamepad_0_Value = Gamepad_1_State + 1# N, X& _; ]; J" O$ T9 Z' |" u& O/ l
- Gamepad_1_Value = Gamepad_0_Value + 18 Z0 p$ a: J3 c
- Gamepad_Port_Value = Gamepad_1_Value + 10 q: R0 y m# |- c5 w/ @
- Gamepad_Merge = Gamepad_Port_Value + 1
( @* b) F8 v/ H5 F: H
, n2 A) Q* V8 ~ A- ;==================================================
7 L' s5 G& K. J: O* ^5 t5 U( _: Z: d$ K - IRQ_Index = Gamepad_Merge + $013 \# O* M+ L% p
- Sprite_0_Y = IRQ_Index + $01
; C8 Q& c. W' q, H2 b$ w8 s) D) o2 @ - Sprite_0_Tile = Sprite_0_Y + $01, b$ S" X5 [; i5 A- V
- Sprite_0_Mode = Sprite_0_Tile + $01
) n) ]% `! ]! e: b5 r - Sprite_0_X = Sprite_0_Mode + $01 ^7 U' C( E d
- Sprite_0_Hit_Move_Direction = Sprite_0_X + $016 |0 Y1 p) o, H: O$ H
- ;==================================================
" B7 V) t4 \. ~1 G# |; s2 q - + q/ F6 X4 D% @1 U$ S1 H
- ;CHR图形数据
0 [2 b0 z' I& c$ m- i - ;==================================================1 n0 w' d! z9 p
- .BANK CHR_DATA_BANK- N9 e9 Y, Q7 R: D. p& {' b
- .INCBIN "chr_bank/chr_data.chr"
2 }; Y# `6 d' u% ~ -
6 N+ i% Z9 d, }/ x# J" x6 V8 L - .BANK RESET_BANK & BANK_DATA_MASK
9 ]3 n# Y$ {# y- u2 `7 F - .ORG RESET_ADDR0 }2 r6 f# A: R. U
-
y& b1 H9 i$ d0 _# T: ~ - ;--------------------------------------------------
g8 X* q N5 A' }; t+ [7 G - Attributes_Data
+ P- X/ i( ]0 V& e - ;命名表属性7 V" H' G# \& g5 x2 e( p% [; G% z
- .DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00$ p8 Y. B! m: z
- .DB $50,$50,$50,$50,$50,$50,$50,$50,$FF,$FF,$FF,$FF,$BB,$AA,$AA,$AA9 [9 f# K# D4 }6 b
- .DB $0F,$0F,$0F,$0F,$0B,$0A,$0A,$0A,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA
0 d( p# ^+ u/ r6 L C& S; c - .DB $AA,$AA,$AA,$AA,$AA,$AA,$AA,$55,$55,$55,$55,$55,$55,$55,$55,$55& _5 c" m/ v2 Q, n- n
- ;--------------------------------------------------
% [7 i3 H8 Y1 g6 e% A - ;调色板数据
% G! y" y& n i$ g - Palette_Data! h; s0 e, j8 E( W4 V" _8 J
- .DB $0F,$27,$20,$0F,$0F,$24,$20,$0F,$0F,$21,$20,$0F,$0F,$25,$20,$0F, N5 j3 z! }; I
- .DB $0F,$24,$20,$0F,$0F,$24,$20,$0F,$0F,$24,$20,$0F,$0F,$24,$20,$0F
1 B" K9 u9 b( n& M, j& D/ n - 5 P" l) c" d) Z! B+ T
- ;==================================================
* K( I' v( e! P( y/ X+ Y - ;命名表初始化
; n3 z. L8 {( A1 ^/ l - Init_Name_Table3 p9 T) s1 ]0 J' r4 d
- LDA #$208 |; L' O% s! h' L! S
- STA PPU_ADDRESS
( y9 o6 [4 c' M- Y - LDA #$00
8 ~% V( B& C' f$ H7 o - STA PPU_ADDRESS8 p2 c' M# Y4 }: B0 t
- LDA #$00, I C9 L6 Y0 t+ ?8 n3 J/ G
- LDY #$00
6 S4 u' f- l* o' k1 E - LDX #$10
3 S' D0 k2 W' V* y/ o; A - Init_Name_Table_Write
9 R* n; @) p- x - STA PPU_DATA3 G; ?' R4 o4 n
- INY
$ w" z2 j$ P' J. T) f G& o9 y - BNE Init_Name_Table_Write
: |3 o, M! P% D$ J4 f+ o - DEX
9 A P3 S% f" O1 }4 e! r - BNE Init_Name_Table_Write+ b* }: g g% X+ V
- RTS: ?7 U n) l6 C1 U8 Z; x
- % ~2 l9 s/ ?3 S9 Z
- ;==================================================, e$ v$ t& z2 g. U
- ;调色板初始化
: R& u$ q, K- Y, l: E- H5 { - Init_Palette
" D2 R5 Y4 v8 n1 d9 I* V - BIT PPU_STATUS' Z* K& ]) x) J! K5 b# [3 H
- LDA #$3F- r9 u: u. m7 F# Y' {* i
- STA PPU_ADDRESS
) w$ O4 T4 x" D1 K: Z& ~6 b - LDA #$00
$ ]# }8 C* `. r% _+ G - STA PPU_ADDRESS
$ t2 @/ d5 F. h, m - LDX #$00
" D% O- t$ h' p+ C5 V* _, u1 d - Init_Palette_Write
0 H8 h4 b# {# M- m# b - LDA Palette_Data,X5 g5 V. W, O- N
- STA PPU_DATA' s/ M* `0 }' B6 h J- \' D. Q7 f
- INX
1 z6 ]$ ~/ u3 v, R - CPX #$20
" O6 X7 C- w1 N; |# | { - BCC Init_Palette_Write
/ H. f4 {% `: w. w/ B' A - RTS
5 v4 A1 G" |' k; A - + U2 R c* E- p1 S8 X
- ;==================================================) v8 p: c: ^ a3 ? @6 k \
- ;设置命名表属性
4 l# o) ^/ ~' U; L) ^6 e - Init_NameTable_Attributes4 g1 I, M9 U" D) ~, Z
- BIT PPU_STATUS
4 t; M) L$ x ^! c - LDA #$23! o3 v- r( l; S! ]+ Z: K
- STA PPU_ADDRESS
, W# M1 T8 _5 Y5 j" {0 m: N; I - LDA #$C0
( m2 h! b' x4 l8 o; ^9 T - STA PPU_ADDRESS
* k8 N1 z; i" b3 c( J - LDX #$00
* C2 ^: g5 J, K% j3 L+ @ - Init_NameTable_Attributes_Write9 Q( i Y/ t2 [2 M. s5 N
- LDA Attributes_Data,X
( Y' i. V g, [ - STA PPU_DATA7 [, k0 w9 X( P" o8 \; \$ N
- INX
9 @/ K. m: P, _# X, D - CPX #$40
" G$ j4 I' O% s- O- f/ O - BCC Init_NameTable_Attributes_Write( W1 O+ F: v- Y+ G e
- RTS" ?* q' L M# f
; o+ b5 `/ f D. t0 g$ l4 I# l( r2 Z- ;==================================================
; Z0 y1 a5 a+ } d - ;初始化命名表文本1 j' e. g; a" _; g3 A, y% V
- Init_Name_Table_Text
+ @' v! K% C- W3 M - BIT PPU_STATUS5 I/ a1 T/ ?8 V+ p
- LDA #$20
% V4 e! b8 N" C+ C - STA PPU_ADDRESS
# w% T4 ~' p% `' F - LDA #$00
1 ?7 T' V9 d( m, ] - STA PPU_ADDRESS9 l1 F" R0 I( M2 \' M7 Y* n3 l7 G
- LDA #$00
9 s- k/ I$ l: b3 U, D0 T R4 H - STA FC_Data_Buf
: f# Y- o$ O9 [0 d; | - LDY #30
4 ~- F$ [, T2 p' y - Init_Name_Table_Text_Write8 M* Z# [7 y" [6 i3 m
- LDX #32
; Z: o& E( u2 f q' g - Init_Name_Table_Text_Write_Char) b3 S$ z+ `! b4 c" P" d& v3 G
- LDA #'0'
5 Q4 V" }% {+ u( d" m+ G0 Y/ ^ - CLC! z( D) [# B% i
- ADC FC_Data_Buf9 o$ }. s, h% e* r8 S" w& r3 i/ t/ ~
- STA PPU_DATA
6 V* e5 W( D {+ @6 E/ N# Y* o6 J - DEX# c( J/ V" M. J o p9 [5 M
- LDA #$14
2 X# H: O; S/ ]6 L - STA PPU_DATA
0 l1 M. s5 i2 s - DEX
! {; L- {/ x+ B. H- o3 }3 s l - BNE Init_Name_Table_Text_Write_Char
! u& _- n {6 o& l( F; g - INC FC_Data_Buf- r9 K% ~" I( \
- DEY4 b) P" W# A9 L
- BNE Init_Name_Table_Text_Write8 G1 j z6 @* ?6 D3 e, ]
- RTS
' C. X4 Y) X5 M: C9 N - ' @: o0 B+ H& w2 X7 k$ K$ N
- ;==============================6 z# _* k4 J: ? P6 `. E( Q: N" u) R
- Init_OAM_Ram;初始化精灵内存
) v `' T# U5 S2 } - LDX #$000 v1 B& @$ l6 U
- LDA #$00
) J: v7 ?. G$ l$ e o/ n - STA PPU_OAM_ADDR. [9 E0 P& A+ i9 U! i# \9 t
- LDA #$F8( ~: b7 T+ f7 u8 Z* D
- Init_OAM_Ram_Write
/ u& l! k) O/ _3 ?4 E- [- r$ P - STA PPU_OAM_DATA4 o* s( W0 l0 }3 T2 `& d
- INX
" _1 e- i# ` W. ]2 r3 V! |) t - BNE Init_OAM_Ram_Write; b' u6 c$ s' q6 E# ~: d5 m
- RTS
, M/ W7 k3 j' j0 i& h -
1 i7 `9 R3 A. i [* X) r9 A4 a* ` - GamepadProcess;手柄处理
. R' r, S) k; |% j - JSR GamepadDatacan
& }' E' _/ R! S - LDA <Gamepad_0_Value
; M# T5 y0 K6 N1 d - STA <Gamepad_0_State
9 n6 ?/ @3 c; l! Q0 C: |' G: H - LDA <Gamepad_1_Value: v+ n* @% Q. C1 |' F! }
- STA <Gamepad_1_State) W6 i6 b3 l+ Y" m* k
- JSR GamepadDatacan" @( `7 d: K5 C' x" U. F% j* M
- LDX #$01
" t( A5 D6 x' u# }) g - GamepadMergeCheck;合并手柄输入检查
0 B* `1 P7 O& ?- ~& M - LDA <Gamepad_0_Value,X
: m% [* j: Y# x - CMP <Gamepad_0_State,X9 T+ i; _ i: G. k; e
- BEQ GamepadMergeInput, C9 o( O8 D$ z9 ?
- LDA <Gamepad_Temp,X
; E- Z) p* X2 u/ d - STA <Gamepad_0_Value,X
8 k s6 _! M+ j& H: \$ ] - GamepadMergeInput;合并手柄输入
. |( V3 n4 a4 R2 _6 N# l - DEX) {2 `7 L* E/ q* d, N8 t5 y- D9 [
- BPL GamepadMergeCheck$ h0 f1 v a# b, a: d. d
- LDA <Gamepad_Merge1 v* f! W3 j% n6 ^6 E0 _1 c. b5 k
- AND #GAMEPAD_MERGE_FLAG1 k9 P' o9 {5 z3 ~( P: W+ ?
- BNE GamepadStateProcess$ r4 t" T+ C5 K* x8 d+ _$ ]6 `
- LDA <Gamepad_0_Value) H' y. C! V4 J- G" h. g
- ORA <Gamepad_1_Value# ^" x0 \3 s* W) \6 I! S
- STA <Gamepad_0_Value% Q) @2 V. v$ q1 W+ |) } L2 q
- GamepadStateProcess;手柄状态处理
& O, u' `& L5 a6 ~; q! f - LDX #$019 a; a) I9 }3 h" T8 c9 Q& Z9 @
- GamepadStateSave;手柄状态保存
& p& P, H7 Y& u - LDA <Gamepad_0_Value,X+ H; y1 m# f2 T, Z4 e1 c
- TAY. q+ G8 H$ v" G
- EOR <Gamepad_Temp,X
' @! L) n; N. O0 H. m% ?9 `. N7 j - AND <Gamepad_0_Value,X
' s/ c$ e: o4 R( g - STA <Gamepad_Once,X
' O o- X6 O6 G6 k - STY <Gamepad_Keep,X
8 E2 _! r' w( n: u: G0 a3 f - STY <Gamepad_Temp,X
- e0 S2 g$ k) @" | - DEX
/ V3 ~5 u2 t! i- Z0 ?9 } - BPL GamepadStateSave
" t1 G8 G* o3 @7 g; D% T - RTS
, c$ c6 Y/ R& v" B - 5 @6 W( C# }: N1 S
- GamepadDatacan;手柄数据扫描' H: A) C( O2 ]) T. u X) G
- LDX #$01- b `( A6 r9 T. v7 R
- STX $4016
1 ]7 j5 e4 _5 e: j+ [) v" t - DEX
- i2 [- A2 P/ W - STX $4016$ S0 f Y9 y& t5 r
- LDY #$08# ~, b. a$ M- l" j, d% \
- GamepadPortScan;手柄端口扫描; e+ U9 c; a- k2 Y
- LDA $40167 w+ Y& G' K, d, H
- STA <Gamepad_Port_Value
* m" I f0 p U - LSR A3 \# D0 N, H9 L
- ORA <Gamepad_Port_Value" `# }: v9 x& ?! F) e/ c
- LSR A9 J7 S$ u" j" Y
- ROL <Gamepad_0_Value4 ?8 z% x+ R- v
- LDA $40179 ]) c0 K- \, A) r- w+ E
- STA <Gamepad_Port_Value
* S. A1 P' w, t" R. v - LSR A0 }5 e: k2 w9 C0 F0 g! f, O
- ORA <Gamepad_Port_Value, O4 f! ^2 y0 H! C( d9 g
- LSR A; o" X/ } N8 ^: c. f1 t6 t
- ROL <Gamepad_1_Value
. ^6 d! Z/ Z4 N6 J - DEY
7 l( ^9 i# j6 ^ d' n; d0 y - BNE GamepadPortScan- b! T1 O# d( Z
- RTS+ }1 ^. z( c6 m
- ) `) h7 e! Y! I; H8 a w
- ;==================================================( y' l4 t% `/ e9 J
- ;PPU处理
! I( ?( d# m: D" X* n - PPU_Process
9 R- @* a# r+ B, s% T$ h" i - LDA #$00% H7 M" ^( B5 K8 k7 _
- STA PPU_MASK
" O- e' }: ]" h' U3 z -
* \ ~9 W L5 O9 T - BIT PPU_STATUS
0 A* n1 a+ p$ ]8 n3 P! n% T# z - LDA #$20
1 B- |* @) s3 {6 L& `; f0 | - STA PPU_ADDRESS$ q' l* b5 ^; h/ c( [* r9 ~: Q
- LDA #$002 Q0 O8 I) \2 p
- STA PPU_ADDRESS
) e8 i9 L1 |% I# O* X - ) Y* v/ P j6 U5 ]3 J
- STA PPU_SCROLL3 }# J3 p" _5 t2 x) m* [2 u* u
- STA PPU_SCROLL
6 k2 k1 [6 P, r8 { -
- \ i, K4 H, B: f# F - LDA PPU_Msak_Buf e' B+ x1 P( j# \) j/ B
- STA PPU_MASK
+ N2 n5 Z* L7 d3 P - ' v1 F' M& J- f- o" ?- v5 W
- RTS
0 C3 E0 |' v' s( N; m% k - # ~% h4 ] x0 N9 {: L$ g8 N# {6 ?
- ;==============================
% d* b; A) m/ g - Time_For_Vblank;延时等待) H( @: p! a E- @! y
- LDA PPU_STATUS
1 b$ B7 Z* a: }" P - BPL Time_For_Vblank" P4 e, `$ x" {- [
- RTS) l; O) s" [4 C& d
-
5 M5 a' n9 V" w: t - ;==================================================' O% T$ w5 Z8 ~ X1 j1 u# E7 f) D
- ;初始化MMC3
. h% S9 B5 @% x- x# q3 t9 y - Init_MMC3
) I( O# e; {, _, e( c, x - STA MMC3_IRQ_DISABLE
X& {( }* z6 |) x3 F - % Q2 Y( z4 [5 R, e+ B7 [( \, D! s; Y
- ;设置MMC3水平镜像
, O1 p9 d% s2 o9 L - LDA #$01% K% }- S& {0 i3 v9 Z$ B; F, R
- STA MMC3_MIRRORING2 m& X% N. s" M2 c
- ! v- c* @2 o! M, G/ |$ r1 a7 K
- LDX #$052 `/ ~5 {, w9 n/ d
- Init_MMC3_Chr_Bank_Write8 X* N8 y+ O# {7 o$ ]$ j' N
- STX MMC3_BANK_CTRL
4 ]$ W' n9 a) A5 g6 ~ - LDA MMC3_Chr_Bank_Data,X
4 I) }$ R& ?, B9 } q* \% B - STA MMC3_BANK_DATA6 i% O9 R9 k0 o3 K7 K" H* M0 }
- DEX- }, U8 x$ y( p* s5 P' E2 ?
- BPL Init_MMC3_Chr_Bank_Write+ ~' a4 P9 f8 N+ h% }
- RTS
* g0 \: w0 {' c# p x6 H) c- u - ;--------------------------------------------------
. T" Q8 k* y, J, e I3 R- B, J( A& C - MMC3_Chr_Bank_Data
# j( J& f t/ N' d! [. l4 ^ - .DB $00,$02,$04,$05,$06,$07
* U2 J' x+ y- H4 H1 h1 n. ?* ~4 |
4 l2 S1 @( e5 w m$ V- ;==================================================
0 f, B4 B5 l; }/ V5 E - ;重置中断处理
! p$ T4 w3 r9 B0 ~: q7 d7 z, D/ Y. B - ResetProgram2 S. G( V& f, H; T9 J2 f+ x2 P' h
- SEI9 o9 |( [8 S( g6 ~$ u% |: F
- CLD) f7 W# y$ {; u7 V$ z H. @
- LDA #$00
3 g: P0 z6 U) U, n - STA PPU_CTRL* x2 ]7 w7 D) M& o. }! b
- STA PPU_MASK1 @* p# v% J, A8 ?1 F' u
- STA PPU_STATUS
, F& N1 ^1 I$ v9 V - STA JOY2_FRAME0 w! `8 X, I b; ?7 {
- STA APU_STATUS
& h& {) n7 ]& n: ~% v& n -
6 X+ ^# M7 C: h# N3 J# b - LDA #$C0# Y/ @6 ^ X# Z3 o1 j2 H; }
- STA JOY2_FRAME& Y- _4 D+ K% X
- ! D/ l4 p" q1 I8 i
- ;等待vblank; x( h5 m" g8 b: W# I
- LDX #$02
- M4 ?1 y, L8 B. N9 a& d% t - Vblank_Wait_1# r0 V- h; j* D/ A- J2 v# Z: B A
- BIT PPU_STATUS
; `8 V6 b- T; k& ] - BPL Vblank_Wait_1
7 ?& a: ~5 @$ _5 o m, V: T - Vblank_Wait_2" J/ B! x: T% f) B, T
- BIT PPU_STATUS& R% c" p! s& P' [6 N
- BMI Vblank_Wait_2# L B# d) y( G" D) C/ r' E
- DEX
5 }0 _1 d. n Y - BNE Vblank_Wait_17 m. C$ J6 o7 v4 }% X0 R1 a
-
2 F- G! _, R; _. O: Z! ~8 z5 }# P - LDX #$FF! H5 K* f( w. H( y4 m
- TXS- P/ w2 q1 T' t5 T' k
-
, D3 P X, O! Y$ { - ;初始化MMC37 u6 @8 a$ m! e( v& {
- JSR Init_MMC3+ g ?$ ^4 a; ]8 B- G, ?0 d
- 3 z4 L' |, V) s* P& i6 ?2 H" [
- ;==============================
' J) x. v2 k8 F% Y6 \9 M$ \ - ;RAM初始化
5 ?9 q% P7 [) s) l* D4 V% ~ - Nes_Ram_Init' l5 t4 k; M/ j
- LDY #$00: H% H; s# S1 {, E R
- LDX #$08( i* U3 o' x, `
- LDA #$00
% k7 y& g! C& @+ N/ {& u - STA <$00& J u: M7 R& f( [
- STA <$01
2 x$ j {; Y& L. ^ - Nes_Ram_Init_Write" k, Y' Y! a) r1 I1 M) I2 s w) f7 [; J
- STA [$00],Y
8 I+ D/ k4 N H! _* y - INY7 a; S, v" _9 @/ l4 O+ D# C# R$ ?
- BNE Nes_Ram_Init_Write
2 ]; v0 L: ?3 X( P2 t - INC <$01
6 q \) R5 V D$ Q8 ]3 V - DEX( T" F. V& [9 _9 S, U* q( f8 V7 U7 S
- BNE Nes_Ram_Init_Write6 P, I B9 @7 t8 v
-
4 R. r0 b5 [& W - ;初始化命名表$ V7 ^ _; o, z/ l/ O; T
- JSR Init_Name_Table
$ {. F* H: ]8 h$ f4 ? - 3 M, N Z3 _" Y& t
- ;初始化调色板( S, o+ B4 Y% {" N; B* |. Q
- JSR Init_Palette
& C2 R( x: x, ]% i -
* I" m' i$ g+ v3 J - ;初始化命名表属性3 w4 C! O4 }# q! y
- JSR Init_NameTable_Attributes$ O( a, D( o. w5 j, G3 C7 o2 d
-
5 `% a( s% _# B; `, [. n4 B - ;初始化精灵内存
" G, R5 F5 z5 y3 h |. `& z$ j9 W - JSR Init_OAM_Ram2 y0 S# m, Q+ T. _
-
- p9 r) F/ T- F" @" F/ G$ w - ;在屏幕上写点东西! [7 p* Y0 g0 _" U. s- A7 i
- JSR Init_Name_Table_Text- j0 Q! d5 p; n6 e! u
- # k0 q3 ]* `4 G, s) a+ X
- JSR Time_For_Vblank
4 {* Z: ^# \ y& i' i3 ^& D - ;开启PPU控制
# I1 S! n2 T' F - LDA #$80& Y0 h, I1 G5 K8 f8 l1 e
- STA PPU_Ctrl_Buf
! r4 S. `/ e C - STA PPU_CTRL
1 J. o8 a& ?/ U% R" v; R -
! v+ F# w/ l9 s! }1 U7 @- w - ;开启PPU显示( u$ d* t9 P- A* C0 J
- LDA #$1E
, f V$ Z' ]( E7 I5 O y - STA PPU_Msak_Buf
! M5 ^( k+ \( I6 u, u2 s3 I; W! V; @ -
, o* F3 z7 G4 L- G. n) }* g - LDA #775 ]8 h1 w7 {8 q( }% ~. w
- STA Sprite_0_Y
, D6 ]2 d( L* Z! m0 e: S: ~, h8 q0 P - LDA #$1E
& p1 }& R0 T5 D1 W J; X t# h# A - STA Sprite_0_Tile2 n- C6 C3 z5 N1 y) L6 S
- LDA #$20
, i. b6 u3 x# r3 `/ Z4 `5 y - STA Sprite_0_Mode
" b' ], U( d" Z0 C - LDA #$005 e# y3 E. j- Z9 _
- STA Sprite_0_X
( D# H0 }4 n5 y2 w' o; a4 r4 f - 4 | [! D: ] D7 M0 |! S. p4 Q
- CLI/ F* U# _7 G+ v3 |
- JMP Loop
: I: ? C. @$ a( V - 4 [6 U0 ^% p: y% ]) i9 c
- ;==============================
. `% Z- i/ O$ U+ B' Y f# `6 m- L - ;死循环, 等待NMI中断8 v- b, ?6 Q8 Y2 M* L
- Loop
9 p- R: J4 c! @3 V( n - JMP Loop7 ?; q/ d1 O1 I& i% k
- ( X8 t0 y# P4 F; Z4 n: G) u
- ;==================================================
; q: D8 V+ V1 g" N' t. G - ;NMI中断处理
" M5 w- k7 [! g4 V - NmiProgram
$ N- ^5 \+ B* g; W; p9 U - PHA
" i& N; R4 v& M+ }# x/ k% g - TXA
! j G" w; a9 ?$ q! C: Y - PHA
( I4 H; v, V/ t4 R - TYA
! S( ?, }5 c) ` - PHA# `9 ^, ~% Z$ u+ q5 S
-
' T5 w. b- v4 D7 u2 Q; d0 | - BIT PPU_STATUS
2 j* }% r8 U N& J% L) G. r - ' X$ j4 a4 o% L& G" l
- ;关闭PPU控制; F, O1 w0 {( ]! h
- LDA #$005 ~+ O5 f7 |, E
- STA PPU_CTRL
( c& I: ]; N- U8 i- W% R - % S* W' Z% ~" P8 l+ m" L6 H' X
- ;处理PPU
) R( \3 r9 w( o+ ^% f - JSR PPU_Process7 D: p# \( w- n: m" I) \* ?
-
6 s& g0 a: M7 q$ P8 f2 u2 e9 `7 o - LDA #$00
: B1 R, l6 s& s! P. B; V - STA PPU_OAM_ADDR1 ?9 ?, ~4 R( n W
- LDA <Sprite_0_Y9 c5 v. ?, j# i g0 x* h
- STA PPU_OAM_DATA6 O) z/ f6 ~8 {6 ]" X
- LDA <Sprite_0_Tile$ m8 E; ?' k7 q% ~, o
- STA PPU_OAM_DATA
& }! Y9 K- s- g! }8 G; S - LDA <Sprite_0_Mode% b' g" R* Q, G* @; _6 {) H8 y2 e8 I3 G6 O
- STA PPU_OAM_DATA
. _3 [8 d$ S7 ^9 ]& w: p0 T' \ - LDA <Sprite_0_X
$ R1 M4 {( x/ m9 t( g- t - STA PPU_OAM_DATA
; ?) E6 u7 s6 e4 Q -
6 k& s! W3 a7 E) x - ;开启PPU控制. G- g3 m4 L7 c- _
- LDA PPU_Ctrl_Buf% F# b, S$ e) E$ f. m# G, e! i
- STA PPU_CTRL8 B" `& U0 c7 t- B5 w" S7 R
-
7 U$ L. M9 r, j - ;屏幕滚动
/ S, |9 U5 B% ~' d& }* R" b8 ~( ~ - LDA <PPU_Scroll_H: K6 ~7 M( }$ T" G' S& A: h7 N6 I
- STA PPU_SCROLL
, n. ]" S' t8 h2 z - LDA #$005 P6 _. L8 Y3 x; ]
- STA PPU_SCROLL
: U* F# N! ]2 U -
( z- ~6 t d- N$ l - ;手柄处理
/ v. T- _, [8 _0 j9 ^! R - JSR GamepadProcess
3 ]8 _) [2 J! s0 t -
" K7 P. I: U0 q5 ?+ D - INC <PPU_Scroll_H+ S/ ~6 R! c0 b% {% p- G
-
0 }- r' L. v+ @ - ;启动0号精灵碰撞检测2 Q1 Y- H9 d% a$ ~
- LDA #$01
3 H& u3 K. I* P8 \2 f - STA Sprite_0_Hit_Move_Direction
+ ~; z% k' N0 ^( a9 o - JSR Sprite_Hit_Test
' }( y& S" G5 B% Z" t -
& N4 s! Y- O6 ]' _ - PLA% i; g- V7 y) }# H6 V
- TAY
9 }! m5 Z7 H+ l0 u4 A - PLA7 g1 K J2 W$ C$ _4 k! m& Z/ b
- TAX4 ]( j" m8 U' u+ G
- PLA" {; V9 l, _2 Z& Y% P8 d1 [
- RTI8 J- Z4 `" f( _% \+ F* u1 B& v- D8 y
- $ h: ]! L! k/ K/ A' N, J- ]$ @2 }
- ;============================== H; j" Y. S# B8 s
- ;0号精灵碰撞测试
& |% y; p6 f6 N& f) _% E; m - Sprite_Hit_Test8 ^& `! x1 }5 _/ f8 D
4 W+ ]% F4 M( E% _- ;------------------------------
0 d, u+ g3 K+ |& R - ;等待0号精灵碰撞状态取消
- X. O- s. y# E! g) E - LDA PPU_STATUS! i( v: ^! H+ {4 k0 K1 O$ ^
- ASL A
6 \( o3 U3 |4 ^( { - BMI * - 4
) ~5 J, K/ q" ?0 s- Y' f - ( ^* i' L7 a0 Q
- ;------------------------------
9 [" @! P4 H8 J7 ` - ;等待0号精灵碰撞发生 P( G- H( C2 G
- LDA PPU_STATUS
1 B, j$ S/ a& E6 |9 w - ASl A: A2 I2 Y: B/ g) x$ v1 {
- BPL * - 4
: w7 S4 _3 u7 r# X, A
1 i% q. \/ Z6 }3 C6 @, f I- ;------------------------------4 h; a5 x$ E1 {$ \% n* x9 [& B
- ;行消隐等待, G3 p% O1 n1 f8 R
- Sprite_Hit_Scroll_Wait+ Z U4 ^7 C& F! R
- LDX #$28% g1 [ z% s* Y% S% e4 A$ v# L& |
- DEX
3 z" f, t2 s( x. D8 Z L( u - BNE * - 1
9 g5 @+ q" @) V* I. p4 X -
7 I* [) @( c2 V - LDA Sprite_0_Hit_Move_Direction9 f2 C F8 u2 R: w9 }# x& i
- AND #$012 {( I1 V. e) `$ N
- BNE Sprite_Hit_Scroll_Set_Right
( ^8 E0 {& V% K; G7 u - 3 |& y5 B" M& h/ p
- ;------------------------------% A& a( X$ `; R6 Y, I) b% T
- ;分割画面向左滚动7 M8 H* m1 t3 W: N) I, Y' |
- Sprite_Hit_Scroll_Set_Left
% m5 p$ H/ P5 t8 w, i - LDA PPU_STATUS7 t9 y q% X, B v: ~5 B) g
- LDA <PPU_Scroll_H
" {- Y$ O: }8 ^5 p4 W - STA PPU_SCROLL
- |* X ?3 Z; R% }: s - LDA #$00
5 V) u9 C! B3 e4 v; X" G5 k; C - STA PPU_SCROLL
0 G9 u: D# E. k7 ~* r - RTS4 l" B# E" X& Y
# z& l9 L0 E7 y' _5 S- ;------------------------------
/ W5 X) _0 A3 y2 d' o _/ h - ;分割画面向右滚动
9 ]# z' Z5 _- { - Sprite_Hit_Scroll_Set_Right
' x2 L! f2 J2 V" h - LDA PPU_STATUS1 ?# y& K1 Q1 c/ e0 u* N
- LDA #$001 @ L# g, F4 ?; V, A0 y- J# N
- SEC
Q/ p( G& p/ [) J - SBC <PPU_Scroll_H
5 }, w+ q& L2 w6 i5 L - STA PPU_SCROLL
. O) j/ J4 R1 V: z - LDA #$00$ p* j! b8 {' f1 _" U8 e
- STA PPU_SCROLL) p' R2 e9 K+ G. G: L
- RTS
" Q# ^; i. W# h2 `1 y
& Z* R; E( u: v- ;==================================================
$ a2 s4 V1 S3 n, l& l$ n - ;IRQ中断处理
9 A" T3 y( G4 X6 Y5 j$ i5 p) ^* a - IrqProgram
0 _8 u5 F7 M) } W, k - PHA: A' F" ~& X' C8 S: B, V5 K
- TXA7 r! c" U, _, _4 T* }
- PHA
) \: ~5 I9 V7 R+ [ - TYA( d" ?. q' }) \- i9 \
- PHA7 a0 S( t8 r: n- h( G8 E; L
-
0 R1 A0 }. Y# Z+ g - ;关闭IRQ# X4 P- O' r9 P2 z; N) Y3 M5 z: z
- STA MMC3_IRQ_DISABLE1 m9 G `- B/ h* Q6 l
- - G1 D6 _+ S# m. Z' j( h6 A0 I' ~
- ;允许下个IRQ触发 W* r$ {7 [+ Q
- STA MMC3_IRQ_ENABLE( t$ J$ P6 Q# M
-
" d" i" J$ _0 I8 ^ - ;IRQ处理, 15线后继续触发
8 b+ \4 j! S; a+ q% A3 t" ] - LDA #15
* b7 m _* c0 | - STA MMC3_IRQ_LATCH
/ g) e- |; n2 m- Z -
- K; C3 o$ i ]8 w* z - LDA <IRQ_Index
" {! i( N- g! _7 ]7 N: P6 Z. G - BNE * + 4
4 k4 J4 ^/ b- s) l" W; J - INC <PPU_Scroll_H
/ h. A4 G z* b - 9 M9 H* E; Q* W# ^
- ;设置屏幕滚动
; \- }8 V. J) R' w - LDA <IRQ_Index
; J( Z% z5 b d; ] o$ d& R, T - AND #$013 q% z; |( Y8 x
- BEQ Irq_Scroll_Right7 Q: z/ p8 N: d/ _, z
6 Z4 Q& M1 Q9 J8 x6 \9 Y) [- Irq_Scroll_Left
" i, n& M6 M' V. F) M - BIT PPU_STATUS
9 q& e) B4 M, }% ?5 ]0 h/ M - LDA <PPU_Scroll_H
) ^# [2 T. @2 F( i& {( L9 B( O4 Z - STA PPU_SCROLL
- D2 r6 W% \) w2 {4 v2 }& B - STA PPU_SCROLL
! I& k/ _6 U# d5 x& E - JMP Irq_Scroll_Over
4 Y$ ]; P' f. a- \. T -
( r3 b0 ~- I/ y4 ^) a. Z' y' u. {: ?( C - Irq_Scroll_Right
) U8 @, B' ~" I8 W - SEC
5 ^/ O* N- @7 H/ G J - SBC <PPU_Scroll_H+ E* s5 ^% A0 N' }8 Z# e
- STA PPU_SCROLL6 H; r# @7 V, @* V/ P6 q
- STA PPU_SCROLL D6 l/ W3 L* k7 d# U; F0 }& R; Z
- Irq_Scroll_Over
Z E! m6 W+ d' J, v" | -
; |8 @2 F% c d0 O5 [( V - INC <IRQ_Index" ~" k T* t/ w/ g; G2 K6 Q7 Y
- I- r6 E% h6 T' Y" ^" Q
- LDA <IRQ_Index
$ [" F+ Y" `2 M! L6 k - CMP #143 v' _2 O( R" \2 ~, A ^/ w& v
- BCC * + 5, p- f, L: r0 L4 u* f
- ;关闭IRQ
% q4 E( S/ K5 D; {0 H) ?/ j, Z - STA MMC3_IRQ_DISABLE y/ x" u9 c9 H; p: U. \1 v1 C: Z
-
9 A/ M- n$ o& X) w+ E. z - IrqProgramEnd
( |* L- R/ P+ ~ s - PLA
6 H5 g6 h0 G5 l* {& p* ]# [- ]: q, p - TAY6 B+ U/ \( E# o
- PLA ^0 H1 K" o3 c
- TAX
) [6 @ r+ o$ T9 t$ {. X, ]* | - PLA3 e) a0 }( P! S6 H7 ?
- RTI7 c8 k6 r3 {& x& L
-
5 H& F' C% _% F) h+ { - ;==================================================6 s: x5 ^6 s3 E# ?9 \
- ;中断表
" v* @, U/ _4 g+ j$ ] - .ORG $FFFA' f0 c, J8 m" G
- .WORD NmiProgram
# s5 }" P6 r+ }2 j m4 ^" v - .WORD ResetProgram
1 [4 B4 y- Q' h - .WORD IrqProgram
复制代码
( g. x# L: H" i, f4 _ |
评分
-
1
查看全部评分
-
|