home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
comm
/
ykh121.zip
/
YKHSRC.ZIP
/
GFXLIB.ASM
< prev
next >
Wrap
Assembly Source File
|
1993-04-18
|
16KB
|
870 lines
; 3C4h index 2 (r/W): Sequencer: Map Mask Register
; bit 0 Enable writes to plane 0 if set
; 1 Enable writes to plane 1 if set
; 2 Enable writes to plane 2 if set
; 3 Enable writes to plane 3 if set
;
; 3CEh index 4 (r/W): Graphics: Read Map Select Register
; bit 0-1 Number of the plane read Mode 0 will read from.
.286c
INT_10H MACRO
PUSH BP
INT 10H
POP BP
ENDM
INT_10HP MACRO
PUSH AX
PUSH BX
PUSH CX
PUSH DX
PUSH BP
PUSH DS
PUSH ES
PUSH SI
PUSH DI
INT 10H
POP DI
POP SI
POP ES
POP DS
POP BP
POP DX
POP CX
POP BX
POP AX
ENDM
VIDEOSEG EQU 0A000H
MAP_MASK EQU 3c4h
READ_MAP EQU 3ceh
MISC_OUT EQU 3c2h
CRTC_IDX EQU 3d4h
ADAPTER_CGA EQU 0
ADAPTER_EGA EQU 1
ADAPTER_VGA EQU 2
GFXLIB_ERROR_OPEN EQU 1 ;file not found
GFXLIB_ERROR_READ EQU 2 ;unexpected end of file
GFXLIB_ERROR_CARD EQU 3 ;inadequate video card
GFXLIB_ERROR_MODE EQU 4 ;unable to set requested mode
GFXLIB_TEXT segment byte public 'CODE'
GFXLIB_TEXT ends
DGROUP group _DATA,_BSS
assume cs:GFXLIB_TEXT,ds:DGROUP
_DATA segment word public 'DATA'
_DATA ends
_BSS segment word public 'BSS'
_BSS ends
GFXLIB_TEXT segment byte public 'CODE'
;
LAST_62: ;db (32*62) dup(0)
asciiseg dw ?
asciioffs dw ?
oldmode db ?
adapter db ?
;
;int far GFX_deinit();
;
_gfx_deinit proc far
xor ah,ah
mov al,cs:oldmode
INT_10HP
ret
_gfx_deinit endp
;
;int far GFX_init(unsigned scanlines,unsigned fg,unsigned bg,char far* filename);
;
_gfx_init proc far
push bp
mov bp,sp
push ds
push si
push es
push di
;
; beginning of video detect code
;
mov ax,1200h ;detect presence of EGA/VGA
mov bl,10h ;
INT_10H ;
cmp bl,10h ;
jne @@egg ;
mov ax,GFXLIB_ERROR_CARD
jmp @@end
@@egg: mov cs:adapter,ADAPTER_EGA ;detect presence of VGA
mov ax,1a00h ;
INT_10H ;
cmp bl,7 ;
jb @@toast ;
mov cs:adapter,ADAPTER_VGA
@@toast:
;
; end of video detect code
;
;
; beginning of video init code
;
mov ax,0f00h
INT_10H
mov cs:oldmode,al
cmp word ptr [bp+6],200
ja @@ega
mov ax,0eh
jmp @@vid
@@ega: cmp word ptr [bp+6],350
ja @@vga
mov ax,10h
jmp @@vid
@@vga: cmp cs:adapter,ADAPTER_VGA
jnb @@okvga
mov ax,GFXLIB_ERROR_MODE
jmp @@end
@@okvga: mov ax,12h
@@vid: INT_10HP
cmp cs:adapter,ADAPTER_VGA
jb @@no400
cmp word ptr [bp+6],400
ja @@no400
cmp word ptr [bp+6],350
jna @@no400
;
; forces VGA into 640x400 mode
;
SC_INDEX EQU 003C4h
SC_DATA EQU 003C5h
CRTC_INDEX EQU 003D4h
CRTC_DATA EQU 003D5h
MISC_OUTPUT EQU 003C2h
MISC_OUTPUT_IN EQU 003CCh
SCREEN_SEG EQU 0A000h
MOV DX,SC_INDEX ;
MOV AX,0100H ;SYNCHRONOUS RESET WHILE SWITCHING CLOCKS
OUT DX,AX ;
;
;------------------------------------------------------
MOV DX,MISC_OUTPUT ;
MOV AL,063H ;SELECT 400 LINE MODE
OUT DX,AL ;
;------------------------------------------------------
;
MOV DX,SC_INDEX ;UNDO RESET
MOV AX,0300H ;
OUT DX,AX ;
mov dx,CRTC_INDEX ;
mov ax,02716h ;
out dx,ax ;
mov ax,0b815h ;
out dx,ax ;
@@no400:
mov ax,1000h ;
xor bl,bl ;
mov cx,8 ;
mov dl,[bp+8 ] ;
mov dh,[bp+10] ;
@@pal: mov bh,dh ;set palette entry to background color
INT_10HP ;
inc bl ;
mov bh,dl ;set palette entry to foreground col
INT_10HP ;
inc bl ;
loop @@pal ;repeat 8 times, for a total of 16 entries
mov bh,6 ;get 16 point font if VGA,
cmp cs:adapter,ADAPTER_VGA ;
je @@getfont ;
mov bh,2 ;14 point font if EGA
@@getfont:
mov ax,1130h ;get location of ASCII font
push bp ;
push ds
int 10h ;
mov cs:asciiseg,es ;
mov cs:asciioffs,bp ;
pop ds
pop bp ;
;
; end of video init code
;
jmp @@win
lds dx,[bp+12] ;DS:DX now points to filename
mov ax,3d00h ;DOS open file function
int 21h ;
jnc @@open
call _gfx_deinit
mov ax,GFXLIB_ERROR_OPEN ;file not found.
jmp @@end ;return with error code
@@open: mov bx,ax ;handle must be in BX for DOS file functions
mov dx,VIDEOSEG ;
mov ds,dx ;DS:DX will soon point to video memory
mov bp,0202H ;store video plane picker in BP
@@loop: mov dx,MAP_MASK ;
mov ax,bp ;
out dx,ax ;pick a video plane for writing
@@read: mov ax,3f00h ;read 32768 bytes into first half
mov cx,32768 ;of video plane
xor dx,dx ;
int 21h ;DOS read file function
cmp cx,ax ;if 32768 bytes were read, go read more
je @@half ;
mov ax,3e00h ;unexpected end of file.
int 21h ;DOS close file function
call _gfx_deinit
mov ax,GFXLIB_ERROR_READ ;
jmp @@end ;return with error code
@@half: mov ax,3f00h ;read 32768 bytes into second half
mov cx,32768 ;of video plane
mov dx,cx ;
int 21h ;DOS read file function
cmp cx,ax ;if 32768 bytes were read, go read more
je @@done ;if there was an error, close the file and exit
mov ax,3e00h ;unexpected end of file.
int 21h ;DOS close file function
call _gfx_deinit
mov ax,GFXLIB_ERROR_READ ;
jmp @@end ;return with error code
@@done: mov ax,bp ;rotate plane picker to select next plane
shl ah,1 ;if we have already read three,
mov bp,ax ;
test ah,0f0h ;
jnz @@final ;go read the last chunk of data
jmp @@loop ;jump back to read another plane
@@final: mov dx,MAP_MASK ;select plane zero for writing
mov ax,0102H ;
out dx,ax ;
mov ax,3f00h ;load all remaining kanji but 62 just below the
mov cx,27136 ;480th line of the 640x480 video page
mov dx,(80*480) ;
int 21h ;DOS read file function
cmp cx,ax
jne @@jclose
mov ax,3f00h ;load final 62 kanji
mov cx,(32*62) ;into code segment
lea dx,LAST_62 ;(weird!)
push cs ;
pop ds ;
int 21h ;
@@jclose: mov dx,ax ;did we get all the kanji we asked for?
mov ax,3e00h ;wait until we close the file to decide.
int 21h ;DOS close file function
cmp dx,cx ;if all kanji were read, we have won.
je @@win ;
call _gfx_deinit
mov ax,GFXLIB_ERROR_READ ;unexpected end of file.
jmp @@end ;return with error code
@@win: mov dx,READ_MAP ;pick a plane for reading
mov ax,0004H ;
out dx,ax ;
mov dx,MAP_MASK ;pick plane zero for writing
mov ax,0102h ;
out dx,ax ;
xor ax,ax ;return with 0
@@end: pop di
pop es
pop si
pop ds
pop bp
ret
_gfx_init endp
;
; void far GFX_put(unsigned GFX,unsigned scanline, unsigned column)
;
_gfx_put proc far
push bp
mov bp,sp
push ds
push si
push es
push di
mov ax,80*16 ;
mul word ptr [bp+8] ;multiply scanline by bytes/scanline
mov di,ax ;
add di,[bp+10] ;add column to obtain video offset
add di,3200
mov ax,di ;forbid attempts to overwrite GFX table
add ax,(80*15+1);
cmp ax,(80*480) ;
jna @@adjust ;
jmp @@putend ;
@@adjust:mov ax,VIDEOSEG ;set up segments
mov ds,ax ;
mov es,ax ;
mov si,[bp+6] ;load GFX code into SI
mov ax,si
mov cl,3
shr ah,cl
mov cl,5
shl si,cl
;SI = ((GFX*32)%65536) ;GFX "offset"
;AH = GFX/2048 ;GFX "segment"
inc ah
and ah,3
jnz @@putit
add si,(80*480)
cmp si,(80*480)
jae @@putit
add si,OFFSET LAST_62
push cs
pop ds
@@putit: mov dx,READ_MAP ;pick a plane for reading
mov al,04H ;
out dx,ax ;
mov dx,MAP_MASK ;pick plane zero for writing
mov ax,0102H ;
out dx,ax ;
mov ax,78
mov cx,16
@@putit2:movsw ;copy lines to video memory
add di,ax ;
loop @@putit2
@@putend:mov dx,READ_MAP ;pick a plane for reading
mov ax,0004H ;
out dx,ax ;
mov dx,MAP_MASK ;pick plane zero for writing
mov ax,0102h ;
out dx,ax ;
pop di
pop es
pop si
pop ds
pop bp
ret
_gfx_put endp
;
; void far ascii_put(unsigned ascii,unsigned scanline, unsigned column)
;
_gfx_ascii_put proc far
push bp
mov bp,sp
push ds
push si
push es
push di
mov ax,80*16 ;
mul word ptr [bp+8] ;multiply scanline by bytes/scanline
mov di,ax ;
add di,[bp+10] ;add column to obtain video offset
add di,3200
mov ax,di ;forbid attempts to overwrite GFX table
add ax,(80*15) ;
cmp ax,(80*480) ;
jna @@asciifoo ;
jmp @@asciiend ;
@@asciifoo:mov ax,VIDEOSEG
mov es,ax
mov ds,cs:asciiseg
mov si,[bp+6] ;SI = ascii character code
mov bx,79
cmp cs:adapter,ADAPTER_VGA
je @@funfun
call ascii14
jmp @@asciiend
@@funfun:call ascii16
@@asciiend:pop di
pop es
pop si
pop ds
pop bp
ret
_gfx_ascii_put endp
ascii14 proc near
mov ax,14
mul si
mov si,ax
add si,cs:asciioffs
mov cx,14
xor al,al
stosb
add di,bx
@@jujube:
movsb
add di,bx
loop @@jujube
stosb
ret
ascii14 endp
ascii16 proc near
mov cl,4
shl si,cl
add si,cs:asciioffs
mov cx,16
@@twojube:
movsb
add di,bx
loop @@twojube
ret
ascii16 endp
;
; void far GFX_clear(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_gfx_clear proc far
push bp
mov bp,sp
push es
push di
mov di,VIDEOSEG
mov es,di
mov ax,[bp+6]
mov di,80*16
mul di
mov di,ax
add di,[bp+8]
add di,3200
xor al,al
shl word ptr [bp+10],4
@@clr: mov cx,[bp+12]
rep stosb
sub di,[bp+12]
add di,80
dec word ptr [bp+10]
jnz @@clr
pop di
pop es
pop bp
ret
_gfx_clear endp
;
; void far GFX_set(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_gfx_set proc far
push bp
mov bp,sp
push es
push di
mov di,VIDEOSEG
mov es,di
mov ax,[bp+6]
mov di,80*16
mul di
mov di,ax
add di,[bp+8]
add di,3200
mov al,0FFH
shl word ptr [bp+10],4
jmp @@clr
;
; NO RET
;
_gfx_set endp
;
; void far GFX_xor(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_gfx_xor proc far
push bp
mov bp,sp
push es
push di
mov di,VIDEOSEG
mov es,di
mov ax,[bp+6]
mov di,80*16
mul di
mov di,ax
add di,[bp+8]
add di,3200
xor al,al
shl word ptr [bp+10],4
@@clx: mov cx,[bp+12]
@@cly: not byte ptr es:[di]
inc di
loop @@cly
sub di,[bp+12]
add di,80
dec word ptr [bp+10]
jnz @@clx
pop di
pop es
pop bp
ret
_gfx_xor endp
;
; void far GFX_gray(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_gfx_gray proc far
push bp
mov bp,sp
push es
push di
mov di,VIDEOSEG
mov es,di
mov ax,[bp+6]
mov di,80*16
mul di
mov di,ax
add di,[bp+8]
add di,3200
xor al,al
mov bl,55H
shl word ptr [bp+10],4
@@gra: mov cx,[bp+12]
@@grb: and es:[di],bl
inc di
loop @@grb
sub di,[bp+12]
add di,80
not bl
dec word ptr [bp+10]
jnz @@gra
pop di
pop es
pop bp
ret
_gfx_gray endp
;
; void far GFX_bold8(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_gfx_bold8 proc far
push bp
mov bp,sp
push es
push di
mov di,VIDEOSEG
mov es,di
mov ax,[bp+6]
mov di,80*16
mul di
mov di,ax
add di,[bp+8]
add di,3200
shl word ptr [bp+10],4
@@bgra: mov cx,[bp+12]
@@bgrb: mov al,es:[di]
shr al,1
or es:[di],al
inc di
loop @@bgrb
sub di,[bp+12]
add di,80
dec word ptr [bp+10]
jnz @@bgra
pop di
pop es
pop bp
ret
_gfx_bold8 endp
;
; void far GFX_underline(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_gfx_underline proc far
push bp
mov bp,sp
push es
push di
mov di,VIDEOSEG
mov es,di
mov ax,[bp+6]
mov di,80*16
mul di
mov di,ax
add di,[bp+8]
add di,3200
add di,80*15
mov al,0FFH
@@ugra: mov cx,[bp+12]
rep stosb
sub di,[bp+12]
add di,80*16
dec word ptr [bp+10]
jnz @@ugra
pop di
pop es
pop bp
ret
_gfx_underline endp
;
; void far GFX_fcopy(unsigned srcy, unsigned srcx,
; unsigned desty, unsigned destx,
; unsigned height, unsigned width );
;
_gfx_fcopy proc far
push bp
mov bp,sp
push ds ;save data and extra segments
push si ;
push es ;
push di ;
mov di,VIDEOSEG ;set up segments for video transfer
mov es,di ;
mov ds,di ;
mov ax,[bp+6] ;set up source register
mov si,80*16 ;
mul si ;
mov si,ax ;
add si,[bp+8] ;
add si,3200
mov ax,[bp+10] ;set up destination register
mov di,80*16 ;
mul di ;
mov di,ax ;
add di,[bp+12] ;
add di,3200
shl word ptr [bp+14],4
mov bx,80
mov dx,[bp+16]
sub bx,dx
js @@copend
cld
@@cop1:
mov cx,dx
shr cx,1
jz @@cop2
rep movsw
@@cop2: jnc @@cop3
movsb
@@cop3:
add si,bx
add di,bx
dec word ptr [bp+14]
jnz @@cop1
@@copend:
pop di
pop es
pop si
pop ds
pop bp
ret
_gfx_fcopy endp
;
; void far GFX_bcopy(unsigned srcy, unsigned srcx,
; unsigned desty, unsigned destx,
; unsigned height, unsigned width );
;
_gfx_bcopy proc far
push bp
mov bp,sp
push ds ;save data and extra segments
push si ;
push es ;
push di ;
mov di,VIDEOSEG ;set up segments for video transfer
mov es,di ;
mov ds,di ;
mov ax,[bp+6] ;set up source register
mov si,80*16 ;
mul si ;
mov si,ax ;
add si,[bp+8] ;
add si,3200
mov ax,[bp+10] ;set up destination register
mov di,80*16 ;
mul di ;
mov di,ax ;
add di,[bp+12] ;
add di,3200
mov ax,80*16
mul word ptr [bp+14]
sub ax,80
add ax,[bp+16]
dec ax
shl word ptr [bp+14],4
add si,ax
add di,ax
mov bx,80
mov dx,[bp+16]
sub bx,dx
std
@@bcop1:
mov cx,dx
rep movsb
sub si,bx
sub di,bx
dec word ptr [bp+14]
jnz @@bcop1
cld
pop di
pop es
pop si
pop ds
pop bp
ret
_gfx_bcopy endp
;
GFXLIB_TEXT ends
public _gfx_init
public _gfx_deinit
public _gfx_put
public _gfx_ascii_put
public _gfx_clear
public _gfx_set
public _gfx_xor
public _gfx_gray
public _gfx_bold8
public _gfx_underline
public _gfx_fcopy
public _gfx_bcopy
end