data2 segment
data2 ends

data segment
 extrn temporary:byte,temporaryx:byte,temporaryy:byte,temporarycurrent:byte
data ends

code segment public byte
 assume cs:code
 public savedraw,draw,drawgridup,drawgridright,saveptext,ptext
 public newsavedraw,newdraw,newdrawgrid,show

savedraw proc far
 push bp
 push ds
 mov bp,sp
 assume ds:data,es:data2
 mov ax,data
 mov ds,ax
 mov ax,0a000h
 mov es,ax
 mov bx,0
 mov al,es:[bx]
 cld
 mov ax,[bp+20]
 mov bh,160d
 mul bh
 add ax,[bp+22]
 assume ds:data2,es:data
 mov si,ax
 mov ax,0a000h
 mov ds,ax
 mov ax,[bp+10]
 mov es,ax
 mov ax,[bp+8]
 mov di,ax
 mov dx,3ceh
 mov al,4
 out dx,al
 mov dx,3cfh

 mov al,0
 out dx,al
 mov cx,16d
gloop0: push cx
 mov cx,1
 rep movsw
 mov ax,si
 add ax,38d
 mov si,ax
 pop cx
 loop gloop0
 mov ax,si
 sub ax,640d
 mov si,ax

 mov al,1
 out dx,al
 mov cx,16d
gloop1: push cx
 mov cx,1
 rep movsw
 mov ax,si
 add ax,38d
 mov si,ax
 pop cx
 loop gloop1
 mov ax,si
 sub ax,640d
 mov si,ax

 mov al,2
 out dx,al
 mov cx,16d
gloop2: push cx
 mov cx,1
 rep movsw
 mov ax,si
 add ax,38d
 mov si,ax
 pop cx
 loop gloop2
 mov ax,si
 sub ax,640d
 mov si,ax

 mov al,3
 out dx,al
 mov cx,16d
gloop3: push cx
 mov cx,1
 rep movsw
 mov ax,si
 add ax,38d
 mov si,ax
 pop cx
 loop gloop3

 assume ds:data,es:data2
 mov ax,[bp+10]
 mov ds,ax
 mov ax,[bp+8]
 mov si,ax
 mov ax,[bp+12]
 mov di,ax
 mov ax,[bp+14]
 mov es,ax
 mov cx,64
 rep movsw
 mov ax,[bp+18]
 mov es,ax
 mov cx,32
cloop: push cx
 mov temporary,0
 mov bx,[bp+16]
 dec cx
 add bx,cx
 mov dh,cl

 mov al,es:[bx]
 mov ah,al
 mov cl,es:[bx+32]
 mov ch,es:[bx+64]
 mov dl,es:[bx+96]

 and al,10000000b
 jnz keep11
 mov al,cl
 and al,10000000b
 jnz keep11
 mov al,ch
 and al,10000000b
 jnz keep11
 mov al,dl
 and al,10000000b
 jnz keep11
 or temporary,10000000b

keep11: mov al,ah
 and al,01000000b
 jnz keep12
 mov al,cl
 and al,01000000b
 jnz keep12
 mov al,ch
 and al,01000000b
 jnz keep12
 mov al,dl
 and al,01000000b
 jnz keep12
 or temporary,01000000b

keep12: mov al,ah
 and al,00100000b
 jnz keep13
 mov al,cl
 and al,00100000b
 jnz keep13
 mov al,ch
 and al,00100000b
 jnz keep13
 mov al,dl
 and al,00100000b
 jnz keep13
 or temporary,00100000b

keep13: mov al,ah
 and al,00010000b
 jnz keep14
 mov al,cl
 and al,00010000b
 jnz keep14
 mov al,ch
 and al,00010000b
 jnz keep14
 mov al,dl
 and al,00010000b
 jnz keep14
 or temporary,00010000b

