// File: STrix8[P]RasPiDS3/RasPiDS3.cpp
// Function: RPDS3::DualShock3::read()
void DualShock3::read() {
	vector<char> data;
	char c;

	while (data.size() != 8) {
		c = JoyStick.get();
		data.push_back(c);
	}
	if (data[6] == 0x01) {
		if (data[7] >= 0 && data[7] <= NumButtons) {
			int index = data[7];
			if (data[4] == 0x00) {
				readButtonData[index] = false;
			} else if (data[4] == 0x01) {
				readButtonData[index] = true;
			}
		}
	} else if (data[6] == 0x02) {
/*		if (data[7] > 0x10) {
			data.clear();
			assert(data.empty());
		}
		*/
		if ((data[7] >= 0 && data[7] < NumSticks - 2) || data[7] == 0x0c || data[7] == 0x0d) {
			int index = data[7];
			if (data[7] == 0x0c || data[7] == 0x0d) {
				index -= 8;
			}
			readStickData[index] = data[5];
			if (precisionFlag) {
				readStickData[index] *= 0x100;
				readStickData[index] += data[4];
				if (readStickData[index] >= 32768) 
					readStickData[index] -= 65536;
				/*
				if (data[7] != index)
					readStickData[index] += 32767;
				*/
			} else {
				if (readStickData[index] >= 128) 
					readStickData[index] -= 256;
				/*
				if (data[7] != index)
					readStickData[index] += 128;
				*/
			}
		}
		if (data[7] >= 0x04 && data[7] <= 0x06) {
			int index = data[7] - 0x04;
			if (precisionFlag)
				readAxisData[index] = data[4] + data[5] * 0x100;
				if (readAxisData[index] >= 32768) 
					readAxisData[index] -= 65536;
			else
				readAxisData[index] = data[5];
				if (readAxisData[index] >= 128)
					readAxisData[index] -= 256;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x37a0
leaq -0x20(%rbp), %rdi
callq 0x37c0
cmpq $0x8, %rax
je 0x2c6f
movq -0x48(%rbp), %rdi
addq $0x8, %rdi
callq 0x2160
movl %eax, -0x4c(%rbp)
jmp 0x2c3e
movl -0x4c(%rbp), %eax
movb %al, -0x21(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x21(%rbp), %rsi
callq 0x37e0
jmp 0x2c53
jmp 0x2c1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x3870
jmp 0x2fe8
leaq -0x20(%rbp), %rdi
movl $0x6, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0x1, %eax
jne 0x2d20
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0x0, %eax
jl 0x2d1b
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0x10, %eax
jg 0x2d1b
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
movl %eax, -0x38(%rbp)
leaq -0x20(%rbp), %rdi
movl $0x4, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x2cf1
movq -0x48(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb $0x0, 0x228(%rax,%rcx)
jmp 0x2d19
leaq -0x20(%rbp), %rdi
movl $0x4, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0x1, %eax
jne 0x2d17
movq -0x48(%rbp), %rax
movslq -0x38(%rbp), %rcx
movb $0x1, 0x228(%rax,%rcx)
jmp 0x2d19
jmp 0x2d1b
jmp 0x2fd9
leaq -0x20(%rbp), %rdi
movl $0x6, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0x2, %eax
jne 0x2fd7
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0x0, %eax
jl 0x2d66
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0x4, %eax
jl 0x2d96
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0xc, %eax
je 0x2d96
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0xd, %eax
jne 0x2eb2
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
movl %eax, -0x3c(%rbp)
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0xc, %eax
je 0x2dd6
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0xd, %eax
jne 0x2ddf
movl -0x3c(%rbp), %eax
subl $0x8, %eax
movl %eax, -0x3c(%rbp)
leaq -0x20(%rbp), %rdi
movl $0x5, %esi
callq 0x3850
movq %rax, %rcx
movq -0x48(%rbp), %rax
movsbl (%rcx), %edx
movslq -0x3c(%rbp), %rcx
movl %edx, 0x238(%rax,%rcx,4)
testb $0x1, 0x21b(%rax)
je 0x2e7d
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl 0x238(%rax,%rcx,4), %edx
shll $0x8, %edx
movl %edx, 0x238(%rax,%rcx,4)
leaq -0x20(%rbp), %rdi
movl $0x4, %esi
callq 0x3850
movq %rax, %rcx
movq -0x48(%rbp), %rax
movsbl (%rcx), %edx
movslq -0x3c(%rbp), %rcx
addl 0x238(%rax,%rcx,4), %edx
movl %edx, 0x238(%rax,%rcx,4)
movslq -0x3c(%rbp), %rcx
cmpl $0x8000, 0x238(%rax,%rcx,4) # imm = 0x8000
jl 0x2e7b
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl 0x238(%rax,%rcx,4), %edx
subl $0x10000, %edx          # imm = 0x10000
movl %edx, 0x238(%rax,%rcx,4)
jmp 0x2eb0
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cmpl $0x80, 0x238(%rax,%rcx,4)
jl 0x2eae
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl 0x238(%rax,%rcx,4), %edx
subl $0x100, %edx            # imm = 0x100
movl %edx, 0x238(%rax,%rcx,4)
jmp 0x2eb0
jmp 0x2eb2
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0x4, %eax
jl 0x2fd5
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movsbl (%rax), %eax
cmpl $0x6, %eax
jg 0x2fd5
leaq -0x20(%rbp), %rdi
movl $0x7, %esi
callq 0x3850
movq %rax, %rcx
movq -0x48(%rbp), %rax
movsbl (%rcx), %ecx
subl $0x4, %ecx
movl %ecx, -0x40(%rbp)
testb $0x1, 0x21b(%rax)
je 0x2f4c
leaq -0x20(%rbp), %rdi
movl $0x4, %esi
callq 0x3850
movsbl (%rax), %eax
movl %eax, -0x50(%rbp)
leaq -0x20(%rbp), %rdi
movl $0x5, %esi
callq 0x3850
movl -0x50(%rbp), %edx
movq %rax, %rcx
movq -0x48(%rbp), %rax
movsbl (%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %edx
movslq -0x40(%rbp), %rcx
movl %edx, 0x250(%rax,%rcx,4)
movq -0x48(%rbp), %rax
movslq -0x40(%rbp), %rcx
cmpl $0x8000, 0x250(%rax,%rcx,4) # imm = 0x8000
jl 0x2f7f
movq -0x48(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl 0x250(%rax,%rcx,4), %edx
subl $0x10000, %edx          # imm = 0x10000
movl %edx, 0x250(%rax,%rcx,4)
jmp 0x2fa2
leaq -0x20(%rbp), %rdi
movl $0x5, %esi
callq 0x3850
movq %rax, %rcx
movq -0x48(%rbp), %rax
movsbl (%rcx), %edx
movslq -0x40(%rbp), %rcx
movl %edx, 0x250(%rax,%rcx,4)
movq -0x48(%rbp), %rax
movslq -0x40(%rbp), %rcx
cmpl $0x80, 0x250(%rax,%rcx,4)
jl 0x2fd3
movq -0x48(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl 0x250(%rax,%rcx,4), %edx
subl $0x100, %edx            # imm = 0x100
movl %edx, 0x250(%rax,%rcx,4)
jmp 0x2fd5
jmp 0x2fd7
jmp 0x2fd9
leaq -0x20(%rbp), %rdi
callq 0x3870
addq $0x50, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x2220
nopw %cs:(%rax,%rax)