home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Games / WHDLoad / Src / gci / dumpfile.c next >
C/C++ Source or Header  |  2000-06-04  |  4KB  |  165 lines

  1. /*****************************************************************************
  2. ;  :Module.    dumpfile.c
  3. ;  :Author.    Bert Jahn
  4. ;  :EMail.    jah@fh-zwickau.de
  5. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  6. ;  :Version.    $Id: dumpfile.c 0.7 2000/05/23 17:12:51 jah Exp $
  7. ;  :History.    18.07.98 started
  8. ;        13.12.98 dumpfilename from whdload.prefs
  9. ;        02.03.00 expmem stuff added
  10. ;             freedump() now resets all pointer
  11. ;  :Copyright.    All Rights Reserved
  12. ;  :Language.    C
  13. ;  :Translator.    GCC
  14. *****************************************************************************/
  15.  
  16. #include <string.h>
  17.  
  18. #include <dos/exall.h>
  19. #include <exec/memory.h>
  20. #include <libraries/iffparse.h>
  21. #include <libraries/mui.h>
  22.  
  23. #include <clib/dos_protos.h>
  24. #include <clib/exec_protos.h>
  25. #include <clib/muimaster_protos.h>
  26.  
  27. #include "whddump.h"
  28.  
  29. extern struct Library *MUIMasterBase;
  30. extern APTR app,win;
  31.  
  32. extern struct whddump_header    * header;
  33. extern char                        * term;
  34. extern struct whddump_cpu        * cpu;
  35. extern struct whddump_custom    * custom;
  36. extern struct whddump_cia        * ciaa;
  37. extern struct whddump_cia        * ciab;
  38. extern APTR                        * slave;
  39. extern APTR                        * mem;
  40. extern APTR                        * emem;
  41.  
  42. /****************************************************************************/
  43.  
  44. APTR    * dumpfile = NULL;
  45.  
  46. /****************************************************************************/
  47.  
  48. void freedump(void) {
  49.     if (dumpfile) {
  50.         FreeVec(dumpfile);
  51.         dumpfile = NULL;
  52.     }
  53.     header = NULL;
  54.     term = NULL;
  55.     cpu = NULL;
  56.     custom = NULL;
  57.     ciaa = NULL;
  58.     ciab = NULL;
  59.     slave = NULL;
  60.     mem = NULL;
  61.     emem = NULL;
  62. }
  63.  
  64. BOOL loaddump(STRPTR name) {
  65.     BOOL ret = FALSE;
  66.     BPTR fh;
  67.     ULONG size;
  68.     ULONG *tmp;
  69.     char filename[256]="";
  70.     char s[256];
  71.     char *t;
  72.     ULONG chk_id,chk_len;
  73.  
  74.     /*
  75.      * free any loaded dump
  76.      */
  77.     freedump();
  78.  
  79.     /*
  80.      * if there is no filename for the dump overgiven try to load
  81.      * whdload config and get the path from there
  82.      */
  83.     if (name) {
  84.         strcpy(filename,name);
  85.     } else {
  86.         fh = Open("S:whdload.prefs",MODE_OLDFILE);
  87.         if (fh) {
  88.             while (FGets(fh,s,256)) {
  89.                 if (strnicmp("coredumppath=",s,13) == 0) {
  90.                     t = strpbrk(&s[13]," \t\n\r");
  91.                     if (t) strncpy(filename,&s[13],t-s-13);
  92.                     else strcpy(filename,&s[13]);
  93.                     break;
  94.                 }
  95.             }
  96.             Close(fh);
  97.         }
  98.         strcat(filename,".whdl_dump");
  99.     }
  100.         
  101.     /*
  102.      * load dump
  103.      */
  104.     if (NULL == (fh = Open(filename,MODE_OLDFILE))) {
  105.             MUI_Request(app,win,0,NULL,"Ok","Could not open dumpfile \"%s\".",filename);
  106.         } else {
  107.         Seek(fh,0,OFFSET_END);
  108.         size = Seek(fh,0,OFFSET_BEGINNING);
  109.         if ((dumpfile = AllocVec(size,0))) {
  110.             if (size == Read(fh,dumpfile,size)) {
  111.                 tmp = (ULONG*)dumpfile;
  112.                 if (*tmp++ == ID_FORM && *tmp++ == size-8 && *tmp++ == ID_WHDD) {
  113.                     size -= 12;
  114.                     do {
  115.                         chk_id = *tmp++;
  116.                         chk_len = *tmp++;
  117.                         switch (chk_id) {
  118.                         case ID_HEAD:
  119.                             header = (struct whddump_header*)tmp;
  120.                             break;
  121.                         case ID_TERM:
  122.                             term = (char*)tmp;
  123.                             break;
  124.                         case ID_CPU:
  125.                             cpu = (struct whddump_cpu*)tmp;
  126.                             break;
  127.                         case ID_CUST:
  128.                             custom = (struct whddump_custom*)tmp;
  129.                             break;
  130.                         case ID_CIAA:
  131.                             ciaa = (struct whddump_cia*)tmp;
  132.                             break;
  133.                         case ID_CIAB:
  134.                             ciab = (struct whddump_cia*)tmp;
  135.                             break;
  136.                         case ID_SLAV:
  137.                             slave = (APTR)tmp;
  138.                             break;
  139.                         case ID_MEM:
  140.                             mem = (APTR)tmp;
  141.                             break;
  142.                         case ID_EMEM:
  143.                             emem = (APTR)tmp;
  144.                             break;
  145.                         }
  146.                         size -= 8 + chk_len;
  147.                         tmp += chk_len>>2;
  148.                         if (!size) ret = TRUE;
  149.                     } while (size>8 && !ret);
  150.                 }
  151.             }
  152.             if (!ret) {
  153.                 FreeVec(dumpfile);
  154.                 dumpfile = NULL;
  155.                 MUI_Request(app,win,0,NULL,"Ok","Dumpfile \"%s\" is corrupt.",filename);
  156.             }
  157.         }
  158.         Close(fh);
  159.     }
  160.     return ret;
  161. }
  162.  
  163. /****************************************************************************/
  164.  
  165.