keep14: mov al,ah
 and al,00001000b
 jnz keep15
 mov al,cl
 and al,00001000b
 jnz keep15
 mov al,ch
 and al,00001000b
 jnz keep15
 mov al,dl
 and al,00001000b
 jnz keep15
 or temporary,00001000b

keep15: mov al,ah
 and al,00000100b
 jnz keep16
 mov al,cl
 and al,00000100b
 jnz keep16
 mov al,ch
 and al,00000100b
 jnz keep16
 mov al,dl
 and al,00000100b
 jnz keep16
 or temporary,00000100b

keep16: mov al,ah
 and al,00000010b
 jnz keep17
 mov al,cl
 and al,00000010b
 jnz keep17
 mov al,ch
 and al,00000010b
 jnz keep17
 mov al,dl
 and al,00000010b
 jnz keep17
 or temporary,00000010b

keep17: mov al,ah
 and al,00000001b
 jnz keep18
 mov al,cl
 and al,00000001b
 jnz keep18
 mov al,ch
 and al,00000001b
 jnz keep18
 mov al,dl
 and al,00000001b
 jnz keep18
 or temporary,00000001b
 jmp keep18

midcloop: jmp cloop

keep18: mov bh,0
 mov bl,dh
 add bx,[bp+8]
 mov al,temporary
 and ds:[bx],al
 and ds:[bx+32],al
 and ds:[bx+64],al
 and ds:[bx+96],al
 or ds:[bx],ah
 or ds:[bx+32],cl
 or ds:[bx+64],ch
 or ds:[bx+96],dl

 pop cx
 loop midcloop
 mov ax,[bp+20]
 mov bh,160d
 mul bh
 add ax,[bp+22]
 mov di,ax
 mov ax,0a000h
 mov es,ax
 mov ax,[bp+10]
 mov ds,ax
 mov ax,[bp+8]
 mov si,ax
 mov dx,3c4h
 mov al,2
 out dx,al
 mov dx,3c5h

 mov al,1
 out dx,al
 mov cx,16
zloop1: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop zloop1
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,2
 out dx,al
 mov cx,16
zloop2: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop zloop2
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,4
 out dx,al
 mov cx,16
zloop4: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop zloop4
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,8
 out dx,al
 mov cx,16
zloop8: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop zloop8

 mov sp,bp
 pop ds
 pop bp
 ret 16
savedraw endp

draw proc far
 push bp
 push ds
 mov bp,sp
 assume ds:data,es:data2
 mov ax,data
 mov ds,ax
 mov ax,0a000h
 mov es,ax
 mov bx,0
 mov al,es:[bx]
 cld
 mov ax,[bp+12]
 mov bh,160d
 mul bh
 add ax,[bp+14]
 mov di,ax
 mov ax,[bp+10]
 mov ds,ax
 mov ax,[bp+8]
 mov si,ax
 mov dx,3c4h
 mov al,2
 out dx,al
 mov dx,3c5h

 mov al,1
 out dx,al
 mov cx,16
drawloop1: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop drawloop1
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,2
 out dx,al
 mov cx,16
drawloop2: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop drawloop2
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,4
 out dx,al
 mov cx,16
drawloop4: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop drawloop4
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,8
 out dx,al
 mov cx,16
drawloop8: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop drawloop8

 mov sp,bp
 pop ds
 pop bp
 ret 8
draw endp

drawgridup proc far
 push bp
 push ds
 mov bp,sp
 assume ds:data,es:data2
 mov ax,data
 mov ds,ax
 mov ax,0a000h
 mov es,ax
 mov bx,0
 mov al,es:[bx]
 cld
 mov al,6d
 mov temporaryx,al
 mov temporaryy,al
 mov dl,temporaryx
 mov dh,temporaryy
 add dl,6d
 add dh,6d
 mov cx,11d
yloop: dec dh
 push cx
 mov cx,11d
