Initial commit for a cc65 joystick testing program.

This commit is contained in:
Jeremy Rand 2020-06-09 15:29:04 -04:00
parent dc97bcf071
commit f52b5b5b5f
9 changed files with 351 additions and 4 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2020 Jeremy Rand
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

7
README.md Normal file
View File

@ -0,0 +1,7 @@
JoyTest
========
This is a joystick test program for the cc65 joystick driver. A problem was found with the original cc65 driver so it is being re-written. I am creating this program to provide feedback that the new implementation works well (or doesn't work well) on a variety of HW.
[Download a disk image](https://github.com/jeremysrand/joytest/releases/download/0.1/joytest.dsk)

View File

@ -46,6 +46,10 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9D1716772490096400C83148 /* pdlread.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = pdlread.s; sourceTree = "<group>"; };
9D171678249009C300C83148 /* pdlread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pdlread.h; sourceTree = "<group>"; };
9D17167B2490184800C83148 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
9D17167C2490187500C83148 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
9DB59E8E2487471900C57C78 /* joytest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = joytest; sourceTree = BUILT_PRODUCTS_DIR; };
9DB59E912487471900C57C78 /* joytest.dsk */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = joytest.dsk; sourceTree = BUILT_PRODUCTS_DIR; };
9DB59E962487471900C57C78 /* doNotBuild */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = doNotBuild; sourceTree = BUILT_PRODUCTS_DIR; };
@ -81,6 +85,8 @@
9DB59E872487471900C57C78 = {
isa = PBXGroup;
children = (
9D17167B2490184800C83148 /* README.md */,
9D17167C2490187500C83148 /* LICENSE */,
9DB59E972487471900C57C78 /* joytest */,
9DB59E8F2487471900C57C78 /* Products */,
);
@ -100,6 +106,8 @@
isa = PBXGroup;
children = (
9DB59E982487471900C57C78 /* main.c */,
9D1716772490096400C83148 /* pdlread.s */,
9D171678249009C300C83148 /* pdlread.h */,
9DB59E9A2487471900C57C78 /* Makefile */,
9DB59E9C2487471900C57C78 /* make */,
9DB59EB32487471900C57C78 /* Supporting Files */,

View File

@ -11,6 +11,9 @@
#
include make/head.mk
export CC65_HOME := /Users/jrand/Coding/AppleCoding/Apple2/cc65/cc65
CC65_BIN=/Users/jrand/Coding/AppleCoding/Apple2/cc65/cc65/bin
# Customize this file to control what gets built, what machines to
# target, where in memory to put it, etc.
@ -21,7 +24,7 @@ PGM=joytest
# Uncomment the one you want below (the first one is the default):
# MACHINE = apple2
# MACHINE = apple2-dos33
# MACHINE = apple2-system
MACHINE = apple2-system
# MACHINE = apple2-loader
# MACHINE = apple2-reboot
# MACHINE = apple2enh
@ -145,7 +148,7 @@ SRCDIRS+=
# If you want to link the joystick driver with your executable,
# uncomment the next line.
# DRIVERS += joystick
DRIVERS += joystick
#
# To use the joystick driver, add code which looks like this to your
# project:

View File

@ -9,12 +9,278 @@
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <conio.h>
#include <joystick.h>
#include <apple2.h>
#include "drivers/a2_joystick_drv.h"
#include "pdlread.h"
// Defines
#define SW_VERSION "0.1"
// Globals
static uint8_t highestUp = 0x00;
static uint8_t lowestDown = 0xff;
static uint8_t lowestVertCentre = 0xff;
static uint8_t highestVertCentre = 0x00;
static uint8_t highestLeft = 0x00;
static uint8_t lowestRight = 0xff;
static uint8_t lowestHorizCentre = 0xff;
static uint8_t highestHorizCentre = 0x00;
// Implementation
void clearGlobals(void)
{
highestUp = 0x00;
lowestDown = 0xff;
lowestVertCentre = 0xff;
highestVertCentre = 0x00;
highestLeft = 0x00;
lowestRight = 0xff;
lowestHorizCentre = 0xff;
highestHorizCentre = 0x00;
}
void drawJoystick(uint8_t joyDriverMask)
{
revers(JOY_BTN_1(joyDriverMask));
cputcxy(9, 11, '1');
revers(JOY_BTN_2(joyDriverMask));
cputcxy(11, 11, '2');
joyDriverMask &= (JOY_UP_MASK | JOY_DOWN_MASK | JOY_LEFT_MASK | JOY_RIGHT_MASK);
revers(joyDriverMask == (JOY_UP_MASK | JOY_LEFT_MASK));
cputsxy(3, 5, "UL");
revers(joyDriverMask == JOY_UP_MASK);
cputcxy(6, 5, 'U');
revers(joyDriverMask == (JOY_UP_MASK | JOY_RIGHT_MASK));
cputsxy(8, 5, "UR");
revers(joyDriverMask == JOY_LEFT_MASK);
cputcxy(4, 7, 'L');
revers(joyDriverMask == 0);
cputcxy(6, 7, 'C');
revers(joyDriverMask == JOY_RIGHT_MASK);
cputcxy(8, 7, 'R');
revers(joyDriverMask == (JOY_DOWN_MASK | JOY_LEFT_MASK));
cputsxy(3, 9, "DL");
revers(joyDriverMask == JOY_DOWN_MASK);
cputcxy(6, 9, 'D');
revers(joyDriverMask == (JOY_DOWN_MASK | JOY_RIGHT_MASK));
cputsxy(8, 9, "DR");
revers(false);
}
void pollJoystick(void)
{
uint8_t joyDriverMask = 0x00;
uint8_t prevJoyDriverMask = 0x00;
uint8_t joystickNum = 0;
char ch;
uint8_t x;
uint8_t y;
bool testingX = true;
uint8_t pdlNum = 0;
clearGlobals();
clrscr();
cputsxy(11, 0, "CC65 JOYSTICK TEST");
cputsxy(11, 1, "------------------");
cputsxy(0, 3, "JOYSTICK NUM:");
cputsxy(0, 11, "BUTTONS:");
cputsxy(0, 20, "PRESS 0/1 TO SELECT JOYSTICK");
cputsxy(0, 21, "PRESS X/Y TO SELECT AXIS TEST");
cputsxy(0, 22, "PRESS C TO CLEAR TEST RESULTS");
cputsxy(0, 23, "PRESS Q TO QUIT");
cputsxy(30, 23, "(VER " SW_VERSION ")");
prevJoyDriverMask = joy_read(joystickNum);
drawJoystick(joyDriverMask);
do {
joyDriverMask = joy_read(joystickNum);
if (testingX)
{
x = pdlRead(pdlNum);
if (JOY_LEFT(joyDriverMask))
{
if ((!JOY_LEFT(prevJoyDriverMask)) &&
(x > highestLeft))
highestLeft = x;
}
else if (JOY_RIGHT(joyDriverMask))
{
if ((!JOY_RIGHT(prevJoyDriverMask)) &&
(x < lowestRight))
lowestRight = x;
}
else
{
if ((JOY_LEFT(prevJoyDriverMask)) &&
(x < lowestHorizCentre))
lowestHorizCentre = x;
else if ((JOY_RIGHT(prevJoyDriverMask)) &&
(x > highestHorizCentre))
highestHorizCentre = x;
}
cputsxy(20, 3, "TESTING: X AXIS");
cputsxy(20, 5, "HIGHEST LEFT: ");
if (highestLeft == 0x00)
cputs("N/A");
else
cprintf("%3d", highestLeft);
cputsxy(20, 6, "LOWEST CENTRE: ");
if (lowestHorizCentre == 0xff)
cputs("N/A");
else
cprintf("%3d", lowestHorizCentre);
cputsxy(20, 7, "HIGHEST CENTRE: ");
if (highestHorizCentre == 0x00)
cputs("N/A");
else
cprintf("%3d", highestHorizCentre);
cputsxy(20, 8, "LOWEST RIGHT: ");
if (lowestRight == 0xff)
cputs("N/A");
else
cprintf("%3d", lowestRight);
}
else
{
y = pdlRead(pdlNum);
if (JOY_UP(joyDriverMask))
{
if ((!JOY_UP(prevJoyDriverMask)) &&
(y > highestUp))
highestUp = y;
}
else if (JOY_DOWN(joyDriverMask))
{
if ((!JOY_DOWN(prevJoyDriverMask)) &&
(y < lowestDown))
lowestDown = y;
}
else
{
if ((JOY_UP(prevJoyDriverMask)) &&
(y < lowestVertCentre))
lowestVertCentre = y;
else if ((JOY_DOWN(prevJoyDriverMask)) &&
(y > highestVertCentre))
highestVertCentre = y;
}
cputsxy(20, 3, "TESTING: Y AXIS");
cputsxy(20, 5, "HIGHEST UP: ");
if (highestUp == 0x00)
cputs("N/A");
else
cprintf("%3d", highestUp);
cputsxy(20, 6, "LOWEST CENTRE: ");
if (lowestVertCentre == 0xff)
cputs("N/A");
else
cprintf("%3d", lowestVertCentre);
cputsxy(20, 7, "HIGHEST CENTRE: ");
if (highestVertCentre == 0x00)
cputs("N/A");
else
cprintf("%3d", highestVertCentre);
cputsxy(20, 8, "LOWEST DOWN: ");
if (lowestDown == 0xff)
cputs("N/A");
else
cprintf("%3d", lowestDown);
}
drawJoystick(joyDriverMask);
cputcxy(14, 3, '0' + joystickNum);
prevJoyDriverMask = joyDriverMask;
if (kbhit())
{
ch = cgetc();
switch (ch)
{
case '0':
case '1':
joystickNum = (ch - '0');
pdlNum = (testingX ? (2 * joystickNum) : ((2 * joystickNum) + 1));
// Fallthrough...
case 'C':
case 'c':
clearGlobals();
break;
case 'x':
case 'X':
testingX = true;
pdlNum = 2 * joystickNum;
break;
case 'y':
case 'Y':
testingX = false;
pdlNum = (2 * joystickNum) + 1;
break;
case 'q':
case 'Q':
case 0x1b:
return;
}
}
} while (1);
}
int main(void)
{
printf("HELLO, WORLD!\n");
cgetc();
joy_install(&a2_joystick_drv);
pollJoystick();
joy_uninstall();
return 0;
}

Binary file not shown.

Binary file not shown.

19
joytest/pdlread.h Normal file
View File

@ -0,0 +1,19 @@
//
// pdlread.h
// joytest
//
// Created by Jeremy Rand on 2020-06-09.
// Copyright © 2020 Jeremy Rand. All rights reserved.
//
#ifndef _GUARD_PROJECTjoytest_FILEpdlread_
#define _GUARD_PROJECTjoytest_FILEpdlread_
#include <stdint.h>
extern uint8_t pdlRead(uint8_t pdlNum);
#endif /* define _GUARD_PROJECTjoytest_FILEpdlread_ */

23
joytest/pdlread.s Normal file
View File

@ -0,0 +1,23 @@
;
; pdlread.s
; joytest
;
; Created by Jeremy Rand on 2020-06-09.
; Copyright © 2020 Jeremy Rand. All rights reserved.
;
.include "apple2.inc"
.export _pdlRead
; ROM entry points
PREAD := $FB1E ; Read paddle in X, return AD conv. value in Y
_pdlRead:
bit $C082 ; Switch in ROM
tax ; Set paddle number
jsr PREAD ; Read paddle value
tya
ldx #$00
bit $C080 ; Switch in LC bank 2 for R/O
rts