; ================================================
;
;  FOR IC SOCKET U18 ON THE IBM 5160 MOTHERBOARD.
;
;  ROM ADDRESSING TEST.
;
;  OUTPUTS TO LPT PORTS 378h, 278h, and 3BCh.  REFER TO FILE TEST6077.TXT FOR DETAILS.
;
;  THIS CODE PURPOSELY USES NO RAM.
;
;  COMPILE THIS CODE USING NASM 2.10 (OR LATER) TO PRODUCE FILE TEST6077_32K_SIZED.BIN
;
; ================================================

BITS 16

CPU 8086

; ----------------------------------------------------------------------------------------------
; TEST BYTES
; ----------------------------------------------------------------------------------------------

ORG 0			; Offset 0 in ROM (i.e. address F8000 in IBM 5160 address space)

	db	080h
TIMES 0x100-1 DB 0	; Pad with zero to address 0100h in ROM (i.e. address F8100 in IBM 5160 address space)
	db	081h
TIMES 0x100-1 DB 0	; Pad with zero to address 0200h in ROM (i.e. address F8200 in IBM 5160 address space)
	db	082h
TIMES 0x100-1 DB 0	; Pad with zero to address 0300h in ROM (i.e. address F8300 in IBM 5160 address space)
	db	083h
TIMES 0x100-1 DB 0	; Pad with zero to address 0400h in ROM (i.e. address F8400 in IBM 5160 address space)
	db	084h
TIMES 0x100-1 DB 0	; Pad with zero to address 0500h in ROM (i.e. address F8500 in IBM 5160 address space)
	db	085h
TIMES 0x100-1 DB 0	; Pad with zero to address 0600h in ROM (i.e. address F8600 in IBM 5160 address space)
	db	086h
TIMES 0x100-1 DB 0	; Pad with zero to address 0700h in ROM (i.e. address F8700 in IBM 5160 address space)
	db	087h
TIMES 0x100-1 DB 0	; Pad with zero to address 0800h in ROM (i.e. address F8800 in IBM 5160 address space)
	db	088h
TIMES 0x100-1 DB 0	; Pad with zero to address 0900h in ROM (i.e. address F8900 in IBM 5160 address space)
	db	089h
TIMES 0x100-1 DB 0	; Pad with zero to address 0A00h in ROM (i.e. address F8A00 in IBM 5160 address space)
	db	08Ah
TIMES 0x100-1 DB 0	; Pad with zero to address 0B00h in ROM (i.e. address F8B00 in IBM 5160 address space)
	db	08Bh
TIMES 0x100-1 DB 0	; Pad with zero to address 0C00h in ROM (i.e. address F8C00 in IBM 5160 address space)
	db	08Ch
TIMES 0x100-1 DB 0	; Pad with zero to address 0D00h in ROM (i.e. address F8D00 in IBM 5160 address space)
	db	08Dh
TIMES 0x100-1 DB 0	; Pad with zero to address 0E00h in ROM (i.e. address F8E00 in IBM 5160 address space)
	db	08Eh
TIMES 0x100-1 DB 0	; Pad with zero to address 0F00h in ROM (i.e. address F8F00 in IBM 5160 address space)
	db	08Fh

TIMES 0x100-1 DB 0	; Pad with zero to address 1000h in ROM (i.e. address F9000 in IBM 5160 address space)
	db	090h
TIMES 0x100-1 DB 0	; Pad with zero to address 1100h in ROM (i.e. address F9100 in IBM 5160 address space)
	db	091h
TIMES 0x100-1 DB 0	; Pad with zero to address 1200h in ROM (i.e. address F9200 in IBM 5160 address space)
	db	092h
TIMES 0x100-1 DB 0	; Pad with zero to address 1300h in ROM (i.e. address F9300 in IBM 5160 address space)
	db	093h
TIMES 0x100-1 DB 0	; Pad with zero to address 1400h in ROM (i.e. address F9400 in IBM 5160 address space)
	db	094h
