// File: /workspace/github_c_makefile_star2_O1/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 0x1623cf
movl %r14d, %r15d
shrl $0x2, %r15d
andl $0x7ffff, %r15d         # imm = 0x7FFFF
leaq 0x8fd9(%rip), %rax      # 0x16b360
leaq -0x5c2(%rip), %rcx      # 0x161dcc
cmpq %rcx, (%rax,%r15,8)
je 0x1623a7
leaq 0x4711(%rip), %rsi      # 0x166aac
movl $0x13, %edi
xorl %eax, %eax
callq 0x10d0
shll $0x3, %r14d
movl $0xff, %eax
movl %r14d, %ecx
shll %cl, %eax
movq 0x408fa4(%rip), %rdx    # 0x56b360
notl %eax
movzbl %bl, %esi
shll %cl, %esi
andl (%rdx,%r15,4), %eax
orl %eax, %esi
movl %esi, (%rdx,%r15,4)
jmp 0x16240a
movl %r14d, %eax
andl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x1f800000, %eax       # imm = 0x1F800000
jne 0x162410
movl %r14d, %eax
shll $0x3, %r14d
movl $0xff, %edx
movl %r14d, %ecx
shll %cl, %edx
movq 0x408f72(%rip), %rsi    # 0x56b368
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 0x162439
leaq 0x3d71(%rip), %rcx      # 0x166194
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 0x16244f
movzbl %bl, %edi
popq %rbx
popq %r14
popq %r15
jmp 0x125a
leaq 0x4668(%rip), %rsi      # 0x166abe
movl $0x13, %edi
movl %r14d, %edx
xorl %eax, %eax
callq 0x10d0
leaq 0x8e2c(%rip), %rax      # 0x16b298
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