Files

33 lines
1.4 KiB
C

// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef VCC_INPUT_H
#define VCC_INPUT_H
#define INPUT_RIGHT 0
#define INPUT_LEFT 1
#define INPUT_PRIMARY 1
#define INPUT_SECONDARY 2
typedef struct {
unsigned char port; // Set by input_init.
unsigned char x, y; // 0..63, increasing to the right and down.
signed char dx, dy; // -1 below 26, 0 from 26 through 37, +1 above 37.
unsigned char held; // Buttons down in this sample.
unsigned char pressed; // Buttons newly down since the preceding sample.
unsigned char released; // Buttons newly up since the preceding sample.
} VccInput;
// Sample the chosen port to establish a baseline. A button already down is
// held, with no press or release event. Use separate state for each player.
// An invalid port gives a neutral, inactive state. A null pointer is ignored.
void input_init(VccInput *input, unsigned char port);
// Take one foreground sample per game update. Transitions between samples
// cannot be observed. Test button fields with INPUT_PRIMARY / INPUT_SECONDARY.
// Uses the standard CoCo analog joystick circuit in BASIC PIA configuration.
// Restores the sound gate, mux, DAC and keyboard column output before return.
// The short PIA transaction masks IRQ/FIRQ and uses normal data-register reads
// (which can acknowledge PIA interrupt flags). Link input followed by bcontrol.
void input_sample(VccInput *input);
#endif