Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <windows.h>
- void _stdcall Out32(short PortAddress, short data);
- typedef short (_stdcall *inpfuncPtr)(short portaddr);
- typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum);
- #define PPORT_BASE 0x378
- void test_read8(void);
- void test_write(void);
- void test_write_datum(short datum);
- inpfuncPtr inp32fp;
- oupfuncPtr oup32fp;
- short Inp32 (short portaddr)
- {
- return (inp32fp)(portaddr);
- }
- void Out32 (short portaddr, short datum)
- {
- (oup32fp)(portaddr,datum);
- }
- int main(void)
- {
- HINSTANCE hLib;
- short x;
- int i;
- hLib = LoadLibrary("inpout32.dll");
- if (hLib == NULL) {
- fprintf(stderr,"LoadLibrary Failed.\n");
- return -1;
- }
- oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32");
- if (oup32fp == NULL) {
- fprintf(stderr,"GetProcAddress for Oup32 Failed.\n");
- return -1;
- }
- test_write();
- FreeLibrary(hLib);
- return 0;
- }
- void test_read8(void) {
- short x;
- int i;
- for (i=PPORT_BASE; (i<(PPORT_BASE+8)); i++) {
- x = Inp32(i);
- printf("Port read (%04X)= %04X\n",i,x);
- }
- }
- void test_write(void) {
- short x;
- int i;
- i=PPORT_BASE;
- x=0x00;
- Out32(i,x);
- printf("Se apagan todos los leds");
- getch();
- x=0xFF;
- Out32(i,x);
- printf("Se prenden todos los leds durante 5 segundos");
- Sleep(5000);
- x=0x00;
- Out32(i,x);
- printf("Se apagan todos los leds");
- printf("\n \n Fin de ejecucion... \n \n");
- getch();
- }
- void test_write_datum(short datum) {
- short x;
- int i;
- i=PPORT_BASE;
- x = datum;
- Out32(i,x);
- printf("Port write to 0x%X, datum=0x%2X\n" ,i ,x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement