RAM test of ZX81 rom

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

RAM test of ZX81 rom

Post by PokeMon »

Well I am working on a memory extension board.
I am just hanging over the memory test routine in the Sinclair rom but can not understand the principles of this test software.
Code could be from Microsoft. :mrgreen:

Code: Select all

;; RAM-CHECK
L03CB:  LD      H,B             ;
        LD      L,C             ;
        LD      A,$3F           ;

;; RAM-FILL
L03CF:  LD      (HL),$02        ;
        DEC     HL              ;
        CP      H               ;
        JR      NZ,L03CF        ; to RAM-FILL

;; RAM-READ
L03D5:  AND     A               ;
        SBC     HL,BC           ;
        ADD     HL,BC           ;
        INC     HL              ;
        JR      NC,L03E2        ; to SET-TOP

        DEC     (HL)            ;
        JR      Z,L03E2         ; to SET-TOP

        DEC     (HL)            ;
        JR      Z,L03D5         ; to RAM-READ

;; SET-TOP
L03E2:  LD      ($4004),HL      ; set system variable RAMTOP to first byte 
                                ; above the BASIC system area.
In general it is clear.
What I do not understand is the sense of writing $02 into memory cells and after decrementing it two times after each other.
So after first DEC (HL) it is testing if it's not zero. But how could it be zero, when filled with $02 ?
So the only chance to meet this condition is when reading back is $01 instead of $02.
When it is testing for $FF I could understand for checking of non-existing RAM.
It doesn't use any march algorythm.
So what's the heck about ? ;)

Second. Why does it always do SBC HL,BC and after ADD HL,BC ?
Okay it checks if it is reaching maybe getting in ROM address area but why does it this about 16384 times when having 16k RAM ?
Could be more easy done with simply

Code: Select all

INC HL
CP H
JR Z,end-of-memtest
when executing one time XOR A before. :roll:

Any ideas ? ;)
RWAP
Posts: 1348
Joined: Thu May 08, 2008 8:42 am
Location: Stoke-on-Trent, UK
Contact:

Re: RAM test of ZX81 rom

Post by RWAP »

I should guess that some of this is to add a slight delay with the processor doing something, so that you are testing if the RAM can hold a status !
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: RAM test of ZX81 rom

Post by PokeMon »

I am not convinced about it.

Well, this routine makes it 30 clock cycles longer than it should be.
All in all it's about 60 clock cycles for memory cell, so something about 20us.
The internal 1k RAM (which doesn't use refresh at all) will not really be influenced much.

Anyway the external 16k RAM which uses RAS/CAS need a refresh every 2 ms.
So 16k need about 320ms to test.
I think they could do in half time without problems to detect refresh failures - a bit earlier or later because it is wide out of specification. ;)
On the other hand it could break memory test after lets say 3k or 4k and use this value as RAMTOP.

So this strategy doesn't really help in my eyes.
Could be more effective when filling RAM from bottom to top and after check RAM content from bottom to top.
Then you have at least 160ms till write and read for every cell.

By the way, filling could be done with LDIR instruction as well in about 2/3 of time. ;)
Or could use stack pointer to fill RAM with PUSH instructions with about 5.5 clock cycles per byte or 5 times faster.
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: RAM test of ZX81 rom

Post by PokeMon »

I think I forgot the DJNZ instruction with the PUSH. So it's about 12 cycles per Byte, anyway nearly 3 times faster.
What would they do it they had 1 MByte ? Just wait ? :mrgreen:
Post Reply