|
- [code];[FC音乐][MMC3 IRQ]: e/ s z9 a* g( O, c9 v
- ;FlameCyclone 20230710
( t- e9 d/ z4 y5 B/ | - # M; b" t4 K8 z& x+ n
- ;文件头
/ [ M# ~4 L- o3 R - ;======================================================================2 q9 b! O, J4 Y% |
- .INESPRG 4 ;16KB PRG 数量
0 ?( |. O H$ m3 w - .INESCHR 1 ;8KB CHR 数量
$ o4 c8 @% y( r: r: a! e' p# |; ~7 c - .INESMAP 4 ;mapper 47 p' M k3 d5 V7 X- z6 D( |2 f j
- .INESMIR 1 ;命名表镜像 0水平 1垂直
5 ^2 k* B& M. i* f; u
# B1 J; j2 H Z3 ]& T- ;必要条件
5 n) g* J% M& U% F7 j+ j1 h - ;1.持有CHR ROM6 }% p9 \% T' M# u
- ;2.背景Tile和精灵Tile必须使用不同的图案表, 如背景图案$0000, 精灵图案$1000
9 c1 z* S) n0 L7 Q3 G3 a1 m- W0 D - ;3.精灵内存(OAM)不为空
# f A+ e, Q: p8 a* i W4 R
- o& B- p" x4 a+ |2 b- ;==================================================
6 d2 Y7 f3 b9 D$ D1 h - ;NES端口常量8 O: h- \4 y R" T
- PPU_CTRL = $2000 ;PPU控制寄存器! W) a9 W+ \( H Q
- PPU_MASK = $2001 ;PPU掩码寄存器' Q7 \' e" x5 t+ Y; s
- PPU_STATUS = $2002 ;PPU状态寄存器:读取后PPU_SCROLL和PPU_ADDRESS被复位,下一个写到PPU_SCROLL的数据是水平的,写到PPU_ADDRESS的数据是高位
, a" N- q' Y* x+ @' s6 z( R# K7 m9 Y - PPU_OAM_ADDR = $2003 ;精灵RAM地址:用来设置通过PPU_OAM_DATA访问的256字节精灵RAM地址。每次访问PPU_OAM_DATA后该地址增加1, A2 d. k% Y. u* b' N: o/ E+ n
- PPU_OAM_DATA = $2004 ;精灵RAM数据:用来读/写精灵内存。地址通过PPU_OAM_ADDR来设置,每次访问后地址增加1# H) Y; Z% K1 O
- PPU_SCROLL = $2005 ;屏幕滚动偏移:第一个写的值会进入垂直滚动寄存器(若>239,被忽略)。第二个值出现在水平滚动寄存器 : N" D% F; Z' r# O
- PPU_ADDRESS = $2006 ;VRAM地址:设置PPU_DATA访问的VRAM地址。第一个写地址的高6位。第二个写低8位。每次访问PPU_DATA后地址增加/ n6 F! V) m6 |; M8 K! A! y
- PPU_DATA = $2007 ;VRAM数据:用来访问VRAM数据,通过PPU_ADDRESS设置的地址在每次访问之后会增加1或32 S; k/ _& \+ |. C9 e
- OAM_DMA = $4014 ;DMA访问精灵RAM:通过写一个值xx到这个端口,引起CPU内存地址为$xx00-$xxFF的区域传送到精灵内存6 X4 J. N' y0 n: i4 R
- APU_STATUS = $4015 ;声音通道切换7 v4 }" v- X( Z c# x
- JOY1_FRAME = $4016 ;手柄1 + 选通
4 f3 `, K. P% p/ H( ]5 h - JOY2_FRAME = $4017 ;手柄2 + 选通
) q7 O& M5 E" d x3 t
- `2 M0 X: L/ `$ F# c/ o" ^/ x- ;==================================================
) P* q& }, R4 l( J6 E2 Y' y - ;MMC3端口常量1 F. F, F, G* ?. p$ d" j( k
- MMC3_BANK_CTRL = $8000
+ ~* ~' B! J8 t- G - MMC3_BANK_DATA = $8001
' a( C- x3 n) |" Q - MMC3_MIRRORING = $A000 ^" f6 D7 }6 x6 s
- MMC3_PRG_RAM_PROTECT = $A001/ N9 V5 B6 {9 T/ l% ^2 u& Y# ]
- MMC3_IRQ_LATCH = $C000
& F' l) ~* ?& ~& ` w2 Y7 p+ d - MMC3_IRQ_RELOAD = $C001
. @& ^/ M+ g5 n, C0 d2 V9 o - MMC3_IRQ_DISABLE = $E000
, Y) _8 t5 U. E - MMC3_IRQ_ENABLE = $E001
0 F# @ m" E! U5 ~5 Q' K) d - 9 E( E8 K% Z. W7 a6 l9 u. x& O$ R
- ;==================================================5 J+ \- ^4 W8 J$ q% |
- ;程序块配置/ l, _6 v/ b6 a1 p/ }+ e
- BANK_DATA_MASK = $07) N1 Y. t2 n2 _8 I* a/ [
- ;--------------------------------------------------
. c3 C; k: F/ G$ r; P+ C - RESET_BANK = $079 P# e. Y5 y" g: {. M2 J
- RESET_ADDR = $FC00. C. a8 b$ j' N, y3 l
; X3 i0 |( Z k6 m" W5 t# x( ~- ;==================================================- H( [$ y( g8 n1 T. X
- ;图像块配置2 M5 l. g; r( B7 Q* U6 v/ `" o9 |
- CHR_DATA_BANK = $08
/ Y* e) d1 Q3 p1 V/ A
. R1 t9 V3 {0 Z3 h/ |8 x6 P- ;==================================================9 I, t7 W+ a% J3 p- A7 h, c
- ;零页内存地址配置
& s2 `! ], ~3 T/ w - Use_Ram_Addr = $80/ J" J. C d+ N8 z8 z
- PPU_Ctrl_Buf = Use_Ram_Addr
8 M8 |# \0 O, f V8 y - PPU_Msak_Buf = PPU_Ctrl_Buf + $01
5 P4 `! s" m ~- H: I - PPU_Scroll_H = PPU_Msak_Buf + $01
/ w1 n% i) G% H0 h2 f - PPU_Scroll_V = PPU_Scroll_H + $016 S. x" H/ F7 m0 B% l
- FC_Data_L = PPU_Scroll_V + $01
# C0 }0 T; y1 J/ n" n* v - FC_Data_H = FC_Data_L + $01, k, F) a3 d! M* m2 N, G9 [& y8 `
- FC_Data_Buf = FC_Data_H + $01
+ L1 [- W% O8 \) l - ;==================================================
, N; _3 P' V2 y! ]: c; a; b
$ O$ ]+ W& o& E& Z1 R V/ Y) ^- GAMEPAD_MERGE_FLAG = $04$ O% p! R2 x) w a/ H, y6 l
- 7 [ Y) Y* ] |% ~% a- {+ T8 I( K
- Gamepad_Keep = FC_Data_Buf + 1
- g3 H- ~' i4 Y H# r' ~ - Gamepad_Once = Gamepad_Keep + 2
7 P: w* ~! n$ {! C - Gamepad_Temp = Gamepad_Once + 2% u8 s' W* D$ \3 {# F0 s- C
- / m8 Y. y3 r# B" P( D9 z
- Gamepad_0_State = Gamepad_Temp + 2
) p- U' M$ N3 `! z* E# @ - Gamepad_1_State = Gamepad_0_State + 1
9 `; k8 r Z/ f - Gamepad_0_Value = Gamepad_1_State + 1
: [2 Q8 ?, V) i9 B0 s+ v/ r9 N - Gamepad_1_Value = Gamepad_0_Value + 1
% o% b+ y+ N3 \1 X8 i; F* r) d - Gamepad_Port_Value = Gamepad_1_Value + 1+ D v+ E' [! B5 T W; U
- Gamepad_Merge = Gamepad_Port_Value + 14 o7 g+ b- l+ G3 k
3 V D! P! R2 s3 q% h0 F9 B- ;==================================================
" N {% J2 y: m( F - IRQ_Index = Gamepad_Merge + $01
) f& W: I* m6 r( X$ c0 q: y - ;==================================================3 z% Y1 l5 y) W8 n$ K# j
7 u8 E7 S: q0 e5 u$ I& x- ;CHR图形数据
* n5 c3 P4 X4 F0 S& _2 N0 d' w - ;==================================================" s0 p) u, L/ K# H
- .BANK CHR_DATA_BANK+ }: x) t0 Y( f' g: l7 T
- .INCBIN "chr_bank/chr_data.chr"+ A4 M; r4 Q2 {
-
: Z/ O4 n/ p7 x+ ~, P - .BANK RESET_BANK & BANK_DATA_MASK
6 ]* |* p4 _7 ?# S3 @8 Z9 L - .ORG RESET_ADDR
! ^% A' e [* q -
5 j+ u9 ?( v" _% H - ;--------------------------------------------------
& t6 J( {5 z* Z7 O! _ - Attributes_Data
" g) ^5 f8 P2 s, T, o - ;命名表属性7 @8 z) t7 `: `# A1 _
- .DB $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
l( ^5 ]2 g; E3 k - .DB $50,$50,$50,$50,$50,$50,$50,$50,$FF,$FF,$FF,$FF,$BB,$AA,$AA,$AA
% f% E# Z+ w& p, A( V( x/ c% G1 i - .DB $0F,$0F,$0F,$0F,$0B,$0A,$0A,$0A,$AA,$AA,$AA,$AA,$AA,$AA,$AA,$AA
& _* ?; N8 k( ?5 }- m* M - .DB $AA,$AA,$AA,$AA,$AA,$AA,$AA,$55,$55,$55,$55,$55,$55,$55,$55,$55
8 J- v4 ^& H3 b - ;--------------------------------------------------! e2 i$ E$ J+ p! M# {: |, ]
- ;调色板数据6 d1 |! k7 {) b2 I: D
- Palette_Data- \+ B8 E: j% O1 |0 L% J' G
- .DB $0F,$27,$20,$0F,$0F,$24,$20,$0F,$0F,$21,$20,$0F,$0F,$25,$20,$0F
. o+ e+ w% I! k - .DB $0F,$24,$20,$0F,$0F,$24,$20,$0F,$0F,$24,$20,$0F,$0F,$24,$20,$0F, |$ h5 y3 \/ B" k' W8 K3 ?
- ' S2 x: ]8 l+ y* r9 e( L
- ;==================================================
6 u! q$ ~7 U l - ;命名表初始化
& k, |0 V: ^5 ~1 \' M - Init_Name_Table
* }8 g2 ]4 r* j8 G - LDA #$205 s0 c( ~- ^8 f2 A, l
- STA PPU_ADDRESS
6 z6 }, Y; Q1 G# u. D% U( \ - LDA #$00% ^: U: C, T, e% j3 w' m6 g f
- STA PPU_ADDRESS# _6 U+ t7 X. o) V& t7 Y
- LDA #$00
* }# [, L& L0 y+ A! v - LDY #$00" l3 D+ h/ `' ]/ W) b c1 k) Y1 I% s
- LDX #$10& u* ~$ H) s* W
- Init_Name_Table_Write
1 F3 E. u% Z+ P" P. J J1 V - STA PPU_DATA }8 s8 _/ A0 D6 o
- INY
5 f- n- ^5 h( u( o2 { - BNE Init_Name_Table_Write: }) p4 z1 X# w) Q% }
- DEX/ i, I; w8 c0 s) Q
- BNE Init_Name_Table_Write( ?) c) g- T1 s* W
- RTS9 i+ b* k9 R# l9 L1 u: B' C4 G
- , G5 b h4 N* l% t1 k V6 C
- ;==================================================
: @/ P# M8 ]% E* ?% B# }3 f - ;调色板初始化4 q0 o5 G; C/ Q# @: ^$ Q2 h
- Init_Palette0 z6 h' p/ J1 ]% b) K1 O
- BIT PPU_STATUS0 c& z) P5 J- G% T0 S; I5 w
- LDA #$3F Z5 N3 L6 T" K- a9 O3 h) D
- STA PPU_ADDRESS% `4 u- d( X" f
- LDA #$00& w& ^3 j% ?4 c4 z
- STA PPU_ADDRESS
0 Q E- x" r+ z# d - LDX #$00
( Z- E) f( g" y - Init_Palette_Write) M6 @5 I9 v3 V( ]. i; d
- LDA Palette_Data,X+ T9 C. P+ L% j$ y
- STA PPU_DATA; B3 U0 n; m% Y7 c& x+ i
- INX
- A9 d: ]3 x3 S' C- j8 p0 b$ c - CPX #$203 C& c/ I! U8 V( @( c
- BCC Init_Palette_Write
5 n0 f, b0 g4 B, N' H) P3 a6 w - RTS
- C6 @! C( X% F -
% e- v5 T' |' g; @% ^* `9 L - ;==================================================
' `2 p6 k6 E( Y - ;设置命名表属性( ]5 y& |3 H3 q% w
- Init_NameTable_Attributes i) }, @$ O, T
- BIT PPU_STATUS. ?8 B/ X* c2 W* G. a
- LDA #$23
' b# s( U8 k3 Z - STA PPU_ADDRESS# U& K5 O2 J2 ]1 X: t
- LDA #$C02 @+ ]4 V9 v6 ?+ [- W1 g
- STA PPU_ADDRESS
( E8 f6 [: k/ e: E* o - LDX #$00
$ L/ R" F" `, j6 m$ x* p: J - Init_NameTable_Attributes_Write) \; H4 k) R y9 q# k1 S6 Q7 E
- LDA Attributes_Data,X" o" P4 ]% t0 y3 P6 B* C* C+ |
- STA PPU_DATA
+ e- m' Y1 ^1 I9 ] - INX" m/ c" L6 c4 ^2 h- a/ Q
- CPX #$40* m0 [. E/ U) ~% d1 `
- BCC Init_NameTable_Attributes_Write
' B' o5 w+ W3 K D# E+ I/ o - RTS: ~* m/ k ]7 P
- ' @% o$ @/ P1 g. _9 D% l
- ;==================================================
% f! | Q( R8 t5 H) G' @ - ;初始化命名表文本
q; q- L1 L( j6 _2 C7 d - Init_Name_Table_Text
3 G- h! g9 c. H _* K - BIT PPU_STATUS
. e/ }# ?, v4 p8 i( V - LDA #$20/ |7 X- j3 T9 v- y1 G. Q( S
- STA PPU_ADDRESS
& ^/ P, B. c# E8 E - LDA #$00
: W( I6 b$ ^5 u6 t8 ?5 J( z - STA PPU_ADDRESS
8 a* ]' ^# G! f- { T: P - LDA #$00
- K2 L5 K% ~% l; i - STA FC_Data_Buf
' P+ o# b8 W& l' Y - LDY #30
( D+ t* R# w+ N( a - Init_Name_Table_Text_Write
% f* D9 b2 U D6 o; R - LDX #32: L" R" b, @' H3 _
- Init_Name_Table_Text_Write_Char
. {9 m8 M# Y6 A7 N - LDA #'0'& o3 K/ u( o1 a0 O
- CLC& M5 U8 J5 V5 X2 E+ z/ F! N
- ADC FC_Data_Buf( T# Q. c% K5 J" f3 ~
- STA PPU_DATA
$ g) e8 J1 I& J; {# Q6 } - DEX
2 X7 ^. s. y0 F - LDA #$14
) H" X5 b3 z' c' |7 h U - STA PPU_DATA; t; i1 t6 Q6 x
- DEX, z$ U* K7 e! S
- BNE Init_Name_Table_Text_Write_Char
. B* ^) ?/ C( `! U6 Z9 W - INC FC_Data_Buf" \* \" s. E$ h. j! f" o" Z4 i
- DEY0 E" G0 u8 j) J! X$ S, Y8 G+ N
- BNE Init_Name_Table_Text_Write+ O7 P$ k" E/ i3 X2 n1 N) v/ y0 W
- RTS& S" Q" I1 q* g7 |# ~" z
- . V" d* a* `* T+ l' @
- ;==============================
: V' s7 m& a% h/ O - Init_OAM_Ram;初始化精灵内存* [; `) H E2 M7 D3 y
- LDX #$00
' ^) a2 `; `& q' @/ S - LDA #$00
( {0 n& P) Z4 d8 k - STA PPU_OAM_ADDR% J& G! v% l# k: F) x2 R
- LDA #$F8
8 A1 Z ^6 j8 A {, H3 m, q1 a - Init_OAM_Ram_Write
4 v) l5 {: u2 i& Y - STA PPU_OAM_DATA
/ S) y9 }$ Y; O# L3 k - INX2 O3 ?& A& T9 G2 g" j6 |
- BNE Init_OAM_Ram_Write
. }- B# n" N% h( ^ - RTS
5 C" n( L) ~5 T2 {0 ? - 9 i7 W8 O x5 _' y/ M- {
- GamepadProcess;手柄处理
# V9 c# T# }) U1 S - JSR GamepadDatacan
. \% v* S; \& | - LDA <Gamepad_0_Value
+ Y! Y( E* T1 m/ C - STA <Gamepad_0_State3 m, b. z. U3 J, X4 p4 l+ C
- LDA <Gamepad_1_Value- R* c: X$ L/ W3 _* ^
- STA <Gamepad_1_State
, O) O/ J' [( X: _9 a9 Z - JSR GamepadDatacan
4 L# v" {3 {* C; S0 p" [" E - LDX #$018 |: T' w2 d1 r* _1 G0 E
- GamepadMergeCheck;合并手柄输入检查
" i* {5 \# ?4 ?, M) \ - LDA <Gamepad_0_Value,X
9 K# j1 J' l6 m( E2 h' W3 a - CMP <Gamepad_0_State,X/ w/ o4 D% ?! s; U6 R" E2 K! P1 I
- BEQ GamepadMergeInput
! s% H4 ~, u5 \3 i2 o - LDA <Gamepad_Temp,X
9 @! O) u" ]+ p; X9 M - STA <Gamepad_0_Value,X
" p) z# v9 E- H v0 l5 \4 V - GamepadMergeInput;合并手柄输入
: C) G, m- m& B. B2 v2 Y - DEX& e3 [% Z# ^9 b5 C8 T" n5 M9 O
- BPL GamepadMergeCheck
. a0 w: Q! Y6 z7 y, b5 X - LDA <Gamepad_Merge9 m& Z# e9 l1 r
- AND #GAMEPAD_MERGE_FLAG! g" K6 Y( f2 l( g% {4 Q
- BNE GamepadStateProcess- v6 E4 M, ^- b
- LDA <Gamepad_0_Value! F+ |8 H: w' H8 p- [+ W
- ORA <Gamepad_1_Value
% G ^3 o3 j1 c- |3 s - STA <Gamepad_0_Value
# g8 h0 Z8 v- t+ l0 `+ F8 z - GamepadStateProcess;手柄状态处理
R. b$ [; @/ N; C" J) \& ~6 m - LDX #$01. S/ F: d9 Z! J
- GamepadStateSave;手柄状态保存9 H3 e2 k; p2 ?! H: X
- LDA <Gamepad_0_Value,X' ?& x: L7 x; v8 ]5 ?% N
- TAY
; r+ G7 L( u- C" p. z4 w) s1 ~7 F - EOR <Gamepad_Temp,X! c( ]4 | t' {5 W( \0 q
- AND <Gamepad_0_Value,X6 l4 j4 O9 a6 m
- STA <Gamepad_Once,X* w& }5 R5 v0 V: q* h
- STY <Gamepad_Keep,X
2 V3 G2 R& q& n! n: _ - STY <Gamepad_Temp,X8 J" T: f9 g+ f! P: B4 x
- DEX
6 @. G1 q% Q% |7 f' x - BPL GamepadStateSave( A9 z3 x2 _* ^# Q/ i: G6 i
- RTS+ |0 j( [! ~2 U0 B1 y; F
/ i" m) Q* |8 H. d: V( D T( T9 Y( d" x- GamepadDatacan;手柄数据扫描: j# d/ w) H$ j
- LDX #$01
; q7 Z9 w$ {7 x2 S/ F2 { - STX $4016
. e9 G' U6 w _% g - DEX7 }4 [; ]1 g- G8 {# y; `3 [
- STX $4016
' _3 S; a* s, N; s. ^ - LDY #$08% M) L7 B0 j. t4 O' J# A
- GamepadPortScan;手柄端口扫描
' ^5 @) j f6 s9 f - LDA $4016
+ m1 S) S3 h0 B g. M' N - STA <Gamepad_Port_Value
9 g( d. C5 j. _# ~8 u- Q5 g8 } - LSR A
9 Z2 D& M: o4 t, D, y- o" T - ORA <Gamepad_Port_Value
! E9 I, _; a6 ` k5 e. k - LSR A
% n2 s$ S J: i' c. R) x! y- y- t5 G - ROL <Gamepad_0_Value- j* p5 J, H& O1 `
- LDA $4017
7 G" o* H9 Z' r" \ - STA <Gamepad_Port_Value
7 w- s" l+ ?0 K* W5 N/ C - LSR A, v2 k+ l( H& o1 I* D% H/ u
- ORA <Gamepad_Port_Value
1 K( V% P6 m; M - LSR A
. b+ Z! L" R6 W; J) g7 w - ROL <Gamepad_1_Value/ l, L4 u. }; ~! M7 L& ~
- DEY# Y# Y8 J% G& Y& u4 n% L/ W& ^+ ]
- BNE GamepadPortScan3 R6 f I+ r2 g+ V" S% Z1 X
- RTS/ ~* O6 k* f6 U1 a0 ~
- ' `: n! h: B7 z# c7 M9 P; C
- ;==================================================
) z6 K8 p6 t8 o5 U - ;PPU处理7 O- v! I4 c7 f: S/ ?0 ^8 ^
- PPU_Process
+ j( _4 _4 U$ _' k0 L$ z# l& B$ p - LDA #$00
: L8 F c# P- G - STA PPU_MASK
7 L {3 Y8 V7 b0 H! N -
) }% |/ Z8 w* k9 K9 f% W - BIT PPU_STATUS
. W& J F5 N9 F/ f1 L - LDA #$20
" u) m) H, k* S2 Z/ q9 w - STA PPU_ADDRESS( D3 M) h `3 @, b
- LDA #$007 f+ C* P$ h2 z( n7 F! W" H+ M* r
- STA PPU_ADDRESS
8 T! H, W, c1 i% F( K/ _ -
1 i R4 f7 V. B. H; J - STA PPU_SCROLL
7 b8 \" O. R. a3 T - STA PPU_SCROLL; {, c4 }1 I' _% r3 z5 P5 C" z3 P
- 7 w$ O4 `8 r2 J
- LDA PPU_Msak_Buf7 y6 o/ b. y/ x# O4 s
- STA PPU_MASK
, t" ~7 j; `- U2 Y
$ c0 I$ `: {+ w& a- RTS
0 {* |8 H% Z9 a1 V% U' J+ L- O o* d - " K6 B( z5 A+ }$ x9 {9 Y) }' i0 g) a
- ;==============================
- u7 m$ [ A* E7 d3 f - Time_For_Vblank;延时等待
- F) e7 ?% q E3 Y/ a' d. U( w - LDA PPU_STATUS
; g9 v/ j. ^. _! K B% K - BPL Time_For_Vblank
& Z9 L" [: ?2 H) N! y- H* [ - RTS9 ^7 n" m6 K* Y/ G( e# D s6 N
-
) H/ \# A3 f# d, J - ;==================================================
k2 n4 F6 d" @( ` - ;初始化MMC35 I# L' Y9 t. {1 e7 V0 o
- Init_MMC3
# I' ^5 k ~, K7 F$ h# w& t - STA MMC3_IRQ_DISABLE9 c: j6 I6 V9 E9 V
- 0 w0 E6 V) b: e% B
- ;设置MMC3水平镜像/ a( {% M( ?& \
- LDA #$01/ A5 `' r; Q! `- w
- STA MMC3_MIRRORING( y- O, C8 r9 R' k( \6 A
-
- S) t/ _1 a1 w - LDX #$05
. N; k0 S6 l3 S - Init_MMC3_Chr_Bank_Write$ m: V6 e7 W( h3 J! }
- STX MMC3_BANK_CTRL
4 U3 w' P6 R6 Z" B - LDA MMC3_Chr_Bank_Data,X
! w% }; [/ U6 K% Y" [! l - STA MMC3_BANK_DATA$ e( k2 A" y: v6 F# m
- DEX
- b; ^+ q+ n# Z( X7 x$ i+ I - BPL Init_MMC3_Chr_Bank_Write
; e; n1 j# U$ o8 { - RTS
- M/ K0 ?5 U% C% I' v; I5 q; }1 S - ;--------------------------------------------------
( S2 d4 |4 Y- G, V - MMC3_Chr_Bank_Data2 K& D7 |2 T5 j6 `) U
- .DB $00,$02,$04,$05,$06,$07
+ x; k0 u7 I s) H - & \/ T% k$ E; o3 w
- ;==================================================0 A. j- e& w6 }! E6 \
- ;重置中断处理! h! |7 a7 A/ h* Y+ e+ @
- ResetProgram
7 f* Q& v, F/ U* J9 v" o) f - SEI8 J) c* I5 D, n1 x# o9 J
- CLD
7 p. p2 I5 I1 ]2 y# \3 Z - LDA #$00
/ O3 q8 [+ m; R: P - STA PPU_CTRL
! P$ n p1 l; X6 W. e - STA PPU_MASK
* d9 x2 s2 S2 P! J" c - STA PPU_STATUS
9 e/ h% K$ o5 ?+ C$ q# ~9 w - STA JOY2_FRAME
+ V, ^1 r, C' f3 q! n# F! o$ d: q; k - STA APU_STATUS/ u# M N) |+ T$ }! W4 b
-
2 W! X" p5 a; U# G - LDA #$C0- t8 _( K) \6 u& Y y9 N
- STA JOY2_FRAME
% i9 `7 G5 ~" R) k9 J/ i& [ - 3 }4 E3 d; O% a, E
- ;等待vblank# N* b; C' t3 L; W1 e8 L) m. {. B
- LDX #$02
" E& g' g6 c) E0 E2 Y - Vblank_Wait_11 g: q. r7 g- P/ W& Y6 X8 z
- BIT PPU_STATUS
' B2 L& ?# v% f( L9 E+ l9 U - BPL Vblank_Wait_1
+ m/ _' ~1 \( `) I. l1 i - Vblank_Wait_2/ g, t7 G. E/ @6 D0 f P
- BIT PPU_STATUS
& W, J) c- b8 ] B$ l - BMI Vblank_Wait_28 @0 Q3 K- R; K& ]1 }, r0 y( A2 W
- DEX
8 o3 c- v8 Z, _! k2 N - BNE Vblank_Wait_1
' }; E; @( A B% `9 _9 w& L2 Q: \% J - 0 J% g; R# e, _* }! a
- LDX #$FF1 Z A% J7 v- x" g2 g
- TXS
]( o9 Q! x9 G( r -
+ C! n Q- W+ r( A) V - ;初始化MMC34 k1 }" M8 }' @
- JSR Init_MMC3+ O2 [- r1 M: l
- H/ |4 r6 t; |/ N4 e
- ;==============================
1 P# C; M. ?6 K5 ?9 q# O, L4 ?3 s - ;RAM初始化
2 T: D3 L- V; t3 W- H - Nes_Ram_Init
3 j! L" V2 ]* e: g! U4 Q- s - LDY #$00
7 v$ a) |! @3 N( }4 v o - LDX #$08
$ W' t( E/ H8 d: Q) ] - LDA #$00
4 T8 e# S) P; z w - STA <$00
9 c0 ]4 W! e; m9 f# r - STA <$01- x' @. w) e. r" }, a. N( \/ ~
- Nes_Ram_Init_Write% l# o1 A- n% C5 U b9 S9 |
- STA [$00],Y( ^# C! T1 o. ^
- INY$ _& F/ y; J3 U3 G
- BNE Nes_Ram_Init_Write4 B' G' z/ g' J8 a! G/ h
- INC <$01
4 }/ G: U& d: w& d9 k. ` @ - DEX0 R- L2 W) @- n
- BNE Nes_Ram_Init_Write/ m5 ^+ K0 c& r5 k
- 3 `) r: c" G! Z, y+ `
- ;初始化命名表
& m* l/ V: A! F5 j - JSR Init_Name_Table
! k/ y: T- n# \ -
: [" q. h: _6 Y# J - ;初始化调色板
0 o+ M: m2 R& ]- x, c) ^ - JSR Init_Palette
5 Z6 O: L: N& G: e. B1 d - ; y2 p' S# {# l' p& m) d
- ;初始化命名表属性6 N8 j0 e+ T1 J8 K% V
- JSR Init_NameTable_Attributes
' w' f; {# o4 B0 [: `6 v - 7 i9 U3 m" y, t, A. A
- ;初始化精灵内存
3 \, U5 ?/ g* s0 j - JSR Init_OAM_Ram
( B1 f T% ~ b' { - & a- r/ B& l$ {; |, z
- ;在屏幕上写点东西
6 I! v- a6 K0 I: d - JSR Init_Name_Table_Text$ y* }+ S* j6 v- R' g
- * d# ?( Y% J, Y7 c, s/ c
- JSR Time_For_Vblank
# W7 [6 D2 J- X3 A( y - ;开启PPU控制
/ Z& }8 J& C9 h M - LDA #$A89 w* b: ?, w* _. g8 E+ S; ^$ X& x
- STA PPU_Ctrl_Buf
' Z* t% A( x9 { l - STA PPU_CTRL, r; D: B- N9 U& b
- - I8 @. [% `# a' K% {0 f5 `+ K
- ;开启PPU显示
3 ?$ Y' j4 D0 e4 y( Z; W - LDA #$1E
9 U9 }4 F g/ p1 \0 }& K! f - STA PPU_Msak_Buf2 S% ]5 h( V2 [# e% Z6 a
- 9 s$ `1 R2 Z/ r( @! t7 R
- CLI
+ ^0 e- B) g! J- D" Q" O - JMP Loop
+ c) i9 o$ i0 K( v" G - 9 g! q4 x2 [ m5 U% b
- ;==============================
" L: D' V; w2 Q - ;死循环, 等待NMI中断
* @$ Y$ d) `& W b: ? - Loop9 Z9 S* l4 k, M) D: f0 G* e5 w2 D% d
- JMP Loop- m2 O( j7 ?3 J
- 0 j8 J* B# ^5 {8 b- p% H
- ;==================================================
) E( Y/ i `! T( u! |% @2 q, h' d - ;NMI中断处理- K6 K1 y$ y- @+ D- T3 i
- NmiProgram, J) T2 F' O) J$ P0 \
- PHA J5 _& X, i+ \- L2 Q
- TXA/ E+ g6 u: S( D, ~: O* o
- PHA" I( t. s4 @: m5 z
- TYA
2 t* i+ P3 |* z - PHA
3 e2 m' P2 V2 i% i0 {2 p( M7 z - % s d" u4 v/ m4 m
- BIT PPU_STATUS
' x, o, W, [' m5 m% f) Y - ( y8 L. |2 M8 T) W+ E) R; J
- ;关闭PPU控制. ~5 S# o& J' C% t2 x
- LDA #$00. P: l M% N+ A; G6 a0 K
- STA PPU_CTRL `) `- l) B' @8 P+ x W( Y, ~3 j7 z
- $ w7 T* O! J8 k D
- ;处理PPU
+ r4 _7 v8 x* X4 _" ]+ Z% V - JSR PPU_Process
5 y; [* }0 _) G+ a, ? -
" v1 w( d; v8 J& U. e' h - ;开启PPU控制+ a) [) N* `! p, ?; i; V
- LDA PPU_Ctrl_Buf: r& x$ w/ d, K: |8 q! K% F
- STA PPU_CTRL0 J# o6 W" ?1 j" r
- + {9 q# c: p2 n2 a
- ;手柄处理+ V5 }' _, o3 K2 I3 H
- JSR GamepadProcess
! s3 X# S5 l* ^0 O4 Q! h - - X6 O: y1 k/ J% K. p
- LDA #$00
0 u+ n( A/ m- r1 U$ [, H. J - STA IRQ_Index
' ?: I B) Q1 I) S0 T$ n" n4 J -
# D7 z, _- {% Z - ;启动IRQ中断, 第15条扫描线触发5 a, c) {1 F/ {$ _8 l1 r, u
- LDA #15 + 12 }9 [7 U6 ^4 z* O# {3 i# Y
- STA MMC3_IRQ_LATCH% Q/ l& S9 n# {4 ~
- STA MMC3_IRQ_RELOAD
8 B F% ?. }4 T" [& z: C7 I R - STA MMC3_IRQ_ENABLE# `5 I9 Q/ m& U% t7 w1 T
- CLI: H, p* M7 v6 i: N
- % C3 j* m( W% {0 o
- PLA
7 V. \0 \3 w6 l1 i8 h6 b' Z - TAY
8 ]9 h0 l$ D9 k4 g - PLA8 I8 I# j0 X" ^& y& ^1 _% _% @
- TAX
9 t; ~! [3 I9 I* Q - PLA3 `. z- U% V0 G
- RTI h6 @; P4 D2 a5 s
- + Q2 u! h: O+ P% @6 ~
- ;==================================================# G1 k( F Q9 i( Q0 `! c
- ;IRQ中断处理0 n- x$ y7 B9 b/ m& [1 n/ F% x
- IrqProgram
9 c" k. j( H [) }) V: @/ Y - PHA, |! G: P# ^6 I p( B+ \; ^8 k
- TXA
5 m* ?8 d4 e' [4 B4 e6 q, k - PHA- y& A8 V& p; z8 Q( w2 |
- TYA
( ^! [, i) h) |( } - PHA
' J, `+ i4 I) p: V% i, N+ l -
6 O7 ~" F h* U8 I6 x - ;关闭IRQ# {- A! X$ Y( T' M' }" a
- STA MMC3_IRQ_DISABLE
; J( Q3 K# @, H+ v -
( j! }# @$ h- u+ W4 D- S( n5 y, o - ;允许下个IRQ触发! b7 R$ [, q0 k2 g9 L, @
- STA MMC3_IRQ_ENABLE; F6 C/ ^( x$ \0 Y
-
* P8 Z; `, _) c8 r" o - ;IRQ处理, 15线后继续触发3 A G8 b+ D0 O- a$ v
- LDA #154 G+ H4 K+ R* P5 y) o
- STA MMC3_IRQ_LATCH5 B# n2 Z3 T: y: ?! u
-
# q. j2 G- E) J - LDA <IRQ_Index
' q x* m; A" f" ]; ` - BNE * + 4
8 o/ s, z, X6 \8 V" Z1 z - INC <PPU_Scroll_H
1 F0 ^0 b9 r3 ` -
: G8 ^* V8 L% {6 {: j - ;设置屏幕滚动
* _6 k1 K* H0 |, ]' X - LDA <IRQ_Index
2 E9 ]2 R# }: j, } - AND #$01% T& r* O0 U! m/ m0 b
- BEQ Irq_Scroll_Right3 c* w5 ~, y& O
9 W% h2 d# @: {( M- ?% S- Irq_Scroll_Left+ @) l; U, h1 e# W8 b7 o
- BIT PPU_STATUS8 Q2 O; B% y0 | [
- LDA <PPU_Scroll_H
5 A3 K( S4 w0 { - STA PPU_SCROLL
1 x0 X; l( l$ o/ v - STA PPU_SCROLL4 ?( y& }1 r/ y. g
- JMP Irq_Scroll_Over
3 t( s' w/ k- w5 N; \1 \ -
0 A1 j' l* ]1 x, Q+ X1 G9 a - Irq_Scroll_Right& g0 U1 E4 x+ k+ g2 w% E; {6 h4 M
- SEC
: V/ P _0 z5 Q$ I - SBC <PPU_Scroll_H0 [$ S1 X9 w9 }. p) M) P& Z/ H' l
- STA PPU_SCROLL
0 J1 w* U0 J4 s- F - STA PPU_SCROLL
1 O0 q: k/ I: F' q5 j: X3 W d - Irq_Scroll_Over
3 G4 V: i$ d+ C% M1 r. X x. \0 [- ? - 8 a3 D9 i" I4 J; C# F% d
- INC <IRQ_Index T4 J5 e, B2 y# V K5 W
-
/ m/ ?" s! q) P" p9 H - LDA <IRQ_Index
( c) Z6 e5 U( s3 \ F/ A& I) Z" ]/ e - CMP #14
9 \- K: u, U# j - BCC * + 5
+ n* k i; {4 C; G7 d - ;关闭IRQ
1 [' `( H8 L- L0 s8 u% o - STA MMC3_IRQ_DISABLE% Q9 ?: E! T, [! \# c2 o) |. W
- " T. [2 q8 P4 X
- IrqProgramEnd
* L* T+ C+ k( k. a4 C! R/ V - PLA
7 r- R a J+ T% z - TAY
- B- U' K8 Q+ |6 i$ C9 `0 X - PLA
3 P4 _3 |4 G- B3 _7 L9 m' f: ? - TAX. ^7 H9 Y' e9 u) D. _
- PLA' v/ Z) O3 ^% H. x. D
- RTI7 T3 L) F; @% V
- + }2 Z* O+ X( i( K6 q5 \# e4 Y
- ;==================================================
8 X) m/ f n8 m$ e - ;中断表 A8 {* W' ?! U' J0 Y4 ?
- .ORG $FFFA
7 X% T+ I& ~+ D# C5 _ - .WORD NmiProgram
) T8 r6 o& u5 N - .WORD ResetProgram
% i& {0 l( y) U" ? - .WORD IrqProgram
复制代码 [/code]
: n/ N- M3 R2 o/ Q) {+ T$ @9 |) O |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|