summaryrefslogtreecommitdiffstatshomepage
path: root/scripts/src/devices.lua
diff options
context:
space:
mode:
author Stefano <stefano_bodrato@hotmail.com>2016-12-15 15:34:08 +0100
committer GitHub <noreply@github.com>2016-12-15 15:34:08 +0100
commit88319825af8730eeb1786b7f6eb38c4b050c722c (patch)
treef9c5d35882d25add5031647c22a3e207b4a41b01 /scripts/src/devices.lua
parentd858209687431252c557ebbd48fd552fec1ff693 (diff)
Scrollup fix for the TMS9927 family
This fix will avoid to reconfigure all the CRTC parameters on any cursor shape change. This invasive "reset" procedure was resetting the scroll counter !
Diffstat (limited to 'scripts/src/devices.lua')
0 files changed, 0 insertions, 0 deletions
98'>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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
// license:BSD-3-Clause
// copyright-holders:Fabio Priuli
/***********************************************************************************************************


    Atari 8 bit cart emulation
    (through slot devices)

    Emulation of the cartslot(s) for Atari 8bit series of home computers

    Accessors to ROM are typically given in the area 0xa000-0xbfff, but some
    carts (and the right slot in A800) maps ROM to 0x8000-0x9fff too
    Bankswitch typically happens by accessing addresses in 0xd500-0xd5ff

    Accordingly, this device offers the following handlers
    - read_80xx/write_80xx
    - read_d5xx/write_d5xx
    Notice that these are installed in different ranges at machine start by
    the drivers, so that it might well be that offs=0 for read_80xx is 0xa000!

 ***********************************************************************************************************/


#include "emu.h"
#include "hashfile.h"
#include "a800_slot.h"

//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

const device_type A800_CART_SLOT = &device_creator<a800_cart_slot_device>;
const device_type A5200_CART_SLOT = &device_creator<a5200_cart_slot_device>;
const device_type XEGS_CART_SLOT = &device_creator<xegs_cart_slot_device>;


//-------------------------------------------------
//  device_vcs_cart_interface - constructor
//-------------------------------------------------

device_a800_cart_interface::device_a800_cart_interface (const machine_config &mconfig, device_t &device)
	: device_slot_card_interface(mconfig, device),
		m_rom(nullptr),
		m_rom_size(0),
		m_bank_mask(0)
{
}


//-------------------------------------------------
//  ~device_a800_cart_interface  - destructor
//-------------------------------------------------

device_a800_cart_interface::~device_a800_cart_interface ()
{
}

//-------------------------------------------------
//  rom_alloc - alloc the space for the cart
//-------------------------------------------------

void device_a800_cart_interface::rom_alloc(UINT32 size, const char *tag)
{
	if (m_rom == nullptr)
	{
		m_rom = device().machine().memory().region_alloc(std::string(tag).append(A800SLOT_ROM_REGION_TAG).c_str(), size, 1, ENDIANNESS_LITTLE)->base();
		m_rom_size = size;

		// setup other helpers
		m_bank_mask = (size / 0x2000) - 1;  // code for XEGS carts makes use of this to simplify banking
	}
}

//-------------------------------------------------
//  ram_alloc - alloc the space for the on-cart RAM
//-------------------------------------------------

void device_a800_cart_interface::ram_alloc(UINT32 size)
{
	m_ram.resize(size);
	device().save_item(NAME(m_ram));
}


//-------------------------------------------------
//  ram_alloc - alloc the space for the on-cart RAM
//-------------------------------------------------

void device_a800_cart_interface::nvram_alloc(UINT32 size)
{
	m_nvram.resize(size);
	device().save_item(NAME(m_nvram));
}



//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

//-------------------------------------------------
//  ****_cart_slot_device - constructor
//-------------------------------------------------
a800_cart_slot_device::a800_cart_slot_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) :
						device_t(mconfig, type, name, tag, owner, clock, shortname, __FILE__),
						device_image_interface(mconfig, *this),
						device_slot_interface(mconfig, *this), m_cart(nullptr), m_type(0)
{
}