xloop: dec dl
 mov ax,11d
 sub dh,1
 mul dh
 add dh,1
 push dx
 mov dh,0d
 sub dl,1
 add ax,dx
 pop dx
 mov bx,[bp+12]
 add bx,ax
 mov ax,[bp+14]
 mov es,ax
 mov al,es:[bx]
 mov temporarycurrent,al
 mov bl,dl
 add bl,5
 sub bl,temporaryx
 mov ax,2d
 mul bl
 push ax
 mov bl,dh
 mov bh,0
 add bl,5
 sub bl,temporaryy
 mov ax,640d
 push dx
 mul bx
 pop dx
 mov bx,ax
 pop ax
 add ax,bx
 mov di,ax
 push dx
 mov dx,[bp+8]
 mov bl,temporarycurrent
 mov ax,[bp+10]
 mov ds,ax
 mov ax,128d
 mul bl
 add ax,dx
 pop dx
 mov si,ax
 push cx
 push dx
 mov ax,0a000h
 mov es,ax
 mov dx,3c4h
 mov al,2
 out dx,al
 mov dx,3c5h

 mov al,1
 out dx,al
 mov cx,16
 jmp draw3loop1

middleway: jmp xloop

draw3loop1: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop draw3loop1
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,2
 out dx,al
 mov cx,16
 jmp draw3loop2

halfway: jmp yloop

draw3loop2: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop draw3loop2
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,4
 out dx,al
 mov cx,16
draw3loop4: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop draw3loop4
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,8
 out dx,al
 mov cx,16
draw3loop8: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop draw3loop8

 mov ax,data
 mov ds,ax
 pop dx
 pop cx
 loop middleway
 pop cx
 mov dl,temporaryx
 add dl,6d
 loop halfway
 mov sp,bp
 pop ds
 pop bp
 ret 8
drawgridup endp

drawgridright proc far
 push bp
 push ds
 mov bp,sp
 assume ds:data,es:data2
 mov ax,data
 mov ds,ax
 mov ax,0a000h
 mov es,ax
 mov bx,0
 mov al,es:[bx]
 cld
 mov al,6d
 mov temporaryx,al
 mov temporaryy,al
 mov dl,temporaryx
 mov dh,temporaryy
 add dl,6d
 add dh,6d
 mov cx,11d
yloopright: dec dl
 push cx
 mov cx,11d
xloopright: dec dh
 mov ax,11d
 sub dh,1
 mul dh
 add dh,1
 push dx
 mov dh,0d
 sub dl,1
 add ax,dx
 pop dx
 mov bx,[bp+12]
 add bx,ax
 mov ax,[bp+14]
 mov es,ax
 mov al,es:[bx]
 mov temporarycurrent,al
 mov bl,dl
 add bl,5
 sub bl,temporaryx
 mov ax,2d
 mul bl
 push ax
 mov bl,dh
 mov bh,0
 add bl,5
 sub bl,temporaryy
 mov ax,640d
 push dx
 mul bx
 pop dx
 mov bx,ax
 pop ax
 add ax,bx
 mov di,ax
 push dx
 mov dx,[bp+8]
 mov bl,temporarycurrent
 mov ax,[bp+10]
 mov ds,ax
 mov ax,128d
 mul bl
 add ax,dx
 pop dx
 mov si,ax
 push cx
 push dx
 mov ax,0a000h
 mov es,ax
 mov dx,3c4h
 mov al,2
 out dx,al
 mov dx,3c5h

 mov al,1
 out dx,al
 mov cx,16
 jmp draw4loop1

middlewayright: jmp xloop

draw4loop1: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop draw4loop1
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,2
 out dx,al
 mov cx,16
 jmp draw4loop2

halfwayright: jmp yloop

draw4loop2: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop draw4loop2
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,4
 out dx,al
 mov cx,16
draw4loop4: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop draw4loop4
 mov ax,di
 sub ax,640d
 mov di,ax

 mov al,8
 out dx,al
 mov cx,16
