x68000:cpsfdev
This is a simple program demonstrating how to interface with a CPSF or CPSF-MD joystick. Refer to the following page for joystick register reference. Using a second CPSF should follow the same technique but with joyport_b, IOC5 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:
// 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 #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 uint8_t joyport_c_old=0; int main(int argc, char *argv[]) { uint16_t port1 = 0; uint32_t usp = 0; // clear screen printf("\e[2J"); // this is working for all buttons with a CPSF or CPSF-MD usp = _iocs_b_super(0); // set IOC4 to 1, disables joystick 1 processing // preserves ADPCM settings joyport_c_old = *joyport_c; *joyport_c = 16|joyport_c_old; 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(_dos_inpout(0xFF)==0x1B){ *joycontrolword = 8; *joyport_c = joyport_c_old; _iocs_b_super(usp); return 0; } } }
x68000/cpsfdev.txt · Last modified: 2019/08/27 20:45 by 127.0.0.1