Advertisement
mcleod_ideafix

Read parallel port data and write it to a file

Jan 28th, 2021
1,393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.20 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////////
  2. //    This file is LEEPAR
  3. //    Creation date is sometime in the 90's by Miguel Angel Rodriguez Jodar
  4. //    (c)2020 Miguel Angel Rodriguez Jodar. ZXProjects
  5. //
  6. //    This program is free software: you can redistribute it and/or modify
  7. //    it under the terms of the GNU General Public License as published by
  8. //    the Free Software Foundation, either version 3 of the License, or
  9. //    (at your option) any later version.
  10. //
  11. //    This program is distributed in the hope that it will be useful,
  12. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. //    GNU General Public License for more details.
  15. //
  16. //    You should have received a copy of the GNU General Public License
  17. //    along with this core.  If not, see <https://www.gnu.org/licenses/>.
  18. //
  19. //    All copies of this file must keep this notice intact.
  20. //
  21. //////////////////////////////////////////////////////////////////////////////////
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <conio.h>
  26. #include <string.h>
  27. #include <dos.h>
  28. #include <bios.h>
  29.  
  30. int base;
  31.  
  32. #define DATOS (base)
  33. #define ESTADO (DATOS+1)
  34. #define CONTROL (DATOS+2)
  35.  
  36. void main (int argc, char *argv[])
  37. {
  38.   char *buffer;
  39.   FILE *f;
  40.   int fin;
  41.   char dato;
  42.   int *dpuerto;
  43.   unsigned long i=0;
  44.  
  45.   dpuerto=MK_FP (0x40, 0x8);
  46.   base=*dpuerto;
  47.  
  48.   if (argc<2)
  49.   {
  50.     printf ("Uso: LEEPAR fichero\n");
  51.     exit(1);
  52.   }
  53.  
  54.   printf ("Encontrado puerto parlelo en %04.4X\n", base);
  55.  
  56.   buffer=malloc(512);
  57.   f=fopen (argv[1], "wb");
  58.  
  59.   fin=0;
  60.   while (!fin)
  61.   {
  62.     outp (CONTROL, 0x22); //autofeed=1, el en otro lado, busy=1
  63.     while ((inp(ESTADO) & 0x40))
  64.     {
  65.       if (kbhit())
  66.         if (getch()==27)
  67.         {
  68.           fin=1;
  69.           break;
  70.         }
  71.     }
  72.     outp (CONTROL, 0x20);
  73.     dato=inp (DATOS);
  74.     fwrite (&dato, 1, 1, f);
  75.  
  76.     printf ("Leidos %lu bytes        \r", ++i);
  77.  
  78.     while ((inp(ESTADO) & 0x40)==0)
  79.     {
  80.       if (kbhit())
  81.         if (getch()==27)
  82.         {
  83.           fin=1;
  84.           break;
  85.         }
  86.     }
  87.   }
  88.  
  89.   fclose(f);
  90.   free(buffer);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement