// File: OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsAPI.cpp
// Function: CAPSGetImageInfo(CapsImageInfo*, int)
SDWORD __cdecl CAPSGetImageInfo(PCAPSIMAGEINFO pi, SDWORD id)
{
	if (!pi)
		return imgeGeneric;

	memset(pi, 0, sizeof(CapsImageInfo));

	if (id<0 || (unsigned)id >= img.size() || !img[id])
		return imgeOutOfRange;

	PDISKIMAGEINFO pd=img[id]->GetInfo();
	if (!pd)
		return imgeGeneric;

	// convert image info
	if (pd->civalid) {
		// use image info if available
		switch (pd->ci.type) {
			case cpimtFDD:
				pi->type = ciitFDD;
				break;

			default:
				pi->type = ciitNA;
				break;
		}

		pi->release = pd->ci.release;
		pi->revision = pd->ci.revision;
		pi->mincylinder = pd->ci.mincylinder;
		pi->maxcylinder = pd->ci.maxcylinder;
		pi->minhead = pd->ci.minhead;
		pi->maxhead = pd->ci.maxhead;
		CDiskImage::DecodeDateTime(&pi->crdt, &pd->ci.crdt);

		for (int plt = 0; plt < CAPS_MAXPLATFORM; plt++)
			pi->platform[plt] = pd->ci.platform[plt];
	} else {
		// image info not available
		if (pd->dmpcount) {
			// if there is at least one track dumped use dump information
			pi->type = ciitFDD;
			pi->release = 0;
			pi->revision = 0;
			pi->mincylinder = pd->umincylinder;
			pi->maxcylinder = pd->umaxcylinder;
			pi->minhead = pd->uminhead;
			pi->maxhead = pd->umaxhead;
		}	else {
			// invalid image type if not a dumped image and there is no information available
			pi->type = ciitNA;
		}
	}

	return imgeOk;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x70d2
movl $0x2, -0x4(%rbp)
jmp 0x72a0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0x4140
cmpl $0x0, -0x14(%rbp)
jl 0x711d
movl -0x14(%rbp), %eax
movq %rax, -0x30(%rbp)
leaq 0x2145a(%rip), %rdi     # 0x28550
callq 0x8100
movq %rax, %rcx
movq -0x30(%rbp), %rax
cmpq %rcx, %rax
jae 0x711d
movslq -0x14(%rbp), %rsi
leaq 0x2143e(%rip), %rdi     # 0x28550
callq 0x8120
cmpq $0x0, (%rax)
jne 0x7129
movl $0x3, -0x4(%rbp)
jmp 0x72a0
movslq -0x14(%rbp), %rsi
leaq 0x2141c(%rip), %rdi     # 0x28550
callq 0x8120
movq (%rax), %rdi
callq 0x81b0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x7158
movl $0x2, -0x4(%rbp)
jmp 0x72a0
movq -0x20(%rbp), %rax
cmpl $0x0, 0x40(%rax)
je 0x7229
movq -0x20(%rbp), %rax
movl 0x44(%rax), %eax
subl $0x1, %eax
jne 0x7180
jmp 0x7174
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
jmp 0x718a
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x20(%rbp), %rax
movl 0x54(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x20(%rbp), %rax
movl 0x5c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movl 0x60(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movl 0x64(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x20(%rbp), %rax
movl 0x68(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rdi
addq $0x1c, %rdi
movq -0x20(%rbp), %rsi
addq $0x44, %rsi
addq $0x28, %rsi
callq 0x188e0
movl $0x0, -0x24(%rbp)
cmpl $0x4, -0x24(%rbp)
jge 0x7227
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl 0x74(%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl %edx, 0x38(%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x71fe
jmp 0x7299
movq -0x20(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x728d
movq -0x10(%rbp), %rax
movl $0x1, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x20(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x20(%rbp), %rax
movl 0x24(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
jmp 0x7297
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
jmp 0x7299
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)