draw4loop8: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,38d
 mov di,ax
 pop cx
 loop draw4loop8

 mov ax,data
 mov ds,ax
 pop dx
 pop cx
 loop middlewayright
 pop cx
 mov dh,temporaryy
 add dh,6d
 loop halfwayright
 mov sp,bp
 pop ds
 pop bp
 ret 8
drawgridright endp

saveptext proc far
 push bp
 push ds
 mov bp,sp
 assume ds:data,es:data2
 mov ax,data
 mov ds,ax
 mov ax,0a000h
 mov es,ax
 mov bx,0
 mov al,[bx]
 cld
 mov ax,[bp+20]
 mov bh,160d
 mul bh
 add ax,[bp+22]
 assume ds:data2,es:data
 mov si,ax
 mov ax,0a000h
 mov ds,ax
 mov ax,[bp+10]
 mov es,ax
 mov ax,[bp+8]
 mov di,ax
 mov dx,3ceh
 mov al,4
 out dx,al
 mov dx,3cfh

 mov al,0
 out dx,al
 mov cx,8d
g2loop0: push cx
 mov cx,1
 rep movsb
 mov ax,si
 add ax,39d
 mov si,ax
 pop cx
 loop g2loop0
 mov ax,si
 sub ax,320d
 mov si,ax

 mov al,1
 out dx,al
 mov cx,8d
g2loop1: push cx
 mov cx,1
 rep movsb
 mov ax,si
 add ax,39d
 mov si,ax
 pop cx
 loop g2loop1
 mov ax,si
 sub ax,320d
 mov si,ax

 mov al,2
 out dx,al
 mov cx,8d
g2loop2: push cx
 mov cx,1
 rep movsb
 mov ax,si
 add ax,39d
 mov si,ax
 pop cx
 loop g2loop2
 mov ax,si
 sub ax,320d
 mov si,ax

 mov al,3
 out dx,al
 mov cx,8d
g2loop3: push cx
 mov cx,1
 rep movsb
 mov ax,si
 add ax,39d
 mov si,ax
 pop cx
 loop g2loop3

 assume ds:data,es:data2
 mov ax,[bp+10]
 mov ds,ax
 mov ax,[bp+8]
 mov si,ax
 mov ax,[bp+12]
 mov di,ax
 mov ax,[bp+14]
 mov es,ax
 mov cx,16
 rep movsw
 mov ax,[bp+18]
 mov es,ax
 mov cx,8
c2loop: push cx
 mov temporary,0
 mov bx,[bp+16]
 dec cx
 add bx,cx
 mov dh,cl

 mov al,es:[bx]
 mov ah,al
 mov cl,es:[bx+8]
 mov ch,es:[bx+16]
 mov dl,es:[bx+24]

 and al,10000000b
 jnz keep1
 mov al,cl
 and al,10000000b
 jnz keep1
 mov al,ch
 and al,10000000b
 jnz keep1
 mov al,dl
 and al,10000000b
 jnz keep1
 or temporary,10000000b

keep1: mov al,ah
 and al,01000000b
 jnz keep2
 mov al,cl
 and al,01000000b
 jnz keep2
 mov al,ch
 and al,01000000b
 jnz keep2
 mov al,dl
 and al,01000000b
 jnz keep2
 or temporary,01000000b

keep2: mov al,ah
 and al,00100000b
 jnz keep3
 mov al,cl
 and al,00100000b
 jnz keep3
 mov al,ch
 and al,00100000b
 jnz keep3
 mov al,dl
 and al,00100000b
 jnz keep3
 or temporary,00100000b

keep3: mov al,ah
 and al,00010000b
 jnz keep4
 mov al,cl
 and al,00010000b
 jnz keep4
 mov al,ch
 and al,00010000b
 jnz keep4
 mov al,dl
 and al,00010000b
 jnz keep4
 or temporary,00010000b

keep4: mov al,ah
 and al,00001000b
 jnz keep5
 mov al,cl
 and al,00001000b
 jnz keep5
 mov al,ch
 and al,00001000b
 jnz keep5
 mov al,dl
 and al,00001000b
 jnz keep5
 or temporary,00001000b

keep5: mov al,ah
 and al,00000100b
 jnz keep6
 mov al,cl
 and al,00000100b
 jnz keep6
 mov al,ch
 and al,00000100b
 jnz keep6
 mov al,dl
 and al,00000100b
 jnz keep6
 or temporary,00000100b

keep6: mov al,ah
 and al,00000010b
 jnz keep7
 mov al,cl
 and al,00000010b
 jnz keep7
 mov al,ch
 and al,00000010b
 jnz keep7
 mov al,dl
 and al,00000010b
 jnz keep7
 or temporary,00000010b

keep7: mov al,ah
 and al,00000001b
 jnz keep8
 mov al,cl
 and al,00000001b
 jnz keep8
 mov al,ch
 and al,00000001b
 jnz keep8
 mov al,dl
 and al,00000001b
 jnz keep8
 or temporary,00000001b
 jmp keep8

mid2cloop: jmp c2loop

keep8: mov bh,0
 mov bl,dh
 add bx,[bp+8]
 mov al,temporary
 and ds:[bx],al
 and ds:[bx+8],al
 and ds:[bx+16],al
 and ds:[bx+24],al
 or ds:[bx],ah
 or ds:[bx+8],cl
 or ds:[bx+16],ch
 or ds:[bx+24],dl

 pop cx
 loop mid2cloop
 mov ax,[bp+20]
 mov bh,160d
 mul bh
 add ax,[bp+22]
 mov di,ax
 mov ax,0a000h
 mov es,ax
 mov ax,[bp+10]
 mov ds,ax
 mov ax,[bp+8]
 mov si,ax
 mov dx,3c4h
 mov al,2
 out dx,al
 mov dx,3c5h

 mov al,1
 out dx,al
 mov cx,8
z2loop1: push cx
 mov cx,1
 rep movsb
 mov ax,di
 add ax,39d
 mov di,ax
 pop cx
 loop z2loop1
 mov ax,di
 sub ax,320d
 mov di,ax

 mov al,2
 out dx,al
 mov cx,8
z2loop2: push cx
 mov cx,1
 rep movsb
 mov ax,di
 add ax,39d
 mov di,ax
 pop cx
 loop z2loop2
 mov ax,di
 sub ax,320d
 mov di,ax

 mov al,4
 out dx,al
 mov cx,8
z2loop4: push cx
 mov cx,1
 rep movsb
 mov ax,di
 add ax,39d
 mov di,ax
 pop cx
 loop z2loop4
 mov ax,di
 sub ax,320d
 mov di,ax

 mov al,8
 out dx,al
 mov cx,8
z2loop8: push cx
 mov cx,1
 rep movsb
 mov ax,di
 add ax,39d
 mov di,ax
 pop cx
 loop z2loop8

 mov sp,bp
 pop ds
 pop bp
 ret 16
saveptext endp

ptext proc far
 push bp
 push ds
 mov bp,sp
 assume ds:data,es:data2
 mov ax,data
 mov ds,ax
 mov ax,0a000h
 mov es,ax
 mov bx,0
 mov al,es:[bx]
 cld
 mov ax,[bp+12]
 mov bh,160d
 mul bh
 add ax,[bp+14]
 mov di,ax
 mov ax,[bp+10]
 mov ds,ax
 mov ax,[bp+8]
 mov si,ax
 mov dx,3c4h
 mov al,2
 out dx,al
 mov dx,3c5h

 mov al,1
 out dx,al
 mov cx,8
draw2loop1: push cx
 mov cx,1
 rep movsb
 mov ax,di
 add ax,39d
 mov di,ax
 pop cx
 loop draw2loop1
 mov ax,di
 sub ax,320d
 mov di,ax

 mov al,2
 out dx,al
 mov cx,8
