#include #include #include #include #include "gpioctl.h" // This defines the IOCTL constants. void main(void) { char *bin(int line); int out[1530],skip,found,line,i,l; puts("Close reset, push Enter, and then release."); while (getchar()==EOF){} line=0; i=0; while(in379()>127){} for(i=1;i<2;i++){} while(in379()<128){} for(i=1;i<2;i++){} while (line<=1030){ while(in379()>127){} for(i=1;i<2;i++){} l=in379(); out[line]=(((l & 0xf8) / 0x8) & 0xf); while(in379()<128){} for(i=1;i<2;i++){} line=line+1; } line=0; skip=1; freopen("dump.txt","w",stdout); puts("lin# addr hexd. bin. dat. source"); puts("------------------------------------"); while(line<=910){ printf("%3d | %2x | %1x%1x | %s%s| ",line/2,line/2,out[line+1],out[line],bin(out[line+1]),bin(out[line])); skip=skip-1; if(skip!=0){ if(out[line-2]==3 & out[line-1]==13){ found=0; if(out[line]==7 & out[line+1]==0){ found=1; printf("port 1b control \n");} if(out[line]==5 & out[line+1]==0){ found=1; printf("port 1b \n");} if(out[line]==10 & out[line+1]==0){ found=1; printf("port 2a control \n");} if(out[line]==8 & out[line+1]==0){ found=1; printf("port 2a \n");} if(out[line]==11 & out[line+1]==0){ found=1; printf("port 2b control \n");} if(out[line]==9 & out[line+1]==0){ found=1; printf("port 2b \n");} if(out[line]==6 & out[line+1]==0){ found=1; printf("port 1a control \n");} if(out[line]==4 & out[line+1]==0){ found=1; printf("port 1a \n");} if(out[line]==2 & out[line+1]==1){ found=1; printf("port 4a control \n");} if(out[line]==3 & out[line+1]==1){ found=1; printf("port 4b control \n");} if(out[line]==2 & out[line+1]==0){ found=1; printf("port 0a control \n");} if(out[line]==3 & out[line+1]==0){ found=1; printf("port 0b control \n");} if(out[line]==1 & out[line+1]==1){ found=1; printf("port 4b \n");} if(out[line]==0 & out[line+1]==0){ found=1; printf("port 0a \n");} if(out[line]==14 & out[line+1]==0){ found=1; printf("port 3a control \n");} if(out[line]==0 & out[line+1]==0){ found=1; printf("port 0a \n");} if(found==0){ printf("----------\n"); } } else{ printf("----------\n"); } } if(skip==0){ found=0; if(out[line]==14 & out[line+1]==3){ printf("LD A,n \n"); found=1; skip=2; } if(out[line]==3 & out[line+1]==13){ printf("OUT (n),A \n"); found=1; skip=2; } if(out[line]==3 & out[line+1]==2){ printf("INC HL \n"); found=1; skip=1; } if(out[line]==11 & out[line+1]==12 & out[line+2]==12 & out[line+3]==5){ printf("BIT b,r \n"); found=1; skip=2; } if(out[line]==6 & out[line+1]==0){ printf("LD B,n\n"); found=1; skip=2; } if(out[line]==14 & out[line+1]==1){ printf("LD E,n\n"); found=1; skip=2; } if(out[line]==13 & out[line+1]==1){ printf("DEC E\n"); found=1; skip=1; } if(out[line]==2 & out[line+1]==12){ printf("JP NZ nn\n"); found=1; skip=3; } if(out[line]==3 & out[line+1]==12){ printf("JP nn\n"); found=1; skip=3; } if(out[line]==0 & out[line+1]==0){ printf("NOP \n"); found=1; skip=1; } if(out[line]==5 & out[line+1]==0){ printf("DEC B \n"); found=1; skip=1; } if(out[line]==1 & out[line+1]==2){ printf("LD HL,nn \n"); found=1; skip=3; } if(out[line]==14 & out[line+1]==7){ printf("LD A,(HL) \n"); found=1; skip=1; } if(out[line]==6 & out[line+1]==15){ printf("OR n \n"); found=1; skip=2; } if(out[line]==6 & out[line+1]==14){ printf("AND n \n"); found=1; skip=2; } if(out[line]==15 & out[line+1]==0){ printf("RRCA \n"); found=1; skip=1; } if(out[line]==12 & out[line+1]==2){ printf("INC L \n"); found=1; skip=1; } if(out[line]==6 & out[line+1]==7){ printf("HALT \n"); found=1; skip=1; } if(out[line]==14 & out[line+1]==0){ printf("LD C,n \n"); found=1; skip=2; } if(out[line]==6 & out[line+1]==1){ printf("LD D,n \n"); found=1; skip=2; } if(out[line]==13 & out[line+1]==14){ printf("OUT (C),B \n"); found=1; skip=2; } if(out[line]==7 & out[line+1]==0){ printf("RLCA \n"); found=1; skip=1; } if(out[line]==11 & out[line+1]==12 & out[line+2]==0 & out[line+3]==0){ printf("RLC B \n"); found=1; skip=2; } if(out[line]==11 & out[line+1]==12 & out[line+2]==8 & out[line+3]==1){ printf("RR B \n"); found=1; skip=2; } if(out[line]==11 & out[line+1]==12 & out[line+2]==15 & out[line+3]==6){ printf("BIT 5,A \n"); found=1; skip=2; } if(out[line]==9 & out[line+1]==13){ printf("EXX \n"); found=1; skip=1; } if(out[line]==2 & out[line+1]==13){ printf("JP NC,nn \n"); found=1; skip=3; } if(out[line]==2 & out[line+1]==3){ printf("LD (nn),A \n"); found=1; skip=3; } if(out[line]==5 & out[line+1]==1){ printf("DEC D \n"); found=1; skip=1; } if(out[line]==8 & out[line+1]==0){ printf("EX AF,AF' \n"); found=1; skip=1; } if(out[line]==11 & out[line+1]==13){ printf("IN A,(n) \n"); found=1; skip=2; } if(out[line]==13 & out[line+1]==7){ printf("LD A,L \n"); found=1; skip=1; } if(out[line]==14 & out[line+1]==15){ printf("CP n \n"); found=1; skip=2; } if(out[line]==10 & out[line+1]==12){ printf("JP Z,nn \n"); found=1; skip=3; } if(out[line]==7 & out[line+1]==7){ printf("LD (HL),A \n"); found=1; skip=1; } if(out[line]==6 & out[line+1]==13){ printf("SUB n \n"); found=1; skip=2; } if(found==0){ printf("----------\n"); } } line=line+2; } fclose(stdout); } char *bin(int dec) { switch(dec){ case 0: return "0000"; case 1: return "0001"; case 2: return "0010"; case 3: return "0011"; case 4: return "0100"; case 5: return "0101"; case 6: return "0110"; case 7: return "0111"; case 8: return "1000"; case 9: return "1001"; case 10: return "1010"; case 11: return "1011"; case 12: return "1100"; case 13: return "1101"; case 14: return "1110"; case 15: return "1111"; } } int in379() { // The following is returned by IOCTL. It is true if the read succeeds. BOOL IoctlResult; // The following parameters are used in the IOCTL call HANDLE hndFile; // Handle to device, obtain from CreateFile ULONG PortNumber; // Buffer sent to the driver (Port #). union { ULONG LongData; USHORT ShortData; UCHAR CharData; } DataBuffer; // Buffer received from driver (Data). LONG IoctlCode; ULONG DataLength; DWORD ReturnedLength; // Number of bytes returned // The input buffer is a ULONG containing the port address. // The port data is returned in the output buffer DataBuffer; hndFile = CreateFile( "\\\\.\\GpdDev", // Open the Device "file" GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); IoctlCode = IOCTL_GPD_READ_PORT_UCHAR; DataLength = sizeof(DataBuffer.CharData); PortNumber=1; IoctlResult = DeviceIoControl( hndFile, // Handle to device IoctlCode, // IO Control code for Read &PortNumber, // Buffer to driver. sizeof(PortNumber), // Length of buffer in bytes. &DataBuffer, // Buffer from driver. DataLength, // Length of buffer in bytes. &ReturnedLength, // Bytes placed in DataBuffer. NULL // NULL means wait till op. completes. ); if (IoctlResult) // Did the IOCTL succeed? { ULONG Data; Data = DataBuffer.CharData; } if (!CloseHandle(hndFile)) // Close the Device "file". { printf("Failed to close device.\n"); } return (DataBuffer.CharData); }