home *** CD-ROM | disk | FTP | other *** search
/ MS DOS Archives 1 / MS-DOS_Archives_Volume_One_Walnut_Creek.iso / msdos / graphics / grafxlib.arc / CGAGRAFA.ASM < prev    next >
Assembly Source File  |  1987-08-31  |  3KB  |  183 lines

  1. ;
  2. ; grafix --- cgagrafa.asm
  3. ;
  4. ; stuff to plot points fast in 8086 assembler (BLEECH!!!)
  5. ;
  6. ; Written 4/87 by Scott Snyder (ssnyder@romeo.caltech.edu or @citromeo.bitnet)
  7. ;
  8. ; Modified 5/29/87 by sss to allow for different memory models
  9. ;
  10.  
  11.     title    cgagrafa
  12.  
  13. include macros.ah
  14.  
  15.     df CGA_point
  16.     df CGA_write_pix
  17.  
  18. sseg
  19. endss
  20.  
  21. g_oddoff equ    02000h
  22. g_linsiz equ    80
  23.  
  24. dseg
  25.  
  26.     ex g_drawbuf,     dword
  27.     ex g_pixbyte,     word
  28.     ex g_bitpix,      word
  29.     ex g_colormask,   byte
  30.     ex g_cmask_tbl,   byte
  31.     ex g_hicolormask, byte
  32.     ex g_xor,         word
  33.     ex g_xcliplo,     word
  34.     ex g_xcliphi,     word
  35.     ex g_ycliplo,     word
  36.     ex g_ycliphi,     word
  37.  
  38. endds
  39.  
  40. cseg _cgagrafa
  41.  
  42. ; plot a point. ax = y; bl = c; cx = x;
  43.  
  44. pBegin    plot
  45.  
  46.     les    si, g_drawbuf        ; get address of buffer
  47.     sar    ax, 1            ; y /= 2
  48.     jnc    p1            ; add in offset if it was odd
  49.     add    si, g_oddoff
  50. p1:    mov    dx, g_linsiz        ; y * g_linsiz
  51.     mul    dx
  52.     add    si, ax            ; add to offset
  53.     mov    ax, cx            ; x to AC (ohhh... what symmetry!)
  54.     mov    dx, 0
  55.     div    g_pixbyte
  56.     add    si, ax            ; add quotient to offset (now complete)
  57.     and    bl, g_colormask        ; get cmask
  58.     mov    bl, g_cmask_tbl[bx]
  59.     mov    cx, g_bitpix        ; only works for bitpix = 0 or 1!
  60.     dec    cx
  61.     shl    dx, cl            ; dx = mask shift count
  62.     mov    cx, dx
  63.     mov    dl, g_hicolormask    ; get mask
  64.     shr    dl, cl            ; shift it
  65.     and    bx, dx            ; bx = cmask & mask
  66.     mov    al, es:[si]        ; get image byte
  67.     cmp    g_xor, 0        ; xor mode?
  68.     jne    p2
  69.     not    dl            ; no - (*ptr & ~mask) | (cmask & mask)
  70.     and    al, dl
  71.     or    al, bl
  72.     jmp    p3
  73. p2:    xor    al, bl            ; yes - *ptr ^ (cmask & mask)
  74. p3:    mov    es:[si], al        ; done!
  75.     ret
  76.  
  77. pEnd    plot
  78.  
  79. ;
  80. ; C interface for point plotter
  81. ;
  82. ; CGA_point(x, y, c)
  83. ;
  84.  
  85. pBegin    CGA_point
  86.     push    bp
  87.     mov    bp, sp
  88.     push    si
  89.     push    di
  90.  
  91.     mov    ax, [bp+argbase+2]
  92.     mov    bx, [bp+argbase+4]
  93.     mov    cx, [bp+argbase]
  94.     call    plot
  95.  
  96.     pop    di
  97.     pop    si
  98.     mov    sp, bp
  99.     pop    bp
  100.     ret
  101.  
  102. pEnd    CGA_point
  103.  
  104. ;
  105. ; write for pixels for circle drawing
  106. ;
  107. ; void CGA_write_pix(x1, y1, x2, y2, c)
  108. ;
  109.  
  110. pBegin    CGA_write_pix
  111.  
  112.     push    bp
  113.     mov    bp, sp
  114.     push    si
  115.     push    di
  116.  
  117.     mov    bx, [bp+argbase+8]    ; bx = c (for plot)
  118.     mov    cx, [bp+argbase]    ; cx = x1
  119.     cmp    cx, g_xcliplo        ; check for clipping
  120.     jb    w2
  121.     cmp    cx, g_xcliphi
  122.     ja    w2
  123.  
  124.     mov    ax, [bp+argbase+2]    ; ax = y1
  125.     cmp    ax, g_ycliplo        ; do clipping
  126.     jb    w1
  127.     cmp    ax, g_ycliphi
  128.     ja    w1
  129.  
  130.     push    bx            ; plot (x1, y1)
  131.     push    cx
  132.     call    plot
  133.     pop    cx
  134.     pop    bx
  135.  
  136. w1:    mov    ax, [bp+argbase+6]    ; ax = y2
  137.     cmp    ax, g_ycliplo
  138.     jb    w2
  139.     cmp    ax, g_ycliphi
  140.     ja    w2
  141.  
  142.     push    bx            ; plot (x1, y2)
  143.     call    plot
  144.     pop    bx
  145.  
  146. w2:    mov    cx, [bp+argbase+4]    ; cx = x2
  147.     cmp    cx, g_xcliplo
  148.     jb    w4
  149.     cmp    cx, g_xcliphi
  150.     ja    w4
  151.  
  152.     mov    ax, [bp+argbase+2]    ; ax = y1
  153.     cmp    ax, g_ycliplo        ; do clipping
  154.     jb    w3
  155.     cmp    ax, g_ycliphi
  156.     ja    w3
  157.  
  158.     push    bx            ; plot (x2, y1)
  159.     push    cx
  160.     call    plot
  161.     pop    cx
  162.     pop    bx
  163.  
  164. w3:    mov    ax, [bp+argbase+6]    ; ax = y2
  165.     cmp    ax, g_ycliplo
  166.     jb    w4
  167.     cmp    ax, g_ycliphi
  168.     ja    w4
  169.  
  170.     call    plot            ; plot (x2, y2)
  171.  
  172. w4:    pop    di
  173.     pop    si
  174.     mov    sp, bp
  175.     pop    bp
  176.     ret
  177.  
  178. pEnd    CGA_write_pix
  179.  
  180. endcs    _cgagrafa
  181.  
  182. end
  183.