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