// File: /workspace/github_c_makefile_star2_O2/calmopyrin[P]tedplay/tedplay.cpp
// Function: tedPlayGetInfo(void*, PsidHeader&)
void tedPlayGetInfo(void *file, PsidHeader &hdr)
{
	unsigned char buf[256];
	FILE *fp = reinterpret_cast<FILE *>(file);

	memset(hdr.title, 0, sizeof(hdr.title));
	strcpy(hdr.title, "Unknown");
	memset(hdr.author, 0, sizeof(hdr.author));
	strcpy(hdr.author, "Unknown");
	memset(hdr.copyright, 0, sizeof(hdr.copyright));
	strcpy(hdr.copyright, "Unknown");

	if (fread(buf, 1, 256, fp) >= 64) {
		if (!strncmp((const char*)buf + 1, "SID", 3)) {
			parsePsid(buf, hdr);
			hdr.loadAddress = buf[PSID_START + 1] + (buf[PSID_START] << 8);
			if (!hdr.loadAddress)
				hdr.loadAddress = buf[PSID_MAX_HEADER_LENGTH] + (buf[PSID_MAX_HEADER_LENGTH + 1] << 8);
			if (buf[0] == 'P') {
				hdr.typeName = "PSID";
			}
			else {
				hdr.typeName = "RSID";
			}
			return;
		}
		else if (!strncmp((const char*)buf + 17, "TEDMUSIC", 8)) {
			hdr.typeName = "TMF";
			hdr.loadAddress = buf[28] + (buf[29] << 8);
			copyPetsciiToAsc(hdr.title, trimTrailingSpace((char*)buf + 65, 32), 32);
			copyPetsciiToAsc(hdr.author, trimTrailingSpace((char*)buf + 97, 32), 32);
			copyPetsciiToAsc(hdr.copyright, trimTrailingSpace((char*)buf + 129, 32), 32);
			return;
		}
		else if (!strncmp((const char*)buf, "CBM8M", 5)) {
			CbmTune tune;
			//tune.parse(
			hdr.typeName = "CBM8M";
			return;
		}
	}
	hdr.typeName = "PRG";
	hdr.loadAddress = buf[0] + (buf[1] << 8);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x3c(%rsi), %rdi
movl $0x1f8, %edx            # imm = 0x1F8
xorl %esi, %esi
callq 0x3130
movabsq $0x6e776f6e6b6e55, %r15 # imm = 0x6E776F6E6B6E55
movq %r15, 0x34(%rbx)
leaq 0x23c(%rbx), %rdi
movl $0x1f8, %edx            # imm = 0x1F8
xorl %esi, %esi
callq 0x3130
movq %r15, 0x234(%rbx)
leaq 0x43c(%rbx), %rdi
movl $0x1f8, %edx            # imm = 0x1F8
xorl %esi, %esi
callq 0x3130
movq %r15, 0x434(%rbx)
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rsi
movl $0x100, %edx            # imm = 0x100
movq %r14, %rcx
callq 0x32d0
cmpq $0x40, %rax
jb 0xcd86
leaq 0x41(%rsp), %rdi
leaq 0x2c3e(%rip), %rsi      # 0xf987
pushq $0x3
popq %rdx
callq 0x3240
testl %eax, %eax
je 0xcda6
movabsq $0x434953554d444554, %rax # imm = 0x434953554D444554
cmpq %rax, 0x51(%rsp)
je 0xcdf3
leaq 0x13bd(%rip), %rsi      # 0xe12e
leaq 0x40(%rsp), %rdi
pushq $0x5
popq %rdx
callq 0x3240
testl %eax, %eax
je 0xce8d
leaq 0x658(%rbx), %rdi
leaq 0x2ced(%rip), %rsi      # 0xfa81
callq 0x3390
movzwl 0x40(%rsp), %eax
movl %eax, 0x2c(%rbx)
jmp 0xceb3
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xc445
movzwl 0x8(%r14), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x2c(%rbx)
testw %ax, %ax
jne 0xcdd5
movzwl 0xbc(%rsp), %eax
movl %eax, 0x2c(%rbx)
addq $0x658, %rbx            # imm = 0x658
cmpb $0x50, 0x40(%rsp)
jne 0xce7c
leaq 0x2b98(%rip), %rsi      # 0xf986
jmp 0xce83
leaq 0x34(%rbx), %r15
leaq 0x234(%rbx), %r12
leaq 0x434(%rbx), %r14
leaq 0x658(%rbx), %rdi
leaq 0x2b7d(%rip), %rsi      # 0xf990
callq 0x3390
leaq 0x81(%rsp), %r13
movzwl -0x25(%r13), %eax
movl %eax, 0x2c(%rbx)
pushq $0x20
popq %rbx
movq %r13, %rdi
movl %ebx, %esi
callq 0xc402
movq %r15, %rdi
movq %r13, %rsi
callq 0xced7
leaq 0xa1(%rsp), %r15
movq %r15, %rdi
movl %ebx, %esi
callq 0xc402
movq %r12, %rdi
movq %r15, %rsi
callq 0xced7
leaq 0xc1(%rsp), %r15
movq %r15, %rdi
movl %ebx, %esi
callq 0xc402
movq %r14, %rdi
movq %r15, %rsi
callq 0xced7
jmp 0xceb3
leaq 0x2b08(%rip), %rsi      # 0xf98b
movq %rbx, %rdi
callq 0x3390
jmp 0xceb3
movq %rsp, %rdi
callq 0x3d2c
addq $0x658, %rbx            # imm = 0x658
leaq 0x128b(%rip), %rsi      # 0xe12e
movq %rbx, %rdi
callq 0x3390
movq %rsp, %rdi
callq 0x3d42
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %rbx
movq %rsp, %rdi
callq 0x3d42
movq %rbx, %rdi
callq 0x3340