draw2loop2: push cx
 mov cx,1
 rep movsb
 mov ax,di
 add ax,39d
 mov di,ax
 pop cx
 loop draw2loop2
 mov ax,di
 sub ax,320d
 mov di,ax

 mov al,4
 out dx,al
 mov cx,8
draw2loop4: push cx
 mov cx,1
 rep movsb
 mov ax,di
 add ax,39d
 mov di,ax
 pop cx
 loop draw2loop4
 mov ax,di
 sub ax,320d
 mov di,ax

 mov al,8
 out dx,al
 mov cx,8
draw2loop8: push cx
 mov cx,1
 rep movsb
 mov ax,di
 add ax,39d
 mov di,ax
 pop cx
 loop draw2loop8

 mov sp,bp
 pop ds
 pop bp
 ret 8
ptext endp

newsavedraw proc far
 push bp
 push ds
 mov bp,sp
 assume ds:data,es:data2
 mov ax,data
 mov ds,ax
 cld
 mov ax,[bp+20]
 mov bh,88d
 mul bh
 add ax,[bp+22]
 add ax,[bp+24]
 assume ds:data2,es:data
 mov si,ax
 mov ax,[bp+26]
 mov ds,ax
 mov ax,[bp+10]
 mov es,ax
 mov ax,[bp+8]
 mov di,ax

 mov cx,16d
newgloop0: push cx
 mov cx,1
 rep movsw
 mov ax,si
 add ax,20d
 mov si,ax
 pop cx
 loop newgloop0
 mov ax,si
 add ax,3520d
 mov si,ax

 mov cx,16d
newgloop1: push cx
 mov cx,1
 rep movsw
 mov ax,si
 add ax,20d
 mov si,ax
 pop cx
 loop newgloop1
 mov ax,si
 add ax,3520d
 mov si,ax

 mov cx,16d
newgloop2: push cx
 mov cx,1
 rep movsw
 mov ax,si
 add ax,20d
 mov si,ax
 pop cx
 loop newgloop2
 mov ax,si
 add ax,3520d
 mov si,ax

 mov cx,16d
newgloop3: push cx
 mov cx,1
 rep movsw
 mov ax,si
 add ax,20d
 mov si,ax
 pop cx
 loop newgloop3

 assume ds:data,es:data2
 mov ax,[bp+10]
 mov ds,ax
 mov ax,[bp+8]
 mov si,ax
 mov ax,[bp+12]
 mov di,ax
 mov ax,[bp+14]
 mov es,ax
 mov cx,64
 rep movsw
 mov ax,[bp+18]
 mov es,ax
 mov cx,32
newcloop: push cx
 mov temporary,0
 mov bx,[bp+16]
 dec cx
 add bx,cx
 mov dh,cl

 mov al,es:[bx]
 mov ah,al
 mov cl,es:[bx+32]
 mov ch,es:[bx+64]
 mov dl,es:[bx+96]

 and al,10000000b
 jnz newkeep11
 mov al,cl
 and al,10000000b
 jnz newkeep11
 mov al,ch
 and al,10000000b
 jnz newkeep11
 mov al,dl
 and al,10000000b
 jnz newkeep11
 or temporary,10000000b

newkeep11: mov al,ah
 and al,01000000b
 jnz newkeep12
 mov al,cl
 and al,01000000b
 jnz newkeep12
 mov al,ch
 and al,01000000b
 jnz newkeep12
 mov al,dl
 and al,01000000b
 jnz newkeep12
 or temporary,01000000b

newkeep12: mov al,ah
 and al,00100000b
 jnz newkeep13
 mov al,cl
 and al,00100000b
 jnz newkeep13
 mov al,ch
 and al,00100000b
 jnz newkeep13
 mov al,dl
 and al,00100000b
 jnz newkeep13
 or temporary,00100000b

