x68000:cpsfdev
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | x68000:cpsfdev [2019/08/27 20:45] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | This is a simple program demonstrating how to interface with a CPSF or CPSF-MD joystick. Refer to the following page for joystick register [[joystick_regs|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 < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | volatile uint8_t *joyport_a = (uint8_t*)0xE9A001; | ||
+ | volatile uint8_t *joyport_b = (uint8_t*)0xE9A003; | ||
+ | volatile uint8_t *joyport_c = (uint8_t*)0xE9A005; | ||
+ | uint8_t *joycontrolword = (uint8_t*)0xE9A007; | ||
+ | uint8_t joyport_c_old=0; | ||
+ | |||
+ | int main(int argc, char *argv[]) | ||
+ | { | ||
+ | uint16_t port1 = 0; | ||
+ | uint32_t usp = 0; | ||
+ | |||
+ | // clear screen | ||
+ | printf(" | ||
+ | |||
+ | // 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(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | |||
+ | // unset PC4, this is the controller clock/ | ||
+ | *joycontrolword = 8; | ||
+ | // read joyport a bits | ||
+ | port1 |= (~*joyport_a)<< | ||
+ | |||
+ | // set PC4 | ||
+ | *joycontrolword = 9; | ||
+ | // read joyport a bits | ||
+ | port1 |= (uint8_t)(~*joyport_a); | ||
+ | |||
+ | printf(" | ||
+ | |||
+ | // 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