var x1,y1,x2,y2:word;
pocet:word;
pomX,pomY:word;
k:word;
procedure pause;assembler;
asm
xor ah,ah
int 16h
end;
procedure initMode(mode:word);assembler;
asm
mov ax,mode
int 10h
end;
procedure init_text;assembler;
asm
mov ax,02h
int 10h
end;
procedure pixel (x,y,barva:word);assembler;
asm
mov di,0A000h
mov es,di
mov di,y
mov bx,di
shl di,8
shl bx,6
add di,bx
ADD DI,X
MOV ax,barva
stosb
end;
procedure delit;assembler;
asm
mov ax,10
mov dx,2
mov cx,4
div Cx
end;
procedure swap_word(var w1,w2:word);
var pomocneTydyt:word;
begin
pomocneTydyt:=w1;
w1:=w2;
w2:=pomocneTydyt;
end;
procedure Drawline (x1, y1, x2, y2: integer; colour: byte);
assembler;
var difx, dify: integer;
d, inc1, inc2, inc3: integer;
asm
mov dx,03c4h
mov al,02h
out dx,al
@absolute_xdif:
mov ax,x1
sub ax,x2
cmp ax,0
jge @save_xdif
xor ax,0ffffh
inc ax
@save_xdif:
mov difx,ax
@absolute_ydif:
mov ax,y1
sub ax,y2
cmp ax,0
jge @save_ydif
xor ax,0ffffh
inc ax
@save_ydif:
mov dify,ax
@find_independant:
cld
mov ax,0a000h
mov es,ax
mov ax,difx
cmp ax,dify
jl @yindependant
@xindependant:
cmp difx,0
jz @line_done
mov ax,dify
shl ax,1
mov inc1,ax
mov ax,dify
sub ax,difx
shl ax,1
mov inc2,ax
mov ax,inc1
sub ax,difx
mov d,ax
mov ax,x2
cmp ax,x1
jg @noswapx
mov ax,x1
mov bx,x2
mov x1,bx
mov x2,ax
mov ax,y1
mov bx,y2
mov y1,bx
mov y2,ax
@noswapx:
mov inc3,80
mov ax,y2
cmp ax,y1
jg @xadd
mov inc3,-80
@xadd:
mov ax,80
mul y1
mov bx,ax
mov ax,x1
shr ax,1
shr ax,1
add ax,bx
mov di,ax
mov ax,x1
and al,3
xchg ah,al
mov cl,ah
mov al,1
shl al,cl
mov dx,03c5h
out dx,al
mov al,colour
mov bx,d
mov cx,difx
@loopx:
stosb
dec di
inc ah
cmp ah,4
jnz @xnoinc_di
xor ah,ah
inc di
@xnoinc_di:
push cx
mov ch,al
mov cl,ah
mov al,1
shl al,cl
out dx,al
mov al,ch
pop cx
cmp bx,0
jl @loopx_noinc
add bx,inc2
add di,inc3
loop @loopx
jmp @line_done
@loopx_noinc:
add bx,inc1
loop @loopx
jmp @line_done
@yindependant:
cmp dify,0
jz @line_done
mov ax,difx
shl ax,1
mov inc1,ax
mov ax,difx
sub ax,dify
shl ax,1
mov inc2,ax
mov ax,inc1
sub ax,dify
mov d,ax
mov ax,y2
cmp ax,y1
jg @noswapy
mov ax,x1
mov bx,x2
mov x1,bx
mov x2,ax
mov ax,y1
mov bx,y2
mov y1,bx
mov y2,ax
@noswapy:
mov inc3,1
mov ax,x2
cmp ax,x1
jg @yadd
mov inc3,-1
@yadd:
mov ax,80
mul y1
mov bx,ax
mov ax,x1
shr ax,1
shr ax,1
add ax,bx
mov di,ax
mov ax,x1
and al,3
xchg ah,al
mov cl,ah
mov al,1
shl al,cl
mov dx,03c5h
out dx,al
mov al,colour
mov bx,d
mov cx,dify
inc cx
@loopy:
stosb
add di,79
cmp bx,0
jl @loopy_noinc
add bx,inc2
cmp inc3,1
jz @inc3_pos
dec ah
cmp ah,255
jnz @ynoinc_di
add di,inc3
and ah,3
jmp @ynoinc_di
@inc3_pos:
inc ah
cmp ah,4
jnz @ynoinc_di
add di,inc3
and ah,3
@ynoinc_di:
push cx
mov ch,al
mov cl,ah
mov al,1
shl al,cl
out dx,al
mov al,ch
pop cx
loop @loopy
jmp @line_done
@loopy_noinc:
add bx,inc1
loop @loopy
jmp @line_done
@line_done:
end;
procedure line(x1,y1,x2,y2:word;barva:byte);assembler;
var flipped:boolean;
COLOR,DIFFx,DIFFy,DELT1,DELT2,dELT3,DELT4:word;
asm
PUSH SI
PUSH DI
PUSH DS
PUSH ES
MOV AX,X1
MOV BX,Y1
MOV SI,X2
MOV DI,Y2
MOV FLIPPED,0
MOV X1,AX
MOV Y1,BX
SUB AX,SI
CWD
XOR AX,DX
SUB AX,DX
MOV DIFFX,AX
MOV AX,BX
SUB AX,DI
CWD
XOR AX,DX
SUB AX,DX
MOV DIFFY,AX
CMP AX,DIFFX
JLE @NOFLIP
MOV FLIPPED,1
MOV DIFFX,AX
MOV AX,X1
MOV BX,Y1
MOV X1,BX
MOV Y1,AX
MOV AX,SI
MOV SI,DI
MOV DI,AX
@NOFLIP:
MOV X2,SI
MOV Y2,DI
MOV AX,X1
CMP AX,X2
JLE @NOFLIP2
MOV AX,Y2
MOV BX,Y1
MOV Y1,AX
MOV Y2,BX
MOV AX,X2
MOV BX,X1
MOV X2,BX
MOV X1,AX
@NOFLIP2:
MOV AX,Y2
SUB AX,Y1
MOV DIFFY,AX
SHL AX,1
MOV DELT2,AX
SUB AX,DIFFX
MOV DELT1,AX
MOV AX,DIFFY
SUB AX,DIFFX
SHL AX,1
MOV DELT3,AX
MOV AX,DIFFY
ADD AX,DIFFX
SHL AX,1
MOV DELT4,AX
@LINELP:
CMP FLIPPED,0
JNE @NO_FLIP3
MOV AX,X1
MOV BX,Y1
JMP @DL1
@NO_FLIP3:
MOV AX,Y1
MOV BX,X1
@DL1:
pushA
{ ;tady put Pixel: >}
mov di,0A000h
mov es,di
{ ;[es:di]ukazuje na ->[0a000h:0000]
;di = y
;dx = x
;al = barva
;320 = shl 1 o 8pozic + shl 1 o 6 pozic
;mem_POS = shl y,8 + shl y,6 + X
;jedu v ramci 0..319 = 320 pozic X,
}
mov bx,y1
mov dx,x1
shl di,8
shl bx,6
add di,bx
add di,dx
MOV Al,barva
stosb
popA
MOV AX,X1
CMP AX,X2
JGE @DLDONE
INC X1
CMP DELT1,0
JGE @DL2
CMP DIFFY,0
JGE @DL3
DEC Y1
MOV AX,DELT4
JMP @DL4
@DL2:
CMP DIFFY,0
JLE @DL3
INC Y1
MOV AX,DELT3
JMP @DL4
@DL3:
MOV AX,DELT2
@DL4:
ADD DELT1,AX
JMP @LINELP
@DLDONE:
POP ES
POP DS
POP DI
POP SI
end;
procedure svisla_C(x,y1,y2,barva:word);assembler;
asm
mov cx,y2
mov bx,y1 {a zaroven v dx zustane y1 i pro vypocet bodu [x,y1] v pameti}
sub cx,bx
mov di,0A000h
mov es,di
mov di,bx {v bx je jiz y1... urychleni reg -> reg a ne mem -> reg}
shl di,8
shl bx,6
add di,bx
ADD DI,X
MOV ax,barva
stosb {ted je teda bod [x,y1]}
mov bx,319
@tadaa:
add di,bx
stosb
loop @tadaa
end;
procedure vodorovna_C(x1,y,x2,barva:word);assembler;
asm
mov cx,x2
mov bx,x1
sub cx,bx {v cx je tedy delka vodorovne cary - tj.pocet pixelu}
mov di,0A000h
mov es,di
mov di,y {v bx je jiz y1... urychleni reg -> reg a ne mem -> reg}
mov bx,di
shl di,8 {a . 2^8 = a . 256}
shl bx,6 {a . 2^6 = a . 64}
add di,bx {a.(256+64)=a.320 ... tj. prenasobeni 320}
ADD DI,X1
MOV ax,barva
rep stosb {ted je teda bod [x,y1], v cx pocet opak -> vykresli}
end;
procedure Xline(x1,y1,x2,y2,barva:word);
var
xt:word;
drY:real;
dy:real;
dx,deltaX,deltaY:word;
begin
if (x2<x1)then begin swap_word(x2,x1);
swap_word(y2,y1);
end;
if y2>y1 then deltaY:=y2-y1 else deltaY:=y1-y2;
deltaX:=X2-X1;
dy:=deltaY/deltaX;
drY:=y1;
if y2>y1 then
for xt:=x1 to x2 do begin
pixel(xt,round(drY),barva);
drY := drY + dy;
if drY>200 then exit;
end
else
for xt:=x1 to x2 do begin
pixel(xt,round(drY),barva);
drY := drY - dy;
if drY<=0 then exit;
end;
end;
procedure ram_DISPLAY(BARVA:WORD);
BEGIN
vodorovna_C(5,5,315,barva);
svisla_c(5,5,195,barva);
vodorovna_C(5,195,315,barva);
svisla_c(315,5,195,barva);
END;
procedure ram(x1,y1,x2,y2,BARVA:WORD);
BEGIN
vodorovna_C(x1,y1,x2,barva);
svisla_c(x1,y1,y2,barva);
vodorovna_C(x1,y2,x2,barva);
svisla_c(x2,y1,y2,barva);
END;
procedure Xxline(x1,y1,x2,y2,barva:word);
var
p1x,p1y,xt:word;
drY:real;
dy,dx,deltaX,deltaY:word;
dilku:word;
delka_d:word;
begin
deltaY:=y2-y1; deltaX:= x2-x1;
dilku:= deltaY div deltaX + 1;
{ZDE vlozit 2 ruzne reseni-1) zvetsovat o 1pixel X a o N pixelu Y
a obracene}
p1x:=x1;
p1y:=y1;
delka_d:=deltaY div dilku;
for xt:=1 to dilku do begin
for p1y:=p1y to p1y+delka_d do pixel (p1x,p1y,barva);
inc(p1x);
end;
end;
procedure Xrline(x1,y1,x2,y2,barva:word);
var
p1x,p1y,xt:word;
drY:real;
dy,dx,deltaX,deltaY:word;
dilku:WORD;
delka_d:real;
begin
deltaY:=y2-y1; deltaX:= x2-x1;
dilku:= deltaY DIV deltaX + 1;
{ZDE vlozit 2 ruzne reseni-1) zvetsovat o 1pixel X a o N pixelu Y
a obracene}
p1x:=x1;
p1y:=y1;
delka_d:=deltaY / dilku;
for xt:=1 to dilku do begin
for p1y:=p1y to p1y+round(delka_d) do pixel (p1x,p1y,barva);
inc(p1x);
end;
end;
procedure delay(ms:word);assembler;
var pom:word;
asm
mov ah,00h
int 1ah
mov pom,dx {v pom je current takt od resetu}
xor dx,dx
mov ax,ms
mov bx,55
div bx
add pom,ax
@otocka:
int 1ah
cmp dx,pom
jae @vysk
jmp @otocka
@vysk:
end;
begin
WRITELN('ZMACKNI KLAVESU PRO DELAY');
pause;
FOR X1:=100 TO 180 do begin delay(x1);
writeln(x1);
end;
writeln('piii');
delay(500);
x1:=10;
y1:=10;
x2:=30;
y2:=100;
{InitMode($13);
drawline(1,1,300,190,3);
{line(1,1,300,190,3);}
{pause;}
{ram_display(64);
ram(50,50,70,90,87);
xline (x1,y1,x2,y2,94);
xxline(x1,y1,x2,y2,2);
xrline(x1,y1,x2,y2,3);
pause;
}
init_text;
delit;
end.