home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
comm
/
ykh121.zip
/
YKHSRC.ZIP
/
JISLIB.ASM
< prev
next >
Wrap
Assembly Source File
|
1992-09-15
|
15KB
|
786 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.
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
JISLIB_ERROR_OPEN EQU 1 ;file not found
JISLIB_ERROR_READ EQU 2 ;unexpected end of file
JISLIB_ERROR_CARD EQU 3 ;inadequate video card
JISLIB_ERROR_MODE EQU 4 ;unable to set requested mode
JISLIB_TEXT segment byte public 'CODE'
JISLIB_TEXT ends
DGROUP group _DATA,_BSS
assume cs:JISLIB_TEXT,ds:DGROUP
_DATA segment word public 'DATA'
_DATA ends
_BSS segment word public 'BSS'
_BSS ends
JISLIB_TEXT segment byte public 'CODE'
;
LAST_62 db (32*62) dup(0)
asciiseg dw ?
asciioffs dw ?
oldmode db ?
adapter db ?
;
;int far jis_deinit();
;
_jis_deinit proc far
xor ah,ah
mov al,cs:oldmode
INT_10HP
ret
_jis_deinit endp
;
;int far jis_init(unsigned scanlines,unsigned fg,unsigned bg,char far* filename);
;
_jis_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,JISLIB_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,JISLIB_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
mov dx,3cch ;forces VGA into 640x400 mode
in al,dx ;unstable!
and al,73h ;
mov dx,3c2h ;
out dx,al ;
;
mov dx,3d4h ;
mov ax,02716h ;
out dx,ax ;
;
mov dx,3d4h ;
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
;
lds dx,[bp+12] ;DS:DX now points to filename
mov ax,3d00h ;DOS open file function
int 21h ;
jnc @@open
call _jis_deinit
mov ax,JISLIB_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 _jis_deinit
mov ax,JISLIB_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 _jis_deinit
mov ax,JISLIB_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 _jis_deinit
mov ax,JISLIB_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
_jis_init endp
;
; void far jis_put(unsigned jis,unsigned scanline, unsigned column)
;
_jis_put proc far
push bp
mov bp,sp
push ds
push si
push es
push di
mov ax,80 ;
mul word ptr [bp+8] ;multiply scanline by bytes/scanline
mov di,ax ;
add di,[bp+10] ;add column to obtain video offset
mov ax,di ;forbid attempts to overwrite jis 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 jis code into SI
mov ax,si
mov cl,3
shr ah,cl
mov cl,5
shl si,cl
;SI = ((jis*32)%65536) ;jis "offset"
;AH = jis/2048 ;jis "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
_jis_put endp
;
; void far ascii_put(unsigned ascii,unsigned scanline, unsigned column)
;
_ascii_put proc far
push bp
mov bp,sp
push ds
push si
push es
push di
mov ax,80 ;
mul word ptr [bp+8] ;multiply scanline by bytes/scanline
mov di,ax ;
add di,[bp+10] ;add column to obtain video offset
mov ax,di ;forbid attempts to overwrite jis 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
_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 jis_clear(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_jis_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
mul di
mov di,ax
add di,[bp+8]
xor al,al
@@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
_jis_clear endp
;
; void far jis_set(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_jis_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
mul di
mov di,ax
add di,[bp+8]
mov al,0FFH
jmp @@clr
;
; NO RET
;
_jis_set endp
;
; void far jis_xor(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_jis_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
mul di
mov di,ax
add di,[bp+8]
xor al,al
@@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
_jis_xor endp
;
; void far jis_gray(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_jis_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
mul di
mov di,ax
add di,[bp+8]
xor al,al
mov bl,55H
@@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
_jis_gray endp
;
; void far jis_bold8(unsigned scanline, unsigned column,
; unsigned scanlines, unsigned columns);
;
_jis_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
mul di
mov di,ax
add di,[bp+8]
@@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
_jis_bold8 endp
;
; void far jis_fcopy(unsigned srcy, unsigned srcx,
; unsigned desty, unsigned destx,
; unsigned height, unsigned width );
;
_jis_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 ;
mul si ;
mov si,ax ;
add si,[bp+8] ;
mov ax,[bp+10] ;set up destination register
mov di,80 ;
mul di ;
mov di,ax ;
add di,[bp+12] ;
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
_jis_fcopy endp
;
; void far jis_bcopy(unsigned srcy, unsigned srcx,
; unsigned desty, unsigned destx,
; unsigned height, unsigned width );
;
_jis_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 ;
mul si ;
mov si,ax ;
add si,[bp+8] ;
mov ax,[bp+10] ;set up destination register
mov di,80 ;
mul di ;
mov di,ax ;
add di,[bp+12] ;
mov ax,80
mul word ptr [bp+14]
sub ax,80
add ax,[bp+16]
dec ax
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
_jis_bcopy endp
;
JISLIB_TEXT ends
public _jis_init
public _jis_deinit
public _jis_put
public _ascii_put
public _jis_clear
public _jis_set
public _jis_xor
public _jis_gray
public _jis_bold8
public _jis_fcopy
public _jis_bcopy
end