# include # include "mult.h" unsigned int testad = 0; /* address of the last 4k memory in system */ rwalk() /* test rec. reg. walk-test */ { int a,b,i; error = rwalk; puts("\n****** recieve walk-test on port #"); putdec(group); puts(" ******\n\n"); in(TBASE); for( i=a=1; i<10; ++i) { base = SBASE; tran(a); base = TBASE; if((b = rec()) > 0xff) terflg(); else if(b != a) waler(a,b); /* test with inverted a */ base = SBASE; tran((~a & 0xff)); base = TBASE; if((b = rec()) > 0xff) terflg(); else if(b != (~a & 0xff)) waler((~a & 0xff),b); a = a << 1 & 0xff; } if(erflg == 0) puts("passes the recieve walk-test !\n"); } waler(a,b) /* prints walk error */ { puts("port #"); putdec(group); puts(" failed the walk-test !\nword "); putbin(a); puts(" came through as "); putbin(b); putc('\n'); terflg(); } bitest() /* test all bit lengths 5, 6, 7, 8, */ { int i,err; error = bitest; puts("\n****** testing different word lengths on port #"); putdec(group); puts("\n\n"); in(SBASE); /* clear port */ in(TBASE); /* clear port */ for(i= 5; i < 9; ++i) { wrdsze = i; base = TBASE; setparm(); err = 0; err = ckparm(); base = SBASE; setparm(); if(err |= ckparm() > 0xff) { puts("failed to set word length to "); putdec(i); puts(" bits !\n\n"); terflg(); } else walktest(i); } if(erflg == 0) puts("passes word length test !\n\n"); } walktest(s) /* walk bits and with mask for right length */ int s; { int a,b,i,mask; switch(s) { case 5 : mask = 0x1f; break; case 6 : mask = 0x3f; break; case 7 : mask = 0x7f; break; case 8 : mask = 0xff; break; } for( i = a = 1; i < 9 ; ++i) { base = TBASE; tran(a); base = SBASE; if((b = rec()) > 0xff) terflg(); if(b != (a & mask)) walker(a,(a & mask),b); /* test with inverted bits */ base = TBASE; tran(~a); base = SBASE; if((b = rec()) > 0xff) terflg(); if(b != (~a & mask)) walker((~a & 0xff),(~a & mask),b); a = (a << 1 & 0xff); } } walker(a,b,c) /* failure for word length walk test */ int a,b,c; { puts("port #"); putdec(group); puts(" failed the word length test !\nword "); putbin(a); puts(" should have come through as "); putbin(b); puts(" but came through as "); putbin(c); putc('\n'); terflg(); } parytest() /* test parity of serial ports */ { int err,b; error = parytest; puts("\n\n****** testing parity on port #"); putdec(group); puts(" ******\n\n"); parity = 'y'; eoparty = 'e'; if(bothset() > 0xff) /* set both to even parity */ { puts("failed to set parity correctly\n"); terflg(); } else /* check for good even parity check */ { base = TBASE; tran(0xa5); base = SBASE; if(rece() != 1) { puts("port #"); putdec(group); puts(" failed to transmit even parity\n"); terflg(); } base = SBASE; tran(0xa5); /* check to see if it can recieve even parity */ base = TBASE; if(rece() != 1) { puts("port #"); putdec(group); puts(" failed to recieve even parity!\n"); terflg(); } eoparty = 'o'; if(bothset() > 0xff) /* set to odd parity */ { puts("failed to set odd parity!\n"); terflg(); } else /* check for odd parity transmit */ { base = TBASE; tran(0xa5); base = SBASE; if(rece() != 1) { puts("port #"); putdec(group); puts(" failed to transmit odd parity!\n"); terflg(); } base = SBASE; tran(0xa5); base = TBASE; if(rece() != 1) /* check for odd parity recieve */ { puts("port #"); putdec(group); puts(" failed to recieve odd parity!\n"); terflg(); } } /* parity error check */ eoparty = 'e'; setparm(); if(ckparm() > 0xff) { puts("failed to set to even parity!\n"); terflg(); } else { tran(0xa5); base = SBASE; if(rece() != 5) { puts("port #"); putdec(group); puts(" failed to detect parity error!\n"); terflg(); } tran(0xa5); base = TBASE; if(rece() != 5) { puts("port #"); putdec(group); puts(" failed to send odd parity!\n"); terflg(); } } eoparty = 'o'; setparm(); b = ckparm(); base = SBASE; eoparty = 'e'; setparm(); if(b |= ckparm() > 0xff) { puts("failed to set parity!\n"); terflg(); } else /* reverse parities on both boards */ { tran(0xa5); base = TBASE; if(rece() != 5) { puts("port #"); putdec(group); puts(" failed to detect odd parity error!\n"); terflg(); } tran(0xa5); base = SBASE; if(rece() != 5) { puts("port #"); putdec(group); puts(" failed to send even parity!\n"); terflg(); } } } if(erflg == 0) puts("passes parity test !\n"); } ovtest() /* over flow test */ { int i,b; puts("\n\n****** overflow test on port #"); putdec(group); puts(" ******\n\n"); error = ovtest; base = SBASE; tran(53); /* output once */ tran(53); /* output again without inputting */ for( i = 0; i < 1000; ++i) /* delay loop */ ; base = TBASE; b = rece(); if(b != 3) { puts("\n didn't overflow on port #"); putdec(group); putc('\n'); terflg(); } else puts("passes over flow test !\n"); } rece() /* inputs the status word */ { int i,status; for( i=0; i<10000 ; ++i) { if((status = (in(base+5) & 0xf)) & 1 == 1) break; } in(base); /* clear recieve reg. */ return(status); } bgsel() /* select groups on both boards */ { base = SBASE; groupsel(); base = TBASE; groupsel(); } /* parallel port test */ partest() { error = partest; puts("******parallel ports are being tested******\n\n"); functs &= 0xcf; group = 0; bgsel(); /* select group 0 both boards */ out(SBASE,0); /* select port 0 input to non-test bd. */ out((SBASE+1),0); /* clear port 1 on non-test bd. */ out(TBASE,0); /* clear port 0 on test bd. */ out((TBASE+1),0); /* clear port 1 on test bd. */ if(in(SBASE) != 0) { puts("the printer port won't disable from the test board !\n"); terflg(); } else { functs |= 0x20; /* turn on the printer outputs */ bgsel(); pinwalk(); /* printer port input walk-test */ poutwalk(0); /* printer port 0 output walk-test */ out(SBASE,1); /* select port 1 on test board */ poutwalk(1); /* printer port 1 output walk-test */ out(SBASE,2); /* select restore bit on test board */ if(in(SBASE) & 1) /* if the restore bit isn't high */ { puts("the restore bit isn't high on test board\n"); terflg(); } functs |= 0x10; /* turn the restore bit low */ bgsel(); if(in(SBASE) & 1 == 0) /* if the restore bit isn't low */ { puts("the restore bit isn't low on test board\n"); terflg(); } } functs &= 0xcf; /* turn off printer ports and restore bit */ bgsel(); if(erflg == 0) puts("passes the parallel port test !\n\n"); } bothset() /* set both parameters up */ { int err; base = TBASE; setparm(); err = ckparm(); base = SBASE; setparm(); err |= ckparm(); return(err); } pinwalk() /* printer port input walk-test */ { int a,b,i; for(i = a = 1; i < 10; i++) { out((SBASE+1),a); b = ~in(TBASE) & 0xff; if(b != a) pwerr(a,b); /* test inverted walk-test also */ out((SBASE+1),(~a & 0xff)); b = (~in(TBASE) & 0xff); if(b != (~a & 0xff)) pwerr(~a & 0xff,b); a = a << 1 & 0xff; } if(erflg == 0) puts("passes parallel input walk-test on port #0 !\n\n"); } /* error for input walk-test */ pwerr(a,b) int a,b; { puts("parallel port failed the input walk-test\n"); puts("word "); putbin(a); puts(" came through as word "); putbin(b); puts("\n\n"); terflg(); } /* parallel port output walk-test */ poutwalk(z) int z; { int a,b,i; for(i = a = 1 ; i < 10; ++i) { out(TBASE+z,a); b = ~in(SBASE) & 0xff; if(b != a) poerr(a,b); /* test with inverted bits */ out(TBASE+z,~a & 0xff); b = (~in(SBASE) & 0xff); if(b != (~a & 0xff)) poerr(~a & 0xff,b); a = a << 1 & 0xff; } if(erflg == 0) { puts("passes parallel output walk-test on port #"); putdec(z); puts("\n\n"); } } /* parallel port error for output walk-test */ poerr(a,b) int a,b; { puts("parallel port failed the output walk-test\n"); puts("word "); putbin(a); puts(" came through as word "); putbin(b); puts("\n\n"); terflg(); } testram() /* should test ram here returns to cp/m */ { int a,b,i; unsigned char *mem; mem = testad; /* mem points to mem 0xftestad */ a = 1; /* initialize a */ for( i=0 ; i<8; ++i) { *mem = a; b = *mem; if(b != (a & 0xff)) { puts("memory fails walk-bit test at first location\n"); puts("word "); putbin(a); puts(" came through as word "); putbin(b); putc('\n'); memerr(); break; } a <<= 1; } for( i=0; i < 256; ++i) /* test one full page of memory */ *(mem+i) = i; /* store data in page */ for( i=0; i < 256; ++i) { b = *(mem+i); if(b != i) /* test for correct data */ { puts("memory fails test at location #"); putdec(i); puts("\nword "); putbin(i); puts(" read as word "); putbin(b); putc('\n'); memerr(); } } for( i=0 ; i < 16; ++i) *(mem+(i * 256)) = i; /* store data */ for( i=0; i < 16; ++i) { b = *(mem +(i * 256)); if( b != i) { puts("memory fails on page #"); putdec(i); puts(" \nword "); putbin(i); puts(" read as word "); putbin(b); putc('\n'); memerr(); } } if(erflg == 0) puts("passes memory test !\n"); oldtask(); } memerr() /* memory error reset mem addr */ { oldtask(); /* reset memory map */ terflg(); } finadd() /* locates the last 4k memory to use */ { int *a,b; a = 6; /* address of storage location of top of ram */ b = *a; /* b = addr of the last memory in system */ b &= 0xf000; /* mask out lower 12 bits from addr */ b -= 0x1000; /* subtract 4k from addr */ testad = b; /* store in external variable */ if(testad < 0x8000) /* if cp/m isn't big enough */ { puts("\n cp/m isn't big enough!!!!"); fatal(); } } memchng() /* maps page testad to page ftestad */ { int (*restore)(); unsigned char *mem,*pc; mem = (testad >> 12) * 2 + 0x220; /* addr of byte in vmap */ *mem = 0xfc; /* set new map byte */ *(mem+0x400) = 0xfc; /* set real map byte */ pc = 0x15; /* program counter for task 1 */ *pc = (unsigned) testram & 0xff; *(pc+1) = (unsigned) testram / 0x100; /* store addr of testram */ restore = 0x815; /* addr to restore task 1 */ (*restore)(); /* return to task 1 at testram */ } memtest() /* enters task 0 then jumps to memchng */ { int (*task)(); unsigned char taskchng[5]; puts("\n\n****** testing memory ******\n\n"); error = memtest; taskchng[0] = 0x76; /* machine code halt */ taskchng[1] = 0x76; /* machine code halt (traps into mon.) */ taskchng[2] = 0xc3; /* machine code jump */ taskchng[3] = (unsigned)(memchng) & 0xff; /* low addr of jump */ taskchng[4] = (unsigned)(memchng) / 0x100; /* high addr of jump */ task = taskchng; (*task)(); } endtest() /* after ram test is done , map is fixed return here */ { } unchng() /* restore map to original setup */ { int (*restore)(); unsigned char *mem,*pc; mem = (testad >> 12) * 2 + 0x220; /* addr of byte in vmap */ *mem = (testad >> 12); /* set new map byte */ *(mem+0x400) = (testad >> 12); /* set real map byte */ pc = 0x15; /* program counter for task 1 */ *pc = (unsigned) endtest & 0xff; *(pc+1) = (unsigned) endtest / 0x100; /* store addr of testram */ restore = 0x815; /* addr to restore task 1 */ (*restore)(); /* return to task 1 at testram */ } oldtask() /* enters task 0 then jumps to memchng */ { int (*task)(); unsigned char taskchng[5]; taskchng[0] = 0x76; /* machine code halt */ taskchng[1] = 0x76; /* machine code halt (traps into mon.) */ taskchng[2] = 0xc3; /* machine code jump */ taskchng[3] = (unsigned)(unchng) & 0xff; /* low addr of jump */ taskchng[4] = (unsigned)(unchng) / 0x100; /* high addr of jump */ task = taskchng; (*task)(); }