woz64/libs/memory.asm

231 lines
6.6 KiB
NASM
Raw Normal View History

2020-01-12 08:10:01 +00:00
#importonce
#import "../libs/module.asm"
2020-01-13 00:52:10 +00:00
#import "../libs/module.asm"
2020-01-12 08:10:01 +00:00
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// MACROS //////////////////////////////////////////
// ========================================================
2020-01-12 08:10:01 +00:00
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// MemoryClone -
// Clone a range of memory to the passe destination.
//
// Parameters:
// from = Start Memory Pointer to clone
// to = End Memory Pointer to clone
// dest = Destination Memory pointer
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro MemoryClone(from, to, dest) {
lda #<from
sta MemMap.MEMORY.from
lda #>from
sta MemMap.MEMORY.from+1
lda #<dest
sta MemMap.MEMORY.dest
lda #>dest
sta MemMap.MEMORY.dest+1
lda #<to-from
sta MemMap.MEMORY.size+1
lda #>to-from
sta MemMap.MEMORY.size
jsr Memory.clone
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// MemoryFill -
// Fill specified memory range with related byte.
//
// Parameters:
// from = Start Memory Pointer to fill
// to = End Memory Pointer to fill
// fillByte = Byte used to fill the range
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro MemoryFill(from, to, fillByte) {
lda #<from
sta MemMap.MEMORY.from
lda #>from
sta MemMap.MEMORY.from+1
lda #<to-from
sta MemMap.MEMORY.size+1
lda #>to-from
sta MemMap.MEMORY.size
lda #fillByte
jsr Memory.fill
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// MemoryClear -
// Fill specified memory range with Zero
//
// Parameters:
// from = Start Memory Pointer to fill
// to = End Memory Pointer to fill
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
.macro MemoryClear(from, to) {
lda #<from
sta MemMap.MEMORY.from
lda #>from
sta MemMap.MEMORY.from+1
lda #<to-from
sta MemMap.MEMORY.size+1
lda #>to-from
sta MemMap.MEMORY.size
jsr Memory.clear
}
.filenamespace Memory
2020-01-13 00:52:10 +00:00
* = * "Memory Lib"
// ========================================================
// ////// METHODS /////////////////////////////////////////
// ========================================================
// --------------------------------------------------------
// init -
// Module Init.
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
init: {
rts
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// toDebug -
// Print debug info.
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
toDebug: {
2020-01-13 00:52:10 +00:00
ModuleToDebug(module_type, module_name, version)
2020-01-12 08:10:01 +00:00
rts
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// clone -
2020-01-12 08:10:01 +00:00
// Clone Memopry Range
//
2020-01-13 00:52:10 +00:00
// Parameters:
// MemMap.MEMORY.from = Should contain the target
// pointer
// MemMap.MEMORY.dest = Should contain the destination
// pointer
// MemMap.MEMORY.size = Should contain the size to
// copy
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
clone: {
2020-01-12 20:57:01 +00:00
stx MemMap.MEMORY.tmpX
sty MemMap.MEMORY.tmpY
2020-01-12 08:10:01 +00:00
sei
ldy #0
ldx MemMap.MEMORY.size
beq md2
md1: lda (MemMap.MEMORY.from),y // move a page at a time
sta (MemMap.MEMORY.dest),y
iny
bne md1
inc MemMap.MEMORY.from+1
inc MemMap.MEMORY.dest+1
dex
bne md1
md2: ldx MemMap.MEMORY.size+1
beq md4
md3: lda (MemMap.MEMORY.from),y // move the remaining bytes
sta (MemMap.MEMORY.dest),y
iny
dex
bne md3
cli
2020-01-12 20:57:01 +00:00
md4:
ldx MemMap.MEMORY.tmpX
ldy MemMap.MEMORY.tmpY
rts
2020-01-12 08:10:01 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// fill -
2020-01-12 08:10:01 +00:00
// Fill Memopry Range with byte loaded in A
//
2020-01-13 00:52:10 +00:00
// Parameters:
// MemMap.MEMORY.dest = Should contain the destination
// pointer
// MemMap.MEMORY.size = Should contain the size to
// fill
// A = The byte to fill memory with
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
fill: {
2020-01-12 20:57:01 +00:00
stx MemMap.MEMORY.tmpX
sty MemMap.MEMORY.tmpY
2020-01-12 08:10:01 +00:00
sei
ldy #0
ldx MemMap.MEMORY.size
beq md2
md1:
sta (MemMap.MEMORY.dest),y
iny
bne md1
inc MemMap.MEMORY.dest+1
dex
bne md1
md2: ldx MemMap.MEMORY.size+1
beq md4
md3:
sta (MemMap.MEMORY.dest),y
iny
dex
bne md3
cli
2020-01-12 20:57:01 +00:00
md4:
ldx MemMap.MEMORY.tmpX
ldy MemMap.MEMORY.tmpY
rts
2020-01-12 08:10:01 +00:00
}
// Clear Memory with 0
//
// MemMap.MEMORY.dest - Should contain the destination pointer
// MemMap.MEMORY.size - Should contain the size to copy
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// clean -
// Clear Memory with 0
//
// Parameters:
// MemMap.MEMORY.dest = Should contain the destination
// pointer
// MemMap.MEMORY.size = Should contain the size to
// clean
// --------------------------------------------------------
clean: {
2020-01-12 08:10:01 +00:00
lda #00
jmp Memory.fill
}
2020-01-13 00:52:10 +00:00
// ========================================================
// ////// DATA ////////////////////////////////////////////
// ========================================================
2020-01-12 08:10:01 +00:00
* = * "Memory Lib Data"
2020-01-13 00:52:10 +00:00
module_type: .byte Module.TYPES.LIB
version: .byte 1, 1, 0
2020-01-12 08:10:01 +00:00
.encoding "screencode_mixed"
module_name:
2020-01-13 00:52:10 +00:00
.text "memory"
2020-01-12 08:10:01 +00:00
.byte 0
2020-01-13 00:52:10 +00:00
2020-01-12 08:10:01 +00:00
#import "../core/mem_map.asm"
#import "../core/screen.asm"