home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / GRAPHIC.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-05-30  |  6.7 KB  |  304 lines

  1.         page    58,132
  2.  
  3. ; graphic.asm
  4. ; contains: palette(),wtdot(),getdot(),fillbox(),readpen()
  5. ;
  6.         include    model.h
  7.         include    prologue.h
  8.         include    equ.h
  9.         name    graphic
  10.         pseg    pallette
  11.  
  12. ;==>--    void palette(id,value)
  13. ;
  14. ;;    ARGUMENTS:
  15. ;      (int)        id    -    palette color ID
  16. ;      (int)          value    -    color value
  17. ;
  18. ;;    DESCRIPTION:
  19. ;      Set color Palette via Rom bios
  20. ;
  21. ;;    AUTHOR:
  22. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  23. ;;;
  24.     cproc    palette
  25.     mov    bx,parm2_    ;get color value to BL
  26.     mov    bh,parm1_    ;get ID to AL
  27.     and    bx,07F0Fh    ;mask off some undesirable bits
  28.     mov    ah,11        ;function 11
  29.     int    10h
  30.     cproce
  31.  
  32. ;==>--    void wtdot(row,column,color)
  33. ;
  34. ;;    ARGUMENTS:
  35. ;      (int)        row        -    y position
  36. ;      (int)        column        -    x position
  37. ;      (int)        color        -    color to write
  38. ;
  39. ;;    DESCRIPTION:
  40. ;      Write a dot via ROM-BIOS
  41. ;
  42. ;;    AUTHOR:
  43. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  44. ;;;
  45.     cproc    wtdot
  46.     mov    dx,parm1_    ;get row
  47.     mov    cx,parm2_    ;get column
  48.     mov    al,parm3_    ;get color value to AL
  49.     mov    ah,12        ;function 12
  50.     int    10h
  51.     cproce
  52.  
  53. ;==>--    unsigned getdot(row,column)
  54. ;
  55. ;;    ARGUMENTS:
  56. ;      (int)        row        -    y position
  57. ;      (int)        column        -    x position
  58. ;
  59. ;;    DESCRIPTION:
  60. ;      Read the current color value of a specified dot on graphics
  61. ;      screen.
  62. ;
  63. ;;    AUTHOR:
  64. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  65. ;;;
  66.     cproc    getdot
  67.     mov    dx,parm1_    ;get row
  68.     mov    cx,parm2_    ;get column
  69.     mov    ah,13        ;function to read dot
  70.     int    10h
  71.     xor    ah,ah        ;entire return in AL
  72.     cproce
  73.  
  74. ;==>--    void fillbox(urow,lrow,lcol,rcol,color)
  75. ;
  76. ;;    ARGUMENTS:
  77. ;      (int)        urow    -    upper row 0.199 of box shaped area
  78. ;      (int)        lrow    -    lower row of area
  79. ;      (int)        lcol    -    left column
  80. ;      (int)        rcol    -    right column
  81. ;      (int)        color    -    fill and edge color
  82. ;
  83. ;;    DESCRIPTION:
  84. ;      Generate a rectangular area and fill with the specified color
  85. ;
  86. ;;    AUTHOR:
  87. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  88. ;
  89. ;    MODIFICATIONS:
  90. ;      Checked video mode in order to make correct calculation for
  91. ;      offset into video buffer.
  92. ;;;
  93.  
  94.  
  95.  
  96. if    _LCODE
  97.  _fdyn struc
  98.      _vidmod dw ?    ;current video mode
  99.     _curcol    dw    ?
  100.     _colcnt    dw    ?
  101.     _currow    dw    ?
  102.     _rowcnt    dw    ?
  103.     _sav1    dw    ?
  104.     _bpsav    dw    ?
  105.     _retn    dd    ?
  106.     _urow    dw    ?
  107.     _lrow    dw    ?
  108.     _lcol    dw    ?
  109.     _rcol    dw    ?
  110.     _colr    dw    ?
  111.  _fdyn ends
  112. else
  113.  _fdyn struc
  114.      _vidmod dw ?    ;current video mode
  115.     _curcol    dw    ?
  116.     _colcnt    dw    ?
  117.     _currow    dw    ?
  118.     _rowcnt    dw    ?
  119.     _sav1    dw    ?
  120.     _bpsav    dw    ?
  121.     _retn    dw    ?
  122.     _urow    dw    ?
  123.     _lrow    dw    ?
  124.     _lcol    dw    ?
  125.     _rcol    dw    ?
  126.     _colr    dw    ?
  127.  _fdyn ends
  128. endif
  129.     cproc    fillbox,,,,12
  130.     mov    ax,[bp]._lrow    ;LROW
  131.     mov    bx,[bp]._urow    ;UROW
  132.     mov    [bp]._currow,bx    ;init current row
  133.     sub    ax,bx        ;form row_count
  134.     jl    _fbox98        ;hop if lower < upper
  135.     inc    ax        ;if same, count is 1
  136.     mov    [bp]._rowcnt,ax    ;else OK, store row_count here..
  137.     mov    ax,[bp]._rcol    ;RCOL
  138.     mov    bx,[bp]._lcol    ;LCOL
  139.     mov    [bp]._curcol,bx    ;init current column
  140.     sub    ax,bx        ;form column count
  141.     jl    _fbox98        ;hop if right < left
  142.     inc    ax
  143.     mov    [bp]._colcnt,ax ;else OK, store column_count
  144.     mov    ah,0fh        ;get video mode
  145.     int    10h        ;
  146.     mov    ah,0        ;
  147.     mov    [bp]._vidmod,ax    ;and store it        
  148. do_all_rows:
  149.     call    do_row
  150.     mov    dx,[bp]._currow
  151.     inc    dx
  152.     mov    [bp]._currow,dx
  153.     mov    cx,[bp]._rowcnt
  154.     dec    cx
  155.     mov    [bp]._rowcnt,cx
  156.     jnz    do_all_rows        ;loop if not done yet
  157.     xor    ax,ax
  158.     jmp    short _fbox98
  159. _fbox98:
  160.     cproce
  161.  
  162. ;==>--    void readpen(out)
  163. ;
  164. ;;    ARGUMENTS:
  165. ;      (struct GFREGS *)    out    -    pointer to GFREGS
  166. ;
  167. ;;    DESCRIPTION:
  168. ;      Read light pen position and transfer values to GFREGS structure.
  169. ;
  170. ;;    AUTHOR:
  171. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  172. ;;;
  173.     cproc    readpen
  174.     mov    ax,0400h    ;function 4 to AH
  175.     int    10h
  176.     if    _LDATA
  177.      push    ds
  178.      lds    si,dword ptr parm1_
  179.     else
  180.      mov    si,parm1_    ;get address of output structure
  181.     endif
  182.     mov    [si+gfax],ax    ;transfer pen trigger bit (AH bit 1)
  183.     mov    [si+gfbx],bx    ;transfer pixel column 0..319,639
  184.     mov    [si+gfcx],cx    ;transfer raster line (row 0..199)
  185.     mov    [si+gfdx],dx    ;transfer character row,column
  186.     if    _LDATA
  187.      pop    ds
  188.     endif
  189.     cproce
  190.  
  191. ;  Subroutine to Do A Single Row.
  192. ;
  193. do_row     proc    near
  194.     mov    ax,[bp]._lcol        ;get LCOL
  195.     mov    [bp]._curcol,ax        ;and init current_column
  196.     mov    cx,[bp]._colcnt        ;get column_count
  197.     mov    [bp]._sav1,cx
  198.  
  199. do_row2:
  200.     call    $dot            ;do a single dot
  201.     inc    word ptr [bp]._curcol    ;update current_column
  202.     mov    cx,[bp]._sav1
  203.     dec    cx
  204.     mov    [bp]._sav1,cx
  205.     jnz    do_row2
  206.     ret
  207. do_row    endp
  208.  
  209. ;********************
  210. ;
  211. ;  $DOT
  212. ;
  213. ;********************
  214. ;
  215. ;  This is a fast dot producing routine which works ONLY with _fbox at
  216. ;  this time.  DO NOT CALL THIS FROM C !!
  217. ;
  218. ;  The major difference between this and _fdot is the linkage with callers.
  219. ;
  220. ;  The same stack setup as for _fbox exists:
  221. ;
  222. ;   BP+  0 -> current_column
  223. ;     2 -> column_count
  224. ;     4 -> current_row
  225. ;     6 -> row_count
  226. ;     8 -> <BP from C>
  227. ;       -> <ret addr >    (2 or 4 bytes)
  228. ;    @ab+8 -> U Row        (may be BP+12 or +14)
  229. ;   @ab+10 -> L Row
  230. ;   @ab+12 -> L Col
  231. ;   @ab+14 -> R Col
  232. ;   @ab+16 -> Color
  233.  
  234. $dot    proc    near
  235.     mov    ax,[bp]._currow ;get row
  236.     mov    ah,0        ;must be < 255
  237.     test    al,1        ;check for odd/even
  238.     jnz    $dot_odd_row    ;hop if odd
  239.     shr    al,1        ;N/2 to AX
  240.     cmp    al,0        ;if 0, hop around..
  241.     jz    $dot2
  242.     mov    bx,ax
  243.     mov    cl,6
  244.     shl    bx,cl        ;* 40h in BX
  245.     mov    cl,4
  246.     shl    ax,cl        ;* 10h in AX
  247.     add    ax,bx        ;* 50h in AX
  248.     jmp    short $dot2
  249. $dot_odd_row:            ;do odd row
  250.     dec    al        ;N - 1
  251.     shr    al,1        ;(N-1)/2
  252.     cmp    al,0        ;is it zero here ?
  253.     jz    $dot1        ;if so, starts at 2000h period.
  254.     mov    bx,ax
  255.     mov    cl,6
  256.     shl    bx,cl        ;* 40h
  257.     mov    cl,4
  258.     shl    ax,cl        ;* 10h
  259.     add    ax,bx        ;* 50h in AX
  260. $dot1:    add    ax,2000h    ;+ offset for odd bank
  261. $dot2:    mov    bx,[bp]._curcol ;get column
  262.     mov    dx,bx        ;& to DX
  263.     shr    bx,1        ;M/2
  264.     shr    bx,1        ;M/2
  265.     mov    cx,[bp]._vidmod    ;check video mode
  266.     cmp    cx,06h        ;see if video mode == 6
  267.     jne    nodiv2        ;if not, do not perform M/2
  268.     shr    bx,1        ;M/2
  269. nodiv2: add    ax,bx        ;+ row offset = target byte offset
  270.     mov    si,ax        ;to index reg.
  271. ;  M is in DX here - derive mask to BL with color in AL
  272.     mov    ax,[bp]._colr    ;get color
  273.     and    ax,3        ;must be <= 3
  274.     and    dx,3        ;form M % 4 in DX
  275.     cmp    dl,0
  276.     jz    $dot00        ;use bits 7,6
  277.     cmp    dl,1
  278.     jz    $dot01        ;5,4
  279.     cmp    dl,2
  280.     jz    $dot10        ;3,2
  281.     mov    bl,0FCh        ;else use 1,0, and color bits are OK
  282.     jmp    short $dot4
  283. $dot00:    mov    cl,6        ;shift color bits to 7,6
  284.     mov    bl,03Fh        ;mask
  285.     jmp    short $dot3
  286. $dot01:    mov    cl,4        ;color bits to 5,4
  287.     mov    bl,0CFh
  288.     jmp    short $dot3
  289. $dot10:    mov    cl,2        ;color bits to 2,3
  290.     mov    bl,0F3h
  291. $dot3:    shl    al,cl        ;move color bits left
  292. $dot4:    push    ds
  293.     mov    dx,0B800h    ;segment addr of graphics memory
  294.     mov    ds,dx
  295.     mov    dl,[si]        ;get current byte...
  296.     and    dl,bl        ;mask off bits for this PEL
  297.     or    dl,al        ;then merge in new color bits
  298.     mov    [si],dl        ;and put it back.
  299.     pop    ds
  300.     ret
  301. $dot    endp
  302.     endps
  303.     end
  304.