	.data

C	struc
	Msk	dw	?
	Opcode	dw	?
	Len	db	?
	Spec	db	?
	ends

Opcodes	C	<0fch,88h,-12,scNorm>
	C	<0fdh,8ch,-12,scNorm>
	C	<0feh,86h,-12,scNorm>
	C	<0feh,0c4h,-12,scNorm>
	C	<0feh,84h,-12,scNorm>
	C	<0fch,0d0h,-12,scNorm>
	C	<0c4h,0,-12,scNorm>
	C	<0ffh,62h,-12,scNorm>
	C	<0f8h,0d8h,-12,scNorm>
	C	<0ffh,8dh,-12,scNorm>
	C	<38ffh,30ffh,-12,scNorm>
	C	<38ffh,008fh,-12,scNorm>
	C	<30feh,00feh,-12,scNorm>
	C	<20feh,20f6h,-12,scNorm>
	C	<30feh,10f6h,-12,scNorm>
	C	<30ffh,10ffh,-12,scInd+scCall>
	C	<30ffh,20ffh,-12,scInd+scJmp>
	C	<0fch,80h,-24,scNorm>
	C	<0c6h,4,-16,scNorm>
	C	<0feh,0a8h,-16,scNorm>
	C	<0f8h,90h,1,scNorm>
	C	<0e7h,27h,1,scNorm>
	C	<0ffh,0d7h,1,scNorm>
	C	<0ffh,0c8h,4,scNorm>
	C	<0ffh,0c9h,1,scNorm>
	C	<0fcffh,034cdh,-28,scInt>
	C	<0fcffh,038cdh,-28,scInt>
	C	<0ffffh,03ccdh,-36,scInt>
	C	<0ffffh,03dcdh,2,scInt>
	C	<0ffh,0cdh,2,scInt>
	C	<0ffh,0cch,1,scNorm>
	C	<0ffh,0ceh,1,scNorm>
	C	<0ffh,9bh,1,scNorm>
	C	<0ffh,0ebh,-2,scJmp>
	C	<0f0h,70h,-2,scJcc>
	C	<0fch,0e0h,-2,scJcc>
	C	<0ffh,0e9h,-4,scJmp>
	C	<0ffh,0e8h,-4,scCall>
	C	<0ffh,0eah,-6,scJmp>
	C	<0ffh,9ah,-6,scCall>
	C	<0e7h,26h,0,scNorm>
	C	<0feh,0f2h,0,scNorm>
	C	<0f7h,0c3h,1,scRet>
	C	<0f7h,0c2h,3,scRet>
	C	<0ffh,0cfh,1,scRet>
	C	<0fffeh,0ad4h,2,scNorm>
	C	<0feh,6ch,-30,scNorm>
	C	<0feh,6eh,-32,scNorm>
	C	<0feh,0a6h,-34,scNorm>
	C	<0feh,0a4h,-34,scNorm>
	C	<0feh,0ach,-32,scNorm>
	C	<0feh,0aeh,-30,scNorm>
	C	<0feh,0aah,-30,scNorm>
	C	<0ffffh,060fh,2,scNorm>
	C	<0c6ffh,800fh,1,scNorm>
	C	<0feh,60h,1,scNorm>
	C	<0feh,0fch,1,scNorm>
	C	<0feh,0f4h,1,scNorm>
	C	<0feh,98h,1,scNorm>
	C	<0fch,0ech,1,scNorm>
	C	<0fch,0e4h,2,scNorm>
	C	<0fch,0f8h,1,scNorm>
	C	<0fch,9ch,1,scNorm>
	C	<0f0h,50h,1,scNorm>
	C	<0f0h,40h,1,scNorm>
	C	<0fch,0a0h,-38,scNorm>
	C	<0e6h,6,1,scNorm>
	C	<0feh,0c0h,-14,scNorm>
	C	<38feh,00c6h,-22,scNorm>
	C	<38feh,00f6h,-22,scNorm>
	C	<0fdh,69h,-26,scNorm>
	C	<0ffffh,0af0fh,-28,scNorm>
	C	<0fdh,68h,-18,scNorm>
	C	<0f0h,0b0h,-20,scNorm>
	C	<0ffh,0f0h,0,scNorm>
	C	<0f8h,0d8h,-12,scNorm>
	C	<0,0,1,scNorm>
OpLen	equ	($-Opcodes)/6

