1
0
mirror of https://github.com/stid/woz64.git synced 2024-11-25 00:31:29 +00:00
woz64/libs/memory.asm

227 lines
6.4 KiB
NASM
Raw Normal View History

2020-01-12 08:10:01 +00:00
#importonce
2020-01-19 06:48:59 +00:00
#import "../core/module.asm"
2020-01-13 07:33:13 +00:00
#import "../core/pseudo.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) {
2020-01-13 01:24:10 +00:00
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-12 08:10:01 +00:00
}
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) {
2020-01-13 01:24:10 +00:00
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-12 08:10:01 +00:00
}
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) {
2020-01-13 01:24:10 +00:00
lda #<from
sta MemMap.MEMORY.from
lda #>from
sta MemMap.MEMORY.from+1
2020-01-12 08:10:01 +00:00
2020-01-13 01:24:10 +00:00
lda #<to-from
sta MemMap.MEMORY.size+1
lda #>to-from
sta MemMap.MEMORY.size
2020-01-12 08:10:01 +00:00
2020-01-13 01:24:10 +00:00
jsr Memory.clear
2020-01-12 08:10:01 +00:00
}
.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: {
2020-01-13 01:24:10 +00:00
rts
2020-01-12 08:10:01 +00:00
}
2020-01-13 00:52:10 +00:00
// --------------------------------------------------------
// toDebug -
// Print debug info.
// --------------------------------------------------------
2020-01-12 08:10:01 +00:00
toDebug: {
2020-01-13 01:24:10 +00:00
ModuleToDebug(module_type, module_name, version)
rts
2020-01-12 08:10:01 +00:00
}
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-13 07:33:13 +00:00
phr
2020-01-13 01:24:10 +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
2020-01-20 07:32:37 +00:00
bne md3
2020-01-13 01:24:10 +00:00
cli
md4:
2020-01-13 07:33:13 +00:00
plr
2020-01-13 01:24:10 +00:00
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-13 07:33:13 +00:00
phr
2020-01-13 01:24:10 +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
md4:
2020-01-13 07:33:13 +00:00
plr
2020-01-13 01:24:10 +00:00
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-13 01:24:10 +00:00
lda #00
jmp Memory.fill
2020-01-12 08:10:01 +00:00
}
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-20 07:38:20 +00:00
#import "../hardware/mem_map.asm"
2020-01-20 07:32:37 +00:00
#import "../devices/video.asm"
2020-01-12 08:10:01 +00:00