#ifndef __VECTREX_H__
#define __VECTREX_H__ 1

#ifdef LINUX

#include <vectrex.h>
#include <stdio.h>
#include <string.h>
#include "headers.h"

sint8_t Vec_Joy_1_X, Vec_Joy_1_Y, Vec_Joy_2_X, Vec_Joy_2_Y;
uint8_t VIA_t1_cnt_lo;
uint8_t Vec_Btn_State, Vec_Buttons;
char Vec_Music_1[] = {0};

void Intensity_a(uint8_t i) {
  (void)i;
}
void Moveto_d(sint8_t y, sint8_t x) {
  (void)x;(void)y;
}
void Draw_Line_d(sint8_t y, sint8_t x) {
  (void)x;(void)y;
}
void Draw_VLp(int8_t *ra) {
  (void)ra;
}
void Read_Btns(void) {
}
sint8_t Random(void) {
  return 0;
}
void Wait_Recal(void) {
}
void Reset0Ref(void) {
}
void Intensity_7F(void) {
}
void Print_Str_d (sint8_t y, sint8_t x, char *s) {
  char ss[strlen(s)+1];
  strcpy(ss, s);
  ss[strlen(ss)-1] = '\0';
  fprintf(stderr, "%s\n", ss);
  (void)x;(void)y;
}
void Joy_Digital(void) {
}

// ***************************************************************************
// controller
// ***************************************************************************




// ---------------------------------------------------------------------------
// controller initialization, each controller axis can be individually
// switched on or off; for performance reasons, activate only what you
// really need

void enable_controller_1_x(void)
{
#ifndef LINUX
		Vec_Joy_Mux_1_X = 1;
#endif
}

void enable_controller_1_y(void)
{
#ifndef LINUX
		Vec_Joy_Mux_1_Y = 3;
#endif
}

void enable_controller_2_x(void)
{
#ifndef LINUX
		Vec_Joy_Mux_2_X = 5;
#endif
}

void enable_controller_2_y(void)
{
#ifndef LINUX
		Vec_Joy_Mux_2_Y = 7;
#endif
}

void disable_controller_1_x(void)
{
#ifndef LINUX
		Vec_Joy_Mux_1_X = 0;
#endif
}

void disable_controller_1_y(void)
{
#ifndef LINUX
		Vec_Joy_Mux_1_Y = 0;
#endif
}

void disable_controller_2_x(void)
{
#ifndef LINUX
		Vec_Joy_Mux_2_X = 0;
#endif
}

void disable_controller_2_y(void)
{
#ifndef LINUX
		Vec_Joy_Mux_2_Y = 0;
#endif
}

// ---------------------------------------------------------------------------
// read controller buttons

// must be called once each time you want to check the buttons
void check_buttons(void)
{
#ifndef LINUX
	Read_Btns();
#endif
}

uint8_t buttons_pressed(void)
{
	return Vec_Buttons;
}

uint8_t buttons_held(void)
{
	return Vec_Btn_State;
}

// call these functions below to check if a specific button is pressed,
// the button must be released before another press is registered,
// return value is 0 or 1, so these functions can be used as check in
// conditional statements

uint8_t button_1_1_pressed(void)
{
	return (buttons_pressed() & 0b00000001);
}

uint8_t button_1_2_pressed(void)
{
	return (buttons_pressed() & 0b00000010);
}
uint8_t button_1_3_pressed(void)
{
	return (buttons_pressed() & 0b00000100);
}
uint8_t button_1_4_pressed(void)
{
	return (buttons_pressed() & 0b00001000);
}

uint8_t button_2_1_pressed(void)
{
	return (buttons_pressed() & 0b00010000);
}

uint8_t button_2_2_pressed(void)
{
	return (buttons_pressed() & 0b00100000);
}
uint8_t button_2_3_pressed(void)
{
	return (buttons_pressed() & 0b01000000);
}

uint8_t button_2_4_pressed(void)
{
	return (buttons_pressed() & 0b10000000);
}

// call these functions below to check if a specific button is held,
// return value is 0 or 1, so these functions can be used as check in
// conditional statements

uint8_t button_1_1_held(void)
{
	return (buttons_held() & 0b00000001);
}

uint8_t button_1_2_held(void)
{
	return (buttons_held() & 0b00000010);
}
uint8_t button_1_3_held(void)
{
	return (buttons_held() & 0b00000100);
}
uint8_t button_1_4_held(void)
{
	return (buttons_held() & 0b00001000);
}

uint8_t button_2_1_held(void)
{
	return (buttons_held() & 0b00010000);
}

uint8_t button_2_2_held(void)
{
	return (buttons_held() & 0b00100000);
}
uint8_t button_2_3_held(void)
{
	return (buttons_held() & 0b01000000);
}

uint8_t button_2_4_held(void)
{
	return (buttons_held() & 0b10000000);
}

// ---------------------------------------------------------------------------
// read controller joysticks

// must be called once each time you want to check the joysticks
void check_joysticks(void)
{
	Joy_Digital();
}

int8_t joystick_1_x(void)
{
	return Vec_Joy_1_X;
}

int8_t joystick_1_y(void)
{
	return Vec_Joy_1_Y;
}

int8_t joystick_2_x(void)
{
	return Vec_Joy_2_X;
}

int8_t joystick_2_y(void)
{
	return Vec_Joy_2_Y;
}

// call these functions below to check if a joystick is moved in
// a specific direction,
// return value is 0 or 1, so these functions can be used as check in
// conditional statements

int8_t joystick_1_left(void)
{
	return (joystick_1_x() < 0);
}

int8_t joystick_1_right(void)
{
	return (joystick_1_x() > 0);
}

int8_t joystick_1_down(void)
{
	return (joystick_1_y() < 0);
}

int8_t joystick_1_up(void)
{
	return (joystick_1_y() > 0);
}

int8_t joystick_2_left(void)
{
	return (joystick_2_x() < 0);
}

int8_t joystick_2_right(void)
{
	return (joystick_2_x() > 0);
}

int8_t joystick_2_down(void)
{
	return (joystick_2_y() < 0);
}

int8_t joystick_2_up(void)
{
	return (joystick_2_y() > 0);
}

// ***************************************************************************
// end of file
// ***************************************************************************
#endif
#endif
