; MONITOR EQU TABLE ; ;;;SP EQU 10F0h BELL EQU 0x003E LETNL EQU 0x0006 IFNL EQU 0x0009 PRNTS EQU 0x000C PRNT EQU 0x0012 MSG EQU 0x0015 BRKEY EQU 0x001E GETL EQU 0x0003 GETKY EQU 0x001B BTHEX EQU 0x03C3 MHEX EQU 0x03B1 HLHEX EQU 0x03BA DPCT EQU 0x0DDC DPCT_SCROLL EQU 0xC0 DPCT_CSRDN EQU 0xC1 DPCT_CSRUP EQU 0xC2 DPCT_CSRRT EQU 0xC3 DPCT_CSRLT EQU 0xC4 DPCT_HOM EQU 0xC5 DPCT_CLS EQU 0xC6 DPCT_DEL EQU 0xC7 DPCT_INS EQU 0xC8 DPCT_ALPHA EQU 0xC9 DPCT_GRMOD EQU 0xCA DPCT_CR EQU 0xCD ; porty RAMDOWN equ 0xE0 RAMUP equ 0xE1 ROMDOWN equ 0xE2 MAPVRAM equ 0xE3 ROMVRAM equ 0xE4 PCGOPEN equ 0xE5 PCGCLOSE equ 0xE6 PCGPRIO equ 0xF0 ; zacatek programy prg_begin: equ 0x1200 org prg_begin - 0x80 ; MZF header db 0x01 db "MZ-1500 MEMTEST ",0x0d dw prg_end - prg_begin dw prg_start dw prg_begin db " " db " " db " " db " " db " " db " " db " " prg_start: ; di ld a,0x00 out (ROMVRAM),a ld a, DPCT_CLS call DPCT ld de,WELCMSG ; "RAM test MZ-1500 (c) Martin8bity 2016" call MSG call LETNL call LETNL TSTALLMEM: ld de,TSTMEMMSG ; "Testing memory " call MSG ld de,TST0000MSG ; "0000-0FFF " call MSG ld hl,0x0000 ; HL = base address ld de,0x1000 ; DE = number of Bytes di out (RAMDOWN),a call RAMTST ; Test memory, CARRY flag should be 0 if OK out (ROMVRAM),a ei jp C,MEMFAIL ld de,OKMSG ; "OK" call MSG call IFNL ; jp MEMADTST ld de,TSTMEMMSG ; "Testing memory " call MSG ld de,TST1800MSG ; "1800-CFFF " call MSG ld hl,0x1800 ; HL = base address ld de,0xB800 ; DE = number of Bytes call RAMTST ; Test memory, CARRY flag should be 0 if OK jp C,MEMFAIL ld de,OKMSG ; "OK" call MSG call IFNL ld de,TSTMEMMSG ; "Testing memory " call MSG ld de,TSTD000MSG ; "D000-FFFF " call MSG ld hl,0xD000 ; HL = base address ld de,0x3000 ; DE = number of Bytes out (RAMUP),a call RAMTST ; Test memory, CARRY flag should be 0 if OK out (ROMVRAM),a jp C,MEMFAIL ld de,OKMSG ; "OK" call MSG call IFNL ld de,TSTMEMMSG ; "Testing memory " call MSG ld de,TSTVRAMMSG ; "VRAM D000 " call MSG ; save VRAM ld hl,0xD000 ; HL = base address ld de,0x7000 ; DE = target address ld bc,0x1000 ; BC = number of Bytes ldir ; test VRAM ld hl,0xD000 ; HL = base address ld de,0x1000 ; DE = number of Bytes call RAMTST ; Test memory, CARRY flag should be 0 if OK ; restore VRAM push hl push af ld hl,0x7000 ; HL = base address ld de,0xD000 ; DE = target address ld bc,0x1000 ; BC = number of Bytes ldir pop af pop hl jp C,MEMFAIL ld de,OKMSG ; "OK" call MSG call IFNL ; fill PCG VRAM memory to make tests visible, not needed, just for visual fun call SAVEPCGVRAM ld a,0x03 out (PCGPRIO),a ld d,0x00 ld hl,0xD400 ld bc,0x0400 fillscr1: ld (hl),d inc hl inc d dec bc ld a,b or c jr nz, fillscr1 ld d,0x08 ld hl,0xDC00 ld bc,0x0400 fillscr2: ld (hl),d inc hl dec bc ld a,c add a, 0 jr nz, fillscr2 ld a, d add a, 0x40 ld d, a ld a,c or b jr nz, fillscr2 ; end of fill PCG VRAM mememory ld de,TSTMEMMSG ; "Testing memory " call MSG ld de,TSTPCGBMSG ; "PCG BLUE " call MSG ld hl,0xD000 ; HL = base address ld de,0x2000 ; DE = number of Bytes ld a,0x01 ; BLUE out (PCGOPEN),a call RAMTST ; Test memory, CARRY flag should be 0 if OK out (PCGCLOSE),a out (ROMVRAM),a jp C,MEMFAIL ld de,OKMSG ; "OK" call MSG call IFNL ld de,TSTMEMMSG ; "Testing memory " call MSG ld de,TSTPCGRMSG ; "PCG RED " call MSG ld hl,0xD000 ; HL = base address ld de,0x2000 ; DE = number of Bytes ld a,0x02 ; RED out (PCGOPEN),a call RAMTST ; Test memory, CARRY flag should be 0 if OK out (PCGCLOSE),a out (ROMVRAM),a jp C,MEMFAIL ld de,OKMSG ; "OK" call MSG call IFNL ld de,TSTMEMMSG ; "Testing memory " call MSG ld de,TSTPCGGMSG ; "PCG GREEN " call MSG ld hl,0xD000 ; HL = base address ld de,0x2000 ; DE = number of Bytes ld a,0x03 ; GREEN out (PCGOPEN),a call RAMTST ; Test memory, CARRY flag should be 0 if OK out (PCGCLOSE),a out (ROMVRAM),a jp C,MEMFAIL ld de,OKMSG ; "OK" call MSG call IFNL ; restore PCG VRAM and switch PCG OFF call RESTPCGVRAM ld a,0 out (PCGPRIO),a ; memory address test MEMADTST: ld de,TSTMEMMSG ; "Testing memory " call MSG ld de,TSTADDRMSG ; "addresses " call MSG ; save VRAM ld hl,0xD000 ; HL = base address ld de,0x1800 ; DE = target address ld bc,0x1000 ; BC = number of Bytes ldir ; fill RAM with address pattern out (RAMDOWN),a out (RAMUP),a ; fill area 0000H-0FFFH ld hl,0x0000 ld bc,0x1000 ld a,0x01 call FILLADDR ; fill area 2800H-FFFFH ld hl,0x2800 ld bc,0xD800 ld a,0x02 call FILLADDR out (ROMVRAM),a ; fill PCG VRAM BLUE ld hl,0xD000 ; HL = base address ld bc,0x2000 ; BC = number of Bytes ld a,0x01 ; BLUE out (PCGOPEN),a ld a,0x04 call FILLADDR out (PCGCLOSE),a out (ROMVRAM),a ; fill PCG VRAM RED ld hl,0xD000 ; HL = base address ld bc,0x2000 ; BC = number of Bytes ld a,0x02 ; RED out (PCGOPEN),a ld a,0x08 call FILLADDR out (PCGCLOSE),a out (ROMVRAM),a ; fill PCG VRAM GREEN ld hl,0xD000 ; HL = base address ld bc,0x2000 ; BC = number of Bytes ld a,0x03 ; GREEN out (PCGOPEN),a ld a,0x10 call FILLADDR out (PCGCLOSE),a out (ROMVRAM),a ; test RAM for address pattern out (RAMDOWN),a out (RAMUP),a ; test area 0000H-0FFFH ld hl,0x0000 ld bc,0x1000 ld a,0x01 call TESTADDR jp C,MEMADFAIL ; fill area 2800H-FFFFH ld hl,0x2800 ld bc,0xD800 ld a,0x02 call TESTADDR jp C,MEMADFAIL out (ROMVRAM),a ; test PCG VRAM BLUE ld hl,0xD000 ; HL = base address ld bc,0x2000 ; BC = number of Bytes ld a,0x01 ; BLUE out (PCGOPEN),a ld a,0x04 call TESTADDR out (PCGCLOSE),a out (ROMVRAM),a jp C,MEMADFAIL ; test PCG VRAM RED ld hl,0xD000 ; HL = base address ld bc,0x2000 ; BC = number of Bytes ld a,0x02 ; RED out (PCGOPEN),a ld a,0x08 call TESTADDR out (PCGCLOSE),a out (ROMVRAM),a jp C,MEMADFAIL ; test PCG VRAM GREEN ld hl,0xD000 ; HL = base address ld bc,0x2000 ; BC = number of Bytes ld a,0x03 ; GREEN out (PCGOPEN),a ld a,0x10 call TESTADDR ; restore VRAM MEMADFAIL: out (PCGCLOSE),a out (ROMVRAM),a push hl push af ld hl,0x1800 ; HL = base address ld de,0xD000 ; DE = target address ld bc,0x1000 ; BC = number of Bytes ldir ; just to be sure no PCG ld a,0x00 out (PCGPRIO),a pop af pop hl inc hl jp C,MEMFAIL ld de,OKMSG ; "OK" call MSG call IFNL ; EVERYTHING OK - REPEAT TESTS ld de,ALLMEMOKMSG call MSG call IFNL call LETNL jp TSTALLMEM ; LOOP FOR MORE TESTING MEMFAIL: push af ld de,ERRMSG ; "ERR " call MSG ld de,ERRADDRMSG call MSG dec HL call HLHEX call PRNTS ld de,ERRDTAMSG call MSG pop af call BTHEX halt ld a,0x03 out (PCGPRIO),a ; ei halt ; ***************** END OF MAIN ******************* WELCMSG: DB "RAM", 05H, " TEST ", 05H, "MZ-1500", 05H, " (C) ", 05H, "M", 05H, "ARTIN8BITY 2016", 05H, 0DH TSTMEMMSG: DB "T", 05H, "ESTING ", 05H, 0DH TST0000MSG: DB "0000-0FFF ", 0DH TST1800MSG: DB "1800-CFFF ", 0DH TSTD000MSG: DB "D000-FFFF ", 0DH TSTVRAMMSG: DB "VRAM D000 ", 0DH TSTPCGBMSG: DB "PCG B", 05H, "LUE ", 05H, 0DH TSTPCGRMSG: DB "PCG R", 05H, "ED ", 05H, 0DH TSTPCGGMSG: DB "PCG G", 05H, "REEN ", 05H, 0DH TSTADDRMSG: DB 05H, "ADDRESSES ", 05H, 0DH ALLMEMOKMSG: DB "A", 05H, "LL MEMORY ", 05H, "OK!", 0DH ERRMSG: DB "ERR ", 0DH ERRADDRMSG: DB "A", 05H, "DDR=", 05H, 0DH ERRDTAMSG: DB "D", 05H, "ATA=", 05H, 0DH OKMSG: DB "OK ", 0DH ; ***************** SUBROUTINES ******************* SAVEPCGVRAM: push hl push de push bc push af ; save PCG VRAM 1 ld hl,0xD400 ; HL = base address ld de,0x7400 ; DE = target address ld bc,0x0400 ; BC = number of Bytes ldir ; save PCG VRAM 2 ld hl,0xDC00 ; HL = base address ld de,0x7C00 ; DE = target address ld bc,0x0400 ; BC = number of Bytes ldir pop af pop bc pop de pop hl ret RESTPCGVRAM: push hl push de push bc push af ; save PCG VRAM 1 ld hl,0x7400 ; HL = base address ld de,0xD400 ; DE = target address ld bc,0x0400 ; BC = number of Bytes ldir ; save PCG VRAM 2 ld hl,0x7C00 ; HL = base address ld de,0xDC00 ; DE = target address ld bc,0x0400 ; BC = number of Bytes ldir pop af pop bc pop de pop hl ret ; Title RAM test ; Name: RAMTST ; ; Purpose: Test a RAM (read/write memory) area ; 1) Write all 0 and test ; 2) Write all FF hex and test ; 3) Write all AA hex and test ; 4) Write all 55 hex and test ; 5) Shift a single 1 through each bit, ; while clearing all other bits ; ; If the program finds an error, it exits ; immediately with the Carry flag set and ; indicates where the error occurred and ; what value it used in the test. ; ; Entry: Register pair HL = Base address of test area ; Register pair DE = Size of area in bytes ; ; Exit: If there are no errors then ; Carry flag = 0 ; test area contains 0 in all bytes ; else ; Carry flag = 1 ; Register pair HL = Address of error ; Register A = Expected value ; ; Registers used: AF,BC,DE.HL ; ; Time: Approximately 633 cycles per byte plus ; 663 cycles overhead ; ; Size: Program 82 bytes RAMTST: ; EXIT WITH NO ERRORS IF SIZE IS ZERO LD A,D ; TEST AREA SIZE OR E RET Z ; EXIT WITH NO ERRORS IF AREA SIZE IS 0 LD B,D ; BC = AREA SIZE LD C,E ; FILL MEMORY WITH 0 AND TEST SUB A CALL FILCMP RET C ; EXIT IF ERROR FOUND ; FILL MEMORY WITH FF HEX (ALL 1'S) AND TEST LD A,0FFH CALL FILCMP RET C ; EXIT IF ERROR FOUND ; FILL MEMORY WITH AA HEX (ALTERNATING 1's AND 0'S) AND TEST LD A,0AAH CALL FILCMP RET C ; EXIT IF ERROR FOUND ; FILL MEMORY WITH 55 HEX (ALTERNATING 0'S AND 1'S) AND TEST LD A,055H CALL FILCMP RET C ; EXIT IF ERROR FOUND ; PERFORM WALKING BIT TEST. PLACE A 1 IN BIT 7 AND ; SEE IF IT CAN BE READ BACK. THEN MOVE THE 1 TO ; BITS 6, 5, 4, 3, 2, 1 AND 0 AND SEE IF IT CAN ; BE READ BACK WLKLP: LD A,10000000B ; MAKE BIT 7 1, ALL OTHER BITS 0 WLKLP1: LD (HL),A ; STORE TEST PATTERN IN MEMORY CP (HL) ; TRY TO READ IT BACK SCF ; SET CARRY IN CASE OF ERROR RET NZ ; RETURN IF ERROR RRCA ; ROTATE PATTERN TO MOVE 1 RIGHT CP 10000000B JR NZ,WLKLP1 ; CONTINUE UNTIL 1 IS BACK IN BIT 7 LD (HL),0 ; CLEAR BYTE JUST CHECKED INC HL DEC BC ; DECREMENT AND TEST 16-BIT COUNTER LD A,B OR C JR NZ,WLKLP ; CONTINUE UNTIL MEMORY TESTED RET ; No ERRORS ; ROUTINE: FILCMP ; PURPOSE: FILL MEMORY WITH A VALUE AND TEST ; THAT IT CAN BE READ BACK ; ; ENTRY: A = TEST VALUE ; HL = BASE ADDRESS ; BC = SIZE OF AREA IN BYTES ; EXIT: IF NO ERRORS THEN ; CARRY FLAG IS 0 ; ELSE ; CARRY FLAG IS 1 ; HL = ADDRESS OF ERROR ; DE = BASE ADDRESS ; BC = SIZE OF AREA IN BYTES ; A = TEST VALUE ; REGISTERS USED: AF, BC, DE, HL FILCMP: PUSH HL ; SAVE BASE ADDRESS PUSH BC ; SAVE SIZE OF AREA LD E, A ; SAVE TEST VALUE LD (HL),A ; STORE TEST VALUE IN FIRST BYTE DEC BC ; REMAINING AREA = SIZE - 1 LD A,B ; CHECK IF ANYTHING IN REMAINING AREA OR C LD A,E ; RESTORE TEST VALUE JR Z,COMPARE ; BRANCH IF AREA WAS ONLY 1 BYTE ; FILL REST OF AREA USING BLOCK MOVE ; EACH ITERATION MOVES TEST VALUE TO NEXT HIGHER ADDRESS LD D,H ; DESTINATION IS ALWAYS SOURCE + 1 LD E,L INC DE LDIR ; FILL MEMORY ; NOW THAT MEMORY HAS BEEN FILLED, TEST TO SEE IF ; EACH BYTE CAN BE READ BACK CORRECTLY COMPARE: POP BC ; RESTORE SIZE OF AREA POP HL ; RESTORE BASE ADDRESS PUSH HL ; SAVE BASE ADDRESS PUSH BC ; SAVE SIZE OF VALUE ; COMPARE MEMORY AND TEST VALUE CMPLP: CPI JR NZ,CMPER ; JUMP IF NOT EQUAL JP PE,CMPLP ; CONTINUE THROUGH ENTIRE AREA ; NOTE CPI CLEARS P/V FLAG IF IT ; DECREMENTS BC TO 0 ; NO ERRORS FOUND, SO CLEAR CARRY POP BC ; BC = SIZE OF AREA POP HL ; HL = BASE ADDRESS OR A ; CLEAR CARRY, INDICATING NO ERRORS RET ; ERROR EXIT, SET CARRY ; HL = ADDRESS OF ERROR ; A = TEST VALUE CMPER: POP DE ; DE = SIZE OF AREA POP BC ; BC = BASE ADDRESS SCF ; SET CARRY, INDICATING AN ERROR RET FILLADDR: PUSH DE LD D,A ; REMEMBER VALUE FILAD1: LD E,H LD (HL),L ; STORE ADDRESS IN FIRST 2 BYTES INC HL LD (HL),E INC HL LD A,D LD (HL),A INC HL CPL LD (HL),A INC HL DEC BC ; REMAINING AREA = SIZE - 4 DEC BC DEC BC DEC BC LD A,B ; CHECK IF ANYTHING IN REMAINING AREA OR C JR NZ,FILAD1 ; REPEAT WHILE NOT FINISHED POP DE RET TESTADDR: LD D,A ; REMEMBER VALUE PUSH DE TESTAD1: LD E,H LD A,(HL) CP L JR NZ,TSTADFAIL INC HL LD A,(HL) CP E JR NZ,TSTADFAIL INC HL LD A,(HL) CP D JR NZ,TSTADFAIL INC HL LD A,(HL) CPL CP D JR NZ,TSTADFAIL INC HL DEC BC ; REMAINING AREA = SIZE - 4 DEC BC DEC BC DEC BC LD A,B ; CHECK IF ANYTHING IN REMAINING AREA OR C JR NZ,TESTAD1 ; REPEAT WHILE NOT FINISHED POP DE LD A,D SCF CCF RET TSTADFAIL: POP DE LD A,D SCF RET prg_end: