LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsAPI.cpp
// Function: CAPSUnlockTrack(int, unsigned int, unsigned int)
SDWORD __cdecl CAPSUnlockTrack(SDWORD id, UDWORD cylinder, UDWORD head)
{
	if (id<0 || (unsigned)id >= img.size() || !img[id])
		return imgeOutOfRange;

	PDISKTRACKINFO pt=img[id]->UnlockTrack(cylinder, head);

	return pt ? imgeOk : imgeOutOfRange;
}

// Assembly:
movl $0x3, %eax
testl %edi, %edi
js 0x61c6
movl %edi, %ecx
movq 0x14385(%rip), %r8      # 0x1a518
movq 0x14376(%rip), %rdi     # 0x1a510
subq %rdi, %r8
sarq $0x3, %r8
cmpq %rcx, %r8
jbe 0x61c6
movq (%rdi,%rcx,8), %rdi
testq %rdi, %rdi
je 0x61c6
pushq %rax
xorl %ecx, %ecx
callq 0xe9aa
xorl %ecx, %ecx
testq %rax, %rax
sete %cl
leal (%rcx,%rcx,2), %eax
addq $0x8, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsAPI.cpp
// Function: CAPSUnlockAllTracks(int)
SDWORD __cdecl CAPSUnlockAllTracks(SDWORD id)
{
	if (id<0 || (unsigned)id >= img.size() || !img[id])
		return imgeOutOfRange;

	img[id]->UnlockTrack();

	return imgeOk;
}

