home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / asm / PLOT.ZIP / PLOT.ASM
Encoding:
Assembly Source File  |  1988-12-30  |  6.6 KB  |  279 lines

  1. comment *
  2.  
  3.                 PLOT
  4.  
  5.          Copyright (C) 1984  Dr. Peter G. Aitken
  6.             Department of Physiology
  7.      Duke University Medical Center, Durham, NC 27710
  8.  
  9. This subroutine uses the IBM color graphics board in the 640 X 200 high
  10. resolution mode to display analog waveforms that are stored as a series
  11. of values in an integer array.
  12.  
  13.  
  14. Format:     call plot (grid%,clr%,offset%,scale%,addr%,stp%)
  15.  
  16.     if grid%<>0 a screen grid is plotted;
  17.     if grid%=0 no grid is plotted.
  18.  
  19.     if clr%<>0 the screen is cleared;
  20.     if clr%=0 the screen is not cleared.
  21.  
  22.     offset% sets the vertical offset of the display; normally set
  23.     in the range 0-199.
  24.  
  25.     scale% sets the vertical gain of the display, with smaller
  26.     values of scale% giving more gain.
  27.  
  28.     addr% is the address (i.e., offset within the data segment)
  29.     of the first array element to be plotted.
  30.  
  31.     stp% must equal 1, 2, or 4: it determines if 640 (step%=1),
  32.     320 (step%=2) or 160 (step%=4) data points are plotted. Value
  33.     not range checked.
  34.  
  35. *
  36.  
  37. ;*****************************************************************************
  38.  
  39. sseg        segment    stack        ;set up stack
  40.         dw    50 DUP (?)
  41. sseg        ends
  42.  
  43. dseg        segment
  44.                     ;set up data segment with reserved
  45. array        dw  (?)            ;memory locations for the 6 para-
  46. divisor        dw  (?)            ;meters to be passed by the calling
  47. step        dw  (?)            ;program.
  48. off_set        dw  (?)
  49. clear        dw  (?)
  50. grid        dw  (?)
  51.  
  52. dseg        ends
  53.  
  54.  
  55. video        segment at 0B800H
  56. video        ends
  57.  
  58.  
  59. cseg        segment public 'CODE'
  60.  
  61.         assume cs:cseg,ss:sseg,ds:dseg,es:video
  62.  
  63.         public    PLOT        ;declare "PLOT" public so it can
  64.                     ;be called from another program
  65. PLOT        proc    far
  66.         push    bp        ;save register
  67.  
  68. ;the next block of code gets the 6 parameters passed by the calling
  69. ;program and stores them in the proper locations
  70.  
  71.         mov    bp,sp
  72.         mov    si,[bp]+16
  73.         mov    dx,[si]
  74.         mov    grid,dx        ;1st parameter in GRID
  75.         mov    si,[bp]+14
  76.         mov    dx,[si]
  77.         mov    clear,dx    ;2nd parameter in CLEAR
  78.         mov    si,[bp]+12
  79.         mov    dx,[si]
  80.         mov    off_set,dx    ;3rd parameter in OFF_SET
  81.         mov    si,[bp]+10
  82.         mov    dx,[si]
  83.         mov    divisor,dx    ;4th parameter in DIVISOR
  84.         mov    si,[bp]+8    
  85.         mov    dx,[si]
  86.         mov    array,dx    ;5th parameter in ARRAY
  87.         mov    si,[bp]+6
  88.         mov    dx,[si]
  89.         mov    step,dx        ;6th parameter in STEP
  90.  
  91.         push    es        ;save es value
  92.         mov    dx,0B800H    ;point es at video ram
  93.         mov    es,dx
  94.  
  95. ;if CLEAR = 0 jump ahead, if CLEAR <> 0 clear screen.
  96.  
  97.         mov    dx,clear
  98.         cmp    dx,0
  99.         je    no_clear
  100.  
  101. ;the next 5 lines clear the screen by using the STOSW instruction to
  102. ;place 0 in all words of video memory.
  103.  
  104.         mov    cx,2000H    ;video ram word count
  105.         mov    ax,0
  106.         mov    di,0        ;start at offset 0
  107.         cld            ;set forward direction
  108.         rep    stosw
  109.  
  110. ;if GRID <>0 put a grid on the screen - else jump
  111.  
  112. no_clear:    mov    dx,grid
  113.         cmp    dx,0
  114.         je    no_grid    
  115.  
  116. ;first do horizontal grid lines
  117.  
  118.         mov    ax,199        ;plot line in row 199
  119.         call    horiz
  120.         mov    ax,175        ;plot line in row 175, 150,
  121. N1:        call    horiz        ;etc.
  122.         sub    ax,25
  123.         jns    N1        ;if dx not < 0, do another
  124.  
  125. ;now do vertical grid lines
  126.  
  127.         mov    cx,639        ;plot line in column 639
  128.         call    vert
  129.         mov    cx,560        ;plot line in column 560,
  130. N2:        call    vert        ;480, etc.
  131.         sub    cx,80
  132.         jns    N2        ;if cx not < 0, do another
  133.     
  134. ;the next block of code initializes cx, which will count loops, and si,
  135. ;which is used as an offset pointer within the data array
  136.  
  137. no_grid:    mov    cx,640        ;count in cx
  138.         mov    ax,1280        ;offset for start of plot will
  139.         cwd            ;be 1278 for step=1, 638 for
  140.         idiv    step        ;step=2, and 318 for step=4
  141.         mov    si,ax        
  142.         sub    si,2
  143.  
  144. ;now we start to plot
  145.  
  146.         mov    bx,array    ;put array base address in bx
  147.  
  148. plot_loop:    sub    cx,step        ;subtract STEP from cx; if
  149.         jcxz    done        ;the result is less than 0,    
  150.                     ;we're done.
  151.         mov    ax,[bx][si]    ;get array element
  152.         cmp    divisor,0    ;if divisor=0 jump ahead
  153.         jz    no_div
  154.         neg    ax        ;negate it
  155.         cwd            ;convert to double word
  156.         idiv    divisor        ;divide by scaling factor
  157.         add    ax,off_set    ;add the offset
  158.  
  159. ;now ax has the row number, which can range from 0 to 199.  The next 4
  160. ;lines check to see if ax is within this range; if ax is less than 0
  161. ;or greater than 199 the point is not plotted.
  162.  
  163. no_div:        cmp    ax,0
  164.         jl    skip
  165.         cmp    ax,199
  166.         jg    skip
  167.  
  168.         call    put_point
  169.  
  170. skip:        sub    si,2        ;decrement data pointer to point
  171.                     ;at next array element
  172.         jmp    plot_loop    ;go back and do another
  173.  
  174. done:        pop    es
  175.         pop    bp
  176.         ret    12
  177. PLOT        endp
  178.  
  179. ;*************************************************************************
  180.  
  181. ;subroutines
  182.  
  183. ;"horiz" places a row of dots across the screen, placing a dot in every
  184. ;15th column.  The calling program must pass the desired row number
  185. ;(0-199) in ax.
  186.  
  187. horiz        proc near
  188.         mov    cx,630        ;starting column number
  189.  
  190. H1:        call    put_point
  191.  
  192.         sub    cx,15        ;decrement column number
  193.         cmp    cx,0        ;if cx>=0 do another
  194.         jge    H1
  195.         ret
  196. horiz        endp
  197.  
  198. ;*******************************************
  199.  
  200. ;"vert" places a column of dots down the screen, placing a dot in every
  201. ;6th row.  The calling program must pass the desired column number
  202. ;(0-639) in cx
  203.  
  204. vert        proc    near
  205.         mov    ax,198        ;starting row number
  206.  
  207. V1:        call    put_point
  208.  
  209.         sub    ax,6        ;decrement row number
  210.         cmp    ax,0        ;if ax>=0 do another
  211.         jge    V1
  212.         ret
  213. vert        endp
  214.  
  215. ;**************************************************************    
  216.  
  217. ;This subroutine puts a point on the high resolution graphics screen.
  218. ;Enter with Y (0-199) in ax, X (0-639) in cx, and es pointing to
  219. ;video ram (B800).  All registers are preserved.
  220.  
  221. put_point    proc    near
  222.  
  223.         push    si        ;save all registers used
  224.         push    bx
  225.         push    cx
  226.         push    ax
  227.         push    cx        ;save cx and ax again for
  228.         push    ax        ;program use
  229.  
  230.         and    ax,0FEh        ;strip off odd/even bit of Y
  231.         sal    ax,1
  232.         sal    ax,1
  233.         sal    ax,1        ;ax=ax times 8
  234.         mov    bx,ax
  235.         sal    ax,1
  236.         sal    ax,1        ;ax=ax times 32
  237.         add    ax,bx        ;ax=ax times 40
  238.         pop    bx        ;now bx has original ax
  239.         sar    bx,1        ;low bit into CF
  240.         jnb    even        ;if low bit was 0, y is even
  241.         add    ax,2000H    ;if odd, adjust for video odd
  242.                     ;row addresses
  243.  
  244. ; now ax has 40*Y if Y is even and 40*Y+2000H if Y is odd - this is the
  245. ;address of the leftmost video byte in the row in which this point is
  246. ;to be put. We now must add (X/8) to get actual address
  247.  
  248. even:        sar    cx,1
  249.         sar    cx,1
  250.         sar    cx,1        ;cx=x/8
  251.         add    ax,cx        ;now ax has final address
  252.         mov    si,ax
  253.         pop    cx        ;now cx has original x 
  254.  
  255. ;now to determine the bit to set
  256.  
  257.         and    cx,0007H    ;now bx has x mod 8
  258.         mov    al,80H        ;start with mask 10000000B
  259.         shr    al,cl        ;shift bit right to correct
  260.                     ;position
  261.         or    al,es:[si]    ;put in any other bits that
  262.                     ;are already set in that
  263.                     ;byte of video ram
  264.         mov    es:[si],al    ;put it back in video ram
  265.  
  266.         pop    ax
  267.         pop    cx
  268.         pop    bx
  269.         pop    si
  270.         ret
  271.  
  272. put_point    endp
  273.  
  274. ;**********************************************************************
  275.  
  276. cseg        ends
  277.         end
  278.  
  279.