-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmem.asm
More file actions
99 lines (84 loc) · 2.31 KB
/
mem.asm
File metadata and controls
99 lines (84 loc) · 2.31 KB
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
; Block move macros
; Expects 16 bit A and X/Y
.macro BlockMoveP src, dest, size
.a16
.i16
ldx #.loword(source) ; Source address
ldy #.loword(dest) ; Destination address
lda #(size-1) ; Block size
mvp (^src), (^dest) ; mvp sourcebank, destinationbank
;MVP Move Positive, some docs say destination > source (this seems to be incorrect? I guess it only applies to the low 16 bits of the address (in X and Y) and not the bank)
; The MVP instruction uses the X and Y registers to denote the top address
; of the two blocks of memory. The data is moved from the address in X to
; the address in Y and then the XY and accumulator registers are
; decremented until the accumulator underflows to $FFFF.
.endmacro
.macro BlockMoveN src, dest, size
.a16
.i16
ldx #.loword(source) ; Source address
ldy #.loword(dest) ; Destination address
lda #(size-1) ; Block size
mvn (^src), (^dest) ; MVN sourcebank, destinationbank
;MVN Move Negative, destination < source
; The MVN instruction uses the X and Y registers to denote the bottom (beginning)
; address of the two memory segments to be moved. With MVN the data is moved
; from the source in X to the destination in Y, then the X and Y registers are
; incremented and the accumulator decremented until the accumulator
; underflows to $FFFF.
.endmacro
; src = source far address
; dest = destination far address
; size = 0 - 64KB
; mode = What to put in $4300
.macro DMA_WramSram src, dest, size, mode
.a8
.i16
ldx #.loword(src)
stx $2181
lda #^src
sta $2183
ldx #.loword(dest)
lda #<mode
xba
lda #^dest
ldy #size
jsr _dma_wram_to_sram
.endmacro
.macro LoadBlockToWRAM src, dest, size
.a8
.i16
ldx #.loword(dest)
stx $2181
lda #^dest
sta $2183
ldx #.loword(src)
lda #^src
ldy #size
jsr _dma_rom_to_wram
.endmacro
.code
_dma_rom_to_wram:
.a8
.i16
stx $4302
sta $4304
sty $4305
ldx #$8000
stx $4300
lda #$01
sta $420B
rts
_dma_wram_to_sram:
.a8
.i16
stx $4302
sta $4304
sty $4305
lda #$80
xba
tax
stx $4300
lda #$01
sta $420B
rts