home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / cpem8010.zip / util.cc < prev    next >
C/C++ Source or Header  |  1994-04-13  |  2KB  |  78 lines

  1. //     $Id: util.cc 1.2 1994/04/12 22:04:42 rg Exp $
  2. //      Copyright (c) 1994 by R. Griech
  3. //
  4. //  utility functions for CP/M
  5. //  --------------------------
  6. //  here are some utility functions
  7. //
  8.  
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <fcntl.h>
  13. #include <io.h>
  14. #include "glob.h"
  15.  
  16.  
  17.  
  18. void fatal( char *fmt, char *msg )
  19. {
  20.    fprintf( stderr,"fatal error: " );
  21.    fprintf( stderr,fmt,msg );
  22.    exit( 3 );
  23. }   // fatal
  24.  
  25.  
  26.  
  27. void RegisterDump( REGS r, char *ErrMsg, int DeArea )
  28. {
  29.    int i;
  30.    unsigned char *op = Mem+r.w.PC;
  31.  
  32.    fprintf( DIAG,"\r\n--------------------------------------------------------\r\n" );
  33.    fprintf( DIAG,"%s\r\n",ErrMsg );
  34.    fprintf( DIAG,"ops:     %02x %02x %02x %02x\r\n",op[0],op[1],op[2],op[3] );
  35.    fprintf( DIAG,"regs:    AF : %04x   BC : %04x   DE : %04x   HL : %04x\r\n",
  36.                    r.w.AF,r.w.BC,r.w.DE,r.w.HL );
  37.    fprintf( DIAG,"         AF': %04x   BC': %04x   DE': %04x   HL': %04x\r\n",
  38.                    r.w.AF2,r.w.BC2,r.w.DE2,r.w.HL2 );
  39.    fprintf( DIAG,"         IX : %04x   IY : %04x   SP : %04x   PC : %04x\r\n",
  40.                    r.w.IX,r.w.IY,r.w.SP,r.w.PC );
  41.    fprintf( DIAG,"stack:   " );
  42.    for (i = 0;  i < 16;  i++) {
  43.       fprintf( DIAG,"%04x", W(Mem+r.w.SP+2*i) );
  44.       if (i == 7)
  45.          fprintf( DIAG,"\r\n         " );
  46.       else
  47.          fprintf( DIAG," " );
  48.    }
  49.    fprintf( DIAG,"\r\n" );
  50.    if (DeArea) {
  51.       fprintf( DIAG,"*DE:     " );
  52.       for (i = 0;  i < 32;  i++) {
  53.          fprintf( DIAG,"%02x", B(Mem+r.w.DE+i) );
  54.          if (i == 15)
  55.             fprintf( DIAG,"\r\n         " );
  56.          else
  57.             fprintf( DIAG," " );
  58.       }
  59.       fprintf( DIAG,"\r\n" );
  60.    }
  61.    fprintf( DIAG,"--------------------------------------------------------\r\n" );
  62. }   // RegisterDump
  63.  
  64.  
  65.  
  66. void CoreDump( void )
  67. {
  68.    int Hnd, res;
  69.  
  70.    Hnd = open( CORE,O_WRONLY|O_BINARY|O_CREAT|O_TRUNC,0666 );
  71.    res = write( Hnd,Mem+TPA_BEG,CORESIZE );
  72.    if (res < 0)
  73.       fprintf( stderr,"can't create '%s'\r\n",CORE );
  74.    else
  75.       fprintf( stderr,"'%s' created\r\n",CORE );
  76.    close( Hnd );
  77. }   // CoreDump
  78.