// File: /workspace/github_c_makefile_star2_O0/mrdudz[P]run6502/run6502.c
// Function: doBtraps
static int doBtraps(int argc, char **argv, M6502 *mpu)
{
  unsigned addr;

  /* Acorn Model B ROM and memory-mapped IO */

  for (addr= 0x8000;  addr <= 0xFBFF;  ++addr)  mpu->callbacks->write[addr]= writeROM;
  for (addr= 0xFC00;  addr <= 0xFEFF;  ++addr)  mpu->memory[addr]= 0xFF;
  for (addr= 0xFE30;  addr <= 0xFE33;  ++addr)  mpu->callbacks->write[addr]= bankSelect;
  for (addr= 0xFE40;  addr <= 0xFE4F;  ++addr)  mpu->memory[addr]= 0x00;
  for (addr= 0xFF00;  addr <= 0xFFFF;  ++addr)  mpu->callbacks->write[addr]= writeROM;

  /* anything already loaded at 0x8000 appears in bank 0 */

  memcpy(bank[0x00], mpu->memory + 0x8000, 0x4000);

  /* fake a few interesting OS calls */

# define trap(vec, addr, func)   mpu->callbacks->call[addr]= (func)
  trap(0x020C, 0xFFF1, osword);
  trap(0x020A, 0xFFF4, osbyte);
//trap(0x0208, 0xFFF7, oscli );	/* enable this to send '*COMMAND's to system(3) :-) */
  trap(0x020E, 0xFFEE, oswrch);
  trap(0x020E, 0xE0A4, oswrch);	/* NVWRCH */
#undef trap

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x8000, -0x1c(%rbp)    # imm = 0x8000
cmpl $0xfbff, -0x1c(%rbp)    # imm = 0xFBFF
ja 0x2118
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
leaq 0xa8b(%rip), %rdx       # 0x2b90
movq %rdx, 0x80000(%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x20ea
movl $0xfc00, -0x1c(%rbp)    # imm = 0xFC00
cmpl $0xfeff, -0x1c(%rbp)    # imm = 0xFEFF
ja 0x2142
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
movb $-0x1, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x211f
movl $0xfe30, -0x1c(%rbp)    # imm = 0xFE30
cmpl $0xfe33, -0x1c(%rbp)    # imm = 0xFE33
ja 0x2177
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
leaq 0xa4c(%rip), %rdx       # 0x2bb0
movq %rdx, 0x80000(%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2149
movl $0xfe40, -0x1c(%rbp)    # imm = 0xFE40
cmpl $0xfe4f, -0x1c(%rbp)    # imm = 0xFE4F
ja 0x21a1
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x217e
movl $0xff00, -0x1c(%rbp)    # imm = 0xFF00
cmpl $0xffff, -0x1c(%rbp)    # imm = 0xFFFF
ja 0x21d6
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
leaq 0x9cd(%rip), %rdx       # 0x2b90
movq %rdx, 0x80000(%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x21a8
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x8000, %rsi           # imm = 0x8000
leaq 0x15f34(%rip), %rdi     # 0x18120
movl $0x4000, %edx           # imm = 0x4000
callq 0x1140
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
leaq -0xe35(%rip), %rcx      # 0x13d0
movq %rcx, 0x17ff88(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
leaq -0xc3b(%rip), %rcx      # 0x15e0
movq %rcx, 0x17ffa0(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
leaq -0x921(%rip), %rcx      # 0x1910
movq %rcx, 0x17ff70(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
leaq -0x937(%rip), %rcx      # 0x1910
movq %rcx, 0x170520(%rax)
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)