home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 111_01 / mcroang.c < prev    next >
Text File  |  1985-08-21  |  11KB  |  593 lines

  1. /*
  2. HEADER:        ;
  3. TITLE:        MicroAngelo;
  4. VERSION:    1.0;
  5. DATE:        02/28/1982;
  6.  
  7. DESCRIPTION:    "Creates new character sets for the MicroAngelo graphics
  8.         board.  Compilation requires MCROANG.H.";
  9.  
  10. KEYWORDS:    MicroAngelo, graphics;
  11. SYSTEM:        CP/M-80;
  12. FILENAME:    MCROANG.C;
  13. SEE-ALSO:    MCROANG.H;
  14. AUTHORS:    Joe Shannon;
  15. COMPILERS:    BDS C;
  16. */
  17. /***********************************************************************
  18.  
  19. Version 1.0, 2/28/1982:
  20.     This program is released to public domain with the
  21.     request that author credit be retained in the source.
  22.     Joe Shannon, 566 Rock Road, State College, PA 16801
  23.     (814) 238-0029
  24.  
  25. ***********************************************************************/
  26.  
  27. #include <BDSCIO.H>
  28. #include "MCROANG.H"
  29. #define    MBASX    290
  30. #define MBASY    60
  31. #define    ABASEC    17
  32. #define    ABASER    8
  33. #define FNC    38
  34. #define    FNR    50
  35. #define PROMPTC    38
  36. #define    PROMPTR    0
  37. #define ON    0
  38. #define    OFF    1
  39. #define    COMP    2
  40. #define MWIDTH    120
  41. #define MHIGTH    240
  42. #define    ALPHABAS    0xF940
  43. #define NOBYTS    1536
  44.  
  45. main()
  46. {
  47.     chrset();
  48. }
  49.  
  50. chrset()
  51. {
  52.     clear();
  53.     setac(0,0);
  54.     printf("\t\t\t");
  55.     alphmode(AMOD_UL);
  56.     printf("Modify Alternate Character Set\n");
  57.     alphmode(0);
  58.     printf("\n\n\tCommand Set\t\t\t\t    Motion Commands\n\n");
  59.     printf("F- Set File Name for I/O\t\t\t\t7  8  9\n");
  60.     printf("L- Load File to MicroAngelo\t\t\t\t  \\|/\n");
  61.     printf("S- Save File from MicroAngelo\t\t\t\t4 - - 6\n");
  62.     printf("A- ASCII Character to work on\t\t\t\t  /|\\\n");
  63.     printf("E- Exit function\t\t\t\t\t1  2  3\n");
  64.     printf("C- Clear the Character\t\t\t\t  5 = Compliment Point\n");
  65.     printf("D- Default Char Set (PAC II only)\n");
  66.  
  67.     setac(ABASEC-1,ABASER);
  68.     printf("      HIGH BYTE");
  69.     setac(ABASEC,ABASER);
  70.     alphmode(AMOD_UL);
  71.     printf("   0 1 2 3 4 5 6 7");
  72.     alphmode(AMOD_CU);
  73.     setac(ABASEC+1,ABASER);
  74.     printf("0|");
  75.     setac(ABASEC+2,ABASER);
  76.     printf("1|");
  77.     setac(ABASEC+3,ABASER);
  78.     printf("2|");
  79.     setac(ABASEC+4,ABASER);
  80.     printf("3|");
  81.     setac(ABASEC+5,ABASER);
  82.     printf("4|");
  83.     setac(ABASEC+6,ABASER);
  84.     printf("5|");
  85.     setac(ABASEC+7,ABASER);
  86.     printf("6|");
  87.     setac(ABASEC+8,ABASER);
  88.     printf("7|");
  89.     setac(ABASEC+9,ABASER);
  90.     printf("8|");
  91.     setac(ABASEC+10,ABASER);
  92.     printf("9|");
  93.     setac(ABASEC+11,ABASER);
  94.     printf("A|");
  95.     setac(ABASEC+12,ABASER);
  96.     printf("B|");
  97.     setac(ABASEC+13,ABASER);
  98.     printf("C|");
  99.     setac(ABASEC+14,ABASER);
  100.     printf("D|");
  101.     setac(ABASEC+15,ABASER);
  102.     printf("E|");
  103.     setac(ABASEC+16,ABASER);
  104.     printf("F|");
  105.  
  106.     drwadisp(); /* Display the alternate char set */
  107.  
  108.     setac(FNC,FNR);
  109.     printf("FILENAME :-");
  110.  
  111.     /* outline chart */
  112.     nvector(ON,MBASX-1,MBASY-1,MBASX+121,MBASY-1);
  113.     vector(ON,MBASX+121,MBASY+241);
  114.     vector(ON,MBASX-1,MBASY+241);
  115.     vector(ON,MBASX-1,MBASY-1);
  116.  
  117.      modify();
  118.     alphmode(0);
  119. }
  120.  
  121.  
  122. /* main program loop */
  123. modify()
  124. {
  125. char    filnam[13];
  126.     strcpy(filnam,"            ");
  127. char    c,chr;
  128. int    curx,cury;
  129.  
  130.     chr=curx=cury=0;
  131.     pltdbl(chr); /* display the char double size */
  132.     loadchr(chr); /* get the char from M/A and display it */
  133.     togcur(curx,cury); /* turn on cursor */
  134.  
  135. while((c=tolower(bios(3)))!='e')
  136.     switch(c) {
  137.         case 'f':
  138.             getnam(filnam);
  139.             break;
  140.         case 'l':
  141.             lodfil(filnam);
  142.             togcur(curx,cury); /* turn on cursor */
  143.             drwadisp(); /* Display the alternate char set */
  144.             pltdbl(chr); /* display the char double size */
  145.             loadchr(chr); /* get the char from M/A and display it */
  146.             togcur(curx,cury); /* turn on cursor */
  147.             break;
  148.         case 's':
  149.             savfil(filnam);
  150.             break;
  151.         case 'a':
  152.             togcur(curx,cury);
  153.             chr=asciichr();
  154.             togcur(curx,cury);
  155.             break;
  156.         case 'c':
  157.             togcur(curx,cury);
  158.             clrchr(chr);
  159.             togcur(curx,cury);
  160.             break;
  161.         case 'd':
  162.             togcur(curx,cury);
  163.             send8(0x9B);
  164.             drwadisp();
  165.             pltdbl(chr);
  166.             loadchr(chr);
  167.             togcur(curx,cury);
  168.             break;
  169.         case '1':
  170.             togcur(curx,cury);
  171.             if(cury>0) cury--;
  172.             if(curx>0) curx--;
  173.             togcur(curx,cury);
  174.             break;
  175.         case '2':
  176.             togcur(curx,cury);
  177.             if(cury>0) cury--;
  178.             togcur(curx,cury);
  179.             break;
  180.         case '3':
  181.             togcur(curx,cury);
  182.             if(curx<5) curx++;
  183.             if(cury>0) cury--;
  184.             togcur(curx,cury);
  185.             break;
  186.         case '4':
  187.             togcur(curx,cury);
  188.             if(curx>0) curx--;
  189.             togcur(curx,cury);
  190.             break;
  191.         case '5':
  192.             togcur(curx,cury);
  193.             compl(chr,curx,cury);
  194.             togcur(curx,cury);
  195.             break;
  196.         case '6':
  197.             togcur(curx,cury);
  198.             if(curx<5) curx++;
  199.             togcur(curx,cury);
  200.             break;
  201.         case '7':
  202.             togcur(curx,cury);
  203.             if(cury<11) cury++;
  204.             if(curx>0) curx--;
  205.             togcur(curx,cury);
  206.             break;
  207.         case '8':
  208.             togcur(curx,cury);
  209.             if(cury<11) cury++;
  210.             togcur(curx,cury);
  211.             break;
  212.         case '9':
  213.             togcur(curx,cury);
  214.             if(cury<11) cury++;
  215.             if(curx<5) curx++;
  216.             togcur(curx,cury);
  217.             break;
  218.         default:
  219.             break;
  220. }
  221. }
  222.  
  223.  
  224. /* draw the alternate alpha set */
  225. drwadisp()
  226. {
  227. int    c,r;
  228.     for(c=0;c<16;c++){
  229.         for(r=0;r<8;r++){
  230.             setac(ABASEC+c+1,ABASER+3+(2*r));
  231.             plotachr((r*16)+c);
  232.         }
  233.     }
  234. }
  235.  
  236. /* plot alternate char at the current alpha position */
  237. plotachr(c)
  238. char    c;
  239. {
  240.     send8(CHAR_MOD);
  241.     send8(0x80);
  242.     send8(GCUR_ALP);
  243.     send8(CHAR_PLT);
  244.     send8(c);
  245. }
  246.  
  247. /* plot the char at the double size position */
  248. pltdbl(c)
  249. char    c;
  250. {
  251.     setgc(MBASX+56,MBASY+250);
  252.     send8(CHAR_MOD);
  253.     send8(0x84);
  254.     send8(CHAR_PLT);
  255.     send8(c);
  256.     send8(CHAR_MOD);
  257.     send8(0);
  258.     setac(36,50);
  259.     printf("ASCII - %02x",c);
  260. }
  261.  
  262. getbyt(chr,yloc)
  263. int    yloc;
  264. char    chr;
  265. {
  266. int    add;
  267.     add=(ALPHABAS+(chr*12)+(11-yloc));
  268.     send8(MEMY_EXM);
  269.     send16(1);
  270.     send16(add);
  271.     return(get8());
  272. }
  273.  
  274. depbyt(b,chr,yloc)
  275. int    b,yloc;
  276. char    chr;
  277. {
  278. int    add;
  279.     add=(ALPHABAS+(chr*12)+(11-yloc));
  280.     send8(MEMY_DEP);
  281.     send16(1);
  282.     send16(add);
  283.     send8(b);
  284. }
  285.  
  286.  
  287. /* gets a charactor from MicroAngelo & draw matrix */
  288. loadchr(c)
  289. char    c;
  290. {
  291. int    add,i;
  292.     region(OFF,MBASX,MBASY,MBASX+MWIDTH,MBASY+MHIGTH);
  293.     for(i=0;i<12;i++) loadbyt(c,i);
  294. }
  295.  
  296. /* draws one byte of the matrix */
  297. loadbyt(chr,i)
  298. int    i;
  299. char    chr;
  300. {
  301. char    bit;
  302. int    j,k;
  303.  
  304.     k=getbyt(chr,i);
  305.     bit=32;
  306.     for(j=0;j<6;j++){
  307.         if( k & bit)    markcmp(j,i);
  308.         bit=bit>>1;
  309.     }
  310. }
  311.  
  312. /* compliments the mark defined by base coordinates  y=0-11 x=0-7 */
  313. markcmp(x,y)
  314. int    x,y;
  315. {
  316. int    baddx,baddy;
  317.     baddy=(y*20)+MBASY+2;
  318.     baddx=(x*20)+MBASX+2;
  319.     region(COMP,baddx,baddy,baddx+16,baddy+16);
  320. }
  321.  
  322.  
  323. /* clear a whole char for fresh start */
  324. clrchr(chr)
  325. char    chr;
  326. {
  327. int    i;
  328.     for(i=0;i<12;i++) depbyt(0,chr,i);
  329.     pltdbl(chr);
  330.     loadchr(chr);
  331.     setac(ABASEC+1+(chr%16),ABASER+3+(2*(chr/16)));
  332.     plotachr(chr);
  333. }
  334.  
  335. /* toggle the graphic cursor ON/OFF */
  336. togcur(curx,cury)
  337. int    curx,cury;
  338. {
  339. int    addrx,addry;
  340.     addrx=MBASX+(curx*20);
  341.     addry=MBASY+(cury*20);
  342.     nvector(COMP,addrx,addry+10,addrx+20,addry+10);
  343.     nvector(COMP,addrx+10,addry,addrx+10,addry+20);
  344. }
  345.  
  346. /* compliment the grafic loc and adjust the rest */
  347. compl(chr,curx,cury)
  348. int    curx,cury;
  349. char    chr;
  350. {
  351. char    byt,mask;
  352.     markcmp(curx,cury);
  353.     byt=getbyt(chr,cury);
  354.     byt^=(32>>curx);
  355.     depbyt(byt,chr,cury);
  356.     pltdbl(chr);
  357.     setac(ABASEC+1+(chr%16),ABASER+3+(2*(chr/16)));
  358.     plotachr(chr);
  359. }
  360.  
  361. prompt(frmt)
  362. {
  363.     clrprompt();
  364.     printf("\7\7\7");
  365.     setac(PROMPTC,PROMPTR);
  366.     printf(frmt);
  367. }
  368.  
  369. getnam(fnam)
  370. char    *fnam;
  371. {
  372. int    i;
  373. char    *ptr;
  374.     ptr=fnam;
  375.     prompt("Enter File Name - ********");
  376.     setac(PROMPTC,18);
  377.     for(i=0;i<8;i++) if((*ptr++=toupper(getchar()))== '\n') break;
  378.     *--ptr= 0;
  379.     strcat(fnam,".CHR");
  380.     clrprompt();
  381.     setac(FNC,FNR+13);
  382.     printf("               ");
  383.     setac(FNC,FNR+13);
  384.     printf("%8s",fnam);
  385.     printf("             ");
  386. }
  387.  
  388. asciichr()
  389. {
  390. char    chr,ch,cl;
  391. while(1){
  392.     prompt("Enter new character in HEX - **");
  393.     setac(PROMPTC,29);
  394.     if(ishexlo(tolower(ch=getchar())))
  395.         if(ishex(tolower(cl=getchar()))) break;
  396. }
  397.     ch=htodec(ch);
  398.     cl=htodec(cl);
  399.     chr=(ch*16)+cl;
  400.     pltdbl(chr);
  401.     loadchr(chr);
  402.     clrprompt();
  403.     return(chr);
  404. }
  405.  
  406. clrprompt()
  407. {
  408.     setac(PROMPTC,PROMPTR);
  409.     printf("                                               ");
  410. }
  411.  
  412. ishex(c)
  413. char    c;
  414. {    if(isdigit(c)) return(1);
  415.     if((c<'a')||(c>'f')) return(0);
  416.     return(1);
  417. }
  418.  
  419. ishexlo(c)
  420. char    c;
  421. {    if(isdigit(c)) if(c<'8') return(1);
  422.     return(0);
  423. }
  424.  
  425. htodec(c)
  426. char    c;
  427. {
  428.     if(isdigit(c)) return(c-'0');
  429.     if(isalpha(c)) return((c-'a')+10);
  430. }
  431.  
  432. savfil(fnam)
  433. char    *fnam;
  434. {
  435. char    c,e,buff[BUFSIZ];
  436. int    i,fd;
  437.     if(*fnam==' '){
  438.         prompt("No File Name Specified **");
  439.         return;
  440.     }
  441.     if(fd=fcreat(fnam,buff)==ERROR){
  442.         prompt("FILE ERROR ! ");
  443.         return;
  444.     }
  445.     prompt(" Writing file - ");
  446.     send8(MEMY_EXM);
  447.     send16(NOBYTS);
  448.     send16(ALPHABAS);
  449.     for(i=0;i<NOBYTS;i++){
  450.             c=get8();
  451.             if(e!=ERROR) e=(putc(c,buff));
  452.             }
  453.     if(e==ERROR) prompt(" Write ERROR- disk prob full ");
  454.     fflush(buff);
  455.     if(fclose(buff)==ERROR) prompt("ERROR Closing file ");
  456.     else(prompt(" File Written -- "));
  457. }
  458.  
  459. lodfil(fnam)
  460. char    *fnam;
  461. {
  462. char    buff[BUFSIZ];
  463. int    i,fd;
  464.     if(*fnam==' '){
  465.         prompt("No File Name Specified **");
  466.         return;
  467.     }
  468.     if(fd=fopen(fnam,buff)==ERROR){
  469.         prompt("FILE ERROR ! ");
  470.         return;
  471.     }
  472.     prompt(" Reading file - ");
  473.     send8(MEMY_DEP);
  474.     send16(NOBYTS);
  475.     send16(ALPHABAS);
  476.     for(i=0;i<NOBYTS;i++) send8(getc(buff));
  477.     if(fclose(buff)==ERROR) prompt("ERROR Closing file ");
  478.     else(prompt(" File Loaded -- "));
  479. }
  480. /*----------------SEND 8 BIT QUANTITY---------------*/
  481. send8(BYTE)
  482. char    BYTE;
  483. {    while (inp(STATPORT) & SENDBIT);
  484.     outp(DATAPORT,BYTE);
  485.     return;
  486. }
  487.  
  488. /*----------------SEND 16 BIT QUANTITY--------------*/
  489. send16(INTEGER)
  490. int   INTEGER;
  491. {    send8(INTEGER>>8);
  492.     send8(INTEGER);
  493.     return;
  494. }
  495.  
  496. /*---------------GET 8 BIT QUANTITY-----------------*/
  497. get8()
  498. {    while((inp(STATPORT) & RECVBIT)==0);
  499.     return(inp(DATAPORT));
  500. }
  501.  
  502. /*-------------CLEAR GRAFICS SCREEN-----------------*/
  503. clear()
  504. {    send8(SCRN_CLR);
  505.     return;
  506. }
  507.  
  508. /*---------------SET THE GRAFICS CURSOR-------------*/
  509. setgc(XLOC,YLOC)
  510. int  XLOC,YLOC;
  511. {    send8(GCUR_SET);
  512.     sendxy(XLOC,YLOC);
  513.     return;
  514. }
  515.  
  516. /*----------------SET THE ALPHA CURSOR--------------*/
  517. setac(XLOC,YLOC)
  518. int  XLOC,YLOC;
  519. {    send8(ACUR_SET);
  520.     send8(XLOC);
  521.     send8(YLOC);
  522.     return;
  523. }
  524.  
  525. /*-----------------VECTOR FUNCTIONS-----------------*/
  526. vector(MODE,XLOC,YLOC)
  527. int  MODE,XLOC,YLOC;
  528. {    switch(MODE){
  529.     case 1:send8(VECT_OFF);
  530.         break;
  531.     case 2:send8(VECT_CPL);
  532.         break;
  533.     case 3:send8(RVEC_ON);
  534.         break;
  535.     case 4:send8(RVEC_OFF);
  536.         break;
  537.     case 5:send8(RVEC_CPL);
  538.         break;
  539.     default:
  540.         send8(VECT_ON);
  541.         break;
  542.     }
  543.     sendxy(XLOC,YLOC);
  544.     return;
  545. }
  546.  
  547. /*-------NEW VECTOR FUNCTIONS-----------------------*/
  548. nvector(MODE,X1LOC,Y1LOC,X2LOC,Y2LOC)
  549. int    MODE,X1LOC,Y1LOC,X2LOC,Y2LOC;
  550. {    setgc(X1LOC,Y1LOC);
  551.     vector(MODE,X2LOC,Y2LOC);
  552.     return;
  553. }
  554.  
  555. /*--------------REGION FUNCTIONS--------------------*/
  556. region(MODE,X1LOC,Y1LOC,X2LOC,Y2LOC)
  557. int  MODE,X1LOC,Y1LOC,X2LOC,Y2LOC;
  558. {    switch(MODE){
  559.     case 1:send8(REG_OFF);
  560.         break;
  561.     case 2:send8(REG_CPL);
  562.         break;
  563.     case 3:send8(RREG_ON);
  564.         break;
  565.     case 4:send8(RREG_OFF);
  566.         break;
  567.     case 5:send8(RREG_CPL);
  568.         break;
  569.     default:
  570.         send8(REG_ON);
  571.         break;
  572.     }
  573.     sendxy(X1LOC,Y1LOC);
  574.     sendxy(X2LOC,Y2LOC);
  575.     return;
  576. }
  577.  
  578. /*--------------SET ALPHA MODE----------------------*/
  579. alphmode(MODE)
  580. char MODE;
  581. {    send8(AMOD_SET);
  582.     send8(MODE);
  583.     return;
  584. }
  585.  
  586. /*--------------SEND XY COORDINATE PAIR-------------*/
  587. sendxy(XLOC,YLOC)
  588. int    XLOC,YLOC;
  589. {    send16(XLOC);
  590.     send16(YLOC);
  591.     return;
  592. }
  593.