local default_text = { -- Alphabetic Buttons (NeoGeo): A~D,H,Z ["A"] = 1, -- BTN_A ["B"] = 2, -- BTN_B ["C"] = 3, -- BTN_C ["D"] = 4, -- BTN_D ["H"] = 8, -- BTN_H ["Z"] = 26, -- BTN_Z -- Numerical Buttons (Capcom): 1~10 ["a"] = 27, -- BTN_1 ["b"] = 28, -- BTN_2 ["c"] = 29, -- BTN_3 ["d"] = 30, -- BTN_4 ["e"] = 31, -- BTN_5 ["f"] = 32, -- BTN_6 ["g"] = 33, -- BTN_7 ["h"] = 34, -- BTN_8 ["i"] = 35, -- BTN_9 ["j"] = 36, -- BTN_10 -- Directions of Arrow, Joystick Ball ["+"] = 39, -- BTN_+ ["."] = 40, -- DIR_... ["1"] = 41, -- DIR_1 ["2"] = 42, -- DIR_2 ["3"] = 43, -- DIR_3 ["4"] = 44, -- DIR_4 ["5"] = 45, -- Joystick Ball ["6"] = 46, -- DIR_6 ["7"] = 47, -- DIR_7 ["8"] = 48, -- DIR_8 ["9"] = 49, -- DIR_9 ["N"] = 50, -- DIR_N -- Special Buttons ["S"] = 51, -- BTN_START ["P"] = 53, -- BTN_PUNCH ["K"] = 54, -- BTN_KICK ["G"] = 55, -- BTN_GUARD -- Composition of Arrow Directions ["!"] = 90, -- Arrow ["k"] = 100, -- Half Circle Back ["l"] = 101, -- Half Circle Front Up ["m"] = 102, -- Half Circle Front ["n"] = 103, -- Half Circle Back Up ["o"] = 104, -- 1/4 Cir For 2 Down ["p"] = 105, -- 1/4 Cir Down 2 Back ["q"] = 106, -- 1/4 Cir Back 2 Up ["r"] = 107, -- 1/4 Cir Up 2 For ["s"] = 108, -- 1/4 Cir Back 2 Down ["t"] = 109, -- 1/4 Cir Down 2 For ["u"] = 110, -- 1/4 Cir For 2 Up ["v"] = 111, -- 1/4 Cir Up 2 Back ["w"] = 112, -- Full Clock Forward ["x"] = 113, -- Full Clock Back ["y"] = 114, -- Full Count Forward ["z"] = 115, -- Full Count Back ["L"] = 116, -- 2x Forward ["M"] = 117, -- 2x Back ["Q"] = 118, -- Dragon Screw Forward ["R"] = 119, -- Dragon Screw Back -- Big letter Text ["^"] = 121, -- AIR ["?"] = 122, -- DIR ["X"] = 124, -- TAP -- Condition of Positions ["|"] = 125, -- Jump ["O"] = 126, -- Hold ["-"] = 127, -- Air ["="] = 128, -- Squatting ["~"] = 131, -- Charge -- Special Character Text ["`"] = 135, -- Small Dot ["@"] = 136, -- Double Ball [")"] = 137, -- Single Ball ["("] = 138, -- Solid Ball ["*"] = 139, -- Star ["&"] = 140, -- Solid star ["%"] = 141, -- Triangle ["$"] = 142, -- Solid Triangle ["#"] = 143, -- Double Square ["]"] = 144, -- Single Square ["["] = 145, -- Solid Square ["{"] = 146, -- Down Triangle ["}"] = 147, -- Solid Down Triangle ["<"] = 148, -- Diamond [">"] = 149, -- Solid Diamond } local expand_text = { -- Alphabetic Buttons (NeoGeo): S (Slash Button) ["s"] = 19, -- BTN_S -- Special Buttons ["S"] = 52, -- BTN_SELECT -- Multiple Punches & Kicks ["E"] = 57, -- Light Punch ["F"] = 58, -- Middle Punch ["G"] = 59, -- Strong Punch ["H"] = 60, -- Light Kick ["I"] = 61, -- Middle Kick ["J"] = 62, -- Strong Kick ["T"] = 63, -- 3 Kick ["U"] = 64, -- 3 Punch ["V"] = 65, -- 2 Kick ["W"] = 66, -- 2 Pick -- Composition of Arrow Directions ["!"] = 91, -- Continue Arrow -- Charge of Arrow Directions ["1"] = 92, -- Charge DIR_1 ["2"] = 93, -- Charge DIR_2 ["3"] = 94, -- Charge DIR_3 ["4"] = 95, -- Charge DIR_4 ["6"] = 96, -- Charge DIR_6 ["7"] = 97, -- Charge DIR_7 ["8"] = 98, -- Charge DIR_8 ["9"] = 99, -- Charge DIR_9 -- Big letter Text ["M"] = 123, -- MAX -- Condition of Positions ["-"] = 129, -- Close ["="] = 130, -- Away ["*"] = 132, -- Serious Tap ["?"] = 133, -- Any Button } local convert_text = { -- Alphabetic Buttons: A~Z ["A-button"] = 1, -- BTN_A ["B-button"] = 2, -- BTN_B ["C-button"] = 3, -- BTN_C ["D-button"] = 4, -- BTN_D ["E-button"] = 5, -- BTN_E ["F-button"] = 6, -- BTN_F ["G-button"] = 7, -- BTN_G ["H-button"] = 8, -- BTN_H ["I-button"] = 9, -- BTN_I ["J-button"] = 10, -- BTN_J ["K-button"] = 11, -- BTN_K ["L-button"] = 12, -- BTN_L ["M-button"] = 13, -- BTN_M ["N-button"] = 14, -- BTN_N ["O-button"] = 15, -- BTN_O ["P-button"] = 16, -- BTN_P ["Q-button"] = 17, -- BTN_Q ["R-button"] = 18, -- BTN_R ["S-button"] = 19, -- BTN_S ["T-button"] = 20, -- BTN_T ["U-button"] = 21, -- BTN_U ["V-button"] = 22, -- BTN_V ["W-button"] = 23, -- BTN_W ["X-button"] = 24, -- BTN_X ["Y-button"] = 25, -- BTN_Y ["Z-button"] = 26, -- BTN_Z -- Special Moves and Buttons ["decrease"] = 37, -- BTN_DEC ["increase"] = 38, -- BTN_INC ["BALL"] = 45, -- Joystick Ball ["start"] = 51, -- BTN_START ["select"] = 52, -- BTN_SELECT ["punch"] = 53, -- BTN_PUNCH ["kick"] = 54, -- BTN_KICK ["guard"] = 55, -- BTN_GUARD ["L-punch"] = 57, -- Light Punch ["M-punch"] = 58, -- Middle Punch ["S-punch"] = 59, -- Strong Punch ["L-kick"] = 60, -- Light Kick ["M-kick"] = 61, -- Middle Kick ["S-kick"] = 62, -- Strong Kick ["3-kick"] = 63, -- 3 Kick ["3-punch"] = 64, -- 3 Punch ["2-kick"] = 65, -- 2 Kick ["2-punch"] = 66, -- 2 Pick -- Custom Buttons and Cursor Buttons ["custom1"] = 67, -- CUSTOM_1 ["custom2"] = 68, -- CUSTOM_2 ["custom3"] = 69, -- CUSTOM_3 ["custom4"] = 70, -- CUSTOM_4 ["custom5"] = 71, -- CUSTOM_5 ["custom6"] = 72, -- CUSTOM_6 ["custom7"] = 73, -- CUSTOM_7 ["custom8"] = 74, -- CUSTOM_8 ["up"] = 75, -- (Cursor Up) ["down"] = 76, -- (Cursor Down) ["left"] = 77, -- (Cursor Left) ["right"] = 78, -- (Cursor Right) -- Player Lever ["lever"] = 79, -- Non Player Lever ["nplayer"] = 80, -- Gray Color Lever ["1player"] = 81, -- 1 Player Lever ["2player"] = 82, -- 2 Player Lever ["3player"] = 83, -- 3 Player Lever ["4player"] = 84, -- 4 Player Lever ["5player"] = 85, -- 5 Player Lever ["6player"] = 86, -- 6 Player Lever ["7player"] = 87, -- 7 Player Lever ["8player"] = 88, -- 8 Player Lever -- Composition of Arrow Directions ["-->"] = 90, -- Arrow ["==>"] = 91, -- Continue Arrow ["hcb"] = 100, -- Half Circle Back ["huf"] = 101, -- Half Circle Front Up ["hcf"] = 102, -- Half Circle Front ["hub"] = 103, -- Half Circle Back Up ["qfd"] = 104, -- 1/4 Cir For 2 Down ["qdb"] = 105, -- 1/4 Cir Down 2 Back ["qbu"] = 106, -- 1/4 Cir Back 2 Up ["quf"] = 107, -- 1/4 Cir Up 2 For ["qbd"] = 108, -- 1/4 Cir Back 2 Down ["qdf"] = 109, -- 1/4 Cir Down 2 For ["qfu"] = 110, -- 1/4 Cir For 2 Up ["qub"] = 111, -- 1/4 Cir Up 2 Back ["fdf"] = 112, -- Full Clock Forward ["fub"] = 113, -- Full Clock Back ["fuf"] = 114, -- Full Count Forward ["fdb"] = 115, -- Full Count Back ["xff"] = 116, -- 2x Forward ["xbb"] = 117, -- 2x Back ["dsf"] = 118, -- Dragon Screw Forward ["dsb"] = 119, -- Dragon Screw Back -- Big letter Text ["AIR"] = 121, -- AIR ["DIR"] = 122, -- DIR ["MAX"] = 123, -- MAX ["TAP"] = 124, -- TAP -- Condition of Positions ["jump"] = 125, -- Jump ["hold"] = 126, -- Hold ["air"] = 127, -- Air ["sit"] = 128, -- Squatting ["close"] = 129, -- Close ["away"] = 130, -- Away ["charge"] = 131, -- Charge ["tap"] = 132, -- Serious Tap ["button"] = 133, -- Any Button } local function convert_char(str) str = str:gsub("@(%g+)", function(s) if convert_text[s] then return utf8.char(convert_text[s] + 0xe000) end return s end) str = str:gsub("_(%g)", function(s) if default_text[s] then return utf8.char(default_text[s] + 0xe000) end return s end) str = str:gsub("%^(%g)", function(s) if expand_text[s] then return utf8.char(expand_text[s] + 0xe000) end return s end) return str end return convert_char ref='#n87'>87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
// license:BSD-3-Clause
// copyright-holders:smf
/*
* PlayStation Root Counter emulator
*
* Copyright 2003-2011 smf
*
*/
#include "emu.h"
#include "rcnt.h"
#define VERBOSE_LEVEL ( 0 )
static inline void ATTR_PRINTF(3,4) verboselog( device_t& device, int n_level, const char *s_fmt, ... )
{
if( VERBOSE_LEVEL >= n_level )
{
va_list v;
char buf[ 32768 ];
va_start( v, s_fmt );
vsprintf( buf, s_fmt, v );
va_end( v );
device.logerror( "%s: %s", device.machine().describe_context(), buf );
}
}
DEFINE_DEVICE_TYPE(PSX_RCNT, psxrcnt_device, "psxrcnt", "Sony PSX RCNT")
psxrcnt_device::psxrcnt_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, PSX_RCNT, tag, owner, clock),
m_irq0_handler(*this),
m_irq1_handler(*this),
m_irq2_handler(*this)
{
}
void psxrcnt_device::device_reset()
{
}
void psxrcnt_device::device_post_load()
{
int n;
for( n = 0; n < 3; n++ )
{
root_timer_adjust( n );
}
}
void psxrcnt_device::device_start()
{
int n;
m_irq0_handler.resolve_safe();
m_irq1_handler.resolve_safe();
m_irq2_handler.resolve_safe();
for( n = 0; n < 3; n++ )
{
root_counter[ n ].timer = timer_alloc(n);
save_item(NAME(root_counter[ n ].n_count), n);
save_item(NAME(root_counter[ n ].n_mode), n);
save_item(NAME(root_counter[ n ].n_target), n);
save_item(NAME(root_counter[ n ].n_start), n);
root_counter[ n ].n_count = 0;
root_counter[ n ].n_mode = 0;
root_counter[ n ].n_target = 0;
root_counter[ n ].n_start = 0;
}
}
void psxrcnt_device::write(offs_t offset, uint32_t data, uint32_t mem_mask)
{
int n_counter = offset / 4;
psx_root *root = &root_counter[ n_counter ];
verboselog( *this, 1, "psx_counter_w ( %08x, %08x, %08x )\n", offset, data, mem_mask );
switch( offset % 4 )
{
case 0:
root->n_count = data;
root->n_start = gettotalcycles();
break;
case 1:
root->n_count = root_current( n_counter );
root->n_start = gettotalcycles();
if( ( data & PSX_RC_RESET ) != 0 )
{
data &= ~( PSX_RC_RESET | PSX_RC_STOP );
root->n_count = 0;
}
root->n_mode = data;
#if 0
if( ( data & 0xfca6 ) != 0 ||
( ( data & 0x0100 ) != 0 && n_counter != 0 && n_counter != 1 ) ||
( ( data & 0x0200 ) != 0 && n_counter != 2 ) )
{
osd_printf_debug( "mode %d 0x%04x\n", n_counter, data & 0xfca6 );
}
#endif
break;
case 2:
root->n_target = data;
break;
default:
verboselog( *this, 0, "psx_counter_w( %08x, %08x, %08x ) unknown register\n", offset, mem_mask, data );
return;
}
root_timer_adjust( n_counter );
}
uint32_t psxrcnt_device::read(offs_t offset, uint32_t mem_mask)
{
int n_counter = offset / 4;
psx_root *root = &root_counter[ n_counter ];
uint32_t data;
switch( offset % 4 )
{
case 0:
data = root_current( n_counter );
break;
case 1:
data = root->n_mode;
break;
case 2:
data = root->n_target;
break;
default:
verboselog( *this, 0, "psx_counter_r( %08x, %08x ) unknown register\n", offset, mem_mask );
return 0;
}
verboselog( *this, 1, "psx_counter_r ( %08x, %08x ) %08x\n", offset, mem_mask, data );
return data;
}
uint64_t psxrcnt_device::gettotalcycles( void )
{
/* TODO: should return the start of the current tick. */
return ((cpu_device *)owner())->total_cycles() * 2;
}
int psxrcnt_device::root_divider( int n_counter )
{
psx_root *root = &root_counter[ n_counter ];
if( n_counter == 0 && ( root->n_mode & PSX_RC_CLC ) != 0 )
{
/* TODO: pixel clock, probably based on resolution */
return 5;
}
else if( n_counter == 1 && ( root->n_mode & PSX_RC_CLC ) != 0 )
{
return 2150;
}
else if( n_counter == 2 && ( root->n_mode & PSX_RC_DIV ) != 0 )
{
return 8;
}
return 1;
}
uint16_t psxrcnt_device::root_current( int n_counter )
{
psx_root *root = &root_counter[ n_counter ];
if( ( root->n_mode & PSX_RC_STOP ) != 0 )
{
return root->n_count;
}
else
{
uint64_t n_current;
n_current = gettotalcycles() - root->n_start;
n_current /= root_divider( n_counter );
n_current += root->n_count;
if( n_current > 0xffff )
{
/* TODO: use timer for wrap on 0x10000. */
root->n_count = n_current;
root->n_start = gettotalcycles();
}
return n_current;
}
}
int psxrcnt_device::root_target( int n_counter )
{
psx_root *root = &root_counter[ n_counter ];
if( ( root->n_mode & PSX_RC_COUNTTARGET ) != 0 ||
( root->n_mode & PSX_RC_IRQTARGET ) != 0 )
{
return root->n_target;
}
return 0x10000;
}
void psxrcnt_device::root_timer_adjust( int n_counter )
{
psx_root *root = &root_counter[ n_counter ];
if( ( root->n_mode & PSX_RC_STOP ) != 0 )
{
root->timer->adjust( attotime::never, n_counter);
}
else
{
int n_duration;
n_duration = root_target( n_counter ) - root_current( n_counter );
if( n_duration < 1 )
{
n_duration += 0x10000;
}
n_duration *= root_divider( n_counter );
// TODO: figure out if this should be calculated from the cpu clock for 50mhz boards?
root->timer->adjust( attotime::from_hz(33868800) * n_duration, n_counter);
}
}
void psxrcnt_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
int n_counter = id;
psx_root *root = &root_counter[ n_counter ];
verboselog( *this, 2, "root_finished( %d ) %04x\n", n_counter, root_current( n_counter ) );
//if( ( root->n_mode & PSX_RC_COUNTTARGET ) != 0 )
{
/* TODO: wrap should be handled differently as PSX_RC_COUNTTARGET & PSX_RC_IRQTARGET don't have to be the same. */
root->n_count = 0;
root->n_start = gettotalcycles();
}
if( ( root->n_mode & PSX_RC_REPEAT ) != 0 )
{
root_timer_adjust( n_counter );
}
if( ( root->n_mode & PSX_RC_IRQOVERFLOW ) != 0 ||
( root->n_mode & PSX_RC_IRQTARGET ) != 0 )
{
switch( n_counter )
{
case 0:
m_irq0_handler(1);
break;
case 1:
m_irq1_handler(1);
break;
case 2:
m_irq2_handler(1);
break;
}
}
}