// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsImageStd.cpp
// Function: CCapsImageStd::DecodeDensity(DiskTrackInfo*, unsigned char*, unsigned int)
int CCapsImageStd::DecodeDensity(PDISKTRACKINFO pti, PUBYTE buf, UDWORD flag)
{
	// generate density
	switch (pti->ci.dentype) {
		case cpdenNoise:
			if (flag & DI_LOCK_DENNOISE)
				GenerateNoiseDensity(pti);
			break;

		case cpdenAuto:
			if (flag & DI_LOCK_DENAUTO)
				GenerateAutoDensity(pti);
			break;

		case cpdenCLAmiga:
			if (flag & DI_LOCK_DENVAR)
				GenerateCLA(pti, buf);
			break;

		case cpdenCLAmiga2:
			if (flag & DI_LOCK_DENVAR)
				GenerateCLA2(pti, buf);
			break;

		case cpdenCLST:
			if (flag & DI_LOCK_DENVAR)
				GenerateCLST(pti, buf);
			break;

		case cpdenSLAmiga:
			if (flag & DI_LOCK_DENVAR)
				GenerateSLA(pti, buf);
			break;

		case cpdenSLAmiga2:
			if (flag & DI_LOCK_DENVAR)
				GenerateSLA2(pti, buf);
			break;

		case cpdenABAmiga:
			if (flag & DI_LOCK_DENVAR)
				GenerateABA(pti, buf);
			break;

		case cpdenABAmiga2:
			if (flag & DI_LOCK_DENVAR)
				GenerateABA2(pti, buf);
			break;
	}

	// density map conversion
	if (flag & DI_LOCK_DENALT)
		ConvertDensity(pti);

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x108(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x8, %eax
ja 0xff05
movq -0x28(%rbp), %rax
leaq 0xe3d7(%rip), %rcx      # 0x1e1ac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x1c(%rbp), %eax
andq $0x10, %rax
cmpq $0x0, %rax
je 0xfdf8
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xff60
jmp 0xff05
movl -0x1c(%rbp), %eax
andq $0x8, %rax
cmpq $0x0, %rax
je 0xfe17
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x100b0
jmp 0xff05
movl -0x1c(%rbp), %eax
andq $0x4, %rax
cmpq $0x0, %rax
je 0xfe3a
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x101b0
jmp 0xff05
movl -0x1c(%rbp), %eax
andq $0x4, %rax
cmpq $0x0, %rax
je 0xfe5d
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x10380
jmp 0xff05
movl -0x1c(%rbp), %eax
andq $0x4, %rax
cmpq $0x0, %rax
je 0xfe80
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x10560
jmp 0xff05
movl -0x1c(%rbp), %eax
andq $0x4, %rax
cmpq $0x0, %rax
je 0xfea3
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x10680
jmp 0xff05
movl -0x1c(%rbp), %eax
andq $0x4, %rax
cmpq $0x0, %rax
je 0xfec3
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x107e0
jmp 0xff05
movl -0x1c(%rbp), %eax
andq $0x4, %rax
cmpq $0x0, %rax
je 0xfee3
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x10900
jmp 0xff05
movl -0x1c(%rbp), %eax
andq $0x4, %rax
cmpq $0x0, %rax
je 0xff03
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x10b30
jmp 0xff05
movl -0x1c(%rbp), %eax
andq $0x400, %rax            # imm = 0x400
cmpq $0x0, %rax
je 0xff21
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x10cc0
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)