home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 3 / FreeSoftwareCollection3pd199x-jp.img / pao / ms_dos / color / src / getbc.c < prev   
Text File  |  1980-01-02  |  5KB  |  229 lines

  1. /** << MSC V5.1 >> ************************************************************
  2. **
  3. **    パレットの確認 ( FMTOWNS 16 色モード )
  4. **
  5. **    < Parameter >
  6. **    GETBC  <Palno.>
  7. **           Palno. : パレット番号 ( 0 ~ F (HEX) )
  8. **
  9. **    < HISTORY >
  10. **    1989.10.07 : CREATE
  11. **    1990.04.16 : FMRに対応
  12. **    1990.11.30 : 新型FMTOWNSに対応
  13. **
  14. **    All Rights Reserved, Copyright (C) Y.Hirata 1990.
  15. **
  16. **    Programed by Y.Hirata ( Nifty ID : NAB03321 )
  17. **
  18. ******************************************************************************/
  19. #include    <stdio.h>
  20. #include    <string.h>
  21. #include    <conio.h>
  22. #include    <dos.h>
  23. #include    <stdlib.h>
  24.  
  25. #define        VER_LEV        (1.20)
  26.  
  27. /*        FMTOWNS                */
  28. #define        PALETTE        0xfd90
  29. #define        BLUE        0xfd92
  30. #define        RED            0xfd94
  31. #define        GREEN        0xfd96
  32. /*        FMR                    */
  33. #define        CONTROL        0x0400
  34. #define        R_PALETTE    0x0408
  35. #define        R_BLUE        0x040a
  36. #define        R_RED        0x040c
  37. #define        R_GREEN        0x040e
  38.  
  39. unsigned int    Palette ;
  40. unsigned int    Blue ;
  41. unsigned int    Red ;
  42. unsigned int    Green ;
  43.  
  44. char    *Msg[6] = {    "(C)パオパオ  パレット色確認プログラム  Version ",
  45.                     "Copyright (C) Y.Hirata 1989-1990. All rights reserved.",
  46.                     "GETBC  <Palno.>  [Palno.  ....]  [Palno.-Palno.]",
  47.                     "       Palno. : パレット番号 ( 0 ~ F (HEX) )",
  48.                     "                (背景色のパレット番号は、0 です。)",
  49.                     "FMR-60では、最後に /r を指定して下さい。"
  50.                     } ;
  51.  
  52. #define        TRUE    1
  53. #define        FALSE    0
  54.  
  55. /*******************************  GET Machine ID  ****************************/
  56. /*
  57. **    < RETURN >
  58. **     機種識別 :
  59. **                Towns1,2      = 1
  60. **                Towns1,2(F,H) = 2 ('90秋型を含む)
  61. **                R70           = 3
  62. **                R60/50        = 4
  63. **                R50S          = 5
  64. **                R50LT         = 6
  65. **                ???           = 0
  66. */
  67. int mid()
  68. {
  69.     union    REGS    regs ;
  70.     struct    SREGS    sregs ;
  71.     unsigned char    mdata[16] ;
  72.     unsigned char    id, cpu ;
  73.     
  74.     regs.h.ah = 0x05 ;
  75.     regs.x.di = (unsigned int)mdata ;
  76.  
  77.     segread( &sregs ) ;
  78.     int86x( 0xaf,®s,®s,&sregs ) ;
  79.  
  80.     id = mdata[0] ;
  81.     if ( (id & 0x07) == 0x01 ) {                /*  R60/50 系列    */
  82.         if ( (id & 0xf0) == 0x50 ) {            /*  FMTowns        */
  83.             cpu = inp( 0x31 ) ;
  84.             switch ( cpu ) {
  85.                 case 1 :
  86.                         return ( 1 ) ;            /*  モデル 1,2    */
  87.                         break ;
  88.                 case 2 :
  89.                         return ( 2 ) ;            /*  モデル 1,2(F,H)    */
  90.                         break ;
  91.                 default :
  92.                         return ( 2 ) ;            /*  ?????        */
  93. /*
  94. **    新型FMTOWNSは、これでいいと思う。
  95. */
  96.                         break ;
  97.             }
  98.         } else if ( (id & 0xf0) == 0x20 ) {        /*  R-70        */
  99.             return ( 3 ) ;
  100.         } else if ( (id & 0xf0) == 0x00 ) {        /*  R-60/50        */
  101.             return ( 4 ) ;
  102.         } else if ( (id & 0xf0) == 0x30) {        /*  R-50S        */
  103.             return ( 5 ) ;
  104.         } else if ( (id & 0xf0) == 0x40) {        /*  R-50LT        */
  105.             return ( 6 ) ;
  106.         } else {                                /*  ?????        */
  107.             return ( 0 ) ;
  108.         }
  109.     } else {                                    /*  ?????        */
  110.         return ( 0 ) ;
  111.     }
  112. }
  113.  
  114. /************************  char 0-f(F) -> int 0-15  **************************/
  115. int ctoi( c )
  116. char    c ;
  117. {
  118.     int    i=0 ;
  119.  
  120.     if ( c >= '0' && c <= '9' ) {
  121.         i = c - '0' ;
  122.     } else {
  123.         if ( c >= 'A' && c <= 'F' )
  124.             i = 10 + c - 'A' ;
  125.         if ( c >= 'a' && c <= 'f' )
  126.             i = 10 + c - 'a' ;
  127.     }
  128.     return i ;
  129. }
  130.  
  131. /*****************************  ★ メイン ★  ********************************/
  132. main( int ac, char *av[] )
  133. {
  134.     char    pal, b, r, g ;
  135.     int        c, cc, st, end, arglen ;
  136.     int        id ;
  137.     int        r60 = FALSE ;
  138.  
  139.     if ( ac > 1 ) {
  140.         for ( c=1; c<ac; c++ ) {
  141.             if ( *av[c] == '-' || *av[c] == '/' ) {        /* オプションスイッチ    */
  142.                 arglen = strlen( av[c] ) ;
  143.                 for ( cc=1; cc<arglen; cc++ ) {
  144.                     switch ( *(av[c]+cc) ) {
  145.                         case 'r' :
  146.                         case 'R' :
  147.                             r60 = TRUE ;
  148.                             break ;
  149.                         default :
  150.                             printf("\x1b[1;33m") ;
  151.                             printf("Option switch error(%c)",*(av[c]+cc)) ;
  152.                             printf("\x1b[m\n") ;
  153.                             break ;
  154.                     }
  155.                 }
  156.             }
  157.         }
  158.     }
  159.     id = mid() ;
  160.     switch ( id ) {                            /*  機種判別    */
  161.         case 1 :                            /*  FMTOWNS        */
  162.         case 2 :                            /*  FMTOWNS        */
  163.         case 5 :                            /*  FMR-50S        */
  164.                 Palette = PALETTE ;
  165.                 Blue = BLUE ;
  166.                 Red = RED ;
  167.                 Green = GREEN ;
  168.                 break ;
  169.         case 4 :                            /*  FMR-60/50    */
  170.                 Palette = PALETTE ;
  171.                 Blue = BLUE ;
  172.                 Red = RED ;
  173.                 Green = GREEN ;
  174.                 if ( !r60 ) {
  175.                     break ;
  176.                 }
  177.         case 3 :                            /*  FMR-70        */
  178.                 outp( CONTROL ,0x05 ) ;
  179.                 Palette = R_PALETTE ;
  180.                 Blue = R_BLUE ;
  181.                 Red = R_RED ;
  182.                 Green = R_GREEN ;
  183.                 break ;
  184.         case 6 :                            /*  FMR-50LT    */
  185.         default :                            /*  ?????        */
  186.                 printf("\nこのマシンでは、使用できません!\n") ;
  187.                 exit ( 1 ) ;
  188.                 break ;
  189.     }
  190.  
  191.     if ( ac < 2 ) {                                /*  引数なし    */
  192.         printf("%s%04.2f\n",Msg[0],VER_LEV) ;
  193.         printf("%s\n",Msg[1]) ;
  194.         printf("\n") ;
  195.         for ( c=2; c<5; c++ ) {
  196.             printf("%s\n",Msg[c]) ;
  197.         }
  198.         if ( id == 4 ) {
  199.             printf("%s\n",Msg[5]) ;
  200.         }
  201.     } else {                                    /*  引数あり    */
  202.         for ( c=1; c<ac; c++ ) {
  203.             if ( *av[c] != '-' && *av[c] != '/' ) {        /* オプションスイッチ    */
  204.                 st  = ctoi( *av[c] ) ;
  205.                 end = st ;
  206.                 if ( strlen(av[c]) == 3 ) {
  207.                     end = ctoi( *(av[c]+2) ) ;
  208.                     if ( st > end )
  209.                         printf("\x1b[1;33mParameter error : %s\x1b[m\n",
  210.                                 av[c]) ;
  211.                 }
  212.                 for ( cc=st; cc<=end; cc++ ) {
  213.                     pal = cc ;
  214.                     printf("\x1b[m\x1b[37mPalno. %xH : ",pal) ;
  215.                     outp( Palette ,pal ) ;
  216.                     b = inp( Blue  ) >> 4 ;
  217.                     r = inp( Red   ) >> 4 ;
  218.                     g = inp( Green ) >> 4 ;
  219.                     printf("\x1b[7;34mBLUE\x1b[m\x1b[37m<%xH> ",b) ;
  220.                     printf("\x1b[7;31mRED\x1b[m\x1b[37m<%xH> ",r) ;
  221.                     printf("\x1b[7;32mGREEN\x1b[m\x1b[37m<%xH>\n",g) ;
  222.                 }
  223.             }
  224.         }
  225.     }
  226.     printf("\x1b[m") ;
  227. }
  228.  
  229.