src/mess/drivers/lynx.c
| r3375 | r3376 | |
| 236 | 236 | |
| 237 | 237 | /* sound hardware */ |
| 238 | 238 | MDRV_SPEAKER_STANDARD_MONO("mono") |
| 239 | | MDRV_SOUND_ADD("lynx", CUSTOM, 0) |
| 239 | MDRV_SOUND_ADD("lynx", CUSTOM, 0) |
| 240 | 240 | MDRV_SOUND_CONFIG(lynx_sound_interface) |
| 241 | 241 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 242 | 242 | |
| r3375 | r3376 | |
| 249 | 249 | MDRV_IMPORT_FROM( lynx ) |
| 250 | 250 | |
| 251 | 251 | /* sound hardware */ |
| 252 | | MDRV_SPEAKER_REMOVE("mono") |
| 252 | MDRV_SPEAKER_REMOVE("mono") |
| 253 | 253 | MDRV_SPEAKER_STANDARD_STEREO("left", "right") |
| 254 | | MDRV_SOUND_REMOVE("lynx") |
| 255 | | MDRV_SOUND_ADD("lynx2", CUSTOM, 0) |
| 254 | MDRV_SOUND_REMOVE("lynx") |
| 255 | MDRV_SOUND_ADD("lynx2", CUSTOM, 0) |
| 256 | 256 | MDRV_SOUND_CONFIG(lynx2_sound_interface) |
| 257 | 257 | MDRV_SOUND_ROUTE(0, "left", 0.50) |
| 258 | 258 | MDRV_SOUND_ROUTE(1, "right", 0.50) |
| r3375 | r3376 | |
| 265 | 265 | these 2 dumps differ only in this byte! |
| 266 | 266 | */ |
| 267 | 267 | |
| 268 | | #define MYROM_LOAD_BIOS(bios,name,offset,length,hash) \ |
| 269 | | ROMX_LOAD(name, offset, length, hash, ROM_BIOS(bios+1)) /* Note '+1' */ |
| 270 | | |
| 271 | 268 | ROM_START(lynx) |
| 272 | 269 | ROM_REGION(0x200,"main", 0) |
| 273 | 270 | ROM_SYSTEM_BIOS( 0, "default", "rom save" ) |
| 274 | | MYROM_LOAD_BIOS( 0, "lynx.bin", 0x00000, 0x200, CRC(e1ffecb6) SHA1(de60f2263851bbe10e5801ef8f6c357a4bc077e6)) |
| 271 | ROMX_LOAD( "lynx.bin", 0x00000, 0x200, CRC(e1ffecb6) SHA1(de60f2263851bbe10e5801ef8f6c357a4bc077e6), ROM_BIOS(1)) |
| 275 | 272 | ROM_SYSTEM_BIOS( 1, "a", "alternate rom save" ) |
| 276 | | MYROM_LOAD_BIOS( 1, "lynxa.bin", 0x00000, 0x200, CRC(0d973c9d) SHA1(e4ed47fae31693e016b081c6bda48da5b70d7ccb)) |
| 277 | | // ROM_LOAD("lynx.bin", 0, 0x200, CRC(e1ffecb6) SHA1(de60f2263851bbe10e5801ef8f6c357a4bc077e6)) |
| 273 | ROMX_LOAD( "lynxa.bin", 0x00000, 0x200, CRC(0d973c9d) SHA1(e4ed47fae31693e016b081c6bda48da5b70d7ccb), ROM_BIOS(2)) |
| 274 | |
| 278 | 275 | ROM_REGION(0x100,"gfx1", ROMREGION_ERASE00) |
| 276 | |
| 279 | 277 | ROM_REGION(0x100000, "user1", ROMREGION_ERASEFF) |
| 280 | 278 | ROM_END |
| 281 | 279 | |
| 282 | 280 | ROM_START(lynx2) |
| 283 | 281 | ROM_REGION(0x200,"main", 0) |
| 284 | 282 | ROM_LOAD("lynx2.bin", 0, 0x200, NO_DUMP) |
| 283 | |
| 285 | 284 | ROM_REGION(0x100,"gfx1", ROMREGION_ERASE00) |
| 285 | |
| 286 | 286 | ROM_REGION(0x100000, "user1", ROMREGION_ERASEFF) |
| 287 | 287 | ROM_END |
| 288 | 288 | |
| r3375 | r3376 | |
| 296 | 296 | hash_compute(dest, &data[64], length - 64, functions); |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | #define LYNX_CART 0 |
| 300 | #define LYNX_QUICKLOAD 1 |
| 299 | 301 | |
| 300 | | |
| 301 | | static int lynx_verify_cart (char *header) |
| 302 | static int lynx_verify_cart (char *header, int kind) |
| 302 | 303 | { |
| 303 | | |
| 304 | 304 | logerror("Trying Header Compare\n"); |
| 305 | 305 | |
| 306 | | if (strncmp("LYNX",&header[0],4) && strncmp("BS9",&header[6],3)) { |
| 307 | | logerror("Not an valid Lynx image\n"); |
| 308 | | return IMAGE_VERIFY_FAIL; |
| 306 | if (kind) |
| 307 | { |
| 308 | if (strncmp("BS93", &header[6], 4)) |
| 309 | { |
| 310 | logerror("Not an valid Lynx image\n"); |
| 311 | return IMAGE_VERIFY_FAIL; |
| 312 | } |
| 309 | 313 | } |
| 314 | else |
| 315 | { |
| 316 | if (strncmp("LYNX",&header[0],4)) |
| 317 | { |
| 318 | logerror("Not an valid Lynx image\n"); |
| 319 | return IMAGE_VERIFY_FAIL; |
| 320 | } |
| 321 | } |
| 322 | |
| 310 | 323 | logerror("returning ID_OK\n"); |
| 311 | 324 | return IMAGE_VERIFY_PASS; |
| 312 | 325 | } |
| r3375 | r3376 | |
| 330 | 343 | static DEVICE_IMAGE_LOAD( lynx_cart ) |
| 331 | 344 | { |
| 332 | 345 | UINT8 *rom = memory_region(image->machine, "user1"); |
| 333 | | int size; |
| 346 | int size = image_length(image); |
| 347 | const char *filetype; |
| 334 | 348 | UINT8 header[0x40]; |
| 335 | 349 | /* 64 byte header |
| 336 | 350 | LYNX |
| r3375 | r3376 | |
| 340 | 354 | 22 chars manufacturer |
| 341 | 355 | */ |
| 342 | 356 | |
| 343 | | size = image_length(image); |
| 344 | | if (image_fread(image, header, 0x40)!=0x40) |
| 345 | | { |
| 346 | | logerror("%s load error\n", image_filename(image)); |
| 347 | | return 1; |
| 348 | | } |
| 357 | filetype = image_filetype(image); |
| 349 | 358 | |
| 350 | | /* Check the image */ |
| 351 | | if (lynx_verify_cart((char*)header) == IMAGE_VERIFY_FAIL) |
| 359 | if (!mame_stricmp (filetype, "lnx")) |
| 352 | 360 | { |
| 353 | | return INIT_FAIL; |
| 354 | | } |
| 361 | if (image_fread(image, header, 0x40)!=0x40) |
| 362 | return INIT_FAIL; |
| 355 | 363 | |
| 356 | | size-=0x40; |
| 357 | | lynx_granularity=header[4]|(header[5]<<8); |
| 364 | /* Check the image */ |
| 365 | if (lynx_verify_cart((char*)header, LYNX_CART) == IMAGE_VERIFY_FAIL) |
| 366 | return INIT_FAIL; |
| 358 | 367 | |
| 359 | | logerror ("%s %dkb cartridge with %dbyte granularity from %s\n", |
| 360 | | header+10,size/1024,lynx_granularity, header+42); |
| 368 | /* 2008-10 FP: According to Handy source these should be page_size_bank0. Are we using |
| 369 | it correctly in MESS? Moreover, the next two values should be page_size_bank1. We should |
| 370 | implement this as well */ |
| 371 | lynx_granularity = header[4] | (header[5] << 8); |
| 361 | 372 | |
| 362 | | if (image_fread(image, rom, size) != size) |
| 373 | logerror ("%s %dkb cartridge with %dbyte granularity from %s\n", |
| 374 | header + 10, size / 1024, lynx_granularity, header + 42); |
| 375 | |
| 376 | size -= 0x40; |
| 377 | } |
| 378 | else if (!mame_stricmp (filetype, "lyx")) |
| 363 | 379 | { |
| 364 | | logerror("%s load error\n", image_filename(image)); |
| 365 | | return 1; |
| 380 | /* 2008-10 FP: FIXME: .lyx file don't have an header, hence they miss "lynx_granularity" |
| 381 | (see above). What if bank 0 has to be loaded elsewhere? And what about bank 1? |
| 382 | This should work with most .lyx files, but we need additional info on raw cart images */ |
| 383 | lynx_granularity = 0x0400; |
| 366 | 384 | } |
| 367 | 385 | |
| 386 | if (image_fread(image, rom, size) != size) |
| 387 | return INIT_FAIL; |
| 388 | |
| 368 | 389 | lynx_crc_keyword(image); |
| 369 | 390 | |
| 370 | | return 0; |
| 391 | return INIT_PASS; |
| 371 | 392 | } |
| 372 | 393 | |
| 373 | 394 | static QUICKLOAD_LOAD( lynx ) |
| 374 | 395 | { |
| 396 | UINT8 *data = NULL; |
| 375 | 397 | UINT8 *rom = memory_region(image->machine, "main"); |
| 376 | 398 | UINT8 header[10]; // 80 08 dw Start dw Len B S 9 3 |
| 377 | | // maybe the first 2 bytes must be used to identify the endianess of the file |
| 378 | | UINT16 start; |
| 399 | UINT16 start, length; |
| 400 | int i; |
| 379 | 401 | |
| 380 | 402 | if (image_fread(image, header, sizeof(header)) != sizeof(header)) |
| 381 | 403 | return INIT_FAIL; |
| 382 | 404 | |
| 383 | | quickload_size -= sizeof(header); |
| 405 | /* Check the image */ |
| 406 | if (lynx_verify_cart((char*)header, LYNX_QUICKLOAD) == IMAGE_VERIFY_FAIL) |
| 407 | return INIT_FAIL; |
| 408 | |
| 384 | 409 | start = header[3] | (header[2]<<8); //! big endian format in file format for little endian cpu |
| 410 | length = header[5] | (header[4]<<8); |
| 411 | length -= 10; |
| 385 | 412 | |
| 386 | | if (image_fread(image, rom+start, quickload_size) != quickload_size) |
| 413 | data = malloc(length); |
| 414 | |
| 415 | if (image_fread(image, data, length) != length) |
| 387 | 416 | return INIT_FAIL; |
| 388 | 417 | |
| 389 | | rom[0xfffc+0x200] = start&0xff; |
| 390 | | rom[0xfffd+0x200] = start>>8; |
| 418 | for (i = 0; i < length; i++) |
| 419 | program_write_byte(start + i, data[i]); |
| 391 | 420 | |
| 392 | | lynx_crc_keyword(image_from_devtype_and_index(IO_QUICKLOAD, 0)); |
| 393 | | return 0; |
| 421 | rom[0x1fc] = start & 0xff; |
| 422 | rom[0x1fd] = start >> 8; |
| 423 | |
| 424 | lynx_crc_keyword(device_list_find_by_tag( image->machine->config->devicelist, QUICKLOAD, TAG_QUICKLOAD )); |
| 425 | |
| 426 | return INIT_PASS; |
| 394 | 427 | } |
| 395 | 428 | |
| 396 | 429 | static void lynx_cartslot_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| r3375 | r3376 | |
| 406 | 439 | case MESS_DEVINFO_PTR_PARTIAL_HASH: info->partialhash = lynx_partialhash; break; |
| 407 | 440 | |
| 408 | 441 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 409 | | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "lnx"); break; |
| 442 | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "lnx,lyx"); break; |
| 410 | 443 | |
| 411 | 444 | default: cartslot_device_getinfo(devclass, state, info); break; |
| 412 | 445 | } |