// File: /workspace/github_c_makefile_star2_O2/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 0x13570e
leaq 0x4a52(%rip), %rsi      # 0x13a156
pushq $0x13
popq %rdi
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 0x135769
shrl $0x2, %ebx
andl $0x7ffff, %ebx          # imm = 0x7FFFF
leaq 0x24c24(%rip), %rax     # 0x15a360
leaq -0x44b(%rip), %rcx      # 0x1352f8
cmpq %rcx, (%rax,%rbx,8)
je 0x13575a
leaq 0x498e(%rip), %rsi      # 0x13a0de
pushq $0x13
popq %rdi
xorl %eax, %eax
callq 0x10d0
movq 0x424bff(%rip), %rax    # 0x55a360
movl (%rax,%rbx,4), %eax
jmp 0x13581b
movl %ebx, %eax
andl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x1f800000, %eax       # imm = 0x1F800000
jne 0x13578c
movq 0x424bea(%rip), %rax    # 0x55a368
andl $0x3fc, %ebx            # imm = 0x3FC
movl (%rax,%rbx), %eax
jmp 0x13581b
cmpl $0x1f801814, %ebx       # imm = 0x1F801814
je 0x1357f4
cmpl $0x1f801074, %ebx       # imm = 0x1F801074
je 0x135813
cmpl $0x1f8010a8, %ebx       # imm = 0x1F8010A8
je 0x13580a
cmpl $0x1f8010b8, %ebx       # imm = 0x1F8010B8
je 0x1357e4
cmpl $0x1f8010f0, %ebx       # imm = 0x1F8010F0
je 0x1357ee
cmpl $0x1f8010f4, %ebx       # imm = 0x1F8010F4
je 0x135804
cmpl $0x1f801110, %ebx       # imm = 0x1F801110
je 0x1357fa
cmpl $0x1f801810, %ebx       # imm = 0x1F801810
je 0x1357e8
cmpl $0x1f801014, %ebx       # imm = 0x1F801014
jne 0x13581d
leaq 0x24aad(%rip), %rax     # 0x15a288
movl $0x1f801014, %edi       # imm = 0x1F801014
callq *(%rax)
jmp 0x135818
pushq $0x3
jmp 0x13580c
popq %rbx
jmp 0x134620
popq %rbx
jmp 0x1346f1
popq %rbx
jmp 0x134654
pushq $0x1
popq %rdi
callq 0x134664
jmp 0x135818
popq %rbx
jmp 0x134712
pushq $0x2
popq %rdi
popq %rbx
jmp 0x1346ca
callq 0x1345fd
movzwl %ax, %eax
popq %rbx
retq
leaq 0x4946(%rip), %rsi      # 0x13a16a
pushq $0x13
popq %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x10d0
leaq 0x24a59(%rip), %rax     # 0x15a290
movl %ebx, %edi
popq %rbx
jmpq *(%rax)