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