// File: /workspace/github_c_makefile_star2_O0/j-hoppe[P]tu58fs/monitor.c
// Function: monitor_init
int monitor_init(monitor_t *_this, serial_device_t *serial, monitor_type_t monitor_type,
		FILE *fecho, int extra_delay_ms) {
	_this->serial = serial;
	_this->fecho = fecho;
	_this->monitor_type = monitor_type;
#ifdef TRACE
	trace_entry[0] = NULL; // empty list
#endif
	switch (_this->monitor_type) {
	case monitor_odt:
		_this->prompt = "@";
		break;
	case monitor_m9312:
		_this->prompt = "@";
		break;
	case monitor_m9301:
		_this->prompt = "$"; // and NUL appended
		break;
	case monitor_1144:
		_this->prompt = ">>>";
		break;
	default:
		return error_set(ERROR_MONITOR, "monitor_init(): Illegal boot monitor %u selected",
				monitor_type);
	}
//	_this->responsetime_us = 200000; // 1/5 th seconds
			// calc time for one bit from baudrate. 1 char = 10 bits
	_this->chartime_us = (1000000 * serial->bitcount) / _this->serial->baudrate;
	//
	// Wait for CPU reponse: 10 milli seconds CPU
	// 1 char time transfer to CPU, 1 char response, 1 char reserve ?
	// _this->responsetime_us = 10000 + 5 * _this->chartime_us;
	// worst case: M9301 at 300 baud: needs 10 chars?!
	_this->responsetime_us = 10000 + 10 * _this->chartime_us;

	// user slow-down for SUB-RS232 dongles. FTDI are worst, Prolific OK.
	// 1 timing unit = 10ms extra
	_this->responsetime_us += 1000 * extra_delay_ms ;

	_this->last_address = 0xffffffff; // invalidate

	return ERROR_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl (%rax), %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x3, %eax
ja 0x17178
movq -0x38(%rbp), %rax
leaq 0x6e6d(%rip), %rcx      # 0x1df98
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
leaq 0x6e71(%rip), %rcx      # 0x1dfb0
movq %rcx, 0x8(%rax)
jmp 0x17193
movq -0x10(%rbp), %rax
leaq 0x6e60(%rip), %rcx      # 0x1dfb0
movq %rcx, 0x8(%rax)
jmp 0x17193
movq -0x10(%rbp), %rax
leaq 0x6e51(%rip), %rcx      # 0x1dfb2
movq %rcx, 0x8(%rax)
jmp 0x17193
movq -0x10(%rbp), %rax
leaq 0x6e42(%rip), %rcx      # 0x1dfb4
movq %rcx, 0x8(%rax)
jmp 0x17193
movl -0x1c(%rbp), %edx
movl $0xfffffff6, %edi       # imm = 0xFFFFFFF6
leaq 0x6e31(%rip), %rsi      # 0x1dfb8
movb $0x0, %al
callq 0xcd70
movl %eax, -0x4(%rbp)
jmp 0x171eb
movq -0x18(%rbp), %rax
imull $0xf4240, 0x8(%rax), %eax # imm = 0xF4240
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
cltd
idivl 0x4(%rcx)
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rax
imull $0xa, 0x1c(%rax), %ecx
addl $0x2710, %ecx           # imm = 0x2710
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
imull $0x3e8, -0x2c(%rbp), %ecx # imm = 0x3E8
movq -0x10(%rbp), %rax
addl 0x18(%rax), %ecx
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x28(%rax) # imm = 0xFFFFFFFF
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)