CPU_Memory.i

Summary
CPU_Memory.i
Macros
memsetFill block of memory (CPU-bus)
memcpyCopy block of memory (from/to CPU-bus)
WRAM_memsetFill block of memory (WRAM)
WRAM_memcpyCopy block of memory (from CPU-bus to WRAM)
VRAM_memsetFill block of memory (VRAM)
VRAM_memcpyCopy block of memory (from CPU-bus to VRAM)
CGRAM_memcpyCopy block of memory (from CPU-bus to CGRAM)

Macros

memset

Fill block of memory (CPU-bus)

Uses the 65816 block move instruction so its much slower than DMA for large blocks of memory.  On the other hand it’s quicker to setup doesn’t interfere with DMA.

Parameters

:in:    addr      Address (uint24)        ax/hi:x/ex:x
                                          constant
:in:    length    Length (uint16)         y
                                          constant
:in?:   value     Value (uint8)           a
                                          constant

Example

ldy               #$40
memset            $7f6000, y, $66         ;Set $7f6000-$7f603f to #$66

memcpy

Copy block of memory (from/to CPU-bus)

Uses the 65816 block move instruction so its much slower than DMA for large transfers.  On the other hand it’s quicker to setup and doesn’t interfere with DMA.

If the memory regions overlap, but are known at assemble time, the copy will be done safely.  If both addresses aren’t known the copy will be performed using MVN, ie. in negative direction.

Parameters

:in:    dest      Destination (uint24)    ay/hi:y/ex:y
                                          constant
:in:    source    Source (uint24)         ax/hi:x/ex:x
                                          constant
:in:    length    Length (uint16)         a
                                          constant

WRAM_memset

Fill block of memory (WRAM)

Disables DMA and uses channel 7 for transfer.

Parameters

:in:    addr      Address (uint24)        hi:x/ex:x
                                          constant
:in:    length    Length (uint16)         y
                                          constant
:in?:   value     Value (uint8)           a
                                          constant

Example

ldx               #$4000
ldy               #$2000
lda               #$40
WRAM_memset       ex:x, y, a              ;Set $7f:4000-5fff to #$40

WRAM_memcpy

Copy block of memory (from CPU-bus to WRAM)

Disables DMA and uses channel 7 for transfer.  WRAM to WRAM copy is not possible.

Parameters

:in:    dest      Destination (uint24)    ax/ay/hi:x/hi:y/ex:y
                                          constant
:in:    source    Source (uint24)         constant
:in:    length    Length (uint16)         a
                                          constant

VRAM_memset

Fill block of memory (VRAM)

Disables DMA and uses channel 7 for transfer.

Parameters

:in:    addr      Address (uint16)        x (word address)
                                          constant (byte address)
:in:    length    Length (uint16)         y (words)
                                          constant (bytes)
:in?:   value     Value (uint8)           a
                                          constant

VRAM_memcpy

Copy block of memory (from CPU-bus to VRAM)

Disables DMA and uses channel 7 for transfer.

Parameters

:in:    dest      Destination (uint16)    y (word address)
                                          constant (byte address)
:in:    source    Source (uint24)         ax/hi:x/ex:x
                                          constant
:in:    length    Length (uint16)         y
                                          a (<<8)
                                          constant
:in?:   vmainc    VRAM increment          constant
:in?:   dmap      DMA mode                constant
:in?:   bbad      DMA B-bus address       constant

Example

;Decompress graphics and upload to VRAM

LZ4_decompress    Tilemap, EXRAM, y           ;Returns decompressed length in y
VRAM_memcpy       $2000, EXRAM, y             ;Copy y bytes to VRAM

CGRAM_memcpy

Copy block of memory (from CPU-bus to CGRAM)

Disables DMA and uses channel 7 for transfer.

Parameters

:in:    dest      Destination (uint16)    a
                                          constant
:in:    source    Source (uint24)         ax/hi:x/ex:x
                                          constant
:in:    length    Length (uint16)         y
                                          constant

Example

CGRAM_memcpy      0, Palette, sizeof_Palette