// File: /workspace/github_c_makefile_star2_O3/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 0x88fa
testl %ebx, %ebx
je 0x899b
cmpl $0x3, %ebx
jne 0x8af2
xorl %r15d, %r15d
movsd 0x787a(%rip), %xmm1     # 0x10068
movsd 0x7842(%rip), %xmm2     # 0x10038
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 0x7818(%rip), %xmm0     # 0x10038
callq 0x30b0
movsd 0x7843(%rip), %xmm0     # 0x10070
movsd 0x7803(%rip), %xmm2     # 0x10038
movsd 0x782b(%rip), %xmm1     # 0x10068
movsd 0x8(%rsp), %xmm3
addsd %xmm0, %xmm3
mulsd 0x7829(%rip), %xmm3     # 0x10078
addsd 0x7829(%rip), %xmm3     # 0x10080
movsd %xmm3, 0x1a0(%r14,%r15,8)
incq %r15
cmpq $0x400, %r15            # imm = 0x400
jne 0x87f6
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 0x779a(%rip), %xmm0     # 0x10038
callq 0x30b0
movsd 0x778d(%rip), %xmm2     # 0x10038
movsd 0x77b5(%rip), %xmm1     # 0x10068
movsd 0x8(%rsp), %xmm0
addsd 0x77af(%rip), %xmm0     # 0x10070
mulsd 0x77bf(%rip), %xmm0     # 0x10088
addsd 0x77bf(%rip), %xmm0     # 0x10090
movsd %xmm0, 0x21a0(%r14,%r15,8)
incq %r15
cmpq $0x400, %r15            # imm = 0x400
jne 0x8870
movl $0x380, %eax            # imm = 0x380
movsd 0x77db(%rip), %xmm9     # 0x100d0
jmp 0x8ae2
movsd 0x683e(%rip), %xmm0     # 0xf140
xorl %eax, %eax
movapd 0x7884(%rip), %xmm1     # 0x10190
movapd 0x788c(%rip), %xmm2     # 0x101a0
movapd 0x7894(%rip), %xmm3     # 0x101b0
movapd 0x789c(%rip), %xmm4     # 0x101c0
movapd 0x78a4(%rip), %xmm5     # 0x101d0
xorpd %xmm9, %xmm9
movdqa 0x77f7(%rip), %xmm6     # 0x10130
xorl %ecx, %ecx
movapd %xmm0, %xmm7
unpcklps %xmm9, %xmm7            # xmm7 = xmm7[0],xmm9[0],xmm7[1],xmm9[1]
orpd %xmm1, %xmm7
subpd %xmm1, %xmm7
mulpd %xmm2, %xmm7
movapd %xmm7, %xmm8
mulpd %xmm3, %xmm8
mulpd %xmm7, %xmm8
mulpd %xmm4, %xmm7
addpd %xmm8, %xmm7
addpd %xmm5, %xmm7
movapd %xmm7, %xmm8
cmpnlepd %xmm9, %xmm8
andpd %xmm7, %xmm8
movupd %xmm8, 0x1a0(%r14,%rcx,8)
addq $0x2, %rcx
paddd %xmm6, %xmm0
cmpq $0x800, %rcx            # imm = 0x800
jne 0x893b
jmp 0x8ae2
xorl %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
divsd 0x76ea(%rip), %xmm0     # 0x10098
addsd 0x76ea(%rip), %xmm0     # 0x100a0
mulsd 0x76aa(%rip), %xmm0     # 0x10068
movsd 0x7672(%rip), %xmm1     # 0x10038
mulsd %xmm1, %xmm0
callq 0x30b0
movsd %xmm0, 0x8(%rsp)
movsd 0x765b(%rip), %xmm0     # 0x10038
callq 0x30b0
movsd 0x8(%rsp), %xmm0
addsd 0x7680(%rip), %xmm0     # 0x10070
mulsd 0x7680(%rip), %xmm0     # 0x10078
addsd 0x7680(%rip), %xmm0     # 0x10080
movsd %xmm0, 0x1a0(%r14,%r15,8)
incq %r15
cmpq $0x400, %r15            # imm = 0x400
jne 0x899e
movq 0x76c2(%rip), %xmm1     # 0x100e0
xorl %eax, %eax
movdqa 0x76c8(%rip), %xmm2     # 0x100f0
movapd 0x76d0(%rip), %xmm3     # 0x10100
movapd 0x76d8(%rip), %xmm4     # 0x10110
movapd 0x76e0(%rip), %xmm5     # 0x10120
movdqa 0x76e8(%rip), %xmm0     # 0x10130
movdqa %xmm1, %xmm6
paddd %xmm2, %xmm6
cvtdq2pd %xmm6, %xmm6
divpd %xmm3, %xmm6
mulpd %xmm4, %xmm6
addpd %xmm5, %xmm6
movupd %xmm6, 0x21a0(%r14,%rax,8)
addq $0x2, %rax
paddd %xmm0, %xmm1
cmpq $0x20, %rax
jne 0x8a48
movq 0x76c0(%rip), %xmm1     # 0x10140
xorl %eax, %eax
movdqa 0x76c6(%rip), %xmm2     # 0x10150
movapd 0x76ce(%rip), %xmm3     # 0x10160
movapd 0x76d6(%rip), %xmm4     # 0x10170
movapd 0x76de(%rip), %xmm5     # 0x10180
movsd 0x7625(%rip), %xmm9     # 0x100d0
movdqa %xmm1, %xmm6
paddd %xmm2, %xmm6
cvtdq2pd %xmm6, %xmm6
divpd %xmm3, %xmm6
mulpd %xmm4, %xmm6
addpd %xmm5, %xmm6
movupd %xmm6, 0x22a0(%r14,%rax,8)
addq $0x2, %rax
paddd %xmm0, %xmm1
cmpq $0x3e0, %rax            # imm = 0x3E0
jne 0x8aab
movl $0x380, %eax            # imm = 0x380
movl %eax, 0x188(%r14)
movlpd %xmm9, 0x180(%r14)
movl 0x198(%r14), %eax
movl 0x41b8(%r14), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd 0x7538(%rip), %xmm0     # 0x10048
movsd 0x7590(%rip), %xmm1     # 0x100a8
minsd %xmm0, %xmm1
movsd 0x1a0(%r14,%rax,8), %xmm0
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
mulpd 0x76ae(%rip), %xmm0     # 0x101e0
cvttpd2dq %xmm0, %xmm0
movd %xmm0, %eax
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %ecx
cmpl %ecx, %eax
cmovgl %ecx, %eax
movl %eax, 0x41a4(%r14)
movl %ebx, 0x41bc(%r14)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq