// File: /workspace/github_c_makefile_star2_O3/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 0x1721e8
leaq 0x51fc(%rip), %rsi      # 0x1773d8
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 0x172248
movl %ebx, %r14d
shrl $0x2, %r14d
andl $0x7ffff, %r14d         # imm = 0x7FFFF
leaq 0x9145(%rip), %rax      # 0x17b360
leaq -0x24a(%rip), %rcx      # 0x171fd8
cmpq %rcx, (%rax,%r14,8)
je 0x17223b
leaq 0x516f(%rip), %rsi      # 0x17739e
movl $0x13, %edi
xorl %eax, %eax
callq 0x10d0
movq 0x40911e(%rip), %rax    # 0x57b360
movl (%rax,%r14,4), %eax
jmp 0x172268
movl %ebx, %eax
andl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x1f800000, %eax       # imm = 0x1F800000
jne 0x17227a
movq 0x40910b(%rip), %rax    # 0x57b368
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 0x172363
leaq 0x3f2a(%rip), %rcx      # 0x1761bc
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 0x1732e0
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1733f1
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1733a3
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x17332e
shrl $0x2, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1735f6
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x173355
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x173307
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x17337c
shrl $0x2, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x173606
shrl $0x4, %ebx
andl $0x1f, %ebx
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1733ca
cmpl $0x1f801074, %ebx       # imm = 0x1F801074
je 0x1723fe
cmpl $0x1f801070, %ebx       # imm = 0x1F801070
jne 0x172383
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x171204
leaq 0x5066(%rip), %rsi      # 0x1773f0
movl $0x13, %edi
movl %ebx, %edx
xorl %eax, %eax
callq 0x10d0
leaq 0x8ee9(%rip), %rax      # 0x17b288
movl %ebx, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1735c7
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x173539
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x173505
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1735d5
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1734d1
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x1734b0
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x17356d
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x171225