// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x34(%rbp)
testl %eax, %eax
je 0x1415f
jmp 0x14077
movl -0x34(%rbp), %eax
decl %eax
subl $0x2, %eax
jb 0x14094
jmp 0x14083
movl -0x34(%rbp), %eax
subl $0x3, %eax
je 0x142f5
jmp 0x14440
movl $0x0, -0x10(%rbp)
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jge 0x14138
cvtsi2sdl -0x10(%rbp), %xmm0
movsd 0xb2a3(%rip), %xmm1     # 0x1f358
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd 0xb28a(%rip), %xmm0     # 0x1f350
mulsd -0x18(%rbp), %xmm0
movsd -0x18(%rbp), %xmm2
movsd 0xb270(%rip), %xmm1     # 0x1f348
mulsd -0x18(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0xb253(%rip), %xmm1     # 0x1f340
subsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x20(%rbp), %xmm0
jb 0x1410a
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x14114
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x40(%rbp), %rax
movsd -0x48(%rbp), %xmm0
movslq -0x10(%rbp), %rcx
movsd %xmm0, 0x1a0(%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x1409b
movq -0x40(%rbp), %rax
movl $0x0, 0x188(%rax)
movl $0x0, 0x180(%rax)
movl $0x0, 0x184(%rax)
jmp 0x14440
movl $0x0, -0x10(%rbp)
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jge 0x14202
cvtsi2sdl -0x10(%rbp), %xmm0
movsd 0xb1b8(%rip), %xmm1     # 0x1f338
divsd %xmm1, %xmm0
movsd 0xb154(%rip), %xmm1     # 0x1f2e0
subsd %xmm1, %xmm0
movsd 0xb148(%rip), %xmm1     # 0x1f2e0
divsd %xmm1, %xmm0
movsd 0xb134(%rip), %xmm1     # 0x1f2d8
mulsd %xmm1, %xmm0
callq 0x30b0
movsd %xmm0, -0x50(%rbp)
movsd 0xb11e(%rip), %xmm0     # 0x1f2d8
callq 0x30b0
movq -0x40(%rbp), %rax
movaps %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd 0xb119(%rip), %xmm1     # 0x1f2f0
mulsd %xmm1, %xmm0
movsd 0xb115(%rip), %xmm1     # 0x1f2f8
addsd %xmm1, %xmm0
movslq -0x10(%rbp), %rcx
movsd %xmm0, 0x1a0(%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x14166
jmp 0x14204
cmpl $0x420, -0x10(%rbp)     # imm = 0x420
jge 0x14268
movq -0x40(%rbp), %rax
cvtsi2sdl -0x10(%rbp), %xmm0
movsd 0xb0c2(%rip), %xmm1     # 0x1f2e0
subsd %xmm1, %xmm0
movsd 0xb106(%rip), %xmm1     # 0x1f330
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0xb0e0(%rip), %xmm1     # 0x1f320
mulsd %xmm1, %xmm0
movsd 0xb0dc(%rip), %xmm1     # 0x1f328
addsd %xmm1, %xmm0
movslq -0x10(%rbp), %rcx
movsd %xmm0, 0x1a0(%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x14204
jmp 0x1426a
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jge 0x142ce
movq -0x40(%rbp), %rax
cvtsi2sdl -0x10(%rbp), %xmm0
movsd 0xb094(%rip), %xmm1     # 0x1f318
subsd %xmm1, %xmm0
movsd 0xb080(%rip), %xmm1     # 0x1f310
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd 0xb05a(%rip), %xmm1     # 0x1f300
mulsd %xmm1, %xmm0
movsd 0xb056(%rip), %xmm1     # 0x1f308
addsd %xmm1, %xmm0
movslq -0x10(%rbp), %rcx
movsd %xmm0, 0x1a0(%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x1426a
movq -0x40(%rbp), %rax
movl $0x380, 0x188(%rax)     # imm = 0x380
movl $0xfffffe3a, 0x180(%rax) # imm = 0xFFFFFE3A
movl $0x7f800, 0x184(%rax)   # imm = 0x7F800
jmp 0x14440
movl $0x0, -0x10(%rbp)
cmpl $0x400, -0x10(%rbp)     # imm = 0x400
jge 0x1438c
cvtsi2sdl -0x10(%rbp), %xmm0
movsd 0xafca(%rip), %xmm1     # 0x1f2e0
subsd %xmm1, %xmm0
movsd 0xafbe(%rip), %xmm1     # 0x1f2e0
divsd %xmm1, %xmm0
movsd 0xafaa(%rip), %xmm1     # 0x1f2d8
mulsd %xmm1, %xmm0
callq 0x30b0
movsd %xmm0, -0x58(%rbp)
movsd 0xaf94(%rip), %xmm0     # 0x1f2d8
callq 0x30b0
movq -0x40(%rbp), %rax
movaps %xmm0, %xmm1
movsd -0x58(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd 0xaf8f(%rip), %xmm1     # 0x1f2f0
mulsd %xmm1, %xmm0
movsd 0xaf8b(%rip), %xmm1     # 0x1f2f8
addsd %xmm1, %xmm0
movslq -0x10(%rbp), %rcx
movsd %xmm0, 0x1a0(%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x142fc
jmp 0x1438e
cmpl $0x800, -0x10(%rbp)     # imm = 0x800
jge 0x1441e
cvtsi2sdl -0x10(%rbp), %xmm0
movsd 0xaf40(%rip), %xmm1     # 0x1f2e8
subsd %xmm1, %xmm0
movsd 0xaf2c(%rip), %xmm1     # 0x1f2e0
divsd %xmm1, %xmm0
movsd 0xaf18(%rip), %xmm1     # 0x1f2d8
mulsd %xmm1, %xmm0
callq 0x30b0
movsd %xmm0, -0x60(%rbp)
movsd 0xaf02(%rip), %xmm0     # 0x1f2d8
callq 0x30b0
movq -0x40(%rbp), %rax
movaps %xmm0, %xmm1
movsd -0x60(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd 0xaed5(%rip), %xmm1     # 0x1f2c8
mulsd %xmm1, %xmm0
movsd 0xaed1(%rip), %xmm1     # 0x1f2d0
addsd %xmm1, %xmm0
movslq -0x10(%rbp), %rcx
movsd %xmm0, 0x1a0(%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x1438e
movq -0x40(%rbp), %rax
movl $0x380, 0x188(%rax)     # imm = 0x380
movl $0xfffffe3a, 0x180(%rax) # imm = 0xFFFFFE3A
movl $0x7f800, 0x184(%rax)   # imm = 0x7F800
movq -0x40(%rbp), %rdi
callq 0x15170
movq -0x40(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, 0x41bc(%rax)
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)