home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / screen / stest / video.asm < prev    next >
Encoding:
Assembly Source File  |  1992-12-22  |  6.4 KB  |  265 lines

  1.  
  2.  
  3.     LOCALS            ;; Enable local labels
  4.  
  5.         IDEAL                   ;; Use Turbo Assembler's IDEAL mode
  6.     JUMPS
  7.  
  8.     ; Driver load and unload calls.  Requires that the application provide
  9.     ; memory allocation functions and access to DOSCALLS.OBJ.
  10.  
  11. SMALL_MODEL    equ    0   ;: True if declaring C procedures as near.
  12.             ; It is false here because all procedures are
  13.             ; far, so that you can link any memory model
  14.             ; to theme. (They are prototyped as well.)
  15.  
  16.  
  17.         INCLUDE "PROLOGUE.MAC"          ;; common prologue
  18.     INCLUDE "386.MAC"               ;. include 32 bit optimization macro.
  19.  
  20.  
  21. SEGMENT  _TEXT BYTE PUBLIC 'CODE'               ;; Set up _TEXT segment
  22.         ENDS
  23.  
  24.     ASSUME    CS: _TEXT, DS: _TEXT, SS: NOTHING, ES: NOTHING
  25.  
  26.  
  27. SEGMENT _TEXT
  28.  
  29. Macro    CPROC    name        ; Macro to establish a C callable procedure.
  30.     public    _&name
  31. IF    SMALL_MODEL
  32. Proc    _&name    near
  33. ELSE
  34. Proc    _&name    far
  35. ENDIF
  36.     endm
  37.  
  38.  
  39. CPROC    VidOn
  40.     mov    ax,13h
  41.     int    10h
  42.     ret
  43.     endp
  44.  
  45. CPROC    VidOff
  46.     mov    ax,03
  47.     int    10h
  48.     ret
  49.     endp
  50.  
  51. CPROC    PutBlit
  52.     ARG    BLIT:DWORD,XLOC:WORD,YLOC:WORD
  53.     PENTER    0
  54.     PushCREGS
  55.  
  56.     mov    ax,[YLOC]
  57.     mov    bx,320        ; 320 pixels per scan line.
  58.     mul    bx        ; Do multiply.
  59.     add    ax,[XLOC]    ; plus xlocation, makes dest address.
  60.     mov    di,ax        ; Place into di, dest screen address.
  61.  
  62.     lds    si,[BLIT]
  63.     mov    ax,0A000h    ; destination screen address.
  64.     mov    es,ax        ; into ES
  65.     CLODSW             ; widht of animation.
  66.     mov    cx,ax        ; Into cX
  67.     CLODSW             ; height of animation.
  68.     mov    dx,ax        ; Into dx.
  69. @@PERL: push    di        ; Save dest screen addresss.
  70.     push    cx        ; Save width.
  71.     RepMovsb
  72.     pop    cx
  73.     pop    di
  74.     add    di,320        ; Next scan line.
  75.     dec    dx        ; Less height.
  76.     jnz    @@PERL        ; send for whole height out.
  77.  
  78.  
  79.     PopCREGS
  80.     PLEAVE
  81.     ret
  82.     endp
  83.  
  84. FULLSIZE    equ    256
  85.  
  86. ScaleTable    dw    320 dup(?)    ; Scaling table.
  87.  
  88. CPROC    PutBlitSize
  89.     ARG    BLIT:DWORD,XLOC:WORD,YLOC:WORD,SCALE:WORD
  90.     LOCAL    OWID:WORD,OHIT:WORD,WID:WORD,BASE:WORD = LocalSpace
  91.     PENTER    LocalSpace
  92.     PushCREGS
  93.  
  94.     mov    ax,[SCALE]
  95.     or    ax,ax
  96.     jz    @@OUT
  97.     js    @@OUT
  98.     cmp    ax,FULLSIZE
  99.     jl    @@SIZEIT        ; Scale it.
  100. @@FULL: push    [YLOC]
  101.     push    [XLOC]
  102.     push    [word BLIT+2]
  103.     push    [word BLIT]
  104.     call    _PutBlit
  105.     add    sp,8        ; balance stack from call
  106.     mov    ax,1
  107.     jmp    @@OUT2
  108. @@SIZEIT:
  109.     lds    si,[BLIT]    ; Get blit image.
  110.     lodsw            ; Get width.
  111.     mov    [WID],ax
  112.     mul    [SCALE]     ; Times scaling size.
  113.     shrd    ax,dx,8     ; /256.
  114.     jz    @@OUT        ; If output width is zero pixels! leave.
  115.     mov    bx,ax        ; Save output width into BX
  116.     mov    [OWID],ax    ; Save output width in local variable.
  117.     lodsw            ; Get height.
  118.     mul    [SCALE]     ; Times scaling size.
  119.     shrd    ax,dx,8     ; Divide by 256.
  120.     jz    @@OUT        ; If ouput height is zero! leave.
  121.     mov    [OHIT],ax    ; Output height.
  122.     mov    cx,ax        ; Into CX.
  123.     cmp    bx,cx        ; Is output width>output height?
  124.     jle    @@NOT        ; no, use output height to build table.
  125.     mov    cx,bx        ; Build table with output height.
  126. @@NOT:
  127.     mov    dx,1
  128.     xor    ax,ax        ; Start with 256*256.
  129.     mov    bx,[SCALE]
  130.     cmp    bx,1
  131.     je    @@ONE        ; Special case divide by 1.
  132.     div    bx
  133. @@ONE:    mov    si,ax        ; Scaling increment into SI
  134.     push    cs
  135.     pop    ds        ; DS=CS.
  136.     lea    bx,[ScaleTable] ; Point to scaling table.
  137.     xor    ax,ax
  138.     mov    dx,ax        ; Zero out accumulator.
  139. @@TAB:    mov    [byte bx],ah    ; Store low byte integer result.
  140.     mov    [byte bx+1],dl     ; Store high byte integer result.
  141.     add    ax,si        ; Add increment with fraction.
  142.     adc    dx,0
  143.     add    bx,2
  144.     CLOOP    @@TAB        ; Complete building the table.
  145.  
  146. ;; Ready to scale and send this puppy out!
  147.  
  148.     mov    ax,[YLOC]
  149.     mov    bx,320        ; 320 pixels per scan line.
  150.     mul    bx        ; Do multiply.
  151.     add    ax,[XLOC]    ; plus xlocation, makes dest address.
  152.     mov    di,ax        ; Place into di, dest screen address.
  153.     lds    si,[BLIT]
  154.     add    si,4
  155.     mov    [BASE],si    ; Base location of source blit.
  156.     mov    ax,0A000h    ; destination screen address.
  157.     mov    es,ax        ; into ES
  158.  
  159.     xor    eax,eax     ; Zero out EAX
  160.     mov    ebx,eax     ; Zero out EBX
  161.     mov    edx,eax     ; Zero out EDX
  162.     mov    esi,eax     ; Zero out ESI
  163.  
  164.     lea    dx,[ScaleTable] ; Y scaling
  165.     shr    dx,1        ; /2
  166.  
  167.  
  168. @@YLOOP:
  169.     push    di
  170.  
  171.     mov    cx,[OWID]
  172.     mov    ax,[WID]    ; width of image data.
  173.     mov    bx,dx        ; Save DX REGISTER!!!
  174.     mul    [word cs:edx*2]      ; Current Y index into scaling tabl.
  175.     mov    dx,bx        ; Restore DX register.
  176.     lea    bx,[ScaleTable] ; Base address of scaling table /2 for auto integer scaling.
  177.     shr    bx,1        ; /2 for 32 bit scaler addressing.
  178.     add    ax,[BASE]    ; Base location!
  179.     mov    si,ax        ; Base location this line!
  180. ;; Register usage in inner X-scaling loop.
  181. ;; AX is used to hold current X scale index.
  182. ;; AL is used to hold the pixel from the source blit image.
  183. ;; BX is contains the current address inside the scaling table.
  184. ;; CX output width, loop counter.
  185. ;; DS:SI point to the base address in the blit for this horizontal line.
  186. ;; ES:DI is the destination vga screen address.
  187. @@XLOOP:
  188.     mov    ax,[cs:ebx*2]    ; Get the index from the scaling table.
  189.     inc    bx        ; next table entry.
  190.     mov    al,[ds:esi+eax] ; Translate it.
  191.     CSTOSB            ; store the result.
  192.     CLOOP    @@XLOOP
  193.  
  194.     pop    di
  195.     add    di,320        ; Next line.
  196.     inc    dx        ; Advance Y scale index.
  197.     dec    [OHIT]        ; Decrement output height.
  198.     jnz    @@YLOOP     ; Do next y=line.
  199.  
  200.     mov    ax,1
  201.     jmp short @@OUT2        ; Exit.
  202.  
  203.  
  204. @@OUT:    xor    ax,ax        ; Return, we didn't draw it return code.
  205. @@OUT2:             ; return with we did draw it return code.
  206.     PopCREGS
  207.     PLEAVE
  208.     ret
  209.     endp
  210.  
  211. pal     db      768 dup(?)      ; Working palette area.
  212.  
  213. CPROC    VGAP
  214.     ARG    PSEG:DWORD,START:WORD,ENTRIES:WORD
  215.     PENTER    0
  216.     PushCREGS
  217.  
  218.     push    cs
  219.     pop    es
  220.     lds    si,[PSEG]
  221.     lea    di,[pal]
  222.     mov    cx,[ENTRIES]
  223.     shl    cx,1
  224.     add    cx,[ENTRIES]    ; Times 3
  225. @@MP:    CLODSB
  226.     shr    al,1
  227.     shr    al,1        ; 5 bit rgb format.
  228.     CSTOSB
  229.     CLOOP     @@MP
  230.  
  231. ;; VGA set palette code.
  232. ;; bx -> color offset.
  233. ;; cx -> number of colors to set.
  234. ;; DS:SI -> points to VGA 5 bit R/G/B colors.
  235.     mov    ax,cs
  236.     mov    ds,ax            ; DS=CS
  237.     lea    si,[pal]        ; get starting addr in SI
  238.     mov    cx,[ENTRIES]
  239.     mov    bx,[START]
  240.     mov    dx,03dah        ; wait for no retrace
  241. @@rt1:    in    al,dx            ;  ...
  242.     and    al,8            ; this bit is high during a retrace
  243.     jnz    @@rt1            ;  so loop until it goes low
  244. @@rt2:    in    al,dx            ; wait for no retrace
  245.     and    al,8            ; this bit is high during a retrace
  246.     jz    @@rt2            ;  so loop until it goes high
  247.     mov    dx,03c8h        ; set up for a blitz-write
  248.     mov    ax,bx            ; from this register
  249.     cli                ; critical section:  no ints
  250.     out    dx,al            ; starting register
  251.     inc    dx            ; set up to update colors
  252.     mov    ax,cx            ; triple the value in CX
  253.     add    cx,ax            ;  ...
  254.     add    cx,ax            ;  ...
  255.     rep    outsb            ; whap!  Zango!  They're updated!
  256.     sti                ; end of critical section
  257.  
  258.     PopCREGS
  259.     PLEAVE
  260.     ret
  261.     endp
  262.  
  263.     ends
  264.     end
  265.