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