main() { /* check install state */ /* this is not correct code, per EMS spec only the segment is used with a fixed offset of 10 (0x0a) char far *p = (char far *)(long)getvect(0x67); if (p == NULL) printf("no int67"),exit(1); */ char far * p; unsigned long seg = *(int far *)(0x67 * 4 + 2); if (seg == NULL) { printf("no int67"); exit(1); } p = (char far *)(seg << 16); if (fmemcmp(p+10, "EMMXXXXX0",3) != 0) { printf("no emm386"); if (fmemcmp(MK_FP(FP_SEG(p),10), "EMMXXXX0",8) != 0) printf("really no emm386"),exit(1); } emmcall(0x46); /* printf("version %x\n",ir.h.al); */ printf("version %d.%d\n",ir.h.al >> 4, ir.h.al & 0x0f); emmcall(0x41); printf("page frame at %x\n",ir.x.bx); emmcall(0x42); printf("total pages %x(%dMB), free %x(%dMB)\n",ir.x.dx,ir.x.dx/(1024/16),ir.x.bx,ir.x.bx/(1024/16)); emmcall(0x4b); printf("emm handles %x\n",ir.x.bx); return 0; }
int fmemcmp_main(int argc, char ** argv) { char * buf, * buf2; uint32_t buflen, failure = 0, i; unsigned int x,y; unsigned int speed[3]; if(argc < 2) { // No input num, just use 1000 buflen = 1000000; } else { buflen = atoi(argv[1]); if(buflen == 0) return EXIT_FAILURE; } if(!(buf = malloc(buflen))) { printf("Couldn't allocate memory.\n"); return 0; } printf("Allocated %u bytes\n", buflen); if(!(buf2 = malloc(buflen))) { printf("Couldn't allocate memory.\n"); return 0; } printf("Allocated %u bytes\n", buflen); printf("Filling %u bytes with junk\n", buflen); for(i=0; i<buflen; i++) { buf[i] = buf2[i] = 1; } // TEST OF MEMCMP VS. FMEMCMP printf("***************** FMEMCMP *****************\n"); printf("Running system memcmp: "); GET_CYCLES(x); if(memcmp(buf, buf2, buflen) != 0) failure = 1; GET_CYCLES(y); printf("time=%u, ", y-x); speed[0] = y-x; if(!failure) { printf("Match!\n"); } else { printf("No Match!\n"); } failure = 0; printf("Running forloop memcmp: "); GET_CYCLES(x); for(i=0; i<buflen; i++) { if(buf[i] != buf2[i]) failure = 1; } GET_CYCLES(y); printf("time=%u, ", y-x); speed[1] = y-x; if(!failure) { printf("Match!\n"); } else { printf("No Match!\n"); } failure = 0; printf("Running fmemcmp: "); GET_CYCLES(x); if((fmemcmp(buf, buf2, buflen)) != 0) failure = 1; GET_CYCLES(y); printf("time=%u, ", y-x); speed[2] = y-x; if(!failure) { printf("Match!\n"); } else { printf("No Match! (%d)\n", failure); } failure = 0; // Summarize printf(":: fmemcmp is %g times faster than system memcmp.\n", ((float)speed[0])/speed[2]); printf(":: fmemcmp is %g times faster than forloop memcmp.\n", ((float)speed[1])/speed[2]); printf("***************** FMEMCMP *****************\n"); return EXIT_SUCCESS; }