view src/controller.c @ 54:bce01001a8c1

Fix some bugs in memory access related to the changes for teh 23-bit address space
author Michael Pavone <pavone@retrodev.com>
date Wed, 31 Aug 2016 22:40:17 -0700
parents b87b3ad5068c
children
line wrap: on
line source

#include <stdint.h>
#include <string.h>
#include "controller.h"

static controllers *current_context;

//UDLR SMAB CXYZ

void controller_init(controllers *context)
{
	memset(context, 0, sizeof(controllers));
	current_context = context;
}

void controller_pressed(int which, uint16_t buttons)
{
	if (which > 1) {
		return;
	}
	current_context->state[which] |= buttons;
}

void controller_released(int which, uint16_t buttons)
{
	if (which > 1) {
		return;
	}
	current_context->state[which] &= (~buttons) & 0xFFF;
}

uint16_t controller_read(controllers *context, int which)
{
	if (which > 1) {
		return 0xFFFF;
	}
	return context->state[which];
}