User Tools

Site Tools


x68000:cpsfdev

This is an old revision of the document!


This is a simple program demonstrating how to interface with a CPSF or CPSF-MD joystick. Using a second CPSF should follow the same technique but with joyport_b, IOC4 and PC5. It can be compiled with the Lydux toolchain with the following commands:

$ human68k-gcc joytest.c -liocs
$ human68k-objcopy -O xfile a.out joytest.x

Code:

#include <stdint.h>
#include <stdio.h>
#include <iocslib.h>

volatile uint8_t *joyport_a = (uint8_t*)0xE9A001;
volatile uint8_t *joyport_b = (uint8_t*)0xE9A003;
volatile uint8_t *joyport_c = (uint8_t*)0xE9A005; // joy control
uint8_t *joycontrolword = (uint8_t*)0xE9A007; // if bit 7 = 0, bit manipulation. if bit 7 = 1, mode setting

int main(int argc, char *argv[])
{
	uint16_t port1;
	
	// clear screen
	printf("\e[2J");

	// this is working for all buttons with a CPSF or CPSF-MD
	

	// set IOC4 to 1, disables joystick 1 processing
	// preserves ADPCM settings
	*joyport_c = 16|(*joyport_c&0xF);
	while(1)
	{
		port1=0;
		// move cursor to origin
		printf("\e[;0H");
		printf("CPSF Controller Tester\n");
		printf("Press ESC to quit.\n\n");
		
		// unset PC4, this is the controller clock/button group select pin
		*joycontrolword = 8;
		// read joyport a bits
		port1 |= (~*joyport_a)<<8;
		
		// set PC4
		*joycontrolword = 9;
		// read joyport a bits
		port1 |= (uint8_t)(~*joyport_a);
		
		printf("0x%04X\n", port1);
		
		// quit on ESC
		if(_iocs_bitsns(0) == 2)
			return 0;
	}
	
	
	return 0;
}
x68000/cpsfdev.1506910062.txt.gz · Last modified: 2019/08/27 20:44 (external edit)