SegPrefix	dw	0

	.code

Disasm	proc	near
	xor	dx,dx
	mov	SegPrefix,dx
@@1:	mov	bx,es:[di]
	lea	si,Opcodes
	mov	cx,OpLen
@@2:	lodsw
	and	ax,bx
	cmp	ax,[si-2].Opcode
	je	@@3
	add	si,size C-2
	loop	@@2
	mov	cx,1
	xor	ax,ax
	ret
@@3:	mov	cl,[si-2].Len
	xor	ch,ch
	mov	al,[si-2].Spec
	xor	ah,ah
	and	cl,cl
	jle	@@5
	add	cx,dx
@@4:	ret
@@5:	jz	@@7
	dec	ch
	mov	si,cx
	neg	si
	add	si,offset @@Tbl
	jmp	word ptr cs:[si]
@@Tbl	dw	@@7,@@10,@@11,@@12,@@4,@@4,@@19,@@18
	dw	@@24,@@26,@@28,@@17,@@16,@@15,@@14,@@30
	dw	@@31,@@35,@@13,@@32
@@7:	mov	al,es:[di]
	inc	di
	inc	dx
	cmp	al,26h
	je	@@9
	cmp	al,2eh
	je	@@8
	cmp	al,26h
	jne	@@1
@@8:	mov	SegPrefix,-1
	jmp	@@1
@@9:	mov	SegPrefix,7
	jmp	@@1
@@10:	mov	bx,ax
	mov	al,es:[di+1]
	cbw
	xchg	ax,bx
	lea	di,[bx+di+2]
	mov	cx,2
	add	cx,dx
	ret
@@11:	mov	bx,es:[di+1]
	lea	di,[bx+di+3]
	mov	cx,3
	add	cx,dx
	ret
@@12:	les	di,es:[di+1]
	mov	cx,5
	add	cx,dx
	ret
@@13:	inc	di
	inc	dx
	mov	bl,es:[di+1]
	and	bl,0f0h
	cmp	bl,20h
	jne	@@14
	inc	dx
	add	cx,dx
	ret
@@14:	inc	di
	jmp	short @@18
@@15:	test	byte ptr es:[di],2
	jnz	@@18
	inc	dx
	jmp	short @@18
@@16:	test	byte ptr es:[di],2
	jnz	@@18
@@17:	inc	dx
	test	byte ptr es:[di],1
	jz	@@19
@@18:	inc	dx
@@19:	and	ax,ax
	jnz	@@21
	mov	cx,SegPrefix
	and	cx,cx
	jl	@@21
	mov	bl,es:[di+1]
	cmp	bl,0c0h
	jae	@@21
	jcxz	@@20
	or	ax,cx
	jmp	short @@21
@@20:	and	bl,0c7h
	cmp	bl,6
	je	@@21
	and	bl,7
	cmp	bl,2
	je	@@21
	cmp	bl,3
	je	@@21
	cmp	bl,6
	je	@@21
	or	ax,6
@@21:	mov	bl,es:[di+1]
	and	bl,0c7h
@@22:	mov	cx,2
	cmp	bl,0c0h
	jae	@@23
	mov	cx,4
	cmp	bl,80h
	jae	@@23
	cmp	bl,6
	je	@@23
	dec	cx
	cmp	bl,40h
	jae	@@23
	dec	cx
@@23:	add	cx,dx
	ret
@@24:	mov	cx,2
	test	byte ptr es:[di],1
	jz	@@25
	inc	cx
@@25:	ret
@@26:	mov	cx,2
	test	byte ptr es:[di],2
	jnz	@@27
	inc	cx
@@27:	ret
@@28:	mov	cx,2
	test	byte ptr es:[di],8
	jz	@@29
	inc	cx
@@29:	ret
@@30:	mov	ax,scES
	mov	cx,dx
	inc	cx
	ret
@@31:	mov	cx,1
	jmp	short @@33
@@32:	mov	cx,3
@@33:	mov	ax,SegPrefix
	cmp	ax,7
	je	@@30
	inc	ax
	jz	@@34
	mov	ax,scDS
@@34:	add	cx,dx
	ret
@@35:	mov	ax,SegPrefix
	cmp	ax,7
	je	@@30
	inc	ax
	jz	@@30
	mov	ax,scBoth
	mov	cx,dx
	inc	cx
	ret
Disasm	endp