TIMES 0x100-1 DB 0	; Pad with zero to address 1500h in ROM (i.e. address F9500 in IBM 5160 address space)
	db	095h
TIMES 0x100-1 DB 0	; Pad with zero to address 1600h in ROM (i.e. address F9600 in IBM 5160 address space)
	db	096h
TIMES 0x100-1 DB 0	; Pad with zero to address 1700h in ROM (i.e. address F9700 in IBM 5160 address space)
	db	097h
TIMES 0x100-1 DB 0	; Pad with zero to address 1800h in ROM (i.e. address F9800 in IBM 5160 address space)
	db	098h
TIMES 0x100-1 DB 0	; Pad with zero to address 1900h in ROM (i.e. address F9900 in IBM 5160 address space)
	db	099h
TIMES 0x100-1 DB 0	; Pad with zero to address 1A00h in ROM (i.e. address F9A00 in IBM 5160 address space)
	db	09Ah
TIMES 0x100-1 DB 0	; Pad with zero to address 1B00h in ROM (i.e. address F9B00 in IBM 5160 address space)
	db	09Bh
TIMES 0x100-1 DB 0	; Pad with zero to address 1C00h in ROM (i.e. address F9C00 in IBM 5160 address space)
	db	09Ch
TIMES 0x100-1 DB 0	; Pad with zero to address 1D00h in ROM (i.e. address F9D00 in IBM 5160 address space)
	db	09Dh
TIMES 0x100-1 DB 0	; Pad with zero to address 1E00h in ROM (i.e. address F9E00 in IBM 5160 address space)
	db	09Eh
TIMES 0x100-1 DB 0	; Pad with zero to address 1F00h in ROM (i.e. address F9F00 in IBM 5160 address space)
	db	09Fh

TIMES 0x100-1 DB 0	; Pad with zero to address 2000h in ROM (i.e. address FA000 in IBM 5160 address space)
	db	0A0h
TIMES 0x100-1 DB 0	; Pad with zero to address 2100h in ROM (i.e. address FA100 in IBM 5160 address space)
	db	0A1h
TIMES 0x100-1 DB 0	; Pad with zero to address 2200h in ROM (i.e. address FA200 in IBM 5160 address space)
	db	0A2h
TIMES 0x100-1 DB 0	; Pad with zero to address 2300h in ROM (i.e. address FA300 in IBM 5160 address space)
	db	0A3h
TIMES 0x100-1 DB 0	; Pad with zero to address 2400h in ROM (i.e. address FA400 in IBM 5160 address space)
	db	0A4h
TIMES 0x100-1 DB 0	; Pad with zero to address 2500h in ROM (i.e. address FA500 in IBM 5160 address space)
	db	0A5h
TIMES 0x100-1 DB 0	; Pad with zero to address 2600h in ROM (i.e. address FA600 in IBM 5160 address space)
	db	0A6h
TIMES 0x100-1 DB 0	; Pad with zero to address 2700h in ROM (i.e. address FA700 in IBM 5160 address space)
	db	0A7h
TIMES 0x100-1 DB 0	; Pad with zero to address 2800h in ROM (i.e. address FA800 in IBM 5160 address space)
	db	0A8h
TIMES 0x100-1 DB 0	; Pad with zero to address 2900h in ROM (i.e. address FA900 in IBM 5160 address space)
	db	0A9h
TIMES 0x100-1 DB 0	; Pad with zero to address 2A00h in ROM (i.e. address FAA00 in IBM 5160 address space)
	db	0AAh
TIMES 0x100-1 DB 0	; Pad with zero to address 2B00h in ROM (i.e. address FAB00 in IBM 5160 address space)
	db	0ABh
TIMES 0x100-1 DB 0	; Pad with zero to address 2C00h in ROM (i.e. address FAC00 in IBM 5160 address space)
	db	0ACh
TIMES 0x100-1 DB 0	; Pad with zero to address 2D00h in ROM (i.e. address FAD00 in IBM 5160 address space)
	db	0ADh
TIMES 0x100-1 DB 0	; Pad with zero to address 2E00h in ROM (i.e. address FAE00 in IBM 5160 address space)
	db	0AEh
