// File: /workspace/github_c_makefile_star2_O0/baines[P]MiniGBS/minigbs.c
// Function: mem_write
static inline void mem_write(uint16_t addr, uint8_t val){
	if(addr >= 0x2000 && addr < 0x4000){
		bank_switch(val);
	} else if(addr >= 0xFF10 && addr <= 0xFF40){
		audio_write(addr, val);
	} else if(addr < 0x8000){
		debug_msg("rom write?: [%4x] <- [%2x]", addr, val);
	} else if(addr == 0xFF06 || addr == 0xFF07){
		if(mem[addr] != val){
			mem[addr] = val;
			audio_update_rate();
		}
	} else {
		switch(addr){
			case 0xFF04: debug_msg("DIV write: %2x", val); break;
			case 0xFF05: debug_msg("TIMA write: %2x", val); break;
			case 0xFF0F: debug_msg("IF write: %2x", val); break;
			case 0xFF41: debug_msg("STAT: %2x", val); break;
			case 0xFF46: debug_msg("DMA: %2x", val); break;
			case 0xFFFF: debug_msg("IE: %2x", val); break;
		}
		mem[addr] = val;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movb %sil, %al
movw %di, %cx
movw %cx, -0x2(%rbp)
movb %al, -0x3(%rbp)
movzwl -0x2(%rbp), %eax
cmpl $0x2000, %eax           # imm = 0x2000
jl 0x9c59
movzwl -0x2(%rbp), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jge 0x9c59
movzbl -0x3(%rbp), %edi
callq 0xa0e0
jmp 0x9dcb
movzwl -0x2(%rbp), %eax
cmpl $0xff10, %eax           # imm = 0xFF10
jl 0x9c84
movzwl -0x2(%rbp), %eax
cmpl $0xff40, %eax           # imm = 0xFF40
jg 0x9c84
movw -0x2(%rbp), %ax
movzwl %ax, %edi
movzbl -0x3(%rbp), %esi
callq 0xca10
jmp 0x9dc9
movzwl -0x2(%rbp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jge 0x9caa
movzwl -0x2(%rbp), %esi
movzbl -0x3(%rbp), %edx
leaq 0x6d3f(%rip), %rdi      # 0x109dd
movb $0x0, %al
callq 0xacd0
jmp 0x9dc7
movzwl -0x2(%rbp), %eax
cmpl $0xff06, %eax           # imm = 0xFF06
je 0x9cc0
movzwl -0x2(%rbp), %eax
cmpl $0xff07, %eax           # imm = 0xFF07
jne 0x9cf2
movq 0xcc49(%rip), %rax      # 0x16910
movzwl -0x2(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movzbl -0x3(%rbp), %ecx
cmpl %ecx, %eax
je 0x9ced
movb -0x3(%rbp), %dl
movq 0xcc2f(%rip), %rax      # 0x16910
movzwl -0x2(%rbp), %ecx
movb %dl, (%rax,%rcx)
callq 0xc290
jmp 0x9dc5
movzwl -0x2(%rbp), %eax
movl %eax, -0x8(%rbp)
subl $0xff04, %eax           # imm = 0xFF04
je 0x9d3e
jmp 0x9d02
movl -0x8(%rbp), %eax
subl $0xff05, %eax           # imm = 0xFF05
je 0x9d52
jmp 0x9d0e
movl -0x8(%rbp), %eax
subl $0xff0f, %eax           # imm = 0xFF0F
je 0x9d66
jmp 0x9d1a
movl -0x8(%rbp), %eax
subl $0xff41, %eax           # imm = 0xFF41
je 0x9d7a
jmp 0x9d26
movl -0x8(%rbp), %eax
subl $0xff46, %eax           # imm = 0xFF46
je 0x9d8e
jmp 0x9d32
movl -0x8(%rbp), %eax
subl $0xffff, %eax           # imm = 0xFFFF
je 0x9da2
jmp 0x9db4
movzbl -0x3(%rbp), %esi
leaq 0x6caf(%rip), %rdi      # 0x109f8
movb $0x0, %al
callq 0xacd0
jmp 0x9db4
movzbl -0x3(%rbp), %esi
leaq 0x6caa(%rip), %rdi      # 0x10a07
movb $0x0, %al
callq 0xacd0
jmp 0x9db4
movzbl -0x3(%rbp), %esi
leaq 0x6ca6(%rip), %rdi      # 0x10a17
movb $0x0, %al
callq 0xacd0
jmp 0x9db4
movzbl -0x3(%rbp), %esi
leaq 0x6ca0(%rip), %rdi      # 0x10a25
movb $0x0, %al
callq 0xacd0
jmp 0x9db4
movzbl -0x3(%rbp), %esi
leaq 0x6c96(%rip), %rdi      # 0x10a2f
movb $0x0, %al
callq 0xacd0
jmp 0x9db4
movzbl -0x3(%rbp), %esi
leaq 0x6c8b(%rip), %rdi      # 0x10a38
movb $0x0, %al
callq 0xacd0
movb -0x3(%rbp), %dl
movq 0xcb52(%rip), %rax      # 0x16910
movzwl -0x2(%rbp), %ecx
movb %dl, (%rax,%rcx)
jmp 0x9dc7
jmp 0x9dc9
jmp 0x9dcb
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)