home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / EXTRA-ST / CPM-80-E / CPM-0.2 / CPM-0 / cpm-0.2 / em.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  1.9 KB  |  93 lines

  1. /*****************************************************************************/
  2. /*                                         */
  3. /*                                         */
  4. /*    CP/M emulator version 0.1                         */
  5. /*                                         */
  6. /*    written by Michael Bischoff (mbi@mo.math.nat.tu-bs.de)             */
  7. /*    June-1994                                 */
  8. /*                                         */
  9. /*    This file is distributed under the GNU COPYRIGHT             */
  10. /*    see COPYRIGHT.GNU for Copyright details                     */
  11. /*                                         */
  12. /*                                         */
  13. /*****************************************************************************/
  14. #include "cpmemu.h"
  15.  
  16. /* read a character from input */
  17. /* if the character is ctrl-@, it is interpreted as BREAK */
  18.  
  19. int conin(void) {
  20.     int c;
  21.     if (!(c = getch())) {
  22.     debug = 2;
  23.     longjmp(mainloop, 1);
  24.     }
  25.     return c < 0 ? 0 : c;
  26. }
  27. int getdig(int mindig) {
  28.     int c;
  29.     fflush(stdout);
  30.     do {
  31.     c = conin();
  32.     } while (c < mindig || c > '9');
  33.     putchar(c);
  34.     fflush(stdout);
  35.     return c;
  36. }
  37. char *rdcmdline(int max, int ctrl_c_enable) {
  38.     int i, c;
  39.     static char s[258];
  40.  
  41.     fflush(stdout);
  42.     max &= 0xff;
  43.     i = 1;      /* number of next character */
  44. loop:
  45.     c = conin();
  46.     if (c < ' ' || c == 0x7f) {
  47.         switch (c) {
  48.     case 3:
  49.         if (ctrl_c_enable) {
  50.         putch('^');
  51.         putch('C');
  52.         z80regs.pc = BIOS+3;
  53.         s[0] = 0;
  54.         return s;
  55.         }
  56.         break;
  57.         case 8:
  58.     case 0x7f:
  59.         if (i > 1) {
  60.         --i;
  61.         printf("\b \b");
  62.         fflush(stdout);
  63.         }
  64.         break;
  65.         case '\n':
  66.         case '\r':
  67.         s[0] = i-1;
  68.         if (i <= max)
  69.         s[i] = '\r';
  70.         return s;
  71.         }
  72.         goto loop;
  73.     } else if (i <= max) {
  74.         s[i++] = c;
  75.         putchar(c);
  76.     fflush(stdout);
  77.     }
  78.     goto loop;
  79. }
  80. unsigned gethex(void) {
  81.     unsigned u;
  82.     char *s;
  83.     fflush(stdout);
  84.     s = rdcmdline(4, 0);
  85.     putchar('\r'); putchar('\n');
  86.     fflush(stdout);
  87.     s[s[0]+1] = '\0';
  88.     if (!s[0])
  89.     return z80regs.pc;
  90.     sscanf(s+1, "%x", &u);
  91.     return u;
  92. }
  93.