TIMES 0x100-1 DB 0	; Pad with zero to address 2F00h in ROM (i.e. address FAF00 in IBM 5160 address space)
	db	0AFh

TIMES 0x100-1 DB 0	; Pad with zero to address 3000h in ROM (i.e. address FB000 in IBM 5160 address space)
	db	0B0h
TIMES 0x100-1 DB 0	; Pad with zero to address 3100h in ROM (i.e. address FB100 in IBM 5160 address space)
	db	0B1h
TIMES 0x100-1 DB 0	; Pad with zero to address 3200h in ROM (i.e. address FB200 in IBM 5160 address space)
	db	0B2h
TIMES 0x100-1 DB 0	; Pad with zero to address 3300h in ROM (i.e. address FB300 in IBM 5160 address space)
	db	0B3h
TIMES 0x100-1 DB 0	; Pad with zero to address 3400h in ROM (i.e. address FB400 in IBM 5160 address space)
	db	0B4h
TIMES 0x100-1 DB 0	; Pad with zero to address 3500h in ROM (i.e. address FB500 in IBM 5160 address space)
	db	0B5h
TIMES 0x100-1 DB 0	; Pad with zero to address 3600h in ROM (i.e. address FB600 in IBM 5160 address space)
	db	0B6h
TIMES 0x100-1 DB 0	; Pad with zero to address 3700h in ROM (i.e. address FB700 in IBM 5160 address space)
	db	0B7h
TIMES 0x100-1 DB 0	; Pad with zero to address 3800h in ROM (i.e. address FB800 in IBM 5160 address space)
	db	0B8h
TIMES 0x100-1 DB 0	; Pad with zero to address 3900h in ROM (i.e. address FB900 in IBM 5160 address space)
	db	0B9h
TIMES 0x100-1 DB 0	; Pad with zero to address 3A00h in ROM (i.e. address FBA00 in IBM 5160 address space)
	db	0BAh
TIMES 0x100-1 DB 0	; Pad with zero to address 3B00h in ROM (i.e. address FBB00 in IBM 5160 address space)
	db	0BBh
TIMES 0x100-1 DB 0	; Pad with zero to address 3C00h in ROM (i.e. address FBC00 in IBM 5160 address space)
	db	0BCh
TIMES 0x100-1 DB 0	; Pad with zero to address 3D00h in ROM (i.e. address FBD00 in IBM 5160 address space)
	db	0BDh
TIMES 0x100-1 DB 0	; Pad with zero to address 3E00h in ROM (i.e. address FBE00 in IBM 5160 address space)
	db	0BEh
TIMES 0x100-1 DB 0	; Pad with zero to address 3F00h in ROM (i.e. address FBF00 in IBM 5160 address space)
	db	0BFh

TIMES 0x100-1 DB 0	; Pad with zero to address 4000h in ROM (i.e. address FC000 in IBM 5160 address space)
	db	0C0h
TIMES 0x100-1 DB 0	; Pad with zero to address 4100h in ROM (i.e. address FC100 in IBM 5160 address space)
	db	0C1h
TIMES 0x100-1 DB 0	; Pad with zero to address 4200h in ROM (i.e. address FC200 in IBM 5160 address space)
	db	0C2h
TIMES 0x100-1 DB 0	; Pad with zero to address 4300h in ROM (i.e. address FC300 in IBM 5160 address space)
	db	0C3h
TIMES 0x100-1 DB 0	; Pad with zero to address 4400h in ROM (i.e. address FC400 in IBM 5160 address space)
	db	0C4h
TIMES 0x100-1 DB 0	; Pad with zero to address 4500h in ROM (i.e. address FC500 in IBM 5160 address space)
	db	0C5h
TIMES 0x100-1 DB 0	; Pad with zero to address 4600h in ROM (i.e. address FC600 in IBM 5160 address space)
	db	0C6h
TIMES 0x100-1 DB 0	; Pad with zero to address 4700h in ROM (i.e. address FC700 in IBM 5160 address space)
	db	0C7h
