| 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | #include <conio.h>
|
|---|
| 4 | #include <dos.h>
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | //----------------------------------------------------------------------//
|
|---|
| 8 | // //
|
|---|
| 9 | //----------------------------------------------------------------------//
|
|---|
| 10 |
|
|---|
| 11 | void HexDump(void *pData, int nLength)
|
|---|
| 12 | {
|
|---|
| 13 | unsigned char acBuffer[81];
|
|---|
| 14 | unsigned char *p = acBuffer, *q = (unsigned char *)pData;
|
|---|
| 15 | int nIdx, n, nAscPos = 54;
|
|---|
| 16 |
|
|---|
| 17 | for( nIdx = 0; nIdx < nLength; nIdx++ )
|
|---|
| 18 | {
|
|---|
| 19 | p += sprintf((char *)p, "%02x ", q[nIdx]);
|
|---|
| 20 | n = nAscPos + (nIdx % 16);
|
|---|
| 21 | acBuffer[n] = ( q[nIdx] < 0x20 ) ? '.' : q[nIdx];
|
|---|
| 22 | acBuffer[n+1] = '\0';
|
|---|
| 23 |
|
|---|
| 24 | switch( (nIdx + 1) % 16 )
|
|---|
| 25 | {
|
|---|
| 26 | case 0: while( p < acBuffer + nAscPos ) *p++ = ' ';
|
|---|
| 27 | cprintf("%s\r\n", acBuffer); p = acBuffer;
|
|---|
| 28 | break;
|
|---|
| 29 | case 4:
|
|---|
| 30 | case 8:
|
|---|
| 31 | case 12: *p++ = ' ';
|
|---|
| 32 | break;
|
|---|
| 33 | }
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | if( p != acBuffer )
|
|---|
| 37 | {
|
|---|
| 38 | while( p < acBuffer + nAscPos ) *p++ = ' ';
|
|---|
| 39 | cprintf("%s\r\n", acBuffer);
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | // cprintf("\n");
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 | int main(int argc, char *argv[])
|
|---|
| 48 | {
|
|---|
| 49 | unsigned char achTemp[256];
|
|---|
| 50 | unsigned uIOBase = 0xe800;
|
|---|
| 51 | int i;
|
|---|
| 52 |
|
|---|
| 53 | if( argc > 1 )
|
|---|
| 54 | {
|
|---|
| 55 | uIOBase = (unsigned)strtoul(argv[1], NULL, 16);
|
|---|
| 56 | clrscr();
|
|---|
| 57 | cprintf("Portbase: %#x", uIOBase);
|
|---|
| 58 |
|
|---|
| 59 | while( !kbhit() )
|
|---|
| 60 | {
|
|---|
| 61 | gotoxy(1, 5);
|
|---|
| 62 | for( i = 0; i < 256; i++ ) achTemp[i] = inportb(uIOBase+i);
|
|---|
| 63 | HexDump(achTemp, sizeof(achTemp));
|
|---|
| 64 |
|
|---|
| 65 | geninterrupt(0x28);
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | getch();
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | return 0;
|
|---|
| 72 | }
|
|---|