newkeep13: mov al,ah
 and al,00010000b
 jnz newkeep14
 mov al,cl
 and al,00010000b
 jnz newkeep14
 mov al,ch
 and al,00010000b
 jnz newkeep14
 mov al,dl
 and al,00010000b
 jnz newkeep14
 or temporary,00010000b

newkeep14: mov al,ah
 and al,00001000b
 jnz newkeep15
 mov al,cl
 and al,00001000b
 jnz newkeep15
 mov al,ch
 and al,00001000b
 jnz newkeep15
 mov al,dl
 and al,00001000b
 jnz newkeep15
 or temporary,00001000b

newkeep15: mov al,ah
 and al,00000100b
 jnz newkeep16
 mov al,cl
 and al,00000100b
 jnz newkeep16
 mov al,ch
 and al,00000100b
 jnz newkeep16
 mov al,dl
 and al,00000100b
 jnz newkeep16
 or temporary,00000100b

newkeep16: mov al,ah
 and al,00000010b
 jnz newkeep17
 mov al,cl
 and al,00000010b
 jnz newkeep17
 mov al,ch
 and al,00000010b
 jnz newkeep17
 mov al,dl
 and al,00000010b
 jnz newkeep17
 or temporary,00000010b

newkeep17: mov al,ah
 and al,00000001b
 jnz newkeep18
 mov al,cl
 and al,00000001b
 jnz newkeep18
 mov al,ch
 and al,00000001b
 jnz newkeep18
 mov al,dl
 and al,00000001b
 jnz newkeep18
 or temporary,00000001b
 jmp newkeep18

newmidcloop: jmp newcloop

newkeep18: mov bh,0
 mov bl,dh
 add bx,[bp+8]
 mov al,temporary
 and ds:[bx],al
 and ds:[bx+32],al
 and ds:[bx+64],al
 and ds:[bx+96],al
 or ds:[bx],ah
 or ds:[bx+32],cl
 or ds:[bx+64],ch
 or ds:[bx+96],dl

 pop cx
 loop newmidcloop
 mov ax,[bp+20]
 mov bh,88d
 mul bh
 add ax,[bp+22]
 add ax,[bp+24]
 mov di,ax
 mov ax,[bp+26]
 mov es,ax
 mov ax,[bp+10]
 mov ds,ax
 mov ax,[bp+8]
 mov si,ax

 mov cx,16
newzloop1: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newzloop1
 mov ax,di
 add ax,3520d
 mov di,ax

 mov cx,16
newzloop2: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newzloop2
 mov ax,di
 add ax,3520d
 mov di,ax

 mov cx,16
newzloop4: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newzloop4
 mov ax,di
 add ax,3520d
 mov di,ax

 mov cx,16
newzloop8: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newzloop8

 mov sp,bp
 pop ds
 pop bp
 ret 20
newsavedraw endp

newdraw proc far
 push bp
 push ds
 mov bp,sp
 assume ds:data,es:data2
 mov ax,data
 mov ds,ax
 cld
 mov ax,[bp+12]
 mov bh,88d
 mul bh
 add ax,[bp+14]
 add ax,[bp+16]
 mov di,ax
 mov ax,[bp+18]
 mov es,ax
 mov ax,[bp+10]
 mov ds,ax
 mov ax,[bp+8]
 mov si,ax

 mov cx,16
newdrawloop1: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newdrawloop1
 mov ax,di
 add ax,3520d
 mov di,ax

 mov cx,16
newdrawloop2: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newdrawloop2
 mov ax,di
 add ax,3520d
 mov di,ax

 mov cx,16
newdrawloop4: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newdrawloop4
 mov ax,di
 add ax,3520d
 mov di,ax

 mov cx,16
newdrawloop8: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newdrawloop8

 mov sp,bp
 pop ds
 pop bp
 ret 12
newdraw endp