TIMES 0x100-1 DB 0	; Pad with zero to address 4800h in ROM (i.e. address FC800 in IBM 5160 address space)
	db	0C8h
TIMES 0x100-1 DB 0	; Pad with zero to address 4900h in ROM (i.e. address FC900 in IBM 5160 address space)
	db	0C9h
TIMES 0x100-1 DB 0	; Pad with zero to address 4A00h in ROM (i.e. address FCA00 in IBM 5160 address space)
	db	0CAh
TIMES 0x100-1 DB 0	; Pad with zero to address 4B00h in ROM (i.e. address FCB00 in IBM 5160 address space)
	db	0CBh
TIMES 0x100-1 DB 0	; Pad with zero to address 4C00h in ROM (i.e. address FCC00 in IBM 5160 address space)
	db	0CCh
TIMES 0x100-1 DB 0	; Pad with zero to address 4D00h in ROM (i.e. address FCD00 in IBM 5160 address space)
	db	0CDh
TIMES 0x100-1 DB 0	; Pad with zero to address 4E00h in ROM (i.e. address FCE00 in IBM 5160 address space)
	db	0CEh
TIMES 0x100-1 DB 0	; Pad with zero to address 4F00h in ROM (i.e. address FCF00 in IBM 5160 address space)
	db	0CFh

TIMES 0x100-1 DB 0	; Pad with zero to address 5000h in ROM (i.e. address FD000 in IBM 5160 address space)
	db	0D0h
TIMES 0x100-1 DB 0	; Pad with zero to address 5100h in ROM (i.e. address FD100 in IBM 5160 address space)
	db	0D1h
TIMES 0x100-1 DB 0	; Pad with zero to address 5200h in ROM (i.e. address FD200 in IBM 5160 address space)
	db	0D2h
TIMES 0x100-1 DB 0	; Pad with zero to address 5300h in ROM (i.e. address FD300 in IBM 5160 address space)
	db	0D3h
TIMES 0x100-1 DB 0	; Pad with zero to address 5400h in ROM (i.e. address FD400 in IBM 5160 address space)
	db	0D4h
TIMES 0x100-1 DB 0	; Pad with zero to address 5500h in ROM (i.e. address FD500 in IBM 5160 address space)
	db	0D5h
TIMES 0x100-1 DB 0	; Pad with zero to address 5600h in ROM (i.e. address FD600 in IBM 5160 address space)
	db	0D6h
TIMES 0x100-1 DB 0	; Pad with zero to address 5700h in ROM (i.e. address FD700 in IBM 5160 address space)
	db	0D7h
TIMES 0x100-1 DB 0	; Pad with zero to address 5800h in ROM (i.e. address FD800 in IBM 5160 address space)
	db	0D8h
TIMES 0x100-1 DB 0	; Pad with zero to address 5900h in ROM (i.e. address FD900 in IBM 5160 address space)
	db	0D9h
TIMES 0x100-1 DB 0	; Pad with zero to address 5A00h in ROM (i.e. address FDA00 in IBM 5160 address space)
	db	0DAh
TIMES 0x100-1 DB 0	; Pad with zero to address 5B00h in ROM (i.e. address FDB00 in IBM 5160 address space)
	db	0DBh
TIMES 0x100-1 DB 0	; Pad with zero to address 5C00h in ROM (i.e. address FDC00 in IBM 5160 address space)
	db	0DCh
TIMES 0x100-1 DB 0	; Pad with zero to address 5D00h in ROM (i.e. address FDD00 in IBM 5160 address space)
	db	0DDh
TIMES 0x100-1 DB 0	; Pad with zero to address 5E00h in ROM (i.e. address FDE00 in IBM 5160 address space)
	db	0DEh
TIMES 0x100-1 DB 0	; Pad with zero to address 5F00h in ROM (i.e. address FDF00 in IBM 5160 address space)
	db	0DFh


TIMES 0x100-1 DB 0	; Pad with zero to address 6000h in ROM (i.e. address FE000 in IBM 5160 address space)
	db	0E0h
