Previous 15994 Revisions Next

r14531 Sunday 19th February, 2012 at 15:38:08 UTC by Miodrag Milanović
Sync with MAME r15452 (no whatsnew)
[src]version.c
[src/emu]clifront.c emuopts.c hash.c romload.c
[src/emu/cpu/m68000]m68k_in.c m68kmmu.h
[src/emu/machine]idectrl.c idectrl.h nscsi_bus.c nscsi_bus.h nscsi_hd.c
[src/emu/sound]samples.c samples.h votrax.c votrax.h
[src/emu/video]pc_vga.c
[src/ldplayer]ldplayer.c
[src/lib/formats]pc_dsk.c
[src/lib/lib7z]7z.h 7zCrc.c 7zIn.c Aes.c Alloc.c Bra.c Bra.h BraIA64.c BwtSort.c CpuArch.c HuffEnc.c HuffEnc.h LzFind.c LzFindMt.c LzFindMt.h Lzma2Dec.c Lzma2Enc.c Lzma86Enc.c LzmaDec.c LzmaDec.h LzmaEnc.c LzmaLib.h MtCoder.c MtCoder.h Ppmd.h Ppmd7.c Ppmd7.h Ppmd7Dec.c Ppmd7Enc.c Ppmd8.c Ppmd8.h Ppmd8Dec.c Ppmd8Enc.c Sha256.c Xz.h XzDec.c XzEnc.c XzIn.c x7zFile.c
[src/lib/util]avhuff.c avhuff.h bitstream.h cdrom.c chd.c chd.h chdcodec.c chdcodec.h coretmpl.h flac.c flac.h hashing.c hashing.h huffman.c huffman.h un7z.c
[src/mame/drivers]chihiro.c coolridr.c kungfur.c namcos21.c namcos23.c naomi.c neodrvr.c taitogn.c vamphalf.c
[src/mame/machine]n64.c
[src/mame/video]n64.c n64.h nmk16.c
[src/osd/sdl]sdl.mak
[src/osd/windows]winwork.c
[src/tools]chdman.c

