-
Notifications
You must be signed in to change notification settings - Fork 3
/
Memory.asm
101 lines (88 loc) · 1.12 KB
/
Memory.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
.segment ZP
mem_source: .word 0
mem_dest: .word 0
mem_size: .word 0
// lda value
// memset(destination,size in bytes)
// e.g.
// LDA #$fe
// memset($d800,$3f8)
.macro memset(dest,size) {
sta mem_source
lda #<size
ldy #>size
sta mem_size
sty mem_size+1
lda #<dest
ldy #>dest
sta mem_dest
sty mem_dest+1
jsr _memset_
}
// memcpy(source,destination,size in bytes)
.macro memcpy(source,dest,size) {
lda #<source
ldy #>source
sta mem_source
sty mem_source+1
lda #<size
ldy #>size
sta mem_size
sty mem_size+1
lda #<dest
ldy #>dest
sta mem_dest
sty mem_dest+1
jsr _memcpy_
}
.segment CODE
_memset_:
{
lda mem_source
ldy #0
ldx mem_size+1
beq remaining_bytes
ms1:
sta (mem_dest),y
iny
bne ms1
inc mem_dest+1
dex
bne ms1
remaining_bytes:
ldx mem_size
beq ms4
ms3:
sta (mem_dest),y
iny
dex
bne ms3
ms4:
rts
}
_memcpy_:
{
ldy #0
ldx mem_size+1
beq remaining_bytes
mc1:
lda (mem_source),y
sta (mem_dest),y
iny
bne mc1
inc mem_dest+1
inc mem_source+1
dex
bne mc1
remaining_bytes:
ldx mem_size
beq mc4
mc3:
lda (mem_source),y
sta (mem_dest),y
iny
dex
bne mc3
mc4:
rts
}