1 2 #include "ticks.h" 3 #include <stdio.h> 4 #ifndef WIN32 5 #include <unistd.h> // For declarations of isatty() 6 #else 7 #include <conio.h> 8 #include <io.h> 9 #endif 10 hook_cpm(void)11void hook_cpm(void) 12 { 13 switch (c) { 14 case 0x01: // c_read 15 /* Returns A=L=character. 16 Wait for a character from the keyboard; then echo it to the screen and return it. 17 */ 18 a=l=fgetc(stdin); 19 break; 20 case 0x02: // c_write 21 // E = ascii character 22 if ( e != 12 ) { 23 fputc(e, stdout); 24 fflush(stdout); 25 } 26 break; 27 case 0x06: // C_RAWIO 28 // E=0FF Return a character without echoing if one is waiting; zero if none is available. 29 if ( e == 0xff ) { 30 int val; 31 if (isatty(fileno(stdin))) 32 val = getch(); // read one character at a time if connected to a tty 33 else 34 val = getchar(); // read in cooked mode if redirected from a file 35 if ( val == -1 ) val = 0; 36 else if ( val == 10 ) val = 13; 37 else if ( val == 13) val = 10; 38 a = val; 39 } 40 break; 41 case 0x09: // c_writestr de=string terminated by $ 42 { 43 int addr = d << 8 | e; 44 int tp; 45 while ( ( tp = *get_memory_addr(addr)) ) { 46 if ( tp == '$' ) 47 break; 48 fputc(tp, stdout); 49 addr++; 50 } 51 fflush(stdout); 52 break; 53 } 54 case 0x19: // DRV_GET 55 a = 0; // Current drive is a 56 break; 57 default: 58 fprintf(stderr,"Unsupported BDOS call %d\n",c); 59 break; 60 } 61 } 62