// File: /workspace/github_c_makefile_star2_O3/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, 0xc295(%rip)      # 0x10b00
jne 0x4887
leaq 0x3c3c(%rip), %rdi      # 0x84b0
leaq 0x3c40(%rip), %rsi      # 0x84bb
callq 0x21d0
movq %rax, 0xc279(%rip)      # 0x10b00
xorl %ebx, %ebx
leaq 0xc280(%rip), %r14      # 0x10b10
movl $0x35, %edi
callq 0x21a0
movq %rax, (%rbx,%r14)
testq %rax, %rax
je 0x49e0
movaps 0x3bf2(%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 0x4890
xorl %ebx, %ebx
leaq 0xc2c6(%rip), %r14      # 0x10ba0
movl $0x51, %edi
callq 0x21a0
movq %rax, (%rbx,%r14)
testq %rax, %rax
je 0x49e7
movaps 0x3ba8(%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 0x48da
callq 0x20d0
xorl %ebx, %ebx
testq %rax, %rax
je 0x4a26
callq 0x2030
testb %al, %al
je 0x49f0
movq 0x769b(%rip), %r15      # 0xbfd8
movq (%r15), %rcx
testq %rcx, %rcx
je 0x49f7
movswl 0x4(%rcx), %eax
leal 0x1(%rax), %ebp
movswl 0x6(%rcx), %ecx
leal 0x1(%rcx), %r14d
cmpl $0x4f, %ecx
jl 0x4a02
cmpw $0x1c, %ax
jle 0x4a02
callq 0x2100
movl $0x1, %ebx
movl $0x1, %edi
movl $0x7, %esi
xorl %edx, %edx
callq 0x2190
movl $0x2, %edi
movl $0x6, %esi
movl $0x4, %edx
callq 0x2190
movl $0x3, %edi
movl $0x7, %esi
movl $0x4, %edx
callq 0x2190
callq 0x2180
callq 0x20b0
movq (%r15), %rdi
movl $0x1, %esi
callq 0x2120
callq 0x2060
movq (%r15), %rdi
xorl %esi, %esi
callq 0x2160
movq (%r15), %rdi
xorl %esi, %esi
callq 0x2170
jmp 0x4a26
callq 0x2314
jmp 0x49ec
callq 0x22f8
xorl %ebx, %ebx
jmp 0x4a26
callq 0x22d5
jmp 0x4a26
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
callq 0x2230
movq 0x75ea(%rip), %rax      # 0xbff8
movq (%rax), %rdi
leaq 0x3b03(%rip), %rsi      # 0x851b
xorl %ebx, %ebx
movl %r14d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2150
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq