// File: tomfunkhouser[P]gaps/pkgs/fglut/freeglut_input_devices.c
// Function: poll_dials
static void poll_dials ( int id )
{
    int data;
    static int dial_state = DIAL_NEW;
    static int dial_which;
    static int dial_value;
    // static int dials[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

    if ( !dialbox_port ) return;

    while ( (data=serial_getchar(dialbox_port)) != EOF )
    {
        if ( ( dial_state > DIAL_WHICH_DEVICE ) || IS_DIAL_EVENT ( data ) )
        {
            switch ( dial_state )
            {
            case DIAL_WHICH_DEVICE:
                dial_which = data - DIAL_BASE;
                dial_state++;
                break;
            case DIAL_VALUE_HIGH:
                dial_value = ( data << 8 );
                dial_state++;
                break;
            case DIAL_VALUE_LOW:
                dial_value |= data;
                if ( dial_value & 0x8000 ) dial_value -= 0x10000;
                // dials[dial_which] = dial_value;
                send_dial_event ( dial_which + 1, dial_value * 360 / 256 );
                dial_state = DIAL_WHICH_DEVICE;
                break;
            default:
                /* error: Impossible state value! */
                break;
            }
        }
        else if ( data == DIAL_INITIALIZED )
        {
            fgState.InputDevsInitialised = GL_TRUE;
            dial_state = DIAL_WHICH_DEVICE;
            serial_putchar(dialbox_port,DIAL_SET_AUTO_DIALS);
            serial_putchar(dialbox_port,0xff);
            serial_putchar(dialbox_port,0xff);
        }
        else  /* Unknown data; try flushing. */
            serial_flush(dialbox_port);
    }

    glutTimerFunc ( 2, poll_dials, 0 );
}

// Assembly:
subq $0x18, %rsp
movl %edi, 0x14(%rsp)
cmpq $0x0, 0x83eb8(%rip)     # 0x1ffe78
jne 0x17bfc7
jmp 0x17c143
jmp 0x17bfc9
movq 0x83ea8(%rip), %rdi     # 0x1ffe78
callq 0x17c1d0
movl %eax, 0x10(%rsp)
cmpl $-0x1, %eax
je 0x17c130
cmpl $0x0, 0x7e59f(%rip)     # 0x1fa588
jg 0x17c001
cmpl $0x30, 0x10(%rsp)
jl 0x17c0c9
cmpl $0x38, 0x10(%rsp)
jge 0x17c0c9
movl 0x7e581(%rip), %eax     # 0x1fa588
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0x17c02a
jmp 0x17c011
movl 0xc(%rsp), %eax
subl $0x1, %eax
je 0x17c048
jmp 0x17c01c
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0x17c066
jmp 0x17c0c5
movl 0x10(%rsp), %eax
subl $0x30, %eax
movl %eax, 0x83e49(%rip)     # 0x1ffe80
movl 0x7e54b(%rip), %eax     # 0x1fa588
addl $0x1, %eax
movl %eax, 0x7e542(%rip)     # 0x1fa588
jmp 0x17c0c7
movl 0x10(%rsp), %eax
shll $0x8, %eax
movl %eax, 0x83e2f(%rip)     # 0x1ffe84
movl 0x7e52d(%rip), %eax     # 0x1fa588
addl $0x1, %eax
movl %eax, 0x7e524(%rip)     # 0x1fa588
jmp 0x17c0c7
movl 0x10(%rsp), %eax
orl 0x83e14(%rip), %eax     # 0x1ffe84
movl %eax, 0x83e0e(%rip)     # 0x1ffe84
movl 0x83e08(%rip), %eax     # 0x1ffe84
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x17c097
movl 0x83df8(%rip), %eax     # 0x1ffe84
subl $0x10000, %eax          # imm = 0x10000
movl %eax, 0x83ded(%rip)     # 0x1ffe84
movl 0x83de3(%rip), %edi     # 0x1ffe80
addl $0x1, %edi
imull $0x168, 0x83dda(%rip), %eax # imm = 0x168
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %eax, %esi
callq 0x17c230
movl $0x0, 0x7e4c5(%rip)     # 0x1fa588
jmp 0x17c0c7
jmp 0x17c0c7
jmp 0x17c12b
cmpl $0x20, 0x10(%rsp)
jne 0x17c11d
leaq 0x7e2b9(%rip), %rax     # 0x1fa390
movb $0x1, 0xb1(%rax)
movl $0x0, 0x7e4a0(%rip)     # 0x1fa588
movq 0x83d89(%rip), %rdi     # 0x1ffe78
movl $0x50, %esi
callq 0x17bf60
movq 0x83d78(%rip), %rdi     # 0x1ffe78
movl $0xff, %esi
callq 0x17bf60
movq 0x83d67(%rip), %rdi     # 0x1ffe78
movl $0xff, %esi
callq 0x17bf60
jmp 0x17c129
movq 0x83d54(%rip), %rdi     # 0x1ffe78
callq 0x17c280
jmp 0x17c12b
jmp 0x17bfc9
movl $0x2, %edi
leaq -0x18c(%rip), %rsi      # 0x17bfb0
xorl %edx, %edx
callq 0x1793a0
addq $0x18, %rsp
retq
nopl (%rax,%rax)