home *** CD-ROM | disk | FTP | other *** search
-
-
- LOCALS ;; Enable local labels
-
- IDEAL ;; Use Turbo Assembler's IDEAL mode
- JUMPS
-
- ; Driver load and unload calls. Requires that the application provide
- ; memory allocation functions and access to DOSCALLS.OBJ.
-
- SMALL_MODEL equ 0 ;: True if declaring C procedures as near.
- ; It is false here because all procedures are
- ; far, so that you can link any memory model
- ; to theme. (They are prototyped as well.)
-
-
- INCLUDE "PROLOGUE.MAC" ;; common prologue
- INCLUDE "386.MAC" ;. include 32 bit optimization macro.
-
-
- SEGMENT _TEXT BYTE PUBLIC 'CODE' ;; Set up _TEXT segment
- ENDS
-
- ASSUME CS: _TEXT, DS: _TEXT, SS: NOTHING, ES: NOTHING
-
-
- SEGMENT _TEXT
-
- Macro CPROC name ; Macro to establish a C callable procedure.
- public _&name
- IF SMALL_MODEL
- Proc _&name near
- ELSE
- Proc _&name far
- ENDIF
- endm
-
-
- CPROC VidOn
- mov ax,13h
- int 10h
- ret
- endp
-
- CPROC VidOff
- mov ax,03
- int 10h
- ret
- endp
-
- CPROC PutBlit
- ARG BLIT:DWORD,XLOC:WORD,YLOC:WORD
- PENTER 0
- PushCREGS
-
- mov ax,[YLOC]
- mov bx,320 ; 320 pixels per scan line.
- mul bx ; Do multiply.
- add ax,[XLOC] ; plus xlocation, makes dest address.
- mov di,ax ; Place into di, dest screen address.
-
- lds si,[BLIT]
- mov ax,0A000h ; destination screen address.
- mov es,ax ; into ES
- CLODSW ; widht of animation.
- mov cx,ax ; Into cX
- CLODSW ; height of animation.
- mov dx,ax ; Into dx.
- @@PERL: push di ; Save dest screen addresss.
- push cx ; Save width.
- RepMovsb
- pop cx
- pop di
- add di,320 ; Next scan line.
- dec dx ; Less height.
- jnz @@PERL ; send for whole height out.
-
-
- PopCREGS
- PLEAVE
- ret
- endp
-
- FULLSIZE equ 256
-
- ScaleTable dw 320 dup(?) ; Scaling table.
-
- CPROC PutBlitSize
- ARG BLIT:DWORD,XLOC:WORD,YLOC:WORD,SCALE:WORD
- LOCAL OWID:WORD,OHIT:WORD,WID:WORD,BASE:WORD = LocalSpace
- PENTER LocalSpace
- PushCREGS
-
- mov ax,[SCALE]
- or ax,ax
- jz @@OUT
- js @@OUT
- cmp ax,FULLSIZE
- jl @@SIZEIT ; Scale it.
- @@FULL: push [YLOC]
- push [XLOC]
- push [word BLIT+2]
- push [word BLIT]
- call _PutBlit
- add sp,8 ; balance stack from call
- mov ax,1
- jmp @@OUT2
- @@SIZEIT:
- lds si,[BLIT] ; Get blit image.
- lodsw ; Get width.
- mov [WID],ax
- mul [SCALE] ; Times scaling size.
- shrd ax,dx,8 ; /256.
- jz @@OUT ; If output width is zero pixels! leave.
- mov bx,ax ; Save output width into BX
- mov [OWID],ax ; Save output width in local variable.
- lodsw ; Get height.
- mul [SCALE] ; Times scaling size.
- shrd ax,dx,8 ; Divide by 256.
- jz @@OUT ; If ouput height is zero! leave.
- mov [OHIT],ax ; Output height.
- mov cx,ax ; Into CX.
- cmp bx,cx ; Is output width>output height?
- jle @@NOT ; no, use output height to build table.
- mov cx,bx ; Build table with output height.
- @@NOT:
- mov dx,1
- xor ax,ax ; Start with 256*256.
- mov bx,[SCALE]
- cmp bx,1
- je @@ONE ; Special case divide by 1.
- div bx
- @@ONE: mov si,ax ; Scaling increment into SI
- push cs
- pop ds ; DS=CS.
- lea bx,[ScaleTable] ; Point to scaling table.
- xor ax,ax
- mov dx,ax ; Zero out accumulator.
- @@TAB: mov [byte bx],ah ; Store low byte integer result.
- mov [byte bx+1],dl ; Store high byte integer result.
- add ax,si ; Add increment with fraction.
- adc dx,0
- add bx,2
- CLOOP @@TAB ; Complete building the table.
-
- ;; Ready to scale and send this puppy out!
-
- mov ax,[YLOC]
- mov bx,320 ; 320 pixels per scan line.
- mul bx ; Do multiply.
- add ax,[XLOC] ; plus xlocation, makes dest address.
- mov di,ax ; Place into di, dest screen address.
- lds si,[BLIT]
- add si,4
- mov [BASE],si ; Base location of source blit.
- mov ax,0A000h ; destination screen address.
- mov es,ax ; into ES
-
- xor eax,eax ; Zero out EAX
- mov ebx,eax ; Zero out EBX
- mov edx,eax ; Zero out EDX
- mov esi,eax ; Zero out ESI
-
- lea dx,[ScaleTable] ; Y scaling
- shr dx,1 ; /2
-
-
- @@YLOOP:
- push di
-
- mov cx,[OWID]
- mov ax,[WID] ; width of image data.
- mov bx,dx ; Save DX REGISTER!!!
- mul [word cs:edx*2] ; Current Y index into scaling tabl.
- mov dx,bx ; Restore DX register.
- lea bx,[ScaleTable] ; Base address of scaling table /2 for auto integer scaling.
- shr bx,1 ; /2 for 32 bit scaler addressing.
- add ax,[BASE] ; Base location!
- mov si,ax ; Base location this line!
- ;; Register usage in inner X-scaling loop.
- ;; AX is used to hold current X scale index.
- ;; AL is used to hold the pixel from the source blit image.
- ;; BX is contains the current address inside the scaling table.
- ;; CX output width, loop counter.
- ;; DS:SI point to the base address in the blit for this horizontal line.
- ;; ES:DI is the destination vga screen address.
- @@XLOOP:
- mov ax,[cs:ebx*2] ; Get the index from the scaling table.
- inc bx ; next table entry.
- mov al,[ds:esi+eax] ; Translate it.
- CSTOSB ; store the result.
- CLOOP @@XLOOP
-
- pop di
- add di,320 ; Next line.
- inc dx ; Advance Y scale index.
- dec [OHIT] ; Decrement output height.
- jnz @@YLOOP ; Do next y=line.
-
- mov ax,1
- jmp short @@OUT2 ; Exit.
-
-
- @@OUT: xor ax,ax ; Return, we didn't draw it return code.
- @@OUT2: ; return with we did draw it return code.
- PopCREGS
- PLEAVE
- ret
- endp
-
- pal db 768 dup(?) ; Working palette area.
-
- CPROC VGAP
- ARG PSEG:DWORD,START:WORD,ENTRIES:WORD
- PENTER 0
- PushCREGS
-
- push cs
- pop es
- lds si,[PSEG]
- lea di,[pal]
- mov cx,[ENTRIES]
- shl cx,1
- add cx,[ENTRIES] ; Times 3
- @@MP: CLODSB
- shr al,1
- shr al,1 ; 5 bit rgb format.
- CSTOSB
- CLOOP @@MP
-
- ;; VGA set palette code.
- ;; bx -> color offset.
- ;; cx -> number of colors to set.
- ;; DS:SI -> points to VGA 5 bit R/G/B colors.
- mov ax,cs
- mov ds,ax ; DS=CS
- lea si,[pal] ; get starting addr in SI
- mov cx,[ENTRIES]
- mov bx,[START]
- mov dx,03dah ; wait for no retrace
- @@rt1: in al,dx ; ...
- and al,8 ; this bit is high during a retrace
- jnz @@rt1 ; so loop until it goes low
- @@rt2: in al,dx ; wait for no retrace
- and al,8 ; this bit is high during a retrace
- jz @@rt2 ; so loop until it goes high
- mov dx,03c8h ; set up for a blitz-write
- mov ax,bx ; from this register
- cli ; critical section: no ints
- out dx,al ; starting register
- inc dx ; set up to update colors
- mov ax,cx ; triple the value in CX
- add cx,ax ; ...
- add cx,ax ; ...
- rep outsb ; whap! Zango! They're updated!
- sti ; end of critical section
-
- PopCREGS
- PLEAVE
- ret
- endp
-
- ends
- end
-