forked from jkotlinski/durexforth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.asm
executable file
·120 lines (114 loc) · 1.56 KB
/
move.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
; routines adapted from cc65
; original by Ullrich von Bassewitz, Christian Krueger, Greg King
SRC = W
DST = W2
LEN = W3
cmove_getparams:
lda LSB, x
sta LEN
lda MSB, x
sta LEN + 1
lda LSB + 1, x
sta DST
lda MSB + 1, x
sta DST + 1
lda LSB + 2, x
sta SRC
lda MSB + 2, x
sta SRC + 1
rts
CMOVE_BACK
txa
pha
jsr cmove_getparams
; copy downwards. adjusts pointers to the end of memory regions.
lda SRC + 1
clc
adc LEN + 1
sta SRC + 1
lda DST + 1
clc
adc LEN + 1
sta DST + 1
ldy LEN
bne .entry
beq .pagesizecopy
.copybyte
lda (SRC),y
sta (DST),y
.entry
dey
bne .copybyte
lda (SRC),y
sta (DST),y
.pagesizecopy
ldx LEN + 1
beq cmove_done
.initbase
dec SRC + 1
dec DST + 1
dey
lda (SRC),y
sta (DST),y
dey
.copybytes
lda (SRC),y
sta (DST),y
dey
lda (SRC),y
sta (DST),y
dey
bne .copybytes
lda (SRC),y
sta (DST),y
dex
bne .initbase
jmp cmove_done
CMOVE
txa
pha
jsr cmove_getparams
ldy #0
ldx LEN + 1
beq .l2
.l1
lda (SRC),y ; copy byte
sta (DST),y
iny
lda (SRC),y ; copy byte again, to make it faster
sta (DST),y
iny
bne .l1
inc SRC + 1
inc DST + 1
dex ; next 256-byte block
bne .l1
.l2
ldx LEN
beq cmove_done
.l3
lda (SRC),y
sta (DST),y
iny
dex
bne .l3
cmove_done
pla
clc
adc #3
tax
rts
+BACKLINK
!byte 4
!text "move" ; ( src dst u -- )
MOVE
jsr TO_R
jsr TWODUP
jsr U_LESS
jsr R_TO
jsr SWAP
jsr ZBRANCH
!word .br
jmp CMOVE_BACK
.br = *
jmp CMOVE