// File: /workspace/github_c_makefile_star2_O1/ughman[P]c2c/src/emu.c
// Function: EMU_ReadU32
uint32_t EMU_ReadU32(uint32_t address)
{
	if (address & 3)
		SDL_LogError(LOG_EMU,"Unaligned word load");
	if (address >= 0x80000000 && address <= 0x801FFFFF)
	{
normal:
		{
			uint32_t (*codehandler)(uint32_t) = EMU_codemap[(address & 0x1FFFFF) >> 2];
			if (codehandler != EMU_ExecuteUnrecognizedCode)
			{
				SDL_LogError(LOG_EMU,"Reading code as data");
			}
		}
		return EMU_ram[(address & 0x1FFFFF) >> 2];
	}
	else if (address >= 0x0 && address <= 0x1FFFFF)
	{
		goto normal;
	}
	else if (address >= 0xA0000000 && address <= 0xA01FFFFF)
	{
		goto normal;
	}
	else if (address >= 0x1F800000 && address <= 0x1F8003FF)
	{
		return EMU_scratch[(address & 0x3FF) >> 2];
	}
	else switch (address)
	{
	case 0x1F801014:
		// Unused waitstate configuration
		return PCSX_Read16(address);
	case 0x1F801074:
		return IRQ_GetMask();
	case 0x1F8010A8:
		return DMA_GetMode(DMA_GPU);
	case 0x1F8010B8:
		return DMA_GetMode(DMA_CDR);
	case 0x1F8010F0:
		return DMA_GetControlRegister();
	case 0x1F8010F4:
		return DMA_GetInterruptRegister();
	case 0x1F801110:
		return RCNT_GetValue(RCNT_HBLANK);
	case 0x1F801810:
		return GPU_Read();
	case 0x1F801814:
		return GPU_GetStatus();
	default:
		SDL_LogError(LOG_EMU,"Unrecognized 32-bit read address %.8X",address);
		return PCSX_Read32(address);
	}
}

// Assembly:
pushq %rbx
movl %edi, %ebx
testb $0x3, %bl
je 0x1621f0
leaq 0x488e(%rip), %rsi      # 0x166a72
movl $0x13, %edi
xorl %eax, %eax
callq 0x10d0
testl $0x7fe00000, %ebx       # imm = 0x7FE00000
setne %al
movl %ebx, %ecx
andl $0xffe00000, %ecx       # imm = 0xFFE00000
cmpl $0xa0000000, %ecx       # imm = 0xA0000000
setne %cl
testb %cl, %al
jne 0x16224d
shrl $0x2, %ebx
andl $0x7ffff, %ebx          # imm = 0x7FFFF
leaq 0x9142(%rip), %rax      # 0x16b360
leaq -0x459(%rip), %rcx      # 0x161dcc
cmpq %rcx, (%rax,%rbx,8)
je 0x16223e
leaq 0x47c8(%rip), %rsi      # 0x1669fa
movl $0x13, %edi
xorl %eax, %eax
callq 0x10d0
movq 0x40911b(%rip), %rax    # 0x56b360
movl (%rax,%rbx,4), %eax
jmp 0x16231b
movl %ebx, %eax
andl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x1f800000, %eax       # imm = 0x1F800000
jne 0x162270
movq 0x409106(%rip), %rax    # 0x56b368
andl $0x3fc, %ebx            # imm = 0x3FC
movl (%rax,%rbx), %eax
jmp 0x16231b
cmpl $0x1f8010ef, %ebx       # imm = 0x1F8010EF
jle 0x1622aa
cmpl $0x1f80110f, %ebx       # imm = 0x1F80110F
jle 0x1622e0
cmpl $0x1f801110, %ebx       # imm = 0x1F801110
je 0x16230e
cmpl $0x1f801810, %ebx       # imm = 0x1F801810
je 0x162323
cmpl $0x1f801814, %ebx       # imm = 0x1F801814
jne 0x162329
popq %rbx
jmp 0x161048
cmpl $0x1f8010a7, %ebx       # imm = 0x1F8010A7
jg 0x1622c9
cmpl $0x1f801014, %ebx       # imm = 0x1F801014
je 0x1622f6
cmpl $0x1f801074, %ebx       # imm = 0x1F801074
jne 0x162329
callq 0x160ff1
jmp 0x162318
cmpl $0x1f8010a8, %ebx       # imm = 0x1F8010A8
je 0x162303
cmpl $0x1f8010b8, %ebx       # imm = 0x1F8010B8
jne 0x162329
movl $0x3, %edi
jmp 0x162308
cmpl $0x1f8010f0, %ebx       # imm = 0x1F8010F0
je 0x16231d
cmpl $0x1f8010f4, %ebx       # imm = 0x1F8010F4
jne 0x162329
popq %rbx
jmp 0x161106
leaq 0x8f8b(%rip), %rax      # 0x16b288
movl %ebx, %edi
callq *(%rax)
jmp 0x162318
movl $0x2, %edi
popq %rbx
jmp 0x1610be
movl $0x1, %edi
callq 0x161058
movzwl %ax, %eax
popq %rbx
retq
popq %rbx
jmp 0x1610e5
popq %rbx
jmp 0x161014
leaq 0x4756(%rip), %rsi      # 0x166a86
movl $0x13, %edi
movl %ebx, %edx
xorl %eax, %eax
callq 0x10d0
leaq 0x8f4b(%rip), %rax      # 0x16b290
movl %ebx, %edi
popq %rbx
jmpq *(%rax)