src/mame/machine/n64.c
r14530r14531
19271927{
19281928   //printf("Before:\n");
19291929   /*for(int i = 0; i < 0x40; i++)
1930   {
1931      printf("%02x ", pif_cmd[i]);
1932      if((i & 0xf) == 0xf)
1933      {
1934         printf("\n");
1935      }
1936   }*/
1930    {
1931        printf("%02x ", pif_cmd[i]);
1932        if((i & 0xf) == 0xf)
1933        {
1934            printf("\n");
1935        }
1936    }*/
19371937   if(pif_cmd[0x3f] == 0x1)      // only handle the command if the last byte is 1
19381938   {
19391939      int channel = 0;
r14530r14531
20052005   }
20062006
20072007   /*printf("After:\n");
2008   for(int i = 0; i < 0x40; i++)
2009   {
2010      printf("%02x ", pif_ram[i]);
2011      if((i & 0xf) == 0xf)
2012      {
2013         printf("\n");
2014      }
2015   }*/
2008    for(int i = 0; i < 0x40; i++)
2009    {
2010        printf("%02x ", pif_ram[i]);
2011        if((i & 0xf) == 0xf)
2012        {
2013            printf("\n");
2014        }
2015    }*/
20162016}
20172017
20182018void n64_periphs::pif_dma(int direction)
src/mame/video/n64.c
r14530r14531
6868   {
6969      temp3 = (temp * temp2) + 4;
7070      userdata->CurrentPixCvg = (temp3 >> 8) & 0xf;
71    }
71   }
7272   if (object.OtherModes.alpha_cvg_select)
7373   {
7474      temp = (OtherModes.cvg_times_alpha) ? (temp3 >> 3) : (temp2 << 5);
r14530r14531
157157
158158            //if(divot)
159159            //{
160            //   if(i > 0 && i < (hres - 1))
161            //   {
162            //      prev_cvg = ((frame_buffer[(pixels - 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels - 1)^BYTE_ADDR_XOR] & 3);
163            //      next_cvg = ((frame_buffer[(pixels + 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels + 1)^BYTE_ADDR_XOR] & 3);
164            //   }
160            //  if(i > 0 && i < (hres - 1))
161            //  {
162            //      prev_cvg = ((frame_buffer[(pixels - 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels - 1)^BYTE_ADDR_XOR] & 3);
163            //      next_cvg = ((frame_buffer[(pixels + 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels + 1)^BYTE_ADDR_XOR] & 3);
164            //  }
165165            //}
166166            c.i.r = ((pix >> 8) & 0xf8) | (pix >> 13);
167167            c.i.g = ((pix >> 3) & 0xf8) | ((pix >>  8) & 0x07);
src/mame/video/n64.h
r14530r14531
370370   INT32            m_precomp_t;
371371   UINT8            BlendEnable;
372372   bool            PreWrap;
373   INT32             m_dzpix_enc;
373   INT32            m_dzpix_enc;
374374   UINT8            *m_tmem;            /* pointer to texture cache for this polygon */
375375   bool            m_start_span;
376376};
r14530r14531
594594
595595      UINT8 ReplicatedRGBA[32];
596596
597      Rectangle       Scissor;
597      Rectangle      Scissor;
598598      SpanBaseT      SpanBase;
599599
600      rectangle       visarea;
600      rectangle      visarea;
601601
602602      void         DrawTriangle(bool shade, bool texture, bool zbuffer, bool rect);
603      void          compute_cvg_noflip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base);
604      void          compute_cvg_flip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base);
603      void         compute_cvg_noflip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base);
604      void         compute_cvg_flip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base);
605605
606606      void*         AuxBuf;
607607      UINT32         AuxBufPtr;
r14530r14531
611611      UINT32         ExtentBufPtr[2];
612612      UINT32         ExtentBufIndex;
613613
614      bool          rdp_range_check(UINT32 addr);
614      bool         rdp_range_check(UINT32 addr);
615615
616616      N64Tile      m_tiles[8];
617617
src/mame/video/nmk16.c
r14530r14531
638638   0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
639639   };
640640   nmk16_draw_sprites2(screen.machine(), bitmap,cliprect, hachamf_swaptbl);
641/*   nmk16_draw_sprites(screen.machine(), bitmap,cliprect,3);
642   nmk16_draw_sprites(screen.machine(), bitmap,cliprect,2);
643   nmk16_draw_sprites(screen.machine(), bitmap,cliprect,1);
644   nmk16_draw_sprites(screen.machine(), bitmap,cliprect,0);*/
641/*  nmk16_draw_sprites(screen.machine(), bitmap,cliprect,3);
642    nmk16_draw_sprites(screen.machine(), bitmap,cliprect,2);
643    nmk16_draw_sprites(screen.machine(), bitmap,cliprect,1);
644    nmk16_draw_sprites(screen.machine(), bitmap,cliprect,0);*/
645645
646646   state->m_tx_tilemap->draw(bitmap, cliprect, 0,0);
647647   return 0;
src/mame/drivers/kungfur.c
r14530r14531
150150static WRITE8_DEVICE_HANDLER( kungfur_control_w )
151151{
152152   kungfur_state *state = device->machine().driver_data<kungfur_state>();
153   
153
154154   // d0-d3: N/C
155155   // d4: irq ack
156156   if (~data & 0x10)
r14530r14531
193193   kungfur_state *state = device->machine().driver_data<kungfur_state>();
194194   UINT8 *ROM = device->machine().region("adpcm1")->base();
195195   UINT8 data = ROM[state->m_adpcm_pos[0] & 0x1ffff];
196   
196
197197   msm5205_data_w(device, state->m_adpcm_sel[0] ? data & 0xf : data >> 4 & 0xf);
198198   state->m_adpcm_pos[0] += state->m_adpcm_sel[0];
199199   state->m_adpcm_sel[0] ^= 1;
r14530r14531
204204   kungfur_state *state = device->machine().driver_data<kungfur_state>();
205205   UINT8 *ROM = device->machine().region("adpcm2")->base();
206206   UINT8 data = ROM[state->m_adpcm_pos[1] & 0x3ffff];
207   
207
208208   msm5205_data_w(device, state->m_adpcm_sel[1] ? data & 0xf : data >> 4 & 0xf);
209209   state->m_adpcm_pos[1] += state->m_adpcm_sel[1];
210210   state->m_adpcm_sel[1] ^= 1;
r14530r14531
244244   PORT_DIPSETTING( 0x06, DEF_STR( 2C_1C ) )
245245   PORT_DIPSETTING( 0x07, DEF_STR( 1C_1C ) )
246246   PORT_DIPSETTING( 0x03, DEF_STR( 1C_2C ) )
247//   PORT_DIPSETTING( 0x01, DEF_STR( 1C_2C ) ) // dupe
247//  PORT_DIPSETTING( 0x01, DEF_STR( 1C_2C ) ) // dupe
248248   PORT_DIPSETTING( 0x02, DEF_STR( 1C_3C ) )
249//   PORT_DIPSETTING( 0x00, DEF_STR( 1C_3C ) ) // dupe
250//   PORT_DIPSETTING( 0x04, DEF_STR( 0C_0C ) ) // invalid
249//  PORT_DIPSETTING( 0x00, DEF_STR( 1C_3C ) ) // dupe
250//  PORT_DIPSETTING( 0x04, DEF_STR( 0C_0C ) ) // invalid
251251   PORT_SERVICE( 0x08, IP_ACTIVE_LOW )
252252   PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNUSED )
253253INPUT_PORTS_END
src/mame/drivers/namcos21.c
r14530r14531
21522152   ROM_LOAD("wrvoi-0.11b", 0x040000, 0x40000, CRC(8040b645) SHA1(7ccafb3073fa79910e26cf9b8b6e8e9ae22e55fc) )
21532153   ROM_LOAD("wrvoi-1.11c", 0x0c0000, 0x40000, CRC(d347e904) SHA1(620cd07e6230322c306283e45a43fa1e217028d4) )
21542154   ROM_LOAD("wrvoi-2.11d", 0x140000, 0x40000, CRC(b34747af) SHA1(7e0b55631bffa0583bf4f7f5368db9f09e411ba1) )
2155   ROM_LOAD("wrvoi-3.11e", 0x1c0000, 0x40000, CRC(43085303) SHA1(9f743055c20df3548879118194244e37a0b91f7e) )   
2155   ROM_LOAD("wrvoi-3.11e", 0x1c0000, 0x40000, CRC(43085303) SHA1(9f743055c20df3548879118194244e37a0b91f7e) )
21562156
21572157   ROM_REGION( 0x1000, "pals", 0 )
21582158   /* Main PCB (2252960101) */
r14530r14531
25412541GAME( 1992, aircomb,  0,       poly_c140_typeB,   aircombt,     aircombt, ROT0,    "Namco", "Air Combat (US)",                        GAME_NOT_WORKING | GAME_IMPERFECT_GRAPHICS )
25422542GAME( 1992, aircombj, aircomb, poly_c140_typeB,   aircombt,     aircombt, ROT0,    "Namco", "Air Combat (Japan)",                    GAME_NOT_WORKING | GAME_IMPERFECT_GRAPHICS )
25432543GAME( 1993, cybsled,  0,       poly_c140_typeA,   cybsled,      cybsled,  ROT0,    "Namco", "Cyber Sled (US)",                       GAME_IMPERFECT_GRAPHICS )
2544GAME( 1993, cybsledj, cybsled, poly_c140_typeA,   cybsled,      cybsled,  ROT0,    "Namco", "Cyber Sled (Japan)",                    GAME_IMPERFECT_GRAPHICS )
No newline at end of file
2544GAME( 1993, cybsledj, cybsled, poly_c140_typeA,   cybsled,      cybsled,  ROT0,    "Namco", "Cyber Sled (Japan)",                    GAME_IMPERFECT_GRAPHICS )
src/mame/drivers/namcos23.c
r14530r14531
967967      J104            - 6 pin connector joined with a cable to J6 on the V198 EMI PCB. This cable is the I/O connection to/from the main board.
968968      J105            - 110VAC power input
969969      J106            - DC variable power output to feed-back motor
970 
971 
970
971
972972Namco Gorgon-based games
973973------------------------
974974
src/mame/drivers/chihiro.c
r14530r14531
829829public:
830830    // construction/destruction
831831    ide_baseboard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
832   
832
833833   virtual int    read_sector(UINT32 lba, void *buffer);
834834   virtual int    write_sector(UINT32 lba, const void *buffer);
835835   virtual bool is_ready() { return true; }
src/mame/drivers/naomi.c
r14530r14531
68616861
68626862   ROM_REGION( 0x4300, "pic", ROMREGION_ERASEFF)
68636863   //PIC16C622A (317-0384-COM)
6864    ROM_LOAD( "317-0384-com.pic", 0x000000, 0x004300, CRC(081ccd51) SHA1(598b3bd9e8b16f5954d15738c1ca55703609b690) )
6864    ROM_LOAD( "317-0384-com.pic", 0x000000, 0x004300, CRC(081ccd51) SHA1(598b3bd9e8b16f5954d15738c1ca55703609b690) )
68656865ROM_END
68666866
68676867/*
r14530r14531
70627062
70637063    ROM_REGION( 0xb000000, "rom_board", ROMREGION_ERASEFF)
70647064    // Cart has a Sega factory EPROM sticker stating "EPR-23838C" and a Sega factory sticker stating "Rev. A".  Seriously.
7065    ROM_LOAD( "epr-23838c.ic22", 0x000000, 0x400000, CRC(5e5fb00f) SHA1(c5e81ebead9072cc08f09d1715d609cb0f7631ba) )
7065    ROM_LOAD( "epr-23838c.ic22", 0x000000, 0x400000, CRC(5e5fb00f) SHA1(c5e81ebead9072cc08f09d1715d609cb0f7631ba) )
70667066    ROM_RELOAD( 0x400000, 0x400000)
7067    ROM_LOAD( "ssf01.ic1s",   0x0800000, 0x800000, CRC(4f12f789) SHA1(7b79b687fc61e2e981b9e5e8e0939c4ad24a98f0) )
7068    ROM_LOAD( "ssf02.ic2s",   0x1000000, 0x800000, CRC(a255d41a) SHA1(3e932527eb68edf3e8538c1ad264a1c599f6a9d5) )
7069    ROM_LOAD( "ssf03.ic3s",   0x1800000, 0x800000, CRC(0f8d6577) SHA1(afaf440e667bacc941c0a5418a0e3b0f2bb725b7) )
7070    ROM_LOAD( "ssf04.ic4s",   0x2000000, 0x800000, CRC(bdf25bd0) SHA1(f79b1fdba9c48969c49617c43c1919637adb13ba) )
7071    ROM_LOAD( "ssf05.ic5s",   0x2800000, 0x800000, CRC(a74b3bb4) SHA1(0ce7cef849061a9af7a61d69dc633f6971a3a63d) )
7072    ROM_LOAD( "ssf06.ic6s",   0x3000000, 0x800000, CRC(3cd1f5d5) SHA1(77573c3a60af64e6e6a0eb85d5b8176ed98b0723) )
7073    ROM_LOAD( "ssf07.ic7s",   0x3800000, 0x800000, CRC(00d240f5) SHA1(43010fc596f2cdffdff35a6122f2ab02a5251bc0) )
7074    ROM_LOAD( "ssf08.ic8s",   0x4000000, 0x800000, CRC(d4907fa1) SHA1(79b1c771819f6e4baa048010bfb940a45370eba2) )
7075    ROM_LOAD( "ssf09.ic9s",   0x4800000, 0x800000, CRC(6327d49e) SHA1(a10e3c27f70dbf18e63cf51962b6a79a52eba26c) )
7076    ROM_LOAD( "ssf10.ic10s",  0x5000000, 0x800000, CRC(7975dc80) SHA1(81bda50968f0153a0c4432d8d81e817c1e82e5b2) )
7077    ROM_LOAD( "ssf11.ic11s",  0x5800000, 0x800000, CRC(a242f682) SHA1(435ea5bb1b3667f9ef3d7de081b15f4e8e6a0d01) )
7078    ROM_LOAD( "ssf12.ic12s",  0x6000000, 0x800000, CRC(45fa259e) SHA1(8d7e708e7a2cbc2d60b68715dd79bac28d894d4c) )
7079    ROM_LOAD( "ssf13.ic13s",  0x6800000, 0x800000, CRC(e9578063) SHA1(618f66d01f6bdacbf2a3242774a316b130594e02) )
7080    ROM_LOAD( "ssf14.ic14s",  0x7000000, 0x800000, CRC(2edc1311) SHA1(bceb54dd29012580e2e6f15f16c6b31195010153) )
7081    ROM_LOAD( "ssf15.ic15s",  0x7800000, 0x800000, CRC(416db320) SHA1(34536716a35260d9457703704bb9174fb1616d60) )
7082    ROM_LOAD( "ssf16.ic16s",  0x8000000, 0x800000, CRC(2530cc04) SHA1(6425c031e5a129a3c9451bc694b5da8553f154c2) )
7083    ROM_LOAD( "ssf17.ic17s",  0x8800000, 0x800000, CRC(9e6afcc2) SHA1(4fb69d834ea12c82e897af47a22dcc47f3c83768) )
7084    ROM_LOAD( "ssf18.ic18s",  0x9000000, 0x800000, CRC(854ed5e5) SHA1(e445599f6a9e9d05c279259307edc08bce5d6d1f) )
7085    ROM_LOAD( "ssf19.ic19s",  0x9800000, 0x800000, CRC(4f8ec86a) SHA1(406ab9eeccd99fa5515d4a2c229c8db1a5cb8f83) )
7086    ROM_LOAD( "ssf20.ic20s",  0xa000000, 0x800000, CRC(c90b960d) SHA1(66e9f09d1f7f6a991371574a2e095c0e22fb7031) )
7087    ROM_LOAD( "ssf21.ic21s",  0xa800000, 0x800000, CRC(1477c064) SHA1(87fb8d8a91d6bed70b246a8df88fa77fbf3db443) )
7067    ROM_LOAD( "ssf01.ic1s",   0x0800000, 0x800000, CRC(4f12f789) SHA1(7b79b687fc61e2e981b9e5e8e0939c4ad24a98f0) )
7068    ROM_LOAD( "ssf02.ic2s",   0x1000000, 0x800000, CRC(a255d41a) SHA1(3e932527eb68edf3e8538c1ad264a1c599f6a9d5) )
7069    ROM_LOAD( "ssf03.ic3s",   0x1800000, 0x800000, CRC(0f8d6577) SHA1(afaf440e667bacc941c0a5418a0e3b0f2bb725b7) )
7070    ROM_LOAD( "ssf04.ic4s",   0x2000000, 0x800000, CRC(bdf25bd0) SHA1(f79b1fdba9c48969c49617c43c1919637adb13ba) )
7071    ROM_LOAD( "ssf05.ic5s",   0x2800000, 0x800000, CRC(a74b3bb4) SHA1(0ce7cef849061a9af7a61d69dc633f6971a3a63d) )
7072    ROM_LOAD( "ssf06.ic6s",   0x3000000, 0x800000, CRC(3cd1f5d5) SHA1(77573c3a60af64e6e6a0eb85d5b8176ed98b0723) )
7073    ROM_LOAD( "ssf07.ic7s",   0x3800000, 0x800000, CRC(00d240f5) SHA1(43010fc596f2cdffdff35a6122f2ab02a5251bc0) )
7074    ROM_LOAD( "ssf08.ic8s",   0x4000000, 0x800000, CRC(d4907fa1) SHA1(79b1c771819f6e4baa048010bfb940a45370eba2) )
7075    ROM_LOAD( "ssf09.ic9s",   0x4800000, 0x800000, CRC(6327d49e) SHA1(a10e3c27f70dbf18e63cf51962b6a79a52eba26c) )
7076    ROM_LOAD( "ssf10.ic10s",  0x5000000, 0x800000, CRC(7975dc80) SHA1(81bda50968f0153a0c4432d8d81e817c1e82e5b2) )
7077    ROM_LOAD( "ssf11.ic11s",  0x5800000, 0x800000, CRC(a242f682) SHA1(435ea5bb1b3667f9ef3d7de081b15f4e8e6a0d01) )
7078    ROM_LOAD( "ssf12.ic12s",  0x6000000, 0x800000, CRC(45fa259e) SHA1(8d7e708e7a2cbc2d60b68715dd79bac28d894d4c) )
7079    ROM_LOAD( "ssf13.ic13s",  0x6800000, 0x800000, CRC(e9578063) SHA1(618f66d01f6bdacbf2a3242774a316b130594e02) )
7080    ROM_LOAD( "ssf14.ic14s",  0x7000000, 0x800000, CRC(2edc1311) SHA1(bceb54dd29012580e2e6f15f16c6b31195010153) )
7081    ROM_LOAD( "ssf15.ic15s",  0x7800000, 0x800000, CRC(416db320) SHA1(34536716a35260d9457703704bb9174fb1616d60) )
7082    ROM_LOAD( "ssf16.ic16s",  0x8000000, 0x800000, CRC(2530cc04) SHA1(6425c031e5a129a3c9451bc694b5da8553f154c2) )
7083    ROM_LOAD( "ssf17.ic17s",  0x8800000, 0x800000, CRC(9e6afcc2) SHA1(4fb69d834ea12c82e897af47a22dcc47f3c83768) )
7084    ROM_LOAD( "ssf18.ic18s",  0x9000000, 0x800000, CRC(854ed5e5) SHA1(e445599f6a9e9d05c279259307edc08bce5d6d1f) )
7085    ROM_LOAD( "ssf19.ic19s",  0x9800000, 0x800000, CRC(4f8ec86a) SHA1(406ab9eeccd99fa5515d4a2c229c8db1a5cb8f83) )
7086    ROM_LOAD( "ssf20.ic20s",  0xa000000, 0x800000, CRC(c90b960d) SHA1(66e9f09d1f7f6a991371574a2e095c0e22fb7031) )
7087    ROM_LOAD( "ssf21.ic21s",  0xa800000, 0x800000, CRC(1477c064) SHA1(87fb8d8a91d6bed70b246a8df88fa77fbf3db443) )
70887088ROM_END
70897089
70907090/*
r14530r14531
78557855/* 0062 */ GAME( 2002, clubkrte, naomi2,   naomi2,   naomi,    naomi2,   ROT0, "Sega", "Club Kart: European Session (Rev D)", GAME_UNEMULATED_PROTECTION|GAME_FLAGS )
78567856/* 0080 */ GAME( 2002, vf4cart,  naomi2,   naomi2m2, naomi,    naomi2,   ROT0, "Sega", "Virtua Fighter 4 (Cartridge)", GAME_UNEMULATED_PROTECTION|GAME_FLAGS )
78577857/* 0087 */ GAME( 2002, kingrt66, naomi2,   naomi2,   naomi,    naomi2,   ROT0, "Sega", "King of Route 66 (Rev A)", GAME_UNEMULATED_PROTECTION|GAME_FLAGS )
7858/* 0095 */ GAME( 2002, soulsurf, naomi2,   naomi2,   naomi,    naomi2,   ROT0, "Sega", "Soul Surfer (Rev A)", GAME_FLAGS )
7858/* 0095 */ GAME( 2002, soulsurf, naomi2,   naomi2,   naomi,    naomi2,   ROT0, "Sega", "Soul Surfer (Rev A)", GAME_FLAGS )
78597859/* 0106 */ GAME( 2002, vf4evoct, naomi2,   naomi2m1, naomi,    vf4evoct, ROT0, "Sega", "Virtua Fighter 4 Evolution (Cartridge)", GAME_UNEMULATED_PROTECTION|GAME_FLAGS )
78607860// 0129 Club Kart Prize
78617861
r14530r14531
79487948// 0032A Initial D Arcade Stage Ver. 3 (Japan) (Rev A)
79497949/* 0032B */ GAME( 2004, initdv3jb, initdv3j, naomigd, naomi,    naomi2,   ROT0, "Sega", "Initial D Arcade Stage Ver. 3 (Japan) (Rev. B) (GDS-0032B)", GAME_FLAGS )
79507950/* 0032C */ GAME( 2004, initdv3j,  naomi2,   naomi2gd,naomi,    naomi2,   ROT0, "Sega", "Initial D Arcade Stage Ver. 3 (Japan) (Rev. C) (GDS-0032C)", GAME_FLAGS )
7951/* 0033 */  GAME( 2004, initdv3e,  naomi2,   naomi2gd,naomi,    naomi2,   ROT0, "Sega", "Initial D Arcade Stage Ver. 3 (Export) (GDS-0033)", GAME_FLAGS )
7951/* 0033 */  GAME( 2004, initdv3e,  naomi2,   naomi2gd,naomi,    naomi2,   ROT0, "Sega", "Initial D Arcade Stage Ver. 3 (Export) (GDS-0033)", GAME_FLAGS )
79527952// 0034
79537953// 0035
79547954// 0036  Virtua Fighter 4 Final Tuned
src/mame/drivers/vamphalf.c
r14530r14531
16541654
16551655ROM_START( wyvernwga )
16561656   ROM_REGION32_BE( 0x100000, "user1", ROMREGION_ERASE00 ) /* Hyperstone CPU Code */
1657   ROM_LOAD( "rom1_alt.rom", 0x000000, 0x080000, CRC(586881fd) SHA1(d335bbd91def8fa4935eb2375c9b00471a1f40eb) )
1658   ROM_LOAD( "rom2_alt.rom", 0x080000, 0x080000, CRC(938049ec) SHA1(cc10944c99ceb388dd4aafc93377c40540861d14) )
1657   ROM_LOAD( "rom1_alt.rom", 0x000000, 0x080000, CRC(586881fd) SHA1(d335bbd91def8fa4935eb2375c9b00471a1f40eb) )
1658   ROM_LOAD( "rom2_alt.rom", 0x080000, 0x080000, CRC(938049ec) SHA1(cc10944c99ceb388dd4aafc93377c40540861d14) )
16591659
16601660   ROM_REGION( 0x020000, "audiocpu", 0 ) /* QDSP ('51) Code */
16611661   ROM_LOAD( "u7", 0x0000, 0x20000, CRC(00a3f705) SHA1(f0a6bafd16bea53d4c05c8cc108983cbd41e5757) )
src/mame/drivers/neodrvr.c
r14530r14531
88898889
88908890   ROM_REGION( 0x800000, "ymsnd", 0 )
88918891   ROM_LOAD( "12a.bin", 0x000000, 0x400000, CRC(c96723b9) SHA1(52eec88550781d45f84efbf9b905d7e7912e96fa) )
8892   ROM_LOAD( "13a.bin", 0x400000, 0x400000, CRC(08c339a5) SHA1(badc9510ae243ef2a7877977eb36efa81b1489fe) )
8892   ROM_LOAD( "13a.bin", 0x400000, 0x400000, CRC(08c339a5) SHA1(badc9510ae243ef2a7877977eb36efa81b1489fe) )
88938893
88948894   NO_DELTAT_REGION
88958895
src/mame/drivers/coolridr.c
r14530r14531
430430      case 0x04:
431431      {
432432         state->m_blitterMode = (data & 0x00ff0000) >> 16;
433         
433
434434         if (state->m_blitterMode == 0xf4)
435435         {
436436            // Some sort of addressing state.
r14530r14531
456456         }
457457         break;
458458      }
459         
459
460460      // The data register
461461      case 0x05:
462462      {
r14530r14531
470470            // DEBUG: Uncomment to see the ASCII strings as they are being blitted
471471            //if (state->m_blitterSerialCount >= state->m_textBytesToWrite)
472472            //{
473            //   for (int i = 0; i < state->m_textBytesToWrite+1; i++)
474            //      printf("%c", space->read_byte(0x03f40000 + state->m_textOffset + i));
475            //   printf("\n");
473            //  for (int i = 0; i < state->m_textBytesToWrite+1; i++)
474            //      printf("%c", space->read_byte(0x03f40000 + state->m_textOffset + i));
475            //  printf("\n");
476476            //}
477477         }
478478         else if (state->m_blitterMode == 0x30 || state->m_blitterMode == 0x90)
r14530r14531
511511            }
512512            else if (state->m_blitterSerialCount == 11)
513513            {
514               const UINT32 memOffset = data;
515               
514               const UINT32 memOffset = data;
515
516516               // Splat some sprites
517517               for (int h = 0; h < state->m_hCellCount; h++)
518518               {
r14530r14531
520520                  {
521521                     const int pixelOffsetX = state->m_hPosition + (h*16);
522522                     const int pixelOffsetY = state->m_vPosition + (v*16);
523                     
523
524524                     // It's unknown if it's row-major or column-major
525525                     // TODO: Study the CRT test and "Cool Riders" logo for clues.
526526                     UINT8 spriteNumber = space->read_byte(memOffset + h + (v*h));
527                     
527
528528                     // DEBUG: For demo purposes, skip spaces and NULL characters
529529                     if (spriteNumber == 0x20 || spriteNumber == 0x00)
530530                        continue;
r14530r14531
541541                              color = 0xff00ff00;
542542                           else if (state->m_colorNumber == 0x5e)
543543                              color = 0xff0000ff;
544                           else
544                           else
545545                              color = 0xff00ffff;
546546                           state->m_temp_bitmap_sprites.pix32(pixelOffsetY+y, pixelOffsetX+x) = color;
547547                        }
r14530r14531
549549                  }
550550               }
551551            }
552           
552
553553            state->m_blitterSerialCount++;
554554         }
555555         break;
src/mame/drivers/taitogn.c
r14530r14531
451451   taitogn_state *state = space->machine().driver_data<taitogn_state>();
452452
453453   if(offset >= 0x140 && offset <= 0x144) {
454      dynamic_buffer key;   
454      dynamic_buffer key;
455455
456456      int pos = (offset - 0x140)*2;
457457      UINT8 v, k;
src/tools/chdman.c
r14530r14531
215215      : m_file(file),
216216        m_offset(offset),
217217        m_maxoffset(MIN(maxoffset, (file != NULL) ? core_fsize(file) : 0)) { }
218   
218
219219   // read interface
220220   virtual UINT32 read_data(void *dest, UINT64 offset, UINT32 length)
221221   {
r14530r14531
247247        m_offset(offset),
248248        m_maxoffset(MIN(maxoffset, file.logical_bytes())) { }
249249
250   // read interface   
250   // read interface
251251   virtual UINT32 read_data(void *dest, UINT64 offset, UINT32 length)
252252   {
253253      offset += m_offset;
r14530r14531
279279      : m_file(NULL),
280280        m_toc(toc),
281281        m_info(info) { }
282       
282
283283   ~chd_cd_compressor()
284284   {
285285      if (m_file != NULL)
286286         core_fclose(m_file);
287287   }
288288
289   // read interface   
289   // read interface
290290   virtual UINT32 read_data(void *_dest, UINT64 offset, UINT32 length)
291291   {
292292      // verify assumptions made below
293293      assert(offset % CD_FRAME_SIZE == 0);
294294      assert(length % CD_FRAME_SIZE == 0);
295   
295
296296      // initialize destination to 0 so that unused areas are filled
297297      UINT8 *dest = reinterpret_cast<UINT8 *>(_dest);
298298      memset(dest, 0, length);
299   
299
300300      // find out which track we're starting in
301301      UINT64 startoffs = 0;
302302      UINT32 length_remaining = length;
r14530r14531
316316               if (filerr != FILERR_NONE)
317317                  report_error(1, "Error opening input file (%s)'", m_lastfile.cstr());
318318            }
319           
319
320320            // iterate over frames
321321            UINT32 bytesperframe = trackinfo.datasize + trackinfo.subsize;
322322            UINT64 src_track_start = m_info.track[tracknum].offset;
r14530r14531
332332                  UINT32 count = core_fread(m_file, dest, bytesperframe);
333333                  if (count != bytesperframe)
334334                     report_error(1, "Error reading input file (%s)'", m_lastfile.cstr());
335                     
335
336336                  // swap if appropriate
337337                  if (m_info.track[tracknum].swap)
338338                     for (UINT32 swapindex = 0; swapindex < 2352; swapindex += 2)
r14530r14531
342342                        dest[swapindex + 1] = temp;
343343                     }
344344               }
345               
345
346346               // advance
347347               offset += CD_FRAME_SIZE;
348348               dest += CD_FRAME_SIZE;
r14530r14531
351351                  break;
352352            }
353353         }
354         
354
355355         // next track starts after the previous one
356356         startoffs = endoffs;
357357      }
r14530r14531
381381        m_frame_count(num_frames),
382382        m_ldframedata(num_frames * VBI_PACKED_BYTES),
383383        m_rawdata(info.bytes_per_frame) { }
384     
384
385385   // getters
386386   const dynamic_buffer &ldframedata() const { return m_ldframedata; }
387   
388   // read interface   
387
388   // read interface
389389   virtual UINT32 read_data(void *_dest, UINT64 offset, UINT32 length)
390390   {
391391      UINT8 *dest = reinterpret_cast<UINT8 *>(_dest);
r14530r14531
402402            INT32 effframe = m_start_frame + framenum;
403403            UINT32 first_sample = (UINT64(m_info.rate) * UINT64(effframe) * UINT64(1000000) + m_info.fps_times_1million - 1) / UINT64(m_info.fps_times_1million);
404404            UINT32 samples = (UINT64(m_info.rate) * UINT64(effframe + 1) * UINT64(1000000) + m_info.fps_times_1million - 1) / UINT64(m_info.fps_times_1million) - first_sample;
405           
405
406406            // loop over channels and read the samples
407407            int channels = MIN(m_info.channels, ARRAY_LENGTH(m_audio));
408408            INT16 *samplesptr[ARRAY_LENGTH(m_audio)];
r14530r14531
437437            UINT32 rawsize = avhuff_encoder::raw_data_size(m_rawdata);
438438            if (rawsize < m_rawdata.count())
439439               memset(&m_rawdata[rawsize], 0, m_rawdata.count() - rawsize);
440           
440
441441            // copy to the destination
442442            UINT64 start_offset = UINT64(framenum) * UINT64(m_info.bytes_per_frame);
443443            UINT64 end_offset = start_offset + m_info.bytes_per_frame;
444444            UINT32 bytes_to_copy = MIN(length_remaining, end_offset - offset);
445445            memcpy(dest, &m_rawdata[offset - start_offset], bytes_to_copy);
446           
446
447447            // advance
448448            offset += bytes_to_copy;
449449            dest += bytes_to_copy;
r14530r14531
519519// descriptions for each command
520520static const command_description s_commands[] =
521521{
522   { COMMAND_INFO, do_info, ": displays information about a CHD",
522   { COMMAND_INFO, do_info, ": displays information about a CHD",
523523      {
524524         REQUIRED OPTION_INPUT,
525525         OPTION_VERBOSE
526      }
526      }
527527   },
528   
529   { COMMAND_VERIFY, do_verify, ": verifies a CHD's integrity",
528
529   { COMMAND_VERIFY, do_verify, ": verifies a CHD's integrity",
530530      {
531531         REQUIRED OPTION_INPUT,
532532         OPTION_INPUT_PARENT
533      }
533      }
534534   },
535   
536   { COMMAND_CREATE_RAW, do_create_raw, ": create a raw CHD from the input file",
535
536   { COMMAND_CREATE_RAW, do_create_raw, ": create a raw CHD from the input file",
537537      {
538         REQUIRED OPTION_OUTPUT,
538         REQUIRED OPTION_OUTPUT,
539539         OPTION_OUTPUT_PARENT,
540540         OPTION_OUTPUT_FORCE,
541         REQUIRED OPTION_INPUT,
542         OPTION_INPUT_START_BYTE,
543         OPTION_INPUT_START_HUNK,
544         OPTION_INPUT_LENGTH_BYTES,
541         REQUIRED OPTION_INPUT,
542         OPTION_INPUT_START_BYTE,
543         OPTION_INPUT_START_HUNK,
544         OPTION_INPUT_LENGTH_BYTES,
545545         OPTION_INPUT_LENGTH_HUNKS,
546546         REQUIRED OPTION_HUNK_SIZE,
547547         REQUIRED OPTION_UNIT_SIZE,
r14530r14531
551551#endif
552552      }
553553   },
554   
555   { COMMAND_CREATE_HD, do_create_hd, ": create a hard disk CHD from the input file",
554
555   { COMMAND_CREATE_HD, do_create_hd, ": create a hard disk CHD from the input file",
556556      {
557         REQUIRED OPTION_OUTPUT,
557         REQUIRED OPTION_OUTPUT,
558558         OPTION_OUTPUT_PARENT,
559559         OPTION_OUTPUT_FORCE,
560         OPTION_INPUT,
561         OPTION_INPUT_START_BYTE,
562         OPTION_INPUT_START_HUNK,
563         OPTION_INPUT_LENGTH_BYTES,
560         OPTION_INPUT,
561         OPTION_INPUT_START_BYTE,
562         OPTION_INPUT_START_HUNK,
563         OPTION_INPUT_LENGTH_BYTES,
564564         OPTION_INPUT_LENGTH_HUNKS,
565565         OPTION_HUNK_SIZE,
566566         OPTION_COMPRESSION,
r14530r14531
572572#endif
573573      }
574574   },
575   
576   { COMMAND_CREATE_CD, do_create_cd, ": create a CD CHD from the input file",
575
576   { COMMAND_CREATE_CD, do_create_cd, ": create a CD CHD from the input file",
577577      {
578         REQUIRED OPTION_OUTPUT,
578         REQUIRED OPTION_OUTPUT,
579579         OPTION_OUTPUT_PARENT,
580580         OPTION_OUTPUT_FORCE,
581         REQUIRED OPTION_INPUT,
581         REQUIRED OPTION_INPUT,
582582         OPTION_HUNK_SIZE,
583583         OPTION_COMPRESSION,
584584#if NUM_PROCESSORS_SUPPORTED
r14530r14531
586586#endif
587587      }
588588   },
589   
590   { COMMAND_CREATE_LD, do_create_ld, ": create a laserdisc CHD from the input file",
589
590   { COMMAND_CREATE_LD, do_create_ld, ": create a laserdisc CHD from the input file",
591591      {
592         REQUIRED OPTION_OUTPUT,
592         REQUIRED OPTION_OUTPUT,
593593         OPTION_OUTPUT_PARENT,
594594         OPTION_OUTPUT_FORCE,
595         REQUIRED OPTION_INPUT,
595         REQUIRED OPTION_INPUT,
596596         OPTION_INPUT_START_FRAME,
597597         OPTION_INPUT_LENGTH_FRAMES,
598598         OPTION_HUNK_SIZE,
r14530r14531
602602#endif
603603      }
604604   },
605   
606   { COMMAND_EXTRACT_RAW, do_extract_raw, ": extract raw file from a CHD input file",
605
606   { COMMAND_EXTRACT_RAW, do_extract_raw, ": extract raw file from a CHD input file",
607607      {
608         REQUIRED OPTION_OUTPUT,
608         REQUIRED OPTION_OUTPUT,
609609         OPTION_OUTPUT_FORCE,
610         REQUIRED OPTION_INPUT,
611         OPTION_INPUT_PARENT,
612         OPTION_INPUT_START_BYTE,
613         OPTION_INPUT_START_HUNK,
614         OPTION_INPUT_LENGTH_BYTES,
610         REQUIRED OPTION_INPUT,
611         OPTION_INPUT_PARENT,
612         OPTION_INPUT_START_BYTE,
613         OPTION_INPUT_START_HUNK,
614         OPTION_INPUT_LENGTH_BYTES,
615615         OPTION_INPUT_LENGTH_HUNKS
616616      }
617617   },
618   
619   { COMMAND_EXTRACT_HD, do_extract_raw, ": extract raw hard disk file from a CHD input file",
618
619   { COMMAND_EXTRACT_HD, do_extract_raw, ": extract raw hard disk file from a CHD input file",
620620      {
621         REQUIRED OPTION_OUTPUT,
621         REQUIRED OPTION_OUTPUT,
622622         OPTION_OUTPUT_FORCE,
623         REQUIRED OPTION_INPUT,
624         OPTION_INPUT_PARENT,
625         OPTION_INPUT_START_BYTE,
626         OPTION_INPUT_START_HUNK,
627         OPTION_INPUT_LENGTH_BYTES,
623         REQUIRED OPTION_INPUT,
624         OPTION_INPUT_PARENT,
625         OPTION_INPUT_START_BYTE,
626         OPTION_INPUT_START_HUNK,
627         OPTION_INPUT_LENGTH_BYTES,
628628         OPTION_INPUT_LENGTH_HUNKS
629629      }
630630   },
631   
632   { COMMAND_EXTRACT_CD, do_extract_cd, ": extract CD file from a CHD input file",
631
632   { COMMAND_EXTRACT_CD, do_extract_cd, ": extract CD file from a CHD input file",
633633      {
634         REQUIRED OPTION_OUTPUT,
635         OPTION_OUTPUT_BIN,
634         REQUIRED OPTION_OUTPUT,
635         OPTION_OUTPUT_BIN,
636636         OPTION_OUTPUT_FORCE,
637637         REQUIRED OPTION_INPUT,
638         OPTION_INPUT_PARENT,
638         OPTION_INPUT_PARENT,
639639      }
640640   },
641   
642   { COMMAND_EXTRACT_LD, do_extract_ld, ": extract laserdisc AVI from a CHD input file",
641
642   { COMMAND_EXTRACT_LD, do_extract_ld, ": extract laserdisc AVI from a CHD input file",
643643      {
644         REQUIRED OPTION_OUTPUT,
644         REQUIRED OPTION_OUTPUT,
645645         OPTION_OUTPUT_FORCE,
646         REQUIRED OPTION_INPUT,
647         OPTION_INPUT_PARENT,
648         OPTION_INPUT_START_FRAME,
646         REQUIRED OPTION_INPUT,
647         OPTION_INPUT_PARENT,
648         OPTION_INPUT_START_FRAME,
649649         OPTION_INPUT_LENGTH_FRAMES
650650      }
651651   },
652   
653   { COMMAND_COPY, do_copy, ": copy data from one CHD to another of the same type",
652
653   { COMMAND_COPY, do_copy, ": copy data from one CHD to another of the same type",
654654      {
655         REQUIRED OPTION_OUTPUT,
655         REQUIRED OPTION_OUTPUT,
656656         OPTION_OUTPUT_PARENT,
657657         OPTION_OUTPUT_FORCE,
658         REQUIRED OPTION_INPUT,
658         REQUIRED OPTION_INPUT,
659659         OPTION_INPUT_PARENT,
660         OPTION_INPUT_START_BYTE,
661         OPTION_INPUT_START_HUNK,
660         OPTION_INPUT_START_BYTE,
661         OPTION_INPUT_START_HUNK,
662662         OPTION_INPUT_LENGTH_BYTES,
663663         OPTION_INPUT_LENGTH_HUNKS,
664664         OPTION_HUNK_SIZE,
r14530r14531
668668#endif
669669      }
670670   },
671   
672   { COMMAND_ADD_METADATA, do_add_metadata, ": add metadata to the CHD",
671
672   { COMMAND_ADD_METADATA, do_add_metadata, ": add metadata to the CHD",
673673      {
674         REQUIRED OPTION_INPUT,
674         REQUIRED OPTION_INPUT,
675675         REQUIRED OPTION_TAG,
676676         OPTION_INDEX,
677677         OPTION_VALUE_TEXT,
r14530r14531
679679         OPTION_NO_CHECKSUM
680680      }
681681   },
682   
683   { COMMAND_DEL_METADATA, do_del_metadata, ": remove metadata from the CHD",
682
683   { COMMAND_DEL_METADATA, do_del_metadata, ": remove metadata from the CHD",
684684      {
685         REQUIRED OPTION_INPUT,
685         REQUIRED OPTION_INPUT,
686686         REQUIRED OPTION_TAG,
687687         OPTION_INDEX
688688      }
r14530r14531
708708   fflush(stderr);
709709   va_end(arg);
710710   fprintf(stderr, "\n");
711   
711
712712   // reset time for progress and return the error
713713   lastprogress = 0;
714714   throw fatal_error(error);
r14530r14531
782782      bool required = (option[0] == REQUIRED[0]);
783783      if (required)
784784         option++;
785     
785
786786      // find the option
787787      for (int optnum = 0; optnum < ARRAY_LENGTH(s_options); optnum++)
788788         if (strcmp(option, s_options[optnum].name) == 0)
r14530r14531
807807   // 0 is a special case
808808   if (intvalue == 0)
809809      return string.cpy("0");
810   
810
811811   // loop until all chunks are done
812812   string.reset();
813813   bool first = true;
r14530r14531
815815   {
816816      int chunk = intvalue % 1000;
817817      intvalue /= 1000;
818     
818
819819      astring insert;
820820      insert.format((intvalue != 0) ? "%03d" : "%d", chunk);
821821
r14530r14531
850850   int length = strlen(string);
851851   if (length == 0)
852852      return 0;
853   
853
854854   // scan forward over digits
855855   UINT64 result = 0;
856856   while (isdigit(*string))
r14530r14531
858858      result = (result * 10) + (*string - '0');
859859      string++;
860860   }
861   
861
862862   // handle multipliers
863863   if (*string == 'k' || *string == 'K')
864864      result *= 1024;
r14530r14531
866866      result *= 1024 * 1024;
867867   if (*string == 'g' || *string == 'G')
868868      result *= 1024 * 1024 * 1024;
869   
869
870870   return result;
871871}
872872
r14530r14531
881881   // if this is a direct physical drive read, handle it specially
882882   if (filename != NULL && osd_get_physical_drive_geometry(*filename, &cylinders, &heads, &sectors, &bps))
883883      return;
884   
884
885885   // if we have no length to work with, we can't guess
886886   if (filesize == 0)
887887      report_error(1, "Can't guess CHS values because there is no input file");
r14530r14531
913913
914914
915915//-------------------------------------------------
916//  parse_input_chd_parameters - parse the
916//  parse_input_chd_parameters - parse the
917917//  standard set of input CHD parameters
918918//-------------------------------------------------
919919
r14530r14531
962962      input_start = parse_number(*input_start_frame_str) * framebytes;
963963   if (input_start >= input_end)
964964      report_error(1, "Input start offset greater than input file size");
965   
965
966966   // process input length
967967   astring *input_length_bytes_str = params.find(OPTION_INPUT_LENGTH_BYTES);
968968   astring *input_length_hunks_str = params.find(OPTION_INPUT_LENGTH_HUNKS);
r14530r14531
10011001
10021002
10031003//-------------------------------------------------
1004//  parse_output_chd_parameters - parse the
1004//  parse_output_chd_parameters - parse the
10051005//  standard set of output CHD parameters
10061006//-------------------------------------------------
10071007
r14530r14531
10251025
10261026
10271027//-------------------------------------------------
1028//  parse_hunk_size - parse the hunk_size
1028//  parse_hunk_size - parse the hunk_size
10291029//  parameter in a standard way
10301030//-------------------------------------------------
10311031
r14530r14531
10441044
10451045
10461046//-------------------------------------------------
1047//  parse_compression - parse a standard
1047//  parse_compression - parse a standard
10481048//  compression parameter string
10491049//-------------------------------------------------
10501050
r14530r14531
10611061      compression[0] = compression[1] = compression[2] = compression[3] = CHD_CODEC_NONE;
10621062      return;
10631063   }
1064   
1064
10651065   // iterate through compressors
10661066   int index = 0;
10671067   for (int start = 0, end = compression_str->chr(0, ','); index < 4; start = end + 1, end = compression_str->chr(end + 1, ','))
r14530r14531
11121112   string.reset();
11131113   if (compression[0] == CHD_CODEC_NONE)
11141114      return string.cpy("none");
1115   
1115
11161116   // iterate over types
11171117   for (int index = 0; index < 4; index++)
11181118   {
r14530r14531
11261126   }
11271127   return string;
11281128}
1129     
11301129
1130
11311131//-------------------------------------------------
11321132//  compress_common - standard compression loop
11331133//-------------------------------------------------
r14530r14531
11371137   // begin compressing
11381138   chd.compress_begin();
11391139
1140   // loop until done   
1140   // loop until done
11411141   double complete, ratio;
11421142   chd_error err;
11431143   while ((err = chd.compress_continue(complete, ratio)) == CHDERR_WALKING_PARENT || err == CHDERR_COMPRESSING)
r14530r14531
11901190            tempstr.cpy("AUDIO");
11911191            break;
11921192      }
1193     
1193
11941194      // output TRACK entry
11951195      core_fprintf(file, "  TRACK %02d %s\n", tracknum + 1, tempstr.cstr());
11961196
r14530r14531
12051205      if (info.postgap > 0)
12061206         core_fprintf(file, "    POSTGAP %s\n", msf_string_from_frames(tempstr, info.postgap));
12071207   }
1208   
1208
12091209   // non-CUE mode
12101210   else
12111211   {
r14530r14531
13041304      chd_error err = input_chd.read_metadata(CHDMETATAG_WILDCARD, index, buffer, metatag, metaflags);
13051305      if (err != CHDERR_NONE)
13061306         break;
1307     
1307
13081308      // determine our index
13091309      UINT32 metaindex = ~0;
13101310      for (int cur = 0; cur < info.count(); cur++)
r14530r14531
13131313            metaindex = ++info[cur].index;
13141314            break;
13151315         }
1316     
1316
13171317      // if not found, add to our tracking
13181318      if (metaindex == ~0)
13191319      {
r14530r14531
13351335         printf("%c", isprint(UINT8(buffer[chnum])) ? buffer[chnum] : '.');
13361336      printf("\n");
13371337   }
1338   
1338
13391339   // print compression stats if verbose
13401340   if (params.find(OPTION_VERBOSE) != NULL)
13411341   {
r14530r14531
13481348         chd_error err = input_chd.hunk_info(hunknum, codec, compbytes);
13491349         if (err != CHDERR_NONE)
13501350            report_error(1, "Error getting info on hunk %d: %s", hunknum, chd_file::error_string(err));
1351         
1351
13521352         // decode into our data
13531353         if (codec > CHD_CODEC_MINI)
13541354            for (int comptype = 0; comptype < 4; comptype++)
r14530r14531
13591359               }
13601360         if (codec > ARRAY_LENGTH(compression_types))
13611361            codec = ARRAY_LENGTH(compression_types) - 1;
1362         
1362
13631363         // count stats
13641364         compression_types[codec]++;
13651365      }
1366     
1366
13671367      // output the stats
13681368      printf("\n");
13691369      printf("     Hunks  Percent  Name\n");
r14530r14531
13851385                     name = chd_codec_list::codec_name(input_chd.compression(index));
13861386                  break;
13871387            }
1388           
1388
13891389            // output the stats
13901390            astring tempstr;
1391            printf("%10s   %5.1f%%  %-40s\n",
1391            printf("%10s   %5.1f%%  %-40s\n",
13921392                  big_int_string(tempstr, compression_types[comptype]),
13931393                  100.0 * double(compression_types[comptype]) / double(input_chd.hunk_count()),
13941394                  name);
r14530r14531
14171417
14181418   // create an array to read into
14191419   dynamic_buffer buffer((TEMP_BUFFER_SIZE / input_chd.hunk_bytes()) * input_chd.hunk_bytes());
1420   
1420
14211421   // read all the data and build up an SHA-1
14221422   sha1_creator rawsha1;
14231423   for (UINT64 offset = 0; offset < input_chd.logical_bytes(); )
r14530r14531
14291429      chd_error err = input_chd.read_bytes(offset, buffer, bytes_to_read);
14301430      if (err != CHDERR_NONE)
14311431         report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->cstr(), chd_file::error_string(err));
1432     
1432
14331433      // add to the checksum
14341434      rawsha1.append(buffer, bytes_to_read);
14351435      offset += bytes_to_read;
14361436   }
14371437   sha1_t computed_sha1 = rawsha1.finish();
1438   
1438
14391439   // finish up
14401440   if (raw_sha1 != computed_sha1)
14411441   {
r14530r14531
14531453   else
14541454   {
14551455      printf("Raw SHA1 verification successful!\n");
1456   
1456
14571457      // now include the metadata for >= v4
14581458      if (input_chd.version() >= 4)
14591459      {
r14530r14531
14981498   // process output CHD
14991499   chd_file output_parent;
15001500   astring *output_chd_str = parse_output_chd_parameters(params, output_parent);
1501   
1501
15021502   // process hunk size
15031503   UINT32 hunk_size = output_parent.opened() ? output_parent.hunk_bytes() : 0;
15041504   parse_hunk_size(params, 1, hunk_size);
r14530r14531
15171517   UINT64 input_start;
15181518   UINT64 input_end;
15191519   parse_input_start_end(params, core_fsize(input_file), hunk_size, hunk_size, input_start, input_end);
1520   
1520
15211521   // process compression
15221522   chd_codec_type compression[4];
15231523   memcpy(compression, s_default_raw_compression, sizeof(compression));
15241524   parse_compression(params, compression);
1525   
1525
15261526   // process numprocessors
15271527   parse_numprocessors(params);
15281528
r14530r14531
15531553         err = chd.create(*output_chd_str, input_end - input_start, hunk_size, unit_size, compression);
15541554      if (err != CHDERR_NONE)
15551555         report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err));
1556     
1556
15571557      // if we have a parent, copy forward all the metadata
15581558      if (output_parent.opened())
15591559         chd.clone_all_metadata(output_parent);
r14530r14531
15881588      if (filerr != FILERR_NONE)
15891589         report_error(1, "Unable to open file (%s)", input_file_str->cstr());
15901590   }
1591   
1591
15921592   // process output CHD
15931593   chd_file output_parent;
15941594   astring *output_chd_str = parse_output_chd_parameters(params, output_parent);
1595   
1595
15961596   // process sectorsize
15971597   UINT32 sector_size = output_parent.opened() ? output_parent.unit_bytes() : IDE_SECTOR_SIZE;
15981598   astring *sectorsize_str = params.find(OPTION_SECTOR_SIZE);
r14530r14531
16021602         report_error(1, "Sector size does not apply when creating a diff from the parent");
16031603      sector_size = parse_number(*sectorsize_str);
16041604   }
1605   
1605
16061606   // process hunk size (needs to know sector_size)
16071607   UINT32 hunk_size = output_parent.opened() ? output_parent.hunk_bytes() : MAX((4096 / sector_size) * sector_size, sector_size);
16081608   parse_hunk_size(params, sector_size, hunk_size);
1609   
1609
16101610   // process input start/end (needs to know hunk_size)
16111611   UINT64 input_start;
16121612   UINT64 input_end;
16131613   parse_input_start_end(params, core_fsize(input_file), hunk_size, hunk_size, input_start, input_end);
1614   
1614
16151615   // process compression
16161616   chd_codec_type compression[4];
16171617   memcpy(compression, s_default_hd_compression, sizeof(compression));
r14530r14531
16561656      heads = (identdata[7] << 8) | identdata[6];
16571657      sectors = (identdata[13] << 8) | identdata[12];
16581658   }
1659   
1659
16601660   // extract geometry from the parent if we have one
16611661   if (output_parent.opened() && cylinders == 0)
16621662   {
r14530r14531
16661666      if (sscanf(metadata, HARD_DISK_METADATA_FORMAT, &cylinders, &heads, &sectors, &sector_size) != 4)
16671667         report_error(1, "Error parsing hard disk metadata in parent CHD");
16681668   }
1669   
1669
16701670   // if no CHS values, try to guess them
16711671   if (cylinders == 0)
16721672   {
r14530r14531
16751675      guess_chs(input_file_str, input_end - input_start, sector_size, cylinders, heads, sectors, sector_size);
16761676   }
16771677   UINT32 totalsectors = cylinders * heads * sectors;
1678   
1678
16791679   // print some info
16801680   astring tempstr;
16811681   printf("Output CHD:   %s\n", output_chd_str->cstr());
r14530r14531
17581758      if (err != CHDERR_NONE)
17591759         report_error(1, "Error parsing input file (%s: %s\n", input_file_str->cstr(), chd_file::error_string(err));
17601760   }
1761   
1761
17621762   // process output CHD
17631763   chd_file output_parent;
17641764   astring *output_chd_str = parse_output_chd_parameters(params, output_parent);
r14530r14531
17661766   // process hunk size
17671767   UINT32 hunk_size = output_parent.opened() ? output_parent.hunk_bytes() : CD_FRAMES_PER_HUNK * CD_FRAME_SIZE;
17681768   parse_hunk_size(params, CD_FRAME_SIZE, hunk_size);
1769   
1769
17701770   // process compression
17711771   chd_codec_type compression[4];
17721772   memcpy(compression, s_default_cd_compression, sizeof(compression));
r14530r14531
18471847         report_error(1, "Error opening AVI file (%s): %s\n", input_file_str->cstr(), avi_error_string(avierr));
18481848   }
18491849   const avi_movie_info *aviinfo = avi_get_movie_info(input_file);
1850   
1850
18511851   // process output CHD
18521852   chd_file output_parent;
18531853   astring *output_chd_str = parse_output_chd_parameters(params, output_parent);
1854   
1854
18551855   // process input start/end
18561856   UINT64 input_start;
18571857   UINT64 input_end;
18581858   parse_input_start_end(params, aviinfo->video_numsamples, 0, 1, input_start, input_end);
1859   
1859
18601860   // determine parameters of the incoming video stream
18611861   avi_info info;
18621862   info.fps_times_1million = UINT64(aviinfo->video_timescale) * 1000000 / aviinfo->video_sampletime;
r14530r14531
18781878   // determine the number of bytes per frame
18791879   info.max_samples_per_frame = (UINT64(info.rate) * 1000000 + info.fps_times_1million - 1) / info.fps_times_1million;
18801880   info.bytes_per_frame = avhuff_encoder::raw_data_size(info.width, info.height, info.channels, info.max_samples_per_frame);
1881   
1881
18821882   // process hunk size
18831883   UINT32 hunk_size = output_parent.opened() ? output_parent.hunk_bytes() : info.bytes_per_frame;
18841884   parse_hunk_size(params, info.bytes_per_frame, hunk_size);
1885   
1885
18861886   // process compression
18871887   chd_codec_type compression[4];
18881888   memcpy(compression, s_default_ld_compression, sizeof(compression));
r14530r14531
19321932
19331933      // create the compressor and then run it generically
19341934      compress_common(chd);
1935     
1935
19361936      // write the final LD metadata
19371937      if (info.height == 524/2 || info.height == 624/2)
19381938      {
r14530r14531
19721972   // process output CHD
19731973   chd_file output_parent;
19741974   astring *output_chd_str = parse_output_chd_parameters(params, output_parent);
1975   
1975
19761976   // process hunk size
19771977   UINT32 hunk_size = input_chd.hunk_bytes();
19781978   parse_hunk_size(params, 1, hunk_size);
19791979   if (hunk_size % input_chd.hunk_bytes() != 0 && input_chd.hunk_bytes() % hunk_size != 0)
19801980      report_error(1, "Hunk size is not an even multiple or divisor of input hunk size");
1981   
1981
19821982   // process compression; we default to our current preferences using metadata to pick the type
19831983   chd_codec_type compression[4];
19841984   {
r14530r14531
20412041            redo_cd = true;
20422042            continue;
20432043         }
2044         
2044
20452045         // otherwise, clone it
20462046         err = chd.write_metadata(metatag, CHDMETAINDEX_APPEND, metadata);
20472047         if (err != CHDERR_NONE)
20482048            report_error(1, "Error writing cloned metadata: %s", chd_file::error_string(err));
20492049      }
2050     
2050
20512051      // if we need to re-do the CD metadata, do it now
20522052      if (redo_cd)
20532053      {
r14530r14531
20592059         if (err != CHDERR_NONE)
20602060            report_error(1, "Error writing upgraded CD metadata: %s", chd_file::error_string(err));
20612061      }
2062     
2062
20632063      // compress it generically
20642064      compress_common(chd);
20652065   }
r14530r14531
20902090   UINT64 input_start;
20912091   UINT64 input_end;
20922092   parse_input_start_end(params, input_chd.logical_bytes(), input_chd.hunk_bytes(), input_chd.hunk_bytes(), input_start, input_end);
2093   
2093
20942094   // verify output file doesn't exist
20952095   astring *output_file_str = params.find(OPTION_OUTPUT);
20962096   if (output_file_str != NULL)
20972097      check_existing_output_file(params, *output_file_str);
2098   
2098
20992099   // print some info
21002100   astring tempstr;
21012101   printf("Output File:  %s\n", output_file_str->cstr());
r14530r14531
21262126         chd_error err = input_chd.read_bytes(offset, buffer, bytes_to_read);
21272127         if (err != CHDERR_NONE)
21282128            report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->cstr(), chd_file::error_string(err));
2129         
2129
21302130         // write to the output
21312131         UINT32 count = core_fwrite(output_file, buffer, bytes_to_read);
21322132         if (count != bytes_to_read)
r14530r14531
21352135         // advance
21362136         offset += bytes_to_read;
21372137      }
2138     
2138
21392139      // finish up
21402140      core_fclose(output_file);
21412141      printf("Extraction complete                                    \n");
r14530r14531
21702170   if (cdrom == NULL)
21712171      report_error(1, "Unable to recognize CHD file as a CD");
21722172   const cdrom_toc *toc = cdrom_get_toc(cdrom);
2173   
2173
21742174   // verify output file doesn't exist
21752175   astring *output_file_str = params.find(OPTION_OUTPUT);
21762176   if (output_file_str != NULL)
r14530r14531
21862186   if (output_bin_file_str == NULL)
21872187      output_bin_file_str = &default_name;
21882188   check_existing_output_file(params, *output_bin_file_str);
2189   
2189
21902190   // print some info
21912191   astring tempstr;
21922192   printf("Output TOC:   %s\n", output_file_str->cstr());
r14530r14531
22132213      UINT64 total_bytes = 0;
22142214      for (int tracknum = 0; tracknum < toc->numtrks; tracknum++)
22152215         total_bytes += toc->tracks[tracknum].frames * (toc->tracks[tracknum].datasize + toc->tracks[tracknum].subsize);
2216     
2216
22172217      // iterate over tracks and copy all data
22182218      UINT64 outputoffs = 0;
22192219      UINT32 discoffs = 0;
r14530r14531
22272227         // resize the buffer for the track
22282228         UINT32 output_frame_size = trackinfo.datasize + ((trackinfo.subtype != CD_SUB_NONE) ? trackinfo.subsize : 0);
22292229         buffer.resize((TEMP_BUFFER_SIZE / output_frame_size) * output_frame_size);
2230         
2230
22312231         // now read and output the actual data
22322232         UINT32 bufferoffs = 0;
22332233         for (int frame = 0; frame < trackinfo.frames; frame++)
r14530r14531
22672267            }
22682268         }
22692269      }
2270     
2270
22712271      // finish up
22722272      core_fclose(output_bin_file);
22732273      core_fclose(output_toc_file);
r14530r14531
23282328   frame_bytes = avhuff_encoder::raw_data_size(width, height, channels, max_samples_per_frame);
23292329   if (frame_bytes != input_chd.hunk_bytes())
23302330      report_error(1, "Frame size does not match hunk size for this CHD");
2331   
2331
23322332   // parse out input start/end
23332333   UINT64 input_start;
23342334   UINT64 input_end;
r14530r14531
23862386         audio_data[chnum].resize(max_samples_per_frame);
23872387         avconfig.audio[chnum] = audio_data[chnum];
23882388      }
2389     
2389
23902390      // iterate over frames
23912391      bitmap_yuy16 fullbitmap(width, height * interlace_factor);
23922392      for (int framenum = input_start; framenum < input_end; framenum++)
r14530r14531
23962396         // set up the fake bitmap for this frame
23972397         avconfig.video.wrap(&fullbitmap.pix(framenum % interlace_factor), fullbitmap.width(), fullbitmap.height() / interlace_factor, fullbitmap.rowpixels() * interlace_factor);
23982398         input_chd.codec_configure(CHD_CODEC_AVHUFF, AVHUFF_CODEC_DECOMPRESS_CONFIG, &avconfig);
2399         
2399
24002400         // read the hunk into the buffers
24012401         chd_error err = input_chd.read_hunk(framenum, NULL);
24022402         if (err != CHDERR_NONE)
r14530r14531
24542454      tag_str->cat("    ");
24552455      tag = CHD_MAKE_TAG((*tag_str)[0], (*tag_str)[1], (*tag_str)[2], (*tag_str)[3]);
24562456   }
2457   
2457
24582458   // process index
24592459   UINT32 index = 0;
24602460   astring *index_str = params.find(OPTION_INDEX);
24612461   if (index_str != NULL)
24622462      index = atoi(*index_str);
2463   
2463
24642464   // process text input
24652465   astring *text_str = params.find(OPTION_VALUE_TEXT);
24662466   astring text;
r14530r14531
24702470      if (text[0] == '"' && text[text.len() - 1] == '"')
24712471         text.substr(1, text.len() - 2);
24722472   }
2473   
2473
24742474   // process file input
24752475   astring *file_str = params.find(OPTION_VALUE_FILE);
24762476   dynamic_buffer file;
r14530r14531
24802480      if (filerr != FILERR_NONE)
24812481         report_error(1, "Error reading metadata file (%s)", file_str->cstr());
24822482   }
2483   
2483
24842484   // make sure we have one or the other
24852485   if (text_str == NULL && file_str == NULL)
24862486      report_error(1, "Error: missing either --valuetext/-vt or --valuefile/-vf parameters");
24872487   if (text_str != NULL && file_str != NULL)
24882488      report_error(1, "Error: both --valuetext/-vt or --valuefile/-vf parameters specified; only one permitted");
2489   
2489
24902490   // process no checksum
24912491   UINT8 flags = CHD_MDFLAGS_CHECKSUM;
24922492   if (params.find(OPTION_NO_CHECKSUM) != NULL)
24932493      flags &= ~CHD_MDFLAGS_CHECKSUM;
2494   
2494
24952495   // print some info
24962496   astring tempstr;
24972497   printf("Input file:   %s\n", params.find(OPTION_INPUT)->cstr());
r14530r14531
25162516
25172517
25182518//-------------------------------------------------
2519//  do_del_metadata - remove metadata from a CHD
2519//  do_del_metadata - remove metadata from a CHD
25202520//-------------------------------------------------
25212521
25222522static void do_del_metadata(parameters_t &params)
r14530r14531
25342534      tag_str->cat("    ");
25352535      tag = CHD_MAKE_TAG((*tag_str)[0], (*tag_str)[1], (*tag_str)[2], (*tag_str)[3]);
25362536   }
2537   
2537
25382538   // process index
25392539   UINT32 index = 0;
25402540   astring *index_str = params.find(OPTION_INDEX);
25412541   if (index_str != NULL)
25422542      index = atoi(*index_str);
2543   
2543
25442544   // print some info
25452545   astring tempstr;
25462546   printf("Input file:   %s\n", params.find(OPTION_INPUT)->cstr());
r14530r14531
25782578         return print_help(argv[0]);
25792579      command = argv[argnum++];
25802580   }
2581   
2581
25822582   // iterate over commands to find our match
25832583   for (int cmdnum = 0; cmdnum < ARRAY_LENGTH(s_commands); cmdnum++)
25842584      if (strcmp(command, s_commands[cmdnum].name) == 0)
25852585      {
25862586         const command_description &desc = s_commands[cmdnum];
2587     
2587
25882588         // print help if that was requested
25892589         if (help)
25902590            return print_help(argv[0], desc);
r14530r14531
26292629                        return print_help(argv[0], desc, "Option is missing parameter");
26302630                     param = argv[argnum++];
26312631                  }
2632                 
2632
26332633                  // add to the map
26342634                  if (parameters.add(odesc.name, new astring(param)) == TMERR_DUPLICATE)
26352635                     return print_help(argv[0], desc, "Multiple parameters of the same type specified");
r14530r14531
26412641            if (valid == ARRAY_LENGTH(desc.valid_options))
26422642               return print_help(argv[0], desc, "Option not valid for this command");
26432643         }
2644         
2644
26452645         // make sure we got all our required parameters
26462646         for (int valid = 0; valid < ARRAY_LENGTH(desc.valid_options); valid++)
26472647         {
r14530r14531
26512651            if (*validname == REQUIRED[0] && parameters.find(++validname) == NULL)
26522652               return print_help(argv[0], desc, "Required parameters missing");
26532653         }
2654         
2654
26552655         // all clear, run the command
26562656         try
26572657         {
r14530r14531
26732673            return 1;
26742674         }
26752675      }
2676   
2676
26772677   // print generic help if nothing found
26782678   return print_help(argv[0]);
26792679}
src/osd/sdl/sdl.mak
r14530r14531
5858# uncomment the next line to use couriersud's multi-keyboard patch for sdl2.0
5959# SDL2_MULTIAPI = 1
6060
61# uncomment the next line to specify where you have installed
61# uncomment the next line to specify where you have installed
6262# SDL. Equivalent to the ./configure --prefix=<path>
6363# SDL_INSTALL_ROOT = /usr/local/sdl13
6464
r14530r14531
382382# FIXME: remove the directfb ref. later. This is just there for now to work around an issue with SDL1.3 and SDL2.0
383383INCPATH += -I$(SDL_INSTALL_ROOT)/include/directfb
384384endif
385endif
385endif
386386
387387INCPATH += `pkg-config --cflags fontconfig`
388388LIBS += `pkg-config --libs fontconfig`
src/osd/windows/winwork.c
r14530r14531
324324   // on an n-CPU system, create n threads for multi queues, and 1 thread for everything else
325325   else
326326      queue->threads = (flags & WORK_QUEUE_FLAG_MULTI) ? numprocs : 1;
327     
327
328328   // multi-queues with high frequency items should top out at 4 for now
329329   // since we have scaling problems above that
330330   if ((flags & WORK_QUEUE_FLAG_HIGH_FREQ) && queue->threads > 1)
src/emu/cpu/m68000/m68kmmu.h
r14530r14531
610610      static UINT32 psrp = 0, purp=0;
611611      if(psrp != m68k->mmu_srp_aptr) {
612612         psrp = m68k->mmu_srp_aptr;
613//         fprintf(stderr, "srp = %08x\n", psrp);
613//          fprintf(stderr, "srp = %08x\n", psrp);
614614      }
615615      if(purp != m68k->mmu_urp_aptr) {
616616         purp = m68k->mmu_urp_aptr;
617//         fprintf(stderr, "urp = %08x\n", purp);
617//          fprintf(stderr, "urp = %08x\n", purp);
618618      }
619619
620620      // is UDT marked valid?
r14530r14531
791791   }
792792   else if ((m68k->ir & 0xffe0) == 0xf500)
793793   {
794//      logerror("68040 pflush: pc=%08x ir=%04x opmode=%d register=%d\n", REG_PPC(m68k), m68k->ir, (m68k->ir >> 3) & 3, m68k->ir & 7);
794//      logerror("68040 pflush: pc=%08x ir=%04x opmode=%d register=%d\n", REG_PPC(m68k), m68k->ir, (m68k->ir >> 3) & 3, m68k->ir & 7);
795795      pmmu_atc_flush(m68k);
796796   }
797797   else   // the rest are 1111000xxxXXXXXX where xxx is the instruction family
src/emu/cpu/m68000/m68k_in.c
r14530r14531
1048510485   {
1048610486      UINT16 ir = mc68kcpu->ir;
1048710487      UINT8 cache = (ir >> 6) & 3;
10488//      UINT8 scope = (ir >> 3) & 3;
10489//      logerror("68040 %s: pc=%08x ir=%04x cache=%d scope=%d register=%d\n", ir & 0x0020 ? "cpush" : "cinv", REG_PPC(mc68kcpu), ir, cache, scope, ir & 7);
10488//      UINT8 scope = (ir >> 3) & 3;
10489//      logerror("68040 %s: pc=%08x ir=%04x cache=%d scope=%d register=%d\n", ir & 0x0020 ? "cpush" : "cinv", REG_PPC(mc68kcpu), ir, cache, scope, ir & 7);
1049010490      switch (cache)
1049110491      {
1049210492      case 2:
src/emu/video/pc_vga.c
r14530r14531
10721072static void crtc_reg_write(running_machine &machine, UINT8 index, UINT8 data)
10731073{
10741074   /* Doom does this */
1075//    if(vga.crtc.protect_enable && index <= 0x07)
1076//       printf("write to protected address %02x\n",index);
1075//  if(vga.crtc.protect_enable && index <= 0x07)
1076//      printf("write to protected address %02x\n",index);
10771077
10781078   switch(index)
10791079   {
r14530r14531
12601260         res = 1;
12611261   }
12621262
1263//   popmessage("%d %d %d",vblank_start,vblank_end,vga.crtc.vert_total);
1263//  popmessage("%d %d %d",vblank_start,vblank_end,vga.crtc.vert_total);
12641264
12651265   return res;
12661266}
r14530r14531
22342234            vga.crtc.data[vga.crtc.index] = data;
22352235            tseng_crtc_reg_write(space->machine(),vga.crtc.index,data);
22362236            //if((vga.crtc.index & 0xfe) != 0x0e)
2237            //   printf("%02x %02x %d\n",vga.crtc.index,data,space->machine().primary_screen->vpos());
2237            //  printf("%02x %02x %d\n",vga.crtc.index,data,space->machine().primary_screen->vpos());
22382238            break;
22392239         case 8:
22402240            et4k.reg_3d8 = data;
src/emu/emuopts.c
r14530r14531
375375   result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
376376   update_slot_options();
377377   while (add_slot_options(false));
378   add_device_options(true);   
378   add_device_options(true);
379379   result = core_options::parse_command_line(argc, argv, OPTION_PRIORITY_CMDLINE, error_string);
380380   return result;
381381}
src/emu/sound/votrax.c
r14530r14531
5252
5353const char *const votrax_device::s_phoneme_table[64] =
5454{
55   "EH3",   "EH2",   "EH1",   " "/*PA0*/"DT",   "A1",    "A2",     "ZH",
56   "AH2",   "I3",    "I2",    "I1",    "M",     "N",     "B",      "V",
57   "CH",    "SH",    "Z",     "AW1",   "NG",    "AH1",   "OO1",    "OO",
58   "L",     "K",     "J",     "H",     "G",     "F",     "D",      "S",
59   "A",     "AY",    "Y1",    "UH3",   "AH",    "P",     "O",      "I",
60   "U",     "Y",     "T",     "R",     "E",     "W",     "AE",     "AE1",
61   "AW2",   "UH2",   "UH1",   "UH",    "O2",    "O1",    "IU",     "U1",
62   "THV",   "TH",    "ER",    "EH",    "E1",    "AW",    " "/*PA1*/, "."/*STOP*/
55   "EH3",   "EH2",   "EH1",   " "/*PA0*/"DT",   "A1",   "A2",   "ZH",
56   "AH2",   "I3",   "I2",   "I1",   "M",   "N",   "B",   "V",
57   "CH",   "SH",   "Z",   "AW1",   "NG",   "AH1",   "OO1",   "OO",
58   "L",   "K",   "J",   "H",   "G",   "F",   "D",   "S",
59   "A",   "AY",   "Y1",   "UH3",   "AH",   "P",   "O",   "I",
60   "U",   "Y",   "T",   "R",   "E",   "W",   "AE",   "AE1",
61   "AW2",   "UH2",   "UH1",   "UH",   "O2",   "O1",   "IU",   "U1",
62   "THV",   "TH",   "ER",   "EH",   "E1",   "AW",   " "/*PA1*/, "."/*STOP*/
6363};
6464
6565
r14530r14531
103103{
104104   // append to the current string
105105   m_current.cat(s_phoneme_table[data & 0x3f]);
106   
106
107107   // look for a match in our sample table
108108   for (int index = 0; m_votrax_map[index].phoneme != NULL; index++)
109109      if (m_current.find(m_votrax_map[index].phoneme) != -1)
r14530r14531
117117         m_current.reset();
118118         return;
119119      }
120   
120
121121   // if we got a stop and didn't find a match, print it
122122   if ((data & 0x3f) == 0x3f)
123123   {
r14530r14531
157157   m_channels = 1;
158158   m_names = m_sample_list;
159159   m_start = NULL;
160   
160
161161   // let the samples device do the rest
162162   samples_device::device_start();
163163}
src/emu/sound/votrax.h
r14530r14531
7676
7777// ======================> votrax_device
7878
79class votrax_device :    public samples_device,
79class votrax_device :   public samples_device,
8080                  public votrax_interface
8181{
8282public:
r14530r14531
8989   // writers
9090   DECLARE_WRITE8_MEMBER( write );
9191   DECLARE_READ_LINE_MEMBER( status );
92   
92
9393protected:
9494   // device-level overrides
9595   virtual void device_start();
src/emu/sound/samples.c
r14530r14531
66
77****************************************************************************
88
9   Playback of pre-recorded samples. Used for high-level simulation of
10   discrete sound circuits where proper low-level simulation isn't
11   available.  Also used for tape loops and similar.
9    Playback of pre-recorded samples. Used for high-level simulation of
10    discrete sound circuits where proper low-level simulation isn't
11    available.  Also used for tape loops and similar.
1212
13   Current limitations
14     - Only supports single channel samples!
13    Current limitations
14      - Only supports single channel samples!
1515
16   Considerations
17     - Maybe this should be part of the presentation layer
18       (artwork etc.) with samples specified in .lay files instead of
19       in drivers?
16    Considerations
17      - Maybe this should be part of the presentation layer
18        (artwork etc.) with samples specified in .lay files instead of
19        in drivers?
2020
2121****************************************************************************
2222
r14530r14531
135135
136136
137137//-------------------------------------------------
138//  start_raw - start playing an externally
138//  start_raw - start playing an externally
139139//  provided sample
140140//-------------------------------------------------
141141
r14530r14531
249249
250250//-------------------------------------------------
251251//  playing - return true if a sample is still
252//   playing on the given channel
252//  playing on the given channel
253253//-------------------------------------------------
254254
255255bool samples_device::playing(UINT8 channel) const
r14530r14531
318318
319319//-------------------------------------------------
320320//  device_post_load - handle updating after a
321//   restore
321//  restore
322322//-------------------------------------------------
323323
324324void samples_device::device_post_load()
r14530r14531
422422//**************************************************************************
423423
424424//-------------------------------------------------
425//  read_sample - read a WAV or FLAC file as a
425//  read_sample - read a WAV or FLAC file as a
426426//  sample
427427//-------------------------------------------------
428428
r14530r14531
436436      mame_printf_warning("Unable to read %s, 0-byte file?\n", file.filename());
437437      return false;
438438   }
439   
439
440440   // look for the appropriate RIFF tag
441441   if (memcmp(&buf[0], "RIFF", 4) == 0)
442442      return read_wav_sample(file, sample);
r14530r14531
458458printf("Reading %s as WAV\n", file.filename());
459459   // we already read the opening 'WAVE' header
460460   UINT32 offset = 4;
461   
461
462462   // get the total size
463463   UINT32 filesize;
464464   offset += file.read(&filesize, 4);
r14530r14531
593593      return false;
594594   if (decoder.bits_per_sample() != 16)
595595      return false;
596   
596
597597   // resize the array and read
598598   sample.data.resize(sample.length);
599599   if (!decoder.decode_interleaved(sample.data, sample.length))
600600      return false;
601   
601
602602   // finish up and clean up
603603   decoder.finish();
604604   return true;
r14530r14531
615615   // if the user doesn't want to use samples, bail
616616   if (!machine().options().samples())
617617      return;
618   
618
619619   // iterate over ourself
620620   const char *basename = machine().basename();
621621   samples_iterator iter(*this);
r14530r14531
634634      file_error filerr = file.open(basename, PATH_SEPARATOR, samplename, ".flac");
635635      if (filerr != FILERR_NONE && altbasename != NULL)
636636         filerr = file.open(altbasename, PATH_SEPARATOR, samplename, ".flac");
637     
637
638638      // if not, try as WAV
639639      if (filerr != FILERR_NONE)
640640         filerr = file.open(basename, PATH_SEPARATOR, samplename, ".wav");
src/emu/sound/samples.h
r14530r14531
7979
8080// ======================> samples_device
8181
82class samples_device :    public device_t,
82class samples_device :   public device_t,
8383                  public device_sound_interface,
8484                  public samples_interface
8585{
r14530r14531
100100   void pause(UINT8 channel, bool pause = true);
101101   void stop(UINT8 channel);
102102   void stop_all();
103   
103
104104   // dynamic control
105105   void set_frequency(UINT8 channel, UINT32 frequency);
106106   void set_volume(UINT8 channel, float volume);
107   
107
108108protected:
109109   // subclasses can do it this way
110110   samples_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
r14530r14531
123123   {
124124      // shouldn't need a copy, but in case it happens, catch it here
125125      loaded_sample &operator=(const loaded_sample &rhs) { assert(false); return *this; }
126   
126
127127       UINT32         length;         // length in samples
128128       UINT32         frequency;      // frequency of the sample
129129       dynamic_array<INT16> data;      // 16-bit signed data
r14530r14531
142142      bool         loop;
143143      bool         paused;
144144   };
145   
145
146146   // internal helpers
147147   bool read_sample(emu_file &file, loaded_sample &sample);
148148   bool read_wav_sample(emu_file &file, loaded_sample &sample);
r14530r14531
172172   samples_iterator(samples_interface &intf)
173173      : m_intf(intf),
174174        m_current(-1) { }
175       
175
176176   // getters
177177   const char *altbasename() const { return (m_intf.m_names != NULL && m_intf.m_names[0] != NULL && m_intf.m_names[0][0] == '*') ? &m_intf.m_names[0][1] : NULL; }
178178
r14530r14531
181181   {
182182      if (m_intf.m_names == NULL || m_intf.m_names[0] == NULL)
183183         return NULL;
184      m_current = 0;
184      m_current = 0;
185185      if (m_intf.m_names[0][0] == '*')
186186         m_current++;
187187      return m_intf.m_names[m_current++];
r14530r14531
193193         return NULL;
194194      return m_intf.m_names[m_current++];
195195   }
196   
196
197197   // counting
198198   int count()
199199   {
src/emu/clifront.c
r14530r14531
14571457            // crude, need real UTF16->UTF8 conversion ideally
14581458            for (int j=0;j<namelen;j++)
14591459            {
1460               temp3[j] = (UINT8)temp[j];           
1460               temp3[j] = (UINT8)temp[j];
14611461            }
1462                 
1462
14631463            if (!(f->IsDir) && (f->Size != 0))
14641464            {
14651465               UINT8 *data = global_alloc_array(UINT8, f->Size);
src/emu/romload.c
r14530r14531
456456   romdata->errorstring.catprintf("    EXPECTED: %s\n", hashes.macro_string(tempstr));
457457   romdata->errorstring.catprintf("       FOUND: %s\n", acthashes.macro_string(tempstr));
458458/*
459   // warn about any ill-formed hashes
460   for (hash_base *hash = hashes.first(); hash != NULL; hash = hash->next())
461      if (hash->parse_error())
462      {
463         romdata->errorstring.catprintf("\tInvalid %s checksum treated as 0 (check leading zeros)\n", hash->name());
464         romdata->warnings++;
465      }
459    // warn about any ill-formed hashes
460    for (hash_base *hash = hashes.first(); hash != NULL; hash = hash->next())
461        if (hash->parse_error())
462        {
463            romdata->errorstring.catprintf("\tInvalid %s checksum treated as 0 (check leading zeros)\n", hash->name());
464            romdata->warnings++;
465        }
466466*/
467467}
468468
r14530r14531
11571157   {
11581158      astring fullpath(diff_file.fullpath());
11591159      diff_file.close();
1160   
1160
11611161      LOG(("Opening differencing image file: %s\n", fullpath.cstr()));
11621162      return diff_chd.open(fullpath, true, &source);
11631163   }
1164     
1164
11651165   /* didn't work; try creating it instead */
11661166   LOG(("Creating differencing image: %s\n", fname.cstr()));
11671167   diff_file.set_openflags(OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
r14530r14531
11771177      chd_error err = diff_chd.create(fullpath, source.logical_bytes(), source.hunk_bytes(), compression, source);
11781178      if (err != CHDERR_NONE)
11791179         return err;
1180     
1180
11811181      return diff_chd.clone_all_metadata(source);
11821182   }
11831183
r14530r14531
11991199      if (ROMENTRY_ISFILE(romp))
12001200      {
12011201         open_chd *chd = global_alloc(open_chd(regiontag));
1202         
1202
12031203         hash_collection hashes(ROM_GETHASHDATA(romp));
12041204         chd_error err;
12051205
src/emu/hash.c
r14530r14531
179179   // handle CRCs
180180   if (type == HASH_CRC)
181181      return m_has_crc32 = m_crc32.from_string(buffer, length);
182   
182
183183   // handle SHA1s
184184   else if (type == HASH_SHA1)
185185      return m_has_sha1 = m_sha1.from_string(buffer, length);
r14530r14531
195195bool hash_collection::remove(char type)
196196{
197197   bool result = false;
198   
198
199199   // handle CRCs
200200   if (type == HASH_CRC)
201201   {
202202      result = m_has_crc32;
203203      m_has_crc32 = false;
204204   }
205     
205
206206   // handle SHA1s
207207   else if (type == HASH_SHA1)
208208   {
r14530r14531
222222const char *hash_collection::internal_string(astring &buffer) const
223223{
224224   buffer.reset();
225   
225
226226   // handle CRCs
227227   astring temp;
228228   if (m_has_crc32)
229229      buffer.cat(HASH_CRC).cat(m_crc32.as_string(temp));
230     
230
231231   // handle SHA1s
232232   if (m_has_sha1)
233233      buffer.cat(HASH_SHA1).cat(m_sha1.as_string(temp));
r14530r14531
250250   astring temp;
251251   if (m_has_crc32)
252252      buffer.cat("CRC(").cat(m_crc32.as_string(temp)).cat(") ");
253     
253
254254   // handle SHA1s
255255   if (m_has_sha1)
256256      buffer.cat("SHA1(").cat(m_sha1.as_string(temp)).cat(") ");
r14530r14531
277277   astring temp;
278278   if (m_has_crc32)
279279      buffer.cat("crc=\"").cat(m_crc32.as_string(temp)).cat("\" ");
280     
280
281281   // handle SHA1s
282282   if (m_has_sha1)
283283      buffer.cat("sha1=\"").cat(m_sha1.as_string(temp)).cat("\" ");
r14530r14531
352352   // by default use all types
353353   if (types == NULL)
354354      m_creator->m_doing_crc32 = m_creator->m_doing_sha1 = true;
355   
355
356356   // otherwise, just allocate the ones that are specified
357357   else
358358   {
r14530r14531
369369void hash_collection::buffer(const UINT8 *data, UINT32 length)
370370{
371371   assert(m_creator != NULL);
372   
372
373373   // append to each active hash
374374   if (m_creator->m_doing_crc32)
375375      m_creator->m_crc32_creator.append(data, length);
r14530r14531
385385void hash_collection::end()
386386{
387387   assert(m_creator != NULL);
388   
388
389389   // default to getting nothing
390390   m_has_crc32 = m_has_sha1 = false;
391   
391
392392   // finish up the CRC32
393393   if (m_creator->m_doing_crc32)
394394   {
395395      m_has_crc32 = true;
396396      m_crc32 = m_creator->m_crc32_creator.finish();
397397   }
398   
398
399399   // finish up the SHA1
400400   if (m_creator->m_doing_sha1)
401401   {
402402      m_has_sha1 = true;
403403      m_sha1 = m_creator->m_sha1_creator.finish();
404404   }
405   
405
406406   // nuke the creator
407407   delete m_creator;
408408   m_creator = NULL;
r14530r14531
418418{
419419   // copy flags directly
420420   m_flags = src.m_flags;
421   
421
422422   // copy hashes
423423   m_has_crc32 = src.m_has_crc32;
424424   m_crc32 = src.m_crc32;
425425   m_has_sha1 = src.m_has_sha1;
426426   m_sha1 = src.m_sha1;
427427
428   // don't copy creators   
428   // don't copy creators
429429   m_creator = NULL;
430430}
src/emu/machine/idectrl.c
r14530r14531
921921   /* now do the write */
922922   if (ide->drive[ide->cur_drive].slot) {
923923      count = ide->drive[ide->cur_drive].slot->write_sector(lba, ide->buffer);
924   }   
924   }
925925
926926   /* by default, mark the buffer ready and the seek complete */
927927   ide->status |= IDE_STATUS_BUFFER_READY;
r14530r14531
11741174         ide->status &= ~IDE_STATUS_ERROR;
11751175         ide->error = IDE_ERROR_NONE;
11761176         ide->drive[ide->cur_drive].slot->set_geometry(ide->sector_count,ide->drive[ide->cur_drive].cur_head + 1);
1177         
1177
11781178         /* signal an interrupt */
11791179         signal_delayed_interrupt(ide, MINIMUM_COMMAND_TIME, 0);
11801180         break;
r14530r14531
19211921static DEVICE_RESET( ide_controller )
19221922{
19231923   ide_state *ide = get_safe_token(device);
1924   LOG(("IDE controller reset performed\n"));   
1924   LOG(("IDE controller reset performed\n"));
19251925   /* reset the drive state */
19261926   ide->cur_drive = 0;
19271927   ide->status = IDE_STATUS_DRIVE_READY | IDE_STATUS_SEEK_COMPLETE;
r14530r14531
19381938SLOT_INTERFACE_END
19391939
19401940SLOT_INTERFACE_START(ide_devices)
1941   SLOT_INTERFACE("hdd", IDE_HARDDISK)   
1941   SLOT_INTERFACE("hdd", IDE_HARDDISK)
19421942SLOT_INTERFACE_END
19431943
19441944/*-------------------------------------------------
r14530r14531
20602060{
20612061   m_handle = get_disk_handle(machine(), owner()->tag());
20622062   m_disk = hard_disk_open(m_handle);
2063   
2063
20642064   if (m_disk != NULL)
20652065   {
20662066      const hard_disk_info *hdinfo = hard_disk_get_info(m_disk);
r14530r14531
20722072         if (PRINTF_IDE_COMMANDS) mame_printf_debug("CHS: %d %d %d\n", m_num_cylinders, m_num_heads, m_num_sectors);
20732073         mame_printf_debug("CHS: %d %d %d\n", m_num_cylinders, m_num_heads, m_num_sectors);
20742074      }
2075      // build the features page
2075      // build the features page
20762076      UINT32 metalength;
20772077      if (m_handle->read_metadata (HARD_DISK_IDENT_METADATA_TAG, 0, m_features, IDE_DISK_SECTOR_SIZE, metalength) != CHDERR_NONE)
20782078         ide_build_features();
2079   }   
2079   }
20802080}
20812081
20822082//-------------------------------------------------
r14530r14531
21372137            m_num_heads = hdinfo->heads;
21382138            if (PRINTF_IDE_COMMANDS) printf("CHS: %d %d %d\n", m_num_cylinders, m_num_heads, m_num_sectors);
21392139         }
2140         // build the features page
2140         // build the features page
21412141         UINT32 metalength;
21422142         if (m_handle->read_metadata (HARD_DISK_IDENT_METADATA_TAG, 0, m_features, IDE_DISK_SECTOR_SIZE, metalength) != CHDERR_NONE)
21432143            ide_build_features();
r14530r14531
21522152//-------------------------------------------------
21532153static MACHINE_CONFIG_FRAGMENT( hdd_image )
21542154   MCFG_HARDDISK_ADD( "harddisk" )
2155MACHINE_CONFIG_END   
2155MACHINE_CONFIG_END
21562156
21572157machine_config_constructor ide_hdd_image_device::device_mconfig_additions() const
21582158{
src/emu/machine/idectrl.h
r14530r14531
3333public:
3434   virtual int    read_sector(UINT32 lba, void *buffer) = 0;
3535   virtual int    write_sector(UINT32 lba, const void *buffer) = 0;
36   
37   UINT8 *get_features() { return m_features;}
3836
37   UINT8 *get_features() { return m_features;}
38
3939   UINT16 get_cylinders() { return m_num_cylinders; }
4040   UINT16 get_sectors() { return m_num_sectors; }
4141   UINT16 get_heads() { return m_num_heads; }
r14530r14531
5959   ide_slot_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
6060
6161   int    read_sector(UINT32 lba, void *buffer) { return (m_dev) ? m_dev->read_sector(lba,buffer) : 0; }
62   int    write_sector(UINT32 lba, const void *buffer) { return (m_dev) ? m_dev->write_sector(lba,buffer) : 0; }   
63   UINT8 *get_features() { return (m_dev) ? m_dev->get_features() : NULL;}
62   int    write_sector(UINT32 lba, const void *buffer) { return (m_dev) ? m_dev->write_sector(lba,buffer) : 0; }
63   UINT8 *get_features() { return (m_dev) ? m_dev->get_features() : NULL;}
6464
6565   UINT16 get_cylinders() { return (m_dev) ? m_dev->get_cylinders() : 0; }
6666   UINT16 get_sectors() { return (m_dev) ? m_dev->get_sectors() : 0; }
67   UINT16 get_heads() { return (m_dev) ? m_dev->get_heads() : 0; }   
67   UINT16 get_heads() { return (m_dev) ? m_dev->get_heads() : 0; }
6868   void set_geometry(UINT8 sectors, UINT8 heads) { if (m_dev) m_dev->set_geometry(sectors,heads); }
6969   bool is_ready() { return (m_dev) ? m_dev->is_ready() : false; }
7070   void read_key(UINT8 key[]) { if (m_dev) m_dev->read_key(key); }
r14530r14531
9696    // device-level overrides
9797    virtual void device_start();
9898   virtual void device_reset();
99   
99
100100   void ide_build_features();
101101   virtual bool is_ready() { return (m_disk != NULL); }
102102protected:
src/emu/machine/nscsi_bus.c
r14530r14531
6868         }
6969      logerror("\n");
7070   }
71     
71
7272   octrl = octrl ^ ctrl;
7373   if(octrl)
7474      for(int i=0; i<devcnt; i++)
r14530r14531
357357      } else
358358         target_recv_byte();
359359      break;
360     
360
361361   default:
362362      logerror("%s: step() unexpected state %d.%d\n",
363363             tag(),
r14530r14531
442442   buf_control_rpos++;
443443   if(buf_control_rpos == buf_control_wpos)
444444      buf_control_rpos = buf_control_wpos = 0;
445   return c;   
445   return c;
446446}
447447
448448void nscsi_full_device::scsi_status_complete(UINT8 st)
src/emu/machine/nscsi_hd.c
r14530r14531
8383         bad_lun();
8484         return;
8585      }
86         
86
8787      int page = scsi_cmdbuf[2];
8888      int size = scsi_cmdbuf[4];
8989      switch(page) {
src/emu/machine/nscsi_bus.h
r14530r14531
77   MCFG_DEVICE_ADD(_tag, NSCSI_BUS, 0)
88
99#define MCFG_NSCSI_DEVICE_ADD(_tag, _subtag, _type, _clock)         \
10   MCFG_DEVICE_ADD(_tag, NSCSI_CONNECTOR, 0)                   \
10   MCFG_DEVICE_ADD(_tag, NSCSI_CONNECTOR, 0)                  \
1111   downcast<nscsi_connector *>(device)->set_fixed_device(_subtag);   \
1212   MCFG_DEVICE_ADD(_tag ":" _subtag, _type, _clock)
1313
r14530r14531
1515   MCFG_NSCSI_DEVICE_ADD(_tag, _subtag, _type, _clock)
1616
1717#define MCFG_NSCSI_ADD(_tag, _slot_intf, _def_slot, _def_inp)   \
18   MCFG_DEVICE_ADD(_tag, NSCSI_CONNECTOR, 0)                \
18   MCFG_DEVICE_ADD(_tag, NSCSI_CONNECTOR, 0)               \
1919   MCFG_DEVICE_SLOT_INTERFACE(_slot_intf, _def_slot, _def_inp)
2020
2121class nscsi_device;
r14530r14531
336336
337337   control *buf_control_push();
338338   control *buf_control_pop();
339   
339
340340   void step(bool timeout);
341341   void target_recv_byte();
342342   void target_send_byte(UINT8 val);
src/lib/lib7z/LzmaLib.h
r14530r14531
3838  LZMA Encoder will use defult values for any parameter, if it is
3939  -1  for any from: level, loc, lp, pb, fb, numThreads
4040   0  for dictSize
41 
41
4242level - compression level: 0 <= level <= 9;
4343 
4444  level dictSize algo  fb
r14530r14531
5050    5:    16 MB   1    32
5151    6:    32 MB   1    32
5252    7+:   64 MB   1    64
53
53
5454  The default value for "level" is 5.
5555 
5656  algo = 0 means fast method
src/lib/lib7z/MtCoder.h
r14530r14531
1414  CAutoResetEvent startEvent;
1515  CAutoResetEvent finishedEvent;
1616  int stop;
17 
17
1818  THREAD_FUNC_TYPE func;
1919  LPVOID param;
2020  THREAD_FUNC_RET_TYPE res;
r14530r14531
7575  size_t blockSize;
7676  size_t destBlockSize;
7777  unsigned numThreads;
78 
78
7979  ISeqInStream *inStream;
8080  ISeqOutStream *outStream;
8181  ICompressProgress *progress;
src/lib/lib7z/Ppmd7Dec.c
r14530r14531
160160      i -= k;
161161    }
162162    while (i != num);
163   
163
164164    see = Ppmd7_MakeEscFreq(p, numMasked, &freqSum);
165165    freqSum += hiCnt;
166166    count = rc->GetThreshold(rc, freqSum);
167   
167
168168    if (count < hiCnt)
169169    {
170170      Byte symbol;
src/lib/lib7z/Aes.c
r14530r14531
228228    p[1] ^= GetUi32(data + 4);
229229    p[2] ^= GetUi32(data + 8);
230230    p[3] ^= GetUi32(data + 12);
231   
231
232232    Aes_Encode(p + 4, p, p);
233   
233
234234    SetUi32(data,      p[0]);
235235    SetUi32(data + 4,  p[1]);
236236    SetUi32(data + 8,  p[2]);
r14530r14531
254254    SetUi32(data + 4,  p[1] ^ out[1]);
255255    SetUi32(data + 8,  p[2] ^ out[2]);
256256    SetUi32(data + 12, p[3] ^ out[3]);
257   
257
258258    p[0] = in[0];
259259    p[1] = in[1];
260260    p[2] = in[2];
src/lib/lib7z/Lzma2Enc.c
r14530r14531
8383  if (packSize < lzHeaderSize)
8484    return SZ_ERROR_OUTPUT_EOF;
8585  packSize -= lzHeaderSize;
86 
86
8787  LzmaEnc_SaveState(p->enc);
8888  res = LzmaEnc_CodeOneMemBlock(p->enc, p->needInitState,
8989      outBuf + lzHeaderSize, &packSize, LZMA2_PACK_SIZE_MAX, &unpackSize);
90 
90
9191  PRF(printf("\npackSize = %7d unpackSize = %7d  ", packSize, unpackSize));
9292 
9393  if (unpackSize == 0)
r14530r14531
146146    outBuf[destPos++] = (Byte)u;
147147    outBuf[destPos++] = (Byte)(pm >> 8);
148148    outBuf[destPos++] = (Byte)pm;
149   
149
150150    if (p->needInitProp)
151151      outBuf[destPos++] = p->props;
152   
152
153153    p->needInitProp = False;
154154    p->needInitState = False;
155155    destPos += packSize;
r14530r14531
244244{
245245  Byte propEncoded;
246246  CLzma2EncProps props;
247 
247
248248  Byte *outBuf;
249249 
250250  ISzAlloc *alloc;
r14530r14531
322322    if (srcSize != 0)
323323    {
324324      RINOK(Lzma2EncInt_Init(p, &mainEncoder->props));
325     
325
326326      RINOK(LzmaEnc_MemPrepare(p->enc, src, srcSize, LZMA2_KEEP_WINDOW_SIZE,
327327          mainEncoder->alloc, mainEncoder->allocBig));
328     
328
329329      while (p->srcPos < srcSize)
330330      {
331331        size_t packSize = destLim - *destSize;
r14530r14531
460460 
461461    mtCallback.funcTable.Code = MtCallbackImp_Code;
462462    mtCallback.lzma2Enc = p;
463   
463
464464    p->mtCoder.progress = progress;
465465    p->mtCoder.inStream = inStream;
466466    p->mtCoder.outStream = outStream;
r14530r14531
470470    p->mtCoder.blockSize = p->props.blockSize;
471471    p->mtCoder.destBlockSize = p->props.blockSize + (p->props.blockSize >> 10) + 16;
472472    p->mtCoder.numThreads = p->props.numBlockThreads;
473   
473
474474    return MtCoder_Code(&p->mtCoder);
475475  }
476476  #endif
src/lib/lib7z/XzDec.c
r14530r14531
421421      const Byte *srcCur;
422422      int srcFinishedCur;
423423      int encodingWasFinished;
424     
424
425425      if (i == 0)
426426      {
427427        srcCur = src;
r14530r14531
434434        srcLenCur = p->size[i - 1] - p->pos[i - 1];
435435        srcFinishedCur = p->finished[i - 1];
436436      }
437     
437
438438      if (i == p->numCoders - 1)
439439      {
440440        destCur = dest;
r14530r14531
447447        destCur = p->buf + (CODER_BUF_SIZE * i);
448448        destLenCur = CODER_BUF_SIZE;
449449      }
450     
450
451451      res = coder->Code(coder->p, destCur, &destLenCur, srcCur, &srcLenCur, srcFinishedCur, finishMode, &encodingWasFinished);
452452 
453453      if (!encodingWasFinished)
r14530r14531
474474        p->pos[i] = 0;
475475        p->finished[i] = encodingWasFinished;
476476      }
477     
477
478478      if (res != SZ_OK)
479479        return res;
480480 
r14530r14531
637637        *status = CODER_STATUS_NOT_FINISHED;
638638        return SZ_OK;
639639      }
640     
640
641641      res = MixCoder_Code(&p->decoder, dest, &destLen2, src, &srcLen2, False, finishMode, status);
642642      XzCheck_Update(&p->check, dest, destLen2);
643     
643
644644      (*srcLen) += srcLen2;
645645      src += srcLen2;
646646      p->packSize += srcLen2;
647     
647
648648      (*destLen) += destLen2;
649649      dest += destLen2;
650650      p->unpackSize += destLen2;
651     
651
652652      RINOK(res);
653     
653
654654      if (*status == CODER_STATUS_FINISHED_WITH_MARK)
655655      {
656656        Byte temp[32];
r14530r14531
659659        Sha256_Update(&p->sha, temp, num);
660660        p->indexSize += num;
661661        p->numBlocks++;
662       
662
663663        p->state = XZ_STATE_BLOCK_FOOTER;
664664        p->pos = 0;
665665        p->alignPos = 0;
666666      }
667667      else if (srcLen2 == 0 && destLen2 == 0)
668668        return SZ_OK;
669     
669
670670      continue;
671671    }
672672 
r14530r14531
872872        }
873873        break;
874874      }
875     
875
876876      case XZ_STATE_BLOCK: break; /* to disable GCC warning */
877877    }
878878  }
src/lib/lib7z/HuffEnc.c
r14530r14531
1818  /* if (maxLen > 10) maxLen = 10; */
1919  {
2020    UInt32 i;
21   
21
2222    #ifdef HUFFMAN_SPEED_OPT
23   
23
2424    UInt32 counters[NUM_COUNTERS];
2525    for (i = 0; i < NUM_COUNTERS; i++)
2626      counters[i] = 0;
r14530r14531
2929      UInt32 freq = freqs[i];
3030      counters[(freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1]++;
3131    }
32
32
3333    for (i = 1; i < NUM_COUNTERS; i++)
3434    {
3535      UInt32 temp = counters[i];
r14530r14531
4747    }
4848    counters[0] = 0;
4949    HeapSort(p + counters[NUM_COUNTERS - 2], counters[NUM_COUNTERS - 1] - counters[NUM_COUNTERS - 2]);
50   
50
5151    #else
5252 
5353    for (i = 0; i < numSymbols; i++)
r14530r14531
7878    lens[minCode] = lens[maxCode] = 1;
7979    return;
8080  }
81 
81
8282  {
8383    UInt32 b, e, i;
84 
84
8585    i = b = e = 0;
8686    do
8787    {
r14530r14531
9696      e++;
9797    }
9898    while (num - e > 1);
99   
99
100100    {
101101      UInt32 lenCounters[kMaxLen + 1];
102102      for (i = 0; i <= kMaxLen; i++)
103103        lenCounters[i] = 0;
104     
104
105105      p[--e] &= MASK;
106106      lenCounters[1] = 2;
107107      while (e > 0)
r14530r14531
113113        lenCounters[len]--;
114114        lenCounters[len + 1] += 2;
115115      }
116     
116
117117      {
118118        UInt32 len;
119119        i = 0;
r14530r14531
124124            lens[p[i++] & MASK] = (Byte)len;
125125        }
126126      }
127     
127
128128      {
129129        UInt32 nextCodes[kMaxLen + 1];
130130        {
src/lib/lib7z/Ppmd8Enc.c
r14530r14531
8181      sum += s->Freq;
8282    }
8383    while (--i);
84   
84
8585    PPMD_SetAllBitsIn256Bytes(charMask);
8686    MASK(s->Symbol) = 0;
8787    i = p->MinContext->NumStats;
r14530r14531
125125      p->MinContext = Ppmd8_GetContext(p, p->MinContext->Suffix);
126126    }
127127    while (p->MinContext->NumStats == numMasked);
128   
128
129129    see = Ppmd8_MakeEscFreq(p, numMasked, &escFreq);
130130    s = Ppmd8_GetStats(p, p->MinContext);
131131    sum = 0;
r14530r14531
154154      s++;
155155    }
156156    while (--i);
157   
157
158158    RangeEnc_Encode(p, sum, escFreq, sum + escFreq);
159159    see->Summ = (UInt16)(see->Summ + sum + escFreq);
160160  }
src/lib/lib7z/HuffEnc.h
r14530r14531
1717  maxLen <= 16 = kMaxLen
1818  Num_Items(p) >= HUFFMAN_TEMP_SIZE(num)
1919*/
20
20
2121void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 num, UInt32 maxLen);
2222 
2323#ifdef __cplusplus
src/lib/lib7z/LzFind.c
r14530r14531
512512 
513513  delta2 = p->pos - p->hash[hash2Value];
514514  curMatch = p->hash[kFix3HashSize + hashValue];
515 
515
516516  p->hash[hash2Value] =
517517  p->hash[kFix3HashSize + hashValue] = p->pos;
518518 
r14530r14531
546546  delta2 = p->pos - p->hash[                hash2Value];
547547  delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
548548  curMatch = p->hash[kFix4HashSize + hashValue];
549 
549
550550  p->hash[                hash2Value] =
551551  p->hash[kFix3HashSize + hash3Value] =
552552  p->hash[kFix4HashSize + hashValue] = p->pos;
src/lib/lib7z/Ppmd8.c
r14530r14531
146146 
147147  p->GlueCount = 1 << 13;
148148  memset(p->Stamps, 0, sizeof(p->Stamps));
149 
149
150150  /* Order-0 context is always at top UNIT, so we don't need guard NODE at the end.
151151     All blocks up to p->LoUnit can be free, so we need guard NODE at LoUnit. */
152152  if (p->LoUnit != p->HiUnit)
r14530r14531
175175    }
176176  }
177177  *prev = 0;
178 
178
179179  /* Fill lists of free blocks */
180180  while (head != 0)
181181  {
r14530r14531
298298  memset(count, 0, sizeof(count));
299299  if (p->LoUnit != p->HiUnit)
300300    ((CPpmd8_Node *)p->LoUnit)->Stamp = 0;
301 
301
302302  {
303303    CPpmd8_Node *node = (CPpmd8_Node *)p->UnitsStart;
304304    for (; node->Stamp == EMPTY_NODE; node += node->NU)
r14530r14531
308308    }
309309    p->UnitsStart = (Byte *)node;
310310  }
311 
311
312312  for (i = 0; i < PPMD_NUM_INDEXES; i++)
313313  {
314314    CPpmd8_Node_Ref *next = (CPpmd8_Node_Ref *)&p->FreeList[i];
r14530r14531
440440  int i;
441441  unsigned tmp;
442442  CPpmd_State *s;
443 
443
444444  if (!ctx->NumStats)
445445  {
446446    s = ONE_STATE(ctx);
r14530r14531
470470      SetSuccessor(s, CutOff(p, CTX(SUCCESSOR(s)), order + 1));
471471    else
472472      SetSuccessor(s, 0);
473   
473
474474  if (i != ctx->NumStats && order)
475475  {
476476    ctx->NumStats = (Byte)i;
r14530r14531
521521      SetSuccessor(s, RemoveBinContexts(p, CTX(SUCCESSOR(s)), order + 1));
522522    else
523523      SetSuccessor(s, 0);
524 
524
525525  return REF(ctx);
526526}
527527#endif
r14530r14531
561561    }
562562    else
563563      Refresh(p, c, (c->NumStats+3) >> 1, 0);
564
564
565565  for (; c != p->MinContext; c = SUFFIX(c))
566566    if (!c->NumStats)
567567      ONE_STATE(c)->Freq -= ONE_STATE(c)->Freq >> 1;
r14530r14531
610610  /* fixed over Shkarin's code. Maybe it could work without + 1 too. */
611611  CPpmd_State *ps[PPMD8_MAX_ORDER + 1];
612612  unsigned numPs = 0;
613 
613
614614  if (!skip)
615615    ps[numPs++] = p->FoundState;
616 
616
617617  while (c->Suffix)
618618  {
619619    CPpmd_Void_Ref successor;
r14530r14531
648648    }
649649    ps[numPs++] = s;
650650  }
651 
651
652652  upState.Symbol = *(const Byte *)Ppmd8_GetPtr(p, upBranch);
653653  SetSuccessor(&upState, upBranch + 1);
654654  flags = 0x10 * (p->FoundState->Symbol >= 0x40) + 0x08 * (upState.Symbol >= 0x40);
r14530r14531
687687    c = c1;
688688  }
689689  while (numPs != 0);
690 
690
691691  return c;
692692}
693693 
r14530r14531
696696  CPpmd_State *s = NULL;
697697  CTX_PTR c1 = c;
698698  CPpmd_Void_Ref upBranch = REF(p->Text);
699 
699
700700  #ifdef PPMD8_FREEZE_SUPPORT
701701  /* The BUG in Shkarin's code was fixed: ps could overflow in CUT_OFF mode. */
702702  CPpmd_State *ps[PPMD8_MAX_ORDER + 1];
r14530r14531
754754    SetSuccessor(s, upBranch);
755755    p->OrderFall++;
756756  }
757 
757
758758  #ifdef PPMD8_FREEZE_SUPPORT
759759  if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
760760  {
r14530r14531
779779      SetSuccessor(s, REF(successor));
780780    p->FoundState = s1;
781781  }
782 
782
783783  if (p->OrderFall == 1 && c1 == p->MaxContext)
784784  {
785785    SetSuccessor(p->FoundState, SUCCESSOR(s));
r14530r14531
797797  unsigned s0, ns, fFreq = p->FoundState->Freq;
798798  Byte flag, fSymbol = p->FoundState->Symbol;
799799  CPpmd_State *s = NULL;
800 
800
801801  if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0)
802802  {
803803    c = SUFFIX(p->MinContext);
804   
804
805805    if (c->NumStats == 0)
806806    {
807807      s = ONE_STATE(c);
r14530r14531
827827      }
828828    }
829829  }
830 
830
831831  c = p->MaxContext;
832832  if (p->OrderFall == 0 && fSuccessor)
833833  {
r14530r14531
844844    }
845845    return;
846846  }
847 
847
848848  *p->Text++ = p->FoundState->Symbol;
849849  successor = REF(p->Text);
850850  if (p->Text >= p->UnitsStart)
r14530r14531
852852    RESTORE_MODEL(c, CTX(fSuccessor)); /* check it */
853853    return;
854854  }
855 
855
856856  if (!fSuccessor)
857857  {
858858    CTX_PTR cs = ReduceOrder(p, s, p->MinContext);
r14530r14531
873873    }
874874    fSuccessor = REF(cs);
875875  }
876 
876
877877  if (--p->OrderFall == 0)
878878  {
879879    successor = fSuccessor;
r14530r14531
887887    p->OrderFall = 0;
888888  }
889889  #endif
890 
890
891891  s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - fFreq;
892892  flag = 0x08 * (fSymbol >= 0x40);
893 
893
894894  for (; c != p->MinContext; c = SUFFIX(c))
895895  {
896896    unsigned ns1;
r14530r14531
958958  }
959959  p->MaxContext = p->MinContext = CTX(fSuccessor);
960960}
961 
961
962962static void Rescale(CPpmd8 *p)
963963{
964964  unsigned i, adder, sumFreq, escFreq;
r14530r14531
979979      );
980980  s->Freq = (Byte)((s->Freq + adder) >> 1);
981981  sumFreq = s->Freq;
982 
982
983983  i = p->MinContext->NumStats;
984984  do
985985  {
r14530r14531
997997    }
998998  }
999999  while (--i);
1000 
1000
10011001  if (s->Freq == 0)
10021002  {
10031003    unsigned numStats = p->MinContext->NumStats;
src/lib/lib7z/7zCrc.c
r14530r14531
5252    UInt32 r = g_CrcTable[i - 256];
5353    g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
5454  }
55 
55
5656  #ifdef MY_CPU_LE
5757 
5858  g_CrcUpdate = CrcUpdateT4;
59 
59
6060  #if CRC_NUM_TABLES == 8
6161  if (!CPU_Is_InOrder())
6262    g_CrcUpdate = CrcUpdateT8;
src/lib/lib7z/x7zFile.c
r14530r14531
120120  return 0;
121121 
122122  #else
123 
123
124124  *size = fread(data, 1, originalSize, p->file);
125125  if (*size == originalSize)
126126    return 0;
127127  return ferror(p->file);
128 
128
129129  #endif
130130}
131131 
r14530r14531
134134  size_t originalSize = *size;
135135  if (originalSize == 0)
136136    return 0;
137 
137
138138  #ifdef USE_WINDOWS_FILE
139139 
140140  *size = 0;
r14530r14531
160160  if (*size == originalSize)
161161    return 0;
162162  return ferror(p->file);
163 
163
164164  #endif
165165}
166166 
r14530r14531
190190  return 0;
191191 
192192  #else
193 
193
194194  int moveMethod;
195195  int res;
196196  switch (origin)
r14530r14531
203203  res = fseek(p->file, (long)*pos, moveMethod);
204204  *pos = ftell(p->file);
205205  return res;
206 
206
207207  #endif
208208}
209209 
210210WRes File_GetLength(CSzFile *p, UInt64 *length)
211211{
212212  #ifdef USE_WINDOWS_FILE
213 
213
214214  DWORD sizeHigh;
215215  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
216216  if (sizeLow == 0xFFFFFFFF)
r14530r14531
221221  }
222222  *length = (((UInt64)sizeHigh) << 32) + sizeLow;
223223  return 0;
224 
224
225225  #else
226 
226
227227  long pos = ftell(p->file);
228228  int res = fseek(p->file, 0, SEEK_END);
229229  *length = ftell(p->file);
230230  fseek(p->file, pos, SEEK_SET);
231231  return res;
232 
232
233233  #endif
234234}
235235 
src/lib/lib7z/LzmaEnc.c
r14530r14531
119119  int c = 2, slotFast;
120120  g_FastPos[0] = 0;
121121  g_FastPos[1] = 1;
122 
122
123123  for (slotFast = 2; slotFast < kNumLogBits * 2; slotFast++)
124124  {
125125    UInt32 k = (1 << ((slotFast >> 1) - 1));
r14530r14531
256256  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
257257  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
258258  CLzmaProb posAlignEncoder[1 << kNumAlignBits];
259 
259
260260  CLenPriceEnc lenEnc;
261261  CLenPriceEnc repLenEnc;
262262 
r14530r14531
279279  #ifndef _7ZIP_ST
280280  Byte pad[128];
281281  #endif
282 
282
283283  UInt32 optimumEndIndex;
284284  UInt32 optimumCurrentIndex;
285285 
r14530r14531
287287  UInt32 numPairs;
288288  UInt32 numAvail;
289289  COptimal opt[kNumOpts];
290 
290
291291  #ifndef LZMA_LOG_BSR
292292  Byte g_FastPos[1 << kNumLogBits];
293293  #endif
r14530r14531
321321  CLzmaProb posSlotEncoder[kNumLenToPosStates][1 << kNumPosSlotBits];
322322  CLzmaProb posEncoders[kNumFullDistances - kEndPosModelIndex];
323323  CLzmaProb posAlignEncoder[1 << kNumAlignBits];
324 
324
325325  CLenPriceEnc lenEnc;
326326  CLenPriceEnc repLenEnc;
327327 
328328  unsigned lclp;
329329 
330330  Bool fastMode;
331 
331
332332  CRangeEnc rc;
333333 
334334  Bool writeEndMark;
r14530r14531
917917    {
918918      UInt32 posPrev = posMem;
919919      UInt32 backCur = backMem;
920     
920
921921      backMem = p->opt[posPrev].backPrev;
922922      posMem = p->opt[posPrev].posPrev;
923     
923
924924      p->opt[posPrev].backPrev = backCur;
925925      p->opt[posPrev].posPrev = cur;
926926      cur = posPrev;
r14530r14531
951951    return lenRes;
952952  }
953953  p->optimumCurrentIndex = p->optimumEndIndex = 0;
954 
954
955955  if (p->additionalOffset == 0)
956956    mainLen = ReadMatchDistances(p, &numPairs);
957957  else
r14530r14531
12491249 
12501250    matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);
12511251    repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);
1252   
1252
12531253    if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))
12541254    {
12551255      UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);
r14530r14531
13111311        }
13121312      }
13131313    }
1314   
1314
13151315    startLen = 2; /* speed optimization */
13161316    {
13171317    UInt32 repIndex;
r14530r14531
13421342      }
13431343      while (--lenTest >= 2);
13441344      lenTest = lenTestTemp;
1345     
1345
13461346      if (repIndex == 0)
13471347        startLen = lenTest + 1;
1348       
1348
13491349      /* if (_maxMode) */
13501350        {
13511351          UInt32 lenTest2 = lenTest + 1;
r14530r14531
13691369            nextRepMatchPrice = curAndLenCharPrice +
13701370                GET_PRICE_1(p->isMatch[state2][posStateNext]) +
13711371                GET_PRICE_1(p->isRep[state2]);
1372           
1372
13731373            /* for (; lenTest2 >= 2; lenTest2--) */
13741374            {
13751375              UInt32 curAndLenPrice;
r14530r14531
14241424          curAndLenPrice += p->distancesPrices[lenToPosState][curBack];
14251425        else
14261426          curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];
1427       
1427
14281428        opt = &p->opt[cur + lenTest];
14291429        if (curAndLenPrice < opt->price)
14301430        {
r14530r14531
14581458            nextRepMatchPrice = curAndLenCharPrice +
14591459                GET_PRICE_1(p->isMatch[state2][posStateNext]) +
14601460                GET_PRICE_1(p->isRep[state2]);
1461           
1461
14621462            /* for (; lenTest2 >= 2; lenTest2--) */
14631463            {
14641464              UInt32 offset = cur + lenTest + 1 + lenTest2;
r14530r14531
15701570    MovePos(p, repLen - 1);
15711571    return repLen;
15721572  }
1573 
1573
15741574  if (mainLen < 2 || numAvail <= 2)
15751575    return 1;
15761576 
r14530r14531
15841584        (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))
15851585      return 1;
15861586  }
1587 
1587
15881588  data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
15891589  for (i = 0; i < LZMA_NUM_REPS; i++)
15901590  {
r14530r14531
18451845        pos -= LZMA_NUM_REPS;
18461846        GetPosSlot(pos, posSlot);
18471847        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);
1848       
1848
18491849        if (posSlot >= kStartPosModelIndex)
18501850        {
18511851          UInt32 footerBits = ((posSlot >> 1) - 1);
r14530r14531
21502150  p->rc.outStream = &outStream.funcTable;
21512151 
21522152  res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
2153 
2153
21542154  *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
21552155  *destLen -= outStream.rem;
21562156  if (outStream.overflow)
src/lib/lib7z/Ppmd8.h
r14530r14531
133133void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol); /* symbol = -1 means EndMarker */
134134 
135135EXTERN_C_END
136
136
137137#endif
src/lib/lib7z/Lzma2Dec.c
r14530r14531
114114      else
115115        p->unpackSize = (UInt32)(p->control & 0x1F) << 16;
116116      return LZMA2_STATE_UNPACK0;
117   
117
118118    case LZMA2_STATE_UNPACK0:
119119      p->unpackSize |= (UInt32)b << 8;
120120      return LZMA2_STATE_UNPACK1;
121   
121
122122    case LZMA2_STATE_UNPACK1:
123123      p->unpackSize |= (UInt32)b;
124124      p->unpackSize++;
125125      PRF(printf(" %8d", p->unpackSize));
126126      return (LZMA2_IS_UNCOMPRESSED_STATE(p)) ? LZMA2_STATE_DATA : LZMA2_STATE_PACK0;
127   
127
128128    case LZMA2_STATE_PACK0:
129129      p->packSize = (UInt32)b << 8;
130130      return LZMA2_STATE_PACK1;
r14530r14531
199199      SizeT destSizeCur = dicLimit - dicPos;
200200      SizeT srcSizeCur = inSize - *srcLen;
201201      ELzmaFinishMode curFinishMode = LZMA_FINISH_ANY;
202     
202
203203      if (p->unpackSize <= destSizeCur)
204204      {
205205        destSizeCur = (SizeT)p->unpackSize;
r14530r14531
250250          Bool initState = (mode > 0);
251251          if ((!initDic && p->needInitDic) || (!initState && p->needInitState))
252252            return SZ_ERROR_DATA;
253         
253
254254          LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
255255          p->needInitDic = False;
256256          p->needInitState = False;
r14530r14531
258258        }
259259        if (srcSizeCur > p->packSize)
260260          srcSizeCur = (SizeT)p->packSize;
261         
261
262262        res = LzmaDec_DecodeToDic(&p->decoder, dicPos + destSizeCur, src, &srcSizeCur, curFinishMode, status);
263       
263
264264        src += srcSizeCur;
265265        *srcLen += srcSizeCur;
266266        p->packSize -= (UInt32)srcSizeCur;
src/lib/lib7z/Ppmd8Dec.c
r14530r14531
128128      i -= k;
129129    }
130130    while (i != num);
131   
131
132132    see = Ppmd8_MakeEscFreq(p, numMasked, &freqSum);
133133    freqSum += hiCnt;
134134    count = RangeDec_GetThreshold(p, freqSum);
135   
135
136136    if (count < hiCnt)
137137    {
138138      Byte symbol;
src/lib/lib7z/7z.h
r14530r14531
136136      *outBufferSize
137137    You can consider "*outBuffer" as cache of solid block. If your archive is solid,
138138    it will increase decompression speed.
139 
139
140140    If you use external function, you can declare these 3 cache variables
141141    (blockIndex, outBuffer, outBufferSize) as static in that external function.
142   
142
143143    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
144144*/
145145 
146146typedef struct
147147{
148148  CSzAr db;
149 
149
150150  UInt64 startPosAfterHeader;
151151  UInt64 dataPos;
152152 
src/lib/lib7z/Xz.h
r14530r14531
199199  unsigned indexPreSize;
200200 
201201  CXzStreamFlags streamFlags;
202 
202
203203  UInt32 blockHeaderSize;
204204  UInt64 packSize;
205205  UInt64 unpackSize;
src/lib/lib7z/Sha256.c
r14530r14531
133133  for (j = 0; j < 8; j++)
134134    state[j] += T[j];
135135  #endif
136 
136
137137  /* Wipe variables */
138138  /* memset(W, 0, sizeof(W)); */
139139  /* memset(T, 0, sizeof(T)); */
src/lib/lib7z/LzmaDec.c
r14530r14531
141141  Byte *dic = p->dic;
142142  SizeT dicBufSize = p->dicBufSize;
143143  SizeT dicPos = p->dicPos;
144 
144
145145  UInt32 processedPos = p->processedPos;
146146  UInt32 checkDicSize = p->checkDicSize;
147147  unsigned len = 0;
r14530r14531
324324            {
325325              NORMALIZE
326326              range >>= 1;
327             
327
328328              {
329329                UInt32 t;
330330                code -= range;
r14530r14531
723723  SizeT inSize = *srcLen;
724724  (*srcLen) = 0;
725725  LzmaDec_WriteRem(p, dicLimit);
726 
726
727727  *status = LZMA_STATUS_NOT_SPECIFIED;
728728 
729729  while (p->remainLen != kMatchSpecLenStart)
r14530r14531
769769 
770770      if (p->needInitState)
771771        LzmaDec_InitStateReal(p);
772 
772
773773      if (p->tempBufSize == 0)
774774      {
775775        SizeT processed;
r14530r14531
900900{
901901  UInt32 dicSize;
902902  Byte d;
903 
903
904904  if (size < LZMA_PROPS_SIZE)
905905    return SZ_ERROR_UNSUPPORTED;
906906  else
907907    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
908
908
909909  if (dicSize < LZMA_DIC_MIN)
910910    dicSize = LZMA_DIC_MIN;
911911  p->dicSize = dicSize;
src/lib/lib7z/LzmaDec.h
r14530r14531
130130  SZ_ERROR_MEM         - Memory allocation error
131131  SZ_ERROR_UNSUPPORTED - Unsupported properties
132132*/
133   
133
134134SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
135135void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
136136 
r14530r14531
159159*/
160160 
161161/* LzmaDec_DecodeToDic
162   
162
163163   The decoding to internal dictionary buffer (CLzmaDec::dic).
164164   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
165165 
src/lib/lib7z/XzIn.c
r14530r14531
8888    if (numBlocks != numBlocks64 || numBlocks * 2 > size)
8989      return SZ_ERROR_ARCHIVE;
9090  }
91 
91
9292  crcStartPos = pos;
9393  Xz_Free(p, alloc);
9494  if (numBlocks != 0)
r14530r14531
149149  RINOK(SeekFromCur(stream, startOffset));
150150 
151151  RINOK(LookInStream_Read2(stream, buf, XZ_STREAM_FOOTER_SIZE, SZ_ERROR_NO_ARCHIVE));
152 
152
153153  if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)
154154  {
155155    UInt32 total = 0;
r14530r14531
185185    if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)
186186      return SZ_ERROR_NO_ARCHIVE;
187187  }
188 
188
189189  p->flags = (CXzStreamFlags)GetBe16(buf + 8);
190190 
191191  if (!XzFlags_IsSupported(p->flags))
src/lib/lib7z/BraIA64.c
r14530r14531
4242        UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
4343        UInt32 dest;
4444        src |= ((UInt32)(instNorm >> 36) & 1) << 20;
45       
45
4646        src <<= 4;
47       
47
4848        if (encoding)
4949          dest = ip + (UInt32)i + src;
5050        else
5151          dest = src - (ip + (UInt32)i);
52       
52
5353        dest >>= 4;
54       
54
5555        instNorm &= ~((UInt64)(0x8FFFFF) << 13);
5656        instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
5757        instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));
58       
58
5959        instruction &= (1 << bitRes) - 1;
6060        instruction |= (instNorm << bitRes);
6161        for (j = 0; j < 6; j++)
src/lib/lib7z/Ppmd.h
r14530r14531
8282  p[i+7] = p[i+6] = p[i+5] = p[i+4] = p[i+3] = p[i+2] = p[i+1] = p[i+0] = ~(size_t)0; }}
8383 
8484EXTERN_C_END
85
85
8686#endif
src/lib/lib7z/Lzma86Enc.c
r14530r14531
2626  LzmaEncProps_Init(&props);
2727  props.level = level;
2828  props.dictSize = dictSize;
29 
29
3030  *destLen = 0;
3131  if (outSize2 < LZMA86_HEADER_SIZE)
3232    return SZ_ERROR_OUTPUT_EOF;
r14530r14531
7878        break;
7979      if (useFilter && i == 0)
8080        curModeIsFiltered = True;
81     
81
8282      curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,
8383          curModeIsFiltered ? filteredStream : src, srcLen,
8484          &props, dest + 1, &outPropsSize, 0,
8585          NULL, &g_Alloc, &g_Alloc);
86     
86
8787      if (curRes != SZ_ERROR_OUTPUT_EOF)
8888      {
8989        if (curRes != SZ_OK)
src/lib/lib7z/Ppmd7.c
r14530r14531
148148  #else
149149  CPpmd7_Node_Ref head = p->AlignOffset + p->Size;
150150  #endif
151 
151
152152  CPpmd7_Node_Ref n = head;
153153  unsigned i;
154154 
r14530r14531
175175  NODE(n)->Prev = head;
176176  if (p->LoUnit != p->HiUnit)
177177    ((CPpmd7_Node *)p->LoUnit)->Stamp = 1;
178 
178
179179  /* Glue free blocks */
180180  while (n != head)
181181  {
r14530r14531
193193    }
194194    n = node->Next;
195195  }
196 
196
197197  /* Fill lists of free blocks */
198198  for (n = NODE(head)->Next; n != head;)
199199  {
r14530r14531
319319      for (m = 0; m < 64; m += 8)
320320        dest[m] = val;
321321    }
322 
322
323323  for (i = 0; i < 25; i++)
324324    for (k = 0; k < 16; k++)
325325    {
r14530r14531
345345  CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState);
346346  CPpmd_State *ps[PPMD7_MAX_ORDER];
347347  unsigned numPs = 0;
348 
348
349349  if (!skip)
350350    ps[numPs++] = p->FoundState;
351 
351
352352  while (c->Suffix)
353353  {
354354    CPpmd_Void_Ref successor;
r14530r14531
370370    }
371371    ps[numPs++] = s;
372372  }
373 
373
374374  upState.Symbol = *(const Byte *)Ppmd7_GetPtr(p, upBranch);
375375  SetSuccessor(&upState, upBranch + 1);
376 
376
377377  if (c->NumStats == 1)
378378    upState.Freq = ONE_STATE(c)->Freq;
379379  else
r14530r14531
407407    c = c1;
408408  }
409409  while (numPs != 0);
410 
410
411411  return c;
412412}
413413 
r14530r14531
423423  CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState);
424424  CTX_PTR c;
425425  unsigned s0, ns;
426 
426
427427  if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0)
428428  {
429429    c = SUFFIX(p->MinContext);
430   
430
431431    if (c->NumStats == 1)
432432    {
433433      CPpmd_State *s = ONE_STATE(c);
r14530r14531
465465    SetSuccessor(p->FoundState, REF(p->MinContext));
466466    return;
467467  }
468 
468
469469  *p->Text++ = p->FoundState->Symbol;
470470  successor = REF(p->Text);
471471  if (p->Text >= p->UnitsStart)
r14530r14531
473473    RestartModel(p);
474474    return;
475475  }
476 
476
477477  if (fSuccessor)
478478  {
479479    if (fSuccessor <= successor)
r14530r14531
497497    SetSuccessor(p->FoundState, successor);
498498    fSuccessor = REF(p->MinContext);
499499  }
500 
500
501501  s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - (p->FoundState->Freq - 1);
502 
502
503503  for (c = p->MaxContext; c != p->MinContext; c = SUFFIX(c))
504504  {
505505    unsigned ns1;
r14530r14531
566566  }
567567  p->MaxContext = p->MinContext = CTX(fSuccessor);
568568}
569 
569
570570static void Rescale(CPpmd7 *p)
571571{
572572  unsigned i, adder, sumFreq, escFreq;
r14530r14531
583583  adder = (p->OrderFall != 0);
584584  s->Freq = (Byte)((s->Freq + adder) >> 1);
585585  sumFreq = s->Freq;
586 
586
587587  i = p->MinContext->NumStats - 1;
588588  do
589589  {
r14530r14531
601601    }
602602  }
603603  while (--i);
604 
604
605605  if (s->Freq == 0)
606606  {
607607    unsigned numStats = p->MinContext->NumStats;
src/lib/lib7z/Alloc.c
r14530r14531
9999  #ifdef _SZ_ALLOC_DEBUG
100100  fprintf(stderr, "\nAlloc_Big %10d bytes;  count = %10d", size, g_allocCountBig++);
101101  #endif
102 
102
103103  #ifdef _7ZIP_LARGE_PAGES
104104  if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
105105  {
r14530r14531
118118  if (address != 0)
119119    fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
120120  #endif
121 
121
122122  if (address == 0)
123123    return;
124124  VirtualFree(address, 0, MEM_RELEASE);
src/lib/lib7z/Ppmd7.h
r14530r14531
136136void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol);
137137 
138138EXTERN_C_END
139
139
140140#endif
src/lib/lib7z/BwtSort.c
r14530r14531
9696        gPrev = Groups[sp];
9797        temp[0] = (gPrev << NumRefBits);
9898      }
99     
99
100100      for (j = 1; j < groupSize; j++)
101101      {
102102        UInt32 sp = ind2[j] + NumSortedBytes;
r14530r14531
114114        return 1;
115115      }
116116    }
117   
117
118118    HeapSort(temp, groupSize);
119119    mask = ((1 << NumRefBits) - 1);
120120    thereAreGroups = 0;
121   
121
122122    group = groupOffset;
123123    cg = (temp[0] >> NumRefBits);
124124    temp[0] = ind2[temp[0] & mask];
r14530r14531
129129    #else
130130    UInt32 prevGroupStart = 0;
131131    #endif
132   
132
133133    for (j = 1; j < groupSize; j++)
134134    {
135135      UInt32 val = temp[j];
136136      UInt32 cgCur = (val >> NumRefBits);
137     
137
138138      if (cgCur != cg)
139139      {
140140        cg = cgCur;
r14530r14531
398398    for (i = 0; i < blockSize - 1; i++)
399399      Indices[counters[((UInt32)data[i] << 8) | data[i + 1]]++] = i;
400400    Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i;
401   
401
402402    #ifndef BLOCK_SORT_EXTERNAL_FLAGS
403403    {
404404    UInt32 prev = 0;
r14530r14531
441441      for (groupSize = 1;
442442        (Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0;
443443        groupSize++);
444     
444
445445      groupSize++;
446446 
447447      #else
r14530r14531
473473      }
474474 
475475      #endif
476     
476
477477      if (NumSortedBytes >= blockSize)
478478      {
479479        UInt32 j;
src/lib/lib7z/Bra.c
r14530r14531
4848        ((UInt32)data[i + 0] << 11) |
4949        (((UInt32)data[i + 3] & 0x7) << 8) |
5050        (data[i + 2]);
51     
51
5252      src <<= 1;
5353      if (encoding)
5454        dest = ip + (UInt32)i + src;
5555      else
5656        dest = src - (ip + (UInt32)i);
5757      dest >>= 1;
58     
58
5959      data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
6060      data[i + 0] = (Byte)(dest >> 11);
6161      data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
r14530r14531
8080        ((UInt32)data[i + 1] << 16) |
8181        ((UInt32)data[i + 2] << 8) |
8282        ((UInt32)data[i + 3] & (~3));
83     
83
8484      UInt32 dest;
8585      if (encoding)
8686        dest = ip + (UInt32)i + src;
r14530r14531
113113        ((UInt32)data[i + 2] << 8) |
114114        ((UInt32)data[i + 3]);
115115      UInt32 dest;
116     
116
117117      src <<= 2;
118118      if (encoding)
119119        dest = ip + i + src;
120120      else
121121        dest = src - (ip + i);
122122      dest >>= 2;
123     
123
124124      dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
125125 
126126      data[i + 0] = (Byte)(dest >> 24);
src/lib/lib7z/Bra.h
r14530r14531
1313/*
1414These functions convert relative addresses to absolute addresses
1515in CALL instructions to increase the compression ratio.
16 
16
1717  In:
1818    data     - data buffer
1919    size     - size of data
2020    ip       - current virtual Instruction Pinter (IP) value
2121    state    - state variable for x86 converter
2222    encoding - 0 (for decoding), 1 (for encoding)
23 
23
2424  Out:
2525    state    - state variable for x86 converter
2626 
2727  Returns:
2828    The number of processed bytes. If you call these functions with multiple calls,
2929    you must start next call with first byte after block of processed bytes.
30 
30
3131  Type   Endian  Alignment  LookAhead
32 
32
3333  x86    little      1          4
3434  ARMT   little      2          2
3535  ARM    little      4          0
src/lib/lib7z/Ppmd7Enc.c
r14530r14531
104104      sum += s->Freq;
105105    }
106106    while (--i);
107   
107
108108    p->HiBitsFlag = p->HB2Flag[p->FoundState->Symbol];
109109    PPMD_SetAllBitsIn256Bytes(charMask);
110110    MASK(s->Symbol) = 0;
r14530r14531
149149      p->MinContext = Ppmd7_GetContext(p, p->MinContext->Suffix);
150150    }
151151    while (p->MinContext->NumStats == numMasked);
152   
152
153153    see = Ppmd7_MakeEscFreq(p, numMasked, &escFreq);
154154    s = Ppmd7_GetStats(p, p->MinContext);
155155    sum = 0;
r14530r14531
178178      s++;
179179    }
180180    while (--i);
181   
181
182182    RangeEnc_Encode(rc, sum, escFreq, sum + escFreq);
183183    see->Summ = (UInt16)(see->Summ + sum + escFreq);
184184  }
src/lib/lib7z/CpuArch.c
r14530r14531
8181    : "0" (function)) ;
8282 
8383  #endif
84 
84
8585  #else
8686 
8787  int CPUInfo[4];
src/lib/lib7z/LzFindMt.c
r14530r14531
5858    p->csWasEntered = False;
5959  }
6060  Semaphore_Release1(&p->freeSemaphore);
61
61
6262  Event_Wait(&p->wasStopped);
6363 
6464  while (myNumBlocks++ != p->numProcessedBlocks)
r14530r14531
108108  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->canStart));
109109  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStarted));
110110  RINOK_THREAD(AutoResetEvent_CreateNotSignaled(&p->wasStopped));
111 
111
112112  RINOK_THREAD(Semaphore_Create(&p->freeSemaphore, numBlocks, numBlocks));
113113  RINOK_THREAD(Semaphore_Create(&p->filledSemaphore, 0, numBlocks));
114114 
115115  p->needStart = True;
116 
116
117117  RINOK_THREAD(Thread_Create(&p->thread, startAddress, obj));
118118  p->wasCreated = True;
119119  return SZ_OK;
r14530r14531
385385    CriticalSection_Enter(&sync->cs);
386386    sync->csWasEntered = True;
387387  }
388 
388
389389  BtGetMatches(p, p->btBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize);
390390 
391391  if (p->pos > kMtMaxValForNormalize - kMtBtBlockSize)
r14530r14531
561561  const Byte *cur = p->pointerToCurPos;
562562  UInt32 lzPos = p->lzPos;
563563  MT_HASH2_CALC
564     
564
565565  curMatch2 = hash[hash2Value];
566566  hash[hash2Value] = lzPos;
567567 
r14530r14531
584584 
585585  curMatch2 = hash[                hash2Value];
586586  curMatch3 = hash[kFix3HashSize + hash3Value];
587 
587
588588  hash[                hash2Value] =
589589  hash[kFix3HashSize + hash3Value] =
590590    lzPos;
r14530r14531
616616  const Byte *cur = p->pointerToCurPos;
617617  UInt32 lzPos = p->lzPos;
618618  MT_HASH4_CALC
619     
619
620620  curMatch2 = hash[                hash2Value];
621621  curMatch3 = hash[kFix3HashSize + hash3Value];
622622  curMatch4 = hash[kFix4HashSize + hash4Value];
623 
623
624624  hash[                hash2Value] =
625625  hash[kFix3HashSize + hash3Value] =
626626  hash[kFix4HashSize + hash4Value] =
src/lib/lib7z/7zIn.c
r14530r14531
537537{
538538  UInt32 numCoders, numBindPairs, numPackStreams, i;
539539  UInt32 numInStreams = 0, numOutStreams = 0;
540 
540
541541  RINOK(SzReadNumber32(sd, &numCoders));
542542  if (numCoders > NUM_FOLDER_CODERS_MAX)
543543    return SZ_ERROR_UNSUPPORTED;
544544  folder->NumCoders = numCoders;
545 
545
546546  MY_ALLOC(CSzCoderInfo, folder->Coders, (size_t)numCoders, alloc);
547547 
548548  for (i = 0; i < numCoders; i++)
r14530r14531
810810      numDigests += numSubstreams;
811811  }
812812 
813
813
814814  si = 0;
815815  for (;;)
816816  {
r14530r14531
963963    RINOK(SzReadArchiveProperties(sd));
964964    RINOK(SzReadID(sd, &type));
965965  }
966 
967 
966 
967 
968968  if (type == k7zIdMainStreamsInfo)
969969  {
970970    RINOK(SzReadStreamsInfo(sd,
r14530r14531
982982    return SZ_OK;
983983  if (type != k7zIdFilesInfo)
984984    return SZ_ERROR_ARCHIVE;
985 
985
986986  RINOK(SzReadNumber32(sd, &numFiles));
987987  p->db.NumFiles = numFiles;
988988 
r14530r14531
11651165  RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,
11661166      &numUnpackStreams,  unpackSizes, digestsDefined, digests,
11671167      allocTemp, allocTemp));
1168 
1168
11691169  dataStartPos += baseOffset;
11701170  if (p->NumFolders != 1)
11711171    return SZ_ERROR_ARCHIVE;
11721172 
11731173  folder = p->Folders;
11741174  unpackSize = SzFolder_GetUnpackSize(folder);
1175 
1175
11761176  RINOK(LookInStream_SeekTo(inStream, dataStartPos));
11771177 
11781178  if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))
11791179    return SZ_ERROR_MEM;
1180 
1180
11811181  res = SzFolder_Decode(folder, p->PackSizes,
11821182          inStream, dataStartPos,
11831183          outBuffer->data, (size_t)unpackSize, allocTemp);
r14530r14531
12401240  nextHeaderCRC = GetUi32(header + 28);
12411241 
12421242  p->startPosAfterHeader = startArcPos + k7zStartHeaderSize;
1243 
1243
12441244  if (CrcCalc(header + 12, 20) != GetUi32(header + 8))
12451245    return SZ_ERROR_CRC;
12461246 
r14530r14531
13561356    *blockIndex = folderIndex;
13571357    IAlloc_Free(allocMain, *outBuffer);
13581358    *outBuffer = 0;
1359   
1359
13601360    RINOK(LookInStream_SeekTo(inStream, startOffset));
1361   
1361
13621362    if (res == SZ_OK)
13631363    {
13641364      *outBufferSize = unpackSize;
src/lib/lib7z/XzEnc.c
r14530r14531
409409    int filterIndex = 0;
410410    CXzFilter *filter = NULL;
411411    const CXzFilterProps *fp = props->filterProps;
412   
412
413413    XzBlock_ClearFlags(&block);
414414    XzBlock_SetNumFilters(&block, 1 + (fp ? 1 : 0));
415   
415
416416    if (fp)
417417    {
418418      filter = &block.filters[filterIndex++];
r14530r14531
440440    seqSizeOutStream.p.Write = MyWrite;
441441    seqSizeOutStream.realStream = outStream;
442442    seqSizeOutStream.processed = 0;
443   
443
444444    RINOK(XzBlock_WriteHeader(&block, &seqSizeOutStream.p));
445   
445
446446    checkInStream.p.Read = SeqCheckInStream_Read;
447447    checkInStream.realStream = inStream;
448448    SeqCheckInStream_Init(&checkInStream, XzFlags_GetCheckType(xz->flags));
449   
449
450450    if (fp)
451451    {
452452      #ifdef USE_SUBBLOCK
src/lib/lib7z/LzFindMt.h
r14530r14531
6262  const UInt32 *crc;
6363 
6464  Mf_Mix_Matches MixMatchesFunc;
65 
65
6666  /* LZ + BT */
6767  CMtSync btSync;
6868  Byte btDummy[kMtCacheLineDummy];
r14530r14531
8585  /* BT + Hash */
8686  CMtSync hashSync;
8787  /* Byte hashDummy[kMtCacheLineDummy]; */
88 
88
8989  /* Hash */
9090  Mf_GetHeads GetHeadsFunc;
9191  CMatchFinder *MatchFinder;
src/lib/lib7z/MtCoder.c
r14530r14531
190190  *stop = True;
191191  if (Event_Wait(&p->canRead) != 0)
192192    return SZ_ERROR_THREAD;
193 
193
194194  next = GET_NEXT_THREAD(p);
195 
195
196196  if (p->stopReading)
197197  {
198198    next->stopReading = True;
src/lib/formats/pc_dsk.c
r14530r14531
300300   const format &f = formats[type];
301301   if(!f.desc)
302302      return false;
303   
303
304304   UINT8 sectdata[36*512];
305305   desc_s sectors[36];
306306   for(int i=0; i<f.sector_count; i++) {
src/lib/util/chd.c
r14530r14531
9090   COMPRESSION_NONE = 4,                  // no compression; implicit length = hunkbytes
9191   COMPRESSION_SELF = 5,                  // same as another block in this chd
9292   COMPRESSION_PARENT = 6,                  // same as a hunk's worth of units in the parent chd
93   
93
9494   // these additional pseudo-types are used for compressed encodings:
9595   COMPRESSION_RLE_SMALL,                  // start of small RLE run (4-bit length)
9696   COMPRESSION_RLE_LARGE,                  // start of large RLE run (8-bit length)
r14530r14531
125125
126126struct chd_file::metadata_hash
127127{
128   UINT8                tag[4];         // tag of the metadata in big-endian
129   sha1_t                sha1;         // hash data
128   UINT8               tag[4];         // tag of the metadata in big-endian
129   sha1_t               sha1;         // hash data
130130};
131131
132132
r14530r14531
179179
180180
181181//-------------------------------------------------
182//  be_write_sha1 - write a sha1_t to a data
182//  be_write_sha1 - write a sha1_t to a data
183183//  stream in bigendian order
184184//-------------------------------------------------
185185
r14530r14531
199199   // no file = failure
200200   if (m_file == NULL)
201201      throw CHDERR_NOT_OPEN;
202   
202
203203   // seek and read
204204   core_fseek(m_file, offset, SEEK_SET);
205205   UINT32 count = core_fread(m_file, dest, length);
r14530r14531
218218   // no file = failure
219219   if (m_file == NULL)
220220      throw CHDERR_NOT_OPEN;
221   
221
222222   // seek and write
223223   core_fseek(m_file, offset, SEEK_SET);
224224   UINT32 count = core_fwrite(m_file, source, length);
r14530r14531
229229
230230//-------------------------------------------------
231231//  file_append - append to the file at the given
232//  offset, ensuring we start at the given
232//  offset, ensuring we start at the given
233233//  alignment; on failure throw an error
234234//-------------------------------------------------
235235
r14530r14531
346346      // determine offset within the file for data-only
347347      if (m_rawsha1_offset == 0)
348348         throw CHDERR_UNSUPPORTED_VERSION;
349     
349
350350      // read the big-endian version
351351      UINT8 rawbuf[sizeof(sha1_t)];
352352      file_read(m_rawsha1_offset, rawbuf, sizeof(rawbuf));
r14530r14531
371371      // determine offset within the file
372372      if (m_parentsha1_offset == 0)
373373         throw CHDERR_UNSUPPORTED_VERSION;
374     
374
375375      // read the big-endian version
376376      UINT8 rawbuf[sizeof(sha1_t)];
377377      file_read(m_parentsha1_offset, rawbuf, sizeof(rawbuf));
r14530r14531
395395   // error if invalid
396396   if (hunknum >= m_hunkcount)
397397      return CHDERR_HUNK_OUT_OF_RANGE;
398   
398
399399   // get the map pointer
400400   UINT8 *rawmap;
401401   switch (m_version)
r14530r14531
410410               compressor = CHD_CODEC_ZLIB;
411411               compbytes = be_read(&rawmap[12], 2) + (rawmap[14] << 16);
412412               break;
413               
413
414414            case V34_MAP_ENTRY_TYPE_UNCOMPRESSED:
415415               compressor = CHD_CODEC_NONE;
416416               compbytes = m_hunkbytes;
417417               break;
418               
418
419419            case V34_MAP_ENTRY_TYPE_MINI:
420420               compressor = CHD_CODEC_MINI;
421421               compbytes = 0;
422422               break;
423           
423
424424            case V34_MAP_ENTRY_TYPE_SELF_HUNK:
425425               compressor = CHD_CODEC_SELF;
426426               compbytes = 0;
r14530r14531
432432               break;
433433         }
434434         break;
435     
435
436436      // v5 map entries
437437      case 5:
438438         rawmap = m_rawmap + m_mapentrybytes * hunknum;
r14530r14531
452452            }
453453            break;
454454         }
455         
455
456456         // compressed case
457457         switch (rawmap[0])
458458         {
r14530r14531
473473               compressor = CHD_CODEC_SELF;
474474               compbytes = 0;
475475               break;
476               
476
477477            case COMPRESSION_PARENT:
478478               compressor = CHD_CODEC_PARENT;
479479               compbytes = 0;
r14530r14531
494494   // create a big-endian version
495495   UINT8 rawbuf[sizeof(sha1_t)];
496496   be_write_sha1(rawbuf, rawdata);
497   
497
498498   // write to the header
499499   UINT64 offset = (m_rawsha1_offset != 0) ? m_rawsha1_offset : m_sha1_offset;
500500   assert(offset != 0);
501501   file_write(offset, rawbuf, sizeof(rawbuf));
502   
502
503503   // if we have a separate rawsha1_offset, update the full sha1 as well
504504   if (m_rawsha1_offset != 0)
505505      metadata_update_hash();
r14530r14531
519519   // create a big-endian version
520520   UINT8 rawbuf[sizeof(sha1_t)];
521521   be_write_sha1(rawbuf, parent);
522   
522
523523   // write to the header
524524   assert(m_parentsha1_offset != 0);
525525   file_write(m_parentsha1_offset, rawbuf, sizeof(rawbuf));
r14530r14531
602602   // create the file normally, then claim the file
603603   chd_error chderr = create(*file, logicalbytes, hunkbytes, unitbytes, compression);
604604   m_owns_file = true;
605   
605
606606   // if an error happened, close and delete the file
607607   if (chderr != CHDERR_NONE)
608608   {
r14530r14531
633633   // create the file normally, then claim the file
634634   chd_error chderr = create(*file, logicalbytes, hunkbytes, compression, parent);
635635   m_owns_file = true;
636   
636
637637   // if an error happened, close and delete the file
638638   if (chderr != CHDERR_NONE)
639639   {
r14530r14531
669669      core_fclose(file);
670670      return err;
671671   }
672     
672
673673   // we now own this file
674674   m_owns_file = true;
675675   return err;
r14530r14531
708708   m_owns_file = false;
709709   m_allow_reads = false;
710710   m_allow_writes = false;
711   
711
712712   // reset core parameters from the header
713713   m_version = HEADER_VERSION;
714714   m_logicalbytes = 0;
r14530r14531
759759      // punt if no file
760760      if (m_file == NULL)
761761         throw CHDERR_NOT_OPEN;
762     
762
763763      // return an error if out of range
764764      if (hunknum >= m_hunkcount)
765765         throw CHDERR_HUNK_OUT_OF_RANGE;
r14530r14531
787787                  if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && dest != NULL && crc32_creator::simple(dest, m_hunkbytes) != blockcrc)
788788                     throw CHDERR_DECOMPRESSION_ERROR;
789789                  return CHDERR_NONE;
790                 
790
791791               case V34_MAP_ENTRY_TYPE_UNCOMPRESSED:
792792                  file_read(blockoffs, dest, m_hunkbytes);
793793                  if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && crc32_creator::simple(dest, m_hunkbytes) != blockcrc)
794794                     throw CHDERR_DECOMPRESSION_ERROR;
795795                  return CHDERR_NONE;
796                 
796
797797               case V34_MAP_ENTRY_TYPE_MINI:
798798                  be_write(dest, blockoffs, 8);
799799                  for (UINT32 bytes = 8; bytes < m_hunkbytes; bytes++)
r14530r14531
801801                  if (!(rawmap[15] & V34_MAP_ENTRY_FLAG_NO_CRC) && crc32_creator::simple(dest, m_hunkbytes) != blockcrc)
802802                     throw CHDERR_DECOMPRESSION_ERROR;
803803                  return CHDERR_NONE;
804               
804
805805               case V34_MAP_ENTRY_TYPE_SELF_HUNK:
806806                  return read_hunk(blockoffs, dest);
807807
r14530r14531
811811                  return m_parent->read_hunk(blockoffs, dest);
812812            }
813813            break;
814         
814
815815         // v5 map entries
816816         case 5:
817817            rawmap = m_rawmap + m_mapentrybytes * hunknum;
r14530r14531
819819            // uncompressed case
820820            if (!compressed())
821821            {
822               blockoffs = UINT64(be_read(rawmap, 4)) * UINT64(m_hunkbytes);
822               blockoffs = UINT64(be_read(rawmap, 4)) * UINT64(m_hunkbytes);
823823               if (blockoffs != 0)
824824                  file_read(blockoffs, dest, m_hunkbytes);
825825               else if (m_parent_missing)
r14530r14531
830830                  memset(dest, 0, m_hunkbytes);
831831               return CHDERR_NONE;
832832            }
833           
833
834834            // compressed case
835835            blocklen = be_read(&rawmap[1], 3);
836836            blockoffs = be_read(&rawmap[4], 6);
r14530r14531
857857
858858               case COMPRESSION_SELF:
859859                  return read_hunk(blockoffs, dest);
860                 
860
861861               case COMPRESSION_PARENT:
862862                  if (m_parent_missing)
863863                     throw CHDERR_REQUIRES_PARENT;
r14530r14531
865865            }
866866            break;
867867      }
868     
868
869869      // if we get here, something was wrong
870870      throw CHDERR_READ_ERROR;
871871   }
872   
872
873873   // just return errors
874874   catch (chd_error &err)
875875   {
r14530r14531
902902      // uncompressed writes only via this interface
903903      if (compressed())
904904         throw CHDERR_FILE_NOT_WRITEABLE;
905     
905
906906      // see if we have allocated the space on disk for this hunk
907907      UINT8 *rawmap = m_rawmap + hunknum * 4;
908908      UINT32 rawentry = be_read(rawmap, 4);
r14530r14531
919919               all_zeros = false;
920920               break;
921921            }
922         
922
923923         // if it's all zeros, do nothing more
924924         if (all_zeros)
925925            return CHDERR_NONE;
926     
926
927927         // append new data to the end of the file, aligning the first chunk
928928         rawentry = file_append(buffer, m_hunkbytes, m_hunkbytes) / m_hunkbytes;
929         
929
930930         // write the map entry back
931931         be_write(rawmap, rawentry, 4);
932932         file_write(m_mapoffset + hunknum * 4, rawmap, 4);
933         
933
934934         // update the cached hunk if we just wrote it
935935         if (hunknum == m_cachehunk && buffer != m_cache)
936936            memcpy(m_cache, buffer, m_hunkbytes);
937937      }
938     
938
939939      // otherwise, just overwrite
940940      else
941941         file_write(UINT64(rawentry) * UINT64(m_hunkbytes), buffer, m_hunkbytes);
942942      return CHDERR_NONE;
943943   }
944   
944
945945   // just return errors
946946   catch (chd_error &err)
947947   {
r14530r14531
973973
974974
975975//-------------------------------------------------
976//  read_bytes - read from the CHD at a byte level,
976//  read_bytes - read from the CHD at a byte level,
977977//  using the cache to handle partial hunks
978978//-------------------------------------------------
979979
r14530r14531
988988      // determine start/end boundaries
989989      UINT32 startoffs = (curhunk == first_hunk) ? (offset % m_hunkbytes) : 0;
990990      UINT32 endoffs = (curhunk == last_hunk) ? ((offset + bytes - 1) % m_hunkbytes) : (m_hunkbytes - 1);
991     
991
992992      // if it's a full block, just read directly from disk unless it's the cached hunk
993993      chd_error err = CHDERR_NONE;
994994      if (startoffs == 0 && endoffs == m_hunkbytes - 1 && curhunk != m_cachehunk)
995995         err = read_hunk(curhunk, dest);
996     
996
997997      // otherwise, read from the cache
998998      else
999999      {
r14530r14531
10321032      // determine start/end boundaries
10331033      UINT32 startoffs = (curhunk == first_hunk) ? (offset % m_hunkbytes) : 0;
10341034      UINT32 endoffs = (curhunk == last_hunk) ? ((offset + bytes - 1) % m_hunkbytes) : (m_hunkbytes - 1);
1035     
1035
10361036      // if it's a full block, just write directly to disk unless it's the cached hunk
10371037      chd_error err = CHDERR_NONE;
10381038      if (startoffs == 0 && endoffs == m_hunkbytes - 1 && curhunk != m_cachehunk)
10391039         err = write_hunk(curhunk, source);
1040     
1040
10411041      // otherwise, write from the cache
10421042      else
10431043      {
r14530r14531
10801080      file_read(metaentry.offset + METADATA_HEADER_SIZE, output.stringbuffer(metaentry.length), metaentry.length);
10811081      return CHDERR_NONE;
10821082   }
1083   
1083
10841084   // just return errors
10851085   catch (chd_error &err)
10861086   {
r14530r14531
11031103      file_read(metaentry.offset + METADATA_HEADER_SIZE, output, metaentry.length);
11041104      return CHDERR_NONE;
11051105   }
1106   
1106
11071107   // just return errors
11081108   catch (chd_error &err)
11091109   {
r14530r14531
11261126      file_read(metaentry.offset + METADATA_HEADER_SIZE, output, MIN(outputlen, resultlen));
11271127      return CHDERR_NONE;
11281128   }
1129   
1129
11301130   // just return errors
11311131   catch (chd_error &err)
11321132   {
r14530r14531
11511151      resultflags = metaentry.flags;
11521152      return CHDERR_NONE;
11531153   }
1154   
1154
11551155   // just return errors
11561156   catch (chd_error &err)
11571157   {
r14530r14531
11911191               be_write(length, inputlen, 3);
11921192               file_write(metaentry.offset + 5, length, sizeof(length));
11931193            }
1194           
1194
11951195            // indicate we did everything
11961196            finished = true;
11971197         }
1198         
1198
11991199         // if it doesn't fit, unlink the current entry
12001200         else
12011201            metadata_set_previous_next(metaentry.prev, metaentry.next);
12021202      }
1203   
1203
12041204      // if not yet done, create a new entry and append
12051205      if (!finished)
12061206      {
r14530r14531
12101210         raw_meta_header[4] = flags;
12111211         be_write(&raw_meta_header[5], (inputlen & 0x00ffffff) | (flags << 24), 3);
12121212         be_write(&raw_meta_header[8], 0, 8);
1213         
1213
12141214         // append the new header, then the data
12151215         UINT64 offset = file_append(raw_meta_header, sizeof(raw_meta_header));
12161216         file_append(inputbuf, inputlen);
r14530r14531
12231223      metadata_update_hash();
12241224      return CHDERR_NONE;
12251225   }
1226   
1226
12271227   // return any errors
12281228   catch (chd_error &err)
12291229   {
r14530r14531
12461246      metadata_entry metaentry;
12471247      if (!metadata_find(metatag, metaindex, metaentry))
12481248         throw CHDERR_METADATA_NOT_FOUND;
1249     
1249
12501250      // point the previous to the next, unlinking us
12511251      metadata_set_previous_next(metaentry.prev, metaentry.next);
12521252      return CHDERR_NONE;
12531253   }
1254   
1254
12551255   // return any errors
12561256   catch (chd_error &err)
12571257   {
r14530r14531
12611261
12621262
12631263//-------------------------------------------------
1264//  clone_all_metadata - clone the metadata from
1264//  clone_all_metadata - clone the metadata from
12651265//  one CHD to a second
12661266//-------------------------------------------------
12671267
r14530r14531
12821282         // read the metadata item
12831283         filedata.resize(metaentry.length);
12841284         source.file_read(metaentry.offset + METADATA_HEADER_SIZE, filedata, metaentry.length);
1285         
1285
12861286         // write it to the destination
1287         chd_error err = write_metadata(metaentry.metatag, -1, filedata, metaentry.length, metaentry.flags);
1287         chd_error err = write_metadata(metaentry.metatag, (UINT32)-1, filedata, metaentry.length, metaentry.flags);
12881288         if (err != CHDERR_NONE)
12891289            throw err;
12901290      }
12911291      return CHDERR_NONE;
12921292   }
1293   
1293
12941294   // return any errors
12951295   catch (chd_error &err)
12961296   {
r14530r14531
13631363         }
13641364      return CHDERR_INVALID_PARAMETER;
13651365   }
1366   
1366
13671367   // return any errors
13681368   catch (chd_error &err)
13691369   {
r14530r14531
14251425
14261426//-------------------------------------------------
14271427//  guess_unitbytes - for older CHD formats, take
1428//   a guess at the bytes/unit based on metadata
1428//  a guess at the bytes/unit based on metadata
14291429//-------------------------------------------------
14301430
14311431UINT32 chd_file::guess_unitbytes()
r14530r14531
14411441      read_metadata(CDROM_TRACK_METADATA_TAG, 0, metadata) == CHDERR_NONE ||
14421442      read_metadata(CDROM_TRACK_METADATA2_TAG, 0, metadata) == CHDERR_NONE)
14431443      return CD_FRAME_SIZE;
1444   
1444
14451445   // otherwise, just map 1:1 with the hunk size
14461446   return m_hunkbytes;
14471447}
r14530r14531
14641464   m_metaoffset = be_read(&rawheader[36], 8);
14651465   m_hunkbytes = be_read(&rawheader[76], 4);
14661466   m_hunkcount = be_read(&rawheader[24], 4);
1467   
1467
14681468   // extract parent SHA-1
14691469   UINT32 flags = be_read(&rawheader[16], 4);
14701470   if ((flags & 2) && m_allow_writes)
r14530r14531
14801480      default: throw CHDERR_UNKNOWN_COMPRESSION;
14811481   }
14821482   m_compression[1] = m_compression[2] = m_compression[3] = CHD_CODEC_NONE;
1483   
1483
14841484   // describe the format
14851485   m_mapoffset_offset = 0;
14861486   m_metaoffset_offset = 36;
14871487   m_sha1_offset = 80;
14881488   m_rawsha1_offset = 0;
14891489   m_parentsha1_offset = 100;
1490   
1490
14911491   // determine properties of map entries
14921492   m_mapentrybytes = 16;
14931493
14941494   // extract parent SHA-1
14951495   if (flags & 1)
14961496      parentsha1 = be_read_sha1(&rawheader[m_parentsha1_offset]);
1497   
1497
14981498   // guess at the units based on snooping the metadata
14991499   m_unitbytes = guess_unitbytes();
15001500   m_unitcount = (m_logicalbytes + m_unitbytes - 1) / m_unitbytes;
r14530r14531
15181518   m_metaoffset = be_read(&rawheader[36], 8);
15191519   m_hunkbytes = be_read(&rawheader[44], 4);
15201520   m_hunkcount = be_read(&rawheader[24], 4);
1521   
1521
15221522   // extract parent SHA-1
15231523   UINT32 flags = be_read(&rawheader[16], 4);
15241524   if ((flags & 2) && m_allow_writes)
r14530r14531
15341534      default: throw CHDERR_UNKNOWN_COMPRESSION;
15351535   }
15361536   m_compression[1] = m_compression[2] = m_compression[3] = CHD_CODEC_NONE;
1537   
1537
15381538   // describe the format
15391539   m_mapoffset_offset = 0;
15401540   m_metaoffset_offset = 36;
15411541   m_sha1_offset = 48;
15421542   m_rawsha1_offset = 88;
15431543   m_parentsha1_offset = 68;
1544   
1544
15451545   // determine properties of map entries
15461546   m_mapentrybytes = 16;
15471547
15481548   // extract parent SHA-1
15491549   if (flags & 1)
15501550      parentsha1 = be_read_sha1(&rawheader[m_parentsha1_offset]);
1551   
1551
15521552   // guess at the units based on snooping the metadata
15531553   m_unitbytes = guess_unitbytes();
15541554   m_unitcount = (m_logicalbytes + m_unitbytes - 1) / m_unitbytes;
r14530r14531
15741574   m_hunkcount = (m_logicalbytes + m_hunkbytes - 1) / m_hunkbytes;
15751575   m_unitbytes = be_read(&rawheader[60], 4);
15761576   m_unitcount = (m_logicalbytes + m_unitbytes - 1) / m_unitbytes;
1577   
1577
15781578   // determine compression
15791579   m_compression[0] = be_read(&rawheader[16], 4);
15801580   m_compression[1] = be_read(&rawheader[20], 4);
15811581   m_compression[2] = be_read(&rawheader[24], 4);
15821582   m_compression[3] = be_read(&rawheader[28], 4);
1583   
1583
15841584   // describe the format
15851585   m_mapoffset_offset = 40;
15861586   m_metaoffset_offset = 48;
15871587   m_sha1_offset = 84;
15881588   m_rawsha1_offset = 64;
15891589   m_parentsha1_offset = 104;
1590   
1590
15911591   // determine properties of map entries
15921592   m_mapentrybytes = compressed() ? 12 : 4;
15931593
r14530r14531
16081608      // first get a CRC-16 of the original rawmap
16091609      crc16_t mapcrc = crc16_creator::simple(m_rawmap, m_hunkcount * 12);
16101610
1611      // create a buffer to hold the RLE data   
1611      // create a buffer to hold the RLE data
16121612      dynamic_buffer compression_rle(m_hunkcount);
16131613      UINT8 *dest = compression_rle;
1614     
1614
16151615      // use a huffman encoder for 16 different codes, maximum length is 8 bits
16161616      huffman_encoder<16, 8> encoder;
16171617      encoder.histo_reset();
r14530r14531
16271627      for (int hunknum = 0; hunknum < m_hunkcount; hunknum++)
16281628      {
16291629         UINT8 curcomp = m_rawmap[hunknum * 12 + 0];
1630         
1630
16311631         // promote self block references to more compact forms
16321632         if (curcomp == COMPRESSION_SELF)
16331633         {
r14530r14531
16551655               max_parent = MAX(max_parent, refunit);
16561656            last_parent = refunit;
16571657         }
1658         
1658
16591659         // track maximum compressed length
1660         else // if (curcomp >= COMPRESSION_TYPE_0 && curcomp <= COMPRESSION_TYPE_3)
1660         else //if (curcomp >= COMPRESSION_TYPE_0 && curcomp <= COMPRESSION_TYPE_3)
16611661            max_complen = MAX(max_complen, be_read(&m_rawmap[hunknum * 12 + 1], 3));
1662         
1662
16631663         // track repeats
16641664         if (curcomp == lastcomp)
16651665            count++;
1666         
1666
16671667         // if no repeat, or we're at the end, flush it
16681668         if (curcomp != lastcomp || hunknum == m_hunkcount - 1)
16691669         {
r14530r14531
16901690               encoder.histo_one(*dest++ = lastcomp = curcomp);
16911691         }
16921692      }
1693     
1693
16941694      // compute a tree and export it to the buffer
16951695      dynamic_buffer compressed(m_hunkcount * 6);
16961696      bitstream_out bitbuf(&compressed[16], compressed.count() - 16);
r14530r14531
17041704      // encode the data
17051705      for (UINT8 *src = compression_rle; src < dest; src++)
17061706         encoder.encode_one(bitbuf, *src);
1707     
1707
17081708      // determine the number of bits we need to hold the a length
17091709      // and a hunk index
17101710      UINT8 lengthbits = bits_for_value(max_complen);
r14530r14531
17221722         UINT32 length = be_read(&rawmap[1], 3);
17231723         UINT64 offset = be_read(&rawmap[4], 6);
17241724         UINT16 crc = be_read(&rawmap[10], 2);
1725         
1725
17261726         // if no count remaining, fetch the next entry
17271727         if (count == 0)
17281728         {
r14530r14531
17361736         }
17371737         else
17381738            count--;
1739         
1739
17401740         // output additional data needed for this entry
17411741         switch (lastcomp)
17421742         {
r14530r14531
17501750               if (firstoffs == 0)
17511751                  firstoffs = offset;
17521752               break;
1753           
1753
17541754            case COMPRESSION_NONE:
17551755               bitbuf.write(crc, 16);
17561756               if (firstoffs == 0)
17571757                  firstoffs = offset;
17581758               break;
1759           
1759
17601760            case COMPRESSION_SELF:
17611761               assert(offset < (UINT64(1) << selfbits));
17621762               bitbuf.write(offset, selfbits);
17631763               break;
1764           
1764
17651765            case COMPRESSION_PARENT:
17661766               assert(offset < (UINT64(1) << parentbits));
17671767               bitbuf.write(offset, parentbits);
17681768               break;
1769           
1769
17701770            case COMPRESSION_SELF_0:
17711771            case COMPRESSION_SELF_1:
17721772            case COMPRESSION_PARENT_SELF:
r14530r14531
17751775               break;
17761776         }
17771777      }
1778     
1778
17791779      // write the map header
17801780      UINT32 complen = bitbuf.flush();
17811781      assert(!bitbuf.overflow());
r14530r14531
17851785      compressed[12] = lengthbits;
17861786      compressed[13] = selfbits;
17871787      compressed[14] = parentbits;
1788     
1788
17891789      // write the result
17901790      m_mapoffset = file_append(compressed, complen + 16);
1791     
1791
17921792      // then write the map offset
17931793      UINT8 rawbuf[sizeof(UINT64)];
17941794      be_write(rawbuf, m_mapoffset, 8);
r14530r14531
18241824   UINT8 lengthbits = rawbuf[12];
18251825   UINT8 selfbits = rawbuf[13];
18261826   UINT8 parentbits = rawbuf[14];
1827   
1827
18281828   // now read the map
18291829   dynamic_buffer compressed(mapbytes);
18301830   file_read(m_mapoffset + 16, compressed, mapbytes);
18311831   bitstream_in bitbuf(compressed, compressed.count());
1832   
1832
18331833   // first decode the compression types
18341834   huffman_decoder<16, 8> decoder;
18351835   huffman_error err = decoder.import_tree_rle(bitbuf);
r14530r14531
18531853            rawmap[0] = lastcomp = val;
18541854      }
18551855   }
1856   
1856
18571857   // then iterate through the hunks and extract the needed data
18581858   UINT64 curoffset = firstoffs;
18591859   UINT32 last_self = 0;
r14530r14531
18741874            curoffset += length = bitbuf.read(lengthbits);
18751875            crc = bitbuf.read(16);
18761876            break;
1877         
1877
18781878         case COMPRESSION_NONE:
18791879            curoffset += length = m_hunkbytes;
18801880            crc = bitbuf.read(16);
18811881            break;
1882         
1882
18831883         case COMPRESSION_SELF:
18841884            last_self = offset = bitbuf.read(selfbits);
18851885            break;
1886         
1886
18871887         case COMPRESSION_PARENT:
18881888            offset = bitbuf.read(parentbits);
18891889            last_parent = offset;
18901890            break;
1891         
1891
18921892         // pseudo-types; convert into base types
18931893         case COMPRESSION_SELF_1:
18941894            last_self++;
r14530r14531
18961896            rawmap[0] = COMPRESSION_SELF;
18971897            offset = last_self;
18981898            break;
1899           
1899
19001900         case COMPRESSION_PARENT_SELF:
19011901            rawmap[0] = COMPRESSION_PARENT;
19021902            last_parent = offset = (UINT64(hunknum) * UINT64(m_hunkbytes)) / m_unitbytes;
19031903            break;
1904           
1904
19051905         case COMPRESSION_PARENT_1:
19061906            last_parent += m_hunkbytes / m_unitbytes;
19071907         case COMPRESSION_PARENT_0:
r14530r14531
19131913      be_write(&rawmap[4], offset, 6);
19141914      be_write(&rawmap[10], crc, 2);
19151915   }
1916   
1916
19171917   // verify the final CRC
19181918   if (crc16_creator::simple(m_rawmap, m_hunkcount * 12) != mapcrc)
19191919      throw CHDERR_DECOMPRESSION_ERROR;
19201920}
1921   
19221921
1922
19231923//-------------------------------------------------
19241924//  create_common - command path when creating a
19251925//  new CHD file
r14530r14531
19331933      // if we have a parent, it must be V3 or later
19341934      if (m_parent != NULL && m_parent->version() < 3)
19351935         throw CHDERR_UNSUPPORTED_VERSION;
1936     
1936
19371937      // must be an even number of units per hunk
19381938      if (m_hunkbytes % m_unitbytes != 0)
19391939         throw CHDERR_INVALID_PARAMETER;
19401940      if (m_parent != NULL && m_unitbytes != m_parent->unit_bytes())
19411941         throw CHDERR_INVALID_PARAMETER;
1942     
1942
19431943      // writes are obviously permitted; reads only if uncompressed
19441944      m_allow_writes = true;
19451945      m_allow_reads = !compressed();
1946   
1946
19471947      // verify the compression types
19481948      bool found_zero = false;
19491949      for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_compression); codecnum++)
r14530r14531
19781978
19791979      // write the resulting header
19801980      file_write(0, rawheader, sizeof(rawheader));
1981     
1981
19821982      // parse it back out to set up fields appropriately
19831983      sha1_t parentsha1;
19841984      parse_v5_header(rawheader, parentsha1);
1985     
1985
19861986      // write out the map (if not compressed)
19871987      if (!compressed())
19881988      {
r14530r14531
20012001      // finish opening the file
20022002      create_open_common();
20032003   }
2004   
2004
20052005   // handle errors by closing ourself
20062006   catch (chd_error &err)
20072007   {
r14530r14531
20302030      // reads are always permitted; writes possibly as well
20312031      m_allow_reads = true;
20322032      m_allow_writes = writeable;
2033     
2033
20342034      // read the raw header
20352035      UINT8 rawheader[MAX_HEADER_SIZE];
20362036      file_read(0, rawheader, sizeof(rawheader));
2037     
2037
20382038      // verify the signature
20392039      if (memcmp(rawheader, "MComprHD", 8) != 0)
20402040         throw CHDERR_INVALID_FILE;
2041     
2041
20422042      // only allow writes to the most recent version
20432043      m_version = be_read(&rawheader[12], 4);
20442044      if (m_allow_writes && m_version < HEADER_VERSION)
20452045         throw CHDERR_UNSUPPORTED_VERSION;
2046     
2046
20472047      // read the header if we support it
20482048      sha1_t parentsha1 = sha1_t::null;
20492049      switch (m_version)
r14530r14531
20512051         case 3:      parse_v3_header(rawheader, parentsha1);   break;
20522052         case 4:      parse_v4_header(rawheader, parentsha1);   break;
20532053         case 5:      parse_v5_header(rawheader, parentsha1);   break;
2054         default:    throw CHDERR_UNSUPPORTED_VERSION;
2054         default:   throw CHDERR_UNSUPPORTED_VERSION;
20552055      }
2056     
2056
20572057      // make sure we have a parent if we need one (and don't if we don't)
20582058      if (parentsha1 != sha1_t::null)
20592059      {
r14530r14531
20642064      }
20652065      else if (parentsha1 == sha1_t::null && m_parent != NULL)
20662066         throw CHDERR_INVALID_PARAMETER;
2067     
2067
20682068      // finish opening the file
20692069      create_open_common();
20702070      return CHDERR_NONE;
20712071   }
2072   
2072
20732073   // handle errors by closing ourself
20742074   catch (chd_error &err)
20752075   {
r14530r14531
20932093      if (m_decompressor[decompnum] == NULL && m_compression[decompnum] != 0)
20942094         throw CHDERR_UNKNOWN_COMPRESSION;
20952095   }
2096   
2096
20972097   // read the map; v5+ compressed drives need to read and decompress their map
20982098   m_rawmap.resize(m_hunkcount * m_mapentrybytes);
20992099   if (m_version >= 5 && compressed())
r14530r14531
21352135   UINT8 *rawmap = &m_rawmap[hunknum * 12];
21362136   if (rawmap[0] != 0xff)
21372137      throw CHDERR_COMPRESSION_ERROR;
2138   
2138
21392139   // if this isn't the first block, only permitted to write immediately
21402140   // after the previous one
21412141   if (hunknum != 0 && rawmap[-12] == 0xff)
21422142      throw CHDERR_COMPRESSION_ERROR;
21432143}
2144   
21452144
2145
21462146//-------------------------------------------------
2147//  hunk_write_compressed - write a hunk to a
2147//  hunk_write_compressed - write a hunk to a
21482148//  compressed CHD, discovering the best
21492149//  technique
21502150//-------------------------------------------------
r14530r14531
21532153{
21542154   // verify that we are appending properly to a compressed file
21552155   verify_proper_compression_append(hunknum);
2156   
2156
21572157   // write the final result
21582158   UINT64 offset = file_append(compressed, complength);
2159   
2159
21602160   // update the map entry
21612161   UINT8 *rawmap = &m_rawmap[hunknum * 12];
21622162   rawmap[0] = (compression == -1) ? COMPRESSION_NONE : compression;
r14530r14531
21752175{
21762176   // verify that we are appending properly to a compressed file
21772177   verify_proper_compression_append(hunknum);
2178   
2178
21792179   // only permitted to reference prior hunks
21802180   if (otherhunk >= hunknum)
2181      throw CHDERR_INVALID_PARAMETER;
2181      throw CHDERR_INVALID_PARAMETER;
21822182
21832183   // update the map entry
21842184   UINT8 *rawmap = &m_rawmap[hunknum * 12];
r14530r14531
22732273   // otherwise, update the link in the previous header
22742274   else
22752275      offset = prevoffset + 8;
2276   
2276
22772277   // create a big-endian version
22782278   UINT8 rawbuf[sizeof(UINT64)];
22792279   be_write(rawbuf, nextoffset, 8);
2280   
2280
22812281   // write to the header and update our local copy
22822282   file_write(offset, rawbuf, sizeof(rawbuf));
22832283}
r14530r14531
22962296
22972297   // compute the new overall hash
22982298   sha1_t fullsha1 = compute_overall_sha1(raw_sha1());
2299     
2299
23002300   // create a big-endian version
23012301   UINT8 rawbuf[sizeof(sha1_t)];
23022302   be_write_sha1(&rawbuf[0], fullsha1);
2303   
2303
23042304   // write to the header
23052305   file_write(m_sha1_offset, rawbuf, sizeof(rawbuf));
23062306}
r14530r14531
23562356   // free the work queues
23572357   osd_work_queue_free(m_read_queue);
23582358   osd_work_queue_free(m_work_queue);
2359   
2359
23602360   // delete allocated arrays
23612361   for (int codecnum = 0; codecnum < ARRAY_LENGTH(m_codecs); codecnum++)
23622362      delete m_codecs[codecnum];
r14530r14531
23742374   m_total_in = 0;
23752375   m_total_out = 0;
23762376   m_compsha1.reset();
2377   
2377
23782378   // reset our maps
23792379   m_parent_map.reset();
23802380   m_current_map.reset();
2381   
2381
23822382   // reset read state
23832383   m_read_queue_offset = 0;
23842384   m_read_done_offset = 0;
23852385   m_read_error = false;
2386   
2386
23872387   // reset work item state
23882388   m_work_buffer.resize(hunk_bytes() * (WORK_BUFFER_HUNKS + 1));
23892389   m_compressed_buffer.resize(hunk_bytes() * WORK_BUFFER_HUNKS);
r14530r14531
23952395      item.m_compressed = m_compressed_buffer + hunk_bytes() * itemnum;
23962396      item.m_hash.resize(hunk_bytes() / unit_bytes());
23972397   }
2398   
2398
23992399   // initialize codec instances
24002400   for (int instance = 0; instance < ARRAY_LENGTH(m_codecs); instance++)
24012401   {
24022402      delete m_codecs[instance];
24032403      m_codecs[instance] = new chd_compressor_group(*this, m_compression);
24042404   }
2405   
2405
24062406   // reset write state
24072407   m_write_hunk = 0;
24082408}
r14530r14531
24292429         if (m_work_item[curitem % WORK_BUFFER_HUNKS].m_status != WS_READY)
24302430            break;
24312431
2432      // if it's not all clear, defer     
2432      // if it's not all clear, defer
24332433      if (curitem != enditem)
24342434         break;
2435     
2435
24362436      // if we're walking the parent, we want one more item to have cleared so we
24372437      // can read an extra hunk there
24382438      if (m_walking_parent && m_work_item[curitem % WORK_BUFFER_HUNKS].m_status != WS_READY)
r14530r14531
24442444      osd_work_item_queue(m_read_queue, async_read_static, this, WORK_ITEM_FLAG_AUTO_RELEASE);
24452445      m_read_queue_offset += WORK_BUFFER_HUNKS * hunk_bytes() / 2;
24462446   }
2447   
2447
24482448   // flush out any finished items
24492449   while (m_work_item[m_write_hunk % WORK_BUFFER_HUNKS].m_status == WS_COMPLETE)
24502450   {
24512451      work_item &item = m_work_item[m_write_hunk % WORK_BUFFER_HUNKS];
2452     
2452
24532453      // free any OSD work item
24542454      if (item.m_osd != NULL)
24552455         osd_work_item_release(item.m_osd);
r14530r14531
24662466            if (m_parent_map.find(item.m_hash[unit].m_crc16, item.m_hash[unit].m_sha1) == hashmap::NOT_FOUND)
24672467               m_parent_map.add(item.m_hunknum * uph + unit, item.m_hash[unit].m_crc16, item.m_hash[unit].m_sha1);
24682468      }
2469     
2469
24702470      // if we're uncompressed, use regular writes
24712471      else if (!compressed())
24722472      {
24732473         chd_error err = write_hunk(item.m_hunknum, item.m_data);
24742474         if (err != CHDERR_NONE)
24752475            return err;
2476   
2477         // writes of all-0 data don't actually take space, so see if we count this     
2476
2477         // writes of all-0 data don't actually take space, so see if we count this
24782478         chd_codec_type codec = CHD_CODEC_NONE;
24792479         UINT32 complen;
24802480         hunk_info(item.m_hunknum, codec, complen);
24812481         if (codec == CHD_CODEC_NONE)
24822482            m_total_out += m_hunkbytes;
24832483      }
2484     
2484
24852485      // for compressing, process the result
24862486      else do
24872487      {
r14530r14531
24922492            hunk_copy_from_self(item.m_hunknum, selfhunk);
24932493            break;
24942494         }
2495         
2495
24962496         // if not, see if it's in the parent map
24972497         if (m_parent != NULL)
24982498         {
r14530r14531
25032503               break;
25042504            }
25052505         }
2506         
2506
25072507         // otherwise, append it compressed and add to the self map
25082508         hunk_write_compressed(item.m_hunknum, item.m_compression, item.m_compressed, item.m_complen, item.m_hash[0].m_crc16);
25092509         m_total_out += item.m_complen;
25102510         m_current_map.add(item.m_hunknum, item.m_hash[0].m_crc16, item.m_hash[0].m_sha1);
25112511      } while (0);
2512     
2512
25132513      // reset the item and advance
25142514      item.m_status = WS_READY;
25152515      m_write_hunk++;
2516     
2516
25172517      // if we hit the end, finalize
25182518      if (m_write_hunk == m_hunkcount)
25192519      {
r14530r14531
25262526            for (int itemnum = 0; itemnum < WORK_BUFFER_HUNKS; itemnum++)
25272527               m_work_item[itemnum].m_status = WS_READY;
25282528         }
2529         
2529
25302530         // wait for all reads to finish and if we're compressed, write the final SHA1 and map
25312531         else
25322532         {
r14530r14531
25382538         }
25392539      }
25402540   }
2541   
2541
25422542   // update progress and ratio
25432543   if (m_walking_parent)
25442544      progress = double(m_read_done_offset) / double(logical_bytes());
r14530r14531
25822582
25832583
25842584//-------------------------------------------------
2585//  async_compress_hunk - handle asynchronous
2585//  async_compress_hunk - handle asynchronous
25862586//  hunk compression
25872587//-------------------------------------------------
25882588
r14530r14531
26152615
26162616
26172617//-------------------------------------------------
2618//  async_read - handle asynchronous source file
2618//  async_read - handle asynchronous source file
26192619//  reading
26202620//-------------------------------------------------
26212621
r14530r14531
26552655            curdest += hunk_bytes();
26562656         }
26572657      }
2658     
2658
26592659      // otherwise, call the virtual function
26602660      else
26612661         read_data(dest, m_read_done_offset, numbytes);
2662     
2662
26632663      // spawn off work for each hunk
26642664      for (UINT64 curoffs = m_read_done_offset; curoffs < end_offset; curoffs += hunk_bytes())
26652665      {
r14530r14531
26782678            m_compsha1.append(dest, numbytes);
26792679         m_total_in += numbytes;
26802680      }
2681     
2681
26822682      // advance the read pointer
26832683      m_read_done_offset += numbytes;
26842684   }
r14530r14531
27302730      delete block;
27312731   }
27322732   m_block_list->m_nextalloc = 0;
2733   
2733
27342734   // reset the hash
27352735   memset(m_map, 0, sizeof(m_map));
27362736}
src/lib/util/bitstream.h
r14530r14531
5555public:
5656   // construction/destruction
5757   bitstream_in(const void *src, UINT32 srclength);
58   
58
5959   // getters
6060   bool overflow() const { return ((m_doffset - m_bits / 8) > m_dlength); }
6161   UINT32 read_offset() const;
62   
62
6363   // operations
6464   UINT32 read(int numbits);
6565   UINT32 peek(int numbits);
r14530r14531
8282public:
8383   // construction/destruction
8484   bitstream_out(void *dest, UINT32 destlength);
85   
85
8686   // getters
8787   bool overflow() const { return (m_doffset > m_dlength); }
88   
88
8989   // operations
9090   void write(UINT32 newbits, int numbits);
9191   UINT32 flush();
src/lib/util/chd.h
r14530r14531
5555
5656    Compressed Hunks of Data header format. All numbers are stored in
5757    Motorola (big-endian) byte ordering.
58   
58
5959    =========================================================================
6060
6161    V1 header:
r14530r14531
7878        0x00000001 - set if this drive has a parent
7979        0x00000002 - set if this drive allows writes
8080
81   Compression types:
82      CHDCOMPRESSION_NONE = 0
83      CHDCOMPRESSION_ZLIB = 1
84   
81    Compression types:
82        CHDCOMPRESSION_NONE = 0
83        CHDCOMPRESSION_ZLIB = 1
84
8585    V1 map format:
86   
87    [  0] UINT64 offset : 44;   // starting offset within the file
88    [  0] UINT64 length : 20;   // length of data; if == hunksize, data is uncompressed
89   
86
87    [  0] UINT64 offset : 44;   // starting offset within the file
88    [  0] UINT64 length : 20;   // length of data; if == hunksize, data is uncompressed
89
9090    =========================================================================
9191
9292    V2 header:
r14530r14531
105105    [ 60] UINT8  parentmd5[16]; // MD5 checksum of parent file
106106    [ 76] UINT32 seclen;        // number of bytes per sector
107107    [ 80] (V2 header length)
108   
108
109109    Flags and map format are same as V1
110   
110
111111    =========================================================================
112112
113113    V3 header:
r14530r14531
126126    [ 80] UINT8  sha1[20];      // SHA1 checksum of raw data
127127    [100] UINT8  parentsha1[20];// SHA1 checksum of parent file
128128    [120] (V3 header length)
129   
129
130130    Flags are the same as V1
131131
132   Compression types:
133      CHDCOMPRESSION_NONE = 0
134      CHDCOMPRESSION_ZLIB = 1
135      CHDCOMPRESSION_ZLIB_PLUS = 2
136   
132    Compression types:
133        CHDCOMPRESSION_NONE = 0
134        CHDCOMPRESSION_ZLIB = 1
135        CHDCOMPRESSION_ZLIB_PLUS = 2
136
137137    V3 map format:
138138
139139    [  0] UINT64 offset;        // starting offset within the file
140    [  8] UINT32 crc32;         // 32-bit CRC of the uncompressed data
141    [ 12] UINT16 length_lo;      // lower 16 bits of length
142    [ 14] UINT8 length_hi;      // upper 8 bits of length
143    [ 15] UINT8 flags;         // flags, indicating compression info
140    [  8] UINT32 crc32;         // 32-bit CRC of the uncompressed data
141    [ 12] UINT16 length_lo;     // lower 16 bits of length
142    [ 14] UINT8 length_hi;      // upper 8 bits of length
143    [ 15] UINT8 flags;          // flags, indicating compression info
144144
145145    =========================================================================
146146
r14530r14531
159159    [ 68] UINT8  parentsha1[20];// combined raw+meta SHA1 of parent
160160    [ 88] UINT8  rawsha1[20];   // raw data SHA1
161161    [108] (V4 header length)
162   
162
163163    Flags are the same as V1
164   
165   Compression types:
166      CHDCOMPRESSION_NONE = 0
167      CHDCOMPRESSION_ZLIB = 1
168      CHDCOMPRESSION_ZLIB_PLUS = 2
169      CHDCOMPRESSION_AV = 3
170   
164
165    Compression types:
166        CHDCOMPRESSION_NONE = 0
167        CHDCOMPRESSION_ZLIB = 1
168        CHDCOMPRESSION_ZLIB_PLUS = 2
169        CHDCOMPRESSION_AV = 3
170
171171    Map format is the same as V3
172   
172
173173    =========================================================================
174174
175175    V5 header:
176   
176
177177    [  0] char   tag[8];        // 'MComprHD'
178178    [  8] UINT32 length;        // length of header (including tag and length fields)
179179    [ 12] UINT32 version;       // drive format version
r14530r14531
188188    [104] UINT8  parentsha1[20];// combined raw+meta SHA1 of parent
189189    [124] (V5 header length)
190190
191   If parentsha1 != 0, we have a parent (no need for flags)
192   If compressors[0] == 0, we are uncompressed (including maps)
193   
191    If parentsha1 != 0, we have a parent (no need for flags)
192    If compressors[0] == 0, we are uncompressed (including maps)
193
194194    V5 uncompressed map format:
195   
196    [  0] UINT32 offset;         // starting offset / hunk size
197   
195
196    [  0] UINT32 offset;        // starting offset / hunk size
197
198198    V5 compressed map format header:
199   
200    [  0] UINT32 length;      // length of compressed map
201    [  4] UINT48 datastart;      // offset of first block
202    [ 10] UINT16 crc;         // crc-16 of the map
203    [ 12] UINT8 lengthbits;      // bits used to encode complength
204    [ 13] UINT8 hunkbits;      // bits used to encode self-refs
205    [ 14] UINT8 parentunitbits;   // bits used to encode parent unit refs
206    [ 15] UINT8 reserved;      // future use
199
200    [  0] UINT32 length;        // length of compressed map
201    [  4] UINT48 datastart;     // offset of first block
202    [ 10] UINT16 crc;           // crc-16 of the map
203    [ 12] UINT8 lengthbits;     // bits used to encode complength
204    [ 13] UINT8 hunkbits;       // bits used to encode self-refs
205    [ 14] UINT8 parentunitbits; // bits used to encode parent unit refs
206    [ 15] UINT8 reserved;       // future use
207207    [ 16] (compressed header length)
208   
208
209209    Each compressed map entry, once expanded, looks like:
210   
211    [  0] UINT8 compression;   // compression type
212    [  1] UINT24 complength;   // compressed length
213    [  4] UINT48 offset;      // offset
214    [ 10] UINT16 crc;         // crc-16 of the data
215210
211    [  0] UINT8 compression;    // compression type
212    [  1] UINT24 complength;    // compressed length
213    [  4] UINT48 offset;        // offset
214    [ 10] UINT16 crc;           // crc-16 of the data
215
216216***************************************************************************/
217217
218218
r14530r14531
222222
223223// pseudo-codecs returned by hunk_info
224224const chd_codec_type CHD_CODEC_SELF       = 1;   // copy of another hunk
225const chd_codec_type CHD_CODEC_PARENT       = 2;   // copy of a parent's hunk
225const chd_codec_type CHD_CODEC_PARENT      = 2;   // copy of a parent's hunk
226226const chd_codec_type CHD_CODEC_MINI       = 3;   // legacy "mini" 8-byte repeat
227227
228228// core types
r14530r14531
322322   static const UINT32 V4_HEADER_SIZE = 108;
323323   static const UINT32 V5_HEADER_SIZE = 124;
324324   static const UINT32 MAX_HEADER_SIZE = V5_HEADER_SIZE;
325   
325
326326public:
327327   // construction/destruction
328328   chd_file();
r14530r14531
360360   // file open
361361   chd_error open(const char *filename, bool writeable = false, chd_file *parent = NULL);
362362   chd_error open(core_file &file, bool writeable = false, chd_file *parent = NULL);
363   
363
364364   // file close
365365   void close();
366366
r14530r14531
382382   chd_error write_metadata(chd_metadata_tag metatag, UINT32 metaindex, const dynamic_buffer &input, UINT8 flags = CHD_MDFLAGS_CHECKSUM) { return write_metadata(metatag, metaindex, input, input.count(), flags = CHD_MDFLAGS_CHECKSUM); }
383383   chd_error delete_metadata(chd_metadata_tag metatag, UINT32 metaindex);
384384   chd_error clone_all_metadata(chd_file &source);
385   
385
386386   // hashing helper
387387   sha1_t compute_overall_sha1(sha1_t rawsha1);
388388
389389   // codec interfaces
390390   chd_error codec_configure(chd_codec_type codec, int param, void *config);
391   
391
392392   // static helpers
393393   static const char *error_string(chd_error err);
394394
395395private:
396396   struct metadata_entry;
397397   struct metadata_hash;
398   
398
399399   // inline helpers
400400   UINT64 be_read(const UINT8 *base, int numbytes);
401401   void be_write(UINT8 *base, UINT64 value, int numbytes);
r14530r14531
430430   bool               m_owns_file;      // flag indicating if this file should be closed on chd_close()
431431   bool               m_allow_reads;      // permit reads from this CHD?
432432   bool               m_allow_writes;      // permit writes to this CHD?
433   
433
434434   // core parameters from the header
435435   UINT32               m_version;         // version of the header
436436   UINT64               m_logicalbytes;      // logical size of the raw CHD data in bytes
r14530r14531
443443   chd_codec_type         m_compression[4];   // array of compression types used
444444   chd_file *            m_parent;         // pointer to parent file, or NULL if none
445445   bool               m_parent_missing;   // are we missing our parent?
446   
446
447447   // key offsets within the header
448448   UINT64               m_mapoffset_offset;   // offset of map offset field
449449   UINT64               m_metaoffset_offset;// offset of metaoffset field
450450   UINT64               m_sha1_offset;      // offset of SHA1 field
451451   UINT64               m_rawsha1_offset;   // offset of raw SHA1 field
452452   UINT64               m_parentsha1_offset;// offset of paren SHA1 field
453   
453
454454   // map information
455455   UINT32               m_mapentrybytes;   // length of each entry in a map
456456   dynamic_buffer         m_rawmap;         // raw map data
r14530r14531
458458   // compression management
459459   chd_decompressor *      m_decompressor[4];   // array of decompression codecs
460460   dynamic_buffer         m_compressed;      // temporary buffer for compressed data
461   
461
462462   // caching
463463   dynamic_buffer         m_cache;         // single-hunk cache for partial reads/writes
464464   UINT32               m_cachehunk;      // which hunk is in the cache?
r14530r14531
474474   // construction/destruction
475475   chd_file_compressor();
476476   virtual ~chd_file_compressor();
477   
477
478478   // compression management
479479   void compress_begin();
480480   chd_error compress_continue(double &progress, double &ratio);
r14530r14531
482482protected:
483483   // required override: read more data
484484   virtual UINT32 read_data(void *dest, UINT64 offset, UINT32 length) = 0;
485   
485
486486private:
487487   // hash map for looking up values
488488   class hashmap
r14530r14531
491491      // construction/destruction
492492      hashmap();
493493      ~hashmap();
494     
494
495495      // operations
496496      void reset();
497497      UINT64 find(crc16_t crc16, sha1_t sha1);
498498      void add(UINT64 itemnum, crc16_t crc16, sha1_t sha1);
499   
499
500500      // constants
501501      static const UINT64 NOT_FOUND = ~UINT64(0);
502502   private:
r14530r14531
507507         UINT64            m_itemnum;         // item number
508508         sha1_t            m_sha1;            // SHA-1 of the block
509509      };
510     
510
511511      // block of entries
512512      struct entry_block
513513      {
514514         entry_block(entry_block *prev)
515515            : m_next(prev), m_nextalloc(0) { }
516     
516
517517         entry_block *      m_next;            // next block in list
518518         UINT32            m_nextalloc;      // next to be allocated
519519         entry_t            m_array[16384];      // array of entries
r14530r14531
532532      WS_QUEUED,
533533      WS_COMPLETE
534534   };
535   
535
536536   // a CRC-16/SHA-1 pair
537537   struct hash_pair
538538   {
r14530r14531
540540      sha1_t            m_sha1;            // calculated SHA-1
541541   };
542542
543   // a single work item   
543   // a single work item
544544   struct work_item
545545   {
546546      osd_work_item *      m_osd;            // OSD work item running on this block
r14530r14531
554554      chd_compressor_group *m_codecs;         // codec instance
555555      dynamic_array<hash_pair> m_hash;      // array of hashes
556556   };
557   
557
558558   // internal helpers
559559   static void *async_walk_parent_static(void *param, int threadid);
560560   void async_walk_parent(work_item &item);
r14530r14531
563563   static void *async_read_static(void *param, int threadid);
564564   void async_read();
565565
566   // current compression status   
567   bool               m_walking_parent;   // are we building the parent map?   
566   // current compression status
567   bool               m_walking_parent;   // are we building the parent map?
568568   UINT64               m_total_in;         // total bytes in
569569   UINT64               m_total_out;      // total bytes out
570570   sha1_creator         m_compsha1;         // running SHA-1 on raw data
571571
572572   // hash lookup maps
573   hashmap                m_parent_map;      // hash map for parent
574   hashmap                m_current_map;      // hash map for current
573   hashmap               m_parent_map;      // hash map for parent
574   hashmap               m_current_map;      // hash map for current
575575
576576   // read I/O thread
577577   osd_work_queue *      m_read_queue;      // work queue for reading
src/lib/util/cdrom.c
r14530r14531
380380   UINT32 chdsector = physical_to_chd_lba(file, lbasector, tracknum);
381381   if (file->cdtoc.tracks[tracknum].subsize == 0)
382382      return 1;
383   
383
384384   // read the data
385385   chd_error err = read_partial_sector(file, buffer, chdsector, tracknum, file->cdtoc.tracks[tracknum].datasize, file->cdtoc.tracks[tracknum].subsize);
386386   return (err == CHDERR_NONE);
src/lib/util/flac.c
r14530r14531
8282
8383
8484//-------------------------------------------------
85//  reset - reset state with the original
85//  reset - reset state with the original
8686//  parameters
8787//-------------------------------------------------
8888
r14530r14531
9696   // configure the encoder in a standard way
9797   // note we do this on each reset; if we don't, results are NOT consistent!
9898   FLAC__stream_encoder_set_verify(m_encoder, false);
99//   FLAC__stream_encoder_set_do_md5(m_encoder, false);
99//  FLAC__stream_encoder_set_do_md5(m_encoder, false);
100100   FLAC__stream_encoder_set_compression_level(m_encoder, 8);
101101   FLAC__stream_encoder_set_channels(m_encoder, m_channels);
102102   FLAC__stream_encoder_set_bits_per_sample(m_encoder, 16);
r14530r14531
161161      for (UINT32 sampnum = 0; sampnum < cur_samples; sampnum++)
162162         for (int channel = 0; channel < num_channels; channel++, srcindex++)
163163            *dest++ = INT16((UINT16(samples[srcindex]) << shift) | (UINT16(samples[srcindex]) >> shift));
164     
164
165165      // process this batch
166166      if (!FLAC__stream_encoder_process_interleaved(m_encoder, converted_buffer, cur_samples))
167167         return false;
r14530r14531
194194      for (UINT32 sampnum = 0; sampnum < cur_samples; sampnum++, srcindex++)
195195         for (int channel = 0; channel < num_channels; channel++)
196196            *dest++ = INT16((UINT16(samples[channel][srcindex]) << shift) | (UINT16(samples[channel][srcindex]) >> shift));
197     
197
198198      // process this batch
199199      if (!FLAC__stream_encoder_process_interleaved(m_encoder, converted_buffer, cur_samples))
200200         return false;
r14530r14531
205205
206206
207207//-------------------------------------------------
208//  finish - complete encoding and flush the
208//  finish - complete encoding and flush the
209209//  stream
210210//-------------------------------------------------
211211
r14530r14531
227227   m_encoder = FLAC__stream_encoder_new();
228228   if (m_encoder == NULL)
229229      throw std::bad_alloc();
230   
230
231231   // initialize default state
232232   m_file = NULL;
233233   m_compressed_offset = 0;
r14530r14531
243243
244244
245245//-------------------------------------------------
246//  write_callback - handle writes to the
246//  write_callback - handle writes to the
247247//  output stream
248248//-------------------------------------------------
249249
r14530r14531
265265         offset += ignore;
266266         m_ignore_bytes -= ignore;
267267      }
268     
268
269269      // if we haven't hit the end of metadata, process a new piece
270270      else if (!m_found_audio)
271271      {
r14530r14531
275275         offset += 4;
276276      }
277277
278      // otherwise process as audio data and copy to the output     
278      // otherwise process as audio data and copy to the output
279279      else
280280      {
281281         int count = bytes - offset;
r14530r14531
360360
361361
362362//-------------------------------------------------
363//  reset - reset state with the original
363//  reset - reset state with the original
364364//  parameters
365365//-------------------------------------------------
366366
367367bool flac_decoder::reset()
368368{
369369   m_compressed_offset = 0;
370   if (FLAC__stream_decoder_init_stream(m_decoder,
371            &flac_decoder::read_callback_static,
372            NULL,
373            &flac_decoder::tell_callback_static,
374            NULL,
375            NULL,
376            &flac_decoder::write_callback_static,
377            &flac_decoder::metadata_callback_static,
370   if (FLAC__stream_decoder_init_stream(m_decoder,
371            &flac_decoder::read_callback_static,
372            NULL,
373            &flac_decoder::tell_callback_static,
374            NULL,
375            NULL,
376            &flac_decoder::write_callback_static,
377            &flac_decoder::metadata_callback_static,
378378            &flac_decoder::error_callback_static, this) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
379379      return false;
380380   return FLAC__stream_decoder_process_until_end_of_metadata(m_decoder);
r14530r14531
407407   static const UINT8 s_header_template[0x2a] =
408408   {
409409      0x66, 0x4C, 0x61, 0x43,                   // +00: 'fLaC' stream header
410      0x80,                                  // +04: metadata block type 0 (STREAMINFO),
410      0x80,                                 // +04: metadata block type 0 (STREAMINFO),
411411                                          //      flagged as last block
412      0x00, 0x00, 0x22,                         // +05: metadata block length = 0x22
412      0x00, 0x00, 0x22,                        // +05: metadata block length = 0x22
413413      0x00, 0x00,                            // +08: minimum block size
414414      0x00, 0x00,                              // +0A: maximum block size
415      0x00, 0x00, 0x00,                         // +0C: minimum frame size (0 == unknown)
416      0x00, 0x00, 0x00,                         // +0F: maximum frame size (0 == unknown)
417      0x0A, 0xC4, 0x42, 0xF0, 0x00, 0x00, 0x00, 0x00, // +12: sample rate (0x0ac44 == 44100),
418                                          //      numchannels (2), sample bits (16),
415      0x00, 0x00, 0x00,                        // +0C: minimum frame size (0 == unknown)
416      0x00, 0x00, 0x00,                        // +0F: maximum frame size (0 == unknown)
417      0x0A, 0xC4, 0x42, 0xF0, 0x00, 0x00, 0x00, 0x00, // +12: sample rate (0x0ac44 == 44100),
418                                          //      numchannels (2), sample bits (16),
419419                                          //      samples in stream (0 == unknown)
420420      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // +1A: MD5 signature (0 == none)
421421      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00   //
r14530r14531
466466   m_uncompressed_offset = 0;
467467   m_uncompressed_length = num_samples;
468468   m_uncompressed_swap = swap_endian;
469   
469
470470   // loop until we get everything we want
471471   while (m_uncompressed_offset < m_uncompressed_length)
472472      if (!FLAC__stream_decoder_process_single(m_decoder))
r14530r14531
494494   m_uncompressed_offset = 0;
495495   m_uncompressed_length = num_samples;
496496   m_uncompressed_swap = swap_endian;
497   
497
498498   // loop until we get everything we want
499499   while (m_uncompressed_offset < m_uncompressed_length)
500500      if (!FLAC__stream_decoder_process_single(m_decoder))
r14530r14531
513513   FLAC__uint64 position = 0;
514514   FLAC__stream_decoder_get_decode_position(m_decoder, &position);
515515   FLAC__stream_decoder_finish(m_decoder);
516   
516
517517   // adjust position if we provided the header
518518   if (position == 0)
519519      return 0;
r14530r14531
536536FLAC__StreamDecoderReadStatus flac_decoder::read_callback(FLAC__byte buffer[], size_t *bytes)
537537{
538538   UINT32 expected = *bytes;
539   
539
540540   // if a file, just read
541541   if (m_file != NULL)
542542      *bytes = core_fread(m_file, buffer, expected);
543   
543
544544   // otherwise, copy from memory
545545   else
546546   {
r14530r14531
553553         outputpos += bytes_to_copy;
554554         m_compressed_offset += bytes_to_copy;
555555      }
556     
556
557557      // once we're out of that, copy from the secondary buffer
558558      if (outputpos < *bytes && m_compressed_offset < m_compressed_length + m_compressed2_length)
559559      {
r14530r14531
579579   // ignore all but STREAMINFO metadata
580580   if (metadata->type != FLAC__METADATA_TYPE_STREAMINFO)
581581      return;
582   
582
583583   // parse out the data we care about
584584   flac_decoder *fldecoder = reinterpret_cast<flac_decoder *>(client_data);
585585   fldecoder->m_sample_rate = metadata->data.stream_info.sample_rate;
r14530r14531
613613FLAC__StreamDecoderWriteStatus flac_decoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
614614{
615615   assert(frame->header.channels == channels());
616   
616
617617   // interleaved case
618618   int shift = m_uncompressed_swap ? 8 : 0;
619619   int blocksize = frame->header.blocksize;
r14530r14531
624624         for (int chan = 0; chan < frame->header.channels; chan++)
625625            *dest++ = INT16((UINT16(buffer[chan][sampnum]) << shift) | (UINT16(buffer[chan][sampnum]) >> shift));
626626   }
627   
627
628628   // non-interleaved case
629629   else
630630   {
src/lib/util/flac.h
r14530r14531
6767   void set_num_channels(UINT8 num_channels) { m_channels = num_channels; }
6868   void set_block_size(UINT32 block_size) { m_block_size = block_size; }
6969   void set_strip_metadata(bool strip) { m_strip_metadata = strip; }
70   
70
7171   // getters (valid after reset)
7272   FLAC__StreamEncoderState state() const { return FLAC__stream_encoder_get_state(m_encoder); }
7373   const char *state_string() const { return FLAC__stream_encoder_get_resolved_state_string(m_encoder); }
74   
74
7575   // reset
7676   bool reset();
7777   bool reset(void *buffer, UINT32 buflength);
7878   bool reset(core_file &file);
79   
79
8080   // encode a buffer
8181   bool encode_interleaved(const INT16 *samples, UINT32 samples_per_channel, bool swap_endian = false);
8282   bool encode(INT16 *const *samples, UINT32 samples_per_channel, bool swap_endian = false);
r14530r14531
9696   UINT32               m_compressed_offset;   // current offset with the compressed stream
9797   FLAC__byte *         m_compressed_start;      // start of compressed data
9898   UINT32               m_compressed_length;   // length of the compressed stream
99   
99
100100   // parameters
101101   UINT32               m_sample_rate;         // sample rate
102102   UINT8               m_channels;            // number of channels
103103   UINT32               m_block_size;         // block size
104104
105105   // header stripping
106   bool               m_strip_metadata;      // strip the the metadata?   
106   bool               m_strip_metadata;      // strip the the metadata?
107107   UINT32               m_ignore_bytes;         // how many bytes to ignore when writing
108108   bool               m_found_audio;         // have we hit the audio yet?
109109};
r14530r14531
119119   flac_decoder(const void *buffer, UINT32 length, const void *buffer2 = NULL, UINT32 length2 = 0);
120120   flac_decoder(core_file &file);
121121   ~flac_decoder();
122   
122
123123   // getters (valid after reset)
124124   UINT32 sample_rate() const { return m_sample_rate; }
125125   UINT8 channels() const { return m_channels; }
r14530r14531
127127   UINT32 total_samples() const { return FLAC__stream_decoder_get_total_samples(m_decoder); }
128128   FLAC__StreamDecoderState state() const { return FLAC__stream_decoder_get_state(m_decoder); }
129129   const char *state_string() const { return FLAC__stream_decoder_get_resolved_state_string(m_decoder); }
130   
130
131131   // reset
132132   bool reset();
133133   bool reset(const void *buffer, UINT32 length, const void *buffer2 = NULL, UINT32 length2 = 0);
134134   bool reset(UINT32 sample_rate, UINT8 num_channels, UINT32 block_size, const void *buffer, UINT32 length);
135135   bool reset(core_file &file);
136   
136
137137   // decode to a buffer; num_samples must be a multiple of the block size
138138   bool decode_interleaved(INT16 *samples, UINT32 num_samples, bool swap_endian = false);
139139   bool decode(INT16 **samples, UINT32 num_samples, bool swap_endian = false);
src/lib/util/hashing.c
r14530r14531
11/***************************************************************************
22
3   hashing.c
3    hashing.c
44
5   Hashing helper classes.
5    Hashing helper classes.
66
77****************************************************************************
88
9   Copyright Aaron Giles
10   All rights reserved.
9    Copyright Aaron Giles
10    All rights reserved.
1111
12   Redistribution and use in source and binary forms, with or without
13   modification, are permitted provided that the following conditions are
14   met:
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
1515
16      * Redistributions of source code must retain the above copyright
17        notice, this list of conditions and the following disclaimer.
18      * Redistributions in binary form must reproduce the above copyright
19        notice, this list of conditions and the following disclaimer in
20        the documentation and/or other materials provided with the
21        distribution.
22      * Neither the name 'MAME' nor the names of its contributors may be
23        used to endorse or promote products derived from this software
24        without specific prior written permission.
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
2525
26   THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29   DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35   IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36   POSSIBILITY OF SUCH DAMAGE.
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
3737
3838***************************************************************************/
3939
r14530r14531
5757//**************************************************************************
5858
5959//-------------------------------------------------
60//  char_to_hex - return the hex value of a
60//  char_to_hex - return the hex value of a
6161//  character
6262//-------------------------------------------------
6363
r14530r14531
8989      length = strlen(string);
9090   if (length < 2 * sizeof(m_raw))
9191      return false;
92   
92
9393   // iterate through our raw buffer
9494   for (int bytenum = 0; bytenum < sizeof(m_raw); bytenum++)
9595   {
r14530r14531
111111{
112112   buffer.reset();
113113   for (int i = 0; i < ARRAY_LENGTH(m_raw); i++)
114      buffer.catformat("%02x", m_raw[i]);
114      buffer.catformat("%02x", m_raw[i]);
115115   return buffer;
116116}
117117
r14530r14531
131131      length = strlen(string);
132132   if (length < 2 * sizeof(m_raw))
133133      return false;
134   
134
135135   // iterate through our raw buffer
136136   for (int bytenum = 0; bytenum < sizeof(m_raw); bytenum++)
137137   {
r14530r14531
153153{
154154   buffer.reset();
155155   for (int i = 0; i < ARRAY_LENGTH(m_raw); i++)
156      buffer.catformat("%02x", m_raw[i]);
156      buffer.catformat("%02x", m_raw[i]);
157157   return buffer;
158158}
159159
r14530r14531
174174      length = strlen(string);
175175   if (length < 2 * sizeof(m_raw))
176176      return false;
177   
177
178178   // iterate through our raw buffer
179179   m_raw = 0;
180180   for (int bytenum = 0; bytenum < sizeof(m_raw) * 2; bytenum++)
r14530r14531
199199
200200
201201//-------------------------------------------------
202//  append - hash a block of data, appending to
202//  append - hash a block of data, appending to
203203//  the currently-accumulated value
204204//-------------------------------------------------
205205
r14530r14531
225225      length = strlen(string);
226226   if (length < 2 * sizeof(m_raw))
227227      return false;
228   
228
229229   // iterate through our raw buffer
230230   m_raw = 0;
231231   for (int bytenum = 0; bytenum < sizeof(m_raw) * 2; bytenum++)
r14530r14531
250250
251251
252252//-------------------------------------------------
253//  append - hash a block of data, appending to
253//  append - hash a block of data, appending to
254254//  the currently-accumulated value
255255//-------------------------------------------------
256256
257257void crc16_creator::append(const void *data, UINT32 length)
258258{
259   static const UINT16 s_table[256] =
259   static const UINT16 s_table[256] =
260260   {
261261       0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
262262       0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
r14530r14531
293293    };
294294
295295   const UINT8 *src = reinterpret_cast<const UINT8 *>(data);
296   
296
297297   // fetch the current value into a local and rip through the source data
298298   UINT16 crc = m_accum.m_raw;
299299   while (length-- != 0)
src/lib/util/hashing.h
r14530r14531
11/***************************************************************************
22
3   hashing.h
3    hashing.h
44
5   Hashing helper classes.
5    Hashing helper classes.
66
77****************************************************************************
88
9   Copyright Aaron Giles
10   All rights reserved.
9    Copyright Aaron Giles
10    All rights reserved.
1111
12   Redistribution and use in source and binary forms, with or without
13   modification, are permitted provided that the following conditions are
14   met:
12    Redistribution and use in source and binary forms, with or without
13    modification, are permitted provided that the following conditions are
14    met:
1515
16      * Redistributions of source code must retain the above copyright
17        notice, this list of conditions and the following disclaimer.
18      * Redistributions in binary form must reproduce the above copyright
19        notice, this list of conditions and the following disclaimer in
20        the documentation and/or other materials provided with the
21        distribution.
22      * Neither the name 'MAME' nor the names of its contributors may be
23        used to endorse or promote products derived from this software
24        without specific prior written permission.
16        * Redistributions of source code must retain the above copyright
17          notice, this list of conditions and the following disclaimer.
18        * Redistributions in binary form must reproduce the above copyright
19          notice, this list of conditions and the following disclaimer in
20          the documentation and/or other materials provided with the
21          distribution.
22        * Neither the name 'MAME' nor the names of its contributors may be
23          used to endorse or promote products derived from this software
24          without specific prior written permission.
2525
26   THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29   DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35   IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36   POSSIBILITY OF SUCH DAMAGE.
26    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
27    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
30    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
35    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36    POSSIBILITY OF SUCH DAMAGE.
3737
3838***************************************************************************/
3939
r14530r14531
7373public:
7474   // construction/destruction
7575   sha1_creator() { reset(); }
76   
76
7777   // reset
7878   void reset() { sha1_init(&m_context); }
79   
79
8080   // append data
8181   void append(const void *data, UINT32 length) { sha1_update(&m_context, length, reinterpret_cast<const UINT8 *>(data)); }
82   
82
8383   // finalize and compute the final digest
8484   sha1_t finish()
8585   {
r14530r14531
9292   // static wrapper to just get the digest from a block
9393   static sha1_t simple(const void *data, UINT32 length)
9494   {
95      sha1_creator creator;
96      creator.append(data, length);
95      sha1_creator creator;
96      creator.append(data, length);
9797      return creator.finish();
9898   }
9999
r14530r14531
124124public:
125125   // construction/destruction
126126   md5_creator() { reset(); }
127   
127
128128   // reset
129129   void reset() { MD5Init(&m_context); }
130   
130
131131   // append data
132132   void append(const void *data, UINT32 length) { MD5Update(&m_context, reinterpret_cast<const unsigned char *>(data), length); }
133   
133
134134   // finalize and compute the final digest
135135   md5_t finish()
136136   {
r14530r14531
142142   // static wrapper to just get the digest from a block
143143   static md5_t simple(const void *data, UINT32 length)
144144   {
145      md5_creator creator;
146      creator.append(data, length);
145      md5_creator creator;
146      creator.append(data, length);
147147      return creator.finish();
148148   }
149149
150150protected:
151151   // internal state
152   struct MD5Context    m_context;      // internal context
152   struct MD5Context   m_context;      // internal context
153153};
154154
155155
r14530r14531
175175public:
176176   // construction/destruction
177177   crc32_creator() { reset(); }
178   
178
179179   // reset
180180   void reset() { m_accum.m_raw = 0; }
181   
181
182182   // append data
183183   void append(const void *data, UINT32 length);
184   
184
185185   // finalize and compute the final digest
186186   crc32_t finish() { return m_accum; }
187187
188188   // static wrapper to just get the digest from a block
189189   static crc32_t simple(const void *data, UINT32 length)
190190   {
191      crc32_creator creator;
192      creator.append(data, length);
191      crc32_creator creator;
192      creator.append(data, length);
193193      return creator.finish();
194194   }
195195
r14530r14531
221221public:
222222   // construction/destruction
223223   crc16_creator() { reset(); }
224   
224
225225   // reset
226226   void reset() { m_accum.m_raw = 0xffff; }
227   
227
228228   // append data
229229   void append(const void *data, UINT32 length);
230   
230
231231   // finalize and compute the final digest
232232   crc16_t finish() { return m_accum; }
233233
234234   // static wrapper to just get the digest from a block
235235   static crc16_t simple(const void *data, UINT32 length)
236236   {
237      crc16_creator creator;
238      creator.append(data, length);
237      crc16_creator creator;
238      creator.append(data, length);
239239      return creator.finish();
240240   }
241241
src/lib/util/coretmpl.h
r14530r14531
5959
6060public:
6161   // construction/destruction
62   dynamic_array(int initial = 0)
62   dynamic_array(int initial = 0)
6363      : m_array(NULL),
6464        m_count(0),
6565        m_allocated(0) { if (initial != 0) expand_internal(initial); m_count = initial; }
r14530r14531
7373
7474   // simple getters
7575   int count() const { return m_count; }
76   
76
7777   // helpers
7878   void append(const _ElementType &element) { if (m_count == m_allocated) expand_internal((m_allocated == 0) ? 16 : (m_allocated << 1), true); m_array[m_count++] = element; }
7979   void reset() { delete[] m_array; m_array = NULL; m_count = m_allocated = 0; }
src/lib/util/chdcodec.c
r14530r14531
6464   // construction/destruction
6565   chd_zlib_allocator();
6666   ~chd_zlib_allocator();
67   
67
6868   // installation
6969   void install(z_stream &stream);
7070
r14530r14531
150150
151151   // core functionality
152152   virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest);
153   
153
154154   // helpers
155155   static void configure_properties(CLzmaEncProps &props, chd_file &chd);
156156
r14530r14531
346346public:
347347   // construction/destruction
348348   chd_avhuff_compressor(chd_file &chd, bool lossy);
349   
349
350350   // core functionality
351351   virtual UINT32 compress(const UINT8 *src, UINT32 srclen, UINT8 *dest);
352352
r14530r14531
368368public:
369369   // construction/destruction
370370   chd_avhuff_decompressor(chd_file &chd, bool lossy);
371   
371
372372   // core functionality
373373   virtual void decompress(const UINT8 *src, UINT32 complen, UINT8 *dest, UINT32 destlen);
374374   virtual void configure(int param, void *config);
r14530r14531
420420chd_codec::~chd_codec()
421421{
422422}
423   
424423
424
425425//-------------------------------------------------
426426//  configure - configuration
427427//-------------------------------------------------
r14530r14531
597597            catch (...)
598598            {
599599            }
600           
600
601601            if (memcmp(src, m_decompressed, m_hunkbytes) != 0)
602602            {
603603               compbytes = m_compressor[codecnum]->compress(src, m_hunkbytes, m_compress_test);
r14530r14531
621621         }
622622         catch (...) { }
623623      }
624   
624
625625   // if the best is none, copy it over
626626   if (compression == -1)
627627      memcpy(compressed, src, m_hunkbytes);
628628   return compression;
629629}
630   
631630
632631
632
633633//**************************************************************************
634634//  ZLIB ALLOCATOR HELPER
635635//**************************************************************************
r14530r14531
832832
833833
834834//-------------------------------------------------
835//  decompress - decompress data using the ZLIB
835//  decompress - decompress data using the ZLIB
836836//  codec
837837//-------------------------------------------------
838838
r14530r14531
869869{
870870   // reset pointer list
871871   memset(m_allocptr, 0, sizeof(m_allocptr));
872   
872
873873   // set our pointers
874874   Alloc = &chd_lzma_allocator::fast_alloc;
875875   Free = &chd_lzma_allocator::fast_free;
r14530r14531
936936{
937937   if (address == NULL)
938938      return;
939     
939
940940   chd_lzma_allocator *codec = reinterpret_cast<chd_lzma_allocator *>(p);
941941
942942   // find the hunk
r14530r14531
994994      SRes res = LzmaEnc_SetProps(encoder, &m_props);
995995      if (res != SZ_OK)
996996         throw CHDERR_COMPRESSION_ERROR;
997     
997
998998      // run it
999999      SizeT complen = srclen;
10001000      res = LzmaEnc_MemEncode(encoder, dest, &complen, src, srclen, 0, NULL, &m_allocator, &m_allocator);
r14530r14531
10461046   // configure the properties like the compressor did
10471047   CLzmaEncProps encoder_props;
10481048   chd_lzma_compressor::configure_properties(encoder_props, chd);
1049   
1049
10501050   // convert to decoder properties
10511051   CLzmaProps decoder_props;
10521052   decoder_props.lc = encoder_props.lc;
10531053   decoder_props.lp = encoder_props.lp;
10541054   decoder_props.pb = encoder_props.pb;
10551055   decoder_props.dicSize = encoder_props.dictSize;
1056   
1056
10571057   // do memory allocations
10581058   SRes res = LzmaDec_Allocate_MAME(&m_decoder, &decoder_props, &m_allocator);
10591059   if (res != SZ_OK)
r14530r14531
10731073
10741074
10751075//-------------------------------------------------
1076//  decompress - decompress data using the LZMA
1076//  decompress - decompress data using the LZMA
10771077//  codec
10781078//-------------------------------------------------
10791079
r14530r14531
10811081{
10821082   // initialize
10831083   LzmaDec_Init(&m_decoder);
1084   
1084
10851085   // decode
10861086   SizeT consumedlen = complen;
10871087   SizeT decodedlen = destlen;
r14530r14531
11081108
11091109
11101110//-------------------------------------------------
1111//  compress - compress data using the Huffman
1111//  compress - compress data using the Huffman
11121112//  codec
11131113//-------------------------------------------------
11141114
r14530r14531
11371137
11381138
11391139//-------------------------------------------------
1140//  decompress - decompress data using the Huffman
1140//  decompress - decompress data using the Huffman
11411141//  codec
11421142//-------------------------------------------------
11431143
r14530r14531
11671167      m_swap_endian = bigendian;
11681168   else
11691169      m_swap_endian = !bigendian;
1170   
1170
11711171   // configure the encoder
11721172   m_encoder.set_sample_rate(44100);
11731173   m_encoder.set_num_channels(2);
r14530r14531
12181218
12191219
12201220//-------------------------------------------------
1221//  decompress - decompress data using the FLAC
1221//  decompress - decompress data using the FLAC
12221222//  codec
12231223//-------------------------------------------------
12241224
r14530r14531
12561256   UINT16 native_endian = 0;
12571257   *reinterpret_cast<UINT8 *>(&native_endian) = 1;
12581258   m_swap_endian = (native_endian == 1);
1259   
1259
12601260   // configure the encoder
12611261   m_encoder.set_sample_rate(44100);
12621262   m_encoder.set_num_channels(2);
r14530r14531
13101310
13111311   // finish up
13121312   UINT32 complen = m_encoder.finish();
1313   
1313
13141314   // deflate the subcode data
13151315   m_deflater.next_in = const_cast<Bytef *>(&m_buffer[frames * CD_MAX_SECTOR_DATA]);
13161316   m_deflater.avail_in = frames * CD_MAX_SUBCODE_DATA;
r14530r14531
13801380
13811381
13821382//-------------------------------------------------
1383//  decompress - decompress data using the FLAC
1383//  decompress - decompress data using the FLAC
13841384//  codec
13851385//-------------------------------------------------
13861386
r14530r14531
14101410   zerr = inflate(&m_inflater, Z_FINISH);
14111411   if (m_inflater.total_out != frames * CD_MAX_SUBCODE_DATA)
14121412      throw CHDERR_DECOMPRESSION_ERROR;
1413   
1413
14141414   // reassemble the data
14151415   for (UINT32 framenum = 0; framenum < frames; framenum++)
14161416   {
r14530r14531
14741474
14751475
14761476//-------------------------------------------------
1477//  postinit - actual initialization of avhuff
1478//  happens here, on the first attempt to compress
1477//  postinit - actual initialization of avhuff
1478//  happens here, on the first attempt to compress
14791479//  or decompress data
14801480//-------------------------------------------------
14811481
r14530r14531
15201520
15211521
15221522//-------------------------------------------------
1523//  decompress - decompress data using the A/V
1523//  decompress - decompress data using the A/V
15241524//  codec
15251525//-------------------------------------------------
15261526
r14530r14531
15421542
15431543
15441544//-------------------------------------------------
1545//  config - codec-specific configuration for the
1545//  config - codec-specific configuration for the
15461546//  A/V codec
15471547//-------------------------------------------------
15481548
r14530r14531
15511551   // if we're getting the decompression configuration, apply it now
15521552   if (param == AVHUFF_CODEC_DECOMPRESS_CONFIG)
15531553      m_decoder.configure(*reinterpret_cast<avhuff_decompress_config *>(config));
1554   
1554
15551555   // anything else is invalid
15561556   else
15571557      throw CHDERR_INVALID_PARAMETER;
src/lib/util/chdcodec.h
r14530r14531
7575protected:
7676   // can't create these directly
7777   chd_codec(chd_file &file, bool lossy);
78   
78
7979public:
8080   // allow public deletion
8181   virtual ~chd_codec();
r14530r14531
133133   // create compressors or decompressors
134134   static chd_compressor *new_compressor(chd_codec_type type, chd_file &file);
135135   static chd_decompressor *new_decompressor(chd_codec_type type, chd_file &file);
136   
136
137137   // utilities
138138   static bool codec_exists(chd_codec_type type) { return (find_in_list(type) != NULL); }
139139   static const char *codec_name(chd_codec_type type);
r14530r14531
151151
152152   // internal helper functions
153153   static const codec_entry *find_in_list(chd_codec_type type);
154   
154
155155   template<class _CompressorClass>
156156   static chd_compressor *construct_compressor(chd_file &chd, bool lossy) { return new _CompressorClass(chd, lossy); }
157157
r14530r14531
172172   // construction/destruction
173173   chd_compressor_group(chd_file &file, chd_codec_type compressor_list[4]);
174174   ~chd_compressor_group();
175   
175
176176   // find the best compressor
177177   INT8 find_best_compressor(const UINT8 *src, UINT8 *compressed, UINT32 &complen);
178   
178
179179private:
180180   // internal state
181181   UINT32               m_hunkbytes;      // number of bytes in a hunk
r14530r14531
197197const chd_codec_type CHD_CODEC_NONE    = 0;
198198const chd_codec_type CHD_CODEC_ZLIB    = CHD_MAKE_TAG('z','l','i','b');
199199const chd_codec_type CHD_CODEC_LZMA    = CHD_MAKE_TAG('l','z','m','a');
200const chd_codec_type CHD_CODEC_HUFFMAN    = CHD_MAKE_TAG('h','u','f','f');
201const chd_codec_type CHD_CODEC_FLAC_BE    = CHD_MAKE_TAG('f','l','c','b');
202const chd_codec_type CHD_CODEC_FLAC_LE    = CHD_MAKE_TAG('f','l','c','l');
203const chd_codec_type CHD_CODEC_CD_FLAC    = CHD_MAKE_TAG('c','d','f','l');
200const chd_codec_type CHD_CODEC_HUFFMAN   = CHD_MAKE_TAG('h','u','f','f');
201const chd_codec_type CHD_CODEC_FLAC_BE   = CHD_MAKE_TAG('f','l','c','b');
202const chd_codec_type CHD_CODEC_FLAC_LE   = CHD_MAKE_TAG('f','l','c','l');
203const chd_codec_type CHD_CODEC_CD_FLAC   = CHD_MAKE_TAG('c','d','f','l');
204204const chd_codec_type CHD_CODEC_AVHUFF   = CHD_MAKE_TAG('a','v','h','u');
205205
206206// A/V codec configuration parameters
src/lib/util/un7z.c
r14530r14531
9191 
9292WRes File_Read(CSzFile *p, void *data, size_t *size)
9393{
94//   file_error err;
94//  file_error err;
9595   UINT32 read_length;
9696 
9797   if (!p->_7z_osdfile)
r14530r14531
104104   if (originalSize == 0)
105105      return 0;
106106 
107//   err =
107//  err =
108108    osd_read( p->_7z_osdfile, data, p->_7z_currfpos, originalSize, &read_length );
109109   *size = read_length;
110110   p->_7z_currfpos += read_length;
r14530r14531
127127   if (origin==2) p->_7z_currfpos = p->_7z_length - *pos;
128128 
129129   *pos = p->_7z_currfpos;
130   
130
131131   return 0;
132132}
133133 
r14530r14531
263263            if ((zn>=0x41) && (zn<=0x5a)) zn+=0x20;
264264 
265265            if (sn != zn) break;
266         }     
266         }
267267         if (j==search_filename_length) namematch = true;
268268      }
269269 
270     
270
271271      /* Check for a CRC match */
272272      if (crc==search_crc) crcmatch = true;
273273 
r14530r14531
289289            found = true;
290290      }
291291 
292      if (found)
292      if (found)
293293      {
294      //   printf("found %S %d %08x %08x %08x %s %d\n", temp, len, crc, search_crc, size, search_filename, search_filename_length);
294      //  printf("found %S %d %08x %08x %08x %s %d\n", temp, len, crc, search_crc, size, search_filename, search_filename_length);
295295         new_7z->curr_file_idx = i;
296296         new_7z->uncompressed_length = size;
297297         new_7z->crc = crc;
r14530r14531
364364 
365365   FileInStream_CreateVTable(&new_7z->archiveStream);
366366   LookToRead_CreateVTable(&new_7z->lookStream, False);
367 
367
368368   new_7z->lookStream.realStream = &new_7z->archiveStream.s;
369369   LookToRead_Init(&new_7z->lookStream);
370370 
r14530r14531
478478      &new_7z->blockIndex, &new_7z->outBuffer, &new_7z->outBufferSize,
479479      &offset, &outSizeProcessed,
480480      &new_7z->allocImp, &new_7z->allocTempImp);
481         
481
482482   if (res != SZ_OK)
483483      return _7ZERR_FILE_ERROR;
484484 
r14530r14531
510510 
511511      if (_7z->outBuffer) IAlloc_Free(&_7z->allocImp, _7z->outBuffer);
512512      if (_7z->inited) SzArEx_Free(&_7z->db, &_7z->allocImp);
513   
514513 
514 
515515      free(_7z);
516516   }
517517}
src/lib/util/avhuff.c
r14530r14531
6060        +02 = samples (2 bytes) - number of samples per audio stream
6161        +04 = width (2 bytes) - width of video data
6262        +06 = height (2 bytes) - height of video data
63        +08 = audio huffman size (2 bytes) - size of audio huffman tables
64              (0x0000 => uncompressed deltas are used)
63        +08 = audio huffman size (2 bytes) - size of audio huffman tables
64                (0x0000 => uncompressed deltas are used)
6565        +0A = str0size (2 bytes) - compressed size of stream 0
6666        +0C = str1size (2 bytes) - compressed size of stream 1
6767              ...
r14530r14531
214214
215215
216216//-------------------------------------------------
217//  encode_data - encode a block of data into a
217//  encode_data - encode a block of data into a
218218//  compressed data stream
219219//-------------------------------------------------
220220
r14530r14531
343343   *dest++ = bitmap.width() & 0xff;
344344   *dest++ = bitmap.height() >> 8;
345345   *dest++ = bitmap.height() & 0xff;
346   
346
347347   // copy the metadata
348348   if (metadatasize > 0)
349349      memcpy(dest, metadata, metadatasize);
350350   dest += metadatasize;
351   
351
352352   // copy the audio streams
353353   for (UINT8 curchan = 0; curchan < channels; curchan++)
354354      for (UINT32 cursamp = 0; cursamp < numsamples; cursamp++)
r14530r14531
356356         *dest++ = samples[curchan][cursamp] >> 8;
357357         *dest++ = samples[curchan][cursamp] & 0xff;
358358      }
359   
359
360360   // copy the video data
361361   for (INT32 y = 0; y < bitmap.height(); y++)
362362   {
r14530r14531
372372
373373
374374//-------------------------------------------------
375//  encode_audio - encode raw audio data to the
375//  encode_audio - encode raw audio data to the
376376//  destination
377377//-------------------------------------------------
378378
r14530r14531
384384   UINT16 be_test = 0;
385385   *(UINT8 *)&be_test = 1;
386386   bool swap_endian = (be_test == 1);
387   
387
388388   // set huffman tree size to 0xffff to indicate FLAC
389389   sizes[0] = 0xff;
390390   sizes[1] = 0xff;
391   
391
392392   // set the block size for this round and iterate over channels
393393   m_flac_encoder.set_block_size(samples);
394   for (int chnum = 0; chnum < channels; chnum++)
394   for (int chnum = 0; chnum < channels; chnum++)
395395   {
396396      // encode the data
397397      m_flac_encoder.reset(dest, samples * 2);
398398      if (!m_flac_encoder.encode_interleaved(reinterpret_cast<const INT16 *>(source) + chnum * samples, samples, swap_endian))
399399         return AVHERR_COMPRESSION_ERROR;
400     
400
401401      // set the size for this channel
402402      UINT32 cursize = m_flac_encoder.finish();
403403      sizes[chnum * 2 + 2] = cursize >> 8;
r14530r14531
495495
496496
497497//-------------------------------------------------
498//  encode_video - encode raw video data to the
498//  encode_video - encode raw video data to the
499499//  destination
500500//-------------------------------------------------
501501
r14530r14531
516516   // set up the output; first byte is 0x80 to indicate lossless encoding
517517   bitstream_out bitbuf(dest, width * height * 2);
518518   bitbuf.write(0x80, 8);
519   
519
520520   // compute the histograms for the data
521521   UINT16 *yrle = m_ycontext.rle_and_histo_bitmap(source + 0, width, 2, height);
522522   UINT16 *cbrle = m_cbcontext.rle_and_histo_bitmap(source + 1, width / 2, 4, height);
r14530r14531
563563//**************************************************************************
564564
565565//-------------------------------------------------
566//  rle_and_histo_bitmap - RLE compress and
566//  rle_and_histo_bitmap - RLE compress and
567567//  histogram a bitmap's worth of data
568568//-------------------------------------------------
569569
r14530r14531
584584         // fetch current data
585585         UINT8 curdelta = *source - prevdata;
586586         prevdata = *source;
587         
587
588588         // 0 deltas scan forward for a count
589589         if (curdelta == 0)
590590         {
591591            int zerocount = 1;
592           
592
593593            // count the number of consecutive values
594594            const UINT8 *scandata;
595595            for (scandata = source + item_advance; scandata < end; scandata += item_advance)
r14530r14531
597597                  zerocount++;
598598               else
599599                  break;
600           
600
601601            // if we hit the end of a row, maximize the count
602602            if (scandata >= end && zerocount >= 8)
603603               zerocount = 100000;
r14530r14531
609609            // advance past the run
610610            source += (code_to_rlecount(rlecode) - 1) * item_advance;
611611         }
612         
612
613613         // otherwise, encode the actual data
614614         else
615615            m_encoder.histo_one(*dest++ = curdelta);
616616      }
617     
617
618618      // advance to the next row
619619      source = end;
620620   }
621   
621
622622   // compute the tree for our histogram
623623   m_encoder.compute_tree_from_histo();
624624   return m_rlebuffer;
r14530r14531
787787
788788
789789//-------------------------------------------------
790//  decode_audio - decode audio from a compressed
790//  decode_audio - decode audio from a compressed
791791//  data stream
792792//-------------------------------------------------
793793
r14530r14531
827827            // finish up
828828            m_flac_decoder.finish();
829829         }
830     
830
831831         // advance to the next channel's data
832832         source += size;
833833      }
r14530r14531
881881               curdest += 2;
882882            }
883883         }
884         
884
885885         // otherwise, Huffman-decode the data
886886         else
887887         {
r14530r14531
902902               return AVHERR_INVALID_DATA;
903903         }
904904      }
905     
905
906906      // advance to the next channel's data
907907      source += size;
908908   }
r14530r14531
911911
912912
913913//-------------------------------------------------
914//  decode_video - decode video from a compressed
914//  decode_video - decode video from a compressed
915915//  data stream
916916//-------------------------------------------------
917917
r14530r14531
969969      m_cbcontext.flush_rle();
970970      m_crcontext.flush_rle();
971971   }
972   
972
973973   // check for errors if we overflowed or decoded too little data
974974   if (bitbuf.overflow() || bitbuf.flush() != complength)
975975      return AVHERR_INVALID_DATA;
src/lib/util/huffman.c
r14530r14531
165165
166166
167167//-------------------------------------------------
168//  import_tree_rle - import an RLE-encoded
168//  import_tree_rle - import an RLE-encoded
169169//  huffman tree from a source data stream
170170//-------------------------------------------------
171171
r14530r14531
215215   huffman_error error = assign_canonical_codes();
216216   if (error != HUFFERR_NONE)
217217      return error;
218   
218
219219   // build the lookup table
220220   build_lookup_table();
221221
r14530r14531
267267
268268
269269//-------------------------------------------------
270//  import_tree_huffman - import a huffman-encoded
270//  import_tree_huffman - import a huffman-encoded
271271//  huffman tree from a source data stream
272272//-------------------------------------------------
273273
r14530r14531
288288         smallhuff.m_huffnode[index].m_numbits = (count == 7) ? 0 : count;
289289      }
290290   }
291   
291
292292   // then regenerate the tree
293293   huffman_error error = smallhuff.assign_canonical_codes();
294294   if (error != HUFFERR_NONE)
295295      return error;
296296   smallhuff.build_lookup_table();
297   
297
298298   // determine the maximum length of an RLE count
299299   UINT32 temp = m_numcodes - 9;
300300   UINT8 rlefullbits = 0;
r14530r14531
337337
338338
339339//-------------------------------------------------
340//  export_tree_huffman - export a huffman tree to
340//  export_tree_huffman - export a huffman tree to
341341//  a huffman target data stream
342342//-------------------------------------------------
343343
r14530r14531
350350   UINT16 *lengths = rle_lengths;
351351   int last = ~0;
352352   int repcount = 0;
353   
353
354354   // use a small huffman context to create a tree (ignoring RLE lengths)
355355   huffman_encoder<24, 6> smallhuff;
356356
r14530r14531
363363      {
364364         if (repcount == 1)
365365            smallhuff.histo_one(*dest++ = last + 1);
366         else
366         else
367367            smallhuff.histo_one(*dest++ = 0), *lengths++ = repcount - 2;
368368      }
369     
369
370370      // if same as last, just track repeats
371371      if (newval == last)
372372         repcount++;
373     
373
374374      // otherwise, write it and start a new run
375375      else
376376      {
r14530r14531
385385   {
386386      if (repcount == 1)
387387         smallhuff.histo_one(*dest++ = last + 1);
388      else
388      else
389389         smallhuff.histo_one(*dest++ = 0), *lengths++ = repcount - 2;
390390   }
391391
r14530r14531
413413   for (int index = first_non_zero; index <= last_non_zero; index++)
414414      bitbuf.write(smallhuff.m_huffnode[index].m_numbits, 3);
415415   bitbuf.write(7, 3);
416   
416
417417   // determine the maximum length of an RLE count
418418   UINT32 temp = m_numcodes - 9;
419419   UINT8 rlefullbits = 0;
r14530r14531
427427      // encode the data
428428      UINT8 data = *src;
429429      smallhuff.encode_one(bitbuf, data);
430     
430
431431      // if this is an RLE token, encode the length following
432432      if (data == 0)
433433      {
r14530r14531
438438            bitbuf.write(7, 3), bitbuf.write(count - 7, rlefullbits);
439439      }
440440   }
441   
441
442442   // flush the final buffer
443443   return bitbuf.overflow() ? HUFFERR_OUTPUT_BUFFER_TOO_SMALL : HUFFERR_NONE;
444444}
r14530r14531
540540
541541
542542//-------------------------------------------------
543//  build_tree - build a huffman tree based on the
543//  build_tree - build a huffman tree based on the
544544//  data distribution
545545//-------------------------------------------------
546546
r14530r14531
616616
617617
618618//-------------------------------------------------
619//  assign_canonical_codes - assign canonical codes
620//  to all the nodes based on the number of bits
619//  assign_canonical_codes - assign canonical codes
620//  to all the nodes based on the number of bits
621621//  in each
622622//-------------------------------------------------
623623
r14530r14531
696696huffman_8bit_encoder::huffman_8bit_encoder()
697697{
698698}
699   
700699
700
701701//-------------------------------------------------
702702//  encode - encode a full buffer
703703//-------------------------------------------------
r14530r14531
713713   huffman_error err = compute_tree_from_histo();
714714   if (err != HUFFERR_NONE)
715715      return err;
716   
716
717717   // export the tree
718718   bitstream_out bitbuf(dest, dlength);
719719   err = export_tree_huffman(bitbuf);
720720   if (err != HUFFERR_NONE)
721721      return err;
722   
722
723723   // then encode the data
724724   for (UINT32 cur = 0; cur < slength; cur++)
725725      encode_one(bitbuf, source[cur]);
r14530r14531
727727   return bitbuf.overflow() ? HUFFERR_OUTPUT_BUFFER_TOO_SMALL : HUFFERR_NONE;
728728}
729729
730   
731730
731
732732//**************************************************************************
733733//  8-BIT DECODER
734734//**************************************************************************
r14530r14531
740740huffman_8bit_decoder::huffman_8bit_decoder()
741741{
742742}
743   
744743
744
745745//-------------------------------------------------
746746//  decode - decode a full buffer
747747//-------------------------------------------------
r14530r14531
753753   huffman_error err = import_tree_huffman(bitbuf);
754754   if (err != HUFFERR_NONE)
755755      return err;
756   
756
757757   // then decode the data
758758   for (UINT32 cur = 0; cur < dlength; cur++)
759759      dest[cur] = decode_one(bitbuf);
src/lib/util/avhuff.h
r14530r14531
129129      // construction/destruction
130130      deltarle_encoder()
131131         : m_rlecount(0) { }
132         
132
133133      // histogramming
134134      UINT16 *rle_and_histo_bitmap(const UINT8 *source, UINT32 items_per_row, UINT32 item_advance, UINT32 row_count);
135135
r14530r14531
150150   avhuff_error encode_video(const UINT8 *source, int width, int height, UINT8 *dest, UINT32 &complength);
151151   avhuff_error encode_video_lossless(const UINT8 *source, int width, int height, UINT8 *dest, UINT32 &complength);
152152
153   // video encoding contexts   
154   deltarle_encoder          m_ycontext;
155   deltarle_encoder          m_cbcontext;
156   deltarle_encoder          m_crcontext;
153   // video encoding contexts
154   deltarle_encoder         m_ycontext;
155   deltarle_encoder         m_cbcontext;
156   deltarle_encoder         m_crcontext;
157157
158158   // audio encoding contexts
159159   dynamic_buffer            m_audiobuffer;
r14530r14531
189189      // construction/destruction
190190      deltarle_decoder()
191191         : m_rlecount(0), m_prevdata(0) { }
192         
192
193193      // general
194194      void reset() { m_rlecount = m_prevdata = 0; }
195195
r14530r14531
212212   avhuff_error decode_video_lossless(int width, int height, const UINT8 *source, UINT32 complength, UINT8 *dest, UINT32 dstride, UINT32 dxor);
213213
214214   // internal state
215   avhuff_decompress_config    m_config;
215   avhuff_decompress_config   m_config;
216216
217217   // video decoding contexts
218   deltarle_decoder          m_ycontext;
219   deltarle_decoder          m_cbcontext;
220   deltarle_decoder          m_crcontext;
218   deltarle_decoder         m_ycontext;
219   deltarle_decoder         m_cbcontext;
220   deltarle_decoder         m_crcontext;
221221
222222   // audio decoding contexts
223223   huffman_8bit_decoder      m_audiohi_decoder;
src/lib/util/huffman.h
r14530r14531
8484      UINT32            m_bits;               // bits used to encode the node
8585      UINT8            m_numbits;            // number of bits needed for this node
8686   };
87   
87
8888   // construction/destruction
8989   huffman_context_base(int numcodes, int maxbits, lookup_value *lookup, UINT32 *histo, node_t *nodes);
9090
r14530r14531
133133   void histo_reset() { memset(m_datahisto_array, 0, sizeof(m_datahisto_array)); }
134134   void histo_one(UINT32 data);
135135   void encode_one(bitstream_out &bitbuf, UINT32 data);
136   
136
137137   // expose tree computation and export
138138   using huffman_context_base::compute_tree_from_histo;
139139   using huffman_context_base::export_tree_rle;
140140   using huffman_context_base::export_tree_huffman;
141   
141
142142private:
143143   // array versions of the info we need
144144   UINT32               m_datahisto_array[_NumCodes];
r14530r14531
159159
160160   // single item operations
161161   UINT32 decode_one(bitstream_in &bitbuf);
162   
162
163163   // expose tree import
164164   using huffman_context_base::import_tree_rle;
165165   using huffman_context_base::import_tree_huffman;
166   
166
167167private:
168168   // array versions of the info we need
169169   node_t               m_huffnode_array[_NumCodes];
r14530r14531
179179public:
180180   // construction/destruction
181181   huffman_8bit_encoder();
182   
182
183183   // operations
184184   huffman_error encode(const UINT8 *source, UINT32 slength, UINT8 *dest, UINT32 destlength, UINT32 &complength);
185185};
186186
187   
187
188188// ======================> huffman_8bit_decoder
189189
190190// generic 8-bit encoder/decoder
r14530r14531
193193public:
194194   // construction/destruction
195195   huffman_8bit_decoder();
196   
196
197197   // operations
198198   huffman_error decode(const UINT8 *source, UINT32 slength, UINT8 *dest, UINT32 destlength);
199199};
src/version.c
r14530r14531
3838***************************************************************************/
3939
4040extern const char build_version[];
41const char build_version[] = "0.145 ("__DATE__")";
41const char build_version[] = "0.145u1 ("__DATE__")";
src/ldplayer/ldplayer.c
r14530r14531
184184         {
185185            astring fullpath(image_file->fullpath();
186186            image_file.close();
187           
187
188188            // try to open the CHD
189           
189
190190            if (set_disk_handle(machine(), "laserdisc", fullpath) == CHDERR_NONE)
191191            {
192192               m_filename.cpy(dir->name);

Previous 15994 Revisions Next


© 1998-2018 The MESS Team