65816-llvm-mos/tests/memBlock/memBlockRegs.s
2026-10-06 17:01:51 -05:00

124 lines
2.3 KiB
ArmAsm

; memBlockRegs -- memcpy / memmove / memset keep the caller's DBR and D.
;
; unsigned short memBlockRegs(void) calls each routine down each of its
; paths (short loop, one MVN / MVP, several runs; memset short, one pass
; and over 64 KB) with DBR = $05 and D = $0100, so the routines' direct-
; page scratch lands at $01E0, and sets one bit at $02:5008 for each call
; that came back with DBR, D and dst in A:X intact. It returns that word:
; 0x0FFF, all 12 bits, is a pass.
REGS_DBR = 0x05
REGS_D = 0x0100
REGS_OUT = 0x025008
.text
.globl memBlockRegs
; The caller pushed the arguments after dst (nWords words); call fn with
; dst in A:X, drop the arguments and check what came back.
.macro regsCall fn, dstLo, dstHi, nWords, bit
lda #\dstLo
ldx #\dstHi
jsl \fn
tay
tsc
clc
adc #(\nWords * 2)
tcs
cpy #\dstLo
bne .Lskip\bit
cpx #\dstHi
bne .Lskip\bit
tdc
cmp #REGS_D
bne .Lskip\bit
phb
sep #0x20
.a8
pla
cmp #REGS_DBR
rep #0x20
.a16
bne .Lskip\bit
lda #(1 << \bit)
ora REGS_OUT
sta REGS_OUT
.Lskip\bit:
.endm
memBlockRegs:
rep #0x30
phb
phd
lda #0
sta REGS_OUT
pea REGS_DBR * 0x101 ; DBR twice: plb, plb
plb
plb
lda #REGS_D
tcd
; memcpy: short, one MVN, runs (source across 03/04)
pea 0
pea 20
pea 0x0002
pea 0x6200
regsCall memcpy, 0x6100, 0x0002, 4, 0
pea 0
pea 300
pea 0x0002
pea 0x6200
regsCall memcpy, 0x6800, 0x0002, 4, 1
pea 0
pea 600
pea 0x0003
pea 0xff00
regsCall memcpy, 0x7000, 0x0002, 4, 2
; memmove backward: short, one MVP, runs (both across 03/04)
pea 0
pea 20
pea 0x0002
pea 0x6100
regsCall memmove, 0x6105, 0x0002, 4, 3
pea 0
pea 300
pea 0x0002
pea 0x6100
regsCall memmove, 0x6105, 0x0002, 4, 4
pea 0
pea 600
pea 0x0003
pea 0xff00
regsCall memmove, 0xff40, 0x0003, 4, 5
; memmove forward: short, one MVN, runs
pea 0
pea 20
pea 0x0002
pea 0x6105
regsCall memmove, 0x6100, 0x0002, 4, 6
pea 0
pea 300
pea 0x0002
pea 0x6105
regsCall memmove, 0x6100, 0x0002, 4, 7
pea 0
pea 600
pea 0x0003
pea 0xff40
regsCall memmove, 0xff00, 0x0003, 4, 8
; memset: short, one pass, over 64 KB
pea 0
pea 5
pea 0x77
regsCall memset, 0x6100, 0x0002, 3, 9
pea 0
pea 300
pea 0x77
regsCall memset, 0x6100, 0x0002, 3, 10
pea 1
pea 0x10
pea 0x77
regsCall memset, 0x0000, 0x0004, 3, 11
pld
plb
lda REGS_OUT
rtl