newdrawgrid proc far
 push bp
 push ds
 mov bp,sp
 assume ds:data,es:data2
 mov ax,data
 mov ds,ax
 mov ax,0a000h
 mov es,ax
 mov bx,0
 mov al,es:[bx]
 cld
 mov al,6d
 mov temporaryx,al
 mov temporaryy,al
 mov dl,temporaryx
 mov dh,temporaryy
 add dl,6d
 add dh,6d
 mov cx,11d
newyloop: dec dh
 push cx
 mov cx,11d
newxloop: dec dl
 mov ax,11d
 sub dh,1
 mul dh
 add dh,1
 push dx
 mov dh,0d
 sub dl,1
 add ax,dx
 pop dx
 mov bx,[bp+12]
 add bx,ax
 mov ax,[bp+14]
 mov es,ax
 mov al,es:[bx]
 mov temporarycurrent,al
 mov bl,dl
 add bl,5
 sub bl,temporaryx
 mov ax,2d
 mul bl
 push ax
 mov bl,dh
 mov bh,0
 add bl,5
 sub bl,temporaryy
 mov ax,352d
 push dx
 mul bx
 pop dx
 mov bx,ax
 pop ax
 add ax,bx
 add ax,[bp+16]
 mov di,ax
 push dx
 mov dx,[bp+8]
 mov bl,temporarycurrent
 mov ax,[bp+10]
 mov ds,ax
 mov ax,128d
 mul bl
 add ax,dx
 pop dx
 mov si,ax
 push cx
 push dx
 mov ax,[bp+18]
 mov es,ax

 mov cx,16
 jmp newdraw3loop1

newmiddleway: jmp newxloop

newdraw3loop1: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newdraw3loop1
 mov ax,di
 add ax,3520d
 mov di,ax

 mov cx,16
 jmp newdraw3loop2

newhalfway: jmp newyloop

newdraw3loop2: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newdraw3loop2
 mov ax,di
 add ax,3520d
 mov di,ax

 mov cx,16
newdraw3loop4: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newdraw3loop4
 mov ax,di
 add ax,3520d
 mov di,ax

 mov cx,16
newdraw3loop8: push cx
 mov cx,1
 rep movsw
 mov ax,di
 add ax,20d
 mov di,ax
 pop cx
 loop newdraw3loop8

 mov ax,data
 mov ds,ax
 pop dx
 pop cx
 loop newmiddleway
 pop cx
 mov dl,temporaryx
 add dl,6d
 loop newhalfway
 mov sp,bp
 pop ds
 pop bp
 ret 12
newdrawgrid endp

show proc far
 push bp
 push ds
 mov bp,sp
 assume ds:data,es:data2
 mov ax,[bp+10]
 mov ds,ax
 mov ax,[bp+8]
 mov si,ax
 mov ax,0d
 mov di,ax
 mov ax,0a000h
 mov es,ax
 mov bx,0
 mov al,es:[bx]
 cld
 mov dx,3c4h
 mov al,2
 out dx,al
 mov dx,3c5h

 mov cx,176d
newsloop: push cx

 mov al,1
 out dx,al
 mov cx,11d
 rep movsw
 mov ax,si
 add ax,3850d
 mov si,ax
 mov ax,di
 sub ax,22d
 mov di,ax

 mov al,2
 out dx,al
 mov cx,11d
 rep movsw
 mov ax,si
 add ax,3850d
 mov si,ax
 mov ax,di
 sub ax,22d
 mov di,ax

 mov al,4
 out dx,al
 mov cx,11d
 rep movsw
 mov ax,si
 add ax,3850d
 mov si,ax
 mov ax,di
 sub ax,22d
 mov di,ax

 mov al,8
 out dx,al
 mov cx,11d
 rep movsw
 mov ax,di
 add ax,18d
 mov di,ax
 mov ax,si
 sub ax,11616d
 mov si,ax

 pop cx
 loop newsloop

 mov sp,bp
 pop ds
 pop bp
 ret 4
show endp

code ends

end
