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