TIMES 0x100-1 DB 0	; Pad with zero to address 6100h in ROM (i.e. address FE100 in IBM 5160 address space)
	db	0E1h
TIMES 0x100-1 DB 0	; Pad with zero to address 6200h in ROM (i.e. address FE200 in IBM 5160 address space)
	db	0E2h
TIMES 0x100-1 DB 0	; Pad with zero to address 6300h in ROM (i.e. address FE300 in IBM 5160 address space)
	db	0E3h
TIMES 0x100-1 DB 0	; Pad with zero to address 6400h in ROM (i.e. address FE400 in IBM 5160 address space)
	db	0E4h
TIMES 0x100-1 DB 0	; Pad with zero to address 6500h in ROM (i.e. address FE500 in IBM 5160 address space)
	db	0E5h
TIMES 0x100-1 DB 0	; Pad with zero to address 6600h in ROM (i.e. address FE600 in IBM 5160 address space)
	db	0E6h
TIMES 0x100-1 DB 0	; Pad with zero to address 6700h in ROM (i.e. address FE700 in IBM 5160 address space)
	db	0E7h
TIMES 0x100-1 DB 0	; Pad with zero to address 6800h in ROM (i.e. address FE800 in IBM 5160 address space)
	db	0E8h
TIMES 0x100-1 DB 0	; Pad with zero to address 6900h in ROM (i.e. address FE900 in IBM 5160 address space)
	db	0E9h
TIMES 0x100-1 DB 0	; Pad with zero to address 6A00h in ROM (i.e. address FEA00 in IBM 5160 address space)
	db	0EAh
TIMES 0x100-1 DB 0	; Pad with zero to address 6B00h in ROM (i.e. address FEB00 in IBM 5160 address space)
	db	0EBh
TIMES 0x100-1 DB 0	; Pad with zero to address 6C00h in ROM (i.e. address FEC00 in IBM 5160 address space)
	db	0ECh
TIMES 0x100-1 DB 0	; Pad with zero to address 6D00h in ROM (i.e. address FED00 in IBM 5160 address space)
	db	0EDh
TIMES 0x100-1 DB 0	; Pad with zero to address 6E00h in ROM (i.e. address FEE00 in IBM 5160 address space)
	db	0EEh
TIMES 0x100-1 DB 0	; Pad with zero to address 6F00h in ROM (i.e. address FEF00 in IBM 5160 address space)
	db	0EFh

TIMES 0x100-1 DB 0	; Pad with zero to address 7000h in ROM (i.e. address FF000 in IBM 5160 address space)
	db	0F0h
TIMES 0x100-1 DB 0	; Pad with zero to address 7100h in ROM (i.e. address FF100 in IBM 5160 address space)
	db	0F1h
TIMES 0x100-1 DB 0	; Pad with zero to address 7200h in ROM (i.e. address FF200 in IBM 5160 address space)
	db	0F2h
TIMES 0x100-1 DB 0	; Pad with zero to address 7300h in ROM (i.e. address FF300 in IBM 5160 address space)
	db	0F3h
TIMES 0x100-1 DB 0	; Pad with zero to address 7400h in ROM (i.e. address FF400 in IBM 5160 address space)
	db	0F4h
TIMES 0x100-1 DB 0	; Pad with zero to address 7500h in ROM (i.e. address FF500 in IBM 5160 address space)
	db	0F5h
TIMES 0x100-1 DB 0	; Pad with zero to address 7600h in ROM (i.e. address FF600 in IBM 5160 address space)
	db	0F6h
TIMES 0x100-1 DB 0	; Pad with zero to address 7700h in ROM (i.e. address FF700 in IBM 5160 address space)
	db	0F7h
TIMES 0x100-1 DB 0	; Pad with zero to address 7800h in ROM (i.e. address FF800 in IBM 5160 address space)
	db	0F8h
TIMES 0x100-1 DB 0	; Pad with zero to address 7900h in ROM (i.e. address FF900 in IBM 5160 address space)
	db	0F9h
