home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / emulator / unix / z80pack / cpmsim / srcsim / simctl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-08  |  2.4 KB  |  112 lines

  1. /*
  2.  * Z80SIM  -  a Z80-CPU simulator
  3.  *
  4.  * Copyright (C) 1987,88,89,90 by Udo Munk
  5.  *
  6.  * History:
  7.  * 28-SEP-87 Development on TARGON/35 with AT&T Unix System V.3
  8.  * 14-MAR-89 new option -l
  9.  * 23-DEC-90 Ported to COHERENT 3.0
  10.  */
  11.  
  12. /*
  13.  *      Dieses Modul enthaelt die Bedieneroberflaeche des
  14.  *      Z80-CPU Simulators
  15.  */
  16.  
  17. #include <stdio.h>
  18. #if defined(COHERENT) && !defined(_I386)
  19. #include <sys/fcntl.h>
  20. #include <sgtty.h>
  21. #else
  22. #include <fcntl.h>
  23. #include <termio.h>
  24. #endif
  25. #include "sim.h"
  26. #include "simglb.h"
  27.  
  28. /*
  29.  *      Die Funktion holt den CP/M-Boot-Loader aus dem ersten
  30.  *      Sektor des simulierten Diskdrive A (Datei drivea.cpm) in
  31.  *      das Z80-RAM ab Adresse 0, wenn die Option l beim Aufruf
  32.  *      nicht angegeben wurde.
  33.  *      Anschliessend wird die Z80-CPU-Simulation gestartet.
  34.  */
  35. mon()
  36. {
  37.     void perror();
  38.  
  39.     register int fd;
  40. #if defined(COHERENT) && !defined(_I386)
  41.     static struct sgttyb old_term, new_term;
  42. #else
  43.     static struct termio old_term, new_term;
  44. #endif
  45.  
  46.     if (!l_flag) {
  47.         if ((fd = open("disks/drivea.cpm", O_RDONLY)) == -1) {
  48.             perror("file disks/drivea.cpm");
  49.             return;
  50.         }
  51.         if (read(fd, (char *) ram, 128) != 128) {
  52.             perror("file disks/drivea.cpm");
  53.             return;
  54.         }
  55.         close(fd);
  56.     }
  57.  
  58. #if defined(COHERENT) && !defined(_I386)
  59.     gtty(0, &old_term);
  60.     new_term = old_term;
  61.     new_term.sg_flags |= CBREAK;
  62.     new_term.sg_flags &= ~ECHO;
  63.     stty(0, &new_term);
  64. #else
  65.     ioctl(0, TCGETA, &old_term);
  66.     new_term = old_term;
  67.     new_term.c_lflag &= ~(ICANON | ECHO);
  68.     new_term.c_iflag &= ~(IXON | IXANY | IXOFF);
  69.     new_term.c_iflag &= ~(IGNCR | ICRNL | INLCR);
  70.     new_term.c_cc[4] = 1;
  71.     ioctl(0, TCSETAW, &new_term);
  72. #endif
  73.  
  74.     cpu_state = CONTIN_RUN;
  75.     cpu_error = NONE;
  76.     cpu();
  77.  
  78. #if defined(COHERENT) && !defined(_I386)
  79.     stty(0, &old_term);
  80. #else
  81.     ioctl(0, TCSETA, &old_term);
  82. #endif
  83.  
  84.     switch (cpu_error) {
  85.     case NONE:
  86.         break;
  87.     case OPHALT:
  88.         printf("HALT Op-Code reached at %04x\n", PC-ram-1);
  89.         break;
  90.     case IOTRAP:
  91.         printf("I/O Trap at %04x\n", PC-ram);
  92.         break;
  93.     case OPTRAP1:
  94.         printf("Op-code trap at %04x %02x\n", PC-1-ram, *(PC-1));
  95.         break;
  96.     case OPTRAP2:
  97.         printf("Op-code trap at %04x %02x %02x\n", PC-2-ram,
  98.                *(PC-2), *(PC-1));
  99.         break;
  100.     case OPTRAP4:
  101.         printf("Op-code trap at %04x %02x %02x %02x %02x\n",
  102.         PC-4-ram, *(PC-4), *(PC-3), *(PC-2), *(PC-1));
  103.         break;
  104.     case USERINT:
  105.         puts("User Interrupt");
  106.         break;
  107.     default:
  108.         printf("Unknown error %d\n", cpu_error);
  109.         break;
  110.     }
  111. }
  112.