home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: DFÜ und Kommunikation / SOS-DFUE.ISO / programm / dos / utility / pccp076 / emued.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-10  |  9.2 KB  |  327 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  */
  3.  
  4. #include<stdio.h>
  5. #include<fcntl.h>
  6. #include<sys\types.h>
  7. #include<sys\stat.h>
  8. #include<bios.h>
  9. #include<graph.h>
  10. #include"emu.h"
  11.  
  12. main(argc, argv)
  13.     int argc;
  14.     char **argv;
  15.     {
  16.     int emufd, major, minor, scan, value;
  17.     char c, fpname[256];
  18.     _settextposition(25,1);
  19.     printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  20.     printf("You may set the environment variable PCCPPATH.\n");
  21.     printf("If not set we use the current directory.\n\n");
  22.     printf("You should have a copy of emu.h to consult to program display functions.\n\n");
  23.     printf("Making a variable length substitution token last in a\n");
  24.     printf("function sequence is highly questionable.\n\n");
  25.     if(!strcmp(getenv("REMOTE"), "YES"))
  26.         {
  27.         printf("You appear to be logged in remotely, judging by the environment\n");
  28.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  29.         printf("Are you sure you want to run EMUED? (y or n) --> ");
  30.         if(getchar()!='y') /* Note getchar() and not getch()! */
  31.             {
  32.             printf("I didn't think so!\n");
  33.             exit(99);
  34.             }
  35.         else
  36.             printf("OK, you're the boss!\n");
  37.         }
  38.     if(argc!=2)
  39.         {
  40.         printf("USAGE: emued <emu file basename>\n");
  41.         exit(1);
  42.         }
  43.     if((getenv("PCCPPATH")==NULL)||(argv[1][0]=='.')||(argv[1][0]=='\\')&&(argv[1][0]&&(argv[1][1]!=':')))
  44.         sprintf(fpname, "%s.emu", argv[1]);
  45.     else
  46.         sprintf(fpname, "%s\\%s.emu", getenv("PCCPPATH"), argv[1]);
  47.     if((emufd=open(fpname, O_RDONLY|O_BINARY))==-1)
  48.         {
  49.         printf("Error opening existing emu file %s for read.\nStarting from scratch.\n\n", fpname);
  50.         nullemu();
  51.         }
  52.     else if(read(emufd, &emu, sizeof(emu))!=sizeof(emu))
  53.         {
  54.         printf("Error reading existing emu file %s.\nStarting from scratch.\n\n", fpname);
  55.         nullemu();
  56.         }
  57.     if(emufd!=-1)
  58.         close(emufd);
  59.     while(1)
  60.         {
  61.         printf("\n\nm(isc), k(ey), f(unc), g(raphics char), w(rite) or q(uit)? --> ");
  62.         c=getch();
  63.         printf("%c\n", c);
  64.         if(c=='m')
  65.             {
  66.             printf("First column numeric address = %d\n", emu.firstcoladdr);
  67.             printf("First row numeric address = %d\n", emu.firstrowaddr);
  68.             printf("Modify? --> ");
  69.             if(getch()=='y')
  70.                 {
  71.                 printf("y\nEnter first column numeric address (decimal): --> ");
  72.                 scanf("%d", &value);
  73.                 emu.firstcoladdr=value;
  74.                 printf("Enter first row numeric address (decimal): --> ");
  75.                 scanf("%d", &value);
  76.                 emu.firstrowaddr=value;
  77.                 }
  78.             else
  79.                 printf("n\n");
  80.             printf("\ntophi_p = %d {1 => top row is 24; 0 => top is 1}\n", (int)emu.tophi_p);
  81.             printf("Binary row offset = %02x\n", emu.binrowoff);
  82.             printf("Binary column offset = %02x\n", emu.bincoloff);
  83.             printf("default_wrap_p = %d\n", emu.default_wrap_p);
  84.             printf("Modify? --> ");
  85.             if(getch()=='y')
  86.                 {
  87.                 printf("y\nEnter tophi_p (0 or 1): --> ");
  88.                 scanf("%d", &value);
  89.                 emu.tophi_p=value;
  90.                 printf("Enter binary row offset (hex): --> ");
  91.                 scanf("%x", &value);
  92.                 emu.binrowoff=value;
  93.                 printf("Enter binary column offset (hex): --> ");
  94.                 scanf("%x", &value);
  95.                 emu.bincoloff=value;
  96.                 printf("Enter default_wrap_p (0 or 1): --> ");
  97.                 scanf("%d", &value);
  98.                 emu.default_wrap_p=value;
  99.                 }
  100.             else
  101.                 printf("n\n");
  102.             printf("\nBinary attribute zero bitmap offset char = %02x\n", emu.attroffset);
  103.             printf("Bold attribute bitmask = %02x\n", emu.boldmask);
  104.             printf("Faint attribute bitmask = %02x\n", emu.faintmask);
  105.             printf("Blink attribute bitmask = %02x\n", emu.blinkmask);
  106.             printf("Inverse attribute bitmask = %02x\n", emu.inversemask);
  107.             printf("Modify? --> ");
  108.             if(getch()=='y')
  109.                 {
  110.                 printf("y\nEnter binary attribute zero bitmap offest char (hex): --> ");
  111.                 scanf("%x", &value);
  112.                 emu.attroffset=value;
  113.                 printf("Enter bold attribute bitmask (hex): -- > ");
  114.                 scanf("%x", &value);
  115.                 emu.boldmask=value;
  116.                 printf("Enter faint attribute bitmask (hex): --> ");
  117.                 scanf("%x", &value);
  118.                 emu.faintmask=value;
  119.                 printf("Enter blink attribute bitmask (hex): --> ");
  120.                 scanf("%x", &value);
  121.                 emu.blinkmask=value;
  122.                 printf("Enter inverse attribute bitmask (hex): --> ");
  123.                 scanf("%x", &value);
  124.                 emu.inversemask=value;
  125.                 }
  126.             else
  127.                 printf("n\n");
  128.             }
  129.         if(c=='k')
  130.             {
  131.             printf("Operate the key (0 = code 0x00 (response)) --> ");
  132.             while(!_bios_keybrd(_KEYBRD_READY));
  133.             major=_bios_keybrd(_KEYBRD_READ);
  134.             if((major&0xff)&&((major&0xff)!='0'))
  135.                 printf("\n\007Not a programmable key!\n");
  136.             else
  137.                 {
  138.                 if((major&0xff)=='0')
  139.                     major=0;
  140.                 else
  141.                     major=(major>>8)&0xff;
  142.                 printf("\nScancode 0x%02x selected; ", major);
  143.                 if(emu.keys[major].nullpause_p)
  144.                     printf("00 => pause > 1 sec. and ff => break.\n");
  145.                 else
  146.                     printf("all codes literal.\n");
  147.                 printf("Present contents (blank line means empty):\n");
  148.                 for(minor=0;minor<emu.keys[major].len;++minor)
  149.                     printf(" %02x", emu.keys[major].chars[minor]);
  150.                 printf("\nModify? (y or n): --> ");
  151.                 if(getch()=='y')
  152.                     {
  153.                     printf("y\nZero means 1.1 sec pause and ff means break? (y or n): --> ");
  154.                     if(getch()=='y')
  155.                         {
  156.                         printf("y\n");
  157.                         emu.keys[major].nullpause_p=1;
  158.                         }
  159.                     else
  160.                         {
  161.                         printf("n\n");
  162.                         emu.keys[major].nullpause_p=0;
  163.                         }
  164.                     printf("Enter chars (up to %d). INSERT to enter in hex. END to end:\n-->\n\n", KEYLEN);
  165.                     _settextposition(23,4);
  166.                     minor=0;
  167.                     while(1)
  168.                         {
  169.                         value=_bios_keybrd(_KEYBRD_READ);
  170.                         if(value==0x5200)
  171.                             {
  172.                             printf("\nEnter hex code: --> ");
  173.                             scanf("%x", &value);
  174.                             _settextposition(24,1);
  175.                             printf("\t\t\t\t\t\t\t\t\t\r");
  176.                             }
  177.                         else
  178.                             if(value==0x4f00)
  179.                                 value=END;
  180.                             else
  181.                                 value&=0xff;
  182.                         if(value==END)
  183.                             {
  184.                             printf("\n");
  185.                             emu.keys[major].len=minor;
  186.                             break;
  187.                             }
  188.                         else
  189.                             if(minor<KEYLEN)
  190.                                 {
  191.                                 emu.keys[major].chars[minor++]=value;
  192.                                 _settextposition(23,1);
  193.                                 for(scan=0;scan<minor;scan++)
  194.                                     printf(" %02x", emu.keys[major].chars[scan]);
  195.                                 printf(" -->");
  196.                                 }
  197.                             else
  198.                                 {
  199.                                 printf("\nExcess char ignored.\n");
  200.                                 emu.keys[major].len=KEYLEN;
  201.                                 break;
  202.                                 }
  203.                             }
  204.                     }
  205.                 else
  206.                     printf("n\n");
  207.                 }
  208.             }
  209.         if(c=='f')
  210.             {
  211.             printf("Sequence number (decimal): --> ");
  212.             scanf("%d", &major);
  213.             if((major<0)||(major>=NFUNCS))
  214.                 printf("Bad sequence number.\n");
  215.             else
  216.                 {
  217.                 printf("Function is presently #%d decimal.\n", emu.funcs[major].func);
  218.                 for(minor=0;emu.funcs[major].codes[minor]!=END;++minor)
  219.                     printf(" %03x", emu.funcs[major].codes[minor]);
  220.                 printf("\nModify? (y or n): --> ");
  221.                 if(getch()=='y')
  222.                     {
  223.                     printf("y\nEnter function number in decimal. --> ");
  224.                     scanf("%d", &value);
  225.                     if((value<0)||(value>LASTFUN))
  226.                         printf("Bad function number.\n");
  227.                     else
  228.                         {
  229.                         emu.funcs[major].func=value;
  230.                         printf("Enter chars (up to %d). INSERT to enter in hex. END at end:\n-->\n\n", FUNLEN-1);
  231.                         _settextposition(23,4);
  232.                         minor=0;
  233.                         while(1)
  234.                             {
  235.                             value=_bios_keybrd(_KEYBRD_READ);
  236.                             if(value==0x5200)
  237.                                 {
  238.                                 printf("\nEnter hex code: --> ");
  239.                                 scanf("%x", &value);
  240.                                 _settextposition(24,1);
  241.                                 printf("\t\t\t\t\t\t\t\r");
  242.                                 }
  243.                             else
  244.                                 if(value==0x4f00)
  245.                                     value=END;
  246.                                 else
  247.                                     value&=0xff;
  248.                             emu.funcs[major].codes[minor++]=value;
  249.                             if(value==END)
  250.                                 {
  251.                                 printf("\n");
  252.                                 break;
  253.                                 }
  254.                             else
  255.                                 if(minor<FUNLEN)
  256.                                     {
  257.  
  258.                                     _settextposition(23,1);
  259.                                     for(scan=0;scan<minor;scan++)
  260.                                         printf(" %03x", emu.funcs[major].codes[scan]);
  261.                                     printf(" -->");
  262.                                     }
  263.                                 else
  264.                                     {
  265.                                     minor--;
  266.                                     printf("\nExcess code ignored.\n");
  267.                                     emu.funcs[major].codes[FUNLEN-1]=END;
  268.                                     break;
  269.                                     }
  270.                             }
  271.                         }
  272.                     }
  273.                 else
  274.                     printf("n\n");
  275.                 }
  276.             }
  277.         if(c=='g')
  278.             {
  279.             printf("Enter char or INSERT to enter in hex: --> ");
  280.             value=_bios_keybrd(_KEYBRD_READ);
  281.             if(value==0x5200)
  282.                 {
  283.                 printf("Enter hex: --> ");
  284.                 scanf("%x", &value);
  285.                 }
  286.             else
  287.                 {
  288.                 value&=0xff;
  289.                 printf("%c\n", value);
  290.                 }
  291.             if(emu.gchars[value])
  292.                 printf("Hex code %02x  Current char: -->%c<--  Modify? (y or n) --> ", value, emu.gchars[value]);
  293.             else
  294.                 printf("Hex code %02x  Current char is zero (unspecified).  Modify? (y or n) --> ", value);
  295.             if(getch()=='y')
  296.                 {
  297.                 printf("y\nEnter hex code of new graphics character: --> ");
  298.                 scanf("%x", &emu.gchars[value]);
  299.                 if(emu.gchars[value])
  300.                     printf("gchar %02x hex is now: -->%c<--\n", value, emu.gchars[value]);
  301.                 else
  302.                     printf("gchar %02x hex is now zero (unspecified).\n", value);
  303.                 }
  304.             else
  305.                 printf("n\n");
  306.             }
  307.         if(c=='w')
  308.             {
  309.             if((emufd=open(fpname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IWRITE))==-1)
  310.                 {
  311.                 printf("Error opening emu file for write.\n");
  312.                 }
  313.             else
  314.                 {
  315.                 if(write(emufd, &emu, sizeof(emu))!=sizeof(emu))
  316.                     printf("Write error!\n");
  317.                 else
  318.                     printf("Emulation structure written successfully.\n");
  319.                 close(emufd);
  320.                 }
  321.             }
  322.         if(c=='q')
  323.             break;
  324.         }
  325.     exit(0);
  326.     }
  327.