-
-
Notifications
You must be signed in to change notification settings - Fork 52
MEMPTR
teeeby edited this page Nov 8, 2025
·
42 revisions
The following table shows the instructions that affect the state of the MEMPTR register and how its value is modified:
| Instruction | New value of MEMPTR |
|---|---|
ld J,(XY+OFFSET)ld (XY+OFFSET),Kld (XY+OFFSET),BYTEU [a,](XY+OFFSET)V (XY+OFFSET)G (XY+OFFSET)G (XY+OFFSET),Kbit N,(XY+OFFSET)M N,(XY+OFFSET)M N,(XY+OFFSET),K
|
XY + OFFSET |
ld a,(bc) |
bc + 1 |
ld a,(de) |
de + 1 |
ld a,(WORD) |
WORD + 1 |
ld (bc),a |
(a << 8) | (c + 1) |
ld (de),a |
(a << 8) | (e + 1) |
ld (WORD),a |
(a << 8) | ((WORD + 1) & FFh) |
ld hl,(WORD)ld SS,(WORD)ld XY,(WORD)ld (WORD),hlld (WORD),SSld (WORD),XY
|
WORD + 1 |
ex (sp),hlex (sp),XY
|
(sp)i |
ldirlddr
|
if bco:pci + 1
|
cpi |
memptr + 1 |
cpir |
if bco ∧ a ≠ (hli):pci + 1else: memptr + 1
|
cpd |
memptr - 1 |
cpdr |
if bco ∧ a ≠ (hli):pci + 1else: memptr - 1
|
add hl,SSadc hl,SSsbc hl,SS
|
hli + 1 |
add XY,WW |
XYi + 1 |
rldrrd
|
hl + 1 |
jp WORDjp Z,WORDcall WORDcall Z,WORD
|
WORD |
jr OFFSET |
pci + 2 + OFFSET |
jr Z,OFFSET |
if Z:pci + 2 + OFFSET
|
djnz OFFSET |
if bo:pci + 2 + OFFSET
|
retretiretn
|
(spi) |
ret Z |
if Z:(spi)
|
rst N |
pco |
in a,(BYTE) |
((ai << 8) | BYTE) + 1 |
in J,(c)in (c)out (c),Jout (c),0
|
bc + 1 |
ini |
bci + 1 |
inir |
if bo:pci + 1else: bci + 1
|
ind |
bci - 1 |
indr |
if bo:pci + 1else: bci - 1
|
out (BYTE),a |
(a << 8) | ((BYTE + 1) & FFh) |
outi |
bco + 1 |
otir |
if bo:pci + 1else: bco + 1
|
outd |
bco - 1 |
otdr |
if bo:pci + 1else: bco - 1
|
| Symbol | Meaning |
|---|---|
J/K |
8-bit register: a, b, c, d, e, h, l or a. |
SS |
16-bit register: bc, de, hl or sp. |
WW |
16-bit register: bc, de, ix, iy or sp. |
XY |
16-bit index register: ix or iy. |
U |
Arithmetic/logical operation: add, adc, sub, sbc, and, xor or or cp. |
V |
Increment/decrement operation: inc or dec. |
G |
Rotation/shift operation: rlc, rrc, rl, rr, sla, sra, sll or srl. |
M |
Bit set/reset operation: res or set. |
Z |
Condition: nz, z, nc, c, po, pe, p or m. |
N |
Immediate 3-bit unsigned integer (embedded in the opcode). |
BYTE |
Immediate 8-bit unsigned integer. |
OFFSET |
Immediate 8-bit signed integer (added to the index register). |
WORD |
Immediate 16-bit unsigned integer. |
i subfix |
Initial/input value of the register or memory address. |
o subfix |
Final/output value of the register or memory address. |
This routine was originally posted by Tony Brewer on stardot.
;
;WZRD is 'slow' routine that reads WZ[13:0]
;place instruction to be tested at WZRD0
;or use JP (IX) / JP (IY) to jump to WZRD
;after test instruction if it is elsewhere
WZRD:
DI
WZRD0:
LD A,(3456H) ;instruction under test
NOP ;allow for 4-byte instruction
;
;read WZ[13] immediately after test instruction
;
BIT 0,(HL) ;F[5] = WZ[13], F[3] = WZ[11]
LD D,20H ;D = 1 << 5 = WZ[13] bit mask
PUSH AF
POP BC ;C[5] = WZ[13]
LD A,C
AND D ;A = 20H or 00H if WZ[13] = 1 or 0
LD E,A ;save WZ[13]
;
;patch JR instruction below
;
RRCA ;A = 10H or 00H
RRCA ;A = 08H or 00H
OR D ;A = 28H or 20H = JR Z or JR NZ opcode
LD HL,WZRD2
LD (HL),A ;write opcode
;
;find WZ[12:0] by using following method:
;decrement WZ using CPD until WZ[13] flips
;
LD HL,0 ;initialise WZ[12:0] counter to 0
LD IX,WZRD1 ;IX = loop address
WZRD1:
CPD ;dec HL and WZ
;
;read WZ[13] after decrementing
;
BIT 0,(HL) ;F[5] = WZ[13], F[3] = WZ[11]
PUSH AF
POP BC ;C[5] = WZ[13]
LD A,C
AND D ;NZ or Z if WZ[13] = 1 or 0
WZRD2:
JR Z,WZRD3 ;or JR NZ,... jump if WZ[13] flipped
JP (IX) ;loop to WZRD1
;
;WZ[13] flipped so WZ[12:0] counting finished
;invert HL = !WZ[12:0] and add WZ[13]
;
WZRD3:
LD A,H
CPL
OR E
LD H,A ;H = WZ[13:8]
LD A,L
CPL
LD L,A ;HL = WZ[13:0]
RETThis routine was originally posted by Tony Brewer on stardot.
N.B. WZRDF1 and WZRDF2 must be in the same 256-byte page (high byte of address the same).
;
;WZRDF is 'fast' routine that reads WZ[13:0]
;place instruction to be tested at WZRDF0
;or use JP (IX) / JP (IY) to jump to WZRDF
;after test instruction if it is elsewhere
;
WZRDF:
DI
WZRDF0:
LD A,(3456H) ;instruction under test
NOP ;allow for 4-byte instruction
;
;read WZ[13] immediately after test instruction
;
BIT 0,(HL) ;F[5] = WZ[13], F[3] = WZ[11]
LD D,20H ;D = 1 << 5 = WZ[13] bit mask
PUSH AF
POP BC ;C[5] = WZ[13]
LD A,C
AND D ;A = 20H or 00H if WZ[13] = 1 or 0
LD E,A ;save WZ[13]
;
;patch JR instruction below
;
RRCA ;A = 10H or 00H
RRCA ;A = 08H or 00H
OR D ;A = 28H or 20H = JR Z or JR NZ opcode
XOR 08H ;A = 20H or 28H = JR NZ or JR Z opcode
LD HL,WZRDF4
LD (HL),A ;write JR opcode
;
;find WZ[12:0] by using following method:
;decrement WZ using block of 25 CPDs until WZ[13] flips
;
LD HL,0FFFFH ;initialise WZ[12:0] counter to -1
LD IX,WZRDF1 ;IX = loop address
WZRDF1:
CPD ;dec HL and WZ for each CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
CPD
;
;read WZ[13] after decrementing
;
BIT 0,(HL) ;F[5] = WZ[13], F[3] = WZ[11]
PUSH AF
POP BC ;C[5] = WZ[13]
LD A,C
AND D
XOR E ;A = 20H if WZ[13] flipped, else A = 00H
ADD A,A ;A = 40H or 00H
;
DB 0DDH
ADD A,L ;ADD A,IXL
DB 0DDH
LD L,A ;LD IXL,A
;
JP (IX) ;jump to WZRDF1 or WZRDF1+40H = WZRDF2
;
;WZRDF1 & WZRDF2 must be in same 256-byte page!
;i.e. high byte of address is same for both
;
;WZ[13] flipped during CPD block
;increment WZ until WZ[13] flips back
;
WZRDF2:
LD IX,WZRDF3 ;IX = loop address
WZRDF3:
CPI ;inc HL and WZ
;
;read WZ[13] after incrementing
;
BIT 0,(HL) ;F[5] = WZ[13] {F[3] = WZ[11]}
PUSH AF
POP BC ;C[5] = WZ[13]
LD A,C
AND D ;NZ or Z if WZ[13] = 1 or 0
WZRDF4:
JR NZ,WZRDF5 ;or JR Z,... jump if WZ[13] flipped
JP (IX) ;jump to WZRDF3
;
;WZ[13] flipped so WZ[12:0] counting finished
;invert HL = !WZ[12:0] and add WZ[13]
;
WZRDF5:
LD A,H
CPL
OR E
LD H,A ;H = WZ[13:8]
LD A,L
CPL
LD L,A ;HL = WZ[13:0]
RET
Copyright © Manuel Sainz de Baranda y Goñi, Tony Brewer and Peter Helcmanovsky
Published under the terms of the GNU Free Documentation License v1.3