// Assembly:
pushq %rbx
movl $0x3, %ebx
testl %edi, %edi
js 0x61ff
movl %edi, %eax
movq 0x1433e(%rip), %rdx     # 0x1a518
movq 0x1432f(%rip), %rcx     # 0x1a510
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rax, %rdx
jbe 0x61ff
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
je 0x61ff
xorl %ebx, %ebx
xorl %esi, %esi
callq 0xe8f6
movl %ebx, %eax
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsAPI.cpp
// Function: CAPSGetVersionInfo(void*, unsigned int)
SDWORD __cdecl CAPSGetVersionInfo(PVOID pversioninfo, UDWORD flag)
{
	if (!pversioninfo)
		return imgeGeneric;

	// structure revision is zero, unless newer one requested
	unsigned rev=0;
	if (flag & DI_LOCK_TYPE)
		rev=*(PUDWORD)pversioninfo;

	// if unsupported type set the highest supported version
	if (rev > 0) {
		*(PUDWORD)pversioninfo=0;
		return imgeUnsupportedType;
	}

	// clear structure
	memset(pversioninfo, 0, sizeversioninfo[rev]);

	// get the correct structure
	switch (rev) {
		case 0:
			CAPSGetVersionInfoT0((PCAPSVERSIONINFO)pversioninfo);
			break;
	}

	return imgeOk;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x6255
movq %rdi, %rbx
btl $0x9, %esi
jae 0x622b
cmpl $0x0, (%rbx)
je 0x622b
movl $0x0, (%rbx)
movl $0xf, %ebp
jmp 0x625a
movslq 0x12ff2(%rip), %rdx     # 0x19224
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4140
movabsq $0x100000005, %rax      # imm = 0x100000005
movq %rax, 0x4(%rbx)
movl $0x7fff, 0xc(%rbx)      # imm = 0x7FFF
jmp 0x625a
movl $0x2, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsAPI.cpp
// Function: CAPSGetInfo(void*, int, unsigned int, unsigned int, unsigned int, unsigned int)
SDWORD __cdecl CAPSGetInfo(PVOID pinfo, SDWORD id, UDWORD cylinder, UDWORD head, UDWORD inftype, UDWORD infid)
{
	if (!pinfo)
		return imgeGeneric;

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

	PDISKIMAGEINFO pd = img[id]->GetInfo();
	PDISKTRACKINFO pt = img[id]->GetTrack(cylinder, head);

	int res=imgeUnsupportedType;

	switch (inftype) {
		case cgiitSector:
			res=CAPSGetSectorInfo((PCAPSSECTORINFO)pinfo, pd, pt, infid);
			break;

		case cgiitWeak:
			res=CAPSGetWeakInfo((PCAPSDATAINFO)pinfo, pd, pt, infid);
			break;

		case cgiitRevolution:
			res = CAPSGetRevolutionInfo((PCAPSREVOLUTIONINFO)pinfo, pd, pt, infid);
			break;
	}

	return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x631a
movl $0x3, %ebp
testl %esi, %esi
js 0x631f
movq %rdi, %rbx
movl %esi, %eax
movq 0x14272(%rip), %rdi     # 0x1a518
movq 0x14263(%rip), %rsi     # 0x1a510
subq %rsi, %rdi
sarq $0x3, %rdi
cmpq %rax, %rdi
jbe 0x631f
movq (%rsi,%rax,8), %rdi
testq %rdi, %rdi
je 0x631f
movl %r9d, %r14d
movl %r8d, %r15d
leaq 0x8(%rdi), %rax
movl 0x8(%rdi), %r13d
xorl %r12d, %r12d
testl %r13d, %r13d
cmovneq %rax, %r12
movl %edx, %esi
movl %ecx, %edx
callq 0xebc6
cmpl $0x3, %r15d
je 0x6383
cmpl $0x2, %r15d
je 0x6330
movl $0xf, %ebp
cmpl $0x1, %r15d
jne 0x631f
movq %rbx, %rdi
movq %rax, %rdx
movl %r14d, %ecx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x63c8
movl $0x2, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, 0x8(%rbx)
movq $0x0, (%rbx)
testq %rax, %rax
je 0x631f
movl 0xd0(%rax), %ecx
testl %ecx, %ecx
jle 0x631f
movq 0xd8(%rax), %rax
testq %rax, %rax
sete %dl
cmpl %r14d, %ecx
setbe %cl
orb %dl, %cl
jne 0x631f
movl %r14d, %ecx
leaq (%rcx,%rcx,2), %rcx
movl $0x1, (%rbx)
movl 0x4(%rax,%rcx,4), %edx
movl %edx, 0x4(%rbx)
movl 0x8(%rax,%rcx,4), %eax
movl %eax, 0x8(%rbx)
xorl %ebp, %ebp
jmp 0x631f
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
testl %r13d, %r13d
je 0x63a5
movl 0x34(%r12), %ecx
movl %ecx, (%rbx)
movl 0x38(%r12), %ecx
movl %ecx, 0x4(%rbx)
movl 0x3c(%r12), %ecx
movl %ecx, 0x8(%rbx)
xorl %ebp, %ebp
testq %rax, %rax
je 0x631f
cmpl $0x0, 0x44(%rax)
je 0x63bb
movl 0x2c(%rax), %eax
jmp 0x63c0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0xc(%rbx)
jmp 0x631f
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsAPI.cpp
// Function: CAPSGetSectorInfo(CapsSectorInfo*, DiskImageInfo*, DiskTrackInfo*, unsigned int)
int CAPSGetSectorInfo(PCAPSSECTORINFO pi, PDISKIMAGEINFO pd, PDISKTRACKINFO pt, UDWORD infid)
{
	memset(pi, 0, sizeof(CapsSectorInfo));

	if (!pt)
		return imgeOutOfRange;

	if (pt->sipsize <= 0 || !pt->sip)
		return imgeOutOfRange;

	if (infid >= (unsigned)pt->sipsize)
		return imgeOutOfRange;

	PDISKSECTORINFO si=pt->sip+infid;

	pi->descdatasize=si->descdatasize;
	pi->descgapsize=si->descgapsize;
	pi->datasize=si->datasize;
	pi->gapsize=si->gapsize;
	pi->datastart=si->datastart;
	pi->gapstart=si->gapstart;
	pi->gapsizews0=si->gapsizews0;
	pi->gapsizews1=si->gapsizews1;
	pi->gapws0mode=si->gapws0mode;
	pi->gapws1mode=si->gapws1mode;
	pi->celltype=si->celltype;
	pi->enctype=si->enctype;

	return imgeOk;
}

// Assembly:
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
movl $0x3, %eax
testq %rdx, %rdx
je 0x6465
movl 0xf4(%rdx), %esi
testl %esi, %esi
jle 0x6465
movq 0xf8(%rdx), %rdx
testq %rdx, %rdx
sete %r8b
cmpl %ecx, %esi
setbe %sil
orb %r8b, %sil
jne 0x6465
movl %ecx, %eax
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movl (%rdx,%rax), %ecx
movl %ecx, (%rdi)
movl 0x4(%rdx,%rax), %ecx
movl %ecx, 0x4(%rdi)
movl 0x8(%rdx,%rax), %ecx
movl %ecx, 0x8(%rdi)
movl 0xc(%rdx,%rax), %ecx
movl %ecx, 0xc(%rdi)
movl 0x10(%rdx,%rax), %ecx
movl %ecx, 0x10(%rdi)
movl 0x14(%rdx,%rax), %ecx
movl %ecx, 0x14(%rdi)
movl 0x18(%rdx,%rax), %ecx
movl %ecx, 0x18(%rdi)
movl 0x1c(%rdx,%rax), %ecx
movl %ecx, 0x1c(%rdi)
movl 0x20(%rdx,%rax), %ecx
movl %ecx, 0x20(%rdi)
movl 0x24(%rdx,%rax), %ecx
movl %ecx, 0x24(%rdi)
movl 0x28(%rdx,%rax), %ecx
movl %ecx, 0x28(%rdi)
movl 0x2c(%rdx,%rax), %eax
movl %eax, 0x2c(%rdi)
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsAPI.cpp
// Function: CAPSGetWeakInfo(CapsDataInfo*, DiskImageInfo*, DiskTrackInfo*, unsigned int)
int CAPSGetWeakInfo(PCAPSDATAINFO pi, PDISKIMAGEINFO pd, PDISKTRACKINFO pt, UDWORD infid)
{
	memset(pi, 0, sizeof(CapsDataInfo));

	if (!pt)
		return imgeOutOfRange;

	if (pt->fdpsize <= 0 || !pt->fdp)
		return imgeOutOfRange;

	if (infid >= (unsigned)pt->fdpsize)
		return imgeOutOfRange;

	PDISKDATAMARK dm=pt->fdp+infid;

	pi->type=cditWeak;
	pi->start=dm->position;
	pi->size=dm->size;

	return imgeOk;
}

// Assembly:
movl $0x0, 0x8(%rdi)
movq $0x0, (%rdi)
movl $0x3, %eax
testq %rdx, %rdx
je 0x64bd
movl 0xd0(%rdx), %esi
testl %esi, %esi
jle 0x64bd
movq 0xd8(%rdx), %rdx
testq %rdx, %rdx
sete %r8b
cmpl %ecx, %esi
setbe %sil
orb %r8b, %sil
jne 0x64bd
movl %ecx, %eax
leaq (%rax,%rax,2), %rax
movl $0x1, (%rdi)
movl 0x4(%rdx,%rax,4), %ecx
movl %ecx, 0x4(%rdi)
movl 0x8(%rdx,%rax,4), %eax
movl %eax, 0x8(%rdi)
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsAPI.cpp
// Function: CAPSGetRevolutionInfo(CapsRevolutionInfo*, DiskImageInfo*, DiskTrackInfo*, unsigned int)
int CAPSGetRevolutionInfo(PCAPSREVOLUTIONINFO pi, PDISKIMAGEINFO pd, PDISKTRACKINFO pt, UDWORD infid)
{
	memset(pi, 0, sizeof(CapsRevolutionInfo));

	// set image data if image is valid
	if (pd) {
		// next, last and real revolution used by lock track
		pi->next = pd->nextrev;
		pi->last = pd->lastrev;
		pi->real = pd->realrev;
	}

	// set track data if track is valid
	if (pt) {
		// use the revolutions sampled for raw dumps, -1 (unlimited/randomized) otherwise
		pi->max = (pt->rawdump) ? pt->rawtrackcnt : -1;
	}

	return imgeOk;
}

// Assembly:
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
testq %rsi, %rsi
je 0x64da
movl 0x34(%rsi), %eax
movl %eax, (%rdi)
movl 0x38(%rsi), %eax
movl %eax, 0x4(%rdi)
movl 0x3c(%rsi), %eax
movl %eax, 0x8(%rdi)
testq %rdx, %rdx
je 0x64f2
cmpl $0x0, 0x44(%rdx)
je 0x64ea
movl 0x2c(%rdx), %eax
jmp 0x64ef
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0xc(%rdi)
xorl %eax, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsAPI.cpp
// Function: CAPSSetRevolution(int, unsigned int)
SDWORD __cdecl CAPSSetRevolution(SDWORD id, UDWORD value)
{
	if (id<0 || (unsigned)id >= img.size() || !img[id])
		return imgeOutOfRange;

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

	// set revolution
	pd->nextrev = value;

	return imgeOk;
}

// Assembly:
movl $0x3, %eax
testl %edi, %edi
js 0x652e
movl %edi, %ecx
movq 0x14011(%rip), %rdi     # 0x1a518
movq 0x14002(%rip), %rdx     # 0x1a510
subq %rdx, %rdi
sarq $0x3, %rdi
cmpq %rcx, %rdi
jbe 0x652e
movq (%rdx,%rcx,8), %rcx
testq %rcx, %rcx
je 0x652e
cmpl $0x0, 0x8(%rcx)
je 0x652f
movl %esi, 0x3c(%rcx)
xorl %eax, %eax
retq
movl $0x2, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsAPI.cpp
// Function: CAPSGetImageTypeMemory(unsigned char*, unsigned int)
SDWORD __cdecl CAPSGetImageTypeMemory(PUBYTE buffer, UDWORD length)
{
	CapsFile cf;
	memset(&cf, 0, sizeof(CapsFile));
	cf.memmap = buffer;
	cf.size = length;
	cf.flag |= CFF_MEMMAP | CFF_MEMREF;

	// get the possible image type used by the file
	return imgfactory.GetImageType(&cf);
}

// Assembly:
subq $0x18, %rsp
xorps %xmm0, %xmm0
movq %rsp, %rax
movaps %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rdi, 0x8(%rax)
movl %esi, 0x14(%rax)
movb $0x6, 0x10(%rax)
movq %rax, %rdi
callq 0xf37c
addq $0x18, %rsp
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComT1_SpinupLoop(CapsFdc*)
void FdcComT1_SpinupLoop(PCAPSFDC pc)
{
	// clock cycles to complete
	UDWORD cmax=pc->clockreq-pc->clockact;

	// if no drive selected run all cycles index can't happen
	if (!pc->driveprc) {
		FdcComIdle(pc, cmax);
		return;
	}

	// if index can't happen on enabled drive run all cycles
	PCAPSDRIVE pd=pc->driveprc;
	if ((pd->diskattr & CAPSDRIVE_DA_IPMASK) != CAPSDRIVE_DA_IPMASK) {
		FdcComIdle(pc, cmax);
		return;
	}

	// if index or spin-up event won't happen, run it all
	if ((pd->idistance+cmax<pd->clockrev) || (pc->spinupcnt+1 < pc->spinuplimit)){
		FdcComIdle(pc, cmax);
		return;
	}

	// cycles until index
	cmax=pd->clockrev-pd->idistance;

	// index and spin-up happens now, only run cycles until index
	if (FdcComIdle(pc, cmax) != cmax)
		return;

	// end loop, but only if wait was complete
	pc->runstate++;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x10(%rdi), %esi
subl 0xc(%rdi), %esi
movq 0x100(%rdi), %rcx
testq %rcx, %rcx
je 0x6793
movl 0x20(%rcx), %eax
notl %eax
testb $0x5, %al
jne 0x6793
movl 0x24(%rcx), %eax
movl 0x28(%rcx), %ebp
leal (%rax,%rsi), %ecx
cmpl %ebp, %ecx
jb 0x6793
movl 0xa4(%rbx), %ecx
incl %ecx
cmpl 0xa8(%rbx), %ecx
jge 0x67a1
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x796e
subl %eax, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x796e
cmpl %ebp, %eax
jne 0x67b4
incl 0x2c(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComT1_VerifyStart(CapsFdc*)
void FdcComT1_VerifyStart(PCAPSFDC pc)
{
	// reset logic
	FdcResetData(pc);

	// set abort on maximum revolutions for verify
	pc->indexlimit=pc->verifylimit;

	// set loop
	pc->runstate++;
}

// Assembly:
xorl %eax, %eax
movl %eax, 0x50(%rdi)
movabsq $0x300000000, %rcx      # imm = 0x300000000
movq %rcx, 0x5c(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x6c(%rdi)
movl %eax, 0x7c(%rdi)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x80(%rdi)
movl %eax, 0x88(%rdi)
movl %eax, 0x94(%rdi)
movabsq $0x200000200, %rax      # imm = 0x200000200
movq %rax, 0x64(%rdi)
movq $0x0, 0x8c(%rdi)
movl 0xa0(%rdi), %eax
movl %eax, 0x98(%rdi)
incl 0x2c(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComT1_VerifyLoop(CapsFdc*)
void FdcComT1_VerifyLoop(PCAPSFDC pc)
{
	// update data access
	FdcUpdateData(pc);

	// get access hook, crc
	FDCREAD ph=FdcGetReadAccess(pc);

	// clock cycles to complete
	UDWORD cst=pc->clockact;

	// process requested cycles
	while (!pc->endrequest && pc->clockact<pc->clockreq) {
		// read byte when ready
		if (!ph(pc))
			continue;

		// check ID
		switch (pc->dataphase) {
			case 0:
				// AM detected, read returns on dsr ready
				pc->amisigmask=CAPSFDC_AI_DSRREADY;
				pc->dataphase++;
				break;

			case 1:
				//if not fc...ff, restart
				if (pc->dsr < 0xfc) {
					FdcResetAm(pc);
					continue;
				}

				pc->dataphase++;
				break;

			case 2:
				//if not the track, restart
				if (pc->dsr != pc->r_track) {
					FdcResetAm(pc);
					continue;
				}

				pc->dataphase++;
				break;

			// skip rest ofID
			case 3:
			case 4:
			case 5:
			case 6:
				pc->dataphase++;
				break;

			case 7:
				// if crc error, set crc flag, restart
				if (pc->crc & 0xffff) {
					FdcResetAm(pc);
					pc->r_st0|=CAPSFDC_SR_CRCERR;
					continue;
				}

				// clear crc flag, stop
				pc->r_st0&=~CAPSFDC_SR_CRCERR;

				// run cycles used on unselected drives
				FdcComIdleOther(pc, pc->clockact-cst);

				// end
				pc->endrequest|=CAPSFDC_ER_COMEND;
				return;

			default:
				NODEFAULT;
		}
	}

	// end requested, set seek error
	if (pc->endrequest & CAPSFDC_ER_COMEND)
		pc->r_st0|=CAPSFDC_SR_RNF;

	// run cycles on unselected drives
	FdcComIdleOther(pc, pc->clockact-cst);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x7a4d
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %ebp
testl %eax, %eax
jne 0x6ab3
movl 0xc(%rbx), %ecx
cmpl 0x10(%rbx), %ecx
jae 0x6ab3
movslq 0x84(%rbx), %rax
leaq 0x12010(%rip), %rcx     # 0x18a00
movq (%rcx,%rax,8), %r14
leaq 0xb681(%rip), %r15      # 0x1207c
movq %rbx, %rdi
callq *%r14
testl %eax, %eax
je 0x6a23
movl 0x8c(%rbx), %eax
movslq (%r15,%rax,4), %rcx
addq %r15, %rcx
jmpq *%rcx
movl $0x100, 0x64(%rbx)      # imm = 0x100
incl %eax
movl %eax, 0x8c(%rbx)
movl 0x8(%rbx), %eax
testl %eax, %eax
jne 0x6ab3
movl 0xc(%rbx), %ecx
cmpl 0x10(%rbx), %ecx
jb 0x69fb
jmp 0x6ab3
cmpw $0x0, 0x54(%rbx)
je 0x6ad2
movl 0x60(%rbx), %eax
andl $-0x10, %eax
orl $0x3, %eax
movl %eax, 0x60(%rbx)
movl $0x200, 0x64(%rbx)      # imm = 0x200
movq $0x0, 0x8c(%rbx)
orb $0x8, 0x30(%rbx)
jmp 0x6a23
cmpl $0xfb, 0x78(%rbx)
jbe 0x6a90
movl $0x2, 0x8c(%rbx)
jmp 0x6a23
movl 0x78(%rbx), %eax
cmpl 0x40(%rbx), %eax
jne 0x6a90
movl $0x3, 0x8c(%rbx)
jmp 0x6a23
movl 0x60(%rbx), %eax
andl $-0x10, %eax
orl $0x3, %eax
movl %eax, 0x60(%rbx)
movl $0x200, 0x64(%rbx)      # imm = 0x200
movq $0x0, 0x8c(%rbx)
jmp 0x6a23
testb $0x1, %al
je 0x6abb
orb $0x10, 0x30(%rbx)
movl 0xc(%rbx), %esi
subl %ebp, %esi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x7b57
andb $-0x9, 0x30(%rbx)
movl 0xc(%rbx), %esi
subl %ebp, %esi
movq %rbx, %rdi
callq 0x7b57
orb $0x1, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComT3_IndexLoop(CapsFdc*)
void FdcComT3_IndexLoop(PCAPSFDC pc)
{
	// clock cycles to complete
	UDWORD cmax=pc->clockreq-pc->clockact;

	// if no drive selected run all cycles index can't happen
	if (!pc->driveprc) {
		FdcComIdle(pc, cmax);
		return;
	}

	// if index can't happen on enabled drive run all cycles
	PCAPSDRIVE pd=pc->driveprc;
	if ((pd->diskattr & CAPSDRIVE_DA_IPMASK) != CAPSDRIVE_DA_IPMASK) {
		FdcComIdle(pc, cmax);
		return;
	}

	// if index event won't happen, run it all
	if (pd->idistance+cmax < pd->clockrev){
		FdcComIdle(pc, cmax);
		return;
	}

	// cycles until index
	cmax=pd->clockrev-pd->idistance;

	// index happens now, only run cycles until index
	if (FdcComIdle(pc, cmax) != cmax)
		return;

	// end loop, but only if wait was complete
	pc->runstate++;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x10(%rdi), %esi
subl 0xc(%rdi), %esi
movq 0x100(%rdi), %rax
testq %rax, %rax
je 0x6e89
movl 0x20(%rax), %ecx
notl %ecx
testb $0x5, %cl
jne 0x6e89
movl 0x24(%rax), %ecx
movl 0x28(%rax), %ebp
leal (%rcx,%rsi), %eax
cmpl %ebp, %eax
jae 0x6e97
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x796e
subl %ecx, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x796e
cmpl %ebp, %eax
jne 0x6eaa
incl 0x2c(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComT3_ReadStart(CapsFdc*)
void FdcComT3_ReadStart(PCAPSFDC pc)
{
	// reset logic
	FdcResetData(pc);
	pc->aminfo&=~CAPSFDC_AI_CRCENABLE;
	pc->amisigmask=CAPSFDC_AI_DSRREADY;

	// abort on next index
	pc->indexlimit=1;

	// set loop
	pc->runstate++;
}

// Assembly:
xorl %eax, %eax
movl %eax, 0x50(%rdi)
movaps 0xb283(%rip), %xmm0     # 0x12140
movups %xmm0, 0x5c(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x6c(%rdi)
movl %eax, 0x7c(%rdi)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x80(%rdi)
movl %eax, 0x88(%rdi)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x94(%rdi)
movq $0x0, 0x8c(%rdi)
movabsq $0x20000000001, %rax    # imm = 0x20000000001
movq %rax, 0x60(%rdi)
movl $0x100, 0x64(%rdi)      # imm = 0x100
incl 0x2c(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComT3_ReadLoop(CapsFdc*)
void FdcComT3_ReadLoop(PCAPSFDC pc)
{
	// update data access
	FdcUpdateData(pc);

	// get access hook, crc
	FDCREAD ph=FdcGetReadAccess(pc);

	// clock cycles to complete
	UDWORD cst=pc->clockact;

	// process requested cycles
	while (!pc->endrequest && pc->clockact<pc->clockreq) {
		// read byte when ready
		if (!ph(pc))
			continue;

		// dsr to data, drq signal
		pc->r_data=pc->dsr;
		FdcSetLine(pc, pc->lineout|CAPSFDC_LO_DRQSET);
	}

	// run cycles on unselected drives
	FdcComIdleOther(pc, pc->clockact-cst);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
callq 0x7a4d
movl 0xc(%rbx), %ebp
cmpl $0x0, 0x8(%rbx)
jne 0x6f65
movslq 0x84(%rbx), %rax
leaq 0x11acb(%rip), %rcx     # 0x18a00
movq (%rcx,%rax,8), %r14
movl 0xc(%rbx), %eax
cmpl 0x10(%rbx), %eax
jae 0x6f65
movq %rbx, %rdi
callq *%r14
testl %eax, %eax
je 0x6f5f
movl 0x24(%rbx), %esi
movl 0x78(%rbx), %eax
movl %eax, 0x48(%rbx)
orl $0x40, %esi
movq %rbx, %rdi
callq 0x7725
cmpl $0x0, 0x8(%rbx)
je 0x6f39
movl 0xc(%rbx), %esi
subl %ebp, %esi
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x7b57
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComT3_WriteStart(CapsFdc*)
void FdcComT3_WriteStart(PCAPSFDC pc)
{
	// reset logic
	FdcResetData(pc);

	// abort on next index
	pc->indexlimit=1;

	// set loop
	pc->runstate++;
}

// Assembly:
xorl %eax, %eax
movl %eax, 0x50(%rdi)
movabsq $0x300000000, %rcx      # imm = 0x300000000
movq %rcx, 0x5c(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x6c(%rdi)
movl %eax, 0x7c(%rdi)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0x80(%rdi)
movl %eax, 0x88(%rdi)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x94(%rdi)
movabsq $0x200000200, %rax      # imm = 0x200000200
movq %rax, 0x64(%rdi)
movq $0x0, 0x8c(%rdi)
incl 0x2c(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComT3_AddressLoop(CapsFdc*)
void FdcComT3_AddressLoop(PCAPSFDC pc)
{
	// update data access
	FdcUpdateData(pc);

	// get access hook, crc
	FDCREAD ph=FdcGetReadAccess(pc);

	// clock cycles to complete
	UDWORD cst=pc->clockact;

	// process requested cycles
	while (!pc->endrequest && pc->clockact<pc->clockreq) {
		// read byte when ready
		if (!ph(pc))
			continue;

		// check ID
		switch (pc->dataphase) {
			// detect a1 sync
			case 0:
				// AM detected, read returns on dsr ready
				pc->amisigmask=CAPSFDC_AI_DSRREADY;
				pc->dataphase++;
				break;

			case 1:
				//if not fc...ff, restart
				if (pc->dsr < 0xfc) {
					FdcResetAm(pc);
					continue;
				}

				pc->dataphase++;
				break;

			case 2:
				// set the sector register to the track number
				pc->r_sector=pc->dsr;

			case 3:
			case 4:
			case 5:
			case 6:
			case 7:
				// dsr to data, drq signal
				pc->r_data=pc->dsr;
				FdcSetLine(pc, pc->lineout|CAPSFDC_LO_DRQSET);

				// next phase
				if (pc->dataphase++ == 7) {
					// if crc error, set crc flag
					if (pc->crc & 0xffff)
						pc->r_st0|=CAPSFDC_SR_CRCERR;

					// run cycles used on unselected drives
					FdcComIdleOther(pc, pc->clockact-cst);

					// end
					pc->endrequest|=CAPSFDC_ER_COMEND;
					return;
				}
				break;

			default:
				NODEFAULT;
		}
	}

	// end requested, set seek error
	if (pc->endrequest & CAPSFDC_ER_COMEND)
		pc->r_st0|=CAPSFDC_SR_RNF;

	// run cycles on unselected drives
	FdcComIdleOther(pc, pc->clockact-cst);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x7a4d
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %ebp
testl %eax, %eax
jne 0x70c9
movl 0xc(%rbx), %ecx
cmpl 0x10(%rbx), %ecx
jae 0x70c9
movslq 0x84(%rbx), %rax
leaq 0x119e2(%rip), %rcx     # 0x18a00
movq (%rcx,%rax,8), %r14
leaq 0xb0af(%rip), %r15      # 0x120d8
movq %rbx, %rdi
callq *%r14
testl %eax, %eax
je 0x706a
movl 0x8c(%rbx), %eax
movslq (%r15,%rax,4), %rcx
addq %r15, %rcx
jmpq *%rcx
movl 0x24(%rbx), %esi
movl 0x78(%rbx), %eax
movl %eax, 0x48(%rbx)
orl $0x40, %esi
movq %rbx, %rdi
callq 0x7725
movl 0x8c(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x8c(%rbx)
cmpl $0x7, %eax
je 0x70e8
movl 0x8(%rbx), %eax
testl %eax, %eax
jne 0x70c9
movl 0xc(%rbx), %ecx
cmpl 0x10(%rbx), %ecx
jb 0x7029
jmp 0x70c9
movl $0x100, 0x64(%rbx)      # imm = 0x100
incl %eax
movl %eax, 0x8c(%rbx)
jmp 0x706a
cmpl $0xfb, 0x78(%rbx)
ja 0x70bd
movl 0x60(%rbx), %eax
andl $-0x10, %eax
orl $0x3, %eax
movl %eax, 0x60(%rbx)
movl $0x200, 0x64(%rbx)      # imm = 0x200
movq $0x0, 0x8c(%rbx)
jmp 0x706a
movl 0x78(%rbx), %eax
movl %eax, 0x44(%rbx)
jmp 0x7042
movl $0x2, 0x8c(%rbx)
jmp 0x706a
testb $0x1, %al
je 0x70d1
orb $0x10, 0x30(%rbx)
movl 0xc(%rbx), %esi
subl %ebp, %esi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x7b57
cmpw $0x0, 0x54(%rbx)
je 0x70f3
orb $0x8, 0x30(%rbx)
movl 0xc(%rbx), %esi
subl %ebp, %esi
movq %rbx, %rdi
callq 0x7b57
orb $0x1, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcSetTiming(CapsFdc*)
void FdcSetTiming(PCAPSFDC pc)
{
	// drive specific values
	for (int drv=0; drv < pc->drivecnt; drv++) {
		PCAPSDRIVE pd=pc->drive+drv;

		// clock cycles per revolution
		pd->clockrev=UDWORD(((UQUAD)pc->clockfrq*60)/pd->rpm);

		// clock cycles for index pulse hold
		pd->clockip=UDWORD(((UQUAD)pc->clockfrq*pc->iptime)/1000000);
	}

	// clock cycles for stepping rates
	for (int drv=0; drv < 4; drv++)
		pc->clockstep[drv]=UDWORD(((UQUAD)pc->clockfrq*pc->steptime[drv])/1000000);

	// clock cycles for head settling
	pc->clockhs=UDWORD(((UQUAD)pc->clockfrq*pc->hstime)/1000000);

	// clock cycles for short operations (some SR updates)
	pc->clockupdate=UDWORD(((UQUAD)pc->clockfrq*pc->updatetime)/1000000);
}

// Assembly:
pushq %rbx
movslq 0xec(%rdi), %r10
movabsq $0x431bde82d7b634db, %r8 # imm = 0x431BDE82D7B634DB
testq %r10, %r10
jle 0x7347
movq 0x108(%rdi), %r9
movl 0x14(%rdi), %edx
movl 0xe0(%rdi), %eax
imulq $0x3c, %rdx, %rcx
imulq %rdx, %rax
mulq %r8
movq %rdx, %rsi
shrq $0x12, %rsi
imulq $0x78, %r10, %r10
xorl %r11d, %r11d
movl 0x4(%r9,%r11), %ebx
movq %rcx, %rax
xorl %edx, %edx
divq %rbx
movl %eax, 0x28(%r9,%r11)
movl %esi, 0x2c(%r9,%r11)
addq $0x78, %r11
cmpq %r11, %r10
jne 0x7327
movl 0x14(%rdi), %ecx
movq $-0x4, %rsi
movl 0xc8(%rdi,%rsi,4), %eax
imulq %rcx, %rax
mulq %r8
shrq $0x12, %rdx
movl %edx, 0xd8(%rdi,%rsi,4)
incq %rsi
jne 0x7351
movl 0x14(%rdi), %ecx
movl 0xd8(%rdi), %eax
imulq %rcx, %rax
mulq %r8
shrq $0x12, %rdx
movl %edx, 0xdc(%rdi)
movl 0xe4(%rdi), %eax
imulq %rcx, %rax
mulq %r8
shrq $0x12, %rdx
movl %edx, 0xe8(%rdi)
popq %rbx
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcInit(CapsFdc*)
void FdcInit(PCAPSFDC pc)
{
	// reset drives, no disk inserted
	for (int drv=0; drv < pc->drivecnt; drv++) {
		PCAPSDRIVE pd=pc->drive+drv;
		pd->track=0;
		pd->buftrack=-1;
		pd->side=0;
		pd->bufside=-1;
		pd->newside=0;
		pd->diskattr=CAPSDRIVE_DA_WP;
		pd->idistance=0;
		pd->ipcnt=0;
		pd->ovlact=0;
		pd->nact=0;
		pd->nseed=0x87654321;

		// no track data
		FdcClearTrackData(pd);
	}

	// reset internal state
	FdcResetState(pc);

	// all output lines are clear, without callbacks from init
	pc->dataline=0;
	pc->lineout=0;

	// forced update
	pc->drivesel=pc->drivenew-1;
	FdcUpdateDrive(pc, 0);
}

// Assembly:
cmpl $0x0, 0xec(%rdi)
jle 0x7420
movl $0x68, %eax
xorl %ecx, %ecx
movaps 0xada7(%rip), %xmm0     # 0x12160
movabsq $0x200000000, %rdx      # imm = 0x200000000
xorps %xmm1, %xmm1
movaps 0xada3(%rip), %xmm2     # 0x12170
movaps 0xadac(%rip), %xmm3     # 0x12180
xorl %esi, %esi
movq 0x108(%rdi), %r8
movups %xmm0, -0x5c(%r8,%rax)
movq %rdx, -0x4c(%r8,%rax)
movl %ecx, -0x44(%r8,%rax)
movl %ecx, -0x38(%r8,%rax)
movups %xmm1, -0x34(%r8,%rax)
movq $0x0, -0x24(%r8,%rax)
movups %xmm2, -0x1c(%r8,%rax)
movups %xmm3, -0xc(%r8,%rax)
incq %rsi
movslq 0xec(%rdi), %r8
addq $0x78, %rax
cmpq %r8, %rsi
jl 0x73d6
xorps %xmm0, %xmm0
movups %xmm0, 0x3c(%rdi)
movups %xmm0, 0x30(%rdi)
xorl %eax, %eax
movl %eax, 0x2c(%rdi)
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
movq %rcx, 0x94(%rdi)
movl %eax, 0xa4(%rdi)
movl %eax, 0xac(%rdi)
movl %eax, 0xb4(%rdi)
movl %eax, 0x1c(%rdi)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0x24(%rdi)
movl 0xf4(%rdi), %eax
decl %eax
movl %eax, 0xf8(%rdi)
xorl %esi, %esi
jmp 0x75ae
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcReset(CapsFdc*)
void FdcReset(PCAPSFDC pc)
{
	// reset internal state
	FdcResetState(pc);

	// all output lines are clear
	pc->dataline=0;
	FdcSetLine(pc, 0);

	// forced update
	pc->drivesel=pc->drivenew-1;
	FdcUpdateDrive(pc, 0);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0x3c(%rdi)
movups %xmm0, 0x30(%rdi)
movq $0x1, 0x28(%rdi)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x94(%rdi)
xorl %eax, %eax
movl %eax, 0xa4(%rdi)
movl %eax, 0xac(%rdi)
movl %eax, 0xb4(%rdi)
movl %eax, 0x1c(%rdi)
xorl %esi, %esi
callq 0x7725
movl 0xf4(%rbx), %eax
decl %eax
movl %eax, 0xf8(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
jmp 0x75ae
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: CAPSFdcEmulate(CapsFdc*, unsigned int)
void __cdecl CAPSFdcEmulate(PCAPSFDC pc, UDWORD cyclecnt)
{
	// no cycles done
	pc->clockact=0;

	// requested cycles
	pc->clockreq=cyclecnt;

	// no end request
	pc->endrequest=0;

	// run fdc for selected clock cycles
	if (pc->clockreq) {
		FDCCALL *fc=fdccall[pc->runmode];

		// process requested cycles
		while (!pc->endrequest && pc->clockact<pc->clockreq)
			fc[pc->runstate](pc);

		// stop processing after end request
		if (pc->endrequest)
			FdcComEnd(pc);
	}

	// update only if all cycles are complete
	if (pc->clockact >= pc->clockreq)
		FdcUpdateDrive(pc, pc->clockreq);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl %esi, 0x10(%rdi)
movq $0x0, 0x8(%rdi)
testl %esi, %esi
je 0x7511
cmpl $0x0, 0x8(%rbx)
sete %al
je 0x7530
movq %rbx, %rdi
callq 0x7567
movl 0x10(%rbx), %esi
cmpl %esi, 0xc(%rbx)
jae 0x7521
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x75ae
movl 0xc(%rbx), %ecx
cmpl 0x10(%rbx), %ecx
jae 0x7561
movl 0x28(%rbx), %eax
leaq 0x1205e(%rip), %rcx     # 0x195a0
movq (%rcx,%rax,8), %r14
movl 0x2c(%rbx), %eax
movq %rbx, %rdi
callq *(%r14,%rax,8)
cmpl $0x0, 0x8(%rbx)
sete %al
jne 0x7509
movl 0xc(%rbx), %ecx
cmpl 0x10(%rbx), %ecx
jb 0x7546
testb %al, %al
je 0x7509
jmp 0x7511
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcSetLine(CapsFdc*, unsigned int)
void FdcSetLine(PCAPSFDC pc, UDWORD lineout)
{
	// forced interrupt keeps intrq set
	if (lineout & CAPSFDC_LO_INTFRC)
		lineout|=CAPSFDC_LO_INTRQ;

	// get old line state
	UDWORD oldline=pc->lineout;

	// check for drq set
	if (lineout & CAPSFDC_LO_DRQSET) {
		lineout&=~CAPSFDC_LO_DRQSET;
		lineout|=CAPSFDC_LO_DRQ;

		// data lost, if trying to set drq and drq is already set
		if (oldline & CAPSFDC_LO_DRQ)
			pc->r_st1|=CAPSFDC_SR_TR0_LD;
	}

	// changed bits are 1
	UDWORD chgmask=oldline ^ lineout;

	// set new line state
	pc->lineout=lineout;

	// drq change
	if (chgmask & CAPSFDC_LO_DRQ) {
		UDWORD setting=lineout & CAPSFDC_LO_DRQ;
		if (setting)
			pc->r_st1|=CAPSFDC_SR_IP_DRQ;
		else
			pc->r_st1&=~CAPSFDC_SR_IP_DRQ;
		pc->cbdrq(pc, setting);
	}

	// irq change
	if (chgmask & CAPSFDC_LO_INTRQ)
		pc->cbirq(pc, lineout & CAPSFDC_LO_INTRQ);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl %esi, %ebp
shrl %ebp
andl $0x2, %ebp
orl %esi, %ebp
movl 0x24(%rdi), %r14d
testb $0x40, %sil
je 0x774e
andl $-0x42, %ebp
incl %ebp
testb $0x1, %r14b
je 0x774e
orb $0x4, 0x34(%rbx)
xorl %ebp, %r14d
movl %ebp, 0x24(%rbx)
testb $0x1, %r14b
je 0x7774
movl %ebp, %esi
andl $0x1, %esi
movl 0x34(%rbx), %eax
andl $-0x3, %eax
leal (%rax,%rsi,2), %eax
movl %eax, 0x34(%rbx)
movq %rbx, %rdi
callq *0x118(%rbx)
testb $0x2, %r14b
jne 0x777f
popq %rbx
popq %r14
popq %rbp
retq
movq 0x110(%rbx), %rax
andl $0x2, %ebp
movq %rbx, %rdi
movl %ebp, %esi
popq %rbx
popq %r14
popq %rbp
jmpq *%rax
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: CAPSFdcInvalidateTrack(CapsFdc*, int)
SDWORD __cdecl CAPSFdcInvalidateTrack(PCAPSFDC pc, SDWORD drive)
{
	if (!pc)
		return imgeGeneric;

	if (drive<0 || drive>=pc->drivecnt)
		return imgeOutOfRange;

	PCAPSDRIVE pd=pc->drive+drive;
	pd->buftrack=-1;
	pd->bufside=-1;

	return imgeOk;
}

// Assembly:
testq %rdi, %rdi
je 0x7895
movl $0x3, %eax
testl %esi, %esi
js 0x789a
cmpl %esi, 0xec(%rdi)
jle 0x789a
movq 0x108(%rdi), %rax
movl %esi, %ecx
imulq $0x78, %rcx, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %edx, 0x10(%rax,%rcx)
movl %edx, 0x18(%rax,%rcx)
xorl %eax, %eax
retq
movl $0x2, %eax
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComIdle(CapsFdc*, unsigned int)
UDWORD FdcComIdle(PCAPSFDC pc, UDWORD cyc)
{
	// wait state cancelled if end requested
	if (pc->endrequest & CAPSFDC_ER_REQEND)
		return 0;

	// process all drives
	for (int drv=0; drv < pc->drivemax; drv++) {
		// get drive
		PCAPSDRIVE pd=pc->drive+drv;

		// if motor off no distance change and no index signals to count
		if (!(pd->diskattr & CAPSDRIVE_DA_MO))
			continue;

		// motor on, advance distance
		UDWORD dist=pd->idistance+cyc;

		// restart distance count on new revolution
		if (dist >= pd->clockrev) {
			dist-=pd->clockrev;

			// process disk index
			pd->idistance=0;
			FdcIndex(pc, drv);
		}

		// set distance
		pd->idistance=dist;
	}

	// !!!
	pc->clockact+=cyc;
	return cyc;
}

// Assembly:
xorl %eax, %eax
testb $0x2, 0x8(%rdi)
jne 0x79fd
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
cmpl $0x0, 0xf0(%rdi)
jle 0x79e9
movl $0x28, %r12d
xorl %r15d, %r15d
movq 0x108(%r14), %r13
testb $0x4, -0x8(%r13,%r12)
je 0x79d6
movl -0x4(%r13,%r12), %eax
addl %ebx, %eax
movl %eax, %ebp
subl (%r13,%r12), %ebp
jb 0x79d1
movl $0x0, -0x4(%r13,%r12)
movq %r14, %rdi
movl %r15d, %esi
callq 0x7be5
movl %ebp, %eax
movl %eax, -0x4(%r13,%r12)
incq %r15
movslq 0xf0(%r14), %rax
addq $0x78, %r12
cmpq %rax, %r15
jl 0x799c
addl %ebx, 0xc(%r14)
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcUpdateData(CapsFdc*)
void FdcUpdateData(PCAPSFDC pc)
{
	// if no drive selected
	if (!pc->driveprc) {
		// and still locked, keep state
		if (pc->datalock >= 0)
			return;

		// lock on data
		FdcLockData(pc);
		return;
	}

	// get selected drive
	PCAPSDRIVE pd=pc->driveprc;

	// keep state if track.side are the same as buffered data
	if (pd->track==pd->buftrack && pd->side==pd->bufside) {
		// keep state if still locked
		if (pc->datalock >= 0)
			return;

		// lock on data
		FdcLockData(pc);
		return;
	}

	// no track data
	FdcClearTrackData(pd);

	// set buffered data track.side
	pd->buftrack=pd->track;
	pd->bufside=pd->side;

	// request track data if disk inserted
	if (pd->diskattr & CAPSDRIVE_DA_IN) {
		// this is required to keep the host informed about the track change, even if the data may not be used later
		pc->cbtrk(pc, pc->driveact);

		// destroy track data if:
		// - drive is single sided and side 1 is being accessed
		// This will result in noise being fed to the DATA line. 
		// Since ttype is reset, track update callbacks won't happen - no need to replicate this code anywhere else.
		if ((pd->diskattr & CAPSDRIVE_DA_SS) && (pd->bufside == 1))
			FdcClearTrackData(pd);
	}

	// update track parameters
	FdcUpdateTrack(pc, pc->driveact);

	// lock on data
	FdcLockData(pc);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x100(%rdi), %r14
testq %r14, %r14
je 0x7a74
movl 0xc(%r14), %eax
cmpl 0x10(%r14), %eax
jne 0x7a89
movl 0x14(%r14), %ecx
cmpl 0x18(%r14), %ecx
jne 0x7a89
cmpl $0x0, 0x80(%rbx)
js 0x7b11
addq $0x8, %rsp
popq %rbx
popq %r14
retq
xorps %xmm0, %xmm0
movups %xmm0, 0x34(%r14)
movq $0x0, 0x44(%r14)
movaps 0xa6d0(%rip), %xmm0     # 0x12170
movups %xmm0, 0x4c(%r14)
movl $0x0, 0x5c(%r14)
movl %eax, 0x10(%r14)
movl 0x14(%r14), %eax
movl %eax, 0x18(%r14)
testb $0x1, 0x20(%r14)
je 0x7b03
movl 0xfc(%rbx), %esi
movq %rbx, %rdi
callq *0x120(%rbx)
movaps 0xa69a(%rip), %xmm1     # 0x12170
testb $0x8, 0x20(%r14)
je 0x7b03
cmpl $0x1, 0x18(%r14)
jne 0x7b03
leaq 0x34(%r14), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movups %xmm1, 0x4c(%r14)
movl $0x0, 0x5c(%r14)
movl 0xfc(%rbx), %esi
movq %rbx, %rdi
callq 0x7d8d
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x7cfc
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcResetAm(CapsFdc*, int)
void FdcResetAm(PCAPSFDC pc, int keepphase)
{
	pc->aminfo|=CAPSFDC_AI_AMDETENABLE|CAPSFDC_AI_CRCENABLE;
	pc->aminfo&=~(CAPSFDC_AI_CRCACTIVE|CAPSFDC_AI_AMACTIVE);
	pc->amisigmask=CAPSFDC_AI_DSRAM;
	if (!keepphase) {
		pc->dataphase=0;
		pc->datapcnt=0;
	}
}

// Assembly:
movl 0x60(%rdi), %eax
andl $-0x10, %eax
orl $0x3, %eax
movl %eax, 0x60(%rdi)
movl $0x200, 0x64(%rdi)      # imm = 0x200
testl %esi, %esi
je 0x7b4b
retq
movq $0x0, 0x8c(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcComIdleOther(CapsFdc*, unsigned int)
void FdcComIdleOther(PCAPSFDC pc, UDWORD cyc)
{
	// process all drives
	for (int drv=0; drv < pc->drivemax; drv++) {
		// skip active drive
		if (drv == pc->driveact)
			continue;

		// get drive
		PCAPSDRIVE pd=pc->drive+drv;

		// if motor off no distance change
		if (!(pd->diskattr & CAPSDRIVE_DA_MO))
			continue;

		// motor on, advance distance
		UDWORD dist=pd->idistance+cyc;

		// restart distance count on new revolution
		if (dist >= pd->clockrev) {
			dist-=pd->clockrev;

			// process disk index
			pd->idistance=0;
			FdcIndex(pc, drv);
		}

		// set distance
		pd->idistance=dist;
	}
}

// Assembly:
cmpl $0x0, 0xf0(%rdi)
jle 0x7be4
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movl $0x28, %r12d
xorl %r15d, %r15d
movl 0xfc(%r14), %eax
cmpq %rax, %r15
je 0x7bc3
movq 0x108(%r14), %r13
testb $0x4, -0x8(%r13,%r12)
je 0x7bc3
movl -0x4(%r13,%r12), %eax
addl %ebx, %eax
movl %eax, %ebp
subl (%r13,%r12), %ebp
jb 0x7bbe
movl $0x0, -0x4(%r13,%r12)
movq %r14, %rdi
movl %r15d, %esi
callq 0x7be5
movl %ebp, %eax
movl %eax, -0x4(%r13,%r12)
incq %r15
movslq 0xf0(%r14), %rax
addq $0x78, %r12
cmpq %rax, %r15
jl 0x7b7d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcIndex(CapsFdc*, int)
void FdcIndex(PCAPSFDC pc, int drive)
{
	// must be valid drive
	if (drive < 0)
		return;

	// get selected drive
	PCAPSDRIVE pd=pc->drive+drive;

	// if drive empty, no index signal, stop
	if (!(pd->diskattr & CAPSDRIVE_DA_IN))
		return;

	// start index pulse
	pd->ipcnt=-1;

	// if track is changing, request new track data
	if ((pd->ttype & CTIT_FLAG_FLAKEY))
		pc->cbtrk(pc, drive);

	// update track parameters
	FdcUpdateTrack(pc, drive);

	// if drive not selected, index signal not routed, stop
	if (drive != pc->driveact)
		return;

	// set index signal
	pc->r_st0|=CAPSFDC_SR_IP_DRQ;

	// increment index pulse counter
	pc->indexcount++;

	// if index abort allowed and limit reached set end and disable abort
	if (pc->indexlimit>=0 && pc->indexcount>=pc->indexlimit) {
		pc->endrequest|=CAPSFDC_ER_COMEND;
		pc->indexlimit=-1;
	}

	// set spin-up flag if limit reached
	if (pc->spinupcnt>=pc->spinuplimit || ++pc->spinupcnt>=pc->spinuplimit)
		pc->r_st0|=CAPSFDC_SR_SU_RT;

	// if fdc is not busy turn motor off once idle limit reached, apparently SR spin-up is not reset
	if (!(pc->r_st0 & CAPSFDC_SR_BUSY)) {
		if (pc->idlecnt>=pc->idlelimit || ++pc->idlecnt>=pc->idlelimit) {
			pc->lineout&=~CAPSFDC_LO_MO;
			pd->diskattr&=~CAPSDRIVE_DA_MO;
			pc->r_st0&=~CAPSFDC_SR_MO;
			pc->spinupcnt=0;
		}
	}

	// set index pulse interrupt if enabled
	if (pc->lineout & CAPSFDC_LO_INTIP)
		FdcSetLine(pc, pc->lineout | CAPSFDC_LO_INTRQ);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
testl %esi, %esi
js 0x7ce8
movl %esi, %ebp
movq %rdi, %rbx
movq 0x108(%rdi), %r14
movl %esi, %eax
imulq $0x78, %rax, %rax
testb $0x1, 0x20(%r14,%rax)
je 0x7ce8
addq %rax, %r14
movl $0xffffffff, 0x30(%r14) # imm = 0xFFFFFFFF
cmpl $0x0, 0x34(%r14)
jns 0x7c2c
movq %rbx, %rdi
movl %ebp, %esi
callq *0x120(%rbx)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7d8d
cmpl %ebp, 0xfc(%rbx)
jne 0x7ce8
movl 0x30(%rbx), %eax
movl 0x94(%rbx), %ecx
movl %eax, %edx
orl $0x2, %edx
movl %edx, 0x30(%rbx)
incl %ecx
movl %ecx, 0x94(%rbx)
movl 0x98(%rbx), %edx
testl %edx, %edx
sets %sil
cmpl %edx, %ecx
setl %cl
orb %sil, %cl
jne 0x7c7f
orb $0x1, 0x8(%rbx)
movl $0xffffffff, 0x98(%rbx) # imm = 0xFFFFFFFF
movl 0xa4(%rbx), %ecx
movl 0xa8(%rbx), %edx
cmpl %edx, %ecx
jge 0x7c9b
incl %ecx
movl %ecx, 0xa4(%rbx)
cmpl %edx, %ecx
jl 0x7ca1
orl $0x22, %eax
movl %eax, 0x30(%rbx)
movl 0x30(%rbx), %eax
testb $0x1, %al
jne 0x7cdf
movl 0xac(%rbx), %ecx
movl 0xb0(%rbx), %edx
cmpl %edx, %ecx
jge 0x7cc4
incl %ecx
movl %ecx, 0xac(%rbx)
cmpl %edx, %ecx
jl 0x7cdf
andb $-0x9, 0x24(%rbx)
andb $-0x5, 0x20(%r14)
andl $0xffffff7e, %eax       # imm = 0xFFFFFF7E
movl %eax, 0x30(%rbx)
movl $0x0, 0xa4(%rbx)
movl 0x24(%rbx), %esi
testb $0x20, %sil
jne 0x7ced
popq %rbx
popq %r14
popq %rbp
retq
orl $0x2, %esi
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x7725
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcLockData(CapsFdc*)
void FdcLockData(PCAPSFDC pc)
{
	// get selected drive
	PCAPSDRIVE pd=pc->driveprc;

	// check input available
	if (!pd || !(pd->diskattr & CAPSDRIVE_DA_IN)) {
		// if no input read 0 on reference clock
		pc->datamode=cfdcdmNoline;

		// lock onto reference clock 2us mfm*(8clock+8data)
		pc->datalock=UDWORD(((UQUAD)pc->clockfrq*2*16)/1000000);
		pc->datacycle=0;
		return;
	}

	// true if track data is defined
	int dat=pd->trackbuf && pd->tracklen;

	// density map is only used when track data is available
	if (pd->timebuf && dat) {
		pc->datamode=cfdcdmDMap;
		FdcLockTime(pc);
		return;
	}

	// noise or data input read
	pc->datamode=dat ? cfdcdmData : cfdcdmNoise;

	// lock onto bit in progress at the drive cycle
	pc->datalock=UDWORD(((UQUAD)pd->idistance*pd->trackbits)/pd->clockrev);
	pc->datacycle=0;
}

// Assembly:
movq 0x100(%rdi), %rax
testq %rax, %rax
je 0x7d0e
testb $0x1, 0x20(%rax)
jne 0x7d2e
movq $0x0, 0x84(%rdi)
movl 0x14(%rdi), %eax
imulq $0x431bde83, %rax, %rax # imm = 0x431BDE83
shrq $0x2d, %rax
movl %eax, 0x80(%rdi)
retq
cmpq $0x0, 0x38(%rax)
je 0x7d3e
cmpl $0x0, 0x48(%rax)
setne %cl
jmp 0x7d40
xorl %ecx, %ecx
cmpq $0x0, 0x40(%rax)
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x7d5e
movl $0x3, 0x84(%rdi)
jmp 0x7e59
movzbl %cl, %ecx
incl %ecx
movl %ecx, 0x84(%rdi)
movl 0x24(%rax), %ecx
movl 0x28(%rax), %esi
movslq 0x50(%rax), %rax
imulq %rcx, %rax
xorl %edx, %edx
divq %rsi
movl %eax, 0x80(%rdi)
movl $0x0, 0x88(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcUpdateTrack(CapsFdc*, int)
void FdcUpdateTrack(PCAPSFDC pc, int drive)
{
	// must be valid drive
	if (drive < 0)
		return;

	// get selected drive
	PCAPSDRIVE pd=pc->drive+drive;

	// no disk inserted, no input
	if (!(pd->diskattr & CAPSDRIVE_DA_IN))
		return;

	// get base track length in bits
	if (!pd->trackbuf || !pd->tracklen) {
		// generate different track size on track updates
		PSDWORD ns=fdcddnoise;
		pd->trackbits=ns[pd->nact++]<<3;
		if (ns[pd->nact] < 0)
			pd->nact=0;
		pd->overlap=0;
	} else
		pd->trackbits=pd->tracklen<<3;

	// if overlap position exists
	int rb;
	if (pd->overlap >= 0) {
		// rob bit count, updated on track updates
		rb=fdcrobbit[pd->ovlact++];
		if (fdcrobbit[pd->ovlact] < 0)
			pd->ovlact=0;
	} else
		rb=0;

	pd->ovlcnt=rb;

	// set bits to remove and their start if any
	if (rb) {
		pd->ovlmin=((pd->overlap+1)<<3)-rb;
		pd->ovlmax=pd->ovlmin+rb-1;
	} else {
		pd->ovlmin=-1;
		pd->ovlmax=-1;
	}
}

// Assembly:
testl %esi, %esi
js 0x7e58
movq 0x108(%rdi), %rax
movl %esi, %ecx
imulq $0x78, %rcx, %rcx
testb $0x1, 0x20(%rax,%rcx)
je 0x7e58
addq %rcx, %rax
cmpq $0x0, 0x38(%rax)
je 0x7dc8
movl 0x48(%rax), %ecx
testl %ecx, %ecx
je 0x7dc8
shll $0x3, %ecx
movl $0x50, %edx
jmp 0x7df8
movslq 0x64(%rax), %rsi
leaq 0x1(%rsi), %rcx
movl %ecx, 0x64(%rax)
leaq 0x11486(%rip), %rdi     # 0x19260
movl (%rdi,%rsi,4), %ecx
shll $0x3, %ecx
movl %ecx, 0x50(%rax)
xorl %ecx, %ecx
movl $0x4c, %edx
cmpl $0x0, 0x4(%rdi,%rsi,4)
jns 0x7df8
movl $0x0, 0x64(%rax)
movl %ecx, (%rax,%rdx)
cmpl $0x0, 0x4c(%rax)
js 0x7e25
movslq 0x60(%rax), %rcx
leaq 0x1(%rcx), %rdx
movl %edx, 0x60(%rax)
leaq 0x1142d(%rip), %rsi     # 0x19240
xorl %edi, %edi
cmpl $0x0, 0x4(%rsi,%rcx,4)
movl (%rsi,%rcx,4), %ecx
cmovnsl %edx, %edi
movl %edi, 0x60(%rax)
jmp 0x7e27
xorl %ecx, %ecx
movl %ecx, 0x5c(%rax)
testl %ecx, %ecx
je 0x7e49
movl 0x4c(%rax), %edx
leal (,%rdx,8), %esi
subl %ecx, %esi
addl $0x8, %esi
movl %esi, 0x54(%rax)
leal 0x7(,%rdx,8), %ecx
jmp 0x7e55
movl $0xffffffff, 0x54(%rax) # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, 0x58(%rax)
retq
// File: /workspace/github_cpp_makefile_star2_O1/OpenFodder[P]SOS_Unpacker/capsimg/CAPSImg/CapsFDCEmulator.cpp
// Function: FdcLockTime(CapsFdc*)
void FdcLockTime(PCAPSFDC pc)
{
	PCAPSDRIVE pd=pc->driveprc;
	int lo=0;
	int hi=pd->tracklen-1;
	UDWORD sum=pd->timebuf[hi];

	// binary search for the nearest item to the actual clock distance
	while (lo <= hi) {
		int mid=(lo+hi)/2;
		UDWORD atm=UDWORD(((UQUAD)pd->timebuf[mid]*pd->clockrev)/sum);

		if (atm <= pd->idistance)
			lo=mid+1;
		else
			hi=mid-1;
	}

	// safety check can only happen if distance was >= clockrev
	if ((unsigned)lo >= pd->tracklen)
		lo=pd->tracklen-1;

	UDWORD base=lo ? pd->timebuf[lo-1] : 0;
	UDWORD diff=pd->timebuf[lo]-base;

	// linear search for nearest distance
	for (hi=1; hi < 8; hi++) {
		UDWORD atm=UDWORD(((UQUAD)(base+(hi*diff)/8)*pd->clockrev)/sum);
		if (pd->idistance < atm)
			break;
	}

	pc->datalock=lo*8+hi-1;
	pc->datacycle=base;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x100(%rdi), %r9
movl 0x48(%r9), %r11d
leal -0x1(%r11), %ecx
movq 0x40(%r9), %r10
movslq %ecx, %rax
movl (%r10,%rax,4), %r8d
xorl %esi, %esi
movl $0x0, %ebx
testl %eax, %eax
js 0x7ebe
movl 0x24(%r9), %ebp
movl 0x28(%r9), %r14d
xorl %ebx, %ebx
movl %ecx, %r15d
leal (%rbx,%r15), %r12d
shrl %r12d
movl (%r10,%r12,4), %eax
imulq %r14, %rax
xorl %edx, %edx
divq %r8
cmpl %eax, %ebp
jb 0x7eb3
incl %r12d
movl %r12d, %ebx
jmp 0x7eb9
decl %r12d
movl %r12d, %r15d
cmpl %r15d, %ebx
jle 0x7e93
cmpl %r11d, %ebx
cmovbl %ebx, %ecx
movslq %ecx, %rax
testl %ecx, %ecx
je 0x7ed0
movl -0x4(%r10,%rax,4), %esi
movl (%r10,%rax,4), %r10d
subl %esi, %r10d
movl 0x24(%r9), %r11d
movl 0x28(%r9), %ebx
movl $0x1, %r9d
movl %r10d, %ebp
movl %ebp, %eax
shrl $0x3, %eax
addl %esi, %eax
imulq %rbx, %rax
xorl %edx, %edx
divq %r8
cmpl %eax, %r11d
jb 0x7f0f
incl %r9d
addl %r10d, %ebp
cmpl $0x8, %r9d
jne 0x7ee8
movl $0x8, %r9d
leal (%r9,%rcx,8), %eax
decl %eax
movl %eax, 0x80(%rdi)
movl %esi, 0x88(%rdi)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq