|
- ;[FC音乐][MMC5 IRQ]" q1 ^: Z9 k) P/ {. m
- ;FlameCyclone 202307106 M# p/ O8 \! T) j
- ( h. p5 i! I1 R3 U! ]& _0 g2 F7 S; M
- ;文件头
: z D" p8 n0 e. B" E' ^6 Q0 o - ;======================================================================) D7 ^, E* T# t3 |
- .INESPRG 4 ;16KB PRG 数量
% {" S) H; e d! w - .INESCHR 1 ;8KB CHR 数量
! v* i/ P( ?" t3 ~ - .INESMAP 5 ;mapper 5
' k' ^% V! g+ _1 [% M - .INESMIR 1 ;命名表镜像 0水平 1垂直5 z& s3 t2 M% @8 B1 b
& f; W6 k# {. b4 N( H+ S- ;必要条件
2 P4 o6 L& N2 s - ;1.持有CHR ROM& ~6 T/ Q2 A- B
- ;2.背景Tile和精灵Tile必须使用不同的图案表, 如背景图案$0000, 精灵图案$1000! R( G9 q4 @; D
- ;3.精灵内存(OAM)不为空# J3 X2 p X1 m( D' I1 N% P( F
- 7 s6 l0 a+ h4 i( X. V
- ;==================================================
2 {" v4 X; e" Y# k6 a - ;NES端口常量5 [, S4 [4 k& t% N
- PPU_CTRL = $2000 ;PPU控制寄存器
I4 ]3 B! q9 n1 D. L. k4 L0 T! h - PPU_MASK = $2001 ;PPU掩码寄存器: j, _' T1 E( ~/ G# }& g2 ?, O4 B# t
- PPU_STATUS = $2002 ;PPU状态寄存器:读取后PPU_SCROLL和PPU_ADDRESS被复位,下一个写到PPU_SCROLL的数据是水平的,写到PPU_ADDRESS的数据是高位
9 P7 z* A8 H/ O8 n% C - PPU_OAM_ADDR = $2003 ;精灵RAM地址:用来设置通过PPU_OAM_DATA访问的256字节精灵RAM地址。每次访问PPU_OAM_DATA后该地址增加1
4 q U' ]: r& S1 k& | - PPU_OAM_DATA = $2004 ;精灵RAM数据:用来读/写精灵内存。地址通过PPU_OAM_ADDR来设置,每次访问后地址增加1
. \, x3 l( v9 ^+ u. `2 Q - PPU_SCROLL = $2005 ;屏幕滚动偏移:第一个写的值会进入垂直滚动寄存器(若>239,被忽略)。第二个值出现在水平滚动寄存器 8 B9 t) v; Z$ V& T0 b2 J
- PPU_ADDRESS = $2006 ;VRAM地址:设置PPU_DATA访问的VRAM地址。第一个写地址的高6位。第二个写低8位。每次访问PPU_DATA后地址增加5 h M' Y+ `( T2 W! a6 O
- PPU_DATA = $2007 ;VRAM数据:用来访问VRAM数据,通过PPU_ADDRESS设置的地址在每次访问之后会增加1或32 0 M8 ~4 x+ Z/ o% o5 d6 ], v" e
- OAM_DMA = $4014 ;DMA访问精灵RAM:通过写一个值xx到这个端口,引起CPU内存地址为$xx00-$xxFF的区域传送到精灵内存
" _, `4 @/ v5 [) I- f+ t# z: y" K - APU_STATUS = $4015 ;声音通道切换4 N: H& |: b p3 @& Y |
- JOY1_FRAME = $4016 ;手柄1 + 选通3 A% B* H; c) s" J; n. r$ r
- JOY2_FRAME = $4017 ;手柄2 + 选通) }" B4 R% j7 }( R) f8 m
- 6 u) C$ L+ y2 A& `) a5 y; n- q8 o
- ;==================================================5 r2 S. J4 ?" a3 j
- ;MMC5端口常量4 q! }0 ?; v+ R8 F# c) j( h% P2 Y
- MMC5_PRG_MODE = $5100; 0: 32KB 1: 16KB * 2 2: 16KB + 8 * 2 3: 8*4
2 z- f& l- E/ F3 H - MMC5_CHR_MODE = $5101; 0: 8KB 1: 4KB * 2 2: 2KB * 4 3: 1KB * 8
5 \ B% G3 |$ _7 N" b4 S% s - MMC5_PRG_RAM_PROTECT_1 = $5102;! k5 Z X: A- K4 n5 M& _" J3 I
- MMC5_PRG_RAM_PROTECT_2 = $5103;& C: Q: a7 v3 e7 [: {0 r
- MMC5_EX_RAM_MODE = $5104; 0: Write Only 1: Write Only 2: RW 3:R
( |( i" `* t. T! s. ] - MMC5_NT_MAPPING = $5105;
! m- O p6 ~2 d" a+ Q3 Z* n" r; q; @ - MMC5_FILL_MODE_TILE = $5106
Y9 P9 P# B6 d* b; Z3 y) _; n - MMC5_FILL_MODE_COLOR = $5107 i" D6 {! r# x- I4 G' Q
: u8 n* ^% b: x3 n' C- MMC5_PRG_BANK_6000 = $5113
- w3 q* ~. ^4 R8 S8 ]3 O - MMC5_PRG_BANK_8000 = $5114* {& G% y; B/ @5 N' B3 L& ?6 N- M
- MMC5_PRG_BANK_A000 = $51154 Z& {2 E) u% y. C) x3 d0 t
- MMC5_PRG_BANK_C000 = $5116
- q6 C: X9 N( J1 m" p, z - MMC5_PRG_BANK_E000 = $5117- `. C4 g. p! C9 A' p7 Y& Y0 \
-
5 G/ q6 {( c. l& | - MMC5_CHR_BANK_0000 = $5120! i+ }) j$ N# ^! }8 }+ ?/ q
- MMC5_CHR_BANK_0400 = $5121
) K$ t6 {6 i, P+ _8 x# X0 ]- b% L - MMC5_CHR_BANK_0800 = $5122
) l. ?' a) y/ e6 }. m1 w7 a) }7 ` - MMC5_CHR_BANK_0C00 = $5123
9 m" K n) ]4 ~" E9 o# K3 W1 q - MMC5_CHR_BANK_1000 = $51241 y3 W, ~! h5 W: N
- MMC5_CHR_BANK_1400 = $5125
, U7 D# L; e2 {6 p% b o - MMC5_CHR_BANK_1800 = $5126
% ]- S/ o" L9 y. Z& @1 s - MMC5_CHR_BANK_1C00 = $5127 u( M m7 v* ]) A8 U
- 8 r1 z* u- F+ k* p. Z) S) ?
- MMC5_CHR_BANK_0000_1000 = $51281 F% S0 Z# e$ S/ I
- MMC5_CHR_BANK_0400_1400 = $5129. L3 c- d8 t4 @- V
- MMC5_CHR_BANK_0800_1800 = $512A
& r5 i4 d0 D `) F, e) v( ]. M, q - MMC5_CHR_BANK_0C00_1C00 = $512B9 r9 ?5 p7 q7 k: W( U' H* U4 L
- 7 ?5 S4 n) I0 Z
- MMC5_CHR_BANK_UPPER = $51308 | e/ u& Z; B% B/ {" z, n3 J
- MMC5_V_SPLIT_MODE = $5200
* ?9 P& |6 N$ [5 u* ^& @" |& d - MMC5_V_SPLIT_SCROLL = $5201
% w9 h0 g4 V) A& q - MMC5_V_SPLIT_BANK = $5202; f2 o5 n r) P
- 4 }, b5 D: C& x f
- MMC5_IRQ_SCAN_CMP = $5203
$ i7 ]6 v( F4 y2 T% Q2 ^, z. ] - MMC5_IRQ_STATUS = $5204
: E" W7 o; S" e I8 u - MMC5_MULTIPLIER_A = $5205
/ H/ |4 c3 [' I; @# B( F - MMC5_MULTIPLIER_B = $5206
3 G" V4 v$ _8 S0 j# A -
3 E' w+ ~( @( t9 z$ p - MMC5A_CL3_SL3_DATA = $5207
1 F& i7 m4 n( I) j6 ]6 T - MMC5A_CL3_SL3_STATUS = $5208" d% ~7 e1 w, a1 K2 M
- MMC5A_IRQ_TIMER_LSB = $5209
1 E8 w7 }9 W+ `) I, k - MMC5A_IRQ_TIMER_MSB = $520A7 P5 p# F/ L4 s5 b7 l
9 l3 f8 _4 d5 q- ;==================================================
) w9 M1 |$ a0 W0 y5 ~ - ;程序块配置
1 K( Z# A8 @7 V- g4 Q; Y - BANK_DATA_MASK = $076 S7 P* }$ E3 Q! r; u, T6 R
- ;--------------------------------------------------3 E( r" n! {/ c0 r
- RESET_BANK = $07
* y5 A8 L0 J8 ? - RESET_ADDR = $FC00. m3 q! E, k: l# H: o# o
- " T7 w: S" j2 i# I! }
- ;==================================================6 s) L6 o8 U! o, \" f
- ;图像块配置
; H3 j, c: }% D5 a# y& }2 M - CHR_DATA_BANK = $08$ m# M& i( |# @4 l- r5 R$ e g5 i
0 m1 P4 M4 U8 ^/ s' g- ;==================================================$ t1 E- W' M: w% D! S
- ;零页内存地址配置
x! e- u0 C7 ?( [ - Use_Ram_Addr = $80
0 c5 W7 W7 W0 \. D6 I8 D! H$ z - PPU_Ctrl_Buf = Use_Ram_Addr" v* I9 u2 [# M+ C3 ?+ E; }( d
- PPU_Msak_Buf = PPU_Ctrl_Buf + $01
$ U3 Z8 M# I# ]- C, D9 d1 b* x% y - PPU_Scroll_H = PPU_Msak_Buf + $01# _. i) F4 m$ \/ L$ `. v7 k9 m
- PPU_Scroll_V = PPU_Scroll_H + $01
2 M6 G7 A. a; N+ f - FC_Data_L = PPU_Scroll_V + $013 G! ]( f+ H6 _/ c/ K; S6 L
- FC_Data_H = FC_Data_L + $01, K! ^9 u) h' Z) x4 J$ O$ c
- FC_Data_Buf = FC_Data_H + $01# }: H, [( o* F0 D q
- ;==================================================; V3 S7 Q+ v0 x3 e) N" O; t% i
- 1 u, |1 D7 F4 A$ N
- GAMEPAD_MERGE_FLAG = $04
' |1 @0 z5 i' L J8 R" x - 5 F) I7 E/ |1 K
- Gamepad_Keep = FC_Data_Buf + 1
3 s! w3 y; g* r* m; X9 P - Gamepad_Once = Gamepad_Keep + 25 h; v5 F2 R/ |
- Gamepad_Temp = Gamepad_Once + 2! ?2 X( @8 n4 l, B U: [
-
3 D+ \# ~3 K8 x. l$ n1 ` - Gamepad_0_State = Gamepad_Temp + 2
/ {/ N e- e7 J3 S$ S6 m- ~ - Gamepad_1_State = Gamepad_0_State + 1
( Z3 w [ l6 A- ~( V# ^ - Gamepad_0_Value = Gamepad_1_State + 1
1 w- r* h; a! i, ? - Gamepad_1_Value = Gamepad_0_Value + 1
5 g0 s+ O i4 x/ a, i - Gamepad_Port_Value = Gamepad_1_Value + 16 H+ D7 z" N1 c" v/ X+ `; f' W4 p
- Gamepad_Merge = Gamepad_Port_Value + 1
3 i7 H6 e3 z7 v* G - 0 G: q0 ]" [. {. S3 J: o2 a, P8 u
- ;==================================================$ N! y# }8 t9 u0 b! n
- IRQ_Index = Gamepad_Merge + $01
# ?# G" F- f/ H4 `. ` - ;==================================================
' j0 r! w9 j8 O) r1 k2 @9 T8 _. y
; d+ F6 M' O( g- Y- ;CHR图形数据
/ S5 `, k. i2 [8 g4 S/ w) B# J$ y - ;==================================================& m. W- B4 ]6 V& W$ }7 ^
- .BANK CHR_DATA_BANK
( M/ w5 R& X1 t4 m" g8 _0 o - .INCBIN "chr_bank/chr_data.chr"! g1 i+ u% a8 E6 n
- 3 q0 ~: n: y J1 O- c
- .BANK RESET_BANK & BANK_DATA_MASK
) p& }& g0 ^* d1 j7 x - .ORG RESET_ADDR
( R( C( M e( ]5 y -
Y/ Q, Z( f1 B) d5 Q& { - ;--------------------------------------------------
% ]3 b8 p% O3 q2 f( J' _' ]; T. ~ - Attributes_Data
6 A/ o5 u& e8 T8 V; Z - ;命名表属性- q6 G. Q8 @& z) w) c0 Y. U
- .DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00, ?6 ~; X3 a* i3 `( {+ H: c+ u
- .DB $50,$50,$50,$50,$50,$50,$50,$50,$FF,$FF,$FF,$FF,$BB,$AA,$AA,$AA
5 c5 v% V# H6 ? ^0 K - .DB $0F,$0F,$0F,$0F,$0B,$0A,$0A,$0A,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA
* Y8 {* G$ J* Z4 B/ b0 p+ n - .DB $AA,$AA,$AA,$AA,$AA,$AA,$AA,$55,$55,$55,$55,$55,$55,$55,$55,$55
( s( n N& \+ q- f9 _+ ~) n ?) u1 I - ;--------------------------------------------------
) k& ^! F6 ~( Y - ;调色板数据
0 Q _2 a! `# B; N - Palette_Data `2 }2 N3 j \+ R0 i' C1 R
- .DB $0F,$27,$20,$0F,$0F,$24,$20,$0F,$0F,$21,$20,$0F,$0F,$25,$20,$0F
. A' S7 S: o9 s8 \" [6 ~/ @' m - .DB $0F,$24,$20,$0F,$0F,$24,$20,$0F,$0F,$24,$20,$0F,$0F,$24,$20,$0F" ~7 |* N! E: p6 F6 m; ?$ y
/ B9 _6 H$ a& a+ c- ;==================================================
' k5 S2 p6 O9 s- x3 L - ;命名表初始化
9 j J4 P/ ^0 k" {; _ - Init_Name_Table# M+ _+ \4 |9 G
- LDA #$20
/ _9 W( c* L# K& ~+ [# V - STA PPU_ADDRESS
( q% [4 J3 X5 F' J$ G T' o - LDA #$00
( D6 f! x; X2 j J - STA PPU_ADDRESS
* F- f* Y( A/ L- p5 C - LDA #$003 ?+ q- L ^ W5 H! G/ d8 `
- LDY #$00
) v5 a& q4 j9 W4 U- [; Z+ { - LDX #$10 m7 n- o2 E% ]2 B( f- D! N
- Init_Name_Table_Write
$ ]% Y8 |( P$ _9 h - STA PPU_DATA
! U# x2 V7 d3 u - INY' j1 c! \; k$ t# P. M: I- }
- BNE Init_Name_Table_Write
; T& p$ B3 X4 c6 V - DEX1 F- P [+ A& S. _3 ~4 O! m
- BNE Init_Name_Table_Write( U0 H4 [: k, E. _) D
- RTS1 I: w6 p( m! m4 k5 l1 k8 s
-
/ y- q) V& [; ? - ;==================================================5 c8 T) Z* t6 R* J- @7 ?
- ;调色板初始化* `7 y$ O5 z& J b
- Init_Palette
8 @: q% K9 ?. }3 S - BIT PPU_STATUS
$ g% w0 l) ?) h9 c( x$ V# h( i - LDA #$3F
6 ?0 V) s; ?4 l, E - STA PPU_ADDRESS& d2 g4 ?" s8 n: E0 a
- LDA #$00
! g6 U) n" P) [/ n - STA PPU_ADDRESS3 y2 H% d; U! q( l& X. U. L0 f$ ^! H( I
- LDX #$00
3 \8 y3 {. G0 I0 d - Init_Palette_Write
) F d' q5 M) O7 s, e( g - LDA Palette_Data,X
/ z, q" C' E h! v8 m3 o) d( P - STA PPU_DATA5 e- K- j. B% o7 w: k- ~" o$ I* y
- INX6 b9 s8 n" Y$ I+ V' u) p
- CPX #$20
0 c- h' n7 Q: l4 f& E/ A" C7 X8 M! e# f - BCC Init_Palette_Write/ F: @+ ?% U# R
- RTS) v4 G& p1 ?& S
- l+ `7 m4 Q3 {: f [
- ;==================================================
4 B0 Y5 {! N8 i, w: o - ;设置命名表属性
# n& r, u1 S1 x. T. c! Q9 P# X q - Init_NameTable_Attributes
( i |3 u( |1 p# j4 ^. w0 c - BIT PPU_STATUS
' t8 E7 v3 \8 G4 M% V- J2 c, C - LDA #$23
& T/ x. S& w; c+ F0 t$ j - STA PPU_ADDRESS
0 S6 x& q9 ?* @3 d - LDA #$C0* f% t! R$ Z2 M% {
- STA PPU_ADDRESS
6 e7 S( { S8 m1 T# O- f" ^2 t, W6 u - LDX #$00
: y+ a, [) W4 ^ Q - Init_NameTable_Attributes_Write
, b" Y: b! B* z' j - LDA Attributes_Data,X
3 \# @2 O* O4 M8 m r' g& \5 y: T - STA PPU_DATA/ q9 X7 N$ L4 W$ B v$ w
- INX; |) C/ r: ]( ]
- CPX #$40
+ u$ z! I5 ~3 \8 R - BCC Init_NameTable_Attributes_Write
* i' I' ] g! w1 J# S9 f% s - RTS8 L( ^# l: s/ ~" {
' z6 G; g9 i, N. L9 l4 U" U2 O' L- ;==================================================
2 R6 o; d, V- q; \9 ^ - ;初始化命名表文本, D2 ]& {: Z: i) F5 {
- Init_Name_Table_Text2 ]* ]3 Y! s) H* T1 G
- BIT PPU_STATUS
' A% k6 f2 O$ e% A- K, ] - LDA #$20
- }; \' g) R% o - STA PPU_ADDRESS8 ^4 S* W( a! N0 o
- LDA #$00
6 O2 E I" L I) I2 o! r - STA PPU_ADDRESS1 y0 a2 m. z. w* F% C) P1 o4 m
- LDA #$00
* e+ j r; h5 T, c$ ^1 m - STA FC_Data_Buf& v$ J; @( ]/ E: b, z" V
- LDY #30
$ g _$ B, C+ j+ s r, K' x - Init_Name_Table_Text_Write
1 M/ \7 U9 M0 T; h, J' S! o5 b) T - LDX #32
9 w2 g' M |! l0 Z - Init_Name_Table_Text_Write_Char$ L& }* f7 ]# B$ z# M8 \( n/ W
- LDA #'0'
d& O% r$ C" n. e5 L+ S/ b2 s- i - CLC
4 p$ e% n4 G) I- i - ADC FC_Data_Buf+ d) S' I" _* H( K
- STA PPU_DATA9 w# S8 i9 a8 w) v5 e
- DEX
; `- I. M2 Z1 k$ k4 R) h - LDA #$14) t- y: W! o* [, u
- STA PPU_DATA! m& j2 U+ `4 { ?1 l$ a f
- DEX$ G, r" m% y2 U7 y8 ]
- BNE Init_Name_Table_Text_Write_Char {! R0 I9 c5 E: C1 e
- INC FC_Data_Buf- V* e# @; w/ b, E& S
- DEY
Z# q, f; v- T9 e/ m# u - BNE Init_Name_Table_Text_Write5 Q. k; l1 s1 m# C: b" u
- RTS6 _2 k# L H- \ d, t# O$ p
/ ?; d3 f( a+ R; @; R! w1 Q+ H- ;==============================
; N9 j2 y c' R1 Z# h( y2 D - Init_OAM_Ram;初始化精灵内存+ \/ B6 c( C7 \$ w
- LDX #$00
2 i2 x8 f' g: Y. q2 E - LDA #$00% S6 d! K: m) h0 J, `
- STA PPU_OAM_ADDR
% r/ _( ?9 o: h: n$ L - LDA #$F8& |1 K: n5 Z4 }
- Init_OAM_Ram_Write( q( e- _7 K! t y# u
- STA PPU_OAM_DATA" L: K5 _% c3 ?: R5 t$ x4 W, _- N
- INX' U( e9 u: l2 F; M3 V
- BNE Init_OAM_Ram_Write
% C* h' u5 W/ L - RTS1 w9 m2 h. X2 H
- / I# d9 u; z) c7 s" `% O4 C
- GamepadProcess;手柄处理
5 ~: }7 U6 v- { - JSR GamepadDatacan1 F7 T4 K; ~% A8 ?5 E! c/ \9 a
- LDA <Gamepad_0_Value
Z. b6 ? m& R0 { - STA <Gamepad_0_State) F, |# J7 g7 A7 R
- LDA <Gamepad_1_Value
/ v4 ~. S+ r* V: O - STA <Gamepad_1_State
# J! o* R# D# @0 X - JSR GamepadDatacan
2 l1 N7 Y5 J" N8 o6 i; x$ Y - LDX #$01
- W$ \/ W ?- s9 U- V - GamepadMergeCheck;合并手柄输入检查7 Q* Z A9 _+ Z& v2 Z
- LDA <Gamepad_0_Value,X, h5 _( b) J, C3 s' S/ b
- CMP <Gamepad_0_State,X+ U1 Y6 L4 ]8 [
- BEQ GamepadMergeInput
# O% A* R/ {4 E) |5 ?3 l - LDA <Gamepad_Temp,X
+ ?% Y" d! D0 y - STA <Gamepad_0_Value,X
) W' S5 K d' y- { - GamepadMergeInput;合并手柄输入7 M% l1 T7 p; h& e( X9 E
- DEX
2 d) l0 z1 y) _, \ - BPL GamepadMergeCheck+ k; f) i2 [) _/ k4 A! R$ G5 n1 u3 ?' ]
- LDA <Gamepad_Merge
( Z( Y4 f) ?3 o3 b8 I - AND #GAMEPAD_MERGE_FLAG- C* z& r9 Q; o' T
- BNE GamepadStateProcess
) n) o! |2 o3 q& o1 y - LDA <Gamepad_0_Value
; K2 h" A, W1 y - ORA <Gamepad_1_Value
% `5 m% t. L$ y2 D5 E5 B# q1 ^9 r - STA <Gamepad_0_Value& V$ r: o. v/ E
- GamepadStateProcess;手柄状态处理
$ [/ D2 @2 [. N X - LDX #$01& s4 D: b, @( m1 J. ^& l* b/ e+ H
- GamepadStateSave;手柄状态保存1 a9 q# z! F" T& T
- LDA <Gamepad_0_Value,X
1 \3 `- q: s2 q+ n& W - TAY
& L" V( o N. r3 \# B4 P - EOR <Gamepad_Temp,X
. G% ]* W. x1 t/ y3 f/ F7 Y4 @ - AND <Gamepad_0_Value,X
! G% I1 e, [$ a% a1 w, K. P" t - STA <Gamepad_Once,X
+ y4 w$ j9 F9 h6 ]& J5 I# T - STY <Gamepad_Keep,X$ ? U! p, Q7 v
- STY <Gamepad_Temp,X
0 C$ O. K: d/ n! D4 \# A- w9 { - DEX1 z& B0 R' W) u, w! t0 Z0 x: ^/ m
- BPL GamepadStateSave$ i6 Z4 ?& K, B# j# @
- RTS
8 `8 t' K: _# p% C - ( D, C3 n6 g1 B0 s n* ^) k+ y7 s
- GamepadDatacan;手柄数据扫描
9 R8 l5 K4 P3 t; f% o! i - LDX #$013 W' n/ S# r& [' m4 D e
- STX $4016
0 H# E! a! w; R( n/ ]* F - DEX
6 ~" e* S1 g" F- k8 m" @. }' g - STX $4016& i9 k! C g% A/ q9 X% L
- LDY #$08
0 S& T w" I1 Y. [ - GamepadPortScan;手柄端口扫描' ~" X3 ?$ T9 r- o# B; ~0 [% ^
- LDA $4016
9 o3 h4 Y. g8 F& ]2 A. O% y/ g5 l1 p% p - STA <Gamepad_Port_Value
: U9 V0 m ?9 y9 m - LSR A
5 r5 F- i5 G& d - ORA <Gamepad_Port_Value
5 `" A" `0 S$ ~1 }" e2 M6 P+ s - LSR A
' `* N6 g6 N4 Z$ { - ROL <Gamepad_0_Value1 h9 s( A5 C1 P6 X: i" w
- LDA $4017
' R. t6 P% A8 q/ N7 D, l0 | - STA <Gamepad_Port_Value1 F5 `1 P. |6 c" O- f
- LSR A( i$ [! _" b( x! |; ~5 W
- ORA <Gamepad_Port_Value, n- r9 c" {8 u+ g
- LSR A5 X u1 p n. f
- ROL <Gamepad_1_Value
l8 ]8 ?! Q- _3 f. Y. i0 f - DEY
: @+ c. ] j$ _9 f - BNE GamepadPortScan
0 s9 j1 L. e7 L7 [( T) d2 q - RTS
- d, B( [/ z3 K' m& L9 s+ M1 y ] - 8 J9 ^' g c2 Z5 q7 ?0 Y+ p
- ;==================================================
) c+ f. V9 N; O% V/ l - ;PPU处理
5 O, ?0 N0 u3 K9 P+ Q. Z7 R - PPU_Process
& y) U' L$ V: F: Q$ `6 w - LDA #$00
: i& |* L# U L1 C4 T - STA PPU_MASK
5 a. k- L9 n/ B, q$ }) c - - t1 K2 l( H3 A
- BIT PPU_STATUS
- d: [" i2 y% Z0 i - LDA #$20, V: z1 j% G, ~) K- R
- STA PPU_ADDRESS j) n6 [9 t3 q
- LDA #$00
2 t4 O& i. I4 L2 V6 u; A - STA PPU_ADDRESS( n9 G# P& m& h6 m
- 7 m1 I, A3 u$ A% C- \9 k
- STA PPU_SCROLL" s0 I- c. K- J4 L
- STA PPU_SCROLL7 t% r0 {' M: N0 \
- 4 Z8 m: f6 M, e! }/ l7 k: Q2 m& {
- LDA PPU_Msak_Buf
: T8 x; {% h6 C" K0 e7 Z - STA PPU_MASK
! R* ]" F1 T; l - 6 @6 k; \( Z. Z8 N, Q' Z" w
- RTS" f$ P! b# p3 I9 K3 I% m2 [. U$ t0 b
- 7 R6 j0 p! `! H' H& B" x
- ;==============================4 H- }6 G3 H: `; X
- Time_For_Vblank;延时等待" ?, X3 I' J- e% d3 @; U
- LDA PPU_STATUS
8 f0 k' `( D' a+ a5 v - BPL Time_For_Vblank( a4 z1 R# {1 a4 B; Z
- RTS& N0 o& U' j& m( ]
-
0 ~. l3 C& I/ t+ y- H n, q - ;==================================================8 l( X9 U) O, L( b
- ;初始化MMC5
8 ]: Q5 `/ ]$ e2 Q) K. C3 M - Init_MMC5
8 ~. F; b2 z3 L
) f6 e) T: R- g0 J' F% p+ [" u- ;设置一下6000-7FFF的RAM$ R" w& }: w2 v2 W
- LDA #$00) \$ y' n" }# f" r* }
- STA MMC5_PRG_BANK_6000
1 k0 y: O- y! H8 X& e L -
9 L6 Y" ]4 {+ [: G9 ] - ;开启 PRG RAM 写入
, W* ?( [3 n1 ]6 R - LDA #$02* J( a7 X; }! i+ j/ O
- STA MMC5_PRG_RAM_PROTECT_1
, Y w% a$ g% `9 m - LDA #$01; S( Z+ c& R, S1 {
- STA MMC5_PRG_RAM_PROTECT_2
) T/ { B4 V1 n/ ?# s - 5 m5 H- L- i8 d+ j
- ;启用 1KB 扩展RAM ($5C00-$5FFF)
( Y$ F( }' ]5 d4 a6 ? - LDA #$02
" C6 X4 V2 c. M1 H0 C4 ~- Y8 N7 H - STA MMC5_EX_RAM_MODE
% [/ M- Z, v: H2 g- A ?5 i+ l - 6 w8 ]: |6 C4 o }- k
- ;设置 CHR* Z ]: R% f b' A/ v
- LDA #$00( _1 P4 H% ^: z/ R& M
- STA MMC5_CHR_BANK_0000% N. K3 P' I+ a! b& \7 y2 E* x) K* J
- LDA #$01
8 A4 [+ _* d! X' v4 Z! N- J7 \ - STA MMC5_CHR_BANK_04009 _/ ?5 A) X* v. Q
- LDA #$02
" _& @: s4 V/ I$ W - STA MMC5_CHR_BANK_0800
4 c& B4 C% Y; K- A - LDA #$03
% `& A5 |& K( Q6 y7 @3 k - STA MMC5_CHR_BANK_0C00
' ] T( O" i4 |2 J% q4 { - LDA #$04
! P3 B/ Z$ v4 |1 a - STA MMC5_CHR_BANK_1000
. z3 I9 ~! I( k2 i! K. `' s3 i/ J' [3 H - LDA #$05 `7 `. v, Y, V+ D9 ~
- STA MMC5_CHR_BANK_1400. n( c8 \7 ]+ k2 `2 Z+ @* \, M
- LDA #$06
% {- p: }+ o& g; [: c - STA MMC5_CHR_BANK_1800 V, _3 t- c4 t! n
- LDA #$07* L! @7 H2 T/ A& H+ L' w
- STA MMC5_CHR_BANK_1C00
K* D; R: n# t# x - - m* ]/ c: U2 r, G6 a
- ;设置屏幕镜像
( a/ o# F( B+ J9 Q: K' V - LDA #$504 i) Y6 k; k, z2 e2 X0 E( w8 h
- STA MMC5_NT_MAPPING6 F3 I! q/ L4 d3 H' S( z- M/ r1 o3 X F
- ^; E7 N' W2 w( D
- ;禁用IRQ" I' b4 ]# H5 f5 p% v* X |
- LDA #$00
: N8 C3 F- \ {, ~$ A0 x) s, i - STA MMC5_IRQ_SCAN_CMP
, E8 |+ p0 @ S, l# q7 S! V/ O - STA MMC5_IRQ_STATUS
8 r8 V7 P: y, P -
. m7 @. o% I/ q1 G - RTS' D( u) G4 r4 p" S2 a9 j: O6 y
- ' h: W* j( e9 H, o$ @
- ;==================================================
5 f4 R8 Q) E. W/ Z$ p j - ;重置中断处理
4 U- p0 ? a0 p' z% e; H - ResetProgram
7 `0 A# K; C$ C$ l# ~3 K& l$ d - SEI
+ S. `& i6 r/ y1 `* X - CLD
- v& a/ x! L6 a - LDA #$00 l d; u+ n; |4 i
- STA PPU_CTRL; {1 A w( V; {5 _3 u* b! O8 G# G& O8 I
- STA PPU_MASK
3 V9 _ Y5 i/ F. P. R6 P0 [ - STA PPU_STATUS
" T, ?$ ^5 e% ^3 f( }2 Z7 b, O; ~ - STA JOY2_FRAME/ n; q' n3 }8 N
- STA APU_STATUS
+ g" O' }- s/ } - 8 X: l/ ]9 W' v3 U' p) A. a
- LDA #$C04 v0 L6 A- \5 M& e, o
- STA JOY2_FRAME
2 Z2 N7 p0 v% F% I, N! N ^8 t - $ ]/ H$ ^, Q8 a" J. ]3 y
- ;等待vblank7 \. \4 I( u. Z" n0 @' B; G: f
- LDX #$026 q, A* R( ~) q; t3 H2 r$ i
- Vblank_Wait_1
6 ?( O% u8 q5 W% o - BIT PPU_STATUS3 i* {1 F5 J1 \6 d: Q
- BPL Vblank_Wait_1
I' E/ M8 G5 P/ }. q - Vblank_Wait_2
) j9 K4 B+ @4 [5 R6 k - BIT PPU_STATUS
4 Y; r" S3 X$ @( K) a- ]0 Q9 r9 I - BMI Vblank_Wait_2* d, X) a' q( Y. r% l. x
- DEX# `0 L4 r9 [' x9 g( [
- BNE Vblank_Wait_1
( S& o2 ?! ~) l: m8 J! C9 A5 q# k2 c -
. S) T- k6 x: s - LDX #$FF
/ B+ Y4 c9 a/ T$ x - TXS1 x# S2 ?% |1 Q C; U' U: a
- e2 m% q# z: a. v
- ;初始化MMC5
1 K( v$ _; P$ Q - JSR Init_MMC51 ~* r& m# J x: A/ m
- 9 h5 p/ \7 ~ V9 c( [9 X& X
- ;==============================
! y8 b4 C) ^, y# d8 U$ H - ;RAM初始化( B: W6 D3 C) Z0 _- U H/ {
- Nes_Ram_Init* T) C4 ~* R; ], @/ J: g0 ^( `
- LDY #$00, @1 |9 V7 S: g) {2 z8 Z/ o0 s
- LDX #$08, P1 P( h$ W7 Y9 t
- LDA #$005 W6 ~: `0 E' u9 d0 E2 K# _; z
- STA <$00
J- Z6 r& a% ^9 l; j' u - STA <$01, G: y. ]! j+ P p1 r1 n$ I$ R4 K
- Nes_Ram_Init_Write# l7 n ~6 q" X, _+ `
- STA [$00],Y, J6 Z1 z2 C' ~/ y0 p1 u+ E1 e& ^
- INY
, a& t2 }+ \5 w - BNE Nes_Ram_Init_Write: W- [ P0 s; P' A" t9 b7 b4 L
- INC <$01
. x9 i! f3 n6 J. D. e& } - DEX
- Q. y. W1 R. O. O7 {8 m - BNE Nes_Ram_Init_Write
5 E/ G7 U# S5 i) ^1 t -
. C2 b, ~( o# ]! C - ;初始化命名表 V! z' r5 t! r- N. F! a/ ~
- JSR Init_Name_Table8 x# \; J! O* v- C9 o2 f
-
+ u( U6 V3 ^- T - ;初始化调色板9 O, v, T" L) i3 a; h0 o/ f G
- JSR Init_Palette% c* X4 _! g3 ^1 f: g
- / j' l! w( T" Q5 ?$ N' X
- ;初始化命名表属性' ]4 k* w* `% c6 ~' B/ q: Z. S
- JSR Init_NameTable_Attributes: \' Z( b5 c; k; |* h
-
* y5 q8 H" `- A7 O( W/ u - ;初始化精灵内存/ g h& C4 D* S4 K% A' u
- JSR Init_OAM_Ram
K8 X) I4 p8 h -
; l0 G# p) x$ w. S$ b - ;在屏幕上写点东西4 w6 O V& W' B" {7 I m
- JSR Init_Name_Table_Text
) B& `* P( P" v4 d! t( L2 h - 7 Z5 Z8 f" D4 o$ g) K$ w
- JSR Time_For_Vblank
: S" M& @! n$ Z- A& B1 ?* h - ;开启PPU控制# Y) g2 e% T1 l6 Q
- LDA #$88
6 m% Q. V. n- n# l - STA PPU_Ctrl_Buf- {7 Q2 c* j( X7 B; I
- STA PPU_CTRL
" ~6 h1 ~ \- g0 q9 c* @ - " n) N0 V% x4 O. |9 {
- ;开启PPU显示
' [& j1 u; ~' n8 `5 |: x0 q - LDA #$1E9 |7 a# V3 S J6 w8 M9 k: ?! a* h3 {4 m
- STA PPU_Msak_Buf
6 _0 N' q0 w2 J3 v) j g" u" M - / N: c4 B3 C- N5 |4 |8 h
- CLI$ G; ?& ^: z6 o2 Q
- JMP Loop
+ z( ^8 X4 x1 k# R' o9 V* X4 A - 6 C+ `. O; s* K1 ^# v
- ;==============================8 t9 ^' C8 Z6 `+ k$ ]" Y$ R6 w0 k
- ;死循环, 等待NMI中断
% j. x. A2 X' Z3 E; L) }/ e - Loop" U' @- j" c3 [5 \- n6 Q
- JMP Loop
! A; @' Q( t) g& z V8 } - 9 P* r c f7 C( a( ~, u$ ^
- ;==================================================
\: S S/ a/ H+ G6 g' j - ;NMI中断处理
' c$ Z2 Q+ V$ K* t1 z. S - NmiProgram# A# Y; H4 Y3 ?; ~- z/ [7 ]1 Q( L+ [% b J
- PHA9 h- c& B; v4 B+ {2 W6 b$ p
- TXA5 T% ~( G& Q6 ~* _& T' A& a( j7 ?& t. m
- PHA
. Z+ k# h4 s! ~; }+ Y+ b9 a - TYA
. V- r% ~% d+ V/ p, g& H7 a - PHA
* z0 r3 [) R5 b. b. l! a+ { - ) J: }0 Z8 }% V1 N. Z% \4 P6 U' R
- BIT PPU_STATUS
. e1 p' f! W6 n - + `' O2 H$ Q/ C
- ;启动IRQ中断, 第16条扫描线触发: S6 ?- h8 ?, t( I
- LDA #16: R1 f9 B" b% C5 g4 _, s9 [- T
- STA MMC5_IRQ_SCAN_CMP
+ J# S4 s% o+ M- A: d% F- j - LDA #$80
3 A, m+ W; c+ a s2 u - STA MMC5_IRQ_STATUS) X6 t% c( k6 S* d7 p) w& d; T
- CLI3 k- L& V4 J; _( O- ^2 }
-
' s, k4 N9 r0 ] - ;关闭PPU控制) _; e* W1 ]7 F' J
- LDA #$00" H: s! {8 m; {' o& V( R. Z* E1 Z
- STA PPU_CTRL# {: }. R" {, u7 g
- " [! p& |1 G+ m$ O* J* \3 p
- ;处理PPU
4 z; {! U! R/ }9 {$ x9 p1 _ - JSR PPU_Process
( v! d& g/ r. W$ V. @; J -
7 e& ^9 U9 Q* w# j' o6 A5 l0 [3 c - ;开启PPU控制( p9 `9 `' T) G" e8 F% o
- LDA PPU_Ctrl_Buf" ~7 a2 d. j% C
- STA PPU_CTRL
* M6 F, q5 |; h! S X( J1 W. r0 l- l - 8 k D1 S; R7 T! m8 y1 L) ^1 P3 _
- ;手柄处理9 }0 W9 Y* f9 z. K9 S2 Y Q
- JSR GamepadProcess
5 g6 u4 K- S8 \9 K7 g+ B# c4 Z -
) p# \+ @/ O, e' j' S - LDA #$00, P* W; ` r6 J6 V; u% V7 T
- STA IRQ_Index
2 f8 Q2 {6 G+ _7 G% n - . _: ~8 z6 n4 @, Y c) [
- PLA" M+ ?) G$ T3 G
- TAY- Z* w e0 r* S$ H# S% r
- PLA* D, A- v5 S$ n4 L% V: x' I) u' f
- TAX
$ y$ o0 ~* {) N9 ?/ M/ ~8 N - PLA: ]- C4 U* A" m8 ^2 f
- RTI
' N5 `( k% n Z2 V) m$ a" q2 I5 ?& a
$ e- n6 z2 e! G( _- ;==================================================1 Y0 _0 D* o0 H8 |" `6 i& ^' v& P; U
- ;IRQ中断处理3 F O" w% w7 y8 a9 K8 T
- IrqProgram
7 `; Y; n" A8 z! j2 g9 B - PHA! b3 Q/ ~6 j' ~
- TXA/ j& G0 X$ t% K0 A5 w+ U$ X
- PHA
$ s7 G+ c3 t$ U' X - TYA6 Z: D [" v1 Z1 ?, R, |& z
- PHA! V* J+ z; f: f# ~. ]( S
-
" n* X" [& I% ^1 V+ e6 R5 ^" {9 o - ;确认IRQ5 y2 P# ~. E8 z7 V0 o& i3 ~
- LDA MMC5_IRQ_STATUS4 x+ L5 L; }2 n6 w8 I
- 3 U* R8 k5 N+ h n( s7 ^; f8 y B
- ;允许下个IRQ触发7 v' ]5 d8 O& o9 n. _5 a- Y
- LDA #$80
- c+ ~4 _. d! _: Z/ g1 h* _2 Q& F - STA MMC5_IRQ_STATUS
2 Q0 t$ w' M% C0 A7 S - 9 {2 e1 }4 ~- W& Y' b' e ]
- ;IRQ处理, 每隔16条扫描线触发
/ Y2 c6 J$ h, G/ h; U, g4 ]9 g - LDA <IRQ_Index( a4 O* ? K/ H& A' A
- CLC
! T) N" m: e4 G4 T6 m& l1 x" W9 J - ADC #$027 f' n: U/ W0 W# o1 M( D( c' v$ @
- ASL A
, S$ \/ @+ x" W/ `; Z* { - ASL A4 u. b$ H3 ^* i# i- l% \7 n G
- ASL A7 o" o5 P/ ] j9 X \
- ASL A
/ M0 }5 r# e& D: g( e9 \ - STA MMC5_IRQ_SCAN_CMP8 p! G; D8 B# }6 r4 ` n
-
. T' Z3 q/ x. Q - LDA <IRQ_Index
2 u- d, {8 U/ l0 G& J& z1 r - BNE * + 48 S, k6 i1 x" K# s+ [+ ~: E5 h
- INC <PPU_Scroll_H! i9 I# f1 P( y; y' b
-
5 q2 K3 H) q$ ]9 T8 b; @6 A - ;设置屏幕滚动
* Y0 q; _4 _+ B4 J4 P - LDA <IRQ_Index y% O5 S+ _$ I
- AND #$01
* ?9 h, I, g' A$ R - BEQ Irq_Scroll_Right
% J4 o& `/ r' `/ y7 ?
7 q' D' V1 c! R! D( }) l% ^6 ]( z# u) A- Irq_Scroll_Left# Q# [( D' B/ z
- BIT PPU_STATUS4 ?) C/ i$ N: P' T" T+ P3 a& ] P
- LDA <PPU_Scroll_H' H4 N- M5 t; W l/ H3 }
- STA PPU_SCROLL
4 |! v8 T! T1 D2 s |) c - STA PPU_SCROLL; S) m! y$ Z" b" a! y7 t
- JMP Irq_Scroll_Over8 r6 e( a' O0 m2 y
- , j. P& [$ u- `
- Irq_Scroll_Right3 Z/ h3 k! |4 {% O7 h" m
- SEC" I, i8 g5 t+ }! {4 z4 P( a/ g
- SBC <PPU_Scroll_H
# Y* L. h5 h& W, p! w. W0 _, A - STA PPU_SCROLL A' q& M- `2 g, r
- STA PPU_SCROLL
9 ~2 Q6 d% W2 }5 N - Irq_Scroll_Over( I! S% y/ _3 R
- ! u W: z# K0 l
- INC <IRQ_Index
% a8 X& c) K, N; P0 a - / W* i# m# {. Z3 {
- LDA <IRQ_Index5 h& M0 @, {6 O1 {% @, X( G
- CMP #14- A' }( Z# D U9 u' {' Y r- J
- BCC * + 5- ?7 c- C( f+ [) _- J# E
- ;关闭IRQ
& p9 n& d: |3 P- w- K& Q - LDA #$00
# R, z2 B( M0 `* y2 } - STA MMC5_IRQ_STATUS$ U% p* u& |3 j& d
-
* \) j, [* I3 H9 H - IrqProgramEnd
/ a( }9 K2 k% x% o% K - PLA
! J; B! N6 f) z5 {+ ? m$ L - TAY& d% W; N' @4 Z$ X# P" ^ M7 k
- PLA4 J$ {6 N0 ^$ [- U
- TAX
" U0 q/ P- v2 _7 z - PLA
+ E+ Q! [# Z: E6 \3 ~! t/ ]; |, I - RTI
2 v$ l5 B! n# A3 D3 f -
1 }1 n# ]' v) D; H4 b" _8 V - ;==================================================
; o; |2 ^! B' _2 P4 j6 M: S8 } - ;中断表
- M; l, O6 W+ O - .ORG $FFFA) J* P0 p$ B% L6 U& a/ @ A
- .WORD NmiProgram
' @% `. _& A) U9 o( h7 E$ i# ~ - .WORD ResetProgram
9 U8 Z' m' \. Z) M! o" E k - .WORD IrqProgram
复制代码 , _6 X: m- l! p/ Q) a0 d# N
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|