// File: /workspace/github_c_makefile_star2_O1/calmopyrin[P]tedplay/Sid.cpp
// Function: SIDsound::setModel(unsigned int)
void SIDsound::setModel(unsigned int model)
{
	int i;

	switch (model) {
		case SID8580DB:
		case SID8580:
			for ( i=0; i<2048; i++) {
				double x = i / 8.0;
				//double cf = 12500.0 * i / 2048.0; // specs and YAPE
				// approximate with a 3-degree polynomial
				//double cf = 0.0003*x*x*x + 0.0882*x*x + 44.49*x - 38.409;
				// approximate with a 2-degree polynomial
				//double cf = -0.0177*x*x + 55.261*x - 55.518; // CSG 8580R4
				double cf = -0.0156*x*x + 48.473*x - 45.074; // 8580R5
				cutOffFreq[i] = cf <= 0 ? 0 : cf;
			}
			dcWave = 0x000;
			dcMixer = 0;
			dcVoice = 0;
			break;

		case SID6581: // R4 actually
			for (i=0; i<1024; i++) {
				cutOffFreq[i] = (tanh(((double)i/1.5 - 1024.0)/1024.0*M_PI) + tanh(M_PI))
					* (6000.0 - 220.0) + 220.0;
			}
			for (; i<1056; i++) {
				double x = ((double)i - 1024.0) / (1056.0 - 1003.);
				cutOffFreq[i] = x*(1315.0 - 1003.0) + 1003.0;
			}
			for (; i<2048; i++) {
				double x = ((double)i - 1056.0) / (2048.0 - 1056.0);
				cutOffFreq[i] = //(tanh (((double)i - 2048.0)/1024.0*M_PI) + tanh(M_PI))
					//* (20163.0 - 1315.0) + 1315.0;
					(20163.0 - 1315.0) * x + 1315.0;
			}
			dcWave = 0x380;
			dcMixer = -0xFFF*0xFF/18 >> 7;
			dcVoice = 0x800*0xFF;
			break;

		case SID6581R1: // 6581 R1
			for (i=0; i<1024; i++) {
				cutOffFreq[i] = (tanh(((double)i-1024.0)/1024.0*M_PI) + tanh(M_PI))
					* (6000.0 - 220.0) + 220.0;
			}
			for (; i<2048; i++) {
				cutOffFreq[i] = (tanh (((double)i-2048.0)/1024.0*M_PI) + tanh(M_PI))
					* (18000.0 - 4600.0) + 4600.0;
			}
			dcWave = 0x380;
			dcMixer = -0xFFF*0xFF/18 >> 7;
			dcVoice = 0x800*0xFF;
			break;
	}
	setFilterCutoff();
	model_ = model;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %esi, %ebx
movq %rdi, %r14
leal -0x1(%rbx), %eax
cmpl $0x2, %eax
jb 0x88c4
testl %ebx, %ebx
je 0x893b
cmpl $0x3, %ebx
jne 0x8a5c
xorl %r15d, %r15d
movsd 0x7892(%rip), %xmm1     # 0x10058
movsd 0x785a(%rip), %xmm2     # 0x10028
movl %r15d, %eax
orl $0xfffffc00, %eax       # imm = 0xFFFFFC00
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
callq 0x30b0
movsd %xmm0, 0x8(%rsp)
movsd 0x7830(%rip), %xmm0     # 0x10028
callq 0x30b0
movsd 0x785b(%rip), %xmm0     # 0x10060
movsd 0x781b(%rip), %xmm2     # 0x10028
movsd 0x7843(%rip), %xmm1     # 0x10058
movsd 0x8(%rsp), %xmm3
addsd %xmm0, %xmm3
mulsd 0x7841(%rip), %xmm3     # 0x10068
addsd 0x7841(%rip), %xmm3     # 0x10070
movsd %xmm3, 0x1a0(%r14,%r15,8)
incq %r15
cmpq $0x400, %r15            # imm = 0x400
jne 0x87ce
xorl %r15d, %r15d
leal 0x400(%r15), %eax
orl $0xfffff800, %eax       # imm = 0xFFFFF800
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm2, %xmm0
callq 0x30b0
movsd %xmm0, 0x8(%rsp)
movsd 0x77b2(%rip), %xmm0     # 0x10028
callq 0x30b0
movsd 0x77a5(%rip), %xmm2     # 0x10028
movsd 0x77cd(%rip), %xmm1     # 0x10058
movsd 0x8(%rsp), %xmm0
addsd 0x77c7(%rip), %xmm0     # 0x10060
mulsd 0x77d7(%rip), %xmm0     # 0x10078
addsd 0x77d7(%rip), %xmm0     # 0x10080
movsd %xmm0, 0x21a0(%r14,%r15,8)
incq %r15
cmpq $0x400, %r15            # imm = 0x400
jne 0x8848
jmp 0x8a38
xorl %eax, %eax
movsd 0x77fa(%rip), %xmm0     # 0x100c8
movsd 0x77fa(%rip), %xmm1     # 0x100d0
movsd 0x77fa(%rip), %xmm2     # 0x100d8
movsd 0x77fa(%rip), %xmm3     # 0x100e0
xorpd %xmm4, %xmm4
xorl %ecx, %ecx
xorps %xmm5, %xmm5
cvtsi2sd %ecx, %xmm5
mulsd %xmm0, %xmm5
movapd %xmm5, %xmm6
mulsd %xmm1, %xmm6
mulsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
addsd %xmm6, %xmm5
addsd %xmm3, %xmm5
movapd %xmm5, %xmm6
cmplesd %xmm4, %xmm6
andnpd %xmm5, %xmm6
movlpd %xmm6, 0x1a0(%r14,%rcx,8)
incq %rcx
cmpq $0x800, %rcx            # imm = 0x800
jne 0x88ec
xorl %edx, %edx
xorl %ecx, %ecx
jmp 0x8a47
xorl %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
divsd 0x773a(%rip), %xmm0     # 0x10088
addsd 0x773a(%rip), %xmm0     # 0x10090
mulsd 0x76fa(%rip), %xmm0     # 0x10058
movsd 0x76c2(%rip), %xmm1     # 0x10028
mulsd %xmm1, %xmm0
callq 0x30b0
movsd %xmm0, 0x8(%rsp)
movsd 0x76ab(%rip), %xmm0     # 0x10028
callq 0x30b0
movsd 0x8(%rsp), %xmm0
addsd 0x76d0(%rip), %xmm0     # 0x10060
mulsd 0x76d0(%rip), %xmm0     # 0x10068
addsd 0x76d0(%rip), %xmm0     # 0x10070
movsd %xmm0, 0x1a0(%r14,%r15,8)
incq %r15
cmpq $0x400, %r15            # imm = 0x400
jne 0x893e
xorl %eax, %eax
movsd 0x76d8(%rip), %xmm0     # 0x10098
movsd 0x76d8(%rip), %xmm1     # 0x100a0
movsd 0x76d8(%rip), %xmm2     # 0x100a8
xorps %xmm3, %xmm3
cvtsi2sd %eax, %xmm3
divsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x21a0(%r14,%rax,8)
incq %rax
cmpq $0x20, %rax
jne 0x89d0
xorl %eax, %eax
movsd 0x76b0(%rip), %xmm0     # 0x100b0
movsd 0x76b0(%rip), %xmm1     # 0x100b8
movsd 0x76b0(%rip), %xmm2     # 0x100c0
xorps %xmm3, %xmm3
cvtsi2sd %eax, %xmm3
divsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x22a0(%r14,%rax,8)
incq %rax
cmpq $0x3e0, %rax            # imm = 0x3E0
jne 0x8a10
movl $0x7f800, %ecx          # imm = 0x7F800
movl $0xfffffe3a, %edx       # imm = 0xFFFFFE3A
movl $0x380, %eax            # imm = 0x380
movl %eax, 0x188(%r14)
movl %edx, 0x180(%r14)
movl %ecx, 0x184(%r14)
movl 0x198(%r14), %eax
movsd 0x767d(%rip), %xmm0     # 0x100e8
movsd 0x1a0(%r14,%rax,8), %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %ecx
movl %ecx, 0x41a4(%r14)
movl 0x41b8(%r14), %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x759d(%rip), %xmm1     # 0x10038
movsd 0x764d(%rip), %xmm2     # 0x100f0
minsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
cvttsd2si %xmm2, %eax
cmpl %eax, %ecx
jle 0x8aba
movl %eax, 0x41a4(%r14)
movl %ebx, 0x41bc(%r14)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop