// File: /workspace/github_c_makefile_star2_O2/ughman[P]c2c/src/emu.c
// Function: EMU_Write8
void EMU_Write8(uint32_t address,uint8_t value)
{
	if (address >= 0x80000000 && address <= 0x801FFFFF)
	{
normal:
		{
			uint32_t (*codehandler)(uint32_t) = EMU_codemap[(address & 0x1FFFFF) >> 2];
			if (codehandler != EMU_ExecuteUnrecognizedCode)
			{
				SDL_LogError(LOG_EMU,"Writing over code");
			}
		}
		uint32_t *word = &EMU_ram[(address & 0x1FFFFF) >> 2];
		*word &= ~(0xFF << (address & 3) * 8);
		*word |= value << (address & 3) * 8;
	}
	else if (address >= 0x0 && address <= 0x1FFFFF)
	{
		goto normal;
	}
	else if (address >= 0xA0000000 && address <= 0xA01FFFFF)
	{
		goto normal;
	}
	else if (address >= 0x1F800000 && address <= 0x1F8003FF)
	{
		uint32_t *word = &EMU_scratch[(address & 0x3FF) >> 2];
		*word &= ~(0xFF << (address & 3) * 8);
		*word |= value << (address & 3) * 8;
	}
	else switch (address)
	{
	case 0x1F801040:
		PAD_Write(value);
		break;
	case 0x1F801800:
		CDR_SetMode(value);
		break;
	case 0x1F801801:
		CDR_Write1(value);
		break;
	case 0x1F801802:
		CDR_Write2(value);
		break;
	case 0x1F801803:
		CDR_Write3(value);
		break;
	default:
		SDL_LogError(LOG_EMU,"Unrecognized 8-bit write address %.8X",address);
		PCSX_Write8(address,value);
		break;
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %esi, %ebx
movl %edi, %r14d
testl $0x7fe00000, %edi       # imm = 0x7FE00000
setne %al
movl %edi, %ecx
andl $0xffe00000, %ecx       # imm = 0xFFE00000
cmpl $0xa0000000, %ecx       # imm = 0xA0000000
setne %cl
testb %cl, %al
jne 0x1358bf
movl %r14d, %r15d
shrl $0x2, %r15d
andl $0x7ffff, %r15d         # imm = 0x7FFFF
leaq 0x24ae7(%rip), %rax     # 0x15a360
leaq -0x588(%rip), %rcx      # 0x1352f8
cmpq %rcx, (%rax,%r15,8)
je 0x135897
leaq 0x4903(%rip), %rsi      # 0x13a190
pushq $0x13
popq %rdi
xorl %eax, %eax
callq 0x10d0
shll $0x3, %r14d
movl $0xff, %eax
movl %r14d, %ecx
shll %cl, %eax
movq 0x424ab4(%rip), %rdx    # 0x55a360
notl %eax
movzbl %bl, %esi
shll %cl, %esi
andl (%rdx,%r15,4), %eax
orl %eax, %esi
movl %esi, (%rdx,%r15,4)
jmp 0x1358fa
movl %r14d, %eax
andl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x1f800000, %eax       # imm = 0x1F800000
jne 0x135900
movl %r14d, %eax
shll $0x3, %r14d
movl $0xff, %edx
movl %r14d, %ecx
shll %cl, %edx
movq 0x424a82(%rip), %rsi    # 0x55a368
andl $0x3fc, %eax            # imm = 0x3FC
notl %edx
movzbl %bl, %edi
shll %cl, %edi
andl (%rsi,%rax), %edx
orl %edx, %edi
movl %edi, (%rsi,%rax)
popq %rbx
popq %r14
popq %r15
retq
leal -0x1f801800(%r14), %eax
cmpl $0x3, %eax
ja 0x135929
leaq 0x3f65(%rip), %rcx      # 0x139878
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl %bl, %edi
popq %rbx
popq %r14
popq %r15
jmp 0x125e
cmpl $0x1f801040, %r14d      # imm = 0x1F801040
jne 0x13593f
movzbl %bl, %edi
popq %rbx
popq %r14
popq %r15
jmp 0x121a
leaq 0x485c(%rip), %rsi      # 0x13a1a2
pushq $0x13
popq %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0x10d0
leaq 0x2493e(%rip), %rax     # 0x15a298
movq (%rax), %rax
movzbl %bl, %esi
movl %r14d, %edi
popq %rbx
popq %r14
popq %r15
jmpq *%rax
movzbl %bl, %edi
popq %rbx
popq %r14
popq %r15
jmp 0x12b0
movzbl %bl, %edi
popq %rbx
popq %r14
popq %r15
jmp 0x12c3
movzbl %bl, %edi
popq %rbx
popq %r14
popq %r15
jmp 0x129d