Previous 15994 Revisions Next

r14547 Monday 20th February, 2012 at 07:58:00 UTC by Miodrag Milanović
Sync with MAME r15467, tools compile now (no whatsnew)
[ROOT]makefile
[src/emu]audit.c audit.h clifront.c dimemory.c info.c info.h machine.c romload.c romload.h validity.c
[src/emu/imagedev]cartslot.c
[src/lib/util]avhuff.c avhuff.h
[src/mame]mame.lst
[src/mame/drivers]segas16b.c
[src/tools]chdman.c ldresample.c ldverify.c tools.mak

src/mame/mame.lst
r14546r14547
41244124aliensynj      // (c) 1987 (FD1089A, decrypted)
41254125altbeast      // (c) 1988 (8751)
41264126altbeastj      // (c) 1988 (8751)
4127altbeast5      // (c) 1988 (8751)
4127altbeast6      // (c) 1988 (8751)
4128altbeast5      // (c) 1988 (FD1094, decrypted)
41284129altbeast4      // (c) 1988 (MC-8123B)
41294130altbeast2      // (c) 1988 (MC-8123B)
41304131altbeastj1      // (c) 1988 (protected)
4131altbeastj2      // (c) 1988 (protected)
41324132altbeastj3      // (c) 1988 (FD1094, decrypted)
41334133aurail         // (c) 1990 Sega / Westone
41344134aurail1         // (c) 1990 Sega / Westone (FD1089B, decrypted)
src/mame/drivers/segas16b.c
r14546r14547
37113711    CPU: 68000 + i8751 (317-0076)
37123712    ROM Board: 171-5521
37133713*/
3714ROM_START( altbeast5 )
3714ROM_START( altbeast6 )
37153715   ROM_REGION( 0xc0000, "maincpu", 0 ) /* 68000 code */
37163716   ROM_LOAD16_BYTE( "epr-11883.a7", 0x000000, 0x20000, CRC(c5b3e8f7) SHA1(06c59d38093330b74f685cb02f8c7311e4a7b38c) )
37173717   ROM_LOAD16_BYTE( "epr-11882.a5", 0x000001, 0x20000, CRC(9c01170b) SHA1(7651f791e5488ce1143eeb4ad01eb924d1460170) )
r14546r14547
37513751
37523752/**************************************************************************************************************************
37533753    Altered Beast, Sega System 16B
3754    CPU: FD1094 (317-0069)
3755    ROM Board: 171-5521
3756    Sega ID# for ROM board: 834-6661-07
3757*/
3758ROM_START( altbeast5 )
3759   ROM_REGION( 0x040000, "maincpu", 0 ) /* 68000 code */
3760   ROM_LOAD16_BYTE( "epr-11742.a7", 0x000000, 0x20000, CRC(61839534) SHA1(0246985ec642fb44d33acbbbec9f6a1936afb302) )
3761   ROM_LOAD16_BYTE( "epr-11741.a5", 0x000001, 0x20000, CRC(9b2159cb) SHA1(dba53afcbb42be3e2611d00324bca6544faec071) )
3762
3763   ROM_REGION( 0x2000, "user1", 0 ) /* decryption key */
3764   ROM_LOAD( "317-0069.key", 0x0000, 0x2000, CRC(959e256a) SHA1(392832620ddbe549b3a807ef226dadbf861a16ee) ) /* The "9" was printed over a "3" */
3765
3766   ROM_REGION( 0xc0000, "gfx1", 0 ) /* tiles */
3767   ROM_LOAD( "epr-11722.a14", 0x00000, 0x10000,  CRC(adaa8db5) SHA1(3262c98d13d08c333d16052cac841f44d2f99743) ) /* plane 1 */
3768   ROM_LOAD( "epr-11736.b14", 0x20000, 0x10000,  CRC(e9ad5e89) SHA1(769628eee6e194a84aa8a3729f4e7d07dd3ba25c) )
3769   ROM_LOAD( "epr-11723.a15", 0x40000, 0x10000,  CRC(131a3f9a) SHA1(8182c3b8ce7a2f02b226cfa2081187593c9d0d0b) ) /* plane 2 */
3770   ROM_LOAD( "epr-11737.b15", 0x60000, 0x10000,  CRC(2e420023) SHA1(3aa2c3b6fccafb4d53b6ab99b95181d3eed7c77f) )
3771   ROM_LOAD( "epr-11724.a16", 0x80000, 0x10000,  CRC(6f2ed50a) SHA1(55d0c4299e7240b0ef5316b48db7a158145c76ab) ) /* plane 3 */
3772   ROM_LOAD( "epr-11738.b16", 0xa0000, 0x10000,  CRC(de3d6d02) SHA1(428811f21c68761022521a17fc4716f6e7214b20) )
3773
3774   ROM_REGION16_BE( 0x200000, "gfx2", 0 ) /* sprites */
3775   ROM_LOAD16_BYTE( "epr-11725.b1",  0x000001, 0x010000, CRC(f8b3684e) SHA1(3de2685cae5fb3c954b8440fafce313072747469) )
3776   ROM_LOAD16_BYTE( "epr-11729.b5",  0x000000, 0x010000, CRC(ae3c2793) SHA1(c4f46861ea63ffa3c038a1ef931479b94e5382df) )
3777   ROM_LOAD16_BYTE( "epr-11726.b2",  0x040001, 0x010000, CRC(3cce5419) SHA1(fccdbd6d05f5927272e7d6e5f997418d4fa2baf5) )
3778   ROM_LOAD16_BYTE( "epr-11730.b6",  0x040000, 0x010000, CRC(3af62b55) SHA1(9f079af88aaf2447948c9ac01c6cbd1e79539704) )
3779   ROM_LOAD16_BYTE( "epr-11727.b3",  0x080001, 0x010000, CRC(b0390078) SHA1(9035d9f45c67bdc802710018722943f5b63e8b5d) )
3780   ROM_LOAD16_BYTE( "epr-11731.b7",  0x080000, 0x010000, CRC(2a87744a) SHA1(421b3926de046ddeddad05f65fc6b5078af28dbd) )
3781   ROM_LOAD16_BYTE( "epr-11728.b4",  0x0c0001, 0x010000, CRC(f3a43fd8) SHA1(d42833ecd0c1920f1a6904d32c096f12d8622141) )
3782   ROM_LOAD16_BYTE( "epr-11732.b8",  0x0c0000, 0x010000, CRC(2fb3e355) SHA1(960e0a66b23f79833b011ea35a5a412dffb47083) )
3783   ROM_LOAD16_BYTE( "epr-11717.a1",  0x100001, 0x010000, CRC(676be0cb) SHA1(1e7d4c5f231992f111cc7885e97bc5a7267a5e89) )
3784   ROM_LOAD16_BYTE( "epr-11733.b10", 0x100000, 0x010000, CRC(802cac94) SHA1(24e5aa74ce8b6c53c78cc33a41a473df3fbce639) )
3785   ROM_LOAD16_BYTE( "epr-11718.a2",  0x140001, 0x010000, CRC(882864c2) SHA1(bd44bbdc13e5fd1b5c31c343da00a75b9dd90478) )
3786   ROM_LOAD16_BYTE( "epr-11734.b11", 0x140000, 0x010000, CRC(76c704d2) SHA1(35b393071e29b8d122d3f904b923689a7dddc808) )
3787   ROM_LOAD16_BYTE( "epr-11719.a3",  0x180001, 0x010000, CRC(339987f7) SHA1(b5650f8bdbd44510e84686b20daf70bc4a564f28) )
3788   ROM_LOAD16_BYTE( "epr-11735.b12", 0x180000, 0x010000, CRC(4fe406aa) SHA1(7f068b81f35be4cc4785824ed524d28f201ff0a5) )
3789
3790   ROM_REGION( 0x50000, "soundcpu", 0 ) /* sound CPU */
3791   ROM_LOAD( "epr-11671.a10", 0x00000, 0x08000, CRC(2b71343b) SHA1(8a657f787de2b9d5161ed2c109642a148348af09) )
3792   ROM_LOAD( "opr-11672.a11", 0x10000, 0x20000, CRC(bbd7f460) SHA1(bbc5c2219cb3a827d84062b19affd9780da2a3cf) )
3793   ROM_LOAD( "opr-11673.a12", 0x30000, 0x20000, CRC(400c4a36) SHA1(de4bdfa91734410e0a7f6a16bf8336db172f458a) )
3794ROM_END
3795
3796/**************************************************************************************************************************
3797    Altered Beast, Sega System 16B
37543798    CPU: 68000 + MC-8123B 317-0066
37553799    ROM Board: 171-5521
37563800    Sega ID# for ROM board: 834-6661-06
r14546r14547
38733917
38743918/**************************************************************************************************************************
38753919    Jyuohki (Altered Beast), Sega System 16B
3876    CPU: FD1094 (317-0069)
3877    ROM Board: 171-5521
3878    Sega ID# for ROM board: 834-6661-07
3879*/
3880ROM_START( altbeastj2 )
3881   ROM_REGION( 0x040000, "maincpu", 0 ) /* 68000 code */
3882   ROM_LOAD16_BYTE( "epr-11742.a7", 0x000000, 0x20000, CRC(61839534) SHA1(0246985ec642fb44d33acbbbec9f6a1936afb302) )
3883   ROM_LOAD16_BYTE( "epr-11741.a5", 0x000001, 0x20000, CRC(9b2159cb) SHA1(dba53afcbb42be3e2611d00324bca6544faec071) )
3884
3885   ROM_REGION( 0x2000, "user1", 0 ) /* decryption key */
3886   ROM_LOAD( "317-0069.key", 0x0000, 0x2000, NO_DUMP ) /* The "9" was printed over a "3" */
3887
3888   ROM_REGION( 0xc0000, "gfx1", 0 ) /* tiles */
3889   ROM_LOAD( "epr-11722.a14", 0x00000, 0x10000,  CRC(adaa8db5) SHA1(3262c98d13d08c333d16052cac841f44d2f99743) ) /* plane 1 */
3890   ROM_LOAD( "epr-11736.b14", 0x20000, 0x10000,  CRC(e9ad5e89) SHA1(769628eee6e194a84aa8a3729f4e7d07dd3ba25c) )
3891   ROM_LOAD( "epr-11723.a15", 0x40000, 0x10000,  CRC(131a3f9a) SHA1(8182c3b8ce7a2f02b226cfa2081187593c9d0d0b) ) /* plane 2 */
3892   ROM_LOAD( "epr-11737.b15", 0x60000, 0x10000,  CRC(2e420023) SHA1(3aa2c3b6fccafb4d53b6ab99b95181d3eed7c77f) )
3893   ROM_LOAD( "epr-11724.a16", 0x80000, 0x10000,  CRC(6f2ed50a) SHA1(55d0c4299e7240b0ef5316b48db7a158145c76ab) ) /* plane 3 */
3894   ROM_LOAD( "epr-11738.b16", 0xa0000, 0x10000,  CRC(de3d6d02) SHA1(428811f21c68761022521a17fc4716f6e7214b20) )
3895
3896   ROM_REGION16_BE( 0x200000, "gfx2", 0 ) /* sprites */
3897   ROM_LOAD16_BYTE( "epr-11725.b1",  0x000001, 0x010000, CRC(f8b3684e) SHA1(3de2685cae5fb3c954b8440fafce313072747469) )
3898   ROM_LOAD16_BYTE( "epr-11729.b5",  0x000000, 0x010000, CRC(ae3c2793) SHA1(c4f46861ea63ffa3c038a1ef931479b94e5382df) )
3899   ROM_LOAD16_BYTE( "epr-11726.b2",  0x040001, 0x010000, CRC(3cce5419) SHA1(fccdbd6d05f5927272e7d6e5f997418d4fa2baf5) )
3900   ROM_LOAD16_BYTE( "epr-11730.b6",  0x040000, 0x010000, CRC(3af62b55) SHA1(9f079af88aaf2447948c9ac01c6cbd1e79539704) )
3901   ROM_LOAD16_BYTE( "epr-11727.b3",  0x080001, 0x010000, CRC(b0390078) SHA1(9035d9f45c67bdc802710018722943f5b63e8b5d) )
3902   ROM_LOAD16_BYTE( "epr-11731.b7",  0x080000, 0x010000, CRC(2a87744a) SHA1(421b3926de046ddeddad05f65fc6b5078af28dbd) )
3903   ROM_LOAD16_BYTE( "epr-11728.b4",  0x0c0001, 0x010000, CRC(f3a43fd8) SHA1(d42833ecd0c1920f1a6904d32c096f12d8622141) )
3904   ROM_LOAD16_BYTE( "epr-11732.b8",  0x0c0000, 0x010000, CRC(2fb3e355) SHA1(960e0a66b23f79833b011ea35a5a412dffb47083) )
3905   ROM_LOAD16_BYTE( "epr-11717.a1",  0x100001, 0x010000, CRC(676be0cb) SHA1(1e7d4c5f231992f111cc7885e97bc5a7267a5e89) )
3906   ROM_LOAD16_BYTE( "epr-11733.b10", 0x100000, 0x010000, CRC(802cac94) SHA1(24e5aa74ce8b6c53c78cc33a41a473df3fbce639) )
3907   ROM_LOAD16_BYTE( "epr-11718.a2",  0x140001, 0x010000, CRC(882864c2) SHA1(bd44bbdc13e5fd1b5c31c343da00a75b9dd90478) )
3908   ROM_LOAD16_BYTE( "epr-11734.b11", 0x140000, 0x010000, CRC(76c704d2) SHA1(35b393071e29b8d122d3f904b923689a7dddc808) )
3909   ROM_LOAD16_BYTE( "epr-11719.a3",  0x180001, 0x010000, CRC(339987f7) SHA1(b5650f8bdbd44510e84686b20daf70bc4a564f28) )
3910   ROM_LOAD16_BYTE( "epr-11735.b12", 0x180000, 0x010000, CRC(4fe406aa) SHA1(7f068b81f35be4cc4785824ed524d28f201ff0a5) )
3911
3912   ROM_REGION( 0x50000, "soundcpu", 0 ) /* sound CPU */
3913   ROM_LOAD( "epr-11671.a10", 0x00000, 0x08000, CRC(2b71343b) SHA1(8a657f787de2b9d5161ed2c109642a148348af09) )
3914   ROM_LOAD( "opr-11672.a11", 0x10000, 0x20000, CRC(bbd7f460) SHA1(bbc5c2219cb3a827d84062b19affd9780da2a3cf) )
3915   ROM_LOAD( "opr-11673.a12", 0x30000, 0x20000, CRC(400c4a36) SHA1(de4bdfa91734410e0a7f6a16bf8336db172f458a) )
3916ROM_END
3917
3918/**************************************************************************************************************************
3919    Jyuohki (Altered Beast), Sega System 16B
39203920    CPU: FD1094 (317-0065)
39213921    ROM Board: 171-5521
39223922*/
r14546r14547
39323932   ROM_LOAD( "opr-11674.a14", 0x00000, 0x20000, CRC(a57a66d5) SHA1(5103583d48997abad12a0c5fee26431c486ced52) )
39333933   ROM_LOAD( "opr-11675.a15", 0x20000, 0x20000, CRC(2ef2f144) SHA1(38d22d609db2d9b6067b5d12f6499436de4605cb) )
39343934   ROM_LOAD( "opr-11676.a16", 0x40000, 0x20000, CRC(0c04acac) SHA1(87fe2a0dd9913f9550e9b4cbc7e7465b61640e07) )
3935/* If this is truly a Japanese set it should use these roms:
3936    ROM_LOAD( "epr-11722.a14", 0x00000, 0x10000,  CRC(adaa8db5) SHA1(3262c98d13d08c333d16052cac841f44d2f99743) )
3937    ROM_LOAD( "epr-11736.b14", 0x20000, 0x10000,  CRC(e9ad5e89) SHA1(769628eee6e194a84aa8a3729f4e7d07dd3ba25c) )
3938    ROM_LOAD( "epr-11723.a15", 0x40000, 0x10000,  CRC(131a3f9a) SHA1(8182c3b8ce7a2f02b226cfa2081187593c9d0d0b) )
3939    ROM_LOAD( "epr-11737.b15", 0x60000, 0x10000,  CRC(2e420023) SHA1(3aa2c3b6fccafb4d53b6ab99b95181d3eed7c77f) )
3940    ROM_LOAD( "epr-11724.a16", 0x80000, 0x10000,  CRC(6f2ed50a) SHA1(55d0c4299e7240b0ef5316b48db7a158145c76ab) )
3941    ROM_LOAD( "epr-11738.b16", 0xa0000, 0x10000,  CRC(de3d6d02) SHA1(428811f21c68761022521a17fc4716f6e7214b20) )
3942*/
39433935
39443936   ROM_REGION16_BE( 0x100000, "gfx2", 0 ) /* sprites */
39453937   ROM_LOAD16_BYTE( "epr-11677.b1", 0x00001, 0x20000, CRC(a01425cd) SHA1(72be5ec29e476601f9bf6aaedef9b73cedeb42f0) )
r14546r14547
39503942   ROM_LOAD16_BYTE( "epr-11683.b7", 0x80000, 0x20000, CRC(f9a60f06) SHA1(0cffcfdb02733feaa869198b7e668c58b47c321a) )
39513943   ROM_LOAD16_BYTE( "epr-11680.b4", 0xc0001, 0x20000, CRC(f43dcdec) SHA1(2941500cf33afca487f19f2329033d5d17aad826) )
39523944   ROM_LOAD16_BYTE( "epr-11684.b8", 0xc0000, 0x20000, CRC(b20c0edb) SHA1(6c8694d05e3adac37c9015037ab800233371db36) )
3953/* If this is truly a Japanese set it should use these roms:
3954    ROM_LOAD16_BYTE( "epr-11725.b1",  0x000001, 0x010000, CRC(f8b3684e) SHA1(3de2685cae5fb3c954b8440fafce313072747469) )
3955    ROM_LOAD16_BYTE( "epr-11729.b5",  0x000000, 0x010000, CRC(ae3c2793) SHA1(c4f46861ea63ffa3c038a1ef931479b94e5382df) )
3956    ROM_LOAD16_BYTE( "epr-11726.b2",  0x040001, 0x010000, CRC(3cce5419) SHA1(fccdbd6d05f5927272e7d6e5f997418d4fa2baf5) )
3957    ROM_LOAD16_BYTE( "epr-11730.b6",  0x040000, 0x010000, CRC(3af62b55) SHA1(9f079af88aaf2447948c9ac01c6cbd1e79539704) )
3958    ROM_LOAD16_BYTE( "epr-11727.b3",  0x080001, 0x010000, CRC(b0390078) SHA1(9035d9f45c67bdc802710018722943f5b63e8b5d) )
3959    ROM_LOAD16_BYTE( "epr-11731.b7",  0x080000, 0x010000, CRC(2a87744a) SHA1(421b3926de046ddeddad05f65fc6b5078af28dbd) )
3960    ROM_LOAD16_BYTE( "epr-11728.b4",  0x0c0001, 0x010000, CRC(f3a43fd8) SHA1(d42833ecd0c1920f1a6904d32c096f12d8622141) )
3961    ROM_LOAD16_BYTE( "epr-11732.b8",  0x0c0000, 0x010000, CRC(2fb3e355) SHA1(960e0a66b23f79833b011ea35a5a412dffb47083) )
3962    ROM_LOAD16_BYTE( "epr-11717.a1",  0x100001, 0x010000, CRC(676be0cb) SHA1(1e7d4c5f231992f111cc7885e97bc5a7267a5e89) )
3963    ROM_LOAD16_BYTE( "epr-11733.b10", 0x100000, 0x010000, CRC(802cac94) SHA1(24e5aa74ce8b6c53c78cc33a41a473df3fbce639) )
3964    ROM_LOAD16_BYTE( "epr-11718.a2",  0x140001, 0x010000, CRC(882864c2) SHA1(bd44bbdc13e5fd1b5c31c343da00a75b9dd90478) )
3965    ROM_LOAD16_BYTE( "epr-11734.b11", 0x140000, 0x010000, CRC(76c704d2) SHA1(35b393071e29b8d122d3f904b923689a7dddc808) )
3966    ROM_LOAD16_BYTE( "epr-11719.a3",  0x180001, 0x010000, CRC(339987f7) SHA1(b5650f8bdbd44510e84686b20daf70bc4a564f28) )
3967    ROM_LOAD16_BYTE( "epr-11735.b12", 0x180000, 0x010000, CRC(4fe406aa) SHA1(7f068b81f35be4cc4785824ed524d28f201ff0a5) )
3968*/
39693945
39703946   ROM_REGION( 0x50000, "soundcpu", 0 ) /* sound CPU */
39713947   ROM_LOAD( "epr-11671.a10", 0x00000, 0x08000, CRC(2b71343b) SHA1(8a657f787de2b9d5161ed2c109642a148348af09) )
r14546r14547
66826658
66836659GAME( 1988, altbeast,   0,        system16b_8751,      altbeast, altbeast_5521,      ROT0,   "Sega", "Altered Beast (set 8, 8751 317-0078)", 0 )
66846660GAME( 1988, altbeastj,  altbeast, system16b_8751,      altbeast, altbeasj_5521,      ROT0,   "Sega", "Juuouki (set 7, Japan, 8751 317-0077)", 0 )
6685GAME( 1988, altbeast5,  altbeast, system16b_8751,      altbeast, altbeas5_5521,      ROT0,   "Sega", "Altered Beast (set 6, 8751 317-0076)", 0 )
6661GAME( 1988, altbeast6,  altbeast, system16b_8751,      altbeast, altbeas5_5521,      ROT0,   "Sega", "Altered Beast (set 6, 8751 317-0076)", 0 )
6662GAME( 1988, altbeast5,  altbeast, system16b,           altbeast, generic_5521,       ROT0,   "Sega", "Altered Beast (set 5, FD1094 317-0069)", 0 )
66866663GAME( 1988, altbeast4,  altbeast, system16b,           altbeast, altbeas4_5521,      ROT0,   "Sega", "Altered Beast (set 4, MC-8123B 317-0066)", 0 )
66876664GAME( 1988, altbeastj3, altbeast, system16b,           altbeast, generic_5521,       ROT0,   "Sega", "Juuouki (set 3, Japan, FD1094 317-0068)", 0 )
66886665GAME( 1988, altbeast2,  altbeast, system16b,           altbeast, altbeas4_5521,      ROT0,   "Sega", "Altered Beast (set 2, MC-8123B 317-0066)", 0 )
66896666GAME( 1988, altbeastj1, altbeast, system16b,           altbeast, generic_5521,       ROT0,   "Sega", "Juuouki (set 1, Japan, FD1094 317-0065)", GAME_NOT_WORKING ) /* No CPU decrypt key */
6690GAME( 1988, altbeastj2, altbeast, system16b,           altbeast, generic_5521,       ROT0,   "Sega", "Juuouki (set 5, Japan, FD1094 317-0069)", GAME_NOT_WORKING ) /* No CPU decrypt key */
66916667
66926668GAME( 1990, aurail,     0,        system16b,           aurail,   generic_5704,       ROT0,   "Sega / Westone", "Aurail (set 3, US, unprotected)", 0 )
66936669GAME( 1990, aurail1,    aurail,   system16b,           aurail,   aurail1_5704,       ROT0,   "Sega / Westone", "Aurail (set 2, World, FD1089B 317-0168)", 0 )
src/tools/ldverify.c
r14546r14547
4141#include <stdlib.h>
4242#include <ctype.h>
4343#include <new>
44#include "coretmpl.h"
4445#include "aviio.h"
46#include "avhuff.h"
4547#include "bitmap.h"
4648#include "chd.h"
4749#include "vbiparse.h"
4850
4951
5052
51/***************************************************************************
52    CONSTANTS
53***************************************************************************/
53//**************************************************************************
54//  CONSTANTS
55//**************************************************************************
5456
55#define REPORT_BLANKS_THRESHOLD      50
57const int REPORT_BLANKS_THRESHOLD = 50;
5658
5759
5860
59/***************************************************************************
60    TYPE DEFINITIONS
61***************************************************************************/
61//**************************************************************************
62//  TYPE DEFINITIONS
63//**************************************************************************
6264
63typedef struct _movie_info movie_info;
64struct _movie_info
65struct movie_info
6566{
6667   double   framerate;
6768   int      numframes;
r14546r14547
7172   int      channels;
7273};
7374
74typedef struct _video_info video_info;
75struct _video_info
75struct video_info
7676{
7777   int first_whitefield;
78   int saw_leadin;
79   int saw_leadout;
78   bool saw_leadin;
79   bool saw_leadout;
8080   int last_frame;
8181   int last_chapter;
8282   int cadence;
r14546r14547
9595   int num_high_fields;
9696};
9797
98typedef struct _audio_info audio_info;
99struct _audio_info
98struct audio_info
10099{
101100   int min_lsample;
102101   int min_rsample;
r14546r14547
111110
112111
113112
114/***************************************************************************
115    GLOBAL VARIABLES
116***************************************************************************/
113//**************************************************************************
114//  GLOBAL VARIABLES
115//**************************************************************************
117116
118static UINT8 chdinterlaced;
117static bool chdinterlaced;
119118
120119
121120
122/***************************************************************************
123    AVI HANDLING
124***************************************************************************/
121//**************************************************************************
122//  AVI HANDLING
123//**************************************************************************
125124
126/*-------------------------------------------------
127    open_avi - open an AVI file and return
128    information about it
129-------------------------------------------------*/
125//-------------------------------------------------
126//  open_avi - open an AVI file and return
127//  information about it
128//-------------------------------------------------
130129
131static void *open_avi(const char *filename, movie_info *info)
130static void *open_avi(const char *filename, movie_info &info)
132131{
133   const avi_movie_info *aviinfo;
134   avi_error avierr;
132   // open the file
135133   avi_file *avi;
136
137   /* open the file */
138   avierr = avi_open(filename, &avi);
134   avi_error avierr = avi_open(filename, &avi);
139135   if (avierr != AVIERR_NONE)
140136   {
141137      fprintf(stderr, "Error opening AVI file: %s\n", avi_error_string(avierr));
142138      return NULL;
143139   }
144140
145   /* extract movie info */
146   aviinfo = avi_get_movie_info(avi);
147   info->framerate = (double)aviinfo->video_timescale / (double)aviinfo->video_sampletime;
148   info->numframes = aviinfo->video_numsamples;
149   info->width = aviinfo->video_width;
150   info->height = aviinfo->video_height;
151   info->samplerate = aviinfo->audio_samplerate;
152   info->channels = aviinfo->audio_channels;
153
141   // extract movie info
142   const avi_movie_info *aviinfo = avi_get_movie_info(avi);
143   info.framerate = (double)aviinfo->video_timescale / (double)aviinfo->video_sampletime;
144   info.numframes = aviinfo->video_numsamples;
145   info.width = aviinfo->video_width;
146   info.height = aviinfo->video_height;
147   info.samplerate = aviinfo->audio_samplerate;
148   info.channels = aviinfo->audio_channels;
154149   return avi;
155150}
156151
157152
158/*-------------------------------------------------
159    read_avi - read a frame from an AVI file
160-------------------------------------------------*/
153//-------------------------------------------------
154//  read_avi - read a frame from an AVI file
155//-------------------------------------------------
161156
162static int read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int *samples)
157static bool read_avi(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int &samples)
163158{
164   const avi_movie_info *aviinfo = avi_get_movie_info((avi_file *)file);
165   UINT32 firstsample = ((UINT64)aviinfo->audio_samplerate * (UINT64)frame * (UINT64)aviinfo->video_sampletime + aviinfo->video_timescale - 1) / (UINT64)aviinfo->video_timescale;
166   UINT32 lastsample = ((UINT64)aviinfo->audio_samplerate * (UINT64)(frame + 1) * (UINT64)aviinfo->video_sampletime + aviinfo->video_timescale - 1) / (UINT64)aviinfo->video_timescale;
167   avi_error avierr;
159   avi_file *avifile = reinterpret_cast<avi_file *>(file);
168160
169   /* read the frame */
170   avierr = avi_read_video_frame((avi_file *)file, frame, bitmap);
161   // read the frame
162   avi_error avierr = avi_read_video_frame(avifile, frame, bitmap);
171163   if (avierr != AVIERR_NONE)
172164      return FALSE;
173165
174   /* read the samples */
175   avierr = avi_read_sound_samples((avi_file *)file, 0, firstsample, lastsample - firstsample, lsound);
176   avierr = avi_read_sound_samples((avi_file *)file, 1, firstsample, lastsample - firstsample, rsound);
166   // read the samples
167   const avi_movie_info *aviinfo = avi_get_movie_info(avifile);
168   UINT32 firstsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale);
169   UINT32 lastsample = (UINT64(aviinfo->audio_samplerate) * UINT64(frame + 1) * UINT64(aviinfo->video_sampletime) + aviinfo->video_timescale - 1) / UINT64(aviinfo->video_timescale);
170   avierr = avi_read_sound_samples(avifile, 0, firstsample, lastsample - firstsample, lsound);
171   avierr = avi_read_sound_samples(avifile, 1, firstsample, lastsample - firstsample, rsound);
177172   if (avierr != AVIERR_NONE)
178      return FALSE;
179   *samples = lastsample - firstsample;
180   return TRUE;
173      return false;
174   samples = lastsample - firstsample;
175   return true;
181176}
182177
183178
184/*-------------------------------------------------
185    close_avi - close an AVI file
186-------------------------------------------------*/
179//-------------------------------------------------
180//  close_avi - close an AVI file
181//-------------------------------------------------
187182
188183static void close_avi(void *file)
189184{
190   avi_close((avi_file *)file);
185   avi_file *avifile = reinterpret_cast<avi_file *>(file);
186   avi_close(avifile);
191187}
192188
193189
194190
195/***************************************************************************
196    CHD HANDLING
197***************************************************************************/
191//**************************************************************************
192//  CHD HANDLING
193//**************************************************************************
198194
199/*-------------------------------------------------
200    open_chd - open a CHD file and return
201    information about it
202-------------------------------------------------*/
195//-------------------------------------------------
196//  open_chd - open a CHD file and return
197//  information about it
198//-------------------------------------------------
203199
204static void *open_chd(const char *filename, movie_info *info)
200static void *open_chd(const char *filename, movie_info &info)
205201{
206   int fps, fpsfrac, width, height, interlaced, channels, rate;
207   char metadata[256];
208   chd_error chderr;
209   chd_file *chd;
202   chd_file *chd = new chd_file;
210203
211   /* open the file */
212   chderr = chd_open(filename, CHD_OPEN_READ, NULL, &chd);
204   // open the file
205   chd_error chderr = chd->open(filename);
213206   if (chderr != CHDERR_NONE)
214207   {
215      fprintf(stderr, "Error opening CHD file: %s\n", chd_error_string(chderr));
208      fprintf(stderr, "Error opening CHD file: %s\n", chd_file::error_string(chderr));
209      delete chd;
216210      return NULL;
217211   }
218212
219   /* get the metadata */
220   chderr = chd_get_metadata(chd, AV_METADATA_TAG, 0, metadata, sizeof(metadata), NULL, NULL, NULL);
213   // get the metadata
214   astring metadata;
215   chderr = chd->read_metadata(AV_METADATA_TAG, 0, metadata);
221216   if (chderr != CHDERR_NONE)
222217   {
223      fprintf(stderr, "Error getting A/V metadata: %s\n", chd_error_string(chderr));
224      chd_close(chd);
218      fprintf(stderr, "Error getting A/V metadata: %s\n", chd_file::error_string(chderr));
219      delete chd;
225220      return NULL;
226221   }
227222
228   /* extract the info */
223   // extract the info
224   int fps, fpsfrac, width, height, interlaced, channels, rate;
229225   if (sscanf(metadata, AV_METADATA_FORMAT, &fps, &fpsfrac, &width, &height, &interlaced, &channels, &rate) != 7)
230226   {
231227      fprintf(stderr, "Improperly formatted metadata\n");
232      chd_close(chd);
228      delete chd;
233229      return NULL;
234230   }
235231
236   /* extract movie info */
237   info->framerate = (fps * 1000000 + fpsfrac) / 1000000.0;
238   info->numframes = chd_get_header(chd)->totalhunks;
239   info->width = width;
240   info->height = height;
241   info->samplerate = rate;
242   info->channels = channels;
232   // extract movie info
233   info.framerate = (fps * 1000000 + fpsfrac) / 1000000.0;
234   info.numframes = chd->hunk_count();
235   info.width = width;
236   info.height = height;
237   info.samplerate = rate;
238   info.channels = channels;
243239
244   /* convert to an interlaced frame */
240   // convert to an interlaced frame
245241   chdinterlaced = interlaced;
246242   if (interlaced)
247243   {
248      info->framerate /= 2;
249      info->numframes = (info->numframes + 1) / 2;
250      info->height *= 2;
244      info.framerate /= 2;
245      info.numframes = (info.numframes + 1) / 2;
246      info.height *= 2;
251247   }
252
253248   return chd;
254249}
255250
256251
257/*-------------------------------------------------
258    read_chd - read a frame from a CHD file
259-------------------------------------------------*/
252//-------------------------------------------------
253//  read_chd - read a frame from a CHD file
254//-------------------------------------------------
260255
261static int read_chd(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int *samples)
256static int read_chd(void *file, int frame, bitmap_yuy16 &bitmap, INT16 *lsound, INT16 *rsound, int &samples)
262257{
263   av_codec_decompress_config avconfig;
258   chd_file *chdfile = reinterpret_cast<chd_file *>(file);
259   
260   // loop over fields
264261   int interlace_factor = chdinterlaced ? 2 : 1;
265   bitmap_yuy16 fakebitmap;
266   UINT32 numsamples;
267   chd_error chderr;
268   int fieldnum;
269
270   /* loop over fields */
271   *samples = 0;
272   for (fieldnum = 0; fieldnum < interlace_factor; fieldnum++)
262   samples = 0;
263   for (int fieldnum = 0; fieldnum < interlace_factor; fieldnum++)
273264   {
274      /* make a fake bitmap for this field */
265      // make a fake bitmap for this field
266      avhuff_decompress_config avconfig;
275267      avconfig.video.wrap(&bitmap.pix16(fieldnum), bitmap.width(), bitmap.height() / interlace_factor, bitmap.rowpixels() * interlace_factor);
276268
277      /* configure the codec */
269      // configure the codec
270      UINT32 numsamples;
278271      avconfig.maxsamples = 48000;
279272      avconfig.actsamples = &numsamples;
280      avconfig.audio[0] = &lsound[*samples];
281      avconfig.audio[1] = &rsound[*samples];
273      avconfig.audio[0] = &lsound[samples];
274      avconfig.audio[1] = &rsound[samples];
282275
283      /* configure the decompressor for this frame */
284      chd_codec_config((chd_file *)file, AV_CODEC_DECOMPRESS_CONFIG, &avconfig);
276      // configure the decompressor for this frame
277      chdfile->codec_configure(CHD_CODEC_AVHUFF, AVHUFF_CODEC_DECOMPRESS_CONFIG, &avconfig);
285278
286      /* read the frame */
287      chderr = chd_read((chd_file *)file, frame * interlace_factor + fieldnum, NULL);
279      // read the frame
280      chd_error chderr = chdfile->read_hunk(frame * interlace_factor + fieldnum, NULL);
288281      if (chderr != CHDERR_NONE)
289         return FALSE;
282         return false;
290283
291      /* account for samples read */
292      *samples += numsamples;
284      // account for samples read
285      samples += numsamples;
293286   }
294   return TRUE;
287   return true;
295288}
296289
297290
298/*-------------------------------------------------
299    close_chd - close a CHD file
300-------------------------------------------------*/
291//-------------------------------------------------
292//  close_chd - close a CHD file
293//-------------------------------------------------
301294
302295static void close_chd(void *file)
303296{
304   chd_close((chd_file *)file);
297   chd_file *chdfile = reinterpret_cast<chd_file *>(file);
298   delete chdfile;
305299}
306300
307301
308302
309/***************************************************************************
310    CORE IMPLEMENTATION
311***************************************************************************/
303//**************************************************************************
304//  CORE IMPLEMENTATION
305//**************************************************************************
312306
313/*-------------------------------------------------
314    init_video - init video info structure
315-------------------------------------------------*/
307//-------------------------------------------------
308//  init_video - init video info structure
309//-------------------------------------------------
316310
317static void init_video(video_info *video)
311static void init_video(video_info &video)
318312{
319   video->first_whitefield = -1;
320   video->saw_leadin = FALSE;
321   video->saw_leadout = FALSE;
322   video->last_frame = -1;
323   video->last_chapter = -1;
324   video->cadence = -1;
325   video->cadence_history = 0;
326   video->prev_whitefield = -1;
327   video->min_overall = 255;
328   video->max_overall = 0;
329   video->first_blank_frame = -1;
330   video->first_blank_field = -1;
331   video->num_blank_fields = -1;
332   video->first_low_frame = -1;
333   video->first_low_field = -1;
334   video->num_low_fields = -1;
335   video->first_high_frame = -1;
336   video->first_high_field = -1;
337   video->num_high_fields = -1;
313   video.first_whitefield = -1;
314   video.saw_leadin = false;
315   video.saw_leadout = false;
316   video.last_frame = -1;
317   video.last_chapter = -1;
318   video.cadence = -1;
319   video.cadence_history = 0;
320   video.prev_whitefield = -1;
321   video.min_overall = 255;
322   video.max_overall = 0;
323   video.first_blank_frame = -1;
324   video.first_blank_field = -1;
325   video.num_blank_fields = -1;
326   video.first_low_frame = -1;
327   video.first_low_field = -1;
328   video.num_low_fields = -1;
329   video.first_high_frame = -1;
330   video.first_high_field = -1;
331   video.num_high_fields = -1;
338332}
339333
340334
341/*-------------------------------------------------
342    verify_video - verify video frame
343-------------------------------------------------*/
335//-------------------------------------------------
336//  verify_video - verify video frame
337//-------------------------------------------------
344338
345static void verify_video(video_info *video, int frame, bitmap_yuy16 &bitmap)
339static void verify_video(video_info &video, int frame, bitmap_yuy16 &bitmap)
346340{
341   // loop over fields
347342   const int fields_per_frame = 2;
348   int fieldnum;
349
350   /* loop over fields */
351   for (fieldnum = 0; fieldnum < fields_per_frame; fieldnum++)
343   for (int fieldnum = 0; fieldnum < fields_per_frame; fieldnum++)
352344   {
353      int yminval, ymaxval, cbminval, cbmaxval, crminval, crmaxval;
354      int field = frame * fields_per_frame + fieldnum;
355      int x, y, pixels, remaining;
356      UINT32 yhisto[256] = { 0 };
357      UINT32 crhisto[256] = { 0 };
358      UINT32 cbhisto[256] = { 0 };
359      vbi_metadata metadata;
360
361      /* output status */
345      // output status
362346      if (frame % 10 == 0 && fieldnum == 0)
363347         fprintf(stderr, "%6d.%d...\r", frame, fieldnum);
364348
365      /* parse the VBI data */
349      // parse the VBI data
350      vbi_metadata metadata;
366351      vbi_parse_all(&bitmap.pix16(fieldnum), bitmap.rowpixels() * 2, bitmap.width(), 8, &metadata);
367352
368      /* if we have data in both 17 and 18, it should match */
353      // if we have data in both 17 and 18, it should match
369354      if (metadata.line17 != 0 && metadata.line18 != 0 && metadata.line17 != metadata.line18)
370355      {
371356         printf("%6d.%d: line 17 and 18 data does not match (17=%06X 18=%06X) (WARNING)\n", frame, fieldnum, metadata.line17, metadata.line18);
372357         printf("%6d.%d: selected %06X based on bit confidence\n", frame, fieldnum, metadata.line1718);
373358      }
374359
375      /* is this a lead-in code? */
360      // is this a lead-in code?
376361      if (metadata.line1718 == VBI_CODE_LEADIN)
377362      {
378         /* if we haven't seen lead-in yet, detect it */
379         if (!video->saw_leadin)
363         // if we haven't seen lead-in yet, detect it
364         if (!video.saw_leadin)
380365         {
381            video->saw_leadin = TRUE;
366            video.saw_leadin = TRUE;
382367            printf("%6d.%d: lead-in code detected\n", frame, fieldnum);
383368         }
384369
385         /* if we've previously seen chapters/frames, that's weird */
386         if (video->last_frame != -1 || video->last_chapter != -1)
370         // if we've previously seen chapters/frames, that's weird
371         if (video.last_frame != -1 || video.last_chapter != -1)
387372            printf("%6d.%d: lead-in code detected after frame/chapter data (WARNING)\n", frame, fieldnum);
388373      }
389374
390      /* is this a lead-out code? */
375      // is this a lead-out code?
391376      if (metadata.line1718 == VBI_CODE_LEADOUT)
392377      {
393         /* if we haven't seen lead-in yet, detect it */
394         if (!video->saw_leadout)
378         // if we haven't seen lead-in yet, detect it
379         if (!video.saw_leadout)
395380         {
396            video->saw_leadout = TRUE;
381            video.saw_leadout = TRUE;
397382            printf("%6d.%d: lead-out code detected\n", frame, fieldnum);
398            if (video->last_frame != -1)
399               printf("%6d.%d: final frame number was %d\n", frame, fieldnum, video->last_frame);
383            if (video.last_frame != -1)
384               printf("%6d.%d: final frame number was %d\n", frame, fieldnum, video.last_frame);
400385            else
401386               printf("%6d.%d: never detected any frame numbers (ERROR)\n", frame, fieldnum);
402387         }
403388
404         /* if we've previously seen chapters/frames, that's weird */
405         if (video->last_frame == -1)
389         // if we've previously seen chapters/frames, that's weird
390         if (video.last_frame == -1)
406391            printf("%6d.%d: lead-out code detected with no frames detected beforehand (WARNING)\n", frame, fieldnum);
407392      }
408393
409      /* is this a frame code? */
394      // is this a frame code?
410395      if ((metadata.line1718 & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE)
411396      {
412397         int framenum = VBI_CAV_PICTURE(metadata.line1718);
413398
414         /* did we see any leadin? */
415         if (!video->saw_leadin)
399         // did we see any leadin?
400         if (!video.saw_leadin)
416401         {
417402            printf("%6d.%d: detected frame number but never saw any lead-in (WARNING)\n", frame, fieldnum);
418            video->saw_leadin = TRUE;
403            video.saw_leadin = TRUE;
419404         }
420405
421         /* if this is the first frame, make sure it's 1 */
422         if (video->last_frame == -1)
406         // if this is the first frame, make sure it's 1
407         if (video.last_frame == -1)
423408         {
424409            if (framenum == 0)
425410               printf("%6d.%d: detected frame 0\n", frame, fieldnum);
r14546r14547
429414               printf("%6d.%d: first frame number is not 0 or 1 (%d) (ERROR)\n", frame, fieldnum, framenum);
430415         }
431416
432         /* print an update every 10000 frames */
417         // print an update every 10000 frames
433418         if (framenum != 0 && framenum % 10000 == 0)
434419            printf("%6d.%d: detected frame %d\n", frame, fieldnum, framenum);
435420
436         /* if this frame is not consecutive, it's an error */
437         if (video->last_frame != -1 && framenum != video->last_frame + 1)
438            printf("%6d.%d: gap in frame number sequence (%d->%d) (ERROR)\n", frame, fieldnum, video->last_frame, framenum);
421         // if this frame is not consecutive, it's an error
422         if (video.last_frame != -1 && framenum != video.last_frame + 1)
423            printf("%6d.%d: gap in frame number sequence (%d->%d) (ERROR)\n", frame, fieldnum, video.last_frame, framenum);
439424
440         /* remember the frame number */
441         video->last_frame = framenum;
425         // remember the frame number
426         video.last_frame = framenum;
442427
443         /* if we've seen a white flag before, but it's not here, warn */
444         if (video->first_whitefield != -1 && !metadata.white)
428         // if we've seen a white flag before, but it's not here, warn
429         if (video.first_whitefield != -1 && !metadata.white)
445430            printf("%6d.%d: detected frame number but no white flag (WARNING)\n", frame, fieldnum);
446431      }
447432
448      /* is the whiteflag set? */
433      // is the whiteflag set?
434      int field = frame * fields_per_frame + fieldnum;
449435      if (metadata.white)
450436      {
451         /* if this is the first white flag we see, count it */
452         if (video->first_whitefield == -1)
437         // if this is the first white flag we see, count it
438         if (video.first_whitefield == -1)
453439         {
454            video->first_whitefield = field;
440            video.first_whitefield = field;
455441            printf("%6d.%d: first white flag seen\n", frame, fieldnum);
456442         }
457443
458         /* if we've seen frame numbers before, but not here, warn */
459         if (video->last_frame != -1 && (metadata.line1718 & VBI_MASK_CAV_PICTURE) != VBI_CODE_CAV_PICTURE)
444         // if we've seen frame numbers before, but not here, warn
445         if (video.last_frame != -1 && (metadata.line1718 & VBI_MASK_CAV_PICTURE) != VBI_CODE_CAV_PICTURE)
460446            printf("%6d.%d: detected white flag but no frame number (WARNING)\n", frame, fieldnum);
461447      }
462448
463      /* if this is the start of a frame, handle cadence */
449      // if this is the start of a frame, handle cadence
464450      if (metadata.white || (metadata.line1718 & VBI_MASK_CAV_PICTURE) == VBI_CODE_CAV_PICTURE)
465451      {
466         /* if we've seen frames, but we're not yet to the lead-out, check the cadence */
467         if (video->last_frame != -1 && !video->saw_leadout)
452         // if we've seen frames, but we're not yet to the lead-out, check the cadence
453         if (video.last_frame != -1 && !video.saw_leadout)
468454         {
469            /* make sure we have a proper history */
470            if (video->prev_whitefield != -1)
471               video->cadence_history = (video->cadence_history << 4) | ((field - video->prev_whitefield) & 0x0f);
472            video->prev_whitefield = field;
455            // make sure we have a proper history
456            if (video.prev_whitefield != -1)
457               video.cadence_history = (video.cadence_history << 4) | ((field - video.prev_whitefield) & 0x0f);
458            video.prev_whitefield = field;
473459
474            /* if we don't know our cadence yet, determine it */
475            if (video->cadence == -1 && (video->cadence_history & 0xf00) != 0)
460            // if we don't know our cadence yet, determine it
461            if (video.cadence == -1 && (video.cadence_history & 0xf00) != 0)
476462            {
477               if ((video->cadence_history & 0xfff) == 0x222)
463               if ((video.cadence_history & 0xfff) == 0x222)
478464               {
479465                  printf("%6d.%d: detected 2:2 cadence\n", frame, fieldnum);
480                  video->cadence = 4;
466                  video.cadence = 4;
481467               }
482               else if ((video->cadence_history & 0xfff) == 0x323)
468               else if ((video.cadence_history & 0xfff) == 0x323)
483469               {
484470                  printf("%6d.%d: detected 3:2 cadence\n", frame, fieldnum);
485                  video->cadence = 5;
471                  video.cadence = 5;
486472               }
487               else if ((video->cadence_history & 0xfff) == 0x232)
473               else if ((video.cadence_history & 0xfff) == 0x232)
488474               {
489475                  printf("%6d.%d: detected 2:3 cadence\n", frame, fieldnum);
490                  video->cadence = 5;
476                  video.cadence = 5;
491477               }
492478               else
493479               {
494480                  printf("%6d.%d: unknown cadence (history %d:%d:%d) (WARNING)\n", frame, fieldnum,
495                        (video->cadence_history >> 8) & 15, (video->cadence_history >> 4) & 15, video->cadence_history & 15);
481                        (video.cadence_history >> 8) & 15, (video.cadence_history >> 4) & 15, video.cadence_history & 15);
496482               }
497483            }
498484
499            /* if we know our cadence, make sure we stick to it */
500            if (video->cadence != -1)
485            // if we know our cadence, make sure we stick to it
486            if (video.cadence != -1)
501487            {
502               if (video->cadence == 4 && (video->cadence_history & 0xfff) != 0x222)
488               if (video.cadence == 4 && (video.cadence_history & 0xfff) != 0x222)
503489               {
504490                  printf("%6d.%d: missed cadence (history %d:%d:%d) (WARNING)\n", frame, fieldnum,
505                        (video->cadence_history >> 8) & 15, (video->cadence_history >> 4) & 15, video->cadence_history & 15);
506                  video->cadence = -1;
507                  video->cadence_history = 0;
491                        (video.cadence_history >> 8) & 15, (video.cadence_history >> 4) & 15, video.cadence_history & 15);
492                  video.cadence = -1;
493                  video.cadence_history = 0;
508494               }
509               else if (video->cadence == 5 && (video->cadence_history & 0xfff) != 0x323 && (video->cadence_history & 0xfff) != 0x232)
495               else if (video.cadence == 5 && (video.cadence_history & 0xfff) != 0x323 && (video.cadence_history & 0xfff) != 0x232)
510496               {
511497                  printf("%6d.%d: missed cadence (history %d:%d:%d) (WARNING)\n", frame, fieldnum,
512                        (video->cadence_history >> 8) & 15, (video->cadence_history >> 4) & 15, video->cadence_history & 15);
513                  video->cadence = -1;
514                  video->cadence_history = 0;
498                        (video.cadence_history >> 8) & 15, (video.cadence_history >> 4) & 15, video.cadence_history & 15);
499                  video.cadence = -1;
500                  video.cadence_history = 0;
515501               }
516502            }
517503         }
518504      }
519505
520      /* now examine the active video signal */
521      pixels = 0;
522      for (y = 22*2 + fieldnum; y < bitmap.height(); y += 2)
506      // now examine the active video signal
507      UINT32 yhisto[256] = { 0 };
508      UINT32 crhisto[256] = { 0 };
509      UINT32 cbhisto[256] = { 0 };
510      int pixels = 0;
511      for (int y = 22*2 + fieldnum; y < bitmap.height(); y += 2)
523512      {
524         for (x = 16; x < 720 - 16; x++)
513         for (int x = 16; x < 720 - 16; x++)
525514         {
526515            yhisto[bitmap.pix16(y, x) >> 8]++;
527516            if (x % 2 == 0)
r14546r14547
532521         pixels += 720 - 16 - 16;
533522      }
534523
535      /* remove the top/bottom 0.1% of Y */
536      remaining = pixels / 1000;
524      // remove the top/bottom 0.1% of Y
525      int remaining = pixels / 1000;
526      int yminval;
537527      for (yminval = 0; (remaining -= yhisto[yminval]) >= 0; yminval++) ;
538528      remaining = pixels / 1000;
529      int ymaxval;
539530      for (ymaxval = 255; (remaining -= yhisto[ymaxval]) >= 0; ymaxval--) ;
540531
541      /* remove the top/bottom 0.1% of Cb */
532      // remove the top/bottom 0.1% of Cb
542533      remaining = pixels / 500;
534      int cbminval;
543535      for (cbminval = 0; (remaining -= cbhisto[cbminval]) >= 0; cbminval++) ;
544536      remaining = pixels / 500;
537      int cbmaxval;
545538      for (cbmaxval = 255; (remaining -= cbhisto[cbmaxval]) >= 0; cbmaxval--) ;
546539
547      /* remove the top/bottom 0.1% of Cr */
540      // remove the top/bottom 0.1% of Cr
548541      remaining = pixels / 500;
542      int crminval;
549543      for (crminval = 0; (remaining -= crhisto[crminval]) >= 0; crminval++) ;
550544      remaining = pixels / 500;
545      int crmaxval;
551546      for (crmaxval = 255; (remaining -= crhisto[crmaxval]) >= 0; crmaxval--) ;
552547
553      /* track blank frames */
548      // track blank frames
554549      if (ymaxval - yminval < 10 && cbmaxval - cbminval < 10 && crmaxval - cbmaxval < 10)
555550      {
556         if (video->first_blank_frame == -1)
551         if (video.first_blank_frame == -1)
557552         {
558            video->first_blank_frame = frame;
559            video->first_blank_field = fieldnum;
560            video->num_blank_fields = 0;
553            video.first_blank_frame = frame;
554            video.first_blank_field = fieldnum;
555            video.num_blank_fields = 0;
561556         }
562         video->num_blank_fields++;
557         video.num_blank_fields++;
563558      }
564      else if (video->num_blank_fields > 0)
559      else if (video.num_blank_fields > 0)
565560      {
566         if (video->num_blank_fields >= REPORT_BLANKS_THRESHOLD)
567            printf("%6d.%d-%6d.%d: blank frames for %d fields (INFO)\n", video->first_blank_frame, video->first_blank_field, frame, fieldnum, video->num_blank_fields);
568         video->first_blank_frame = video->first_blank_field = video->num_blank_fields = -1;
561         if (video.num_blank_fields >= REPORT_BLANKS_THRESHOLD)
562            printf("%6d.%d-%6d.%d: blank frames for %d fields (INFO)\n", video.first_blank_frame, video.first_blank_field, frame, fieldnum, video.num_blank_fields);
563         video.first_blank_frame = video.first_blank_field = video.num_blank_fields = -1;
569564      }
570565
571      /* update the overall min/max */
572      video->min_overall = MIN(yminval, video->min_overall);
573      video->max_overall = MAX(ymaxval, video->max_overall);
566      // update the overall min/max
567      video.min_overall = MIN(yminval, video.min_overall);
568      video.max_overall = MAX(ymaxval, video.max_overall);
574569
575      /* track low fields */
570      // track low fields
576571      if (yminval <= 0)
577572      {
578         if (video->first_low_frame == -1)
573         if (video.first_low_frame == -1)
579574         {
580            video->first_low_frame = frame;
581            video->first_low_field = fieldnum;
582            video->num_low_fields = 0;
575            video.first_low_frame = frame;
576            video.first_low_field = fieldnum;
577            video.num_low_fields = 0;
583578         }
584         video->num_low_fields++;
579         video.num_low_fields++;
585580      }
586      else if (video->num_low_fields > 0)
581      else if (video.num_low_fields > 0)
587582      {
588         printf("%6d.%d-%6d.%d: active video signal level low for %d fields (WARNING)\n", video->first_low_frame, video->first_low_field, frame, fieldnum, video->num_low_fields);
589         video->first_low_frame = video->first_low_field = video->num_low_fields = -1;
583         printf("%6d.%d-%6d.%d: active video signal level low for %d fields (WARNING)\n", video.first_low_frame, video.first_low_field, frame, fieldnum, video.num_low_fields);
584         video.first_low_frame = video.first_low_field = video.num_low_fields = -1;
590585      }
591586
592      /* track high fields */
587      // track high fields
593588      if (ymaxval >= 255)
594589      {
595         if (video->first_high_frame == -1)
590         if (video.first_high_frame == -1)
596591         {
597            video->first_high_frame = frame;
598            video->first_high_field = fieldnum;
599            video->num_high_fields = 0;
592            video.first_high_frame = frame;
593            video.first_high_field = fieldnum;
594            video.num_high_fields = 0;
600595         }
601         video->num_high_fields++;
596         video.num_high_fields++;
602597      }
603      else if (video->num_high_fields > 0)
598      else if (video.num_high_fields > 0)
604599      {
605         printf("%6d.%d-%6d.%d: active video signal level high for %d fields (WARNING)\n", video->first_high_frame, video->first_high_field, frame, fieldnum, video->num_high_fields);
606         video->first_high_frame = video->first_high_field = video->num_high_fields = -1;
600         printf("%6d.%d-%6d.%d: active video signal level high for %d fields (WARNING)\n", video.first_high_frame, video.first_high_field, frame, fieldnum, video.num_high_fields);
601         video.first_high_frame = video.first_high_field = video.num_high_fields = -1;
607602      }
608603   }
609604}
610605
611606
612/*-------------------------------------------------
613    verify_video_final - final verification
614-------------------------------------------------*/
607//-------------------------------------------------
608//  verify_video_final - final verification
609//-------------------------------------------------
615610
616static void verify_video_final(video_info *video, int frame, bitmap_yuy16 &bitmap)
611static void verify_video_final(video_info &video, int frame, bitmap_yuy16 &bitmap)
617612{
618613   int fields_per_frame = (bitmap.height() >= 288) ? 2 : 1;
619614   int field = frame * fields_per_frame;
620615
621   /* did we ever see any white flags? */
622   if (video->first_whitefield == -1)
616   // did we ever see any white flags?
617   if (video.first_whitefield == -1)
623618      printf("Track %6d.%d: never saw any white flags (WARNING)\n", field / fields_per_frame, 0);
624619
625   /* did we ever see any lead-out? */
626   if (!video->saw_leadout)
620   // did we ever see any lead-out?
621   if (!video.saw_leadout)
627622      printf("Track %6d.%d: never saw any lead-out (WARNING)\n", field / fields_per_frame, 0);
628623
629   /* any remaining high/low reports? */
630   if (video->num_blank_fields >= REPORT_BLANKS_THRESHOLD)
631      printf("%6d.%d-%6d.%d: blank frames for %d fields (INFO)\n", video->first_blank_frame, video->first_blank_field, frame, 0, video->num_blank_fields);
632   if (video->num_low_fields > 0)
633      printf("%6d.%d-%6d.%d: active video signal level low for %d fields (WARNING)\n", video->first_low_frame, video->first_low_field, frame, 0, video->num_low_fields);
634   if (video->num_high_fields > 0)
635      printf("%6d.%d-%6d.%d: active video signal level high for %d fields (WARNING)\n", video->first_high_frame, video->first_high_field, frame, 0, video->num_high_fields);
624   // any remaining high/low reports?
625   if (video.num_blank_fields >= REPORT_BLANKS_THRESHOLD)
626      printf("%6d.%d-%6d.%d: blank frames for %d fields (INFO)\n", video.first_blank_frame, video.first_blank_field, frame, 0, video.num_blank_fields);
627   if (video.num_low_fields > 0)
628      printf("%6d.%d-%6d.%d: active video signal level low for %d fields (WARNING)\n", video.first_low_frame, video.first_low_field, frame, 0, video.num_low_fields);
629   if (video.num_high_fields > 0)
630      printf("%6d.%d-%6d.%d: active video signal level high for %d fields (WARNING)\n", video.first_high_frame, video.first_high_field, frame, 0, video.num_high_fields);
636631
637   /* summary info */
632   // summary info
638633   printf("\nVideo summary:\n");
639   printf("  Overall video range: %d-%d (%02X-%02X)\n", video->min_overall, video->max_overall, video->min_overall, video->max_overall);
634   printf("  Overall video range: %d-%d (%02X-%02X)\n", video.min_overall, video.max_overall, video.min_overall, video.max_overall);
640635}
641636
642637
643/*-------------------------------------------------
644    init_audio - init audio info structure
645-------------------------------------------------*/
638//-------------------------------------------------
639//  init_audio - init audio info structure
640//-------------------------------------------------
646641
647static void init_audio(audio_info *audio)
642static void init_audio(audio_info &audio)
648643{
649   audio->min_lsample = 32767;
650   audio->min_rsample = 32767;
651   audio->max_lsample = -32768;
652   audio->max_rsample = -32768;
653   audio->min_lsample_count = 0;
654   audio->min_rsample_count = 0;
655   audio->max_lsample_count = 0;
656   audio->max_rsample_count = 0;
657   audio->sample_count = 0;
644   audio.min_lsample = 32767;
645   audio.min_rsample = 32767;
646   audio.max_lsample = -32768;
647   audio.max_rsample = -32768;
648   audio.min_lsample_count = 0;
649   audio.min_rsample_count = 0;
650   audio.max_lsample_count = 0;
651   audio.max_rsample_count = 0;
652   audio.sample_count = 0;
658653}
659654
660655
661/*-------------------------------------------------
662    verify_audio - verify audio data
663-------------------------------------------------*/
656//-------------------------------------------------
657//  verify_audio - verify audio data
658//-------------------------------------------------
664659
665static void verify_audio(audio_info *audio, const INT16 *lsound, const INT16 *rsound, int samples)
660static void verify_audio(audio_info &audio, const INT16 *lsound, const INT16 *rsound, int samples)
666661{
667   int sampnum;
662   // count the overall samples
663   audio.sample_count += samples;
668664
669   /* count the overall samples */
670   audio->sample_count += samples;
671
672   /* iterate over samples, tracking min/max */
673   for (sampnum = 0; sampnum < samples; sampnum++)
665   // iterate over samples, tracking min/max
666   for (int sampnum = 0; sampnum < samples; sampnum++)
674667   {
675      /* did we hit a minimum on the left? */
676      if (lsound[sampnum] < audio->min_lsample)
668      // did we hit a minimum on the left?
669      if (lsound[sampnum] < audio.min_lsample)
677670      {
678         audio->min_lsample = lsound[sampnum];
679         audio->min_lsample_count = 1;
671         audio.min_lsample = lsound[sampnum];
672         audio.min_lsample_count = 1;
680673      }
681      else if (lsound[sampnum] == audio->min_lsample)
682         audio->min_lsample_count++;
674      else if (lsound[sampnum] == audio.min_lsample)
675         audio.min_lsample_count++;
683676
684      /* did we hit a maximum on the left? */
685      if (lsound[sampnum] > audio->max_lsample)
677      // did we hit a maximum on the left?
678      if (lsound[sampnum] > audio.max_lsample)
686679      {
687         audio->max_lsample = lsound[sampnum];
688         audio->max_lsample_count = 1;
680         audio.max_lsample = lsound[sampnum];
681         audio.max_lsample_count = 1;
689682      }
690      else if (lsound[sampnum] == audio->max_lsample)
691         audio->max_lsample_count++;
683      else if (lsound[sampnum] == audio.max_lsample)
684         audio.max_lsample_count++;
692685
693      /* did we hit a minimum on the right? */
694      if (rsound[sampnum] < audio->min_rsample)
686      // did we hit a minimum on the right?
687      if (rsound[sampnum] < audio.min_rsample)
695688      {
696         audio->min_rsample = rsound[sampnum];
697         audio->min_rsample_count = 1;
689         audio.min_rsample = rsound[sampnum];
690         audio.min_rsample_count = 1;
698691      }
699      else if (rsound[sampnum] == audio->min_rsample)
700         audio->min_rsample_count++;
692      else if (rsound[sampnum] == audio.min_rsample)
693         audio.min_rsample_count++;
701694
702      /* did we hit a maximum on the right? */
703      if (rsound[sampnum] > audio->max_rsample)
695      // did we hit a maximum on the right?
696      if (rsound[sampnum] > audio.max_rsample)
704697      {
705         audio->max_rsample = rsound[sampnum];
706         audio->max_rsample_count = 1;
698         audio.max_rsample = rsound[sampnum];
699         audio.max_rsample_count = 1;
707700      }
708      else if (rsound[sampnum] == audio->max_rsample)
709         audio->max_rsample_count++;
701      else if (rsound[sampnum] == audio.max_rsample)
702         audio.max_rsample_count++;
710703   }
711704}
712705
713706
714/*-------------------------------------------------
715    verify_audio_final - final verification
716-------------------------------------------------*/
707//-------------------------------------------------
708//  verify_audio_final - final verification
709//-------------------------------------------------
717710
718static void verify_audio_final(audio_info *audio)
711static void verify_audio_final(audio_info &audio)
719712{
720713   printf("\nAudio summary:\n");
721   printf("  Overall channel 0 range: %d-%d (%04X-%04X)\n", audio->min_lsample, audio->max_lsample, (UINT16)audio->min_lsample, (UINT16)audio->max_lsample);
722   printf("  Overall channel 1 range: %d-%d (%04X-%04X)\n", audio->min_rsample, audio->max_rsample, (UINT16)audio->min_rsample, (UINT16)audio->max_rsample);
714   printf("  Overall channel 0 range: %d-%d (%04X-%04X)\n", audio.min_lsample, audio.max_lsample, UINT16(audio.min_lsample), UINT16(audio.max_lsample));
715   printf("  Overall channel 1 range: %d-%d (%04X-%04X)\n", audio.min_rsample, audio.max_rsample, UINT16(audio.min_rsample), UINT16(audio.max_rsample));
723716}
724717
725718
726/*-------------------------------------------------
727    usage - display program usage
728-------------------------------------------------*/
719//-------------------------------------------------
720//  usage - display program usage
721//-------------------------------------------------
729722
730723static int usage(void)
731724{
r14546r14547
735728}
736729
737730
738/*-------------------------------------------------
739    main - main entry point
740-------------------------------------------------*/
731//-------------------------------------------------
732//  main - main entry point
733//-------------------------------------------------
741734
742735int main(int argc, char *argv[])
743736{
744737   try
745738   {
746      movie_info info = { 0 };
747      INT16 *lsound, *rsound;
748      const char *srcfile;
749      bitmap_yuy16 bitmap;
750      int srcfilelen;
751      int samples = 0;
752      void *file;
753      int isavi;
754      int frame;
739      // init globals
755740      audio_info audio;
741      init_audio(audio);
756742      video_info video;
743      init_video(video);
757744
758      /* init globals */
759      init_audio(&audio);
760      init_video(&video);
761
762      /* verify arguments */
745      // verify arguments
763746      if (argc < 2)
764747         return usage();
765      srcfile = argv[1];
748      const char *srcfile = argv[1];
766749
767      /* check extension of file */
768      srcfilelen = strlen(srcfile);
750      // check extension of file
751      int srcfilelen = strlen(srcfile);
769752      if (srcfilelen < 4)
770753         return usage();
754      bool isavi;
771755      if (tolower((UINT8)srcfile[srcfilelen-3]) == 'a' && tolower((UINT8)srcfile[srcfilelen-2]) == 'v' && tolower((UINT8)srcfile[srcfilelen-1]) == 'i')
772         isavi = TRUE;
756         isavi = true;
773757      else if (tolower((UINT8)srcfile[srcfilelen-3]) == 'c' && tolower((UINT8)srcfile[srcfilelen-2]) == 'h' && tolower((UINT8)srcfile[srcfilelen-1]) == 'd')
774         isavi = FALSE;
758         isavi = false;
775759      else
776760         return usage();
777761
778      /* open the file */
762      // open the file
779763      printf("Processing file: %s\n", srcfile);
780      file = isavi ? open_avi(srcfile, &info) : open_chd(srcfile, &info);
764      movie_info info = { 0 };
765      void *file = isavi ? open_avi(srcfile, info) : open_chd(srcfile, info);
781766      if (file == NULL)
782767      {
783768         fprintf(stderr, "Unable to open file '%s'\n", srcfile);
784769         return 1;
785770      }
786771
787      /* comment on the video dimensions */
772      // comment on the video dimensions
788773      printf("Video dimensions: %dx%d\n", info.width, info.height);
789774      if (info.width != 720)
790775         printf("WARNING: Unexpected video width (should be 720)\n");
791776      if (info.height != 524)
792777         printf("WARNING: Unexpected video height (should be 262 or 524)\n");
793778
794      /* comment on the video frame rate */
779      // comment on the video frame rate
795780      printf("Video frame rate: %.2fHz\n", info.framerate);
796      if ((int)(info.framerate * 100.0 + 0.5) != 2997)
781      if (int(info.framerate * 100.0 + 0.5) != 2997)
797782         printf("WARNING: Unexpected frame rate (should be 29.97Hz)\n");
798783
799      /* comment on the sample rate */
784      // comment on the sample rate
800785      printf("Sample rate: %dHz\n", info.samplerate);
801786      if (info.samplerate != 48000)
802787         printf("WARNING: Unexpected sampele rate (should be 48000Hz)\n");
803788
804      /* allocate a bitmap */
805      bitmap.allocate(info.width, info.height);
789      // allocate a bitmap
790      bitmap_yuy16 bitmap(info.width, info.height);
806791
807      /* allocate sound buffers */
808      lsound = (INT16 *)malloc(info.samplerate * sizeof(*lsound));
809      rsound = (INT16 *)malloc(info.samplerate * sizeof(*rsound));
810      if (lsound == NULL || rsound == NULL)
811      {
812         isavi ? close_avi(file) : close_chd(file);
813         if (rsound != NULL)
814            free(rsound);
815         if (lsound != NULL)
816            free(lsound);
817         fprintf(stderr, "Out of memory allocating sound buffers of %d bytes\n", (INT32)(info.samplerate * sizeof(*rsound)));
818         return 1;
819      }
792      // allocate sound buffers
793      dynamic_array<INT16> lsound(info.samplerate);
794      dynamic_array<INT16> rsound(info.samplerate);
820795
821      /* loop over frames */
822      frame = 0;
823      while (isavi ? read_avi(file, frame, bitmap, lsound, rsound, &samples) : read_chd(file, frame, bitmap, lsound, rsound, &samples))
796      // loop over frames
797      int frame = 0;
798      int samples = 0;
799      while (isavi ? read_avi(file, frame, bitmap, lsound, rsound, samples) : read_chd(file, frame, bitmap, lsound, rsound, samples))
824800      {
825         verify_video(&video, frame, bitmap);
826         verify_audio(&audio, lsound, rsound, samples);
801         verify_video(video, frame, bitmap);
802         verify_audio(audio, lsound, rsound, samples);
827803         frame++;
828804      }
829805
830      /* close the files */
806      // close the files
831807      isavi ? close_avi(file) : close_chd(file);
832808
833      /* final output */
834      verify_video_final(&video, frame, bitmap);
835      verify_audio_final(&audio);
836
837      /* free memory */
838      free(lsound);
839      free(rsound);
809      // final output
810      verify_video_final(video, frame, bitmap);
811      verify_audio_final(audio);
840812   }
841813   catch (std::bad_alloc &)
842814   {
src/tools/tools.mak
r14546r14547
124124LDRESAMPLEOBJS = \
125125   $(TOOLSOBJ)/ldresample.o \
126126
127ldresample$(EXE): $(LDRESAMPLEOBJS) $(LIBUTIL) $(LIBOCORE) $(ZLIB) $(FLAC_LIB) $(EXPAT)
127ldresample$(EXE): $(LDRESAMPLEOBJS) $(LIBUTIL) $(LIBOCORE) $(ZLIB) $(FLAC_LIB) $(7Z_LIB) $(EXPAT)
128128   @echo Linking $@...
129129   $(LD) $(LDFLAGS) $^ $(LIBS) $(FLAC_LIB) -o $@
130130
r14546r14547
137137LDVERIFYOBJS = \
138138   $(TOOLSOBJ)/ldverify.o \
139139
140ldverify$(EXE): $(LDVERIFYOBJS) $(LIBUTIL) $(LIBOCORE) $(ZLIB) $(FLAC_LIB) $(EXPAT)
140ldverify$(EXE): $(LDVERIFYOBJS) $(LIBUTIL) $(LIBOCORE) $(ZLIB) $(FLAC_LIB) $(7Z_LIB) $(EXPAT)
141141   @echo Linking $@...
142142   $(LD) $(LDFLAGS) $^ $(LIBS) $(FLAC_LIB) -o $@
143143
src/tools/ldresample.c
r14546r14547
4444#include <new>
4545#include "bitmap.h"
4646#include "chd.h"
47#include "avhuff.h"
4748#include "vbiparse.h"
4849
4950
5051
51/***************************************************************************
52    CONSTANTS
53***************************************************************************/
52//**************************************************************************
53//  CONSTANTS
54//**************************************************************************
5455
55/* size of window where we scan ahead to find maximum; this should be large enough to
56   catch peaks of even slow waves */
57#define MAXIMUM_WINDOW_SIZE      40
56// size of window where we scan ahead to find maximum; this should be large enough to
57// catch peaks of even slow waves
58const UINT32 MAXIMUM_WINDOW_SIZE = 40;
5859
59/* number of standard deviations away from silence that we consider a real signal */
60#define SIGNAL_DEVIATIONS      100
60// number of standard deviations away from silence that we consider a real signal
61const UINT32 SIGNAL_DEVIATIONS = 100;
6162
62/* number of standard deviations away from silence that we consider the start of a signal */
63#define SIGNAL_START_DEVIATIONS   5
63// number of standard deviations away from silence that we consider the start of a signal
64const UINT32 SIGNAL_START_DEVIATIONS = 5;
6465
65/* number of consecutive entries of signal before we consider that we found it */
66#define MINIMUM_SIGNAL_COUNT   20
66// number of consecutive entries of signal before we consider that we found it
67const UINT32 MINIMUM_SIGNAL_COUNT = 20;
6768
6869
6970
70/***************************************************************************
71    TYPE DEFINITIONS
72***************************************************************************/
71//**************************************************************************
72//  TYPE DEFINITIONS
73//**************************************************************************
7374
74typedef struct _movie_info movie_info;
75struct _movie_info
75struct movie_info
7676{
77   double      framerate;
78   int         iframerate;
79   int         numfields;
80   int         width;
81   int         height;
82   int         samplerate;
83   int         channels;
84   int         interlaced;
85   bitmap_yuy16 bitmap;
77   double         framerate;
78   int            iframerate;
79   int            numfields;
80   int            width;
81   int            height;
82   int            samplerate;
83   int            channels;
84   int            interlaced;
85   bitmap_yuy16    bitmap;
8686   dynamic_array<INT16> lsound;
8787   dynamic_array<INT16> rsound;
88   UINT32      samples;
88   UINT32         samples;
8989};
9090
9191
92// ======================> chd_resample_compressor
9293
93/***************************************************************************
94    GLOBAL VARIABLES
95***************************************************************************/
94class chd_resample_compressor : public chd_file_compressor
95{
96public:
97   // construction/destruction
98   chd_resample_compressor(chd_file &source, movie_info &info, INT64 ioffset, INT64 islope)
99      : m_source(source),
100        m_info(info),
101        m_ioffset(ioffset),
102        m_islope(islope) { }
96103
104   // read interface
105   virtual UINT32 read_data(void *_dest, UINT64 offset, UINT32 length)
106   {
107      assert(offset % m_source.hunk_bytes() == 0);
108      assert(length % m_source.hunk_bytes() == 0);
109     
110      UINT32 startfield = offset / m_source.hunk_bytes();
111      UINT32 endfield = startfield + length / m_source.hunk_bytes();
112      UINT8 *dest = reinterpret_cast<UINT8 *>(_dest);
97113
114      for (UINT32 fieldnum = startfield; fieldnum < endfield; fieldnum++)
115      {
116         generate_one_frame(dest, m_source.hunk_bytes(), fieldnum);
117         dest += m_source.hunk_bytes();
118      }
119      return length;
120   }
98121
99/***************************************************************************
100    INLINE FUNCTIONS
101***************************************************************************/
122private:
123   // internal helpers
124   void generate_one_frame(UINT8 *dest, UINT32 datasize, UINT32 fieldnum);
102125
103/*-------------------------------------------------
104    field_to_sample_number - given a field number
105    compute the absolute sample number for the
106    first sample of that field
107-------------------------------------------------*/
126   // internal state
127   chd_file &               m_source;
128   movie_info &            m_info;
129   INT64                  m_ioffset;
130   INT64                  m_islope;
131};
108132
109INLINE UINT32 field_to_sample_number(const movie_info *info, UINT32 field)
133
134
135//**************************************************************************
136//  INLINE FUNCTIONS
137//**************************************************************************
138
139//-------------------------------------------------
140//  field_to_sample_number - given a field number
141//  compute the absolute sample number for the
142//  first sample of that field
143//-------------------------------------------------
144
145inline UINT32 field_to_sample_number(const movie_info &info, UINT32 field)
110146{
111   return ((UINT64)info->samplerate * (UINT64)field * (UINT64)1000000 + info->iframerate - 1) / (UINT64)info->iframerate;
147   return (UINT64(info.samplerate) * UINT64(field) * UINT64(1000000) + info.iframerate - 1) / UINT64(info.iframerate);
112148}
113149
114150
115/*-------------------------------------------------
116    sample_number_to_field - given a sample number
117    compute the field where it is located and
118    the offset within the field
119-------------------------------------------------*/
151//-------------------------------------------------
152//  sample_number_to_field - given a sample number
153//  compute the field where it is located and
154//  the offset within the field
155//-------------------------------------------------
120156
121INLINE UINT32 sample_number_to_field(const movie_info *info, UINT32 samplenum, UINT32 *offset)
157inline UINT32 sample_number_to_field(const movie_info &info, UINT32 samplenum, UINT32 &offset)
122158{
123   UINT32 guess = ((UINT64)samplenum * (UINT64)info->iframerate + ((UINT64)info->samplerate * (UINT64)1000000 - 1)) / ((UINT64)info->samplerate * (UINT64)1000000);
159   UINT32 guess = (UINT64(samplenum) * UINT64(info.iframerate) + (UINT64(info.samplerate) * UINT64(1000000) - 1)) / (UINT64(info.samplerate) * UINT64(1000000));
124160   while (1)
125161   {
126162      UINT32 fieldstart = field_to_sample_number(info, guess);
127163      UINT32 fieldend = field_to_sample_number(info, guess + 1);
128164      if (samplenum >= fieldstart && samplenum < fieldend)
129165      {
130         *offset = samplenum - fieldstart;
166         offset = samplenum - fieldstart;
131167         return guess;
132168      }
133169      else if (samplenum < fieldstart)
r14546r14547
139175
140176
141177
142/***************************************************************************
143    CHD HANDLING
144***************************************************************************/
178//**************************************************************************
179//  CHD HANDLING
180//**************************************************************************
145181
146/*-------------------------------------------------
147    open_chd - open a CHD file and return
148    information about it
149-------------------------------------------------*/
182//-------------------------------------------------
183//  open_chd - open a CHD file and return
184//  information about it
185//-------------------------------------------------
150186
151187static chd_error open_chd(chd_file &file, const char *filename, movie_info &info)
152188{
153   /* open the file */
189   // open the file
154190   chd_error chderr = file.open(filename);
155191   if (chderr != CHDERR_NONE)
156192   {
157      fprintf(stderr, "Error opening CHD file: %s\n", chd_error_string(chderr));
193      fprintf(stderr, "Error opening CHD file: %s\n", chd_file::error_string(chderr));
158194      return chderr;
159195   }
160196
161   /* get the metadata */
197   // get the metadata
162198   astring metadata;
163   chderr = chd.read_metadata(chd, AV_METADATA_TAG, 0, metadata);
199   chderr = file.read_metadata(AV_METADATA_TAG, 0, metadata);
164200   if (chderr != CHDERR_NONE)
165201   {
166      fprintf(stderr, "Error getting A/V metadata: %s\n", chd_error_string(chderr));
202      fprintf(stderr, "Error getting A/V metadata: %s\n", chd_file::error_string(chderr));
167203      return chderr;
168204   }
169205
170   /* extract the info */
206   // extract the info
171207   int fps, fpsfrac, width, height, interlaced, channels, rate;
172208   if (sscanf(metadata, AV_METADATA_FORMAT, &fps, &fpsfrac, &width, &height, &interlaced, &channels, &rate) != 7)
173209   {
r14546r14547
175211      return CHDERR_INVALID_DATA;
176212   }
177213
178   /* extract movie info */
214   // extract movie info
179215   info.iframerate = fps * 1000000 + fpsfrac;
180216   info.framerate = info.iframerate / 1000000.0;
181   info.numfields = file->hunk_count();
217   info.numfields = file.hunk_count();
182218   info.width = width;
183219   info.height = height;
184220   info.interlaced = interlaced;
185221   info.samplerate = rate;
186222   info.channels = channels;
187223
188   /* allocate buffers */
224   // allocate buffers
189225   info.bitmap.resize(info.width, info.height);
190226   info.lsound.resize(info.samplerate);
191227   info.rsound.resize(info.samplerate);
r14546r14547
193229}
194230
195231
196/*-------------------------------------------------
197    create_chd - create a new CHD file
198-------------------------------------------------*/
232//-------------------------------------------------
233//  create_chd - create a new CHD file
234//-------------------------------------------------
199235
200static chd_error create_chd(chd_compressor &file, const char *filename, chd_file &source, const movie_info &info)
236static chd_error create_chd(chd_file_compressor &file, const char *filename, chd_file &source, const movie_info &info)
201237{
202   /* create the file */
203   chd_codec_type compression = { CHD_CODEC_AVHUFF };
238   // create the file
239   chd_codec_type compression[4] = { CHD_CODEC_AVHUFF };
204240   chd_error chderr = file.create(filename, source.logical_bytes(), source.hunk_bytes(), source.unit_bytes(), compression);
205241   if (chderr != CHDERR_NONE)
206242   {
207      fprintf(stderr, "Error creating new CHD file: %s\n", chd_error_string(chderr));
243      fprintf(stderr, "Error creating new CHD file: %s\n", chd_file::error_string(chderr));
208244      return chderr;
209245   }
210246
211   /* clone the metadata */
247   // clone the metadata
212248   chderr = file.clone_all_metadata(source);
213249   if (chderr != CHDERR_NONE)
214250   {
215      fprintf(stderr, "Error cloning metadata: %s\n", chd_error_string(chderr));
251      fprintf(stderr, "Error cloning metadata: %s\n", chd_file::error_string(chderr));
216252      return chderr;
217253   }
218254
219   /* begin compressing */
220   chderr = file.compress_begin();
221   if (chderr != CHDERR_NONE)
222   {
223      fprintf(stderr, "Error beginning compression: %s\n", chd_error_string(chderr));
224      return chderr;
225   }
226
255   // begin compressing
256   file.compress_begin();
227257   return CHDERR_NONE;
228258}
229259
230260
231/*-------------------------------------------------
232    read_chd - read a field from a CHD file
233-------------------------------------------------*/
261//-------------------------------------------------
262//  read_chd - read a field from a CHD file
263//-------------------------------------------------
234264
235static int read_chd(chd_file *file, UINT32 field, movie_info *info, UINT32 soundoffs)
265static bool read_chd(chd_file &file, UINT32 field, movie_info &info, UINT32 soundoffs)
236266{
237   av_codec_decompress_config avconfig;
238   chd_error chderr;
267   // configure the codec
268   avhuff_decompress_config avconfig;
269   avconfig.video.wrap(info.bitmap, info.bitmap.cliprect());
270   avconfig.maxsamples = info.lsound.count();
271   avconfig.actsamples = &info.samples;
272   avconfig.audio[0] = info.lsound + soundoffs;
273   avconfig.audio[1] = info.rsound + soundoffs;
239274
240   /* configure the codec */
241   avconfig.video.wrap(*info->bitmap, info->bitmap->cliprect());
242   avconfig.maxsamples = 48000;
243   avconfig.actsamples = &info->samples;
244   avconfig.audio[0] = info->lsound + soundoffs;
245   avconfig.audio[1] = info->rsound + soundoffs;
275   // configure the decompressor for this field
276   file.codec_configure(CHD_CODEC_AVHUFF, AVHUFF_CODEC_DECOMPRESS_CONFIG, &avconfig);
246277
247   /* configure the decompressor for this field */
248   chd_codec_config(file, AV_CODEC_DECOMPRESS_CONFIG, &avconfig);
249
250   /* read the field */
251   chderr = chd_read(file, field, NULL);
252   if (chderr != CHDERR_NONE)
253      return FALSE;
254
255   return TRUE;
278   // read the field
279   chd_error chderr = file.read_hunk(field, NULL);
280   return (chderr == CHDERR_NONE);
256281}
257282
258283
259/*-------------------------------------------------
260    write_chd - write a field to a CHD file
261-------------------------------------------------*/
262284
263static int write_chd(chd_file *file, UINT32 field, movie_info *info)
264{
265   av_codec_compress_config avconfig;
266   chd_error chderr;
285//**************************************************************************
286//  CORE IMPLEMENTATION
287//**************************************************************************
267288
268   /* configure the codec */
269   avconfig.video.wrap(*info->bitmap, info->bitmap->cliprect());
270   avconfig.channels = 2;
271   avconfig.samples = info->samples;
272   avconfig.audio[0] = info->lsound;
273   avconfig.audio[1] = info->rsound;
289//-------------------------------------------------
290//  find_edge_near_field - given a field number,
291//  load +/- 1/2 second on either side and find
292//  an audio edge
293//-------------------------------------------------
274294
275   /* configure the decompressor for this field */
276   chd_codec_config(file, AV_CODEC_COMPRESS_CONFIG, &avconfig);
277
278   /* read the field */
279   chderr = chd_compress_hunk(file, NULL, NULL);
280   if (chderr != CHDERR_NONE)
281      return FALSE;
282
283   return TRUE;
284}
285
286
287/*-------------------------------------------------
288    create_close_chd - close a CHD file
289-------------------------------------------------*/
290
291static void create_close_chd(chd_file *file)
295static bool find_edge_near_field(chd_file &srcfile, UINT32 fieldnum, movie_info &info, bool report_best_field, INT32 &delta)
292296{
293   chd_error err;
297   // clear the sound buffers
298   memset(info.lsound, 0, info.lsound.count() * 2);
299   memset(info.rsound, 0, info.rsound.count() * 2);
294300
295   err = chd_compress_finish(file, TRUE);
296   if (err != CHDERR_NONE)
297      fprintf(stderr, "Error finishing compression: %s\n", chd_error_string(err));
298
299   chd_close(file);
300}
301
302
303/*-------------------------------------------------
304    close_chd - close a CHD file
305-------------------------------------------------*/
306
307static void close_chd(chd_file *file, movie_info *info)
308{
309   if (info != NULL)
310      chd_free_buffers(info);
311   chd_close(file);
312}
313
314
315
316/***************************************************************************
317    CORE IMPLEMENTATION
318***************************************************************************/
319
320/*-------------------------------------------------
321    find_edge_near_field - given a field number,
322    load +/- 1/2 second on either side and find
323    an audio edge
324-------------------------------------------------*/
325
326static int find_edge_near_field(chd_file *srcfile, UINT32 fieldnum, movie_info *info, int report_best_field, INT32 *delta)
327{
328   int fields_to_read = info->iframerate / 1000000;
329   UINT32 firstlavg = 0, firstravg = 0;
330   UINT32 firstldev = 0, firstrdev = 0;
331   UINT32 lcount = 0, rcount = 0;
301   // read 1 second around the target area
302   int fields_to_read = info.iframerate / 1000000;
303   INT32 firstfield = fieldnum - (fields_to_read / 2);
332304   UINT32 targetsoundstart = 0;
333305   UINT32 firstfieldend = 0;
334   INT32 firstfield, curfield;
335306   UINT32 fieldstart[100];
336307   UINT32 soundend = 0;
337   UINT32 sampnum;
338
339   /* clear the sound buffers */
340   memset(info->lsound, 0, info->samplerate * sizeof(*info->lsound));
341   memset(info->rsound, 0, info->samplerate * sizeof(*info->rsound));
342
343   /* read 1 second around the target area */
344   firstfield = fieldnum - (fields_to_read / 2);
345   for (curfield = 0; curfield < fields_to_read; curfield++)
308   for (INT32 curfield = 0; curfield < fields_to_read; curfield++)
346309   {
347      /* remember the start of each field */
310      // remember the start of each field
348311      fieldstart[curfield] = soundend;
349312
350      /* remember the sound offset where the initial fieldnum is */
313      // remember the sound offset where the initial fieldnum is
351314      if (firstfield + curfield == fieldnum)
352315         targetsoundstart = soundend;
353316
354      /* read the frame and samples */
317      // read the frame and samples
355318      if (firstfield + curfield >= 0)
356319      {
357320         read_chd(srcfile, firstfield + curfield, info, soundend);
358         soundend += info->samples;
321         soundend += info.samples;
359322
360         /* also remember the offset at the end of the first field */
323         // also remember the offset at the end of the first field
361324         if (firstfieldend == 0)
362325            firstfieldend = soundend;
363326      }
364327   }
365328
366   /* compute absolute deltas across the samples */
367   for (sampnum = 0; sampnum < soundend; sampnum++)
329   // compute absolute deltas across the samples
330   for (UINT32 sampnum = 0; sampnum < soundend; sampnum++)
368331   {
369      info->lsound[sampnum] = labs(info->lsound[sampnum + 1] - info->lsound[sampnum]);
370      info->rsound[sampnum] = labs(info->rsound[sampnum + 1] - info->rsound[sampnum]);
332      info.lsound[sampnum] = labs(info.lsound[sampnum + 1] - info.lsound[sampnum]);
333      info.rsound[sampnum] = labs(info.rsound[sampnum + 1] - info.rsound[sampnum]);
371334   }
372335
373   /* for each sample in the collection, find the highest deltas over the
374       next few samples, and take the nth highest value (to remove outliers) */
375   for (sampnum = 0; sampnum < soundend - MAXIMUM_WINDOW_SIZE; sampnum++)
336   // for each sample in the collection, find the highest deltas over the
337    // next few samples, and take the nth highest value (to remove outliers)
338   for (UINT32 sampnum = 0; sampnum < soundend - MAXIMUM_WINDOW_SIZE; sampnum++)
376339   {
340      // scan forward over the maximum window
377341      UINT32 lmax = 0, rmax = 0;
378      UINT32 scannum;
379
380      /* scan forward over the maximum window */
381      for (scannum = 0; scannum < MAXIMUM_WINDOW_SIZE; scannum++)
342      for (UINT32 scannum = 0; scannum < MAXIMUM_WINDOW_SIZE; scannum++)
382343      {
383         if (info->lsound[sampnum + scannum] > lmax)
384            lmax = info->lsound[sampnum + scannum];
385         if (info->rsound[sampnum + scannum] > rmax)
386            rmax = info->rsound[sampnum + scannum];
344         if (info.lsound[sampnum + scannum] > lmax)
345            lmax = info.lsound[sampnum + scannum];
346         if (info.rsound[sampnum + scannum] > rmax)
347            rmax = info.rsound[sampnum + scannum];
387348      }
388349
389      /* replace this sample with the maximum value found */
390      info->lsound[sampnum] = lmax;
391      info->rsound[sampnum] = rmax;
350      // replace this sample with the maximum value found
351      info.lsound[sampnum] = lmax;
352      info.rsound[sampnum] = rmax;
392353   }
393354
394   /* now compute the average over the first field, which is assumed to be silence */
395   for (sampnum = 0; sampnum < firstfieldend; sampnum++)
355   // now compute the average over the first field, which is assumed to be silence
356   UINT32 firstlavg = 0;
357   UINT32 firstravg = 0;
358   for (UINT32 sampnum = 0; sampnum < firstfieldend; sampnum++)
396359   {
397      firstlavg += info->lsound[sampnum];
398      firstravg += info->rsound[sampnum];
360      firstlavg += info.lsound[sampnum];
361      firstravg += info.rsound[sampnum];
399362   }
400363   firstlavg /= firstfieldend;
401364   firstravg /= firstfieldend;
402365
403   /* then compute the standard deviation over the first field */
404   for (sampnum = 0; sampnum < firstfieldend; sampnum++)
366   // then compute the standard deviation over the first field
367   UINT32 firstldev = 0;
368   UINT32 firstrdev = 0;
369   for (UINT32 sampnum = 0; sampnum < firstfieldend; sampnum++)
405370   {
406      firstldev += (info->lsound[sampnum] - firstlavg) * (info->lsound[sampnum] - firstlavg);
407      firstrdev += (info->rsound[sampnum] - firstravg) * (info->rsound[sampnum] - firstravg);
371      firstldev += (info.lsound[sampnum] - firstlavg) * (info.lsound[sampnum] - firstlavg);
372      firstrdev += (info.rsound[sampnum] - firstravg) * (info.rsound[sampnum] - firstravg);
408373   }
409   firstldev = sqrt((double)firstldev / firstfieldend);
410   firstrdev = sqrt((double)firstrdev / firstfieldend);
374   firstldev = sqrt(double(firstldev) / firstfieldend);
375   firstrdev = sqrt(double(firstrdev) / firstfieldend);
411376
412   /* scan forward through the samples, counting consecutive samples more than
413       SIGNAL_DEVIATIONS standard deviations away from silence */
377   // scan forward through the samples, counting consecutive samples more than
378    // SIGNAL_DEVIATIONS standard deviations away from silence
379   UINT32 lcount = 0;
380   UINT32 rcount = 0;
381   UINT32 sampnum = 0;
414382   for (sampnum = 0; sampnum < soundend; sampnum++)
415383   {
416      /* left speaker */
417      if (info->lsound[sampnum] > firstlavg + SIGNAL_DEVIATIONS * firstldev)
384      // left speaker
385      if (info.lsound[sampnum] > firstlavg + SIGNAL_DEVIATIONS * firstldev)
418386         lcount++;
419387      else
420388         lcount = 0;
421389
422      /* right speaker */
423      if (info->rsound[sampnum] > firstravg + SIGNAL_DEVIATIONS * firstrdev)
390      // right speaker
391      if (info.rsound[sampnum] > firstravg + SIGNAL_DEVIATIONS * firstrdev)
424392         rcount++;
425393      else
426394         rcount = 0;
427395
428      /* stop if we find enough */
396      // stop if we find enough
429397      if (lcount > MINIMUM_SIGNAL_COUNT || rcount > MINIMUM_SIGNAL_COUNT)
430398         break;
431399   }
432400
433   /* if we didn't find any, return failure */
401   // if we didn't find any, return failure
434402   if (sampnum >= soundend)
435403   {
436404      if (!report_best_field)
437405         printf("Field %5d: Unable to find edge\n", fieldnum);
438      return FALSE;
406      return false;
439407   }
440408
441   /* scan backwards to find the start of the signal */
409   // scan backwards to find the start of the signal
442410   for ( ; sampnum > 0; sampnum--)
443      if (info->lsound[sampnum - 1] < firstlavg + SIGNAL_START_DEVIATIONS * firstldev ||
444         info->rsound[sampnum - 1] < firstravg + SIGNAL_START_DEVIATIONS * firstrdev)
411      if (info.lsound[sampnum - 1] < firstlavg + SIGNAL_START_DEVIATIONS * firstldev ||
412         info.rsound[sampnum - 1] < firstravg + SIGNAL_START_DEVIATIONS * firstrdev)
445413         break;
446414
447   /* if we're to report the best field, figure out which field we are in */
415   // if we're to report the best field, figure out which field we are in
448416   if (report_best_field)
449417   {
418      INT32 curfield;
450419      for (curfield = 0; curfield < fields_to_read - 1; curfield++)
451420         if (sampnum < fieldstart[curfield + 1])
452421            break;
453422      printf("Field %5d: Edge found at offset %d (frame %.1f)\n", firstfield + curfield, sampnum - fieldstart[curfield], (double)(firstfield + curfield) * 0.5);
454423   }
455424
456   /* otherwise, compute the delta from the provided field number */
425   // otherwise, compute the delta from the provided field number
457426   else
458427   {
459428      printf("Field %5d: Edge at offset %d from expected (found at %d, expected %d)\n", fieldnum, sampnum - targetsoundstart, sampnum, targetsoundstart);
460      *delta = sampnum - targetsoundstart;
429      delta = sampnum - targetsoundstart;
461430   }
462   return TRUE;
431   return true;
463432}
464433
465434
466/*-------------------------------------------------
467    usage - display program usage
468-------------------------------------------------*/
435//-------------------------------------------------
436//  generate_one_frame - generate a single
437//  resampled frame
438//-------------------------------------------------
469439
440void chd_resample_compressor::generate_one_frame(UINT8 *dest, UINT32 datasize, UINT32 fieldnum)
441{
442   // determine the first field needed to cover this range of samples
443   UINT32 srcbegin = field_to_sample_number(m_info, fieldnum);
444   INT64 dstbegin = (INT64(srcbegin) << 24) + m_ioffset + m_islope * fieldnum;
445   UINT32 dstbeginoffset;
446   INT32 dstbeginfield;
447   if (dstbegin >= 0)
448      dstbeginfield = sample_number_to_field(m_info, dstbegin >> 24, dstbeginoffset);
449   else
450   {
451      dstbeginfield = -1 - sample_number_to_field(m_info, -dstbegin >> 24, dstbeginoffset);
452      dstbeginoffset = (field_to_sample_number(m_info, -dstbeginfield) - field_to_sample_number(m_info, -dstbeginfield - 1)) - dstbeginoffset;
453   }
454   
455   // determine the last field needed to cover this range of samples
456   UINT32 srcend = field_to_sample_number(m_info, fieldnum + 1);
457   INT64 dstend = (INT64(srcend) << 24) + m_ioffset + m_islope * (fieldnum + 1);
458   UINT32 dstendoffset;
459   INT32 dstendfield;
460   if (dstend >= 0)
461      dstendfield = sample_number_to_field(m_info, dstend >> 24, dstendoffset);
462   else
463   {
464      dstendfield = -1 - -sample_number_to_field(m_info, -dstend >> 24, dstendoffset);
465      dstendoffset = (field_to_sample_number(m_info, -dstendfield) - field_to_sample_number(m_info, -dstendfield - 1)) - dstendoffset;
466   }
467/*
468printf("%5d: start=%10d (%5d.%03d) end=%10d (%5d.%03d)\n",
469        fieldnum,
470        (INT32)(dstbegin >> 24), dstbeginfield, dstbeginoffset,
471        (INT32)(dstend >> 24), dstendfield, dstendoffset);
472*/
473   // read all samples required into the end of the sound buffers
474   UINT32 dstoffset = srcend - srcbegin;
475   for (INT32 dstfield = dstbeginfield; dstfield <= dstendfield; dstfield++)
476   {
477      if (dstfield >= 0)
478         read_chd(m_source, dstfield, m_info, dstoffset);
479      else
480      {
481         m_info.samples = field_to_sample_number(m_info, -dstfield) - field_to_sample_number(m_info, -dstfield - 1);
482         memset(&m_info.lsound[dstoffset], 0, m_info.samples * sizeof(m_info.lsound[0]));
483         memset(&m_info.rsound[dstoffset], 0, m_info.samples * sizeof(m_info.rsound[0]));
484      }
485      dstoffset += m_info.samples;
486   }
487
488   // resample the destination samples to the source
489   dstoffset = srcend - srcbegin;
490   INT64 dstpos = dstbegin;
491   INT64 dststep = (dstend - dstbegin) / INT64(srcend - srcbegin);
492   for (UINT32 srcoffset = 0; srcoffset < srcend - srcbegin; srcoffset++)
493   {
494      m_info.lsound[srcoffset] = m_info.lsound[(int)(dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24))];
495      m_info.rsound[srcoffset] = m_info.rsound[(int)(dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24))];
496      dstpos += dststep;
497   }
498
499   // read the original frame, pointing the sound buffer past where we've calculated
500   read_chd(m_source, fieldnum, m_info, srcend - srcbegin);
501   
502   // assemble the final frame
503   dynamic_buffer buffer;
504   INT16 *sampledata[2] = { m_info.lsound, m_info.rsound };
505   avhuff_encoder::assemble_data(buffer, m_info.bitmap, m_info.channels, m_info.samples, sampledata);
506   memcpy(dest, buffer, MIN(buffer.count(), datasize));
507   if (buffer.count() < datasize)
508      memset(&dest[buffer.count()], 0, datasize - buffer.count());
509}
510
511
512//-------------------------------------------------
513//  usage - display program usage
514//-------------------------------------------------
515
470516static int usage(void)
471517{
472518   fprintf(stderr, "Usage: \n");
r14546r14547
480526}
481527
482528
483/*-------------------------------------------------
484    main - main entry point
485-------------------------------------------------*/
529//-------------------------------------------------
530//  main - main entry point
531//-------------------------------------------------
486532
487533int main(int argc, char *argv[])
488534{
489   movie_info info = { 0 };
490   const char *srcfilename;
491   const char *dstfilename;
492   double offset, slope;
493   chd_file *dstfile;
494
495   /* verify arguments */
535   // verify arguments
496536   if (argc < 2)
497537      return usage();
498   srcfilename = argv[1];
499   dstfilename = (argc < 3) ? NULL : argv[2];
500   offset = (argc < 4) ? 0.0 : atof(argv[3]);
501   slope = (argc < 5) ? 1.0 : atof(argv[4]);
538   const char *srcfilename = argv[1];
539   const char *dstfilename = (argc < 3) ? NULL : argv[2];
540   double offset = (argc < 4) ? 0.0 : atof(argv[3]);
541   double slope = (argc < 5) ? 1.0 : atof(argv[4]);
502542
503   /* print basic information */
543   // print basic information
504544   printf("Input file: %s\n", srcfilename);
505545   if (dstfilename != NULL)
506546   {
r14546r14547
509549      printf("Slope: %f\n", slope);
510550   }
511551
512   /* open the source file */
552   // open the source file
513553   chd_file srcfile;
554   movie_info info;
514555   chd_error err = open_chd(srcfile, srcfilename, info);
515556   if (err != CHDERR_NONE)
516557   {
r14546r14547
518559      return 1;
519560   }
520561
521   /* output some basics */
562   // output some basics
522563   printf("Video dimensions: %dx%d\n", info.width, info.height);
523564   printf("Video frame rate: %.2fHz\n", info.framerate);
524565   printf("Sample rate: %dHz\n", info.samplerate);
525566   printf("Total fields: %d\n", info.numfields);
526567
527   /* if we don't have a destination file, scan for edges */
568   // if we don't have a destination file, scan for edges
528569   if (dstfilename == NULL)
529570   {
530      UINT32 fieldnum;
531      INT32 delta;
532
533      for (fieldnum = 60; fieldnum < info.numfields - 60; fieldnum += 30)
571      for (UINT32 fieldnum = 60; fieldnum < info.numfields - 60; fieldnum += 30)
534572      {
535573         fprintf(stderr, "Field %5d\r", fieldnum);
536         find_edge_near_field(srcfile, fieldnum, &info, TRUE, &delta);
574         INT32 delta;
575         find_edge_near_field(srcfile, fieldnum, info, true, delta);
537576      }
538577   }
539578
540   /* otherwise, resample the source to the destination */
579   // otherwise, resample the source to the destination
541580   else
542581   {
543      INT64 ioffset = (INT64)(offset * 65536.0 * 256.0);
544      INT64 islope = (INT64)(slope * 65536.0 * 256.0);
545      UINT32 fieldnum;
546
547      /* open the destination file */
582      // open the destination file
583      chd_resample_compressor dstfile(srcfile, info, INT64(offset * 65536.0 * 256.0), INT64(slope * 65536.0 * 256.0));
548584      err = create_chd(dstfile, dstfilename, srcfile, info);
549585      if (dstfile == NULL)
550586      {
r14546r14547
552588         return 1;
553589      }
554590
555      /* loop over all the fields in the source file */
556      for (fieldnum = 0; fieldnum < info.numfields; fieldnum++)
557      {
558         UINT32 srcbegin = field_to_sample_number(&info, fieldnum);
559         UINT32 srcend = field_to_sample_number(&info, fieldnum + 1);
560         INT64 dstbegin = ((INT64)srcbegin << 24) + ioffset + islope * fieldnum;
561         INT64 dstend = ((INT64)srcend << 24) + ioffset + islope * (fieldnum + 1);
562         UINT32 dstbeginoffset, dstendoffset, dstoffset;
563         INT32 dstbeginfield, dstendfield, dstfield;
564         INT64 dstpos, dststep;
565         UINT32 srcoffset;
566
567         /* update progress (this ain't fast!) */
568         if (fieldnum % 10 == 0)
569            fprintf(stderr, "Field %d\r", fieldnum);
570
571         /* determine the first and last fields needed to cover this range of samples */
572         if (dstbegin >= 0)
573            dstbeginfield = sample_number_to_field(&info, dstbegin >> 24, &dstbeginoffset);
574         else
591      // loop over all the fields in the source file
592      double progress, ratio;
593      osd_ticks_t last_update = 0;
594      while (dstfile.compress_continue(progress, ratio) == CHDERR_COMPRESSING)
595         if (osd_ticks() - last_update > osd_ticks_per_second() / 4)
575596         {
576            dstbeginfield = -1 - sample_number_to_field(&info, -dstbegin >> 24, &dstbeginoffset);
577            dstbeginoffset = (field_to_sample_number(&info, -dstbeginfield) - field_to_sample_number(&info, -dstbeginfield - 1)) - dstbeginoffset;
597            last_update = osd_ticks();
598            printf("Processing, %.1f%% complete....\r", progress * 100.0);
578599         }
579         if (dstend >= 0)
580            dstendfield = sample_number_to_field(&info, dstend >> 24, &dstendoffset);
581         else
582         {
583            dstendfield = -1 - -sample_number_to_field(&info, -dstend >> 24, &dstendoffset);
584            dstendoffset = (field_to_sample_number(&info, -dstendfield) - field_to_sample_number(&info, -dstendfield - 1)) - dstendoffset;
585         }
586/*
587printf("%5d: start=%10d (%5d.%03d) end=%10d (%5d.%03d)\n",
588        fieldnum,
589        (INT32)(dstbegin >> 24), dstbeginfield, dstbeginoffset,
590        (INT32)(dstend >> 24), dstendfield, dstendoffset);
591*/
592         /* read all samples required into the end of the sound buffers */
593         dstoffset = srcend - srcbegin;
594         for (dstfield = dstbeginfield; dstfield <= dstendfield; dstfield++)
595         {
596            if (dstfield >= 0)
597               read_chd(srcfile, dstfield, &info, dstoffset);
598            else
599            {
600               info.samples = field_to_sample_number(&info, -dstfield) - field_to_sample_number(&info, -dstfield - 1);
601               memset(&info.lsound[dstoffset], 0, info.samples * sizeof(info.lsound[0]));
602               memset(&info.rsound[dstoffset], 0, info.samples * sizeof(info.rsound[0]));
603            }
604            dstoffset += info.samples;
605         }
606
607         /* resample the destination samples to the source */
608         dstoffset = srcend - srcbegin;
609         dstpos = dstbegin;
610         dststep = (dstend - dstbegin) / (INT64)(srcend - srcbegin);
611         for (srcoffset = 0; srcoffset < srcend - srcbegin; srcoffset++)
612         {
613            info.lsound[srcoffset] = info.lsound[dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24)];
614            info.rsound[srcoffset] = info.rsound[dstoffset + dstbeginoffset + (dstpos >> 24) - (dstbegin >> 24)];
615            dstpos += dststep;
616         }
617
618         /* read the original frame, pointing the sound buffer past where we've calculated */
619         read_chd(srcfile, fieldnum, &info, srcend - srcbegin);
620
621         /* write it to the destination */
622         write_chd(dstfile, fieldnum, &info);
623      }
624
625      /* close the destination file */
626      create_close_chd(dstfile);
627600   }
628
629   /* close the source file */
630   close_chd(srcfile, &info);
631
632601   return 0;
633602}
src/tools/chdman.c
r14546r14547
431431            }
432432
433433            // assemble the data into final form
434            avhuff_error averr = avhuff_encoder::assemble_data(m_rawdata, m_rawdata.count(), subbitmap, channels, samples, samplesptr);
434            avhuff_error averr = avhuff_encoder::assemble_data(m_rawdata, subbitmap, channels, samples, samplesptr);
435435            if (averr != AVHERR_NONE)
436436               report_error(1, "Error assembling data for frame %d", framenum);
437            UINT32 rawsize = avhuff_encoder::raw_data_size(m_rawdata);
438            if (rawsize < m_rawdata.count())
439               memset(&m_rawdata[rawsize], 0, m_rawdata.count() - rawsize);
437            if (m_rawdata.count() < m_info.bytes_per_frame)
438            {
439               UINT32 delta = m_info.bytes_per_frame - m_rawdata.count();
440               m_rawdata.resize(m_info.bytes_per_frame, true);
441               memset(&m_rawdata[m_info.bytes_per_frame - delta], 0, delta);
442            }
440443
441444            // copy to the destination
442445            UINT64 start_offset = UINT64(framenum) * UINT64(m_info.bytes_per_frame);
src/emu/machine.c
r14546r14547
10831083
10841084   // set the short name to the game's name
10851085   driver.m_shortname = game.name;
1086   
1087   // set the full name to the game's description
1088   driver.m_name = game.description;
10861089
10871090   // and set the search path to include all parents
10881091   driver.m_searchpath = game.name;
src/emu/clifront.c
r14546r14547
463463
464464   // iterate through matches, and then through ROMs
465465   while (drivlist.next())
466      for (const rom_source *source = rom_first_source(drivlist.config()); source != NULL; source = rom_next_source(*source))
467      {
468         bool isdriver = (source == rom_first_source(drivlist.config()));
469         for (const rom_entry *region = rom_first_region(*source); region; region = rom_next_region(region))
466   {
467      device_iterator deviter(drivlist.config().root_device());
468      for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
469         for (const rom_entry *region = rom_first_region(*device); region; region = rom_next_region(region))
470470            for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom))
471471            {
472472               // if we have a CRC, display it
473473               UINT32 crc;
474474               if (hash_collection(ROM_GETHASHDATA(rom)).crc(crc))
475                  mame_printf_info("%08x %-16s \t %-8s \t %s\n", crc, ROM_GETNAME(rom), source->shortname(), isdriver ? drivlist.driver().description : source->name());
475                  mame_printf_info("%08x %-16s \t %-8s \t %s\n", crc, ROM_GETNAME(rom), device->shortname(), device->name());
476476            }
477      }
477   }
478478}
479479
480480
r14546r14547
503503            "Name                    Size Checksum\n", drivlist.driver().name);
504504
505505      // iterate through roms
506      for (const rom_source *source = rom_first_source(drivlist.config()); source != NULL; source = rom_next_source(*source))
507         for (const rom_entry *region = rom_first_region(*source); region; region = rom_next_region(region))
506      device_iterator deviter(drivlist.config().root_device());
507      for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
508         for (const rom_entry *region = rom_first_region(*device); region; region = rom_next_region(region))
508509            for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom))
509510            {
510511               // accumulate the total length of all chunks
r14546r14547
16491650   m_drivlist.reset();
16501651   while (m_drivlist.next())
16511652   {
1652      // iterate over sources, regions and files within the region */
1653      for (const rom_source *source = rom_first_source(m_drivlist.config()); source != NULL; source = rom_next_source(*source))
1654         for (const rom_entry *region = rom_first_region(*source); region != NULL; region = rom_next_region(region))
1653      // iterate over devices, regions and files within the region */
1654      device_iterator deviter(m_drivlist.config().root_device());
1655      for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
1656         for (const rom_entry *region = rom_first_region(*device); region != NULL; region = rom_next_region(region))
16551657            for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
16561658            {
16571659               hash_collection romhashes(ROM_GETHASHDATA(rom));
src/emu/validity.c
r14546r14547
616616void validity_checker::validate_roms()
617617{
618618   // iterate, starting with the driver's ROMs and continuing with device ROMs
619   for (const rom_source *source = rom_first_source(*m_current_config); source != NULL; source = rom_next_source(*source))
619   device_iterator deviter(m_current_config->root_device());
620   for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
620621   {
621622      // for non-root devices, track the current device
622      m_current_device = (source == &m_current_config->root_device()) ? NULL : source;
623      m_current_device = (device->owner() == NULL) ? NULL : device;
623624
624625      // scan the ROM entries for this device
625626      const char *last_region_name = "???";
r14546r14547
628629      int items_since_region = 1;
629630      int last_bios = 0;
630631      int total_files = 0;
631      for (const rom_entry *romp = rom_first_region(*source); !ROMENTRY_ISEND(romp); romp++)
632      for (const rom_entry *romp = rom_first_region(*device); romp != NULL && !ROMENTRY_ISEND(romp); romp++)
632633      {
633634         // if this is a region, make sure it's valid, and record the length
634635         if (ROMENTRY_ISREGION(romp))
r14546r14547
654655
655656            // generate the full tag
656657            astring fulltag;
657            rom_region_name(fulltag, m_current_driver, source, romp);
658            rom_region_name(fulltag, *device, romp);
658659
659660            // attempt to add it to the map, reporting duplicates as errors
660661            current_length = ROMREGION_GETLENGTH(romp);
src/emu/romload.c
r14546r14547
165165***************************************************************************/
166166
167167/*-------------------------------------------------
168    rom_first_source - return pointer to first ROM
169    source
170-------------------------------------------------*/
171
172const rom_source *rom_first_source(const machine_config &config)
173{
174   /* look through devices */
175   device_iterator iter(config.root_device());
176   for (const device_t *device = iter.first(); device != NULL; device = iter.next())
177      if (device->rom_region() != NULL)
178         return device;
179
180   return NULL;
181}
182
183
184/*-------------------------------------------------
185    rom_next_source - return pointer to next ROM
186    source
187-------------------------------------------------*/
188
189const rom_source *rom_next_source(const rom_source &previous)
190{
191   /* look for further devices with ROM definitions */
192// fixme: this is awful
193   device_iterator iter(previous.mconfig().root_device());
194   const device_t *device;
195   for (device = iter.first(); device != NULL; device = iter.next())
196      if (device == &previous)
197         break;
198
199   for (device = iter.next(); device != NULL; device = iter.next())
200      if (device->rom_region() != NULL)
201         return device;
202
203   return NULL;
204}
205
206
207/*-------------------------------------------------
208168    rom_first_region - return pointer to first ROM
209169    region
210170-------------------------------------------------*/
211171
212const rom_entry *rom_first_region(const rom_source &source)
172const rom_entry *rom_first_region(const device_t &device)
213173{
214   const rom_entry *romp = source.rom_region();
174   const rom_entry *romp = device.rom_region();
215175   return (romp != NULL && !ROMENTRY_ISEND(romp)) ? romp : NULL;
216176}
217177
r14546r14547
263223    for a rom region
264224-------------------------------------------------*/
265225
266astring &rom_region_name(astring &result, const game_driver *drv, const rom_source *source, const rom_entry *romp)
226astring &rom_region_name(astring &result, const device_t &device, const rom_entry *romp)
267227{
268   return source->subtag(result, ROM_GETNAME(romp));
228   return device.subtag(result, ROM_GETNAME(romp));
269229}
270230
271231
r14546r14547
333293
334294   romdata->system_bios = 0;
335295
336   for (const rom_source *source = rom_first_source(romdata->machine().config()); source != NULL; source = rom_next_source(*source))
337   {
338      /* first determine the default BIOS name */
339      for (rom = source->rom_region(); !ROMENTRY_ISEND(rom); rom++)
340         if (ROMENTRY_ISDEFAULT_BIOS(rom))
341            defaultname = ROM_GETNAME(rom);
296   device_t &rootdevice = romdata->machine().config().root_device();
342297
343      /* look for a BIOS with a matching name */
344      for (rom = source->rom_region(); !ROMENTRY_ISEND(rom); rom++)
345         if (ROMENTRY_ISSYSTEM_BIOS(rom))
346         {
347            const char *biosname = ROM_GETNAME(rom);
348            int bios_flags = ROM_GETBIOSFLAGS(rom);
349            char bios_number[20];
298   /* first determine the default BIOS name */
299   for (rom = rootdevice.rom_region(); !ROMENTRY_ISEND(rom); rom++)
300      if (ROMENTRY_ISDEFAULT_BIOS(rom))
301         defaultname = ROM_GETNAME(rom);
350302
351            /* Allow '-bios n' to still be used */
352            sprintf(bios_number, "%d", bios_flags - 1);
353            if (mame_stricmp(bios_number, specbios) == 0 || mame_stricmp(biosname, specbios) == 0)
354               romdata->system_bios = bios_flags;
355            if (defaultname != NULL && mame_stricmp(biosname, defaultname) == 0)
356               default_no = bios_flags;
357            bios_count++;
358         }
359
360      /* if none found, use the default */
361      if (romdata->system_bios == 0 && bios_count > 0)
303   /* look for a BIOS with a matching name */
304   for (rom = rootdevice.rom_region(); !ROMENTRY_ISEND(rom); rom++)
305      if (ROMENTRY_ISSYSTEM_BIOS(rom))
362306      {
363         /* if we got neither an empty string nor 'default' then warn the user */
364         if (specbios[0] != 0 && strcmp(specbios, "default") != 0 && romdata != NULL)
365         {
366            romdata->errorstring.catprintf("%s: invalid bios\n", specbios);
367            romdata->warnings++;
368         }
307         const char *biosname = ROM_GETNAME(rom);
308         int bios_flags = ROM_GETBIOSFLAGS(rom);
309         char bios_number[20];
369310
370         /* set to default */
371         romdata->system_bios = default_no;
311         /* Allow '-bios n' to still be used */
312         sprintf(bios_number, "%d", bios_flags - 1);
313         if (mame_stricmp(bios_number, specbios) == 0 || mame_stricmp(biosname, specbios) == 0)
314            romdata->system_bios = bios_flags;
315         if (defaultname != NULL && mame_stricmp(biosname, defaultname) == 0)
316            default_no = bios_flags;
317         bios_count++;
372318      }
373      romdata->default_bios = default_no;
374      LOG(("Using System BIOS: %d\n", romdata->system_bios));
319
320   /* if none found, use the default */
321   if (romdata->system_bios == 0 && bios_count > 0)
322   {
323      /* if we got neither an empty string nor 'default' then warn the user */
324      if (specbios[0] != 0 && strcmp(specbios, "default") != 0 && romdata != NULL)
325      {
326         romdata->errorstring.catprintf("%s: invalid bios\n", specbios);
327         romdata->warnings++;
328      }
329
330      /* set to default */
331      romdata->system_bios = default_no;
375332   }
333   romdata->default_bios = default_no;
334   LOG(("Using System BIOS: %d\n", romdata->system_bios));
376335}
377336
378337
r14546r14547
384343static void count_roms(rom_load_data *romdata)
385344{
386345   const rom_entry *region, *rom;
387   const rom_source *source;
388346
389347   /* start with 0 */
390348   romdata->romstotal = 0;
391349   romdata->romstotalsize = 0;
392350
393351   /* loop over regions, then over files */
394   for (source = rom_first_source(romdata->machine().config()); source != NULL; source = rom_next_source(*source))
395      for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region))
352   device_iterator deviter(romdata->machine().config().root_device());
353   for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
354      for (region = rom_first_region(*device); region != NULL; region = rom_next_region(region))
396355         for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
397356            if (ROM_GETBIOSFLAGS(rom) == 0 || ROM_GETBIOSFLAGS(rom) == romdata->system_bios)
398357            {
r14546r14547
1003962{
1004963   emu_file image_file(options.media_path(), OPEN_FLAG_READ);
1005964   const rom_entry *region, *rom;
1006   const rom_source *source;
1007965   file_error filerr;
1008966   chd_error err;
1009967
r14546r14547
11071065   for (int drv = driver_list::find(*gamedrv); drv != -1; drv = driver_list::clone(drv))
11081066   {
11091067      machine_config config(driver_list::driver(drv), options);
1110      for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source))
1111         for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region))
1068      device_iterator deviter(config.root_device());
1069      for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
1070         for (region = rom_first_region(*device); region != NULL; region = rom_next_region(region))
11121071            if (ROMREGION_ISDISKDATA(region))
11131072               for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
11141073
r14546r14547
14301389static void process_region_list(rom_load_data *romdata)
14311390{
14321391   astring regiontag;
1433   const rom_source *source;
1434   const rom_entry *region;
14351392
14361393   /* loop until we hit the end */
1437   for (source = rom_first_source(romdata->machine().config()); source != NULL; source = rom_next_source(*source))
1438      for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region))
1394   device_iterator deviter(romdata->machine().root_device());
1395   for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
1396      for (const rom_entry *region = rom_first_region(*device); region != NULL; region = rom_next_region(region))
14391397      {
14401398         UINT32 regionlength = ROMREGION_GETLENGTH(region);
14411399
1442         rom_region_name(regiontag, &romdata->machine().system(), source, region);
1400         rom_region_name(regiontag, *device, region);
14431401         LOG(("Processing region \"%s\" (length=%X)\n", regiontag.cstr(), regionlength));
14441402
14451403         /* the first entry must be a region */
r14546r14547
14721430#endif
14731431
14741432            /* now process the entries in the region */
1475            process_rom_entries(romdata, (source->shortname()!=NULL) ? source->shortname() : NULL, region, region + 1);
1433            process_rom_entries(romdata, device->shortname(), region, region + 1);
14761434         }
14771435         else if (ROMREGION_ISDISKDATA(region))
14781436            process_disk_entries(romdata, regiontag, region, region + 1, NULL);
14791437      }
14801438
14811439   /* now go back and post-process all the regions */
1482   for (source = rom_first_source(romdata->machine().config()); source != NULL; source = rom_next_source(*source))
1483      for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) {
1484         rom_region_name(regiontag, &romdata->machine().system(), source, region);
1440   for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
1441      for (const rom_entry *region = rom_first_region(*device); region != NULL; region = rom_next_region(region))
1442      {
1443         rom_region_name(regiontag, *device, region);
14851444         region_post_process(romdata, regiontag, ROMREGION_ISINVERTED(region));
14861445      }
14871446}
src/emu/imagedev/cartslot.c
r14546r14547
171171
172172int cartslot_image_device::process_cartridge(bool load)
173173{
174   const rom_source *source;
175174   const rom_entry *romrgn, *roment;
176175   int result = 0;
177176
178   for (source = rom_first_source(device().machine().config()); source != NULL; source = rom_next_source(*source))
179   {
180      for (romrgn = rom_first_region(*source); romrgn != NULL; romrgn = rom_next_region(romrgn))
177   device_iterator deviter(device().mconfig().root_device());
178   for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
179      for (romrgn = rom_first_region(*device); romrgn != NULL; romrgn = rom_next_region(romrgn))
181180      {
182181         roment = romrgn + 1;
183182         while(!ROMENTRY_ISREGIONEND(roment))
r14546r14547
185184            if (ROMENTRY_GETTYPE(roment) == ROMENTRYTYPE_CARTRIDGE)
186185            {
187186               astring regiontag;
188               device().siblingtag(regiontag, roment->_hashdata);
187               this->device().siblingtag(regiontag, roment->_hashdata);
189188
190               if (strcmp(regiontag.cstr(),device().tag())==0)
189               if (strcmp(regiontag.cstr(),this->device().tag())==0)
191190               {
192191                  result |= load_cartridge(romrgn, roment, load);
193192
r14546r14547
199198            roment++;
200199         }
201200      }
202   }
203201
204202   return IMAGE_INIT_PASS;
205203}
src/emu/romload.h
r14546r14547
123123class emu_options;
124124class chd_file;
125125
126typedef device_t rom_source;
127126
128
129127struct rom_entry
130128{
131129   const char *   _name;            /* name of the file to load */
r14546r14547
284282
285283/* ----- ROM iteration ----- */
286284
287/* return pointer to first ROM source */
288const rom_source *rom_first_source(const machine_config &config);
289
290/* return pointer to next ROM source */
291const rom_source *rom_next_source(const rom_source &previous);
292
293285/* return pointer to the first ROM region within a source */
294const rom_entry *rom_first_region(const rom_source &romp);
286const rom_entry *rom_first_region(const device_t &romp);
295287
296288/* return pointer to the next ROM region within a source */
297289const rom_entry *rom_next_region(const rom_entry *romp);
r14546r14547
302294/* return pointer to the next ROM file within a region */
303295const rom_entry *rom_next_file(const rom_entry *romp);
304296
305/* return TRUE if the given rom_source refers to the game driver itself */
306int rom_source_is_gamedrv(const game_driver *drv, const rom_source *source);
307
308297/* return the expected size of a file given the ROM description */
309298UINT32 rom_file_size(const rom_entry *romp);
310299
311300/* return the appropriate name for a rom region */
312astring &rom_region_name(astring &result, const game_driver *drv, const rom_source *source, const rom_entry *romp);
301astring &rom_region_name(astring &result, const device_t &device, const rom_entry *romp);
313302
314303
315304
src/emu/info.c
r14546r14547
239239      CONFIG_VERSION
240240   );
241241
242   m_device_used = global_alloc_array_clear(UINT8, m_device_count);
242   m_device_used.resize(m_device_count);
243   memset(m_device_used, 0, m_device_count);
243244
244245   // iterate through the drivers, outputting one at a time
245246   while (m_drivlist.next())
r14546r14547
248249   // iterate through the devices, and output their roms
249250   output_devices();
250251
251   global_free(m_device_used);
252
253252   // close the top level tag
254253   fprintf(m_output, "</%s>\n",emulator_info::get_xml_root());
255254}
r14546r14547
266265   m_drivlist.next();
267266   machine_config &config = m_drivlist.config();
268267   device_t &owner = config.root_device();
268
269269   // check if all are listed, note that empty one is included
270   bool display_all = driver_list::total() == (m_drivlist.count()+1);
271   for(int i=0;i<m_device_count;i++) {
272      if (display_all || (m_device_used[i]!=0)) {
273         device_type type = *s_devices_sorted[i];
270   bool display_all = (driver_list::total() == m_drivlist.count() + 1);
271   for (int devnum = 0; devnum < m_device_count; devnum++)
272   {
273      if (display_all || m_device_used[devnum])
274      {
275         device_type type = *s_devices_sorted[devnum];
274276         device_t *dev = (*type)(config, "dummy", &owner, 0);
275277         dev->config_complete();
276278
277279         // print the header and the game name
278         fprintf(m_output, "\t<%s",emulator_info::get_xml_top());
280         fprintf(m_output, "\t<%s", emulator_info::get_xml_top());
279281         fprintf(m_output, " name=\"%s\"", xml_normalize_string(dev->shortname()));
280282         fprintf(m_output, " isdevice=\"yes\"");
281283         fprintf(m_output, " runnable=\"no\"");
r14546r14547
285287         if (dev->name() != NULL)
286288            fprintf(m_output, "\t\t<description>%s</description>\n", xml_normalize_string(dev->name()));
287289
288         output_rom(dev);
290         output_rom(*dev);
289291
290292         // close the topmost tag
291         fprintf(m_output, "\t</%s>\n",emulator_info::get_xml_top());
293         fprintf(m_output, "\t</%s>\n", emulator_info::get_xml_top());
292294         global_free(dev);
293295      }
294296   }
295297}
296298
299
297300//-------------------------------------------------
298301//  output_one - print the XML information
299302//  for one particular game driver
r14546r14547
359362
360363   // now print various additional information
361364   output_bios();
362   output_rom(rom_first_source(m_drivlist.config()));
365   output_rom(m_drivlist.config().root_device());
363366   output_device_roms();
364367   output_sample();
365368   output_chips();
r14546r14547
379382   fprintf(m_output, "\t</%s>\n",emulator_info::get_xml_top());
380383}
381384
385
382386//------------------------------------------------
383387//  output_device_roms - print the device
384388//  with roms, if appropriate
r14546r14547
386390
387391void info_xml_creator::output_device_roms()
388392{
389   int cnt=0;
390   for (const rom_source *source = rom_first_source(m_drivlist.config()); source != NULL; source = rom_next_source(*source))
391   {
392      if (cnt!=0) {
393         fprintf(m_output, "\t\t<device_ref name=\"%s\"/>\n", xml_normalize_string(source->shortname()));
394         for(int i=0;i<m_device_count;i++) {
395            if (source->type() == *s_devices_sorted[i]) m_device_used[i] = 1;
396         }
393   device_iterator deviter(m_drivlist.config().root_device());
394   for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
395      if (device->owner() != NULL)
396      {
397         fprintf(m_output, "\t\t<device_ref name=\"%s\"/>\n", xml_normalize_string(device->shortname()));
398         for (int devnum = 0; devnum < m_device_count; devnum++)
399            if (device->type() == *s_devices_sorted[devnum])
400               m_device_used[devnum] = 1;
397401      }
398      cnt++;
399   }
400402}
401403
404
402405//------------------------------------------------
403406//  output_sampleof - print the 'sampleof'
404407//  attribute, if appropriate
r14546r14547
453456//  the XML output
454457//-------------------------------------------------
455458
456void info_xml_creator::output_rom(const rom_source *source)
459void info_xml_creator::output_rom(device_t &device)
457460{
458461   // iterate over 3 different ROM "types": BIOS, ROMs, DISKs
459462   for (int rom_type = 0; rom_type < 3; rom_type++)
460   {
461         for (const rom_entry *region = rom_first_region(*source); region != NULL; region = rom_next_region(region))
463      for (const rom_entry *region = rom_first_region(device); region != NULL; region = rom_next_region(region))
464      {
465         bool is_disk = ROMREGION_ISDISKDATA(region);
466
467         // disk regions only work for disks
468         if ((is_disk && rom_type != 2) || (!is_disk && rom_type == 2))
469            continue;
470
471         // iterate through ROM entries
472         for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
462473         {
463            bool is_disk = ROMREGION_ISDISKDATA(region);
474            bool is_bios = ROM_GETBIOSFLAGS(rom);
475            const char *name = ROM_GETNAME(rom);
476            int offset = ROM_GETOFFSET(rom);
477            const char *merge_name = NULL;
478            char bios_name[100];
464479
465            // disk regions only work for disks
466            if ((is_disk && rom_type != 2) || (!is_disk && rom_type == 2))
480            // BIOS ROMs only apply to bioses
481            if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0))
467482               continue;
468483
469            // iterate through ROM entries
470            for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
484            // if we have a valid ROM and we are a clone, see if we can find the parent ROM
485            hash_collection hashes(ROM_GETHASHDATA(rom));
486            if (!hashes.flag(hash_collection::FLAG_NO_DUMP))
487               merge_name = get_merge_name(hashes);
488
489            // scan for a BIOS name
490            bios_name[0] = 0;
491            if (!is_disk && is_bios)
471492            {
472               bool is_bios = ROM_GETBIOSFLAGS(rom);
473               const char *name = ROM_GETNAME(rom);
474               int offset = ROM_GETOFFSET(rom);
475               const char *merge_name = NULL;
476               char bios_name[100];
493               // scan backwards through the ROM entries
494               for (const rom_entry *brom = rom - 1; brom != m_drivlist.driver().rom; brom--)
495                  if (ROMENTRY_ISSYSTEM_BIOS(brom))
496                  {
497                     strcpy(bios_name, ROM_GETNAME(brom));
498                     break;
499                  }
500            }
477501
478               // BIOS ROMs only apply to bioses
479               if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0))
480                  continue;
502            // opening tag
503            if (!is_disk)
504               fprintf(m_output, "\t\t<rom");
505            else
506               fprintf(m_output, "\t\t<disk");
481507
482               // if we have a valid ROM and we are a clone, see if we can find the parent ROM
483               hash_collection hashes(ROM_GETHASHDATA(rom));
484               if (!hashes.flag(hash_collection::FLAG_NO_DUMP))
485                  merge_name = get_merge_name(hashes);
508            // add name, merge, bios, and size tags */
509            if (name != NULL && name[0] != 0)
510               fprintf(m_output, " name=\"%s\"", xml_normalize_string(name));
511            if (merge_name != NULL)
512               fprintf(m_output, " merge=\"%s\"", xml_normalize_string(merge_name));
513            if (bios_name[0] != 0)
514               fprintf(m_output, " bios=\"%s\"", xml_normalize_string(bios_name));
515            if (!is_disk)
516               fprintf(m_output, " size=\"%d\"", rom_file_size(rom));
486517
487               // scan for a BIOS name
488               bios_name[0] = 0;
489               if (!is_disk && is_bios)
490               {
491                  // scan backwards through the ROM entries
492                  for (const rom_entry *brom = rom - 1; brom != m_drivlist.driver().rom; brom--)
493                     if (ROMENTRY_ISSYSTEM_BIOS(brom))
494                     {
495                        strcpy(bios_name, ROM_GETNAME(brom));
496                        break;
497                     }
498               }
518            // dump checksum information only if there is a known dump
519            if (!hashes.flag(hash_collection::FLAG_NO_DUMP))
520            {
521               // iterate over hash function types and print m_output their values
522               astring tempstr;
523               fprintf(m_output, " %s", hashes.attribute_string(tempstr));
524            }
525            else
526               fprintf(m_output, " status=\"nodump\"");
499527
500               // opening tag
501               if (!is_disk)
502                  fprintf(m_output, "\t\t<rom");
503               else
504                  fprintf(m_output, "\t\t<disk");
528            // append a region name
529            fprintf(m_output, " region=\"%s\"", ROMREGION_GETTAG(region));
505530
506               // add name, merge, bios, and size tags */
507               if (name != NULL && name[0] != 0)
508                  fprintf(m_output, " name=\"%s\"", xml_normalize_string(name));
509               if (merge_name != NULL)
510                  fprintf(m_output, " merge=\"%s\"", xml_normalize_string(merge_name));
511               if (bios_name[0] != 0)
512                  fprintf(m_output, " bios=\"%s\"", xml_normalize_string(bios_name));
513               if (!is_disk)
514                  fprintf(m_output, " size=\"%d\"", rom_file_size(rom));
531            // for non-disk entries, print offset
532            if (!is_disk)
533               fprintf(m_output, " offset=\"%x\"", offset);
515534
516               // dump checksum information only if there is a known dump
517               if (!hashes.flag(hash_collection::FLAG_NO_DUMP))
518               {
519                  // iterate over hash function types and print m_output their values
520                  astring tempstr;
521                  fprintf(m_output, " %s", hashes.attribute_string(tempstr));
522               }
523               else
524                  fprintf(m_output, " status=\"nodump\"");
535            // for disk entries, add the disk index
536            else
537            {
538               fprintf(m_output, " index=\"%x\"", DISK_GETINDEX(rom));
539               fprintf(m_output, " writable=\"%s\"", DISK_ISREADONLY(rom) ? "no" : "yes");
540            }
525541
526               // append a region name
527               fprintf(m_output, " region=\"%s\"", ROMREGION_GETTAG(region));
542            // add optional flag
543            if ((!is_disk && ROM_ISOPTIONAL(rom)) || (is_disk && DISK_ISOPTIONAL(rom)))
544               fprintf(m_output, " optional=\"yes\"");
528545
529               // for non-disk entries, print offset
530               if (!is_disk)
531                  fprintf(m_output, " offset=\"%x\"", offset);
532
533               // for disk entries, add the disk index
534               else
535               {
536                  fprintf(m_output, " index=\"%x\"", DISK_GETINDEX(rom));
537                  fprintf(m_output, " writable=\"%s\"", DISK_ISREADONLY(rom) ? "no" : "yes");
538               }
539
540               // add optional flag
541               if ((!is_disk && ROM_ISOPTIONAL(rom)) || (is_disk && DISK_ISOPTIONAL(rom)))
542                  fprintf(m_output, " optional=\"yes\"");
543
544               fprintf(m_output, "/>\n");
545            }
546            fprintf(m_output, "/>\n");
546547         }
547   }
548      }
548549}
549550
550551
r14546r14547
12621263
12631264const char *info_xml_creator::get_merge_name(const hash_collection &romhashes)
12641265{
1266   // walk the parent chain
12651267   const char *merge_name = NULL;
1266   // walk the parent chain
12671268   for (int clone_of = m_drivlist.find(m_drivlist.driver().parent); clone_of != -1; clone_of = m_drivlist.find(m_drivlist.driver(clone_of).parent))
1268
1269   {
12691270      // look in the parent's ROMs
1270      for (const rom_source *psource = rom_first_source(m_drivlist.config(clone_of,m_lookup_options)); psource != NULL; psource = rom_next_source(*psource))
1271         for (const rom_entry *pregion = rom_first_region(*psource); pregion != NULL; pregion = rom_next_region(pregion))
1271      device_iterator deviter(m_drivlist.config(clone_of, m_lookup_options).root_device());
1272      for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
1273         for (const rom_entry *pregion = rom_first_region(*device); pregion != NULL; pregion = rom_next_region(pregion))
12721274            for (const rom_entry *prom = rom_first_file(pregion); prom != NULL; prom = rom_next_file(prom))
12731275            {
12741276               hash_collection phashes(ROM_GETHASHDATA(prom));
r14546r14547
12791281                  break;
12801282               }
12811283            }
1284   }
12821285
12831286   return merge_name;
12841287}
src/emu/info.h
r14546r14547
6262   void output_one();
6363   void output_sampleof();
6464   void output_bios();
65   void output_rom(const rom_source *source);
65   void output_rom(device_t &device);
6666   void output_device_roms();
6767   void output_sample();
6868   void output_chips();
r14546r14547
8585   // internal state
8686   FILE *               m_output;
8787   driver_enumerator &      m_drivlist;
88   UINT8 *             m_device_used;
88   dynamic_array<UINT8>   m_device_used;
8989   emu_options          m_lookup_options;
9090
9191   static const char s_dtd_string[];
src/emu/audit.c
r14546r14547
7777// all searches
7878const char *driverpath = m_enumerator.config().root_device().searchpath();
7979
80   // iterate over ROM sources and regions
8180   int found = 0;
8281   int required = 0;
83   int sharedFound = 0;
84   int sharedRequired = 0;
82   int shared_found = 0;
83   int shared_required = 0;
8584
86   for (const rom_source *source = rom_first_source(m_enumerator.config()); source != NULL; source = rom_next_source(*source))
85   // iterate over devices and regions
86   device_iterator deviter(m_enumerator.config().root_device());
87   for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
8788   {
8889      // determine the search path for this source and iterate through the regions
89      m_searchpath = source->searchpath();
90      m_searchpath = device->searchpath();
9091
9192      // now iterate over regions and ROMs within
92      for (const rom_entry *region = rom_first_region(*source); region != NULL; region = rom_next_region(region))
93      for (const rom_entry *region = rom_first_region(*device); region != NULL; region = rom_next_region(region))
9394      {
9495// temporary hack: add the driver path & region name
95astring combinedpath(source->searchpath(), ";", driverpath);
96if(source->shortname())
97{
98   combinedpath=combinedpath.cat(";");
99   combinedpath=combinedpath.cat(source->shortname());
100}
96astring combinedpath(device->searchpath(), ";", driverpath);
97if (device->shortname())
98   combinedpath.cat(";").cat(device->shortname());
10199m_searchpath = combinedpath;
102100
103101         for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom))
104102         {
105103            hash_collection hashes(ROM_GETHASHDATA(rom));
106            const rom_source *shared_source = find_shared_source(source, hashes, ROM_GETLENGTH(rom));
104            device_t *shared_device = find_shared_device(*device, hashes, ROM_GETLENGTH(rom));
107105
108106            // count the number of files with hashes
109107            if (!hashes.flag(hash_collection::FLAG_NO_DUMP) && !ROM_ISOPTIONAL(rom))
110108            {
111109               required++;
112               if (shared_source != NULL)
113               {
114                  sharedRequired++;
115               }
110               if (shared_device != NULL)
111                  shared_required++;
116112            }
117113
118114            // audit a file
r14546r14547
127123            if (record != NULL)
128124            {
129125               // count the number of files that are found.
130               if (record->status() == audit_record::STATUS_GOOD || (record->status() == audit_record::STATUS_FOUND_INVALID && find_shared_source(source, record->actual_hashes(), record->actual_length()) == NULL))
126               if (record->status() == audit_record::STATUS_GOOD || (record->status() == audit_record::STATUS_FOUND_INVALID && find_shared_device(*device, record->actual_hashes(), record->actual_length()) == NULL))
131127               {
132128                  found++;
133                  if (shared_source != NULL)
134                  {
135                     sharedFound++;
136                  }
129                  if (shared_device != NULL)
130                     shared_found++;
137131               }
138132
139               record->set_shared_source(shared_source);
133               record->set_shared_device(shared_device);
140134            }
141135         }
142136      }
143137   }
144138
145139   // if we only find files that are in the parent & either the set has no unique files or the parent is not found, then assume we don't have the set at all
146   if (found == sharedFound && required > 0 && (required != sharedRequired || sharedFound == 0))
140   if (found == shared_found && required > 0 && (required != shared_required || shared_found == 0))
147141   {
148142      m_record_list.reset();
149143      return NOTFOUND;
150144   }
151145   else if (found == 0 && m_record_list.count() == 0)
152   {
153146      return NONE_NEEDED;
154   }
155147
156148   // return a summary
157149   return summarize(m_enumerator.driver().name);
r14546r14547
345337         case audit_record::SUBSTATUS_NOT_FOUND:
346338            if (string != NULL)
347339            {
348               const rom_source *shared_source = record->shared_source();
349               if (shared_source == NULL) string->catprintf("NOT FOUND\n");
350               else string->catprintf("NOT FOUND (%s)\n", shared_source->shortname());
340               device_t *shared_device = record->shared_device();
341               if (shared_device == NULL)
342                  string->catprintf("NOT FOUND\n");
343               else
344                  string->catprintf("NOT FOUND (%s)\n", shared_device->shortname());
351345            }
352346            break;
353347
r14546r14547
494488
495489
496490//-------------------------------------------------
497//  find_shared_source - return the source that
491//  find_shared_device - return the source that
498492//  shares a media entry with the same hashes
499493//-------------------------------------------------
500const rom_source *media_auditor::find_shared_source(const rom_source *source, const hash_collection &romhashes, UINT64 romlength)
494
495device_t *media_auditor::find_shared_device(device_t &device, const hash_collection &romhashes, UINT64 romlength)
501496{
502   const rom_source *highest_source = NULL;
497   // doesn't apply to NO_DUMP items
498   if (romhashes.flag(hash_collection::FLAG_NO_DUMP))
499      return NULL;
503500
504   if (!romhashes.flag(hash_collection::FLAG_NO_DUMP))
501   // special case for non-root devices
502   device_t *highest_device = NULL;
503   if (device.owner() != NULL)
505504   {
506      if (dynamic_cast<const driver_device *>(source) == NULL)
505      for (const rom_entry *region = rom_first_region(device); region != NULL; region = rom_next_region(region))
506         for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom))
507            if (ROM_GETLENGTH(rom) == romlength)
508            {
509               hash_collection hashes(ROM_GETHASHDATA(rom));
510               if (hashes == romhashes)
511                  highest_device = &device;
512            }
513   }
514   else
515   {
516      // iterate up the parent chain
517      for (int drvindex = m_enumerator.find(m_enumerator.driver().parent); drvindex != -1; drvindex = m_enumerator.find(m_enumerator.driver(drvindex).parent))
507518      {
508         for (const rom_entry *region = rom_first_region(*source); region; region = rom_next_region(region))
509            for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom))
510               if (ROM_GETLENGTH(rom) == romlength)
511               {
512                  hash_collection hashes(ROM_GETHASHDATA(rom));
513                  if (hashes == romhashes)
514                     highest_source = source;
515               }
519         device_iterator deviter(m_enumerator.config().root_device());
520         for (device_t *scandevice = deviter.first(); scandevice != NULL; scandevice = deviter.next())
521            for (const rom_entry *region = rom_first_region(*scandevice); region; region = rom_next_region(region))
522               for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom))
523                  if (ROM_GETLENGTH(rom) == romlength)
524                  {
525                     hash_collection hashes(ROM_GETHASHDATA(rom));
526                     if (hashes == romhashes)
527                        highest_device = scandevice;
528                  }
516529      }
517      else
518      {
519         // iterate up the parent chain
520         for (int drvindex = m_enumerator.find(m_enumerator.driver().parent); drvindex != -1; drvindex = m_enumerator.find(m_enumerator.driver(drvindex).parent))
521            for (const rom_source *source = rom_first_source(m_enumerator.config(drvindex)); source != NULL; source = rom_next_source(*source))
522               for (const rom_entry *region = rom_first_region(*source); region; region = rom_next_region(region))
523                  for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom))
524                     if (ROM_GETLENGTH(rom) == romlength)
525                     {
526                        hash_collection hashes(ROM_GETHASHDATA(rom));
527                        if (hashes == romhashes)
528                           highest_source = source;
529                     }
530      }
531530   }
532531
533   return highest_source;
532   return highest_device;
534533}
535534
536535
r14546r14547
546545     m_name(ROM_GETNAME(&media)),
547546     m_explength(rom_file_size(&media)),
548547     m_length(0),
549     m_shared_source(NULL)
548     m_shared_device(NULL)
550549{
551550   m_exphashes.from_internal_string(ROM_GETHASHDATA(&media));
552551}
r14546r14547
559558     m_name(name),
560559     m_explength(0),
561560     m_length(0),
562     m_shared_source(NULL)
561     m_shared_device(NULL)
563562{
564563}
src/emu/audit.h
r14546r14547
114114   UINT64 actual_length() const { return m_length; }
115115   const hash_collection &expected_hashes() const { return m_exphashes; }
116116   const hash_collection &actual_hashes() const { return m_hashes; }
117   const rom_source *shared_source() const { return m_shared_source; }
117   device_t *shared_device() const { return m_shared_device; }
118118
119119   // setters
120120   void set_status(audit_status status, audit_substatus substatus)
r14546r14547
129129      m_length = length;
130130   }
131131
132   void set_shared_source(const rom_source *shared_source)
132   void set_shared_device(device_t *shared_device)
133133   {
134      m_shared_source = shared_source;
134      m_shared_device = shared_device;
135135   }
136136
137137private:
r14546r14547
145145   UINT64            m_length;            /* actual length of item */
146146   hash_collection      m_exphashes;          /* expected hash data */
147147   hash_collection      m_hashes;            /* actual hash information */
148   const rom_source *   m_shared_source;      /* rom_source that shares the rom */
148   device_t *         m_shared_device;      /* device that shares the rom */
149149};
150150
151151
r14546r14547
183183   audit_record *audit_one_rom(const rom_entry *rom);
184184   audit_record *audit_one_disk(const rom_entry *rom);
185185   void compute_status(audit_record &record, const rom_entry *rom, bool found);
186   const rom_source *find_shared_source(const rom_source *source, const hash_collection &romhashes, UINT64 romlength);
186   device_t *find_shared_device(device_t &device, const hash_collection &romhashes, UINT64 romlength);
187187
188188   // internal state
189189   simple_list<audit_record>   m_record_list;
src/emu/dimemory.c
r14546r14547
301301               device().siblingtag(entry_region, entry->m_region);
302302
303303               // look for the region
304               for (const rom_source *source = rom_first_source(device().mconfig()); source != NULL && !found; source = rom_next_source(*source))
305                  for (const rom_entry *romp = rom_first_region(*source); romp != NULL && !found; romp = rom_next_region(romp))
304               device_iterator deviter(device().mconfig().root_device());
305               for (device_t *device = deviter.first(); device != NULL; device = deviter.next())
306                  for (const rom_entry *romp = rom_first_region(*device); romp != NULL && !found; romp = rom_next_region(romp))
306307                  {
307308                     astring fulltag;
308                     rom_region_name(fulltag, &device().mconfig().gamedrv(), source, romp);
309                     rom_region_name(fulltag, *device, romp);
309310                     if (fulltag == entry_region)
310311                     {
311312                        // verify the address range is within the region's bounds
src/lib/util/avhuff.c
r14546r14547
318318//  bits
319319//-------------------------------------------------
320320
321avhuff_error avhuff_encoder::assemble_data(UINT8 *dest, UINT32 dlength, bitmap_yuy16 &bitmap, UINT8 channels, UINT32 numsamples, INT16 **samples, UINT8 *metadata, UINT32 metadatasize)
321avhuff_error avhuff_encoder::assemble_data(dynamic_buffer &buffer, bitmap_yuy16 &bitmap, UINT8 channels, UINT32 numsamples, INT16 **samples, UINT8 *metadata, UINT32 metadatasize)
322322{
323323   // sanity check the inputs
324324   if (metadatasize > 255)
r14546r14547
327327      return AVHERR_AUDIO_TOO_LARGE;
328328   if (bitmap.width() > 65535 || bitmap.height() > 65535)
329329      return AVHERR_VIDEO_TOO_LARGE;
330   if (dlength < 12 + metadatasize + numsamples * channels * 2 + bitmap.width() * bitmap.height() * 2)
331      return AVHERR_BUFFER_TOO_SMALL;
332330
333331   // fill in the header
332   buffer.resize(12 + metadatasize + numsamples * channels * 2 + bitmap.width() * bitmap.height() * 2);
333   UINT8 *dest = buffer;
334334   *dest++ = 'c';
335335   *dest++ = 'h';
336336   *dest++ = 'a';
src/lib/util/avhuff.h
r14546r14547
119119   // static helpers
120120   static UINT32 raw_data_size(const UINT8 *data);
121121   static UINT32 raw_data_size(UINT32 width, UINT32 height, UINT8 channels, UINT32 numsamples, UINT32 metadatasize = 0) { return 12 + channels * numsamples * 2 + width * height * 2; }
122   static avhuff_error assemble_data(UINT8 *dest, UINT32 dlength, bitmap_yuy16 &bitmap, UINT8 channels, UINT32 numsamples, INT16 **samples, UINT8 *metadata = NULL, UINT32 metadatasize = 0);
122   static avhuff_error assemble_data(dynamic_buffer &buffer, bitmap_yuy16 &bitmap, UINT8 channels, UINT32 numsamples, INT16 **samples, UINT8 *metadata = NULL, UINT32 metadatasize = 0);
123123
124124private:
125125   // delta-RLE Huffman encoder
makefile
r14546r14547
733733
734734ifndef EXECUTABLE_DEFINED
735735
736# always recompile the version string
737$(VERSIONOBJ): $(DRVLIBS) $(LIBOSD) $(LIBCPU) $(LIBEMU) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(ZLIB) $(7Z_LIB) $(SOFTFLOAT) $(FORMATS_LIB) $(LIBOCORE) $(RESFILE)
738
739736$(EMULATOR): $(VERSIONOBJ) $(EMUINFOOBJ) $(DRIVLISTOBJ) $(DEVLISTOBJ) $(DRVLIBS) $(LIBOSD) $(LIBCPU) $(LIBEMU) $(LIBDASM) $(LIBSOUND) $(LIBUTIL) $(EXPAT) $(SOFTFLOAT) $(JPEG_LIB) $(FLAC_LIB) $(7Z_LIB) $(FORMATS_LIB) $(ZLIB) $(LIBOCORE) $(RESFILE)
737   $(CC) $(CDEFS) $(CFLAGS) -c $(SRC)/version.c -o $(VERSIONOBJ)
740738   @echo Linking $@...
741739   $(LD) $(LDFLAGS) $(LDFLAGSEMULATOR) $^ $(LIBS) -o $@
742740ifeq ($(TARGETOS),win32)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team