home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / VGAGRAPH.ZIP / GRAPHX.C < prev    next >
C/C++ Source or Header  |  1993-03-25  |  21KB  |  1,226 lines

  1. #include <dos.h>
  2. #include <string.h>
  3. #include <mem.h>
  4. #include <stdio.h>
  5. #include <io.h>
  6. #include <fcntl.h>
  7. #include <dir.h>
  8. #include <stdlib.h>
  9. #include <alloc.h>
  10. #include "low.h"
  11.  
  12. extern char byte_tabXL[4];
  13. extern char byte_tabXR[4];
  14. extern char char_tab[16];
  15. extern char byte_tab[8];
  16. extern char pln_tab[4];
  17.  
  18. extern unsigned int BytesPerLine,FastPlace;
  19.  
  20. typedef
  21.      struct {
  22.        unsigned int dx,dy,type;
  23.        unsigned int p[4];
  24.        } Image;
  25.  
  26. void setscrlinex(unsigned int w)
  27. {
  28.     w=w*BytesPerLine;
  29.     outportb(0x3D4,0x0C);outportb(0x3D5,w>>8);
  30.     outportb(0x3D4,0x0D);outportb(0x3D5,w);
  31. }
  32. void putpixelx(int x,int y,char color)
  33. {
  34.     asm{
  35.     mov     cx,x
  36.     and     cl,3
  37.     mov     ah,1
  38.     shl     ah,cl
  39.     mov     dx,3C4h
  40.     mov     al,02h
  41.     out     dx,ax
  42.     mov     ax,0A000h
  43.     mov     es,ax
  44.     mov     ax,y
  45.     mul     BytesPerLine
  46.     mov     cx,x
  47.     shr     cx,2
  48.         add     ax,cx
  49.     mov     si,ax
  50.     mov     cl,color
  51.     mov     es:[si],cl
  52.     mov     dx,03C4h
  53.     mov     ax,0F02h
  54.     out     dx,ax
  55.     }
  56. }
  57. char getpixelx(int x,int y)
  58. {
  59. char b;
  60.  
  61.     asm{
  62.     mov    ah,byte ptr x
  63.     and     ah,011b
  64.     mov    al,04h
  65.     mov    dx,03CEh
  66.     out    dx,ax
  67.     mov     ax,0A000h
  68.         mov     es,ax
  69.     mov     ax,y
  70.         mul     BytesPerLine
  71.         mov     di,x
  72.         shr     di,2
  73.     add     di,ax
  74.     mov     al,es:[di]
  75.     mov     b,al
  76.     mov     ax,0004h
  77.     mov     dx,03CEh
  78.     out     dx,ax
  79.     }
  80.     return(b);
  81. }
  82. void clearscrx(char color)
  83. {
  84.     asm{
  85.       cld
  86.       mov   ax,0A000h
  87.       mov   es,ax
  88.       mov   di,0
  89.       mov   dx,03C4h
  90.       mov   ax,0F02h
  91.       out   dx,ax
  92.       mov   cx,0FFFFh
  93.       mov   al,color
  94.       rep   stosb
  95.     }
  96. }
  97. void linex(int x1,int y1,int x2,int y2,char color)
  98. {
  99. int delta_x,delta_y,distance,add1,add2;
  100.  
  101.       asm{
  102.      cld
  103.      mov   ax,0A000h
  104.      mov   es,ax
  105.      mov   cx,x2
  106.      cmp   cx,x1
  107.      jg    cont1
  108.      mov   cx,x2
  109.      xchg  cx,x1
  110.      mov   x2,cx
  111.      mov   cx,y2
  112.      xchg  cx,y1
  113.      mov   y2,cx
  114.      }
  115. cont1:
  116.      asm{
  117.      mov   cx,y2
  118.      sub   cx,y1
  119.      mov   ax,y1
  120.      mul   BytesPerLine
  121.      mov   si,x1
  122.      shr   si,2
  123.      add   si,ax
  124.      mov   cl,byte ptr x1
  125.      and   cl,011b
  126.      mov   ah,01h
  127.      shl   ah,cl
  128.      mov   al,02h
  129.      mov   dx,03C4h
  130.      out   dx,al
  131.      inc   dx
  132.      mov   cx,y2
  133.      sub   cx,y1
  134.      js   UPLine
  135.      mov   delta_y,cx
  136.      mov   bx,cx
  137.      mov   cx,x2
  138.      sub   cx,x1
  139.      mov   delta_x,cx
  140.      cmp   bx,cx
  141.      jg    dy_g
  142.      mov   distance,cx
  143.      jmp   cont2
  144.      }
  145. dy_g:
  146.      asm{
  147.      mov   distance,bx
  148.      }
  149. cont2:
  150.      asm{
  151.      mov   cx,0
  152.      mov   bx,0
  153.      mov   di,distance
  154.      mov   al,ah
  155.      mov   ah,color
  156.      }
  157. L1:
  158.      asm{
  159.      out   dx,al
  160.      mov   es:[si],ah
  161.      add   cx,delta_y
  162.      add   bx,delta_x
  163.  
  164.      cmp   bx,di
  165.      jl    cont4
  166.      sub   bx,di
  167.      rol   al,1
  168.      and   al,00001111b
  169.      jnz   cont4
  170.      inc   si
  171.      mov   al,01h
  172.      }
  173. cont4:
  174.      asm{
  175.      cmp   cx,di
  176.      jl    cont5
  177.      sub   cx,di
  178.      add   si,word ptr BytesPerLine
  179.      }
  180. cont5:
  181.      asm{
  182.      dec   distance
  183.      jns   L1
  184.      jmp   LineEnd
  185.      }
  186. UPLine:
  187.      asm{
  188.      neg   cx
  189.      mov   delta_y,cx
  190.      mov   bx,cx
  191.      mov   cx,x2
  192.      sub   cx,x1
  193.      mov   delta_x,cx
  194.      cmp   bx,cx
  195.      jg    dy_g_
  196.      mov   distance,cx
  197.      jmp   cont2_
  198.      }
  199. dy_g_:
  200.      asm{
  201.      mov   distance,bx
  202.      }
  203. cont2_:
  204.      asm{
  205.      mov   cx,0
  206.      mov   bx,0
  207.      mov   di,distance
  208.      mov   al,ah
  209.      mov   ah,color
  210.      }
  211. L1_:
  212.      asm{
  213.      out   dx,al
  214.      mov   es:[si],ah
  215.      add   cx,delta_y
  216.      add   bx,delta_x
  217.  
  218.      cmp   bx,di
  219.      jl    cont4_
  220.      sub   bx,di
  221.      rol   al,1
  222.      and   al,00001111b
  223.      jnz   cont4_
  224.      inc   si
  225.      mov   al,01h
  226.      }
  227. cont4_:
  228.      asm{
  229.      cmp   cx,di
  230.      jl    cont5_
  231.      sub   cx,di
  232.      sub   si,word ptr BytesPerLine
  233.      }
  234. cont5_:
  235.      asm{
  236.      dec   distance
  237.      jns   L1_
  238.      jmp   LineEnd
  239.      }
  240. cont5__:
  241.      asm{
  242.      neg   bx
  243.      inc   bx
  244.      mov   ax,y2
  245.      }
  246. cont6:
  247.      asm{
  248.      mul   BytesPerLine
  249.      mov   si,x1
  250.      shr   si,2
  251.      add   si,ax
  252.      mov   cl,byte ptr x1
  253.      and   cl,011b
  254.      mov   ah,01h
  255.      shl   ah,cl
  256.      mov   al,02h
  257.      mov   dx,03C4h
  258.      out   dx,ax
  259.      mov   al,color
  260.      }
  261. L2:
  262.      asm{
  263.      mov   es:[si],al
  264.      add   si,word ptr BytesPerLine
  265.      dec   bx
  266.      jnz   L2
  267.      jmp   LineEnd
  268.      }
  269. NotMixMask:
  270.      asm{
  271.      mov   ah,color
  272.      mov   al,02h
  273.      mov   dx,03C4h
  274.      out   dx,al
  275.      inc   dx
  276.      mov   al,bh
  277.      out   dx,al
  278.      mov   es:[di],ah
  279.      inc   di
  280.      dec   cx
  281.      js    LineEnd
  282.      jz    RightEdge
  283.      mov   al,0Fh
  284.      out   dx,al
  285.      mov   al,ah
  286.      rep   stosb
  287.      }
  288. RightEdge:
  289.      asm{
  290.      mov   al,bl
  291.      out   dx,al
  292.      mov   es:[di],ah
  293.      }
  294. LineEnd:;
  295.  
  296. }
  297.  
  298. void barx(int x,int y,int dx,int dy,int colorb)
  299. {
  300. char l=dx;
  301.  
  302.        asm{
  303.      cld
  304.      mov   ax,0A000h
  305.      mov   es,ax
  306.      mov   ax,y
  307.      mul   BytesPerLine
  308.      mov   di,x
  309.      shr   di,2
  310.      add   di,ax
  311.      mov   ax,0F02h
  312.      mov   dx,03C4h
  313.      out   dx,ax
  314.      mov   si,word ptr l
  315.      shr   si,2
  316.      mov   bx,dy
  317.      inc   bx
  318.      mov   al,byte ptr colorb
  319.      mov   dx,word ptr BytesPerLine
  320.      sub   dx,si
  321.      }
  322. L1:
  323.      asm{
  324.      mov   cx,si
  325.      rep   stosb
  326.      add   di,dx
  327.      dec   bx
  328.      jnz   L1
  329.      }
  330. }
  331. void barsx(int x,int y,int dx,int dy,char colorb)
  332. {
  333. int  x2,add1,add2;
  334. char Mask_bl;
  335.  
  336.        x2=x+dx;
  337.        asm{
  338.      cld
  339.      inc   dy
  340.      mov   ax,y
  341.      mul   BytesPerLine
  342.      mov   di,x
  343.      shr   di,2
  344.      add   di,ax
  345.      mov   add1,di
  346.      mov   di,x2
  347.      inc   di
  348.      shr   di,2
  349.      add   di,ax
  350.      mov   add2,di
  351.      mov   si,x
  352.      and   si,03h
  353.      mov   bh,byte ptr byte_tabXL[si]
  354.      mov   si,x2
  355.      inc   si
  356.      and   si,03h
  357.      }
  358.      Mask_bl=byte_tabXR[_SI];
  359.      asm{
  360.      mov   dx,03C4h
  361.      mov   al,02h
  362.      out   dx,ax
  363.      inc   dx
  364.      mov   ax,0A000h
  365.      mov   es,ax
  366.      sub   di,word ptr add1
  367.      jnz   Not_Set_Mask
  368.      jmp   Not_Set_Mask1
  369.      }
  370. Not_Set_Mask:
  371.      asm{
  372.      cmp   bh,0Fh
  373.      jne   Not_Set_Mask1
  374.      dec   add1
  375.      jmp   Middle_Part
  376.      }
  377. Not_Set_Mask1:
  378.      asm{
  379.      mov   cx,dy
  380.      mov   di,add1
  381.      mov   al,bh
  382.      out   dx,al
  383.      mov   al,colorb
  384.      }
  385. L1:
  386.      asm{
  387.      stosb
  388.      dec   di
  389.      add   di,word ptr BytesPerLine
  390.      dec   cx
  391.      jnz   L1
  392.      }
  393. Middle_Part:
  394.      asm{
  395.      mov   si,add2
  396.      dec   si
  397.      sub   si,word ptr add1
  398.      js    Fill_Done
  399.      jz    RightEdge
  400.      mov   al,0FFh
  401.      out   dx,al
  402.      mov   cx,si
  403.  
  404.      mov   bx,dy
  405.      mov   di,add1
  406.      inc   di
  407.      mov   al,colorb
  408.      push  bp
  409.      mov   bp,word ptr BytesPerLine
  410.      sub   bp,cx
  411.      }
  412. L2:
  413.      asm{
  414.      rep   stosb
  415.      add   di,bp
  416.      mov   cx,si
  417.      dec   bx
  418.      jnz   L2
  419.      pop   bp
  420.      }
  421.  
  422. RightEdge:
  423.      asm{
  424.      mov   bl,Mask_bl
  425.      cmp   bl,00h
  426.      je    Fill_Done
  427.      mov   al,bl
  428.      out   dx,al
  429.      mov   di,add2
  430.      mov   cx,dy
  431.      mov   al,colorb
  432.      }
  433. L3:
  434.      asm{
  435.      stosb
  436.      dec   di
  437.      add   di,word ptr BytesPerLine
  438.      dec   cx
  439.      jnz   L3
  440.      }
  441. Fill_Done:;
  442. }
  443. void barpatx(int x,int y,int dx,int dy,char colorb1,char colorb2)
  444. {
  445. int l=dx;
  446. unsigned int count,add1,add2;
  447.  
  448.        asm{
  449.      cld
  450.      mov   ax,0A000h
  451.      mov   es,ax
  452.          mov   di,x
  453.          shr   di,2
  454.          mov   ax,y
  455.      mul   BytesPerLine
  456.      add   di,ax
  457.          mov   add1,di
  458.      add   di,word ptr BytesPerLine
  459.      mov   add2,di
  460.      mov   di,add1
  461.      mov   dx,03C4h
  462.      mov   al,02h
  463.      out   dx,al
  464.      inc   dx
  465.      mov   ah,colorb1
  466.      mov   al,10
  467.      out   dx,al
  468.      mov   es:[di],ah
  469.      mov   al,5
  470.      out   dx,al
  471.      mov   ah,colorb2
  472.      mov   es:[di],ah
  473.          mov   ah,colorb1
  474.          mov   al,5
  475.      out   dx,al
  476.      mov   di,add2
  477.          mov   es:[di],ah
  478.      mov   al,10
  479.          out   dx,al
  480.          mov   ah,colorb2
  481.          mov   es:[di],ah
  482.          mov   al,0Fh
  483.          out   dx,al
  484.      mov   dx,03CEh
  485.          mov   ax,0008h
  486.      out   dx,ax
  487.      mov   bx,dy
  488.      inc   bx
  489.      mov   dx,l
  490.      shr   dx,2
  491.      mov   si,word ptr BytesPerLine
  492.      sub   si,dx
  493.      mov   count,si
  494.      mov   si,add1
  495.      mov   di,si
  496.      }
  497. L1:
  498.      asm{
  499.      mov   al,es:[si]
  500.      mov   cx,dx
  501.      rep   stosb
  502.      xchg  si,add2
  503.      add   di,count
  504.      dec   bx
  505.      jnz   L1
  506.        }
  507.        outport(0x03CE,0xFF08);
  508. }
  509. void displaycharx(int x,int y,char s,char colorf,char colorb,char flag)
  510. {
  511. char char_tab1[16];
  512. unsigned int Bytes,yoff,CellOff,dssave;
  513. char Shift_C,Left_Mask,Right_Mask,ScanLine,BM,SM1,SM,bb,bb1,b,ln;
  514.  
  515.        memmove(char_tab1,char_tab,16);
  516.        ln=1;
  517.      asm{
  518.      cld
  519.      mov    dssave,ds
  520.      mov    ax,BytesPerLine
  521.      mov    Bytes,ax
  522.      mov    ax,40h
  523.      mov    ds,ax
  524.      mov    al,ds:[85h]
  525.      mov    ScanLine,al
  526.      mul    Bytes
  527.      dec    ax
  528.      mov    CellOff,ax
  529.      xor    ax,ax
  530.      mov    ds,ax
  531.      mov    bx,010Ch
  532.      lds    si,ds:[bx]
  533.      mov    ax,0A000h
  534.      mov    es,ax
  535.      mov    ax,Bytes
  536.      mul    y
  537.      mov    yoff,ax
  538.      mov    ax,x
  539.      shr    ax,2
  540.      add    yoff,ax
  541.      mov    bx,01h
  542.      mov    dx,03C4h
  543.      mov    al,02h
  544.      out    dx,al
  545.      inc    dx
  546.      mov    di,x
  547.      and    di,03h
  548.      jz     Byte_A
  549.      jmp    NByte_A
  550.      }
  551. Byte_A:
  552.      asm{
  553.      xor    cx,cx
  554.      mov    cl,ln
  555.      mov    di,yoff
  556.      }
  557.      if (flag==1) goto L__1;
  558.      asm{
  559.      dec    Bytes
  560.      dec    CellOff
  561.      }
  562. L1:
  563.      asm{
  564.      push   cx
  565.      push   si
  566.      xchg   di,bx
  567.      mov    al,s
  568.      mul    byte  ptr  ScanLine
  569.      add    si,ax
  570.      xchg   di,bx
  571.      inc    bx
  572.      mov    cl,ScanLine
  573.      }
  574. L11:
  575.      asm{
  576.      lodsb
  577.      push   si
  578.      mov    BM,al
  579.      shr    al,4
  580.      xor    ah,ah
  581.      mov    si,ax
  582.      mov    al,byte ptr char_tab1[si]
  583.      out    dx,al
  584.      mov    ah,colorf
  585.      mov    es:[di],ah
  586.      inc    di
  587.      mov    al,BM
  588.      and    al,00001111b
  589.      xor    ah,ah
  590.      mov    si,ax
  591.      mov    al,byte ptr char_tab1[si]
  592.      out    dx,al
  593.      mov    ah,colorf
  594.      mov    es:[di],ah
  595.      add    di,Bytes
  596.      pop    si
  597.      loop   L11
  598.      sub    di,CellOff
  599.      pop    si
  600.      pop    cx
  601.      loop   L1
  602.      jmp    STR_OUT
  603.      }
  604. L__1:
  605.      asm{
  606.      dec    Bytes
  607.      dec    CellOff
  608.      }
  609. L_1:
  610.      asm{
  611.      push   cx
  612.      push   si
  613.          xchg   di,bx
  614.      mov    al,s
  615.      mul    byte  ptr  ScanLine
  616.      add    si,ax
  617.      xchg   di,bx
  618.      inc    bx
  619.      mov    cl,ScanLine
  620.      }
  621. L_11:
  622.      asm{
  623.      lodsb
  624.      xor    ah,ah
  625.      mov    BM,al
  626.      push   si
  627.      not    al
  628.      shr    al,4
  629.      mov    si,ax
  630.      mov    al,byte ptr char_tab1[si]
  631.      out    dx,al
  632.      mov    al,colorb
  633.      mov    es:[di],al
  634.      mov    al,BM
  635.      not    al
  636.          and    al,00001111b
  637.          mov    si,ax
  638.      mov    al,byte ptr char_tab1[si]
  639.      out    dx,al
  640.          mov    al,colorb
  641.          mov    es:[di+1],al
  642.      mov    al,BM
  643.          shr    al,4
  644.          mov    si,ax
  645.          mov    al,byte ptr char_tab1[si]
  646.          out    dx,al
  647.          mov    ah,colorf
  648.      mov    es:[di],ah
  649.          inc    di
  650.          mov    al,BM
  651.          and    al,00001111b
  652.      xor    ah,ah
  653.          mov    si,ax
  654.          mov    al,byte ptr char_tab1[si]
  655.      out    dx,al
  656.          mov    ah,colorf
  657.          mov    es:[di],ah
  658.      add    di,Bytes
  659.      pop    si
  660.          loop   L_11
  661.          sub    di,CellOff
  662.      pop    si
  663.      pop    cx
  664.      loop   L_1
  665.      jmp    STR_OUT
  666.      }
  667. NByte_A:
  668.      asm{
  669.      mov   cx,x
  670.          mov   di,x
  671.          shr   di,2
  672.      shl   di,2
  673.          sub   cx,di
  674.          mov   SM,cl
  675.      mov   ax,4
  676.      sub   ax,cx
  677.      mov   SM1,al
  678.      xor   cx,cx
  679.      mov   cl,ln
  680.      mov   bb,cl
  681.      mov   di,yoff
  682.      }
  683.      if (flag==1) goto L__2;
  684.      asm{
  685.      dec   CellOff
  686.      }
  687. L2:
  688.      asm{
  689.      push  cx
  690.      push  si
  691.      xchg  di,bx
  692.      mov   al,s
  693.      mul   ScanLine
  694.      add   si,ax
  695.      xchg  di,bx
  696.      inc   bx
  697.      mov   cl,ScanLine
  698.      }
  699. L22:
  700.      asm{
  701.      push  cx
  702.      push  si
  703.          mov   al,ds:[si]
  704.          mov   BM,al
  705.          shr   al,4
  706.          mov   cl,SM
  707.          shr   al,cl
  708.      xor   ah,ah
  709.          mov   si,ax
  710.          mov   al,byte ptr char_tab1[si]
  711.          out   dx,al
  712.      mov   ah,colorf
  713.          mov   es:[di],ah
  714.  
  715.          mov   al,BM
  716.          shr   al,4
  717.          mov   cl,SM1
  718.          shl   al,cl
  719.      and   al,00001111b
  720.      mov   ah,BM
  721.      and   ah,00001111b
  722.          mov   cl,SM
  723.          shr   ah,cl
  724.          or    al,ah
  725.          xor   ah,ah
  726.          mov   si,ax
  727.          mov   al,byte ptr char_tab1[si]
  728.      out   dx,al
  729.          mov   ah,colorf
  730.          mov   es:[di+1],ah
  731.  
  732.      mov   al,BM
  733.          and   al,00001111b
  734.          mov   cl,SM1
  735.          shl   al,cl
  736.          and   al,00001111b
  737.          xor   ah,ah
  738.          mov   si,ax
  739.      mov   al,byte ptr char_tab1[si]
  740.      out   dx,al
  741.      mov   ah,colorf
  742.      mov   es:[di+2],ah
  743.      pop   si
  744.      inc   si
  745.      add   di,Bytes
  746.      pop   cx
  747.      loop  L22
  748.      sub   di,CellOff
  749.      pop   si
  750.      pop   cx
  751.      dec   bb
  752.      }
  753.      if (bb!=0) goto L2;
  754.      asm{
  755.      jmp   STR_OUT
  756.      }
  757. L__2:
  758.      asm{
  759.      dec   CellOff
  760.      }
  761. L_2:
  762.      asm{
  763.      push  cx
  764.      push  si
  765.      xchg  di,bx
  766.      mov   al,s
  767.      mul   ScanLine
  768.      add   si,ax
  769.      xchg  di,bx
  770.      inc   bx
  771.      mov   al,ScanLine
  772.      mov   bb1,al
  773.      }
  774. L_22:
  775.      asm{
  776.      mov   al,ds:[si]
  777.      mov   BM,al
  778.      push  si
  779.      xor   ah,ah
  780.          not   al
  781.      mov   cl,SM
  782.          shr   al,4
  783.          shr   al,cl
  784.          mov   si,ax
  785.          mov   al,byte ptr char_tab1[si]
  786.      out   dx,al
  787.          mov   al,colorb
  788.          mov   es:[di],al
  789.          mov   al,BM
  790.      shr   al,4
  791.          mov   cl,SM
  792.          shr   al,cl
  793.          mov   si,ax
  794.      mov   al,byte ptr char_tab1[si]
  795.      out   dx,al
  796.          mov   ah,colorf
  797.          mov   es:[di],ah
  798.  
  799.          mov   al,BM
  800.          not   al
  801.      shr   al,4
  802.          mov   cl,SM1
  803.          shl   al,cl
  804.          and   al,00001111b
  805.          mov   ah,BM
  806.      not   ah
  807.          and   ah,00001111b
  808.          mov   cl,SM
  809.          shr   ah,cl
  810.      or    al,ah
  811.          xor   ah,ah
  812.          mov   si,ax
  813.          mov   al,byte ptr char_tab1[si]
  814.      out   dx,al
  815.      mov   al,colorb
  816.          mov   es:[di+1],al
  817.          mov   al,BM
  818.          shr   al,4
  819.          mov   cl,SM1
  820.          shl   al,cl
  821.      and   al,00001111b
  822.          mov   ah,BM
  823.          and   ah,00001111b
  824.          mov   cl,SM
  825.          shr   ah,cl
  826.      or    al,ah
  827.          xor   ah,ah
  828.          mov   si,ax
  829.          mov   al,byte ptr char_tab1[si]
  830.      out   dx,al
  831.          mov   ah,colorf
  832.          mov   es:[di+1],ah
  833.  
  834.      xor   ah,ah
  835.      mov   al,BM
  836.          mov   cl,SM1
  837.          not   al
  838.          and   al,00001111b
  839.          shl   al,cl
  840.          and   al,00001111b
  841.      mov   si,ax
  842.          mov   al,byte ptr char_tab1[si]
  843.          out   dx,al
  844.          mov   al,colorb
  845.          mov   es:[di+2],al
  846.      mov   al,BM
  847.          and   al,00001111b
  848.          mov   cl,SM1
  849.          shl   al,cl
  850.      and   al,00001111b
  851.          mov   si,ax
  852.          mov   al,byte ptr char_tab1[si]
  853.          out   dx,al
  854.      mov   ah,colorf
  855.      mov   es:[di+2],ah
  856.      pop   si
  857.      inc   si
  858.      add   di,Bytes
  859.      dec   bb1
  860.      }
  861.      if (bb1!=0) goto L_22;
  862.      asm{
  863.      sub   di,CellOff
  864.      pop   si
  865.      pop   cx
  866.      dec   bb
  867.      }
  868.      if (bb!=0) goto L_2;
  869. STR_OUT:
  870.      asm{
  871.      mov   al,0Fh
  872.      out   dx,al
  873.      mov   ds,dssave
  874.      }
  875. }
  876. void setcolx(char colorf,char colorb,unsigned int place)
  877. {
  878. char BM;
  879. char char_tab1[16];
  880.  
  881.       FastPlace=place;
  882.       memmove(char_tab1,char_tab,16);
  883.       asm{
  884.     cld
  885.     push    ds
  886.     mov     ax,FastPlace
  887.     push    ax
  888.     mov     ax,40h
  889.         mov     ds,ax
  890.     mov     cx,ds:[85h]
  891.         xor     ax,ax
  892.         mov     ds,ax
  893.         mov     bx,43h*4
  894.         lds     si,ds:[bx]
  895.         mov     ax,0A000h
  896.         mov     es,ax
  897.         pop     ax
  898.     mov     di,ax
  899.     mov     al,0h
  900.         mov     ah,1h
  901.         mul     cx
  902.         mov     cx,ax
  903.         mov     bl,colorf
  904.         mov     bh,colorb
  905.         mov     dx,03C4h
  906.     mov     al,02h
  907.     out     dx,al
  908.     inc     dx
  909.     }
  910. L1:
  911.     asm{
  912.     mov     al,ds:[si]
  913.     mov     BM,al
  914.     push    si
  915.     xor     ah,ah
  916.     shr     al,4
  917.     mov     si,ax
  918.     mov     al,byte ptr char_tab1[si]
  919.     out     dx,al
  920.     mov     es:[di],bl
  921.     mov     al,BM
  922.     not     al
  923.     shr     al,4
  924.     mov     si,ax
  925.     mov     al,byte ptr char_tab1[si]
  926.     out     dx,al
  927.     mov     es:[di],bh
  928.     inc     di
  929.     mov     al,BM
  930.     and     al,00001111b
  931.     mov     si,ax
  932.     mov     al,byte ptr char_tab1[si]
  933.     out     dx,al
  934.     mov     es:[di],bl
  935.     mov     al,BM
  936.     not     al
  937.     and     al,00001111b
  938.     mov     si,ax
  939.     mov     al,byte ptr char_tab1[si]
  940.         out     dx,al
  941.         mov     es:[di],bh
  942.         pop     si
  943.         inc     di
  944.         inc     si
  945.         loop    L1
  946.         mov     al,0Fh
  947.         out     dx,al
  948.         pop     ds
  949.     }
  950. }
  951. void fasttextx(int x,int y,char *s)
  952. {
  953. char *strs;
  954. unsigned int Bytes,ScanLine,wd,w;
  955. char i,b;
  956.  
  957.       strcpy(strs,s);
  958.       asm{
  959.     cld
  960.     push    ds
  961.     mov     ax,FastPlace
  962.     push    ax
  963.     mov     ax,BytesPerLine
  964.     mov     Bytes,ax
  965.     mov     ax,40h
  966.     mov     ds,ax
  967.     mov     ax,ds:[85h]
  968.     mov     ScanLine,ax
  969.     mov     ax,0A000h
  970.     mov     es,ax
  971.     mov     ds,ax
  972.  
  973.     mov     dx,03CEh
  974.     mov     ax,0008h
  975.     out     dx,ax
  976.     mov     dx,03C4h
  977.     mov     ax,0F02h
  978.     out     dx,ax
  979.  
  980.     mov     ax,y
  981.     mul     Bytes
  982.     mov     di,x
  983.     shr     di,2
  984.     add     di,ax
  985.     mov     dx,di
  986.     mov     bx,Bytes
  987.     mov     wd,dx
  988.     mov     w,bx
  989.     }
  990.     for(i=0;i<strlen(strs);i++)
  991.       {
  992.       b=strs[i];
  993.       asm{
  994.     mov     ax,0A000h
  995.     mov     es,ax
  996.     mov     ax,0A000h
  997.     mov     ds,ax
  998.     mov     dx,wd
  999.     pop     ax
  1000.     mov     si,ax
  1001.     push    ax
  1002.     mov     al,b
  1003.     mov     cx,ScanLine
  1004.     mul     cl
  1005.     shl     ax,1
  1006.     add     si,ax
  1007.     mov     di,dx
  1008.     }
  1009. L1:
  1010.     asm{
  1011.     movsb
  1012.     movsb
  1013.     dec     di
  1014.     dec     di
  1015.     add     di,w
  1016.     loop    L1
  1017.     inc     dx
  1018.     inc     dx
  1019.     mov     wd,dx
  1020.     }
  1021.       }
  1022.       asm{
  1023.     pop     ax
  1024.     pop     ds
  1025.     mov     ax,0FF08h
  1026.     mov     dx,03CEh
  1027.     out     dx,ax
  1028.     mov     ax,0F02h
  1029.     mov     dx,03C4h
  1030.     out     dx,ax
  1031.     }
  1032. }
  1033.  
  1034. char getimageramx(unsigned int x,unsigned int y,unsigned int dx,
  1035.            unsigned int dy,Image *W)
  1036. {
  1037. unsigned int i,j,k,scrofs,xend;
  1038. long t,l;
  1039. char s[20];
  1040.     xend=x+dx;
  1041.     x=x >> 2;
  1042.     if (xend % 4 != 0) xend=((xend >> 2) << 2)+4;
  1043.     dx=xend-x;
  1044.     W->dx=dx >> 2;
  1045.     W->dy=dy;
  1046.     t=coreleft();
  1047.  
  1048.     l=(W->dy+1)*(W->dx)*(long)(4);
  1049.     t=l-t+10000;
  1050.     if (t>0) return(1);
  1051.  
  1052.     for (i=0;i<=3;i++)
  1053.     t=allocmem(((W->dx)*(W->dy+1))/16+1,&W->p[i]);
  1054.  
  1055.     outportb(0x03CE,4);
  1056.     k=y*BytesPerLine+x;
  1057.  
  1058.     for (i=0;i<=3;i++){
  1059.         scrofs=k;
  1060.         outportb(0x03CF,i);
  1061.     for (j=0;j<=W->dy;j++){
  1062.         move(0xA000,scrofs,W->p[i],j*W->dx,W->dx);
  1063.         scrofs=scrofs+BytesPerLine;
  1064.         }
  1065.         }
  1066.     W->type=0;
  1067.     outport(0x03CE,0x0004);
  1068.     return(0);
  1069. }
  1070. void putimageramx(unsigned int x,unsigned int y,Image W,char Restore)
  1071. {
  1072. unsigned int  i,j,scrofs;
  1073.  
  1074.     scrofs=y*BytesPerLine+(x >> 2);
  1075.     outportb(0x03C4,0x02);
  1076.     for (i=0;i<=W.dy;i++)
  1077.         {
  1078.     for (j=0;j<=3;j++)
  1079.         {
  1080.         outportb(0x03C5,1 << j);
  1081.         move(W.p[j],i*W.dx,0xA000,scrofs,W.dx);
  1082.         }
  1083.         scrofs=scrofs+BytesPerLine;
  1084.         }
  1085.     if (Restore==0) for (i=0;i<=3;i++) freemem(W.p[i]);
  1086.  
  1087. }
  1088. char getimagediskx(unsigned int x,unsigned int y,unsigned int dx,unsigned int dy,
  1089.            Image *W)
  1090. {
  1091. unsigned int  k,i,j,n,bufsize,xend,Buff,scrofs;
  1092. long t0,ll,l;
  1093. int   f;
  1094. struct dfree free;
  1095. long avail;
  1096. int drive;
  1097. char Name[12];
  1098. void far *buff;
  1099. char *buffer;
  1100.  
  1101.     xend=x+dx;
  1102.     x=x >> 2;
  1103.     if (xend % 4 != 0) xend=((xend >> 2) << 2)+4;
  1104.     dx=xend-x;
  1105.     W->dx=dx >> 2;
  1106.     W->dy=dy;
  1107.     l=(W->dy+1)*(W->dx)*(long)(4);
  1108.  
  1109.  
  1110.     drive = getdisk()+1;
  1111.     getdfree(drive, &free);
  1112.     if (free.df_sclus == 0xFFFF) return(1);
  1113.     avail =  (long)free.df_avail*(long)free.df_bsec*(long)free.df_sclus;
  1114.  
  1115.     l=avail-l;
  1116.     if (l<10000) return(1);
  1117.     randomize();
  1118.     W->p[0]=rand();
  1119.  
  1120.     itoa(W->p[0],Name,10);
  1121.     _fmode=O_BINARY;
  1122.     if ((f=creat(Name,0x0100 | 0x0080))==NULL) return(1);
  1123.     l=coreleft();
  1124.     if (l>0xFFF0) bufsize=0xFFF0; else bufsize=l;
  1125.     bufsize=(bufsize-(bufsize % (W->dx*4)));
  1126.     if (l>80) t0=allocmem(bufsize/16+1,&Buff); else return(1);
  1127.     if (t0!=-1) return(1);
  1128.  
  1129.     buff=MK_FP(Buff,0);
  1130.     scrofs=y*BytesPerLine+x;
  1131.     outportb(0x03CE,4);
  1132.  
  1133.     k=0;
  1134.     for (i=0;i<=W->dy;i++)
  1135.         {
  1136.     for (j=0;j<=3;j++)
  1137.         {
  1138.         outportb(0x03CF,j);
  1139.         move(0xA000,scrofs,Buff,k,W->dx);
  1140.         k=k+W->dx;
  1141.         }
  1142.         if (k==bufsize)
  1143.            {
  1144.            write(f,buff,bufsize);
  1145.            k=0;
  1146.            }
  1147.            scrofs=scrofs+BytesPerLine;
  1148.         }
  1149.         if (k!=0) write(f,buff,k);
  1150.         freemem(Buff);
  1151.         close(f);
  1152.         W->type=1;
  1153.         outport(0x03CE,0x0004);
  1154.         return(0);
  1155. }
  1156. void putimagediskx(unsigned int x,unsigned int y,Image W,char Restore)
  1157. {
  1158. unsigned int  k,i,j,bufsize,scrofs,Buff;
  1159. long t0,l;
  1160. int  f,b;
  1161. char Name[12];
  1162. void far *buff;
  1163.  
  1164.        itoa(W.p[0],Name,10);
  1165.        _fmode=O_BINARY;
  1166.        if ((f=open(Name,0x0100 | 0x0080))==NULL) exit(0);
  1167.        l= coreleft();
  1168.        if (l>0xFFF0) bufsize=0xFFF0; else bufsize=l;
  1169.        bufsize=(bufsize-(bufsize % (W.dx*4)));
  1170.        if (l>80) t0=allocmem(bufsize/16+1,&Buff); else exit(0);
  1171.        if (t0!=-1) exit(0);
  1172.        buff=MK_FP(Buff,0);
  1173.        scrofs=y*BytesPerLine+(x >> 2);
  1174.        read(f,buff,bufsize);
  1175.        k=0;
  1176.        outportb(0x03C4,0x02);
  1177.        for (i=0;i<=W.dy;i++)
  1178.            {
  1179.        for (j=0;j<=3;j++)
  1180.            {
  1181.            outportb(0x03C5,1 << j);
  1182.            move(Buff,k,0xA000,scrofs,W.dx);
  1183.            k=k+W.dx;
  1184.            }
  1185.            if (k==bufsize)
  1186.           {
  1187.            read(f,buff,bufsize);
  1188.            k=0;
  1189.            }
  1190.            scrofs=scrofs+BytesPerLine;
  1191.            }
  1192.          freemem(Buff);
  1193.          outportb(0x03C5,0x0F);
  1194.          close(f);
  1195.          if (Restore==0) remove(Name);
  1196. }
  1197. char getimagex(unsigned int x,unsigned int y,unsigned int dx,unsigned int dy,Image *W)
  1198. {
  1199.     if (getimageramx(x,y,dx,dy,W)==0) return(0);
  1200.     return(getimagediskx(x,y,dx,dy,W));
  1201. }
  1202. void putimagex(unsigned int x,unsigned int y,Image W,char Restore)
  1203. {
  1204.      if (W.type==0) putimageramx(x,y,W,Restore);
  1205.      if (W.type==1) putimagediskx(x,y,W,Restore);
  1206. }
  1207. void screentoscreenx(int x,int y,int dx,int dy,int x1,int y1)
  1208. {
  1209. unsigned int ofsp,ofsp1,i,j;
  1210.  
  1211.      outport(0x03CE,0x0008);
  1212.      outport(0x03C4,0x0f02);
  1213.      x=x >> 2;
  1214.      x1=x1 >> 2;
  1215.      dx=dx >> 2;
  1216.      ofsp=y*BytesPerLine+x;
  1217.      ofsp1=y1*BytesPerLine+x1;
  1218.      for (i=y;i<=(y+dy);i++)
  1219.      {
  1220.      move(0xA000,ofsp,0xA000,ofsp1,dx);
  1221.      ofsp=ofsp+BytesPerLine;
  1222.      ofsp1=ofsp1+BytesPerLine;
  1223.      }
  1224.     outport(0x03CE,0xff08);
  1225. }
  1226.