2020-05-20 16:56:35 +00:00
|
|
|
//
|
|
|
|
// paddle.h
|
2020-07-13 17:23:33 +00:00
|
|
|
// Steve ][
|
2020-05-20 16:56:35 +00:00
|
|
|
//
|
|
|
|
// Created by Tamas Rudnai on 5/19/20.
|
2020-07-13 17:16:37 +00:00
|
|
|
// Copyright © 2019, 2020 Tamas Rudnai. All rights reserved.
|
2020-07-13 17:10:33 +00:00
|
|
|
//
|
|
|
|
// This file is part of Steve ][ -- The Apple ][ Emulator.
|
|
|
|
//
|
|
|
|
// Steve ][ is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Steve ][ is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Steve ][. If not, see <https://www.gnu.org/licenses/>.
|
2020-05-20 16:56:35 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef paddle_h
|
|
|
|
#define paddle_h
|
|
|
|
|
|
|
|
#include "6502.h"
|
|
|
|
|
2020-05-21 05:22:44 +00:00
|
|
|
// TODO: We may need a joystick calibration
|
|
|
|
#define PDL_MAX_TIME 3072.0 // 3300.0
|
2020-05-20 16:56:35 +00:00
|
|
|
#define PDL_TIME_DECAY ( 255.0 / PDL_MAX_TIME )
|
|
|
|
|
|
|
|
uint64_t pdl_reset_time = 0;
|
|
|
|
uint64_t pdl_current_time = 0;
|
|
|
|
uint64_t pdl_elapsed_time = 0;
|
|
|
|
|
2020-05-21 05:22:44 +00:00
|
|
|
double pdl_value[4] = { 0.5, 0.5, 0.5, 0.5 };
|
2020-05-22 05:09:57 +00:00
|
|
|
double pdl_prev[4] = { 0.5, 0.5, 0.5, 0.5 };
|
|
|
|
double pdl_diff[4] = { 0.0, 0.0, 0.0, 0.0 };
|
2020-05-21 05:22:44 +00:00
|
|
|
double * pdl_valarr = pdl_value;
|
2020-05-22 05:09:57 +00:00
|
|
|
double * pdl_prevarr = pdl_prev;
|
|
|
|
double * pdl_diffarr = pdl_diff;
|
2020-05-20 16:56:35 +00:00
|
|
|
|
|
|
|
INLINE uint8_t pdl_reset() {
|
|
|
|
pdl_reset_time = m6502.clktime + clkfrm;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INLINE uint8_t pdl_read( uint8_t pdl ) {
|
|
|
|
pdl_current_time = m6502.clktime + clkfrm;
|
|
|
|
pdl_elapsed_time = pdl_current_time - pdl_reset_time;
|
|
|
|
double normalized_time = pdl_elapsed_time / PDL_MAX_TIME; // 0: started, >= 1 ended
|
2020-05-21 05:22:44 +00:00
|
|
|
return normalized_time >= pdl_value[pdl] ? 0 : 1 << 7;
|
2020-05-20 16:56:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* paddle_h */
|