// File: /workspace/github_c_makefile_star2_O1/Joy-Division[P]tools-mgs/txp-convert.c
// Function: getTxpHeader
txpHeader *getTxpHeader(unsigned char *data, unsigned int game) {
	txpHeaderPO *pohead = NULL;
	txpHeaderPW *pwhead = NULL;
	txpHeader *rethead = malloc(sizeof(txpHeader));
	
	printf("Raw header values:\n");
	
	switch(game) {
		case mgspo: {
			pohead = (txpHeaderPO *)data;
			
			printf("unknown1 - unknown2 - numTexts - texloffs - numFrame - framloff - unknown3 - unknown4\n");
			printf("%08x - %08x - %08x - %08x - %08x - %08x - %08x - %08x\n",
				pohead->unknown1, pohead->unknown2, pohead->numTextures, pohead->texlistOffset,
				pohead->numFrames, pohead->framelistOffset, pohead->unknown3, pohead->unknown4);
			
			rethead->namehash = 0;
			
			rethead->numtextures = pohead->numTextures;
			rethead->texturelist = pohead->texlistOffset;
			
			rethead->numframes = pohead->numFrames;
			rethead->framelist = pohead->framelistOffset;
			break;
		}
		case mgspw: {
			pwhead = (txpHeaderPW *)data;
			
			printf("unknown1 - namehash - numTexts - numFrame - unknown2 - texloffs - framloff - unknown3\n");
			printf("%08x - %08x - %08x - %08x - %08x - %08x - %08x - %08x\n",
				pwhead->unknown1, pwhead->namehash, pwhead->numTextures, pwhead->numFrames,
				pwhead->unknown2, pwhead->texlistOffset, pwhead->framelistOffset, pwhead->unknown3);
			
			rethead->namehash = pwhead->namehash;
			
			rethead->numtextures = pwhead->numTextures;
			rethead->texturelist = pwhead->texlistOffset;
			
			rethead->numframes = pwhead->numFrames;
			rethead->framelist = pwhead->framelistOffset;
			break;
		}
		default: {
			printf("i am asplod\n");
			break;
		}
	}
	
	printf("Processed header values:\nnamehash %08x - numtex %d - texoff %08x - numframe %d - frameoff %08x\n",
		rethead->namehash, rethead->numtextures, rethead->texturelist, rethead->numframes, rethead->framelist);
	
	return rethead;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %r14
movl $0x14, %edi
callq 0x10f0
movq %rax, %rbx
leaq 0x32d0(%rip), %rdi      # 0xfd0b
callq 0x1050
cmpl $0x1, %ebp
je 0xcab5
testl %ebp, %ebp
jne 0xcb20
leaq 0x3320(%rip), %rdi      # 0xfd74
callq 0x1050
movl (%r14), %esi
movl 0x4(%r14), %edx
movl 0x8(%r14), %ecx
movl 0xc(%r14), %r8d
movl 0x10(%r14), %r9d
movl 0x14(%r14), %r10d
movl 0x18(%r14), %r11d
movl 0x1c(%r14), %r15d
subq $0x8, %rsp
leaq 0x2f31(%rip), %rdi      # 0xf9b4
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r10
callq 0x10a0
addq $0x20, %rsp
movl $0x0, (%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x4(%rbx)
movl 0xc(%r14), %eax
movl %eax, 0x8(%rbx)
movl 0x10(%r14), %eax
movl %eax, 0xc(%rbx)
movl 0x14(%r14), %eax
jmp 0xcb1b
leaq 0x3262(%rip), %rdi      # 0xfd1e
callq 0x1050
movl (%r14), %esi
movl 0x4(%r14), %edx
movl 0x8(%r14), %ecx
movl 0xc(%r14), %r8d
movl 0x10(%r14), %r9d
movl 0x14(%r14), %r10d
movl 0x18(%r14), %r11d
movl 0x1c(%r14), %r15d
subq $0x8, %rsp
leaq 0x2ec9(%rip), %rdi      # 0xf9b4
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %r10
callq 0x10a0
addq $0x20, %rsp
movl 0x4(%r14), %eax
movl %eax, (%rbx)
movl 0x8(%r14), %eax
movl %eax, 0x4(%rbx)
movl 0x14(%r14), %eax
movl %eax, 0x8(%rbx)
movl 0xc(%r14), %eax
movl %eax, 0xc(%rbx)
movl 0x18(%r14), %eax
movl %eax, 0x10(%rbx)
jmp 0xcb2c
leaq 0x32a3(%rip), %rdi      # 0xfdca
callq 0x1050
movl (%rbx), %esi
movl 0x4(%rbx), %edx
movl 0x8(%rbx), %ecx
movl 0xc(%rbx), %r8d
movl 0x10(%rbx), %r9d
leaq 0x2ea8(%rip), %rdi      # 0xf9eb
xorl %eax, %eax
callq 0x10a0
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq