mcleod_ideafix

HD Image to parallel port

Jan 28th, 2021 (edited)
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.01 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////////
  2. //    This file is HDIMAGE
  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. // Compile with Turbo C 2.0 for DOS
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <conio.h>
  28. #include <string.h>
  29. #include <dos.h>
  30. #include <bios.h>
  31.  
  32. int base;
  33.  
  34. #define DATOS (base)
  35. #define ESTADO (DATOS+1)
  36. #define CONTROL (DATOS+2)
  37.  
  38. int obtener_parametros_disco (int unidad, unsigned *cilindros, unsigned *cabezas, unsigned *sectores)
  39. {
  40.   int nc,nh,ns,estado;
  41.  
  42.   estado=nc=ns=nh=0;
  43.  
  44.   asm push bx
  45.   asm push cx
  46.   asm push dx
  47.   asm push si
  48.   asm push di
  49.   asm mov ah,8
  50.   asm mov dl,byte ptr unidad
  51.   asm int 13h
  52.   asm mov byte ptr estado,ah
  53.   asm mov byte ptr ns,cl
  54.   asm and cl,0c0h
  55.   asm shr cl,6
  56.   asm xchg cl,ch
  57.   asm inc cx
  58.   asm mov nc,cx
  59.   asm inc dh
  60.   asm mov byte ptr nh,dh
  61.   asm pop di
  62.   asm pop si
  63.   asm pop dx
  64.   asm pop cx
  65.   asm pop bx
  66.  
  67.   ns&=0x3f;
  68.   *cilindros=nc;
  69.   *cabezas=nh;
  70.   *sectores=ns;
  71.  
  72.   return estado;
  73. }
  74.  
  75. void escribe_paralelo (char *buffer, int tam)
  76. {
  77.   int i;
  78.   char dato;
  79.  
  80.   for (i=0;i<tam;i++)
  81.   {
  82.     dato=buffer[i];
  83.     while ((inp(ESTADO) & 0x80)==0)
  84.     {
  85.       if (kbhit())
  86.         if (getch()==27)
  87.           exit(1);
  88.     }
  89.  
  90.     outp (DATOS, dato);
  91.     outp (CONTROL, 1);
  92.  
  93.     while (inp(ESTADO) & 0x80)
  94.     {
  95.       if (kbhit())
  96.         if (getch()==27)
  97.           exit(1);
  98.     }
  99.  
  100.     outp (CONTROL, 0);
  101.   }
  102. }
  103.  
  104. void main (int argc, char *argv[])
  105. {
  106.   unsigned unidad, cilindros, cabezas, sectores;
  107.   unsigned cylact, cabact, secact, estado;
  108.   unsigned long total;
  109.   int *dpuerto;
  110.   char *buffer;
  111.  
  112.   dpuerto=MK_FP (0x40, 0x8);
  113.   base=*dpuerto;
  114.  
  115.   unidad=atoi(argv[1]);
  116.   estado=obtener_parametros_disco (unidad, &cilindros, &cabezas, &sectores);
  117.  
  118.   if (argc<5 && estado!=0)
  119.   {
  120.     printf ("Uso: HDIMAGE unidad cilindros cabezas sectores\n");
  121.     exit(1);
  122.   }
  123.  
  124.   if (argc>=5)
  125.   {
  126.     cilindros=atoi(argv[2]);
  127.     cabezas=atoi(argv[3]);
  128.     sectores=atoi(argv[4]);
  129.   }
  130.  
  131.   buffer=malloc(sectores*512);
  132.  
  133.   printf ("Se ha encontrado un puerto paralelo en %04.4X\n", base);
  134.  
  135.   printf ("Se va a proceder a leer desde la unidad %02.2X, con geometr¡a: %4u cilindros, %4u cabezas, %4u sectores por pista\n",
  136.            unidad, cilindros, cabezas, sectores);
  137.   total=(unsigned long)cilindros*(unsigned long)cabezas*(unsigned long)sectores;
  138.   printf ("Se transferiran %lu Mb.\n", total/2048);
  139.   printf ("Continuar? (S/N)");
  140.   if (getch()!='s')
  141.     exit(1);
  142.  
  143.   printf ("\n\n");
  144.  
  145.   for (cylact=0;cylact<cilindros;cylact++)
  146.   {
  147.     for (cabact=0;cabact<cabezas;cabact++)
  148.     {
  149.       for (secact=1;secact<=sectores;secact++)
  150.       {
  151.         estado=biosdisk(2,unidad,cabact,cylact,secact,1,buffer);
  152.         if (estado)
  153.         {
  154.           printf ("\n\nERROR!!! No se pudo leer el disco. (C=%d,H=%d,S=%d)\n",cylact,cabact,secact);
  155.           exit(1);
  156.         }
  157.         escribe_paralelo (buffer,512);
  158.         printf ("Realizado el %d %% de la operacion...  (%u:%u:%u)         \r", cylact*100/(cilindros-1), cylact, cabact, secact);
  159.       }
  160.     }
  161.   }
  162.   free(buffer);
  163. }
Add Comment
Please, Sign In to add comment