home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / lenssrc / lens.asm next >
Assembly Source File  |  1993-12-01  |  7KB  |  282 lines

  1. ideal
  2. locals
  3. jumps
  4. model huge
  5. stack 100h
  6.  
  7. segment Code
  8.         assume cs:Code
  9. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  10. include "lens.inc"
  11. SourceBuffer    db  LensDiameter*LensDiameter dup(?)
  12. TargetBuffer    db  LensDiameter*LensDiameter dup(?)
  13. NoMouse         db  'No mouse installed.',0Dh,0Ah,'$'
  14. TGA_filename    db  'LENS.TGA',0
  15. TGA_handle      dw  ?
  16. PositionX       dw  ?
  17. PositionY       dw  ?
  18. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  19. proc    Start
  20.         ;check to make sure a mouse is present
  21.         mov ax,0
  22.         int 33h
  23.         cmp ax,0
  24.         jnz @@GotMouse
  25.         mov ah,9
  26.         push cs
  27.         pop ds
  28.         mov dx,offset NoMouse
  29.         int 21h
  30.         mov ax,4C00h
  31.         int 21h
  32.  
  33. @@GotMouse:
  34.         ;switch over to graphics mode
  35.         mov ax,0013h
  36.         int 10h
  37.  
  38.         ;define the limits of the mouse
  39.         mov ax,0007h
  40.         mov cx,0
  41.         mov dx,(320-LensDiameter)*2-1
  42.         int 33h
  43.         mov ax,0008h
  44.         mov cx,0
  45.         mov dx,(200-LensDiameter)-1
  46.         int 33h
  47.  
  48.         ;find out the current location of the mouse and save it
  49.         mov ax,3
  50.         int 33h
  51.         mov [cs:PositionX],cx
  52.         mov [cs:PositionY],dx
  53.  
  54.         ;load in a pretty picture to look at
  55.         call LoadTGA
  56.  
  57. @@MainLoop:
  58.         ;read in the portion of the screen we're going to work on
  59.         call FetchBuffer
  60.  
  61.         ;put it under the lens
  62.         call MorphBuffer
  63.  
  64.         ;display the new buffer
  65.         call DisplayNewBuffer
  66.  
  67. @@WaitForMovement:
  68.         ;read in the mouse position, if it's changed, then reupdate
  69.         mov ax,3
  70.         int 33h
  71.         shr cx,1
  72.         cmp [cs:PositionX],cx
  73.         jnz @@ItMoved
  74.         cmp [cs:PositionY],dx
  75.         jnz @@ItMoved
  76.  
  77.         ;get stdio.  If something's been pressed, quit
  78.         mov ah,6
  79.         mov dl,0FFh
  80.         int 21h
  81.         jz @@WaitForMovement
  82.         jmp @@Quit
  83.  
  84. @@ItMoved:
  85.         push cx dx
  86.  
  87.         ;restore what was originally on the screen
  88.         call RestoreBuffer
  89.  
  90.         pop dx cx
  91.  
  92.         ;save the new position
  93.         mov [cs:PositionX],cx
  94.         mov [cS:PositionY],dx
  95.         jmp @@MainLoop
  96.  
  97. @@Quit:
  98.         ;change back to text mode and quit
  99.         mov ax,0003h
  100.         int 10h
  101.         mov ax,4C00h
  102.         int 21h
  103. endp    Start
  104. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  105. ;read in the portion of the screen that we're working on into a buffer
  106. proc    FetchBuffer
  107.         mov ax,0A000h
  108.         mov ds,ax
  109.         push cs
  110.         pop es
  111.         mov si,[cs:PositionY]
  112.         mov ax,320
  113.         mul si
  114.         mov si,ax
  115.         add si,[cs:PositionX]
  116.         mov di,offset SourceBuffer
  117.         mov cx,LensDiameter
  118. @@CopyRow:
  119.         push si cx
  120.         mov cx,LensDiameter
  121.         cld
  122.         rep movsb
  123.         pop cx si
  124.         add si,320
  125.         dec cx
  126.         jnz @@CopyRow
  127.  
  128.         ret
  129. endp    FetchBuffer
  130. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  131. ;put the portion of the screen that we've captured under the lens
  132. proc    MorphBuffer
  133.         mov ax,cs
  134.         mov ds,ax
  135.         mov es,ax
  136.         mov si,offset Lens
  137.         mov di,offset TargetBuffer
  138.         mov cx,LensDiameter*LensDiameter
  139.         cld
  140.         xor bh,bh
  141. @@DoPoint:
  142.         lodsw
  143.         mov bx,ax
  144.         mov al,[byte offset SourceBuffer+bx]
  145.         stosb
  146.         inc dx
  147.         dec cx
  148.         jnz @@DoPoint
  149.  
  150.         ret
  151. endp    MorphBuffer
  152. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  153. ;display the new calculated buffer
  154. proc    DisplayNewBuffer
  155.         mov ax,0A000h
  156.         mov es,ax
  157.         push cs
  158.         pop ds
  159.         mov di,[cs:PositionY]
  160.         mov ax,320
  161.         mul di
  162.         mov di,ax
  163.         add di,[cs:PositionX]
  164.         mov si,offset TargetBuffer
  165.         mov cx,LensDiameter
  166. @@CopyRow:
  167.         push di cx
  168.         mov cx,LensDiameter
  169.         cld
  170.         rep movsb
  171.         pop cx di
  172.         add di,320
  173.         dec cx
  174.         jnz @@CopyRow
  175.  
  176.         ret
  177. endp    DisplayNewBuffer
  178. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  179. ;restore the unmagnified portion of the image on screen
  180. proc    RestoreBuffer
  181.         mov ax,0A000h
  182.         mov es,ax
  183.         push cs
  184.         pop ds
  185.         mov di,[cs:PositionY]
  186.         mov ax,320
  187.         mul di
  188.         mov di,ax
  189.         add di,[cs:PositionX]
  190.         mov si,offset SourceBuffer
  191.         mov cx,LensDiameter
  192. @@CopyRow:
  193.         push di cx
  194.         mov cx,LensDiameter
  195.         cld
  196.         rep movsb
  197.         pop cx di
  198.         add di,320
  199.         dec cx
  200.         jnz @@CopyRow
  201.  
  202.         ret
  203. endp    RestoreBuffer
  204. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  205. ;load a TGA and display it
  206. proc    LoadTGA
  207.         push cs
  208.         pop ds
  209.         mov ax,3D00h
  210.         mov dx,offset TGA_filename
  211.         int 21h
  212.         jc @@Quit
  213.         mov [cs:TGA_handle],ax
  214.  
  215.         mov ah,3Fh
  216.         mov bx,[cs:TGA_handle]
  217.         mov cx,18
  218.         mov dx,offset ReadBuffer
  219.         int 21h
  220.         jc @@Quit
  221.         
  222.         mov ah,3Fh
  223.         mov bx,[cs:TGA_handle]
  224.         mov cx,768
  225.         mov dx,offset ReadBuffer
  226.         int 21h
  227.         jc @@Quit
  228.  
  229.         mov cx,256
  230.         push cs
  231.         pop ds
  232.         push cs
  233.         pop es
  234.         mov si,offset ReadBuffer
  235.         mov di,offset ReadBuffer
  236.         cld
  237. @@FixPal:
  238.         lodsb           ;\
  239.         shr al,2        ; > load in Blue component
  240.         mov ah,al       ;/
  241.         lodsb           ;\
  242.         shr al,2        ; > load in Green component
  243.         mov bh,al       ;/
  244.         lodsb           ;\ load in Red component
  245.         shr al,2        ;/
  246.         stosb           ;write out Red
  247.         mov al,bh       ;\ write out Green
  248.         stosb           ;/
  249.         mov al,ah       ;\ write out Blue
  250.         stosb           ;/
  251.         dec cx
  252.         jnz @@FixPal
  253.  
  254.         mov ax,1012h
  255.         mov bx,0
  256.         mov cx,256
  257.         push cs
  258.         pop es
  259.         mov dx,offset ReadBuffer
  260.         int 10h
  261.  
  262.         mov ah,3Fh
  263.         mov bx,[cs:TGA_handle]
  264.         mov cx,64000
  265.         mov dx,0A000h
  266.         mov ds,dx
  267.         mov dx,0
  268.         int 21h
  269.         jc @@Quit
  270.  
  271.         mov ah,3Eh
  272.         mov bx,[cs:TGA_handle]
  273.         int 21h
  274.  
  275. @@Quit:
  276.         ret
  277. endp    LoadTGA
  278. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  279. label   ReadBuffer byte
  280. ends    Code
  281.         end     Start
  282.