;*******************************************************************
;
; CK BD (Check Board)
;    Very basic RAM test for 1K, 4K and 16K ranges starting
;    at address zero.
;
;    PROM Origin: FE00
;
;    This PROM is part of the test suite used by MITS bench 
;    technician Robert Lopez. These PROMs were used at MITS
;    to test and debug boards for the Altair 8800 computer.
;
;    OPERATION:
;
;    Examine and run from the addresses shown below that
;    correspond to the size of RAM board to be tested. The
;    test repeats forever until an error is found. The
;    program stalls in a loop at the addresses shown when
;    an error is detected.
;
;    16K test at FE00, error stall at FE24
;     4K test at FE28, error stall at FE4C
;     1K test at FE50, error stall at FE74
;
;    Disassembled 1/23/2016 by Mike Douglas from a 1702a PROM
;    provided by Tom Sanderson.
;
;*******************************************************************

;---------------------------------------------------------------
; 16K test at FE00, dies at FE24 with error
;---------------------------------------------------------------
	org	0FE00h

test16:	lxi	h,0		;start address-1 (skips loc 0)
	lxi	d,03FFFh	;end address
	mvi	b,055h
	mvi	c,0AAh

loop16:	inx	h		;next location
	mov	m,b		;store 55
	mov	a,b
	cmp	m		;55 read?
	jnz	die16		;no, die

	mov	m,c		;store AA
	mov	a,c
	cmp	m		;AA read?
	jnz	die16		;no, die

	mov	a,e		;see if at upper limit
	cmp	l		;test LSB first
	jnz	loop16		;not done

	mov	a,d		;test MSB of upper limit
	cmp	h
	jnz	loop16		;not done

	jmp	test16		;repeat test

; die16 - error during 16K test

die16:	jmp	die16		;die here

	nop			;divider

;---------------------------------------------------------------
; 4K test at FE28, dies at FE4C with error
;---------------------------------------------------------------
test4:	lxi	h,0		;start address-1 (skips loc 0)
	lxi	d,0fffh		;end address
	mvi	b,055h
	mvi	c,0aah

loop4:	inx	h		;next location
	mov	m,b		;store 55
	mov	a,b
	cmp	m		;55 read?
	jnz	die4		;no, die

	mov	m,c		;store AA
	mov	a,c
	cmp	m		;AA read?
	jnz	die4		;no, die

	mov	a,e		;see if at upper limit
	cmp	l		;test LSB first
	jnz	loop4		;not done yet

	mov	a,d		;test MSB of upper limit
	cmp	h
	jnz	loop4		;not done yet

	jmp	test4		;repeat test

; die4 - error during 4K test

die4:	jmp	die4
;
	nop			;divider

;---------------------------------------------------------------
; 1K test at FE50, dies at FE74 with error
;---------------------------------------------------------------
test1:	lxi	h,0		;start address-1 (skips loc 0)
	lxi	d,003FFh	;end address
	mvi	b,055h
	mvi	c,0AAh

loop1:	inx	h		;next location
	mov	m,b		;store 55
	mov	a,b
	cmp	m		;55 read?
	jnz	die1		;no, die

	mov	m,c		;store AA
	mov	a,c
	cmp	m		;AA read?
	jnz	die1		;no, die

	mov	a,e		;see if at upper limit
	cmp	l		;test LSB first
	jnz	loop1		;not done yet

	mov	a,d		;test MSB of upper limit
	cmp	h
	jnz	loop1		;not done yet

	jmp	test1		;repeat test

; die4 - error during 1K test

die1:	jmp	die1

	nop			;divider

	end
