// File: /workspace/github_c_makefile_star2_O0/mrdudz[P]run6502/run6502.c
// Function: osbyte
int osbyte(M6502 *mpu, word address, byte data)
{
  switch (mpu->registers->a)
    {
    case 0x7A:	/* perform keyboard scan */
      mpu->registers->x= 0x00;
      break;

    case 0x7E:	/* acknowledge detection of escape condition */
      return 1;
      break;

    case 0x82:	/* read machine higher order address */
      mpu->registers->y= 0x00;
      mpu->registers->x= 0x00;
      break;

    case 0x83:	/* read top of OS ram address (OSHWM) */
      mpu->registers->y= 0x0E;
      mpu->registers->x= 0x00;
      break;

    case 0x84:	/* read bottom of display ram address */
      mpu->registers->y= 0x80;
      mpu->registers->x= 0x00;
      break;

    case 0x89:	/* motor control */
      break;

    case 0xDA:	/* read/write number of items in vdu queue (stored at 0x026A) */
      return 0;
      break;

    default:
      {
	char state[64];
	M6502_dump(mpu, state);
	fflush(stdout);
	fprintf(stderr, "\nOSBYTE %s\n", state);
	fail("ABORT");
      }
      break;
    }

  rts;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %dl, %al
movw %si, %cx
movq %rdi, -0x10(%rbp)
movw %cx, -0x12(%rbp)
movb %al, -0x13(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movzbl (%rax), %eax
movl %eax, -0x68(%rbp)
subl $0x7a, %eax
je 0x1652
jmp 0x160c
movl -0x68(%rbp), %eax
subl $0x7e, %eax
je 0x1662
jmp 0x1616
movl -0x68(%rbp), %eax
subl $0x82, %eax
je 0x166e
jmp 0x1622
movl -0x68(%rbp), %eax
subl $0x83, %eax
je 0x1689
jmp 0x162e
movl -0x68(%rbp), %eax
subl $0x84, %eax
je 0x16a1
jmp 0x163a
movl -0x68(%rbp), %eax
subl $0x89, %eax
je 0x16b9
jmp 0x1646
movl -0x68(%rbp), %eax
subl $0xda, %eax
je 0x16bb
jmp 0x16c7
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb $0x0, 0x1(%rax)
jmp 0x170d
movl $0x1, -0x4(%rbp)
jmp 0x1778
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb $0x0, 0x2(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb $0x0, 0x1(%rax)
jmp 0x170d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb $0xe, 0x2(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb $0x0, 0x1(%rax)
jmp 0x170d
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb $-0x80, 0x2(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movb $0x0, 0x1(%rax)
jmp 0x170d
jmp 0x170d
movl $0x0, -0x4(%rbp)
jmp 0x1778
movq -0x10(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x7570
movq 0x168f5(%rip), %rax     # 0x17fd0
movq (%rax), %rdi
callq 0x1150
movq 0x1690e(%rip), %rax     # 0x17ff8
movq (%rax), %rdi
leaq -0x60(%rbp), %rdx
leaq 0x1391e(%rip), %rsi     # 0x15016
movb $0x0, %al
callq 0x1120
leaq 0x1390a(%rip), %rdi     # 0x15010
movb $0x0, %al
callq 0x12d0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rdx
movb 0x4(%rdx), %cl
addb $0x1, %cl
movb %cl, 0x4(%rdx)
movzbl %cl, %ecx
addl $0x100, %ecx            # imm = 0x100
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movw %ax, -0x62(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq (%rcx), %rdx
movb 0x4(%rdx), %cl
addb $0x1, %cl
movb %cl, 0x4(%rdx)
movzbl %cl, %ecx
addl $0x100, %ecx            # imm = 0x100
movslq %ecx, %rcx
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
movzwl -0x62(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x62(%rbp)
movzwl -0x62(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)