// File: mrlordkaj[P]i2cdevlib-pi/MS5803/MS5803.cpp
// Function: MS5803::initialize(unsigned char)
bool MS5803::initialize(uint8_t model) {
	_initialized = false;
	// Make sure model is valid.
	switch (model) {
		case ( 1): _model = BA01; break;
		case ( 2): _model = BA02; break;
		case ( 5): _model = BA05; break;
		case (14): _model = BA14; break;
		case (30): _model = BA30; break;
		default:
			Serial.print(F("MS5803 Model entered (")); Serial.print(model); Serial.println(F(") is not valid/supported."));
			_model = INVALID; 
			return 0;
	}
	if (_debug) Serial.println(reset());
	uint8_t tries = 0;
	do {
		_getCalConstants(); // Seems to partially fail the first try sometimes.
		if (_c1_SENSt1 && _c2_OFFt1 && _c3_TCS && _c4_TCO && _c5_Tref && _c6_TEMPSENS ) _initialized = true; // They must all be non-0
		tries++;
	} while (!_initialized && ( tries < INIT_TRIES) );
	if (_debug) {
		for ( uint8_t i = 1 ; i <= 6; i++){
			Serial.print(i);
			Serial.print(": ");
			Serial.print(CALIBRATION_CONSTANTS[i-1]);
			Serial.print(" = ");
			Serial.println(_getCalConstant(i));
		}
	}
	return _initialized;
}

// Assembly:
subq $0x38, %rsp
movb %sil, %al
movq %rdi, 0x28(%rsp)
movb %al, 0x27(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movb $0x0, 0x14(%rax)
movzbl 0x27(%rsp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, 0x18(%rsp)
subl $0x1d, %eax
ja 0x4814f
movq 0x18(%rsp), %rax
leaq 0x3ccb(%rip), %rcx      # 0x4bdc8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%rsp), %rax
movl $0x1, 0x10(%rax)
jmp 0x4819c
movq 0x10(%rsp), %rax
movl $0x2, 0x10(%rax)
jmp 0x4819c
movq 0x10(%rsp), %rax
movl $0x5, 0x10(%rax)
jmp 0x4819c
movq 0x10(%rsp), %rax
movl $0xe, 0x10(%rax)
jmp 0x4819c
movq 0x10(%rsp), %rax
movl $0x1e, 0x10(%rax)
jmp 0x4819c
movq 0x13e0a(%rip), %rdi     # 0x5bf60
leaq 0x3ece(%rip), %rsi      # 0x4c02b
callq 0x22e80
movq 0x13df7(%rip), %rdi     # 0x5bf60
movzbl 0x27(%rsp), %esi
callq 0x22ba0
movq 0x13de6(%rip), %rdi     # 0x5bf60
leaq 0x3ec1(%rip), %rsi      # 0x4c042
callq 0x22de0
movq 0x10(%rsp), %rax
movl $0x0, 0x10(%rax)
movb $0x0, 0x37(%rsp)
jmp 0x48307
movq 0x10(%rsp), %rax
testb $0x1, 0x15(%rax)
je 0x481c0
movq 0x10(%rsp), %rdi
callq 0x234c0
movq 0x13da8(%rip), %rdi     # 0x5bf60
movzwl %ax, %esi
callq 0x22fa0
movb $0x0, 0x26(%rsp)
movq 0x10(%rsp), %rdi
callq 0x22890
movq 0x10(%rsp), %rax
cmpl $0x0, 0x18(%rax)
je 0x4821a
movq 0x10(%rsp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x4821a
movq 0x10(%rsp), %rax
cmpl $0x0, 0x20(%rax)
je 0x4821a
movq 0x10(%rsp), %rax
cmpl $0x0, 0x24(%rax)
je 0x4821a
movq 0x10(%rsp), %rax
cmpl $0x0, 0x28(%rax)
je 0x4821a
movq 0x10(%rsp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x4821a
movq 0x10(%rsp), %rax
movb $0x1, 0x14(%rax)
movb 0x26(%rsp), %al
addb $0x1, %al
movb %al, 0x26(%rsp)
movq 0x10(%rsp), %rcx
xorl %eax, %eax
testb $0x1, 0x14(%rcx)
movb %al, 0xf(%rsp)
jne 0x48244
movzbl 0x26(%rsp), %eax
cmpl $0x3, %eax
setl %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x481c5
movq 0x10(%rsp), %rax
testb $0x1, 0x15(%rax)
je 0x482f9
movb $0x1, 0x25(%rsp)
movzbl 0x25(%rsp), %eax
cmpl $0x6, %eax
jg 0x482f7
movq 0x13ce7(%rip), %rdi     # 0x5bf60
movzbl 0x25(%rsp), %esi
callq 0x22ba0
movq 0x13cd6(%rip), %rdi     # 0x5bf60
leaq 0x2f3e(%rip), %rsi      # 0x4b1cf
callq 0x22e80
movzbl 0x25(%rsp), %eax
subl $0x1, %eax
movslq %eax, %rcx
movq 0x13cc8(%rip), %rax     # 0x5bf70
movq (%rax,%rcx,8), %rsi
movq 0x13cad(%rip), %rdi     # 0x5bf60
callq 0x22e80
movq 0x13ca1(%rip), %rdi     # 0x5bf60
leaq 0x3e2d(%rip), %rsi      # 0x4c0f3
callq 0x22e80
movq 0x10(%rsp), %rdi
movzbl 0x25(%rsp), %esi
callq 0x233e0
movl %eax, %esi
movq 0x13c7d(%rip), %rdi     # 0x5bf60
callq 0x230b0
movb 0x25(%rsp), %al
addb $0x1, %al
movb %al, 0x25(%rsp)
jmp 0x48264
jmp 0x482f9
movq 0x10(%rsp), %rax
movb 0x14(%rax), %al
andb $0x1, %al
movb %al, 0x37(%rsp)
movb 0x37(%rsp), %al
andb $0x1, %al
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)