#include <snd.h>
#include "display.h"

TOWNSpad_t *DSP_TOWNSpad(int port, TOWNSpad_t *data)
{
    int p;
    
    asm volatile("
	movb	$0x41, %%ah
	movb	%1, %%dh
	push	$0x0110
	pop	%%fs
	lcall	%%fs:(0x80)
	movzbl	%%dl, %%eax
	movl	%%eax, %0
    ": "=g"(p): "g"((char)port): "ax", "dx");
    
    p = ~p;
    
    data->right = (p & 0x08) ? ON : OFF;
    data->left = (p & 0x04) ? ON : OFF;
    data->down = (p & 0x02) ? ON : OFF;
    data->up = (p & 0x01) ? ON : OFF;
    
    data->a_botton = (p & 0x10) ? ON : OFF;
    data->b_botton = (p & 0x20) ? ON : OFF;
    
    data->select = (p & 0x80) ? ON : OFF;
    data->run = (p & 0x40) ? ON : OFF;

    return data;
}
    