// File: /workspace/github_c_makefile_star2_O2/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, 0xc46d(%rip)      # 0x10af0
jne 0x469f
leaq 0x3e24(%rip), %rdi      # 0x84b0
leaq 0x3e28(%rip), %rsi      # 0x84bb
callq 0x21b0
movq %rax, 0xc451(%rip)      # 0x10af0
xorl %r14d, %r14d
pushq $0x35
popq %rbx
leaq 0xc454(%rip), %r15      # 0x10b00
cmpq $0x88, %r14
je 0x46ed
movq %rbx, %rdi
callq 0x2190
movq %rax, (%r14,%r15)
testq %rax, %rax
je 0x47fa
movaps 0x3dcf(%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, %r14
jmp 0x46ac
xorl %r14d, %r14d
pushq $0x51
popq %rbx
leaq 0xc496(%rip), %r15      # 0x10b90
cmpq $0x30, %r14
je 0x4739
movq %rbx, %rdi
callq 0x2190
movq %rax, (%r14,%r15)
testq %rax, %rax
je 0x480f
movaps 0x3d84(%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, %r14
jmp 0x46fa
callq 0x20d0
xorl %ebx, %ebx
testq %rax, %rax
je 0x47ed
callq 0x2030
testb %al, %al
je 0x482f
movq 0x787b(%rip), %r15      # 0xbfd8
movq (%r15), %rcx
testq %rcx, %rcx
je 0x4852
movswl 0x4(%rcx), %eax
leal 0x1(%rax), %ebp
movswl 0x6(%rcx), %ecx
leal 0x1(%rcx), %r14d
cmpl $0x4f, %ecx
jl 0x4859
cmpw $0x1c, %ax
jle 0x4859
callq 0x20f0
pushq $0x1
popq %rbx
pushq $0x7
popq %rbp
movl %ebx, %edi
movl %ebp, %esi
xorl %edx, %edx
callq 0x2180
pushq $0x2
popq %rdi
pushq $0x6
popq %rsi
pushq $0x4
popq %r14
movl %r14d, %edx
callq 0x2180
pushq $0x3
popq %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x2180
callq 0x2170
callq 0x20b0
movq (%r15), %rdi
movl %ebx, %esi
callq 0x2110
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
movq 0x77f7(%rip), %rax      # 0xbff8
movq (%rax), %rcx
leaq 0x3cb3(%rip), %rdi      # 0x84be
pushq $0x1f
jmp 0x4822
movq 0x77e2(%rip), %rax      # 0xbff8
movq (%rax), %rcx
leaq 0x3cbe(%rip), %rdi      # 0x84de
pushq $0x1e
popq %rsi
pushq $0x1
popq %rdx
callq 0x2200
xorl %ebx, %ebx
jmp 0x47ed
callq 0x2210
movq 0x77bd(%rip), %rax      # 0xbff8
movq (%rax), %rcx
leaq 0x3cb8(%rip), %rdi      # 0x84fd
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x2200
jmp 0x47ed
pushq $-0x1
popq %r14
movl %r14d, %ebp
callq 0x2210
movq 0x7793(%rip), %rax      # 0xbff8
movq (%rax), %rdi
leaq 0x3cac(%rip), %rsi      # 0x851b
xorl %ebx, %ebx
movl %r14d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2140
jmp 0x47ed