home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
PROG_C
/
VGAGRAPH.ZIP
/
GRAPH10.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-26
|
31KB
|
1,752 lines
#include <dos.h>
#include <string.h>
#include <mem.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <dir.h>
#include <stdlib.h>
#include <alloc.h>
#include "low.h"
extern char byte_tabXL[4];
extern char byte_tabXR[4];
extern char char_tab[16];
extern char byte_tab[8];
extern char pln_tab[4];
extern unsigned int BytesPerLine,FastPlace;
typedef
struct {
unsigned int dx,dy,type;
unsigned int p[4];
} Image;
void setscrline10(unsigned int w)
{
w=w*BytesPerLine;
asm{
mov ax,3D4h
mov dx,ax
}
waitstart:asm{
in al,dx
test al,8
je waitstart
}
outportb(0x03D4,12);outportb(0x03D5,w>>8);
outportb(0x03D4,13);outportb(0x03D5,w);
asm{
mov ax,3D4h
mov dx,ax
}
waitend: asm{
in al,dx
test al,1
je waitend
}
}
void putpixel10(int x,int y,char color)
{
asm{
mov ax,y
mov bx,x
mov cl,bl
push dx
mov dx,BytesPerLine
mul dx
pop dx
shr bx,1
shr bx,1
shr bx,1
add bx,ax
mov ax,0A000h
mov es,ax
and cl,7
xor cl,7
mov ah,1
shl ah,cl
mov dx,3CEh
mov al,8
out dx,ax
mov ax,0005h
out dx,ax
mov ah,0 /* Bit logic */
mov al,3
out dx,ax
mov ah,color
mov al,00h
out dx,ax
mov ax,0F01h
out dx,ax
or es:[bx],al
mov ax,0FF08h
out dx,ax
mov ax,0005
out dx,ax
mov ax,0003
out dx,ax
mov ax,0001
out dx,ax
mov ax,0000h
out dx,ax
}
}
char getpixel10(int x,int y)
{
char b;
asm{
mov ax,y
mov bx,x
mov cl,bl
push dx
mov dx,BytesPerLine
mul dx
pop dx
shr bx,1
shr bx,1
shr bx,1
add bx,ax
mov ax,0A000h
mov es,ax
and cl,7
xor cl,7
mov ah,1
mov ch,ah
shl ch,cl
mov si,bx
xor bl,bl
mov dx,3CEh
mov ax,304h
}
L:
asm{
out dx,ax
mov bh,es:[si]
and bh,ch
neg bh
rol bx,1
dec ah
jge L
mov b,bl
mov ax,0004h
out dx,ax
}
return(b);
}
void clearscr10(char color)
{
void far *Screen;
outport(0x03CE,color << 8);
outport(0x03CE,0x0F01);
outport(0x03CE,0x0003);
outport(0x03CE,0x0003);
Screen=MK_FP(0xA000, 0);
setmem(Screen,0xFFFF,0);
outport(0x03CE,0x0000);
outport(0x03CE,0x0001);
}
void line10(int x1,int y1,int x2,int y2,char color)
{
unsigned int VertIncr,Incr1,Incr2,Routine;
asm{
cld
mov dx,3CEh
mov ax,0005h
out dx,ax
mov ah,color
xor al,al
out dx,ax
mov ax,0F01h
out dx,ax
mov ah,0 /* bit logic */
mov al,3
out dx,ax
mov si,BytesPerLine
mov cx,x2
sub cx,x1
jns L01
neg cx
mov bx,x2
xchg bx,x1
mov x2,bx
mov bx,y2
xchg bx,y1
mov y2,bx
}
L01:
asm{
mov bx,y2
sub bx,y1
jns L03
neg bx
neg si
}
L03:
asm{
mov VertIncr,si
mov Routine,0
cmp bx,cx
jle L04
mov Routine,1
xchg bx,cx
}
L04:
asm{
shl bx,1
mov Incr1,bx
sub bx,cx
mov si,bx
sub bx,cx
mov Incr2,bx
push cx
mov ax,y1
mov bx,x1
mov cl,bl
push dx
mov dx,BytesPerLine
mul dx
pop dx
shr bx,1
shr bx,1
shr bx,1
add bx,ax
mov ax,0A000h
mov es,ax
and cl,7
xor cl,7
mov ah,1
mov di,bx
shl ah,cl
mov bl,ah
mov al,8
pop cx
inc cx
}
if (Routine!=0) goto HiSlopeLine10;
LL10:
asm{
mov ah,bl
}
LL11:
asm{
or ah,bl
ror bl,1
jc LL14
or si,si
jns LL12
add si,Incr1
loop LL11
out dx,ax
or es:[di],al
jmp Lexit_line
}
LL12:
asm{
add si,Incr2
out dx,ax
or es:[di],al
add di,VertIncr
loop LL10
jmp Lexit_line
}
LL14:
asm{
out dx,ax
or es:[di],al
inc di
or si,si
jns LL15
add si,Incr1
loop LL10
jmp Lexit_line
}
LL15:
asm{
add si,Incr2
add di,VertIncr
loop LL10
jmp Lexit_line
}
HiSlopeLine10:
asm{
mov bx,VertIncr
}
LL21:
asm{
out dx,ax
or es:[di],al
add di,bx
}
LL22:
asm{
or si,si
jns LL23
add si,Incr1
loop LL21
jmp Lexit_line
}
LL23:
asm{
add si,Incr2
ror ah,1
adc di,0
loop LL21
}
Lexit_line:
asm{
xor ax,ax
out dx,ax
inc ax
out dx,ax
mov ax,0FF08h
out dx,ax
mov ax,0003h
out dx,ax
mov ax,0000h
out dx,ax
mov ax,0001h
out dx,ax
}
}
void bar10(int x,int y,int dx,int dy,int color)
{
unsigned int Bytes=BytesPerLine;
unsigned int lx=dx;
unsigned int StartOffset,i,yoff;
asm{
mov ax,0A000h
mov es,ax
mov ax,y
mul Bytes
mov yoff,ax
mov dx,03CEh
mov ax,0005h
out dx,ax
mov ah,0 /* bit logic */
mov al,03h
out dx,ax
mov ax,0FF08h
out dx,ax
mov ax,0F01h
out dx,ax
mov ax,color
shl ax,8
out dx,ax
mov bx,x
shr bx,3
mov si,bx
add si,yoff
mov bx,lx
shr bx,3
mov cx,dy
}
L2:
asm{
push cx
mov cx,bx
mov di,si
}
L1:
asm{
or es:[di],al
inc di
loop L1
add si,Bytes
pop cx
loop L2
mov ax,0005h
out dx,ax
mov ax,0003h
out dx,ax
mov ax,0001h
out dx,ax
}
}
void bars10(int x,int y,int dx,int dy,char color)
{
unsigned int x2,add1,add2,row_to_adjust,count,yoff;
unsigned int Bytes=BytesPerLine;
unsigned int i=dy;
char byte_tab1[8];
memmove(byte_tab1,byte_tab,8);
x2=x+dx;
asm{
cld
inc i
mov dx,03CEh
mov ax,0205h
out dx,ax
mov ah,0 /* bit logic */
mov al,03h
out dx,ax
mov ax,y
mul Bytes
mov yoff,ax
mov si,x
and si,7
mov dh,byte ptr byte_tab1[si]
mov si,x2
inc si
and si,7
mov dl,byte ptr byte_tab1[si]
not dl
mov si,x
mov cl,3
shr si,cl
mov add1,si
mov si,x2
inc si
shr si,cl
mov add2,si
mov ax,0A000h
mov es,ax
mov bx,Bytes
cmp si,add1
jnz More_Byte
mov si,add1
add si,yoff
mov ah,8
mov al,dl
and al,dh
xchg al,ah
mov dx,03CEh
out dx,ax
xchg al,ah
mov al,color
mov cx,i
}
L1:
asm{
mov ah,es:[si]
mov es:[si],al
add si,bx
loop L1
jmp FILL_EXIT
}
More_Byte:
asm{
dec si
cmp si,add1
jnz More_Two_Byte
dec bx
mov row_to_adjust,bx
mov bx,dx
mov si,add1
add si,yoff
mov dx,03CEh
mov al,8
out dx,al
inc dx
mov ah,color
mov cx,i
}
L2:
asm{
mov al,bh
out dx,al
test ch,es:[si]
mov es:[si],ah
mov al,bl
out dx,al
inc si
test ch,es:[si]
mov es:[si],ah
add si,row_to_adjust
loop L2
jmp FILL_EXIT
}
More_Two_Byte:
asm{
sub bx,add2
mov di,add1
add bx,di
mov row_to_adjust,bx
mov bx,add2
sub bx,di
dec bx
mov count,bx
mov bx,dx
mov dx,03CEh
mov al,8
out dx,al
inc dx
mov ah,color
add di,yoff
cld
}
L3:
asm{
mov al,bh
out dx,al
test ch,es:[di]
mov es:[di],ah
inc di
mov cx,count
mov al,0FFh
out dx,al
mov al,ah
}
L4:
asm{
test ch,es:[di]
stosb
loop L4
mov al,bl
out dx,al
test ch,es:[di]
mov es:[di],ah
add di,row_to_adjust
dec i
cmp i,0
jne L3
}
FILL_EXIT:
asm{
dec dx
mov ax,0005h
out dx,ax
mov ax,0003h
out dx,ax
mov ax,0FF08h
out dx,ax
}
}
void barpat10(int x,int y,int dx,int dy,char colorb1,char colorb2)
{
char BitMask = 0x55;
unsigned int add1,add2,add3,yoff,i,lx;
unsigned int l=dx;
unsigned int Bytes=BytesPerLine;
asm{
cld
push ds
mov ax,y
mul Bytes
mov yoff,ax
mov ax,x
shr ax,3
add ax,yoff
mov add1,ax
add ax,Bytes
mov add2,ax
mov ax,0A000h
mov es,ax
mov si,add1
mov cx,l
shr cx,3
mov lx,cx
mov dx,03CEh
mov ah,0 /* bit logic */
mov al,03h
out dx,ax
mov cx,2
}
L2:
asm{
push cx
mov ax,0205h
out dx,ax
mov ah,BitMask
mov al,08h
out dx,ax
mov al,colorb1
mov ah,es:[si]
mov es:[si],al
not BitMask
mov ah,BitMask
mov al,08h
out dx,ax
mov al,colorb2
mov ah,es:[si]
mov es:[si],al
mov cx,lx
dec cx
mov ax,0105h
out dx,ax
cmp cx,00h
je L5
mov di,si
inc si
}
L1:
asm{
mov al,es:[di]
mov es:[si],al
inc si
loop L1
}
L5:
asm{
mov si,add2
pop cx
loop L2
mov cx,dy
sub cx,01h
cmp cx,00h
je Fill_Exit
mov si,add1
add si,Bytes
mov bx,si
add si,Bytes
mov di,si
mov si,add1
}
L3:
asm{
push cx
push di
mov cx,lx
}
L4:
asm{
mov al,es:[si]
mov es:[di],al
inc di
loop L4
xchg si,bx
pop di
add di,Bytes
pop cx
loop L3
}
Fill_Exit:
asm{
mov ax,0005h
out dx,ax
mov ax,0003h
out dx,ax
mov ax,0FF08h
out dx,ax
pop ds
}
}
void displaychar10(int x,int y,char s,char colorf,char colorb,char flag)
{
unsigned int Bytes,yoff,CellOff,dssave;
char ln,Shift_C,Left_Mask,Right_Mask,ScanLine;
char byte_tab1[8];
memmove(byte_tab1,byte_tab,8);
ln=1;
asm{
cld
mov dssave,ds
mov dx,03CEh
mov ah,0 /* Bit logic */
mov al,03h
out dx,ax
mov ax,0205h
out dx,ax
mov ax,BytesPerLine
mov Bytes,ax
mov ax,40h
mov ds,ax
mov al,ds:[85h]
mov ScanLine,al
mul Bytes
dec ax
mov CellOff,ax
xor ax,ax
mov ds,ax
mov bx,010Ch
lds si,ds:[bx]
mov ax,0A000h
mov es,ax
mov ax,Bytes
mul y
mov yoff,ax
mov ax,x
shr ax,3
add yoff,ax
mov bx,01h
mov dx,03CEh
mov di,x
and di,7
jz Byte_A
jmp NByte_A
}
Byte_A:
asm{
mov al,8
out dx,al
inc dx
xor cx,cx
mov cl,ln
mov di,yoff
cmp flag,1
je L_1
}
L1:
asm{
push cx
push si
xchg di,bx
mov al,s
mul byte ptr ScanLine
add si,ax
xchg di,bx
inc bx
mov cl,ScanLine
}
L11:
asm{
lodsb
out dx,al
mov ah,colorf
cmp ah,es:[di]
mov es:[di],ah
add di,Bytes
loop L11
sub di,CellOff
pop si
pop cx
loop L1
jmp STR_OUT
}
L_1:
asm{
push cx
push si
xchg di,bx
mov al,s
mul byte ptr ScanLine
add si,ax
xchg di,bx
inc bx
mov cl,ScanLine
}
L_11:
asm{
lodsb
out dx,al
mov ah,colorf
test ah,es:[di]
mov es:[di],ah
not al
out dx,al
mov ah,colorb
test ah,es:[di]
mov es:[di],ah
add di,Bytes
loop L_11
sub di,CellOff
pop si
pop cx
loop L_1
jmp STR_OUT
}
NByte_A:
asm{
mov ax,di
mov Shift_C,al
push ds
mov ax,dssave
mov ds,ax
mov al,byte ptr byte_tab1[di]
pop ds
mov Left_Mask,al
not al
mov Right_Mask,al
mov al,8
out dx,al
inc dx
xor cx,cx
mov cl,ln
mov di,yoff
cmp flag,01h
je L_2
}
L2:
asm{
push cx
push si
xchg di,bx
mov al,s
mul ScanLine
add si,ax
xchg di,bx
inc bx
mov cl,ScanLine
}
L22:
asm{
push cx
mov al,ds:[si]
mov cl,Shift_C
ror al,cl
and al,Left_Mask
out dx,al
mov ah,es:[di]
mov ah,colorf
mov es:[di],ah
mov al,ds:[si]
ror al,cl
and al,Right_Mask
out dx,al
mov ah,es:[di+1]
mov ah,colorf
mov es:[di+1],ah
inc si
add di,Bytes
pop cx
loop L22
sub di,CellOff
pop si
pop cx
loop L2
jmp STR_OUT
}
L_2:
asm{
push cx
push si
xchg di,bx
mov al,s
mul ScanLine
add si,ax
xchg di,bx
inc bx
mov cl,ScanLine
}
L_22:
asm{
push cx
mov al,ds:[si]
mov cl,Shift_C
ror al,cl
and al,Left_Mask
out dx,al
mov ah,es:[di]
mov ah,colorf
mov es:[di],ah
not al
and al,Left_Mask
out dx,al
mov ah,es:[di]
mov ah,colorb
mov es:[di],ah
mov al,ds:[si]
ror al,cl
and al,Right_Mask
out dx,al
mov ah,es:[di+1]
mov ah,colorf
mov es:[di+1],ah
not al
and al,Right_Mask
out dx,al
mov ah,es:[di+1]
mov ah,colorb
mov es:[di+1],ah
inc si
add di,Bytes
pop cx
loop L_22
sub di,CellOff
pop si
pop cx
loop L_2
}
STR_OUT:
asm{
mov dx,03CEh
mov ax,0005h
out dx,ax
mov ax,0003h
out dx,ax
mov ax,0FF08h
out dx,ax
mov ds,dssave
}
}
void lineh10(int x,int y,int dx,char color1,char color2)
{
char BIT_MASK = 0x55,b;
unsigned int yoff,x2,add1,add2;
unsigned int l=dx;
char byte_tab1[8];
if ((y%2)==0){b=color1;color1=color2;color2=b;}
memmove(byte_tab1,byte_tab,8);
asm{
cld
mov ax,x
add ax,l
mov x2,ax
mov ax,y
mul BytesPerLine
mov yoff,ax
mov dx,03CEh
mov ah,0 /* Bit logic */
mov al,03h
out dx,ax
mov ax,0205h
out dx,ax
mov si,x
and si,7
mov bh,byte ptr byte_tab1[si]
mov si,x2
inc si
and si,7
mov bl,byte ptr byte_tab1[si]
not bl
mov si,x
shr si,3
add si,yoff
mov add1,si
mov si,x2
inc si
shr si,3
add si,yoff
mov add2,si
mov ax,0A000h
mov es,ax
cmp si,add1
jnz More_Byte
mov si,add1
mov ah,bh
and ah,bl
and ah,BIT_MASK
mov al,08h
out dx,ax
mov ah,color1
test al,es:[si]
mov es:[si],ah
not BIT_MASK
mov ah,bh
and ah,bl
and ah,BIT_MASK
out dx,ax
mov ah,color2
test al,es:[si]
mov es:[si],ah
not BIT_MASK
jmp LINE_END
}
More_Byte:
asm{
dec si
cmp si,add1
jnz More_Two_Byte
mov al,08h
mov cx,02h
}
L__:
asm{
mov ah,bh
and ah,BIT_MASK
out dx,ax
mov ah,color1
test al,es:[si]
mov es:[si],ah
not BIT_MASK
mov ah,bh
and ah,BIT_MASK
out dx,ax
mov ah,color2
test al,es:[si]
mov es:[si],ah
inc si
not BIT_MASK
xchg bh,bl
loop L__
not BIT_MASK
jmp LINE_END
}
More_Two_Byte:
asm{
mov si,add1
mov al,08h
mov ah,bh
and ah,BIT_MASK
out dx,ax
mov ah,color1
test al,es:[si]
mov es:[si],ah
mov ah,bh
not BIT_MASK
and ah,BIT_MASK
out dx,ax
mov ah,color2
test al,es:[si]
mov es:[si],ah
not BIT_MASK
mov si,add2
mov al,08h
mov ah,bl
and ah,BIT_MASK
out dx,ax
mov ah,color1
test al,es:[si]
mov es:[si],ah
mov ah,bl
not BIT_MASK
and ah,BIT_MASK
out dx,ax
mov ah,color2
test al,es:[si]
mov es:[si],ah
not BIT_MASK
mov si,add1
inc si
mov ah,BIT_MASK
out dx,ax
mov ah,color1
test al,es:[si]
mov es:[si],ah
not BIT_MASK
mov ah,BIT_MASK
out dx,ax
mov ah,color2
test al,es:[si]
mov es:[si],ah
mov ax,0105h
out dx,ax
inc si
cmp si,add2
je LINE_END
push ds
mov ax,0A000h
mov ds,ax
mov di,si
dec si
}
L_1:
asm{
movsb
cmp di,add2
jnz L_1
pop ds
}
LINE_END:
asm{
mov ax,0005h
out dx,ax
mov ax,0FF08h
out dx,ax
mov ax,0003h
out dx,ax
}
}
void linev10(int x,int y,int dy,char color1,char color2)
{
asm{
mov cx,x
shr cx,3
mov ax,y
mul BytesPerLine
add ax,cx
mov si,ax
mov cl,byte ptr x
and cl,7
xor cl,7
mov bh,01h
shl bh,cl
mov cx,dy
inc cx
mov ax,0A000h
mov es,ax
mov dx,03CEh
mov ax,0205h
out dx,ax
mov al,03h
mov ah,0 /* Bit logic */
out dx,ax
mov al,08h
mov ah,bh
out dx,ax
mov bh,color1
mov bl,color2
}
L1:
asm{
test al,es:[si]
mov es:[si],bh
xchg bh,bl
add si,BytesPerLine
loop L1
mov ax,0005h
out dx,ax
mov ah,0003h
out dx,ax
mov ax,0FF08h
out dx,ax
}
}
void barpats10(int x,int y,int dx,int dy,char color1,char color2)
{
char BIT_MASK = 0x55;
unsigned int l=dx;
unsigned int x2,yoff,add1,add2,add0,lx;
char Mask1,Mask2,MaskL1,MaskL2,MaskR1,MaskR2,i;
char byte_tab1[8];
memmove(byte_tab1,byte_tab,8);
asm{
mov lx,01h
mov i,0
mov ax,x
add ax,l
mov x2,ax
mov ax,y
mul BytesPerLine
mov yoff,ax
mov dx,03CEh
mov ax,0205h
out dx,ax
mov ah,0 /* bit logic */
mov al,03h
out dx,ax
mov si,x
and si,7
mov bh,byte ptr byte_tab1[si]
mov si,x2
inc si
and si,7
mov bl,byte ptr byte_tab1[si]
not bl
mov si,x
shr si,3
add si,yoff
mov add1,si
mov si,x2
inc si
shr si,3
add si,yoff
mov add2,si
mov ax,0A000h
mov es,ax
cmp si,add1
jnz More_Byte
mov si,add1
mov ah,bh
and ah,bl
mov bh,ah
and bh,BIT_MASK
not BIT_MASK
and ah,BIT_MASK
mov bl,ah
mov cx,dy
mov al,08h
mov ah,bh
out dx,ax
mov al,color1
mov ah,color2
}
L1:
asm{
test al,es:[si]
mov es:[si],al
add si,BytesPerLine
xchg al,ah
loop L1
mov si,add1
mov al,08h
mov ah,bl
out dx,ax
mov cx,dy
mov al,color2
mov ah,color1
}
L2:
asm{
test al,es:[si]
mov es:[si],al
add si,BytesPerLine
xchg al,ah
loop L2
jmp FILL_END
}
More_Byte:
asm{
mov ah,bh
and ah,BIT_MASK
mov MaskL1,ah
mov ah,bh
not BIT_MASK
and ah,BIT_MASK
mov MaskL2,ah
mov ah,bl
and ah,BIT_MASK
mov MaskR2,ah
mov ah,bl
not BIT_MASK
and ah,BIT_MASK
mov MaskR1,ah
mov Mask1,ah
mov ah,MaskR2
mov Mask2,ah
mov si,add2
mov add0,si
}
L__1:
asm{
mov cx,dy
inc cx
mov al,08h
mov ah,Mask1
out dx,ax
mov al,color1
mov ah,color2
}
L_1:
asm{
test al,es:[si]
mov es:[si],al
add si,BytesPerLine
xchg al,ah
loop L_1
mov si,add0
mov cx,dy
inc cx
mov al,08h
mov ah,Mask2
out dx,ax
mov al,color2
mov ah,color1
}
L_2:
asm{
test al,es:[si]
mov es:[si],al
add si,BytesPerLine
xchg al,ah
loop L_2
inc i
cmp i,02h
je L__C
mov ah,MaskL1
mov Mask1,ah
mov ah,MaskL2
mov Mask2,ah
mov si,add1
mov add0,si
jmp L__1
}
L__C:
asm{
mov si,add1
inc si
cmp si,add2
je FILL_END
mov ah,BIT_MASK
mov al,08h
out dx,ax
mov ah,color1
test es:[si],al
mov es:[si],ah
not BIT_MASK
mov ah,BIT_MASK
out dx,ax
mov ah,color2
test al,es:[si]
mov es:[si],ah
add si,BytesPerLine
mov ah,BIT_MASK
mov al,08h
out dx,ax
mov ah,color1
test es:[si],al
mov es:[si],ah
not BIT_MASK
mov ah,BIT_MASK
out dx,ax
mov ah,color2
test al,es:[si]
mov es:[si],ah
mov ax,0105h
out dx,ax
mov si,add1
inc si
mov di,si
inc di
cmp di,add2
je LC
}
L___1:
asm{
mov al,es:[si]
mov es:[di],al
inc di
cmp di,add2
jnz L___1
mov add0,di
sub di,si
mov lx,di
mov di,add0
add di,BytesPerLine
mov add0,di
add si,BytesPerLine
mov di,si
inc di
}
L___2:
asm{
mov al,es:[si]
mov es:[di],al
inc di
cmp di,add0
jnz L___2
}
LC:
asm{
cmp dy,02h
je FILL_END
mov cx,dy
sub cx,01h
mov si,add1
inc si
add si,BytesPerLine
mov add0,si
mov di,si
add di,BytesPerLine
mov si,add1
inc si
mov bx,add0
}
L___:
asm{
push cx
push di
mov cx,lx
}
L_I:
asm{
mov al,es:[si]
mov es:[di],al
inc di
loop L_I
xchg si,bx
pop di
add di,BytesPerLine
pop cx
loop L___
}
FILL_END:
asm{
mov ax,0005h
out dx,ax
mov ax,0003h
out dx,ax
mov ax,0FF08h
out dx,ax
}
}
void setcol10(char colorf,char colorb,unsigned int place)
{
FastPlace=place;
asm{
push ds
mov ax,FastPlace
push ax
mov ax,40h
mov ds,ax
mov cx,ds:[85h]
xor ax,ax
mov ds,ax
mov bx,43h*4
lds si,ds:[bx]
mov ax,0A000h
mov es,ax
pop ax
mov di,ax
mov al,0h
mov ah,1
mul cx
mov cx,ax
mov bl,colorf
mov bh,colorb
mov dx,3CEh
mov ax,0A05h
out dx,ax
mov ax,0003h
out dx,ax
mov ax,0007
out dx,ax
mov al,8
}
L1:
asm{
mov ah,ds:[si]
out dx,ax
and es:[di],bl
not ah
out dx,ax
and es:[di],bh
inc di
inc si
loop L1
mov ax,0FF08h
out dx,ax
mov ax,0005
out dx,ax
mov ax,0003
out dx,ax
mov ax,0F07h
out dx,ax
pop ds
}
}
void fasttext10(int x,int y,char *s)
{
char *strs;
char b,i;
unsigned int w,ScanLine,wd;
w=BytesPerLine;
strcpy(strs,s);
asm{
cld
push ds
mov ax,FastPlace
push ax
mov dx,3CEh
mov ax,0105h
out dx,ax
mov ax,0003h
out dx,ax
mov ax,40h
mov ds,ax
mov ax,ds:[85h]
mov ScanLine,ax
mov ax,0A000h
mov es,ax
mov bx,x
mov ax,y
shr bx,1
shr bx,1
shr bx,1
mov dx,w
mul dx
add ax,bx
mov di,ax
mov dx,ax
mov bx,w
mov wd,dx
}
for (i=0;i<strlen(strs);i++)
{
b=strs[i];
asm{
mov dx,wd
mov ax,0A000h
mov es,ax
mov ax,0A000h
mov ds,ax
pop ax
mov si,ax
push ax
mov al,b
mov cx,ScanLine
mul cl
add si,ax
mov di,dx
}
L1:
asm{
movsb
dec di
add di,w
loop L1
inc dx
mov wd,dx
}
}
asm{
mov dx,03CEh
mov ax,0005h
out dx,ax
pop ax
pop ds
}
}
void UnLockEGA()
{
outport(0x03CE,0x0000);
outport(0x03CE,0x0001);
outport(0x03CE,0x0002);
outport(0x03CE,0x0003);
outport(0x03CE,0x0004);
outport(0x03CE,0x0805);
outport(0x03CE,0x0506);
outport(0x03CE,0x0f07);
outport(0x03CE,0xff08);
outportb(0x03C4,0x02);
}
void LockEGA()
{
outport(0x03CE,0x0003);
outport(0x03CE,0x0004);
outport(0x03CE,0x0005);
outport(0x03CE,0x0506);
outport(0x03CE,0x0f07);
outport(0x03CE,0xff08);
outport(0x03C4,0x0f02);
}
char getimageram10(unsigned int x,unsigned int y,unsigned int dx,
unsigned int dy,Image *W)
{
unsigned int i,j,k,scrofs,xend;
long t,l;
char s[20];
xend=x+dx;
x=x >> 3;
if (xend % 8 != 0) xend=((xend >> 3) << 3)+8;
dx=xend-x;
W->dx=dx >> 3;
W->dy=dy;
t=coreleft();
l=(W->dy+1)*(W->dx)*(long)(4);
t=l-t+10000;
if (t>0) return(1);
for (i=0;i<=3;i++)
t=allocmem(((W->dx)*(W->dy+1))/16+1,&W->p[i]);
outport(0x03CE,0x0005);
outportb(0x03CE,4);
k=y*BytesPerLine+x;
for (i=0;i<=3;i++){
scrofs=k;
outportb(0x03CF,i);
for (j=0;j<=W->dy;j++){
move(0xA000,scrofs,W->p[i],j*W->dx,W->dx);
scrofs=scrofs+BytesPerLine;
}
}
W->type=0;
return(0);
}
void putimageram10(unsigned int x,unsigned int y,Image W,char Restore)
{
unsigned int i,j,scrofs;
scrofs=y*BytesPerLine+(x >> 3);
UnLockEGA();
for (i=0;i<=W.dy;i++)
{
for (j=0;j<=3;j++)
{
outportb(0x03C5,1 << j);
move(W.p[j],i*W.dx,0xA000,scrofs,W.dx);
}
scrofs=scrofs+BytesPerLine;
}
LockEGA();
if (Restore==0) for (i=0;i<=3;i++) freemem(W.p[i]);
}
char getimagedisk10(unsigned int x,unsigned int y,unsigned int dx,unsigned int dy,
Image *W)
{
unsigned int k,i,j,n,bufsize,xend,Buff,scrofs;
long t0,ll,l;
int f;
struct dfree free;
long avail;
int drive;
char Name[12];
void far *buff;
char *buffer;
xend=x+dx;
x=x >> 3;
if (xend % 8 != 0) xend=((xend >> 3) << 3)+8;
dx=xend-x;
W->dx=dx >> 3;
W->dy=dy;
l=(W->dy+1)*(W->dx)*(long)(4);
drive = getdisk()+1;
getdfree(drive, &free);
if (free.df_sclus == 0xFFFF) return(1);
avail = (long)free.df_avail*(long)free.df_bsec*(long)free.df_sclus;
l=avail-l;
if (l<10000) return(1);
randomize();
W->p[0]=rand();
itoa(W->p[0],Name,10);
_fmode=O_BINARY;
if ((f=creat(Name,0x0100 | 0x0080))==NULL) return(1);
l=coreleft();
if (l>0xFFF0) bufsize=0xFFF0; else bufsize=l;
bufsize=(bufsize-(bufsize % (W->dx*4)));
if (l>80) t0=allocmem(bufsize/16+1,&Buff); else return(1);
//if (t0!=-1) return(1);
buff=MK_FP(Buff,0);
scrofs=y*BytesPerLine+x;
outport(0x03CE,0x0005);
outportb(0x03CE,4);
k=0;
for (i=0;i<=W->dy;i++)
{
for (j=0;j<=3;j++)
{
outportb(0x03CF,j);
move(0xA000,scrofs,Buff,k,W->dx);
k=k+W->dx;
}
if (k==bufsize)
{
write(f,buff,bufsize);
k=0;
}
scrofs=scrofs+BytesPerLine;
}
if (k!=0) write(f,buff,k);
freemem(Buff);
close(f);
W->type=1;
return(0);
}
void putimagedisk10(unsigned int x,unsigned int y,Image W,char Restore)
{
unsigned int k,i,j,bufsize,scrofs,Buff;
long t0,l;
int f,b;
char Name[12];
void far *buff;
itoa(W.p[0],Name,10);
_fmode=O_BINARY;
if ((f=open(Name,0x0100 | 0x0080))==NULL) exit(0);
l= coreleft();
if (l>0xFFF0) bufsize=0xFFF0; else bufsize=l;
bufsize=(bufsize-(bufsize % (W.dx*4)));
if (l>80) t0=allocmem(bufsize/16+1,&Buff); else exit(0);
if (t0!=-1) exit(0);
buff=MK_FP(Buff,0);
scrofs=y*BytesPerLine+(x >> 3);
read(f,buff,bufsize);
k=0;
UnLockEGA();
for (i=0;i<=W.dy;i++)
{
for (j=0;j<=3;j++)
{
outportb(0x03C5,1 << j);
move(Buff,k,0xA000,scrofs,W.dx);
k=k+W.dx;
}
if (k==bufsize)
{
read(f,buff,bufsize);
k=0;
}
scrofs=scrofs+BytesPerLine;
}
LockEGA();
freemem(Buff);
close(f);
if (Restore==0) remove(Name);
}
char getimage10(unsigned int x,unsigned int y,unsigned int dx,unsigned int dy,Image *W)
{
if (getimageram10(x,y,dx,dy,W)==0) return(0);
return(getimagedisk10(x,y,dx,dy,W));
}
void putimage10(unsigned int x,unsigned int y,Image W,char Restore)
{
if (W.type==0) putimageram10(x,y,W,Restore);
if (W.type==1) putimagedisk10(x,y,W,Restore);
}
void windowshadow10(int x,int y,int dx,int dy)
{
unsigned int i,k,j,x1,y1,ofsp,ofspp;
char b;
x=(x >> 3) << 3;
dx=(dx >> 3) << 3;
x1=x+dx;
y1=y+dy;
x=x+10;
y=y+10;
ofsp=y*BytesPerLine+(x1 >> 3);
outport(0x03CE,0x0005);
outport(0x03CE,0x0007);
outport(0x03CE,0x0003);
for (i=1;i<=dy;i++)
{
outport(0x03CE,0x0005);
outport(0x03CE,0x0304);
b=peekb(0xA000,ofsp);
outport(0x03CE,0x0A05);
outportb(0x03CE,0x08);
outportb(0x03CF,b);
pokeb(0xA000,ofsp,peekb(0xA000,ofsp) & 7);
outportb(0x03CE,0x08);
outportb(0x03CF,~b);
pokeb(0xA000,ofsp,peekb(0xA000,ofsp) & 8);
ofsp=ofsp+BytesPerLine;
}
ofsp=(y1+1)*BytesPerLine+(x >> 3);
ofspp=ofsp;
outport(0x03CE,0x0005);
outport(0x03CE,0x0007);
outport(0x03CE,0x0003);
dx=(dx >> 3)-1;
for (i=1;i<=9;i++)
{
for (j=1;j<=dx;j++)
{
outport(0x03CE,0x0005);
outport(0x03CE,0x0304);
b=peekb(0xA000,ofsp);
outport(0x03CE,0x0A05);
outportb(0x03CE,0x08);
outportb(0x03CF,b);
pokeb(0xA000,ofsp,peekb(0xA000,ofsp) & 7);
outportb(0x03CE,0x08);
outportb(0x03CF,~b);
pokeb(0xA000,ofsp,peekb(0xA000,ofsp) & 8);
ofsp=ofsp+1;
}
ofspp=ofspp+BytesPerLine;
ofsp=ofspp;
}
LockEGA();
}
void screentoscreen10(int x,int y,int dx,int dy,int x1,int y1)
{
unsigned int ofsp,ofsp1,i,j;
outport(0x03CE,0x0105);
x=x >> 3;
x1=x1 >> 3;
dx=dx >> 3;
ofsp=y*BytesPerLine+x;
ofsp1=y1*BytesPerLine+x1;
for (i=y;i<=(y+dy);i++)
{
move(0xA000,ofsp,0xA000,ofsp1,dx);
ofsp=ofsp+BytesPerLine;
ofsp1=ofsp1+BytesPerLine;
}
outport(0x03CE,0x0005);
}