a800_cart_slot_device::a800_cart_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
						device_t(mconfig, A800_CART_SLOT, "Atari 8bit Cartridge Slot", tag, owner, clock, "a800_cart_slot", __FILE__),
						device_image_interface(mconfig, *this),
						device_slot_interface(mconfig, *this), m_cart(nullptr), m_type(0)
{
}


a5200_cart_slot_device::a5200_cart_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
						a800_cart_slot_device(mconfig, A5200_CART_SLOT, "Atari 5200 Cartridge Slot", tag, owner, clock, "a5200_cart_slot", __FILE__)
{
}


xegs_cart_slot_device::xegs_cart_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
						a800_cart_slot_device(mconfig, XEGS_CART_SLOT, "Atari XEGS Cartridge Slot", tag, owner, clock, "xegs_cart_slot", __FILE__)
{
}


//-------------------------------------------------
//  ****_cart_slot_device - destructor
//-------------------------------------------------

a800_cart_slot_device::~a800_cart_slot_device()
{
}

a5200_cart_slot_device::~a5200_cart_slot_device()
{
}

xegs_cart_slot_device::~xegs_cart_slot_device()
{
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void a800_cart_slot_device::device_start()
{
	m_cart = dynamic_cast<device_a800_cart_interface  *>(get_card_device());
}

//-------------------------------------------------
//  device_config_complete - perform any
//  operations now that the configuration is
//  complete
//-------------------------------------------------

void a800_cart_slot_device::device_config_complete()
{
	// set brief and instance name
	update_names();
}



/*-------------------------------------------------
 call load
 -------------------------------------------------*/

//-------------------------------------------------
//  A800 PCBs
//-------------------------------------------------

struct a800_slot
{
	int                     pcb_id;
	const char              *slot_option;
};

// Here, we take the feature attribute from .xml (i.e. the PCB name) and we assign a unique ID to it
static const a800_slot slot_list[] =
{
	{ A800_8K,        "a800_8k" },
	{ A800_16K,       "a800_16k" },
	{ A800_OSS034M,   "a800_oss034m" },
	{ A800_OSS043M,   "a800_oss043m" },
	{ A800_OSSM091,   "a800_ossm091" },
	{ A800_OSS8K,     "a800_oss8k" },
	{ A800_PHOENIX,   "a800_phoenix" },
	{ A800_XEGS,      "xegs" },
	{ A800_BBSB,      "a800_bbsb" },
	{ A800_DIAMOND,   "a800_diamond" },
	{ A800_WILLIAMS,  "a800_williams" },
	{ A800_EXPRESS,   "a800_express" },
	{ A800_SPARTADOS, "a800_sparta" },
	{ A800_TURBO64,   "a800_turbo64" },
	{ A800_TURBO128,  "a800_turbo128" },
	{ A800_BLIZZARD,  "a800_blizzard" },
	{ A800_TELELINK2, "a800_tlink2" },
	{ A800_MICROCALC, "a800_sitsa" },
	{ A800_CORINA,    "a800_corina" },
	{ A800_8K_RIGHT,  "a800_8k_right" },
	{ A5200_4K,       "a5200" },
	{ A5200_8K,       "a5200" },
	{ A5200_16K,      "a5200" },
	{ A5200_32K,      "a5200" },
	{ A5200_16K_2CHIPS, "a5200_2chips" },
	{ A5200_32K,      "a5200" },
	{ A5200_BBSB,     "a5200_bbsb" }
};


static int a800_get_pcb_id(const char *slot)
{
	for (auto & elem : slot_list)
	{
		if (!core_stricmp(elem.slot_option, slot))
			return elem.pcb_id;
	}

	return 0;
}

static const char *a800_get_slot(int type)
{
	for (auto & elem : slot_list)
	{
		if (elem.pcb_id == type)
			return elem.slot_option;
	}

	return "a800_8k";
}

bool a800_cart_slot_device::call_load()
{
	if (m_cart)
	{
		UINT32 len;

		if (software_entry() != nullptr)
		{
			const char *pcb_name;
			len = get_software_region_length("rom");

			m_cart->rom_alloc(len, tag());
			memcpy(m_cart->get_rom_base(), get_software_region("rom"), len);

			if ((pcb_name = get_feature("slot")) != nullptr)
				m_type = a800_get_pcb_id(pcb_name);
			else
				m_type = A800_8K;
		}
		else
		{
			len = length();

			// check whether there is an header, to identify the cart type
			if ((len % 0x1000) == 0x10)
			{
				UINT8 header[16];
				fread(header, 0x10);
				m_type = identify_cart_type(header);
				len -= 0x10;    // in identify_cart_type the first 0x10 bytes are read, so we need to adjust here
			}
			else    // otherwise try to guess based on size
			{
				if (len == 0x8000)
					m_type = A5200_32K;
				if (len == 0x4000)
					m_type = A800_16K;
				if (len == 0x2000)
					m_type = A800_8K;
				if (len == 0x1000)
					m_type = A5200_4K;
			}

			m_cart->rom_alloc(len, tag());
			fread(m_cart->get_rom_base(), len);
		}
		if (m_type == A800_TELELINK2)
			m_cart->nvram_alloc(0x100);

		printf("%s loaded cartridge '%s' size %dK\n", machine().system().name, filename(), len/1024);
	}
	return IMAGE_INIT_PASS;
}


/*-------------------------------------------------
 call_unload
 -------------------------------------------------*/

void a800_cart_slot_device::call_unload()
{
}

/*-------------------------------------------------
 call softlist load
 -------------------------------------------------*/

bool a800_cart_slot_device::call_softlist_load(software_list_device &swlist, const char *swname, const rom_entry *start_entry)
{
	machine().rom_load().load_software_part_region(*this, swlist, swname, start_entry);
	return TRUE;
}

/*-------------------------------------------------
 identify_cart_type - code to detect cart type from
 fullpath
 -------------------------------------------------*/

int a800_cart_slot_device::identify_cart_type(UINT8 *header)
{
	int type = A800_8K;

	// check CART format
	if (strncmp((const char *)header, "CART", 4))
		fatalerror("Invalid header detected!\n");

	switch ((header[4] << 24) + (header[5] << 16) +  (header[6] << 8) + (header[7] << 0))
	{
		case 1:
			type = A800_8K;
			break;
		case 2:
			type = A800_16K;
			break;
		case 3:
			type = A800_OSS034M;
			break;
		case 8:
			type = A800_WILLIAMS;
			break;
		case 9:
			type = A800_DIAMOND;
			break;
		case 10:
			type = A800_EXPRESS;
			break;
		case 11:
			type = A800_SPARTADOS;
			break;
		case 12:
			type = A800_XEGS;
			break;
		case 15:
			type = A800_OSSM091;
			break;
		case 18:
			type = A800_BBSB;
			break;
		case 21:
			type = A800_8K_RIGHT;
			break;
		case 39:
			type = A800_PHOENIX;
			break;
		case 40:
			type = A800_BLIZZARD;
			break;
		case 44:
			type = A800_OSS8K;
			break;
		case 50:
			type = A800_TURBO64;
			break;
		case 51:
			type = A800_TURBO128;
			break;
		case 52:
			type = A800_MICROCALC;
			break;
			// Atari 5200 CART files
		case 4:
			type = A5200_32K;
			break;
		case 16:
			type = A5200_16K;
			break;
		case 19:
			type = A5200_8K;
			break;
		case 20:
			type = A5200_4K;
			break;
		case 6:
			type = A5200_16K_2CHIPS;
			break;
		case 7:
			type = A5200_BBSB;
			break;
		default:
			osd_printf_info("Cart type \"%d\" is currently unsupported.\n", (header[4] << 24) + (header[5] << 16) +  (header[6] << 8) + (header[7] << 0));
			break;
	}

	return type;
}

/*-------------------------------------------------
 get default card software
 -------------------------------------------------*/

std::string a800_cart_slot_device::get_default_card_software()
{
	if (open_image_file(mconfig().options()))
	{
		const char *slot_string;
		dynamic_buffer head(0x10);
		UINT32 len = core_fsize(m_file);
		int type = A800_8K;

		// check whether there is an header, to identify the cart type
		if ((len % 0x1000) == 0x10)
		{
			core_fread(m_file, &head[0], 0x10);
			type = identify_cart_type(&head[0]);
		}
		else    // otherwise try to guess based on size
		{
			if (len == 0x4000)
				type = A800_16K;
			if (len == 0x2000)
				type = A800_8K;
		}

		if (type >= A5200_4K)
			osd_printf_info("This game is not designed for A800. You might want to run it in A5200.\n");

		slot_string = a800_get_slot(type);

		clear();

		return std::string(slot_string);
	}
	else
		return software_get_default_slot("a800_8k");
}


std::string a5200_cart_slot_device::get_default_card_software()
{
	if (open_image_file(mconfig().options()))
	{
		const char *slot_string;
		dynamic_buffer head(0x10);
		UINT32 len = core_fsize(m_file);
		int type = A5200_8K;

		// check whether there is an header, to identify the cart type
		if ((len % 0x1000) == 0x10)
		{
			core_fread(m_file, &head[0], 0x10);
			type = identify_cart_type(&head[0]);

			std::string info;
			if (hashfile_extrainfo(*this, info) && info.compare("A13MIRRORING")==0)
				type = A5200_16K_2CHIPS;
		}
		if (type < A5200_4K)
			osd_printf_info("This game is not designed for A5200. You might want to run it in A800 or A800XL.\n");

		slot_string = a800_get_slot(type);

		clear();

		return std::string(slot_string);
	}
	else
		return software_get_default_slot("a5200");
}


std::string xegs_cart_slot_device::get_default_card_software()
{
	if (open_image_file(mconfig().options()))
	{
		const char *slot_string;
		dynamic_buffer head(0x10);
		UINT32 len = core_fsize(m_file);
		int type = A800_8K;

		// check whether there is an header, to identify the cart type
		if ((len % 0x1000) == 0x10)
		{
			core_fread(m_file, &head[0], 0x10);
			type = identify_cart_type(&head[0]);
		}
		if (type != A800_XEGS)
		{
			osd_printf_info("This game is not designed for XEGS. ");
			if (type >= A5200_4K)
				osd_printf_info("You might want to run it in A5200.\n");
			else
				osd_printf_info("You might want to run it in A800 or A800XL.\n");
		}

		slot_string = a800_get_slot(type);

		clear();

		return std::string(slot_string);
	}
	else
		return software_get_default_slot("xegs");
}


/*-------------------------------------------------
 read
 -------------------------------------------------*/

READ8_MEMBER(a800_cart_slot_device::read_80xx)
{
	if (m_cart)
		return m_cart->read_80xx(space, offset, mem_mask);
	else
		return 0xff;
}

READ8_MEMBER(a800_cart_slot_device::read_d5xx)
{
	if (m_cart)
		return m_cart->read_d5xx(space, offset, mem_mask);
	else
		return 0xff;
}


/*-------------------------------------------------
 write
 -------------------------------------------------*/

WRITE8_MEMBER(a800_cart_slot_device::write_80xx)
{
	if (m_cart)
		m_cart->write_80xx(space, offset, data, mem_mask);
}

WRITE8_MEMBER(a800_cart_slot_device::write_d5xx)
{
	if (m_cart)
		m_cart->write_d5xx(space, offset, data, mem_mask);
}