|
本帖最后由 yandagui 于 2017-4-28 14:17 编辑
: J8 R. {: M) x1 b, O) V# U5 D, G* a0 N/ g
;[FC][任意数据搬移到$6000-$7FFF] BY FlameCyclone1 \$ o: F* S8 m1 y( E/ S
;2017.4.28) X' z! ^7 I" z0 z
;例子:双截龙3
" x; u& C& m% F: {9 h .ORG $8100 ;定义程序开始地址3 ?1 f; Z3 {4 w% Z$ K
JMP Copy_Data_Start ;跳转到复制程序
. ]# J- V6 E. x# J/ Y/ R A4 P2 Q! A# Y" C- m% K
Addr_To: ;目的写入地址0 f+ i; j' Z- n
.BYTE $00,$70 ;想要复制到的地方1 G5 r$ T! ^0 u1 `0 Z8 i
Add_Begin: ;源开始数据地址
H8 E1 \. _& U$ d( O$ y. W6 f .BYTE $00,$82 ;想要从何处开始复制; Y: h; `' ~3 i; n4 W) N
Addr_End: ;源结束数据地址
# O$ x7 b- k C, M .BYTE $EE,$91 ;想要从何处结束复制
' N2 u$ `; {5 r+ ^+ a
* P% z$ K/ @0 b8 G, a9 C( s) y8 ~INT_Addr = $A0 ;中断地址
) ~$ y0 c1 h, H+ m' d0 j+ {Flag_Over = $7FFF ;完成标志地址( g6 d8 `* m3 z+ [! u |# k
Data_Over = $7F ;完成标志
8 @/ u+ K! t+ d: r) U5 Y; v# C8 {
4 G$ f0 K7 n7 I* K" b8 I. _
7 C r/ ^6 |5 [6 [0 Z+ {Addr_Data_TO = $A0 ;目的写入地址
. ^; h4 ~& \8 l1 h% _5 xAddr_From_Start = $A2 ;源开始读取地址
7 X2 ^2 J2 n. S: d) x2 U4 QAddr_From_End = $A4 ;源结束读取地址
2 v; j& D5 U% a! K/ K. L3 X, N
! ` u( g, s4 ?" cCopy_Data_Start:/ \# s" Z: y1 l
Data_Copy_Protect: ;保护数据$ [ w" {& h# S9 ~/ D
PHA
- m/ Y" ^) U8 d8 b3 @4 k! b8 ] TXA$ R! P- l1 `0 t4 p0 d% U0 Q* B
PHA& I" e3 N8 r2 }/ b/ {
TYA
+ e! p$ l" z$ K% j PHA+ R. K4 N B1 r' n
JSR Off_INT ;跳转到禁用软件中断: e7 t: C/ C) g# ]
LDA Addr_Data_TO
. V+ G* r4 b2 g; U PHA# v; E) u' f, o" h/ U/ N% V
LDA Addr_Data_TO+1
' d7 \2 U# A, T PHA
" B' L, z9 C2 s9 Q6 C" } LDA Addr_From_Start
; a# @% E( Z1 X/ M, V: `0 S/ e PHA9 Q3 a7 D5 J( \( w- a1 G
LDA Addr_From_Start+1
6 d: H3 C$ J% e3 N$ v, ]" G# Z PHA
- q3 u) g9 h9 _6 i; G3 B0 J [- {1 N LDA Addr_From_End
7 K+ J, s, a. k( R }& s! T7 }* ] PHA
& D+ D3 s; `6 y& H& s LDA Addr_From_End+1) w W& M. N' E
PHA
% I4 _9 `: I( R* u9 U" J m
) `# C# k6 a+ I3 _# | 7 w- q! w$ r$ X: d" v- f
Set_Data_Addr_Start: ;设置复制起始地址5 F: O: V0 t% S/ W% @' z
LDA Add_Begin
" L. y- k2 M( _1 ^. S# G1 P STA Addr_From_Start ;设置复制起始地址低位
4 [# v) ~5 _& c2 j2 u+ R- f5 v0 s LDA Add_Begin+1
% w% i3 `" e% A: S$ m( X* A* J1 |+ | STA Addr_From_Start+1 ;设置复制起始地址高位* c3 D9 c. `8 [( n5 C' V
, `8 @5 ^4 O* A+ c0 _$ \
Set_Data_Addr_End: ;设置复制结束地址7 w. c5 z8 I0 C5 q! }
LDA Addr_End* |7 Y1 `: R6 u" `& K2 J) g
STA Addr_From_End ;设置复制结束地址低位
C4 j) o C2 l- \0 j LDA Addr_End+1
# l) e/ K7 l9 N+ P STA Addr_From_End+1 ;设置复制结束地址高位* p- H# D+ b c0 W# Q" X# e
) X$ Z( D! F' o/ w- u: f- YSet_Data_Copy_Start: ;设置目的起始地址
- m0 t# Q( T V' `: Z1 n% B, c/ G LDA Addr_To7 |8 c! I: t, ?- f P# Z# O Y
STA Addr_Data_TO ;设置目的起始地址低位
. f: c* v9 h( _5 o" S* o- u LDA Addr_To+1
8 P ?# P# X. D. H9 n STA Addr_Data_TO+1 ;设置目的起始地址高位; Q/ ^) c( Q. H4 ~ ~ l8 |) ?# H4 n
n6 l" _3 Y- F3 S4 eOver_Copy_Cmp: ;复制完成比较
7 l' Q+ H& T3 p. c LDA Flag_Over4 V E: g: s+ U1 v1 F
CMP #Data_Over ;复制完成标志比较" z4 }! _" w3 T) k
BEQ Data_Copy_Exact1 \, d& z# T7 _
/ u# z" U/ Q$ BINI_XY_Count: ;计数器初始化
2 k$ k( }. M \+ P% ~) `: M LDX #$000 b) O G2 ~6 r k" h
LDY #$00& f4 M4 `7 d: _5 Z9 e
0 n1 p. o/ y* n Y/ u1 j" m
Copy_Over_Cmp: ;地址比较' S+ k( s! g" b# k. `' Z
Cmp_Addr_Data_TO: ;写入目的地址越界判断(向$6000前写入)3 B+ _: u; L2 g& X' V' y7 X
LDA Addr_Data_TO+1
5 A1 H# H G/ G. `( [8 X CMP #$60
8 b! q, x. f9 Y BCC Data_Copy_Exact ;写入目的地址小于$6000时结束复制
3 K# Z8 |0 z* B4 j6 nCmp_Addr_Data_TO_H: ;写入目的地址越界判断(向$7FFF后写入)
' _" l+ A! b2 I# Y! g LDA Addr_Data_TO+1
! A6 k5 R$ w; { O, w& H CMP #$80' v7 v5 f7 b; b
BEQ Data_Copy_Exact ;写入目的地址大于$7FFF时结束复制; Q) w4 x/ e; y: K$ R e
8 {; f2 n: [) i& Z
Cmp_Copy_FREE: ;源地址结束判断0 \+ h* h6 @( X; b* g b+ o
LDA Addr_From_Start
, T! H" G3 r& q& S+ X CMP Addr_From_End7 T; k3 @# O; c5 |% x3 r* C
BNE Copy_Start
* p/ W% M+ F) [ LDA Addr_From_Start+1
+ |9 V" f. k* ?- }- Z8 D3 N% } CMP Addr_From_End+1
6 r0 L6 f) K! Q0 @/ o BEQ Copy_Over Q9 S$ ~6 l0 ?+ _
! A+ T& b& u, y9 A# i' v
Copy_Start: ;数据复制开始
0 J& A& F' j. P# @ LDA (Addr_From_Start),Y ;读取源地址
/ j" n# N& x1 H STA (Addr_Data_TO),Y ;写入目的地址8 C3 L' h# E, K5 s
Copy_INC_From: ;源地址低位递增$ u* G, ^. B: U' }& W$ ^
INC Addr_From_Start ;源地址低位递增
# }/ M* r! Z& i& }- I2 ? BNE Copy_INC_TO
' L9 h6 o" S' i- c, E INC Addr_From_Start+1 ;源地址高位递增5 | d" l- k7 L5 S% \
Copy_INC_TO: ;源地址高位递增) u6 D/ M/ k6 n& R" U
INC Addr_Data_TO ;目的地址低位递增
# [& N; Q# S) Q0 k0 k0 |. E BNE Recopy3 `1 G* |. N- J# W) N9 C: S
INC Addr_Data_TO+1 ;目的地址高位递增; [0 k, ]$ S$ Y- Z. g5 Y& h8 X
Recopy:
m; u# R M! B8 c JMP Copy_JMP4 s y: Z( q+ k9 n
% D& n6 [% x+ w- P
Copy_JMP:
- D3 {! ]8 E, I7 p" {% k2 R6 [' ^( C JMP Copy_Over_Cmp/ {' D+ {+ F" X7 |
! ~" i! [% L/ b* v! Z. s
Copy_Over: ;复制完成- `, n9 V& e. E/ ^# V0 l6 H/ A
LDA #Data_Over0 }& h4 |% f1 d: ~" m
STA Flag_Over ;写入完成标志& ?, Z# r* b6 j! ]* t
FINAL_BYTE:
5 w3 b1 H7 _4 n' Y- L LDA (Addr_From_Start),Y ;读取最后一个字节3 d% Q e% G' Z m7 A+ E4 r
STA (Addr_Data_TO),Y ;写入最后一个字节7 C3 i& f3 X& D1 x4 m3 V- j) @: o
$ ]8 L2 ^+ H0 u0 n
Data_Copy_Exact: ;恢复数据7 Y, I# J6 } Y& N% z( s: m
PLA
9 J7 I, G$ j% h0 Q" Q STA Addr_From_End+13 R4 A3 y' z* |, U+ k- r
PLA' W5 Z2 Y! y/ x( K! F+ c/ T/ O! a
STA Addr_From_End' G* d' @8 Q1 {" _3 u' [3 S; I, G
PLA+ P+ v6 ]3 U% y; x- x# [
STA Addr_From_Start+1
, Y, U6 R0 ~; Q6 Z) Q0 `2 w9 K: K PLA, h. X. [5 R# {& o9 F: u* P
STA Addr_From_Start" |' L- y5 x6 o; w7 Y! y: W& s- m
PLA3 `/ y6 F3 N# w# X9 O
STA Addr_Data_TO+1+ {! R+ b1 ]' Z i- Y, f, a
PLA
/ G- @" L0 _; y& V7 ]' ^8 H STA Addr_Data_TO9 j# c1 M4 g5 L, U
PLA
# B. C" b) {1 h) Q- ?6 k TAY
4 ]9 R6 h6 r) n0 ~# B! W PLA' D- Y3 s5 j" e4 F& \8 W
TAX
( ~( X: @% Y; F6 ] PLA& u$ p5 o7 B0 J
+ W" ]8 C% M$ V; J j" }1 v5 z
Data_Copy_Return:
$ I, S& a: @ j9 T, `( B0 N" q3 b JSR Rec_INT ;跳转到恢复软件中断数据+ T: W0 P, c' p* {7 ?# u
RTS
* [. s* Z' c5 B9 B
0 o- x) d; n& rOff_INT: ;禁用软件中断
8 K( M$ c% ^3 U2 O LDA INT_Addr
, \, a, A; c9 T AND #$7F
. \7 O- f2 |; K4 f% v STA 2000& E( {) e; E% g$ B! e
RTS
6 h2 [; l8 F2 ^/ j M0 r9 B$ x2 n6 e2 u3 H6 p: m1 i
Rec_INT: ;恢复软件中断数据
3 B6 P/ q2 Q5 u: ^! j+ q% w LDA INT_Addr
' L+ m. p- K; D9 ~. o' u# g STA 20000 u7 W! Q7 u0 K1 M! R+ s% c. e7 `
RTS |
|