// File: /workspace/github_c_makefile_star2_O2/ughman[P]c2c/src/emu.c
// Function: EMU_ReadU16
uint16_t EMU_ReadU16(uint32_t address)
{
	if (address & 1)
		SDL_LogError(LOG_EMU,"Unaligned halfword 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] >> (address & 2) * 8;
	}
	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] >> (address & 2) * 8;
	}
	else switch (address)
	{
	case 0x1F801070:
		return IRQ_GetStatus();
	case 0x1F801074:
		return IRQ_GetMask();
	CASE_SPU_IO_PORT(0x0):
		return SPU_Voice_GetVolumeLeft((address & 0x1F0) >> 4);
	CASE_SPU_IO_PORT(0x2):
		return SPU_Voice_GetVolumeRight((address & 0x1F0) >> 4);
	CASE_SPU_IO_PORT(0x4):
		return SPU_Voice_GetSampleRate((address & 0x1F0) >> 4);
	CASE_SPU_IO_PORT(0x6):
		return SPU_Voice_GetStartAddress((address & 0x1F0) >> 4);
	CASE_SPU_IO_PORT(0x8):
		return SPU_Voice_GetADSRLow((address & 0x1F0) >> 4);
	CASE_SPU_IO_PORT(0xA):
		return SPU_Voice_GetADSRHigh((address & 0x1F0) >> 4);
	CASE_SPU_IO_PORT(0xC):
		return SPU_Voice_GetADSRVolume((address & 0x1F0) >> 4);
	CASE_SPU_IO_PORT(0xE):
		return SPU_Voice_GetLoopAddress((address & 0x1F0) >> 4);
	case 0x1F801D98:
		return SPU_GetReverbLow();
	case 0x1F801D9A:
		return SPU_GetReverbHigh();
	case 0x1F801DA6:
		return SPU_GetTransferAddress();
	case 0x1F801DAA:
		return SPU_ReadControlRegister();
	case 0x1F801DAE:
		return SPU_ReadStatusRegister();
	case 0x1F801DB8:
		return SPU_GetCurrentVolumeLeft();
	case 0x1F801DBA:
		return SPU_GetCurrentVolumeRight();
	case 0x1F801E00:
	case 0x1F801E04:
	case 0x1F801E08:
	case 0x1F801E0C:
	case 0x1F801E10:
	case 0x1F801E14:
	case 0x1F801E18:
	case 0x1F801E1C:
	case 0x1F801E20:
	case 0x1F801E24:
	case 0x1F801E28:
	case 0x1F801E2C:
	case 0x1F801E30:
	case 0x1F801E34:
	case 0x1F801E38:
	case 0x1F801E3C:
	case 0x1F801E40:
	case 0x1F801E44:
	case 0x1F801E48:
	case 0x1F801E4C:
	case 0x1F801E50:
	case 0x1F801E54:
	case 0x1F801E58:
	case 0x1F801E5C:
		return SPU_Voice_GetCurrentVolumeLeft((address & 0x7C) >> 2);
	case 0x1F801E02:
	case 0x1F801E06:
	case 0x1F801E0A:
	case 0x1F801E0E:
	case 0x1F801E12:
	case 0x1F801E16:
	case 0x1F801E1A:
	case 0x1F801E1E:
	case 0x1F801E22:
	case 0x1F801E26:
	case 0x1F801E2A:
	case 0x1F801E2E:
	case 0x1F801E32:
	case 0x1F801E36:
	case 0x1F801E3A:
	case 0x1F801E3E:
	case 0x1F801E42:
	case 0x1F801E46:
	case 0x1F801E4A:
	case 0x1F801E4E:
	case 0x1F801E52:
	case 0x1F801E56:
	case 0x1F801E5A:
	case 0x1F801E5E:
		return SPU_Voice_GetCurrentVolumeRight((address & 0x7C) >> 2);
	default:
		SDL_LogError(LOG_EMU,"Unrecognized 16-bit read address %.8X",address);
		return PCSX_Read16(address);
	}
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %ebx
testb $0x1, %bl
je 0x1354d7
leaq 0x4c4b(%rip), %rsi      # 0x13a118
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 0x135535
movl %ebx, %r14d
shrl $0x2, %r14d
andl $0x7ffff, %r14d         # imm = 0x7FFFF
leaq 0x24e56(%rip), %rax     # 0x15a360
leaq -0x219(%rip), %rcx      # 0x1352f8
cmpq %rcx, (%rax,%r14,8)
je 0x135528
leaq 0x4bc0(%rip), %rsi      # 0x13a0de
pushq $0x13
popq %rdi
xorl %eax, %eax
callq 0x10d0
movq 0x424e31(%rip), %rax    # 0x55a360
movl (%rax,%r14,4), %eax
jmp 0x135555
movl %ebx, %eax
andl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x1f800000, %eax       # imm = 0x1F800000
jne 0x135567
movq 0x424e1e(%rip), %rax    # 0x55a368
movl %ebx, %ecx
andl $0x3fc, %ecx            # imm = 0x3FC
movl (%rax,%rcx), %eax
shll $0x3, %ebx
andb $0x10, %bl
movl %ebx, %ecx
shrl %cl, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leal -0x1f801c00(%rbx), %eax
cmpl $0x25e, %eax            # imm = 0x25E
ja 0x135650
leaq 0x397d(%rip), %rcx      # 0x138efc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x136524
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x136635
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1365e7
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x136572
shrl $0x2, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x13683a
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x136599
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x13654b
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1365c0
shrl $0x2, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x13684a
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x13660e
cmpl $0x1f801074, %ebx       # imm = 0x1F801074
je 0x1356e9
cmpl $0x1f801070, %ebx       # imm = 0x1F801070
jne 0x135670
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1345dc
leaq 0x4ab9(%rip), %rsi      # 0x13a130
pushq $0x13
popq %rdi
movl %ebx, %edx
xorl %eax, %eax
callq 0x10d0
leaq 0x24bfe(%rip), %rax     # 0x15a288
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x13680b
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x13677d
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x136749
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x136819
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x136715
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1366f4
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1367b1
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1345fd