#include #include #define P_PORT_DATA 888 #define P_PORT_INPUT 889 #define UNIX #define READTO 128 #define SC_OFF 0 /* (0) */ #define SC_POWER 1 /* (2^0) */ #define SC_RESET 2 /* (2^1) */ #define SC_CLOCK 4 /* (2^2) */ #define SC_VPP 16 /* (2^4) aka PGM*/ /* Bit maskes */ //#define BIT2 2 /* 0010 */ //#define OFF 0 /* 0000 * /* ^ this bit for pin 16 (initialise) */ #define SC_1 64 /* 0010 */ /* ^ this bit for pin 16 (initialise) */ /* function that writes a 0 to the bit */ int writebit_sc(int byte_offset, int bit_offset){ int i, currbit; reset_sc(); /* move to correct byte */ for (i=0; i=1; currbit--) { paraddrinc(); } } /* move to correct bit */ for (currbit=bit_offset; currbit>=1; currbit--) { paraddrinc(); } parsend(SC_POWER | SC_VPP); usleep(3); /* min 3 micro secs */ parsend(SC_POWER | SC_VPP | SC_CLOCK); parsend(SC_POWER | SC_CLOCK); usleep(5000); /* min 5 ms for writing */ parsend(SC_POWER); /* can check here on falling edge of clock*/ /* if bit was written correctly */ reset_sc(); /* sets address counter back to 0 */ return 1; } /* function that writes a 1 to the bit */ int erasebit_sc(int byte_offset, int bit_offset){ int i, currbit; reset_sc(); /* move to correct byte */ for (i=0; i=1; currbit--) { printf("%d %d %d %d\n",byte_offset,bit_offset,i,currbit); paraddrinc(); } } /* move to correct bit */ for (currbit=bit_offset; currbit>=1; currbit--) { paraddrinc(); } parsend(SC_POWER | SC_VPP); usleep(3); /* min 3 micro secs */ parsend(SC_POWER | SC_VPP | SC_CLOCK | SC_1); usleep(3); /* min 5 ms for writing */ parsend(SC_POWER | SC_CLOCK | SC_1); usleep(5000); /* min 5 ms for writing */ parsend(SC_POWER); /* can check here on falling edge of clock*/ /* if bit was written correctly */ reset_sc(); /* sets address counter back to 0 */ return 1; } /* int parsendIO(int value) { outb((unsigned char) value, P_PORT_INPUT); return 1; } */ int parsend(int value) { outb((unsigned char) value, P_PORT_DATA); return 1; } int parget() { return inb(P_PORT_INPUT); } int paropen() { #ifdef UNIX return !(ioperm(P_PORT_DATA, 3, P_PORT_INPUT)); #else return 1; #endif } int parclose() { #ifdef UNIX return !(ioperm(P_PORT_DATA, 3, 0)); #else return 1; #endif } int open_sc() { parsend(SC_OFF); /* power off */ usleep(1000); parsend(SC_POWER); /* power card */ usleep(1000); /* delay before reset */ reset_sc(); /* max 2.0 micro seconds till correct data appears at i/o */ usleep(10); return 1; } /* resets address counter to 0 */ int reset_sc() { parsend(SC_POWER | SC_RESET); parsend(SC_POWER | SC_RESET | SC_CLOCK); /* must be min 0.1 micro second */ parsend(SC_POWER | SC_RESET); parsend(SC_POWER); return 1; } int close_sc() { parsend(SC_OFF); return 1; } int paraddrinc() { parsend(SC_POWER | SC_CLOCK); parsend(SC_POWER); /* max 2.0 micro seconds till correct data appears at i/o */ usleep(2); return 1; } int dump_sc(int *buf, int bytes) { int i, currbit; for (i=0; i=1; currbit--) { buf[i] += ((parget() & 8)/8) * pow(2,currbit-1); usleep(2); /* min 3.3/2 micro secs between increments */ paraddrinc(); } } /* should work now but can't test */ buf[0]-=128; /* HACK */ return 1; } int pow(int i, int j) { int tally=1; while(j>0) { tally*=i; j--; } return tally; } /* 1111 1010 0000 0000 */ /* F A 0 0 */ /* $16 */ void showmetheMoney(){ erasebit_sc(53,1); /*erasebit_sc(53,2); erasebit_sc(53,3); erasebit_sc(53,4); erasebit_sc(53,5); writebit_sc(53,6); erasebit_sc(53,7); writebit_sc(53,8); writebit_sc(54,1); writebit_sc(54,2); writebit_sc(54,3); writebit_sc(54,4); writebit_sc(54,5); writebit_sc(54,6); writebit_sc(54,7); writebit_sc(54,8); */ } float amount_on_sc(int *tp) { int tpi=0; tpi=(tp[51]<<16) + (tp[52]<<8) + tp[53]; return tpi/4000.0; } int main() { int tp[READTO]; int i; memset(tp, 0, sizeof(tp)); if (!paropen()) { printf("Sorry, you need to be r00ted.\n"); exit(-1); } open_sc(); //dump_sc(tp, READTO); /* printf("HardCore Software Laundry Card Reader\n"); printf(" HEX DEC\n"); for (i=0; i