// File: /workspace/github_c_makefile_star2_O1/hamsternz[P]emulate-risc-v/display.c
// Function: display_start
int display_start(void) {
  int i, maxx, maxy;
  if(log_file == NULL) {
    log_file = fopen("events.log","wb");
  }
  for(i = 0; i < N_TRACE; i++) {
    trace_lines[i] = malloc(TRACE_WIDTH+1);
    if(trace_lines[i] == NULL) {
      fprintf(stderr, "Unable to allocate trace lines\n");
      return 0;
    }
    memset(trace_lines[i], ' ', TRACE_WIDTH);
    trace_lines[i][TRACE_WIDTH] = 0;
  }

  for(i = 0; i < N_UART; i++) {
    uart_lines[i] = malloc(UART_WIDTH+1);
    if(uart_lines[i] == NULL) {
      fprintf(stderr, "Unable to allocate uart lines\n");
      return 0;
    }
    memset(uart_lines[i], ' ', UART_WIDTH);
    uart_lines[i][UART_WIDTH] = 0;
  }

  /* This sets up the screen */
  if(initscr()==NULL) {
    return 0;
  }

  if(!has_colors()) {
    endwin();
    fprintf(stderr,"Terminal must support colour\n");
    return 0;
  }

  getmaxyx(stdscr, maxy, maxx);
  if(maxx < 80 || maxy < 30)
  {
    endwin();
    fprintf(stderr,"Terminal must be at least 80x30 - currently %i x %i\n", maxx, maxy);
    return 0;
  }

  start_color();
  init_pair(BORDER_PAIR,   COLOR_WHITE, COLOR_BLACK);
  init_pair(INACTIVE_PAIR, COLOR_CYAN,  COLOR_BLUE);
  init_pair(ACTIVE_PAIR,   COLOR_WHITE, COLOR_BLUE);
  /* This sets up the keyboard to send character by
   *    *      character, without echoing to the screen */ 
  cbreak();
  noecho();
  keypad(stdscr, TRUE);
  nonl();
  timeout(0);
  intrflush(stdscr, FALSE);
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
cmpq $0x0, 0xc245(%rip)      # 0x10b00
jne 0x48d7
leaq 0x3bec(%rip), %rdi      # 0x84b0
leaq 0x3bf0(%rip), %rsi      # 0x84bb
callq 0x21c0
movq %rax, 0xc229(%rip)      # 0x10b00
xorl %ebx, %ebx
leaq 0xc230(%rip), %r14      # 0x10b10
movl $0x35, %edi
callq 0x2190
movq %rax, (%rbx,%r14)
testq %rax, %rax
je 0x4a46
movaps 0x3ba2(%rip), %xmm0     # 0x84a0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movl $0x20202020, 0x30(%rax) # imm = 0x20202020
movb $0x0, 0x34(%rax)
addq $0x8, %rbx
cmpq $0x88, %rbx
jne 0x48e0
xorl %ebx, %ebx
leaq 0xc276(%rip), %r14      # 0x10ba0
movl $0x51, %edi
callq 0x2190
movq %rax, (%rbx,%r14)
testq %rax, %rax
je 0x4a4d
movaps 0x3b58(%rip), %xmm0     # 0x84a0
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movb $0x0, 0x50(%rax)
addq $0x8, %rbx
cmpq $0x30, %rbx
jne 0x492a
callq 0x20d0
xorl %ebx, %ebx
testq %rax, %rax
je 0x4a39
callq 0x2030
testb %al, %al
je 0x4a56
movq 0x764b(%rip), %r15      # 0xbfd8
movq (%r15), %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x49a8
movswl 0x4(%rax), %r14d
incl %r14d
testq %rax, %rax
je 0x49b3
movswl 0x6(%rax), %ebp
incl %ebp
cmpl $0x50, %ebp
jl 0x4a5d
cmpl $0x1d, %r14d
jle 0x4a5d
callq 0x2100
movl $0x1, %ebx
movl $0x1, %edi
movl $0x7, %esi
xorl %edx, %edx
callq 0x2180
movl $0x2, %edi
movl $0x6, %esi
movl $0x4, %edx
callq 0x2180
movl $0x3, %edi
movl $0x7, %esi
movl $0x4, %edx
callq 0x2180
callq 0x2170
callq 0x20b0
movq (%r15), %rdi
movl $0x1, %esi
callq 0x2120
callq 0x2060
movq (%r15), %rdi
xorl %esi, %esi
callq 0x2150
movq (%r15), %rdi
xorl %esi, %esi
callq 0x2160
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x2304
jmp 0x4a52
callq 0x22e8
xorl %ebx, %ebx
jmp 0x4a39
callq 0x22c5
jmp 0x4a39
callq 0x2220
movq 0x758f(%rip), %rax      # 0xbff8
movq (%rax), %rdi
leaq 0x3aa8(%rip), %rsi      # 0x851b
xorl %ebx, %ebx
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2140
jmp 0x4a39