|
- ;[FC][MMC3 精灵碰撞]
( {3 a" L& v1 U - ;FlameCyclone 20230710
/ e: O# o4 W' B, {* r
6 O b: N+ O9 Y. t7 I: d- ;文件头 r9 y6 ~/ m! Q- J* V
- ;======================================================================
/ ?& e0 i( l# O3 q1 j ?% V - .INESPRG 4 ;16KB PRG 数量 C/ G4 I6 m9 r! `3 T" d
- .INESCHR 1 ;8KB CHR 数量9 K v; P3 W, c( F7 T3 t
- .INESMAP 4 ;mapper 4
7 p* ?, O+ E% l! l" K' p" {5 R - .INESMIR 1 ;命名表镜像 0水平 1垂直6 A$ N; e9 g+ c* C
6 Q* K/ |1 s0 j& _ a- ;必要条件/ \% g' W* }2 v$ ~1 K
- ;1.持有CHR ROM
4 [9 g9 l" P: U" V% A. |- g - ;2.背景Tile和精灵Tile必须使用不同的图案表, 如背景图案$0000, 精灵图案$1000
: o i1 c; ~" ]3 K) P& ~ - ;3.精灵内存(OAM)不为空) `. Q- V& B5 ~/ n0 {5 d
- 6 E3 J+ i2 M+ f9 u: T& I
- ;==================================================. Z$ l/ ?- C( a7 F4 m. r& ~! G
- ;NES端口常量; x0 C3 b% M. A& n3 l: r% d7 C
- PPU_CTRL = $2000 ;PPU控制寄存器* M& f% k8 t: f# W
- PPU_MASK = $2001 ;PPU掩码寄存器
$ O% K3 [' r% f5 V) W1 t& g' M8 e - PPU_STATUS = $2002 ;PPU状态寄存器:读取后PPU_SCROLL和PPU_ADDRESS被复位,下一个写到PPU_SCROLL的数据是水平的,写到PPU_ADDRESS的数据是高位
$ @/ ~7 ?6 v1 m7 N* b' w4 J5 H* @ - PPU_OAM_ADDR = $2003 ;精灵RAM地址:用来设置通过PPU_OAM_DATA访问的256字节精灵RAM地址。每次访问PPU_OAM_DATA后该地址增加1
' o6 s5 O n5 a3 p% S3 e; E - PPU_OAM_DATA = $2004 ;精灵RAM数据:用来读/写精灵内存。地址通过PPU_OAM_ADDR来设置,每次访问后地址增加1
_5 V; \9 R+ T: {; v - PPU_SCROLL = $2005 ;屏幕滚动偏移:第一个写的值会进入垂直滚动寄存器(若>239,被忽略)。第二个值出现在水平滚动寄存器 - H- U! n& t) w$ P' R E
- PPU_ADDRESS = $2006 ;VRAM地址:设置PPU_DATA访问的VRAM地址。第一个写地址的高6位。第二个写低8位。每次访问PPU_DATA后地址增加
( |8 V9 d8 e- r+ H' s - PPU_DATA = $2007 ;VRAM数据:用来访问VRAM数据,通过PPU_ADDRESS设置的地址在每次访问之后会增加1或32 ( \& F# F& @& c" |. ?( G
- OAM_DMA = $4014 ;DMA访问精灵RAM:通过写一个值xx到这个端口,引起CPU内存地址为$xx00-$xxFF的区域传送到精灵内存
/ }2 }" C0 P0 A( T" l" ]7 C - APU_STATUS = $4015 ;声音通道切换9 j# W: i# H- m; R# e4 t
- JOY1_FRAME = $4016 ;手柄1 + 选通
: O$ N. H" E) | j! c) I - JOY2_FRAME = $4017 ;手柄2 + 选通
4 Y2 R3 W7 r$ G! _& P) M
$ o1 |0 J; e- H/ G: U- ;==================================================* q H" L" H h( j4 o3 A& c, ?
- ;MMC3端口常量) a1 q8 N$ N, D2 f# d
- MMC3_BANK_CTRL = $8000
$ e: H8 _* h/ ^, F" e: X/ m - MMC3_BANK_DATA = $8001
0 ?# n* T* G% \( @+ M/ Y - MMC3_MIRRORING = $A000
1 w' \: f2 X( S9 Y - MMC3_PRG_RAM_PROTECT = $A001% O# T0 \. m$ L9 g2 c( E1 A* F
- MMC3_IRQ_LATCH = $C000 u/ |4 c% @* X% x
- MMC3_IRQ_RELOAD = $C001
* @% w7 Y9 m$ m - MMC3_IRQ_DISABLE = $E0002 b+ [9 y/ @3 a4 N/ b
- MMC3_IRQ_ENABLE = $E0016 M: H! T. _4 u/ U) e7 C
- 2 ^( b* L3 q$ F4 S8 c0 ~/ K' ~
- ;==================================================7 y4 a: W! {9 U4 U1 n6 s3 T
- ;程序块配置
* d7 f. d! b5 B - BANK_DATA_MASK = $076 m, f, o! j* Z- _$ A) C
- ;--------------------------------------------------3 X; |7 @, O7 I/ A
- RESET_BANK = $07
% t7 l; N, R1 L: J4 @# g - RESET_ADDR = $FC00
. r' c) g# Q! c) u3 q5 y5 B, _ - / t* V- E' u1 m3 o7 W; Q! i$ U
- ;==================================================/ _% E8 T% v+ S/ D2 r G) k& m
- ;图像块配置
2 i5 i7 _# \8 k& \. \1 U r - CHR_DATA_BANK = $080 ~$ h/ P& x6 U$ I/ d
) ?- L3 n) P* L+ h+ q9 R( j. h- ;==================================================
) G0 z" \9 L& u% @ - ;零页内存地址配置
2 K2 d6 o4 {5 G# X/ Q - Use_Ram_Addr = $80
5 ~3 l7 J7 R" ?9 p - PPU_Ctrl_Buf = Use_Ram_Addr- A3 k. C4 Q& ^/ K. y+ G
- PPU_Msak_Buf = PPU_Ctrl_Buf + $012 n' A5 h4 S* n' b9 f
- PPU_Scroll_H = PPU_Msak_Buf + $016 a% j4 [" g* c3 ^* l, O1 C, K; e4 ]
- PPU_Scroll_V = PPU_Scroll_H + $01
$ C1 d- c, m9 B( V0 d* v( S- R - FC_Data_L = PPU_Scroll_V + $01& P; l4 {& |% X+ y" O/ \* l
- FC_Data_H = FC_Data_L + $01
* k9 T7 u; u$ n% g/ q - FC_Data_Buf = FC_Data_H + $01
: l8 e1 @- r5 L( P+ Y% Y - ;==================================================
# p' X3 C+ f* C4 I/ t/ N7 [+ V) p, a - 3 ~' k3 Y0 f6 M
- GAMEPAD_MERGE_FLAG = $04, w: |% k6 y, D' w+ P# ~' r9 Y
- * g7 @ q; t0 J9 b1 |: U
- Gamepad_Keep = FC_Data_Buf + 1
* p/ @$ U4 |& F+ G* L - Gamepad_Once = Gamepad_Keep + 2$ e x- K9 d) q7 Z
- Gamepad_Temp = Gamepad_Once + 2# }4 ` K0 l; ~; l; d
- # k9 g' i4 A) z2 v
- Gamepad_0_State = Gamepad_Temp + 2& c7 F/ k$ G. `; I1 n- Z5 f
- Gamepad_1_State = Gamepad_0_State + 1
! k+ L# \7 z! |: N6 B' |, |- r - Gamepad_0_Value = Gamepad_1_State + 12 u- b {' o* q, @0 G' D
- Gamepad_1_Value = Gamepad_0_Value + 1; e Z8 Y5 `5 v5 D
- Gamepad_Port_Value = Gamepad_1_Value + 1- N9 L- A3 @% a7 s) X( }! x
- Gamepad_Merge = Gamepad_Port_Value + 1
1 x! D* _( i9 v - $ |6 {( q" Q2 ~$ w- i
- ;==================================================, L. u- ]" ~ _ g7 N7 o
- IRQ_Index = Gamepad_Merge + $01
1 r8 y! }, C/ r" k- e3 I @& [7 a - Sprite_0_Y = IRQ_Index + $01+ |( Q, W; H, i2 r
- Sprite_0_Tile = Sprite_0_Y + $01& ]/ M8 d4 A; X. \ O9 a
- Sprite_0_Mode = Sprite_0_Tile + $01
\. b* f1 D8 l! D - Sprite_0_X = Sprite_0_Mode + $01, G7 W9 Q6 W) k" q3 \5 e! u+ R9 a
- Sprite_0_Hit_Move_Direction = Sprite_0_X + $01, t/ l7 @8 a/ L, h- ? P- z( I# g
- ;==================================================
, S, {5 W4 }1 |5 j: D. _ - . D2 Y: N4 H+ B
- ;CHR图形数据- ?& v' [5 B/ R; L: ], k
- ;==================================================
: ]9 L8 Z6 y0 o6 b- L0 y - .BANK CHR_DATA_BANK! I3 P3 k; c% C; }' v8 S# h
- .INCBIN "chr_bank/chr_data.chr"* i. @: L8 ?- z, S4 V
-
+ f- Y: I, D" E2 e - .BANK RESET_BANK & BANK_DATA_MASK3 ~* w; v( Z8 L* Q. A/ E1 P" E; ^( }
- .ORG RESET_ADDR
# I8 M* v# C% U1 p# i -
0 k: T) D2 x4 P - ;--------------------------------------------------
' k5 d5 X4 p, i# ^5 H2 e, z9 \ - Attributes_Data
% w' V$ P5 q/ A - ;命名表属性
" h7 _0 G5 d3 ~3 b9 p' W' r - .DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
, e- N. Z# l9 b: W; @0 [ - .DB $50,$50,$50,$50,$50,$50,$50,$50,$FF,$FF,$FF,$FF,$BB,$AA,$AA,$AA
1 ?, T% c2 s$ N6 o! j; ?+ g8 { - .DB $0F,$0F,$0F,$0F,$0B,$0A,$0A,$0A,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA0 k9 b# P7 j! s% i, x
- .DB $AA,$AA,$AA,$AA,$AA,$AA,$AA,$55,$55,$55,$55,$55,$55,$55,$55,$55
) A2 i% b$ z& S( } - ;--------------------------------------------------% |% ]6 N1 C; X" r/ f( j1 m
- ;调色板数据7 Z8 F: l- |% v# c/ R! l2 ?
- Palette_Data
4 g0 F( ]( |2 f/ z4 y - .DB $0F,$27,$20,$0F,$0F,$24,$20,$0F,$0F,$21,$20,$0F,$0F,$25,$20,$0F2 t- `5 N0 W) u+ g
- .DB $0F,$24,$20,$0F,$0F,$24,$20,$0F,$0F,$24,$20,$0F,$0F,$24,$20,$0F# f F! o" l4 o, m
- : m& N9 y# i2 J+ n, m6 N
- ;==================================================7 d: m4 t+ B+ X: U7 g
- ;命名表初始化
3 Y2 O5 K7 U- S C$ _5 i4 z - Init_Name_Table
& F) g: R2 ?$ A" D! T, x. p - LDA #$20
6 t" @6 d/ b1 J - STA PPU_ADDRESS1 k& N( C$ }2 A3 L9 y% ~
- LDA #$00
# x+ F2 N7 e% c* n ^; O, B% M - STA PPU_ADDRESS$ J# x& O1 o0 S
- LDA #$008 x" M q" O/ [2 H# V6 C( o
- LDY #$004 G5 q' q; d; o5 V! Q# d8 ~
- LDX #$104 w# ?" x5 f3 `4 U# G
- Init_Name_Table_Write
5 l h B# V! ~0 D* D - STA PPU_DATA
6 d! e5 j: g; s6 U - INY
/ c2 x P5 t( i& X# `, S% b% g; Y - BNE Init_Name_Table_Write
1 N' q7 D. H0 _! g5 [- ] j - DEX% V/ n0 G; X+ L3 v
- BNE Init_Name_Table_Write
/ O8 N4 E- ^" D; Q2 j; w: h2 c - RTS/ e& f. d5 \ Q1 k
-
$ K3 T; ]$ j I ^, W, B6 y: p5 [1 r - ;==================================================' |9 a; X+ e: A% Y
- ;调色板初始化6 g/ r( h5 F) B% Q& H
- Init_Palette
& V, e5 I3 h# Z8 m y$ X - BIT PPU_STATUS
* V0 v9 l8 K% {' V - LDA #$3F
$ P$ Z% ]. J4 T! `. @4 [2 ]/ N' h - STA PPU_ADDRESS$ m- M t# Z% h; H" D/ [
- LDA #$00
- G9 c) R, Y% G0 Z# v- X3 @ - STA PPU_ADDRESS" V$ U: Z" v c/ E. Z. V
- LDX #$00
( y% ]; z6 \& X1 c% `& y5 c - Init_Palette_Write! v7 N" N3 F/ V
- LDA Palette_Data,X. u5 ^( K! _7 Q7 z6 m- T& N. O. b
- STA PPU_DATA
" {# b; ^# X3 }( [ - INX
; W ]& O2 S/ }) c, S - CPX #$20
. `$ i5 e) {2 W3 A - BCC Init_Palette_Write
$ v5 Z, h7 o& i- {* z- g6 E - RTS
2 d/ ^$ I* o c7 x1 k - ' F0 W$ K9 R. Y; \
- ;==================================================
1 H( L/ x, H' F, |7 } - ;设置命名表属性! I* ?" P& J( P7 t: w, K9 v O+ m
- Init_NameTable_Attributes
8 ^/ V3 c B5 }. V1 Y$ W/ O - BIT PPU_STATUS; \+ f$ M9 f& I8 v8 g y9 n
- LDA #$23' a3 @5 V) w& e+ B9 F
- STA PPU_ADDRESS8 b# C/ ]: G( ^; \! F
- LDA #$C0
1 \! |9 P. e5 v% a2 Z1 e - STA PPU_ADDRESS5 e' ]) t, G1 I+ F- G
- LDX #$00
+ s; e; I+ N+ `) n( T% q - Init_NameTable_Attributes_Write
1 u% e8 Q5 A8 `* T7 h4 f; f4 [& D - LDA Attributes_Data,X- Q8 _. e; ?7 S* J" p( p
- STA PPU_DATA. G5 ^ ~. ^% Y8 O# t
- INX8 ]" b" x% {, e1 x) l$ a2 j
- CPX #$409 c" Y& j' f/ F6 {
- BCC Init_NameTable_Attributes_Write
% [" \# Y( t9 a7 X* K3 a - RTS
/ D5 C5 U! |& o/ v# | r
1 p- X y w- G- ;==================================================( U' W6 D( T# R5 `$ q# q
- ;初始化命名表文本
" ]$ G z( d, b/ p3 O0 m - Init_Name_Table_Text5 }& @ F3 w# P5 L$ P: V
- BIT PPU_STATUS
: `" r. J( R" R: i - LDA #$20. ~( l0 P1 J; ~' }5 f
- STA PPU_ADDRESS
5 Q1 q. i9 a# o( M# p. | - LDA #$00
4 |) ^# G. v, y) g D$ x0 Y - STA PPU_ADDRESS X; { N6 o1 n3 Z' C( O( B, ^' Z5 h/ W$ k
- LDA #$00
, T3 w# o8 a o0 |6 L- M3 u. A$ Y - STA FC_Data_Buf% g, V+ f R" \8 P( N& p
- LDY #30
% @' O2 Z% B2 s* T- Z9 o( q - Init_Name_Table_Text_Write
6 _9 m- f2 l6 h/ B. M: I - LDX #32
# D& l! R" ]7 p& c - Init_Name_Table_Text_Write_Char
) a9 q5 ?8 l ^ g& u6 N& S" Q - LDA #'0'
& W; b3 P, A1 R- r" {& O' w - CLC
, c: `# a1 D% X& u3 E - ADC FC_Data_Buf
3 U% H4 x5 _$ G- R - STA PPU_DATA' f6 _: G$ a' ^) r
- DEX
; f: z# m7 g0 q - LDA #$14
9 }" v0 I4 M5 ~6 x: ]/ C3 _% n - STA PPU_DATA
8 k" {5 s ^1 i - DEX
3 D7 w6 ]) z6 Q6 y2 ^4 z$ w - BNE Init_Name_Table_Text_Write_Char9 j4 n+ h1 o8 q/ W! r3 Z
- INC FC_Data_Buf
t" W( k3 B1 j- I! b - DEY
: ]5 V0 I/ S/ w( y8 y - BNE Init_Name_Table_Text_Write* Y1 z2 @" B7 f. d. Q/ V( j# S4 U
- RTS, A6 i0 z: ]3 y2 k* l, @/ Q
- & I6 o T* f$ U; Q* N# d% X! L; R+ R7 d
- ;==============================" a0 s8 y5 Y R$ M
- Init_OAM_Ram;初始化精灵内存! V, P9 o/ F$ U. o. N G& v
- LDX #$00 F2 ^" \' Q9 C, a& b! i
- LDA #$00# i2 R; Y3 t8 [ t$ u5 o/ K, W
- STA PPU_OAM_ADDR1 R# U' C/ q0 O, e
- LDA #$F8
/ ]! q5 S+ Z1 b- }2 e! s% F - Init_OAM_Ram_Write
* J( F4 N4 Z$ F - STA PPU_OAM_DATA$ U1 i$ }$ I1 n$ i
- INX
+ A. J& S& Z. z0 Q; R- O* i9 ^( K - BNE Init_OAM_Ram_Write
. w9 h; |3 M! t/ U: N - RTS, q. f! K: G m1 d2 O2 G
- 9 M3 X7 s1 S' y7 h+ r# K
- GamepadProcess;手柄处理
& d+ c+ o. c9 A3 O* n$ ]" n - JSR GamepadDatacan) R! [% v4 }" l: d; j% d
- LDA <Gamepad_0_Value7 H, n* T3 `$ _( r3 }
- STA <Gamepad_0_State
* F& {7 U3 P' Y: _' f - LDA <Gamepad_1_Value) y# O- |- _6 L% B8 n8 t
- STA <Gamepad_1_State+ n5 Y) | h7 V6 b6 H
- JSR GamepadDatacan2 ?5 v" r9 ?% g
- LDX #$01- M3 [5 [: z6 f7 H/ |, T
- GamepadMergeCheck;合并手柄输入检查
3 n% C2 L9 }0 z - LDA <Gamepad_0_Value,X" f* R7 P1 }1 z2 P3 l s
- CMP <Gamepad_0_State,X
0 H% F& P1 ~ w( [) e7 s, z - BEQ GamepadMergeInput. V9 \/ T0 t$ c/ r0 B7 x
- LDA <Gamepad_Temp,X- s0 ]- ]3 S/ B3 V. K4 L- X
- STA <Gamepad_0_Value,X
+ Y( p! P" P: ^4 j- J- b - GamepadMergeInput;合并手柄输入0 l* d0 m b1 N, I4 b5 K' c' p
- DEX
/ {, {" P4 `( ]. U - BPL GamepadMergeCheck
3 l' K% Y8 \+ E- {# _) Y - LDA <Gamepad_Merge' c5 U/ P9 q$ S6 b+ B: `8 ^, ~
- AND #GAMEPAD_MERGE_FLAG
. R, P; ^/ N5 _0 X6 ~& _+ { - BNE GamepadStateProcess& h! i8 a* @) ]' S9 }% F, j
- LDA <Gamepad_0_Value0 C9 R' e* s( P( Z6 P
- ORA <Gamepad_1_Value7 a% N4 V- `+ R
- STA <Gamepad_0_Value6 V$ {2 J+ i% u$ c: w2 o
- GamepadStateProcess;手柄状态处理1 j0 e. m4 N5 x1 @3 t2 I; U( v
- LDX #$016 j! V E3 l- g1 B) l4 U6 B. D
- GamepadStateSave;手柄状态保存
. ]: \7 M8 }. E" g# ] - LDA <Gamepad_0_Value,X
: u. `% v7 a9 S7 Z+ o - TAY# Y# v2 I, b; c7 S6 \; h
- EOR <Gamepad_Temp,X( c; ^5 \ m/ P# P# L
- AND <Gamepad_0_Value,X
D+ ~! C, V- {4 J9 s - STA <Gamepad_Once,X
& G2 l$ B1 ^! X4 [3 p2 r& t! O - STY <Gamepad_Keep,X3 b# d( p* R* h0 C. x+ y4 s0 U
- STY <Gamepad_Temp,X1 }, h- W4 t: H2 N
- DEX
& E# J3 U8 l$ _; Q- U+ b - BPL GamepadStateSave
/ A* C' y$ x. v% E- d4 B3 j, z - RTS
/ u0 u& n' g; M0 Q
4 U* C7 H% |2 F2 ~# t- GamepadDatacan;手柄数据扫描3 [0 m% ]2 E9 g! G! n4 d
- LDX #$01
! Y2 |% R* c, @ X( ~( E; p. M1 o - STX $4016
# {1 R! y* i5 ^ - DEX
0 p) ?' Z1 a1 ?) ] - STX $40168 z' V6 Y# C" n$ U! z; \( H
- LDY #$08/ V3 S% N: r4 B- v8 @4 b; h, W
- GamepadPortScan;手柄端口扫描* \4 Y, r7 A. v9 B
- LDA $4016$ P6 m6 \# B6 Y8 F; l/ V5 a
- STA <Gamepad_Port_Value
- G) c/ r" @4 t/ d1 p - LSR A# W# L9 e. W4 _# J( Z( O0 ~
- ORA <Gamepad_Port_Value# |* a3 [; g) G
- LSR A) {& C9 t8 L& `
- ROL <Gamepad_0_Value- o# f/ \0 m2 m: t0 U1 k/ u% O4 a7 m
- LDA $4017
6 M' t: ]" f# } b ] - STA <Gamepad_Port_Value/ { B# _9 @' D% U
- LSR A
8 M% [2 L! W0 }1 p8 D/ ^ - ORA <Gamepad_Port_Value
% B( z: ^; N- C - LSR A
' k0 s# `: M6 P: s1 Y - ROL <Gamepad_1_Value
2 f% k* G8 j: y Z - DEY
! q+ B, m. ]; X- p! N Z$ V - BNE GamepadPortScan
' G/ r) V' G; j9 c) ^% \* _ - RTS
/ n9 X4 \, [' _% i+ P8 H- { -
+ H+ }; O0 b9 `% r, u, y - ;==================================================
- Q* O8 W9 [, w9 t0 X6 [1 V: y - ;PPU处理# K5 D6 t+ Y0 M# z6 U
- PPU_Process# ^% }* Y: b4 ]: D- M
- LDA #$00. O' D+ Q, R* M/ E9 t3 p2 t( x- z) M b
- STA PPU_MASK" u) K" Y0 w/ c2 m, ^
- ; P. H( W# |1 i' o' h% C
- BIT PPU_STATUS0 T7 z; f l. o: h+ p" l# b/ x0 n
- LDA #$20) d; a! a1 r# x% v' ]
- STA PPU_ADDRESS
. ? m; ^. v. x+ A3 X1 [# c4 G* A - LDA #$00
+ Q: f. \$ X' g' h; W7 @. k: S1 N - STA PPU_ADDRESS, P# h1 k9 R! u7 u* C4 ]
- 9 \5 H; J; w Q. e5 L
- STA PPU_SCROLL1 N0 K9 z% f+ L! b1 t2 E
- STA PPU_SCROLL v! X: L9 _* P% |# B' X; G( ^
-
' n9 [4 I9 v. i; c) I( t5 y - LDA PPU_Msak_Buf" u( @ p- M) ?2 j
- STA PPU_MASK
! c, M) [- E0 C- u4 f W - 7 H# p- a: @6 i M+ H: ~) v
- RTS
4 Q% J, N' F8 B, _" V; B -
8 T! W% |: l2 p; X& Z1 C1 a* J# ] - ;==============================" n; L) M* \& V+ X* b8 s, H* B
- Time_For_Vblank;延时等待 C8 o: M& R2 o4 ^9 B
- LDA PPU_STATUS
2 Q- t0 Q) l9 m& q( D. N) W; e - BPL Time_For_Vblank( ]8 r. M7 O5 j) N) H8 f1 z5 L- i
- RTS
5 V' m" m3 j8 o. G+ ?6 U' h -
: ?6 }+ Q2 K8 f9 p' x - ;==================================================# O T* J* [+ r j
- ;初始化MMC3
4 l7 Z9 t( U# s" J5 h - Init_MMC3
) A: N" x. r" q @ - STA MMC3_IRQ_DISABLE
2 q1 `, J/ W% \' q* N' @7 M& H -
0 | s# }" H: _ - ;设置MMC3水平镜像
0 z8 k: L$ |/ |7 p8 Q+ N! y! m% g8 [ - LDA #$010 c& K# p! Z7 D6 S
- STA MMC3_MIRRORING- h- q" B7 t$ x9 B2 V) j" B
- 6 x" {% l9 ]. X' }2 s2 [* S% {. Z
- LDX #$05# S \# X* u( \7 \, t# k# z$ c
- Init_MMC3_Chr_Bank_Write! K; \" e w, h8 q
- STX MMC3_BANK_CTRL
4 [7 b" h+ d2 P* t9 \+ @ - LDA MMC3_Chr_Bank_Data,X- j5 E. [: t, }9 L+ _
- STA MMC3_BANK_DATA: \: O4 F' v5 I0 X9 `
- DEX
! Y. T; |7 e: d% R* P3 l* w - BPL Init_MMC3_Chr_Bank_Write
( o( \' E- ~( [ - RTS
2 `* ?0 a: _2 L3 m - ;--------------------------------------------------
/ x9 W: s6 |* D$ J$ \ - MMC3_Chr_Bank_Data
, b5 [7 v3 L1 h5 i' N - .DB $00,$02,$04,$05,$06,$074 Z' R1 N: {* l7 h6 }- C) F& { }
- $ w7 r, h6 L }2 B+ R1 }6 C" `9 w
- ;==================================================& l, \$ W: H) ~3 e+ I1 B2 e* D
- ;重置中断处理( } _7 i, T! ~. G
- ResetProgram+ R& H- M# a H6 S; O
- SEI2 d6 |$ Q& t& U
- CLD
* u# t. [8 t& c - LDA #$00
- ~) C n. V! n: r% E/ o - STA PPU_CTRL
; _- I" b( f0 p9 w+ B1 k [ - STA PPU_MASK# I) ~ M( q3 G0 w
- STA PPU_STATUS# J4 ]3 j3 [1 e% t9 {0 I7 L
- STA JOY2_FRAME
2 u2 P$ ~. g! k H' Y( U - STA APU_STATUS
Q- O* v" U2 V( ~8 Z4 |' W" H -
* Y& V, i& m) `8 E) \ - LDA #$C06 v1 h% J, B: D2 i
- STA JOY2_FRAME
7 ~6 c6 M1 h: L+ N -
( ~+ o$ w% t) Q8 M - ;等待vblank
+ x0 N: J5 F2 L+ w4 B - LDX #$02
1 V) X5 \7 d' g% I7 u1 q4 j( q - Vblank_Wait_1* Z& ?( X$ m3 H$ `' t3 E9 I
- BIT PPU_STATUS
0 c) D. N! }% \2 ^0 t" s' A3 W z - BPL Vblank_Wait_1
- ~( H! e2 i/ x* f) K - Vblank_Wait_2
9 T2 @$ R1 s x! q4 t" ~4 y: L - BIT PPU_STATUS( i" K0 W* o7 B" K5 M$ ]# W# E$ }
- BMI Vblank_Wait_24 y0 W1 z( v0 j& ^2 Z& [9 v
- DEX& @" V( i3 h. s, F, O
- BNE Vblank_Wait_1
j* U# H% y; r7 S" p$ D+ o - 8 J* {8 w8 e/ s) H% M9 O* f
- LDX #$FF
8 F' }% q; `" S* F1 Y9 @# u - TXS% a$ B) u7 t- a7 h
- 2 W4 O) D/ g8 s/ u- `
- ;初始化MMC3: |7 t% P$ ~" c
- JSR Init_MMC3 P w5 o6 g0 v8 }4 t4 ?4 I1 i
-
) e. v* d7 u$ g8 i5 O! }( R - ;==============================+ W& o0 M% J2 }
- ;RAM初始化
_( N' P6 ^. J6 y$ K- \2 e% G - Nes_Ram_Init
8 r$ F0 U5 k3 v% z7 X - LDY #$008 l& h: `! J3 `
- LDX #$089 e; Y. o0 W, K& O
- LDA #$00( V# ?; l9 d) Q, c3 \6 f2 t: J
- STA <$00
# m! s' O# j: N% A |4 U* C - STA <$01
4 Y* k# [9 ^9 s6 c; L - Nes_Ram_Init_Write
- S3 S, d7 S5 ? - STA [$00],Y6 l& X8 F# k* O$ h3 }4 h
- INY
) r7 L+ l2 O" u _ - BNE Nes_Ram_Init_Write
5 i% t0 l4 i- i! C4 M3 T - INC <$015 B" J' Z$ }# s! {% z" p5 c
- DEX/ B& b' L- O: H* _5 \
- BNE Nes_Ram_Init_Write! h! L n/ x; r& U$ W
- 3 x: u% @: D+ I" M
- ;初始化命名表
# J" ]2 p( G- G4 x0 P& N5 e - JSR Init_Name_Table
; ^; ~) x. W/ U% c* w6 O7 b, W -
6 R: [% x0 f* q. y3 d# U4 g - ;初始化调色板
* C9 F9 `6 r) x& m# Z' v6 P - JSR Init_Palette
, M; g' V7 @9 Q8 N; h - G4 S- |9 d) ?; S, Z( k( \
- ;初始化命名表属性
: S1 z6 l. K1 j( F; \3 e5 N* z) S - JSR Init_NameTable_Attributes' ?/ C& _+ K# G- O1 F& i3 b$ X8 v
-
- H* D0 ^9 Z/ }, A' e - ;初始化精灵内存
( O- ^ p$ a+ \0 } - JSR Init_OAM_Ram: |; q9 F4 X' K& c" p( A* K0 V
- 9 k3 X& ^9 _1 L$ L% q7 E
- ;在屏幕上写点东西
& L7 m$ C& g4 x9 L& _/ s8 n - JSR Init_Name_Table_Text2 ]* [9 N+ W( w" O* h5 v& g
-
7 V) }6 S5 b8 c" N$ p! m - JSR Time_For_Vblank
6 Y1 ^3 y4 E$ b4 [( o - ;开启PPU控制
) f$ d* U. M, d# M* d0 m - LDA #$80
5 Q+ V/ I0 p! ]! M+ j/ g' q - STA PPU_Ctrl_Buf3 t- C4 @2 o# M, m$ J0 j! ^
- STA PPU_CTRL4 t+ U5 n6 o, U9 M
- % x7 t7 c; T( V4 J. p6 ~
- ;开启PPU显示" I" }: u' I& n1 |
- LDA #$1E0 C! I# U( X5 Q1 d0 r" M
- STA PPU_Msak_Buf
4 ]: w1 J/ B3 s0 Z" } - & A$ Y4 q1 o$ @0 D* J! x- U
- LDA #77, ]4 [# r$ {* K* v4 I( R' ?
- STA Sprite_0_Y4 p4 w4 o( P# s* ~% k0 f5 [1 D
- LDA #$1E3 J7 h$ G1 d# a# Z, \& U
- STA Sprite_0_Tile
' t& A n; Z f/ x8 c3 b - LDA #$20& p* o( s" A0 u- r* K- H
- STA Sprite_0_Mode0 `% V9 d' B# M9 b: T& @
- LDA #$008 U5 L I5 N" y3 C: x" J+ \* U: H
- STA Sprite_0_X1 k4 c( O* L" [) R( B
- 6 `2 Z' X* K5 X# f2 m
- CLI
0 s. e4 Z- H' ?) w) z" _4 { - JMP Loop; {: C5 p/ ?, e' A
-
/ S x: ?6 S7 T1 j1 x - ;==============================% n Y+ Q& }- c/ J) ^0 u$ [
- ;死循环, 等待NMI中断
! I: l' R" z4 S& q - Loop
. E5 P% e9 Y# ]* r: N - JMP Loop
6 S% }9 a, y0 h" }! n& I$ A - + R5 H6 R$ \3 o7 c2 L2 h0 K; a
- ;==================================================
* C4 U( r1 j, |- k - ;NMI中断处理
, e, j1 d2 \& Q6 d/ {' ?7 m - NmiProgram* s; f) V- \/ _5 N4 j
- PHA
8 e5 X9 I, o) L! X* m! H - TXA
% Y* r$ e; x/ p, L1 x - PHA
+ X: i( }, ^/ T' Z1 Z7 A - TYA b) U6 ~( S7 b. C7 w
- PHA
5 M: Y' s' [" T* U$ E6 s; M - ; H. b! k( ?$ X
- BIT PPU_STATUS
) W. X3 [4 I' u, h - ( N# M6 d4 o/ l+ D+ V& k7 @
- ;关闭PPU控制% ]( a: c% d! v c4 K
- LDA #$00 o L9 C% q7 p, F6 e1 T# u' ^- S
- STA PPU_CTRL
/ w* B7 Z4 t# q6 M ~ -
2 I: B! x3 R4 J2 r4 k# ~0 l - ;处理PPU1 w0 ~% s1 d! B
- JSR PPU_Process4 j# K4 M) b% {) g( D
- . J! ?7 ]0 ~- I, ~( T
- LDA #$00
6 Y& E' _: d0 D: X8 H4 o - STA PPU_OAM_ADDR4 }5 F; A6 n; G" l4 Z U: Z
- LDA <Sprite_0_Y5 j# ^8 H4 q" P9 \3 M& j
- STA PPU_OAM_DATA9 ?! [) Y% U% _+ V" u/ v
- LDA <Sprite_0_Tile R% ~0 W, B5 c3 M
- STA PPU_OAM_DATA; ?( }) j" k1 s/ C# f) W" {/ d2 x5 m' S# {
- LDA <Sprite_0_Mode6 h$ w. x c7 Z9 Z0 y' C! E
- STA PPU_OAM_DATA
6 k6 z* ^9 L0 Z& L* g - LDA <Sprite_0_X
7 o4 ]4 A: C+ {( p! X - STA PPU_OAM_DATA/ U: z' _0 C' x- S: l, _. |
-
' O& W% [# J5 j8 b7 ~ - ;开启PPU控制( _) P* X) C7 f. l8 b
- LDA PPU_Ctrl_Buf
1 A* O X+ S0 r$ u% X - STA PPU_CTRL2 X5 P `1 q. m& L* E& W3 o# k( `, P
-
0 ]' `4 O! U ?0 g p6 ` - ;屏幕滚动 U$ w. ?2 `- G8 C$ ^
- LDA <PPU_Scroll_H
% F( b% H- E9 ?8 N& J - STA PPU_SCROLL) z; |( ^7 u4 f9 ^# ]" r, J
- LDA #$00" W/ f, w; a% F$ ? ]
- STA PPU_SCROLL1 Q* n: |6 ]- n' w# W6 Q) D
- 4 ]( p% e% b; u& X. U( A
- ;手柄处理" a+ b8 f) Z: w
- JSR GamepadProcess3 A; D& _. E# Z4 V5 k! [+ u4 v
-
3 f( B6 ?* i' H. b - INC <PPU_Scroll_H7 Q% a. y) A' z7 Z* S. ?
-
" G8 r# k. b3 j5 f/ }2 t; k - ;启动0号精灵碰撞检测
2 a! b5 i6 ?- } - LDA #$01
! O( R5 l4 `/ s- t1 p2 k7 [1 b2 p8 T - STA Sprite_0_Hit_Move_Direction) M; q0 v/ q; @; s4 \: c
- JSR Sprite_Hit_Test8 I6 l5 Z: c5 B$ e* `" A( n
-
" H( P1 S# w& D5 s1 C. h8 m, a. B - PLA
, R! G% u5 C* x - TAY
t% E& s- e; h0 P - PLA
3 x G( I2 M7 R& b - TAX' {6 j5 d# A1 f5 A2 ?
- PLA
- Y a9 ^7 w9 M- y3 W$ M - RTI e6 B% E9 S, @6 P J% n
- 2 R, U1 K; e2 T" j
- ;==============================
& ~ P2 N3 I5 p! J( C. P. V$ ] - ;0号精灵碰撞测试4 e& ]/ ^8 V# z1 u' b
- Sprite_Hit_Test
3 z- z+ ?) B6 a$ z - # a- H! A, D& d$ X- L/ H4 l! z
- ;------------------------------
0 j3 ^" p' g5 ]( Q. h x - ;等待0号精灵碰撞状态取消
7 D" x3 s' }/ F; Z' `2 h - LDA PPU_STATUS
$ V' c! |5 J/ {2 R& f# f9 z - ASL A
1 |4 x3 T- D3 O5 B% X: ~7 }( ?' E3 P1 G6 I - BMI * - 4
) A0 W8 V7 s+ ^, x - " V0 P4 l& g$ H" n" L) t
- ;------------------------------
% t: J& b$ k) L" D* }1 K6 }$ Z9 m - ;等待0号精灵碰撞发生
# n# _" i; g. G1 U - LDA PPU_STATUS/ A/ G1 i1 C2 z2 F8 g R4 ]
- ASl A
. G% Y% x8 M- Z* Z) H0 t0 x - BPL * - 4+ S: p+ p/ _' b7 Q" y
# ^4 a0 s4 ]. a) H2 N( u* I6 U# K8 W- ;------------------------------
5 G( F/ |* Q8 C6 a5 d - ;行消隐等待
# i( F* X, H, v - Sprite_Hit_Scroll_Wait
* ]" P0 R9 w9 f* ?! i- Y - LDX #$28
3 w0 Z4 F- q" o1 ^# }6 b3 f - DEX& E' K3 u r1 E% L. Z, N
- BNE * - 1
5 @8 c- L1 M! {6 i$ p; Z0 Z1 i - ) F: G. J( ^! C
- LDA Sprite_0_Hit_Move_Direction
9 X7 |) W) j, t" O% J* l8 v - AND #$01% X0 C! d. F' h: ?$ \( r* o; {
- BNE Sprite_Hit_Scroll_Set_Right# \ {/ Y5 E/ K. }* Q4 c$ M
- 3 t' N% F' M" o3 G, u
- ;------------------------------0 ]3 M% Y$ O7 r
- ;分割画面向左滚动$ s6 P* a; E, ]% K2 E# l4 o: z, t
- Sprite_Hit_Scroll_Set_Left
( p) h' \ g/ E - LDA PPU_STATUS
) E8 O0 ^( T V: t - LDA <PPU_Scroll_H w; `8 F0 ^% z' d3 E% U+ l9 Q- b- D
- STA PPU_SCROLL
* h* ]7 n! U8 U9 X/ e g2 r - LDA #$00
$ ^+ G1 k" r" o3 q - STA PPU_SCROLL7 ^& y" O9 r! ]
- RTS; A+ Q" B! S7 S) u& V
3 O0 f9 G, B/ [3 p A- ;------------------------------
0 j+ p3 C; S+ \ - ;分割画面向右滚动& L6 L0 g' T7 A
- Sprite_Hit_Scroll_Set_Right
8 d7 u6 j' r7 x% R - LDA PPU_STATUS3 L8 k$ G6 P/ p6 E8 |- ], W
- LDA #$00 E+ A, _( M% ?8 Z/ i) s, v
- SEC
; H9 Y( ]" {$ [4 q - SBC <PPU_Scroll_H d2 d: F7 q) c1 L
- STA PPU_SCROLL9 |. b8 A3 x) H l7 H" ~
- LDA #$00
1 j; o y# _9 Q" |+ u - STA PPU_SCROLL1 ~+ q2 v, V/ W2 b/ r8 |% C1 ` A
- RTS
U% c7 |* I @) J8 A- e& G
( v! r$ f8 h- s7 n3 N+ d. |- ;==================================================, ]" E1 f0 ^1 x6 n
- ;IRQ中断处理4 r. t5 |2 F, r5 H0 j* c* ~" U% E
- IrqProgram' L" c6 k$ f, u( ?: P# J) z
- PHA
9 w3 Q9 u4 p, T: {, V h5 L T - TXA
6 W; |# Y. f" h* ]* E5 Y - PHA5 F+ W( _) ^1 g# M2 F4 t, w& {
- TYA; S5 p5 l2 v. O* B' v
- PHA
! H% n$ u# \% I6 _3 P( N - 8 c8 r$ y! b; L
- ;关闭IRQ! a& }9 d1 ^$ Y: x8 B! J( a- v/ `
- STA MMC3_IRQ_DISABLE8 z: @& E! c' h6 r' M
-
1 Z. J3 E9 r( k. {9 _1 ~! \5 F- z9 Y - ;允许下个IRQ触发
* I- j) Z7 a# Q4 V - STA MMC3_IRQ_ENABLE
9 W# d+ z$ O; l$ g* T& G3 g. V B0 ^ -
p" A+ K4 D! i8 ^. s - ;IRQ处理, 15线后继续触发
' ^& q$ |) v8 u' m* h3 i4 K- U - LDA #15
; T. t i, [5 g - STA MMC3_IRQ_LATCH1 d( q: b7 ^: z1 @
- ) P, m0 x9 B' S% x
- LDA <IRQ_Index
- G0 H$ B# n+ a3 l - BNE * + 4
( M& w8 m ?) W: V) I. p1 I - INC <PPU_Scroll_H0 x/ N! r* k' @% l+ f* o* ^( O
- 9 |2 u% I( } u0 w9 g
- ;设置屏幕滚动/ f! Z+ n8 E" V* Z X' D
- LDA <IRQ_Index
1 r8 ?' H" j, s @, E3 @$ c' a - AND #$01
! T" d% w8 y8 h; V4 C. {; @. b - BEQ Irq_Scroll_Right
" t7 U. s1 {" ~; k
: R. R* J% b; n0 E) s) H- Irq_Scroll_Left
- v4 m" K( ]+ P, d; g - BIT PPU_STATUS2 x7 N& b" l1 U6 |. a
- LDA <PPU_Scroll_H/ i# M$ I; t+ m; E; V! S
- STA PPU_SCROLL
2 ^# n, h% r# ^' j: | - STA PPU_SCROLL
" ?. C2 u. U% `6 U! B - JMP Irq_Scroll_Over
" B4 a! L2 s4 L7 j -
1 e: F$ @1 x3 j3 A! f8 [ - Irq_Scroll_Right' d& E- e B* u0 {8 ]6 V
- SEC* J7 ?! D+ [3 |& w r
- SBC <PPU_Scroll_H4 I, p7 ]* k2 _5 ?
- STA PPU_SCROLL
$ D( y7 \. p9 N# I: Q* V& m3 u. k' f0 @ - STA PPU_SCROLL
' q* [8 Y8 \4 Z7 O/ y5 w$ A - Irq_Scroll_Over5 O# r8 [6 A/ P" i
-
- u" `7 L# J! t$ l8 Z b5 T( O - INC <IRQ_Index
3 X+ W% X% _. Q" _6 R -
$ N$ H; ^- a1 j8 R' q# e" I - LDA <IRQ_Index' n( a5 @3 ^" T2 q( J5 o0 A
- CMP #147 h' [7 e% D! E' |% H" t
- BCC * + 55 G, P$ R- ^9 h# p
- ;关闭IRQ* x) ~/ Z) G A
- STA MMC3_IRQ_DISABLE, N4 U6 g3 T1 F! U) P; f7 x
- 6 L; K1 U- P& k2 O( K: H
- IrqProgramEnd' r' Z, X4 i$ c0 v+ h7 w
- PLA
" {3 L8 ~+ K: @' U1 f4 U* W - TAY
5 D6 Q7 Z# u/ h - PLA" @) N3 E8 f! K/ w$ G
- TAX
( b* ]6 |( w' m7 p - PLA2 M* z. o8 X2 V. t$ ^
- RTI
0 N* m( p5 L2 e& |4 x5 j8 q$ U - 9 b5 Q. Z. e% L2 e: G
- ;==================================================' k3 ^6 y; \4 a, |/ o4 ?" N4 }
- ;中断表
( H$ s1 w# G4 B - .ORG $FFFA' L2 R0 j# g% _
- .WORD NmiProgram
1 p4 q. m; G( k$ a8 J1 {; V! A- b - .WORD ResetProgram9 w/ ~% Y8 A' ^) h4 S2 y- a4 f
- .WORD IrqProgram
复制代码 % D# O! }( y3 V2 U
|
评分
-
1
查看全部评分
-
|