TIMES 0x100-1 DB 0	; Pad with zero to address 7A00h in ROM (i.e. address FFA00 in IBM 5160 address space)
	db	0FAh
TIMES 0x100-1 DB 0	; Pad with zero to address 7B00h in ROM (i.e. address FFB00 in IBM 5160 address space)
	db	0FBh
TIMES 0x100-1 DB 0	; Pad with zero to address 7C00h in ROM (i.e. address FFC00 in IBM 5160 address space)
	db	0FCh
TIMES 0x100-1 DB 0	; Pad with zero to address 7D00h in ROM (i.e. address FFD00 in IBM 5160 address space)
	db	0FDh
TIMES 0x100-1 DB 0	; Pad with zero to address 0E00h in ROM (i.e. address FFE00 in IBM 5160 address space)
	db	0FEh
TIMES 0x100-1 DB 0	; Pad with zero to address 7F00h in ROM (i.e. address FFF00 in IBM 5160 address space)
	db	0FFh

; ----------------------------------------------------------------------------------------------
; CODE STARTS HERE, AT ADDRESS 7F01h in ROM (i.e. address FFF01 in IBM 5160 address space)
; ----------------------------------------------------------------------------------------------

	cli

	mov	ax,0F000H	; Segment of ROM address to be read
	mov	ds,ax		; Put that into the data segment register
	mov	bx,07F00h	; Offset of first ROM address to be read (i.e. 8000) minus 100H
	mov	cx,128		; 128 test addresses. So addresses F000:8000, F000:8100, F000:8200, F000:8300, ......... F000:FF00

NEXTADDR:
	; Test ROM address is stored in DS:BX
	; Calculate the next address to be tested
	add	bh,1		; e.g. BX=7F00 becomes BX=8000, BX=8000 becomes BX=8100, etc.

	; Output the high byte of the address offset (e.g. 80) to the LPT ports 
	mov	al,bh
	mov	dx,378h
	out	dx,al		; Send high byte to LPT port 378h
	mov	dx,278h
	out	dx,al		; Send high byte to LPT port 278h
	mov	dx,3BCh
	out	dx,al		; Send high byte to LPT port 3BCh

	; 2 second delay
	mov	dl,8
	mov	ax,cx		; Preserve CX
	sub	cx,cx
.loop:	loop	.loop
	dec	dl
	jnz	.loop
	mov	cx,ax		; Restore CX

	; Read the test address in the ROM
	; Is the read byte as expected?  Example: For address F000:9B00, expect to read the byte of 9B
	; If so (GOOD), output 11h to the LPT ports
	; If not (BAD), output 99h to the LPT ports
	mov	al,[ds:bx]	; Read the ROM address
	cmp	al,bh		; As expected?
	je	GOOD
	mov	al,099h		; BAD: Output 99h to LPT ports
	mov	dx,378h
	out	dx,al		; Send high byte to LPT port 378h
	mov	dx,278h
	out	dx,al		; Send high byte to LPT port 278h
	mov	dx,3BCh
	out	dx,al		; Send high byte to LPT port 3BCh
	jmp	CONT
GOOD:
	mov	al,11h		; GOOD: Output 11h to LPT ports
	mov	dx,378h
	out	dx,al		; Send high byte to LPT port 378h
	mov	dx,278h
	out	dx,al		; Send high byte to LPT port 278h
	mov	dx,3BCh
	out	dx,al		; Send high byte to LPT port 3BCh
CONT:
	; 2 second delay
	mov	dl,8
	mov	ax,cx		; Preserve CX
	sub	cx,cx
.loop:	loop	.loop
	dec	dl
	jnz	.loop
	mov	cx,ax		; Restore CX

	; If all 128 addresses not yet done, go do the next one
	loop	NEXTADDR

	; All 128 address done - halt
	hlt


TIMES 0x7FF0-($-$$) DB 0	; Pad out to reset vector

	jmp	0xFFF0:0001

TIMES 0x8000-($-$$) DB 0	; Pad out to end of ROM 




