|
本帖最后由 yandagui 于 2023-12-2 17:37 编辑
8 W) w, m, u) T) W1 Y; r" Y5 G, j1 P/ f, Z8 O9 J3 x+ u) t
本次IRQ研究了如下:
4 j0 r% |( Q, ?" \2 bVRC2&4(Mapper21,23,25)
2 m$ ~! k! |3 w( G/ S* j7 g; }5 v. bVRC3(Mapper73)$ m: ?! D' ?1 r8 }5 q, m
VRC6(Mapper24 & Mapper26)
1 m8 j! h, k( }3 X& l% ~VRC7(Mapper85)+ m( n9 Q& F; ]" j; R* ?
MMC3(Mapper4)
( d( S, z" D7 I! Y4 o( o, N$ QMMC4(Mapper10)
6 l# [6 x# D% x6 r% {MMC5(Mapper5)
( s' J- J4 S# L U6 e3 S. XMapper18
7 v7 \, d( _3 V GMapper64# o! p/ U; F- `2 S
Namco163(Mapper19)9 [( Y# F4 @4 e, I' M
Sunsoft FME-7(Mapper69)2 F) N6 u! X1 X+ k/ h
) ~! p$ q! ~2 Y4 @" M" {
共计11种Mapper的IRQ操作使用例子
7 b7 J& Y' B" i: ^$ w3 r代码内有详细注释, 希望能帮助到感兴趣的人.
+ U; d* n1 ?2 ~0 u+ p: Y9 ]2 v. x! T2 n0 B# Y8 [1 R3 q: W5 ]6 Q( }
e3 G' P+ W' T# x0 L n
2 F( J% e' v' B0 E( M( J0 S( {
Mapper代码主要逻辑(以MMC3为例):
7 f8 y( b. p+ a9 X7 } j4 Q( j- & l0 w& x- b" F0 m I
- ;==================================================1 G& _* G; T* ]6 F$ U5 H' f6 L
- ;Mapper号
) m0 R4 j a8 i' v2 n Q! I - MAPPER_NUMBER = 041 R3 ?# x' J7 P3 L/ W; x7 |4 d; q
- ;==================================================
! Q2 I! g1 m! v1 x9 ~ D: {" P - ;MMC3 (Mapper 4) 寄存器常量
6 q7 j4 k9 Y2 ~& n6 T8 y1 d - MAPPER_REG_BANK_CTRL = $80007 x- X1 e0 @2 W! U0 w
- MAPPER_REG_BANK_DATA = $8001; R0 C7 M4 \- c1 J
- MAPPER_REG_MIRRORING = $A000& `4 R! r8 L9 h- E! @6 e# @. |
- MAPPER_REG_PRG_RAM_PROTECT = $A001% t1 v5 y6 y& i {( \
- MAPPER_REG_IRQ_LATCH = $C000
0 _& I( R. h& Q# q - MAPPER_REG_IRQ_RELOAD = $C001
% q- m9 |( A; f! a O - MAPPER_REG_IRQ_DISABLE = $E000
6 U9 z! K, S8 N7 u& v* F: L - MAPPER_REG_IRQ_ENABLE = $E0018 d2 N. D% o" n% A& I" Z& A2 I
- ;==================================================
1 \+ D3 _& S o% n& y- ` - IRQ_SCANLINE_BEGIN = 135
6 G. {9 I# ?# W' X - IRQ_SCANLINE_1 = 8
0 H# d% P9 v6 Q5 G' c, g - IRQ_SCANLINE_2 = 54
7 T/ N0 G8 \& A7 | - IRQ_SCANLINE_3 = 8
$ R' z& X" m( T0 m. T% {& \$ W( i - ;==================================================
# W w1 g0 h: |7 b* p$ W: Z
- f% ^8 o, o) L" e! I- ;====================================================================================================
5 r. z' L/ {' Y% ]; s - ;宏常量
( s: X/ O3 g2 e% k. E - ;====================================================================================================3 u0 X! M" W6 ^6 Z3 @
6 `4 [& i* Q+ {& U- ;====================================================================================================
* F S! R* j% R% P0 X - MACRO_MAPPER_INIT .MACRO; b4 O5 p: ~- C, B# r
- ;禁用IRQ& a& J4 I5 ~5 q$ U& l0 c4 {7 q& g2 _
- STA MAPPER_REG_IRQ_DISABLE
+ Q9 g# n" Z" ?3 G -
9 g/ B' }( k5 ^* J - ;水平镜像
( r a0 s' U. R - LDA #$01
5 W# [6 P% W7 }8 }9 ^6 f6 {4 I) m7 F - STA MAPPER_REG_MIRRORING7 X" ?7 m) P5 m; k4 D
- ( J: ?; M1 R9 B2 r6 O
- ;初始化图形bank
0 \( j4 E0 U! q, Y - LDX #$05
, g" b: Q( ]& t% n! v* A - .Init_Chr_Bank/ V0 y& E1 _* i* U% }8 s
- STX MAPPER_REG_BANK_CTRL
7 n0 }9 b- z$ q' E/ b - LDA .ChrBankData,X
0 i- r4 K% {3 _ - STA MAPPER_REG_BANK_DATA! O, i6 w) u" q6 Y3 f
- DEX. |9 R* P' I/ u0 w9 T. ]0 m
- BPL .Init_Chr_Bank
9 n f+ ~ z/ S$ @ - JMP .Init_Chr_Bank_End
0 _& ~( w. i; F - .ChrBankData$ F, s( j8 {2 P# M9 \ X
- .DB $00,$02,$04,$05,$06,$075 A; s/ _" L2 Z/ q
- .Init_Chr_Bank_End
' I0 h$ f) p. Y' Q! N8 @ - ) E& B+ K" Z! c
- ;启用SRAM
( c" W0 E: @- X$ c - LDA #$80
4 Y3 @' w0 R. b( s; ? - STA MAPPER_REG_PRG_RAM_PROTECT; w8 o+ a Q- A0 f; e' ^/ _# u
- .ENDM% J% f2 g' e$ Z6 B5 _( _
- 7 Y- _5 J9 Q# D5 ~& u9 C" i8 J
- ;====================================================================================================
- R+ T8 f, I4 U - MACRO_MAPPER_SOUND_CLEAR .MACRO
. e. D! } }! \ - .ENDM0 t- X) ^+ K) ^4 y
-
, q9 u1 w% i1 W - ;====================================================================================================
2 E. ~% l) G% a' Z* m) n - MACRO_SRAM_ENABLE .MACRO! u. G4 Z2 p4 o; E# M6 [* k
- LDA #$80
+ m( b- }0 v. c \2 J8 @ - STA MAPPER_REG_PRG_RAM_PROTECT6 _) J0 F7 W" k9 b; p
- .ENDM
) f- f: B3 T9 t7 g5 G7 P -
' @ I. o. L }4 ^7 }$ V - ;====================================================================================================
; l `+ v7 ]) ^6 x: o$ n - MACRO_SWITCH_BANK_8000_A .MACRO( h5 a7 c7 h! F4 v) u( ^
- PHA# P( l' p$ p$ Y
- LDA #$06
7 U7 U3 H. ] V - STA MAPPER_REG_BANK_CTRL
! @) I% `7 V& o( c x! f: q3 ^4 [ - PLA/ w) U) C4 f i' R
- STA MAPPER_REG_BANK_DATA
5 d2 r6 r# ~6 U9 W8 F - .ENDM
) s) T8 y W8 f) Y% X5 k
3 n: w, O0 e3 E2 H- MACRO_SWITCH_BANK_A000_A .MACRO, J. D% A8 j7 p5 }
- PHA
4 T: H& w) h9 V2 H6 T - LDA #$07
6 k: L- X& x! k% H - STA MAPPER_REG_BANK_CTRL
) }: e% t% A% y+ b2 w. l* ]* P, y - PLA# w' x; x) q9 F+ [( f7 `( C
- STA MAPPER_REG_BANK_DATA/ h: X" \; }9 v6 ]- Q) j8 \$ n' X
- .ENDM
* h' X1 U! b* y0 p+ G w5 a - 8 a6 \9 t: ~$ W, u
- MACRO_SWITCH_BANK_C000_A .MACRO. b2 s4 }* G8 w0 x
- .ENDM
+ z8 T6 j. g% ] - e0 i" E( n* H
- MACRO_SWITCH_BANK_E000_A .MACRO
$ B; ] l2 r* y: V - .ENDM
2 n# n) z2 D4 k - ) M4 a& ~9 j- k( O; p0 P8 Q' B* |
- ;====================================================================================================+ Y0 [& n) F: J
- MACRO_TRIGGER_FIRST_IRQ .MACRO
( X, a k# e. G; o6 Y6 m9 T - LDA #IRQ_SCANLINE_BEGIN + 1+ A0 O0 A3 P6 [2 Y! l
- STA MAPPER_REG_IRQ_LATCH7 I# L3 M( r7 V2 a2 B
- STA MAPPER_REG_IRQ_RELOAD
5 O8 F# e3 ?5 L6 O7 G4 B2 U - STA MAPPER_REG_IRQ_ENABLE2 p+ ]- o6 j" Z. E/ K
- CLI
$ _( C! a: i6 l. d! h - .ENDM2 ^9 d7 J* m" _8 l
- 9 z4 o6 C+ {. R
- ;====================================================================================================
1 @# W% X# [4 w6 @' M - MACRO_ENABLE_IRQ .MACRO
# z& B( u& q7 d$ F3 x( t - STA MAPPER_REG_IRQ_ENABLE
% k* R6 h( \, U - .ENDM4 X- A) i% I' \$ t! A
- " h% `+ H% ?. @
- ;====================================================================================================
+ w3 j m3 r* S9 |1 s7 t - MACRO_DISABLE_IRQ .MACRO: J* c8 C) Z+ @8 N0 [8 A7 a
- LDA #$00" b: {' y% e8 [6 D V+ A. s
- STA MAPPER_REG_IRQ_CTRL- Q% S1 n8 \( c$ q
- STA MAPPER_REG_IRQ_ACK
- J9 x* k+ G8 l4 R, o5 C - .ENDM
- Y& C- w/ p, ~- V0 n -
( f g4 Z. h& U# g - ;====================================================================================================
8 P2 m# f# w, [) Z - MACRO_ACK_IRQ .MACRO, B. M- x* O5 F& @4 ^+ ]
- STA MAPPER_REG_IRQ_DISABLE; t. P! J# n: }7 |1 p, b
- STA MAPPER_REG_IRQ_ENABLE0 U6 Y q5 b# Z! U& j& S
- .ENDM- ?0 m$ j* m, K0 |8 N4 O% h
- ~3 C- _* R6 H
- ;====================================================================================================3 R/ G" l0 S- e' u- [, d: @
- MACRO_IRQ_OPERATE .MACRO8 @6 f' d* E/ l5 E2 N/ }& Z
& v) r5 s4 w* [' j- ;==================================================
, t$ n3 Y; |$ ~# R. V - ;IRQ滚动模式常量& ?9 T# O1 l: z
- IRQ_SCROLL_MODE_ZERO = 0 ;不滚动
2 b7 n) ~# \, W5 V0 B - IRQ_SCROLL_MODE_LEFT = 1 ;向左滚动
; F0 ?6 q/ w% p - IRQ_SCROLL_MODE_RIGHT = 2 ;向右滚动8 [" x3 \8 ^! K* n
- * Q5 J, Y3 D" Z- h) F+ N6 l% R/ ?
- ;IRQ扫描线数据
) y' q, {: R2 t6 ]# ?. O - IRQ_Scanline_Data( y& c* |' i: ?5 G
- .DB IRQ_SCANLINE_1* F# O' P2 g! W* s, y4 f3 A
- .DB IRQ_SCANLINE_2
0 M7 }: T! T3 X2 ~" v - .DB IRQ_SCANLINE_3/ z: X( Q- m9 d* u0 ?( P. Q+ ~/ W
- .DW 00 ;关闭IRQ9 ^$ c$ C) {/ ^5 L5 ], S* l/ `! j2 ]
- , N# }! O! ^" X; u6 I& v$ h- L W- V: t! Y
- ;IRQ滚动控制模式
$ y) m& K" u; i ]3 m/ I$ ]1 y - IRQ_Scanline_Mode5 \5 O2 f( \/ N2 h+ B. }/ q# R
- .DB IRQ_SCROLL_MODE_RIGHT
2 h3 S1 q( Y% g+ C" B - .DB IRQ_SCROLL_MODE_LEFT7 \3 h$ a; f1 E( ~/ w# Y
- .DB IRQ_SCROLL_MODE_RIGHT
+ S5 F3 ]3 @; `. Z% Z( T+ f$ s, r - .DB IRQ_SCROLL_MODE_LEFT
% {- [& N: ]; w* W - % P2 l0 s7 s# k2 V" k8 ?
- ;==================================================
# f& H/ E8 z$ { - ;;IRQ滚动控制
# w4 M3 G7 C; W2 g( c F6 x - IRQ_Set_Scroll
$ A8 j1 V: w4 I/ D - LDX IRQ_Process_Index8 x, x; y7 d0 f2 I1 N; {
- LDA IRQ_Scanline_Mode,X
& i2 C/ B7 y/ Q - CMP #IRQ_SCROLL_MODE_LEFT2 t6 G) C- C. }' X4 \8 Z
- BEQ IRQ_Set_Scroll_Left
$ \$ K! u8 b' |7 o3 H* p - CMP #IRQ_SCROLL_MODE_RIGHT: `2 C. r7 Z6 H. p7 e* h& t
- BEQ IRQ_Set_Scroll_Right
" v$ \6 M* u8 p3 I" u - IRQ_Set_Scroll_Zero;不滚动
* X' {' V: R! k3 Z- `: J0 L' ~ - LDA #$00
% _3 ?+ Z, Z4 |/ d6 g1 y7 E - STA PPU_SCROLL
: I1 z7 D( y8 I) l - STA PPU_SCROLL+ w. |. _9 c7 k* G4 D: |
- RTS
' D5 [( q7 W' |# A. ^, _) D* b - IRQ_Set_Scroll_Left;向左滚动
q( @3 v7 ? f e5 Q+ n; Q - LDA Scroll_H
) X$ p( C3 x8 h8 W" ~ - STA PPU_SCROLL2 J2 M4 j/ f* ]
- STA PPU_SCROLL3 o4 {# e& A7 I# o+ Q
- RTS; s* P% ^7 U# [
- IRQ_Set_Scroll_Right;向右滚动
5 N0 J$ {+ h- O4 M7 u4 b+ q - LDA #$00. G% J, g2 S6 Y3 K" x
- SEC
6 |# L( H+ n |8 A: W# s7 T - SBC Scroll_H8 F$ p, b1 j6 u) D4 y
- STA PPU_SCROLL
3 ]+ b6 s! {3 @/ \. e3 i3 b - STA PPU_SCROLL
! e. O) n1 G" J3 T. @4 c. l6 V - RTS( ~5 B" F; W& m, L$ n5 a
- 2 r7 M1 U J/ J) i" H& D7 {
- ;==================================================
$ |+ u) f# M% z9 |* Q - ;;IRQ滚动控制* x9 v& {* f; @$ @) f
- IRQ_Set_Ctrl9 K! D" C9 c" H) S0 ~: f$ |# k
- LDX IRQ_Process_Index' T# i, X# F2 Q
- LDA IRQ_Scanline_Data,X
7 [1 }2 e# b9 z' I5 J# f - BNE IRQ_Process_Latch2 L& @7 f8 k, Y3 g$ y1 ]0 ~# U
- IRQ_Process_Disable;禁用IRQ2 Q4 F/ Y$ e |
- STA MAPPER_REG_IRQ_DISABLE; d/ G* C) [7 I' ^% J" q$ n
- STA IRQ_Process_Index
7 b( h( v$ h6 {* C4 j& Q - RTS
+ `+ B) Q2 ]& S+ A J) ~$ q - IRQ_Process_Latch;设置下次 IRQ 触发扫描线
" p* e0 {8 [3 f$ F4 w! l - STA MAPPER_REG_IRQ_LATCH
. B/ u) J4 q6 }4 w - INC IRQ_Process_Index- z& @( F9 m5 S# i/ s
- RTS
1 S' V4 A/ Z' c5 w/ J5 g4 Q
/ Y9 C" V; M w7 f- ;==================================================
0 a& |/ ~/ |' [) P2 H - ;IRQ处理
0 p0 `: k( ~- R# g( q - IRQ_Process_By_Index' l, ~1 r+ b& O, _
- JSR IRQ_Set_Scroll1 s% ~6 s+ O. r' T( V1 x! Y
- JSR IRQ_Set_Ctrl& ]2 J! l% v7 Q2 N3 v% E
- IRQ_Process_End+ Q# {! z9 `, e. S7 o) {$ J
- RTS
; J% r0 J- Q3 U, Z! j - 0 a$ \* l: Y4 z5 V1 b
- .ENDM- T2 z5 D, d2 @
-
# S9 j, e8 {: v
复制代码
" r6 _; |0 @ M% b0 v Z! W9 n/ R7 B% U" D, I
代码仓库地址: https://gitee.com/flame_cyclone/fc-irq |
|