// File: /workspace/github_c_makefile_star2_O3/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 0x172607
movl %r14d, %r15d
shrl $0x2, %r15d
andl $0x7ffff, %r15d         # imm = 0x7FFFF
leaq 0x8da1(%rip), %rax      # 0x17b360
leaq -0x5ee(%rip), %rcx      # 0x171fd8
cmpq %rcx, (%rax,%r15,8)
je 0x1725df
leaq 0x4e7d(%rip), %rsi      # 0x177450
movl $0x13, %edi
xorl %eax, %eax
callq 0x10d0
shll $0x3, %r14d
movl $0xff, %eax
movl %r14d, %ecx
shll %cl, %eax
movq 0x408d6c(%rip), %rdx    # 0x57b360
notl %eax
movzbl %bl, %esi
shll %cl, %esi
andl (%rdx,%r15,4), %eax
orl %eax, %esi
movl %esi, (%rdx,%r15,4)
jmp 0x172642
movl %r14d, %eax
andl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x1f800000, %eax       # imm = 0x1F800000
jne 0x172648
movl %r14d, %eax
shll $0x3, %r14d
movl $0xff, %edx
movl %r14d, %ecx
shll %cl, %edx
movq 0x408d3a(%rip), %rsi    # 0x57b368
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 0x172671
leaq 0x44dd(%rip), %rcx      # 0x176b38
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl %bl, %edi
popq %rbx
popq %r14
popq %r15
jmp 0x129e
cmpl $0x1f801040, %r14d      # imm = 0x1F801040
jne 0x172687
movzbl %bl, %edi
popq %rbx
popq %r14
popq %r15
jmp 0x125a
leaq 0x4dd4(%rip), %rsi      # 0x177462
movl $0x13, %edi
movl %r14d, %edx
xorl %eax, %eax
callq 0x10d0
leaq 0x8bf4(%rip), %rax      # 0x17b298
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 0x12f0
movzbl %bl, %edi
popq %rbx
popq %r14
popq %r15
jmp 0x1303
movzbl %bl, %edi
popq %rbx
popq %r14
popq %r15
jmp 0x12dd