home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1986 / 02 / plotdot.asm < prev    next >
Assembly Source File  |  1986-02-27  |  3KB  |  84 lines

  1. ;*************************************************************************
  2. ; PLOTDOT.OBJ   Library module for Microsoft C  (small model programs)
  3. ;               Copyright (C) 1985 by Dan Rollins
  4. ;
  5. ; Mid-resolution graphics pixel-plot function.
  6. ; Uses look-up tables for fastest operation.
  7. ; Permission is granted to use this for any purpose whatsoever.
  8. ;
  9. ; synopsis:
  10. ;  plotdot(x,y,color)
  11. ;    int x;            horizontal (0-319) not value-checked
  12. ;    int y;            vertical (0-199) not value-checked
  13. ;    int color;        color for dot (0 to 3)
  14.  
  15.  
  16. ;------- preamble for placing data into Microsoft C 'S model' static data area
  17. dgroup   group data
  18. data     segment word public 'data'
  19.  
  20. ;-------- lookup table for start of each graphics line
  21. ;-------- index is: (Y * 2)
  22. row_tbl   label word
  23.           addr = 0
  24.           rept 100
  25.            dw addr,addr+2000H    ;Y=0,1; 2,3; 4,5; etc
  26.            addr = addr+80
  27.           endm
  28.  
  29. ;-------- lookup table for mid-res pixel positions in relevent byte
  30. ;-------- index is: (X mod 4)
  31. mask_tbl  db 00111111b, 11001111b, 11110011b, 11111100b
  32.  
  33. ;-------- lookup table for color, according to position in byte
  34. ;-------- index is (COLOR * 4) + (X mod 4)
  35. color_tbl db 00000000b, 00000000b, 00000000b, 00000000b    ;color 0
  36.           db 01000000b, 00010000b, 00000100b, 00000001b    ;color 1
  37.           db 10000000b, 00100000b, 00001000b, 00000010b    ;color 2
  38.           db 11000000b, 00110000b, 00001100b, 00000011b    ;color 3
  39. data      ends
  40.  
  41. ;------- preamble for placing code into Microsoft C 'S model' program area
  42. pgroup   group prog
  43. prog     segment byte public 'prog'
  44.          assume cs:pgroup, ds:dgroup
  45.  
  46. public   plotdot
  47. plotdot  proc    near            ;SMALL MODEL ONLY
  48.          pop     si              ;fetch return addr /this technique is faster
  49.          pop     bx              ;fetch X ordinate  /than stack-relative access
  50.          pop     di              ;fetch Y ordinate
  51.          pop     cx              ;fetch color
  52.  
  53.          mov     dx,es           ;save current ES
  54.          mov     ax,0b800H
  55.          mov     es,ax           ;get set to write to video buffer
  56.  
  57.          shl     di,1            ;index into row address lookup table
  58.  
  59.          mov     di,row_tbl[di]  ;DI points to start of selected row
  60.  
  61.          mov     ax,bx           ;copy the X ordinate
  62.          shr     ax,1
  63.          shr     ax,1            ;divided by 4 is byte offset from start of row
  64.  
  65.          add     di,ax           ;DI points to byte to modify
  66.          mov     al,es:[di]      ;fetch current screen byte
  67.  
  68.          and     bx,3            ;get pixel-offset in byte (0,1,2, or 3)
  69.          and     al,mask_tbl[bx] ;mask a "hole" into the current byte
  70.  
  71. ;------- index into the color table
  72.          and     cx,3             ;make sure it's a valid color
  73.          shl     cx,1             ; COLOR * 2
  74.          shl     cx,1             ; COLOR * 4
  75.          add     bx,cx            ; index is (COLOR * 4) + (X mod 4)
  76.          or      al,color_tbl[bx] ;fill the "hole" with selected color
  77.  
  78.          mov     es:[di],al       ;place modified byte back into screen
  79.          mov     es,dx            ;restore caller's ES
  80.          jmp     si               ;artificial (quick) NEAR return to caller
  81. plotdot  endp
  82. prog     ends
  83.          end
  84.