home *** CD-ROM | disk | FTP | other *** search
/ Kyūkyoku!! X68000 Emulator / X68000Book.dat / mac / OLS / X68000 / Ko-Window / kow142s.lzh / wsrv / vram.c < prev    next >
C/C++ Source or Header  |  1995-11-22  |  10KB  |  438 lines

  1. #define    WINDOW    WinDow
  2. #include "iocslib.h"
  3. #undef    WINDOW
  4.  
  5. #define    VRAM
  6. #define    DRAW
  7.  
  8. #define    AUTOGPOS    1
  9. #define    FILLIOCS    1
  10. #define    WIDE256        0
  11.  
  12. #include "clip.h"
  13. #include "window.h"
  14. #include "vram.h"
  15. #include "sheet.h"
  16.  
  17. #include "screen.h"
  18.  
  19. #include    "super.h"
  20.  
  21. ClipClass    *VramClipPtr;
  22.  
  23. static Sheet        Vram= { 1024, 1024, 64,
  24.                                 (unsigned short*)0xe00000,
  25.                                 (unsigned short*)0xe20000 };
  26. static ClipClass    VramClip= { 0, 0, 1023, 1023 };
  27. static ClipClass    GraphicClip= { 0, 0, 511, 1023 };
  28.  
  29. /*
  30.     proto -s vram.c > temp
  31. */
  32. static    void    GramFill( int, int, int, int, int );
  33. static    void    GramBox( int, int, int, int, int );
  34. static    void    GramLine( int, int, int, int, int );
  35. static    void    GramDot( int, int, int );
  36. static    void    GramCircle( int, int, int, int, int, int );
  37.  
  38. extern    void    GramPut( ClipClass*, int, int, int, int, short* );
  39.  
  40. void
  41. VramRegion( x1, y1, x2, y2 )
  42. int        x1, y1, x2, y2;
  43. {
  44.     VramClip.clip.x1= x1;
  45.     VramClip.clip.y1= y1;
  46.     VramClip.clip.x2= x2;
  47.     VramClip.clip.y2= y2;
  48. }
  49.  
  50. #if AUTOGPOS
  51. void
  52. GVramRegion( x1, y1, x2, y2 )
  53. int        x1, y1, x2, y2;
  54. {
  55. # if WIDE256
  56.     GraphicClip.clip.x1= x1;
  57.     GraphicClip.clip.x2= x2;
  58. # else
  59.     GraphicClip.clip.x1= x1;
  60.     GraphicClip.clip.y1= y1;
  61.     GraphicClip.clip.x2= x2;
  62.     GraphicClip.clip.y2= y2;
  63. # endif
  64. }
  65. #endif
  66.  
  67. #if 0
  68. /****************************************** from clip.c ***************/
  69. #define min( a, b ) (a) < (b) ? (a) : (b)
  70. #define max( a, b ) (a) > (b) ? (a) : (b)
  71.  
  72. static inline int
  73. XClipOverlap( ret, v1, v2 )
  74. ClipClass    *ret, *v1, *v2;
  75. {
  76.     ret->clip.x1= max( v1->clip.x1, v2->clip.x1 );
  77.     ret->clip.y1= max( v1->clip.y1, v2->clip.y1 );
  78.     ret->clip.x2= min( v1->clip.x2, v2->clip.x2 );
  79.     ret->clip.y2= min( v1->clip.y2, v2->clip.y2 );
  80.  
  81.     if( ret->clip.x1 > ret->clip.x2 || ret->clip.y1 > ret->clip.y2 )
  82.         return    FALSE;
  83.  
  84.     return    TRUE;
  85. }
  86. /**********************************************************************/
  87. #endif
  88.  
  89. void
  90. VramDraw( bufp, n, clipptr, ox, oy )
  91. DrawBuf        *bufp;
  92. int            n;
  93. ClipClass    *clipptr;
  94. int            ox, oy;
  95. {
  96.     ClipClass    clip, gclip;
  97.     int    Gclip= FALSE, Gbreak;
  98.  
  99.     if( ClipOverlap( &clip, VramClipPtr, clipptr ) == FALSE )
  100.         return;
  101.  
  102.     if( ClipOverlap( &clip, &clip, &VramClip ) == FALSE )
  103.         return;
  104.  
  105.     X_InSuper();    /* +14 COR. */
  106.     for(; n-- ; bufp++ ){
  107.         switch( bufp->type ){
  108.             case DrawClear:
  109.                 SheetLine( &Vram, &clip,
  110.                             clip.clip.x1, clip.clip.y1,
  111.                             clip.clip.x2, clip.clip.y2,
  112.                             bufp->option.clear.code, OptionFill );
  113.                 break;
  114.             case DrawLine:
  115.                 SheetLine( &Vram, &clip,
  116.                                     bufp->option.line.x1 + ox,
  117.                                     bufp->option.line.y1 + oy,
  118.                                     bufp->option.line.x2 + ox,
  119.                                     bufp->option.line.y2 + oy,
  120.                                     bufp->option.line.code,
  121.                                         bufp->option.line.option );
  122.                 break;
  123.             case DrawPut:
  124.                 SheetCopy( &Vram, &clip,
  125.                                     bufp->option.put.x + ox,
  126.                                     bufp->option.put.y + oy,
  127.                                         bufp->option.put.sp );
  128.                 break;
  129.             case DrawSymbol:
  130.                 SheetSymbol( &Vram, &clip,
  131.                             bufp->option.symbol.x + ox,
  132.                             bufp->option.symbol.y + oy,
  133.                             bufp->option.symbol.str,
  134.                             bufp->option.symbol.attr,
  135.                             bufp->option.symbol.font );
  136.                 break;
  137.             case DrawPattern:
  138.                 SheetPutPattern( &Vram, &clip, bufp->option.pattern.sp );
  139.                 break;
  140.  
  141.             case DrawGraphicClear:
  142.                 if( GraphicMode != WindowAttrGraphic16 ){
  143.                     if( !Gclip ){
  144.                         Gclip= TRUE;
  145.                         if( Gbreak= !ClipOverlap( &gclip, &clip, &GraphicClip ) )
  146.                             break;
  147.                     }else if( Gbreak )
  148.                         break;
  149. #if AUTOGPOS
  150.                     WINDOW( gclip.clip.x1-GraphicClip.clip.x1,
  151.                             gclip.clip.y1-GraphicClip.clip.y1,
  152.                             gclip.clip.x2-GraphicClip.clip.x1,
  153.                             gclip.clip.y2-GraphicClip.clip.y1 );
  154.                     GramFill( gclip.clip.x1, gclip.clip.y1,
  155.                                     gclip.clip.x2, gclip.clip.y2,
  156.                                             bufp->option.clear.code );
  157. #endif
  158.                 }else{
  159.                     WINDOW( clip );
  160.                     GramFill( clip.clip.x1, clip.clip.y1,
  161.                                             clip.clip.x2, clip.clip.y2,
  162.                                             bufp->option.clear.code );
  163.                 }
  164.                 break;
  165.  
  166.             case DrawGraphicLine:
  167.                 if( GraphicMode != WindowAttrGraphic16 ){
  168.                     if( !Gclip ){
  169.                         Gclip= TRUE;
  170.                         if( Gbreak= !ClipOverlap( &gclip, &clip, &GraphicClip ) )
  171.                             break;
  172.                     }else if( Gbreak )
  173.                         break;
  174. #if AUTOGPOS
  175.                     WINDOW( gclip.clip.x1-GraphicClip.clip.x1,
  176.                             gclip.clip.y1-GraphicClip.clip.y1,
  177.                             gclip.clip.x2-GraphicClip.clip.x1,
  178.                             gclip.clip.y2-GraphicClip.clip.y1 );
  179. #endif
  180.                 }else
  181.                     WINDOW( clip );
  182.  
  183.                 {
  184.                     int        x, y, x2, y2;
  185.                     x = bufp->option.line.x1 + ox;
  186.                     y = bufp->option.line.y1 + oy;
  187.                     x2= bufp->option.line.x2 + ox;
  188.                     y2= bufp->option.line.y2 + oy;
  189.                     switch( bufp->option.line.option ){
  190.                         case OptionLine:
  191.                             GramLine( x, y, x2, y2, bufp->option.line.code );
  192.                             break;
  193.                         case OptionFill:
  194.                             GramFill( x, y, x2, y2, bufp->option.line.code );
  195.                             break;
  196.                         case OptionBox:
  197.                             GramBox( x, y, x2, y2, bufp->option.line.code );
  198.                             break;
  199.                     }
  200.                 }
  201.                 break;
  202.  
  203.             case DrawGraphicPut:
  204.                 if( GraphicMode != WindowAttrGraphic16 ){
  205.                     if( !Gclip ){
  206.                         Gclip= TRUE;
  207.                         if( Gbreak= !ClipOverlap(&gclip,&clip,&GraphicClip) )
  208.                             break;
  209.                     }else if( Gbreak )
  210.                         break;
  211.                     GramPut( &gclip, bufp->option.gput.x1 + ox,
  212.                                             bufp->option.gput.y1 + oy,
  213.                                             bufp->option.gput.x2 + ox,
  214.                                             bufp->option.gput.y2 + oy,
  215.                                             bufp->option.gput.gbuf );
  216.                 }else{
  217.                     GramPut( &clip, bufp->option.gput.x1 + ox,
  218.                                             bufp->option.gput.y1 + oy,
  219.                                             bufp->option.gput.x2 + ox,
  220.                                             bufp->option.gput.y2 + oy,
  221.                                             bufp->option.gput.gbuf );
  222.                 }
  223.                 break;
  224.  
  225.             case DrawDot :    /* ZARU2 */
  226.                 SheetDot( &Vram, &clip,
  227.                                 bufp->option.dot.x + ox,
  228.                                 bufp->option.dot.y + oy,
  229.                                     bufp->option.dot.code );
  230.                 break;
  231.             case DrawGraphicDot :    /* COR.*/
  232.                 if( GraphicMode != WindowAttrGraphic16 ){
  233.                     if( !Gclip ){
  234.                         Gclip= TRUE;
  235.                         if( Gbreak= !ClipOverlap(&gclip,&clip,&GraphicClip) )
  236.                             break;
  237.                     }else if( Gbreak )
  238.                         break;
  239. #if AUTOGPOS
  240.                     WINDOW( gclip.clip.x1-GraphicClip.clip.x1,
  241.                             gclip.clip.y1-GraphicClip.clip.y1,
  242.                             gclip.clip.x2-GraphicClip.clip.x1,
  243.                             gclip.clip.y2-GraphicClip.clip.y1 );
  244. #endif
  245.                 }else
  246.                     WINDOW( clip );
  247.                 GramDot( bufp->option.dot.x+ox, bufp->option.dot.y+oy,
  248.                                                 bufp->option.dot.code );
  249.                 break;
  250.             case DrawCircle :    /* ZARU2 */
  251.                 SheetCircle( &Vram, &clip,
  252.                         bufp->option.circle.x + ox,
  253.                         bufp->option.circle.y + oy,
  254.                         bufp->option.circle.rx,
  255.                         bufp->option.circle.ry, bufp->option.circle.code,
  256.                         bufp->option.circle.option );
  257.                 break;
  258.             case DrawGraphicCircle :    /* COR.*/
  259.                 if( GraphicMode != WindowAttrGraphic16 ){
  260.                     if( !Gclip ){
  261.                         Gclip= TRUE;
  262.                         if( Gbreak= !ClipOverlap( &gclip,&clip,&GraphicClip) )
  263.                             break;
  264.                     }else if( Gbreak )
  265.                         break;
  266. #if AUTOGPOS
  267.                     WINDOW( gclip.clip.x1-GraphicClip.clip.x1,
  268.                             gclip.clip.y1-GraphicClip.clip.y1,
  269.                             gclip.clip.x2-GraphicClip.clip.x1,
  270.                             gclip.clip.y2-GraphicClip.clip.y1 );
  271. #endif
  272.                 }else
  273.                     WINDOW( clip );
  274.                 GramCircle(
  275.                         bufp->option.circle.x + ox,
  276.                         bufp->option.circle.y + oy,
  277.                         bufp->option.circle.rx,
  278.                         bufp->option.circle.ry, bufp->option.circle.code,
  279.                         bufp->option.circle.option );
  280.                 break;
  281.             default:{
  282.                 X_OutSuper();
  283.                 ErrorCheck( FALSE, "VramDraw" );
  284.                 return;
  285.             }
  286.         }
  287.     }
  288.     X_OutSuper();    /* +14 COR. */
  289. }
  290.  
  291. /*  ê┌ô«  */
  292. void
  293. VramMove( x, y, clipptr )
  294. int        x, y;
  295. ClipClass    *clipptr ;
  296. {
  297.     X_InSuper();    /* +14 */
  298.     SheetMove( &Vram, &VramClip, x, y, clipptr );
  299.     X_OutSuper();    /* +14 */
  300. }
  301.  
  302. /*  âXâNâìü[âï  */
  303. void
  304. VramScroll( clipptr, dx, dy )
  305. ClipClass    *clipptr;
  306. int        dx, dy ;
  307. {
  308.     ClipClass    clip;
  309.  
  310.     if( ClipOverlap( &clip, VramClipPtr, clipptr ) == FALSE )
  311.         return;
  312.     if( ClipOverlap( &clip, &clip, &VramClip ) == FALSE )
  313.         return;
  314.  
  315.     X_InSuper();    /* +14 */
  316.     dx&= -16;
  317.     SheetScroll( &Vram, &clip, dx, dy );
  318.     X_OutSuper();    /* +14 */
  319. }
  320.  
  321.  
  322.  
  323. /*  âOâëâtâBâbâNé╠âtâBâï  */
  324. static void
  325. GramFill( x1, y1, x2, y2, code )
  326. int        x1, y1, x2, y2, code;
  327. {
  328. #if FILLIOCS
  329.     struct FILLPTR    fill;
  330. # if AUTOGPOS
  331.     x1-= GraphicClip.clip.x1;
  332.     x2-= GraphicClip.clip.x1;
  333.     y1-= GraphicClip.clip.y1;
  334.     y2-= GraphicClip.clip.y1;
  335. # endif
  336.     fill.x1= x1;
  337.     fill.y1= y1;
  338.     fill.x2= x2;
  339.     fill.y2= y2;
  340.     fill.color= code;
  341.     FILL( &fill );
  342. #else /* FILLIOCS */
  343.     int    Xlen= x2-x1+1,
  344.         Ylen= y2-y1+1,
  345.         adrH, adr;
  346.     if( GraphicMode == 4 /* WindowAttrGraphic16 */ ){
  347.         adrH= 1024*2;
  348.     }else{
  349.         adrH= 512*2;
  350.     }
  351.     adr= 0xc00000+ x1*2 + adrH * y1;
  352.     InSuper();
  353.     GramFill1( Xlen, Ylen, code, adrH, adr );
  354.     OutSuper();
  355. #endif /* FILLIOCS */
  356. }
  357.  
  358. /*  âOâëâtâBâbâNé╠â{âbâNâX  */
  359. static void
  360. GramBox( x1, y1, x2, y2, code )
  361. int        x1, y1, x2, y2, code ;
  362. {
  363.     struct    BOXPTR    box ;
  364. #if AUTOGPOS
  365.     x1-= GraphicClip.clip.x1;
  366.     x2-= GraphicClip.clip.x1;
  367.     y1-= GraphicClip.clip.y1;
  368.     y2-= GraphicClip.clip.y1;
  369. #endif
  370.     box.x1 = x1 ;
  371.     box.y1 = y1 ;
  372.     box.x2 = x2 ;
  373.     box.y2 = y2 ;
  374.     box.color = code ;
  375.     box.linestyle = 0xFFFF ;    /* 1992 COR.*/
  376.     BOX( &box );
  377. }
  378.  
  379. /*  âOâëâtâBâbâNé╠âëâCâô  */
  380. static    void
  381. GramLine( x1, y1, x2, y2, code )
  382. int        x1, y1, x2, y2, code ;
  383. {
  384.     struct    LINEPTR    line ;
  385. #if AUTOGPOS
  386.     x1-= GraphicClip.clip.x1;
  387.     x2-= GraphicClip.clip.x1;
  388.     y1-= GraphicClip.clip.y1;
  389.     y2-= GraphicClip.clip.y1;
  390. #endif
  391.     line.x1 = x1 ;
  392.     line.y1 = y1 ;
  393.     line.x2 = x2 ;
  394.     line.y2 = y2 ;
  395.     line.color = code ;
  396.     line.linestyle = 0xFFFF ;
  397.  
  398.     LINE( &line );
  399. }
  400.  
  401. /*  âOâëâtâBâbâNé╠âhâbâg 1992 12/9 COR. */
  402. static void
  403. GramDot( x1, y1, code )
  404. int        x1, y1, code ;
  405. {
  406.     struct    PSETPTR    pset ;
  407. #if AUTOGPOS
  408.     x1-= GraphicClip.clip.x1;
  409.     y1-= GraphicClip.clip.y1;
  410. #endif
  411.     pset.x = x1 ;
  412.     pset.y = y1 ;
  413.     pset.color = code ;
  414.  
  415.     PSET( &pset );
  416. }
  417.  
  418. /*  âOâëâtâBâbâNé╠âTü[âNâï 1992 12/9 COR. */
  419. static void
  420. GramCircle( x1, y1, rx, ry, code, option )
  421. int        x1, y1, rx, ry, code, option ;
  422. {
  423.     struct    CIRCLEPTR    circle ;
  424. #if AUTOGPOS
  425.     x1-= GraphicClip.clip.x1;
  426.     y1-= GraphicClip.clip.y1;
  427. #endif
  428.     circle.x = x1 ;
  429.     circle.y = y1 ;
  430.     circle.color = code ;
  431.     circle.start= 0;
  432.     circle.end= 360;
  433.     circle.radius = rx > ry ? rx : ry;
  434.     circle.ratio= (ry<<8)/rx;
  435.  
  436.     CIRCLE( &circle );
  437. }
  438.