// File: /workspace/github_c_makefile_star2_O2/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 0x860c
testl %ebx, %ebx
je 0x8682
cmpl $0x3, %ebx
jne 0x8826
xorl %r15d, %r15d
cmpq $0x400, %r15            # imm = 0x400
je 0x8700
movl %r15d, %eax
orl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cvtsi2sd %eax, %xmm0
mulsd 0x6aad(%rip), %xmm0     # 0xf068
movsd 0x6a7d(%rip), %xmm1     # 0xf040
mulsd %xmm1, %xmm0
callq 0x30a0
movsd %xmm0, 0x8(%rsp)
movsd 0x6a66(%rip), %xmm0     # 0xf040
callq 0x30a0
movsd 0x8(%rsp), %xmm0
addsd 0x6a83(%rip), %xmm0     # 0xf070
mulsd 0x6a83(%rip), %xmm0     # 0xf078
addsd 0x6a83(%rip), %xmm0     # 0xf080
movsd %xmm0, 0x1a0(%r14,%r15,8)
incq %r15
jmp 0x859a
xorl %eax, %eax
movsd 0x6ac2(%rip), %xmm0     # 0xf0d8
movsd 0x6ac2(%rip), %xmm1     # 0xf0e0
movsd 0x6ac2(%rip), %xmm2     # 0xf0e8
movsd 0x6ac2(%rip), %xmm3     # 0xf0f0
xorpd %xmm4, %xmm4
xorl %ecx, %ecx
cmpq $0x800, %rcx            # imm = 0x800
je 0x8679
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
jmp 0x8634
xorpd %xmm4, %xmm4
jmp 0x8816
xorl %r15d, %r15d
cmpq $0x400, %r15            # imm = 0x400
je 0x8789
cvtsi2sd %r15d, %xmm0
divsd 0x69f9(%rip), %xmm0     # 0xf098
addsd 0x69f9(%rip), %xmm0     # 0xf0a0
mulsd 0x69b9(%rip), %xmm0     # 0xf068
movsd 0x6989(%rip), %xmm1     # 0xf040
mulsd %xmm1, %xmm0
callq 0x30a0
movsd %xmm0, 0x8(%rsp)
movsd 0x6972(%rip), %xmm0     # 0xf040
callq 0x30a0
movsd 0x8(%rsp), %xmm0
addsd 0x698f(%rip), %xmm0     # 0xf070
mulsd 0x698f(%rip), %xmm0     # 0xf078
addsd 0x698f(%rip), %xmm0     # 0xf080
movsd %xmm0, 0x1a0(%r14,%r15,8)
incq %r15
jmp 0x8685
xorl %r15d, %r15d
movsd 0x6a15(%rip), %xmm4     # 0xf120
cmpq $0x400, %r15            # imm = 0x400
je 0x8811
leal 0x400(%r15), %eax
orl $0xfffff800, %eax       # imm = 0xFFFFF800
cvtsi2sd %eax, %xmm0
mulsd 0x6938(%rip), %xmm0     # 0xf068
movsd 0x6908(%rip), %xmm1     # 0xf040
mulsd %xmm1, %xmm0
callq 0x30a0
movsd %xmm0, 0x8(%rsp)
movsd 0x68f1(%rip), %xmm0     # 0xf040
callq 0x30a0
movsd 0x69c4(%rip), %xmm4     # 0xf120
movsd 0x8(%rsp), %xmm0
addsd 0x6906(%rip), %xmm0     # 0xf070
mulsd 0x6916(%rip), %xmm0     # 0xf088
addsd 0x6916(%rip), %xmm0     # 0xf090
movsd %xmm0, 0x21a0(%r14,%r15,8)
incq %r15
jmp 0x870b
xorl %eax, %eax
movsd 0x6915(%rip), %xmm0     # 0xf0a8
movsd 0x6915(%rip), %xmm1     # 0xf0b0
movsd 0x6915(%rip), %xmm2     # 0xf0b8
cmpq $0x20, %rax
je 0x87c8
cvtsi2sd %eax, %xmm3
divsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x21a0(%r14,%rax,8)
incq %rax
jmp 0x87a3
xorl %eax, %eax
movsd 0x694e(%rip), %xmm4     # 0xf120
movsd 0x68e6(%rip), %xmm0     # 0xf0c0
movsd 0x68e6(%rip), %xmm1     # 0xf0c8
movsd 0x68e6(%rip), %xmm2     # 0xf0d0
cmpq $0x3e0, %rax            # imm = 0x3E0
je 0x8811
cvtsi2sd %eax, %xmm3
divsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x22a0(%r14,%rax,8)
incq %rax
jmp 0x87ea
movl $0x380, %eax            # imm = 0x380
movl %eax, 0x188(%r14)
movlpd %xmm4, 0x180(%r14)
movq %r14, %rdi
callq 0x8eac
movl %ebx, 0x41bc(%r14)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop