home *** CD-ROM | disk | FTP | other *** search
/ PC Underground / UNDERGROUND.ISO / graphic / bres.asm < prev    next >
Assembly Source File  |  1995-07-28  |  3KB  |  101 lines

  1. .286
  2. b equ byte ptr
  3. w equ word ptr
  4.  
  5. data segment
  6.   extrn vpage:word              ;current video page
  7. data ends
  8.  
  9. putpixel macro                  ;puts pixel at ax/bx
  10.   pusha
  11.   xchg ax,bx                    ;exchange x and y
  12.   push ax                       ;store y for later
  13.   mov cx,bx                     ;get x
  14.   and cx,3                      ;mask plane
  15.   mov ax,1                      ;and set corresp. bit
  16.   shl ax,cl
  17.   mov ah,2                      ;TS register 2
  18.   xchg ah,al
  19.   mov dx,3c4h
  20.   out dx,ax
  21.  
  22.   pop cx                        ;get y
  23.   mov ax,80d                    ;calculate row offset
  24.   mul cx
  25.   shr bx,2                      ;add column offset
  26.   add bx,ax
  27.   add bx,vpage                  ;write to current page
  28.   mov b es:[bx],3               ;and set color
  29.  
  30.   popa
  31. endm
  32.  
  33. code segment public
  34. assume cs:code,ds:data
  35.  
  36. public bline
  37. bline proc    near
  38. ;draws line from ax/bx to cx/dx
  39.   push bp
  40.   push ax                       ;store x0 and
  41.   push bx                       ;y0
  42.   mov bx,4340h                  ;prepare self modification
  43.   sub cx,ax                     ;calculate deltax
  44.   jns deltax_ok                 ;negative ?
  45.   neg cx                        ;yes, then reverse deltax sign
  46.   mov bl,48h                    ;and decrement ax instead of incrementing ax
  47. deltax_ok:
  48.   mov bp,sp                     ;addressing of y1 on the stack
  49.   sub dx,ss:[bp]                ;calculate deltay
  50.   jns deltay_ok                 ;negative ?
  51.   neg dx                        ;yes, then reverse deltay sign
  52.   mov bh,4bh                    ;and decrement bx instead of  incrementing bx
  53. deltay_ok:
  54.   mov si,dx                     ;deltay and
  55.   or si,cx                      ;deltax = 0 ?
  56.   jne ok
  57.   add sp,6                      ;then ax, bx and bp from stack and end
  58.   ret
  59. ok:
  60.   mov w cs:dist_pos,bx          ;write dec/inc ax/bx to destination
  61.   cmp cx,dx                     ;deltax >= deltay ?
  62.   jge deltax_great
  63.   xchg cx,dx                    ;no, then exchange deltax and deltay
  64.   mov bl,90h                    ;and increment ax noppen
  65.   jmp constants
  66. deltax_great:
  67.   mov bh,90h                    ;otherwise increment bx noppen
  68. constants:
  69.   mov w cs:dist_neg,bx          ;write dec/inc ax/bx to destination
  70.   shl dx,1                      ;define add_2
  71.   mov di,dx                     ;store in di
  72.   sub dx,cx                     ;define start-dist
  73.   mov bp,dx                     ;and store in bp
  74.   mov si,bp                     ;define add_1
  75.   sub si,cx                     ;and store in si
  76.   mov ax,0a000h                 ;load VGA segment
  77.   mov es,ax
  78.   pop bx                        ;retrieve stored values for x0 and y0
  79.   pop ax
  80. loop_p:
  81.   putpixel                      ;set pixel
  82.   or bp,bp                      ;dist positive ?
  83.   jns dist_pos
  84. dist_neg:
  85.   inc ax                        ;increment x (if necessary, self modification)
  86.   inc bx                        ;increment y (if necessary, self modification)
  87.   add bp,di                     ;update dist
  88.   loop loop_p                   ;next pixel
  89.   jmp finished                  ;finished
  90. dist_pos:
  91.   inc ax                        ;increment x (if necessary, self modification)
  92.   inc bx                        ;increment y (if necessary, self modification)
  93.   add bp,si                     ;update dist
  94.   loop loop_p                   ;next pixel
  95. finished:
  96.   pop bp
  97.   ret
  98. bline endp
  99. code ends
  100. end
  101.