diff --git a/src/386.c b/src/386.c index d685edf56..6c6df2623 100644 --- a/src/386.c +++ b/src/386.c @@ -232,7 +232,6 @@ void exec386(int cycs) /* testr[8]=flags;*/ // oldcs2=oldcs; // oldpc2=oldpc; -opcode_realstart: oldcs=CS; cpu_state.oldpc = cpu_state.pc; oldcpl=CPL; @@ -243,7 +242,6 @@ dontprint=0; cpu_state.ea_seg = &_ds; cpu_state.ssegs = 0; -opcodestart: fetchdat = fastreadl(cs + cpu_state.pc); if (!cpu_state.abrt) diff --git a/src/808x.c b/src/808x.c index 75dd2ad46..7e0bceec6 100644 --- a/src/808x.c +++ b/src/808x.c @@ -505,7 +505,7 @@ int indump = 0; void dumpregs() { - int c,d=0,e=0,ff; + int c,d=0,e=0; #ifndef RELEASE_BUILD FILE *f; if (indump) return; @@ -644,7 +644,14 @@ void resetx86() eflags=0; cgate32=0; loadcs(0xFFFF); - rammask = AT ? 0xFFFFFFFF : 0xfffff; + if (AT) + { + rammask = mem_a20_state ? 0xffffffff : 0xffefffff; + } + else + { + rammask = 0xfffff; + } idt.base = 0; flags=2; makeznptable(); diff --git a/src/Makefile.mingw b/src/Makefile.mingw index a55977278..b7a2dfa75 100644 --- a/src/Makefile.mingw +++ b/src/Makefile.mingw @@ -1,12 +1,12 @@ -VPATH = . dosbox resid-fp slirp +VPATH = . crcspeed dosbox lzf resid-fp slirp CPP = g++.exe CC = gcc.exe WINDRES = windres.exe -CFLAGS = -O3 -march=native -mtune=native -fbranch-probabilities -fvpt -funroll-loops -fpeel-loops -ftracer -fomit-frame-pointer -ffast-math -msse -msse2 -msse3 -mssse3 -mfpmath=sse -mstackrealign +CFLAGS = -O3 -march=native -mtune=native -fbranch-probabilities -fvpt -fpeel-loops -ftracer -fomit-frame-pointer -ffast-math -msse -msse2 -msse3 -mssse3 -mfpmath=sse -mstackrealign -g DFLAGS = -O3 -march=i686 -fomit-frame-pointer -msse2 -mstackrealign OBJ = 386.o 386_dynarec.o 386_dynarec_ops.o 808x.o acer386sx.o acerm3a.o ali1429.o amstrad.o cdrom-ioctl.o cdrom-iso.o \ cdrom-null.o codegen.o codegen_ops.o codegen_timing_486.o codegen_timing_686.o codegen_timing_pentium.o codegen_timing_winchip.o codegen_x86.o compaq.o config.o cpu.o dac.o \ - device.o disc.o disc_86f.o disc_fdi.o disc_imd.o disc_img_86box.o disc_random.o disc_td0.o dma.o fdc.o fdc37c665.o fdc37c932fr.o fdd.o fdi2raw.o gameport.o headland.o i430hx.o i430lx.o i430fx.o \ + device.o disc.o disc_86f.o disc_fdi.o disc_imd.o disc_img.o disc_random.o disc_td0.o dma.o fdc.o fdc37c665.o fdc37c932fr.o fdd.o fdi2raw.o gameport.o headland.o i430hx.o i430lx.o i430fx.o \ i430nx.o i430vx.o i440fx.o ide.o intel.o intel_flash.o io.o jim.o joystick_ch_flightstick_pro.o joystick_standard.o joystick_sw_pad.o joystick_tm_fcs.o keyboard.o keyboard_amstrad.o keyboard_at.o \ keyboard_olim24.o keyboard_pcjr.o keyboard_xt.o lpt.o mcr.o mem.o memregs.o model.o mouse.o mouse_amstrad.o mouse_ps2.o \ mouse_serial.o ne2000.o neat.o nethandler.o nmi.o nvr.o olivetti_m24.o opti.o pc.o pc87306.o pci.o pic.o piix.o pit.o ppi.o ps1.o rom.o rtc.o \ @@ -14,24 +14,25 @@ OBJ = 386.o 386_dynarec.o 386_dynarec_ops.o 808x.o acer386sx.o acerm3a.o ali1429 sound_dbopl.o sound_emu8k.o sound_gus.o sound_mpu401_uart.o sound_opl.o sound_pas16.o sound_ps1.o sound_pssj.o sound_resid.o \ sound_sb.o sound_sb_dsp.o sound_sn76489.o sound_speaker.o sound_ssi2001.o sound_wss.o sound_ym7128.o \ soundopenal.o tandy_eeprom.o tandy_rom.o timer.o um8669f.o vid_ati_eeprom.o vid_ati_mach64.o vid_ati18800.o \ - vid_ati28800.o vid_ati68860_ramdac.o vid_bt485_ramdac.o vid_cga.o vid_cl_gd.o vid_cl_gd_blit.o vid_cl_ramdac.o vid_ega.o vid_et4000.o \ + vid_ati28800.o vid_ati68860_ramdac.o vid_bt485_ramdac.o vid_cga.o vid_cl_gd.o vid_cl_gd_blit.o vid_cl_ramdac.o vid_colorplus.o vid_ega.o vid_et4000.o \ vid_et4000w32.o vid_hercules.o vid_icd2061.o vid_ics2595.o vid_incolor.o vid_mda.o vid_nv_riva128.o vid_nv_rivatnt.o \ vid_olivetti_m24.o vid_oti067.o vid_paradise.o vid_pc1512.o vid_pc1640.o vid_pc200.o \ vid_pcjr.o vid_ps1_svga.o vid_s3.o vid_s3_virge.o vid_sdac_ramdac.o vid_stg_ramdac.o vid_svga.o \ vid_svga_render.o vid_tandy.o vid_tandysl.o vid_tgui9440.o vid_tkd8001_ramdac.o vid_tvga.o vid_unk_ramdac.o \ - vid_vga.o vid_voodoo.o video.o w83877f.o wd76c10.o win.o win-config.o win-d3d.o win-d3d-fs.o win-ddraw.o \ + vid_vga.o vid_voodoo.o video.o wd76c10.o win.o win-config.o win-d3d.o win-d3d-fs.o win-ddraw.o \ win-ddraw-fs.o win-ddraw-screenshot.o win-deviceconfig.o win-hdconf.o win-joystick.o win-joystickconfig.o win-keyboard.o win-midi.o win-mouse.o \ win-status.o win-video.o x86seg.o x87.o xtide.o pc.res +CRCOBJ = crcspeed.o crc64speed.o DBOBJ = dbopl.o nukedopl.o vid_cga_comp.o +LZFOBJ = lzf_c.o lzf_d.o SIDOBJ = convolve.o convolve-sse.o envelope.o extfilt.o filter.o pot.o sid.o voice.o wave6581__ST.o wave6581_P_T.o wave6581_PS_.o wave6581_PST.o wave8580__ST.o wave8580_P_T.o wave8580_PS_.o wave8580_PST.o wave.o SLIRPOBJ = bootp.o ip_icmp.o misc.o socket.o tcp_timer.o cksum.o ip_input.o queue.o tcp_input.o tftp.o debug.o ip_output.o sbuf.o tcp_output.o udp.o if.o mbuf.o slirp.o tcp_subr.o LIBS = -mwindows -lwinmm -lopenal.dll -lopenal -lddraw -ldinput8 -ldxguid -ld3d9 -ld3dx9 -lwsock32 -liphlpapi -lstdc++ -static-libstdc++ -static-libgcc -static -86Box.exe: $(OBJ) $(DBOBJ) $(SIDOBJ) $(SLIRPOBJ) - $(CC) $(OBJ) $(DBOBJ) $(SIDOBJ) $(SLIRPOBJ) -o "86Box.exe" $(LIBS) - +86Box.exe: $(OBJ) $(CRCOBJ) $(DBOBJ) $(LZFOBJ) $(SIDOBJ) $(SLIRPOBJ) + $(CC) $(OBJ) $(CRCOBJ) $(DBOBJ) $(LZFOBJ) $(SIDOBJ) $(SLIRPOBJ) -o "86Box.exe" $(LIBS) strip "86Box.exe" all : 86Box.exe diff --git a/src/Makefile.mingw64 b/src/Makefile.mingw64 index 4a2a5a33d..04f59513c 100644 --- a/src/Makefile.mingw64 +++ b/src/Makefile.mingw64 @@ -1,12 +1,12 @@ -VPATH = . dosbox resid-fp slirp +VPATH = . crcspeed dosbox lzf resid-fp slirp CPP = g++.exe CC = gcc.exe WINDRES = windres.exe -CFLAGS = -O3 -march=native -mtune=native -fbranch-probabilities -fvpt -funroll-loops -fpeel-loops -ftracer -fomit-frame-pointer -ffast-math -msse -msse2 -msse3 -mssse3 -mfpmath=sse -mstackrealign +CFLAGS = -O3 -march=native -mtune=native -fbranch-probabilities -fvpt -fpeel-loops -ftracer -fomit-frame-pointer -ffast-math -msse -msse2 -msse3 -mssse3 -mfpmath=sse -mstackrealign DFLAGS = -O3 -fomit-frame-pointer -msse2 OBJ = 386.o 386_dynarec.o 386_dynarec_ops.o 808x.o acer386sx.o acerm3a.o ali1429.o amstrad.o cdrom-ioctl.o cdrom-iso.o \ cdrom-null.o codegen.o codegen_ops.o codegen_timing_486.o codegen_timing_686.o codegen_timing_pentium.o codegen_timing_winchip.o codegen_x86-64.o compaq.o config.o cpu.o dac.o \ - device.o disc.o disc_86f.o disc_fdi.o disc_imd.o disc_img_86box.o disc_random.o disc_td0.o dma.o fdc.o fdc37c665.o fdc37c932fr.o fdd.o fdi2raw.o gameport.o headland.o i430hx.o i430lx.o i430fx.o \ + device.o disc.o disc_86f.o disc_fdi.o disc_imd.o disc_img.o disc_random.o disc_td0.o dma.o fdc.o fdc37c665.o fdc37c932fr.o fdd.o fdi2raw.o gameport.o headland.o i430hx.o i430lx.o i430fx.o \ i430nx.o i430vx.o i440fx.o ide.o intel.o intel_flash.o io.o jim.o joystick_ch_flightstick_pro.o joystick_standard.o joystick_sw_pad.o joystick_tm_fcs.o keyboard.o keyboard_amstrad.o keyboard_at.o \ keyboard_olim24.o keyboard_pcjr.o keyboard_xt.o lpt.o mcr.o mem.o memregs.o model.o mouse.o mouse_amstrad.o mouse_ps2.o \ mouse_serial.o ne2000.o neat.o nethandler.o nmi.o nvr.o olivetti_m24.o opti.o pc.o pc87306.o pci.o pic.o piix.o pit.o ppi.o ps1.o rom.o rtc.o \ @@ -14,23 +14,25 @@ OBJ = 386.o 386_dynarec.o 386_dynarec_ops.o 808x.o acer386sx.o acerm3a.o ali1429 sound_dbopl.o sound_emu8k.o sound_gus.o sound_mpu401_uart.o sound_opl.o sound_pas16.o sound_ps1.o sound_pssj.o sound_resid.o \ sound_sb.o sound_sb_dsp.o sound_sn76489.o sound_speaker.o sound_ssi2001.o sound_wss.o sound_ym7128.o \ soundopenal.o tandy_eeprom.o tandy_rom.o timer.o um8669f.o vid_ati_eeprom.o vid_ati_mach64.o vid_ati18800.o \ - vid_ati28800.o vid_ati68860_ramdac.o vid_bt485_ramdac.o vid_cga.o vid_cl_gd.o vid_cl_gd_blit.o vid_cl_ramdac.o vid_ega.o vid_et4000.o \ + vid_ati28800.o vid_ati68860_ramdac.o vid_bt485_ramdac.o vid_cga.o vid_cl_gd.o vid_cl_gd_blit.o vid_cl_ramdac.o vid_colorplus.o vid_ega.o vid_et4000.o \ vid_et4000w32.o vid_hercules.o vid_icd2061.o vid_ics2595.o vid_incolor.o vid_mda.o vid_nv_riva128.o vid_nv_rivatnt.o \ vid_olivetti_m24.o vid_oti067.o vid_paradise.o vid_pc1512.o vid_pc1640.o vid_pc200.o \ vid_pcjr.o vid_ps1_svga.o vid_s3.o vid_s3_virge.o vid_sdac_ramdac.o vid_stg_ramdac.o vid_svga.o \ vid_svga_render.o vid_tandy.o vid_tandysl.o vid_tgui9440.o vid_tkd8001_ramdac.o vid_tvga.o vid_unk_ramdac.o \ - vid_vga.o vid_voodoo.o video.o w83877f.o wd76c10.o win.o win-config.o win-d3d.o win-d3d-fs.o win-ddraw.o \ + vid_vga.o vid_voodoo.o video.o wd76c10.o win.o win-config.o win-d3d.o win-d3d-fs.o win-ddraw.o \ win-ddraw-fs.o win-ddraw-screenshot.o win-deviceconfig.o win-hdconf.o win-joystick.o win-joystickconfig.o win-keyboard.o win-midi.o win-mouse.o \ win-status.o win-video.o x86seg.o x87.o xtide.o pc.res +CRCOBJ = crcspeed.o crc64speed.o DBOBJ = dbopl.o nukedopl.o vid_cga_comp.o +LZFOBJ = lzf_c.o lzf_d.o SIDOBJ = convolve.o convolve-sse.o envelope.o extfilt.o filter.o pot.o sid.o voice.o wave6581__ST.o wave6581_P_T.o wave6581_PS_.o wave6581_PST.o wave8580__ST.o wave8580_P_T.o wave8580_PS_.o wave8580_PST.o wave.o SLIRPOBJ = bootp.o ip_icmp.o misc.o socket.o tcp_timer.o cksum.o ip_input.o queue.o tcp_input.o tftp.o debug.o ip_output.o sbuf.o tcp_output.o udp.o if.o mbuf.o slirp.o tcp_subr.o LIBS = -mwindows -lwinmm -lopenal -lddraw -ldinput8 -ldxguid -ld3d9 -ld3dx9 -lwsock32 -liphlpapi -lstdc++ -static-libstdc++ -static-libgcc -static -lopenal.dll -lgcov -lPacket -lwpcap -86Box64.exe: $(OBJ) $(DBOBJ) $(SIDOBJ) $(SLIRPOBJ) - $(CC) $(OBJ) $(DBOBJ) $(SIDOBJ) $(SLIRPOBJ) -o "86Box64.exe" $(LIBS) +86Box64.exe: $(OBJ) $(CRCOBJ) $(DBOBJ) $(LZFOBJ) $(SIDOBJ) $(SLIRPOBJ) + $(CC) $(OBJ) $(CRCOBJ) $(DBOBJ) $(LZFOBJ) $(SIDOBJ) $(SLIRPOBJ) -o "86Box64.exe" $(LIBS) strip "86Box64.exe" peflags --bigaddr=false 86Box64.exe diff --git a/src/cdrom-ioctl-linux.c b/src/cdrom-ioctl-linux.c index 07e93737f..5427d35d3 100644 --- a/src/cdrom-ioctl-linux.c +++ b/src/cdrom-ioctl-linux.c @@ -210,7 +210,7 @@ static int read_toc(int fd, struct cdrom_tocentry *btoc) first_track = toc_hdr.cdth_trk0; last_track = toc_hdr.cdth_trk1; //pclog("read_toc: first_track=%i last_track=%i\n", first_track, last_track); - memset(btoc, 0, sizeof(btoc)); + memset(btoc, 0, sizeof(cdrom_tocentry)); for (track = toc_hdr.cdth_trk0; track <= toc_hdr.cdth_trk1; track++) { diff --git a/src/cdrom-ioctl.c b/src/cdrom-ioctl.c index 3b1e0ff4a..9159655a1 100644 --- a/src/cdrom-ioctl.c +++ b/src/cdrom-ioctl.c @@ -273,6 +273,7 @@ static int ioctl_get_last_block(unsigned char starttrack, int msf, int maxlen, i DeviceIoControl(hIOCTL,IOCTL_CDROM_READ_TOC, NULL,0,&lbtoc,sizeof(lbtoc),&size,NULL); ioctl_close(); tocvalid=1; + d=0; for (c=d;c<=lbtoc.LastTrack;c++) { uint32_t address; diff --git a/src/cdrom-iso.c b/src/cdrom-iso.c index f6af00252..7cd85d1ce 100644 --- a/src/cdrom-iso.c +++ b/src/cdrom-iso.c @@ -157,7 +157,6 @@ static void lba_to_msf(uint8_t *buf, int lba) static void iso_readsector_raw(uint8_t *b, int sector) { - uint32_t temp; if (!cdrom_drive) return; iso_image = fopen(iso_path, "rb"); fseek(iso_image, sector*2048, SEEK_SET); diff --git a/src/codegen_ops_x86-64.h b/src/codegen_ops_x86-64.h index dc6330cfd..5fd9923ba 100644 --- a/src/codegen_ops_x86-64.h +++ b/src/codegen_ops_x86-64.h @@ -3637,7 +3637,6 @@ static void FP_FXCH(int reg) addbyte(0x4c); addbyte(0xdd); addbyte(cpu_state_offset(MM)); - reg = reg; } diff --git a/src/codegen_ops_x86.h b/src/codegen_ops_x86.h index 79db54ee5..09e1b8896 100644 --- a/src/codegen_ops_x86.h +++ b/src/codegen_ops_x86.h @@ -1802,7 +1802,6 @@ static void FP_LOAD_S() addbyte(0xdd); /*FSTP ST[reg][EBP]*/ addbyte(0x5d); addbyte(cpu_state_offset(ST[(cpu_state.TOP - 1) & 7])); - block_current = block_current; } else { diff --git a/src/codegen_x86-64.h b/src/codegen_x86-64.h index da2d7a987..f8b055751 100644 --- a/src/codegen_x86-64.h +++ b/src/codegen_x86-64.h @@ -18,7 +18,7 @@ enum OP_RET = 0xc3 }; -#define NR_HOST_REGS 3 +#define NR_HOST_REGS 4 extern int host_reg_mapping[NR_HOST_REGS]; #define NR_HOST_XMM_REGS 7 extern int host_reg_xmm_mapping[NR_HOST_XMM_REGS]; diff --git a/src/codegen_x86.h b/src/codegen_x86.h index 67f51b15c..ca2d4ef87 100644 --- a/src/codegen_x86.h +++ b/src/codegen_x86.h @@ -15,7 +15,7 @@ enum OP_RET = 0xc3 }; -#define NR_HOST_REGS 3 +#define NR_HOST_REGS 4 extern int host_reg_mapping[NR_HOST_REGS]; #define NR_HOST_XMM_REGS 7 extern int host_reg_xmm_mapping[NR_HOST_XMM_REGS]; diff --git a/src/config.c b/src/config.c index 7683a450a..234254fe5 100644 --- a/src/config.c +++ b/src/config.c @@ -121,7 +121,7 @@ void config_load(char *fn) c = 0; - while (buffer[c] == ' ' && buffer[c]) + while (buffer[c] == ' ') c++; if (!buffer[c]) continue; @@ -281,7 +281,6 @@ char *config_get_string(char *head, char *name, char *def) { section_t *section; entry_t *entry; - int value; section = find_section(head); diff --git a/src/cpu.c b/src/cpu.c index dd8974b52..0baa13313 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -604,12 +604,12 @@ void cpu_set() if (cpu_s->pci_speed) { - pci_nonburst_time = 3*cpu_s->rspeed / cpu_s->pci_speed; + pci_nonburst_time = 4*cpu_s->rspeed / cpu_s->pci_speed; pci_burst_time = cpu_s->rspeed / cpu_s->pci_speed; } else { - pci_nonburst_time = 3; + pci_nonburst_time = 4; pci_burst_time = 1; } pclog("PCI burst=%i nonburst=%i\n", pci_burst_time, pci_nonburst_time); diff --git a/src/crcspeed/crc64speed.c b/src/crcspeed/crc64speed.c new file mode 100644 index 000000000..b1a7bbb94 --- /dev/null +++ b/src/crcspeed/crc64speed.c @@ -0,0 +1,275 @@ +/* Copyright (c) 2014, Matt Stancliff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Redis nor the names of its contributors may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ + +#include "crc64speed.h" + +/* If CRC64SPEED_DUAL is defined, we allow calls to + * both _little and _big CRC. + * By default, we only allow one endianness to be used + * and the first call to either _init function will set the + * lookup table endianness for the life of this module. + * We don't enable dual lookups by default because + * each 8x256 lookup table is 16k. */ +#ifndef CRC64SPEED_DUAL +static uint64_t crc64_table[8][256] = {{0}}; +static void *crc64_table_little = NULL, *crc64_table_big = NULL; +static const bool dual = false; +#else +static uint64_t crc64_table_little[8][256] = {{0}}; +static uint64_t crc64_table_big[8][256] = {{0}}; +static void *crc64_table = NULL; +static const bool dual = true; +#endif + +/* value of crc64_table[0][1], architecture dependent. */ +#define LITTLE1 UINT64_C(0x7ad870c830358979) +#define BIG1 UINT64_C(0x79893530c870d87a) + +/* Define CRC64SPEED_SAFE if you want runtime checks to stop + * CRCs from being calculated by uninitialized tables (and also stop tables + * from being initialized more than once). */ +#ifdef CRC64SPEED_SAFE +#define should_init(table, val) \ + do { \ + if ((table)[0][1] == (val)) \ + return false; \ + } while (0) +#define check_init(table, val) \ + do { \ + if ((table)[0][1] != (val)) \ + return false; \ + } while (0) +#else +#define should_init(a, b) +#define check_init(a, b) +#endif + +#define POLY UINT64_C(0xad93d23594c935a9) +/******************** BEGIN GENERATED PYCRC FUNCTIONS ********************/ +/** + * Generated on Sun Dec 21 14:14:07 2014, + * by pycrc v0.8.2, https://www.tty1.net/pycrc/ + * + * LICENSE ON GENERATED CODE: + * ========================== + * As of version 0.6, pycrc is released under the terms of the MIT licence. + * The code generated by pycrc is not considered a substantial portion of the + * software, therefore the author of pycrc will not claim any copyright on + * the generated code. + * ========================== + * + * CRC configuration: + * Width = 64 + * Poly = 0xad93d23594c935a9 + * XorIn = 0xffffffffffffffff + * ReflectIn = True + * XorOut = 0x0000000000000000 + * ReflectOut = True + * Algorithm = bit-by-bit-fast + * + * Modifications after generation (by matt): + * - included finalize step in-line with update for single-call generation + * - re-worked some inner variable architectures + * - adjusted function parameters to match expected prototypes. + *****************************************************************************/ + +/** + * Reflect all bits of a \a data word of \a data_len bytes. + * + * \param data The data word to be reflected. + * \param data_len The width of \a data expressed in number of bits. + * \return The reflected data. + *****************************************************************************/ +static inline uint_fast64_t crc_reflect(uint_fast64_t data, size_t data_len) { + uint_fast64_t ret = data & 0x01; + + for (size_t i = 1; i < data_len; i++) { + data >>= 1; + ret = (ret << 1) | (data & 0x01); + } + + return ret; +} + +/** + * Update the crc value with new data. + * + * \param crc The current crc value. + * \param data Pointer to a buffer of \a data_len bytes. + * \param data_len Number of bytes in the \a data buffer. + * \return The updated crc value. + ******************************************************************************/ +uint64_t crc64(uint_fast64_t crc, const void *in_data, const uint64_t len) { + const uint8_t *data = in_data; + bool bit; + + for (uint64_t offset = 0; offset < len; offset++) { + uint8_t c = data[offset]; + for (uint_fast8_t i = 0x01; i & 0xff; i <<= 1) { + bit = crc & 0x8000000000000000; + if (c & i) { + bit = !bit; + } + + crc <<= 1; + if (bit) { + crc ^= POLY; + } + } + + crc &= 0xffffffffffffffff; + } + + crc = crc & 0xffffffffffffffff; + return crc_reflect(crc, 64) ^ 0x0000000000000000; +} + +/******************** END GENERATED PYCRC FUNCTIONS ********************/ + +/* Only for testing; doesn't support DUAL */ +uint64_t crc64_lookup(uint64_t crc, const void *in_data, const uint64_t len) { + const uint8_t *data = in_data; + for (size_t i = 0; i < len; i++) { + crc = crc64_table[0][(uint8_t)crc ^ data[i]] ^ (crc >> 8); + } + + return crc; +} + +/* Returns false if CRC64SPEED_SAFE and table already initialized. */ +bool crc64speed_init(void) { +#ifndef CRC64SPEED_DUAL + should_init(crc64_table, LITTLE1); +#else + should_init(crc64_table_little, LITTLE1); +#endif + crcspeed64little_init(crc64, dual ? crc64_table_little : crc64_table); + return true; +} + +/* Returns false if CRC64SPEED_SAFE and table already initialized. */ +bool crc64speed_init_big(void) { +#ifndef CRC64SPEED_DUAL + should_init(crc64_table, BIG1); +#else + should_init(crc64_table_big, BIG1); +#endif + crcspeed64big_init(crc64, dual ? crc64_table_big : crc64_table); + return true; +} + +uint64_t crc64speed(uint64_t crc, const void *s, const uint64_t l) { +/* Quickly check if CRC table is initialized to little endian correctly. */ +#ifndef CRC64SPEED_DUAL + check_init(crc64_table, LITTLE1); +#else + check_init(crc64_table_little, LITTLE1); +#endif + return crcspeed64little(dual ? crc64_table_little : crc64_table, crc, + (void *)s, l); +} + +uint64_t crc64speed_big(uint64_t crc, const void *s, const uint64_t l) { +/* Quickly check if CRC table is initialized to big endian correctly. */ +#ifndef CRC64SPEED_DUAL + check_init(crc64_table, BIG1); +#else + check_init(crc64_table_big, BIG1); +#endif + return crcspeed64big(dual ? crc64_table_big : crc64_table, crc, (void *)s, + l); +} + +bool crc64speed_init_native(void) { + const uint64_t n = 1; + return *(char *)&n ? crc64speed_init() : crc64speed_init_big(); +} + +/* Iterate over table to fully load it into a cache near the CPU. */ +void crc64speed_cache_table(void) { + uint64_t m; + for (int i = 0; i < 8; ++i) { + for (int j = 0; j < 256; ++j) { +#ifndef CRC64SPEED_DUAL + m = crc64_table[i][j]; +#else + m = crc64_table_little[i][j]; + m += crc64_table_big[i][j]; +#endif + ++m; + } + } +} + +/* If you are on a platform where endianness can change at runtime, this + * will break unless you compile with CRC64SPEED_DUAL and manually run + * _init() and _init_big() instead of using _init_native() */ +uint64_t crc64speed_native(uint64_t crc, const void *s, const uint64_t l) { + const uint64_t n = 1; + return *(char *)&n ? crc64speed(crc, s, l) : crc64speed_big(crc, s, l); +} + +/* Test main */ +#if defined(REDIS_TEST) || defined(REDIS_TEST_MAIN) +#include + +#define UNUSED(x) (void)(x) +int crc64Test(int argc, char *argv[]) { + UNUSED(argc); + UNUSED(argv); + crc64speed_init(); + printf("[calcula]: e9c6d914c4b8d9ca == %016" PRIx64 "\n", + (uint64_t)crc64(0, "123456789", 9)); + printf("[lookupt]: e9c6d914c4b8d9ca == %016" PRIx64 "\n", + (uint64_t)crc64_lookup(0, "123456789", 9)); + printf("[64speed]: e9c6d914c4b8d9ca == %016" PRIx64 "\n", + (uint64_t)crc64speed(0, "123456789", 9)); + char li[] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed " + "do eiusmod tempor incididunt ut labore et dolore magna " + "aliqua. Ut enim ad minim veniam, quis nostrud exercitation " + "ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis " + "aute irure dolor in reprehenderit in voluptate velit esse " + "cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia " + "deserunt mollit anim id est laborum."; + printf("[calcula]: c7794709e69683b3 == %016" PRIx64 "\n", + (uint64_t)crc64(0, li, sizeof(li))); + printf("[lookupt]: c7794709e69683b3 == %016" PRIx64 "\n", + (uint64_t)crc64_lookup(0, li, sizeof(li))); + printf("[64speed]: c7794709e69683b3 == %016" PRIx64 "\n", + (uint64_t)crc64speed(0, li, sizeof(li))); + return 0; +} + +#endif + +#ifdef REDIS_TEST_MAIN +int main(int argc, char *argv[]) { + return crc64Test(argc, argv); +} + +#endif diff --git a/src/crcspeed/crc64speed.h b/src/crcspeed/crc64speed.h new file mode 100644 index 000000000..c72cd8f91 --- /dev/null +++ b/src/crcspeed/crc64speed.h @@ -0,0 +1,20 @@ +#ifndef CRC64SPEED_H +#define CRC64SPEED_H +#include "crcspeed.h" +#include "stdbool.h" + +/* Does not require init */ +uint64_t crc64(uint64_t crc, const void *data, const uint64_t len); +void crc64speed_cache_table(void); + +/* All other crc functions here require _init() before usage. */ +bool crc64speed_init(void); +uint64_t crc64_lookup(uint64_t crc, const void *in_data, const uint64_t len); +uint64_t crc64speed(uint64_t crc, const void *s, const uint64_t l); + +bool crc64speed_init_big(void); +uint64_t crc64speed_big(uint64_t crc, const void *s, const uint64_t l); + +bool crc64speed_init_native(void); +uint64_t crc64speed_native(uint64_t crc, const void *s, const uint64_t l); +#endif diff --git a/src/crcspeed/crcspeed.c b/src/crcspeed/crcspeed.c new file mode 100644 index 000000000..d2d97a8c7 --- /dev/null +++ b/src/crcspeed/crcspeed.c @@ -0,0 +1,281 @@ +/* + * Copyright (C) 2013 Mark Adler + * Originally by: crc64.c Version 1.4 16 Dec 2013 Mark Adler + * Modifications by Matt Stancliff : + * - removed CRC64-specific behavior + * - added generation of lookup tables by parameters + * - removed inversion of CRC input/result + * - removed automatic initialization in favor of explicit initialization + + This software is provided 'as-is', without any express or implied + warranty. In no event will the author be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Mark Adler + madler@alumni.caltech.edu + */ + +#include "crcspeed.h" + +/* Fill in a CRC constants table. */ +void crcspeed64little_init(crcfn64 crcfn, uint64_t table[8][256]) { + uint64_t crc; + + /* generate CRCs for all single byte sequences */ + for (int n = 0; n < 256; n++) { + table[0][n] = crcfn(0, &n, 1); + } + + /* generate nested CRC table for future slice-by-8 lookup */ + for (int n = 0; n < 256; n++) { + crc = table[0][n]; + for (int k = 1; k < 8; k++) { + crc = table[0][crc & 0xff] ^ (crc >> 8); + table[k][n] = crc; + } + } +} + +void crcspeed16little_init(crcfn16 crcfn, uint16_t table[8][256]) { + uint16_t crc; + + /* generate CRCs for all single byte sequences */ + for (int n = 0; n < 256; n++) { + table[0][n] = crcfn(0, &n, 1); + } + + /* generate nested CRC table for future slice-by-8 lookup */ + for (int n = 0; n < 256; n++) { + crc = table[0][n]; + for (int k = 1; k < 8; k++) { + crc = table[0][(crc >> 8) & 0xff] ^ (crc << 8); + table[k][n] = crc; + } + } +} + +/* Reverse the bytes in a 64-bit word. */ +static inline uint64_t rev8(uint64_t a) { +#if defined(__GNUC__) || defined(__clang__) + return __builtin_bswap64(a); +#else + uint64_t m; + + m = UINT64_C(0xff00ff00ff00ff); + a = ((a >> 8) & m) | (a & m) << 8; + m = UINT64_C(0xffff0000ffff); + a = ((a >> 16) & m) | (a & m) << 16; + return a >> 32 | a << 32; +#endif +} + +/* This function is called once to initialize the CRC table for use on a + big-endian architecture. */ +void crcspeed64big_init(crcfn64 fn, uint64_t big_table[8][256]) { + /* Create the little endian table then reverse all the entires. */ + crcspeed64little_init(fn, big_table); + for (int k = 0; k < 8; k++) { + for (int n = 0; n < 256; n++) { + big_table[k][n] = rev8(big_table[k][n]); + } + } +} + +void crcspeed16big_init(crcfn16 fn, uint16_t big_table[8][256]) { + /* Create the little endian table then reverse all the entires. */ + crcspeed16little_init(fn, big_table); + for (int k = 0; k < 8; k++) { + for (int n = 0; n < 256; n++) { + big_table[k][n] = rev8(big_table[k][n]); + } + } +} + +/* Calculate a non-inverted CRC multiple bytes at a time on a little-endian + * architecture. If you need inverted CRC, invert *before* calling and invert + * *after* calling. + * 64 bit crc = process 8 bytes at once; + */ +uint64_t crcspeed64little(uint64_t little_table[8][256], uint64_t crc, + void *buf, size_t len) { + unsigned char *next = buf; + + /* process individual bytes until we reach an 8-byte aligned pointer */ + while (len && ((uintptr_t)next & 7) != 0) { + crc = little_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8); + len--; + } + + /* fast middle processing, 8 bytes (aligned!) per loop */ + while (len >= 8) { + crc ^= *(uint64_t *)next; + crc = little_table[7][crc & 0xff] ^ + little_table[6][(crc >> 8) & 0xff] ^ + little_table[5][(crc >> 16) & 0xff] ^ + little_table[4][(crc >> 24) & 0xff] ^ + little_table[3][(crc >> 32) & 0xff] ^ + little_table[2][(crc >> 40) & 0xff] ^ + little_table[1][(crc >> 48) & 0xff] ^ + little_table[0][crc >> 56]; + next += 8; + len -= 8; + } + + /* process remaining bytes (can't be larger than 8) */ + while (len) { + crc = little_table[0][(crc ^ *next++) & 0xff] ^ (crc >> 8); + len--; + } + + return crc; +} + +uint16_t crcspeed16little(uint16_t little_table[8][256], uint16_t crc, + void *buf, size_t len) { + unsigned char *next = buf; + + /* process individual bytes until we reach an 8-byte aligned pointer */ + while (len && ((uintptr_t)next & 7) != 0) { + crc = little_table[0][((crc >> 8) ^ *next++) & 0xff] ^ (crc << 8); + len--; + } + + /* fast middle processing, 8 bytes (aligned!) per loop */ + while (len >= 8) { + uint64_t n = *(uint64_t *)next; + crc = little_table[7][(n & 0xff) ^ ((crc >> 8) & 0xff)] ^ + little_table[6][((n >> 8) & 0xff) ^ (crc & 0xff)] ^ + little_table[5][(n >> 16) & 0xff] ^ + little_table[4][(n >> 24) & 0xff] ^ + little_table[3][(n >> 32) & 0xff] ^ + little_table[2][(n >> 40) & 0xff] ^ + little_table[1][(n >> 48) & 0xff] ^ + little_table[0][n >> 56]; + next += 8; + len -= 8; + } + + /* process remaining bytes (can't be larger than 8) */ + while (len) { + crc = little_table[0][((crc >> 8) ^ *next++) & 0xff] ^ (crc << 8); + len--; + } + + return crc; +} + +/* Calculate a non-inverted CRC eight bytes at a time on a big-endian + * architecture. + */ +uint64_t crcspeed64big(uint64_t big_table[8][256], uint64_t crc, void *buf, + size_t len) { + unsigned char *next = buf; + + crc = rev8(crc); + while (len && ((uintptr_t)next & 7) != 0) { + crc = big_table[0][(crc >> 56) ^ *next++] ^ (crc << 8); + len--; + } + + while (len >= 8) { + crc ^= *(uint64_t *)next; + crc = big_table[0][crc & 0xff] ^ + big_table[1][(crc >> 8) & 0xff] ^ + big_table[2][(crc >> 16) & 0xff] ^ + big_table[3][(crc >> 24) & 0xff] ^ + big_table[4][(crc >> 32) & 0xff] ^ + big_table[5][(crc >> 40) & 0xff] ^ + big_table[6][(crc >> 48) & 0xff] ^ + big_table[7][crc >> 56]; + next += 8; + len -= 8; + } + + while (len) { + crc = big_table[0][(crc >> 56) ^ *next++] ^ (crc << 8); + len--; + } + + return rev8(crc); +} + +/* WARNING: Completely untested on big endian architecture. Possibly broken. */ +uint16_t crcspeed16big(uint16_t big_table[8][256], uint16_t crc_in, void *buf, + size_t len) { + unsigned char *next = buf; + uint64_t crc = crc_in; + + crc = rev8(crc); + while (len && ((uintptr_t)next & 7) != 0) { + crc = big_table[0][((crc >> (56 - 8)) ^ *next++) & 0xff] ^ (crc >> 8); + len--; + } + + while (len >= 8) { + uint64_t n = *(uint64_t *)next; + crc = big_table[0][(n & 0xff) ^ ((crc >> (56 - 8)) & 0xff)] ^ + big_table[1][((n >> 8) & 0xff) ^ (crc & 0xff)] ^ + big_table[2][(n >> 16) & 0xff] ^ + big_table[3][(n >> 24) & 0xff] ^ + big_table[4][(n >> 32) & 0xff] ^ + big_table[5][(n >> 40) & 0xff] ^ + big_table[6][(n >> 48) & 0xff] ^ + big_table[7][n >> 56]; + next += 8; + len -= 8; + } + + while (len) { + crc = big_table[0][((crc >> (56 - 8)) ^ *next++) & 0xff] ^ (crc >> 8); + len--; + } + + return rev8(crc); +} + +/* Return the CRC of buf[0..len-1] with initial crc, processing eight bytes + at a time using passed-in lookup table. + This selects one of two routines depending on the endianess of + the architecture. */ +uint64_t crcspeed64native(uint64_t table[8][256], uint64_t crc, void *buf, + size_t len) { + uint64_t n = 1; + + return *(char *)&n ? crcspeed64little(table, crc, buf, len) + : crcspeed64big(table, crc, buf, len); +} + +uint16_t crcspeed16native(uint16_t table[8][256], uint16_t crc, void *buf, + size_t len) { + uint64_t n = 1; + + return *(char *)&n ? crcspeed16little(table, crc, buf, len) + : crcspeed16big(table, crc, buf, len); +} + +/* Initialize CRC lookup table in architecture-dependent manner. */ +void crcspeed64native_init(crcfn64 fn, uint64_t table[8][256]) { + uint64_t n = 1; + + *(char *)&n ? crcspeed64little_init(fn, table) + : crcspeed64big_init(fn, table); +} + +void crcspeed16native_init(crcfn16 fn, uint16_t table[8][256]) { + uint64_t n = 1; + + *(char *)&n ? crcspeed16little_init(fn, table) + : crcspeed16big_init(fn, table); +} diff --git a/src/crcspeed/crcspeed.h b/src/crcspeed/crcspeed.h new file mode 100644 index 000000000..d7ee95ebb --- /dev/null +++ b/src/crcspeed/crcspeed.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2014, Matt Stancliff + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Redis nor the names of its contributors may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ + +#ifndef CRCSPEED_H +#define CRCSPEED_H + +#include +#include + +typedef uint64_t (*crcfn64)(uint64_t, const void *, const uint64_t); +typedef uint16_t (*crcfn16)(uint16_t, const void *, const uint64_t); + +/* CRC-64 */ +void crcspeed64little_init(crcfn64 fn, uint64_t table[8][256]); +void crcspeed64big_init(crcfn64 fn, uint64_t table[8][256]); +void crcspeed64native_init(crcfn64 fn, uint64_t table[8][256]); + +uint64_t crcspeed64little(uint64_t table[8][256], uint64_t crc, void *buf, + size_t len); +uint64_t crcspeed64big(uint64_t table[8][256], uint64_t crc, void *buf, + size_t len); +uint64_t crcspeed64native(uint64_t table[8][256], uint64_t crc, void *buf, + size_t len); + +/* CRC-16 */ +void crcspeed16little_init(crcfn16 fn, uint16_t table[8][256]); +void crcspeed16big_init(crcfn16 fn, uint16_t table[8][256]); +void crcspeed16native_init(crcfn16 fn, uint16_t table[8][256]); + +uint16_t crcspeed16little(uint16_t table[8][256], uint16_t crc, void *buf, + size_t len); +uint16_t crcspeed16big(uint16_t table[8][256], uint16_t crc, void *buf, + size_t len); +uint16_t crcspeed16native(uint16_t table[8][256], uint16_t crc, void *buf, + size_t len); +#endif diff --git a/src/device.c b/src/device.c index 92cfca8fd..66d74c179 100644 --- a/src/device.c +++ b/src/device.c @@ -21,7 +21,7 @@ void device_add(device_t *d) int c = 0; void *priv; - while (devices[c] != NULL && c < 256) + while ((c < 256) && (devices[c] != NULL)) c++; if (c >= 256) diff --git a/src/disc.c b/src/disc.c index 7d064a7e0..32250b8d5 100644 --- a/src/disc.c +++ b/src/disc.c @@ -14,8 +14,7 @@ #include "fdd.h" #include "timer.h" -int disc_drivesel = 0; -int64_t disc_poll_time = 16; +int64_t disc_poll_time[2] = { 16, 16 }; int disc_track[2]; int writeprot[2], fwriteprot[2]; @@ -40,7 +39,7 @@ int drive_empty[2] = {1, 1}; int disc_changed[2]; int motorspin; -int64_t motoron; +int64_t motoron[2]; int fdc_indexcount = 52; @@ -140,7 +139,6 @@ void disc_close(int drive) drives[drive].comparesector = NULL; drives[drive].readaddress = NULL; drives[drive].format = NULL; - drives[drive].realtrack = NULL; drives[drive].byteperiod = NULL; drives[drive].stop = NULL; } @@ -176,30 +174,30 @@ double disc_byteperiod(int drive) } } -double disc_real_period() +double disc_real_period(int drive) { double ddbp; double dusec; - ddbp = disc_byteperiod(disc_drivesel ^ fdd_swap); + ddbp = disc_byteperiod(drive ^ fdd_swap); dusec = (double) TIMER_USEC; return (ddbp * dusec); } -void disc_poll() +void disc_poll(int drive) { - if (disc_drivesel > 1) + if (drive > 1) { - disc_poll_time += (int64_t) (32.0 * TIMER_USEC); + disc_poll_time[drive] += (int64_t) (32.0 * TIMER_USEC); return; } - disc_poll_time += (int64_t) disc_real_period(); + disc_poll_time[drive] += (int64_t) disc_real_period(drive); - if (drives[disc_drivesel].poll) - drives[disc_drivesel].poll(); + if (drives[drive].poll) + drives[drive].poll(drive); if (disc_notfound) { @@ -209,6 +207,16 @@ void disc_poll() } } +void disc_poll_0() +{ + disc_poll(0); +} + +void disc_poll_1() +{ + disc_poll(1); +} + int disc_get_bitcell_period(int rate) { int bit_rate; @@ -266,7 +274,8 @@ void disc_reset() { curdrive = 0; disc_period = 32; - timer_add(disc_poll, &disc_poll_time, &motoron, NULL); + timer_add(disc_poll_0, &(disc_poll_time[0]), &(motoron[0]), NULL); + timer_add(disc_poll_1, &(disc_poll_time[1]), &(motoron[1]), NULL); } void disc_init() @@ -338,16 +347,6 @@ void disc_format(int drive, int track, int side, int density, uint8_t fill) disc_notfound = 1000; } -int disc_realtrack(int drive, int track) -{ - drive ^= fdd_swap; - - if (drives[drive].realtrack) - return drives[drive].realtrack(drive, track); - else - return track; -} - void disc_stop(int drive) { drive ^= fdd_swap; @@ -355,10 +354,3 @@ void disc_stop(int drive) if (drives[drive].stop) drives[drive].stop(drive); } - -void disc_set_drivesel(int drive) -{ - drive ^= fdd_swap; - - disc_drivesel = drive; -} diff --git a/src/disc.h b/src/disc.h index ef644ce93..274938711 100644 --- a/src/disc.h +++ b/src/disc.h @@ -12,8 +12,7 @@ typedef struct int (*hole)(int drive); double (*byteperiod)(int drive); void (*stop)(int drive); - void (*poll)(); - int (*realtrack)(int drive, int track); + void (*poll)(int drive); } DRIVE; extern DRIVE drives[2]; @@ -25,23 +24,22 @@ void disc_new(int drive, char *fn); void disc_close(int drive); void disc_init(); void disc_reset(); -void disc_poll(); +void disc_poll(int drive); +void disc_poll_0(); +void disc_poll_1(); void disc_seek(int drive, int track); void disc_readsector(int drive, int sector, int track, int side, int density, int sector_size); void disc_writesector(int drive, int sector, int track, int side, int density, int sector_size); void disc_comparesector(int drive, int sector, int track, int side, int density, int sector_size); void disc_readaddress(int drive, int track, int side, int density); void disc_format(int drive, int track, int side, int density, uint8_t fill); -int disc_realtrack(int drive, int track); int disc_hole(int drive); double disc_byteperiod(int drive); void disc_stop(int drive); int disc_empty(int drive); void disc_set_rate(int drive, int drvden, int rate); -void disc_set_drivesel(int drive); extern int disc_time; -extern int64_t disc_poll_time; -extern int disc_drivesel; +extern int64_t disc_poll_time[2]; void fdc_callback(); int fdc_data(uint8_t dat); @@ -59,7 +57,7 @@ extern int fdc_ready; extern int fdc_indexcount;*/ extern int motorspin; -extern int64_t motoron; +extern int64_t motoron[2]; extern int swwp; extern int disable_write; @@ -116,7 +114,7 @@ typedef union { uint8_t bytes[2]; } crc_t; -void disc_calccrc(int drive, uint8_t byte, crc_t *crc_var); +void disc_calccrc(uint8_t byte, crc_t *crc_var); typedef struct { @@ -127,6 +125,11 @@ typedef struct uint8_t (*read_data)(int drive, int side, uint16_t pos); void (*write_data)(int drive, int side, uint16_t pos, uint8_t data); int (*format_conditions)(int drive); + int32_t (*extra_bit_cells)(int drive); + uint16_t* (*encoded_data)(int drive, int side); + void (*read_revolution)(int drive); + uint32_t (*index_hole_pos)(int drive, int side); + uint32_t (*get_raw_size)(int drive); uint8_t check_crc; } d86f_handler_t; @@ -136,19 +139,17 @@ void d86f_common_handlers(int drive); int d86f_is_40_track(int drive); -uint8_t* d86f_track_data(int drive, int side); -uint8_t* d86f_track_layout(int drive, int side); +void d86f_reset_index_hole_pos(int drive, int side); -uint16_t d86f_prepare_pretrack(int drive, int side, int iso, int write_data); -uint16_t d86f_prepare_sector(int drive, int side, int pos, uint8_t *id_buf, uint8_t *data_buf, int data_len, int write_data, int gap2, int gap3, int limit, int deleted, int bad_crc); +uint16_t d86f_prepare_pretrack(int drive, int side, int iso); +uint16_t d86f_prepare_sector(int drive, int side, int prev_pos, uint8_t *id_buf, uint8_t *data_buf, int data_len, int gap2, int gap3, int deleted, int bad_crc); int gap3_sizes[5][8][256]; void null_writeback(int drive); -void null_poll_write_data(int drive, int side, uint16_t pos, uint8_t data); +void null_write_data(int drive, int side, uint16_t pos, uint8_t data); int null_format_conditions(int drive); void d86f_unregister(int drive); -void d86f_reset_index_hole_pos(int drive, int side); uint8_t dmf_r[21]; uint8_t xdf_physical_sectors[2][2]; @@ -173,3 +174,13 @@ xdf_sector_t xdf_disk_layout[2][2][38]; uint32_t td0_get_raw_tsize(int side_flags, int slower_rpm); void d86f_set_track_pos(int drive, uint32_t track_pos); + +int32_t null_extra_bit_cells(int drive); +uint16_t* common_encoded_data(int drive, int side); + +void common_read_revolution(int drive); +void null_set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n); + +uint32_t null_index_hole_pos(int drive, int side); + +uint32_t common_get_raw_size(int drive); diff --git a/src/disc_86f.c b/src/disc_86f.c index beed65d37..e329d07f9 100644 --- a/src/disc_86f.c +++ b/src/disc_86f.c @@ -1,45 +1,132 @@ -/* Copyright holders: Tenshi - see COPYING for more details -*/ -#include "ibm.h" +#include +#include +#include +#include +#include + +#include "crcspeed/crc64speed.h" +//#include "zlib.h" +#include "lzf/lzf.h" + +#include "config.h" #include "disc.h" #include "disc_86f.h" #include "disc_random.h" #include "fdc.h" #include "fdd.h" +#include "ibm.h" -#define MAX_SECTORS 256 +#define CHUNK 16384 +uint64_t poly = 0x42F0E1EBA9EA3693; /* ECMA normal */ + +uint64_t table[256]; + +/* Let's give this some more logic: + Bits 4,3 = Read/write (0 = read, 1 = write, 2 = scan, 3 = verify) + Bits 6,5 = Sector/track (0 = ID, 1 = sector, 2 = deleted sector, 3 = track) + Bit 7 = State type (0 = idle states, 1 = active states) +*/ enum { - STATE_IDLE, - STATE_READ_FIND_SECTOR, - STATE_READ_SECTOR, - STATE_READ_SECTOR_CRC, - STATE_READ_SECTOR_GAP3, - STATE_READ_FIND_FIRST_SECTOR, - STATE_READ_FIRST_SECTOR, - STATE_READ_FIRST_SECTOR_CRC, - STATE_READ_FIRST_SECTOR_GAP3, - STATE_READ_FIND_NEXT_SECTOR, - STATE_READ_NEXT_SECTOR, - STATE_READ_NEXT_SECTOR_CRC, - STATE_READ_NEXT_SECTOR_GAP3, - STATE_WRITE_FIND_SECTOR, - STATE_WRITE_SECTOR, - STATE_WRITE_SECTOR_CRC, - STATE_WRITE_SECTOR_GAP3, - STATE_COMPARE_FIND_SECTOR, - STATE_COMPARE_SECTOR, - STATE_COMPARE_SECTOR_CRC, - STATE_COMPARE_SECTOR_GAP3, - STATE_READ_FIND_ADDRESS, - STATE_READ_ADDRESS, - STATE_FORMAT_FIND, - STATE_FORMAT, - STATE_SEEK, + /* 0 ?? ?? ??? */ + STATE_IDLE = 0x00, + STATE_SECTOR_NOT_FOUND, + + /* 1 00 00 ??? */ + STATE_0A_FIND_ID = 0x80, /* READ SECTOR ID */ + STATE_0A_READ_ID, + + /* 1 01 00 ??? */ + STATE_06_FIND_ID = 0xA0, /* READ DATA */ + STATE_06_READ_ID, + STATE_06_FIND_DATA, + STATE_06_READ_DATA, + + /* 1 01 01 ??? */ + STATE_05_FIND_ID = 0xA8, /* WRITE DATA */ + STATE_05_READ_ID, + STATE_05_FIND_DATA, + STATE_05_WRITE_DATA, + + /* 1 01 10 ??? */ + STATE_11_FIND_ID = 0xB0, /* SCAN EQUAL, SCAN LOW OR EQUAL, SCAN HIGH OR EQUAL */ + STATE_11_READ_ID, + STATE_11_FIND_DATA, + STATE_11_SCAN_DATA, + + /* 1 01 11 ??? */ + STATE_16_FIND_ID = 0xB8, /* VERIFY */ + STATE_16_READ_ID, + STATE_16_FIND_DATA, + STATE_16_VERIFY_DATA, + + /* 1 10 00 ??? */ + STATE_0C_FIND_ID = 0xC0, /* READ DELETED DATA */ + STATE_0C_READ_ID, + STATE_0C_FIND_DATA, + STATE_0C_READ_DATA, + + /* 1 10 01 ??? */ + STATE_09_FIND_ID = 0xC8, /* WRITE DELETED DATA */ + STATE_09_READ_ID, + STATE_09_FIND_DATA, + STATE_09_WRITE_DATA, + + /* 1 11 00 ??? */ + STATE_02_SPIN_TO_INDEX = 0xE0, /* READ TRACK */ + STATE_02_FIND_ID, + STATE_02_READ_ID, + STATE_02_FIND_DATA, + STATE_02_READ_DATA, + + /* 1 11 01 ??? */ + STATE_0D_SPIN_TO_INDEX = 0xE8, /* FORMAT TRACK */ + STATE_0D_FORMAT_TRACK }; +static uint16_t CRCTable[256]; + +typedef struct +{ + uint8_t c; + uint8_t h; + uint8_t r; + uint8_t n; +} sector_id_fields_t; + +typedef union +{ + uint32_t dword; + uint8_t byte_array[4]; + sector_id_fields_t id; +} sector_id_t; + +typedef struct __attribute__((packed)) +{ + uint8_t buffer[10]; + uint32_t pos; + uint32_t len; +} sliding_buffer_t; + +typedef struct __attribute__((packed)) +{ + uint32_t sync_marks; + uint32_t bits_obtained; + uint32_t bytes_obtained; + uint32_t sync_pos; +} find_t; + +uint8_t encoded_fm[64] = { 0xAA, 0xAB, 0xAE, 0xAF, 0xBA, 0xBB, 0xBE, 0xBF, 0xEA, 0xEB, 0xEE, 0xEF, 0xFA, 0xFB, 0xFE, 0xFF, + 0xAA, 0xAB, 0xAE, 0xAF, 0xBA, 0xBB, 0xBE, 0xBF, 0xEA, 0xEB, 0xEE, 0xEF, 0xFA, 0xFB, 0xFE, 0xFF, + 0xAA, 0xAB, 0xAE, 0xAF, 0xBA, 0xBB, 0xBE, 0xBF, 0xEA, 0xEB, 0xEE, 0xEF, 0xFA, 0xFB, 0xFE, 0xFF, + 0xAA, 0xAB, 0xAE, 0xAF, 0xBA, 0xBB, 0xBE, 0xBF, 0xEA, 0xEB, 0xEE, 0xEF, 0xFA, 0xFB, 0xFE, 0xFF }; + +uint8_t encoded_mfm[64] = { 0xAA, 0xA9, 0xA4, 0xA5, 0x92, 0x91, 0x94, 0x95, 0x4A, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55, + 0x2A, 0x29, 0x24, 0x25, 0x12, 0x11, 0x14, 0x15, 0x4A, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55, + 0xAA, 0xA9, 0xA4, 0xA5, 0x92, 0x91, 0x94, 0x95, 0x4A, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55, + 0x2A, 0x29, 0x24, 0x25, 0x12, 0x11, 0x14, 0x15, 0x4A, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55 }; + enum { FMT_PRETRK_GAP0, @@ -62,40 +149,43 @@ enum FMT_POSTTRK_GAP4, }; -static uint16_t CRCTable[256]; - -static int d86f_drive; - -typedef struct +typedef struct __attribute__((packed)) { - uint8_t c; - uint8_t h; - uint8_t r; - uint8_t n; -} sector_id_fields_t; + unsigned nibble0 :4; + unsigned nibble1 :4; +} split_byte_t; -typedef union -{ - uint32_t dword; - uint8_t byte_array[4]; - sector_id_fields_t id; -} sector_id_t; +typedef union { + uint8_t byte; + split_byte_t nibbles; +} decoded_t; -static struct +/* Disk flags: Bit 0 Has surface data (1 = yes, 0 = no) + Bits 2, 1 Hole (3 = ED + 2000 kbps, 2 = ED, 1 = HD, 0 = DD) + Bit 3 Sides (1 = 2 sides, 0 = 1 side) + Bit 4 Write protect (1 = yes, 0 = no) + Bits 6, 5 RPM slowdown (3 = 2%, 2 = 1.5%, 1 = 1%, 0 = 0%) + Bit 7 Bitcell mode (1 = Extra bitcells count specified after disk flags, 0 = No extra bitcells) + The maximum number of extra bitcells is 1024 (which after decoding translates to 64 bytes) + Bit 8 Disk type (1 = Zoned, 0 = Fixed RPM) + Bits 10, 9 Zone type (3 = Commodore 64 zoned, 2 = Apple zoned, 1 = Pre-Apple zoned #2, 0 = Pre-Apple zoned #1) + Bit 11 Data and surface bits are stored in reverse byte endianness */ + +static struct __attribute__((packed)) { FILE *f; uint16_t version; uint16_t disk_flags; - uint8_t track_data[2][51000]; - uint16_t track_encoded_data[2][51000]; - uint8_t track_layout[2][51000]; + int16_t extra_bit_cells; + uint16_t track_encoded_data[2][53048]; + uint16_t track_surface_data[2][53048]; + uint16_t thin_track_encoded_data[2][2][53048]; + uint16_t thin_track_surface_data[2][2][53048]; uint16_t side_flags[2]; - uint16_t index_hole_pos[2]; - uint8_t track_in_file; + uint32_t index_hole_pos[2]; uint32_t track_offset[256]; uint32_t file_size; sector_id_t format_sector_id; - sector_id_t rw_sector_id; sector_id_t last_sector; sector_id_t req_sector; uint32_t index_count; @@ -104,216 +194,209 @@ static struct uint32_t track_pos; uint32_t datac; uint32_t id_pos; - uint32_t section_pos; + uint16_t last_word[2]; + find_t id_find; + find_t data_find; crc_t calc_crc; crc_t track_crc; - uint8_t track_byte; - uint8_t track_index; - uint8_t track_is_hole; - uint8_t track_fuzzy; - uint8_t track_data_byte; - uint16_t track_data_word; - uint8_t old_track_byte; - uint8_t old_track_index; - uint8_t old_track_is_hole; - uint8_t old_track_fuzzy; - uint8_t old_track_data_byte; - uint16_t old_track_data_word; - uint8_t cur_track; - uint8_t side_flag_bytes; - uint8_t id_am_counter; - uint8_t id_counter; - uint8_t id_match; - uint8_t data_am_counter; - uint8_t am_sync_counter; - uint8_t am_sync_valid; - uint8_t idam_found; - uint8_t id_was_read; - uint8_t id_read_state; uint8_t sector_count; uint8_t format_state; uint16_t satisfying_bytes; + uint16_t preceding_bit[2]; + uint16_t current_byte[2]; + uint16_t current_bit[2]; + int cur_track; + uint32_t error_condition; + int is_compressed; + uint8_t original_file_name[2048]; + uint8_t *filebuf; + uint8_t *outbuf; } d86f[2]; -uint8_t encoded_fm[64] = { 0xAA, 0xAB, 0xAE, 0xAF, 0xBA, 0xBB, 0xBE, 0xBF, 0xEA, 0xEB, 0xEE, 0xEF, 0xFA, 0xFB, 0xFE, 0xFF, - 0xAA, 0xAB, 0xAE, 0xAF, 0xBA, 0xBB, 0xBE, 0xBF, 0xEA, 0xEB, 0xEE, 0xEF, 0xFA, 0xFB, 0xFE, 0xFF, - 0xAA, 0xAB, 0xAE, 0xAF, 0xBA, 0xBB, 0xBE, 0xBF, 0xEA, 0xEB, 0xEE, 0xEF, 0xFA, 0xFB, 0xFE, 0xFF, - 0xAA, 0xAB, 0xAE, 0xAF, 0xBA, 0xBB, 0xBE, 0xBF, 0xEA, 0xEB, 0xEE, 0xEF, 0xFA, 0xFB, 0xFE, 0xFF }; - -uint8_t encoded_mfm[64] = { 0xAA, 0xA9, 0xA4, 0xA5, 0x92, 0x91, 0x94, 0x95, 0x4A, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55, - 0x2A, 0x29, 0x24, 0x25, 0x12, 0x11, 0x14, 0x15, 0x4A, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55, - 0xAA, 0xA9, 0xA4, 0xA5, 0x92, 0x91, 0x94, 0x95, 0x4A, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55, - 0x2A, 0x29, 0x24, 0x25, 0x12, 0x11, 0x14, 0x15, 0x4A, 0x49, 0x44, 0x45, 0x52, 0x51, 0x54, 0x55 }; - -typedef union { - uint16_t word; - uint8_t bytes[2]; -} encoded_t; - -typedef struct { - unsigned nibble0 :4; - unsigned nibble1 :4; -} split_byte_t; - -typedef struct { - unsigned area0 :2; - unsigned area1 :6; -} preceding_byte_t; - -typedef union { - uint8_t byte; - split_byte_t nibbles; - preceding_byte_t p; -} decoded_t; - -static void d86f_new_style_reset(int drive) +#ifdef OLD_COMPRESS +/* Compress from file source to file dest until EOF on source. + def() returns Z_OK on success, Z_MEM_ERROR if memory could not be + allocated for processing, Z_STREAM_ERROR if an invalid compression + level is supplied, Z_VERSION_ERROR if the version of zlib.h and the + version of the library linked do not match, or Z_ERRNO if there is + an error reading or writing the files. */ +int def(FILE *source, FILE *dest, int level) { - d86f[drive].id_am_counter = 0; - d86f[drive].id_counter = 0; - d86f[drive].id_match = 0; - d86f[drive].data_am_counter = 0; - d86f[drive].am_sync_counter = 0; - d86f[drive].am_sync_valid = 0; - d86f[drive].idam_found = 0; - d86f[drive].id_was_read = 0; - d86f[drive].id_read_state = 0; - d86f[drive].sector_count = 0; - d86f[drive].format_state = 0; + int ret, flush; + unsigned have; + z_stream strm; + unsigned char in[CHUNK]; + unsigned char out[CHUNK]; + + /* allocate deflate state */ + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + ret = deflateInit(&strm, level); + if (ret != Z_OK) + return ret; + + /* compress until end of file */ + do { + strm.avail_in = fread(in, 1, CHUNK, source); + if (ferror(source)) { + (void)deflateEnd(&strm); + return Z_ERRNO; + } + flush = feof(source) ? Z_FINISH : Z_NO_FLUSH; + strm.next_in = in; + + /* run deflate() on input until output buffer not full, finish + compression if all of source has been read in */ + do { + strm.avail_out = CHUNK; + strm.next_out = out; + ret = deflate(&strm, flush); /* no bad return value */ + assert(ret != Z_STREAM_ERROR); /* state not clobbered */ + have = CHUNK - strm.avail_out; + if (fwrite(out, 1, have, dest) != have || ferror(dest)) { + (void)deflateEnd(&strm); + return Z_ERRNO; + } + } while (strm.avail_out == 0); + assert(strm.avail_in == 0); /* all input will be used */ + + /* done when last data in file processed */ + } while (flush != Z_FINISH); + assert(ret == Z_STREAM_END); /* stream will be complete */ + + /* clean up and return */ + (void)deflateEnd(&strm); + return Z_OK; } -static uint16_t d86f_encode_get_data(uint8_t dat) +/* Decompress from file source to file dest until stream ends or EOF. + inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be + allocated for processing, Z_DATA_ERROR if the deflate data is + invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and + the version of the library linked do not match, or Z_ERRNO if there + is an error reading or writing the files. */ +int inf(FILE *source, FILE *dest) { - uint16_t temp; - temp = 0; - if (dat & 0x01) temp |= 256; - if (dat & 0x02) temp |= 1024; - if (dat & 0x04) temp |= 4096; - if (dat & 0x08) temp |= 16384; - if (dat & 0x10) temp |= 1; - if (dat & 0x20) temp |= 4; - if (dat & 0x40) temp |= 16; - if (dat & 0x80) temp |= 64; - return temp; + int ret; + unsigned have; + z_stream strm; + unsigned char in[CHUNK]; + unsigned char out[CHUNK]; + + /* allocate inflate state */ + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + strm.avail_in = 0; + strm.next_in = Z_NULL; + ret = inflateInit(&strm); + if (ret != Z_OK) + return ret; + + /* decompress until deflate stream ends or end of file */ + do { + strm.avail_in = fread(in, 1, CHUNK, source); + if (ferror(source)) { + (void)inflateEnd(&strm); + return Z_ERRNO; + } + if (strm.avail_in == 0) + break; + strm.next_in = in; + + /* run inflate() on input until output buffer not full */ + do { + strm.avail_out = CHUNK; + strm.next_out = out; + ret = inflate(&strm, Z_NO_FLUSH); + assert(ret != Z_STREAM_ERROR); /* state not clobbered */ + switch (ret) { + case Z_NEED_DICT: + ret = Z_DATA_ERROR; /* and fall through */ + case Z_DATA_ERROR: + case Z_MEM_ERROR: + (void)inflateEnd(&strm); + return ret; + } + have = CHUNK - strm.avail_out; + if (fwrite(out, 1, have, dest) != have || ferror(dest)) { + (void)inflateEnd(&strm); + return Z_ERRNO; + } + } while (strm.avail_out == 0); + + /* done when inflate() says it's done */ + } while (ret != Z_STREAM_END); + + /* clean up and return */ + (void)inflateEnd(&strm); + return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; } -static uint16_t d86f_encode_get_clock(uint8_t dat) +/* compress or decompress */ +int d86f_zlib(FILE *dst, FILE *src, int dir) { - uint16_t temp; - temp = 0; - if (dat & 0x01) temp |= 512; - if (dat & 0x02) temp |= 2048; - if (dat & 0x04) temp |= 8192; - if (dat & 0x08) temp |= 32768; - if (dat & 0x10) temp |= 2; - if (dat & 0x20) temp |= 8; - if (dat & 0x40) temp |= 32; - if (dat & 0x80) temp |= 128; - return temp; + int ret; + + /* do compression if no arguments */ + if (!dir) { + ret = def(src, dst, Z_DEFAULT_COMPRESSION); + if (ret != Z_OK) + return 0; + return 1; + } + + /* do decompression if -d specified */ + else if (dir) { + ret = inf(src, dst); + if (ret != Z_OK) + return 0; + return 1; + } +} +#endif + +#ifdef OLD_CRC +void d86f_generate_table64() +{ + for(int i=0; i<256; ++i) + { + uint64_t crc = i; + + for(unsigned int j=0; j<8; ++j) + { + // is current coefficient set? + if(crc & 1) + { + // yes, then assume it gets zero'd (by implied x^64 coefficient of dividend) + crc >>= 1; + + // and add rest of the divisor + crc ^= poly; + } + else + { + // no? then move to next coefficient + crc >>= 1; + } + } + + table[i] = crc; + } } -uint8_t* d86f_track_data(int drive, int side) +void d86f_calccrc64(uint8_t b, uint64_t *crc) { - return d86f[drive].track_data[side]; + uint8_t index = b ^ *crc; + uint64_t lookup = table[index]; + + *crc >>= 8; + *crc ^= lookup; } +#endif -uint8_t* d86f_track_layout(int drive, int side) -{ - return d86f[drive].track_layout[side]; -} - -uint16_t d86f_side_flags(int drive); -int d86f_is_mfm(int drive); -void d86f_writeback(int drive); -void d86f_set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n); -uint8_t d86f_poll_read_data(int drive, int side, uint16_t pos); -void d86f_poll_write_data(int drive, int side, uint16_t pos, uint8_t data); -int d86f_format_conditions(int drive); - -uint16_t d86f_disk_flags(int drive) -{ - return d86f[drive].disk_flags; -} - -uint16_t null_disk_flags(int drive) -{ - return 0x09; -} - -uint16_t null_side_flags(int drive) -{ - return 0x0A; -} - -void null_writeback(int drive) -{ - return; -} - -void null_set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) -{ - return; -} - -uint8_t null_poll_read_data(int drive, int side, uint16_t pos) -{ - return 0xf6; -} - -void null_poll_write_data(int drive, int side, uint16_t pos, uint8_t data) -{ - return; -} - -int null_format_conditions(int drive) -{ - return 0; -} - -void d86f_unregister(int drive) -{ - d86f_handler[drive].disk_flags = null_disk_flags; - d86f_handler[drive].side_flags = null_side_flags; - d86f_handler[drive].writeback = null_writeback; - d86f_handler[drive].set_sector = null_set_sector; - d86f_handler[drive].read_data = null_poll_read_data; - d86f_handler[drive].write_data = null_poll_write_data; - d86f_handler[drive].format_conditions = null_format_conditions; - d86f_handler[drive].check_crc = 0; - d86f[drive].version = 0x0063; /* Proxied formats report as version 0.99. */ -} - -void d86f_register_86f(int drive) -{ - d86f_handler[drive].disk_flags = d86f_disk_flags; - d86f_handler[drive].side_flags = d86f_side_flags; - d86f_handler[drive].writeback = d86f_writeback; - d86f_handler[drive].set_sector = d86f_set_sector; - d86f_handler[drive].read_data = d86f_poll_read_data; - d86f_handler[drive].write_data = d86f_poll_write_data; - d86f_handler[drive].format_conditions = d86f_format_conditions; - d86f_handler[drive].check_crc = 1; -} - -void d86f_set_track_pos(int drive, uint32_t track_pos) -{ - d86f[drive].track_pos = track_pos; -} - -/* Needed for formatting! */ -int d86f_is_40_track(int drive) -{ - return (d86f_handler[drive].disk_flags(drive) & 1) ? 0 : 1; -} - -int d86f_realtrack(int drive, int track) -{ - if (d86f_is_40_track(drive) && fdd_doublestep_40(drive)) - track /= 2; - - return track; -} - -static void d86f_setupcrc(uint16_t poly, uint16_t rvalue) +static void d86f_setupcrc(uint16_t poly) { int c = 256, bc; uint16_t crctemp; @@ -339,365 +422,97 @@ static void d86f_setupcrc(uint16_t poly, uint16_t rvalue) } } -void disc_calccrc(int drive, uint8_t byte, crc_t *crc_var) +static int d86f_has_surface_desc(int drive) { - crc_var->word = (crc_var->word << 8) ^ CRCTable[(crc_var->word >> 8)^byte]; -} - -static void d86f_calccrc(int drive, uint8_t byte) -{ - // d86f[drive].calc_crc.word = (d86f[drive].calc_crc.word << 8) ^ CRCTable[(d86f[drive].calc_crc.word >> 8)^byte]; - disc_calccrc(drive, byte, &(d86f[drive].calc_crc)); -} - -void d86f_init() -{ - disc_random_init(); - - memset(d86f, 0, sizeof(d86f)); - d86f_setupcrc(0x1021, 0xcdb4); - - // d86f_unregister(0); - // d86f_unregister(1); + return (d86f_handler[drive].disk_flags(drive) & 1); } int d86f_get_sides(int drive) { - return (d86f_handler[drive].disk_flags(drive) & 8) ? 2 : 1; + return ((d86f_handler[drive].disk_flags(drive) >> 3) & 1) + 1; } int d86f_get_rpm_mode(int drive) { - if (d86f[drive].version != 0x0132) return 0; return (d86f_handler[drive].disk_flags(drive) & 0x60) >> 5; } -int d86f_get_array_size(int drive) +int d86f_reverse_bytes(int drive) { - int pos = 0; - int rm = 0; - rm = d86f_get_rpm_mode(drive); - switch (d86f_hole(drive)) - { - case 0: - default: - pos = 7500; - if (d86f[drive].version != 0x0132) return pos; - switch (rm) - { - case 1: - pos = 7575; - break; - case 2: - pos = 7612; - break; - case 3: - pos = 7650; - break; - default: - pos = 7500; - break; - } - break; - case 1: - pos = 12500; - if (d86f[drive].version != 0x0132) return pos; - switch (rm) - { - case 1: - pos = 12625; - break; - case 2: - pos = 12687; - break; - case 3: - pos = 12750; - break; - default: - pos = 12500; - break; - } - break; - case 2: - pos = 50000; - if (d86f[drive].version != 0x0132) return pos; - switch (rm) - { - case 1: - pos = 50500; - break; - case 2: - pos = 50750; - break; - case 3: - pos = 51000; - break; - default: - pos = 50000; - break; - } - break; - } - return pos; + return (d86f_handler[drive].disk_flags(drive) & 0x800) >> 11; } -int d86f_get_mini_size(int drive) +uint16_t d86f_side_flags(int drive); +int d86f_is_mfm(int drive); +void d86f_writeback(int drive); +uint8_t d86f_poll_read_data(int drive, int side, uint16_t pos); +void d86f_poll_write_data(int drive, int side, uint16_t pos, uint8_t data); +int d86f_format_conditions(int drive); + +uint16_t d86f_disk_flags(int drive) { - int pos = 0; - int rm = 0; - rm = d86f_get_rpm_mode(drive); - switch (d86f_hole(drive)) - { - case 0: - default: - switch (rm) - { - case 1: - pos = 1894; - break; - case 2: - pos = 1904; - break; - case 3: - pos = 1913; - break; - default: - pos = 1875; - break; - } - break; - case 1: - switch (rm) - { - case 1: - pos = 3157; - break; - case 2: - pos = 3172; - break; - case 3: - pos = 3188; - break; - default: - pos = 3125; - break; - } - break; - case 2: - pos = 50000; - if (d86f[drive].version != 0x0132) return pos; - switch (rm) - { - case 1: - pos = 12625; - break; - case 2: - pos = 12688; - break; - case 3: - pos = 12750; - break; - default: - pos = 12500; - break; - } - break; - } - return pos; + return d86f[drive].disk_flags; } -void d86f_mini_pos(int drive, uint32_t *pos, uint32_t *bit) + +uint32_t d86f_index_hole_pos(int drive, int side) { - uint32_t i, j, k; - i = d86f[drive].track_pos; - j = i >> 2; - k = (i & 3) << 1; - *pos = j; - *bit = k; + return d86f[drive].index_hole_pos[side]; } -int d86f_valid_bit_rate(int drive) +uint32_t null_index_hole_pos(int drive, int side) { - int rate = 0; - rate = fdc_get_bit_rate(); - switch (d86f_hole(drive)) - { - case 0: /* DD */ - if ((rate < 1) || (rate > 2)) return 0; - return 1; - case 1: /* HD */ - if (rate != 0) return 0; - return 1; - case 2: /* ED */ - if (rate < 3) return 0; - return 1; - } - return 1; + return 0; } -void d86f_common_handlers(int drive) +uint16_t null_disk_flags(int drive) { - drives[drive].readsector = d86f_readsector; - drives[drive].writesector = d86f_writesector; - drives[drive].comparesector=d86f_comparesector; - drives[drive].readaddress = d86f_readaddress; - drives[drive].hole = d86f_hole; - drives[drive].byteperiod = d86f_byteperiod; - drives[drive].poll = d86f_poll; - drives[drive].format = d86f_format; - drives[drive].realtrack = d86f_realtrack; - drives[drive].stop = d86f_stop; + return 0x09; } -int d86f_has_mini_table(int drive) +uint16_t null_side_flags(int drive) { - return ((d86f_handler[drive].disk_flags(drive) >> 7) & 3) == 2; + return 0x0A; } -int d86f_is_old_style(int drive) +void null_writeback(int drive) { - return ((d86f_handler[drive].disk_flags(drive) >> 7) & 3) < 2; + return; } -int d86f_is_encoded(int drive) +void null_set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) { - return ((d86f_handler[drive].disk_flags(drive) >> 7) & 3) > 0; + return; } -void d86f_load(int drive, char *fn) +void null_write_data(int drive, int side, uint16_t pos, uint8_t data) { - uint32_t magic = 0; - uint32_t len = 0; - - int i = 0; - int j = 0; - - uint8_t temp = 0; - - d86f_unregister(drive); - - writeprot[drive] = 0; - d86f[drive].f = fopen(fn, "rb+"); - if (!d86f[drive].f) - { - d86f[drive].f = fopen(fn, "rb"); - if (!d86f[drive].f) - return; - writeprot[drive] = 1; - } - if (ui_writeprot[drive]) - { - writeprot[drive] = 1; - } - fwriteprot[drive] = writeprot[drive]; - - fseek(d86f[drive].f, 0, SEEK_END); - len = ftell(d86f[drive].f); - fseek(d86f[drive].f, 0, SEEK_SET); - - if (len < 52056) - { - /* File too small, abort. */ - fclose(d86f[drive].f); - return; - } - - fread(&magic, 4, 1, d86f[drive].f); - - if (magic != 0x46423638) - { - /* File is not of the valid format, abort. */ - pclog("86F: Unrecognized magic bytes: %08X\n", magic); - fclose(d86f[drive].f); - return; - } - - fread(&(d86f[drive].version), 2, 1, d86f[drive].f); - - if (d86f[drive].version != 0x0132) - { - /* File is not of a recognized format version abort. */ - if (d86f[drive].version == 0x0063) - { - pclog("86F: File has emulator-internal version 0.99, this version is not valid in a file\n"); - } - else if ((d86f[drive].version >= 0x0100) && (d86f[drive].version < 0x0132)) - { - pclog("86F: No longer supported development file version: %i.%02i\n", d86f[drive].version >> 8, d86f[drive].version & 0xFF); - } - else - { - pclog("86F: Unrecognized file version: %i.%02i\n", d86f[drive].version >> 8, d86f[drive].version & 0xFF); - } - fclose(d86f[drive].f); - return; - } - else - { - pclog("86F: Recognized file version: %i.%02i\n", d86f[drive].version >> 8, d86f[drive].version & 0xFF); - } - - fread(&(d86f[drive].disk_flags), 2, 1, d86f[drive].f); - - if (((d86f[drive].disk_flags >> 1) & 3) == 3) - { - /* Invalid disk hole. */ - pclog("86F: Unrecognized disk hole type 3\n"); - fclose(d86f[drive].f); - return; - } - - if (d86f[drive].disk_flags & 0x200) - { - /* Zoned disk. */ - pclog("86F: Disk is zoned (Apple or Sony)\n"); - fclose(d86f[drive].f); - return; - } - - if (!writeprot[drive]) - { - writeprot[drive] = (d86f[drive].disk_flags & 0x10) ? 1 : 0; - fwriteprot[drive] = writeprot[drive]; - } - - fread(d86f[drive].track_offset, 1, 1024, d86f[drive].f); - - if (!(d86f[drive].track_offset[0])) - { - /* File has no track 0, abort. */ - pclog("86F: No Track 0\n"); - fclose(d86f[drive].f); - return; - } - - /* Load track 0 flags as default. */ - d86f[drive].side_flag_bytes = d86f_get_sides(drive); - - fseek(d86f[drive].f, d86f[drive].track_offset[0], SEEK_SET); - d86f[drive].side_flags[0] = d86f[drive].side_flags[1] = 0; - fread(&(d86f[drive].side_flags[0]), 2, 1, d86f[drive].f); - if (d86f_get_sides(drive) == 2) - { - fread(&(d86f[drive].side_flags[1]), 2, 1, d86f[drive].f); - } - - fseek(d86f[drive].f, 0, SEEK_END); - d86f[drive].file_size = ftell(d86f[drive].f); - - fseek(d86f[drive].f, 0, SEEK_SET); - - d86f_register_86f(drive); - - drives[drive].seek = d86f_seek; - d86f_common_handlers(drive); - - pclog("86F: Disk format is %s style and it %s a mini track layout table\n", d86f_is_old_style(drive) ? "old" : "new", d86f_has_mini_table(drive) ? "has" : "does not have"); + return; } -int d86f_hole(int drive) +int null_format_conditions(int drive) { - return (d86f_handler[drive].disk_flags(drive) >> 1) & 3; + return 0; +} + +int32_t d86f_extra_bit_cells(int drive) +{ + return d86f[drive].extra_bit_cells; +} + +int32_t null_extra_bit_cells(int drive) +{ + return 0; +} + +uint16_t* common_encoded_data(int drive, int side) +{ + return d86f[drive].track_encoded_data[side]; +} + +void common_read_revolution(int drive) +{ + return; } uint16_t d86f_side_flags(int drive) @@ -742,72 +557,32 @@ uint16_t d86f_track_flags(int drive) return tf; } -double d86f_byteperiod(int drive) -{ - switch (d86f_track_flags(drive) & 0x0f) - { - case 0x02: /* 125 kbps, FM */ - return 64.0; - case 0x01: /* 150 kbps, FM */ - return 320.0 / 6.0; - case 0x0A: /* 250 kbps, MFM */ - case 0x00: /* 250 kbps, FM */ - return 32.0; - case 0x09: /* 300 kbps, MFM */ - return 160.0 / 6.0; - case 0x08: /* 500 kbps, MFM */ - return 16.0; - case 0x0B: /* 1000 kbps, MFM */ - return 8.0; - case 0x0D: /* 2000 kbps, MFM */ - return 4.0; - default: - return 32.0; - } - return 32.0; -} - -void d86f_close(int drive) -{ - if (d86f[drive].f) - fclose(d86f[drive].f); - d86f[drive].f = NULL; -} - -int d86f_is_mfm(int drive) -{ - return (d86f_track_flags(drive) & 8) ? 1 : 0; -} - -uint32_t d86f_get_raw_size(int drive) +uint32_t common_get_raw_size(int drive) { double rate = 0.0; int mfm = 0; - double rpm = 300.0; + double rpm; double rpm_diff = 0.0; - double size = 6250.0; + double size = 100000.0; mfm = d86f_is_mfm(drive); rpm = ((d86f_track_flags(drive) & 0xE0) == 0x20) ? 360.0 : 300.0; rpm_diff = 1.0; - if (d86f[drive].version == 0x0132) + switch (d86f_get_rpm_mode(drive)) { - switch (d86f_get_rpm_mode(drive)) - { - case 1: - rpm_diff = 1.01; - break; - case 2: - rpm_diff = 1.015; - break; - case 3: - rpm_diff = 1.02; - break; - default: - rpm_diff = 1.0; - break; - } + case 1: + rpm_diff = 1.01; + break; + case 2: + rpm_diff = 1.015; + break; + case 3: + rpm_diff = 1.02; + break; + default: + rpm_diff = 1.0; + break; } switch (d86f_track_flags(drive) & 7) { @@ -834,159 +609,303 @@ uint32_t d86f_get_raw_size(int drive) size = (size / 250.0) * rate; size = (size * 300.0) / rpm; size *= rpm_diff; - return (uint16_t) size; + /* Round down to a multiple of 16 and add the extra bit cells, then return. */ + return ((((uint32_t) size) >> 4) << 4) + d86f_handler[drive].extra_bit_cells(drive); } -void d86f_seek(int drive, int track) +void d86f_unregister(int drive) { - uint8_t track_id = track; - int sides; - int side; - sides = d86f_get_sides(drive); + d86f_handler[drive].disk_flags = null_disk_flags; + d86f_handler[drive].side_flags = null_side_flags; + d86f_handler[drive].writeback = null_writeback; + d86f_handler[drive].set_sector = null_set_sector; + d86f_handler[drive].write_data = null_write_data; + d86f_handler[drive].format_conditions = null_format_conditions; + d86f_handler[drive].extra_bit_cells = null_extra_bit_cells; + d86f_handler[drive].encoded_data = common_encoded_data; + d86f_handler[drive].read_revolution = common_read_revolution; + d86f_handler[drive].index_hole_pos = null_index_hole_pos; + d86f_handler[drive].get_raw_size = common_get_raw_size; + d86f_handler[drive].check_crc = 0; + d86f[drive].version = 0x0063; /* Proxied formats report as version 0.99. */ +} +void d86f_register_86f(int drive) +{ + d86f_handler[drive].disk_flags = d86f_disk_flags; + d86f_handler[drive].side_flags = d86f_side_flags; + d86f_handler[drive].writeback = d86f_writeback; + d86f_handler[drive].set_sector = null_set_sector; + d86f_handler[drive].write_data = null_write_data; + d86f_handler[drive].format_conditions = d86f_format_conditions; + d86f_handler[drive].extra_bit_cells = d86f_extra_bit_cells; + d86f_handler[drive].encoded_data = common_encoded_data; + d86f_handler[drive].read_revolution = common_read_revolution; + d86f_handler[drive].index_hole_pos = d86f_index_hole_pos; + d86f_handler[drive].get_raw_size = common_get_raw_size; + d86f_handler[drive].check_crc = 1; +} - if (d86f_is_40_track(drive) && fdd_doublestep_40(drive)) - track /= 2; - - for (side = 0; side < d86f_get_sides(drive); side++) +int d86f_get_array_size(int drive) +{ + int array_size = 0; + int rm = 0; + int hole = 0; + int extra_bytes = 0; + rm = d86f_get_rpm_mode(drive); + hole = (d86f_handler[drive].disk_flags(drive) & 6) >> 1; + switch (hole) { - if (d86f_is_old_style(drive)) - { - memset(d86f[drive].track_layout[side], BYTE_GAP0, 50000); - } - else - { - memset(d86f[drive].track_layout[side], 0, 50000); - } - if (d86f_is_encoded(drive)) - { - memset(d86f[drive].track_encoded_data[side], 0xFF, 50000); - } - else - { - memset(d86f[drive].track_data[side], 0xFF, 50000); - } - } - - d86f[drive].cur_track = track; - - if (!(d86f[drive].track_offset[track])) - { - /* Track does not exist in the image, initialize it as unformatted. */ - d86f[drive].track_in_file = 0; - for (side = 0; side < d86f_get_sides(drive); side++) - { - d86f[drive].side_flags[side] = 0x0A; /* 300 rpm, MFM, 250 kbps */ - } - return; - } - - d86f[drive].track_in_file = 1; - - fseek(d86f[drive].f, d86f[drive].track_offset[track], SEEK_SET); - - for (side = 0; side < d86f[drive].side_flag_bytes; side++) - { - fread(&(d86f[drive].side_flags[side]), 2, 1, d86f[drive].f); - } - - for (side = 0; side < d86f[drive].side_flag_bytes; side++) - { - fread(&(d86f[drive].index_hole_pos[side]), 2, 1, d86f[drive].f); - } - - fread(&track_id, 1, 1, d86f[drive].f); - - for (side = 0; side < d86f_get_sides(drive); side++) - { - if (d86f_is_old_style(drive)) - { - fread(d86f[drive].track_layout[side], 1, d86f_get_array_size(drive), d86f[drive].f); - } - else - { - if (d86f_has_mini_table(drive)) + case 0: + case 1: + default: + array_size = 12500; + switch (rm) { - fread(d86f[drive].track_layout[side], 1, d86f_get_mini_size(drive), d86f[drive].f); + case 1: + array_size = 12625; + break; + case 2: + array_size = 12687; + break; + case 3: + array_size = 12750; + break; + default: + array_size = 12500; + break; + } + break; + case 2: + array_size = 25000; + switch (rm) + { + case 1: + array_size = 25250; + break; + case 2: + array_size = 25375; + break; + case 3: + array_size = 25500; + break; + default: + array_size = 25000; + break; + } + break; + case 3: + array_size = 50000; + switch (rm) + { + case 1: + array_size = 50500; + break; + case 2: + array_size = 50750; + break; + case 3: + array_size = 51000; + break; + default: + array_size = 50000; + break; + } + break; + } + array_size <<= 4; + array_size += d86f_handler[drive].extra_bit_cells(drive); + array_size >>= 4; + if (d86f_handler[drive].extra_bit_cells(drive) & 15) + { + array_size++; + } + return array_size; +} + +int d86f_valid_bit_rate(int drive) +{ + int rate = 0; + int hole = 0; + rate = fdc_get_bit_rate(); + hole = (d86f_handler[drive].disk_flags(drive) & 6) >> 1; + switch (hole) + { + case 0: /* DD */ + if (!rate && (fdd_get_flags(drive) & 0x10)) return 1; + if ((rate < 1) || (rate > 2)) return 0; + return 1; + case 1: /* HD */ + if (rate != 0) return 0; + return 1; + case 2: /* ED */ + if (rate != 3) return 0; + return 1; + case 3: /* ED with 2000 kbps support */ + if (rate < 3) return 0; + return 1; + } + return 1; +} + +int d86f_hole(int drive) +{ + if (((d86f_handler[drive].disk_flags(drive) >> 1) & 3) == 3) return 2; + return (d86f_handler[drive].disk_flags(drive) >> 1) & 3; +} + +uint8_t d86f_get_encoding(int drive) +{ + return (d86f_track_flags(drive) & 0x18) >> 3; +} + +double d86f_byteperiod(int drive) +{ + switch (d86f_track_flags(drive) & 0x0f) + { + case 0x02: /* 125 kbps, FM */ + return 4.0; + case 0x01: /* 150 kbps, FM */ + return 20.0 / 6.0; + case 0x0A: /* 250 kbps, MFM */ + case 0x00: /* 250 kbps, FM */ + return 2.0; + case 0x09: /* 300 kbps, MFM */ + return 10.0 / 6.0; + case 0x08: /* 500 kbps, MFM */ + return 1.0; + case 0x0B: /* 1000 kbps, MFM */ + return 0.5; + case 0x0D: /* 2000 kbps, MFM */ + return 0.25; + default: + return 2.0; + } + return 2.0; +} + +int d86f_is_mfm(int drive) +{ + return (d86f_track_flags(drive) & 8) ? 1 : 0; +} + +uint32_t d86f_get_data_len(int drive) +{ + if (d86f[drive].req_sector.id.n) + { + if (d86f[drive].req_sector.id.n == 8) return 32768; + return (128 << ((uint32_t) d86f[drive].req_sector.id.n)); + } + else + { + if (fdc_get_dtl() < 128) + { + return fdc_get_dtl(); + } + else + { + return (128 << ((uint32_t) d86f[drive].req_sector.id.n)); + } + } +} + +uint32_t d86f_has_extra_bit_cells(int drive) +{ + return (d86f_disk_flags(drive) >> 7) & 1; +} + +uint32_t d86f_header_size(int drive) +{ + uint32_t temp = 16; + if (d86f_has_extra_bit_cells(drive)) + { + temp += 2; + } + return temp; +} + +static uint16_t d86f_encode_get_data(uint8_t dat) +{ + uint16_t temp; + temp = 0; + if (dat & 0x01) temp |= 1; + if (dat & 0x02) temp |= 4; + if (dat & 0x04) temp |= 16; + if (dat & 0x08) temp |= 64; + if (dat & 0x10) temp |= 256; + if (dat & 0x20) temp |= 1024; + if (dat & 0x40) temp |= 4096; + if (dat & 0x80) temp |= 16384; + return temp; +} + +static uint16_t d86f_encode_get_clock(uint8_t dat) +{ + uint16_t temp; + temp = 0; + if (dat & 0x01) temp |= 2; + if (dat & 0x02) temp |= 8; + if (dat & 0x40) temp |= 32; + if (dat & 0x08) temp |= 128; + if (dat & 0x10) temp |= 512; + if (dat & 0x20) temp |= 2048; + if (dat & 0x40) temp |= 8192; + if (dat & 0x80) temp |= 32768; + return temp; +} + +int d86f_format_conditions(int drive) +{ + return d86f_valid_bit_rate(drive); +} + +int d86f_can_format(int drive) +{ + int temp; + temp = !writeprot[drive]; + temp = temp && !swwp; + temp = temp && fdd_can_read_medium(drive ^ fdd_swap); + temp = temp && d86f_handler[drive].format_conditions(drive); /* Allows proxied formats to add their own extra conditions to formatting. */ + return temp; +} + +uint16_t d86f_encode_byte(int drive, int sync, decoded_t b, decoded_t prev_b) +{ + uint8_t encoding = d86f_get_encoding(drive); + uint8_t bits89AB = prev_b.nibbles.nibble0; + uint8_t bits7654 = b.nibbles.nibble1; + uint8_t bits3210 = b.nibbles.nibble0; + uint16_t encoded_7654, encoded_3210, result; + if (encoding > 1) return 0xFF; + if (sync) + { + result = d86f_encode_get_data(b.byte); + if (encoding) + { + switch(b.byte) + { + case 0xA1: return result | d86f_encode_get_clock(0x0A); + case 0xC2: return result | d86f_encode_get_clock(0x14); + case 0xF8: return result | d86f_encode_get_clock(0x03); + case 0xFB: case 0xFE: return result | d86f_encode_get_clock(0x00); + case 0xFC: return result | d86f_encode_get_clock(0x01); } } - if (d86f_is_encoded(drive)) - { - fread(d86f[drive].track_encoded_data[side], 1, d86f_get_array_size(drive) << 1, d86f[drive].f); - } else { - fread(d86f[drive].track_data[side], 1, d86f_get_array_size(drive), d86f[drive].f); - } - } -} - -void d86f_writeback(int drive) -{ - int track = d86f[drive].cur_track; - uint8_t track_id = track; - int side; - - if (!d86f[drive].f) - { - return; - } - - if (!d86f[drive].track_in_file) - { - return; /*Should never happen*/ - } - - fseek(d86f[drive].f, 8, SEEK_SET); - fwrite(d86f[drive].track_offset, 1, 1024, d86f[drive].f); - - fseek(d86f[drive].f, d86f[drive].track_offset[track], SEEK_SET); - - for (side = 0; side < d86f[drive].side_flag_bytes; side++) - { - fwrite(&(d86f[drive].side_flags[side]), 2, 1, d86f[drive].f); - } - - for (side = 0; side < d86f[drive].side_flag_bytes; side++) - { - fwrite(&(d86f[drive].index_hole_pos[side]), 2, 1, d86f[drive].f); - } - - fwrite(&track_id, 1, 1, d86f[drive].f); - - for (side = 0; side < d86f_get_sides(drive); side++) - { - if (d86f_is_old_style(drive)) - { - fwrite(d86f[drive].track_layout[side], 1, d86f_get_array_size(drive), d86f[drive].f); - } - else - { - if (d86f_has_mini_table(drive)) + switch(b.byte) { - fwrite(d86f[drive].track_layout[side], 1, d86f_get_mini_size(drive), d86f[drive].f); + case 0xF8: case 0xFB: case 0xFE: return result | d86f_encode_get_clock(0xC7); + case 0xFC: return result | d86f_encode_get_clock(0xD7); } } - if (d86f_is_encoded(drive)) - { - fwrite(d86f[drive].track_encoded_data[side], 1, d86f_get_array_size(drive) << 1, d86f[drive].f); - } - else - { - fwrite(d86f[drive].track_data[side], 1, d86f_get_array_size(drive), d86f[drive].f); - } - } - - // pclog("d86f_writeback(): %08X\n", d86f[drive].track_offset[track]); -} - -void d86f_reset(int drive, int side) -{ - if (side == 0) - { - d86f[drive].index_count = 0; - d86f[drive].state = STATE_SEEK; } + bits3210 += ((bits7654 & 3) << 4); + bits7654 += ((bits89AB & 3) << 4); + encoded_3210 = (encoding == 1) ? encoded_mfm[bits3210] : encoded_fm[bits3210]; + encoded_7654 = (encoding == 1) ? encoded_mfm[bits7654] : encoded_fm[bits7654]; + result = (encoded_7654 << 8) | encoded_3210; + return result; } static int d86f_get_bitcell_period(int drive) @@ -1027,542 +946,9 @@ static int d86f_get_bitcell_period(int drive) return (int) size; } -void d86f_readsector(int drive, int sector, int track, int side, int rate, int sector_size) -{ - // pclog("d86f_readsector: fdc_period=%i img_period=%i rate=%i sector=%i track=%i side=%i\n", fdc_get_bitcell_period(), d86f_get_bitcell_period(drive), rate, sector, track, side); - - d86f[drive].req_sector.id.c = track; - d86f[drive].req_sector.id.h = side; - - if (fdd_get_head(drive) && (d86f_get_sides(drive) == 1)) - { - fdc_notfound(); - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; - return; - } - - d86f_drive = drive; - - if (sector == SECTOR_FIRST) - d86f[drive].req_sector.id.r = 1; - else if (sector == SECTOR_NEXT) - d86f[drive].req_sector.id.r++; - else - d86f[drive].req_sector.id.r = sector; - - d86f[drive].rw_sector_id.dword = 0xFFFFFFFF; - d86f[drive].last_sector.dword = 0xFFFFFFFF; - d86f[drive].req_sector.id.n = sector_size; - d86f[drive].index_count = d86f[drive].satisfying_bytes = 0; - d86f_new_style_reset(drive); - d86f[drive].state = STATE_READ_FIND_SECTOR; -} - -void d86f_writesector(int drive, int sector, int track, int side, int rate, int sector_size) -{ - d86f[drive].req_sector.id.c = track; - d86f[drive].req_sector.id.h = side; - d86f[drive].req_sector.id.r = sector; - d86f[drive].req_sector.id.n = sector_size; - - // pclog("d86f_writesector: drive=%c: fdc_period=%i img_period=%i rate=%i chrn=%08X\n", drive + 0x41, fdc_get_bitcell_period(), d86f_get_bitcell_period(drive), rate, d86f[drive].req_sector.dword); - - if (writeprot[drive] || swwp) - { - // pclog("Write protected\n"); - fdc_writeprotect(); - return; - } - - if (fdd_get_head(drive) && (d86f_get_sides(drive) == 1)) - { - // pclog("Wrong side\n"); - fdc_notfound(); - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; - return; - } - - d86f[drive].rw_sector_id.dword = 0xFFFFFFFF; - d86f[drive].last_sector.dword = 0xFFFFFFFF; - d86f_drive = drive; - d86f[drive].index_count = d86f[drive].satisfying_bytes = 0; - d86f_new_style_reset(drive); - d86f[drive].state = STATE_WRITE_FIND_SECTOR; -} - -void d86f_comparesector(int drive, int sector, int track, int side, int rate, int sector_size) -{ - d86f[drive].req_sector.id.c = track; - d86f[drive].req_sector.id.h = side; - d86f[drive].req_sector.id.r = sector; - d86f[drive].req_sector.id.n = sector_size; - - // pclog("d86f_comparesector: drive=%c: fdc_period=%i img_period=%i rate=%i chrn=%08X\n", drive + 0x41, fdc_get_bitcell_period(), d86f_get_bitcell_period(drive), rate, d86f[drive].req_sector.dword); - - if (writeprot[drive] || swwp) - { - // pclog("Write protected\n"); - fdc_writeprotect(); - return; - } - - if (fdd_get_head(drive) && (d86f_get_sides(drive) == 1)) - { - // pclog("Wrong side\n"); - fdc_notfound(); - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; - return; - } - - d86f[drive].rw_sector_id.dword = 0xFFFFFFFF; - d86f[drive].last_sector.dword = 0xFFFFFFFF; - d86f_drive = drive; - d86f[drive].index_count = d86f[drive].satisfying_bytes = 0; - d86f_new_style_reset(drive); - d86f[drive].state = STATE_COMPARE_FIND_SECTOR; -} - -void d86f_readaddress(int drive, int track, int side, int rate) -{ - // pclog("d86f_readaddress: fdc_period=%i img_period=%i rate=%i track=%i side=%i\n", fdc_get_bitcell_period(), d86f_get_bitcell_period(drive), rate, track, side); - - d86f[drive].req_sector.id.c = track; - d86f[drive].req_sector.id.h = side; - - if (fdd_get_head(drive) && (d86f_get_sides(drive) == 1)) - { - fdc_notfound(); - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; - return; - } - - d86f[drive].rw_sector_id.dword = 0xFFFFFFFF; - d86f[drive].last_sector.dword = 0xFFFFFFFF; - d86f_drive = drive; - d86f[drive].index_count = d86f[drive].satisfying_bytes = 0; - d86f_new_style_reset(drive); - d86f[drive].state = STATE_READ_FIND_ADDRESS; -} - -uint16_t d86f_prepare_pretrack(int drive, int side, int iso, int write_data) -{ - uint16_t i; - - int mfm = 0; - int real_gap0_len = 0; - int sync_len = 0; - int real_gap1_len = 0; - - mfm = d86f_is_mfm(drive); - real_gap0_len = mfm ? 80 : 40; - sync_len = mfm ? 12 : 6; - real_gap1_len = mfm ? 50 : 26; - - d86f[drive].index_hole_pos[side] = 0; - - if (d86f_is_encoded(drive)) write_data = 0; - - memset(d86f[drive].track_layout[side], BYTE_GAP0, d86f_get_raw_size(drive)); - if (write_data) memset(d86f[drive].track_data[side], mfm ? 0x4E : 0xFF, d86f_get_raw_size(drive)); - i = 0; - - if (!iso) - { - memset(d86f[drive].track_layout[side] + i, BYTE_GAP0, real_gap0_len); - if (write_data) memset(d86f[drive].track_data[side] + i, mfm ? 0x4E : 0xFF, real_gap0_len); - i += real_gap0_len; - memset(d86f[drive].track_layout[side] + i, BYTE_I_SYNC, sync_len); - if (write_data) memset(d86f[drive].track_data[side] + i, 0, sync_len); - i += sync_len; - if (mfm) - { - memset(d86f[drive].track_layout[side] + i, BYTE_IAM_SYNC, 3); - if (write_data) memset(d86f[drive].track_data[side] + i, 0xC2, 3); - i += 3; - } - memset(d86f[drive].track_layout[side] + i, BYTE_IAM, 1); - if (write_data) memset(d86f[drive].track_data[side] + i, 0xFC, 1); - i++; - } - memset(d86f[drive].track_layout[side] + i, BYTE_GAP1, real_gap1_len); - if (write_data) memset(d86f[drive].track_data[side] + i, mfm ? 0x4E : 0xFF, real_gap1_len); - i += real_gap1_len; - - return i; -} - -void d86f_calccrc_buf(int drive, uint8_t *buf, uint16_t len) -{ - uint16_t i = 0; - - for (i = 0; i < len; i++) - { - d86f_calccrc(drive, buf[i]); - } -} - -static void *d86f_memset(void *str, int c, size_t n, size_t s, uint16_t rs, int limit) -{ - void *temp; - - size_t wrap_n[2]; - uint8_t *wrap_str[2]; - - if ((n + s - 1) >= rs) - { - /* This is going to wrap around, so we need to split the data in two. */ - wrap_n[0] = ((rs - 1) - s) + 1; - wrap_n[1] = n - wrap_n[0]; - wrap_str[0] = (uint8_t *) str; - wrap_str[1] = wrap_str[0] - s; - temp = memset(wrap_str[0], c, wrap_n[0]); - if (!limit) temp = memset(wrap_str[1], c, wrap_n[1]); - } - else - { - /* No wrap around, do a standard memcpy. */ - temp = memset(str, c, n); - } - return temp; -} - -static void *d86f_memcpy(void *str1, const void *str2, size_t n, size_t s, uint16_t rs, int limit) -{ - void *temp; - - size_t wrap_n[2]; - uint8_t *wrap_str1[2]; - uint8_t *wrap_str2[2]; - - if ((n + s - 1) >= rs) - { - /* This is going to wrap around, so we need to split the data in two. */ - wrap_n[0] = ((rs - 1) - s) + 1; - wrap_n[1] = n - wrap_n[0]; - wrap_str1[0] = (uint8_t *) str1; - wrap_str2[0] = (uint8_t *) str2; - wrap_str1[1] = wrap_str1[0] - s; - wrap_str2[1] = wrap_str2[0] + wrap_n[0]; - temp = memcpy(wrap_str1[0], wrap_str2[0], wrap_n[0]); - if (!limit) temp = memcpy(wrap_str1[1], wrap_str2[1], wrap_n[1]); - } - else - { - /* No wrap around, do a standard memcpy. */ - temp = memcpy(str1, str2, n); - } - return temp; -} - -void d86f_reset_index_hole_pos(int drive, int side) -{ - d86f[drive].index_hole_pos[side] = 0; -} - -uint16_t d86f_prepare_sector(int drive, int side, int pos, uint8_t *id_buf, uint8_t *data_buf, int data_len, int write_data, int gap2, int gap3, int limit, int deleted, int bad_crc) -{ - uint16_t i = pos; - uint16_t j = 0; - uint16_t rs = 0; - - uint8_t am[4] = { 0xA1, 0xA1, 0xA1 }; - - int real_gap2_len = gap2; - int real_gap3_len = gap3; - int mfm = 0; - int sync_len = 0; - - if (d86f_is_encoded(drive)) write_data = 0; - - rs = d86f_get_raw_size(drive); - - mfm = d86f_is_mfm(drive); - sync_len = mfm ? 12 : 6; - - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_ID_SYNC, sync_len, i, rs, limit); - if (write_data) d86f_memset(d86f[drive].track_data[side] + i, 0, sync_len, i, rs, limit); - i += sync_len; - if ((i >= rs) && limit) return 0; - i %= rs; - if (mfm) - { - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_IDAM_SYNC, 3, i, rs, limit); - if (write_data) - { - d86f[drive].calc_crc.word = 0xffff; - d86f_memset(d86f[drive].track_data[side] + i, 0xA1, 3, i, rs, limit); - d86f_calccrc_buf(drive, am, 3); - } - i += 3; - if ((i >= rs) && limit) return 0; - i %= rs; - } - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_IDAM, 1, i, rs, limit); - if (write_data) - { - if (!mfm) d86f[drive].calc_crc.word = 0xffff; - d86f_memset(d86f[drive].track_data[side] + i, 0xFE, 1, i, rs, limit); - d86f_calccrc(drive, 0xFE); - } - i++; - if ((i >= rs) && limit) return 0; - i %= rs; - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_ID, 4, i, rs, limit); - if (write_data) - { - d86f_memcpy(d86f[drive].track_data[side] + i, id_buf, 4, i, rs, limit); - d86f_calccrc_buf(drive, id_buf, 4); - // if ((id_buf[0] == 4) && (id_buf[1] == 0) && (id_buf[2] == 19) && (id_buf[3] == 2)) pclog("Prepare (%i %i %i %i): ID CRC %04X\n", id_buf[0], id_buf[1], id_buf[2], id_buf[3], d86f[drive].calc_crc); - } - i += 4; - if ((i >= rs) && limit) return 0; - i %= rs; - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_ID_CRC, 2, i, rs, limit); - if (write_data) - { - d86f[drive].track_data[side][i] = d86f[drive].calc_crc.bytes[1]; - d86f[drive].track_data[side][(i + 1) % rs] = d86f[drive].calc_crc.bytes[0]; - } - i += 2; - if ((i >= rs) && limit) return 0; - i %= rs; - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_GAP2, real_gap2_len, i, rs, limit); - if (write_data) d86f_memset(d86f[drive].track_data[side] + i, mfm ? 0x4E : 0xFF, real_gap2_len, i, rs, limit); - i += real_gap2_len; - if ((i >= rs) && limit) return 0; - i %= rs; - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_DATA_SYNC, sync_len, i, rs, limit); - if (write_data) d86f_memset(d86f[drive].track_data[side] + i, 0, sync_len, i, rs, limit); - i += sync_len; - if ((i >= rs) && limit) return 0; - i %= rs; - if (mfm) - { - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_DATAAM_SYNC, 3, i, rs, limit); - if (write_data) - { - d86f[drive].calc_crc.word = 0xffff; - d86f_memset(d86f[drive].track_data[side] + i, 0xA1, 3, i, rs, limit); - d86f_calccrc_buf(drive, am, 3); - } - i += 3; - if ((i >= rs) && limit) return 0; - i %= rs; - } - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_DATAAM, 1, i, rs, limit); - if (write_data) - { - if (!mfm) d86f[drive].calc_crc.word = 0xffff; - d86f_memset(d86f[drive].track_data[side] + i, deleted ? 0xF8 : 0xFB, 1, i, rs, limit); - d86f_calccrc(drive, deleted ? 0xF8 : 0xFB); - } - i++; - if ((i >= rs) && limit) return 0; - i %= rs; - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_DATA, data_len, i, rs, limit); - if (write_data) - { - d86f_memcpy(d86f[drive].track_data[side] + i, data_buf, data_len, i, rs, limit); - d86f_calccrc_buf(drive, data_buf, data_len); - // if ((id_buf[0] == 4) && (id_buf[1] == 0) && (id_buf[2] == 19) && (id_buf[3] == 2)) pclog("Prepare (%i %i %i %i): Data CRC %04X\n", id_buf[0], id_buf[1], id_buf[2], id_buf[3], d86f[drive].calc_crc); - } - i += data_len; - if ((i >= rs) && limit) return 0; - i %= rs; - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_DATA_CRC, 2, i, rs, limit); - if (write_data) - { - if (bad_crc) - { - /* If sector has to be prepared with a bad CRC, just reverse the bytes and toggle the LSB of the first byte, and the CRC will automatically be wrong. */ - d86f[drive].track_data[side][i] = d86f[drive].calc_crc.bytes[0] ^ 1; - d86f[drive].track_data[side][(i + 1) % rs] = d86f[drive].calc_crc.bytes[1]; - } - else - { - d86f[drive].track_data[side][i] = d86f[drive].calc_crc.bytes[1]; - d86f[drive].track_data[side][(i + 1) % rs] = d86f[drive].calc_crc.bytes[0]; - } - } - i += 2; - if ((i >= rs) && limit) return 0; - i %= rs; - d86f_memset(d86f[drive].track_layout[side] + i, BYTE_GAP3, real_gap3_len, i, rs, limit); - d86f_memset(d86f[drive].track_data[side] + i, mfm ? 0x4E : 0xFF, real_gap3_len, i, rs, limit); - i += real_gap3_len; - if ((i >= rs) && limit) return 0; - i %= rs; - - return i; -} - -void d86f_prepare_track_layout(int drive, int side) -{ - uint16_t i = 0; - uint16_t j = 0; - uint16_t sc = 0; - uint16_t dtl = 0; - int real_gap2_len = 0; - int real_gap3_len = 0; - sc = fdc_get_format_sectors(); - dtl = 128 << fdc_get_format_n(); - real_gap2_len = fdc_get_gap2(drive ^ fdd_swap); - real_gap3_len = fdc_get_gap(); - - i = d86f_prepare_pretrack(drive, side, 0, 0); - - for (j = 0; j < sc; j++) - { - /* Always limit to prevent wraparounds when formatting! */ - i = d86f_prepare_sector(drive, side, i, NULL, NULL, dtl, 0, real_gap2_len, real_gap3_len, 1, 0, 0); - } -} - -int d86f_format_conditions(int drive) -{ - return d86f_valid_bit_rate(drive); -} - -int d86f_can_format(int drive) -{ - int temp; - temp = !writeprot[drive]; - temp = temp && !swwp; - temp = temp && fdd_can_read_medium(drive ^ fdd_swap); - temp = temp && d86f_handler[drive].format_conditions(drive); /* Allows proxied formats to add their own extra conditions to formatting. */ - return temp; -} - -void d86f_format(int drive, int track, int side, int rate, uint8_t fill) -{ - int full_size, store_size; - int flag_bytes = 5; - - full_size = d86f_get_array_size(drive); - store_size = full_size << 1; - if (d86f_is_encoded(drive)) store_size += full_size; - if (!d86f_is_old_style(drive)) - { - store_size -= full_size; - if (d86f_has_mini_table(drive)) - { - store_size += d86f_get_mini_size(drive); - } - } - if (d86f_get_sides(drive) == 2) flag_bytes += 4; - - d86f[drive].req_sector.id.c = d86f[drive].cur_track; - d86f[drive].req_sector.id.h = side; - - if ((side && (d86f_get_sides(drive) == 1)) || !(d86f_can_format(drive))) - { - fdc_notfound(); - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; - return; - } - - if ((d86f[drive].cur_track < 0) || (d86f[drive].cur_track > 256)) - { - // pclog("Track below 0 or above 256\n"); - fdc_writeprotect(); - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; - return; - } - - d86f_drive = drive; - d86f[drive].fill = fill; - d86f[drive].index_count = 0; - /* Let's prepare the track space and layout before filling. */ - if (d86f[drive].version != 0x0063) - { - d86f[drive].side_flags[side] &= 0xc0; - d86f[drive].side_flags[side] |= (fdd_getrpm(drive ^ fdd_swap) == 360) ? 0x20 : 0; - d86f[drive].side_flags[side] |= fdc_get_bit_rate(); - d86f[drive].side_flags[side] |= fdc_is_mfm() ? 8 : 0; - - d86f[drive].index_hole_pos[side] = 0; - } - - if (!d86f_is_encoded(drive)) - { - memset(d86f[drive].track_data[side], 0xFF, full_size); - } - else - { - memset(d86f[drive].track_encoded_data[side], 0xFF, full_size * 2); - } - - /* For version 0.99 (= another format proxied to the 86F handler), the track layout is fixed. */ - if (d86f[drive].version != 0x0063) - { - if (d86f_is_old_style(drive)) - { - d86f_prepare_track_layout(drive, side); - } - - if (!d86f[drive].track_in_file) - { - /* Track is absent from the file, let's add it. */ - d86f[drive].track_offset[d86f[drive].cur_track] = d86f[drive].file_size; - - d86f[drive].file_size += store_size + flag_bytes; - if (d86f_get_sides(drive) == 2) - { - d86f[drive].file_size += store_size; - } - d86f[drive].track_in_file = 1; - } - } - - // pclog("Formatting track %i side %i\n", d86f[drive].cur_track, side); - - d86f_new_style_reset(drive); - d86f[drive].state = STATE_FORMAT_FIND; -} - -void d86f_stop(int drive) -{ - d86f[drive].state = STATE_IDLE; -} - -static void index_pulse(int drive) -{ - if (d86f[drive].state != STATE_IDLE) fdc_indexpulse(); -} - -uint32_t d86f_get_data_len(int drive) -{ - if (d86f[drive].req_sector.id.n) - { - return (128 << ((uint32_t) d86f[drive].req_sector.id.n)); - } - else - { - if (fdc_get_dtl() < 128) - { - return fdc_get_dtl(); - } - else - { - return (128 << ((uint32_t) d86f[drive].req_sector.id.n)); - } - } -} - -uint8_t d86f_get_encoding(int drive) -{ - return (d86f_track_flags(drive) & 0x18) >> 3; -} - int d86f_can_read_address(int drive) { - int temp; + int temp = 0; temp = (fdc_get_bitcell_period() == d86f_get_bitcell_period(drive)); temp = temp && fdd_can_read_medium(drive ^ fdd_swap); temp = temp && (fdc_is_mfm() == d86f_is_mfm(drive)); @@ -1570,352 +956,222 @@ int d86f_can_read_address(int drive) return temp; } -int d86f_find_state_nf_ignore_id(int drive) +void d86f_get_bit(int drive, int side) { - int temp; - temp = temp || (d86f[drive].state == STATE_READ_FIND_FIRST_SECTOR); - temp = temp || (d86f[drive].state == STATE_READ_FIND_NEXT_SECTOR); - return temp; -} + uint32_t track_word; + uint32_t track_bit; + uint16_t encoded_data; + uint16_t surface_data; + uint16_t current_bit; + uint16_t surface_bit; -int d86f_find_state_nf(int drive) -{ - int temp; - temp = (d86f[drive].state == STATE_READ_FIND_SECTOR); - temp = temp || (d86f[drive].state == STATE_COMPARE_FIND_SECTOR); - temp = temp || d86f_find_state_nf_ignore_id(drive); - temp = temp || (d86f[drive].state == STATE_WRITE_FIND_SECTOR); - temp = temp || (d86f[drive].state == STATE_READ_FIND_ADDRESS); - return temp; -} + track_word = d86f[drive].track_pos >> 4; + /* We need to make sure we read the bits from MSB to LSB. */ + track_bit = 15 - (d86f[drive].track_pos & 15); -int d86f_find_state(int drive) -{ - int temp; - temp = d86f_find_state_nf(drive); - temp = temp || (d86f[drive].state == STATE_FORMAT_FIND); - return temp; -} - -int d86f_read_state_data(int drive) -{ - int temp; - temp = (d86f[drive].state == STATE_READ_SECTOR); - temp = temp || (d86f[drive].state == STATE_READ_FIRST_SECTOR); - temp = temp || (d86f[drive].state == STATE_READ_NEXT_SECTOR); - return temp; -} - -int d86f_read_state_crc(int drive) -{ - int temp; - temp = (d86f[drive].state == STATE_READ_SECTOR_CRC); - temp = temp || (d86f[drive].state == STATE_READ_FIRST_SECTOR_CRC); - temp = temp || (d86f[drive].state == STATE_READ_NEXT_SECTOR_CRC); - temp = temp || (d86f[drive].state == STATE_COMPARE_SECTOR_CRC); - return temp; -} - -int d86f_read_state_gap3(int drive) -{ - int temp; - temp = (d86f[drive].state == STATE_READ_SECTOR_GAP3); - temp = temp || (d86f[drive].state == STATE_READ_FIRST_SECTOR_GAP3); - temp = temp || (d86f[drive].state == STATE_READ_NEXT_SECTOR_GAP3); - temp = temp || (d86f[drive].state == STATE_COMPARE_SECTOR_GAP3); - return temp; -} - -int d86f_write_state(int drive) -{ - int temp; - temp = (d86f[drive].state == STATE_WRITE_SECTOR); - temp = temp || (d86f[drive].state == STATE_WRITE_SECTOR_CRC); - temp = temp || (d86f[drive].state == STATE_WRITE_SECTOR_GAP3); - return temp; -} - -int d86f_read_state(int drive) -{ - int temp; - temp = d86f_read_state_data(drive); - temp = temp || d86f_read_state_crc(drive); - temp = temp || d86f_read_state_gap3(drive); - temp = temp || (d86f[drive].state == STATE_COMPARE_SECTOR); - return temp; -} - -int d86f_data_size(int drive) -{ - int temp; - temp = d86f[drive].req_sector.id.n; - temp = 128 << temp; - return temp; -} - -uint32_t d86f_get_pos(int drive) -{ - uint32_t pos; - if (d86f[drive].track_pos >= d86f[drive].section_pos) + if (d86f_reverse_bytes(drive)) { - pos = d86f[drive].track_pos - d86f[drive].section_pos; + /* Image is in reverse endianness, read the data as is. */ + encoded_data = d86f_handler[drive].encoded_data(drive, side)[track_word]; } else { - /* A wrap arround has occurred, let's add the raw size to the position. */ - pos = d86f_get_raw_size(drive) + d86f[drive].track_pos; - pos -= d86f[drive].section_pos; + /* We store the words as big endian, so we need to convert them to little endian when reading. */ + encoded_data = (d86f_handler[drive].encoded_data(drive, side)[track_word] & 0xFF) << 8; + encoded_data |= (d86f_handler[drive].encoded_data(drive, side)[track_word] >> 8); } - return pos; + if (d86f_has_surface_desc(drive)) + { + if (d86f_reverse_bytes(drive)) + { + surface_data = d86f[drive].track_surface_data[side][track_word] & 0xFF; + } + else + { + surface_data = (d86f[drive].track_surface_data[side][track_word] & 0xFF) << 8; + surface_data |= (d86f[drive].track_surface_data[side][track_word] >> 8); + } + } + + current_bit = (encoded_data >> track_bit) & 1; + d86f[drive].last_word[side] <<= 1; + + if (d86f_has_surface_desc(drive)) + { + surface_bit = (surface_data >> track_bit) & 1; + if (!surface_bit) + { + if (!current_bit) + { + /* Bit is 0 and is not set to fuzzy, we add it as read. */ + d86f[drive].last_word[side] |= 1; + } + else + { + /* Bit is 1 and is not set to fuzzy, we add it as read. */ + d86f[drive].last_word[side] |= 1; + } + } + else + { + if (current_bit) + { + /* Bit is 1 and is set to fuzzy, we randomly generate it. */ + d86f[drive].last_word[side] |= (disc_random_generate() & 1); + } + } + } + else + { + d86f[drive].last_word[side] |= current_bit; + } +} + +void d86f_put_bit(int drive, int side, int bit) +{ + uint32_t track_word; + uint32_t track_bit; + uint16_t encoded_data; + uint16_t surface_data; + uint16_t current_bit; + uint16_t surface_bit; + + track_word = d86f[drive].track_pos >> 4; + /* We need to make sure we read the bits from MSB to LSB. */ + track_bit = 15 - (d86f[drive].track_pos & 15); + + if (d86f_reverse_bytes(drive)) + { + /* Image is in reverse endianness, read the data as is. */ + encoded_data = d86f_handler[drive].encoded_data(drive, side)[track_word]; + } + else + { + /* We store the words as big endian, so we need to convert them to little endian when reading. */ + encoded_data = (d86f_handler[drive].encoded_data(drive, side)[track_word] & 0xFF) << 8; + encoded_data |= (d86f_handler[drive].encoded_data(drive, side)[track_word] >> 8); + } + + if (d86f_has_surface_desc(drive)) + { + if (d86f_reverse_bytes(drive)) + { + surface_data = d86f[drive].track_surface_data[side][track_word] & 0xFF; + } + else + { + surface_data = (d86f[drive].track_surface_data[side][track_word] & 0xFF) << 8; + surface_data |= (d86f[drive].track_surface_data[side][track_word] >> 8); + } + } + + current_bit = (encoded_data >> track_bit) & 1; + d86f[drive].last_word[side] <<= 1; + + if (d86f_has_surface_desc(drive)) + { + surface_bit = (surface_data >> track_bit) & 1; + if (!surface_bit) + { + if (!current_bit) + { + /* Bit is 0 and is not set to fuzzy, we overwrite it as is. */ + d86f[drive].last_word[side] |= bit; + current_bit = bit; + } + else + { + /* Bit is 1 and is not set to fuzzy, we overwrite it as is. */ + d86f[drive].last_word[side] |= bit; + current_bit = bit; + } + } + else + { + if (current_bit) + { + /* Bit is 1 and is set to fuzzy, we overwrite it with a non-fuzzy bit. */ + d86f[drive].last_word[side] |= bit; + current_bit = bit; + surface_bit = 0; + } + } + + surface_data &= ~(1 << track_bit); + surface_data |= (surface_bit << track_bit); + if (d86f_reverse_bytes(drive)) + { + d86f[drive].track_surface_data[side][track_word] = surface_data; + } + else + { + d86f[drive].track_surface_data[side][track_word] = (surface_data & 0xFF) << 8; + d86f[drive].track_surface_data[side][track_word] |= (surface_data >> 8); + } + } + else + { + d86f[drive].last_word[side] |= bit; + current_bit = bit; + } + + encoded_data &= ~(1 << track_bit); + encoded_data |= (current_bit << track_bit); + + if (d86f_reverse_bytes(drive)) + { + d86f_handler[drive].encoded_data(drive, side)[track_word] = encoded_data; + } + else + { + d86f_handler[drive].encoded_data(drive, side)[track_word] = (encoded_data & 0xFF) << 8; + d86f_handler[drive].encoded_data(drive, side)[track_word] |= (encoded_data >> 8); + } } static uint8_t decodefm(int drive, uint16_t dat) { - uint8_t temp; - if (d86f_get_encoding(drive) > 1) - { - /* 2 means M2FM encoding, and 3 means GCR encoding, neither of which is supported by this emulator. */ - return 0xFF; - } - temp = 0; + uint8_t temp = 0; /* We write the encoded bytes in big endian, so we process the two 8-bit halves swapped here. */ - if (dat & 0x0100) temp |= 1; - if (dat & 0x0400) temp |= 2; - if (dat & 0x1000) temp |= 4; - if (dat & 0x4000) temp |= 8; - if (dat & 0x0001) temp |= 16; - if (dat & 0x0004) temp |= 32; - if (dat & 0x0010) temp |= 64; - if (dat & 0x0040) temp |= 128; + if (dat & 0x0001) temp |= 1; + if (dat & 0x0004) temp |= 2; + if (dat & 0x0010) temp |= 4; + if (dat & 0x0040) temp |= 8; + if (dat & 0x0100) temp |= 16; + if (dat & 0x0400) temp |= 32; + if (dat & 0x1000) temp |= 64; + if (dat & 0x4000) temp |= 128; return temp; } -uint16_t d86f_encode_byte(int drive, int sync, decoded_t b, decoded_t prev_b) +void disc_calccrc(uint8_t byte, crc_t *crc_var) { - uint8_t encoding = d86f_get_encoding(drive); - uint8_t bits89AB = prev_b.nibbles.nibble0; - uint8_t bits7654 = b.nibbles.nibble1; - uint8_t bits3210 = b.nibbles.nibble0; - uint16_t encoded_7654, encoded_3210, result; - if (encoding > 1) return 0xFF; - if (sync) - { - result = d86f_encode_get_data(b.byte); - if (encoding) - { - switch(b.byte) - { - case 0xA1: return result | d86f_encode_get_clock(0x0A); - case 0xC2: return result | d86f_encode_get_clock(0x14); - case 0xF8: return result | d86f_encode_get_clock(0x03); - case 0xFB: case 0xFE: return result | d86f_encode_get_clock(0x00); - case 0xFC: return result | d86f_encode_get_clock(0x01); - } - } - else - { - switch(b.byte) - { - case 0xF8: case 0xFB: case 0xFE: return result | d86f_encode_get_clock(0xC7); - case 0xFC: return result | d86f_encode_get_clock(0xD7); - } - } - } - bits3210 += ((bits7654 & 3) << 4); - bits7654 += ((bits89AB & 3) << 4); - encoded_3210 = (encoding == 1) ? encoded_mfm[bits3210] : encoded_fm[bits3210]; - encoded_7654 = (encoding == 1) ? encoded_mfm[bits7654] : encoded_fm[bits7654]; - result = (encoded_3210 << 8) | encoded_7654; - return result; + crc_var->word = (crc_var->word << 8) ^ CRCTable[(crc_var->word >> 8)^byte]; } -uint8_t d86f_read_byte(int drive, int side) +static void d86f_calccrc(int drive, uint8_t byte) { - if (d86f[drive].track_is_hole) + disc_calccrc(byte, &(d86f[drive].calc_crc)); +} + +int d86f_word_is_aligned(int drive, uint32_t base_pos) +{ + int adjusted_track_pos = d86f[drive].track_pos; + + if (base_pos == 0xFFFFFFFF) { return 0; } - if (!d86f_is_encoded(drive)) + /* This is very important, it makes sure alignment is detected correctly even across the index hole of a track whose length is not divisible by 16. */ + if (adjusted_track_pos < base_pos) { - return d86f[drive].track_data[side][d86f[drive].track_pos]; - } - else - { - return decodefm(drive, d86f[drive].track_encoded_data[side][d86f[drive].track_pos]); - } -} - -void d86f_write_byte(int drive, int side, uint8_t byte) -{ - int sync = 0; - decoded_t dbyte, dpbyte; - d86f[drive].track_data_byte = byte; - dbyte.byte = byte; - dpbyte.byte = d86f[drive].old_track_data_byte; - - if (d86f[drive].track_is_hole) - { - return; + adjusted_track_pos += d86f_handler[drive].get_raw_size(drive); } - if (!d86f_is_encoded(drive)) + if ((adjusted_track_pos & 15) == (base_pos & 15)) { - d86f[drive].track_data[side][d86f[drive].track_pos] = byte; - } - else - { - if ((d86f[drive].track_byte == BYTE_IAM_SYNC) || - (d86f[drive].track_byte == BYTE_IAM) || - (d86f[drive].track_byte == BYTE_IDAM_SYNC) || - (d86f[drive].track_byte == BYTE_IDAM) || - (d86f[drive].track_byte == BYTE_DATAAM_SYNC) || - (d86f[drive].track_byte == BYTE_DATAAM)) - { - sync = 1; - } - - d86f[drive].track_encoded_data[side][d86f[drive].track_pos] = d86f_encode_byte(drive, sync, dbyte, dpbyte); - } -} - -void d86f_write_byte_direct(int drive, int side, uint8_t byte) -{ - decoded_t dbyte, dpbyte; - d86f[drive].track_data_byte = byte; - dbyte.byte = byte; - dpbyte.byte = d86f[drive].old_track_data_byte; - - if (d86f[drive].track_is_hole) - { - return; - } - - d86f[drive].track_data_byte = byte; - d86f[drive].track_encoded_data[side][d86f[drive].track_pos] = d86f_encode_byte(drive, 0, dbyte, dpbyte); - d86f[drive].track_data_word = d86f[drive].track_encoded_data[side][d86f[drive].track_pos]; -} - -void d86f_write_word(int drive, int side, uint16_t word) -{ - int sync = 0; - - if (d86f[drive].track_is_hole) - { - return; - } - - d86f[drive].track_data_byte = decodefm(drive, word); - d86f[drive].track_data_word = word; - d86f[drive].track_encoded_data[side][d86f[drive].track_pos] = word; -} - -void d86f_poll_write_crc(int drive, int side) -{ - if (d86f[drive].state != STATE_FORMAT) return; - d86f[drive].id_pos = d86f_get_pos(drive); - d86f_write_byte(drive, side, d86f[drive].calc_crc.bytes[d86f[drive].id_pos ^ 1]); -} - -void d86f_poll_advancebyte(int drive, int side) -{ - uint32_t mini_pos, mini_bit; - uint8_t mini_layout, temp_layout; - - if (d86f_handler[drive].side_flags == NULL) - { - fatal("NULL side flags handler\n"); - } - d86f[drive].old_track_byte = d86f[drive].track_byte; - d86f[drive].old_track_index = d86f[drive].track_index; - d86f[drive].old_track_data_byte = d86f[drive].track_data_byte; - d86f[drive].old_track_fuzzy = d86f[drive].track_fuzzy; - d86f[drive].old_track_is_hole = d86f[drive].track_is_hole; - d86f[drive].old_track_data_word = d86f[drive].track_data_word; - - d86f[drive].track_pos++; - d86f[drive].track_pos %= d86f_get_raw_size(drive); - - if (d86f_is_old_style(drive)) - { - temp_layout = d86f[drive].track_layout[side][d86f[drive].track_pos]; - } - else - { - if (d86f_has_mini_table(drive)) - { - d86f_mini_pos(drive, &mini_pos, &mini_bit); - mini_layout = (d86f[drive].track_layout[side][mini_pos] >> mini_bit) & 3; - temp_layout = 0; - if (mini_layout & 1) temp_layout |= 0x20; - if (mini_layout & 2) temp_layout |= BYTE_IS_FUZZY; - } - else - { - temp_layout = 0; - } - } - d86f[drive].track_byte = d86f[drive].track_layout[side][d86f[drive].track_pos] & ~BYTE_IS_FUZZY; - d86f[drive].track_byte = d86f[drive].track_layout[side][d86f[drive].track_pos] & ~0x20; - d86f[drive].track_is_hole = d86f[drive].track_layout[side][d86f[drive].track_pos] & 0x20; - d86f[drive].track_index = (d86f[drive].track_pos == d86f[drive].index_hole_pos[side]); - d86f[drive].track_fuzzy = d86f[drive].track_layout[side][d86f[drive].track_pos] & BYTE_IS_FUZZY; - - if (d86f[drive].track_fuzzy && !d86f[drive].track_is_hole) - { - d86f[drive].track_data_byte = disc_random_generate(); - } - else - { - d86f[drive].track_data_byte = d86f_read_byte(drive, side); - } - - if (d86f_is_encoded(drive)) - { - if (d86f[drive].track_fuzzy && !d86f[drive].track_is_hole) - { - d86f[drive].track_data_word = disc_random_generate(); - d86f[drive].track_data_word <<= 8; - d86f[drive].track_data_word |= disc_random_generate(); - } - else - { - if (d86f[drive].track_is_hole) - { - d86f[drive].track_data_word = 0; - } - else - { - d86f[drive].track_data_word = d86f[drive].track_encoded_data[side][d86f[drive].track_pos]; - } - } - } - else - { - d86f[drive].track_data_word = 0; - } -} - -void d86f_poll_reset(int drive, int side) -{ - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; - d86f[drive].datac = 0; - d86f_poll_advancebyte(drive, side); -} - -int d86f_poll_check_notfound(int drive) -{ - if (d86f[drive].index_count > 1) - { - /* The index hole has been hit twice and we're still in a find state. - This means sector finding has failed for whatever reason. - Abort with sector not found and set state to idle. */ - // pclog("d86f_poll(): Sector not found (%i %i %i %i) (%i, %i)\n", d86f[drive].req_sector.id.c, d86f[drive].req_sector.id.h, d86f[drive].req_sector.id.r, d86f[drive].req_sector.id.n, fdc_get_bitcell_period(), d86f_get_bitcell_period(drive)); - fdc_notfound(); - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; return 1; } else @@ -1924,863 +1180,610 @@ int d86f_poll_check_notfound(int drive) } } -void d86f_poll_write(int drive, int side, uint8_t data, uint8_t type) +/* State 1: Find sector ID */ +void d86f_find_address_mark_fm(int drive, int side, find_t *find, uint16_t req_am, uint16_t other_am, uint16_t ignore_other_am) { - d86f[drive].track_layout[side][d86f[drive].track_pos] = type; - d86f_write_byte(drive, side, data); -} + d86f_get_bit(drive, side); -void d86f_set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) -{ - return; -} - -uint8_t d86f_poll_read_data(int drive, int side, uint16_t pos) -{ - return d86f[drive].track_data_byte; -} - -void d86f_poll_write_data(int drive, int side, uint16_t pos, uint8_t data) -{ - d86f_poll_write(drive, side, data, BYTE_DATA); -} - -void d86f_poll_readwrite(int drive, int side) -{ - int data; - uint16_t max_len; - - if (d86f_read_state_data(drive)) + if (d86f[drive].last_word[side] == req_am) { - max_len = d86f_data_size(drive); - - data = d86f_handler[drive].read_data(drive, side, d86f[drive].datac); - if (d86f[drive].datac < d86f_get_data_len(drive)) - { - fdc_data(data); - } - d86f_calccrc(drive, data); + d86f[drive].calc_crc.word = 0xFFFF; + disc_calccrc(decodefm(drive, d86f[drive].last_word[side]), &(d86f[drive].calc_crc)); + find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; + find->sync_pos = 0xFFFFFFFF; + d86f[drive].preceding_bit[side] = d86f[drive].last_word[side] & 1; + d86f[drive].state++; + return; } - else if (d86f[drive].state == STATE_WRITE_SECTOR) + + if ((ignore_other_am & 2) && (d86f[drive].last_word[side] == other_am)) { - max_len = d86f_data_size(drive); - - if (d86f[drive].datac < d86f_get_data_len(drive)) + d86f[drive].calc_crc.word = 0xFFFF; + disc_calccrc(decodefm(drive, d86f[drive].last_word[side]), &(d86f[drive].calc_crc)); + find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; + find->sync_pos = 0xFFFFFFFF; + if (ignore_other_am & 1) { - data = fdc_getdata(d86f[drive].datac == ((128 << ((uint32_t) d86f[drive].last_sector.id.n)) - 1)); - - if (data == -1) - { - data = 0; - } + /* Skip mode, let's go back to finding ID. */ + d86f[drive].state -= 2; } else { - data = 0; + /* Not skip mode, process the sector anyway. */ + fdc_set_wrong_am(); + d86f[drive].preceding_bit[side] = d86f[drive].last_word[side] & 1; + d86f[drive].state++; } - if (!disable_write) - { - if (d86f_is_old_style(drive)) - { - d86f_handler[drive].write_data(drive, side, d86f[drive].datac, data); - } - else - { - d86f_write_byte_direct(drive, side, data); - } - } - d86f_calccrc(drive, data & 0xff); + return; } - else if (d86f[drive].state == STATE_COMPARE_SECTOR) - { - max_len = d86f_data_size(drive); +} - if (d86f[drive].datac < d86f_get_data_len(drive)) - { - data = fdc_getdata(d86f[drive].datac == ((128 << ((uint32_t) d86f[drive].last_sector.id.n)) - 1)); +/* When writing in FM mode, we find the beginning of the address mark by looking for 352 (22 * 16) set bits (gap fill = 0xFF, 0xFFFF FM-encoded). */ +void d86f_write_find_address_mark_fm(int drive, int side, find_t *find) +{ + d86f_get_bit(drive, side); - if (data == -1) - { - data = 0; - } - } - else - { - data = 0; - } - switch(fdc_get_compare_condition()) - { - case 0: /* SCAN EQUAL */ - if ((data == d86f[drive].track_data_byte) || (data == 0xFF)) - { - d86f[drive].satisfying_bytes++; - } - break; - case 1: /* SCAN LOW OR EQUAL */ - if ((data <= d86f[drive].track_data_byte) || (data == 0xFF)) - { - d86f[drive].satisfying_bytes++; - } - break; - case 2: /* SCAN HIGH OR EQUAL */ - if ((data >= d86f[drive].track_data_byte) || (data == 0xFF)) - { - d86f[drive].satisfying_bytes++; - } - break; - } - d86f_calccrc(drive, data & 0xff); - } - else if (d86f_read_state_crc(drive)) + if (d86f[drive].last_word[side] & 1) { - max_len = 2; - d86f[drive].track_crc.bytes[d86f[drive].datac ^ 1] = d86f[drive].track_data_byte; - } - else if (d86f[drive].state == STATE_WRITE_SECTOR_CRC) - { - max_len = 2; - if (!disable_write) + find->sync_marks++; + if (find->sync_marks == 352) { - if (d86f_is_old_style(drive)) + d86f[drive].calc_crc.word = 0xFFFF; + d86f[drive].preceding_bit[side] = 1; + find->sync_marks = 0; + d86f[drive].state++; + return; + } + } + + /* If we hadn't found enough set bits but have found a clear bit, null the counter of set bits. */ + if (!(d86f[drive].last_word[side] & 1)) + { + find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; + find->sync_pos = 0xFFFFFFFF; + } +} + +void d86f_find_address_mark_mfm(int drive, int side, find_t *find, uint16_t req_am, uint16_t other_am, uint16_t ignore_other_am) +{ + d86f_get_bit(drive, side); + + if (d86f[drive].last_word[side] == 0x4489) + { + find->sync_marks++; + find->sync_pos = d86f[drive].track_pos; + // pclog("Sync marks: %i\n", find->sync_marks); + + return; + } + + if ((d86f[drive].last_word[side] == req_am) && (find->sync_marks >= 3)) + { + if (d86f_word_is_aligned(drive, find->sync_pos)) + { + d86f[drive].calc_crc.word = 0xCDB4; + disc_calccrc(decodefm(drive, d86f[drive].last_word[side]), &(d86f[drive].calc_crc)); + find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; + find->sync_pos = 0xFFFFFFFF; + // pclog("AM found (%04X) (%02X)\n", req_am, d86f[drive].state); + d86f[drive].preceding_bit[side] = d86f[drive].last_word[side] & 1; + d86f[drive].state++; + return; + } + } + + if ((ignore_other_am & 2) && (d86f[drive].last_word[side] == other_am) && (find->sync_marks >= 3)) + { + if (d86f_word_is_aligned(drive, find->sync_pos)) + { + d86f[drive].calc_crc.word = 0xCDB4; + disc_calccrc(decodefm(drive, d86f[drive].last_word[side]), &(d86f[drive].calc_crc)); + find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; + find->sync_pos = 0xFFFFFFFF; + if (ignore_other_am & 1) { - d86f_poll_write(drive, side, d86f[drive].calc_crc.bytes[d86f[drive].datac ^ 1], BYTE_DATA_CRC); + /* Skip mode, let's go back to finding ID. */ + d86f[drive].state -= 2; } else { - d86f_write_byte_direct(drive, side, d86f[drive].calc_crc.bytes[d86f[drive].datac ^ 1]); + /* Not skip mode, process the sector anyway. */ + fdc_set_wrong_am(); + d86f[drive].preceding_bit[side] = d86f[drive].last_word[side] & 1; + d86f[drive].state++; } + return; } } - else if (d86f_read_state_gap3(drive)) + + if (d86f[drive].last_word[side] != 0x4489) { - max_len = fdc_get_gap(); - if (d86f[drive].datac == (fdc_get_gap() - 1)) + if (d86f_word_is_aligned(drive, find->sync_pos)) { - d86f_poll_reset(drive, side); - if ((d86f[drive].track_crc.word != d86f[drive].calc_crc.word) && d86f_handler[drive].check_crc) + find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; + find->sync_pos = 0xFFFFFFFF; + } + } +} + +/* When writing in MFM mode, we find the beginning of the address mark by looking for 3 0xA1 sync bytes. */ +void d86f_write_find_address_mark_mfm(int drive, int side, find_t *find) +{ + d86f_get_bit(drive, side); + + if (d86f[drive].last_word[side] == 0x4489) + { + find->sync_marks++; + find->sync_pos = d86f[drive].track_pos; + if (find->sync_marks == 3) + { + d86f[drive].calc_crc.word = 0xCDB4; + d86f[drive].preceding_bit[side] = 1; + find->sync_marks = 0; + d86f[drive].state++; + return; + } + } + + /* If we hadn't found enough address mark sync marks, null the counter. */ + if (d86f[drive].last_word[side] != 0x4489) + { + if (d86f_word_is_aligned(drive, find->sync_pos)) + { + find->sync_marks = find->bits_obtained = find->bytes_obtained = 0; + find->sync_pos = 0xFFFFFFFF; + } + } +} + +/* State 2: Read sector ID and CRC*/ +void d86f_read_sector_id(int drive, int side, int match) +{ + uint16_t temp; + + if (d86f[drive].id_find.bits_obtained) + { + if (!(d86f[drive].id_find.bits_obtained & 15)) + { + /* We've got a byte. */ + if (d86f[drive].id_find.bytes_obtained < 4) { - // pclog("d86f_poll(): Data CRC error (%i %i %i %i) (%04X %04X)\n", d86f[drive].req_sector.id.c, d86f[drive].req_sector.id.h, d86f[drive].req_sector.id.r, d86f[drive].req_sector.id.n, d86f[drive].track_crc.word, d86f[drive].calc_crc.word); - fdc_finishread(); - fdc_datacrcerror(); + d86f[drive].last_sector.byte_array[d86f[drive].id_find.bytes_obtained] = decodefm(drive, d86f[drive].last_word[side]); + disc_calccrc(d86f[drive].last_sector.byte_array[d86f[drive].id_find.bytes_obtained], &(d86f[drive].calc_crc)); } - else + else if ((d86f[drive].id_find.bytes_obtained >= 4) && (d86f[drive].id_find.bytes_obtained < 6)) { - // pclog("Read finished (%i %i %i %i)\n", d86f[drive].req_sector.id.c, d86f[drive].req_sector.id.h, d86f[drive].req_sector.id.r, d86f[drive].req_sector.id.n); - if (d86f[drive].state == STATE_COMPARE_SECTOR_GAP3) + d86f[drive].track_crc.bytes[(d86f[drive].id_find.bytes_obtained & 1) ^ 1] = decodefm(drive, d86f[drive].last_word[side]); + } + d86f[drive].id_find.bytes_obtained++; + + if (d86f[drive].id_find.bytes_obtained == 6) + { + /* We've got the ID. */ + if (d86f[drive].calc_crc.word != d86f[drive].track_crc.word) { - fdc_sector_finishcompare((d86f[drive].satisfying_bytes == ((128 << ((uint32_t) d86f[drive].last_sector.id.n)) - 1)) ? 1 : 0); + d86f[drive].id_find.sync_marks = d86f[drive].id_find.bits_obtained = d86f[drive].id_find.bytes_obtained = 0; + printf("%04X != %04X (%08X)\n", d86f[drive].track_crc.word, d86f[drive].calc_crc.word, d86f[drive].last_sector.dword); + if ((d86f[drive].state != STATE_02_READ_ID) && (d86f[drive].state != STATE_0A_READ_ID)) + { + d86f[drive].error_condition = 0; + d86f[drive].state = STATE_IDLE; + fdc_finishread(); + fdc_headercrcerror(); + } + else if (d86f[drive].state == STATE_0A_READ_ID) + { + d86f[drive].state--; + } + else + { + d86f[drive].error_condition |= 1; /* Mark that there was an ID CRC error. */ + d86f[drive].state++; + } + } + else if ((d86f[drive].calc_crc.word == d86f[drive].track_crc.word) && (d86f[drive].state == STATE_0A_READ_ID)) + { + /* CRC is valid and this is a read sector ID command. */ + d86f[drive].id_find.sync_marks = d86f[drive].id_find.bits_obtained = d86f[drive].id_find.bytes_obtained = d86f[drive].error_condition = 0; + fdc_sectorid(d86f[drive].last_sector.id.c, d86f[drive].last_sector.id.h, d86f[drive].last_sector.id.r, d86f[drive].last_sector.id.n, 0, 0); + d86f[drive].state = STATE_IDLE; } else { - fdc_sector_finishread(); + /* CRC is valid. */ + // pclog("Sector ID found: %08X\n", last_sector.dword); + d86f[drive].id_find.sync_marks = d86f[drive].id_find.bits_obtained = d86f[drive].id_find.bytes_obtained = 0; + if ((d86f[drive].last_sector.dword == d86f[drive].req_sector.dword) || !match) + { + // pclog("ID read (%02X)\n", d86f[drive].state); + d86f_handler[drive].set_sector(drive, side, d86f[drive].last_sector.id.c, d86f[drive].last_sector.id.h, d86f[drive].last_sector.id.r, d86f[drive].last_sector.id.n); + d86f[drive].state++; + } + else + { + d86f[drive].state--; + } } } - return; } } - else if (d86f[drive].state == STATE_WRITE_SECTOR_GAP3) + + d86f_get_bit(drive, side); + + d86f[drive].id_find.bits_obtained++; +} + +uint8_t d86f_get_data(int drive, int base) +{ + int data; + + if (d86f[drive].data_find.bytes_obtained < (d86f_get_data_len(drive) + base)) { - max_len = fdc_get_gap(); - if (!disable_write && !d86f[drive].datac) + data = fdc_getdata(d86f[drive].data_find.bytes_obtained == (d86f_get_data_len(drive) + base - 1)); + if (data == -1) { - if (d86f_is_old_style(drive)) + data = 0; + } + } + else + { + data = 0; + } + + return data; +} + +void d86f_compare_byte(int drive, uint8_t received_byte, uint8_t disk_byte) +{ + switch(fdc_get_compare_condition()) + { + case 0: /* SCAN EQUAL */ + if ((received_byte == disk_byte) || (received_byte == 0xFF)) { - d86f_poll_write(drive, side, fdc_is_mfm() ? 0x4E : 0xFF, BYTE_GAP3); + d86f[drive].satisfying_bytes++; + } + break; + case 1: /* SCAN LOW OR EQUAL */ + if ((received_byte <= disk_byte) || (received_byte == 0xFF)) + { + d86f[drive].satisfying_bytes++; + } + break; + case 2: /* SCAN HIGH OR EQUAL */ + if ((received_byte >= disk_byte) || (received_byte == 0xFF)) + { + d86f[drive].satisfying_bytes++; + } + break; + } +} + +/* State 4: Read sector data and CRC*/ +void d86f_read_sector_data(int drive, int side) +{ + int data = 0; + int recv_data = 0; + uint16_t temp; + uint32_t sector_len = d86f[drive].last_sector.id.n; + uint32_t crc_pos = 0; + sector_len = 1 << (7 + sector_len); + crc_pos = sector_len + 2; + + if (d86f[drive].data_find.bits_obtained) + { + if (!(d86f[drive].data_find.bits_obtained & 15)) + { + /* We've got a byte. */ + if (d86f[drive].data_find.bytes_obtained < sector_len) + { + data = decodefm(drive, d86f[drive].last_word[side]); + if (d86f[drive].state == STATE_11_SCAN_DATA) + { + /* Scan/compare command. */ + recv_data = d86f_get_data(drive, 0); + d86f_compare_byte(drive, recv_data, data); + } + else + { + if (d86f[drive].data_find.bytes_obtained < d86f_get_data_len(drive)) + { + if (d86f[drive].state != STATE_16_VERIFY_DATA) + { + fdc_data(data); + } + } + } + disc_calccrc(data, &(d86f[drive].calc_crc)); + } + else if (d86f[drive].data_find.bytes_obtained < crc_pos) + { + d86f[drive].track_crc.bytes[(d86f[drive].data_find.bytes_obtained - sector_len) ^ 1] = decodefm(drive, d86f[drive].last_word[side]); + } + d86f[drive].data_find.bytes_obtained++; + + if (d86f[drive].data_find.bytes_obtained == (crc_pos + fdc_get_gap())) + { + /* We've got the data. */ + if ((d86f[drive].calc_crc.word != d86f[drive].track_crc.word) && (d86f[drive].state != STATE_02_READ_DATA)) + { + printf("%04X != %04X (%08X)\n", d86f[drive].track_crc.word, d86f[drive].calc_crc.word, d86f[drive].last_sector.dword); + d86f[drive].data_find.sync_marks = d86f[drive].data_find.bits_obtained = d86f[drive].data_find.bytes_obtained = 0; + d86f[drive].error_condition = 0; + d86f[drive].state = STATE_IDLE; + fdc_finishread(); + fdc_datacrcerror(); + } + else if ((d86f[drive].calc_crc.word != d86f[drive].track_crc.word) && (d86f[drive].state == STATE_02_READ_DATA)) + { + // printf("%04X != %04X (%08X)\n", d86f[drive].track_crc.word, d86f[drive].calc_crc.word, d86f[drive].last_sector.dword); + d86f[drive].data_find.sync_marks = d86f[drive].data_find.bits_obtained = d86f[drive].data_find.bytes_obtained = 0; + d86f[drive].error_condition |= 2; /* Mark that there was a data error. */ + d86f[drive].state = STATE_IDLE; + fdc_track_finishread(d86f[drive].error_condition); + } + else + { + /* CRC is valid. */ + d86f[drive].data_find.sync_marks = d86f[drive].data_find.bits_obtained = d86f[drive].data_find.bytes_obtained = 0; + d86f[drive].error_condition = 0; + if (d86f[drive].state == STATE_11_SCAN_DATA) + { + d86f[drive].state = STATE_IDLE; + fdc_sector_finishcompare((d86f[drive].satisfying_bytes == ((128 << ((uint32_t) d86f[drive].last_sector.id.n)) - 1)) ? 1 : 0); + } + else + { + d86f[drive].state = STATE_IDLE; + fdc_sector_finishread(); + } + } + } + } + } + + d86f_get_bit(drive, side); + + d86f[drive].data_find.bits_obtained++; +} + +void d86f_write_sector_data(int drive, int side, int mfm, uint16_t am) +{ + uint16_t bit_pos; + uint16_t temp; + uint32_t sector_len = d86f[drive].last_sector.id.n; + uint32_t crc_pos = 0; + sector_len = (1 << (7 + sector_len)) + 1; + crc_pos = sector_len + 2; + + if (!(d86f[drive].data_find.bits_obtained & 15)) + { + if (d86f[drive].data_find.bytes_obtained < crc_pos) + { + if (!d86f[drive].data_find.bytes_obtained) + { + /* We're writing the address mark. */ + d86f[drive].current_byte[side] = am; + } + else if (d86f[drive].data_find.bytes_obtained < sector_len) + { + /* We're in the data field of the sector, read byte from FDC and request new byte. */ + d86f[drive].current_byte[side] = d86f_get_data(drive, 1); + d86f_handler[drive].write_data(drive, side, d86f[drive].data_find.bytes_obtained - 1, d86f[drive].current_byte[side]); } else { - d86f_write_byte_direct(drive, side, fdc_is_mfm() ? 0x4E : 0xFF); + /* We're in the data field of the sector, use a CRC byte. */ + d86f[drive].current_byte[side] = d86f[drive].calc_crc.bytes[(d86f[drive].data_find.bytes_obtained & 1)]; + // pclog("BO: %04X (%02X)\n", d86f[drive].data_find.bytes_obtained, d86f[drive].current_byte[side]); + } + + d86f[drive].current_bit[side] = (15 - (d86f[drive].data_find.bits_obtained & 15)) >> 1; + + /* Write the bit. */ + temp = (d86f[drive].current_byte[side] >> d86f[drive].current_bit[side]) & 1; + if ((!temp && !d86f[drive].preceding_bit[side]) || !mfm) + { + temp |= 2; + } + + /* This is an even bit, so write the clock. */ + if (!d86f[drive].data_find.bytes_obtained) + { + /* Address mark, write bit directly. */ + d86f_put_bit(drive, side, am >> 15); + } + else + { + d86f_put_bit(drive, side, temp >> 1); + } + + if (d86f[drive].data_find.bytes_obtained < sector_len) + { + /* This is a data byte, so CRC it. */ + if (!d86f[drive].data_find.bytes_obtained) + { + disc_calccrc(decodefm(drive, am), &(d86f[drive].calc_crc)); + } + else + { + disc_calccrc(d86f[drive].current_byte[side], &(d86f[drive].calc_crc)); + } } } - if (d86f[drive].datac == (max_len - 1)) + } + else + { + if (d86f[drive].data_find.bytes_obtained < crc_pos) { - if (!disable_write) + /* Encode the bit. */ + bit_pos = 15 - (d86f[drive].data_find.bits_obtained & 15); + d86f[drive].current_bit[side] = bit_pos >> 1; + + temp = (d86f[drive].current_byte[side] >> d86f[drive].current_bit[side]) & 1; + if ((!temp && !d86f[drive].preceding_bit[side]) || !mfm) { - d86f_handler[drive].writeback(drive); + temp |= 2; + } + + if (!d86f[drive].data_find.bytes_obtained) + { + /* Address mark, write directly. */ + d86f_put_bit(drive, side, am >> bit_pos); + if (!(bit_pos & 1)) + { + d86f[drive].preceding_bit[side] = am >> bit_pos; + } + } + else + { + if (bit_pos & 1) + { + /* Clock bit */ + d86f_put_bit(drive, side, temp >> 1); + } + else + { + /* Data bit */ + d86f_put_bit(drive, side, temp & 1); + d86f[drive].preceding_bit[side] = temp & 1; + } + } + } + + if ((d86f[drive].data_find.bits_obtained & 15) == 15) + { + d86f[drive].data_find.bytes_obtained++; + + if (d86f[drive].data_find.bytes_obtained == (crc_pos + fdc_get_gap())) + { + /* We've written the data. */ + d86f[drive].data_find.sync_marks = d86f[drive].data_find.bits_obtained = d86f[drive].data_find.bytes_obtained = 0; + d86f[drive].error_condition = 0; + d86f[drive].state = STATE_IDLE; + d86f_handler[drive].writeback(drive); + fdc_sector_finishread(); + return; } - d86f_poll_reset(drive, side); - // pclog("Write finished (%i %i %i %i)\n", d86f[drive].req_sector.id.c, d86f[drive].req_sector.id.h, d86f[drive].req_sector.id.r, d86f[drive].req_sector.id.n); - fdc_sector_finishread(drive); - return; } } - d86f[drive].datac++; - d86f_poll_advancebyte(drive, side); + d86f[drive].data_find.bits_obtained++; +} - if (d86f[drive].datac >= max_len) +void d86f_advance_bit(int drive, int side) +{ + d86f[drive].track_pos++; + d86f[drive].track_pos %= d86f_handler[drive].get_raw_size(drive); + + if (d86f[drive].track_pos == d86f_handler[drive].index_hole_pos(drive, side)) d86f_handler[drive].read_revolution(drive); + + if ((d86f[drive].track_pos == d86f_handler[drive].index_hole_pos(drive, side)) && (d86f[drive].state != STATE_IDLE)) d86f[drive].index_count++; +} + +void d86f_advance_word(int drive, int side) +{ + d86f[drive].track_pos += 16; + d86f[drive].track_pos %= d86f_handler[drive].get_raw_size(drive); + + if (d86f[drive].track_pos == d86f_handler[drive].index_hole_pos(drive, side)) d86f_handler[drive].read_revolution(drive); + + if ((d86f[drive].track_pos == d86f_handler[drive].index_hole_pos(drive, side)) && (d86f[drive].state != STATE_IDLE)) d86f[drive].index_count++; +} + +void d86f_spin_to_index(int drive, int side) +{ + d86f_get_bit(drive, side); + d86f_get_bit(drive, side ^ 1); + + d86f_advance_bit(drive, side); + + if (d86f[drive].index_count == 1) { - d86f[drive].datac = 0; + if (d86f[drive].state == STATE_0D_SPIN_TO_INDEX) + { + /* When starting format, reset format state to the beginning. */ + d86f[drive].preceding_bit[side] = 1; + d86f[drive].format_state = FMT_PRETRK_GAP0; + } d86f[drive].state++; } } -void d86f_poll_find_nf(int drive, int side) +void d86f_write_direct_common(int drive, int side, uint16_t byte, uint8_t type, uint32_t pos) { - uint8_t mfm = 0; - uint8_t am_len = 0; - uint8_t requested_am = 0; - mfm = fdc_is_mfm(); - am_len = mfm ? 4 : 1; - requested_am = fdc_is_deleted() ? 0xF8 : 0xFB; + uint16_t encoded_byte, mask_data, mask_surface, mask_hole, mask_fuzzy; + decoded_t dbyte, dpbyte; - if (d86f[drive].track_index) + dbyte.byte = byte; + dpbyte.byte = d86f[drive].preceding_bit[side]; + d86f[drive].preceding_bit[side] = encoded_byte & 1; + + if (type == 0) { - // pclog("d86f_poll_find_nf(): Index pulse\n"); - index_pulse(drive); - d86f[drive].index_count++; - } - - switch(d86f[drive].track_byte) - { - case BYTE_DATAAM_SYNC: - if ((d86f[drive].id_match) || d86f_find_state_nf_ignore_id(drive)) - { - d86f[drive].data_am_counter++; - - if (mfm) - { - d86f_calccrc(drive, d86f[drive].track_data_byte); - } - } - break; - - case BYTE_IDAM_SYNC: - d86f[drive].id_am_counter++; - - if (mfm) - { - d86f_calccrc(drive, d86f[drive].track_data_byte); - } - break; - - case BYTE_DATAAM: - if ((d86f[drive].id_match) || d86f_find_state_nf_ignore_id(drive)) - { - if ((d86f[drive].state == STATE_WRITE_FIND_SECTOR) && (d86f[drive].data_am_counter == (am_len - 1))) - { - d86f_poll_write(drive, side, fdc_is_deleted() ? 0xF8 : 0xFB, BYTE_DATAAM); - } - else if ((d86f[drive].state != STATE_WRITE_FIND_SECTOR) && (d86f[drive].data_am_counter == (am_len - 1))) - { - if (d86f[drive].track_data_byte != requested_am) - { - fdc_set_wrong_am(); - if (fdc_is_sk()) - { - /* Read command in skip mode, invalidate the data AM counter in order to ignore the sector. */ - d86f[drive].data_am_counter = 0; - } - } - } - - d86f[drive].data_am_counter++; - d86f[drive].id_match = 0; - - d86f_calccrc(drive, d86f[drive].track_data_byte); - } - break; - - case BYTE_IDAM: - if (d86f_can_read_address(drive)) d86f[drive].id_am_counter++; - d86f_calccrc(drive, d86f[drive].track_data_byte); - break; - - case BYTE_ID: - d86f[drive].id_pos = d86f_get_pos(drive); - d86f[drive].last_sector.byte_array[d86f[drive].id_pos] = d86f[drive].track_data_byte; - d86f_calccrc(drive, d86f[drive].track_data_byte); - if (d86f[drive].id_am_counter == am_len) - { - d86f[drive].id_counter++; - } - break; - case BYTE_ID_CRC: - // pclog("Last sector: %08X\n", d86f[drive].last_sector.dword); - d86f[drive].id_pos = d86f_get_pos(drive); - d86f[drive].track_crc.bytes[d86f[drive].id_pos ^ 1] = d86f[drive].track_data_byte; - break; - } - - d86f_poll_advancebyte(drive, side); - - if (d86f_poll_check_notfound(drive)) return; - - if (d86f[drive].track_byte != d86f[drive].old_track_byte) - { - d86f[drive].section_pos = d86f[drive].track_pos; - - switch(d86f[drive].track_byte) + /* Byte write. */ + encoded_byte = d86f_encode_byte(drive, 0, dbyte, dpbyte); + if (!d86f_reverse_bytes(drive)) { - case BYTE_IDAM_SYNC: - case BYTE_DATAAM_SYNC: - if (mfm) - { - d86f[drive].calc_crc.word = 0xffff; - } - break; - case BYTE_IDAM: - case BYTE_DATAAM: - if (!mfm) - { - d86f[drive].calc_crc.word = 0xffff; - } - break; - case BYTE_GAP2: - d86f[drive].id_match = 0; - d86f[drive].data_am_counter = 0; - if (d86f[drive].id_counter != 4) - { - d86f[drive].id_am_counter = d86f[drive].id_counter = 0; - break; - } - d86f[drive].id_am_counter = d86f[drive].id_counter = 0; - if ((d86f[drive].req_sector.dword == d86f[drive].last_sector.dword) || (d86f[drive].state == STATE_READ_FIND_ADDRESS)) - { - if ((d86f[drive].track_crc.word != d86f[drive].calc_crc.word) && d86f_handler[drive].check_crc) - { - if (d86f[drive].state != STATE_READ_FIND_ADDRESS) - { - // pclog("d86f_poll(): Header CRC error (mfm=%i) (%i %i %i %i) (%04X %04X)\n", d86f_is_mfm(drive), d86f[drive].req_sector.id.c, d86f[drive].req_sector.id.h, d86f[drive].req_sector.id.r, d86f[drive].req_sector.id.n, d86f[drive].track_crc.word, d86f[drive].calc_crc.word); - fdc_finishread(); - fdc_headercrcerror(); - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; - return; - } - else - { - // pclog("d86f_poll(): Header CRC error at read sector ID (mfm=%i) (%i %i %i %i) (%04X %04X)\n", d86f_is_mfm(drive), d86f[drive].req_sector.id.c, d86f[drive].req_sector.id.h, d86f[drive].req_sector.id.r, d86f[drive].req_sector.id.n, d86f[drive].track_crc.word, d86f[drive].calc_crc.word); - } - } - else - { - if (d86f[drive].state != STATE_READ_FIND_ADDRESS) d86f[drive].id_match = 1; - - // pclog("Read sector ID in find state: %i %i %i %i (sought: %i, %i, %i, %i)\n", d86f[drive].last_sector.id.c, d86f[drive].last_sector.id.h, d86f[drive].last_sector.id.r, d86f[drive].last_sector.id.n, d86f[drive].req_sector.id.c, d86f[drive].req_sector.id.h, d86f[drive].req_sector.id.r, d86f[drive].req_sector.id.n); - - if (d86f[drive].state == STATE_READ_FIND_ADDRESS) - { - // pclog("Reading sector ID (%i %i %i %i)...\n", d86f[drive].last_sector.id.c, d86f[drive].last_sector.id.h, d86f[drive].last_sector.id.r, d86f[drive].last_sector.id.n); - fdc_sectorid(d86f[drive].last_sector.id.c, d86f[drive].last_sector.id.h, d86f[drive].last_sector.id.r, d86f[drive].last_sector.id.n, 0, 0); - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; - } - else - { - d86f_handler[drive].set_sector(drive, side, d86f[drive].last_sector.id.c, d86f[drive].last_sector.id.h, d86f[drive].last_sector.id.r, d86f[drive].last_sector.id.n); - } - } - } - break; - case BYTE_DATA: - d86f[drive].datac = 0; - switch (d86f[drive].state) - { - case STATE_READ_FIND_SECTOR: - case STATE_WRITE_FIND_SECTOR: - case STATE_READ_FIND_FIRST_SECTOR: - case STATE_READ_FIND_NEXT_SECTOR: - case STATE_COMPARE_FIND_SECTOR: - /* If the data address mark counter is anything other than 0, then either the ID matches or the FDC is in the ignore sector ID mode (ie. the READ TRACK command). - Also, the bitcell period, etc. are already checked during the wait state which is designed to never end in case of a mismatch. - Therefore, ensuring the data address mark acounter is at a correct length is all we need to do. */ - if (d86f[drive].data_am_counter == am_len) - { - // pclog("Changing state...\n"); - d86f[drive].state++; - } - /* Data address mark counter always reset to 0. */ - d86f[drive].data_am_counter = 0; - break; - } - break; + mask_data = encoded_byte >> 8; + encoded_byte &= 0xFF; + encoded_byte <<= 8; + encoded_byte |= mask_data; } } -} - -void d86f_poll_find_format(int drive, int side) -{ - d86f_poll_advancebyte(drive, side); - - if (d86f[drive].track_index) - { - // pclog("Index hole hit, formatting track...\n"); - if (!d86f_is_old_style(drive)) - { - d86f[drive].format_state = FMT_PRETRK_GAP0; - d86f[drive].sector_count = d86f[drive].datac = 0; - } - d86f[drive].state = STATE_FORMAT; - return; - } -} - -void d86f_poll_format(int drive, int side) -{ - int data; - - switch(d86f[drive].track_byte) - { - case BYTE_GAP0: - case BYTE_GAP1: - case BYTE_GAP2: - case BYTE_GAP3: - if (!disable_write) - { - d86f_write_byte(drive, side, fdc_is_mfm() ? 0x4E : 0xFF); - } - break; - case BYTE_IAM_SYNC: - if (!disable_write) - { - d86f_write_byte(drive, side, 0xC2); - } - break; - case BYTE_IAM: - if (!disable_write) - { - d86f_write_byte(drive, side, 0xFC); - } - break; - case BYTE_ID_SYNC: - d86f[drive].id_pos = d86f_get_pos(drive); - - if (d86f[drive].id_pos <= 3) - { - data = fdc_getdata(0); - if ((data == -1) && (d86f[drive].id_pos < 3)) - { - data = 0; - } - if (d86f[drive].version != 0063) - { - d86f[drive].format_sector_id.byte_array[d86f[drive].id_pos] = data & 0xff; - } - // pclog("format_sector_id[%i] = %i\n", d86f[drive].id_pos, d86f[drive].format_sector_id.byte_array[d86f[drive].id_pos]); - if (d86f[drive].id_pos == 3) - { - fdc_stop_id_request(); - if (d86f[drive].version != 0063) - { - d86f_handler[drive].set_sector(drive, side, d86f[drive].format_sector_id.id.c, d86f[drive].format_sector_id.id.h, d86f[drive].format_sector_id.id.r, d86f[drive].format_sector_id.id.n); - } - // pclog("Formatting sector: %08X...\n", d86f[drive].format_sector_id.dword); - } - } - - case BYTE_I_SYNC: - case BYTE_DATA_SYNC: - if (!disable_write) - { - d86f_write_byte(drive, side, 0); - } - break; - case BYTE_IDAM_SYNC: - case BYTE_DATAAM_SYNC: - if (!disable_write) - { - d86f_write_byte(drive, side, 0xA1); - } - if (d86f_is_mfm(drive)) - { - d86f_calccrc(drive, d86f[drive].track_data_byte); - } - break; - case BYTE_IDAM: - case BYTE_DATAAM: - // pclog("CRC reset: %02X\n", d86f[drive].track_byte); - - if (!disable_write) - { - d86f_write_byte(drive, side, (d86f[drive].track_byte == BYTE_IDAM) ? 0xFE : 0xFB); - } - d86f_calccrc(drive, d86f[drive].track_data_byte); - break; - case BYTE_ID: - d86f[drive].id_pos = d86f_get_pos(drive); - if (d86f[drive].version != 0063) - { - if (!disable_write) - { - d86f_write_byte(drive, side, d86f[drive].format_sector_id.byte_array[d86f[drive].id_pos]); - } - } - else - { - d86f[drive].format_sector_id.byte_array[d86f[drive].id_pos] = d86f[drive].track_data_byte; - if (d86f[drive].id_pos == 3) - { - d86f_handler[drive].set_sector(drive, side, d86f[drive].format_sector_id.id.c, d86f[drive].format_sector_id.id.h, d86f[drive].format_sector_id.id.r, d86f[drive].format_sector_id.id.n); - } - } - d86f_calccrc(drive, d86f[drive].track_data_byte); - break; - case BYTE_DATA: - d86f[drive].id_pos = d86f_get_pos(drive); - if (!disable_write) - { - d86f_handler[drive].write_data(drive, side, d86f[drive].id_pos, d86f[drive].fill); - } - d86f_calccrc(drive, d86f[drive].fill); - break; - case BYTE_ID_CRC: - case BYTE_DATA_CRC: - d86f_poll_write_crc(drive, side); - break; - } - - d86f_poll_advancebyte(drive, side); - - if (d86f[drive].track_index) - { - // pclog("Track position %08X\n", d86f[drive].track_pos); - // pclog("Index hole hit again, format finished\n"); - d86f[drive].state = STATE_IDLE; - if (!disable_write) d86f_handler[drive].writeback(drive); - fdc_sector_finishread(drive); - d86f[drive].index_count = 0; - return; - } - - if (d86f[drive].track_byte != d86f[drive].old_track_byte) - { - // pclog("Track byte: %02X, old: %02X\n", track_byte, old_track_byte); - d86f[drive].section_pos = d86f[drive].track_pos; - - switch(d86f[drive].track_byte & ~BYTE_INDEX_HOLE) - { - case BYTE_IDAM: - case BYTE_DATAAM: - if (!d86f_is_mfm(drive)) - { - d86f[drive].calc_crc.word = 0xffff; - } - break; - case BYTE_IDAM_SYNC: - case BYTE_DATAAM_SYNC: - if (d86f_is_mfm(drive)) - { - d86f[drive].calc_crc.word = 0xffff; - } - break; - case BYTE_ID_SYNC: - // pclog("Requesting next sector ID...\n"); - fdc_request_next_sector_id(); - break; - case BYTE_GAP2: - d86f[drive].last_sector.dword = d86f[drive].format_sector_id.dword; - break; - case BYTE_DATA: - d86f[drive].datac = 0; - break; - } - } -} - -void d86f_poll_read_id(int drive, int side) -{ - uint16_t max_len; - - if (d86f[drive].id_read_state == 0) - { - max_len = 4; - d86f[drive].last_sector.byte_array[d86f[drive].datac] = d86f[drive].track_data_byte; - d86f_calccrc(drive, d86f[drive].track_data_byte); - } - else if (d86f[drive].id_read_state == 1) - { - max_len = 2; - d86f[drive].track_crc.bytes[d86f[drive].datac ^ 1] = d86f[drive].track_data_byte; - - if (d86f[drive].datac == 1) - { - if ((d86f[drive].track_crc.word != d86f[drive].calc_crc.word) && d86f_handler[drive].check_crc) - { - // pclog("d86f_poll(): Header CRC error (%i %i %i %i) (%04X %04X)\n", d86f[drive].req_sector.id.c, d86f[drive].req_sector.id.h, d86f[drive].req_sector.id.r, d86f[drive].req_sector.id.n, d86f[drive].track_crc.word, d86f[drive].calc_crc.word); - fdc_finishread(); - fdc_headercrcerror(); - } - else - { - d86f[drive].idam_found = 0; - - if ((d86f[drive].req_sector.dword == d86f[drive].last_sector.dword) && (d86f[drive].state != STATE_READ_FIND_ADDRESS)) - { - d86f[drive].id_was_read = 1; - d86f[drive].id_match = 1; - } - else - { - d86f[drive].id_was_read = 0; - d86f[drive].id_match = 0; - } - - if (d86f[drive].state == STATE_READ_FIND_ADDRESS) - { - // pclog("Reading sector ID (%i %i %i %i)...\n", d86f[drive].last_sector.id.c, d86f[drive].last_sector.id.h, d86f[drive].last_sector.id.r, d86f[drive].last_sector.id.n); - fdc_sectorid(d86f[drive].last_sector.id.c, d86f[drive].last_sector.id.h, d86f[drive].last_sector.id.r, d86f[drive].last_sector.id.n, 0, 0); - d86f[drive].state = STATE_IDLE; - d86f[drive].index_count = 0; - } - /* else - { - pclog("Found sector ID (%i %i %i %i)...\n", d86f[drive].last_sector.id.c, d86f[drive].last_sector.id.h, d86f[drive].last_sector.id.r, d86f[drive].last_sector.id.n); - } */ - } - return; - } - } - - d86f[drive].datac++; - d86f_poll_advancebyte(drive, side); - - if (d86f[drive].datac >= max_len) - { - d86f[drive].datac = 0; - d86f[drive].id_read_state++; - // pclog("Read ID: %04X is bigger than %04X, new state: %02X\n", d86f[drive].datac, max_len, d86f[drive].id_read_state); - } -} - -void d86f_poll_find_am_fm(int drive, int side) -{ - uint16_t requested_am = fdc_is_deleted() ? 0x6AF5 : 0x6FF5; - - switch (d86f[drive].track_data_word) - { - case 0x7EF5: /* ID address mark */ - d86f[drive].idam_found = 1; /* Mark ID address mark as found so on the next byte, we're in the ID reading handler. */ - d86f[drive].id_read_state = 0; - d86f[drive].datac = 0; - d86f[drive].calc_crc.word = 0xffff; - d86f_calccrc(drive, 0xFE); - break; - case 0x6FF5: /* Data address mark */ - case 0x6AF5: /* Deleted data address mark */ - if (d86f[drive].id_was_read) - { - if ((d86f[drive].id_match) || d86f_find_state_nf_ignore_id(drive)) - { - d86f[drive].id_match = 0; /* Invalidate ID match to avoid false positives after read. */ - d86f[drive].calc_crc.word = 0xffff; - if (d86f[drive].state == STATE_WRITE_FIND_SECTOR) - { - d86f_write_byte_direct(drive, side, fdc_is_deleted() ? 0xF8 : 0xFB); - } - else - { - if (d86f[drive].track_data_word != requested_am) - { - fdc_set_wrong_am(); - if (fdc_is_sk()) - { - d86f[drive].datac = 0; - d86f_poll_advancebyte(drive, side); - d86f[drive].id_was_read = 0; /* Invalidate ID was read flag to avoid false positives after read. */ - return; - } - } - } - d86f_calccrc(drive, d86f[drive].track_data_byte); - d86f[drive].datac = 0; - switch (d86f[drive].state) - { - case STATE_READ_FIND_SECTOR: - case STATE_WRITE_FIND_SECTOR: - case STATE_READ_FIND_FIRST_SECTOR: - case STATE_READ_FIND_NEXT_SECTOR: - case STATE_COMPARE_FIND_SECTOR: - d86f[drive].state++; - d86f_poll_advancebyte(drive, side); - d86f[drive].id_was_read = 0; /* Invalidate ID was read flag to avoid false positives after read. */ - return; - } - } - d86f[drive].id_was_read = 0; /* Invalidate ID was read flag to avoid false positives after read. */ - } - break; - } - - d86f_poll_advancebyte(drive, side); - - if (d86f_poll_check_notfound(drive)) return; -} - -void d86f_poll_find_am_mfm(int drive, int side) -{ - uint16_t requested_am = fdc_is_deleted() ? 0x4A55 : 0x4555; - - switch (d86f[drive].track_data_word) - { - case 0x8944: - d86f[drive].am_sync_counter++; - d86f_calccrc(drive, 0xA1); - break; - case 0x5455: /* ID address mark */ - if (d86f[drive].am_sync_valid) - { - d86f[drive].am_sync_valid = 0; /* Invalidate address mark sync validity flag to avoid false positives after read. */ - d86f[drive].idam_found = 1; /* Mark ID address mark as found so on the next byte, we're in the ID reading handler. */ - d86f[drive].id_read_state = 0; - d86f[drive].datac = 0; - d86f_calccrc(drive, 0xFE); - // pclog("ID address mark found (%08X)\n", d86f[drive].track_pos); - } - break; - case 0x4555: /* Data address mark */ - case 0x4A55: /* Deleted data address mark */ - if (d86f[drive].id_was_read && d86f[drive].am_sync_valid) - { - if ((d86f[drive].id_match) || d86f_find_state_nf_ignore_id(drive)) - { - d86f[drive].id_match = 0; /* Invalidate ID match to avoid false positives after read. */ - if (d86f[drive].state == STATE_WRITE_FIND_SECTOR) - { - d86f_write_byte_direct(drive, side, fdc_is_deleted() ? 0xF8 : 0xFB); - } - else - { - if (d86f[drive].track_data_word != requested_am) - { - fdc_set_wrong_am(); - if (fdc_is_sk()) - { - d86f[drive].datac = 0; - d86f_poll_advancebyte(drive, side); - d86f[drive].id_was_read = 0; /* Invalidate ID was read flag to avoid false positives after read. */ - return; - } - } - } - d86f_calccrc(drive, d86f[drive].track_data_byte); - d86f[drive].datac = 0; - switch (d86f[drive].state) - { - case STATE_READ_FIND_SECTOR: - case STATE_WRITE_FIND_SECTOR: - case STATE_READ_FIND_FIRST_SECTOR: - case STATE_READ_FIND_NEXT_SECTOR: - case STATE_COMPARE_FIND_SECTOR: - // pclog("Advancing state (%04X)...\n", d86f[drive].calc_crc); - d86f[drive].state++; - d86f_poll_advancebyte(drive, side); - d86f[drive].id_was_read = 0; /* Invalidate ID was read flag to avoid false positives after read. */ - return; - } - } - d86f[drive].id_was_read = 0; /* Invalidate ID was read flag to avoid false positives after read. */ - } - if (d86f[drive].am_sync_valid) - { - d86f[drive].am_sync_valid = 0; /* Invalidate address mark sync validity flag to avoid false positives after read. */ - } - break; - } - - d86f_poll_advancebyte(drive, side); - - if (d86f_poll_check_notfound(drive)) return; - - if (d86f[drive].idam_found) - { - return; - } - - if (d86f[drive].track_data_word != d86f[drive].old_track_data_word) - { - switch (d86f[drive].old_track_data_word) - { - case 0x8944: /* Address mark sync */ - if (d86f[drive].am_sync_counter >= 3) /* Three is the minimum but we should tolerate more than three as probably a real FDC would. */ - { - switch (d86f[drive].track_data_word) - { - case 0x5455: - case 0x4555: - case 0x4A55: - // pclog("Sync found: %08X: %i %02X %04X\n", d86f[drive].track_pos, d86f[drive].am_sync_counter, d86f[drive].track_data_byte, d86f[drive].track_data_word); - d86f[drive].am_sync_valid = 1; /* Only set it to valid if we've hit 3 A1 sync bytes AND the address mark in a row. */ - break; - default: - d86f[drive].am_sync_valid = 0; /* A1 sync bytes not followed by a valid address mark, invalidate it. */ - break; - } - } - else - { - d86f[drive].am_sync_valid = 0; /* Too few A1 sync bytes, set it to invalid. */ - } - d86f[drive].am_sync_counter = 0; /* Reset address mark sync counter to zero to avoid false positives the next time we hit such a sync. */ - break; - } - switch (d86f[drive].track_data_word) - { - case 0x8944: /* Address mark sync */ - d86f[drive].am_sync_valid = 0; /* Make sure to reset the address mark sync validity flag to avoid false positives after read. */ - d86f[drive].am_sync_counter = 0; /* Reset address mark sync counter to zero to start counting. */ - d86f[drive].calc_crc.word = 0xffff; - break; - } - } -} - -void d86f_poll_time_out(int drive, int side) -{ - if (d86f[drive].track_index) - { - // pclog("d86f_poll_find_nf(): Index pulse\n"); - index_pulse(drive); - d86f[drive].index_count++; - } - - d86f_poll_advancebyte(drive, side); - - if (d86f_poll_check_notfound(drive)) return; -} - -void d86f_poll_find_nf_new_style(int drive, int side) -{ - uint8_t mfm = 0; - mfm = fdc_is_mfm(); - - if (!d86f_can_read_address(drive)) - { - d86f_poll_time_out(drive, side); /* If we know in advance we should time out, just do nothing and wait for two index pulses to be hit, then abort the command with Sector not found. */ - return; - } - - if (d86f[drive].idam_found) - { - d86f_poll_read_id(drive, side); /* A valid ID address mark was found (with A1 sync bytes if MFM), read the ID and its CRC, and verify it if needed. */ - } else { - if (mfm) + /* Word write. */ + encoded_byte = byte; + if (d86f_reverse_bytes(drive)) { - d86f_poll_find_am_mfm(drive, side); /* Finding a valid ID or data address mark, MFM method. */ - } - else - { - d86f_poll_find_am_fm(drive, side); /* Finding a valid ID or data address mark, FM method. */ + mask_data = encoded_byte >> 8; + encoded_byte &= 0xFF; + encoded_byte <<= 8; + encoded_byte |= mask_data; } } + + if (d86f_has_surface_desc(drive)) + { + mask_data = d86f[drive].track_encoded_data[side][pos] ^= 0xFFFF; + mask_surface = d86f[drive].track_surface_data[side][pos]; + mask_hole = (mask_surface & mask_data) ^ 0xFFFF; /* This will retain bits that are both fuzzy and 0, therefore physical holes. */ + encoded_byte &= mask_hole; /* Filter out physical hole bits from the encoded data. */ + mask_data ^= 0xFFFF; /* Invert back so bits 1 are 1 again. */ + mask_fuzzy = (mask_surface & mask_data) ^ 0xFFFF; /* All fuzzy bits are 0. */ + d86f[drive].track_surface_data[side][pos] &= mask_fuzzy; /* Remove fuzzy bits (but not hole bits) from the surface mask, making them regular again. */ + } + + d86f[drive].track_encoded_data[side][pos] = encoded_byte; + d86f[drive].last_word[side] = encoded_byte; } -void d86f_poll_format_new_style(int drive, int side) +void d86f_write_direct(int drive, int side, uint16_t byte, uint8_t type) +{ + d86f_write_direct_common(drive, side, byte, type, d86f[drive].track_pos >> 4); +} + +uint16_t endian_swap(uint16_t word) +{ + uint16_t temp; + + temp = word & 0xff; + temp <<= 8; + temp |= (word >> 8); + return temp; +} + +void d86f_format_track(int drive, int side) { int data; - uint16_t max_len; + uint16_t max_len, temp, temp2; int mfm; uint16_t i = 0; uint16_t j = 0; uint16_t sc = 0; uint16_t dtl = 0; - int real_gap0_len = 0; - int real_gap1_len = 0; - int real_gap2_len = 0; - int real_gap3_len = 0; + int gap_sizes[4] = { 0, 0, 0, 0 }; int am_len = 0; int sync_len = 0; uint16_t iam_mfm[4] = { 0x2452, 0x2452, 0x2452, 0x5255 }; @@ -2790,27 +1793,29 @@ void d86f_poll_format_new_style(int drive, int side) uint16_t idam_fm = 0x7EF5; uint16_t dataam_fm = 0x6FF5; uint16_t gap_fill = 0x4E; + int do_write = 0; mfm = d86f_is_mfm(drive); am_len = mfm ? 4 : 1; - real_gap0_len = mfm ? 80 : 40; - real_gap1_len = mfm ? 50 : 26; - real_gap2_len = fdc_get_gap2(drive ^ fdd_swap); - real_gap3_len = fdc_get_gap(); + gap_sizes[0] = mfm ? 80 : 40; + gap_sizes[1] = mfm ? 50 : 26; + gap_sizes[2] = fdc_get_gap2(drive ^ fdd_swap); + gap_sizes[3] = fdc_get_gap(); sync_len = mfm ? 12 : 6; sc = fdc_get_format_sectors(); dtl = 128 << fdc_get_format_n(); gap_fill = mfm ? 0x4E : 0xFF; + do_write = (d86f[drive].version == 0x0200); switch(d86f[drive].format_state) { case FMT_POSTTRK_GAP4: max_len = 60000; - d86f_write_byte_direct(drive, side, gap_fill); + if (do_write) d86f_write_direct(drive, side, gap_fill, 0); break; case FMT_PRETRK_GAP0: - max_len = real_gap0_len; - d86f_write_byte_direct(drive, side, gap_fill); + max_len = gap_sizes[0]; + if (do_write) d86f_write_direct(drive, side, gap_fill, 0); break; case FMT_SECTOR_ID_SYNC: if (d86f[drive].datac <= 3) @@ -2831,85 +1836,105 @@ void d86f_poll_format_new_style(int drive, int side) case FMT_PRETRK_SYNC: case FMT_SECTOR_DATA_SYNC: max_len = sync_len; - d86f_write_byte_direct(drive, side, 0x00); + if (do_write) d86f_write_direct(drive, side, 0x00, 0); break; case FMT_PRETRK_IAM: max_len = am_len; - if (mfm) + if (do_write) { - d86f_write_word(drive, side, iam_mfm[d86f[drive].datac]); - } - else - { - d86f_write_word(drive, side, iam_fm); + if (mfm) + { + d86f_write_direct(drive, side, iam_mfm[d86f[drive].datac], 1); + } + else + { + d86f_write_direct(drive, side, iam_fm, 1); + } } break; case FMT_PRETRK_GAP1: - max_len = real_gap1_len; - d86f_write_byte_direct(drive, side, gap_fill); + max_len = gap_sizes[1]; + if (do_write) d86f_write_direct(drive, side, gap_fill, 0); break; case FMT_SECTOR_IDAM: max_len = am_len; if (mfm) { - d86f_write_word(drive, side, idam_mfm[d86f[drive].datac]); - d86f_calccrc(drive, d86f[drive].track_data_byte); + if (do_write) d86f_write_direct(drive, side, idam_mfm[d86f[drive].datac], 1); + d86f_calccrc(drive, (d86f[drive].datac < 3) ? 0xA1 : 0xFE); } else { - d86f_write_word(drive, side, idam_fm); - d86f_calccrc(drive, d86f[drive].track_data_byte); + if (do_write) d86f_write_direct(drive, side, idam_fm, 1); + d86f_calccrc(drive, 0xFE); } break; case FMT_SECTOR_ID: max_len = 4; - d86f_write_byte_direct(drive, side, d86f[drive].format_sector_id.byte_array[d86f[drive].datac]); - d86f_calccrc(drive, d86f[drive].track_data_byte); + if (do_write) + { + d86f_write_direct(drive, side, d86f[drive].format_sector_id.byte_array[d86f[drive].datac], 0); + d86f_calccrc(drive, d86f[drive].format_sector_id.byte_array[d86f[drive].datac]); + } + else + { + if (d86f[drive].datac == 3) + { + d86f_handler[drive].set_sector(drive, side, d86f[drive].format_sector_id.id.c, d86f[drive].format_sector_id.id.h, d86f[drive].format_sector_id.id.r, d86f[drive].format_sector_id.id.n); + } + } break; case FMT_SECTOR_ID_CRC: case FMT_SECTOR_DATA_CRC: max_len = 2; - d86f_write_byte_direct(drive, side, d86f[drive].calc_crc.bytes[d86f[drive].datac ^ 1]); + if (do_write) d86f_write_direct(drive, side, d86f[drive].calc_crc.bytes[d86f[drive].datac ^ 1], 0); break; case FMT_SECTOR_GAP2: - max_len = real_gap2_len; - d86f_write_byte_direct(drive, side, gap_fill); + max_len = gap_sizes[2]; + if (do_write) d86f_write_direct(drive, side, gap_fill, 0); break; case FMT_SECTOR_DATAAM: max_len = am_len; if (mfm) { - d86f_write_word(drive, side, dataam_mfm[d86f[drive].datac]); - d86f_calccrc(drive, d86f[drive].track_data_byte); + if (do_write) d86f_write_direct(drive, side, dataam_mfm[d86f[drive].datac], 1); + d86f_calccrc(drive, (d86f[drive].datac < 3) ? 0xA1 : 0xFB); } else { - d86f_write_word(drive, side, dataam_fm); - d86f_calccrc(drive, d86f[drive].track_data_byte); + if (do_write) d86f_write_direct(drive, side, dataam_fm, 1); + d86f_calccrc(drive, 0xFB); } break; case FMT_SECTOR_DATA: max_len = dtl; - d86f_write_byte_direct(drive, side, d86f[drive].fill); + if (do_write) d86f_write_direct(drive, side, d86f[drive].fill, 0); d86f_calccrc(drive, d86f[drive].fill); break; case FMT_SECTOR_GAP3: - max_len = real_gap3_len; - d86f_write_byte_direct(drive, side, gap_fill); + max_len = gap_sizes[3]; + if (do_write) d86f_write_direct(drive, side, gap_fill, 0); break; } d86f[drive].datac++; - d86f_poll_advancebyte(drive, side); - if (d86f[drive].track_index) + d86f_advance_word(drive, side); + + if (d86f[drive].track_pos == d86f_handler[drive].index_hole_pos(drive, side)) { - // pclog("Track position %08X\n", d86f[drive].track_pos); - // pclog("Index hole hit again, format finished\n"); + /* Before we return, if the encoding is MFM, we have to make sure the clock bit of the first bit in the track is correct. */ + if (mfm && do_write) + { + if (do_write) d86f_write_direct_common(drive, side, gap_fill, 0, 0); + } + d86f[drive].state = STATE_IDLE; - if (!disable_write) d86f_handler[drive].writeback(drive); - fdc_sector_finishread(drive); - d86f[drive].index_count = 0; + d86f_handler[drive].writeback(drive); + // pclog("Format finished!\n"); + d86f[drive].error_condition = 0; + d86f[drive].datac = 0; + fdc_sector_finishread(); return; } @@ -2946,75 +1971,1212 @@ void d86f_poll_format_new_style(int drive, int side) } } +void d86f_poll(int drive) +{ + int side = 0; + int mfm = 1; + + side = fdd_get_head(drive); + mfm = fdc_is_mfm(); + + if ((d86f[drive].state & 0xF8) == 0xE8) + { + if (!d86f_can_format(drive)) + { + d86f[drive].state = STATE_SECTOR_NOT_FOUND; + } + } + + if ((d86f[drive].state != STATE_IDLE) && (d86f[drive].state != STATE_SECTOR_NOT_FOUND) && ((d86f[drive].state & 0xF8) != 0xE8)) + { + if (!d86f_can_read_address(drive)) + { + d86f[drive].state = STATE_SECTOR_NOT_FOUND; + } + } + + d86f_get_bit(drive, side ^ 1); + + switch(d86f[drive].state) + { + case STATE_02_SPIN_TO_INDEX: + case STATE_0D_SPIN_TO_INDEX: + d86f_spin_to_index(drive, side); + return; + case STATE_02_FIND_ID: + case STATE_05_FIND_ID: + case STATE_09_FIND_ID: + case STATE_06_FIND_ID: + case STATE_0A_FIND_ID: + case STATE_0C_FIND_ID: + case STATE_11_FIND_ID: + case STATE_16_FIND_ID: + if (mfm) + { + d86f_find_address_mark_mfm(drive, side, &(d86f[drive].id_find), 0x5554, 0, 0); + } + else + { + d86f_find_address_mark_fm(drive, side, &(d86f[drive].id_find), 0xF57E, 0, 0); + } + break; + case STATE_0A_READ_ID: + case STATE_02_READ_ID: + d86f_read_sector_id(drive, side, 0); + break; + case STATE_05_READ_ID: + case STATE_09_READ_ID: + case STATE_06_READ_ID: + case STATE_0C_READ_ID: + case STATE_11_READ_ID: + case STATE_16_READ_ID: + d86f_read_sector_id(drive, side, 1); + break; + case STATE_02_FIND_DATA: + if (mfm) + { + d86f_find_address_mark_mfm(drive, side, &(d86f[drive].data_find), 0x5545, 0x554A, 2); + } + else + { + d86f_find_address_mark_fm(drive, side, &(d86f[drive].data_find), 0xF56F, 0xF56A, 2); + } + break; + case STATE_06_FIND_DATA: + case STATE_11_FIND_DATA: + case STATE_16_FIND_DATA: + if (mfm) + { + d86f_find_address_mark_mfm(drive, side, &(d86f[drive].data_find), 0x5545, 0x554A, fdc_is_sk() | 2); + } + else + { + d86f_find_address_mark_fm(drive, side, &(d86f[drive].data_find), 0xF56F, 0xF56A, fdc_is_sk() | 2); + } + break; + case STATE_05_FIND_DATA: + case STATE_09_FIND_DATA: + if (mfm) + { + d86f_write_find_address_mark_mfm(drive, side, &(d86f[drive].data_find)); + } + else + { + d86f_write_find_address_mark_fm(drive, side, &(d86f[drive].data_find)); + } + break; + case STATE_0C_FIND_DATA: + if (mfm) + { + d86f_find_address_mark_mfm(drive, side, &(d86f[drive].data_find), 0x554A, 0x5545, fdc_is_sk() | 2); + } + else + { + d86f_find_address_mark_fm(drive, side, &(d86f[drive].data_find), 0xF56A, 0xF56F, fdc_is_sk() | 2); + } + break; + case STATE_02_READ_DATA: + case STATE_06_READ_DATA: + case STATE_0C_READ_DATA: + case STATE_11_SCAN_DATA: + case STATE_16_VERIFY_DATA: + d86f_read_sector_data(drive, side); + break; + case STATE_05_WRITE_DATA: + if (mfm) + { + d86f_write_sector_data(drive, side, mfm, 0x5545); + } + else + { + d86f_write_sector_data(drive, side, mfm, 0xF56F); + } + break; + case STATE_09_WRITE_DATA: + if (mfm) + { + d86f_write_sector_data(drive, side, mfm, 0x554A); + } + else + { + d86f_write_sector_data(drive, side, mfm, 0xF56A); + } + break; + case STATE_0D_FORMAT_TRACK: + if (!(d86f[drive].track_pos & 15)) + { + d86f_format_track(drive, side); + } + return; + case STATE_IDLE: + case STATE_SECTOR_NOT_FOUND: + default: + d86f_get_bit(drive, side); + break; + } + + d86f_advance_bit(drive, side); + + if ((d86f[drive].index_count == 2) && (d86f[drive].state != STATE_IDLE)) + { + pclog("[State: %02X] [Side %i] Sector not found (%i != %i?) (%02X) (%08X)\n", d86f[drive].state, side, fdc_get_bitcell_period(), d86f_get_bitcell_period(drive), d86f_handler[drive].side_flags(drive), d86f[drive].req_sector.dword); + d86f[drive].state = STATE_IDLE; + fdc_notfound(); + } +} + +#if 0 +void d86f_poll(int drive) +{ + int i = 0; + for (i = 0; i < 16; i++) + { + d86f_bit_poll(drive); + } +} + void d86f_poll() { - // int drive = d86f_drive; int drive = 0; - int side = 0; - int mfm; drive = fdc_get_drive(); - side = fdd_get_head(drive); + d86f_poll_per_drive(drive); +} +#endif + +void d86f_reset_index_hole_pos(int drive, int side) +{ + d86f[drive].index_hole_pos[side] = 0; +} + +uint16_t d86f_prepare_pretrack(int drive, int side, int iso) +{ + uint16_t i, pos; + + int mfm = 0; + int real_gap0_len = 0; + int sync_len = 0; + int real_gap1_len = 0; + uint16_t gap_fill = 0; + uint32_t raw_size = 0; + uint16_t iam_fm = 0xFAF7; + uint16_t iam_mfm = 0x5255; + + mfm = d86f_is_mfm(drive); + real_gap0_len = mfm ? 80 : 40; + sync_len = mfm ? 12 : 6; + real_gap1_len = mfm ? 50 : 26; + gap_fill = mfm ? 0x4E : 0xFF; + raw_size = d86f_handler[drive].get_raw_size(drive) >> 4; + + d86f[drive].index_hole_pos[side] = 0; + + for (i = 0; i < raw_size; i++) + { + d86f_write_direct_common(drive, side, gap_fill, 0, i); + } + + pos = 0; + + if (!iso) + { + for (i = 0; i < real_gap0_len; i++) + { + d86f_write_direct_common(drive, side, gap_fill, 0, pos); + pos = (pos + 1) % raw_size; + } + for (i = 0; i < sync_len; i++) + { + d86f_write_direct_common(drive, side, 0, 0, pos); + pos = (pos + 1) % raw_size; + } + if (mfm) + { + for (i = 0; i < 3; i++) + { + d86f_write_direct_common(drive, side, 0x2452, 1, pos); + pos = (pos + 1) % raw_size; + } + } + d86f_write_direct_common(drive, side, mfm ? iam_mfm : iam_fm, 1, pos); + pos = (pos + 1) % raw_size; + } + for (i = 0; i < real_gap0_len; i++) + { + d86f_write_direct_common(drive, side, gap_fill, 0, pos); + pos = (pos + 1) % raw_size; + } + + return pos; +} + +uint16_t d86f_prepare_sector(int drive, int side, int prev_pos, uint8_t *id_buf, uint8_t *data_buf, int data_len, int gap2, int gap3, int deleted, int bad_crc) +{ + uint16_t pos; + + int i; + + int real_gap2_len = gap2; + int real_gap3_len = gap3; + int mfm = 0; + int sync_len = 0; + uint16_t gap_fill = 0; + uint32_t raw_size = 0; + uint16_t idam_fm = 0x7EF5; + uint16_t dataam_fm = 0x6FF5; + uint16_t datadam_fm = 0x6AF5; + uint16_t idam_mfm = 0x5455; + uint16_t dataam_mfm = 0x4555; + uint16_t datadam_mfm = 0x4A55; + mfm = d86f_is_mfm(drive); - if ((d86f[drive].state == STATE_FORMAT) && d86f_is_old_style(drive)) + gap_fill = mfm ? 0x4E : 0xFF; + raw_size = d86f_handler[drive].get_raw_size(drive) >> 4; + + pos = prev_pos; + + sync_len = mfm ? 12 : 6; + + for (i = 0; i < sync_len; i++) { - d86f_poll_format(drive, side); - return; + d86f_write_direct_common(drive, side, 0, 0, pos); + pos = (pos + 1) % raw_size; } - - if ((d86f[drive].state == STATE_FORMAT) && !d86f_is_old_style(drive)) + d86f[drive].calc_crc.word = 0xffff; + if (mfm) { - d86f_poll_format_new_style(drive, side); - return; - } - - if (d86f[drive].state == STATE_FORMAT_FIND) - { - d86f_poll_find_format(drive, side); - return; - } - - if (d86f_find_state_nf(drive) && d86f_is_old_style(drive)) - { - d86f_poll_find_nf(drive, side); - } - - if (d86f_find_state_nf(drive) && !d86f_is_old_style(drive)) - { - d86f_poll_find_nf_new_style(drive, side); - return; - } - - if (d86f_read_state(drive) || d86f_write_state(drive)) - { - d86f_poll_readwrite(drive, side); - return; - } - - if ((d86f[drive].state == STATE_SEEK) || (d86f[drive].state == STATE_IDLE)) - { - d86f_poll_advancebyte(drive, side); - - if (d86f[drive].track_byte != d86f[drive].old_track_byte) + for (i = 0; i < 3; i++) { - d86f[drive].section_pos = d86f[drive].track_pos; + d86f_write_direct_common(drive, side, 0x8944, 1, pos); + pos = (pos + 1) % raw_size; + d86f_calccrc(drive, 0xA1); + } + } + d86f_write_direct_common(drive, side, mfm ? idam_mfm : idam_fm, 1, pos); + pos = (pos + 1) % raw_size; + d86f_calccrc(drive, 0xFE); + for (i = 0; i < 4; i++) + { + d86f_write_direct_common(drive, side, id_buf[i], 0, pos); + pos = (pos + 1) % raw_size; + d86f_calccrc(drive, id_buf[i]); + } + for (i = 1; i >= 0; i--) + { + d86f_write_direct_common(drive, side, d86f[drive].calc_crc.bytes[i], 0, pos); + pos = (pos + 1) % raw_size; + } + for (i = 0; i < real_gap2_len; i++) + { + d86f_write_direct_common(drive, side, gap_fill, 0, pos); + pos = (pos + 1) % raw_size; + } + for (i = 0; i < sync_len; i++) + { + d86f_write_direct_common(drive, side, 0, 0, pos); + pos = (pos + 1) % raw_size; + } + d86f[drive].calc_crc.word = 0xffff; + if (mfm) + { + for (i = 0; i < 3; i++) + { + d86f_write_direct_common(drive, side, 0x8944, 1, pos); + pos = (pos + 1) % raw_size; + d86f_calccrc(drive, 0xA1); + } + } + d86f_write_direct_common(drive, side, mfm ? (deleted ? datadam_mfm : dataam_mfm) : (deleted ? datadam_fm : dataam_fm), 1, pos); + pos = (pos + 1) % raw_size; + d86f_calccrc(drive, deleted ? 0xF8 : 0xFB); + for (i = 0; i < data_len; i++) + { + d86f_write_direct_common(drive, side, data_buf[i], 0, pos); + pos = (pos + 1) % raw_size; + d86f_calccrc(drive, data_buf[i]); + } + if (bad_crc) + { + d86f[drive].calc_crc.word ^= 0xffff; + } + for (i = 1; i >= 0; i--) + { + d86f_write_direct_common(drive, side, d86f[drive].calc_crc.bytes[i], 0, pos); + pos = (pos + 1) % raw_size; + } + for (i = 0; i < real_gap3_len; i++) + { + d86f_write_direct_common(drive, side, gap_fill, 0, pos); + pos = (pos + 1) % raw_size; + } - switch(d86f[drive].track_byte) + return pos; +} + +/* Note on handling of tracks on thick track drives: + - On seek, encoded data is constructed from both (track << 1) and ((track << 1) + 1); + - Any bits that differ are treated as thus: + - Both are regular but contents differ -> Output is fuzzy; + - One is regular and one is fuzzy -> Output is fuzzy; + - Both are fuzzy -> Output is fuzzy; + - Both are physical holes -> Output is a physical hole; + - One is regular and one is a physical hole -> Output is puzzy, the hole half is handled appropriately on writeback; + - One is fuzzy and one is a physical hole -> Output is puzzy, the hole half is handled appropriately on writeback; + - On write back, apart from the above notes, the final two tracks are written; + - Destination ALWAYS has surface data even if the image does not. + In case of a thin track drive, tracks are handled normally. */ + +void d86f_construct_encoded_buffer(int drive, int side) +{ + int i = 0; + /* *_fuzm are fuzzy bit masks, *_holm are hole masks, dst_neim are masks is mask for bits that are neither fuzzy nor holes in both, + and src1_d and src2_d are filtered source data. */ + uint16_t src1_fuzm, src2_fuzm, dst_fuzm, src1_holm, src2_holm, dst_holm, dst_neim, src1_d, src2_d; + uint32_t len; + uint16_t *dst = d86f[drive].track_encoded_data[side]; + uint16_t *dst_s = d86f[drive].track_surface_data[side]; + uint16_t *src1 = d86f[drive].thin_track_encoded_data[0][side]; + uint16_t *src1_s = d86f[drive].thin_track_surface_data[0][side]; + uint16_t *src2 = d86f[drive].thin_track_encoded_data[1][side]; + uint16_t *src2_s = d86f[drive].thin_track_surface_data[1][side]; + len = d86f_get_array_size(drive); + + for (i = 0; i < len; i++) + { + /* The two bits differ. */ + if (d86f_has_surface_desc(drive)) + { + /* Source image has surface description data, so we have some more handling to do. */ + src1_fuzm = src1[i] & src1_s[i]; + src2_fuzm = src2[i] & src2_s[i]; + dst_fuzm = src1_fuzm | src2_fuzm; /* The bits that remain set are fuzzy in either one or + the other or both. */ + src1_holm = src1[i] | (src1_s[i] ^ 0xffff); + src2_holm = src2[i] | (src2_s[i] ^ 0xffff); + dst_holm = (src1_holm & src2_holm) ^ 0xffff; /* The bits that remain set are holes in both. */ + dst_neim = (dst_fuzm | dst_holm) ^ 0xffff; /* The bits that remain set are those that are neither + fuzzy nor are holes in both. */ + src1_d = src1[i] & dst_neim; + src2_d = src2[i] & dst_neim; + + dst_s[i] = (dst_neim ^ 0xffff); /* The set bits are those that are either fuzzy or are + holes in both. */ + dst[i] = (src1_d | src2_d); /* Initial data is remaining data from Source 1 and + Source 2. */ + dst[i] |= dst_fuzm; /* Add to it the fuzzy bytes (holes have surface bit set + but data bit clear). */ + } + else + { + /* No surface data, the handling is much simpler - a simple OR. */ + dst[i] = src1[i] | src2[i]; + dst_s[i] = 0; + } + } +} + +/* Decomposition is easier since we at most have to care about the holes. */ +void d86f_decompose_encoded_buffer(int drive, int side) +{ + int i = 0; + uint16_t temp, temp2; + uint32_t len; + uint16_t *dst = d86f[drive].track_encoded_data[side]; + uint16_t *dst_s = d86f[drive].track_surface_data[side]; + uint16_t *src1 = d86f[drive].thin_track_encoded_data[0][side]; + uint16_t *src1_s = d86f[drive].thin_track_surface_data[0][side]; + uint16_t *src2 = d86f[drive].thin_track_encoded_data[1][side]; + uint16_t *src2_s = d86f[drive].thin_track_surface_data[1][side]; + len = d86f_get_array_size(drive); + + for (i = 0; i < len; i++) + { + if (d86f_has_surface_desc(drive)) + { + /* Source image has surface description data, so we have some more handling to do. + We need hole masks for both buffers. Holes have data bit clear and surface bit set. */ + temp = src1[i] & (src1_s[i] ^ 0xffff); + temp2 = src2[i] & (src2_s[i] ^ 0xffff); + src1[i] = dst[i] & temp; + src1_s[i] = temp ^ 0xffff; + src2[i] = dst[i] & temp2; + src2_s[i] = temp2 ^ 0xffff; + } + else + { + src1[i] = src2[i] = dst[i]; + } + } +} + +void d86f_seek(int drive, int track) +{ + uint8_t track_id = track; + int sides; + int side, thin_track; + sides = d86f_get_sides(drive); + + /* If the drive has thick tracks, shift the track number by 1. */ + if (!fdd_doublestep_40(drive)) + { + track <<= 1; + + for (thin_track = 0; thin_track < sides; thin_track++) + { + for (side = 0; side < sides; side++) { - case BYTE_IDAM_SYNC: - if (mfm) + if (d86f_has_surface_desc(drive)) + { + memset(d86f[drive].thin_track_surface_data[thin_track][side], 0, 106096); + } + memset(d86f[drive].thin_track_encoded_data[thin_track][side], 0, 106096); + } + } + } + + for (side = 0; side < sides; side++) + { + if (d86f_has_surface_desc(drive)) + { + memset(d86f[drive].track_surface_data[side], 0, 106096); + } + memset(d86f[drive].track_encoded_data[side], 0, 106096); + } + + d86f[drive].cur_track = track; + + if (!(d86f[drive].track_offset[track])) + { + /* Track does not exist in the image, initialize it as unformatted. */ + for (side = 0; side < sides; side++) + { + d86f[drive].side_flags[side] = 0x0A; /* 300 rpm, MFM, 250 kbps */ + } + return; + } + + fseek(d86f[drive].f, d86f[drive].track_offset[track], SEEK_SET); + + for (side = 0; side < sides; side++) + { + fread(&(d86f[drive].side_flags[side]), 2, 1, d86f[drive].f); + } + + for (side = 0; side < sides; side++) + { + fread(&(d86f[drive].index_hole_pos[side]), 4, 1, d86f[drive].f); + } + + if (!fdd_doublestep_40(drive)) + { + for (thin_track = 0; thin_track < sides; thin_track++) + { + if (d86f[drive].track_offset[track + thin_track]) + { + fseek(d86f[drive].f, d86f[drive].track_offset[track + thin_track] + 8, SEEK_SET); + for (side = 0; side < sides; side++) + { + if (d86f_has_surface_desc(drive)) { - d86f[drive].calc_crc.word = 0xffff; + fread(d86f[drive].thin_track_surface_data[thin_track][side], 1, d86f_get_array_size(drive) << 1, d86f[drive].f); } - break; - case BYTE_IDAM: - if (!mfm) - { - d86f[drive].calc_crc.word = 0xffff; - } - break; + fread(d86f[drive].thin_track_encoded_data[thin_track][side], 1, d86f_get_array_size(drive) << 1, d86f[drive].f); + } + } + } + for (side = 0; side < sides; side++) + { + d86f_construct_encoded_buffer(drive, side); + } + } + else + { + for (side = 0; side < sides; side++) + { + if (d86f_has_surface_desc(drive)) + { + fread(d86f[drive].track_surface_data[side], 1, d86f_get_array_size(drive) << 1, d86f[drive].f); + } + fread(d86f[drive].track_encoded_data[side], 1, d86f_get_array_size(drive) << 1, d86f[drive].f); + } + } + + d86f[drive].state = STATE_IDLE; +} + +void d86f_write_track(int drive, int sides, uint16_t *da0, uint16_t *sa0, uint16_t *da1, uint16_t *sa1) +{ + int side; + + // pclog("Pos: %08X\n", ftell(d86f[drive].f)); + + for (side = 0; side < sides; side++) + { + fwrite(&(d86f[drive].side_flags[side]), 1, 2, d86f[drive].f); + } + + for (side = 0; side < sides; side++) + { + fwrite(&(d86f[drive].index_hole_pos[side]), 1, 4, d86f[drive].f); + } + + if (d86f_has_surface_desc(drive)) + { + fwrite(sa0, 1, d86f_get_array_size(drive) << 1, d86f[drive].f); + } + fwrite(da0, 1, d86f_get_array_size(drive) << 1, d86f[drive].f); + + if (sides == 2) + { + if (d86f_has_surface_desc(drive)) + { + fwrite(sa1, 1, d86f_get_array_size(drive) << 1, d86f[drive].f); + } + fwrite(da1, 1, d86f_get_array_size(drive) << 1, d86f[drive].f); + } + + // pclog("Pos: %08X\n", ftell(d86f[drive].f)); +} + +void d86f_writeback(int drive) +{ + uint8_t track_id = d86f[drive].cur_track; + uint8_t header[32]; + int sides, header_size; + int side, thin_track; + uint64_t crc64; + uint32_t len; + int i = 0; + int ret = 0; + uint8_t tempb; + FILE *cf; + sides = d86f_get_sides(drive); + header_size = d86f_header_size(drive); + + if (!d86f[drive].f) + { + return; + } + + /* First write the track offsets table. */ + fseek(d86f[drive].f, 0, SEEK_SET); + fread(header, 1, header_size, d86f[drive].f); + + // pclog("PosEx: %08X\n", ftell(d86f[drive].f)); + fwrite(d86f[drive].track_offset, 1, 1024, d86f[drive].f); + // pclog("PosEx: %08X\n", ftell(d86f[drive].f)); + + if (!fdd_doublestep_40(drive)) + { + for (side = 0; side < sides; side++) + { + d86f_decompose_encoded_buffer(drive, side); + } + + if (d86f[drive].track_offset[d86f[drive].cur_track]) + { + fseek(d86f[drive].f, d86f[drive].track_offset[d86f[drive].cur_track], SEEK_SET); + d86f_write_track(drive, sides, d86f[drive].thin_track_encoded_data[0][0], d86f[drive].thin_track_surface_data[0][0], d86f[drive].thin_track_encoded_data[0][1], d86f[drive].thin_track_surface_data[0][1]); + } + + if (d86f[drive].track_offset[d86f[drive].cur_track + 1]) + { + fseek(d86f[drive].f, d86f[drive].track_offset[d86f[drive].cur_track + 1], SEEK_SET); + d86f_write_track(drive, sides, d86f[drive].thin_track_encoded_data[1][0], d86f[drive].thin_track_surface_data[1][0], d86f[drive].thin_track_encoded_data[1][1], d86f[drive].thin_track_surface_data[1][1]); + } + } + else + { + if (d86f[drive].track_offset[d86f[drive].cur_track]) + { + // pclog("Writing track...\n"); + fseek(d86f[drive].f, d86f[drive].track_offset[d86f[drive].cur_track], SEEK_SET); + d86f_write_track(drive, sides, d86f[drive].track_encoded_data[0], d86f[drive].track_surface_data[0], d86f[drive].track_encoded_data[1], d86f[drive].track_surface_data[1]); + } + } + + // pclog("Position: %08X\n", ftell(d86f[drive].f)); + + if (d86f[drive].is_compressed) + { + /* The image is compressed. */ + + /* Open the original, compressed file. */ + cf = fopen(d86f[drive].original_file_name, "wb"); + + /* Write the header to the original file. */ + fwrite(header, 1, header_size, cf); + + fseek(d86f[drive].f, 0, SEEK_END); + len = ftell(d86f[drive].f); + + fseek(d86f[drive].f, header_size, SEEK_SET); + + /* Compress data from the temporary uncompressed file to the original, compressed file. */ + d86f[drive].filebuf = (uint8_t *) malloc(len); + d86f[drive].outbuf = (uint8_t *) malloc(len - 1); + fread(d86f[drive].filebuf, 1, len, d86f[drive].f); + ret = lzf_compress(d86f[drive].filebuf, len, d86f[drive].outbuf, len - 1); + + // ret = d86f_zlib(cf, d86f[drive].f, 0); + if (!ret) + { + pclog("86F: Error compressing file\n"); + } + + fwrite(d86f[drive].outbuf, 1, ret, cf); + free(d86f[drive].outbuf); + free(d86f[drive].filebuf); + + len = ftell(cf); + + fclose(cf); + cf = fopen(d86f[drive].original_file_name, "rb+"); + + crc64 = 0xffffffffffffffff; + fseek(cf, 8, SEEK_SET); + fwrite(&crc64, 1, 8, cf); + + d86f[drive].filebuf = (uint8_t *) malloc(len); + fread(d86f[drive].filebuf, 1, len, cf); + + crc64 = (uint64_t) crc64speed(0, d86f[drive].filebuf, len); + free(d86f[drive].filebuf); + + fseek(cf, 8, SEEK_SET); + fwrite(&crc64, 1, 8, cf); + + /* Close the original file. */ + fclose(cf); + } + else + { + fseek(d86f[drive].f, 0, SEEK_END); + len = ftell(d86f[drive].f); + + fseek(d86f[drive].f, 0, SEEK_SET); + + crc64 = 0xffffffffffffffff; + fseek(d86f[drive].f, 8, SEEK_SET); + fwrite(&crc64, 1, 8, d86f[drive].f); + + d86f[drive].filebuf = (uint8_t *) malloc(len); + fread(d86f[drive].filebuf, 1, len, d86f[drive].f); + + crc64 = (uint64_t) crc64speed(0, d86f[drive].filebuf, len); + free(d86f[drive].filebuf); + + fseek(d86f[drive].f, 8, SEEK_SET); + fwrite(&crc64, 1, 8, d86f[drive].f); + } + + // pclog("d86f_writeback(): %08X\n", d86f[drive].track_offset[track]); +} + +void d86f_stop(int drive) +{ + d86f[drive].state = STATE_IDLE; +} + +int d86f_common_command(int drive, int sector, int track, int side, int rate, int sector_size) +{ + pclog("d86f_common_command: fdc_period=%i img_period=%i rate=%i sector=%i track=%i side=%i\n", fdc_get_bitcell_period(), d86f_get_bitcell_period(drive), rate, sector, track, side); + + d86f[drive].req_sector.id.c = track; + d86f[drive].req_sector.id.h = side; + d86f[drive].req_sector.id.r = sector; + d86f[drive].req_sector.id.n = sector_size; + + if (fdd_get_head(drive) && (d86f_get_sides(drive) == 1)) + { + fdc_notfound(); + d86f[drive].state = STATE_IDLE; + d86f[drive].index_count = 0; + return 0; + } + + d86f[drive].id_find.sync_marks = d86f[drive].id_find.bits_obtained = d86f[drive].id_find.bytes_obtained = 0; + d86f[drive].data_find.sync_marks = d86f[drive].data_find.bits_obtained = d86f[drive].data_find.bytes_obtained = 0; + d86f[drive].index_count = d86f[drive].error_condition = d86f[drive].satisfying_bytes = 0; + + return 1; +} + +void d86f_readsector(int drive, int sector, int track, int side, int rate, int sector_size) +{ + int ret = 0; + + ret = d86f_common_command(drive, sector, track, side, rate, sector_size); + if (!ret) return; + + if (sector == SECTOR_FIRST) + d86f[drive].state = STATE_02_SPIN_TO_INDEX; + else if (sector == SECTOR_NEXT) + d86f[drive].state = STATE_02_FIND_ID; + else + d86f[drive].state = fdc_is_deleted() ? STATE_0C_FIND_ID : (fdc_is_verify() ? STATE_16_FIND_ID : STATE_06_FIND_ID); +} + +void d86f_writesector(int drive, int sector, int track, int side, int rate, int sector_size) +{ + int ret = 0; + + if (writeprot[drive]) + { + fdc_writeprotect(); + d86f[drive].state = STATE_IDLE; + d86f[drive].index_count = 0; + return; + } + + ret = d86f_common_command(drive, sector, track, side, rate, sector_size); + if (!ret) return; + + d86f[drive].state = fdc_is_deleted() ? STATE_09_FIND_ID : STATE_05_FIND_ID; +} + +void d86f_comparesector(int drive, int sector, int track, int side, int rate, int sector_size) +{ + int ret = 0; + + ret = d86f_common_command(drive, sector, track, side, rate, sector_size); + if (!ret) return; + + d86f[drive].state = STATE_11_FIND_ID; +} + +void d86f_readaddress(int drive, int track, int side, int rate) +{ + if (fdd_get_head(drive) && (d86f_get_sides(drive) == 1)) + { + pclog("Trying to access the second side of a single-sided disk\n"); + fdc_notfound(); + d86f[drive].state = STATE_IDLE; + d86f[drive].index_count = 0; + return; + } + + d86f[drive].id_find.sync_marks = d86f[drive].id_find.bits_obtained = d86f[drive].id_find.bytes_obtained = 0; + d86f[drive].data_find.sync_marks = d86f[drive].data_find.bits_obtained = d86f[drive].data_find.bytes_obtained = 0; + d86f[drive].index_count = d86f[drive].error_condition = d86f[drive].satisfying_bytes = 0; + + d86f[drive].state = STATE_0A_FIND_ID; +} + +void d86f_add_track(int drive, int track) +{ + uint32_t array_size; + array_size = d86f_get_array_size(drive); + array_size <<= 1; + + if (!d86f[drive].track_offset[track]) + { + /* Track is absent from the file, let's add it. */ + d86f[drive].track_offset[track] = d86f[drive].file_size; + + if (d86f_has_surface_desc(drive)) + { + d86f[drive].file_size += (((array_size << 1) + 6) * d86f_get_sides(drive)); + } + else + { + d86f[drive].file_size += ((array_size + 6) * d86f_get_sides(drive)); + } + } +} + +void d86f_common_format(int drive, int track, int side, int rate, uint8_t fill, int proxy) +{ + int i = 0; + uint16_t temp, temp2; + uint32_t array_size; + + if (writeprot[drive]) + { + fdc_writeprotect(); + d86f[drive].state = STATE_IDLE; + d86f[drive].index_count = 0; + return; + } + + if ((side && (d86f_get_sides(drive) == 1)) || !(d86f_can_format(drive))) + { + fdc_notfound(); + d86f[drive].state = STATE_IDLE; + d86f[drive].index_count = 0; + return; + } + + if (!proxy) + { + d86f_reset_index_hole_pos(drive, side); + + if (d86f[drive].cur_track > 256) + { + // pclog("Track above 256\n"); + fdc_writeprotect(); + d86f[drive].state = STATE_IDLE; + d86f[drive].index_count = 0; + return; + } + + array_size = d86f_get_array_size(drive); + + if (d86f_has_surface_desc(drive)) + { + /* Preserve the physical holes but get rid of the fuzzy bytes. */ + for (i = 0; i < array_size; i++) + { + temp = d86f[drive].track_encoded_data[side][i] ^ 0xffff; + temp2 = d86f[drive].track_surface_data[side][i]; + temp &= temp2; + d86f[drive].track_surface_data[side][i] = temp; + } + } + /* Zero the data buffer. */ + memset(d86f[drive].track_encoded_data[side], 0, array_size << 1); + + d86f_add_track(drive, d86f[drive].cur_track); + if (!fdd_doublestep_40(drive)) + { + d86f_add_track(drive, d86f[drive].cur_track + 1); + } + } + + pclog("Formatting track %i side %i\n", track, side); + + d86f[drive].fill = fill; + + if (!proxy) + { + // d86f[drive].side_flags[side] &= 0xc0; + d86f[drive].side_flags[side] = 0; + d86f[drive].side_flags[side] |= (fdd_getrpm(drive ^ fdd_swap) == 360) ? 0x20 : 0; + d86f[drive].side_flags[side] |= fdc_get_bit_rate(); + d86f[drive].side_flags[side] |= fdc_is_mfm() ? 8 : 0; + + d86f[drive].index_hole_pos[side] = 0; + } + + d86f[drive].id_find.sync_marks = d86f[drive].id_find.bits_obtained = d86f[drive].id_find.bytes_obtained = 0; + d86f[drive].data_find.sync_marks = d86f[drive].data_find.bits_obtained = d86f[drive].data_find.bytes_obtained = 0; + d86f[drive].index_count = d86f[drive].error_condition = d86f[drive].satisfying_bytes = 0; + + d86f[drive].state = STATE_0D_SPIN_TO_INDEX; +} + +void d86f_proxy_format(int drive, int track, int side, int rate, uint8_t fill) +{ + d86f_common_format(drive, track, side, rate, fill, 1); +} + +void d86f_format(int drive, int track, int side, int rate, uint8_t fill) +{ + d86f_common_format(drive, track, side, rate, fill, 0); +} + +void d86f_common_handlers(int drive) +{ + drives[drive].readsector = d86f_readsector; + drives[drive].writesector = d86f_writesector; + drives[drive].comparesector=d86f_comparesector; + drives[drive].readaddress = d86f_readaddress; + drives[drive].hole = d86f_hole; + drives[drive].byteperiod = d86f_byteperiod; + drives[drive].poll = d86f_poll; + drives[drive].format = d86f_proxy_format; + drives[drive].stop = d86f_stop; +} + +void d86f_load(int drive, char *fn) +{ + uint32_t magic = 0; + uint32_t len = 0; + uint32_t len2 = 0; + uint8_t temp_file_name[2048]; + uint16_t temp = 0; + uint8_t tempb = 0; + uint64_t crc64 = 0; + uint64_t read_crc64 = 0; + int i = 0; + FILE *tf; + + d86f_unregister(drive); + + writeprot[drive] = 0; + d86f[drive].f = fopen(fn, "rb+"); + if (!d86f[drive].f) + { + d86f[drive].f = fopen(fn, "rb"); + if (!d86f[drive].f) + return; + writeprot[drive] = 1; + } + if (ui_writeprot[drive]) + { + writeprot[drive] = 1; + } + fwriteprot[drive] = writeprot[drive]; + + fseek(d86f[drive].f, 0, SEEK_END); + len = ftell(d86f[drive].f); + fseek(d86f[drive].f, 0, SEEK_SET); + + fread(&magic, 4, 1, d86f[drive].f); + + if (len < 16) + { + /* File is WAY too small, abort. */ + fclose(d86f[drive].f); + return; + } + + if ((magic != 0x46423638) && (magic != 0x66623638)) + { + /* File is not of the valid format, abort. */ + pclog("86F: Unrecognized magic bytes: %08X\n", magic); + fclose(d86f[drive].f); + return; + } + + fread(&(d86f[drive].version), 2, 1, d86f[drive].f); + + if (d86f[drive].version != 0x0200) + { + /* File is not of a recognized format version, abort. */ + if (d86f[drive].version == 0x0063) + { + pclog("86F: File has emulator-internal version 0.99, this version is not valid in a file\n"); + } + else if ((d86f[drive].version >= 0x0100) && (d86f[drive].version < 0x0200)) + { + pclog("86F: No longer supported development file version: %i.%02i\n", d86f[drive].version >> 8, d86f[drive].version & 0xFF); + } + else + { + pclog("86F: Unrecognized file version: %i.%02i\n", d86f[drive].version >> 8, d86f[drive].version & 0xFF); + } + fclose(d86f[drive].f); + return; + } + else + { + pclog("86F: Recognized file version: %i.%02i\n", d86f[drive].version >> 8, d86f[drive].version & 0xFF); + } + + fread(&(d86f[drive].disk_flags), 2, 1, d86f[drive].f); + + d86f[drive].is_compressed = (magic == 0x66623638) ? 1 : 0; + + if ((len < 51052) && !d86f[drive].is_compressed) + { + /* File too small, abort. */ + fclose(d86f[drive].f); + return; + } + + fseek(d86f[drive].f, 8, SEEK_SET); + fread(&read_crc64, 1, 8, d86f[drive].f); + + fseek(d86f[drive].f, 0, SEEK_SET); + + crc64 = 0xffffffffffffffff; + + d86f[drive].filebuf = malloc(len); + fread(d86f[drive].filebuf, 1, len, d86f[drive].f); + *(uint64_t *) &(d86f[drive].filebuf[8]) = 0xffffffffffffffff; + crc64 = (uint64_t) crc64speed(0, d86f[drive].filebuf, len); + free(d86f[drive].filebuf); + + if (crc64 != read_crc64) + { + pclog("86F: CRC64 error\n"); + fclose(d86f[drive].f); + return; + } + + if (d86f[drive].is_compressed) + { + append_filename(temp_file_name, pcempath, drive ? "TEMP$$$1.$$$" : "TEMP$$$0.$$$", 511); + memcpy(temp_file_name, drive ? "TEMP$$$1.$$$" : "TEMP$$$0.$$$", 13); + memcpy(d86f[drive].original_file_name, fn, strlen(fn) + 1); + + fclose(d86f[drive].f); + + d86f[drive].f = fopen(temp_file_name, "wb"); + if (!d86f[drive].f) + { + pclog("86F: Unable to create temporary decompressed file\n"); + return; + } + + tf = fopen(fn, "rb"); + + for (i = 0; i < 8; i++) + { + fread(&temp, 1, 2, tf); + fwrite(&temp, 1, 2, d86f[drive].f); + } + + if (d86f[drive].disk_flags & 0x80) + { + fread(&temp, 1, 2, tf); + fwrite(&temp, 1, 2, d86f[drive].f); + } + + // temp = d86f_zlib(d86f[drive].f, tf, 1); + + d86f[drive].filebuf = (uint8_t *) malloc(len); + d86f[drive].outbuf = (uint8_t *) malloc(67108864); + fread(d86f[drive].filebuf, 1, len, tf); + temp = lzf_decompress(d86f[drive].filebuf, len, d86f[drive].outbuf, 67108864); + if (temp) + { + fwrite(d86f[drive].outbuf, 1, temp, d86f[drive].f); + } + free(d86f[drive].outbuf); + free(d86f[drive].filebuf); + + fclose(tf); + fclose(d86f[drive].f); + + if (!temp) + { + pclog("86F: Error decompressing file\n"); + remove(temp_file_name); + return; + } + + d86f[drive].f = fopen(temp_file_name, "rb+"); + } + + if (d86f[drive].disk_flags & 0x100) + { + /* Zoned disk. */ + pclog("86F: Disk is zoned (Apple or Sony)\n"); + fclose(d86f[drive].f); + if (d86f[drive].is_compressed) + { + remove(temp_file_name); + } + return; + } + + if (d86f[drive].disk_flags & 0x600) + { + /* Zone type is not 0 but the disk is fixed-RPM. */ + pclog("86F: Disk is fixed-RPM but zone type is not 0\n"); + fclose(d86f[drive].f); + if (d86f[drive].is_compressed) + { + remove(temp_file_name); + } + return; + } + + if (!writeprot[drive]) + { + writeprot[drive] = (d86f[drive].disk_flags & 0x10) ? 1 : 0; + fwriteprot[drive] = writeprot[drive]; + } + + if (writeprot[drive]) + { + fclose(d86f[drive].f); + + if (d86f[drive].is_compressed) + { + d86f[drive].f = fopen(temp_file_name, "rb"); + } + else + { + d86f[drive].f = fopen(fn, "rb"); + } + } + + fseek(d86f[drive].f, 16, SEEK_SET); + + d86f[drive].extra_bit_cells = 0; + if (d86f[drive].disk_flags & 0x80) + { + fread(&(d86f[drive].extra_bit_cells), 1, 2, d86f[drive].f); + + if (d86f[drive].extra_bit_cells < -2048) + { + pclog("86F: Extra bit cells smaller than -2048\n"); + fclose(d86f[drive].f); + if (d86f[drive].is_compressed) + { + remove(temp_file_name); + } + return; + } + if (d86f[drive].extra_bit_cells > 2048) + { + pclog("86F: Extra bit cells bigger than 2048\n"); + fclose(d86f[drive].f); + if (d86f[drive].is_compressed) + { + remove(temp_file_name); } return; } } + + fread(d86f[drive].track_offset, 1, 1024, d86f[drive].f); + + if (!(d86f[drive].track_offset[0])) + { + /* File has no track 0, abort. */ + pclog("86F: No Track 0\n"); + fclose(d86f[drive].f); + return; + } + + /* Load track 0 flags as default. */ + fseek(d86f[drive].f, d86f[drive].track_offset[0], SEEK_SET); + fread(&(d86f[drive].side_flags[0]), 4, 1, d86f[drive].f); + if (d86f_get_sides(drive) == 2) + { + fread(&(d86f[drive].side_flags[1]), 4, 1, d86f[drive].f); + } + + fseek(d86f[drive].f, 0, SEEK_END); + d86f[drive].file_size = ftell(d86f[drive].f); + + fseek(d86f[drive].f, 0, SEEK_SET); + + d86f_register_86f(drive); + + drives[drive].seek = d86f_seek; + d86f_common_handlers(drive); + drives[drive].format = d86f_format; + + pclog("86F: Disk is %scompressed and %s surface description data\n", d86f[drive].is_compressed ? "" : "not ", d86f_has_surface_desc(drive) ? "has" : "does not have"); +} + +void d86f_init() +{ + disc_random_init(); + + memset(d86f, 0, sizeof(d86f)); + d86f_setupcrc(0x1021); + + crc64speed_init(); + + d86f[0].state = d86f[1].state = STATE_IDLE; +} + +void d86f_close(int drive) +{ + uint8_t temp_file_name[2048]; + + append_filename(temp_file_name, pcempath, drive ? "TEMP$$$1.$$$" : "TEMP$$$0.$$$", 511); + memcpy(temp_file_name, drive ? "TEMP$$$1.$$$" : "TEMP$$$0.$$$", 13); + + if (d86f[drive].f) + fclose(d86f[drive].f); + if (d86f[drive].is_compressed) + remove(temp_file_name); + d86f[drive].f = NULL; } diff --git a/src/disc_fdi.c b/src/disc_fdi.c index 8e8c98ba7..e6c071c0c 100644 --- a/src/disc_fdi.c +++ b/src/disc_fdi.c @@ -8,6 +8,7 @@ #include "disc_img.h" #include "disc_fdi.h" #include "fdc.h" +#include "fdd.h" #include "fdi2raw.h" static struct @@ -15,79 +16,101 @@ static struct FILE *f; FDI *h; uint8_t track_data[2][4][256*1024]; + uint8_t track_timing[2][4][256*1024]; int sides; + int track; int tracklen[2][4]; int trackindex[2][4]; int lasttrack; } fdi[2]; -static uint8_t fdi_timing[256*1024]; -static int fdi_pos; -static int fdi_revs; - -static int fdi_sector, fdi_track, fdi_side, fdi_drive, fdi_density, fdi_n; -static int fdi_inread, fdi_inwrite, fdi_incompare,fdi_readpos, fdi_inreadaddr; -static int fdi_satisfying_bytes; - -static uint16_t CRCTable[256]; - -static int pollbytesleft=0,pollbitsleft=0,polltotalbytes=0; - -int fdi_realtrack(int drive, int track) +uint16_t fdi_disk_flags(int drive) { - return track; -} + uint16_t temp_disk_flags = 0x80; /* We ALWAYS claim to have extra bit cells, even if the actual amount is 0. */ -static void fdi_setupcrc(uint16_t poly, uint16_t rvalue) -{ - int c = 256, bc; - uint16_t crctemp; - - while(c--) - { - crctemp = c << 8; - bc = 8; - - while(bc--) - { - if(crctemp & 0x8000) - { - crctemp = (crctemp << 1) ^ poly; - } - else - { - crctemp <<= 1; - } - } - - CRCTable[c] = crctemp; - } -} - -void fdi_init() -{ -// printf("FDI reset\n"); - memset(&fdi, 0, sizeof(fdi)); - fdi_setupcrc(0x1021, 0xcdb4); -} - -double fdi_byteperiod(int drive) -{ switch (fdi2raw_get_bit_rate(fdi[drive].h)) { - case 1000: - return 8.0; case 500: - return 16.0; + temp_disk_flags |= 2; case 300: - return 160.0 / 6.0; case 250: - return 32.0; + temp_disk_flags |= 0; + case 1000: + temp_disk_flags |= 4; default: - return 32.0; + temp_disk_flags |= 0; } + + if (fdi[drive].sides == 2) + { + temp_disk_flags |= 8; + } + + /* Tell the 86F handler that will handle our data to handle it in reverse byte endianness. */ + temp_disk_flags |= 0x800; + + return temp_disk_flags; +} + +uint16_t fdi_side_flags(int drive) +{ + uint16_t temp_side_flags = 0; + switch (fdi2raw_get_bit_rate(fdi[drive].h)) + { + case 500: + temp_side_flags = 0; + case 300: + temp_side_flags = 1; + case 250: + temp_side_flags = 2; + case 1000: + temp_side_flags = 3; + default: + temp_side_flags = 2; + } + if (fdi2raw_get_rotation(fdi[drive].h) == 360) + { + temp_side_flags |= 0x20; + } + + /* Set the encoding value to match that provided by the FDC. Then if it's wrong, it will sector not found anyway. */ + temp_side_flags |= 0x08; + + return temp_side_flags; +} + +int32_t fdi_extra_bit_cells(int drive) +{ + int side = 0; + int density = 0; + + int raw_size = 0; + + side = fdd_get_head(drive); + + switch (fdc_get_bit_rate()) + { + case 0: + raw_size = (fdd_getrpm(drive ^ fdd_swap) == 300) ? 200000 : 166666; + density = 2; + case 1: + raw_size = (fdd_getrpm(drive ^ fdd_swap) == 300) ? 120000 : 100000; + density = 1; + case 2: + raw_size = (fdd_getrpm(drive ^ fdd_swap) == 300) ? 100000 : 83333; + density = 1; + case 3: + case 5: + raw_size = (fdd_getrpm(drive ^ fdd_swap) == 300) ? 400000 : 333333; + density = 3; + default: + raw_size = (fdd_getrpm(drive ^ fdd_swap) == 300) ? 100000 : 83333; + density = 1; + } + + return (fdi[drive].tracklen[side][density] - raw_size); } int fdi_hole(int drive) @@ -103,6 +126,129 @@ int fdi_hole(int drive) } } +void fdi_read_revolution(int drive) +{ + int density; + int track = fdi[drive].track; + + int side = 0; + + if (track > fdi[drive].lasttrack) + { + for (density = 0; density < 4; density++) + { + memset(fdi[drive].track_data[0][density], 0, 106096); + memset(fdi[drive].track_data[1][density], 0, 106096); + fdi[drive].tracklen[0][density] = fdi[drive].tracklen[1][density] = 100000; + } + // pclog("Track is bigger than last track\n"); + return; + } + + for (density = 0; density < 4; density++) + { + for (side = 0; side < fdi[drive].sides; side++) + { + int c = fdi2raw_loadtrack(fdi[drive].h, (uint16_t *)fdi[drive].track_data[side][density], + (uint16_t *)fdi[drive].track_timing[side][density], + track * fdi[drive].sides, + &fdi[drive].tracklen[side][density], + &fdi[drive].trackindex[side][density], NULL, density); + // pclog("Side 0 [%i]: len %i, index %i\n", density, fdi[drive].tracklen[side][density], fdi[drive].trackindex[side][density]); + if (!c) + memset(fdi[drive].track_data[side][density], 0, fdi[drive].tracklen[side][density]); + } + } + + if (fdi[drive].sides == 1) + { + memset(fdi[drive].track_data[1][density], 0, 106096); + fdi[drive].tracklen[1][density] = 100000; + } +} + +uint32_t fdi_index_hole_pos(int drive, int side) +{ + int density; + + switch (fdc_get_bit_rate()) + { + case 0: + density = 2; + case 1: + density = 1; + case 2: + density = 1; + case 3: + case 5: + density = 3; + default: + density = 1; + } + + return fdi[drive].trackindex[side][density]; +} + +uint32_t fdi_get_raw_size(int drive) +{ + int side = 0; + int density; + + side = fdd_get_head(drive); + + switch (fdc_get_bit_rate()) + { + case 0: + density = 2; + case 1: + density = 1; + case 2: + density = 1; + case 3: + case 5: + density = 3; + default: + density = 1; + } + + return fdi[drive].tracklen[side][density]; +} + +uint16_t* fdi_encoded_data(int drive, int side) +{ + int density = 0; + + if (fdc_get_bit_rate() == 2) + density = 1; + if (fdc_get_bit_rate() == 0) + density = 2; + if (fdc_get_bit_rate() == 3) + density = 3; + + if (!fdc_is_mfm()) + { + density = 0; + } + + return (uint16_t *)fdi[drive].track_data[side][density]; +} + +void d86f_register_fdi(int drive) +{ + d86f_handler[drive].disk_flags = fdi_disk_flags; + d86f_handler[drive].side_flags = fdi_side_flags; + d86f_handler[drive].writeback = null_writeback; + d86f_handler[drive].set_sector = null_set_sector; + d86f_handler[drive].write_data = null_write_data; + d86f_handler[drive].format_conditions = null_format_conditions; + d86f_handler[drive].extra_bit_cells = fdi_extra_bit_cells; + d86f_handler[drive].encoded_data = fdi_encoded_data; + d86f_handler[drive].read_revolution = fdi_read_revolution; + d86f_handler[drive].index_hole_pos = fdi_index_hole_pos; + d86f_handler[drive].get_raw_size = fdi_get_raw_size; + d86f_handler[drive].check_crc = 1; +} + void fdi_load(int drive, char *fn) { char header[26]; @@ -111,6 +257,8 @@ void fdi_load(int drive, char *fn) fdi[drive].f = fopen(fn, "rb"); if (!fdi[drive].f) return; + d86f_unregister(drive); + fread(header, 1, 25, fdi[drive].f); fseek(fdi[drive].f, 0, SEEK_SET); header[25] = 0; @@ -128,22 +276,19 @@ void fdi_load(int drive, char *fn) fdi[drive].lasttrack = fdi2raw_get_last_track(fdi[drive].h); fdi[drive].sides = fdi2raw_get_last_head(fdi[drive].h) + 1; // printf("Last track %i\n",fdilasttrack[drive]); + + d86f_register_fdi(drive); + drives[drive].seek = fdi_seek; - drives[drive].readsector = fdi_readsector; - drives[drive].writesector = fdi_writesector; - drives[drive].comparesector=fdi_comparesector; - drives[drive].readaddress = fdi_readaddress; - drives[drive].hole = fdi_hole; - drives[drive].byteperiod = fdi_byteperiod; - drives[drive].poll = fdi_poll; - drives[drive].format = fdi_format; - drives[drive].stop = fdi_stop; - drives[drive].realtrack = fdi_realtrack; -// pclog("Loaded as FDI\n"); + d86f_common_handlers(drive); + + pclog("Loaded as FDI\n"); } void fdi_close(int drive) { + d86f_unregister(drive); + drives[drive].seek = NULL; if (fdi[drive].h) fdi2raw_header_free(fdi[drive].h); if (fdi[drive].f) @@ -153,8 +298,14 @@ void fdi_close(int drive) void fdi_seek(int drive, int track) { - int c; - int density; + if (fdd_doublestep_40(drive)) + { + if (fdi[drive].lasttrack < 43) + { + track /= 2; + } + // pclog("fdi_seek(): %i %i\n", fdi[drive].lasttrack, track); + } if (!fdi[drive].f) return; @@ -163,507 +314,13 @@ void fdi_seek(int drive, int track) track = 0; if (track > fdi[drive].lasttrack) track = fdi[drive].lasttrack - 1; - - for (density = 0; density < 4; density++) - { - int c = fdi2raw_loadtrack(fdi[drive].h, (uint16_t *)fdi[drive].track_data[0][density], - (uint16_t *)fdi_timing, - track * fdi[drive].sides, - &fdi[drive].tracklen[0][density], - &fdi[drive].trackindex[0][density], NULL, density); - if (!c) - memset(fdi[drive].track_data[0][density], 0, fdi[drive].tracklen[0][density]); - if (fdi[drive].sides == 2) - { - c = fdi2raw_loadtrack(fdi[drive].h, (uint16_t *)fdi[drive].track_data[1][density], - (uint16_t *)fdi_timing, - (track * fdi[drive].sides) + 1, - &fdi[drive].tracklen[1][density], - &fdi[drive].trackindex[1][density], NULL, density); - if (!c) - memset(fdi[drive].track_data[1][density], 0, fdi[drive].tracklen[1][density]); - } - else - { - memset(fdi[drive].track_data[1][density], 0, 65536); - fdi[drive].tracklen[1][density] = fdi[drive].tracklen[1][density] = 10000; - } - } + fdi[drive].track = track; + + fdi_read_revolution(drive); } -void fdi_writeback(int drive, int track) +void fdi_init() { - return; -} - -void fdi_readsector(int drive, int sector, int track, int side, int rate, int sector_size) -{ - fdi_revs = 0; - fdi_sector = sector; - fdi_track = track; - fdi_side = side; - fdi_n = sector_size; - fdi_drive = drive; - if (rate == 2) - fdi_density = 1; - if (rate == 0) - fdi_density = 2; - if (rate == 3) - fdi_density = 3; - -// pclog("FDI Read sector %i %i %i %i %i\n",drive,side,track,sector, fdi_density); -// if (pollbytesleft) -// pclog("In the middle of a sector!\n"); - - fdi_inread = 1; - fdi_inwrite = 0; - fdi_incompare = 0; - fdi_inreadaddr = 0; - fdi_readpos = 0; - fdi_satisfying_bytes = 0; -} - -void fdi_writesector(int drive, int sector, int track, int side, int rate, int sector_size) -{ - fdi_revs = 0; - fdi_sector = sector; - fdi_track = track; - fdi_side = side; - fdi_n = sector_size; - fdi_drive = drive; - if (rate == 2) - fdi_density = 1; - if (rate == 0) - fdi_density = 2; - if (rate == 3) - fdi_density = 3; -// pclog("Write sector %i %i %i %i\n",drive,side,track,sector); - - fdi_inread = 0; - fdi_inwrite = 1; - fdi_incompare = 0; - fdi_inreadaddr = 0; - fdi_readpos = 0; - fdi_satisfying_bytes = 0; -} - -void fdi_comparesector(int drive, int sector, int track, int side, int rate, int sector_size) -{ - fdi_revs = 0; - fdi_sector = sector; - fdi_track = track; - fdi_side = side; - fdi_n = sector_size; - fdi_drive = drive; - if (rate == 2) - fdi_density = 1; - if (rate == 0) - fdi_density = 2; - if (rate == 3) - fdi_density = 3; - -// pclog("FDI Read sector %i %i %i %i %i\n",drive,side,track,sector, fdi_density); -// if (pollbytesleft) -// pclog("In the middle of a sector!\n"); - - fdi_inread = 0; - fdi_inwrite = 0; - fdi_incompare = 1; - fdi_inreadaddr = 0; - fdi_readpos = 0; - fdi_satisfying_bytes = 0; -} - -void fdi_readaddress(int drive, int track, int side, int rate) -{ - fdi_revs = 0; - fdi_track = track; - fdi_side = side; - fdi_drive = drive; - if (rate == 2) - fdi_density = 1; - if (rate == 0) - fdi_density = 2; - if (rate == 3) - fdi_density = 3; -// pclog("Read address %i %i %i %i %i %p\n",drive,side,track, rate, fdi_density, &fdi_inreadaddr); - - fdi_inread = 0; - fdi_inwrite = 0; - fdi_incompare = 0; - fdi_inreadaddr = 1; - fdi_readpos = 0; - fdi_satisfying_bytes = 0; -} - -void fdi_format(int drive, int track, int side, int rate, uint8_t fill) -{ - fdi_revs = 0; - fdi_track = track; - fdi_side = side; - fdi_drive = drive; - if (rate == 2) - fdi_density = 1; - if (rate == 0) - fdi_density = 2; - if (rate == 3) - fdi_density = 3; -// pclog("Format %i %i %i\n",drive,side,track); - - fdi_inread = 0; - fdi_inwrite = 1; - fdi_incompare = 0; - fdi_inreadaddr = 0; - fdi_readpos = 0; - fdi_satisfying_bytes = 0; -} - -static uint16_t fdi_buffer; -static int readidpoll=0,readdatapoll=0,comparedatapoll=0,fdi_nextsector=0,inreadop=0; -static uint8_t fdi_sectordat[1026]; -static int lastfdidat[2],sectorcrc[2]; -static int sectorsize,fdc_sectorsize; -static int ddidbitsleft=0; - -static uint8_t decodefm(uint16_t dat) -{ - uint8_t temp; - temp = 0; - if (dat & 0x0001) temp |= 1; - if (dat & 0x0004) temp |= 2; - if (dat & 0x0010) temp |= 4; - if (dat & 0x0040) temp |= 8; - if (dat & 0x0100) temp |= 16; - if (dat & 0x0400) temp |= 32; - if (dat & 0x1000) temp |= 64; - if (dat & 0x4000) temp |= 128; - return temp; -} - -void fdi_stop(int drive) -{ -// pclog("fdi_stop\n"); - fdi_inread = fdi_inwrite = fdi_inreadaddr = 0; - fdi_nextsector = ddidbitsleft = pollbitsleft = 0; -} - -static uint16_t crc; - -static void calccrc(uint8_t byte) -{ - crc = (crc << 8) ^ CRCTable[(crc >> 8)^byte]; -} - -static int fdi_indextime_blank = 6250 * 8; -void fdi_poll() -{ - int tempi, c; - int bitcount; - int indata, readdata; - int side = fdd_get_head(fdi_drive); - - for (bitcount = 0; bitcount < 16; bitcount++) - { - if (fdi_pos >= fdi[fdi_drive].tracklen[side][fdi_density]) - { - fdi_pos = 0; - if (fdi[fdi_drive].tracklen[side][fdi_density]) - fdc_indexpulse(); - else - { - fdi_indextime_blank--; - if (!fdi_indextime_blank) - { - fdi_indextime_blank = 6250 * 8; - fdc_indexpulse(); - } - } - } - tempi = fdi[fdi_drive].track_data[side][fdi_density][((fdi_pos >> 3) & 0xFFFF) ^ 1] & (1 << (7 - (fdi_pos & 7))); - fdi_pos++; - fdi_buffer <<= 1; - fdi_buffer |= (tempi ? 1 : 0); - if (fdi_inwrite) - { - fdi_inwrite = 0; - fdc_writeprotect(); - return; - } - if (!fdi_inread && !fdi_inreadaddr && !fdi_incompare) - return; - if (fdi_pos == fdi[fdi_drive].trackindex[side][fdi_density]) - { - fdi_revs++; - if (fdi_revs == 3) - { -// pclog("Not found!\n"); - fdc_notfound(); - fdi_inread = fdi_inreadaddr = 0; - return; - } - if (fdi_sector == SECTOR_FIRST) - fdi_sector = SECTOR_NEXT; - } - if (pollbitsleft) - { - pollbitsleft--; - if (!pollbitsleft) - { - pollbytesleft--; - if (pollbytesleft) pollbitsleft = 16; /*Set up another word if we need it*/ - if (readidpoll) - { - fdi_sectordat[5 - pollbytesleft] = decodefm(fdi_buffer); - if (fdi_inreadaddr && !fdc_sectorid)// && pollbytesleft > 1) - { -// rpclog("inreadaddr - %02X\n", fdi_sectordat[5 - pollbytesleft]); - fdc_data(fdi_sectordat[5 - pollbytesleft]); - } - if (!pollbytesleft) - { -// pclog("Header over %i,%i %i,%i\n", fdi_sectordat[0], fdi_sectordat[2], fdi_track, fdi_sector); - if ((fdi_sectordat[0] == fdi_track && (fdi_sectordat[3] == fdi_n) && (fdi_sectordat[2] == fdi_sector || fdi_sector == SECTOR_NEXT)) || fdi_inreadaddr) - { - crc = (fdi_density) ? 0xcdb4 : 0xffff; - calccrc(0xFE); - for (c = 0; c < 4; c++) - calccrc(fdi_sectordat[c]); - - if ((crc >> 8) != fdi_sectordat[4] || (crc & 0xFF) != fdi_sectordat[5]) - { -// pclog("Header CRC error : %02X %02X %02X %02X\n",crc>>8,crc&0xFF,fdi_sectordat[4],fdi_sectordat[5]); -// dumpregs(); -// exit(-1); - inreadop = 0; - if (fdi_inreadaddr) - { -// rpclog("inreadaddr - %02X\n", fdi_sector); -// fdc_data(fdi_sector); - if (fdc_sectorid) - fdc_sectorid(fdi_sectordat[0], fdi_sectordat[1], fdi_sectordat[2], fdi_sectordat[3], fdi_sectordat[4], fdi_sectordat[5]); - else - fdc_finishread(); - } - else fdc_headercrcerror(); - return; - } -// pclog("Sector %i,%i %i,%i\n", fdi_sectordat[0], fdi_sectordat[2], fdi_track, fdi_sector); - if (fdi_sectordat[0] == fdi_track && (fdi_sectordat[2] == fdi_sector || fdi_sector == SECTOR_NEXT) && fdi_inread && !fdi_inreadaddr) - { - fdi_nextsector = 1; - readidpoll = 0; - sectorsize = (1 << (fdi_sectordat[3] + 7)) + 2; - fdc_sectorsize = fdi_sectordat[3]; - } - if (fdi_inreadaddr) - { - if (fdc_sectorid) - fdc_sectorid(fdi_sectordat[0], fdi_sectordat[1], fdi_sectordat[2], fdi_sectordat[3], fdi_sectordat[4], fdi_sectordat[5]); - else - fdc_finishread(); - fdi_inreadaddr = 0; - } - } - } - } - if (readdatapoll) - { -// pclog("readdatapoll %i %02x\n", pollbytesleft, decodefm(fdi_buffer)); - if (pollbytesleft > 1) - { - calccrc(decodefm(fdi_buffer)); - } - else - sectorcrc[1 - pollbytesleft] = decodefm(fdi_buffer); - if (!pollbytesleft) - { - fdi_inread = 0; -//#if 0 - if ((crc >> 8) != sectorcrc[0] || (crc & 0xFF) != sectorcrc[1])// || (fditrack==79 && fdisect==4 && fdc_side&1)) - { -// pclog("Data CRC error : %02X %02X %02X %02X %i %04X %02X%02X\n",crc>>8,crc&0xFF,sectorcrc[0],sectorcrc[1],fdi_pos,crc,sectorcrc[0],sectorcrc[1]); - inreadop = 0; - fdc_data(decodefm(lastfdidat[1])); - fdc_finishread(); - fdc_datacrcerror(); - readdatapoll = 0; - return; - } -//#endif -// pclog("End of FDI read %02X %02X %02X %02X\n",crc>>8,crc&0xFF,sectorcrc[0],sectorcrc[1]); - fdc_data(decodefm(lastfdidat[1])); - fdc_finishread(); - } - else if (lastfdidat[1] != 0) - fdc_data(decodefm(lastfdidat[1])); - lastfdidat[1] = lastfdidat[0]; - lastfdidat[0] = fdi_buffer; - if (!pollbytesleft) - readdatapoll = 0; - } - if (comparedatapoll) - { -// pclog("readdatapoll %i %02x\n", pollbytesleft, decodefm(fdi_buffer)); - if (pollbytesleft > 1) - { - calccrc(decodefm(fdi_buffer)); - } - else - sectorcrc[1 - pollbytesleft] = decodefm(fdi_buffer); - if (!pollbytesleft) - { - fdi_inread = 0; -//#if 0 - if ((crc >> 8) != sectorcrc[0] || (crc & 0xFF) != sectorcrc[1])// || (fditrack==79 && fdisect==4 && fdc_side&1)) - { -// pclog("Data CRC error : %02X %02X %02X %02X %i %04X %02X%02X\n",crc>>8,crc&0xFF,sectorcrc[0],sectorcrc[1],fdi_pos,crc,sectorcrc[0],sectorcrc[1]); - inreadop = 0; - fdc_data(decodefm(lastfdidat[1])); - fdc_finishcompare(fdi_satisfying_bytes == polltotalbytes); - fdc_datacrcerror(); - comparedatapoll = 0; - return; - } -//#endif -// pclog("End of FDI read %02X %02X %02X %02X\n",crc>>8,crc&0xFF,sectorcrc[0],sectorcrc[1]); - indata = fdc_getdata(!pollbytesleft); - readdata = decodefm(lastfdidat[1]); - if (indata == -1) - { - indata = 0; - } - switch(fdc_get_compare_condition()) - { - case 0: /* SCAN EQUAL */ - if ((indata == readdata) || (indata == 0xFF)) - { - fdi_satisfying_bytes++; - } - break; - case 1: /* SCAN LOW OR EQUAL */ - if ((indata <= readdata) || (indata == 0xFF)) - { - fdi_satisfying_bytes++; - } - break; - case 2: /* SCAN HIGH OR EQUAL */ - if ((indata >= readdata) || (indata == 0xFF)) - { - fdi_satisfying_bytes++; - } - break; - } - fdc_finishcompare(fdi_satisfying_bytes == polltotalbytes); - } - else if (lastfdidat[1] != 0) - { - indata = fdc_getdata(!pollbytesleft); - readdata = decodefm(lastfdidat[1]); - if (indata == -1) - { - indata = 0; - } - switch(fdc_get_compare_condition()) - { - case 0: /* SCAN EQUAL */ - if ((indata == readdata) || (indata == 0xFF)) - { - fdi_satisfying_bytes++; - } - break; - case 1: /* SCAN LOW OR EQUAL */ - if ((indata <= readdata) || (indata == 0xFF)) - { - fdi_satisfying_bytes++; - } - break; - case 2: /* SCAN HIGH OR EQUAL */ - if ((indata >= readdata) || (indata == 0xFF)) - { - fdi_satisfying_bytes++; - } - break; - } - } - lastfdidat[1] = lastfdidat[0]; - lastfdidat[0] = fdi_buffer; - if (!pollbytesleft) - readdatapoll = 0; - } - } - } - if (fdi_buffer == 0x4489 && fdi_density) - { -// rpclog("Found sync\n"); - ddidbitsleft = 17; - } - - if (fdi_buffer == 0xF57E && !fdi_density) - { - pollbytesleft = 6; - pollbitsleft = 16; - readidpoll = 1; - } - if ((fdi_buffer == 0xF56F || fdi_buffer == 0xF56A) && !fdi_density) - { - if (fdi_nextsector) - { - pollbytesleft = sectorsize; - pollbitsleft = 16; - if (fdi_inread) - { - readdatapoll = 1; - } - else - { - polltotalbytes = sectorsize; - comparedatapoll = 1; - } - fdi_nextsector = 0; - crc = 0xffff; - if (fdi_buffer == 0xF56A) calccrc(0xF8); - else calccrc(0xFB); - lastfdidat[0] = lastfdidat[1] = 0; - } - } - if (ddidbitsleft) - { - ddidbitsleft--; - if (!ddidbitsleft && !readdatapoll) - { -// printf("ID bits over %04X %02X %i\n",fdibuffer,decodefm(fdibuffer),fdipos); - if (decodefm(fdi_buffer) == 0xFE) - { -// printf("Sector header %i %i\n", fdi_inread, fdi_inreadaddr); - pollbytesleft = 6; - pollbitsleft = 16; - readidpoll = 1; - } - else if (decodefm(fdi_buffer) == 0xFB) - { -// printf("Data header %i %i\n", fdi_inread, fdi_inreadaddr); - if (fdi_nextsector) - { - pollbytesleft = sectorsize; - pollbitsleft = 16; - if (fdi_inread) - { - readdatapoll = 1; - } - else - { - polltotalbytes = sectorsize; - comparedatapoll = 1; - } - fdi_nextsector = 0; - crc = 0xcdb4; - if (fdi_buffer == 0xF56A) calccrc(0xF8); - else calccrc(0xFB); - lastfdidat[0] = lastfdidat[1] = 0; - } - } - } - } - } +// printf("FDI reset\n"); } diff --git a/src/disc_fdi.h b/src/disc_fdi.h index c977e0b31..d26340fd0 100644 --- a/src/disc_fdi.h +++ b/src/disc_fdi.h @@ -14,4 +14,3 @@ int fdi_hole(int drive); double fdi_byteperiod(int drive); void fdi_stop(); void fdi_poll(); -int fdi_realtrack(int track, int drive); diff --git a/src/disc_imd.c b/src/disc_imd.c index 966401309..06fd0a45a 100644 --- a/src/disc_imd.c +++ b/src/disc_imd.c @@ -33,6 +33,7 @@ static struct int track_count, sides; int track; uint16_t disk_flags; + int track_width; imd_track_t tracks[256][2]; uint16_t current_side_flags[2]; uint8_t xdf_ordered_pos[256][2]; @@ -261,7 +262,8 @@ void imd_load(int drive, char *fn) } } - if (imd[drive].track_count > 43) imd[drive].disk_flags |= 1; /* If the image has more than 43 tracks, then the tracks are thin (96 tpi). */ + imd[drive].track_width = 0; + if (imd[drive].track_count > 43) imd[drive].track_width = 1; /* If the image has more than 43 tracks, then the tracks are thin (96 tpi). */ if (imd[drive].sides == 2) imd[drive].disk_flags |= 8; /* If the has 2 sides, mark it as such. */ d86f_register_imd(drive); @@ -274,7 +276,6 @@ void imd_load(int drive, char *fn) void imd_close(int drive) { int i = 0; - int j = 0; d86f_unregister(drive); if (imd[drive].f) { @@ -441,7 +442,6 @@ int imd_track_is_interleave(int drive, int side, int track) void imd_sector_to_buffer(int drive, int track, int side, uint8_t *buffer, int sector, int len) { - int i = 0; int type = imd[drive].buffer[imd[drive].tracks[track][side].sector_data_offs[sector]]; if (type == 0) { @@ -471,7 +471,6 @@ void imd_seek(int drive, int track) int c = 0; int h = 0; - int r = 0; int n = 0; int ssize = 512; @@ -505,7 +504,7 @@ void imd_seek(int drive, int track) // pclog("IMD: Seeking...\n"); - if (d86f_is_40_track(drive) && fdd_doublestep_40(drive)) + if (!imd[drive].track_width && fdd_doublestep_40(drive)) track /= 2; is_trackx = (track == 0) ? 0 : 1; @@ -524,7 +523,7 @@ void imd_seek(int drive, int track) { track_rate = imd[drive].current_side_flags[side] & 7; if (!track_rate && (imd[drive].current_side_flags[side] & 0x20)) track_rate = 4; - if ((imd[drive].current_side_flags[side] & 27) == 0x21) track_rate = 2; + if ((imd[drive].current_side_flags[side] & 0x27) == 0x21) track_rate = 2; r_map = imd[drive].buffer + imd[drive].tracks[track][side].r_map_offs; h = imd[drive].tracks[track][side].params[2]; @@ -559,7 +558,7 @@ void imd_seek(int drive, int track) interleave_type = imd_track_is_interleave(drive, side, track); - current_pos = d86f_prepare_pretrack(drive, side, 0, 1); + current_pos = d86f_prepare_pretrack(drive, side, 0); if (!xdf_type) { @@ -589,7 +588,7 @@ void imd_seek(int drive, int track) // pclog("IMD: (%i %i) %i %i %i %i (%i %i) (GPL=%i)\n", track, side, id[0], id[1], id[2], id[3], deleted, bad_crc, track_gap3); imd_sector_to_buffer(drive, track, side, data, actual_sector, ssize); - current_pos = d86f_prepare_sector(drive, side, current_pos, id, data, ssize, 1, 22, track_gap3, 0, deleted, bad_crc); + current_pos = d86f_prepare_sector(drive, side, current_pos, id, data, ssize, 22, track_gap3, deleted, bad_crc); track_buf_pos[side] += ssize; } } @@ -617,11 +616,11 @@ void imd_seek(int drive, int track) if (is_trackx) { - current_pos = d86f_prepare_sector(drive, side, xdf_trackx_spos[xdf_type][xdf_sector], id, data, ssize, 1, track_gap2, xdf_gap3_sizes[xdf_type][is_trackx], 0, deleted, bad_crc); + current_pos = d86f_prepare_sector(drive, side, xdf_trackx_spos[xdf_type][xdf_sector], id, data, ssize, track_gap2, xdf_gap3_sizes[xdf_type][is_trackx], deleted, bad_crc); } else { - current_pos = d86f_prepare_sector(drive, side, current_pos, id, data, ssize, 1, track_gap2, xdf_gap3_sizes[xdf_type][is_trackx], 0, deleted, bad_crc); + current_pos = d86f_prepare_sector(drive, side, current_pos, id, data, ssize, track_gap2, xdf_gap3_sizes[xdf_type][is_trackx], deleted, bad_crc); } track_buf_pos[side] += ssize; @@ -701,7 +700,6 @@ void imd_writeback(int drive) int i = 0; - uint8_t *track_buf; uint8_t *n_map; uint8_t h, n, spt; @@ -711,7 +709,6 @@ void imd_writeback(int drive) { if (imd[drive].tracks[track][side].is_present) { - track_buf = imd[drive].buffer + imd[drive].tracks[track][side].file_offs; fseek(imd[drive].f, imd[drive].tracks[track][side].file_offs, SEEK_SET); h = imd[drive].tracks[track][side].params[2]; spt = imd[drive].tracks[track][side].params[3]; @@ -740,19 +737,6 @@ void imd_writeback(int drive) } } -uint8_t imd_poll_read_data(int drive, int side, uint16_t pos) -{ - int type = imd[drive].current_data[side][0]; - if (!type) - { - return 0; - } - else - { - return (type & 1) ? imd[drive].current_data[side][pos + 1] : imd[drive].current_data[side][1]; - } -} - void imd_poll_write_data(int drive, int side, uint16_t pos, uint8_t data) { int type = imd[drive].current_data[side][0]; @@ -784,8 +768,12 @@ void d86f_register_imd(int drive) d86f_handler[drive].side_flags = imd_side_flags; d86f_handler[drive].writeback = imd_writeback; d86f_handler[drive].set_sector = imd_set_sector; - d86f_handler[drive].read_data = imd_poll_read_data; d86f_handler[drive].write_data = imd_poll_write_data; d86f_handler[drive].format_conditions = imd_format_conditions; + d86f_handler[drive].extra_bit_cells = null_extra_bit_cells; + d86f_handler[drive].encoded_data = common_encoded_data; + d86f_handler[drive].read_revolution = common_read_revolution; + d86f_handler[drive].index_hole_pos = null_index_hole_pos; + d86f_handler[drive].get_raw_size = common_get_raw_size; d86f_handler[drive].check_crc = 1; } diff --git a/src/disc_img.c b/src/disc_img.c index e6abf55c8..cf399ad7a 100644 --- a/src/disc_img.c +++ b/src/disc_img.c @@ -2,74 +2,125 @@ see COPYING for more details */ #include "ibm.h" +#include "fdc.h" #include "fdd.h" #include "disc.h" #include "disc_img.h" -#include "disc_sector.h" static struct { FILE *f; - // uint8_t track_data[2][20*1024]; uint8_t track_data[2][50000]; int sectors, tracks, sides; - int sector_size; - int rate; + uint8_t sector_size; int xdf_type; /* 0 = not XDF, 1-5 = one of the five XDF types */ + int dmf; int hole; - int byte_period; - double bitcell_period_300rpm; + int track; + int track_width; uint32_t base; + uint8_t gap2_size; + uint8_t gap3_size; + uint16_t disk_flags; + uint16_t track_flags; + uint8_t sector_pos_side[2][256]; + uint16_t sector_pos[2][256]; + uint8_t current_sector_pos_side; + uint16_t current_sector_pos; } img[2]; -static uint8_t xdf_track0[3][3]; -static uint8_t xdf_spt[3] = { 6, 8, 8 }; -static uint8_t xdf_map[3][24][3]; -static uint16_t xdf_track0_layout[3][92] = { { 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700, 0x8800, - 0x8101, 0x8201, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, - 0x0700, 0x0800, 0, 0x8301, 0x8401, 0x8501, 0x8601, 0x8701, - 0x8801, 0x8901, 0x8A01, 0x8B01, 0x8C01, 0x8D01, 0x8E01, 0x8F01, - 0x9001 }, /* 5.25" 2HD */ - { 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700, 0x8800, - 0x8900, 0x8A00, 0x8B00, 0x8101, 0x0100, 0x0200, 0x0300, 0x0400, - 0x0500, 0x0600, 0x0700, 0x0800, 0, 0, 0, 0x8201, - 0x8301, 0x8401, 0x8501, 0x8601, 0x8701, 0x8801, 0x8901, 0x8A01, - 0x8B01, 0x8C01, 0x8D01, 0x8E01, 0x8F01, 0, 0, 0, - 0, 0, 0x9001, 0x9101, 0x9201, 0x9301 }, /* 3.5" 2HD */ - { 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700, 0x8800, - 0x8900, 0x8A00, 0x8B00, 0x8C00, 0x8D00, 0x8E00, 0x8F00, 0x9000, - 0x9100, 0x9200, 0x9300, 0x9400, 0x9500, 0x9600, 0x9700, 0x0100, - 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700, 0x0800, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0x9800, 0x9900, 0x9A00, - 0x9B00, 0x9C00, 0x9D00, 0x9E00, 0x8101, 0x8201, 0x8301, 0x8401, - 0x8501, 0x8601, 0x8701, 0x8801, 0, 0, 0, 0, - 0x8901, 0x8A01, 0x8B01, 0x8C01, 0x8D01, 0x8E01, 0x8F01, 0x9001, - 0x9101, 0x9201, 0x9301, 0x9401, 0x9501, 0x9601, 0x9701, 0x9801, - 0x9901, 0x9A01, 0x9B01, 0x9C01, 0x9D01, 0x9E01, 0x9F01, 0xA001, - 0xA101, 0xA201, 0xA301, 0xA401 }, - }; -static uint16_t xdf_sector_pos[256]; +uint8_t dmf_r[21] = { 12, 2, 13, 3, 14, 4, 15, 5, 16, 6, 17, 7, 18, 8, 19, 9, 20, 10, 21, 11, 1 }; +static uint8_t xdf_spt[2] = { 6, 8 }; +static uint8_t xdf_logical_sectors[2][2] = { { 38, 6 }, { 46, 8 } }; +uint8_t xdf_physical_sectors[2][2] = { { 16, 3 }, { 19, 4 } }; +uint8_t xdf_gap3_sizes[2][2] = { { 60, 69 }, { 60, 50 } }; +uint16_t xdf_trackx_spos[2][8] = { { 0xA7F, 0xF02, 0x11B7, 0xB66, 0xE1B, 0x129E }, { 0x302, 0x7E2, 0xA52, 0x12DA, 0x572, 0xDFA, 0x106A, 0x154A } }; + +/* XDF: Layout of the sectors in the image. */ +xdf_sector_t xdf_img_layout[2][2][46] = { { { 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700, 0x8800, + 0x8101, 0x8201, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, + 0x0700, 0x0800, 0, + 0x8301, 0x8401, 0x8501, 0x8601, 0x8701, 0x8801, 0x8901, 0x8A01, + 0x8B01, 0x8C01, 0x8D01, 0x8E01, 0x8F01, 0x9001, 0, 0, + 0, 0, 0 }, + { 0x8300, 0x8600, 0x8201, 0x8200, 0x8601, 0x8301 } + }, /* 5.25" 2HD */ + { { 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700, 0x8800, + 0x8900, 0x8A00, 0x8B00, 0x8101, 0x0100, 0x0200, 0x0300, 0x0400, + 0x0500, 0x0600, 0x0700, 0x0800, 0, 0, 0, + 0x8201, 0x8301, 0x8401, 0x8501, 0x8601, 0x8701, 0x8801, 0x8901, + 0x8A01, 0x8B01, 0x8C01, 0x8D01, 0x8E01, 0x8F01, 0, 0, + 0, 0, 0, 0x9001, 0x9101, 0x9201, 0x9301 }, + { 0x8300, 0x8400, 0x8601, 0x8200, 0x8201, 0x8600, 0x8401, 0x8301 } + } /* 3.5" 2HD */ + }; + +/* XDF: Layout of the sectors on the disk's track. */ +xdf_sector_t xdf_disk_layout[2][2][38] = { { { 0x0100, 0x0200, 0x8100, 0x8800, 0x8200, 0x0300, 0x8300, 0x0400, + 0x8400, 0x0500, 0x8500, 0x0600, 0x8600, 0x0700, 0x8700, 0x0800, + 0x8D01, 0x8501, 0x8E01, 0x8601, 0x8F01, 0x8701, 0x9001, 0x8801, + 0x8101, 0x8901, 0x8201, 0x8A01, 0x8301, 0x8B01, 0x8401, 0x8C01 }, + { 0x8300, 0x8200, 0x8600, 0x8201, 0x8301, 0x8601 } + }, /* 5.25" 2HD */ + { { 0x0100, 0x8A00, 0x8100, 0x8B00, 0x8200, 0x0200, 0x8300, 0x0300, + 0x8400, 0x0400, 0x8500, 0x0500, 0x8600, 0x0600, 0x8700, 0x0700, + 0x8800, 0x0800, 0x8900, + 0x9001, 0x8701, 0x9101, 0x8801, 0x9201, 0x8901, 0x9301, 0x8A01, + 0x8101, 0x8B01, 0x8201, 0x8C01, 0x8301, 0x8D01, 0x8401, 0x8E01, + 0x8501, 0x8F01, 0x8601 }, + { 0x8300, 0x8200, 0x8400, 0x8600, 0x8401, 0x8201, 0x8301, 0x8601 }, + }, /* 3.5" 2HD */ + }; /* First dimension is possible sector sizes (0 = 128, 7 = 16384), second is possible bit rates (250/360, 250, 300, 500/360, 500, 1000). */ /* Disks formatted at 250 kbps @ 360 RPM can be read with a 360 RPM single-RPM 5.25" drive by setting the rate to 250 kbps. Disks formatted at 300 kbps @ 300 RPM can be read with any 300 RPM single-RPM drive by setting the rate rate to 300 kbps. */ static uint8_t maximum_sectors[8][6] = { { 26, 31, 38, 53, 64, 118 }, /* 128 */ { 15, 19, 23, 32, 38, 73 }, /* 256 */ - { 7, 10, 12, 19, 23, 46 }, /* 512 */ + { 7, 10, 12, 17, 21, 41 }, /* 512 */ { 3, 5, 6, 9, 11, 22 }, /* 1024 */ { 2, 2, 3, 4, 5, 11 }, /* 2048 */ { 1, 1, 1, 2, 2, 5 }, /* 4096 */ { 0, 0, 0, 1, 1, 3 }, /* 8192 */ { 0, 0, 0, 0, 0, 1 } }; /* 16384 */ -static int gap3_sizes[5][8][256] = { [0][1][16] = 0x54, +static uint8_t xdf_sectors[8][6] = { { 0, 0, 0, 0, 0, 0 }, /* 128 */ + { 0, 0, 0, 0, 0, 0 }, /* 256 */ + { 0, 0, 0, 19, 23, 0 }, /* 512 */ + { 0, 0, 0, 0, 0, 0 }, /* 1024 */ + { 0, 0, 0, 0, 0, 0 }, /* 2048 */ + { 0, 0, 0, 0, 0, 0 }, /* 4096 */ + { 0, 0, 0, 0, 0, 0 }, /* 8192 */ + { 0, 0, 0, 0, 0, 0 } }; /* 16384 */ + +static uint8_t xdf_types[8][6] = { { 0, 0, 0, 0, 0, 0 }, /* 128 */ + { 0, 0, 0, 0, 0, 0 }, /* 256 */ + { 0, 0, 0, 1, 2, 0 }, /* 512 */ + { 0, 0, 0, 0, 0, 0 }, /* 1024 */ + { 0, 0, 0, 0, 0, 0 }, /* 2048 */ + { 0, 0, 0, 0, 0, 0 }, /* 4096 */ + { 0, 0, 0, 0, 0, 0 }, /* 8192 */ + { 0, 0, 0, 0, 0, 0 } }; /* 16384 */ + +static double bit_rates_300[6] = { (250.0 * 300.0) / 360.0, 250.0, 300.0, (500.0 * 300.0) / 360.0, 500.0, 1000.0 }; + +static uint8_t rates[6] = { 2, 2, 1, 4, 0, 3 }; + +static uint8_t holes[6] = { 0, 0, 0, 1, 1, 2 }; + +int gap3_sizes[5][8][256] = { [0][1][16] = 0x54, [0][2][18] = 0x6C, [0][2][19] = 0x48, [0][2][20] = 0x2A, - [0][2][21] = 0x0C, + [0][2][21] = 0x08, /* Microsoft DMFWRITE.EXE uses this, 0x0C is used by FDFORMAT. */ [0][2][23] = 0x01, + [0][3][10] = 0x83, [0][3][11] = 0x26, + [1][2][11] = 0x54, + [1][2][12] = 0x1C, + [1][2][13] = 0x0E, + [1][3][6] = 0x79, + [1][3][7] = 0x06, [2][1][10] = 0x32, [2][1][11] = 0x0C, [2][1][15] = 0x36, @@ -77,30 +128,32 @@ static int gap3_sizes[5][8][256] = { [0][1][16] = 0x54, [2][2][8] = 0x58, [2][2][9] = 0x50, [2][2][10] = 0x2E, - [2][2][11] = 0x02, [2][2][21] = 0x1C, [2][3][4] = 0xF0, [2][3][5] = 0x74, [3][2][36] = 0x53, - [3][2][39] = 0x20, + [3][2][37] = 0x4E, + [3][2][38] = 0x3D, + [3][2][39] = 0x2C, + [3][2][40] = 0x1C, + [3][2][41] = 0x0D, + [3][2][42] = 0x02, [3][2][46] = 0x01, + [3][3][18] = 0xF7, + [3][3][19] = 0xAF, + [3][3][20] = 0x6F, + [3][3][21] = 0x55, + [3][3][22] = 0x1F, [4][1][32] = 0x36, + [4][2][14] = 0x92, [4][2][15] = 0x54, + [4][2][16] = 0x38, [4][2][17] = 0x23, - [4][2][18] = 0x02, [4][2][19] = 0x01, - [4][3][8] = 0x74 + [4][3][8] = 0x74, + [4][3][9] = 0x24 }; -/* Needed for formatting! */ -int img_realtrack(int drive, int track) -{ - if ((img[drive].tracks <= 43) && fdd_doublestep_40(drive)) - track /= 2; - - return track; -} - void img_writeback(int drive); static int sector_size_code(int sector_size) @@ -138,18 +191,7 @@ void img_init() // adl[0] = adl[1] = 0; } -static void add_to_map(uint8_t *arr, uint8_t p1, uint8_t p2, uint8_t p3) -{ - arr[0] = p1; - arr[1] = p2; - arr[2] = p3; -} - -static int xdf_maps_initialized = 0; - -static uint16_t xdf_trackx_layout[3][8] = { { 0x8300, 0x8600, 0x8201, 0x8200, 0x8601, 0x8301}, - { 0x8300, 0x8400, 0x8601, 0x8200, 0x8201, 0x8600, 0x8401, 0x8301}, - { 0x8300, 0x8400, 0x8500, 0x8700, 0x8301, 0x8401, 0x8501, 0x8701} }; +void d86f_register_img(int drive); void img_load(int drive, char *fn) { @@ -165,12 +207,15 @@ void img_load(int drive, char *fn) int temp_rate; char ext[4]; int fdi; + int i; ext[0] = fn[strlen(fn) - 3] | 0x60; ext[1] = fn[strlen(fn) - 2] | 0x60; ext[2] = fn[strlen(fn) - 1] | 0x60; ext[3] = 0; + d86f_unregister(drive); + writeprot[drive] = 0; img[drive].f = fopen(fn, "rb+"); if (!img[drive].f) @@ -230,7 +275,7 @@ void img_load(int drive, char *fn) } img[drive].sides = 2; - img[drive].sector_size = 512; + img[drive].sector_size = 2; img[drive].hole = 0; @@ -241,74 +286,47 @@ void img_load(int drive, char *fn) /* The BPB is giving us a wacky number of sides and/or bytes per sector, therefore it is most probably not a BPB at all, so we have to guess the parameters from file size. */ - if (size <= (160*1024)) { img[drive].sectors = 8; img[drive].tracks = 40; img[drive].sides = 1; bit_rate_300 = 250; raw_tsize[drive] = 6250; } - else if (size <= (180*1024)) { img[drive].sectors = 9; img[drive].tracks = 40; img[drive].sides = 1; bit_rate_300 = 250; raw_tsize[drive] = 6250; } - else if (size <= (320*1024)) { img[drive].sectors = 8; img[drive].tracks = 40; bit_rate_300 = 250; raw_tsize[drive] = 6250; } - else if (size <= (360*1024)) { img[drive].sectors = 9; img[drive].tracks = 40; bit_rate_300 = 250; raw_tsize[drive] = 6250; } /*Double density*/ - else if (size <= (640*1024)) { img[drive].sectors = 8; img[drive].tracks = 80; bit_rate_300 = 250; raw_tsize[drive] = 6250; } /*Double density 640k*/ - else if (size < (1024*1024)) { img[drive].sectors = 9; img[drive].tracks = 80; bit_rate_300 = 250; raw_tsize[drive] = 6250; } /*Double density*/ - else if (size <= 1228800) { img[drive].sectors = 15; img[drive].tracks = 80; bit_rate_300 = (500.0 * 300.0) / 360.0; raw_tsize[drive] = 10416; } /*High density 1.2MB*/ - else if (size <= 1261568) { img[drive].sectors = 8; img[drive].tracks = 77; img[drive].sector_size = 1024; bit_rate_300 = (500.0 * 300.0) / 360.0; raw_tsize[drive] = 10416; } /*High density 1.25MB Japanese format*/ - else if (size <= (0x1A4000-1)) { img[drive].sectors = 18; img[drive].tracks = 80; bit_rate_300 = 500; raw_tsize[drive] = 12500; } /*High density (not supported by Tandy 1000)*/ - else if (size <= 1556480) { img[drive].sectors = 19; img[drive].tracks = 80; bit_rate_300 = 500; raw_tsize[drive] = 12500; } /*High density (not supported by Tandy 1000)*/ - else if (size <= 1638400) { img[drive].sectors = 10; img[drive].tracks = 80; img[drive].sector_size = 1024; bit_rate_300 = 500; raw_tsize[drive] = 12500; } /*High density (not supported by Tandy 1000)*/ - // else if (size == 1884160) { img[drive].sectors = 23; img[drive].tracks = 80; bit_rate_300 = 500; } /*XDF format - used by OS/2 Warp*/ - // else if (size == 1763328) { img[drive].sectors = 21; img[drive].tracks = 82; bit_rate_300 = 500; } /*XDF format - used by OS/2 Warp*/ - else if (size <= 2000000) { img[drive].sectors = 21; img[drive].tracks = 80; bit_rate_300 = 500; raw_tsize[drive] = 12500; } /*DMF format - used by Windows 95 - changed by OBattler to 2000000, ie. the real unformatted capacity @ 500 kbps and 300 rpm */ - else if (size <= 2949120) { img[drive].sectors = 36; img[drive].tracks = 80; bit_rate_300 = 1000; raw_tsize[drive] = 25000; } /*E density*/ - - temp_rate = 2; - bpb_bps = img[drive].sector_size; - bpt = bpb_bps * img[drive].sectors; - if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][0] * bpb_bps)) - { - temp_rate = 2; - raw_tsize[drive] = 5208; - } - else if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][1] * bpb_bps)) - { - temp_rate = 2; - raw_tsize[drive] = 6250; - } - else if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][2] * bpb_bps)) - { - temp_rate = 1; - raw_tsize[drive] = 7500; - } - else if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][3] * bpb_bps)) - { - if (bpb_bps == 512) max_spt = (bit_rate_300 == 500) ? 21 : 17; - temp_rate = (bit_rate_300 == 500) ? 0 : 4; - raw_tsize[drive] = (bit_rate_300 == 500) ? 12500 : 10416; - } - else if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][4] * bpb_bps)) - { - if (bpb_bps == 512) max_spt = 21; - pclog("max_spt is %i\n", max_spt); - temp_rate = 0; - raw_tsize[drive] = 12500; - } - else if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][5] * bpb_bps)) - { - if (bpb_bps == 512) max_spt = 41; - temp_rate = 3; - raw_tsize[drive] = 25000; - } - else /* Image too big, eject */ + if (size <= (160*1024)) { img[drive].sectors = 8; img[drive].tracks = 40; img[drive].sides = 1; } + else if (size <= (180*1024)) { img[drive].sectors = 9; img[drive].tracks = 40; img[drive].sides = 1; } + else if (size <= (320*1024)) { img[drive].sectors = 8; img[drive].tracks = 40; } + else if (size <= (360*1024)) { img[drive].sectors = 9; img[drive].tracks = 40; } /*Double density*/ + else if (size <= (400*1024)) { img[drive].sectors = 10; img[drive].tracks = 80; img[drive].sides = 1; } /*DEC RX50*/ + else if (size <= (640*1024)) { img[drive].sectors = 8; img[drive].tracks = 80; } /*Double density 640k*/ + else if (size <= (720*1024)) { img[drive].sectors = 9; img[drive].tracks = 80; } /*Double density*/ + else if (size <= (800*1024)) { img[drive].sectors = 10; img[drive].tracks = 80; } /*Double density*/ + else if (size <= (880*1024)) { img[drive].sectors = 11; img[drive].tracks = 80; } /*Double density*/ + else if (size <= (960*1024)) { img[drive].sectors = 12; img[drive].tracks = 80; } /*Double density*/ + else if (size <= (1040*1024)) { img[drive].sectors = 13; img[drive].tracks = 80; } /*Double density*/ + else if (size <= (1120*1024)) { img[drive].sectors = 14; img[drive].tracks = 80; } /*Double density*/ + else if (size <= 1228800) { img[drive].sectors = 15; img[drive].tracks = 80; } /*High density 1.2MB*/ + else if (size <= 1261568) { img[drive].sectors = 8; img[drive].tracks = 77; img[drive].sector_size = 3; } /*High density 1.25MB Japanese format*/ + else if (size <= (0x1A4000-1)) { img[drive].sectors = 18; img[drive].tracks = 80; } /*High density (not supported by Tandy 1000)*/ + else if (size <= 1556480) { img[drive].sectors = 19; img[drive].tracks = 80; } /*High density (not supported by Tandy 1000)*/ + else if (size <= 1638400) { img[drive].sectors = 10; img[drive].tracks = 80; img[drive].sector_size = 3; } /*High density (not supported by Tandy 1000)*/ + else if (size <= 1720320) { img[drive].sectors = 21; img[drive].tracks = 80; } /*DMF format - used by Windows 95 */ + else if (size <= 1741824) { img[drive].sectors = 21; img[drive].tracks = 81; } + else if (size <= 1763328) { img[drive].sectors = 21; img[drive].tracks = 82; } + else if (size <= 1802240) { img[drive].sectors = 11; img[drive].tracks = 80; img[drive].sector_size = 3; } /*High density (not supported by Tandy 1000)*/ + else if (size == 1884160) { img[drive].sectors = 23; img[drive].tracks = 80; } /*XDF format - used by OS/2 Warp*/ + else if (size <= 2949120) { img[drive].sectors = 36; img[drive].tracks = 80; } /*E density*/ + else if (size <= 3194880) { img[drive].sectors = 39; img[drive].tracks = 80; } /*E density*/ + else if (size <= 3276800) { img[drive].sectors = 40; img[drive].tracks = 80; } /*E density*/ + else if (size <= 3358720) { img[drive].sectors = 41; img[drive].tracks = 80; } /*E density, maximum possible size*/ + else if (size <= 3440640) { img[drive].sectors = 42; img[drive].tracks = 80; } /*E density, maximum possible size*/ + /* else if (size <= 3440640) { img[drive].sectors = 21; img[drive].tracks = 80; img[drive].sector_size = 3; } */ /*High density (not supported by Tandy 1000)*/ + else if (size <= 3604480) { img[drive].sectors = 22; img[drive].tracks = 80; img[drive].sector_size = 3; } /*High density (not supported by Tandy 1000)*/ + else if (size <= 3610624) { img[drive].sectors = 41; img[drive].tracks = 86; } /*E density, maximum possible size*/ + else if (size <= 3698688) { img[drive].sectors = 42; img[drive].tracks = 86; } /*E density, maximum possible size*/ + else { pclog("Image is bigger than can fit on an ED floppy, ejecting...\n"); fclose(img[drive].f); return; } - - pclog("Temporary rate: %i (%i bytes per track)\n", temp_rate, bpt); - - img[drive].xdf_type = 0; } else { /* The BPB readings appear to be valid, so let's set the values. */ - /* Number of tracks = number of total sectors divided by sides times sectors per track. */ if (fdi) { /* The image is a Japanese FDI, therefore we read the number of tracks from the header. */ @@ -317,297 +335,304 @@ void img_load(int drive, char *fn) } else { + /* Number of tracks = number of total sectors divided by sides times sectors per track. */ img[drive].tracks = ((uint32_t) bpb_total) / (((uint32_t) bpb_sides) * ((uint32_t) bpb_sectors)); } /* The rest we just set directly from the BPB. */ img[drive].sectors = bpb_sectors; img[drive].sides = bpb_sides; /* The sector size. */ - img[drive].sector_size = bpb_bps; - /* Now we calculate bytes per track, which is bpb_sectors * bpb_bps. */ - bpt = (uint32_t) bpb_sectors * (uint32_t) bpb_bps; - /* Now we should be able to calculate the bit rate. */ - pclog("The image has %i bytes per track\n", bpt); + img[drive].sector_size = sector_size_code(bpb_bps); - temp_rate = 2; - if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][0] * bpb_bps)) - { - bit_rate_300 = ((250.0 * 300.0) / 360.0); - temp_rate = 2; - raw_tsize[drive] = 5208; - } - else if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][1] * bpb_bps)) - { - bit_rate_300 = 250; - temp_rate = 2; - raw_tsize[drive] = 6250; - } - else if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][2] * bpb_bps)) - { - bit_rate_300 = 300; - temp_rate = 1; - raw_tsize[drive] = 7500; - } - else if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][3] * bpb_bps)) - { - bit_rate_300 = (bpb_mid == 0xF0) ? 500 : ((500.0 * 300.0) / 360.0); - if (bpb_bps == 512) max_spt = (bit_rate_300 == 500) ? 21 : 17; - temp_rate = (bit_rate_300 == 500) ? 0 : 4; - raw_tsize[drive] = (bit_rate_300 == 500) ? 12500 : 10416; - } - else if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][4] * bpb_bps)) - { - bit_rate_300 = 500; - if (bpb_bps == 512) max_spt = 21; - pclog("max_spt is %i\n", max_spt); - temp_rate = 0; - raw_tsize[drive] = 12500; - } - else if (bpt <= (maximum_sectors[sector_size_code(bpb_bps)][5] * bpb_bps)) - { - bit_rate_300 = 1000; - if (bpb_bps == 512) max_spt = 41; - temp_rate = 3; - raw_tsize[drive] = 25000; - } - else /* Image too big, eject */ - { - pclog("Image is bigger than can fit on an ED floppy, ejecting...\n"); - fclose(img[drive].f); - return; - } + temp_rate = 0xFF; + } - if (bpb_bps == 512) /* BPB reports 512 bytes per sector, let's see if it's XDF or not */ + for (i = 0; i < 6; i++) + { + if ((img[drive].sectors <= maximum_sectors[img[drive].sector_size][i]) || (img[drive].sectors == xdf_sectors[img[drive].sector_size][i])) { - if (bit_rate_300 <= 300) /* Double-density disk, not XDF */ + bit_rate_300 = bit_rates_300[i]; + temp_rate = rates[i]; + img[drive].disk_flags = holes[i] << 1; + img[drive].xdf_type = (img[drive].sectors == xdf_sectors[img[drive].sector_size][i]) ? xdf_types[img[drive].sector_size][i] : 0; + if ((bit_rate_300 == 500.0) && (img[drive].sectors == 21) && (img[drive].sector_size == 2) && (img[drive].tracks >= 80) && (img[drive].tracks <= 82) && (img[drive].sides == 2)) { - img[drive].xdf_type = 0; + /* This is a DMF floppy, set the flag so we know to interleave the sectors. */ + img[drive].dmf = 1; } else { - pclog("bpb_sectors is %i\n", bpb_sectors); - if (bpb_sectors > max_spt) - { - switch(bpb_sectors) - { - case 19: /* High density XDF @ 360 rpm */ - img[drive].xdf_type = 1; - break; - case 23: /* High density XDF @ 300 rpm */ - img[drive].xdf_type = 2; - pclog("XDF type is 2 @ %i kbps\n", bit_rate_300); - break; - case 46: /* Extended density XDF */ - img[drive].xdf_type = 3; - break; - default: /* Unknown, as we're beyond maximum sectors, get out */ - fclose(img[drive].f); - return; - } - pclog("XDF type: %i\n", img[drive].xdf_type); - } - else /* Amount of sectors per track that fits into a track, therefore not XDF */ - { - img[drive].xdf_type = 0; - } + img[drive].dmf = 0; } - } - else /* BPB reports sector size other than 512, can't possibly be XDF */ - { - img[drive].xdf_type = 0; + + pclog("Image parameters: bit rate 300: %f, temporary rate: %i, hole: %i, DMF: %i, XDF type: %i\n", bit_rate_300, temp_rate, img[drive].disk_flags >> 1, img[drive].dmf, img[drive].xdf_type); + break; } } - gap2_size[drive] = (temp_rate == 3) ? 41 : 22; - // pclog("GAP2 size: %i bytes\n", gap2_size[drive]); - gap3_size[drive] = gap3_sizes[temp_rate][sector_size_code(img[drive].sector_size)][img[drive].sectors]; - if (!gap3_size[drive]) + if (temp_rate == 0xFF) { - gap3_size[drive] = 40; - pclog("WARNING: Floppy image of unknown format was inserted into drive %c:!\n", drive + 0x41); + pclog("Image is bigger than can fit on an ED floppy, ejecting...\n"); + fclose(img[drive].f); + return; } - if (bit_rate_300 == 250) + img[drive].gap2_size = (temp_rate == 3) ? 41 : 22; + if (img[drive].dmf) { - img[drive].hole = 0; - /* If drive does not support 300 RPM, the medium is to be read at a period of 26 (300 kbps). */ - img[drive].byte_period = 29; - } - else if (bit_rate_300 == 300) - { - img[drive].hole = 0; - img[drive].byte_period = 26; - } - else if (bit_rate_300 == 1000) - { - img[drive].hole = 2; - img[drive].byte_period = 8; - } - else if (bit_rate_300 < 250) - { - img[drive].hole = 0; - img[drive].byte_period = 32; + img[drive].gap3_size = 8; } else { - img[drive].hole = 1; - img[drive].byte_period = 16; + img[drive].gap3_size = gap3_sizes[temp_rate][img[drive].sector_size][img[drive].sectors]; } + if (!img[drive].gap3_size) + { + pclog("ERROR: Floppy image of unknown format was inserted into drive %c:!\n", drive + 0x41); + fclose(img[drive].f); + return; + } + + img[drive].track_width = 0; + if (img[drive].tracks > 43) img[drive].track_width = 1; /* If the image has more than 43 tracks, then the tracks are thin (96 tpi). */ + if (img[drive].sides == 2) img[drive].disk_flags |= 8; /* If the has 2 sides, mark it as such. */ + + img[drive].track_flags = 0x08; /* IMG files are always assumed to be MFM-encoded. */ + img[drive].track_flags |= temp_rate & 3; /* Data rate. */ + if (temp_rate & 4) img[drive].track_flags |= 0x20; /* RPM. */ + + pclog("Disk flags: %i, track flags: %i\n", img[drive].disk_flags, img[drive].track_flags); + + d86f_register_img(drive); drives[drive].seek = img_seek; - drives[drive].readsector = disc_sector_readsector; - drives[drive].writesector = disc_sector_writesector; - drives[drive].readaddress = disc_sector_readaddress; - drives[drive].hole = img_hole; - drives[drive].byteperiod = img_byteperiod; - drives[drive].poll = disc_sector_poll; - drives[drive].format = disc_sector_format; - drives[drive].realtrack = img_realtrack; - drives[drive].stop = disc_sector_stop; - disc_sector_writeback[drive] = img_writeback; - - img[drive].bitcell_period_300rpm = 1000000.0 / bit_rate_300*2.0; - pclog("bit_rate_300=%g\n", bit_rate_300); - pclog("bitcell_period_300=%g\n", img[drive].bitcell_period_300rpm); -// img[drive].bitcell_period_300rpm = disc_get_bitcell_period(img[drive].rate); - pclog("img_load %d %p sectors=%i tracks=%i sides=%i sector_size=%i hole=%i\n", drive, drives, img[drive].sectors, img[drive].tracks, img[drive].sides, img[drive].sector_size, img[drive].hole); -} -int img_hole(int drive) -{ - return img[drive].hole; -} - -double img_byteperiod(int drive) -{ - if (img[drive].byte_period == 29) - { - return (fdd_get_type(drive) & 1) ? 32.0 : (160.0 / 6.0); - } - return (double) img[drive].byte_period; + d86f_common_handlers(drive); } void img_close(int drive) { + d86f_unregister(drive); if (img[drive].f) fclose(img[drive].f); img[drive].f = NULL; } +#define xdf_img_sector xdf_img_layout[current_xdft][!is_t0][sector] +#define xdf_disk_sector xdf_disk_layout[current_xdft][!is_t0][array_sector] + +int interleave(int sector, int skew, int track_spt) +{ + uint32_t skewed_i = 0; + uint32_t adjusted_r = 0; + + uint32_t add = (track_spt & 1); + uint32_t adjust = (track_spt >> 1); + + skewed_i = (sector + skew) % track_spt; + adjusted_r = (skewed_i >> 1) + 1; + if (skewed_i & 1) + { + adjusted_r += (adjust + add); + } + + return adjusted_r; +} + void img_seek(int drive, int track) { int side; int current_xdft = img[drive].xdf_type - 1; - int sector, current_pos, sh, sr, sn, sside, total, max_pos; + uint8_t id[4] = { 0, 0, 0, 0 }; + + int is_t0, sector, current_pos, img_pos, sr, sside, total, array_sector, buf_side, buf_pos; + + int ssize = 128 << ((int) img[drive].sector_size); if (!img[drive].f) return; - // pclog("Seek drive=%i track=%i sectors=%i sector_size=%i sides=%i\n", drive, track, img[drive].sectors,img[drive].sector_size, img[drive].sides); -// pclog(" %i %i\n", drive_type[drive], img[drive].tracks); - if ((img[drive].tracks <= 43) && fdd_doublestep_40(drive)) + + if (!img[drive].track_width && fdd_doublestep_40(drive)) track /= 2; - // pclog("Disk seeked to track %i\n", track); - disc_track[drive] = track; + img[drive].track = track; - if (img[drive].sides == 2) - { - fseek(img[drive].f, img[drive].base + (track * img[drive].sectors * img[drive].sector_size * 2), SEEK_SET); - // pclog("Seek: Current file position (H0) is: %08X\n", ftell(img[drive].f)); - fread(img[drive].track_data[0], img[drive].sectors * img[drive].sector_size, 1, img[drive].f); - // pclog("Seek: Current file position (H1) is: %08X\n", ftell(img[drive].f)); - fread(img[drive].track_data[1], img[drive].sectors * img[drive].sector_size, 1, img[drive].f); - } - else - { - fseek(img[drive].f, img[drive].base + (track * img[drive].sectors * img[drive].sector_size), SEEK_SET); - fread(img[drive].track_data[0], img[drive].sectors * img[drive].sector_size, 1, img[drive].f); - } - - disc_sector_reset(drive, 0); - disc_sector_reset(drive, 1); - - if (img[drive].xdf_type) + is_t0 = (track == 0) ? 1 : 0; + + fseek(img[drive].f, img[drive].base + (track * img[drive].sectors * ssize * img[drive].sides), SEEK_SET); + for (side = 0; side < img[drive].sides; side++) { - max_pos = (img[drive].sectors * 512); - if (!track) + fread(img[drive].track_data[side], img[drive].sectors * ssize, 1, img[drive].f); + } + + d86f_reset_index_hole_pos(drive, 0); + d86f_reset_index_hole_pos(drive, 1); + + if (!img[drive].xdf_type) + { + for (side = 0; side < img[drive].sides; side++) { - /* Track 0, register sectors according to track 0 layout. */ - total = img[drive].sectors; - current_pos = 0; - for (sector = 0; sector < (total << 1); sector++) + current_pos = d86f_prepare_pretrack(drive, side, 0); + + for (sector = 0; sector < img[drive].sectors; sector++) { - current_pos = (sector % total) << 9; - sside = (sector >= total) ? 1 : 0; - if (xdf_track0_layout[current_xdft][sector]) + // sr = img[drive].dmf ? (dmf_r[sector]) : (sector + 1); + if (img[drive].gap3_size < 68) { - sh = xdf_track0_layout[current_xdft][sector] & 0xFF; - sr = xdf_track0_layout[current_xdft][sector] >> 8; - xdf_sector_pos[(sh << 8) | sr] = current_pos; - disc_sector_add(drive, sh, track, sh, sr, 2, - img[drive].bitcell_period_300rpm, - &img[drive].track_data[sside][current_pos]); + sr = interleave(sector, 1, img[drive].sectors); } - } - } - else - { - /* Non-zero track, this will have sectors of various sizes. */ - total = xdf_spt[current_xdft] >> 1; - current_pos = 0; - for (sector = 0; sector < xdf_spt[current_xdft]; sector++) - { - sside = (sector >= total) ? 1 : 0; - sh = xdf_trackx_layout[current_xdft][sector] & 0xFF; - sr = xdf_trackx_layout[current_xdft][sector] >> 8; - sn = sr & 7; - disc_sector_add(drive, sh, track, sh, sr, sn, - img[drive].bitcell_period_300rpm, - &img[drive].track_data[sside][current_pos]); - current_pos += (128 << sn); - current_pos %= max_pos; + else + { + sr = img[drive].dmf ? (dmf_r[sector]) : (sector + 1); + } + id[0] = track; + id[1] = side; + id[2] = sr; + id[3] = img[drive].sector_size; + img[drive].sector_pos_side[side][sr] = side; + img[drive].sector_pos[side][sr] = (sr - 1) * ssize; + // pclog("Seek: %i %i %i %i | %i %04X\n", id[0], id[1], id[2], id[3], side, (sr - 1) * ssize); + current_pos = d86f_prepare_sector(drive, side, current_pos, id, &img[drive].track_data[side][(sr - 1) * ssize], ssize, img[drive].gap2_size, img[drive].gap3_size, 0, 0); } } } else - { - for (side = 0; side < img[drive].sides; side++) - { - for (sector = 0; sector < img[drive].sectors; sector++) - disc_sector_add(drive, side, track, side, sector+1, img_sector_size_code(drive), - img[drive].bitcell_period_300rpm, - &img[drive].track_data[side][sector * img[drive].sector_size]); + { + total = img[drive].sectors; + img_pos = 0; + sside = 0; + + /* Pass 1, get sector positions in the image. */ + for (sector = 0; sector < xdf_logical_sectors[current_xdft][!is_t0]; sector++) + { + if (is_t0) + { + img_pos = (sector % total) << 9; + sside = (sector >= total) ? 1 : 0; + } + + if (xdf_img_sector.word) + { + img[drive].sector_pos_side[xdf_img_sector.id.h][xdf_img_sector.id.r] = sside; + img[drive].sector_pos[xdf_img_sector.id.h][xdf_img_sector.id.r] = img_pos; + // pclog("Side: %i, Position: %04X\n", sside, img_pos); + } + + if (!is_t0) + { + img_pos += (128 << (xdf_img_sector.id.r & 7)); + if (img_pos >= (total << 9)) sside = 1; + img_pos %= (total << 9); + } + } + + /* Pass 2, prepare the actual track. */ + for (side = 0; side < img[drive].sides; side++) + { + current_pos = d86f_prepare_pretrack(drive, side, 0); + + for (sector = 0; sector < xdf_physical_sectors[current_xdft][!is_t0]; sector++) + { + array_sector = (side * xdf_physical_sectors[current_xdft][!is_t0]) + sector; + // pclog("Sector %i, array sector %i\n", sector, array_sector); + + buf_side = img[drive].sector_pos_side[xdf_disk_sector.id.h][xdf_disk_sector.id.r]; + buf_pos = img[drive].sector_pos[xdf_disk_sector.id.h][xdf_disk_sector.id.r]; + + // pclog("Side: %i, Position: %04X\n", buf_side, buf_pos); + + id[0] = track; + id[1] = xdf_disk_sector.id.h; + id[2] = xdf_disk_sector.id.r; + + if (is_t0) + { + id[3] = 2; + // pclog("XDF Track 0: Registering sector: %i %i %i %i\n", id[0], id[1], id[2], id[3]); + current_pos = d86f_prepare_sector(drive, side, current_pos, id, &img[drive].track_data[buf_side][buf_pos], ssize, img[drive].gap2_size, xdf_gap3_sizes[current_xdft][!is_t0], 0, 0); + } + else + { + id[3] = id[2] & 7; + // pclog("XDF Track X: Registering sector: %i %i %i %i\n", id[0], id[1], id[2], id[3]); + ssize = (128 << id[3]); + current_pos = d86f_prepare_sector(drive, side, xdf_trackx_spos[current_xdft][array_sector], id, &img[drive].track_data[buf_side][buf_pos], ssize, img[drive].gap2_size, xdf_gap3_sizes[current_xdft][!is_t0], 0, 0); + } + } } } - for (side = img[drive].sides - 1; side >= 0; side--) - { - disc_sector_prepare_track_layout(drive, side, track); - } + + // pclog("Seeked to track: %i\n", img[drive].track); } void img_writeback(int drive) { + int side; + int ssize = 128 << ((int) img[drive].sector_size); + if (!img[drive].f) return; - // if (img[drive].xdf_type) - // return; /*Should never happen*/ - - if (img[drive].sides == 2) - { - fseek(img[drive].f, img[drive].base + (disc_track[drive] * img[drive].sectors * img[drive].sector_size * 2), SEEK_SET); - fwrite(img[drive].track_data[0], img[drive].sectors * img[drive].sector_size, 1, img[drive].f); - fwrite(img[drive].track_data[1], img[drive].sectors * img[drive].sector_size, 1, img[drive].f); - } - else - { - fseek(img[drive].f, img[drive].base + (disc_track[drive] * img[drive].sectors * img[drive].sector_size), SEEK_SET); - fwrite(img[drive].track_data[0], img[drive].sectors * img[drive].sector_size, 1, img[drive].f); - } + fseek(img[drive].f, img[drive].base + (img[drive].track * img[drive].sectors * ssize * img[drive].sides), SEEK_SET); + for (side = 0; side < img[drive].sides; side++) + { + fwrite(img[drive].track_data[side], img[drive].sectors * ssize, 1, img[drive].f); + } } int img_xdf_type(int drive) { return img[drive].xdf_type; } + +uint16_t img_disk_flags(int drive) +{ + return img[drive].disk_flags; +} + +uint16_t img_side_flags(int drive) +{ + return img[drive].track_flags; +} + +void img_set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) +{ + img[drive].current_sector_pos_side = img[drive].sector_pos_side[h][r]; + img[drive].current_sector_pos = img[drive].sector_pos[h][r]; + return; +} + +uint8_t img_poll_read_data(int drive, int side, uint16_t pos) +{ + return img[drive].track_data[img[drive].current_sector_pos_side][img[drive].current_sector_pos + pos]; +} + +void img_poll_write_data(int drive, int side, uint16_t pos, uint8_t data) +{ + img[drive].track_data[img[drive].current_sector_pos_side][img[drive].current_sector_pos + pos] = data; +} + +int img_format_conditions(int drive) +{ + int temp = (fdc_get_format_sectors() == img[drive].sectors); + temp = temp && (fdc_get_format_n() == img[drive].sector_size); + temp = temp && (img[drive].xdf_type == 0); + return temp; +} + +void d86f_register_img(int drive) +{ + d86f_handler[drive].disk_flags = img_disk_flags; + d86f_handler[drive].side_flags = img_side_flags; + d86f_handler[drive].writeback = img_writeback; + d86f_handler[drive].set_sector = img_set_sector; + d86f_handler[drive].write_data = img_poll_write_data; + d86f_handler[drive].format_conditions = img_format_conditions; + d86f_handler[drive].extra_bit_cells = null_extra_bit_cells; + d86f_handler[drive].encoded_data = common_encoded_data; + d86f_handler[drive].read_revolution = common_read_revolution; + d86f_handler[drive].index_hole_pos = null_index_hole_pos; + d86f_handler[drive].get_raw_size = common_get_raw_size; + d86f_handler[drive].check_crc = 1; +} diff --git a/src/disc_img_86box.c b/src/disc_img_86box.c deleted file mode 100644 index 091049f2e..000000000 --- a/src/disc_img_86box.c +++ /dev/null @@ -1,603 +0,0 @@ -/* Copyright holders: Sarah Walker, Tenshi - see COPYING for more details -*/ -#include "ibm.h" -#include "fdc.h" -#include "fdd.h" -#include "disc.h" -#include "disc_img.h" - -static struct -{ - FILE *f; - uint8_t track_data[2][50000]; - int sectors, tracks, sides; - uint8_t sector_size; - int rate; - int xdf_type; /* 0 = not XDF, 1-5 = one of the five XDF types */ - int dmf; - int hole; - int track; - uint32_t base; - uint8_t gap2_size; - uint8_t gap3_size; - uint16_t disk_flags; - uint16_t track_flags; - uint8_t sector_pos_side[2][256]; - uint16_t sector_pos[2][256]; - uint8_t current_sector_pos_side; - uint16_t current_sector_pos; -} img[2]; - -uint8_t dmf_r[21] = { 12, 2, 13, 3, 14, 4, 15, 5, 16, 6, 17, 7, 18, 8, 19, 9, 20, 10, 21, 11, 1 }; -static uint8_t xdf_spt[2] = { 6, 8 }; -static uint8_t xdf_logical_sectors[2][2] = { { 38, 6 }, { 46, 8 } }; -uint8_t xdf_physical_sectors[2][2] = { { 16, 3 }, { 19, 4 } }; -uint8_t xdf_gap3_sizes[2][2] = { { 60, 69 }, { 60, 50 } }; -uint16_t xdf_trackx_spos[2][8] = { { 0xA7F, 0xF02, 0x11B7, 0xB66, 0xE1B, 0x129E }, { 0x302, 0x7E2, 0xA52, 0x12DA, 0x572, 0xDFA, 0x106A, 0x154A } }; - -/* XDF: Layout of the sectors in the image. */ -xdf_sector_t xdf_img_layout[2][2][46] = { { { 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700, 0x8800, - 0x8101, 0x8201, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, - 0x0700, 0x0800, 0, - 0x8301, 0x8401, 0x8501, 0x8601, 0x8701, 0x8801, 0x8901, 0x8A01, - 0x8B01, 0x8C01, 0x8D01, 0x8E01, 0x8F01, 0x9001, 0, 0, - 0, 0, 0 }, - { 0x8300, 0x8600, 0x8201, 0x8200, 0x8601, 0x8301 } - }, /* 5.25" 2HD */ - { { 0x8100, 0x8200, 0x8300, 0x8400, 0x8500, 0x8600, 0x8700, 0x8800, - 0x8900, 0x8A00, 0x8B00, 0x8101, 0x0100, 0x0200, 0x0300, 0x0400, - 0x0500, 0x0600, 0x0700, 0x0800, 0, 0, 0, - 0x8201, 0x8301, 0x8401, 0x8501, 0x8601, 0x8701, 0x8801, 0x8901, - 0x8A01, 0x8B01, 0x8C01, 0x8D01, 0x8E01, 0x8F01, 0, 0, - 0, 0, 0, 0x9001, 0x9101, 0x9201, 0x9301 }, - { 0x8300, 0x8400, 0x8601, 0x8200, 0x8201, 0x8600, 0x8401, 0x8301 } - } /* 3.5" 2HD */ - }; - -/* XDF: Layout of the sectors on the disk's track. */ -xdf_sector_t xdf_disk_layout[2][2][38] = { { { 0x0100, 0x0200, 0x8100, 0x8800, 0x8200, 0x0300, 0x8300, 0x0400, - 0x8400, 0x0500, 0x8500, 0x0600, 0x8600, 0x0700, 0x8700, 0x0800, - 0x8D01, 0x8501, 0x8E01, 0x8601, 0x8F01, 0x8701, 0x9001, 0x8801, - 0x8101, 0x8901, 0x8201, 0x8A01, 0x8301, 0x8B01, 0x8401, 0x8C01 }, - { 0x8300, 0x8200, 0x8600, 0x8201, 0x8301, 0x8601 } - }, /* 5.25" 2HD */ - { { 0x0100, 0x8A00, 0x8100, 0x8B00, 0x8200, 0x0200, 0x8300, 0x0300, - 0x8400, 0x0400, 0x8500, 0x0500, 0x8600, 0x0600, 0x8700, 0x0700, - 0x8800, 0x0800, 0x8900, - 0x9001, 0x8701, 0x9101, 0x8801, 0x9201, 0x8901, 0x9301, 0x8A01, - 0x8101, 0x8B01, 0x8201, 0x8C01, 0x8301, 0x8D01, 0x8401, 0x8E01, - 0x8501, 0x8F01, 0x8601 }, - { 0x8300, 0x8200, 0x8400, 0x8600, 0x8401, 0x8201, 0x8301, 0x8601 }, - }, /* 3.5" 2HD */ - }; - -/* First dimension is possible sector sizes (0 = 128, 7 = 16384), second is possible bit rates (250/360, 250, 300, 500/360, 500, 1000). */ -/* Disks formatted at 250 kbps @ 360 RPM can be read with a 360 RPM single-RPM 5.25" drive by setting the rate to 250 kbps. - Disks formatted at 300 kbps @ 300 RPM can be read with any 300 RPM single-RPM drive by setting the rate rate to 300 kbps. */ -static uint8_t maximum_sectors[8][6] = { { 26, 31, 38, 53, 64, 118 }, /* 128 */ - { 15, 19, 23, 32, 38, 73 }, /* 256 */ - { 7, 10, 12, 17, 21, 41 }, /* 512 */ - { 3, 5, 6, 9, 11, 22 }, /* 1024 */ - { 2, 2, 3, 4, 5, 11 }, /* 2048 */ - { 1, 1, 1, 2, 2, 5 }, /* 4096 */ - { 0, 0, 0, 1, 1, 3 }, /* 8192 */ - { 0, 0, 0, 0, 0, 1 } }; /* 16384 */ - -static uint8_t xdf_sectors[8][6] = { { 0, 0, 0, 0, 0, 0 }, /* 128 */ - { 0, 0, 0, 0, 0, 0 }, /* 256 */ - { 0, 0, 0, 19, 23, 0 }, /* 512 */ - { 0, 0, 0, 0, 0, 0 }, /* 1024 */ - { 0, 0, 0, 0, 0, 0 }, /* 2048 */ - { 0, 0, 0, 0, 0, 0 }, /* 4096 */ - { 0, 0, 0, 0, 0, 0 }, /* 8192 */ - { 0, 0, 0, 0, 0, 0 } }; /* 16384 */ - -static uint8_t xdf_types[8][6] = { { 0, 0, 0, 0, 0, 0 }, /* 128 */ - { 0, 0, 0, 0, 0, 0 }, /* 256 */ - { 0, 0, 0, 1, 2, 0 }, /* 512 */ - { 0, 0, 0, 0, 0, 0 }, /* 1024 */ - { 0, 0, 0, 0, 0, 0 }, /* 2048 */ - { 0, 0, 0, 0, 0, 0 }, /* 4096 */ - { 0, 0, 0, 0, 0, 0 }, /* 8192 */ - { 0, 0, 0, 0, 0, 0 } }; /* 16384 */ - -static double bit_rates_300[6] = { (250.0 * 300.0) / 360.0, 250.0, 300.0, (500.0 * 300.0) / 360.0, 500.0, 1000.0 }; - -static uint8_t rates[6] = { 2, 2, 1, 4, 0, 3 }; - -static uint8_t holes[6] = { 0, 0, 0, 1, 1, 2 }; - -int gap3_sizes[5][8][256] = { [0][1][16] = 0x54, - [0][2][18] = 0x6C, - [0][2][19] = 0x48, - [0][2][20] = 0x2A, - [0][2][21] = 0x08, /* Microsoft DMFWRITE.EXE uses this, 0x0C is used by FDFORMAT. */ - [0][2][23] = 0x01, - [0][3][10] = 0x83, - [0][3][11] = 0x26, - [1][2][11] = 0x54, - [1][2][12] = 0x1C, - [1][2][13] = 0x0E, - [1][3][6] = 0x79, - [1][3][7] = 0x06, - [2][1][10] = 0x32, - [2][1][11] = 0x0C, - [2][1][15] = 0x36, - [2][1][16] = 0x32, - [2][2][8] = 0x58, - [2][2][9] = 0x50, - [2][2][10] = 0x2E, - [2][2][21] = 0x1C, - [2][3][4] = 0xF0, - [2][3][5] = 0x74, - [3][2][36] = 0x53, - [3][2][37] = 0x4E, - [3][2][38] = 0x40, - [3][2][39] = 0x30, - [3][2][40] = 0x20, - [3][2][41] = 0x10, - [3][2][46] = 0x01, - [3][3][18] = 0xF7, - [3][3][19] = 0xAF, - [3][3][20] = 0x6F, - [3][3][21] = 0x55, - [3][3][22] = 0x1F, - [4][1][32] = 0x36, - [4][2][14] = 0x92, - [4][2][15] = 0x54, - [4][2][16] = 0x38, - [4][2][17] = 0x23, - [4][2][19] = 0x01, - [4][3][8] = 0x74, - [4][3][9] = 0x24 -}; - -void img_writeback(int drive); - -static int sector_size_code(int sector_size) -{ - switch(sector_size) - { - case 128: - return 0; - case 256: - return 1; - default: - case 512: - return 2; - case 1024: - return 3; - case 2048: - return 4; - case 4096: - return 5; - case 8192: - return 6; - case 16384: - return 7; - } -} - -static int img_sector_size_code(int drive) -{ - return sector_size_code(img[drive].sector_size); -} - -void img_init() -{ - memset(img, 0, sizeof(img)); -// adl[0] = adl[1] = 0; -} - -void d86f_register_img(int drive); - -void img_load(int drive, char *fn) -{ - int size; - double bit_rate_300; - uint16_t bpb_bps; - uint16_t bpb_total; - uint8_t bpb_mid; /* Media type ID. */ - uint8_t bpb_sectors; - uint8_t bpb_sides; - uint32_t bpt; - uint8_t max_spt; /* Used for XDF detection. */ - int temp_rate; - char ext[4]; - int fdi; - int i; - - ext[0] = fn[strlen(fn) - 3] | 0x60; - ext[1] = fn[strlen(fn) - 2] | 0x60; - ext[2] = fn[strlen(fn) - 1] | 0x60; - ext[3] = 0; - - d86f_unregister(drive); - - writeprot[drive] = 0; - img[drive].f = fopen(fn, "rb+"); - if (!img[drive].f) - { - img[drive].f = fopen(fn, "rb"); - if (!img[drive].f) - return; - writeprot[drive] = 1; - } - if (ui_writeprot[drive]) - { - writeprot[drive] = 1; - } - fwriteprot[drive] = writeprot[drive]; - - if (strcmp(ext, "fdi") == 0) - { - /* This is a Japanese FDI image, so let's read the header */ - pclog("img_load(): File is a Japanese FDI image...\n"); - fseek(img[drive].f, 0x10, SEEK_SET); - fread(&bpb_bps, 1, 2, img[drive].f); - fseek(img[drive].f, 0x0C, SEEK_SET); - fread(&size, 1, 4, img[drive].f); - bpb_total = size / bpb_bps; - fseek(img[drive].f, 0x08, SEEK_SET); - fread(&(img[drive].base), 1, 4, img[drive].f); - fseek(img[drive].f, img[drive].base + 0x15, SEEK_SET); - bpb_mid = fgetc(img[drive].f); - if (bpb_mid < 0xF0) bpb_mid = 0xF0; - fseek(img[drive].f, 0x14, SEEK_SET); - bpb_sectors = fgetc(img[drive].f); - fseek(img[drive].f, 0x18, SEEK_SET); - bpb_sides = fgetc(img[drive].f); - - fdi = 1; - } - else - { - /* Read the BPB */ - pclog("img_load(): File is a raw image...\n"); - fseek(img[drive].f, 0x0B, SEEK_SET); - fread(&bpb_bps, 1, 2, img[drive].f); - fseek(img[drive].f, 0x13, SEEK_SET); - fread(&bpb_total, 1, 2, img[drive].f); - fseek(img[drive].f, 0x15, SEEK_SET); - bpb_mid = fgetc(img[drive].f); - fseek(img[drive].f, 0x18, SEEK_SET); - bpb_sectors = fgetc(img[drive].f); - fseek(img[drive].f, 0x1A, SEEK_SET); - bpb_sides = fgetc(img[drive].f); - - img[drive].base = 0; - fdi = 0; - - fseek(img[drive].f, -1, SEEK_END); - size = ftell(img[drive].f) + 1; - } - - img[drive].sides = 2; - img[drive].sector_size = 2; - - img[drive].hole = 0; - - pclog("BPB reports %i sides and %i bytes per sector\n", bpb_sides, bpb_bps); - - if (((bpb_sides < 1) || (bpb_sides > 2) || (bpb_bps < 128) || (bpb_bps > 2048)) && !fdi) - { - /* The BPB is giving us a wacky number of sides and/or bytes per sector, therefore it is most probably - not a BPB at all, so we have to guess the parameters from file size. */ - - if (size <= (160*1024)) { img[drive].sectors = 8; img[drive].tracks = 40; img[drive].sides = 1; } - else if (size <= (180*1024)) { img[drive].sectors = 9; img[drive].tracks = 40; img[drive].sides = 1; } - else if (size <= (320*1024)) { img[drive].sectors = 8; img[drive].tracks = 40; } - else if (size <= (360*1024)) { img[drive].sectors = 9; img[drive].tracks = 40; } /*Double density*/ - else if (size <= (400*1024)) { img[drive].sectors = 10; img[drive].tracks = 80; img[drive].sides = 1; } /*DEC RX50*/ - else if (size <= (640*1024)) { img[drive].sectors = 8; img[drive].tracks = 80; } /*Double density 640k*/ - else if (size <= (720*1024)) { img[drive].sectors = 9; img[drive].tracks = 80; } /*Double density*/ - else if (size <= (800*1024)) { img[drive].sectors = 10; img[drive].tracks = 80; } /*Double density*/ - else if (size <= (880*1024)) { img[drive].sectors = 11; img[drive].tracks = 80; } /*Double density*/ - else if (size <= (960*1024)) { img[drive].sectors = 12; img[drive].tracks = 80; } /*Double density*/ - else if (size <= (1040*1024)) { img[drive].sectors = 13; img[drive].tracks = 80; } /*Double density*/ - else if (size <= (1120*1024)) { img[drive].sectors = 14; img[drive].tracks = 80; } /*Double density*/ - else if (size <= 1228800) { img[drive].sectors = 15; img[drive].tracks = 80; } /*High density 1.2MB*/ - else if (size <= 1261568) { img[drive].sectors = 8; img[drive].tracks = 77; img[drive].sector_size = 3; } /*High density 1.25MB Japanese format*/ - else if (size <= (0x1A4000-1)) { img[drive].sectors = 18; img[drive].tracks = 80; } /*High density (not supported by Tandy 1000)*/ - else if (size <= 1556480) { img[drive].sectors = 19; img[drive].tracks = 80; } /*High density (not supported by Tandy 1000)*/ - else if (size <= 1638400) { img[drive].sectors = 10; img[drive].tracks = 80; img[drive].sector_size = 3; } /*High density (not supported by Tandy 1000)*/ - else if (size <= 1720320) { img[drive].sectors = 21; img[drive].tracks = 80; } /*DMF format - used by Windows 95 */ - else if (size <= 1741824) { img[drive].sectors = 21; img[drive].tracks = 81; } - else if (size <= 1763328) { img[drive].sectors = 21; img[drive].tracks = 82; } - else if (size <= 1802240) { img[drive].sectors = 11; img[drive].tracks = 80; img[drive].sector_size = 3; } /*High density (not supported by Tandy 1000)*/ - else if (size == 1884160) { img[drive].sectors = 23; img[drive].tracks = 80; } /*XDF format - used by OS/2 Warp*/ - else if (size <= 2949120) { img[drive].sectors = 36; img[drive].tracks = 80; } /*E density*/ - else if (size <= 3194880) { img[drive].sectors = 39; img[drive].tracks = 80; } /*E density*/ - else if (size <= 3276800) { img[drive].sectors = 40; img[drive].tracks = 80; } /*E density*/ - else if (size <= 3358720) { img[drive].sectors = 41; img[drive].tracks = 80; } /*E density, maximum possible size*/ - else if (size <= 3440640) { img[drive].sectors = 21; img[drive].tracks = 80; img[drive].sector_size = 3; } /*High density (not supported by Tandy 1000)*/ - else if (size <= 3604480) { img[drive].sectors = 22; img[drive].tracks = 80; img[drive].sector_size = 3; } /*High density (not supported by Tandy 1000)*/ - else - { - pclog("Image is bigger than can fit on an ED floppy, ejecting...\n"); - fclose(img[drive].f); - return; - } - } - else - { - /* The BPB readings appear to be valid, so let's set the values. */ - if (fdi) - { - /* The image is a Japanese FDI, therefore we read the number of tracks from the header. */ - fseek(img[drive].f, 0x1C, SEEK_SET); - fread(&(img[drive].tracks), 1, 4, img[drive].f); - } - else - { - /* Number of tracks = number of total sectors divided by sides times sectors per track. */ - img[drive].tracks = ((uint32_t) bpb_total) / (((uint32_t) bpb_sides) * ((uint32_t) bpb_sectors)); - } - /* The rest we just set directly from the BPB. */ - img[drive].sectors = bpb_sectors; - img[drive].sides = bpb_sides; - /* The sector size. */ - img[drive].sector_size = sector_size_code(bpb_bps); - - temp_rate = 0xFF; - } - - for (i = 0; i < 6; i++) - { - if ((img[drive].sectors <= maximum_sectors[img[drive].sector_size][i]) || (img[drive].sectors == xdf_sectors[img[drive].sector_size][i])) - { - bit_rate_300 = bit_rates_300[i]; - temp_rate = rates[i]; - img[drive].disk_flags = holes[i] << 1; - img[drive].xdf_type = (img[drive].sectors == xdf_sectors[img[drive].sector_size][i]) ? xdf_types[img[drive].sector_size][i] : 0; - if ((bit_rate_300 == 500.0) && (img[drive].sectors == 21) && (img[drive].sector_size == 2) && (img[drive].tracks >= 80) && (img[drive].tracks <= 82) && (img[drive].sides == 2)) - { - /* This is a DMF floppy, set the flag so we know to interleave the sectors. */ - img[drive].dmf = 1; - } - else - { - img[drive].dmf = 0; - } - - pclog("Image parameters: bit rate 300: %f, temporary rate: %i, hole: %i, DMF: %i, XDF type: %i\n", bit_rate_300, temp_rate, img[drive].disk_flags >> 1, img[drive].dmf, img[drive].xdf_type); - break; - } - } - - if (temp_rate == 0xFF) - { - pclog("Image is bigger than can fit on an ED floppy, ejecting...\n"); - fclose(img[drive].f); - return; - } - - img[drive].gap2_size = (temp_rate == 3) ? 41 : 22; - if (img[drive].dmf) - { - img[drive].gap3_size = 8; - } - else - { - img[drive].gap3_size = gap3_sizes[temp_rate][img[drive].sector_size][img[drive].sectors]; - } - if (!img[drive].gap3_size) - { - pclog("ERROR: Floppy image of unknown format was inserted into drive %c:!\n", drive + 0x41); - fclose(img[drive].f); - return; - } - - if (img[drive].tracks > 43) img[drive].disk_flags |= 1; /* If the image has more than 43 tracks, then the tracks are thin (96 tpi). */ - if (img[drive].sides == 2) img[drive].disk_flags |= 8; /* If the has 2 sides, mark it as such. */ - - img[drive].track_flags = 0x08; /* IMG files are always assumed to be MFM-encoded. */ - img[drive].track_flags |= temp_rate & 3; /* Data rate. */ - if (temp_rate & 4) img[drive].track_flags |= 0x20; /* RPM. */ - - pclog("Disk flags: %i, track flags: %i\n", img[drive].disk_flags, img[drive].track_flags); - - d86f_register_img(drive); - - drives[drive].seek = img_seek; - - d86f_common_handlers(drive); -} - -void img_close(int drive) -{ - d86f_unregister(drive); - if (img[drive].f) - fclose(img[drive].f); - img[drive].f = NULL; -} - -#define xdf_img_sector xdf_img_layout[current_xdft][!is_t0][sector] -#define xdf_disk_sector xdf_disk_layout[current_xdft][!is_t0][array_sector] - -void img_seek(int drive, int track) -{ - int side; - int current_xdft = img[drive].xdf_type - 1; - - uint8_t id[4] = { 0, 0, 0, 0 }; - - int is_t0, sector, current_pos, img_pos, sh, sr, sn, sside, total, max_pos, bytes, array_sector, buf_side, buf_pos; - - int ssize = 128 << ((int) img[drive].sector_size); - - if (!img[drive].f) - return; - - if (d86f_is_40_track(drive) && fdd_doublestep_40(drive)) - track /= 2; - - img[drive].track = track; - - is_t0 = (track == 0) ? 1 : 0; - - fseek(img[drive].f, img[drive].base + (track * img[drive].sectors * ssize * img[drive].sides), SEEK_SET); - for (side = 0; side < img[drive].sides; side++) - { - fread(img[drive].track_data[side], img[drive].sectors * ssize, 1, img[drive].f); - } - - d86f_reset_index_hole_pos(drive, 0); - d86f_reset_index_hole_pos(drive, 1); - - if (!img[drive].xdf_type) - { - for (side = 0; side < img[drive].sides; side++) - { - current_pos = d86f_prepare_pretrack(drive, side, 0, 1); - - for (sector = 0; sector < img[drive].sectors; sector++) - { - sr = img[drive].dmf ? (dmf_r[sector]) : (sector + 1); - id[0] = track; - id[1] = side; - id[2] = sr; - id[3] = img[drive].sector_size; - img[drive].sector_pos_side[side][sr] = side; - img[drive].sector_pos[side][sr] = (sr - 1) * ssize; - // if (img[drive].dmf) pclog("DMF: %i %i %i %i | %i %04X\n", id[0], id[1], id[2], id[3], side, (sr - 1) * ssize); - current_pos = d86f_prepare_sector(drive, side, current_pos, id, &img[drive].track_data[side][(sr - 1) * ssize], ssize, 1, img[drive].gap2_size, img[drive].gap3_size, 0, 0, 0); - } - } - } - else - { - total = img[drive].sectors; - img_pos = 0; - sside = 0; - - /* Pass 1, get sector positions in the image. */ - for (sector = 0; sector < xdf_logical_sectors[current_xdft][!is_t0]; sector++) - { - if (is_t0) - { - img_pos = (sector % total) << 9; - sside = (sector >= total) ? 1 : 0; - } - - if (xdf_img_sector.word) - { - img[drive].sector_pos_side[xdf_img_sector.id.h][xdf_img_sector.id.r] = sside; - img[drive].sector_pos[xdf_img_sector.id.h][xdf_img_sector.id.r] = img_pos; - // pclog("Side: %i, Position: %04X\n", sside, img_pos); - } - - if (!is_t0) - { - img_pos += (128 << (xdf_img_sector.id.r & 7)); - if (img_pos >= (total << 9)) sside = 1; - img_pos %= (total << 9); - } - } - - /* Pass 2, prepare the actual track. */ - for (side = 0; side < img[drive].sides; side++) - { - current_pos = d86f_prepare_pretrack(drive, side, 0, 1); - - for (sector = 0; sector < xdf_physical_sectors[current_xdft][!is_t0]; sector++) - { - array_sector = (side * xdf_physical_sectors[current_xdft][!is_t0]) + sector; - // pclog("Sector %i, array sector %i\n", sector, array_sector); - - buf_side = img[drive].sector_pos_side[xdf_disk_sector.id.h][xdf_disk_sector.id.r]; - buf_pos = img[drive].sector_pos[xdf_disk_sector.id.h][xdf_disk_sector.id.r]; - - // pclog("Side: %i, Position: %04X\n", buf_side, buf_pos); - - id[0] = track; - id[1] = xdf_disk_sector.id.h; - id[2] = xdf_disk_sector.id.r; - - if (is_t0) - { - id[3] = 2; - // pclog("XDF Track 0: Registering sector: %i %i %i %i\n", id[0], id[1], id[2], id[3]); - current_pos = d86f_prepare_sector(drive, side, current_pos, id, &img[drive].track_data[buf_side][buf_pos], ssize, 1, img[drive].gap2_size, xdf_gap3_sizes[current_xdft][!is_t0], 0, 0, 0); - } - else - { - id[3] = id[2] & 7; - // pclog("XDF Track X: Registering sector: %i %i %i %i\n", id[0], id[1], id[2], id[3]); - ssize = (128 << id[3]); - current_pos = d86f_prepare_sector(drive, side, xdf_trackx_spos[current_xdft][array_sector], id, &img[drive].track_data[buf_side][buf_pos], ssize, 1, img[drive].gap2_size, xdf_gap3_sizes[current_xdft][!is_t0], 0, 0, 0); - } - } - } - } - - // pclog("Seeked to track: %i\n", img[drive].track); -} - -void img_writeback(int drive) -{ - int side; - int ssize = 128 << ((int) img[drive].sector_size); - - if (!img[drive].f) - return; - - fseek(img[drive].f, img[drive].base + (img[drive].track * img[drive].sectors * ssize * img[drive].sides), SEEK_SET); - for (side = 0; side < img[drive].sides; side++) - { - fwrite(img[drive].track_data[side], img[drive].sectors * ssize, 1, img[drive].f); - } -} - -int img_xdf_type(int drive) -{ - return img[drive].xdf_type; -} - -uint16_t img_disk_flags(int drive) -{ - return img[drive].disk_flags; -} - -uint16_t img_side_flags(int drive) -{ - return img[drive].track_flags; -} - -void img_set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n) -{ - img[drive].current_sector_pos_side = img[drive].sector_pos_side[h][r]; - img[drive].current_sector_pos = img[drive].sector_pos[h][r]; - return; -} - -uint8_t img_poll_read_data(int drive, int side, uint16_t pos) -{ - return img[drive].track_data[img[drive].current_sector_pos_side][img[drive].current_sector_pos + pos]; -} - -void img_poll_write_data(int drive, int side, uint16_t pos, uint8_t data) -{ - img[drive].track_data[img[drive].current_sector_pos_side][img[drive].current_sector_pos + pos] = data; -} - -int img_format_conditions(int drive) -{ - int temp = (fdc_get_format_sectors() == img[drive].sectors); - temp = temp && (fdc_get_format_n() == img[drive].sector_size); - temp = temp && (img[drive].xdf_type == 0); - return temp; -} - -void d86f_register_img(int drive) -{ - d86f_handler[drive].disk_flags = img_disk_flags; - d86f_handler[drive].side_flags = img_side_flags; - d86f_handler[drive].writeback = img_writeback; - d86f_handler[drive].set_sector = img_set_sector; - d86f_handler[drive].read_data = img_poll_read_data; - d86f_handler[drive].write_data = img_poll_write_data; - d86f_handler[drive].format_conditions = img_format_conditions; - d86f_handler[drive].check_crc = 1; -} diff --git a/src/disc_sector.c b/src/disc_sector.c deleted file mode 100644 index 76a07d47b..000000000 --- a/src/disc_sector.c +++ /dev/null @@ -1,463 +0,0 @@ -/* Copyright holders: Sarah Walker, Tenshi - see COPYING for more details -*/ -#include "ibm.h" -#include "disc.h" -#include "disc_sector.h" -#include "fdd.h" - -/*Handling for 'sector based' image formats (like .IMG) as opposed to 'stream based' formats (eg .FDI)*/ - -#define MAX_SECTORS 256 - -typedef struct -{ - uint8_t c, h, r, n; - int rate; - uint8_t *data; -} sector_t; - -static sector_t disc_sector_data[2][2][MAX_SECTORS]; -static int disc_sector_count[2][2]; -void (*disc_sector_writeback[2])(int drive); - -enum -{ - STATE_IDLE, - STATE_READ_FIND_SECTOR, - STATE_READ_SECTOR, - STATE_READ_FIND_FIRST_SECTOR, - STATE_READ_FIRST_SECTOR, - STATE_READ_FIND_NEXT_SECTOR, - STATE_READ_NEXT_SECTOR, - STATE_WRITE_FIND_SECTOR, - STATE_WRITE_SECTOR, - STATE_READ_FIND_ADDRESS, - STATE_READ_ADDRESS, - STATE_FORMAT_FIND, - STATE_FORMAT -}; - -static int disc_sector_state[2] = {0, 0}; -static int disc_sector_track[2] = {0, 0}; -static int disc_sector_side[2] = {0, 0}; -static int disc_sector_drive; -static int disc_sector_sector[2] = {0, 0}; -static int disc_sector_n[2] = {0, 0}; -static int disc_intersector_delay[2] = {0, 0}; -static int disc_postdata_delay[2] = {0, 0}; -static int disc_track_delay[2] = {0, 0}; -static int disc_gap4_delay[2] = {0, 0}; -static uint8_t disc_sector_fill[2] = {0, 0}; -static int cur_sector[2], cur_byte[2]; -static int index_count[2]; - -int raw_tsize[2] = {6250, 6250}; -int gap2_size[2] = {22, 22}; -int gap3_size[2] = {0, 0}; -int gap4_size[2] = {0, 0}; - -void disc_sector_reset(int drive, int side) -{ - disc_sector_count[drive][side] = 0; - - disc_intersector_delay[drive] = 0; - disc_postdata_delay[drive] = 0; - disc_track_delay[drive] = 0; - disc_gap4_delay[drive] = 0; - cur_sector[drive] = 0; - cur_byte[drive] = 0; - index_count[drive] = 0; -} - -void disc_sector_add(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n, int rate, uint8_t *data) -{ - sector_t *s = &disc_sector_data[drive][side][disc_sector_count[drive][side]]; -//pclog("disc_sector_add: drive=%i side=%i %i r=%i\n", drive, side, disc_sector_count[drive][side],r ); - if (disc_sector_count[drive][side] >= MAX_SECTORS) - return; - - s->c = c; - s->h = h; - s->r = r; - s->n = n; - s->rate = rate; - s->data = data; - - disc_sector_count[drive][side]++; -} - -static int get_bitcell_period(int drive) -{ - return (disc_sector_data[drive][disc_sector_side[drive]][cur_sector[drive]].rate * 300) / fdd_getrpm(drive); -} - -void disc_sector_readsector(int drive, int sector, int track, int side, int rate, int sector_size) -{ - pclog("disc_sector_readsector: fdc_period=%i img_period=%i rate=%i sector=%i track=%i side=%i\n", fdc_get_bitcell_period(), get_bitcell_period(drive), rate, sector, track, side); - - disc_sector_track[drive] = track; - disc_sector_side[drive] = side; - disc_sector_drive = drive; - disc_sector_sector[drive] = sector; - disc_sector_n[drive] = sector_size; - if ((cur_sector[drive] == 0) && (cur_byte[drive] == 0) && !disc_track_delay[drive]) disc_track_delay[drive] = pre_track; - index_count[drive] = 0; - if (sector == SECTOR_FIRST) - disc_sector_state[drive] = STATE_READ_FIND_FIRST_SECTOR; - else if (sector == SECTOR_NEXT) - disc_sector_state[drive] = STATE_READ_FIND_NEXT_SECTOR; - else - disc_sector_state[drive] = STATE_READ_FIND_SECTOR; -} - -void disc_sector_writesector(int drive, int sector, int track, int side, int rate, int sector_size) -{ -// pclog("disc_sector_writesector: fdc_period=%i img_period=%i rate=%i\n", fdc_get_bitcell_period(), get_bitcell_period(), rate); - - disc_sector_track[drive] = track; - disc_sector_side[drive] = side; - disc_sector_drive = drive; - disc_sector_sector[drive] = sector; - disc_sector_n[drive] = sector_size; - if ((cur_sector[drive] == 0) && (cur_byte[drive] == 0) && !disc_track_delay[drive]) disc_track_delay[drive] = pre_track; - index_count[drive] = 0; - disc_sector_state[drive] = STATE_WRITE_FIND_SECTOR; -} - -void disc_sector_readaddress(int drive, int track, int side, int rate) -{ -// pclog("disc_sector_readaddress: fdc_period=%i img_period=%i rate=%i track=%i side=%i\n", fdc_get_bitcell_period(), get_bitcell_period(), rate, track, side); - - disc_sector_track[drive] = track; - disc_sector_side[drive] = side; - disc_sector_drive = drive; - if ((cur_sector[drive] == 0) && (cur_byte[drive] == 0) && !disc_track_delay[drive]) - { - disc_track_delay[drive] = pre_track; - index_count[drive] = -1; - } - else - index_count[drive] = 0; - disc_sector_state[drive] = STATE_READ_FIND_ADDRESS; -} - -void disc_sector_format(int drive, int track, int side, int rate, uint8_t fill) -{ - disc_sector_track[drive] = track; - disc_sector_side[drive] = side; - disc_sector_drive = drive; - disc_sector_fill[drive] = fill; - index_count[drive] = 0; - disc_sector_state[drive] = STATE_FORMAT_FIND; -} - -void disc_sector_stop(int drive) -{ - disc_sector_state[drive] = STATE_IDLE; -} - -static void index_pulse(int drive) -{ - if (disc_sector_state[drive] != STATE_IDLE) fdc_indexpulse(); -} - -void disc_sector_prepare_track_layout(int drive, int side) -{ -} - -static void advance_byte() -{ - int drive = disc_sector_drive; - - if (disc_postdata_delay[drive]) - { - disc_postdata_delay[drive]--; - return; - } - if (disc_gap4_delay[drive]) - { - disc_gap4_delay[drive]--; - return; - } - if (disc_track_delay[drive]) - { - if (disc_track_delay[drive] == pre_track) - { - index_pulse(drive); - if (disc_sector_state[drive] != STATE_IDLE) index_count[drive]++; - } - disc_track_delay[drive]--; - return; - } - if (disc_intersector_delay[drive]) - { - disc_intersector_delay[drive]--; - return; - } - cur_byte[drive]++; - if (cur_byte[drive] >= (128 << disc_sector_data[drive][disc_sector_side[drive]][cur_sector[drive]].n)) - { - cur_byte[drive] = 0; - cur_sector[drive]++; - disc_postdata_delay[drive] = post_gap + (gap3_size[drive]); - if (cur_sector[drive] >= disc_sector_count[drive][disc_sector_side[drive]]) - { - cur_sector[drive] = 0; - disc_gap4_delay[drive] = (gap4_size[drive]); - disc_track_delay[drive] = pre_track; - disc_intersector_delay[drive] = pre_gap + gap2_size[drive] + pre_data; - } - else - { - disc_gap4_delay[drive] = 0; - disc_track_delay[drive] = 0; - disc_intersector_delay[drive] = pre_gap + gap2_size[drive] + pre_data; - } - } - return; -} - -int disc_gap_has_ended(int drive) -{ - return (disc_postdata_delay[drive] == (post_gap + (gap3_size[drive]) - fdc_get_gap() - length_crc)); -} - -void disc_sector_poll() -{ - sector_t *s; - int data; - int drive = disc_sector_drive; - - if (cur_sector[drive] >= disc_sector_count[drive][disc_sector_side[drive]]) - cur_sector[drive] = 0; - if (disc_sector_n[drive]) - { - if (cur_byte[drive] >= (128 << disc_sector_data[drive][disc_sector_side[drive]][cur_sector[drive]].n)) - cur_byte[drive] = 0; - } - else - { - if (cur_byte[drive] >= fdc_get_dtl()) - cur_byte[drive] = 0; - } - - /* Note: Side to read from should be chosen from FDC head select rather than from the sector ID. */ - s = &disc_sector_data[drive][disc_sector_side[drive]][cur_sector[drive]]; - - switch (disc_sector_state[drive]) - { - case STATE_IDLE: - advance_byte(); - break; - - case STATE_READ_FIND_SECTOR: - if (index_count[drive] > 1) - { - pclog("READ: Sector (%i %i %i %i) not found (last: %i %i %i %i) (period=%i,%i) (ic=%i)\n", s->c, s->h, s->r, s->n, disc_sector_track[drive], disc_sector_side[drive], disc_sector_sector[drive], disc_sector_n[drive], fdc_get_bitcell_period(), get_bitcell_period(drive), index_count[drive]); - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - break; - } - if (/*cur_byte[drive] || */ disc_sector_track[drive] != s->c || - disc_sector_side[drive] != s->h || - disc_sector_sector[drive] != s->r || - ((disc_sector_n[drive] != s->n) && (disc_sector_n[drive])) || - (fdc_get_bitcell_period() != get_bitcell_period(drive)) || - !fdd_can_read_medium(drive ^ fdd_swap) || - disc_intersector_delay[drive] || disc_postdata_delay[drive] || disc_track_delay[drive] || disc_gap4_delay[drive]) - { - advance_byte(); - break; - } - disc_sector_state[drive] = STATE_READ_SECTOR; - - case STATE_READ_SECTOR: - if (!disc_postdata_delay[drive]) - { - if (fdc_data(s->data[cur_byte[drive]])) - { - return; - } - } - advance_byte(); - if (!cur_byte[drive] && disc_gap_has_ended(drive)) - { - disc_sector_state[drive] = STATE_IDLE; - fdc_finishread(drive); - } - break; - - case STATE_READ_FIND_FIRST_SECTOR: - if (!fdd_can_read_medium(drive ^ fdd_swap)) - { - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - break; - } - if (cur_byte[drive] || !index_count[drive] || fdc_get_bitcell_period() != get_bitcell_period(drive) || - disc_intersector_delay[drive] || disc_postdata_delay[drive] || disc_track_delay[drive] || disc_gap4_delay[drive]) - { - advance_byte(); - break; - } - disc_sector_state[drive] = STATE_READ_FIRST_SECTOR; - - case STATE_READ_FIRST_SECTOR: - if (!disc_postdata_delay[drive]) - { - if (fdc_data(s->data[cur_byte[drive]])) - return; - } - advance_byte(); - if (!cur_byte[drive] && disc_gap_has_ended(drive)) - { - disc_sector_state[drive] = STATE_IDLE; - fdc_finishread(drive); - } - break; - - case STATE_READ_FIND_NEXT_SECTOR: - if (!fdd_can_read_medium(drive ^ fdd_swap)) - { - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - break; - } - if (index_count[drive] > 0) - { - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - break; - } - if (cur_byte[drive] || (fdc_get_bitcell_period() != get_bitcell_period(drive)) || - disc_intersector_delay[drive] || disc_postdata_delay[drive] || disc_track_delay[drive] || disc_gap4_delay[drive]) - { - advance_byte(); - break; - } - disc_sector_state[drive] = STATE_READ_NEXT_SECTOR; - - case STATE_READ_NEXT_SECTOR: - if (!disc_postdata_delay[drive]) - { - if (fdc_data(s->data[cur_byte[drive]])) - break; - } - advance_byte(); - if (!cur_byte[drive] && disc_gap_has_ended(drive)) - { - disc_sector_state[drive] = STATE_IDLE; - fdc_finishread(drive); - } - break; - - case STATE_WRITE_FIND_SECTOR: - if (!fdd_can_read_medium(drive ^ fdd_swap)) - { - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - break; - } - if (writeprot[drive] || swwp) - { - fdc_writeprotect(); - } - if (index_count[drive] > 1) - { - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - break; - } - if (cur_byte[drive] || disc_sector_track[drive] != s->c || - disc_sector_side[drive] != s->h || - disc_sector_sector[drive] != s->r || - ((disc_sector_n[drive] != s->n) && (disc_sector_n[drive])) || - (fdc_get_bitcell_period() != get_bitcell_period(drive)) || - disc_intersector_delay[drive] || disc_postdata_delay[drive] || disc_track_delay[drive] || disc_gap4_delay[drive]) - { - advance_byte(); - break; - } - disc_sector_state[drive] = STATE_WRITE_SECTOR; - - case STATE_WRITE_SECTOR: - if (!disc_postdata_delay[drive]) - { - data = fdc_getdata(cur_byte[drive] == ((128 << s->n) - 1)); - if (data == -1) - break; - if (!disable_write) s->data[cur_byte[drive]] = data; - } - advance_byte(); - if (!cur_byte[drive] && disc_gap_has_ended(drive)) - { - disc_sector_state[drive] = STATE_IDLE; - if (!disable_write) disc_sector_writeback[drive](drive); - fdc_finishread(drive); - } - break; - - case STATE_READ_FIND_ADDRESS: - if (!fdd_can_read_medium(drive ^ fdd_swap)) - { - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - break; - } - if (index_count[drive] > 0) - { - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - break; - } - if (cur_byte[drive] || (fdc_get_bitcell_period() != get_bitcell_period(drive)) || - disc_intersector_delay[drive] || disc_postdata_delay[drive] || disc_track_delay[drive] || disc_gap4_delay[drive]) - { - advance_byte(); - break; - } - disc_sector_state[drive] = STATE_READ_ADDRESS; - case STATE_READ_ADDRESS: - fdc_sectorid(s->c, s->h, s->r, s->n, 0, 0); - disc_sector_state[drive] = STATE_IDLE; - break; - - case STATE_FORMAT_FIND: - if (writeprot[drive] || swwp) - { - fdc_writeprotect(); - } - if (!index_count[drive] || (fdc_get_bitcell_period() != get_bitcell_period(drive)) || - disc_intersector_delay[drive] || disc_postdata_delay[drive] || disc_track_delay[drive] || disc_gap4_delay[drive]) - { - advance_byte(); - break; - } - if (!(fdd_can_read_medium(drive ^ fdd_swap))) - { - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - break; - } - if (fdc_get_bitcell_period() != get_bitcell_period(drive)) - { - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - break; - } - disc_sector_state[drive] = STATE_FORMAT; - - case STATE_FORMAT: - if (!disc_intersector_delay[drive] && fdc_get_bitcell_period() == get_bitcell_period(drive) && !disable_write) - s->data[cur_byte[drive]] = disc_sector_fill[drive]; - advance_byte(); - if (index_count[drive] == 2) - { - if (!disable_write) disc_sector_writeback[drive](drive); - fdc_finishread(drive); - disc_sector_state[drive] = STATE_IDLE; - } - break; - } -} \ No newline at end of file diff --git a/src/disc_sector.h b/src/disc_sector.h deleted file mode 100644 index 31390e355..000000000 --- a/src/disc_sector.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright holders: Sarah Walker, Tenshi - see COPYING for more details -*/ -void disc_sector_reset(int drive, int side); -void disc_sector_add(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n, int rate, uint8_t *data); -void disc_sector_readsector(int drive, int sector, int track, int side, int density, int sector_size); -void disc_sector_writesector(int drive, int sector, int track, int side, int density, int sector_size); -void disc_sector_readaddress(int drive, int sector, int side, int density); -void disc_sector_format(int drive, int sector, int side, int density, uint8_t fill); -void disc_sector_stop(); -void disc_sector_poll(); -void disc_sector_stop(); - -extern void (*disc_sector_writeback[2])(int drive); -void disc_sector_prepare_track_layout(int drive, int side, int track); - -#define length_gap0 80 -#define length_gap1 50 -#define length_sync 12 -#define length_am 4 -#define length_crc 2 - -#define IBM -#define MFM -#ifdef IBM -#define pre_gap1 length_gap0 + length_sync + length_am -#else -#define pre_gap1 0 -#endif - -#define pre_track pre_gap1 + length_gap1 -#define pre_gap length_sync + length_am + 4 + length_crc -#define pre_data length_sync + length_am -#define post_gap length_crc - -extern int raw_tsize[2]; -extern int gap2_size[2]; -extern int gap3_size[2]; -// extern int gap4_size[2]; diff --git a/src/disc_sector_86box.c b/src/disc_sector_86box.c deleted file mode 100644 index a6b45598c..000000000 --- a/src/disc_sector_86box.c +++ /dev/null @@ -1,638 +0,0 @@ -/* Copyright holders: Tenshi - see COPYING for more details -*/ -#include "ibm.h" -#include "disc.h" -#include "disc_sector.h" -#include "fdc.h" -#include "fdd.h" - -/*Handling for 'sector based' image formats (like .IMG) as opposed to 'stream based' formats (eg .FDI)*/ - -#define MAX_SECTORS 256 - -typedef struct -{ - uint8_t c, h, r, n; - int rate; - uint8_t *data; -} sector_t; - -static sector_t disc_sector_data[2][2][MAX_SECTORS]; -static int disc_sector_count[2][2]; -void (*disc_sector_writeback[2])(int drive); - -int cur_track_pos[2] = {0, 0}; -int id_counter[2] = {0, 0}; -int data_counter[2] = {0, 0}; -int gap3_counter[2] = {0, 0}; -int cur_rate[2] = {0, 0}; - -sector_t *last_sector[2]; - -enum -{ - STATE_IDLE, - STATE_READ_FIND_SECTOR, - STATE_READ_SECTOR, - STATE_READ_FIND_FIRST_SECTOR, - STATE_READ_FIRST_SECTOR, - STATE_READ_FIND_NEXT_SECTOR, - STATE_READ_NEXT_SECTOR, - STATE_WRITE_FIND_SECTOR, - STATE_WRITE_SECTOR, - STATE_READ_FIND_ADDRESS, - STATE_READ_ADDRESS, - STATE_FORMAT_FIND, - STATE_FORMAT, - STATE_SEEK -}; - -static int disc_sector_state[2] = {0, 0}; -static int disc_sector_track[2] = {0, 0}; -static int disc_sector_side[2] = {0, 0}; -static int disc_sector_drive; -static int disc_sector_sector[2] = {0, 0}; -static int disc_sector_n[2] = {0, 0}; -static uint8_t disc_sector_fill[2] = {0, 0}; -static int cur_sector[2], cur_byte[2]; -static int index_count[2]; - -int raw_tsize[2] = {6250, 6250}; -int gap2_size[2] = {22, 22}; -int gap3_size[2] = {0, 0}; - -int disc_sector_reset_state(int drive); - -void disc_sector_reset(int drive, int side) -{ - disc_sector_count[drive][side] = 0; - - if (side == 0) - { - disc_sector_reset_state(drive); - disc_sector_state[drive] = STATE_SEEK; - } -} - -void disc_sector_add(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_t n, int rate, uint8_t *data) -{ - sector_t *s = &disc_sector_data[drive][side][disc_sector_count[drive][side]]; -//pclog("disc_sector_add: drive=%i side=%i %i r=%i\n", drive, side, disc_sector_count[drive][side],r ); - if (disc_sector_count[drive][side] >= MAX_SECTORS) - return; - - s->c = c; - s->h = h; - s->r = r; - s->n = n; - // pclog("Adding sector: %i %i %i %i\n", c, h, r, n); - s->rate = rate; - s->data = data; - - disc_sector_count[drive][side]++; -} - -static int get_bitcell_period(int drive) -{ - return ((&disc_sector_data[drive][0][0])->rate * 300) / fdd_getrpm(drive ^ fdd_swap); -} - -void disc_sector_readsector(int drive, int sector, int track, int side, int rate, int sector_size) -{ - // pclog("disc_sector_readsector: fdc_period=%i img_period=%i rate=%i sector=%i track=%i side=%i\n", fdc_get_bitcell_period(), get_bitcell_period(drive), rate, sector, track, side); - // pclog("disc_sector_readsector: fdc_period=%i img_period=%i rate=%i c=%i h=%i r=%i n=%i\n", fdc_get_bitcell_period(), get_bitcell_period(drive), rate, track, side, sector, sector_size); - - disc_sector_track[drive] = track; - disc_sector_side[drive] = side; - disc_sector_drive = drive; - disc_sector_sector[drive] = sector; - disc_sector_n[drive] = sector_size; - disc_sector_reset_state(drive); - if (sector == SECTOR_FIRST) - disc_sector_state[drive] = STATE_READ_FIND_FIRST_SECTOR; - else if (sector == SECTOR_NEXT) - disc_sector_state[drive] = STATE_READ_FIND_NEXT_SECTOR; - else - disc_sector_state[drive] = STATE_READ_FIND_SECTOR; -} - -void disc_sector_writesector(int drive, int sector, int track, int side, int rate, int sector_size) -{ -// pclog("disc_sector_writesector: fdc_period=%i img_period=%i rate=%i\n", fdc_get_bitcell_period(), get_bitcell_period(drive), rate); - - if (writeprot[drive] || swwp) - { - fdc_writeprotect(); - return; - } - - disc_sector_track[drive] = track; - disc_sector_side[drive] = side; - disc_sector_drive = drive; - disc_sector_sector[drive] = sector; - disc_sector_n[drive] = sector_size; - disc_sector_reset_state(drive); - disc_sector_state[drive] = STATE_WRITE_FIND_SECTOR; -} - -void disc_sector_readaddress(int drive, int track, int side, int rate) -{ - // pclog("disc_sector_readaddress: fdc_period=%i img_period=%i rate=%i track=%i side=%i\n", fdc_get_bitcell_period(), get_bitcell_period(drive), rate, track, side); - - disc_sector_track[drive] = track; - disc_sector_side[drive] = side; - disc_sector_drive = drive; - disc_sector_reset_state(drive); - disc_sector_state[drive] = STATE_READ_FIND_ADDRESS; -} - -void disc_sector_format(int drive, int track, int side, int rate, uint8_t fill) -{ - disc_sector_track[drive] = track; - disc_sector_side[drive] = side; - disc_sector_drive = drive; - disc_sector_fill[drive] = fill; - disc_sector_reset_state(drive); - disc_sector_state[drive] = STATE_FORMAT_FIND; -} - -void disc_sector_stop(int drive) -{ - disc_sector_state[drive] = STATE_IDLE; -} - -static void index_pulse(int drive) -{ - if (disc_sector_state[drive] != STATE_IDLE) fdc_indexpulse(); -} - -// char *track_buffer[2][2][25512]; -char track_layout[2][2][25512]; - -int id_positions[2][2][MAX_SECTORS]; - -/* 0 = MFM, 1 = FM, 2 = MFM perpendicular, 3 = reserved */ -/* 4 = ISO, 0 = IBM */ -int media_type = 0; - -#define GAP3_LEN_VARIABLE 0x1B - -int disc_sector_get_gap3_size(int drive, int side, int track) -{ - if (!img_xdf_type(drive)) - { - return gap3_size[drive]; - } - - switch (track) - { - case 0: - return 60; - default: - return GAP3_LEN_VARIABLE; - } - - return 0x7A; -} - -void disc_sector_prepare_track_layout(int drive, int side, int track) -{ - sector_t *s; - int i = 0; - int j = 0; - int real_gap0_len = ((media_type & 3) == 1) ? 40 : 80; - int sync_len = ((media_type & 3) == 1) ? 6 : 12; - int am_len = ((media_type & 3) == 1) ? 1 : 4; - int real_gap1_len = ((media_type & 3) == 1) ? 26 : 50; - // track_layout[drive][side] = (char *) malloc(raw_tsize[drive]); - // id_positions[drive][side] = (int *) malloc(disc_sector_count[drive][side] * 4); - memset(track_layout[drive][side], BYTE_GAP4, raw_tsize[drive]); - memset(id_positions[drive][side], 0, 1024); - i = 0; - if (!(media_type & 4)) - { - memset(track_layout[drive][side] + i, BYTE_GAP0, real_gap0_len); - i += real_gap0_len - 1; - memset(track_layout[drive][side] + i, BYTE_I_SYNC, sync_len); - i += sync_len; - if ((media_type & 3) != 1) - { - memset(track_layout[drive][side] + i, BYTE_IAM_SYNC, 3); - i += 3; - } - memset(track_layout[drive][side] + i, BYTE_IAM, 1); - i++; - memset(track_layout[drive][side] + i, BYTE_GAP1, real_gap1_len); - i += real_gap1_len; - } - else - { - memset(track_layout[drive][side] + i, BYTE_GAP1, real_gap1_len); - i += real_gap1_len - 1; - } - track_layout[drive][side][0] |= BYTE_INDEX_HOLE; - for (j = 0; j < disc_sector_count[drive][side]; j++) - { - s = &disc_sector_data[drive][side][j]; - // pclog("Sector %i (%i)\n", j, s->n); - memset(track_layout[drive][side] + i, BYTE_ID_SYNC, sync_len); - i += sync_len; - if ((media_type & 3) != 1) - { - memset(track_layout[drive][side] + i, BYTE_IDAM_SYNC, 3); - i += 3; - } - memset(track_layout[drive][side] + i, BYTE_IDAM, 1); - i++; - memset(track_layout[drive][side] + i, BYTE_ID, 4); - i += 4; - memset(track_layout[drive][side] + i, BYTE_ID_CRC, 2); - i += 2; - id_positions[drive][side][j] = i; - memset(track_layout[drive][side] + i, BYTE_GAP2, gap2_size[drive]); - i += gap2_size[drive]; - memset(track_layout[drive][side] + i, BYTE_DATA_SYNC, sync_len); - i += sync_len; - if ((media_type & 3) != 1) - { - memset(track_layout[drive][side] + i, BYTE_DATAAM_SYNC, 3); - i += 3; - } - memset(track_layout[drive][side] + i, BYTE_DATAAM, 1); - i++; - memset(track_layout[drive][side] + i, BYTE_DATA, (128 << ((int) s->n))); - i += (128 << ((int) s->n)); - memset(track_layout[drive][side] + i, BYTE_DATA_CRC, 2); - i += 2; - memset(track_layout[drive][side] + i, BYTE_GAP3, disc_sector_get_gap3_size(drive, side, track)); - i += disc_sector_get_gap3_size(drive, side, track); - } - // pclog("Track length: %i bytes\n", i); - - if (side == 0) disc_sector_state[drive] = STATE_IDLE; -} - -int disc_sector_reset_state(int drive) -{ - id_counter[drive] = data_counter[drive] = index_count[drive] = gap3_counter[drive] = cur_rate[drive] = 0; - last_sector[drive] = NULL; -} - -int disc_sector_find_sector(int drive) -{ - int side = fdd_get_head(drive); - int i = 0; - for (i = 0; i < disc_sector_count[drive][side]; i++) - { - if (id_positions[drive][side][i] == cur_track_pos[drive]) - { - return i; - } - } - return -1; -} - -int disc_sector_match(int drive) -{ - int temp; - if (last_sector[drive] == NULL) return 0; - temp = (disc_sector_track[drive] == last_sector[drive]->c); - temp = temp && (disc_sector_side[drive] == last_sector[drive]->h); - temp = temp && (disc_sector_sector[drive] == last_sector[drive]->r); - temp = temp && (disc_sector_n[drive] == last_sector[drive]->n); - return temp; -} - -uint32_t disc_sector_get_data_len(int drive) -{ - if (disc_sector_n[drive]) - { - return (128 << ((uint32_t) disc_sector_n[drive])); - } - else - { - if (fdc_get_dtl() < 128) - { - return fdc_get_dtl(); - } - else - { - return (128 << ((uint32_t) disc_sector_n[drive])); - } - } -} - -int disc_sector_can_read_address(int drive) -{ - int temp; - temp = (fdc_get_bitcell_period() == get_bitcell_period(drive)); - temp = temp && fdd_can_read_medium(drive ^ fdd_swap); - return temp; -} - -int disc_sector_can_format(int drive) -{ - int temp; - temp = !writeprot[drive]; - temp = temp && !swwp; - temp = temp && disc_sector_can_read_address(drive); - temp = temp && (fdc_get_format_sectors() == disc_sector_count[drive][disc_sector_side[drive]]); - temp = temp && (!img_xdf_type(drive)); - return temp; -} - -int disc_sector_find_state(int drive) -{ - int temp; - temp = (disc_sector_state[drive] == STATE_READ_FIND_SECTOR); - temp = temp || (disc_sector_state[drive] == STATE_READ_FIND_FIRST_SECTOR); - temp = temp || (disc_sector_state[drive] == STATE_READ_FIND_NEXT_SECTOR); - temp = temp || (disc_sector_state[drive] == STATE_WRITE_FIND_SECTOR); - temp = temp || (disc_sector_state[drive] == STATE_READ_FIND_ADDRESS); - temp = temp || (disc_sector_state[drive] == STATE_FORMAT_FIND); - return temp; -} - -int disc_sector_read_state(int drive) -{ - int temp; - temp = (disc_sector_state[drive] == STATE_READ_SECTOR); - temp = temp || (disc_sector_state[drive] == STATE_READ_FIRST_SECTOR); - temp = temp || (disc_sector_state[drive] == STATE_READ_NEXT_SECTOR); - return temp; -} - -int section_pos[2] = {0, 0}; - -typedef union -{ - uint32_t dword; - uint8_t byte_array[4]; -} sector_id; - -sector_id format_sector_id; - -void disc_sector_poll() -{ - sector_t *s; - int data; - int drive = disc_sector_drive; - int side = fdd_get_head(drive); - int found_sector = 0; - int b = 0; - - int cur_id_pos = 0; - int cur_data_pos = 0; - int cur_gap3_pos = 0; - int max_gap = 0; - - uint8_t track_byte = 0; - uint8_t track_index = 0; - uint8_t track_sector = 0; - uint8_t track_byte_type = 0; - - uint8_t old_track_byte = 0; - uint8_t old_track_index = 0; - uint8_t old_track_sector = 0; - uint8_t old_track_byte_type = 0; - - if (disc_sector_state[drive] == STATE_SEEK) - { - cur_track_pos[drive]++; - cur_track_pos[drive] %= raw_tsize[drive]; - return; - } - - if (disc_sector_state[drive] == STATE_FORMAT_FIND) - { - if (!(disc_sector_can_format(drive))) - { - if (disc_sector_can_read_address(drive)) - { - // pclog("disc_sector_poll(): Disk is write protected or attempting to format wrong number of sectors per track\n"); - fdc_writeprotect(); - } - else - { - // pclog("disc_sector_poll(): Unable to format at the requested density or bitcell period\n"); - fdc_notfound(); - } - disc_sector_state[drive] = STATE_IDLE; - disc_sector_reset_state(drive); - cur_track_pos[drive]++; - cur_track_pos[drive] %= raw_tsize[drive]; - return; - } - } - - track_byte = track_layout[drive][side][cur_track_pos[drive]]; - track_index = track_byte & BYTE_INDEX_HOLE; - track_sector = track_byte & BYTE_IS_SECTOR; - track_byte_type = track_byte & BYTE_TYPE; - - if (track_index) - { - if (disc_sector_state[drive] != STATE_IDLE) - { - index_pulse(drive); - index_count[drive]++; - } - if (disc_sector_state[drive] == STATE_FORMAT) - { - // pclog("Index hole hit again, format finished\n"); - disc_sector_state[drive] = STATE_IDLE; - if (!disable_write) disc_sector_writeback[drive](drive); - fdc_sector_finishread(drive); - } - if ((disc_sector_state[drive] == STATE_FORMAT_FIND) && disc_sector_can_read_address(drive)) - { - // pclog("Index hole hit, formatting track...\n"); - disc_sector_state[drive] = STATE_FORMAT; - } - } - - switch(track_byte) - { - case BYTE_ID_SYNC: - if (disc_sector_state[drive] != STATE_FORMAT) break; - cur_id_pos = cur_track_pos[drive] - section_pos[drive]; - if (cur_id_pos > 3) break; - data = fdc_getdata(0); - if ((data == -1) && (cur_id_pos < 3)) - { - /* Data failed to be sent from the FDC, abort. */ - // pclog("disc_sector_poll(): Unable to receive further data from the FDC\n"); - disc_sector_state[drive] = STATE_IDLE; - disc_sector_reset_state(drive); - cur_track_pos[drive]++; - cur_track_pos[drive] %= raw_tsize[drive]; - return; - } - format_sector_id.byte_array[cur_id_pos] = data & 0xff; - // pclog("format_sector_id[%i] = %i\n", cur_id_pos, format_sector_id.byte_array[cur_id_pos]); - if (cur_id_pos == 3) - { - fdc_stop_id_request(); - // pclog("Formatting sector: %08X...\n", format_sector_id.dword); - } - break; - case BYTE_DATA: - cur_data_pos = cur_track_pos[drive] - section_pos[drive]; - if (disc_sector_read_state(drive) && (last_sector[drive] != NULL)) - { - if (fdc_data(last_sector[drive]->data[data_counter[drive]])) - { - /* Data failed to be sent to the FDC, abort. */ - // pclog("disc_sector_poll(): Unable to send further data to the FDC\n"); - disc_sector_state[drive] = STATE_IDLE; - disc_sector_reset_state(drive); - cur_track_pos[drive]++; - cur_track_pos[drive] %= raw_tsize[drive]; - return; - } - } - if ((disc_sector_state[drive] == STATE_WRITE_SECTOR) && (last_sector[drive] != NULL)) - { - data = fdc_getdata(data_counter[drive] == ((128 << ((uint32_t) last_sector[drive]->n)) - 1)); - if (data == -1) - { - /* Data failed to be sent from the FDC, abort. */ - // pclog("disc_sector_poll(): Unable to receive further data from the FDC\n"); - disc_sector_state[drive] = STATE_IDLE; - disc_sector_reset_state(drive); - cur_track_pos[drive]++; - cur_track_pos[drive] %= raw_tsize[drive]; - return; - } - if (!disable_write) last_sector[drive]->data[data_counter[drive]] = data; - } - if ((disc_sector_state[drive] == STATE_FORMAT) && (last_sector[drive] != NULL)) - { - if (!disable_write) last_sector[drive]->data[data_counter[drive]] = disc_sector_fill[drive]; - } - data_counter[drive]++; - if (last_sector[drive] == NULL) - { - data_counter[drive] = 0; - } - else - { - data_counter[drive] %= (128 << ((uint32_t) last_sector[drive]->n)); - } - break; - case BYTE_GAP3: - cur_gap3_pos = cur_track_pos[drive] - section_pos[drive]; - max_gap = fdc_get_gap(); - if (max_gap > disc_sector_get_gap3_size(drive, side, disc_sector_track[drive])) - { - max_gap = disc_sector_get_gap3_size(drive, side, disc_sector_track[drive]); - } - if (cur_gap3_pos == (max_gap - 1)) - { - if (disc_sector_read_state(drive) && (last_sector[drive] != NULL)) - { - disc_sector_state[drive] = STATE_IDLE; - fdc_sector_finishread(drive); - } - if ((disc_sector_state[drive] == STATE_WRITE_SECTOR) && (last_sector[drive] != NULL)) - { - disc_sector_state[drive] = STATE_IDLE; - if (!disable_write) disc_sector_writeback[drive](drive); - fdc_sector_finishread(drive); - } - } - break; - } - - old_track_byte = track_byte; - old_track_index = track_index; - old_track_sector = track_sector; - old_track_byte_type = track_byte_type; - - cur_track_pos[drive]++; - cur_track_pos[drive] %= raw_tsize[drive]; - - track_byte = track_layout[drive][side][cur_track_pos[drive]]; - track_index = track_byte & BYTE_INDEX_HOLE; - track_sector = track_byte & BYTE_IS_SECTOR; - track_byte_type = track_byte & BYTE_TYPE; - - if ((disc_sector_state[drive] != STATE_IDLE) && (disc_sector_state[drive] != STATE_SEEK)) - { - if (index_count[drive] > 1) - { - if (disc_sector_find_state(drive)) - { - /* The index hole has been hit twice and we're still in a find state. - This means sector finding has failed for whatever reason. - Abort with sector not found and set state to idle. */ - // pclog("disc_sector_poll(): Sector not found (%i %i %i %i)\n", disc_sector_track[drive], disc_sector_side[drive], disc_sector_sector[drive], disc_sector_n[drive]); - fdc_notfound(); - disc_sector_state[drive] = STATE_IDLE; - disc_sector_reset_state(drive); - return; - } - } - } - - if (track_byte != old_track_byte) - { - // if (disc_sector_state[drive] == STATE_FORMAT) pclog("Track byte: %02X, old: %02X\n", track_byte, old_track_byte); - section_pos[drive] = cur_track_pos[drive]; - switch(track_byte) - { - case BYTE_ID_SYNC: - if (disc_sector_state[drive] == STATE_FORMAT) - { - // pclog("Requesting next sector ID...\n"); - fdc_request_next_sector_id(); - } - break; - case BYTE_GAP2: - found_sector = disc_sector_find_sector(drive); - // pclog("Found sector: %i\n", found_sector); - cur_sector[drive] = found_sector; - last_sector[drive] = &disc_sector_data[drive][side][found_sector]; - cur_rate[drive] = last_sector[drive]->rate; - if (!(disc_sector_can_read_address(drive))) last_sector[drive] = NULL; - - /* ID CRC read, if state is read address, return address */ - // if ((disc_sector_state[drive] == STATE_READ_FIND_ADDRESS) && !(disc_sector_can_read_address(drive))) - if ((disc_sector_state[drive] == STATE_READ_FIND_ADDRESS) && disc_sector_can_read_address(drive)) - { - // pclog("Reading sector ID...\n"); - fdc_sectorid(last_sector[drive]->c, last_sector[drive]->h, last_sector[drive]->r, last_sector[drive]->n, 0, 0); - disc_sector_state[drive] = STATE_IDLE; - } - break; - case BYTE_DATA: - // data_counter[drive] = 0; - switch (disc_sector_state[drive]) - { - case STATE_READ_FIND_SECTOR: - if (disc_sector_match(drive) && disc_sector_can_read_address(drive)) - { - disc_sector_state[drive] = STATE_READ_SECTOR; - } - break; - case STATE_READ_FIND_FIRST_SECTOR: - if ((cur_sector[drive] == 0) && disc_sector_can_read_address(drive)) disc_sector_state[drive] = STATE_READ_FIRST_SECTOR; - break; - case STATE_READ_FIND_NEXT_SECTOR: - if (disc_sector_can_read_address(drive)) disc_sector_state[drive] = STATE_READ_NEXT_SECTOR; - break; - case STATE_WRITE_FIND_SECTOR: - if (disc_sector_match(drive) && disc_sector_can_read_address(drive)) disc_sector_state[drive] = STATE_WRITE_SECTOR; - break; - /* case STATE_FORMAT: - // pclog("Format: Starting sector fill...\n"); - break; */ - } - break; - case BYTE_GAP4: - if (last_sector[drive] != NULL) last_sector[drive] = NULL; - break; - } - } -} diff --git a/src/disc_td0.c b/src/disc_td0.c index 1e12a97a7..3844deef9 100644 --- a/src/disc_td0.c +++ b/src/disc_td0.c @@ -90,6 +90,7 @@ typedef struct FILE *f; int tracks; + int track_width; int sides; uint16_t disk_flags; uint16_t default_track_flags; @@ -226,7 +227,7 @@ int td0_state_next_word(td0dsk_t *state) { state->tdctl.ibufndx = 0; state->tdctl.ibufcnt = td0_state_data_read(state, state->tdctl.inbuf,BUFSZ); - if(state->tdctl.ibufcnt <= 0) + if(state->tdctl.ibufcnt == 0) return(-1); } while (state->getlen <= 8) { // typically reads a word at a time @@ -503,12 +504,7 @@ uint8_t header[12]; void td0_load(int drive, char *fn) { - int track; - int head; - int fm; - int offset = 0; int ret = 0; - const int max_size = 4*1024*1024; // 4MB ought to be large enough for any floppy d86f_unregister(drive); @@ -740,6 +736,8 @@ int td0_initialize(int drive) td0[drive].disk_flags = header[5] & 0x06; + td0[drive].track_width = (header[7] & 1) ^ 1; + // rate = (header[5] & 0x7f) >= 3 ? 0 : rates[header[5] & 0x7f]; // td0[drive].default_track_flags |= rate; @@ -898,13 +896,16 @@ int td0_initialize(int drive) td0[drive].gap3_len = td0[drive].calculated_gap3_lengths[0][0]; /* If we can't determine the GAP3 length, assume the smallest one we possibly know of. */ } - if (td0[drive].tracks > 43) td0[drive].disk_flags |= 1; /* If the image has more than 43 tracks, then the tracks are thin (96 tpi). */ - if(head_count == 2) { td0[drive].disk_flags |= 8; /* 2 sides */ } + if (td0[drive].tracks <= 43) + { + td0[drive].track_width &= ~1; + } + td0[drive].sides = head_count; td0[drive].current_side_flags[0] = td0[drive].side_flags[0][0]; @@ -1076,7 +1077,7 @@ void td0_seek(int drive, int track) if (!td0[drive].f) return; - if (d86f_is_40_track(drive) && fdd_doublestep_40(drive)) + if (!td0[drive].track_width && fdd_doublestep_40(drive)) track /= 2; is_trackx = (track == 0) ? 0 : 1; @@ -1107,7 +1108,7 @@ void td0_seek(int drive, int track) interleave_type = td0_track_is_interleave(drive, side, track); - current_pos = d86f_prepare_pretrack(drive, side, 0, 1); + current_pos = d86f_prepare_pretrack(drive, side, 0); if (!xdf_type) { @@ -1129,7 +1130,7 @@ void td0_seek(int drive, int track) id[3] = td0[drive].sects[track][side][actual_sector].size; // pclog("TD0: %i %i %i %i (%i %i) (GPL=%i)\n", id[0], id[1], id[2], id[3], td0[drive].sects[track][side][actual_sector].deleted, td0[drive].sects[track][side][actual_sector].bad_crc, track_gap3); ssize = 128 << ((uint32_t) td0[drive].sects[track][side][actual_sector].size); - current_pos = d86f_prepare_sector(drive, side, current_pos, id, td0[drive].sects[track][side][actual_sector].data, ssize, 1, track_gap2, track_gap3, 0, td0[drive].sects[track][side][actual_sector].deleted, td0[drive].sects[track][side][actual_sector].bad_crc); + current_pos = d86f_prepare_sector(drive, side, current_pos, id, td0[drive].sects[track][side][actual_sector].data, ssize, track_gap2, track_gap3, td0[drive].sects[track][side][actual_sector].deleted, td0[drive].sects[track][side][actual_sector].bad_crc); } } else @@ -1148,11 +1149,11 @@ void td0_seek(int drive, int track) // pclog("TD0: XDF: (%i %i) %i %i %i %i (%i %i) (GPL=%i)\n", track, side, id[0], id[1], id[2], id[3], td0[drive].sects[track][side][ordered_pos].deleted, td0[drive].sects[track][side][ordered_pos].bad_crc, track_gap3); if (is_trackx) { - current_pos = d86f_prepare_sector(drive, side, xdf_trackx_spos[xdf_type][xdf_sector], id, td0[drive].sects[track][side][ordered_pos].data, ssize, 1, track_gap2, xdf_gap3_sizes[xdf_type][is_trackx], 0, td0[drive].sects[track][side][ordered_pos].deleted, td0[drive].sects[track][side][ordered_pos].bad_crc); + current_pos = d86f_prepare_sector(drive, side, xdf_trackx_spos[xdf_type][xdf_sector], id, td0[drive].sects[track][side][ordered_pos].data, ssize, track_gap2, xdf_gap3_sizes[xdf_type][is_trackx], td0[drive].sects[track][side][ordered_pos].deleted, td0[drive].sects[track][side][ordered_pos].bad_crc); } else { - current_pos = d86f_prepare_sector(drive, side, current_pos, id, td0[drive].sects[track][side][ordered_pos].data, ssize, 1, track_gap2, xdf_gap3_sizes[xdf_type][is_trackx], 0, td0[drive].sects[track][side][ordered_pos].deleted, td0[drive].sects[track][side][ordered_pos].bad_crc); + current_pos = d86f_prepare_sector(drive, side, current_pos, id, td0[drive].sects[track][side][ordered_pos].data, ssize, track_gap2, xdf_gap3_sizes[xdf_type][is_trackx], td0[drive].sects[track][side][ordered_pos].deleted, td0[drive].sects[track][side][ordered_pos].bad_crc); } } } @@ -1193,19 +1194,18 @@ void td0_set_sector(int drive, int side, uint8_t c, uint8_t h, uint8_t r, uint8_ return; } -uint8_t td0_poll_read_data(int drive, int side, uint16_t pos) -{ - return td0[drive].sects[td0[drive].track][side][td0[drive].current_sector_index[side]].data[pos]; -} - void d86f_register_td0(int drive) { d86f_handler[drive].disk_flags = td0_disk_flags; d86f_handler[drive].side_flags = td0_side_flags; d86f_handler[drive].writeback = null_writeback; d86f_handler[drive].set_sector = td0_set_sector; - d86f_handler[drive].read_data = td0_poll_read_data; - d86f_handler[drive].write_data = null_poll_write_data; + d86f_handler[drive].write_data = null_write_data; d86f_handler[drive].format_conditions = null_format_conditions; + d86f_handler[drive].extra_bit_cells = null_extra_bit_cells; + d86f_handler[drive].encoded_data = common_encoded_data; + d86f_handler[drive].read_revolution = common_read_revolution; + d86f_handler[drive].index_hole_pos = null_index_hole_pos; + d86f_handler[drive].get_raw_size = common_get_raw_size; d86f_handler[drive].check_crc = 1; } \ No newline at end of file diff --git a/src/fdc.c b/src/fdc.c index 35a22fdf7..e1bcfefd5 100644 --- a/src/fdc.c +++ b/src/fdc.c @@ -12,10 +12,25 @@ #include "pic.h" #include "timer.h" -extern int64_t motoron; +extern int64_t motoron[2]; int ui_writeprot[2] = {0, 0}; +int command_has_drivesel[256] = { [0x02] = 1, /* READ TRACK */ + [0x04] = 1, /* SENSE DRIVE STATUS */ + [0x05] = 1, /* WRITE DATA */ + [0x06] = 1, /* READ DATA */ + [0x07] = 1, /* RECALIBRATE */ + [0x09] = 1, /* WRITE DELETED DATA */ + [0x0A] = 1, /* READ ID */ + [0x0C] = 1, /* READ DELETED DATA */ + [0x0D] = 1, /* FORMAT TRACK */ + [0x0F] = 1, /* SEEK, RELATIVE SEEK */ + [0x11] = 1, /* SCAN EQUAL */ + [0x16] = 1, /* VERIFY */ + [0x19] = 1, /* SCAN LOW OR EQUAL */ + [0x1D] = 1 }; /* SCAN HIGH OR EQUAL */ + static int fdc_reset_stat = 0; /*FDC*/ typedef struct FDC @@ -239,7 +254,6 @@ int fdc_get_format_sectors() void fdc_reset_fifo_buf() { - int i = 0; memset(fdc.fifobuf, 0, 16); fdc.fifobufpos = 0; } @@ -346,7 +360,6 @@ void fdc_update_enh_mode(int enh_mode) int fdc_get_rwc(int drive) { return fdc.rwc[drive]; - fdc_rate(drive); } void fdc_update_rwc(int drive, int rwc) @@ -525,8 +538,6 @@ void fdc_write(uint16_t addr, uint8_t val, void *priv) // pclog("Write FDC %04X %02X %04X:%04X %i %02X %i rate=%i %i\n",addr,val,cs>>4,pc,ins,fdc.st0,ins,fdc.rate, fdc.data_ready); int drive; int seek_time; - int temp_drive; - int temp_motoron; switch (addr&7) { @@ -551,8 +562,12 @@ void fdc_write(uint16_t addr, uint8_t val, void *priv) discint=-1; fdc_reset(); } - motoron = val & 0x01; - fdc.drive = 0; + if (!fdd_get_flags(0)) + { + val &= 0xfe; + } + motoron[0] = val & 0x01; + // fdc.drive = 0; /* if (motoron) output = 3; else @@ -577,25 +592,17 @@ void fdc_write(uint16_t addr, uint8_t val, void *priv) timer_process(); timer_update_outstanding(); val &= 0x3f; /* Drives 2 and 3 are not emulated, so their motors are always forced off. */ - temp_drive = val & 3; - temp_motoron = 0x10 << temp_drive; - temp_motoron = val & temp_motoron; - motoron = 0; - if (temp_motoron && (temp_drive <= 1)) + /* We can now simplify this since each motor now spins separately. */ + if (!fdd_get_flags(0 ^ fdd_swap)) { - /* Selected drive is drive 0 or 1 and has motor on bit set too, change drive selection. */ - fdc.drive = temp_drive; - disc_drivesel = fdc.drive; - disc_set_drivesel(fdc.drive); - motoron = (val & 0xf0) ? 1 : 0; - val &= 0x3f; + val &= 0x2f; } - else + if (!fdd_get_flags(1 ^ fdd_swap)) { - /* Selected drive is either drive 2 or 3 or has motor on bit clear, turn off the motor. */ - motoron = 0; - val &= 0x0f; + val &= 0x1f; } + motoron[0] = (val & 0x10); + motoron[1] = (val & 0x20); } fdc.dor=val; // printf("DOR now %02X\n",val); @@ -809,22 +816,15 @@ bad_command: timer_process(); disctime = 1024 * (1 << TIMER_SHIFT); timer_update_outstanding(); -// fdc.drive = fdc.params[0] & 3; + if (command_has_drivesel[discint & 0x1F]) + { + fdc.drive = fdc.params[0] & 3; + } fdc_reset_stat = 0; - if (fdc.dor & (0x10 << fdc.drive)) - { - motoron = 0; - disc_drivesel = fdc.drive; - disc_set_drivesel(fdc.drive); - motoron = 1; - } - else - { - motoron = 0; - } switch (discint & 0x1F) { case 2: /*Read a track*/ + fdc_reset_fifo_buf(); fdc_rate(fdc.drive); fdc.head=fdc.params[2]; fdd_set_head(fdc.drive, (fdc.params[0] & 4) ? 1 : 0); @@ -877,6 +877,7 @@ bad_command: case 5: /*Write data*/ case 9: /*Write deleted data*/ + fdc_reset_fifo_buf(); fdc_rate(fdc.drive); fdc.head=fdc.params[2]; fdd_set_head(fdc.drive, (fdc.params[0] & 4) ? 1 : 0); @@ -900,12 +901,24 @@ bad_command: fdc.pos = 0; if (fdc.pcjr) fdc.stat = 0xb0; + else + { + if (fdc.dma) + { + fdc.stat = 0x90; + } + else + { + fdc.stat = 0xb0; + } + } // ioc_fiq(IOC_FIQ_DISC_DATA); break; case 0x11: /*Scan equal*/ case 0x19: /*Scan low or equal*/ case 0x1D: /*Scan high or equal*/ + fdc_reset_fifo_buf(); fdc_rate(fdc.drive); fdc.head=fdc.params[2]; fdd_set_head(fdc.drive, (fdc.params[0] & 4) ? 1 : 0); @@ -929,6 +942,17 @@ bad_command: fdc.pos = 0; if (fdc.pcjr) fdc.stat = 0xb0; + else + { + if (fdc.dma) + { + fdc.stat = 0x90; + } + else + { + fdc.stat = 0xb0; + } + } // ioc_fiq(IOC_FIQ_DISC_DATA); break; @@ -936,6 +960,7 @@ bad_command: if (fdc.params[0] & 0x80) fdc.sc = fdc.params[7]; case 6: /*Read data*/ case 0xC: /*Read deleted data*/ + fdc_reset_fifo_buf(); fdc_rate(fdc.drive); fdc.head=fdc.params[2]; fdd_set_head(fdc.drive, (fdc.params[0] & 4) ? 1 : 0); @@ -1176,7 +1201,7 @@ void fdc_poll_readwrite_finish(int compare) fdc.res[6] |= 0x40; fdc.wrong_am = 0; } - if (compare) + if (compare == 1) { if (!fdc.satisfying_sectors) { @@ -1187,6 +1212,18 @@ void fdc_poll_readwrite_finish(int compare) fdc.res[6] |= 8; } } + else if (compare == 2) + { + if (fdc.satisfying_sectors & 1) + { + fdc.res[5] |= 0x20; + } + if (fdc.satisfying_sectors & 2) + { + fdc.res[5] |= 0x20; + fdc.res[6] |= 0x20; + } + } fdc.res[7]=fdc.rw_track; fdc.res[8]=fdc.head; fdc.res[9]=fdc.sector; @@ -1208,7 +1245,7 @@ void fdc_no_dma_end(int compare) fdc.res[6] |= 0x40; fdc.wrong_am = 0; } - if (compare) + if (compare == 1) { if (!fdc.satisfying_sectors) { @@ -1219,6 +1256,18 @@ void fdc_no_dma_end(int compare) fdc.res[6] |= 8; } } + else if (compare == 2) + { + if (fdc.satisfying_sectors & 1) + { + fdc.res[5] |= 0x20; + } + if (fdc.satisfying_sectors & 2) + { + fdc.res[5] |= 0x20; + fdc.res[6] |= 0x20; + } + } fdc.res[7]=fdc.rw_track; fdc.res[8]=fdc.head; fdc.res[9]=fdc.sector; @@ -1259,7 +1308,7 @@ void fdc_callback() // pclog("Read a track callback, eot=%i\n", fdc.eot[fdc.drive]); if (!fdc.eot[fdc.drive] || fdc.tc) { - fdc_poll_readwrite_finish(0); + fdc_poll_readwrite_finish(2); return; } else @@ -1587,6 +1636,11 @@ void fdc_overrun() paramstogo=7; } +int fdc_is_verify() +{ + return (fdc.deleted & 2) ? 1 : 0; +} + int fdc_data(uint8_t data) { if (fdc.deleted & 2) @@ -1665,6 +1719,14 @@ void fdc_finishread() // rpclog("fdc_finishread\n"); } +void fdc_track_finishread(int condition) +{ + fdc.satisfying_sectors |= condition; + fdc.inread = 0; + fdc_callback(); +// rpclog("fdc_finishread\n"); +} + void fdc_sector_finishcompare(int satisfying) { fdc.satisfying_sectors++; diff --git a/src/fdc.h b/src/fdc.h index 232411bf6..eefeee400 100644 --- a/src/fdc.h +++ b/src/fdc.h @@ -52,3 +52,5 @@ void fdc_finishcompare(int satisfying); void fdc_finishread(); void fdc_sector_finishcompare(int satisfying); void fdc_sector_finishread(); +void fdc_track_finishread(int condition); +int fdc_is_verify(); diff --git a/src/fdc37c932fr.c b/src/fdc37c932fr.c index 6d15ad8d7..4f91667f7 100644 --- a/src/fdc37c932fr.c +++ b/src/fdc37c932fr.c @@ -194,7 +194,7 @@ void fdc37c932fr_write(uint16_t port, uint8_t val, void *priv) else { valxor = val ^ fdc37c932fr_ld_regs[fdc37c932fr_regs[7]][fdc37c932fr_curreg]; - if ((fdc37c932fr_curreg & 0xF0 == 0x70) && (fdc37c932fr_regs[7] < 4)) return; + if (((fdc37c932fr_curreg & 0xF0) == 0x70) && (fdc37c932fr_regs[7] < 4)) return; /* Block writes to IDE configuration. */ if (fdc37c932fr_regs[7] == 1) return; if (fdc37c932fr_regs[7] == 2) return; @@ -474,6 +474,7 @@ void fdc37c932fr_init() fdc_update_rwc(1, 0); fdc_update_drvrate(0, 0); fdc_update_drvrate(1, 0); + fdc_update_max_track(79); io_sethandler(0xe0, 0x0006, fdc37c932fr_gpio_read, NULL, NULL, fdc37c932fr_gpio_write, NULL, NULL, NULL); io_sethandler(0xea, 0x0002, fdc37c932fr_gpio_read, NULL, NULL, fdc37c932fr_gpio_write, NULL, NULL, NULL); io_sethandler(0x3f0, 0x0002, fdc37c932fr_read, NULL, NULL, fdc37c932fr_write, NULL, NULL, NULL); diff --git a/src/fdd.c b/src/fdd.c index 44d3a7d89..5d7fb46c8 100644 --- a/src/fdd.c +++ b/src/fdd.c @@ -14,11 +14,6 @@ static struct int densel; - int drate; - - int kbps; - int fdc_kbps; - int head; } fdd[2]; @@ -63,19 +58,19 @@ static struct }, { /*3.5" DD*/ .max_track = 86, - .flags = FLAG_RPM_300 | FLAG_HOLE0 + .flags = FLAG_RPM_300 | FLAG_HOLE0 | FLAG_DOUBLE_STEP }, { /*3.5" HD*/ .max_track = 86, - .flags = FLAG_RPM_300 | FLAG_HOLE0 | FLAG_HOLE1 + .flags = FLAG_RPM_300 | FLAG_HOLE0 | FLAG_HOLE1 | FLAG_DOUBLE_STEP }, { /*3.5" HD 3-Mode*/ .max_track = 86, - .flags = FLAG_RPM_300 | FLAG_RPM_360 | FLAG_HOLE0 | FLAG_HOLE1 + .flags = FLAG_RPM_300 | FLAG_RPM_360 | FLAG_HOLE0 | FLAG_HOLE1 | FLAG_DOUBLE_STEP }, { /*3.5" ED*/ .max_track = 86, - .flags = FLAG_RPM_300 | FLAG_HOLE0 | FLAG_HOLE1 | FLAG_HOLE2 + .flags = FLAG_RPM_300 | FLAG_HOLE0 | FLAG_HOLE1 | FLAG_HOLE2 | FLAG_DOUBLE_STEP } }; @@ -186,7 +181,7 @@ int fdd_can_read_medium(int drive) int fdd_doublestep_40(int drive) { - return drive_types[fdd[drive].type].flags & FLAG_DOUBLE_STEP; + return (drive_types[fdd[drive].type].flags & FLAG_DOUBLE_STEP) ? 1 : 0; } void fdd_set_type(int drive, int type) diff --git a/src/fdi2raw.c b/src/fdi2raw.c index 7f2a8da40..1b921717b 100644 --- a/src/fdi2raw.c +++ b/src/fdi2raw.c @@ -1913,8 +1913,8 @@ static int decode_lowlevel_track (FDI *fdi, int track, struct fdi_cache *cache) idxp[i] = sum; } len = totalavg / 100000; - outlog("totalavg=%u index=%d (%d) maxidx=%d weakbits=%d len=%d\n", - totalavg, indexoffset, maxidx, weakbits, len); + /* outlog("totalavg=%u index=%d (%d) maxidx=%d weakbits=%d len=%d\n", + totalavg, indexoffset, maxidx, weakbits, len); */ cache->avgp = avgp; cache->idxp = idxp; cache->minp = minp; @@ -2073,8 +2073,8 @@ int fdi2raw_loadrevolution_2 (FDI *fdi, uae_u16 *mfmbuf, uae_u16 *tracktiming, i cache->avgp, cache->minp, cache->maxp, cache->idxp, cache->maxidx, &idx, cache->pulses, mfm); //fdi2_gcr_decode (fdi, totalavg, avgp, minp, maxp, idxp, idx_off1, idx_off2, idx_off3, maxidx, pulses); - outlog("track %d: nbits=%d avg len=%.2f weakbits=%d idx=%d\n", - track, bitoffset, (double)cache->totalavg / bitoffset, cache->weakbits, cache->indexoffset); + /* outlog("track %d: nbits=%d avg len=%.2f weakbits=%d idx=%d\n", + track, bitoffset, (double)cache->totalavg / bitoffset, cache->weakbits, cache->indexoffset); */ len = fdi->out; if (cache->weakbits >= 10 && multirev) *multirev = 1; @@ -2126,8 +2126,8 @@ int fdi2raw_loadtrack (FDI *fdi, uae_u16 *mfmbuf, uae_u16 *tracktiming, int trac else fdi->bit_rate = 250; - outlog ("track %d: srclen: %d track_type: %02.2X, bitrate: %d\n", - fdi->current_track, fdi->track_src_len, fdi->track_type, fdi->bit_rate); + /* outlog ("track %d: srclen: %d track_type: %02.2X, bitrate: %d\n", + fdi->current_track, fdi->track_src_len, fdi->track_type, fdi->bit_rate); */ if ((fdi->track_type & 0xc0) == 0x80) { diff --git a/src/ibm.h b/src/ibm.h index 32734eb90..516145257 100644 --- a/src/ibm.h +++ b/src/ibm.h @@ -347,7 +347,7 @@ char discfns[2][256]; int driveempty[2]; #define MDA ((gfxcard==GFX_MDA || gfxcard==GFX_HERCULES || gfxcard==GFX_INCOLOR) && (romset=ROM_IBMAT)) -#define VGA ((gfxcard>=GFX_TVGA || romset==ROM_ACER386) && gfxcard!=GFX_INCOLOR && gfxcard!=GFX_COMPAQ_EGA && gfxcard!=GFX_SUPER_EGA && romset!=ROM_PC1640 && romset!=ROM_PC1512 && romset!=ROM_TANDY && romset!=ROM_PC200) +#define VGA ((gfxcard>=GFX_TVGA || romset==ROM_ACER386) && gfxcard!=GFX_COLORPLUS && gfxcard!=GFX_INCOLOR && gfxcard!=GFX_COMPAQ_EGA && gfxcard!=GFX_SUPER_EGA && romset!=ROM_PC1640 && romset!=ROM_PC1512 && romset!=ROM_TANDY && romset!=ROM_PC200) #define PCJR (romset == ROM_IBMPCJR) #define AMIBIOS (romset==ROM_AMI386 || romset==ROM_AMI486 || romset == ROM_WIN486) @@ -413,7 +413,6 @@ enum ROM_P55VA, /*Epox P55-VA / 430VX / Award BIOS / SMC FDC37C932FR*/ ROM_440FX, /*Unknown / 440FX / Award BIOS / SMC FDC37C665*/ - ROM_KN97, /*ASUS KN-97 / 440FX / Award BIOS / Winbond W8387F*/ ROM_MARL, /*Intel Advanced/ML / 430HX / AMI BIOS / National Semiconductors PC87306*/ ROM_THOR, /*Intel Advanced/ATX / 430FX / AMI BIOS / National Semiconductors PC87306*/ @@ -448,7 +447,8 @@ enum GFX_VIRGEDX, /*S3 Virge/DX*/ GFX_PHOENIX_TRIO32, /*S3 732/Trio32 (Phoenix)*/ GFX_PHOENIX_TRIO64, /*S3 764/Trio64 (Phoenix)*/ - GFX_INCOLOR, /* Hercules InColor */ + GFX_INCOLOR, /* Hercules InColor */ + GFX_COLORPLUS, /* Plantronics ColorPlus */ GFX_ET4000W32C, /*Tseng ET4000/W32p (Cardex) (STG RAMDAC) */ GFX_COMPAQ_EGA, /*Compaq EGA*/ GFX_SUPER_EGA, /*Using Chips & Technologies SuperEGA BIOS*/ @@ -633,3 +633,5 @@ extern char nvr_path[1024]; extern int path_len; char *nvr_concat(char *to_concat); + +int mem_a20_state; diff --git a/src/ide.c b/src/ide.c index b666d029e..288906a6c 100644 --- a/src/ide.c +++ b/src/ide.c @@ -751,8 +751,6 @@ static void loadhd(IDE *ide, int d, const char *fn) uint32_t sector_size = 512; uint32_t zero = 0; uint32_t full_size = 0; - uint32_t transl_spt = 0; - uint32_t transl_hpc = 0; int c; ide->base = 0; ide->hdi = 0; @@ -1327,7 +1325,8 @@ void writeide(int ide_board, uint16_t addr, uint8_t val) case WIN_CHECKPOWERMODE1: ide->atastat = BUSY_STAT; timer_process(); - callbackide(ide_board); + idecallback[ide_board]=30*IDE_TIME; + // callbackide(ide_board); // idecallback[ide_board]=200*IDE_TIME; timer_update_outstanding(); return; @@ -1358,7 +1357,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val) ide->error = ABRT_ERR; ide_irq_raise(ide); /* fatal("Bad IDE command %02X\n", val);*/ - pclog("Bad IDE command %02X\n", val); + // pclog("Bad IDE command %02X\n", val); return; } @@ -1640,6 +1639,9 @@ void callbackide(int ide_board) return; case WIN_CHECKPOWERMODE1: + if (IDE_DRIVE_IS_CDROM(ide)) { + goto abort_cmd; + } ide->secount = 0xFF; ide->atastat = READY_STAT | DSC_STAT; ide_irq_raise(ide); @@ -1671,16 +1673,12 @@ void callbackide(int ide_board) case WIN_READ_DMA: if (IDE_DRIVE_IS_CDROM(ide)) { - atapi->readsector(ide->buffer, ide_get_sector(ide)); - ide->pos=0; - } - else - { - addr = ide_get_sector(ide) * 512; - fseeko64(ide->hdfile, ide->base + addr, SEEK_SET); - fread(ide->buffer, 512, 1, ide->hdfile); - ide->pos=0; + goto abort_cmd; } + addr = ide_get_sector(ide) * 512; + fseeko64(ide->hdfile, addr, SEEK_SET); + fread(ide->buffer, 512, 1, ide->hdfile); + ide->pos=0; if (ide_bus_master_read_sector) { @@ -1710,7 +1708,7 @@ void callbackide(int ide_board) return; case WIN_READ_MULTIPLE: - /* According to the official ATAPI reference: + /* According to the official ATA reference: If the Read Multiple command is attempted before the Set Multiple Mode command has been executed or when Read Multiple commands are @@ -2119,6 +2117,7 @@ static int atapi_read_structure(IDE *ide, int format, { int layer = packet[6]; uint64_t total_sectors; + total_sectors = (uint64_t) atapi->size(); if (layer != 0) return -ASC_INV_FIELD_IN_CMD_PACKET; @@ -3209,7 +3208,6 @@ atapi_out: case GPCMD_SEND_DVD_STRUCTURE: default: -bad_atapi_command: ide->atastat = READY_STAT | ERR_STAT; /*CHECK CONDITION*/ ide->error = (SENSE_ILLEGAL_REQUEST << 4) | ABRT_ERR; if (atapi_sense.sensekey == SENSE_UNIT_ATTENTION) diff --git a/src/intel_flash.c b/src/intel_flash.c index 53d81fca3..f1d78f342 100644 --- a/src/intel_flash.c +++ b/src/intel_flash.c @@ -280,25 +280,12 @@ void *intel_flash_init(uint8_t type) case ROM_MB500N: strcpy(flash_path, "roms/mb500n/"); break; -#if 0 - case ROM_P54TP4XE: - strcpy(flash_path, "roms/p54tp4xe/"); - break; -#endif case ROM_ACERM3A: strcpy(flash_path, "roms/acerm3a/"); break; case ROM_ACERV35N: strcpy(flash_path, "roms/acerv35n/"); break; - case ROM_P55TVP4: - strcpy(flash_path, "roms/p55tvp4/"); - break; -#if 0 - case ROM_P55T2P4: - strcpy(flash_path, "roms/p55t2p4/"); - break; -#endif case ROM_430VX: strcpy(flash_path, "roms/430vx/"); break; @@ -308,9 +295,6 @@ void *intel_flash_init(uint8_t type) case ROM_440FX: strcpy(flash_path, "roms/440fx/"); break; - case ROM_KN97: - strcpy(flash_path, "roms/kn97/"); - break; case ROM_MARL: strcpy(flash_path, "roms/marl/"); break; @@ -394,7 +378,6 @@ void *intel_flash_init(uint8_t type) } /* Load the DMI block. */ - memset(fpath, 0, 1024); strcpy(fpath, flash_path); strcat(fpath, "dmi.bin"); f = romfopen(fpath, "rb"); @@ -405,7 +388,6 @@ void *intel_flash_init(uint8_t type) } /* Load the ESCD block. */ - memset(fpath, 0, 1024); strcpy(fpath, flash_path); strcat(fpath, "escd.bin"); f = romfopen(fpath, "rb"); @@ -460,7 +442,6 @@ void intel_flash_close(void *p) fclose(f); /* Save the DMI block. */ - memset(fpath, 0, 1024); strcpy(fpath, flash_path); strcat(fpath, "dmi.bin"); f = romfopen(fpath, "wb"); @@ -468,7 +449,6 @@ void intel_flash_close(void *p) fclose(f); /* Save the ESCD block. */ - memset(fpath, 0, 1024); strcpy(fpath, flash_path); strcat(fpath, "escd.bin"); f = romfopen(fpath, "wb"); diff --git a/src/jim.c b/src/jim.c index d2e33e223..d1adcd5c3 100644 --- a/src/jim.c +++ b/src/jim.c @@ -73,7 +73,7 @@ void jim_init() europc_rtc.dat[3]=1; europc_rtc.dat[4]=1; europc_rtc.dat[5]=0x88; - if (gfxcard==GFX_CGA) viddat=0x12; + if (gfxcard==GFX_CGA || gfxcard == GFX_COLORPLUS) viddat=0x12; else if (gfxcard==GFX_MDA || gfxcard==GFX_HERCULES || gfxcard==GFX_INCOLOR) viddat=3; else viddat=0x10; europc_rtc.dat[0xB]=viddat; diff --git a/src/lzf/Changes b/src/lzf/Changes new file mode 100644 index 000000000..93bd4cb6d --- /dev/null +++ b/src/lzf/Changes @@ -0,0 +1,136 @@ +3.6 Mon Feb 7 17:37:31 CET 2011 + - fixed hash calculation in C♯ version (Tiago Freitas Leal). + - unroll copy for small sizes, use memcpy for larger sizes, + greatly speeding up decompression in most cases. + - finally disable rep movsb - it's a big loss on modern intel cpus, + and only a small win on amd cpus. + - improve C++ compatibility of the code. + - slightly improve compressor speed. + - halved memory requirements for compressor on 64 bit architectures, + which can improve the speed quite a bit on older cpus. + +3.5 Fri May 1 02:28:42 CEST 2009 + - lzf_compress did sometimes write one octet past the given output + buffer (analyzed and nice testcase by Salvatore Sanfilippo). + +3.4 Tue Sep 2 06:45:00 CEST 2008 + - the fix from 3.3 introduced a compression bug, which is fixed in + this release (which explains the mysterious prerelease...). Thanks + once more to Clément Calmels. + +3.3 Mon Aug 25 03:17:42 CEST 2008 + - lzf_compress could access memory after the given input buffer + when outputting back references. reported with nice testcase + by Clément Calmels. + +3.2 Fri May 9 18:52:23 CEST 2008 + - include a workaround for failing POSIX and real-world compliance + on 64 bit windows (microsoft claims to support POSIX, but is far + from it). (bug found and analysed nicely by John Lilley). + +3.1 Fri Nov 30 11:33:04 CET 2007 + - IMPORTANT BUGFIX: a too long final literal run would corrupt data + in the encoder (this was introduced in 3.0 only, earlier versions + are safe). + +3.0 Tue Nov 13 22:13:09 CET 2007 + - switched to 2-clause bsd with "GPL v2 or any later version" option. + - speed up compression by ~10-15% in common cases + by some manual unrolling. + - import some compiler tricks from JSON::XS, for further speed-ups. + - tune hash functions depending on ULTRA_FAST or VERY_FAST settings. + - for typical binary data (e.g. /bin/bash, memory dumps, + canterbury corpus etc.), speed is now comparable to fastlz, but + with better compression ratio. with ULTRA_FAST, it's typically + 3-15% faster than fastlz while still maintaining a similar ratio. + (amd64 and core 2 duo, ymmv). thanks a lot for the competition :) + - undo inline assembly in compressor, it is no longer helpful. + - no changes to the decompressor. + - use a HLOG of 16 by default now (formerly 15). + +2.1 Fri Nov 2 13:34:42 CET 2007 + - switched to a 2-clause bsd license with GPL exception. + - get rid of memcpy. + - tentatively use rep movsb on x86 and x86_64 (gcc only) for a + moderate speed improvement. + - applied patch by Kein-Hong Man to maske lzf.c compile under + the crippled mingw32 environment. + +2.0 Fri Feb 16 23:11:18 CET 2007 + - replaced lzf demo by industrial-strength lzf utility with behaviour + similar other compression utilities. Thanks for Stefan Traby for + rewriting it! + - fix state arg prototype. + +1.7 Wed Sep 27 17:29:15 CEST 2006 + - remove bogus "unlzf" patch. + note to self: never accept well-meant patches. + - make lzf more robust in presence of padding bytes or sudden eof. + +1.6 Fri Jul 7 17:31:26 CEST 2006 + - the lzf example utility will now uncompress if invoked + as "unlzf" (patch by Scott Feeney). + - add CHECK_INPUT option that adds more checks for input + data validity. + - help applications that do not pass in the correct length + (such as php) by returning either EINVAL or E2BIG. + - default HLOG size is now 15 (cpu caches have increased). + - documentation fixes. + +1.51 Thu Apr 14 22:15:46 CEST 2005 + - incorporated C♯ implementation of both the en- and decoder, + written by "Oren J. Maurice". + You can find it in the cs/ subdirectory. + - make FRST, NEXT IDX overridable if lzf_c.c is directly included + in the code. + +1.5 Tue Mar 8 20:23:23 CET 2005 + - incorporated improvements by Adam D. Moss, + which includes a new VERY_FAST mode which is + a bit slower than ULTRA_FAST but much better, + and enabled it as default. + +1.401 Thu Mar 3 18:00:52 CET 2005 + - use cstring in c++, not string.h. + - change of contact address. + +1.4 Wed Dec 15 08:08:49 CET 2004 + - very very slight tuning of the hashing function. + +1.3 Thu Mar 25 15:41:17 CET 2004 + - changed license of lzf core code to explicitly allow + relicensing under the GPLv2. + - added VPATH support as suggested by Björn Eriksson. + +1.2 Mon Dec 29 13:47:28 CET 2003 + - avoid spurious memory accesses after the to-be-compressed + memory region. originally reported by Michal Zalewski. + - flip LZF_STACK_ARG meaning (to be correct). + +1.1 Tue Dec 23 05:48:32 CET 2003 + - removed #warn directive, it's not worth the hassle. + - add LZF_STACK_ARG and AVOID_ERRNO configurations + for embedded systems. + - make it compile cleanly as c++. + - some small documentation and code fixes. + +1.0 Sun Nov 17 12:37:37 CET 2002 + - slightly better compression ratio, almost unmeasurably + slower. + - some documentation fixes. + +0.4 Thu Jun 13 14:11:10 CEST 2002 + - typoe fix. + - lzf demo program now properly decompresses small files. + - fix another 64 bit issue, found by Laurent Deniel. + +0.3 Tue Jan 16 13:21:14 CET 2001 + - fix silly beginners 32/64 bit mistake. + +0.2 Thu Jan 4 05:56:42 CET 2001 + - now totally independent of autoconfig, for + easy inclusion into other programs. + - much better fine-tuning, faster and better than 0.1. + +0.1 2000 + - initial release. diff --git a/src/lzf/LICENSE b/src/lzf/LICENSE new file mode 100644 index 000000000..ee54ff717 --- /dev/null +++ b/src/lzf/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2000-2009 Marc Alexander Lehmann + +Redistribution and use in source and binary forms, with or without modifica- +tion, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- +CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- +CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- +ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +OF THE POSSIBILITY OF SUCH DAMAGE. + +Alternatively, the following files carry an additional notice that +explicitly allows relicensing under the GPLv2: lzf.c lzf.h lzfP.h lzf_c.c +lzf_d.c + diff --git a/src/lzf/Makefile.in b/src/lzf/Makefile.in new file mode 100644 index 000000000..3c87d62de --- /dev/null +++ b/src/lzf/Makefile.in @@ -0,0 +1,66 @@ +VERSION = 3.6 + +prefix = @prefix@ +exec_prefix = @exec_prefix@ +libdir = @libdir@ +bindir = @bindir@ +includedir = @includedir@ + +VPATH = @srcdir@ + +CC = @CC@ +CPPFLAGS = -I. @CPPFLAGS@ +CFLAGS = @CFLAGS@ +LDFLAGS = @LDFLAGS@ +RANLIB = @RANLIB@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ + +all: Makefile lzf + +clean: + -rm -f *.o *.a lzf bench + +lzf_c.o: lzf_c.c lzfP.h + +lzf_d.o: lzf_d.c lzfP.h + +lzf.o: lzf.c + +lzf: lzf.o liblzf.a + +lzfP.h: lzf.h config.h + +liblzf.a: lzf_c.o lzf_d.o + rm -f $@ + $(AR) rc $@ $^ + $(RANLIB) $@ + +install: all + $(INSTALL) -d $(bindir) + $(INSTALL) -m 755 lzf $(bindir) + $(INSTALL) -d $(includedir) + $(INSTALL_DATA) lzf.h $(includedir) + $(INSTALL) -d $(libdir) + $(INSTALL_DATA) liblzf.a $(libdir) + +dist: + mkdir liblzf-$(VERSION) + tar c LICENSE README Makefile.in config.h.in \ + configure configure.ac install-sh \ + cs/README cs/CLZF.cs \ + lzf.h lzfP.h lzf_c.c lzf_d.c \ + crc32.h lzf.c Changes \ + | tar xpC liblzf-$(VERSION) + -chown -R root.root liblzf-$(VERSION) + chmod -R u=rwX,go=rX liblzf-$(VERSION) + tar cvf - liblzf-$(VERSION) | gzip -9 >liblzf-$(VERSION).tar.gz + rm -rf liblzf-$(VERSION) + ls -l liblzf-$(VERSION).tar.gz + +Makefile: Makefile.in + ./config.status + +bench: Makefile liblzf.a bench.c + $(CC) $(CPPFLAGS) $(CFLAGS) -g -o bench bench.c -L. -llzf + diff --git a/src/lzf/README b/src/lzf/README new file mode 100644 index 000000000..0734ebe06 --- /dev/null +++ b/src/lzf/README @@ -0,0 +1,29 @@ +DESCRIPTION + LZF is an extremely fast (not that much slower than a pure memcpy) + compression algorithm. It is ideal for applications where you want to + save *some* space but not at the cost of speed. It is ideal for + repetitive data as well. The module is self-contained and very small. + + It's written in ISO-C with no external dependencies other than what + C provides and can easily be #include'd into your code, no makefile + changes or library builds requires. + + A C♯ implementation without external dependencies is available, too. + + I do not know for certain whether any patents in any countries apply + to this algorithm, but at the moment it is believed that it is free + from any patents. More importantly, it is also free to use in every + software package (see LICENSE). + + See the lzf.h file for details on how the functions in this + mini-library are to be used. + + NOTE: This package contains a very bare-bones command-line utility + which is neither optimized for speed nor for compression. This library + is really intended to be used inside larger programs. + +AUTHOR + This library was written by Marc Lehmann (See also + http://software.schmorp.de/pkg/liblzf). + + diff --git a/src/lzf/config.h b/src/lzf/config.h new file mode 100644 index 000000000..5fd69c6bd --- /dev/null +++ b/src/lzf/config.h @@ -0,0 +1,16 @@ +/* config.h.in. Generated automatically from configure.in by autoheader 2.13. */ + +/* Define to empty if the keyword does not work. */ +#undef const + +/* Define if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* The number of bytes in a int. */ +#undef SIZEOF_INT + +/* The number of bytes in a long. */ +#undef SIZEOF_LONG + +/* The number of bytes in a short. */ +#undef SIZEOF_SHORT diff --git a/src/lzf/configure b/src/lzf/configure new file mode 100644 index 000000000..7a3a2b25c --- /dev/null +++ b/src/lzf/configure @@ -0,0 +1,7871 @@ +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.60. +# +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + + +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + +if test "x$CONFIG_SHELL" = x; then + if (eval ":") 2>/dev/null; then + as_have_required=yes +else + as_have_required=no +fi + + if test $as_have_required = yes && (eval ": +(as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=\$LINENO + as_lineno_2=\$LINENO + test \"x\$as_lineno_1\" != \"x\$as_lineno_2\" && + test \"x\`expr \$as_lineno_1 + 1\`\" = \"x\$as_lineno_2\") || { (exit 1); exit 1; } +") 2> /dev/null; then + : +else + as_candidate_shells= + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in /usr/bin/posix$PATH_SEPARATOR/bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + case $as_dir in + /*) + for as_base in sh bash ksh sh5; do + as_candidate_shells="$as_candidate_shells $as_dir/$as_base" + done;; + esac +done +IFS=$as_save_IFS + + + for as_shell in $as_candidate_shells $SHELL; do + # Try only shells that exist, to save several forks. + if { test -f "$as_shell" || test -f "$as_shell.exe"; } && + { ("$as_shell") 2> /dev/null <<\_ASEOF +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +: +_ASEOF +}; then + CONFIG_SHELL=$as_shell + as_have_required=yes + if { "$as_shell" 2> /dev/null <<\_ASEOF +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + +: +(as_func_return () { + (exit $1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = "$1" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test $exitcode = 0) || { (exit 1); exit 1; } + +( + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2") || { (exit 1); exit 1; } + +_ASEOF +}; then + break +fi + +fi + + done + + if test "x$CONFIG_SHELL" != x; then + for as_var in BASH_ENV ENV + do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + done + export CONFIG_SHELL + exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} +fi + + + if test $as_have_required = no; then + echo This script requires a shell more modern than all the + echo shells that I found on your system. Please install a + echo modern shell, or manually run the script under such a + echo shell if you do have one. + { (exit 1); exit 1; } +fi + + +fi + +fi + + + +(eval "as_func_return () { + (exit \$1) +} +as_func_success () { + as_func_return 0 +} +as_func_failure () { + as_func_return 1 +} +as_func_ret_success () { + return 0 +} +as_func_ret_failure () { + return 1 +} + +exitcode=0 +if as_func_success; then + : +else + exitcode=1 + echo as_func_success failed. +fi + +if as_func_failure; then + exitcode=1 + echo as_func_failure succeeded. +fi + +if as_func_ret_success; then + : +else + exitcode=1 + echo as_func_ret_success failed. +fi + +if as_func_ret_failure; then + exitcode=1 + echo as_func_ret_failure succeeded. +fi + +if ( set x; as_func_ret_success y && test x = \"\$1\" ); then + : +else + exitcode=1 + echo positional parameters were not saved. +fi + +test \$exitcode = 0") || { + echo No shell found that supports shell functions. + echo Please tell autoconf@gnu.org about your system, + echo including any error possibly output before this + echo message +} + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +# Find out whether ``test -x'' works. Don't use a zero-byte file, as +# systems may use methods other than mode bits to determine executability. +cat >conf$$.file <<_ASEOF +#! /bin/sh +exit 0 +_ASEOF +chmod +x conf$$.file +if test -x conf$$.file >/dev/null 2>&1; then + as_executable_p="test -x" +else + as_executable_p=: +fi +rm -f conf$$.file + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + + +exec 7<&0 &1 + +# Name of the host. +# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# so uname gets run too. +ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` + +# +# Initializations. +# +ac_default_prefix=/usr/local +ac_clean_files= +ac_config_libobj_dir=. +LIBOBJS= +cross_compiling=no +subdirs= +MFLAGS= +MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} + +# Identity of this package. +PACKAGE_NAME= +PACKAGE_TARNAME= +PACKAGE_VERSION= +PACKAGE_STRING= +PACKAGE_BUGREPORT= + +ac_unique_file="lzfP.h" +# Factoring default headers for most tests. +ac_includes_default="\ +#include +#if HAVE_SYS_TYPES_H +# include +#endif +#if HAVE_SYS_STAT_H +# include +#endif +#if STDC_HEADERS +# include +# include +#else +# if HAVE_STDLIB_H +# include +# endif +#endif +#if HAVE_STRING_H +# if !STDC_HEADERS && HAVE_MEMORY_H +# include +# endif +# include +#endif +#if HAVE_STRINGS_H +# include +#endif +#if HAVE_INTTYPES_H +# include +#endif +#if HAVE_STDINT_H +# include +#endif +#if HAVE_UNISTD_H +# include +#endif" + +ac_subst_vars='SHELL +PATH_SEPARATOR +PACKAGE_NAME +PACKAGE_TARNAME +PACKAGE_VERSION +PACKAGE_STRING +PACKAGE_BUGREPORT +exec_prefix +prefix +program_transform_name +bindir +sbindir +libexecdir +datarootdir +datadir +sysconfdir +sharedstatedir +localstatedir +includedir +oldincludedir +docdir +infodir +htmldir +dvidir +pdfdir +psdir +libdir +localedir +mandir +DEFS +ECHO_C +ECHO_N +ECHO_T +LIBS +build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +CPPFLAGS +ac_ct_CC +EXEEXT +OBJEXT +RANLIB +INSTALL_PROGRAM +INSTALL_SCRIPT +INSTALL_DATA +CPP +GREP +EGREP +LIBOBJS +LTLIBOBJS' +ac_subst_files='' + ac_precious_vars='build_alias +host_alias +target_alias +CC +CFLAGS +LDFLAGS +CPPFLAGS +CPP' + + +# Initialize some variables set by options. +ac_init_help= +ac_init_version=false +# The variables have the same names as the options, with +# dashes changed to underlines. +cache_file=/dev/null +exec_prefix=NONE +no_create= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, +silent= +site= +srcdir= +verbose= +x_includes=NONE +x_libraries=NONE + +# Installation directory options. +# These are left unexpanded so users can "make install exec_prefix=/foo" +# and all the variables that are supposed to be based on exec_prefix +# by default will actually change. +# Use braces instead of parens because sh, perl, etc. also accept them. +# (The list follows the same order as the GNU Coding Standards.) +bindir='${exec_prefix}/bin' +sbindir='${exec_prefix}/sbin' +libexecdir='${exec_prefix}/libexec' +datarootdir='${prefix}/share' +datadir='${datarootdir}' +sysconfdir='${prefix}/etc' +sharedstatedir='${prefix}/com' +localstatedir='${prefix}/var' +includedir='${prefix}/include' +oldincludedir='/usr/include' +docdir='${datarootdir}/doc/${PACKAGE}' +infodir='${datarootdir}/info' +htmldir='${docdir}' +dvidir='${docdir}' +pdfdir='${docdir}' +psdir='${docdir}' +libdir='${exec_prefix}/lib' +localedir='${datarootdir}/locale' +mandir='${datarootdir}/man' + +ac_prev= +ac_dashdash= +for ac_option +do + # If the previous option needs an argument, assign it. + if test -n "$ac_prev"; then + eval $ac_prev=\$ac_option + ac_prev= + continue + fi + + case $ac_option in + *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *) ac_optarg=yes ;; + esac + + # Accept the important Cygnus configure options, so we can diagnose typos. + + case $ac_dashdash$ac_option in + --) + ac_dashdash=yes ;; + + -bindir | --bindir | --bindi | --bind | --bin | --bi) + ac_prev=bindir ;; + -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*) + bindir=$ac_optarg ;; + + -build | --build | --buil | --bui | --bu) + ac_prev=build_alias ;; + -build=* | --build=* | --buil=* | --bui=* | --bu=*) + build_alias=$ac_optarg ;; + + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file=$ac_optarg ;; + + --config-cache | -C) + cache_file=config.cache ;; + + -datadir | --datadir | --datadi | --datad) + ac_prev=datadir ;; + -datadir=* | --datadir=* | --datadi=* | --datad=*) + datadir=$ac_optarg ;; + + -datarootdir | --datarootdir | --datarootdi | --datarootd | --dataroot \ + | --dataroo | --dataro | --datar) + ac_prev=datarootdir ;; + -datarootdir=* | --datarootdir=* | --datarootdi=* | --datarootd=* \ + | --dataroot=* | --dataroo=* | --dataro=* | --datar=*) + datarootdir=$ac_optarg ;; + + -disable-* | --disable-*) + ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/-/_/g'` + eval enable_$ac_feature=no ;; + + -docdir | --docdir | --docdi | --doc | --do) + ac_prev=docdir ;; + -docdir=* | --docdir=* | --docdi=* | --doc=* | --do=*) + docdir=$ac_optarg ;; + + -dvidir | --dvidir | --dvidi | --dvid | --dvi | --dv) + ac_prev=dvidir ;; + -dvidir=* | --dvidir=* | --dvidi=* | --dvid=* | --dvi=* | --dv=*) + dvidir=$ac_optarg ;; + + -enable-* | --enable-*) + ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid feature name: $ac_feature" >&2 + { (exit 1); exit 1; }; } + ac_feature=`echo $ac_feature | sed 's/-/_/g'` + eval enable_$ac_feature=\$ac_optarg ;; + + -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ + | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ + | --exec | --exe | --ex) + ac_prev=exec_prefix ;; + -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \ + | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \ + | --exec=* | --exe=* | --ex=*) + exec_prefix=$ac_optarg ;; + + -gas | --gas | --ga | --g) + # Obsolete; use --with-gas. + with_gas=yes ;; + + -help | --help | --hel | --he | -h) + ac_init_help=long ;; + -help=r* | --help=r* | --hel=r* | --he=r* | -hr*) + ac_init_help=recursive ;; + -help=s* | --help=s* | --hel=s* | --he=s* | -hs*) + ac_init_help=short ;; + + -host | --host | --hos | --ho) + ac_prev=host_alias ;; + -host=* | --host=* | --hos=* | --ho=*) + host_alias=$ac_optarg ;; + + -htmldir | --htmldir | --htmldi | --htmld | --html | --htm | --ht) + ac_prev=htmldir ;; + -htmldir=* | --htmldir=* | --htmldi=* | --htmld=* | --html=* | --htm=* \ + | --ht=*) + htmldir=$ac_optarg ;; + + -includedir | --includedir | --includedi | --included | --include \ + | --includ | --inclu | --incl | --inc) + ac_prev=includedir ;; + -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \ + | --includ=* | --inclu=* | --incl=* | --inc=*) + includedir=$ac_optarg ;; + + -infodir | --infodir | --infodi | --infod | --info | --inf) + ac_prev=infodir ;; + -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*) + infodir=$ac_optarg ;; + + -libdir | --libdir | --libdi | --libd) + ac_prev=libdir ;; + -libdir=* | --libdir=* | --libdi=* | --libd=*) + libdir=$ac_optarg ;; + + -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \ + | --libexe | --libex | --libe) + ac_prev=libexecdir ;; + -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \ + | --libexe=* | --libex=* | --libe=*) + libexecdir=$ac_optarg ;; + + -localedir | --localedir | --localedi | --localed | --locale) + ac_prev=localedir ;; + -localedir=* | --localedir=* | --localedi=* | --localed=* | --locale=*) + localedir=$ac_optarg ;; + + -localstatedir | --localstatedir | --localstatedi | --localstated \ + | --localstate | --localstat | --localsta | --localst | --locals) + ac_prev=localstatedir ;; + -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \ + | --localstate=* | --localstat=* | --localsta=* | --localst=* | --locals=*) + localstatedir=$ac_optarg ;; + + -mandir | --mandir | --mandi | --mand | --man | --ma | --m) + ac_prev=mandir ;; + -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*) + mandir=$ac_optarg ;; + + -nfp | --nfp | --nf) + # Obsolete; use --without-fp. + with_fp=no ;; + + -no-create | --no-create | --no-creat | --no-crea | --no-cre \ + | --no-cr | --no-c | -n) + no_create=yes ;; + + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; + + -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \ + | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \ + | --oldin | --oldi | --old | --ol | --o) + ac_prev=oldincludedir ;; + -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \ + | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \ + | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*) + oldincludedir=$ac_optarg ;; + + -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) + ac_prev=prefix ;; + -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*) + prefix=$ac_optarg ;; + + -program-prefix | --program-prefix | --program-prefi | --program-pref \ + | --program-pre | --program-pr | --program-p) + ac_prev=program_prefix ;; + -program-prefix=* | --program-prefix=* | --program-prefi=* \ + | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*) + program_prefix=$ac_optarg ;; + + -program-suffix | --program-suffix | --program-suffi | --program-suff \ + | --program-suf | --program-su | --program-s) + ac_prev=program_suffix ;; + -program-suffix=* | --program-suffix=* | --program-suffi=* \ + | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*) + program_suffix=$ac_optarg ;; + + -program-transform-name | --program-transform-name \ + | --program-transform-nam | --program-transform-na \ + | --program-transform-n | --program-transform- \ + | --program-transform | --program-transfor \ + | --program-transfo | --program-transf \ + | --program-trans | --program-tran \ + | --progr-tra | --program-tr | --program-t) + ac_prev=program_transform_name ;; + -program-transform-name=* | --program-transform-name=* \ + | --program-transform-nam=* | --program-transform-na=* \ + | --program-transform-n=* | --program-transform-=* \ + | --program-transform=* | --program-transfor=* \ + | --program-transfo=* | --program-transf=* \ + | --program-trans=* | --program-tran=* \ + | --progr-tra=* | --program-tr=* | --program-t=*) + program_transform_name=$ac_optarg ;; + + -pdfdir | --pdfdir | --pdfdi | --pdfd | --pdf | --pd) + ac_prev=pdfdir ;; + -pdfdir=* | --pdfdir=* | --pdfdi=* | --pdfd=* | --pdf=* | --pd=*) + pdfdir=$ac_optarg ;; + + -psdir | --psdir | --psdi | --psd | --ps) + ac_prev=psdir ;; + -psdir=* | --psdir=* | --psdi=* | --psd=* | --ps=*) + psdir=$ac_optarg ;; + + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + silent=yes ;; + + -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb) + ac_prev=sbindir ;; + -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \ + | --sbi=* | --sb=*) + sbindir=$ac_optarg ;; + + -sharedstatedir | --sharedstatedir | --sharedstatedi \ + | --sharedstated | --sharedstate | --sharedstat | --sharedsta \ + | --sharedst | --shareds | --shared | --share | --shar \ + | --sha | --sh) + ac_prev=sharedstatedir ;; + -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \ + | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \ + | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \ + | --sha=* | --sh=*) + sharedstatedir=$ac_optarg ;; + + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site=$ac_optarg ;; + + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) + ac_prev=srcdir ;; + -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*) + srcdir=$ac_optarg ;; + + -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \ + | --syscon | --sysco | --sysc | --sys | --sy) + ac_prev=sysconfdir ;; + -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \ + | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*) + sysconfdir=$ac_optarg ;; + + -target | --target | --targe | --targ | --tar | --ta | --t) + ac_prev=target_alias ;; + -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*) + target_alias=$ac_optarg ;; + + -v | -verbose | --verbose | --verbos | --verbo | --verb) + verbose=yes ;; + + -version | --version | --versio | --versi | --vers | -V) + ac_init_version=: ;; + + -with-* | --with-*) + ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package| sed 's/-/_/g'` + eval with_$ac_package=\$ac_optarg ;; + + -without-* | --without-*) + ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'` + # Reject names that are not valid shell variable names. + expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid package name: $ac_package" >&2 + { (exit 1); exit 1; }; } + ac_package=`echo $ac_package | sed 's/-/_/g'` + eval with_$ac_package=no ;; + + --x) + # Obsolete; use --with-x. + with_x=yes ;; + + -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ + | --x-incl | --x-inc | --x-in | --x-i) + ac_prev=x_includes ;; + -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \ + | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*) + x_includes=$ac_optarg ;; + + -x-libraries | --x-libraries | --x-librarie | --x-librari \ + | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l) + ac_prev=x_libraries ;; + -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \ + | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) + x_libraries=$ac_optarg ;; + + -*) { echo "$as_me: error: unrecognized option: $ac_option +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } + ;; + + *=*) + ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='` + # Reject names that are not valid shell variable names. + expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null && + { echo "$as_me: error: invalid variable name: $ac_envvar" >&2 + { (exit 1); exit 1; }; } + eval $ac_envvar=\$ac_optarg + export $ac_envvar ;; + + *) + # FIXME: should be removed in autoconf 3.0. + echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && + echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} + ;; + + esac +done + +if test -n "$ac_prev"; then + ac_option=--`echo $ac_prev | sed 's/_/-/g'` + { echo "$as_me: error: missing argument to $ac_option" >&2 + { (exit 1); exit 1; }; } +fi + +# Be sure to have absolute directory names. +for ac_var in exec_prefix prefix bindir sbindir libexecdir datarootdir \ + datadir sysconfdir sharedstatedir localstatedir includedir \ + oldincludedir docdir infodir htmldir dvidir pdfdir psdir \ + libdir localedir mandir +do + eval ac_val=\$$ac_var + case $ac_val in + [\\/$]* | ?:[\\/]* ) continue;; + NONE | '' ) case $ac_var in *prefix ) continue;; esac;; + esac + { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2 + { (exit 1); exit 1; }; } +done + +# There might be people who depend on the old broken behavior: `$host' +# used to hold the argument of --host etc. +# FIXME: To remove some day. +build=$build_alias +host=$host_alias +target=$target_alias + +# FIXME: To remove some day. +if test "x$host_alias" != x; then + if test "x$build_alias" = x; then + cross_compiling=maybe + echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. + If a cross compiler is detected then cross compile mode will be used." >&2 + elif test "x$build_alias" != "x$host_alias"; then + cross_compiling=yes + fi +fi + +ac_tool_prefix= +test -n "$host_alias" && ac_tool_prefix=$host_alias- + +test "$silent" = yes && exec 6>/dev/null + + +ac_pwd=`pwd` && test -n "$ac_pwd" && +ac_ls_di=`ls -di .` && +ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || + { echo "$as_me: error: Working directory cannot be determined" >&2 + { (exit 1); exit 1; }; } +test "X$ac_ls_di" = "X$ac_pwd_ls_di" || + { echo "$as_me: error: pwd does not report name of working directory" >&2 + { (exit 1); exit 1; }; } + + +# Find the source files, if location was not specified. +if test -z "$srcdir"; then + ac_srcdir_defaulted=yes + # Try the directory containing this script, then the parent directory. + ac_confdir=`$as_dirname -- "$0" || +$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$0" : 'X\(//\)[^/]' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X"$0" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + srcdir=$ac_confdir + if test ! -r "$srcdir/$ac_unique_file"; then + srcdir=.. + fi +else + ac_srcdir_defaulted=no +fi +if test ! -r "$srcdir/$ac_unique_file"; then + test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." + { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2 + { (exit 1); exit 1; }; } +fi +ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" +ac_abs_confdir=`( + cd "$srcdir" && test -r "./$ac_unique_file" || { echo "$as_me: error: $ac_msg" >&2 + { (exit 1); exit 1; }; } + pwd)` +# When building in place, set srcdir=. +if test "$ac_abs_confdir" = "$ac_pwd"; then + srcdir=. +fi +# Remove unnecessary trailing slashes from srcdir. +# Double slashes in file names in object file debugging info +# mess up M-x gdb in Emacs. +case $srcdir in +*/) srcdir=`expr "X$srcdir" : 'X\(.*[^/]\)' \| "X$srcdir" : 'X\(.*\)'`;; +esac +for ac_var in $ac_precious_vars; do + eval ac_env_${ac_var}_set=\${${ac_var}+set} + eval ac_env_${ac_var}_value=\$${ac_var} + eval ac_cv_env_${ac_var}_set=\${${ac_var}+set} + eval ac_cv_env_${ac_var}_value=\$${ac_var} +done + +# +# Report the --help message. +# +if test "$ac_init_help" = "long"; then + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. + cat <<_ACEOF +\`configure' configures this package to adapt to many kinds of systems. + +Usage: $0 [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + --help=recursive display the short help of all the included packages + -V, --version display version information and exit + -q, --quiet, --silent do not print \`checking...' messages + --cache-file=FILE cache test results in FILE [disabled] + -C, --config-cache alias for \`--cache-file=config.cache' + -n, --no-create do not create output files + --srcdir=DIR find the sources in DIR [configure dir or \`..'] + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX + [PREFIX] + +By default, \`make install' will install all the files in +\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify +an installation prefix other than \`$ac_default_prefix' using \`--prefix', +for instance \`--prefix=\$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [EPREFIX/bin] + --sbindir=DIR system admin executables [EPREFIX/sbin] + --libexecdir=DIR program executables [EPREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com] + --localstatedir=DIR modifiable single-machine data [PREFIX/var] + --libdir=DIR object code libraries [EPREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --oldincludedir=DIR C header files for non-gcc [/usr/include] + --datarootdir=DIR read-only arch.-independent data root [PREFIX/share] + --datadir=DIR read-only architecture-independent data [DATAROOTDIR] + --infodir=DIR info documentation [DATAROOTDIR/info] + --localedir=DIR locale-dependent data [DATAROOTDIR/locale] + --mandir=DIR man documentation [DATAROOTDIR/man] + --docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE] + --htmldir=DIR html documentation [DOCDIR] + --dvidir=DIR dvi documentation [DOCDIR] + --pdfdir=DIR pdf documentation [DOCDIR] + --psdir=DIR ps documentation [DOCDIR] +_ACEOF + + cat <<\_ACEOF +_ACEOF +fi + +if test -n "$ac_init_help"; then + + cat <<\_ACEOF + +Optional Features: + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --disable-largefile omit support for large files + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L if you have libraries in a + nonstandard directory + CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I if + you have headers in a nonstandard directory + CPP C preprocessor + +Use these variables to override the choices made by `configure' or to help +it to find libraries and programs with nonstandard names/locations. + +_ACEOF +ac_status=$? +fi + +if test "$ac_init_help" = "recursive"; then + # If there are subdirs, report their specific --help. + for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue + test -d "$ac_dir" || continue + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + cd "$ac_dir" || { ac_status=$?; continue; } + # Check for guested configure. + if test -f "$ac_srcdir/configure.gnu"; then + echo && + $SHELL "$ac_srcdir/configure.gnu" --help=recursive + elif test -f "$ac_srcdir/configure"; then + echo && + $SHELL "$ac_srcdir/configure" --help=recursive + else + echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + fi || ac_status=$? + cd "$ac_pwd" || { ac_status=$?; break; } + done +fi + +test -n "$ac_init_help" && exit $ac_status +if $ac_init_version; then + cat <<\_ACEOF +configure +generated by GNU Autoconf 2.60 + +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +This configure script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it. +_ACEOF + exit +fi +cat >config.log <<_ACEOF +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. + +It was created by $as_me, which was +generated by GNU Autoconf 2.60. Invocation command line was + + $ $0 $@ + +_ACEOF +exec 5>>config.log +{ +cat <<_ASUNAME +## --------- ## +## Platform. ## +## --------- ## + +hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown` + +/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown` +/usr/bin/hostinfo = `(/usr/bin/hostinfo) 2>/dev/null || echo unknown` +/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown` +/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown` + +_ASUNAME + +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + echo "PATH: $as_dir" +done +IFS=$as_save_IFS + +} >&5 + +cat >&5 <<_ACEOF + + +## ----------- ## +## Core tests. ## +## ----------- ## + +_ACEOF + + +# Keep a trace of the command line. +# Strip out --no-create and --no-recursion so they do not pile up. +# Strip out --silent because we don't want to record it for future runs. +# Also quote any args containing shell meta-characters. +# Make two passes to allow for proper duplicate-argument suppression. +ac_configure_args= +ac_configure_args0= +ac_configure_args1= +ac_must_keep_next=false +for ac_pass in 1 2 +do + for ac_arg + do + case $ac_arg in + -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil) + continue ;; + *\'*) + ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + case $ac_pass in + 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;; + 2) + ac_configure_args1="$ac_configure_args1 '$ac_arg'" + if test $ac_must_keep_next = true; then + ac_must_keep_next=false # Got value, back to normal. + else + case $ac_arg in + *=* | --config-cache | -C | -disable-* | --disable-* \ + | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \ + | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \ + | -with-* | --with-* | -without-* | --without-* | --x) + case "$ac_configure_args0 " in + "$ac_configure_args1"*" '$ac_arg' "* ) continue ;; + esac + ;; + -* ) ac_must_keep_next=true ;; + esac + fi + ac_configure_args="$ac_configure_args '$ac_arg'" + ;; + esac + done +done +$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; } +$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; } + +# When interrupted or exit'd, cleanup temporary files, and complete +# config.log. We remove comments because anyway the quotes in there +# would cause problems or look ugly. +# WARNING: Use '\'' to represent an apostrophe within the trap. +# WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. +trap 'exit_status=$? + # Save into config.log some information that might help in debugging. + { + echo + + cat <<\_ASBOX +## ---------------- ## +## Cache variables. ## +## ---------------- ## +_ASBOX + echo + # The following way of writing the cache mishandles newlines in values, +( + for ac_var in `(set) 2>&1 | sed -n '\''s/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'\''`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + (set) 2>&1 | + case $as_nl`(ac_space='\'' '\''; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + sed -n \ + "s/'\''/'\''\\\\'\'''\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\''\\2'\''/p" + ;; #( + *) + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) + echo + + cat <<\_ASBOX +## ----------------- ## +## Output variables. ## +## ----------------- ## +_ASBOX + echo + for ac_var in $ac_subst_vars + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + + if test -n "$ac_subst_files"; then + cat <<\_ASBOX +## ------------------- ## +## File substitutions. ## +## ------------------- ## +_ASBOX + echo + for ac_var in $ac_subst_files + do + eval ac_val=\$$ac_var + case $ac_val in + *\'\''*) ac_val=`echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + esac + echo "$ac_var='\''$ac_val'\''" + done | sort + echo + fi + + if test -s confdefs.h; then + cat <<\_ASBOX +## ----------- ## +## confdefs.h. ## +## ----------- ## +_ASBOX + echo + cat confdefs.h + echo + fi + test "$ac_signal" != 0 && + echo "$as_me: caught signal $ac_signal" + echo "$as_me: exit $exit_status" + } >&5 + rm -f core *.core core.conftest.* && + rm -f -r conftest* confdefs* conf$$* $ac_clean_files && + exit $exit_status +' 0 +for ac_signal in 1 2 13 15; do + trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal +done +ac_signal=0 + +# confdefs.h avoids OS command line length limits that DEFS can exceed. +rm -f -r conftest* confdefs.h + +# Predefined preprocessor variables. + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_NAME "$PACKAGE_NAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_TARNAME "$PACKAGE_TARNAME" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_VERSION "$PACKAGE_VERSION" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_STRING "$PACKAGE_STRING" +_ACEOF + + +cat >>confdefs.h <<_ACEOF +#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" +_ACEOF + + +# Let the site file select an alternate cache file if it wants to. +# Prefer explicitly selected file to automatically selected ones. +if test -n "$CONFIG_SITE"; then + set x "$CONFIG_SITE" +elif test "x$prefix" != xNONE; then + set x "$prefix/share/config.site" "$prefix/etc/config.site" +else + set x "$ac_default_prefix/share/config.site" \ + "$ac_default_prefix/etc/config.site" +fi +shift +for ac_site_file +do + if test -r "$ac_site_file"; then + { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5 +echo "$as_me: loading site script $ac_site_file" >&6;} + sed 's/^/| /' "$ac_site_file" >&5 + . "$ac_site_file" + fi +done + +if test -r "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special + # files actually), so we avoid doing that. + if test -f "$cache_file"; then + { echo "$as_me:$LINENO: loading cache $cache_file" >&5 +echo "$as_me: loading cache $cache_file" >&6;} + case $cache_file in + [\\/]* | ?:[\\/]* ) . "$cache_file";; + *) . "./$cache_file";; + esac + fi +else + { echo "$as_me:$LINENO: creating cache $cache_file" >&5 +echo "$as_me: creating cache $cache_file" >&6;} + >$cache_file +fi + +# Check that the precious variables saved in the cache have kept the same +# value. +ac_cache_corrupted=false +for ac_var in $ac_precious_vars; do + eval ac_old_set=\$ac_cv_env_${ac_var}_set + eval ac_new_set=\$ac_env_${ac_var}_set + eval ac_old_val=\$ac_cv_env_${ac_var}_value + eval ac_new_val=\$ac_env_${ac_var}_value + case $ac_old_set,$ac_new_set in + set,) + { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,set) + { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5 +echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + ac_cache_corrupted=: ;; + ,);; + *) + if test "x$ac_old_val" != "x$ac_new_val"; then + { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5 +echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { echo "$as_me:$LINENO: former value: $ac_old_val" >&5 +echo "$as_me: former value: $ac_old_val" >&2;} + { echo "$as_me:$LINENO: current value: $ac_new_val" >&5 +echo "$as_me: current value: $ac_new_val" >&2;} + ac_cache_corrupted=: + fi;; + esac + # Pass precious variables to config.status. + if test "$ac_new_set" = set; then + case $ac_new_val in + *\'*) ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *) ac_arg=$ac_var=$ac_new_val ;; + esac + case " $ac_configure_args " in + *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy. + *) ac_configure_args="$ac_configure_args '$ac_arg'" ;; + esac + fi +done +if $ac_cache_corrupted; then + { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5 +echo "$as_me: error: changes in the environment can compromise the build" >&2;} + { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5 +echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;} + { (exit 1); exit 1; }; } +fi + + + + + + + + + + + + + + + + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + + +ac_config_headers="$ac_config_headers config.h" + + + +cat >>confdefs.h <<\_ACEOF +#define _GNU_SOURCE 1 +_ACEOF + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&5 +echo "$as_me: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + +# Provide some information about the compiler. +echo "$as_me:$LINENO: checking for C compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (ac_try="$ac_compiler --version >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler --version >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -v >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -v >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -V >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -V >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files a.out a.exe b.out" +# Try to create an executable without -o first, disregard a.out. +# It will help us diagnose broken compilers, and finding out an intuition +# of exeext. +{ echo "$as_me:$LINENO: checking for C compiler default output file name" >&5 +echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6; } +ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` +# +# List of possible output files, starting from the most likely. +# The algorithm is not robust to junk in `.', hence go to wildcards (a.*) +# only as a last resort. b.out is created by i960 compilers. +ac_files='a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out' +# +# The IRIX 6 linker writes into existing files which may not be +# executable, retaining their permissions. Remove them first so a +# subsequent execution test works. +ac_rmfiles= +for ac_file in $ac_files +do + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;; + * ) ac_rmfiles="$ac_rmfiles $ac_file";; + esac +done +rm -f $ac_rmfiles + +if { (ac_try="$ac_link_default" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link_default") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. +# So ignore a value of `no', otherwise this would lead to `EXEEXT = no' +# in a Makefile. We should not override ac_cv_exeext if it was cached, +# so that the user can short-circuit this test for compilers unknown to +# Autoconf. +for ac_file in $ac_files +do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) + ;; + [ab].out ) + # We found the default executable, but exeext='' is most + # certainly right. + break;; + *.* ) + if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + then :; else + ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + fi + # We set ac_cv_exeext here because the later test for it is not + # safe: cross compilers may not add the suffix if given an `-o' + # argument, so we may need to know it at that point already. + # Even if this section looks crufty: it has the advantage of + # actually working. + break;; + * ) + break;; + esac +done +test "$ac_cv_exeext" = no && ac_cv_exeext= + +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: C compiler cannot create executables +See \`config.log' for more details." >&5 +echo "$as_me: error: C compiler cannot create executables +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } +fi + +ac_exeext=$ac_cv_exeext +{ echo "$as_me:$LINENO: result: $ac_file" >&5 +echo "${ECHO_T}$ac_file" >&6; } + +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ echo "$as_me:$LINENO: checking whether the C compiler works" >&5 +echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6; } +# FIXME: These cross compiler hacks should be removed for Autoconf 3.0 +# If not cross compiling, check that we can run a simple program. +if test "$cross_compiling" != yes; then + if { ac_try='./$ac_file' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { echo "$as_me:$LINENO: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run C compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + fi + fi +fi +{ echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + +rm -f a.out a.exe conftest$ac_cv_exeext b.out +ac_clean_files=$ac_clean_files_save +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ echo "$as_me:$LINENO: checking whether we are cross compiling" >&5 +echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6; } +{ echo "$as_me:$LINENO: result: $cross_compiling" >&5 +echo "${ECHO_T}$cross_compiling" >&6; } + +{ echo "$as_me:$LINENO: checking for suffix of executables" >&5 +echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6; } +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + # If both `conftest.exe' and `conftest' are `present' (well, observable) +# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will +# work properly (i.e., refer to `conftest.exe'), while it won't with +# `rm'. +for ac_file in conftest.exe conftest conftest.*; do + test -f "$ac_file" || continue + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf | *.o | *.obj ) ;; + *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` + break;; + * ) break;; + esac +done +else + { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest$ac_cv_exeext +{ echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5 +echo "${ECHO_T}$ac_cv_exeext" >&6; } + +rm -f conftest.$ac_ext +EXEEXT=$ac_cv_exeext +ac_exeext=$EXEEXT +{ echo "$as_me:$LINENO: checking for suffix of object files" >&5 +echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6; } +if test "${ac_cv_objext+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.o conftest.obj +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; then + for ac_file in conftest.o conftest.obj conftest.*; do + test -f "$ac_file" || continue; + case $ac_file in + *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.map | *.inf ) ;; + *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'` + break;; + esac +done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute suffix of object files: cannot compile +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +rm -f conftest.$ac_cv_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_objext" >&5 +echo "${ECHO_T}$ac_cv_objext" >&6; } +OBJEXT=$ac_cv_objext +ac_objext=$OBJEXT +{ echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6; } +if test "${ac_cv_c_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_compiler_gnu=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_compiler_gnu=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6; } +GCC=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 +echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6; } +if test "${ac_cv_prog_cc_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_prog_cc_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + CFLAGS="" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_prog_cc_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ echo "$as_me:$LINENO: checking for $CC option to accept ISO C89" >&5 +echo $ECHO_N "checking for $CC option to accept ISO C89... $ECHO_C" >&6; } +if test "${ac_cv_prog_cc_c89+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_prog_cc_c89=$ac_arg +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { echo "$as_me:$LINENO: result: none needed" >&5 +echo "${ECHO_T}none needed" >&6; } ;; + xno) + { echo "$as_me:$LINENO: result: unsupported" >&5 +echo "${ECHO_T}unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { echo "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_c89" >&6; } ;; +esac + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +# Check whether --enable-largefile was given. +if test "${enable_largefile+set}" = set; then + enableval=$enable_largefile; +fi + +if test "$enable_largefile" != no; then + + { echo "$as_me:$LINENO: checking for special C compiler options needed for large files" >&5 +echo $ECHO_N "checking for special C compiler options needed for large files... $ECHO_C" >&6; } +if test "${ac_cv_sys_largefile_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_sys_largefile_CC=no + if test "$GCC" != yes; then + ac_save_CC=$CC + while :; do + # IRIX 6.2 and later do not support large files by default, + # so use the C compiler's -n32 option if that helps. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF + rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext + CC="$CC -n32" + rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sys_largefile_CC=' -n32'; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext + break + done + CC=$ac_save_CC + rm -f conftest.$ac_ext + fi +fi +{ echo "$as_me:$LINENO: result: $ac_cv_sys_largefile_CC" >&5 +echo "${ECHO_T}$ac_cv_sys_largefile_CC" >&6; } + if test "$ac_cv_sys_largefile_CC" != no; then + CC=$CC$ac_cv_sys_largefile_CC + fi + + { echo "$as_me:$LINENO: checking for _FILE_OFFSET_BITS value needed for large files" >&5 +echo $ECHO_N "checking for _FILE_OFFSET_BITS value needed for large files... $ECHO_C" >&6; } +if test "${ac_cv_sys_file_offset_bits+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + while :; do + ac_cv_sys_file_offset_bits=no + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#define _FILE_OFFSET_BITS 64 +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sys_file_offset_bits=64; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + break +done +fi +{ echo "$as_me:$LINENO: result: $ac_cv_sys_file_offset_bits" >&5 +echo "${ECHO_T}$ac_cv_sys_file_offset_bits" >&6; } +if test "$ac_cv_sys_file_offset_bits" != no; then + +cat >>confdefs.h <<_ACEOF +#define _FILE_OFFSET_BITS $ac_cv_sys_file_offset_bits +_ACEOF + +fi +rm -f conftest* + { echo "$as_me:$LINENO: checking for _LARGE_FILES value needed for large files" >&5 +echo $ECHO_N "checking for _LARGE_FILES value needed for large files... $ECHO_C" >&6; } +if test "${ac_cv_sys_large_files+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + while :; do + ac_cv_sys_large_files=no + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#define _LARGE_FILES 1 +#include + /* Check that off_t can represent 2**63 - 1 correctly. + We can't simply define LARGE_OFF_T to be 9223372036854775807, + since some C++ compilers masquerading as C compilers + incorrectly reject 9223372036854775807. */ +#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) + int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 + && LARGE_OFF_T % 2147483647 == 1) + ? 1 : -1]; +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sys_large_files=1; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + break +done +fi +{ echo "$as_me:$LINENO: result: $ac_cv_sys_large_files" >&5 +echo "${ECHO_T}$ac_cv_sys_large_files" >&6; } +if test "$ac_cv_sys_large_files" != no; then + +cat >>confdefs.h <<_ACEOF +#define _LARGE_FILES $ac_cv_sys_large_files +_ACEOF + +fi +rm -f conftest* +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. +set dummy ${ac_tool_prefix}gcc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="gcc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. +set dummy ${ac_tool_prefix}cc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="${ac_tool_prefix}cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + fi +fi +if test -z "$CC"; then + # Extract the first word of "cc", so it can be a program name with args. +set dummy cc; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + ac_prog_rejected=no +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + ac_prog_rejected=yes + continue + fi + ac_cv_prog_CC="cc" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +if test $ac_prog_rejected = yes; then + # We found a bogon in the path, so make sure we never use it. + set dummy $ac_cv_prog_CC + shift + if test $# != 0; then + # We chose a different compiler from the bogus one. + # However, it has the same basename, so the bogon will be chosen + # first if we set CC to just the basename; use the full file name. + shift + ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + fi +fi +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + for ac_prog in cl.exe + do + # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. +set dummy $ac_tool_prefix$ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_CC="$ac_tool_prefix$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { echo "$as_me:$LINENO: result: $CC" >&5 +echo "${ECHO_T}$CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$CC" && break + done +fi +if test -z "$CC"; then + ac_ct_CC=$CC + for ac_prog in cl.exe +do + # Extract the first word of "$ac_prog", so it can be a program name with args. +set dummy $ac_prog; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_CC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_CC="$ac_prog" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { echo "$as_me:$LINENO: result: $ac_ct_CC" >&5 +echo "${ECHO_T}$ac_ct_CC" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + + test -n "$ac_ct_CC" && break +done + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +fi + +fi + + +test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&5 +echo "$as_me: error: no acceptable C compiler found in \$PATH +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } + +# Provide some information about the compiler. +echo "$as_me:$LINENO: checking for C compiler version" >&5 +ac_compiler=`set X $ac_compile; echo $2` +{ (ac_try="$ac_compiler --version >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler --version >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -v >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -v >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } +{ (ac_try="$ac_compiler -V >&5" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compiler -V >&5") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } + +{ echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5 +echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6; } +if test "${ac_cv_c_compiler_gnu+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +#ifndef __GNUC__ + choke me +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_compiler_gnu=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_compiler_gnu=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_cv_c_compiler_gnu=$ac_compiler_gnu + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5 +echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6; } +GCC=`test $ac_compiler_gnu = yes && echo yes` +ac_test_CFLAGS=${CFLAGS+set} +ac_save_CFLAGS=$CFLAGS +{ echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5 +echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6; } +if test "${ac_cv_prog_cc_g+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_save_c_werror_flag=$ac_c_werror_flag + ac_c_werror_flag=yes + ac_cv_prog_cc_g=no + CFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_prog_cc_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + CFLAGS="" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_c_werror_flag=$ac_save_c_werror_flag + CFLAGS="-g" + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_prog_cc_g=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + ac_c_werror_flag=$ac_save_c_werror_flag +fi +{ echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_g" >&6; } +if test "$ac_test_CFLAGS" = set; then + CFLAGS=$ac_save_CFLAGS +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-g" + fi +else + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi +fi +{ echo "$as_me:$LINENO: checking for $CC option to accept ISO C89" >&5 +echo $ECHO_N "checking for $CC option to accept ISO C89... $ECHO_C" >&6; } +if test "${ac_cv_prog_cc_c89+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include +/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ +struct buf { int x; }; +FILE * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (p, i) + char **p; + int i; +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not '\xHH' hex character constants. + These don't provoke an error unfortunately, instead are silently treated + as 'x'. The following induces an error, until -std is added to get + proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an + array size at least. It's necessary to write '\x00'==0 to get something + that's true only with -std. */ +int osf4_cc_array ['\x00' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) 'x' +int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); +int argc; +char **argv; +int +main () +{ +return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; + ; + return 0; +} +_ACEOF +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ + -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +do + CC="$ac_save_CC $ac_arg" + rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_prog_cc_c89=$ac_arg +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext + test "x$ac_cv_prog_cc_c89" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC + +fi +# AC_CACHE_VAL +case "x$ac_cv_prog_cc_c89" in + x) + { echo "$as_me:$LINENO: result: none needed" >&5 +echo "${ECHO_T}none needed" >&6; } ;; + xno) + { echo "$as_me:$LINENO: result: unsupported" >&5 +echo "${ECHO_T}unsupported" >&6; } ;; + *) + CC="$CC $ac_cv_prog_cc_c89" + { echo "$as_me:$LINENO: result: $ac_cv_prog_cc_c89" >&5 +echo "${ECHO_T}$ac_cv_prog_cc_c89" >&6; } ;; +esac + + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_RANLIB+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { echo "$as_me:$LINENO: result: $RANLIB" >&5 +echo "${ECHO_T}$RANLIB" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; } +if test "${ac_cv_prog_ac_ct_RANLIB+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { echo "$as_me:$LINENO: result: $ac_ct_RANLIB" >&5 +echo "${ECHO_T}$ac_ct_RANLIB" >&6; } +else + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ echo "$as_me:$LINENO: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&5 +echo "$as_me: WARNING: In the future, Autoconf will not detect cross-tools +whose name does not start with the host triplet. If you think this +configuration is useful to you, please write to autoconf@gnu.org." >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + +ac_aux_dir= +for ac_dir in "$srcdir" "$srcdir/.." "$srcdir/../.."; do + if test -f "$ac_dir/install-sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f "$ac_dir/install.sh"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + elif test -f "$ac_dir/shtool"; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/shtool install -c" + break + fi +done +if test -z "$ac_aux_dir"; then + { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&5 +echo "$as_me: error: cannot find install-sh or install.sh in \"$srcdir\" \"$srcdir/..\" \"$srcdir/../..\"" >&2;} + { (exit 1); exit 1; }; } +fi + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. +ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. +ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. + + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AmigaOS /C/install, which installs bootblocks on floppy discs +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# OS/2's system install, which has a completely different semantic +# ./install, which can be erroneously created by make from ./install.sh. +{ echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5 +echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6; } +if test -z "$INSTALL"; then +if test "${ac_cv_path_install+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + # Account for people who put trailing slashes in PATH elements. +case $as_dir/ in + ./ | .// | /cC/* | \ + /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ + ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \ + /usr/ucb/* ) ;; + *) + # OSF1 and SCO ODT 3.0 have their own names for install. + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_executable_p "$as_dir/$ac_prog$ac_exec_ext"; }; then + if test $ac_prog = install && + grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # AIX install. It has an incompatible calling convention. + : + elif test $ac_prog = install && + grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + # program-specific install script used by HP pwplus--don't use. + : + else + ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + break 3 + fi + fi + done + done + ;; +esac +done +IFS=$as_save_IFS + + +fi + if test "${ac_cv_path_install+set}" = set; then + INSTALL=$ac_cv_path_install + else + # As a last resort, use the slow shell script. Don't cache a + # value for INSTALL within a source directory, because that will + # break other packages using the cache if that directory is + # removed, or if the value is a relative name. + INSTALL=$ac_install_sh + fi +fi +{ echo "$as_me:$LINENO: result: $INSTALL" >&5 +echo "${ECHO_T}$INSTALL" >&6; } + +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. +# It thinks the first close brace ends the variable substitution. +test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' + +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' + +test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu +{ echo "$as_me:$LINENO: checking how to run the C preprocessor" >&5 +echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6; } +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi +if test -z "$CPP"; then + if test "${ac_cv_prog_CPP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # Double quotes because CPP needs to be expanded + for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" + do + ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + break +fi + + done + ac_cv_prog_CPP=$CPP + +fi + CPP=$ac_cv_prog_CPP +else + ac_cv_prog_CPP=$CPP +fi +{ echo "$as_me:$LINENO: result: $CPP" >&5 +echo "${ECHO_T}$CPP" >&6; } +ac_preproc_ok=false +for ac_c_preproc_warn_flag in '' yes +do + # Use a header file that comes with gcc, so configuring glibc + # with a fresh cross-compiler works. + # Prefer to if __STDC__ is defined, since + # exists even on freestanding compilers. + # On the NeXT, cc -E runs the code through the compiler's parser, + # not just through cpp. "Syntax error" is here to catch this case. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifdef __STDC__ +# include +#else +# include +#endif + Syntax error +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + : +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Broken: fails on valid input. +continue +fi + +rm -f conftest.err conftest.$ac_ext + + # OK, works on sane cases. Now check whether nonexistent headers + # can be detected and how. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + # Broken: success on invalid input. +continue +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + # Passes both tests. +ac_preproc_ok=: +break +fi + +rm -f conftest.err conftest.$ac_ext + +done +# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. +rm -f conftest.err conftest.$ac_ext +if $ac_preproc_ok; then + : +else + { { echo "$as_me:$LINENO: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&5 +echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +fi + +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + +{ echo "$as_me:$LINENO: checking for grep that handles long lines and -e" >&5 +echo $ECHO_N "checking for grep that handles long lines and -e... $ECHO_C" >&6; } +if test "${ac_cv_path_GREP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + # Extract the first word of "grep ggrep" to use in msg output +if test -z "$GREP"; then +set dummy grep ggrep; ac_prog_name=$2 +if test "${ac_cv_path_GREP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_path_GREP_found=false +# Loop through the user's path and test for each of PROGNAME-LIST +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in grep ggrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_GREP" && $as_executable_p "$ac_path_GREP"; } || continue + # Check for GNU ac_path_GREP and select it if it is found. + # Check for GNU $ac_path_GREP +case `"$ac_path_GREP" --version 2>&1` in +*GNU*) + ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; +*) + ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + echo 'GREP' >> "conftest.nl" + "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + ac_count=`expr $ac_count + 1` + if test $ac_count -gt ${ac_path_GREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_GREP="$ac_path_GREP" + ac_path_GREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + + $ac_path_GREP_found && break 3 + done +done + +done +IFS=$as_save_IFS + + +fi + +GREP="$ac_cv_path_GREP" +if test -z "$GREP"; then + { { echo "$as_me:$LINENO: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5 +echo "$as_me: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;} + { (exit 1); exit 1; }; } +fi + +else + ac_cv_path_GREP=$GREP +fi + + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_path_GREP" >&5 +echo "${ECHO_T}$ac_cv_path_GREP" >&6; } + GREP="$ac_cv_path_GREP" + + +{ echo "$as_me:$LINENO: checking for egrep" >&5 +echo $ECHO_N "checking for egrep... $ECHO_C" >&6; } +if test "${ac_cv_path_EGREP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 + then ac_cv_path_EGREP="$GREP -E" + else + # Extract the first word of "egrep" to use in msg output +if test -z "$EGREP"; then +set dummy egrep; ac_prog_name=$2 +if test "${ac_cv_path_EGREP+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_path_EGREP_found=false +# Loop through the user's path and test for each of PROGNAME-LIST +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_prog in egrep; do + for ac_exec_ext in '' $ac_executable_extensions; do + ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + { test -f "$ac_path_EGREP" && $as_executable_p "$ac_path_EGREP"; } || continue + # Check for GNU ac_path_EGREP and select it if it is found. + # Check for GNU $ac_path_EGREP +case `"$ac_path_EGREP" --version 2>&1` in +*GNU*) + ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; +*) + ac_count=0 + echo $ECHO_N "0123456789$ECHO_C" >"conftest.in" + while : + do + cat "conftest.in" "conftest.in" >"conftest.tmp" + mv "conftest.tmp" "conftest.in" + cp "conftest.in" "conftest.nl" + echo 'EGREP' >> "conftest.nl" + "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break + diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break + ac_count=`expr $ac_count + 1` + if test $ac_count -gt ${ac_path_EGREP_max-0}; then + # Best one so far, save it but keep looking for a better one + ac_cv_path_EGREP="$ac_path_EGREP" + ac_path_EGREP_max=$ac_count + fi + # 10*(2^10) chars as input seems more than enough + test $ac_count -gt 10 && break + done + rm -f conftest.in conftest.tmp conftest.nl conftest.out;; +esac + + + $ac_path_EGREP_found && break 3 + done +done + +done +IFS=$as_save_IFS + + +fi + +EGREP="$ac_cv_path_EGREP" +if test -z "$EGREP"; then + { { echo "$as_me:$LINENO: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&5 +echo "$as_me: error: no acceptable $ac_prog_name could be found in $PATH$PATH_SEPARATOR/usr/xpg4/bin" >&2;} + { (exit 1); exit 1; }; } +fi + +else + ac_cv_path_EGREP=$EGREP +fi + + + fi +fi +{ echo "$as_me:$LINENO: result: $ac_cv_path_EGREP" >&5 +echo "${ECHO_T}$ac_cv_path_EGREP" >&6; } + EGREP="$ac_cv_path_EGREP" + + +{ echo "$as_me:$LINENO: checking for ANSI C header files" >&5 +echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6; } +if test "${ac_cv_header_stdc+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#include +#include + +int +main () +{ + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_header_stdc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_header_stdc=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +if test $ac_cv_header_stdc = yes; then + # SunOS 4.x string.h does not declare mem*, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "memchr" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "free" >/dev/null 2>&1; then + : +else + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. + if test "$cross_compiling" = yes; then + : +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include +#if ((' ' & 0x0FF) == 0x020) +# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') +# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) +#else +# define ISLOWER(c) \ + (('a' <= (c) && (c) <= 'i') \ + || ('j' <= (c) && (c) <= 'r') \ + || ('s' <= (c) && (c) <= 'z')) +# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) +#endif + +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) +int +main () +{ + int i; + for (i = 0; i < 256; i++) + if (XOR (islower (i), ISLOWER (i)) + || toupper (i) != TOUPPER (i)) + return 2; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + : +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +ac_cv_header_stdc=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + + +fi +fi +{ echo "$as_me:$LINENO: result: $ac_cv_header_stdc" >&5 +echo "${ECHO_T}$ac_cv_header_stdc" >&6; } +if test $ac_cv_header_stdc = yes; then + +cat >>confdefs.h <<\_ACEOF +#define STDC_HEADERS 1 +_ACEOF + +fi + + +# On IRIX 5.3, sys/types and inttypes.h are conflicting. + + + + + + + + + +for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ + inttypes.h stdint.h unistd.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +{ echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; } +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_Header=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + eval "$as_ac_Header=no" +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +ac_res=`eval echo '${'$as_ac_Header'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +{ echo "$as_me:$LINENO: checking for short" >&5 +echo $ECHO_N "checking for short... $ECHO_C" >&6; } +if test "${ac_cv_type_short+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +typedef short ac__type_new_; +int +main () +{ +if ((ac__type_new_ *) 0) + return 0; +if (sizeof (ac__type_new_)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_short=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_type_short=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_type_short" >&5 +echo "${ECHO_T}$ac_cv_type_short" >&6; } + +{ echo "$as_me:$LINENO: checking size of short" >&5 +echo $ECHO_N "checking size of short... $ECHO_C" >&6; } +if test "${ac_cv_sizeof_short+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$ac_cv_type_short" = yes; then + # The cast to long int works around a bug in the HP C Compiler + # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects + # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. + # This bug is HP SR number 8606223364. + if test "$cross_compiling" = yes; then + # Depending upon the size, compute the lo and hi bounds. +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef short ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=0 ac_mid=0 + while :; do + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef short ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo=`expr $ac_mid + 1` + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid + 1` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef short ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) < 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=-1 ac_mid=-1 + while :; do + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef short ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_hi=`expr '(' $ac_mid ')' - 1` + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo= ac_hi= +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef short ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo=`expr '(' $ac_mid ')' + 1` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +done +case $ac_lo in +?*) ac_cv_sizeof_short=$ac_lo;; +'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (short) +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (short) +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } ;; +esac +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef short ac__type_sizeof_; +static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); } +static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); } +#include +#include +int +main () +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + return 1; + if (((long int) (sizeof (ac__type_sizeof_))) < 0) + { + long int i = longval (); + if (i != ((long int) (sizeof (ac__type_sizeof_)))) + return 1; + fprintf (f, "%ld\n", i); + } + else + { + unsigned long int i = ulongval (); + if (i != ((long int) (sizeof (ac__type_sizeof_)))) + return 1; + fprintf (f, "%lu\n", i); + } + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sizeof_short=`cat conftest.val` +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +{ { echo "$as_me:$LINENO: error: cannot compute sizeof (short) +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (short) +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +rm -f conftest.val +else + ac_cv_sizeof_short=0 +fi +fi +{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_short" >&5 +echo "${ECHO_T}$ac_cv_sizeof_short" >&6; } +cat >>confdefs.h <<_ACEOF +#define SIZEOF_SHORT $ac_cv_sizeof_short +_ACEOF + + +{ echo "$as_me:$LINENO: checking for int" >&5 +echo $ECHO_N "checking for int... $ECHO_C" >&6; } +if test "${ac_cv_type_int+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +typedef int ac__type_new_; +int +main () +{ +if ((ac__type_new_ *) 0) + return 0; +if (sizeof (ac__type_new_)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_int=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_type_int=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_type_int" >&5 +echo "${ECHO_T}$ac_cv_type_int" >&6; } + +{ echo "$as_me:$LINENO: checking size of int" >&5 +echo $ECHO_N "checking size of int... $ECHO_C" >&6; } +if test "${ac_cv_sizeof_int+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$ac_cv_type_int" = yes; then + # The cast to long int works around a bug in the HP C Compiler + # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects + # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. + # This bug is HP SR number 8606223364. + if test "$cross_compiling" = yes; then + # Depending upon the size, compute the lo and hi bounds. +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef int ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=0 ac_mid=0 + while :; do + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef int ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo=`expr $ac_mid + 1` + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid + 1` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef int ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) < 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=-1 ac_mid=-1 + while :; do + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef int ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_hi=`expr '(' $ac_mid ')' - 1` + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo= ac_hi= +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef int ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo=`expr '(' $ac_mid ')' + 1` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +done +case $ac_lo in +?*) ac_cv_sizeof_int=$ac_lo;; +'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (int) +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (int) +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } ;; +esac +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef int ac__type_sizeof_; +static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); } +static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); } +#include +#include +int +main () +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + return 1; + if (((long int) (sizeof (ac__type_sizeof_))) < 0) + { + long int i = longval (); + if (i != ((long int) (sizeof (ac__type_sizeof_)))) + return 1; + fprintf (f, "%ld\n", i); + } + else + { + unsigned long int i = ulongval (); + if (i != ((long int) (sizeof (ac__type_sizeof_)))) + return 1; + fprintf (f, "%lu\n", i); + } + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sizeof_int=`cat conftest.val` +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +{ { echo "$as_me:$LINENO: error: cannot compute sizeof (int) +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (int) +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +rm -f conftest.val +else + ac_cv_sizeof_int=0 +fi +fi +{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_int" >&5 +echo "${ECHO_T}$ac_cv_sizeof_int" >&6; } +cat >>confdefs.h <<_ACEOF +#define SIZEOF_INT $ac_cv_sizeof_int +_ACEOF + + +{ echo "$as_me:$LINENO: checking for long" >&5 +echo $ECHO_N "checking for long... $ECHO_C" >&6; } +if test "${ac_cv_type_long+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +typedef long ac__type_new_; +int +main () +{ +if ((ac__type_new_ *) 0) + return 0; +if (sizeof (ac__type_new_)) + return 0; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_type_long=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_type_long=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_type_long" >&5 +echo "${ECHO_T}$ac_cv_type_long" >&6; } + +{ echo "$as_me:$LINENO: checking size of long" >&5 +echo $ECHO_N "checking size of long... $ECHO_C" >&6; } +if test "${ac_cv_sizeof_long+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test "$ac_cv_type_long" = yes; then + # The cast to long int works around a bug in the HP C Compiler + # version HP92453-01 B.11.11.23709.GP, which incorrectly rejects + # declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. + # This bug is HP SR number 8606223364. + if test "$cross_compiling" = yes; then + # Depending upon the size, compute the lo and hi bounds. +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=0 ac_mid=0 + while :; do + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo=`expr $ac_mid + 1` + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid + 1` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) < 0)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=-1 ac_mid=-1 + while :; do + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) >= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_lo=$ac_mid; break +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_hi=`expr '(' $ac_mid ')' - 1` + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + ac_mid=`expr 2 '*' $ac_mid` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + done +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo= ac_hi= +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + ac_mid=`expr '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo` + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long ac__type_sizeof_; +int +main () +{ +static int test_array [1 - 2 * !(((long int) (sizeof (ac__type_sizeof_))) <= $ac_mid)]; +test_array [0] = 0 + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_hi=$ac_mid +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_lo=`expr '(' $ac_mid ')' + 1` +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +done +case $ac_lo in +?*) ac_cv_sizeof_long=$ac_lo;; +'') { { echo "$as_me:$LINENO: error: cannot compute sizeof (long) +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (long) +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } ;; +esac +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default + typedef long ac__type_sizeof_; +static long int longval () { return (long int) (sizeof (ac__type_sizeof_)); } +static unsigned long int ulongval () { return (long int) (sizeof (ac__type_sizeof_)); } +#include +#include +int +main () +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + return 1; + if (((long int) (sizeof (ac__type_sizeof_))) < 0) + { + long int i = longval (); + if (i != ((long int) (sizeof (ac__type_sizeof_)))) + return 1; + fprintf (f, "%ld\n", i); + } + else + { + unsigned long int i = ulongval (); + if (i != ((long int) (sizeof (ac__type_sizeof_)))) + return 1; + fprintf (f, "%lu\n", i); + } + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_sizeof_long=`cat conftest.val` +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +{ { echo "$as_me:$LINENO: error: cannot compute sizeof (long) +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot compute sizeof (long) +See \`config.log' for more details." >&2;} + { (exit 77); exit 77; }; } +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi +rm -f conftest.val +else + ac_cv_sizeof_long=0 +fi +fi +{ echo "$as_me:$LINENO: result: $ac_cv_sizeof_long" >&5 +echo "${ECHO_T}$ac_cv_sizeof_long" >&6; } +cat >>confdefs.h <<_ACEOF +#define SIZEOF_LONG $ac_cv_sizeof_long +_ACEOF + + + +{ echo "$as_me:$LINENO: checking for an ANSI C-conforming const" >&5 +echo $ECHO_N "checking for an ANSI C-conforming const... $ECHO_C" >&6; } +if test "${ac_cv_c_const+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +int +main () +{ +/* FIXME: Include the comments suggested by Paul. */ +#ifndef __cplusplus + /* Ultrix mips cc rejects this. */ + typedef int charset[2]; + const charset x; + /* SunOS 4.1.1 cc rejects this. */ + char const *const *ccp; + char **p; + /* NEC SVR4.0.2 mips cc rejects this. */ + struct point {int x, y;}; + static struct point const zero = {0,0}; + /* AIX XL C 1.02.0.0 rejects this. + It does not let you subtract one const X* pointer from another in + an arm of an if-expression whose if-part is not a constant + expression */ + const char *g = "string"; + ccp = &g + (g ? g-g : 0); + /* HPUX 7.0 cc rejects these. */ + ++ccp; + p = (char**) ccp; + ccp = (char const *const *) p; + { /* SCO 3.2v4 cc rejects this. */ + char *t; + char const *s = 0 ? (char *) 0 : (char const *) 0; + + *t++ = 0; + if (s) return 0; + } + { /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ + int x[] = {25, 17}; + const int *foo = &x[0]; + ++foo; + } + { /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ + typedef const int *iptr; + iptr p = 0; + ++p; + } + { /* AIX XL C 1.02.0.0 rejects this saying + "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ + struct s { int j; const int *ap[3]; }; + struct s *b; b->j = 5; + } + { /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ + const int foo = 10; + if (!foo) return 0; + } + return !x[0] && !zero.x; +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_c_const=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_c_const=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ echo "$as_me:$LINENO: result: $ac_cv_c_const" >&5 +echo "${ECHO_T}$ac_cv_c_const" >&6; } +if test $ac_cv_c_const = no; then + +cat >>confdefs.h <<\_ACEOF +#define const +_ACEOF + +fi + +{ echo "$as_me:$LINENO: checking for inline" >&5 +echo $ECHO_N "checking for inline... $ECHO_C" >&6; } +if test "${ac_cv_c_inline+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + ac_cv_c_inline=no +for ac_kw in inline __inline__ __inline; do + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#ifndef __cplusplus +typedef int foo_t; +static $ac_kw foo_t static_foo () {return 0; } +$ac_kw foo_t foo () {return 0; } +#endif + +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_c_inline=$ac_kw +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + test "$ac_cv_c_inline" != no && break +done + +fi +{ echo "$as_me:$LINENO: result: $ac_cv_c_inline" >&5 +echo "${ECHO_T}$ac_cv_c_inline" >&6; } + + +case $ac_cv_c_inline in + inline | yes) ;; + *) + case $ac_cv_c_inline in + no) ac_val=;; + *) ac_val=$ac_cv_c_inline;; + esac + cat >>confdefs.h <<_ACEOF +#ifndef __cplusplus +#define inline $ac_val +#endif +_ACEOF + ;; +esac + + +for ac_header in getopt.h +do +as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + { echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; } +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +fi +ac_res=`eval echo '${'$as_ac_Header'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +else + # Is the header compilable? +{ echo "$as_me:$LINENO: checking $ac_header usability" >&5 +echo $ECHO_N "checking $ac_header usability... $ECHO_C" >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include <$ac_header> +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_header_compiler=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_compiler=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +echo "${ECHO_T}$ac_header_compiler" >&6; } + +# Is the header present? +{ echo "$as_me:$LINENO: checking $ac_header presence" >&5 +echo $ECHO_N "checking $ac_header presence... $ECHO_C" >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include <$ac_header> +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null; then + if test -s conftest.err; then + ac_cpp_err=$ac_c_preproc_warn_flag + ac_cpp_err=$ac_cpp_err$ac_c_werror_flag + else + ac_cpp_err= + fi +else + ac_cpp_err=yes +fi +if test -z "$ac_cpp_err"; then + ac_header_preproc=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi + +rm -f conftest.err conftest.$ac_ext +{ echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +echo "${ECHO_T}$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5 +echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5 +echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5 +echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5 +echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5 +echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5 +echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;} + { echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5 +echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;} + + ;; +esac +{ echo "$as_me:$LINENO: checking for $ac_header" >&5 +echo $ECHO_N "checking for $ac_header... $ECHO_C" >&6; } +if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + eval "$as_ac_Header=\$ac_header_preproc" +fi +ac_res=`eval echo '${'$as_ac_Header'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } + +fi +if test `eval echo '${'$as_ac_Header'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_header" | $as_tr_cpp` 1 +_ACEOF + +fi + +done + + +for ac_func in getopt_long +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +{ echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; } +if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$ac_func || defined __stub___$ac_func +choke me +#endif + +int +main () +{ +return $ac_func (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + eval "$as_ac_var=no" +fi + +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +ac_res=`eval echo '${'$as_ac_var'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + +if test "$GCC" = yes; then + CFLAGS="$CFLAGS -O3 -funroll-all-loops" +else + { echo "$as_me:$LINENO: result: no gcc" >&5 +echo "${ECHO_T}no gcc" >&6; } +fi + +ac_config_files="$ac_config_files Makefile" + +cat >confcache <<\_ACEOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs, see configure's option --config-cache. +# It is not useful on other systems. If it contains results you don't +# want to keep, you may remove or edit it. +# +# config.status only pays attention to the cache file if you give it +# the --recheck option to rerun configure. +# +# `ac_cv_env_foo' variables (set or unset) will be overridden when +# loading this file, other *unset* `ac_cv_foo' will be assigned the +# following values. + +_ACEOF + +# The following way of writing the cache mishandles newlines in values, +# but we know of no workaround that is simple, portable, and efficient. +# So, we kill variables containing newlines. +# Ultrix sh set writes to stderr and can't be redirected directly, +# and sets the high bit in the cache file unless we assign to the vars. +( + for ac_var in `(set) 2>&1 | sed -n 's/^\([a-zA-Z_][a-zA-Z0-9_]*\)=.*/\1/p'`; do + eval ac_val=\$$ac_var + case $ac_val in #( + *${as_nl}*) + case $ac_var in #( + *_cv_*) { echo "$as_me:$LINENO: WARNING: Cache variable $ac_var contains a newline." >&5 +echo "$as_me: WARNING: Cache variable $ac_var contains a newline." >&2;} ;; + esac + case $ac_var in #( + _ | IFS | as_nl) ;; #( + *) $as_unset $ac_var ;; + esac ;; + esac + done + + (set) 2>&1 | + case $as_nl`(ac_space=' '; set) 2>&1` in #( + *${as_nl}ac_space=\ *) + # `set' does not quote correctly, so add quotes (double-quote + # substitution turns \\\\ into \\, and sed turns \\ into \). + sed -n \ + "s/'/'\\\\''/g; + s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p" + ;; #( + *) + # `set' quotes correctly as required by POSIX, so do not add quotes. + sed -n "/^[_$as_cr_alnum]*_cv_[_$as_cr_alnum]*=/p" + ;; + esac | + sort +) | + sed ' + /^ac_cv_env_/b end + t clear + :clear + s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + t end + s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ + :end' >>confcache +if diff "$cache_file" confcache >/dev/null 2>&1; then :; else + if test -w "$cache_file"; then + test "x$cache_file" != "x/dev/null" && + { echo "$as_me:$LINENO: updating cache $cache_file" >&5 +echo "$as_me: updating cache $cache_file" >&6;} + cat confcache >$cache_file + else + { echo "$as_me:$LINENO: not updating unwritable cache $cache_file" >&5 +echo "$as_me: not updating unwritable cache $cache_file" >&6;} + fi +fi +rm -f confcache + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + +DEFS=-DHAVE_CONFIG_H + +ac_libobjs= +ac_ltlibobjs= +for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue + # 1. Remove the extension, and $U if already installed. + ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' + ac_i=`echo "$ac_i" | sed "$ac_script"` + # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR + # will be set to the directory where LIBOBJS objects are built. + ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext" + ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo' +done +LIBOBJS=$ac_libobjs + +LTLIBOBJS=$ac_ltlibobjs + + + +: ${CONFIG_STATUS=./config.status} +ac_clean_files_save=$ac_clean_files +ac_clean_files="$ac_clean_files $CONFIG_STATUS" +{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5 +echo "$as_me: creating $CONFIG_STATUS" >&6;} +cat >$CONFIG_STATUS <<_ACEOF +#! $SHELL +# Generated by $as_me. +# Run this file to recreate the current configuration. +# Compiler output produced by configure, useful for debugging +# configure, is in config.log if it exists. + +debug=false +ac_cs_recheck=false +ac_cs_silent=false +SHELL=\${CONFIG_SHELL-$SHELL} +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +## --------------------- ## +## M4sh Initialization. ## +## --------------------- ## + +# Be Bourne compatible +if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then + emulate sh + NULLCMD=: + # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which + # is contrary to our usage. Disable this feature. + alias -g '${1+"$@"}'='"$@"' + setopt NO_GLOB_SUBST +else + case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac +fi +BIN_SH=xpg4; export BIN_SH # for Tru64 +DUALCASE=1; export DUALCASE # for MKS sh + + +# PATH needs CR +# Avoid depending upon Character Ranges. +as_cr_letters='abcdefghijklmnopqrstuvwxyz' +as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' +as_cr_Letters=$as_cr_letters$as_cr_LETTERS +as_cr_digits='0123456789' +as_cr_alnum=$as_cr_Letters$as_cr_digits + +# The user is always right. +if test "${PATH_SEPARATOR+set}" != set; then + echo "#! /bin/sh" >conf$$.sh + echo "exit 0" >>conf$$.sh + chmod +x conf$$.sh + if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then + PATH_SEPARATOR=';' + else + PATH_SEPARATOR=: + fi + rm -f conf$$.sh +fi + +# Support unset when possible. +if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then + as_unset=unset +else + as_unset=false +fi + + +# IFS +# We need space, tab and new line, in precisely that order. Quoting is +# there to prevent editors from complaining about space-tab. +# (If _AS_PATH_WALK were called with IFS unset, it would disable word +# splitting by setting IFS to empty value.) +as_nl=' +' +IFS=" "" $as_nl" + +# Find who we are. Look in the path if we contain no directory separator. +case $0 in + *[\\/]* ) as_myself=$0 ;; + *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break +done +IFS=$as_save_IFS + + ;; +esac +# We did not find ourselves, most probably we were run as `sh COMMAND' +# in which case we are not to be found in the path. +if test "x$as_myself" = x; then + as_myself=$0 +fi +if test ! -f "$as_myself"; then + echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + { (exit 1); exit 1; } +fi + +# Work around bugs in pre-3.0 UWIN ksh. +for as_var in ENV MAIL MAILPATH +do ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var +done +PS1='$ ' +PS2='> ' +PS4='+ ' + +# NLS nuisances. +for as_var in \ + LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \ + LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \ + LC_TELEPHONE LC_TIME +do + if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then + eval $as_var=C; export $as_var + else + ($as_unset $as_var) >/dev/null 2>&1 && $as_unset $as_var + fi +done + +# Required to use basename. +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +if (basename -- /) >/dev/null 2>&1 && test "X`basename -- / 2>&1`" = "X/"; then + as_basename=basename +else + as_basename=false +fi + + +# Name of the executable. +as_me=`$as_basename -- "$0" || +$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ + X"$0" : 'X\(//\)$' \| \ + X"$0" : 'X\(/\)' \| . 2>/dev/null || +echo X/"$0" | + sed '/^.*\/\([^/][^/]*\)\/*$/{ + s//\1/ + q + } + /^X\/\(\/\/\)$/{ + s//\1/ + q + } + /^X\/\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + +# CDPATH. +$as_unset CDPATH + + + + as_lineno_1=$LINENO + as_lineno_2=$LINENO + test "x$as_lineno_1" != "x$as_lineno_2" && + test "x`expr $as_lineno_1 + 1`" = "x$as_lineno_2" || { + + # Create $as_me.lineno as a copy of $as_myself, but with $LINENO + # uniformly replaced by the line number. The first 'sed' inserts a + # line-number line after each line using $LINENO; the second 'sed' + # does the real work. The second script uses 'N' to pair each + # line-number line with the line containing $LINENO, and appends + # trailing '-' during substitution so that $LINENO is not a special + # case at line end. + # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the + # scripts with optimization help from Paolo Bonzini. Blame Lee + # E. McMahon (1931-1989) for sed's syntax. :-) + sed -n ' + p + /[$]LINENO/= + ' <$as_myself | + sed ' + s/[$]LINENO.*/&-/ + t lineno + b + :lineno + N + :loop + s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/ + t loop + s/-\n.*// + ' >$as_me.lineno && + chmod +x "$as_me.lineno" || + { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2 + { (exit 1); exit 1; }; } + + # Don't try to exec as it changes $[0], causing all sort of problems + # (the dirname of $[0] is not the place where we might find the + # original and so on. Autoconf is especially sensitive to this). + . "./$as_me.lineno" + # Exit status is that of the last command. + exit +} + + +if (as_dir=`dirname -- /` && test "X$as_dir" = X/) >/dev/null 2>&1; then + as_dirname=dirname +else + as_dirname=false +fi + +ECHO_C= ECHO_N= ECHO_T= +case `echo -n x` in +-n*) + case `echo 'x\c'` in + *c*) ECHO_T=' ';; # ECHO_T is single tab character. + *) ECHO_C='\c';; + esac;; +*) + ECHO_N='-n';; +esac + +if expr a : '\(a\)' >/dev/null 2>&1 && + test "X`expr 00001 : '.*\(...\)'`" = X001; then + as_expr=expr +else + as_expr=false +fi + +rm -f conf$$ conf$$.exe conf$$.file +if test -d conf$$.dir; then + rm -f conf$$.dir/conf$$.file +else + rm -f conf$$.dir + mkdir conf$$.dir +fi +echo >conf$$.file +if ln -s conf$$.file conf$$ 2>/dev/null; then + as_ln_s='ln -s' + # ... but there are two gotchas: + # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. + # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. + # In both cases, we have to default to `cp -p'. + ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || + as_ln_s='cp -p' +elif ln conf$$.file conf$$ 2>/dev/null; then + as_ln_s=ln +else + as_ln_s='cp -p' +fi +rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file +rmdir conf$$.dir 2>/dev/null + +if mkdir -p . 2>/dev/null; then + as_mkdir_p=: +else + test -d ./-p && rmdir ./-p + as_mkdir_p=false +fi + +# Find out whether ``test -x'' works. Don't use a zero-byte file, as +# systems may use methods other than mode bits to determine executability. +cat >conf$$.file <<_ASEOF +#! /bin/sh +exit 0 +_ASEOF +chmod +x conf$$.file +if test -x conf$$.file >/dev/null 2>&1; then + as_executable_p="test -x" +else + as_executable_p=: +fi +rm -f conf$$.file + +# Sed expression to map a string onto a valid CPP name. +as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" + +# Sed expression to map a string onto a valid variable name. +as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" + + +exec 6>&1 + +# Save the log message, to keep $[0] and so on meaningful, and to +# report actual input values of CONFIG_FILES etc. instead of their +# values after options handling. +ac_log=" +This file was extended by $as_me, which was +generated by GNU Autoconf 2.60. Invocation command line was + + CONFIG_FILES = $CONFIG_FILES + CONFIG_HEADERS = $CONFIG_HEADERS + CONFIG_LINKS = $CONFIG_LINKS + CONFIG_COMMANDS = $CONFIG_COMMANDS + $ $0 $@ + +on `(hostname || uname -n) 2>/dev/null | sed 1q` +" + +_ACEOF + +cat >>$CONFIG_STATUS <<_ACEOF +# Files that config.status was made for. +config_files="$ac_config_files" +config_headers="$ac_config_headers" + +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +ac_cs_usage="\ +\`$as_me' instantiates files from templates according to the +current configuration. + +Usage: $0 [OPTIONS] [FILE]... + + -h, --help print this help, then exit + -V, --version print version number, then exit + -q, --quiet do not print progress messages + -d, --debug don't remove temporary files + --recheck update $as_me by reconfiguring in the same conditions + --file=FILE[:TEMPLATE] + instantiate the configuration file FILE + --header=FILE[:TEMPLATE] + instantiate the configuration header FILE + +Configuration files: +$config_files + +Configuration headers: +$config_headers + +Report bugs to ." + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +ac_cs_version="\\ +config.status +configured by $0, generated by GNU Autoconf 2.60, + with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" + +Copyright (C) 2006 Free Software Foundation, Inc. +This config.status script is free software; the Free Software Foundation +gives unlimited permission to copy, distribute and modify it." + +ac_pwd='$ac_pwd' +srcdir='$srcdir' +INSTALL='$INSTALL' +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If no file are specified by the user, then we need to provide default +# value. By we need to know if files were specified by the user. +ac_need_defaults=: +while test $# != 0 +do + case $1 in + --*=*) + ac_option=`expr "X$1" : 'X\([^=]*\)='` + ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'` + ac_shift=: + ;; + *) + ac_option=$1 + ac_optarg=$2 + ac_shift=shift + ;; + esac + + case $ac_option in + # Handling of the options. + -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) + ac_cs_recheck=: ;; + --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) + echo "$ac_cs_version"; exit ;; + --debug | --debu | --deb | --de | --d | -d ) + debug=: ;; + --file | --fil | --fi | --f ) + $ac_shift + CONFIG_FILES="$CONFIG_FILES $ac_optarg" + ac_need_defaults=false;; + --header | --heade | --head | --hea ) + $ac_shift + CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg" + ac_need_defaults=false;; + --he | --h) + # Conflict between --help and --header + { echo "$as_me: error: ambiguous option: $1 +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; };; + --help | --hel | -h ) + echo "$ac_cs_usage"; exit ;; + -q | -quiet | --quiet | --quie | --qui | --qu | --q \ + | -silent | --silent | --silen | --sile | --sil | --si | --s) + ac_cs_silent=: ;; + + # This is an error. + -*) { echo "$as_me: error: unrecognized option: $1 +Try \`$0 --help' for more information." >&2 + { (exit 1); exit 1; }; } ;; + + *) ac_config_targets="$ac_config_targets $1" + ac_need_defaults=false ;; + + esac + shift +done + +ac_configure_extra_args= + +if $ac_cs_silent; then + exec 6>/dev/null + ac_configure_extra_args="$ac_configure_extra_args --silent" +fi + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +if \$ac_cs_recheck; then + echo "running CONFIG_SHELL=$SHELL $SHELL $0 "$ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6 + CONFIG_SHELL=$SHELL + export CONFIG_SHELL + exec $SHELL "$0"$ac_configure_args \$ac_configure_extra_args --no-create --no-recursion +fi + +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +exec 5>>config.log +{ + echo + sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX +## Running $as_me. ## +_ASBOX + echo "$ac_log" +} >&5 + +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF + +# Handling of arguments. +for ac_config_target in $ac_config_targets +do + case $ac_config_target in + "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;; + "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; + + *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 +echo "$as_me: error: invalid argument: $ac_config_target" >&2;} + { (exit 1); exit 1; }; };; + esac +done + + +# If the user did not use the arguments to specify the items to instantiate, +# then the envvar interface is used. Set only those that are not. +# We use the long form for the default assignment because of an extremely +# bizarre bug on SunOS 4.1.3. +if $ac_need_defaults; then + test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files + test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers +fi + +# Have a temporary directory for convenience. Make it in the build tree +# simply because there is no reason against having it here, and in addition, +# creating and moving files from /tmp can sometimes cause problems. +# Hook for its removal unless debugging. +# Note that there is a small window in which the directory will not be cleaned: +# after its creation but before its name has been assigned to `$tmp'. +$debug || +{ + tmp= + trap 'exit_status=$? + { test -z "$tmp" || test ! -d "$tmp" || rm -fr "$tmp"; } && exit $exit_status +' 0 + trap '{ (exit 1); exit 1; }' 1 2 13 15 +} +# Create a (secure) tmp directory for tmp files. + +{ + tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` && + test -n "$tmp" && test -d "$tmp" +} || +{ + tmp=./conf$$-$RANDOM + (umask 077 && mkdir "$tmp") +} || +{ + echo "$me: cannot create a temporary directory in ." >&2 + { (exit 1); exit 1; } +} + +# +# Set up the sed scripts for CONFIG_FILES section. +# + +# No need to generate the scripts if there are no CONFIG_FILES. +# This happens for instance when ./config.status config.h +if test -n "$CONFIG_FILES"; then + +_ACEOF + + + +ac_delim='%!_!# ' +for ac_last_try in false false false false false :; do + cat >conf$$subs.sed <<_ACEOF +SHELL!$SHELL$ac_delim +PATH_SEPARATOR!$PATH_SEPARATOR$ac_delim +PACKAGE_NAME!$PACKAGE_NAME$ac_delim +PACKAGE_TARNAME!$PACKAGE_TARNAME$ac_delim +PACKAGE_VERSION!$PACKAGE_VERSION$ac_delim +PACKAGE_STRING!$PACKAGE_STRING$ac_delim +PACKAGE_BUGREPORT!$PACKAGE_BUGREPORT$ac_delim +exec_prefix!$exec_prefix$ac_delim +prefix!$prefix$ac_delim +program_transform_name!$program_transform_name$ac_delim +bindir!$bindir$ac_delim +sbindir!$sbindir$ac_delim +libexecdir!$libexecdir$ac_delim +datarootdir!$datarootdir$ac_delim +datadir!$datadir$ac_delim +sysconfdir!$sysconfdir$ac_delim +sharedstatedir!$sharedstatedir$ac_delim +localstatedir!$localstatedir$ac_delim +includedir!$includedir$ac_delim +oldincludedir!$oldincludedir$ac_delim +docdir!$docdir$ac_delim +infodir!$infodir$ac_delim +htmldir!$htmldir$ac_delim +dvidir!$dvidir$ac_delim +pdfdir!$pdfdir$ac_delim +psdir!$psdir$ac_delim +libdir!$libdir$ac_delim +localedir!$localedir$ac_delim +mandir!$mandir$ac_delim +DEFS!$DEFS$ac_delim +ECHO_C!$ECHO_C$ac_delim +ECHO_N!$ECHO_N$ac_delim +ECHO_T!$ECHO_T$ac_delim +LIBS!$LIBS$ac_delim +build_alias!$build_alias$ac_delim +host_alias!$host_alias$ac_delim +target_alias!$target_alias$ac_delim +CC!$CC$ac_delim +CFLAGS!$CFLAGS$ac_delim +LDFLAGS!$LDFLAGS$ac_delim +CPPFLAGS!$CPPFLAGS$ac_delim +ac_ct_CC!$ac_ct_CC$ac_delim +EXEEXT!$EXEEXT$ac_delim +OBJEXT!$OBJEXT$ac_delim +RANLIB!$RANLIB$ac_delim +INSTALL_PROGRAM!$INSTALL_PROGRAM$ac_delim +INSTALL_SCRIPT!$INSTALL_SCRIPT$ac_delim +INSTALL_DATA!$INSTALL_DATA$ac_delim +CPP!$CPP$ac_delim +GREP!$GREP$ac_delim +EGREP!$EGREP$ac_delim +LIBOBJS!$LIBOBJS$ac_delim +LTLIBOBJS!$LTLIBOBJS$ac_delim +_ACEOF + + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 53; then + break + elif $ac_last_try; then + { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 +echo "$as_me: error: could not make $CONFIG_STATUS" >&2;} + { (exit 1); exit 1; }; } + else + ac_delim="$ac_delim!$ac_delim _$ac_delim!! " + fi +done + +ac_eof=`sed -n '/^CEOF[0-9]*$/s/CEOF/0/p' conf$$subs.sed` +if test -n "$ac_eof"; then + ac_eof=`echo "$ac_eof" | sort -nru | sed 1q` + ac_eof=`expr $ac_eof + 1` +fi + +cat >>$CONFIG_STATUS <<_ACEOF +cat >"\$tmp/subs-1.sed" <<\CEOF$ac_eof +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b end +_ACEOF +sed ' +s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g +s/^/s,@/; s/!/@,|#_!!_#|/ +:n +t n +s/'"$ac_delim"'$/,g/; t +s/$/\\/; p +N; s/^.*\n//; s/[,\\&]/\\&/g; s/@/@|#_!!_#|/g; b n +' >>$CONFIG_STATUS >$CONFIG_STATUS <<_ACEOF +:end +s/|#_!!_#|//g +CEOF$ac_eof +_ACEOF + + +# VPATH may cause trouble with some makes, so we remove $(srcdir), +# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and +# trailing colons and then remove the whole line if VPATH becomes empty +# (actually we leave an empty line to preserve line numbers). +if test "x$srcdir" = x.; then + ac_vpsub='/^[ ]*VPATH[ ]*=/{ +s/:*\$(srcdir):*/:/ +s/:*\${srcdir}:*/:/ +s/:*@srcdir@:*/:/ +s/^\([^=]*=[ ]*\):*/\1/ +s/:*$// +s/^[^=]*=[ ]*$// +}' +fi + +cat >>$CONFIG_STATUS <<\_ACEOF +fi # test -n "$CONFIG_FILES" + + +for ac_tag in :F $CONFIG_FILES :H $CONFIG_HEADERS +do + case $ac_tag in + :[FHLC]) ac_mode=$ac_tag; continue;; + esac + case $ac_mode$ac_tag in + :[FHL]*:*);; + :L* | :C*:*) { { echo "$as_me:$LINENO: error: Invalid tag $ac_tag." >&5 +echo "$as_me: error: Invalid tag $ac_tag." >&2;} + { (exit 1); exit 1; }; };; + :[FH]-) ac_tag=-:-;; + :[FH]*) ac_tag=$ac_tag:$ac_tag.in;; + esac + ac_save_IFS=$IFS + IFS=: + set x $ac_tag + IFS=$ac_save_IFS + shift + ac_file=$1 + shift + + case $ac_mode in + :L) ac_source=$1;; + :[FH]) + ac_file_inputs= + for ac_f + do + case $ac_f in + -) ac_f="$tmp/stdin";; + *) # Look for the file first in the build tree, then in the source tree + # (if the path is not absolute). The absolute path cannot be DOS-style, + # because $ac_f cannot contain `:'. + test -f "$ac_f" || + case $ac_f in + [\\/$]*) false;; + *) test -f "$srcdir/$ac_f" && ac_f="$srcdir/$ac_f";; + esac || + { { echo "$as_me:$LINENO: error: cannot find input file: $ac_f" >&5 +echo "$as_me: error: cannot find input file: $ac_f" >&2;} + { (exit 1); exit 1; }; };; + esac + ac_file_inputs="$ac_file_inputs $ac_f" + done + + # Let's still pretend it is `configure' which instantiates (i.e., don't + # use $as_me), people would be surprised to read: + # /* config.h. Generated by config.status. */ + configure_input="Generated from "`IFS=: + echo $* | sed 's|^[^:]*/||;s|:[^:]*/|, |g'`" by configure." + if test x"$ac_file" != x-; then + configure_input="$ac_file. $configure_input" + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + fi + + case $ac_tag in + *:-:* | *:-) cat >"$tmp/stdin";; + esac + ;; + esac + + ac_dir=`$as_dirname -- "$ac_file" || +$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$ac_file" : 'X\(//\)[^/]' \| \ + X"$ac_file" : 'X\(//\)$' \| \ + X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || +echo X"$ac_file" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + { as_dir="$ac_dir" + case $as_dir in #( + -*) as_dir=./$as_dir;; + esac + test -d "$as_dir" || { $as_mkdir_p && mkdir -p "$as_dir"; } || { + as_dirs= + while :; do + case $as_dir in #( + *\'*) as_qdir=`echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #( + *) as_qdir=$as_dir;; + esac + as_dirs="'$as_qdir' $as_dirs" + as_dir=`$as_dirname -- "$as_dir" || +$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ + X"$as_dir" : 'X\(//\)[^/]' \| \ + X"$as_dir" : 'X\(//\)$' \| \ + X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || +echo X"$as_dir" | + sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ + s//\1/ + q + } + /^X\(\/\/\)[^/].*/{ + s//\1/ + q + } + /^X\(\/\/\)$/{ + s//\1/ + q + } + /^X\(\/\).*/{ + s//\1/ + q + } + s/.*/./; q'` + test -d "$as_dir" && break + done + test -z "$as_dirs" || eval "mkdir $as_dirs" + } || test -d "$as_dir" || { { echo "$as_me:$LINENO: error: cannot create directory $as_dir" >&5 +echo "$as_me: error: cannot create directory $as_dir" >&2;} + { (exit 1); exit 1; }; }; } + ac_builddir=. + +case "$ac_dir" in +.) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; +*) + ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'` + # A ".." for each directory in $ac_dir_suffix. + ac_top_builddir_sub=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,/..,g;s,/,,'` + case $ac_top_builddir_sub in + "") ac_top_builddir_sub=. ac_top_build_prefix= ;; + *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; + esac ;; +esac +ac_abs_top_builddir=$ac_pwd +ac_abs_builddir=$ac_pwd$ac_dir_suffix +# for backward compatibility: +ac_top_builddir=$ac_top_build_prefix + +case $srcdir in + .) # We are building in place. + ac_srcdir=. + ac_top_srcdir=$ac_top_builddir_sub + ac_abs_top_srcdir=$ac_pwd ;; + [\\/]* | ?:[\\/]* ) # Absolute name. + ac_srcdir=$srcdir$ac_dir_suffix; + ac_top_srcdir=$srcdir + ac_abs_top_srcdir=$srcdir ;; + *) # Relative name. + ac_srcdir=$ac_top_build_prefix$srcdir$ac_dir_suffix + ac_top_srcdir=$ac_top_build_prefix$srcdir + ac_abs_top_srcdir=$ac_pwd/$srcdir ;; +esac +ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix + + + case $ac_mode in + :F) + # + # CONFIG_FILE + # + + case $INSTALL in + [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;; + *) ac_INSTALL=$ac_top_build_prefix$INSTALL ;; + esac +_ACEOF + +cat >>$CONFIG_STATUS <<\_ACEOF +# If the template does not know about datarootdir, expand it. +# FIXME: This hack should be removed a few years after 2.60. +ac_datarootdir_hack=; ac_datarootdir_seen= + +case `sed -n '/datarootdir/ { + p + q +} +/@datadir@/p +/@docdir@/p +/@infodir@/p +/@localedir@/p +/@mandir@/p +' $ac_file_inputs` in +*datarootdir*) ac_datarootdir_seen=yes;; +*@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) + { echo "$as_me:$LINENO: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} +_ACEOF +cat >>$CONFIG_STATUS <<_ACEOF + ac_datarootdir_hack=' + s&@datadir@&$datadir&g + s&@docdir@&$docdir&g + s&@infodir@&$infodir&g + s&@localedir@&$localedir&g + s&@mandir@&$mandir&g + s&\\\${datarootdir}&$datarootdir&g' ;; +esac +_ACEOF + +# Neutralize VPATH when `$srcdir' = `.'. +# Shell code in configure.ac might set extrasub. +# FIXME: do we really want to maintain this feature? +cat >>$CONFIG_STATUS <<_ACEOF + sed "$ac_vpsub +$extrasub +_ACEOF +cat >>$CONFIG_STATUS <<\_ACEOF +:t +/@[a-zA-Z_][a-zA-Z_0-9]*@/!b +s&@configure_input@&$configure_input&;t t +s&@top_builddir@&$ac_top_builddir_sub&;t t +s&@srcdir@&$ac_srcdir&;t t +s&@abs_srcdir@&$ac_abs_srcdir&;t t +s&@top_srcdir@&$ac_top_srcdir&;t t +s&@abs_top_srcdir@&$ac_abs_top_srcdir&;t t +s&@builddir@&$ac_builddir&;t t +s&@abs_builddir@&$ac_abs_builddir&;t t +s&@abs_top_builddir@&$ac_abs_top_builddir&;t t +s&@INSTALL@&$ac_INSTALL&;t t +$ac_datarootdir_hack +" $ac_file_inputs | sed -f "$tmp/subs-1.sed" >$tmp/out + +test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && + { ac_out=`sed -n '/\${datarootdir}/p' "$tmp/out"`; test -n "$ac_out"; } && + { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' "$tmp/out"`; test -z "$ac_out"; } && + { echo "$as_me:$LINENO: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&5 +echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +which seems to be undefined. Please make sure it is defined." >&2;} + + rm -f "$tmp/stdin" + case $ac_file in + -) cat "$tmp/out"; rm -f "$tmp/out";; + *) rm -f "$ac_file"; mv "$tmp/out" $ac_file;; + esac + ;; + :H) + # + # CONFIG_HEADER + # +_ACEOF + +# Transform confdefs.h into a sed script `conftest.defines', that +# substitutes the proper values into config.h.in to produce config.h. +rm -f conftest.defines conftest.tail +# First, append a space to every undef/define line, to ease matching. +echo 's/$/ /' >conftest.defines +# Then, protect against being on the right side of a sed subst, or in +# an unquoted here document, in config.status. If some macros were +# called several times there might be several #defines for the same +# symbol, which is useless. But do not sort them, since the last +# AC_DEFINE must be honored. +ac_word_re=[_$as_cr_Letters][_$as_cr_alnum]* +# These sed commands are passed to sed as "A NAME B PARAMS C VALUE D", where +# NAME is the cpp macro being defined, VALUE is the value it is being given. +# PARAMS is the parameter list in the macro definition--in most cases, it's +# just an empty string. +ac_dA='s,^\\([ #]*\\)[^ ]*\\([ ]*' +ac_dB='\\)[ (].*,\\1define\\2' +ac_dC=' ' +ac_dD=' ,' + +uniq confdefs.h | + sed -n ' + t rset + :rset + s/^[ ]*#[ ]*define[ ][ ]*// + t ok + d + :ok + s/[\\&,]/\\&/g + s/^\('"$ac_word_re"'\)\(([^()]*)\)[ ]*\(.*\)/ '"$ac_dA"'\1'"$ac_dB"'\2'"${ac_dC}"'\3'"$ac_dD"'/p + s/^\('"$ac_word_re"'\)[ ]*\(.*\)/'"$ac_dA"'\1'"$ac_dB$ac_dC"'\2'"$ac_dD"'/p + ' >>conftest.defines + +# Remove the space that was appended to ease matching. +# Then replace #undef with comments. This is necessary, for +# example, in the case of _POSIX_SOURCE, which is predefined and required +# on some systems where configure will not decide to define it. +# (The regexp can be short, since the line contains either #define or #undef.) +echo 's/ $// +s,^[ #]*u.*,/* & */,' >>conftest.defines + +# Break up conftest.defines: +ac_max_sed_lines=50 + +# First sed command is: sed -f defines.sed $ac_file_inputs >"$tmp/out1" +# Second one is: sed -f defines.sed "$tmp/out1" >"$tmp/out2" +# Third one will be: sed -f defines.sed "$tmp/out2" >"$tmp/out1" +# et cetera. +ac_in='$ac_file_inputs' +ac_out='"$tmp/out1"' +ac_nxt='"$tmp/out2"' + +while : +do + # Write a here document: + cat >>$CONFIG_STATUS <<_ACEOF + # First, check the format of the line: + cat >"\$tmp/defines.sed" <<\\CEOF +/^[ ]*#[ ]*undef[ ][ ]*$ac_word_re[ ]*\$/b def +/^[ ]*#[ ]*define[ ][ ]*$ac_word_re[( ]/b def +b +:def +_ACEOF + sed ${ac_max_sed_lines}q conftest.defines >>$CONFIG_STATUS + echo 'CEOF + sed -f "$tmp/defines.sed"' "$ac_in >$ac_out" >>$CONFIG_STATUS + ac_in=$ac_out; ac_out=$ac_nxt; ac_nxt=$ac_in + sed 1,${ac_max_sed_lines}d conftest.defines >conftest.tail + grep . conftest.tail >/dev/null || break + rm -f conftest.defines + mv conftest.tail conftest.defines +done +rm -f conftest.defines conftest.tail + +echo "ac_result=$ac_in" >>$CONFIG_STATUS +cat >>$CONFIG_STATUS <<\_ACEOF + if test x"$ac_file" != x-; then + echo "/* $configure_input */" >"$tmp/config.h" + cat "$ac_result" >>"$tmp/config.h" + if diff $ac_file "$tmp/config.h" >/dev/null 2>&1; then + { echo "$as_me:$LINENO: $ac_file is unchanged" >&5 +echo "$as_me: $ac_file is unchanged" >&6;} + else + rm -f $ac_file + mv "$tmp/config.h" $ac_file + fi + else + echo "/* $configure_input */" + cat "$ac_result" + fi + rm -f "$tmp/out12" + ;; + + + esac + +done # for ac_tag + + +{ (exit 0); exit 0; } +_ACEOF +chmod +x $CONFIG_STATUS +ac_clean_files=$ac_clean_files_save + + +# configure is writing to config.log, and then calls config.status. +# config.status does its own redirection, appending to config.log. +# Unfortunately, on DOS this fails, as config.log is still kept open +# by configure, so config.status won't be able to write to it; its +# output is simply discarded. So we exec the FD to /dev/null, +# effectively closing config.log, so it can be properly (re)opened and +# appended to by config.status. When coming back to configure, we +# need to make the FD available again. +if test "$no_create" != yes; then + ac_cs_success=: + ac_config_status_args= + test "$silent" = yes && + ac_config_status_args="$ac_config_status_args --quiet" + exec 5>/dev/null + $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false + exec 5>>config.log + # Use ||, not &&, to avoid exiting from the if with $? = 1, which + # would make configure fail if this is the last instruction. + $ac_cs_success || { (exit 1); exit 1; } +fi + diff --git a/src/lzf/configure.ac b/src/lzf/configure.ac new file mode 100644 index 000000000..58316a01b --- /dev/null +++ b/src/lzf/configure.ac @@ -0,0 +1,25 @@ +AC_INIT +AC_CONFIG_SRCDIR([lzfP.h]) + +AC_CONFIG_HEADER(config.h) + +AC_GNU_SOURCE +AC_SYS_LARGEFILE +AC_PROG_CC +AC_PROG_RANLIB +AC_PROG_INSTALL +AC_HEADER_STDC + +AC_C_CONST +AC_C_INLINE +AC_CHECK_HEADERS(getopt.h) +AC_CHECK_FUNCS(getopt_long) + +if test "$GCC" = yes; then + CFLAGS="$CFLAGS -O3 -funroll-all-loops" +else + AC_MSG_RESULT(no gcc) +fi + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/src/lzf/crc32.h b/src/lzf/crc32.h new file mode 100644 index 000000000..cf8f6d409 --- /dev/null +++ b/src/lzf/crc32.h @@ -0,0 +1,65 @@ +#ifndef CRC32_H +#define CRC32_H + +/* crc32 0xdebb20e3 table and supplementary functions. */ + +static const u32 crc_32_tab[] = +{ + 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, + 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, + 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, + 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, + 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, + 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, + 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, + 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, + 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, + 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, + 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, + 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, + 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, + 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, + 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, + 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, + 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, + 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, + 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, + 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, + 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, + 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, + 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, + 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, + 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, + 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, + 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, + 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, + 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, + 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, + 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, + 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, + 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, + 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, + 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, + 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, + 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, + 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, + 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, + 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, + 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, + 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, + 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, + 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, + 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, + 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, + 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, + 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, + 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, + 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, + 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, + 0x2d02ef8dL +}; + +#define crc32(crc,byte) (crc_32_tab[(u8)(crc) ^ (u8)(byte)] ^ ((crc) >> 8)) + +#endif + diff --git a/src/lzf/install-sh b/src/lzf/install-sh new file mode 100644 index 000000000..e9de23842 --- /dev/null +++ b/src/lzf/install-sh @@ -0,0 +1,251 @@ +#!/bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5 (mit/util/scripts/install.sh). +# +# Copyright 1991 by the Massachusetts Institute of Technology +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of M.I.T. not be used in advertising or +# publicity pertaining to distribution of the software without specific, +# written prior permission. M.I.T. makes no representations about the +# suitability of this software for any purpose. It is provided "as is" +# without express or implied warranty. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +transformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd="$cpprog" + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "install: no input file specified" + exit 1 +else + true +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d $dst ]; then + instcmd=: + chmodcmd="" + else + instcmd=mkdir + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f $src -o -d $src ] + then + true + else + echo "install: $src does not exist" + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "install: no destination specified" + exit 1 + else + true + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d $dst ] + then + dst="$dst"/`basename $src` + else + true + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' +' +IFS="${IFS-${defaultIFS}}" + +oIFS="${IFS}" +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS="${oIFS}" + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp="${pathcomp}${1}" + shift + + if [ ! -d "${pathcomp}" ] ; + then + $mkdirprog "${pathcomp}" + else + true + fi + + pathcomp="${pathcomp}/" +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd $dst && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename $dst` + else + dstfile=`basename $dst $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename $dst` + else + true + fi + +# Make a temp file name in the proper directory. + + dsttmp=$dstdir/#inst.$$# + +# Move or copy the file name to the temp name + + $doit $instcmd $src $dsttmp && + + trap "rm -f ${dsttmp}" 0 && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && + +# Now rename the file to the real destination. + + $doit $rmcmd -f $dstdir/$dstfile && + $doit $mvcmd $dsttmp $dstdir/$dstfile + +fi && + + +exit 0 diff --git a/src/lzf/lzf.c b/src/lzf/lzf.c new file mode 100644 index 000000000..bedfdb6fe --- /dev/null +++ b/src/lzf/lzf.c @@ -0,0 +1,537 @@ +/* + * Copyright (c) 2006 Stefan Traby + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License ("GPL") version 2 or any later version, + * in which case the provisions of the GPL are applicable instead of + * the above. If you wish to allow the use of your version of this file + * only under the terms of the GPL and not to allow others to use your + * version of this file under the BSD license, indicate your decision + * by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL. If you do not delete the + * provisions above, a recipient may use your version of this file under + * either the BSD or the GPL. + */ + +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lzf.h" + +#ifdef HAVE_GETOPT_H +# include +#endif + +#define BLOCKSIZE (1024 * 64 - 1) +#define MAX_BLOCKSIZE BLOCKSIZE + +typedef unsigned char u8; + +static off_t nr_read, nr_written; + +static const char *imagename; +static enum { compress, uncompress, lzcat } mode = compress; +static int verbose = 0; +static int force = 0; +static long blocksize = BLOCKSIZE; + +#ifdef HAVE_GETOPT_LONG + + struct option longopts[] = { + {"compress", 0, 0, 'c'}, + {"decompress", 0, 0, 'd'}, + {"uncompress", 0, 0, 'd'}, + {"force", 0, 0, 'f'}, + {"help", 0, 0, 'h'}, + {"verbose", 0, 0, 'v'}, + {"blocksize", 1, 0, 'b'}, + {0, 0, 0, 0} + }; + + static const char *opt = + "-c --compress compress\n" + "-d --decompress decompress\n" + "-f --force force overwrite of output file\n" + "-h --help give this help\n" "-v --verbose verbose mode\n" "-b # --blocksize # set blocksize\n" "\n"; + +#else + + static const char *opt = + "-c compress\n" + "-d decompress\n" + "-f force overwrite of output file\n" + "-h give this help\n" + "-v verbose mode\n" + "-b # set blocksize\n" + "\n"; + +#endif + +static void +usage (int rc) +{ + fprintf (stderr, "\n" + "lzf, a very lightweight compression/decompression utility written by Stefan Traby.\n" + "uses liblzf written by Marc Lehmann You can find more info at\n" + "http://liblzf.plan9.de/\n" + "\n" + "usage: lzf [-dufhvb] [file ...]\n" + " unlzf [file ...]\n" + " lzcat [file ...]\n" + "\n%s", + opt); + + exit (rc); +} + +static inline ssize_t +rread (int fd, void *buf, size_t len) +{ + ssize_t rc = 0, offset = 0; + char *p = buf; + + while (len && (rc = read (fd, &p[offset], len)) > 0) + { + offset += rc; + len -= rc; + } + + nr_read += offset; + + if (rc < 0) + return rc; + + return offset; +} + +/* returns 0 if all written else -1 */ +static inline ssize_t +wwrite (int fd, void *buf, size_t len) +{ + ssize_t rc; + char *b = buf; + size_t l = len; + + while (l) + { + rc = write (fd, b, l); + if (rc < 0) + { + fprintf (stderr, "%s: write error: ", imagename); + perror (""); + return -1; + } + + l -= rc; + b += rc; + } + + nr_written += len; + return 0; +} + +/* + * Anatomy: an lzf file consists of any number of blocks in the following format: + * + * \x00 EOF (optional) + * "ZV\0" 2-byte-usize + * "ZV\1" 2-byte-csize 2-byte-usize + * "ZV\2" 4-byte-crc32-0xdebb20e3 (NYI) + */ + + +#define TYPE0_HDR_SIZE 5 +#define TYPE1_HDR_SIZE 7 +#define MAX_HDR_SIZE 7 +#define MIN_HDR_SIZE 5 + +static int +compress_fd (int from, int to) +{ + ssize_t us, cs, len; + u8 buf1[MAX_BLOCKSIZE + MAX_HDR_SIZE + 16]; + u8 buf2[MAX_BLOCKSIZE + MAX_HDR_SIZE + 16]; + u8 *header; + + nr_read = nr_written = 0; + while ((us = rread (from, &buf1[MAX_HDR_SIZE], blocksize)) > 0) + { + cs = lzf_compress (&buf1[MAX_HDR_SIZE], us, &buf2[MAX_HDR_SIZE], us > 4 ? us - 4 : us); + if (cs) + { + header = &buf2[MAX_HDR_SIZE - TYPE1_HDR_SIZE]; + header[0] = 'Z'; + header[1] = 'V'; + header[2] = 1; + header[3] = cs >> 8; + header[4] = cs & 0xff; + header[5] = us >> 8; + header[6] = us & 0xff; + len = cs + TYPE1_HDR_SIZE; + } + else + { // write uncompressed + header = &buf1[MAX_HDR_SIZE - TYPE0_HDR_SIZE]; + header[0] = 'Z'; + header[1] = 'V'; + header[2] = 0; + header[3] = us >> 8; + header[4] = us & 0xff; + len = us + TYPE0_HDR_SIZE; + } + + if (wwrite (to, header, len) == -1) + return -1; + } + + return 0; +} + +static int +uncompress_fd (int from, int to) +{ + u8 header[MAX_HDR_SIZE]; + u8 buf1[MAX_BLOCKSIZE + MAX_HDR_SIZE + 16]; + u8 buf2[MAX_BLOCKSIZE + MAX_HDR_SIZE + 16]; + u8 *p; + int l, rd; + ssize_t rc, cs, us, bytes, over = 0; + + nr_read = nr_written = 0; + while (1) + { + rc = rread (from, header + over, MAX_HDR_SIZE - over); + if (rc < 0) + { + fprintf (stderr, "%s: read error: ", imagename); + perror (""); + return -1; + } + + rc += over; + over = 0; + if (!rc || header[0] == 0) + return 0; + + if (rc < MIN_HDR_SIZE || header[0] != 'Z' || header[1] != 'V') + { + fprintf (stderr, "%s: invalid data stream - magic not found or short header\n", imagename); + return -1; + } + + switch (header[2]) + { + case 0: + cs = -1; + us = (header[3] << 8) | header[4]; + p = &header[TYPE0_HDR_SIZE]; + break; + case 1: + if (rc < TYPE1_HDR_SIZE) + { + goto short_read; + } + cs = (header[3] << 8) | header[4]; + us = (header[5] << 8) | header[6]; + p = &header[TYPE1_HDR_SIZE]; + break; + default: + fprintf (stderr, "%s: unknown blocktype\n", imagename); + return -1; + } + + bytes = cs == -1 ? us : cs; + l = &header[rc] - p; + + if (l > 0) + memcpy (buf1, p, l); + + if (l > bytes) + { + over = l - bytes; + memmove (header, &p[bytes], over); + } + + p = &buf1[l]; + rd = bytes - l; + if (rd > 0) + if ((rc = rread (from, p, rd)) != rd) + goto short_read; + + if (cs == -1) + { + if (wwrite (to, buf1, us)) + return -1; + } + else + { + if (lzf_decompress (buf1, cs, buf2, us) != us) + { + fprintf (stderr, "%s: decompress: invalid stream - data corrupted\n", imagename); + return -1; + } + + if (wwrite (to, buf2, us)) + return -1; + } + } + + return 0; + +short_read: + fprintf (stderr, "%s: short data\n", imagename); + return -1; +} + +static int +open_out (const char *name) +{ + int fd; + int m = O_EXCL; + + if (force) + m = 0; + + fd = open (name, O_CREAT | O_WRONLY | O_TRUNC | m, 600); +#if defined(__MINGW32__) + _setmode(fd, _O_BINARY); +#endif + return fd; +} + +static int +compose_name (const char *fname, char *oname) +{ + char *p; + + if (mode == compress) + { + if (strlen (fname) > PATH_MAX - 4) + { + fprintf (stderr, "%s: %s.lzf: name too long", imagename, fname); + return -1; + } + + strcpy (oname, fname); + strcat (oname, ".lzf"); + } + else + { + if (strlen (fname) > PATH_MAX) + { + fprintf (stderr, "%s: %s: name too long\n", imagename, fname); + return -1; + } + + strcpy (oname, fname); + p = &oname[strlen (oname)] - 4; + if (p < oname || strcmp (p, ".lzf")) + { + fprintf (stderr, "%s: %s: unknown suffix\n", imagename, fname); + return -1; + } + + *p = 0; + } + + return 0; +} + +static int +run_file (const char *fname) +{ + int fd, fd2; + int rc; + struct stat mystat; + char oname[PATH_MAX + 1]; + + if (mode != lzcat) + if (compose_name (fname, oname)) + return -1; + +#if !defined(__MINGW32__) + rc = lstat (fname, &mystat); +#else + rc = stat (fname, &mystat); +#endif + fd = open (fname, O_RDONLY); +#if defined(__MINGW32__) + _setmode(fd, _O_BINARY); +#endif + if (rc || fd == -1) + { + fprintf (stderr, "%s: %s: ", imagename, fname); + perror (""); + return -1; + } + + if (!S_ISREG (mystat.st_mode)) + { + fprintf (stderr, "%s: %s: not a regular file.\n", imagename, fname); + close (fd); + return -1; + } + + if (mode == lzcat) + { + rc = uncompress_fd (fd, 1); + close (fd); + return rc; + } + + fd2 = open_out (oname); + if (fd2 == -1) + { + fprintf (stderr, "%s: %s: ", imagename, oname); + perror (""); + close (fd); + return -1; + } + + if (mode == compress) + { + rc = compress_fd (fd, fd2); + if (!rc && verbose) + fprintf (stderr, "%s: %5.1f%% -- replaced with %s\n", + fname, nr_read == 0 ? 0 : 100.0 - nr_written / ((double) nr_read / 100.0), oname); + } + else + { + rc = uncompress_fd (fd, fd2); + if (!rc && verbose) + fprintf (stderr, "%s: %5.1f%% -- replaced with %s\n", + fname, nr_written == 0 ? 0 : 100.0 - nr_read / ((double) nr_written / 100.0), oname); + } + +#if !defined(__MINGW32__) + fchmod (fd2, mystat.st_mode); +#else + chmod (oname, mystat.st_mode); +#endif + close (fd); + close (fd2); + + if (!rc) + unlink (fname); + + return rc; +} + +int +main (int argc, char *argv[]) +{ + char *p = argv[0]; + int optc; + int rc = 0; + + errno = 0; + p = getenv ("LZF_BLOCKSIZE"); + if (p) + { + blocksize = strtoul (p, 0, 0); + if (errno || !blocksize || blocksize > MAX_BLOCKSIZE) + blocksize = BLOCKSIZE; + } + + p = strrchr (argv[0], '/'); + imagename = p ? ++p : argv[0]; + + if (!strncmp (imagename, "un", 2) || !strncmp (imagename, "de", 2)) + mode = uncompress; + + if (strstr (imagename, "cat")) + mode = lzcat; + +#ifdef HAVE_GETOPT_LONG + while ((optc = getopt_long (argc, argv, "cdfhvb:", longopts, 0)) != -1) +#else + while ((optc = getopt (argc, argv, "cdfhvb:")) != -1) +#endif + { + switch (optc) + { + case 'c': + mode = compress; + break; + case 'd': + mode = uncompress; + break; + case 'f': + force = 1; + break; + case 'h': + usage (0); + break; + case 'v': + verbose = 1; + break; + case 'b': + errno = 0; + blocksize = strtoul (optarg, 0, 0); + if (errno || !blocksize || blocksize > MAX_BLOCKSIZE) + blocksize = BLOCKSIZE; + break; + default: + usage (1); + break; + } + } + + if (optind == argc) + { // stdin stdout + if (!force) + { + if ((mode == uncompress || mode == lzcat) && isatty (0)) + { + fprintf (stderr, "%s: compressed data not read from a terminal. Use -f to force decompression.\n", imagename); + exit (1); + } + if (mode == compress && isatty (1)) + { + fprintf (stderr, "%s: compressed data not written to a terminal. Use -f to force compression.\n", imagename); + exit (1); + } + } + + if (mode == compress) + rc = compress_fd (0, 1); + else + rc = uncompress_fd (0, 1); + + exit (rc ? 1 : 0); + } + + while (optind < argc) + rc |= run_file (argv[optind++]); + + exit (rc ? 1 : 0); +} + diff --git a/src/lzf/lzf.h b/src/lzf/lzf.h new file mode 100644 index 000000000..919b6e6be --- /dev/null +++ b/src/lzf/lzf.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2000-2008 Marc Alexander Lehmann + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License ("GPL") version 2 or any later version, + * in which case the provisions of the GPL are applicable instead of + * the above. If you wish to allow the use of your version of this file + * only under the terms of the GPL and not to allow others to use your + * version of this file under the BSD license, indicate your decision + * by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL. If you do not delete the + * provisions above, a recipient may use your version of this file under + * either the BSD or the GPL. + */ + +#ifndef LZF_H +#define LZF_H + +/*********************************************************************** +** +** lzf -- an extremely fast/free compression/decompression-method +** http://liblzf.plan9.de/ +** +** This algorithm is believed to be patent-free. +** +***********************************************************************/ + +#define LZF_VERSION 0x0105 /* 1.5, API version */ + +/* + * Compress in_len bytes stored at the memory block starting at + * in_data and write the result to out_data, up to a maximum length + * of out_len bytes. + * + * If the output buffer is not large enough or any error occurs return 0, + * otherwise return the number of bytes used, which might be considerably + * more than in_len (but less than 104% of the original size), so it + * makes sense to always use out_len == in_len - 1), to ensure _some_ + * compression, and store the data uncompressed otherwise (with a flag, of + * course. + * + * lzf_compress might use different algorithms on different systems and + * even different runs, thus might result in different compressed strings + * depending on the phase of the moon or similar factors. However, all + * these strings are architecture-independent and will result in the + * original data when decompressed using lzf_decompress. + * + * The buffers must not be overlapping. + * + * If the option LZF_STATE_ARG is enabled, an extra argument must be + * supplied which is not reflected in this header file. Refer to lzfP.h + * and lzf_c.c. + * + */ +unsigned int +lzf_compress (const void *const in_data, unsigned int in_len, + void *out_data, unsigned int out_len); + +/* + * Decompress data compressed with some version of the lzf_compress + * function and stored at location in_data and length in_len. The result + * will be stored at out_data up to a maximum of out_len characters. + * + * If the output buffer is not large enough to hold the decompressed + * data, a 0 is returned and errno is set to E2BIG. Otherwise the number + * of decompressed bytes (i.e. the original length of the data) is + * returned. + * + * If an error in the compressed data is detected, a zero is returned and + * errno is set to EINVAL. + * + * This function is very fast, about as fast as a copying loop. + */ +unsigned int +lzf_decompress (const void *const in_data, unsigned int in_len, + void *out_data, unsigned int out_len); + +#endif + diff --git a/src/lzf/lzfP.h b/src/lzf/lzfP.h new file mode 100644 index 000000000..1fae96a32 --- /dev/null +++ b/src/lzf/lzfP.h @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2000-2007 Marc Alexander Lehmann + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License ("GPL") version 2 or any later version, + * in which case the provisions of the GPL are applicable instead of + * the above. If you wish to allow the use of your version of this file + * only under the terms of the GPL and not to allow others to use your + * version of this file under the BSD license, indicate your decision + * by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL. If you do not delete the + * provisions above, a recipient may use your version of this file under + * either the BSD or the GPL. + */ + +#ifndef LZFP_h +#define LZFP_h + +#define STANDALONE 1 /* at the moment, this is ok. */ + +#ifndef STANDALONE +# include "lzf.h" +#endif + +/* + * Size of hashtable is (1 << HLOG) * sizeof (char *) + * decompression is independent of the hash table size + * the difference between 15 and 14 is very small + * for small blocks (and 14 is usually a bit faster). + * For a low-memory/faster configuration, use HLOG == 13; + * For best compression, use 15 or 16 (or more, up to 22). + */ +#ifndef HLOG +# define HLOG 16 +#endif + +/* + * Sacrifice very little compression quality in favour of compression speed. + * This gives almost the same compression as the default code, and is + * (very roughly) 15% faster. This is the preferred mode of operation. + */ +#ifndef VERY_FAST +# define VERY_FAST 1 +#endif + +/* + * Sacrifice some more compression quality in favour of compression speed. + * (roughly 1-2% worse compression for large blocks and + * 9-10% for small, redundant, blocks and >>20% better speed in both cases) + * In short: when in need for speed, enable this for binary data, + * possibly disable this for text data. + */ +#ifndef ULTRA_FAST +# define ULTRA_FAST 1 +#endif + +/* + * Unconditionally aligning does not cost very much, so do it if unsure + */ +#ifndef STRICT_ALIGN +# define STRICT_ALIGN !(defined(__i386) || defined (__amd64)) +#endif + +/* + * You may choose to pre-set the hash table (might be faster on some + * modern cpus and large (>>64k) blocks, and also makes compression + * deterministic/repeatable when the configuration otherwise is the same). + */ +#ifndef INIT_HTAB +# define INIT_HTAB 1 +#endif + +/* + * Avoid assigning values to errno variable? for some embedding purposes + * (linux kernel for example), this is necessary. NOTE: this breaks + * the documentation in lzf.h. Avoiding errno has no speed impact. + */ +#ifndef AVOID_ERRNO +# define AVOID_ERRNO 0 +#endif + +/* + * Whether to pass the LZF_STATE variable as argument, or allocate it + * on the stack. For small-stack environments, define this to 1. + * NOTE: this breaks the prototype in lzf.h. + */ +#ifndef LZF_STATE_ARG +# define LZF_STATE_ARG 0 +#endif + +/* + * Whether to add extra checks for input validity in lzf_decompress + * and return EINVAL if the input stream has been corrupted. This + * only shields against overflowing the input buffer and will not + * detect most corrupted streams. + * This check is not normally noticeable on modern hardware + * (<1% slowdown), but might slow down older cpus considerably. + */ +#ifndef CHECK_INPUT +# define CHECK_INPUT 1 +#endif + +/* + * Whether to store pointers or offsets inside the hash table. On + * 64 bit architetcures, pointers take up twice as much space, + * and might also be slower. Default is to autodetect. + */ +/*#define LZF_USER_OFFSETS autodetect */ + +/*****************************************************************************/ +/* nothing should be changed below */ + +#ifdef __cplusplus +# include +# include +using namespace std; +#else +# include +# include +#endif + +#ifndef LZF_USE_OFFSETS +# if defined (WIN32) +# define LZF_USE_OFFSETS defined(_M_X64) +# else +# if __cplusplus > 199711L +# include +# else +# include +# endif +# define LZF_USE_OFFSETS (UINTPTR_MAX > 0xffffffffU) +# endif +#endif + +typedef unsigned char u8; + +#if LZF_USE_OFFSETS +# define LZF_HSLOT_BIAS ((const u8 *)in_data) + typedef unsigned int LZF_HSLOT; +#else +# define LZF_HSLOT_BIAS 0 + typedef const u8 *LZF_HSLOT; +#endif + +typedef LZF_HSLOT LZF_STATE[1 << (HLOG)]; + +#if !STRICT_ALIGN +/* for unaligned accesses we need a 16 bit datatype. */ +# if USHRT_MAX == 65535 + typedef unsigned short u16; +# elif UINT_MAX == 65535 + typedef unsigned int u16; +# else +# undef STRICT_ALIGN +# define STRICT_ALIGN 1 +# endif +#endif + +#if ULTRA_FAST +# undef VERY_FAST +#endif + +#endif + diff --git a/src/lzf/lzf_c.c b/src/lzf/lzf_c.c new file mode 100644 index 000000000..bc07084b8 --- /dev/null +++ b/src/lzf/lzf_c.c @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2000-2010 Marc Alexander Lehmann + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License ("GPL") version 2 or any later version, + * in which case the provisions of the GPL are applicable instead of + * the above. If you wish to allow the use of your version of this file + * only under the terms of the GPL and not to allow others to use your + * version of this file under the BSD license, indicate your decision + * by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL. If you do not delete the + * provisions above, a recipient may use your version of this file under + * either the BSD or the GPL. + */ + +#include "lzfP.h" + +#define HSIZE (1 << (HLOG)) + +/* + * don't play with this unless you benchmark! + * the data format is not dependent on the hash function. + * the hash function might seem strange, just believe me, + * it works ;) + */ +#ifndef FRST +# define FRST(p) (((p[0]) << 8) | p[1]) +# define NEXT(v,p) (((v) << 8) | p[2]) +# if ULTRA_FAST +# define IDX(h) ((( h >> (3*8 - HLOG)) - h ) & (HSIZE - 1)) +# elif VERY_FAST +# define IDX(h) ((( h >> (3*8 - HLOG)) - h*5) & (HSIZE - 1)) +# else +# define IDX(h) ((((h ^ (h << 5)) >> (3*8 - HLOG)) - h*5) & (HSIZE - 1)) +# endif +#endif +/* + * IDX works because it is very similar to a multiplicative hash, e.g. + * ((h * 57321 >> (3*8 - HLOG)) & (HSIZE - 1)) + * the latter is also quite fast on newer CPUs, and compresses similarly. + * + * the next one is also quite good, albeit slow ;) + * (int)(cos(h & 0xffffff) * 1e6) + */ + +#if 0 +/* original lzv-like hash function, much worse and thus slower */ +# define FRST(p) (p[0] << 5) ^ p[1] +# define NEXT(v,p) ((v) << 5) ^ p[2] +# define IDX(h) ((h) & (HSIZE - 1)) +#endif + +#define MAX_LIT (1 << 5) +#define MAX_OFF (1 << 13) +#define MAX_REF ((1 << 8) + (1 << 3)) + +#if __GNUC__ >= 3 +# define expect(expr,value) __builtin_expect ((expr),(value)) +# define inline inline +#else +# define expect(expr,value) (expr) +# define inline static +#endif + +#define expect_false(expr) expect ((expr) != 0, 0) +#define expect_true(expr) expect ((expr) != 0, 1) + +/* + * compressed format + * + * 000LLLLL ; literal, L+1=1..33 octets + * LLLooooo oooooooo ; backref L+1=1..7 octets, o+1=1..4096 offset + * 111ooooo LLLLLLLL oooooooo ; backref L+8 octets, o+1=1..4096 offset + * + */ + +unsigned int +lzf_compress (const void *const in_data, unsigned int in_len, + void *out_data, unsigned int out_len +#if LZF_STATE_ARG + , LZF_STATE htab +#endif + ) +{ +#if !LZF_STATE_ARG + LZF_STATE htab; +#endif + const u8 *ip = (const u8 *)in_data; + u8 *op = (u8 *)out_data; + const u8 *in_end = ip + in_len; + u8 *out_end = op + out_len; + const u8 *ref; + + /* off requires a type wide enough to hold a general pointer difference. + * ISO C doesn't have that (size_t might not be enough and ptrdiff_t only + * works for differences within a single object). We also assume that no + * no bit pattern traps. Since the only platform that is both non-POSIX + * and fails to support both assumptions is windows 64 bit, we make a + * special workaround for it. + */ +#if defined (WIN32) && defined (_M_X64) + unsigned _int64 off; /* workaround for missing POSIX compliance */ +#else + unsigned long off; +#endif + unsigned int hval; + int lit; + + if (!in_len || !out_len) + return 0; + +#if INIT_HTAB + memset (htab, 0, sizeof (htab)); +#endif + + lit = 0; op++; /* start run */ + + hval = FRST (ip); + while (ip < in_end - 2) + { + LZF_HSLOT *hslot; + + hval = NEXT (hval, ip); + hslot = htab + IDX (hval); + ref = *hslot + LZF_HSLOT_BIAS; *hslot = ip - LZF_HSLOT_BIAS; + + if (1 +#if INIT_HTAB + && ref < ip /* the next test will actually take care of this, but this is faster */ +#endif + && (off = ip - ref - 1) < MAX_OFF + && ref > (u8 *)in_data + && ref[2] == ip[2] +#if STRICT_ALIGN + && ((ref[1] << 8) | ref[0]) == ((ip[1] << 8) | ip[0]) +#else + && *(u16 *)ref == *(u16 *)ip +#endif + ) + { + /* match found at *ref++ */ + unsigned int len = 2; + unsigned int maxlen = in_end - ip - len; + maxlen = maxlen > MAX_REF ? MAX_REF : maxlen; + + if (expect_false (op + 3 + 1 >= out_end)) /* first a faster conservative test */ + if (op - !lit + 3 + 1 >= out_end) /* second the exact but rare test */ + return 0; + + op [- lit - 1] = lit - 1; /* stop run */ + op -= !lit; /* undo run if length is zero */ + + for (;;) + { + if (expect_true (maxlen > 16)) + { + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + len++; if (ref [len] != ip [len]) break; + } + + do + len++; + while (len < maxlen && ref[len] == ip[len]); + + break; + } + + len -= 2; /* len is now #octets - 1 */ + ip++; + + if (len < 7) + { + *op++ = (off >> 8) + (len << 5); + } + else + { + *op++ = (off >> 8) + ( 7 << 5); + *op++ = len - 7; + } + + *op++ = off; + + lit = 0; op++; /* start run */ + + ip += len + 1; + + if (expect_false (ip >= in_end - 2)) + break; + +#if ULTRA_FAST || VERY_FAST + --ip; +# if VERY_FAST && !ULTRA_FAST + --ip; +# endif + hval = FRST (ip); + + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip - LZF_HSLOT_BIAS; + ip++; + +# if VERY_FAST && !ULTRA_FAST + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip - LZF_HSLOT_BIAS; + ip++; +# endif +#else + ip -= len + 1; + + do + { + hval = NEXT (hval, ip); + htab[IDX (hval)] = ip - LZF_HSLOT_BIAS; + ip++; + } + while (len--); +#endif + } + else + { + /* one more literal byte we must copy */ + if (expect_false (op >= out_end)) + return 0; + + lit++; *op++ = *ip++; + + if (expect_false (lit == MAX_LIT)) + { + op [- lit - 1] = lit - 1; /* stop run */ + lit = 0; op++; /* start run */ + } + } + } + + if (op + 3 > out_end) /* at most 3 bytes can be missing here */ + return 0; + + while (ip < in_end) + { + lit++; *op++ = *ip++; + + if (expect_false (lit == MAX_LIT)) + { + op [- lit - 1] = lit - 1; /* stop run */ + lit = 0; op++; /* start run */ + } + } + + op [- lit - 1] = lit - 1; /* end run */ + op -= !lit; /* undo run if length is zero */ + + return op - (u8 *)out_data; +} + diff --git a/src/lzf/lzf_d.c b/src/lzf/lzf_d.c new file mode 100644 index 000000000..8433b8f1f --- /dev/null +++ b/src/lzf/lzf_d.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2000-2010 Marc Alexander Lehmann + * + * Redistribution and use in source and binary forms, with or without modifica- + * tion, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- + * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- + * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- + * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Alternatively, the contents of this file may be used under the terms of + * the GNU General Public License ("GPL") version 2 or any later version, + * in which case the provisions of the GPL are applicable instead of + * the above. If you wish to allow the use of your version of this file + * only under the terms of the GPL and not to allow others to use your + * version of this file under the BSD license, indicate your decision + * by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL. If you do not delete the + * provisions above, a recipient may use your version of this file under + * either the BSD or the GPL. + */ + +#include "lzfP.h" + +#if AVOID_ERRNO +# define SET_ERRNO(n) +#else +# include +# define SET_ERRNO(n) errno = (n) +#endif + +#if USE_REP_MOVSB /* small win on amd, big loss on intel */ +#if (__i386 || __amd64) && __GNUC__ >= 3 +# define lzf_movsb(dst, src, len) \ + asm ("rep movsb" \ + : "=D" (dst), "=S" (src), "=c" (len) \ + : "0" (dst), "1" (src), "2" (len)); +#endif +#endif + +unsigned int +lzf_decompress (const void *const in_data, unsigned int in_len, + void *out_data, unsigned int out_len) +{ + u8 const *ip = (const u8 *)in_data; + u8 *op = (u8 *)out_data; + u8 const *const in_end = ip + in_len; + u8 *const out_end = op + out_len; + + do + { + unsigned int ctrl = *ip++; + + if (ctrl < (1 << 5)) /* literal run */ + { + ctrl++; + + if (op + ctrl > out_end) + { + SET_ERRNO (E2BIG); + return 0; + } + +#if CHECK_INPUT + if (ip + ctrl > in_end) + { + SET_ERRNO (EINVAL); + return 0; + } +#endif + +#ifdef lzf_movsb + lzf_movsb (op, ip, ctrl); +#else + switch (ctrl) + { + case 32: *op++ = *ip++; case 31: *op++ = *ip++; case 30: *op++ = *ip++; case 29: *op++ = *ip++; + case 28: *op++ = *ip++; case 27: *op++ = *ip++; case 26: *op++ = *ip++; case 25: *op++ = *ip++; + case 24: *op++ = *ip++; case 23: *op++ = *ip++; case 22: *op++ = *ip++; case 21: *op++ = *ip++; + case 20: *op++ = *ip++; case 19: *op++ = *ip++; case 18: *op++ = *ip++; case 17: *op++ = *ip++; + case 16: *op++ = *ip++; case 15: *op++ = *ip++; case 14: *op++ = *ip++; case 13: *op++ = *ip++; + case 12: *op++ = *ip++; case 11: *op++ = *ip++; case 10: *op++ = *ip++; case 9: *op++ = *ip++; + case 8: *op++ = *ip++; case 7: *op++ = *ip++; case 6: *op++ = *ip++; case 5: *op++ = *ip++; + case 4: *op++ = *ip++; case 3: *op++ = *ip++; case 2: *op++ = *ip++; case 1: *op++ = *ip++; + } +#endif + } + else /* back reference */ + { + unsigned int len = ctrl >> 5; + + u8 *ref = op - ((ctrl & 0x1f) << 8) - 1; + +#if CHECK_INPUT + if (ip >= in_end) + { + SET_ERRNO (EINVAL); + return 0; + } +#endif + if (len == 7) + { + len += *ip++; +#if CHECK_INPUT + if (ip >= in_end) + { + SET_ERRNO (EINVAL); + return 0; + } +#endif + } + + ref -= *ip++; + + if (op + len + 2 > out_end) + { + SET_ERRNO (E2BIG); + return 0; + } + + if (ref < (u8 *)out_data) + { + SET_ERRNO (EINVAL); + return 0; + } + +#ifdef lzf_movsb + len += 2; + lzf_movsb (op, ref, len); +#else + switch (len) + { + default: + len += 2; + + if (op >= ref + len) + { + /* disjunct areas */ + memcpy (op, ref, len); + op += len; + } + else + { + /* overlapping, use octte by octte copying */ + do + *op++ = *ref++; + while (--len); + } + + break; + + case 9: *op++ = *ref++; + case 8: *op++ = *ref++; + case 7: *op++ = *ref++; + case 6: *op++ = *ref++; + case 5: *op++ = *ref++; + case 4: *op++ = *ref++; + case 3: *op++ = *ref++; + case 2: *op++ = *ref++; + case 1: *op++ = *ref++; + case 0: *op++ = *ref++; /* two octets more */ + *op++ = *ref++; + } +#endif + } + } + while (ip < in_end); + + return op - (u8 *)out_data; +} + diff --git a/src/mem.c b/src/mem.c index a4e12e3fd..18507f95b 100644 --- a/src/mem.c +++ b/src/mem.c @@ -665,14 +665,6 @@ int loadbios() biosmask = 0x1ffff; return 1; - case ROM_P54TP4XE: - f = romfopen("roms/p54tp4xe/T15I0302.AWD", "rb"); - if (!f) break; - fread(rom, 0x20000, 1, f); - fclose(f); - biosmask = 0x1ffff; - return 1; - case ROM_ACERM3A: f = romfopen("roms/acerm3a/r01-b3.bin", "rb"); if (!f) break; @@ -689,22 +681,6 @@ int loadbios() biosmask = 0x1ffff; return 1; - case ROM_P55T2P4: - f = romfopen("roms/p55t2p4/0207_J2.BIN", "rb"); - if (!f) break; - fread(rom, 0x20000, 1, f); - fclose(f); - biosmask = 0x1ffff; - return 1; - - case ROM_P55TVP4: - f = romfopen("roms/p55tvp4/tv5i0201.awd", "rb"); - if (!f) break; - fread(rom, 0x20000, 1, f); - fclose(f); - biosmask = 0x1ffff; - return 1; - case ROM_P55VA: f = romfopen("roms/p55va/VA021297.BIN", "rb"); if (!f) break; @@ -721,14 +697,6 @@ int loadbios() biosmask = 0x1ffff; return 1; - case ROM_KN97: - f = romfopen("roms/kn97/NAKI0116.AWD", "rb"); - if (!f) break; - fread(rom, 0x20000, 1, f); - fclose(f); - biosmask = 0x1ffff; - return 1; - case ROM_MARL: f = romfopen("roms/marl/1008DB0_.BIO", "rb"); if (!f) break; @@ -1961,7 +1929,7 @@ void mem_add_bios() } int mem_a20_key = 0, mem_a20_alt = 0; -static int mem_a20_state = 1; +int mem_a20_state = 1; void mem_init() { diff --git a/src/memregs.c b/src/memregs.c index b01f2a8e9..578f9e3d4 100644 --- a/src/memregs.c +++ b/src/memregs.c @@ -25,8 +25,6 @@ uint8_t memregs_read(uint16_t port, void *priv) void memregs_init() { - int i = 0; - pclog("Memory Registers Init\n"); io_sethandler(0x00e1, 0x0002, memregs_read, NULL, NULL, memregs_write, NULL, NULL, NULL); diff --git a/src/model.c b/src/model.c index af024c902..dd226764e 100644 --- a/src/model.c +++ b/src/model.c @@ -98,12 +98,10 @@ void at_mb500n_init(); void at_acerm3a_init(); void at_acerv35n_init(); // void at_p55t2p4_init(); -void at_p55tvp4_init(); +// void at_p55tvp4_init(); void at_marl_init(); void at_p55va_init(); void at_i440fx_init(); -void at_kn97_init(); -void at_deskpro2k_init(); int model; @@ -165,11 +163,9 @@ MODEL models[] = // {"ASUS P/I-P55T2P4", ROM_P55T2P4, { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, 1, 1, 512, 1, at_p55t2p4_init}, {"Award 430VX PCI", ROM_430VX, { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, 1, 1, 256, 1, at_i430vx_init}, {"Epox P55-VA", ROM_P55VA, { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, 1, 1, 256, 1, at_p55va_init}, - {"ASUS P/I-P55TVP4", ROM_P55TVP4, { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, 1, 1, 256, 1, at_p55tvp4_init}, +/* {"ASUS P/I-P55TVP4", ROM_P55TVP4, { "Intel", cpus_Pentium, "IDT", cpus_WinChip, "Cyrix", cpus_6x86, "AMD", cpus_K56, "", NULL}, 0, 1, 1, 256, 1, at_p55tvp4_init}, */ {"Award 440FX PCI", ROM_440FX, { "Intel", cpus_PentiumPro, "", NULL, "", NULL}, 0, 1, 1, 1024, 1, at_i440fx_init}, - {"Award KN97 (440FX PCI)",ROM_KN97, { "Intel", cpus_PentiumPro, "", NULL, "", NULL}, 0, 1, 1, 1024, 1, at_kn97_init}, // {"Award 440FX PCI", ROM_440FX, { "Intel", cpus_PentiumPro,"Klamath", cpus_Pentium2, "Deschutes", cpus_Pentium2D}, 0, 1, 1, 1024, 1, at_i440fx_init}, - // {"Award KN97 (440FX PCI)",ROM_KN97, { "Intel", cpus_PentiumPro,"Klamath", cpus_Pentium2, "Deschutes", cpus_Pentium2D}, 0, 1, 1, 1024, 1, at_kn97_init}, {"", -1, {"", 0, "", 0, "", 0}, 0,0,0, 0} }; @@ -596,6 +592,7 @@ void at_i430vx_init() // rom_t ami_ec_rom; +#if 0 void at_p55tvp4_init() { at_init(); @@ -614,6 +611,7 @@ void at_p55tvp4_init() if (cdrom_channel >= 4) ide_ter_init(); } +#endif void at_p55va_init() { @@ -641,19 +639,6 @@ void at_i440fx_init() if (cdrom_channel >= 4) ide_ter_init(); } -void at_kn97_init() -{ - at_init(); - memregs_init(); - mouse_always_serial ? mouse_serial_init() : mouse_ps2_init(); - pci_init(PCI_CONFIG_TYPE_1, 0, 31); - i440fx_init(); - piix3_init(7); - w83877f_init(); - device_add(&intel_flash_bxt_device); - if (cdrom_channel >= 4) ide_ter_init(); -} - void model_init() { pclog("Initting as %s\n", model_getname()); diff --git a/src/mouse_ps2.c b/src/mouse_ps2.c index 07064f3dc..db45e78f0 100644 --- a/src/mouse_ps2.c +++ b/src/mouse_ps2.c @@ -26,7 +26,6 @@ static struct uint8_t flags; uint8_t resolution; uint8_t sample_rate; - uint8_t type; uint8_t command; diff --git a/src/mouse_serial.c b/src/mouse_serial.c index 0b9456bbd..403873361 100644 --- a/src/mouse_serial.c +++ b/src/mouse_serial.c @@ -25,8 +25,8 @@ void mouse_serial_poll(int x, int y, int b) /*Use Microsoft format*/ mousedat[0]=0x40; - mousedat[0]|=(((y>>6)&3)<<2); - mousedat[0]|=((x>>6)&3); + mousedat[0]|=(((y / 64)&3)<<2); + mousedat[0]|=((x / 64)&3); if (b&1) mousedat[0]|=0x20; if (b&2) mousedat[0]|=0x10; mousedat[1]=x&0x3F; diff --git a/src/ne2000.c b/src/ne2000.c index f12230aa6..c8561ac15 100644 --- a/src/ne2000.c +++ b/src/ne2000.c @@ -461,13 +461,13 @@ uint32_t ne2000_chipmem_read(ne2000_t *ne2000, uint32_t address, unsigned int io // ROM'd MAC address if ((address >=0) && (address <= 31)) { - retval = ne2000->macaddr[address]; + retval = ne2000->macaddr[address % 32]; if ((io_len == 2) || (io_len == 4)) { - retval |= (ne2000->macaddr[address + 1] << 8); + retval |= (ne2000->macaddr[(address + 1) % 32] << 8); } if (io_len == 4) { - retval |= (ne2000->macaddr[address + 2] << 16); - retval |= (ne2000->macaddr[address + 3] << 24); + retval |= (ne2000->macaddr[(address + 2) % 32] << 16); + retval |= (ne2000->macaddr[(address + 3) % 32] << 24); } return (retval); } diff --git a/src/nvr.c b/src/nvr.c index d4190e5c5..2f760d7ea 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -231,10 +231,8 @@ void loadnvr() case ROM_MB500N: f = romfopen(nvr_concat("mb500n.nvr"), "rb"); nvrmask = 127; break; case ROM_ACERM3A: f = romfopen(nvr_concat("acerm3a.nvr"), "rb"); nvrmask = 127; break; case ROM_ACERV35N: f = romfopen(nvr_concat("acerv35n.nvr"), "rb"); nvrmask = 127; break; - case ROM_P55TVP4: f = romfopen(nvr_concat("p55tvp4.nvr"), "rb"); nvrmask = 127; break; case ROM_P55VA: f = romfopen(nvr_concat("p55va.nvr"), "rb"); nvrmask = 127; break; case ROM_440FX: f = romfopen(nvr_concat("440fx.nvr"), "rb"); nvrmask = 127; break; - case ROM_KN97: f = romfopen(nvr_concat("kn97.nvr"), "rb"); nvrmask = 127; break; case ROM_MARL: f = romfopen(nvr_concat("marl.nvr"), "rb"); nvrmask = 127; break; case ROM_THOR: f = romfopen(nvr_concat("thor.nvr"), "rb"); nvrmask = 127; break; default: return; @@ -301,10 +299,8 @@ void savenvr() case ROM_MB500N: f = romfopen(nvr_concat("mb500n.nvr"), "wb"); break; case ROM_ACERM3A: f = romfopen(nvr_concat("acerm3a.nvr"), "wb"); break; case ROM_ACERV35N: f = romfopen(nvr_concat("acerv35n.nvr"), "wb"); break; - case ROM_P55TVP4: f = romfopen(nvr_concat("p55tvp4.nvr"), "wb"); break; case ROM_P55VA: f = romfopen(nvr_concat("p55va.nvr"), "wb"); break; case ROM_440FX: f = romfopen(nvr_concat("440fx.nvr"), "wb"); break; - case ROM_KN97: f = romfopen(nvr_concat("kn97.nvr"), "wb"); break; case ROM_MARL: f = romfopen(nvr_concat("marl.nvr"), "wb"); break; case ROM_THOR: f = romfopen(nvr_concat("thor.nvr"), "wb"); break; default: return; diff --git a/src/pc.c b/src/pc.c index 31b6b02fb..2027f6a2f 100644 --- a/src/pc.c +++ b/src/pc.c @@ -273,7 +273,7 @@ void initpc(int argc, char *argv[]) sound_reset(); fdc_init(); disc_init(); - fdi_init(); + fdi_init(); img_init(); d86f_init(); td0_init(); diff --git a/src/pc87306.c b/src/pc87306.c index ce0ea4756..875014190 100644 --- a/src/pc87306.c +++ b/src/pc87306.c @@ -251,7 +251,7 @@ process_value: break; case 9: // pclog("Setting DENSEL polarity to: %i (before: %i)\n", (val & 0x40 ? 1 : 0), fdc_get_densel_polarity()); - fdc_update_densel_polarity(val & 0x40 ? 1 : 0); + fdc_update_densel_polarity((val & 0x40) ? 1 : 0); break; case 0xF: pc87306_gpio_init(); diff --git a/src/piix.c b/src/piix.c index fcb8988d4..c6a9775ca 100644 --- a/src/piix.c +++ b/src/piix.c @@ -35,7 +35,6 @@ void piix_write(int func, int addr, uint8_t val, void *priv) switch (addr) { case 0x04: - if (val & 0x10) resetide(); /* Only the ASUS boards attempt to modify this register - reset IDE when that happens. Fixes soft reset on the ASUS boards. */ card_piix_ide[0x04] = (card_piix_ide[0x04] & ~5) | (val & 5); break; case 0x07: @@ -52,18 +51,6 @@ void piix_write(int func, int addr, uint8_t val, void *priv) card_piix_ide[0x21] = val; break; -#if 0 - case 0x33: - /* Note by OBattler: This is a hack, but it's needed to reset the cylinders of the IDE devices. */ - if (romset != ROM_P55T2P4) break; - if (val != piix_33) - { - resetide(); - } - piix_33 = val; - break; -#endif - case 0x40: card_piix_ide[0x40] = val; break; diff --git a/src/rtc.c b/src/rtc.c index 9d7dc5344..eba9bfd53 100644 --- a/src/rtc.c +++ b/src/rtc.c @@ -164,8 +164,6 @@ static void time_internal_set(struct tm *time_var) static void time_set_nvrram(char *nvrram, struct tm *cur_time_tm) { - int dow, mon, year; - if (nvrram[RTC_REGB] & RTC_DM) { nvrram[RTC_SECONDS] = cur_time_tm->tm_sec; diff --git a/src/vid_ati_mach64.c b/src/vid_ati_mach64.c index 249447659..27bf01adb 100644 --- a/src/vid_ati_mach64.c +++ b/src/vid_ati_mach64.c @@ -875,6 +875,7 @@ void mach64_start_fill(mach64_t *mach64) mach64->accel.dst_width = (mach64->dst_height_width >> 16) & 0x1fff; mach64->accel.dst_height = mach64->dst_height_width & 0x1fff; mach64->accel.x_count = mach64->accel.dst_width; + mach64->accel.y_count = mach64->accel.dst_height; mach64->accel.src_x = 0; mach64->accel.src_y = 0; @@ -2574,7 +2575,6 @@ void mach64_pci_write(int func, int addr, uint8_t val, void *p) switch (addr) { case PCI_REG_COMMAND: - if (romset == ROM_KN97) return; mach64->pci_regs[PCI_REG_COMMAND] = val & 0x27; if (val & PCI_COMMAND_IO) mach64_io_set(mach64); diff --git a/src/vid_cl_gd.c b/src/vid_cl_gd.c index 4038e94af..b244f408a 100644 --- a/src/vid_cl_gd.c +++ b/src/vid_cl_gd.c @@ -208,7 +208,7 @@ uint8_t clgd_in(uint16_t addr, void *p) clgd_t *clgd = (clgd_t *)p; svga_t *svga = &clgd->svga; - if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3d0) && !(svga->miscout & 1)) + if ((((addr & 0xfff0) == 0x3d0) || (addr & 0xfff0) == 0x3d0) && !(svga->miscout & 1)) addr ^= 0x60; // if (addr != 0x3da) pclog("IN clgd %04X\n", addr); diff --git a/src/vid_colorplus.c b/src/vid_colorplus.c new file mode 100644 index 000000000..cb3ab38b3 --- /dev/null +++ b/src/vid_colorplus.c @@ -0,0 +1,470 @@ +/*Plantronics ColorPlus emulation*/ +#include +#include +#include "ibm.h" +#include "device.h" +#include "io.h" +#include "mem.h" +#include "timer.h" +#include "video.h" +#include "vid_cga.h" +#include "vid_colorplus.h" +#include "dosbox/vid_cga_comp.h" + +/* Bits in the colorplus control register: */ +#define COLORPLUS_PLANE_SWAP 0x40 /* Swap planes at 0000h and 4000h */ +#define COLORPLUS_640x200_MODE 0x20 /* 640x200x4 mode active */ +#define COLORPLUS_320x200_MODE 0x10 /* 320x200x16 mode active */ +#define COLORPLUS_EITHER_MODE 0x30 /* Either mode active */ + +/* Bits in the CGA graphics mode register */ +#define CGA_GRAPHICS_MODE 0x02 /* CGA graphics mode selected? */ + +#define CGA_RGB 0 +#define CGA_COMPOSITE 1 + +#define COMPOSITE_OLD 0 +#define COMPOSITE_NEW 1 + + +void cga_recalctimings(cga_t *cga); + +void colorplus_out(uint16_t addr, uint8_t val, void *p) +{ + colorplus_t *colorplus = (colorplus_t *)p; + +// pclog("COLORPLUS_OUT %04X %02X\n", addr, val); + if (addr == 0x3DD) + { + colorplus->control = val & 0x70; + } + else + { + cga_out(addr, val, &colorplus->cga); + } +} + +uint8_t colorplus_in(uint16_t addr, void *p) +{ + colorplus_t *colorplus = (colorplus_t *)p; + + return cga_in(addr, &colorplus->cga); +} + +void colorplus_write(uint32_t addr, uint8_t val, void *p) +{ + colorplus_t *colorplus = (colorplus_t *)p; + +// pclog("COLORPLUS_WRITE %04X %02X\n", addr, val); + if ((colorplus->control & COLORPLUS_PLANE_SWAP) && + (colorplus->control & COLORPLUS_EITHER_MODE) && + (colorplus->cga.cgamode & CGA_GRAPHICS_MODE)) + { + addr ^= 0x4000; + } + else if (!(colorplus->control & COLORPLUS_EITHER_MODE)) + { + addr &= 0x3FFF; + } + colorplus->cga.vram[addr & 0x7fff] = val; + if (colorplus->cga.snow_enabled) + { + colorplus->cga.charbuffer[ ((int)(((colorplus->cga.dispontime - colorplus->cga.vidtime) * 2) / CGACONST)) & 0xfc] = val; + colorplus->cga.charbuffer[(((int)(((colorplus->cga.dispontime - colorplus->cga.vidtime) * 2) / CGACONST)) & 0xfc) | 1] = val; + } + egawrites++; + cycles -= 4; +} + +uint8_t colorplus_read(uint32_t addr, void *p) +{ + colorplus_t *colorplus = (colorplus_t *)p; + + if ((colorplus->control & COLORPLUS_PLANE_SWAP) && + (colorplus->control & COLORPLUS_EITHER_MODE) && + (colorplus->cga.cgamode & CGA_GRAPHICS_MODE)) + { + addr ^= 0x4000; + } + else if (!(colorplus->control & COLORPLUS_EITHER_MODE)) + { + addr &= 0x3FFF; + } + cycles -= 4; + if (colorplus->cga.snow_enabled) + { + colorplus->cga.charbuffer[ ((int)(((colorplus->cga.dispontime - colorplus->cga.vidtime) * 2) / CGACONST)) & 0xfc] = colorplus->cga.vram[addr & 0x7fff]; + colorplus->cga.charbuffer[(((int)(((colorplus->cga.dispontime - colorplus->cga.vidtime) * 2) / CGACONST)) & 0xfc) | 1] = colorplus->cga.vram[addr & 0x7fff]; + } + egareads++; +// pclog("COLORPLUS_READ %04X\n", addr); + return colorplus->cga.vram[addr & 0x7fff]; +} + +void colorplus_recalctimings(colorplus_t *colorplus) +{ + cga_recalctimings(&colorplus->cga); +} + +void colorplus_poll(void *p) +{ + colorplus_t *colorplus = (colorplus_t *)p; + int x, c; + int oldvc; + uint16_t dat0, dat1; + int cols[4]; + int col; + int oldsc; + static const int cols16[16] = { 0x10,0x12,0x14,0x16, + 0x18,0x1A,0x1C,0x1E, + 0x11,0x13,0x15,0x17, + 0x19,0x1B,0x1D,0x1F }; + uint8_t *plane0 = colorplus->cga.vram; + uint8_t *plane1 = colorplus->cga.vram + 0x4000; + + /* If one of the extra modes is not selected, drop down to the CGA + * drawing code. */ + if (!((colorplus->control & COLORPLUS_EITHER_MODE) && + (colorplus->cga.cgamode & CGA_GRAPHICS_MODE))) + { + cga_poll(&colorplus->cga); + return; + } + + if (!colorplus->cga.linepos) + { + colorplus->cga.vidtime += colorplus->cga.dispofftime; + colorplus->cga.cgastat |= 1; + colorplus->cga.linepos = 1; + oldsc = colorplus->cga.sc; + if ((colorplus->cga.crtc[8] & 3) == 3) + colorplus->cga.sc = ((colorplus->cga.sc << 1) + colorplus->cga.oddeven) & 7; + if (colorplus->cga.cgadispon) + { + if (colorplus->cga.displine < colorplus->cga.firstline) + { + colorplus->cga.firstline = colorplus->cga.displine; + video_wait_for_buffer(); +// printf("Firstline %i\n",firstline); + } + colorplus->cga.lastline = colorplus->cga.displine; + /* Left / right border */ + for (c = 0; c < 8; c++) + { + buffer->line[colorplus->cga.displine][c] = + buffer->line[colorplus->cga.displine][c + (colorplus->cga.crtc[1] << 4) + 8] = (colorplus->cga.cgacol & 15) + 16; + } + if (colorplus->control & COLORPLUS_320x200_MODE) + { + for (x = 0; x < colorplus->cga.crtc[1]; x++) + { + dat0 = (plane0[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000)] << 8) | + plane0[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000) + 1]; + dat1 = (plane1[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000)] << 8) | + plane1[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000) + 1]; + colorplus->cga.ma++; + for (c = 0; c < 8; c++) + { + buffer->line[colorplus->cga.displine][(x << 4) + (c << 1) + 8] = + buffer->line[colorplus->cga.displine][(x << 4) + (c << 1) + 1 + 8] = + cols16[(dat0 >> 14) | ((dat1 >> 14) << 2)]; + dat0 <<= 2; + dat1 <<= 2; + } + } + } + else if (colorplus->control & COLORPLUS_640x200_MODE) + { + cols[0] = (colorplus->cga.cgacol & 15) | 16; + col = (colorplus->cga.cgacol & 16) ? 24 : 16; + if (colorplus->cga.cgamode & 4) + { + cols[1] = col | 3; + cols[2] = col | 4; + cols[3] = col | 7; + } + else if (colorplus->cga.cgacol & 32) + { + cols[1] = col | 3; + cols[2] = col | 5; + cols[3] = col | 7; + } + else + { + cols[1] = col | 2; + cols[2] = col | 4; + cols[3] = col | 6; + } + for (x = 0; x < colorplus->cga.crtc[1]; x++) + { + dat0 = (plane0[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000)] << 8) | + plane0[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000) + 1]; + dat1 = (plane1[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000)] << 8) | + plane1[((colorplus->cga.ma << 1) & 0x1fff) + ((colorplus->cga.sc & 1) * 0x2000) + 1]; + colorplus->cga.ma++; + for (c = 0; c < 16; c++) + { + buffer->line[colorplus->cga.displine][(x << 4) + c + 8] = + cols[(dat0 >> 15) | ((dat1 >> 15) << 1)]; + dat0 <<= 1; + dat1 <<= 1; + } + } + } + } + else /* Top / bottom border */ + { + cols[0] = (colorplus->cga.cgacol & 15) + 16; + hline(buffer, 0, colorplus->cga.displine, (colorplus->cga.crtc[1] << 4) + 16, cols[0]); + } + + x = (colorplus->cga.crtc[1] << 4) + 16; + + if (colorplus->cga.composite) + { + for (c = 0; c < x; c++) + buffer32->line[colorplus->cga.displine][c] = buffer->line[colorplus->cga.displine][c] & 0xf; + + Composite_Process(&colorplus->cga, 0, x >> 2, buffer32->line[colorplus->cga.displine]); + } + + colorplus->cga.sc = oldsc; + if (colorplus->cga.vc == colorplus->cga.crtc[7] && !colorplus->cga.sc) + colorplus->cga.cgastat |= 8; + colorplus->cga.displine++; + if (colorplus->cga.displine >= 360) + colorplus->cga.displine = 0; + } + else + { + colorplus->cga.vidtime += colorplus->cga.dispontime; + colorplus->cga.linepos = 0; + if (colorplus->cga.vsynctime) + { + colorplus->cga.vsynctime--; + if (!colorplus->cga.vsynctime) + colorplus->cga.cgastat &= ~8; + } + if (colorplus->cga.sc == (colorplus->cga.crtc[11] & 31) || ((colorplus->cga.crtc[8] & 3) == 3 && colorplus->cga.sc == ((colorplus->cga.crtc[11] & 31) >> 1))) + { + colorplus->cga.con = 0; + colorplus->cga.coff = 1; + } + if ((colorplus->cga.crtc[8] & 3) == 3 && colorplus->cga.sc == (colorplus->cga.crtc[9] >> 1)) + colorplus->cga.maback = colorplus->cga.ma; + if (colorplus->cga.vadj) + { + colorplus->cga.sc++; + colorplus->cga.sc &= 31; + colorplus->cga.ma = colorplus->cga.maback; + colorplus->cga.vadj--; + if (!colorplus->cga.vadj) + { + colorplus->cga.cgadispon = 1; + colorplus->cga.ma = colorplus->cga.maback = (colorplus->cga.crtc[13] | (colorplus->cga.crtc[12] << 8)) & 0x3fff; + colorplus->cga.sc = 0; + } + } + else if (colorplus->cga.sc == colorplus->cga.crtc[9]) + { + colorplus->cga.maback = colorplus->cga.ma; + colorplus->cga.sc = 0; + oldvc = colorplus->cga.vc; + colorplus->cga.vc++; + colorplus->cga.vc &= 127; + + if (colorplus->cga.vc == colorplus->cga.crtc[6]) + colorplus->cga.cgadispon = 0; + + if (oldvc == colorplus->cga.crtc[4]) + { + colorplus->cga.vc = 0; + colorplus->cga.vadj = colorplus->cga.crtc[5]; + if (!colorplus->cga.vadj) colorplus->cga.cgadispon = 1; + if (!colorplus->cga.vadj) colorplus->cga.ma = colorplus->cga.maback = (colorplus->cga.crtc[13] | (colorplus->cga.crtc[12] << 8)) & 0x3fff; + if ((colorplus->cga.crtc[10] & 0x60) == 0x20) colorplus->cga.cursoron = 0; + else colorplus->cga.cursoron = colorplus->cga.cgablink & 8; + } + + if (colorplus->cga.vc == colorplus->cga.crtc[7]) + { + colorplus->cga.cgadispon = 0; + colorplus->cga.displine = 0; + colorplus->cga.vsynctime = 16; + if (colorplus->cga.crtc[7]) + { + if (colorplus->cga.cgamode & 1) x = (colorplus->cga.crtc[1] << 3) + 16; + else x = (colorplus->cga.crtc[1] << 4) + 16; + colorplus->cga.lastline++; + if (x != xsize || (colorplus->cga.lastline - colorplus->cga.firstline) != ysize) + { + xsize = x; + ysize = colorplus->cga.lastline - colorplus->cga.firstline; + if (xsize < 64) xsize = 656; + if (ysize < 32) ysize = 200; + updatewindowsize(xsize, (ysize << 1) + 16); + } + + if (colorplus->cga.composite) + video_blit_memtoscreen(0, colorplus->cga.firstline - 4, 0, (colorplus->cga.lastline - colorplus->cga.firstline) + 8, xsize, (colorplus->cga.lastline - colorplus->cga.firstline) + 8); + else + video_blit_memtoscreen_8(0, colorplus->cga.firstline - 4, xsize, (colorplus->cga.lastline - colorplus->cga.firstline) + 8); + frames++; + + video_res_x = xsize - 16; + video_res_y = ysize; + if (colorplus->cga.cgamode & 1) + { + video_res_x /= 8; + video_res_y /= colorplus->cga.crtc[9] + 1; + video_bpp = 0; + } + else if (!(colorplus->cga.cgamode & 2)) + { + video_res_x /= 16; + video_res_y /= colorplus->cga.crtc[9] + 1; + video_bpp = 0; + } + else if (!(colorplus->cga.cgamode & 16)) + { + video_res_x /= 2; + video_bpp = 2; + } + else + { + video_bpp = 1; + } + } + colorplus->cga.firstline = 1000; + colorplus->cga.lastline = 0; + colorplus->cga.cgablink++; + colorplus->cga.oddeven ^= 1; + } + } + else + { + colorplus->cga.sc++; + colorplus->cga.sc &= 31; + colorplus->cga.ma = colorplus->cga.maback; + } + if (colorplus->cga.cgadispon) + colorplus->cga.cgastat &= ~1; + if ((colorplus->cga.sc == (colorplus->cga.crtc[10] & 31) || ((colorplus->cga.crtc[8] & 3) == 3 && colorplus->cga.sc == ((colorplus->cga.crtc[10] & 31) >> 1)))) + colorplus->cga.con = 1; + if (colorplus->cga.cgadispon && (colorplus->cga.cgamode & 1)) + { + for (x = 0; x < (colorplus->cga.crtc[1] << 1); x++) + colorplus->cga.charbuffer[x] = colorplus->cga.vram[(((colorplus->cga.ma << 1) + x) & 0x3fff)]; + } + } +} + +void colorplus_init(colorplus_t *colorplus) +{ + cga_init(&colorplus->cga); +} + +void *colorplus_standalone_init() +{ + int display_type; + + colorplus_t *colorplus = malloc(sizeof(colorplus_t)); + memset(colorplus, 0, sizeof(colorplus_t)); + + /* Copied from the CGA init. Ideally this would be done by + * calling a helper function rather than duplicating code */ + display_type = device_get_config_int("display_type"); + colorplus->cga.composite = (display_type != CGA_RGB); + colorplus->cga.revision = device_get_config_int("composite_type"); + colorplus->cga.snow_enabled = device_get_config_int("snow_enabled"); + + colorplus->cga.vram = malloc(0x8000); + + cga_comp_init(&colorplus->cga); + timer_add(colorplus_poll, &colorplus->cga.vidtime, TIMER_ALWAYS_ENABLED, colorplus); + mem_mapping_add(&colorplus->cga.mapping, 0xb8000, 0x08000, colorplus_read, NULL, NULL, colorplus_write, NULL, NULL, NULL, 0, colorplus); + io_sethandler(0x03d0, 0x0010, colorplus_in, NULL, NULL, colorplus_out, NULL, NULL, colorplus); + + return colorplus; +} + +void colorplus_close(void *p) +{ + colorplus_t *colorplus = (colorplus_t *)p; + + free(colorplus->cga.vram); + free(colorplus); +} + +void colorplus_speed_changed(void *p) +{ + colorplus_t *colorplus = (colorplus_t *)p; + + cga_recalctimings(&colorplus->cga); +} + +static device_config_t colorplus_config[] = +{ + { + .name = "display_type", + .description = "Display type", + .type = CONFIG_SELECTION, + .selection = + { + { + .description = "RGB", + .value = CGA_RGB + }, + { + .description = "Composite", + .value = CGA_COMPOSITE + }, + { + .description = "" + } + }, + .default_int = CGA_RGB + }, + { + .name = "composite_type", + .description = "Composite type", + .type = CONFIG_SELECTION, + .selection = + { + { + .description = "Old", + .value = COMPOSITE_OLD + }, + { + .description = "New", + .value = COMPOSITE_NEW + }, + { + .description = "" + } + }, + .default_int = COMPOSITE_OLD + }, + { + .name = "snow_enabled", + .description = "Snow emulation", + .type = CONFIG_BINARY, + .default_int = 1 + }, + { + .type = -1 + } +}; + +device_t colorplus_device = +{ + "Colorplus", + 0, + colorplus_standalone_init, + colorplus_close, + NULL, + colorplus_speed_changed, + NULL, + NULL, + colorplus_config +}; diff --git a/src/vid_colorplus.h b/src/vid_colorplus.h new file mode 100644 index 000000000..3213b4edc --- /dev/null +++ b/src/vid_colorplus.h @@ -0,0 +1,15 @@ +typedef struct colorplus_t +{ + cga_t cga; + uint8_t control; +} colorplus_t; + +void colorplus_init(colorplus_t *colorplus); +void colorplus_out(uint16_t addr, uint8_t val, void *p); +uint8_t colorplus_in(uint16_t addr, void *p); +void colorplus_write(uint32_t addr, uint8_t val, void *p); +uint8_t colorplus_read(uint32_t addr, void *p); +void colorplus_recalctimings(colorplus_t *colorplus); +void colorplus_poll(void *p); + +extern device_t colorplus_device; diff --git a/src/vid_et4000w32.c b/src/vid_et4000w32.c index b38734a2a..df8555e99 100644 --- a/src/vid_et4000w32.c +++ b/src/vid_et4000w32.c @@ -1191,7 +1191,6 @@ void et4000w32p_pci_write(int func, int addr, uint8_t val, void *p) switch (addr) { case PCI_REG_COMMAND: - if (romset == ROM_KN97) return; et4000->pci_regs[PCI_REG_COMMAND] = val & 0x27; if (val & PCI_COMMAND_IO) et4000w32p_io_set(et4000); diff --git a/src/vid_nv_riva128.c b/src/vid_nv_riva128.c index 7d251ac32..048b15d4f 100644 --- a/src/vid_nv_riva128.c +++ b/src/vid_nv_riva128.c @@ -1267,7 +1267,6 @@ static void riva128_pci_write(int func, int addr, uint8_t val, void *p) return; case PCI_REG_COMMAND: - if (romset == ROM_KN97) return; riva128->pci_regs[PCI_REG_COMMAND] = val & 0x27; if (val & PCI_COMMAND_IO) { diff --git a/src/vid_nv_rivatnt.c b/src/vid_nv_rivatnt.c index 6668366b3..d26ee1bb4 100644 --- a/src/vid_nv_rivatnt.c +++ b/src/vid_nv_rivatnt.c @@ -1153,7 +1153,6 @@ static void rivatnt_pci_write(int func, int addr, uint8_t val, void *p) return; case PCI_REG_COMMAND: - if (romset == ROM_KN97) return; rivatnt->pci_regs[PCI_REG_COMMAND] = val & 0x27; if (val & PCI_COMMAND_IO) { diff --git a/src/vid_s3.c b/src/vid_s3.c index 4f44109e6..68c6f65eb 100644 --- a/src/vid_s3.c +++ b/src/vid_s3.c @@ -704,7 +704,6 @@ static void fifo_thread(void *param) static void s3_queue(s3_t *s3, uint32_t addr, uint32_t val, uint32_t type) { fifo_entry_t *fifo = &s3->fifo[s3->fifo_write_idx & FIFO_MASK]; - int c; if (FIFO_FULL) { @@ -2115,7 +2114,6 @@ void s3_pci_write(int func, int addr, uint8_t val, void *p) switch (addr) { case PCI_REG_COMMAND: - if (romset == ROM_KN97) return; s3->pci_regs[PCI_REG_COMMAND] = val & 0x27; if (val & PCI_COMMAND_IO) s3_io_set(s3); diff --git a/src/vid_s3_virge.c b/src/vid_s3_virge.c index 7e626d422..5b0264633 100644 --- a/src/vid_s3_virge.c +++ b/src/vid_s3_virge.c @@ -3711,7 +3711,6 @@ static void s3_virge_pci_write(int func, int addr, uint8_t val, void *p) return; case PCI_REG_COMMAND: - if (romset == ROM_KN97) return; if (val & PCI_COMMAND_IO) { io_removehandler(0x03c0, 0x0020, s3_virge_in, NULL, NULL, s3_virge_out, NULL, NULL, virge); diff --git a/src/vid_svga.c b/src/vid_svga.c index 01f95d45c..592fb83a1 100644 --- a/src/vid_svga.c +++ b/src/vid_svga.c @@ -334,7 +334,6 @@ uint8_t svga_in(uint16_t addr, void *p) case 0x32CB: pclog("Read port %04X\n", addr); return 0xEE; - return charsettings; // return 0xEE | (charedit_on ? 0x10 : 0); case 0x3C0: diff --git a/src/vid_svga.h b/src/vid_svga.h index b73c8636c..29e67d73d 100644 --- a/src/vid_svga.h +++ b/src/vid_svga.h @@ -7,7 +7,7 @@ typedef struct svga_t uint8_t crtcreg; uint8_t crtc[128]; - uint8_t gdcreg[16]; + uint8_t gdcreg[64]; int gdcaddr; uint8_t attrregs[32]; int attraddr, attrff; diff --git a/src/vid_svga_render.c b/src/vid_svga_render.c index 17455ea5f..39136aa39 100644 --- a/src/vid_svga_render.c +++ b/src/vid_svga_render.c @@ -161,7 +161,6 @@ void svga_render_text_40_12(svga_t *svga) void svga_render_text_80(svga_t *svga) { - FILE *f; int y_add = (enable_overscan) ? 16 : 0; int x_add = y_add >> 1; @@ -228,7 +227,6 @@ void svga_render_text_80(svga_t *svga) void svga_render_text_80_12(svga_t *svga) { - FILE *f; int y_add = (enable_overscan) ? 16 : 0; int x_add = (enable_overscan) ? 12 : 0; diff --git a/src/vid_voodoo.c b/src/vid_voodoo.c index a53fd56cf..eba63c43b 100644 --- a/src/vid_voodoo.c +++ b/src/vid_voodoo.c @@ -22,6 +22,13 @@ #define TEX_CACHE_MAX 64 +enum +{ + VOODOO_1 = 0, + VOODOO_SB50 = 1, + VOODOO_2 = 2 +}; + static uint32_t texture_offset[LOD_MAX+3] = { 0, @@ -203,6 +210,7 @@ typedef struct voodoo_t voodoo_params_t params; uint32_t fbiInit0, fbiInit1, fbiInit2, fbiInit3, fbiInit4; + uint32_t fbiInit5, fbiInit6, fbiInit7; /*Voodoo 2*/ uint8_t initEnable; @@ -217,6 +225,7 @@ typedef struct voodoo_t uint32_t fb_read_offset, fb_write_offset; int row_width; + int block_width; uint8_t *fb_mem, *tex_mem[2]; uint16_t *tex_mem_w[2]; @@ -227,7 +236,7 @@ typedef struct voodoo_t int swap_count; - int disp_buffer; + int disp_buffer, draw_buffer; int timer_count; int line; @@ -237,7 +246,7 @@ typedef struct voodoo_t uint32_t videoDimensions; uint32_t hSync, vSync; - int v_total, v_disp; + int h_total, v_total, v_disp; int h_disp; int v_retrace; @@ -283,6 +292,7 @@ typedef struct voodoo_t uint32_t texture_mask; int dual_tmus; + int type; fifo_entry_t fifo[FIFO_SIZE]; volatile int fifo_read_idx, fifo_write_idx; @@ -291,6 +301,22 @@ typedef struct voodoo_t voodoo_params_t params_buffer[PARAM_SIZE]; volatile int params_read_idx[2], params_write_idx; + uint32_t cmdfifo_base, cmdfifo_end; + int cmdfifo_rp, cmdfifo_depth_rd, cmdfifo_depth_wr; + uint32_t cmdfifo_amin, cmdfifo_amax; + + uint32_t sSetupMode; + struct + { + float sVx, sVy; + float sRed, sGreen, sBlue, sAlpha; + float sVz, sWb; + float sW0, sS0, sT0; + float sW1, sS1, sT1; + } verts[4]; + int vertex_num; + int num_verticies; + int flush; int scrfilter; @@ -302,6 +328,35 @@ typedef struct voodoo_t uint32_t fbiZFuncFail; uint32_t fbiAFuncFail; uint32_t fbiPixelsOut; + + uint32_t bltSrcBaseAddr; + uint32_t bltDstBaseAddr; + int bltSrcXYStride, bltDstXYStride; + uint32_t bltSrcChromaRange, bltDstChromaRange; + int bltSrcChromaMinR, bltSrcChromaMinG, bltSrcChromaMinB; + int bltSrcChromaMaxR, bltSrcChromaMaxG, bltSrcChromaMaxB; + int bltDstChromaMinR, bltDstChromaMinG, bltDstChromaMinB; + int bltDstChromaMaxR, bltDstChromaMaxG, bltDstChromaMaxB; + + int bltClipRight, bltClipLeft; + int bltClipHighY, bltClipLowY; + + int bltSrcX, bltSrcY; + int bltDstX, bltDstY; + int bltSizeX, bltSizeY; + int bltRop[4]; + uint16_t bltColorFg, bltColorBg; + + uint32_t bltCommand; + + struct + { + int dst_x, dst_y; + int cur_x; + int size_x, size_y; + int x_dir, y_dir; + int dst_stride; + } blt; rgb_t clutData[33]; int clutData_dirty; @@ -312,7 +367,10 @@ typedef struct voodoo_t int dirty_line_low, dirty_line_high; int fb_write_buffer, fb_draw_buffer; + int buffer_cutoff; + int read_time, write_time, burst_time; + uint16_t thefilter[1024][1024]; // pixel filter, feeding from one or two uint16_t thefilterg[1024][1024]; // for green @@ -335,6 +393,7 @@ static inline void wait_for_render_thread_idle(voodoo_t *voodoo); enum { SST_status = 0x000, + SST_intrCtrl = 0x004, SST_vertexAx = 0x008, SST_vertexAy = 0x00c, @@ -425,7 +484,9 @@ enum SST_fogColor = 0x12c, SST_zaColor = 0x130, SST_chromaKey = 0x134, - + + SST_userIntrCMD = 0x13c, + SST_color0 = 0x144, SST_color1 = 0x148, @@ -467,6 +528,14 @@ enum SST_fogTable1d = 0x1d4, SST_fogTable1e = 0x1d8, SST_fogTable1f = 0x1dc, + + SST_cmdFifoBaseAddr = 0x1e0, + SST_cmdFifoBump = 0x1e4, + SST_cmdFifoRdPtr = 0x1e8, + SST_cmdFifoAMin = 0x1ec, + SST_cmdFifoAMax = 0x1f0, + SST_cmdFifoDepth = 0x1f4, + SST_cmdFifoHoles = 0x1f8, SST_fbiInit4 = 0x200, @@ -481,6 +550,48 @@ enum SST_clutData = 0x228, SST_dacData = 0x22c, + SST_hvRetrace = 0x240, + SST_fbiInit5 = 0x244, + SST_fbiInit6 = 0x248, + SST_fbiInit7 = 0x24c, + + SST_sSetupMode = 0x260, + SST_sVx = 0x264, + SST_sVy = 0x268, + SST_sARGB = 0x26c, + SST_sRed = 0x270, + SST_sGreen = 0x274, + SST_sBlue = 0x278, + SST_sAlpha = 0x27c, + SST_sVz = 0x280, + SST_sWb = 0x284, + SST_sW0 = 0x288, + SST_sS0 = 0x28c, + SST_sT0 = 0x290, + SST_sW1 = 0x294, + SST_sS1 = 0x298, + SST_sT1 = 0x29c, + + SST_sDrawTriCMD = 0x2a0, + SST_sBeginTriCMD = 0x2a4, + + SST_bltSrcBaseAddr = 0x2c0, + SST_bltDstBaseAddr = 0x2c4, + SST_bltXYStrides = 0x2c8, + SST_bltSrcChromaRange = 0x2cc, + SST_bltDstChromaRange = 0x2d0, + SST_bltClipX = 0x2d4, + SST_bltClipY = 0x2d8, + + SST_bltSrcXY = 0x2e0, + SST_bltDstXY = 0x2e4, + SST_bltSize = 0x2e8, + SST_bltRop = 0x2ec, + SST_bltColor = 0x2f0, + + SST_bltCommand = 0x2f8, + SST_bltData = 0x2fc, + SST_textureMode = 0x300, SST_tLOD = 0x304, SST_tDetail = 0x308, @@ -651,6 +762,7 @@ enum TEX_I8 = 0x3, TEX_AI8 = 0x4, TEX_PAL8 = 0x5, + TEX_APAL8 = 0x6, TEX_ARGB8332 = 0x8, TEX_A8Y4I2Q2 = 0x9, TEX_R5G6B5 = 0xa, @@ -670,7 +782,8 @@ enum enum { - FBIINIT0_VGA_PASS = 1 + FBIINIT0_VGA_PASS = 1, + FBIINIT0_GRAPHICS_RESET = (1 << 1) }; enum @@ -678,6 +791,11 @@ enum FBIINIT3_REMAP = 1 }; +enum +{ + FBIINIT7_CMDFIFO_ENABLE = (1 << 8) +}; + enum { CC_LOCALSELECT_ITER_RGB = 0, @@ -808,6 +926,7 @@ enum FOG_MULT = 0x04, FOG_ALPHA = 0x08, FOG_Z = 0x10, + FOG_W = 0x18, FOG_CONSTANT = 0x20 }; @@ -815,7 +934,9 @@ enum { LOD_ODD = (1 << 18), LOD_SPLIT = (1 << 19), - LOD_S_IS_WIDER = (1 << 20) + LOD_S_IS_WIDER = (1 << 20), + LOD_TMIRROR_S = (1 << 28), + LOD_TMIRROR_T = (1 << 29) }; enum { @@ -830,6 +951,12 @@ enum FBZCP_TEXTURE_ENABLED = (1 << 27) }; +enum +{ + BLTCMD_SRC_TILED = (1 << 10), + BLTCMD_DST_TILED = (1 << 12) +}; + #define TEXTUREMODE_MASK 0x3ffff000 #define TEXTUREMODE_PASSTHROUGH 0 @@ -882,31 +1009,29 @@ static void voodoo_update_ncc(voodoo_t *voodoo, int tmu) } } +#define TRIPLE_BUFFER ((voodoo->fbiInit2 & 0x10) || (voodoo->fbiInit5 & 0x600) == 0x400) static void voodoo_recalc(voodoo_t *voodoo) { uint32_t buffer_offset = ((voodoo->fbiInit2 >> 11) & 511) * 4096; - if (voodoo->disp_buffer) - { - voodoo->back_offset = 0; - voodoo->params.front_offset = buffer_offset; - } + voodoo->params.front_offset = voodoo->disp_buffer*buffer_offset; + voodoo->back_offset = voodoo->draw_buffer*buffer_offset; + + voodoo->buffer_cutoff = TRIPLE_BUFFER ? (buffer_offset * 4) : (buffer_offset * 3); + if (TRIPLE_BUFFER) + voodoo->params.aux_offset = buffer_offset * 3; else - { - voodoo->params.front_offset = 0; - voodoo->back_offset = buffer_offset; - } - voodoo->params.aux_offset = buffer_offset * 2; - + voodoo->params.aux_offset = buffer_offset * 2; + switch (voodoo->lfbMode & LFB_WRITE_MASK) { case LFB_WRITE_FRONT: voodoo->fb_write_offset = voodoo->params.front_offset; - voodoo->fb_write_buffer = voodoo->disp_buffer ? 1 : 0; + voodoo->fb_write_buffer = voodoo->disp_buffer; break; case LFB_WRITE_BACK: voodoo->fb_write_offset = voodoo->back_offset; - voodoo->fb_write_buffer = voodoo->disp_buffer ? 0 : 1; + voodoo->fb_write_buffer = voodoo->draw_buffer; break; default: @@ -935,20 +1060,24 @@ static void voodoo_recalc(voodoo_t *voodoo) { case FBZ_DRAW_FRONT: voodoo->params.draw_offset = voodoo->params.front_offset; - voodoo->fb_draw_buffer = voodoo->disp_buffer ? 1 : 0; + voodoo->fb_draw_buffer = voodoo->disp_buffer; break; case FBZ_DRAW_BACK: voodoo->params.draw_offset = voodoo->back_offset; - voodoo->fb_draw_buffer = voodoo->disp_buffer ? 0 : 1; + voodoo->fb_draw_buffer = voodoo->draw_buffer; break; default: fatal("voodoo_recalc : unknown draw buffer\n"); } - - voodoo->row_width = ((voodoo->fbiInit1 >> 4) & 15) * 64 * 2; -// pclog("voodoo_recalc : front_offset %08X back_offset %08X aux_offset %08X draw_offset %08x\n", voodoo->params.front_offset, voodoo->back_offset, voodoo->params.aux_offset, voodoo->params.draw_offset); -// pclog(" fb_read_offset %08X fb_write_offset %08X row_width %i %08x %08x\n", voodoo->fb_read_offset, voodoo->fb_write_offset, voodoo->row_width, voodoo->lfbMode, voodoo->params.fbzMode); + + voodoo->block_width = ((voodoo->fbiInit1 >> 4) & 15) * 2; + if (voodoo->fbiInit6 & (1 << 30)) + voodoo->fbiInit1 += 1; + voodoo->row_width = voodoo->block_width * 32 * 2; + +/* pclog("voodoo_recalc : front_offset %08X back_offset %08X aux_offset %08X draw_offset %08x\n", voodoo->params.front_offset, voodoo->back_offset, voodoo->params.aux_offset, voodoo->params.draw_offset); + pclog(" fb_read_offset %08X fb_write_offset %08X row_width %i %08x %08x\n", voodoo->fb_read_offset, voodoo->fb_write_offset, voodoo->row_width, voodoo->lfbMode, voodoo->params.fbzMode);*/ } static void voodoo_recalc_tex(voodoo_t *voodoo, int tmu) @@ -1036,9 +1165,7 @@ static void use_texture(voodoo_t *voodoo, voodoo_params_t *params, int tmu) lod_min = (params->tLOD[tmu] >> 2) & 15; lod_max = (params->tLOD[tmu] >> 8) & 15; -//pclog("use_texture %08x %i %i-%i\n", params->texBaseAddr[tmu], tmu, lod_min,lod_max); - - if (params->tformat[tmu] == TEX_PAL8 || params->tformat[tmu] == TEX_APAL88) + if (params->tformat[tmu] == TEX_PAL8 || params->tformat[tmu] == TEX_APAL8 || params->tformat[tmu] == TEX_APAL88) { if (voodoo->palette_dirty[tmu]) { @@ -1105,6 +1232,7 @@ static void use_texture(voodoo_t *voodoo, voodoo_params_t *params, int tmu) rgba_u *pal; //pclog(" LOD %i : %08x - %08x %i %i,%i\n", lod, params->tex_base[tmu][lod] & voodoo->texture_mask, addr, voodoo->params.tformat[tmu], voodoo->params.tex_w_mask[tmu][lod],voodoo->params.tex_h_mask[tmu][lod]); + switch (params->tformat[tmu]) { @@ -1194,6 +1322,26 @@ static void use_texture(voodoo_t *voodoo, voodoo_params_t *params, int tmu) } break; + case TEX_APAL8: + pal = voodoo->palette[tmu]; + for (y = 0; y < voodoo->params.tex_h_mask[tmu][lod]+1; y++) + { + for (x = 0; x < voodoo->params.tex_w_mask[tmu][lod]+1; x++) + { + uint8_t dat = voodoo->tex_mem[tmu][(tex_addr+x) & voodoo->texture_mask]; + + int r = ((pal[dat].rgba.r & 3) << 6) | ((pal[dat].rgba.g & 0xf0) >> 2) | (pal[dat].rgba.r & 3); + int g = ((pal[dat].rgba.g & 0xf) << 4) | ((pal[dat].rgba.b & 0xc0) >> 4) | ((pal[dat].rgba.g & 0xf) >> 2); + int b = ((pal[dat].rgba.b & 0x3f) << 2) | ((pal[dat].rgba.b & 0x30) >> 4); + int a = (pal[dat].rgba.r & 0xfc) | ((pal[dat].rgba.r & 0xc0) >> 6); + + base[x] = makergba(r, g, b, a); + } + tex_addr += (1 << voodoo->params.tex_shift[tmu][lod]); + base += (1 << shift); + } + break; + case TEX_ARGB8332: for (y = 0; y < voodoo->params.tex_h_mask[tmu][lod]+1; y++) { @@ -1616,6 +1764,17 @@ static inline void voodoo_get_texture(voodoo_t *voodoo, voodoo_params_t *params, texture_state.w_mask = state->tex_w_mask[tmu][state->lod]; texture_state.h_mask = state->tex_h_mask[tmu][state->lod]; texture_state.tex_shift = 8 - tex_lod; + + if (params->tLOD[tmu] & LOD_TMIRROR_S) + { + if (state->tex_s & 0x1000) + state->tex_s = ~state->tex_s; + } + if (params->tLOD[tmu] & LOD_TMIRROR_T) + { + if (state->tex_t & 0x1000) + state->tex_t = ~state->tex_t; + } if (voodoo->bilinear_enabled && params->textureMode[tmu] & 6) { @@ -1780,7 +1939,7 @@ static inline void voodoo_tmu_fetch(voodoo_t *voodoo, voodoo_params_t *params, v } \ } while (0) -#define APPLY_FOG(src_r, src_g, src_b, z, ia) \ +#define APPLY_FOG(src_r, src_g, src_b, z, ia, w) \ do \ { \ if (params->fogMode & FOG_CONSTANT) \ @@ -1792,6 +1951,7 @@ static inline void voodoo_tmu_fetch(voodoo_t *voodoo, voodoo_params_t *params, v else \ { \ int fog_r, fog_g, fog_b, fog_a; \ + int fog_idx; \ \ if (!(params->fogMode & FOG_ADD)) \ { \ @@ -1809,16 +1969,23 @@ static inline void voodoo_tmu_fetch(voodoo_t *voodoo, voodoo_params_t *params, v fog_b -= src_b; \ } \ \ - if (params->fogMode & FOG_Z) \ - fog_a = (z >> 20) & 0xff; \ - else if (params->fogMode & FOG_ALPHA) \ - fog_a = CLAMP(ia >> 12); \ - else \ + switch (params->fogMode & (FOG_Z|FOG_ALPHA)) \ { \ - int fog_idx = (w_depth >> 10) & 0x3f; \ + case 0: \ + fog_idx = (w_depth >> 10) & 0x3f; \ \ fog_a = params->fogTable[fog_idx].fog; \ fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10; \ + break; \ + case FOG_Z: \ + fog_a = (z >> 20) & 0xff; \ + break; \ + case FOG_ALPHA: \ + fog_a = CLAMP(ia >> 12); \ + break; \ + case FOG_W: \ + fog_a = CLAMP((w >> 32) & 0xff); \ + break; \ } \ fog_a++; \ \ @@ -1992,6 +2159,7 @@ static inline void voodoo_tmu_fetch(voodoo_t *voodoo, voodoo_params_t *params, v src_b = (src_b * (255-dest_a)) / 255; \ break; \ case AFUNC_ACOLORBEFOREFOG: \ + fatal("AFUNC_ACOLORBEFOREFOG\n"); \ break; \ } \ \ @@ -2169,6 +2337,7 @@ static inline voodoo_tmu_fetch_and_blend(voodoo_t *voodoo, voodoo_params_t *para state->tex_a[1] = CLAMP(a); } + voodoo_tmu_fetch(voodoo, params, state, 0, x); if ((params->textureMode[0] & TEXTUREMODE_TRILINEAR) && (state->lod & 1)) @@ -2283,6 +2452,7 @@ static inline voodoo_tmu_fetch_and_blend(voodoo_t *voodoo, voodoo_params_t *para if (tca_add_clocal || tca_add_alocal) a += state->tex_a[0]; + state->tex_r[0] = CLAMP(r); state->tex_g[0] = CLAMP(g); state->tex_b[0] = CLAMP(b); @@ -2452,7 +2622,7 @@ static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, vood if (voodoo_output) pclog("%03i:%03i : Ax=%08x start_x=%08x dSdX=%016llx dx=%08x s=%08x -> ", x, state->y, state->vertexAx << 8, start_x, params->tmu[0].dTdX, dx, state->tmu0_t); - + state->ir += (params->dRdX * dx); state->ig += (params->dGdX * dx); state->ib += (params->dBdX * dx); @@ -2547,6 +2717,7 @@ static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, vood do { start_x = x; + state->x = x; voodoo->pixel_count[odd_even]++; voodoo->texel_count[odd_even] += texels; voodoo->fbiPixelsIn++; @@ -2707,6 +2878,7 @@ static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, vood break; default: + fatal("Bad cca_localselect %i\n", cca_localselect); alocal = 0xff; break; } @@ -2723,6 +2895,7 @@ static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, vood aother = (params->color1 >> 24) & 0xff; break; default: + fatal("Bad a_sel %i\n", a_sel); aother = 0; break; } @@ -2784,6 +2957,7 @@ static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, vood break; default: + fatal("Bad cc_mselect %i\n", cc_mselect); msel_r = 0; msel_g = 0; msel_b = 0; @@ -2809,6 +2983,7 @@ static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, vood break; default: + fatal("Bad cca_mselect %i\n", cca_mselect); msel_a = 0; break; } @@ -2826,7 +3001,7 @@ static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, vood if (!cca_reverse_blend) msel_a ^= 0xff; msel_a++; - + src_r = (src_r * msel_r) >> 8; src_g = (src_g * msel_g) >> 8; src_b = (src_b * msel_b) >> 8; @@ -2844,6 +3019,10 @@ static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, vood src_g += alocal; src_b += alocal; break; + case 0: + break; + default: + fatal("Bad cc_add %i\n", cc_add); } if (cca_add) @@ -2864,7 +3043,7 @@ static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, vood src_a ^= 0xff; if (params->fogMode & FOG_ENABLE) - APPLY_FOG(src_r, src_g, src_b, state->z, state->ia); + APPLY_FOG(src_r, src_g, src_b, state->z, state->ia, state->w); if (params->alphaMode & 1) ALPHA_TEST(src_a); @@ -2898,6 +3077,7 @@ static void voodoo_half_triangle(voodoo_t *voodoo, voodoo_params_t *params, vood if (params->fbzMode & FBZ_RGB_WMASK) fb_mem[x] = src_b | (src_g << 5) | (src_r << 11); + if (params->fbzMode & FBZ_DEPTH_WMASK) aux_mem[x] = new_depth; } @@ -2988,9 +3168,11 @@ static void voodoo_triangle(voodoo_t *voodoo, voodoo_params_t *params, int odd_e if ((params->vertexAy & 0xf) > 8) dy += 16; -/* pclog("voodoo_triangle %i %i %i : vA %f, %f vB %f, %f vC %f, %f f %i %08x %08x %08x\n", odd_even, voodoo->params_read_idx[odd_even], voodoo->params_read_idx[odd_even] & PARAM_MASK, (float)params->vertexAx / 16.0, (float)params->vertexAy / 16.0, +/* pclog("voodoo_triangle %i %i %i : vA %f, %f vB %f, %f vC %f, %f f %i,%i %08x %08x %08x,%08x tex=%i,%i fogMode=%08x\n", odd_even, voodoo->params_read_idx[odd_even], voodoo->params_read_idx[odd_even] & PARAM_MASK, (float)params->vertexAx / 16.0, (float)params->vertexAy / 16.0, (float)params->vertexBx / 16.0, (float)params->vertexBy / 16.0, - (float)params->vertexCx / 16.0, (float)params->vertexCy / 16.0, (params->fbzColorPath & FBZCP_TEXTURE_ENABLED) ? params->tformat : 0, params->fbzColorPath, params->alphaMode, params->textureMode);*/ + (float)params->vertexCx / 16.0, (float)params->vertexCy / 16.0, + (params->fbzColorPath & FBZCP_TEXTURE_ENABLED) ? params->tformat[0] : 0, + (params->fbzColorPath & FBZCP_TEXTURE_ENABLED) ? params->tformat[1] : 0, params->fbzColorPath, params->alphaMode, params->textureMode[0],params->textureMode[1], params->tex_entry[0],params->tex_entry[1], params->fogMode);*/ state.base_r = params->startR; state.base_g = params->startG; @@ -3240,43 +3422,540 @@ static void voodoo_fastfill(voodoo_t *voodoo, voodoo_params_t *params) } } -static uint32_t voodoo_reg_readl(uint32_t addr, void *p) +enum { - voodoo_t *voodoo = (voodoo_t *)p; - uint32_t temp; + SETUPMODE_RGB = (1 << 0), + SETUPMODE_ALPHA = (1 << 1), + SETUPMODE_Z = (1 << 2), + SETUPMODE_Wb = (1 << 3), + SETUPMODE_W0 = (1 << 4), + SETUPMODE_S0_T0 = (1 << 5), + SETUPMODE_W1 = (1 << 6), + SETUPMODE_S1_T1 = (1 << 7), - switch (addr & 0x3fc) + SETUPMODE_STRIP_MODE = (1 << 16), + SETUPMODE_CULLING_ENABLE = (1 << 17), + SETUPMODE_CULLING_SIGN = (1 << 18) +}; + +static void triangle_setup(voodoo_t *voodoo) +{ + float dxAB, dxBC, dyAB, dyBC; + float area; + int va = 0, vb = 1, vc = 2; + int reverse_cull = 0; + + if (voodoo->verts[0].sVy < voodoo->verts[1].sVy) { - - case SST_lfbMode: - temp = voodoo->lfbMode; - break; - - case SST_fbiInit4: - temp = voodoo->fbiInit4; - break; - case SST_fbiInit0: - temp = voodoo->fbiInit0; - break; - case SST_fbiInit1: - temp = voodoo->fbiInit1 & ~5; /*Pass-thru board with one SST-1*/ - break; - case SST_fbiInit2: - if (voodoo->initEnable & 0x04) - temp = voodoo->dac_readdata; + if (voodoo->verts[1].sVy < voodoo->verts[2].sVy) + { + /* V1>V0, V2>V1, V2>V1>V0*/ + va = 0; /*OK*/ + vb = 1; + vc = 2; + } else - temp = voodoo->fbiInit2; + { + /* V1>V0, V1>V2*/ + if (voodoo->verts[0].sVy < voodoo->verts[2].sVy) + { + /* V1>V0, V1>V2, V2>V0, V1>V2>V0*/ + va = 0; + vb = 2; + vc = 1; + reverse_cull = 1; + } + else + { + /* V1>V0, V1>V2, V0>V2, V1>V0>V2*/ + va = 2; + vb = 0; + vc = 1; + } + } + } + else + { + if (voodoo->verts[1].sVy < voodoo->verts[2].sVy) + { + /* V0>V1, V2>V1*/ + if (voodoo->verts[0].sVy < voodoo->verts[2].sVy) + { + /* V0>V1, V2>V1, V2>V0, V2>V0>V1*/ + va = 1; + vb = 0; + vc = 2; + reverse_cull = 1; + } + else + { + /* V0>V1, V2>V1, V0>V2, V0>V2>V1*/ + va = 1; + vb = 2; + vc = 0; + } + } + else + { + /*V0>V1>V2*/ + va = 2; + vb = 1; + vc = 0; + reverse_cull = 1; + } + } + + dxAB = voodoo->verts[va].sVx - voodoo->verts[vb].sVx; + dxBC = voodoo->verts[vb].sVx - voodoo->verts[vc].sVx; + dyAB = voodoo->verts[va].sVy - voodoo->verts[vb].sVy; + dyBC = voodoo->verts[vb].sVy - voodoo->verts[vc].sVy; + + area = dxAB * dyBC - dxBC * dyAB; + + if (area == 0.0) + return; + + dxAB /= area; + dxBC /= area; + dyAB /= area; + dyBC /= area; + + if (voodoo->sSetupMode & SETUPMODE_CULLING_ENABLE) + { + int sign = (area < 0.0); + + if (reverse_cull) + sign = !sign; + + if ((voodoo->sSetupMode & SETUPMODE_CULLING_SIGN) && sign) + return; + if (!(voodoo->sSetupMode & SETUPMODE_CULLING_SIGN) && !sign) + return; + } + + voodoo->params.vertexAx = (int32_t)(int16_t)((int32_t)(voodoo->verts[va].sVx * 16.0f) & 0xffff); + voodoo->params.vertexAy = (int32_t)(int16_t)((int32_t)(voodoo->verts[va].sVy * 16.0f) & 0xffff); + voodoo->params.vertexBx = (int32_t)(int16_t)((int32_t)(voodoo->verts[vb].sVx * 16.0f) & 0xffff); + voodoo->params.vertexBy = (int32_t)(int16_t)((int32_t)(voodoo->verts[vb].sVy * 16.0f) & 0xffff); + voodoo->params.vertexCx = (int32_t)(int16_t)((int32_t)(voodoo->verts[vc].sVx * 16.0f) & 0xffff); + voodoo->params.vertexCy = (int32_t)(int16_t)((int32_t)(voodoo->verts[vc].sVy * 16.0f) & 0xffff); + + if (voodoo->params.vertexAy > voodoo->params.vertexBy || voodoo->params.vertexBy > voodoo->params.vertexCy) + fatal("triangle_setup wrong order %d %d %d\n", voodoo->params.vertexAy, voodoo->params.vertexBy, voodoo->params.vertexCy); + + if (voodoo->sSetupMode & SETUPMODE_RGB) + { + voodoo->params.startR = (int32_t)(voodoo->verts[va].sRed * 4096.0f); + voodoo->params.dRdX = (int32_t)(((voodoo->verts[va].sRed - voodoo->verts[vb].sRed) * dyBC - (voodoo->verts[vb].sRed - voodoo->verts[vc].sRed) * dyAB) * 4096.0f); + voodoo->params.dRdY = (int32_t)(((voodoo->verts[vb].sRed - voodoo->verts[vc].sRed) * dxAB - (voodoo->verts[va].sRed - voodoo->verts[vb].sRed) * dxBC) * 4096.0f); + voodoo->params.startG = (int32_t)(voodoo->verts[va].sGreen * 4096.0f); + voodoo->params.dGdX = (int32_t)(((voodoo->verts[va].sGreen - voodoo->verts[vb].sGreen) * dyBC - (voodoo->verts[vb].sGreen - voodoo->verts[vc].sGreen) * dyAB) * 4096.0f); + voodoo->params.dGdY = (int32_t)(((voodoo->verts[vb].sGreen - voodoo->verts[vc].sGreen) * dxAB - (voodoo->verts[va].sGreen - voodoo->verts[vb].sGreen) * dxBC) * 4096.0f); + voodoo->params.startB = (int32_t)(voodoo->verts[va].sBlue * 4096.0f); + voodoo->params.dBdX = (int32_t)(((voodoo->verts[va].sBlue - voodoo->verts[vb].sBlue) * dyBC - (voodoo->verts[vb].sBlue - voodoo->verts[vc].sBlue) * dyAB) * 4096.0f); + voodoo->params.dBdY = (int32_t)(((voodoo->verts[vb].sBlue - voodoo->verts[vc].sBlue) * dxAB - (voodoo->verts[va].sBlue - voodoo->verts[vb].sBlue) * dxBC) * 4096.0f); + } + if (voodoo->sSetupMode & SETUPMODE_ALPHA) + { + voodoo->params.startA = (int32_t)(voodoo->verts[va].sAlpha * 4096.0f); + voodoo->params.dAdX = (int32_t)(((voodoo->verts[va].sAlpha - voodoo->verts[vb].sAlpha) * dyBC - (voodoo->verts[vb].sAlpha - voodoo->verts[vc].sAlpha) * dyAB) * 4096.0f); + voodoo->params.dAdY = (int32_t)(((voodoo->verts[vb].sAlpha - voodoo->verts[vc].sAlpha) * dxAB - (voodoo->verts[va].sAlpha - voodoo->verts[vb].sAlpha) * dxBC) * 4096.0f); + } + if (voodoo->sSetupMode & SETUPMODE_Z) + { + voodoo->params.startZ = (int32_t)(voodoo->verts[va].sVz * 4096.0f); + voodoo->params.dZdX = (int32_t)(((voodoo->verts[va].sVz - voodoo->verts[vb].sVz) * dyBC - (voodoo->verts[vb].sVz - voodoo->verts[vc].sVz) * dyAB) * 4096.0f); + voodoo->params.dZdY = (int32_t)(((voodoo->verts[vb].sVz - voodoo->verts[vc].sVz) * dxAB - (voodoo->verts[va].sVz - voodoo->verts[vb].sVz) * dxBC) * 4096.0f); + } + if (voodoo->sSetupMode & SETUPMODE_Wb) + { + voodoo->params.startW = (int64_t)(voodoo->verts[va].sWb * 4294967296.0f); + voodoo->params.dWdX = (int64_t)(((voodoo->verts[va].sWb - voodoo->verts[vb].sWb) * dyBC - (voodoo->verts[vb].sWb - voodoo->verts[vc].sWb) * dyAB) * 4294967296.0f); + voodoo->params.dWdY = (int64_t)(((voodoo->verts[vb].sWb - voodoo->verts[vc].sWb) * dxAB - (voodoo->verts[va].sWb - voodoo->verts[vb].sWb) * dxBC) * 4294967296.0f); + voodoo->params.tmu[0].startW = voodoo->params.tmu[1].startW = voodoo->params.startW; + voodoo->params.tmu[0].dWdX = voodoo->params.tmu[1].dWdX = voodoo->params.dWdX; + voodoo->params.tmu[0].dWdY = voodoo->params.tmu[1].dWdY = voodoo->params.dWdY; + } + if (voodoo->sSetupMode & SETUPMODE_W0) + { + voodoo->params.tmu[0].startW = (int64_t)(voodoo->verts[va].sW0 * 4294967296.0f); + voodoo->params.tmu[0].dWdX = (int64_t)(((voodoo->verts[va].sW0 - voodoo->verts[vb].sW0) * dyBC - (voodoo->verts[vb].sW0 - voodoo->verts[vc].sW0) * dyAB) * 4294967296.0f); + voodoo->params.tmu[0].dWdY = (int64_t)(((voodoo->verts[vb].sW0 - voodoo->verts[vc].sW0) * dxAB - (voodoo->verts[va].sW0 - voodoo->verts[vb].sW0) * dxBC) * 4294967296.0f); + voodoo->params.tmu[1].startW = voodoo->params.tmu[0].startW; + voodoo->params.tmu[1].dWdX = voodoo->params.tmu[0].dWdX; + voodoo->params.tmu[1].dWdY = voodoo->params.tmu[0].dWdY; + } + if (voodoo->sSetupMode & SETUPMODE_S0_T0) + { + voodoo->params.tmu[0].startS = (int64_t)(voodoo->verts[va].sS0 * 4294967296.0f); + voodoo->params.tmu[0].dSdX = (int64_t)(((voodoo->verts[va].sS0 - voodoo->verts[vb].sS0) * dyBC - (voodoo->verts[vb].sS0 - voodoo->verts[vc].sS0) * dyAB) * 4294967296.0f); + voodoo->params.tmu[0].dSdY = (int64_t)(((voodoo->verts[vb].sS0 - voodoo->verts[vc].sS0) * dxAB - (voodoo->verts[va].sS0 - voodoo->verts[vb].sS0) * dxBC) * 4294967296.0f); + voodoo->params.tmu[0].startT = (int64_t)(voodoo->verts[va].sT0 * 4294967296.0f); + voodoo->params.tmu[0].dTdX = (int64_t)(((voodoo->verts[va].sT0 - voodoo->verts[vb].sT0) * dyBC - (voodoo->verts[vb].sT0 - voodoo->verts[vc].sT0) * dyAB) * 4294967296.0f); + voodoo->params.tmu[0].dTdY = (int64_t)(((voodoo->verts[vb].sT0 - voodoo->verts[vc].sT0) * dxAB - (voodoo->verts[va].sT0 - voodoo->verts[vb].sT0) * dxBC) * 4294967296.0f); + voodoo->params.tmu[1].startS = voodoo->params.tmu[0].startS; + voodoo->params.tmu[1].dSdX = voodoo->params.tmu[0].dSdX; + voodoo->params.tmu[1].dSdY = voodoo->params.tmu[0].dSdY; + voodoo->params.tmu[1].startT = voodoo->params.tmu[0].startT; + voodoo->params.tmu[1].dTdX = voodoo->params.tmu[0].dTdX; + voodoo->params.tmu[1].dTdY = voodoo->params.tmu[0].dTdY; + } + if (voodoo->sSetupMode & SETUPMODE_W1) + { + voodoo->params.tmu[1].startW = (int64_t)(voodoo->verts[va].sW0 * 4294967296.0f); + voodoo->params.tmu[1].dWdX = (int64_t)(((voodoo->verts[va].sW0 - voodoo->verts[vb].sW0) * dyBC - (voodoo->verts[vb].sW0 - voodoo->verts[vc].sW0) * dyAB) * 4294967296.0f); + voodoo->params.tmu[1].dWdY = (int64_t)(((voodoo->verts[vb].sW0 - voodoo->verts[vc].sW0) * dxAB - (voodoo->verts[va].sW0 - voodoo->verts[vb].sW0) * dxBC) * 4294967296.0f); + } + if (voodoo->sSetupMode & SETUPMODE_S1_T1) + { + voodoo->params.tmu[1].startS = (int64_t)(voodoo->verts[va].sS1 * 4294967296.0f); + voodoo->params.tmu[1].dSdX = (int64_t)(((voodoo->verts[va].sS1 - voodoo->verts[vb].sS1) * dyBC - (voodoo->verts[vb].sS1 - voodoo->verts[vc].sS1) * dyAB) * 4294967296.0f); + voodoo->params.tmu[1].dSdY = (int64_t)(((voodoo->verts[vb].sS1 - voodoo->verts[vc].sS1) * dxAB - (voodoo->verts[va].sS1 - voodoo->verts[vb].sS1) * dxBC) * 4294967296.0f); + voodoo->params.tmu[1].startT = (int64_t)(voodoo->verts[va].sT1 * 4294967296.0f); + voodoo->params.tmu[1].dTdX = (int64_t)(((voodoo->verts[va].sT1 - voodoo->verts[vb].sT1) * dyBC - (voodoo->verts[vb].sT1 - voodoo->verts[vc].sT1) * dyAB) * 4294967296.0f); + voodoo->params.tmu[1].dTdY = (int64_t)(((voodoo->verts[vb].sT1 - voodoo->verts[vc].sT1) * dxAB - (voodoo->verts[va].sT1 - voodoo->verts[vb].sT1) * dxBC) * 4294967296.0f); + } + + voodoo->params.sign = (area < 0.0); + + if (voodoo->ncc_dirty[0]) + voodoo_update_ncc(voodoo, 0); + if (voodoo->ncc_dirty[1]) + voodoo_update_ncc(voodoo, 1); + voodoo->ncc_dirty[0] = voodoo->ncc_dirty[1] = 0; + + queue_triangle(voodoo, &voodoo->params); +} + +enum +{ + BLIT_COMMAND_SCREEN_TO_SCREEN = 0, + BLIT_COMMAND_CPU_TO_SCREEN = 1, + BLIT_COMMAND_RECT_FILL = 2, + BLIT_COMMAND_SGRAM_FILL = 3 +}; + +enum +{ + BLIT_SRC_1BPP = (0 << 3), + BLIT_SRC_1BPP_BYTE_PACKED = (1 << 3), + BLIT_SRC_16BPP = (2 << 3), + BLIT_SRC_24BPP = (3 << 3), + BLIT_SRC_24BPP_DITHER_2X2 = (4 << 3), + BLIT_SRC_24BPP_DITHER_4X4 = (5 << 3) +}; + +enum +{ + BLIT_SRC_RGB_ARGB = (0 << 6), + BLIT_SRC_RGB_ABGR = (1 << 6), + BLIT_SRC_RGB_RGBA = (2 << 6), + BLIT_SRC_RGB_BGRA = (3 << 6) +}; + +enum +{ + BLIT_COMMAND_MASK = 7, + BLIT_SRC_FORMAT = (7 << 3), + BLIT_SRC_RGB_FORMAT = (3 << 6), + BLIT_SRC_CHROMA = (1 << 10), + BLIT_DST_CHROMA = (1 << 12), + BLIT_CLIPPING_ENABLED = (1 << 16) +}; + +enum +{ + BLIT_ROP_DST_PASS = (1 << 0), + BLIT_ROP_SRC_PASS = (1 << 1) +}; + +#define MIX(src_dat, dst_dat, rop) \ + switch (rop) \ + { \ + case 0x0: dst_dat = 0; break; \ + case 0x1: dst_dat = ~(src_dat | dst_dat); break; \ + case 0x2: dst_dat = ~src_dat & dst_dat; break; \ + case 0x3: dst_dat = ~src_dat; break; \ + case 0x4: dst_dat = src_dat & ~dst_dat; break; \ + case 0x5: dst_dat = ~dst_dat; break; \ + case 0x6: dst_dat = src_dat ^ dst_dat; break; \ + case 0x7: dst_dat = ~(src_dat & dst_dat); break; \ + case 0x8: dst_dat = src_dat & dst_dat; break; \ + case 0x9: dst_dat = ~(src_dat ^ dst_dat); break; \ + case 0xa: dst_dat = dst_dat; break; \ + case 0xb: dst_dat = ~src_dat | dst_dat; break; \ + case 0xc: dst_dat = src_dat; break; \ + case 0xd: dst_dat = src_dat | ~dst_dat; break; \ + case 0xe: dst_dat = src_dat | dst_dat; break; \ + case 0xf: dst_dat = 0xffff; break; \ + } + +#define ABS(x) ((x) > 0 ? (x) : -(x)) + +static void blit_start(voodoo_t *voodoo) +{ + uint64_t dat64; + int size_x = ABS(voodoo->bltSizeX), size_y = ABS(voodoo->bltSizeY); + int x_dir = (voodoo->bltSizeX > 0) ? 1 : -1; + int y_dir = (voodoo->bltSizeY > 0) ? 1 : -1; + int src_x, dst_x; + int src_y = voodoo->bltSrcY & 0x7ff, dst_y = voodoo->bltDstY & 0x7ff; + int src_stride = (voodoo->bltCommand & BLTCMD_SRC_TILED) ? ((voodoo->bltSrcXYStride & 0x3f) * 32*2) : (voodoo->bltSrcXYStride & 0xff8); + int dst_stride = (voodoo->bltCommand & BLTCMD_DST_TILED) ? ((voodoo->bltDstXYStride & 0x3f) * 32*2) : (voodoo->bltDstXYStride & 0xff8); + uint32_t src_base_addr = (voodoo->bltCommand & BLTCMD_SRC_TILED) ? ((voodoo->bltSrcBaseAddr & 0x3ff) << 12) : (voodoo->bltSrcBaseAddr & 0x3ffff8); + uint32_t dst_base_addr = (voodoo->bltCommand & BLTCMD_DST_TILED) ? ((voodoo->bltDstBaseAddr & 0x3ff) << 12) : (voodoo->bltDstBaseAddr & 0x3ffff8); + int x, y; + +/* pclog("blit_start: command=%08x srcX=%i srcY=%i dstX=%i dstY=%i sizeX=%i sizeY=%i color=%04x,%04x\n", + voodoo->bltCommand, voodoo->bltSrcX, voodoo->bltSrcY, voodoo->bltDstX, voodoo->bltDstY, voodoo->bltSizeX, voodoo->bltSizeY, voodoo->bltColorFg, voodoo->bltColorBg);*/ + + wait_for_render_thread_idle(voodoo); + + switch (voodoo->bltCommand & BLIT_COMMAND_MASK) + { + case BLIT_COMMAND_SCREEN_TO_SCREEN: + for (y = 0; y <= size_y; y++) + { + uint16_t *src = (uint16_t *)&voodoo->fb_mem[src_base_addr + src_y*src_stride]; + uint16_t *dst = (uint16_t *)&voodoo->fb_mem[dst_base_addr + dst_y*dst_stride]; + int src_x = voodoo->bltSrcX, dst_x = voodoo->bltDstX; + + for (x = 0; x <= size_x; x++) + { + uint16_t src_dat = src[src_x]; + uint16_t dst_dat = dst[dst_x]; + + if (voodoo->bltCommand & BLIT_CLIPPING_ENABLED) + { + if (dst_x < voodoo->bltClipLeft || dst_x > voodoo->bltClipRight || + dst_y < voodoo->bltClipLowY || dst_y > voodoo->bltClipHighY) + goto skip_pixel_blit; + } + + MIX(src_dat, dst_dat, voodoo->bltRop[3]); + + dst[dst_x] = dst_dat; +skip_pixel_blit: + src_x += x_dir; + dst_x += x_dir; + } + + src_y += y_dir; + dst_y += y_dir; + } break; - case SST_fbiInit3: - temp = voodoo->fbiInit3; + + case BLIT_COMMAND_CPU_TO_SCREEN: + voodoo->blt.dst_x = voodoo->bltDstX; + voodoo->blt.dst_y = voodoo->bltDstY; + voodoo->blt.cur_x = 0; + voodoo->blt.size_x = size_x; + voodoo->blt.size_y = size_y; + voodoo->blt.x_dir = x_dir; + voodoo->blt.y_dir = y_dir; + voodoo->blt.dst_stride = (voodoo->bltCommand & BLTCMD_DST_TILED) ? ((voodoo->bltDstXYStride & 0x3f) * 32*2) : (voodoo->bltDstXYStride & 0xff8); + break; + + case BLIT_COMMAND_RECT_FILL: + for (y = 0; y <= size_y; y++) + { + uint16_t *dst = (uint16_t *)&voodoo->fb_mem[dst_base_addr + dst_y*dst_stride]; + int dst_x = voodoo->bltDstX; + + for (x = 0; x <= size_x; x++) + { + if (voodoo->bltCommand & BLIT_CLIPPING_ENABLED) + { + if (dst_x < voodoo->bltClipLeft || dst_x > voodoo->bltClipRight || + dst_y < voodoo->bltClipLowY || dst_y > voodoo->bltClipHighY) + goto skip_pixel_fill; + } + + dst[dst_x] = voodoo->bltColorFg; +skip_pixel_fill: + dst_x += x_dir; + } + + dst_y += y_dir; + } + break; + + case BLIT_COMMAND_SGRAM_FILL: + /*32x32 tiles - 2kb*/ + dst_y = voodoo->bltDstY & 0x3ff; + size_x = voodoo->bltSizeX & 0x1ff; //512*8 = 4kb + size_y = voodoo->bltSizeY & 0x3ff; + + dat64 = voodoo->bltColorFg | ((uint64_t)voodoo->bltColorFg << 16) | + ((uint64_t)voodoo->bltColorFg << 32) | ((uint64_t)voodoo->bltColorFg << 48); + + for (y = 0; y <= size_y; y++) + { + uint64_t *dst; + + /*This may be wrong*/ + if (!y) + { + dst_x = voodoo->bltDstX & 0x1ff; + size_x = 511 - dst_x; + } + else if (y < size_y) + { + dst_x = 0; + size_x = 511; + } + else + { + dst_x = 0; + size_x = voodoo->bltSizeX & 0x1ff; + } + + dst = (uint64_t *)&voodoo->fb_mem[dst_y*512*8 + dst_x*8]; + + for (x = 0; x <= size_x; x++) + dst[x] = dat64; + + dst_y++; + } break; default: - fatal("voodoo_readl : bad addr %08X\n", addr); - temp = 0xffffffff; + fatal("bad blit command %08x\n", voodoo->bltCommand); } +} - return temp; +static void blit_data(voodoo_t *voodoo, uint32_t data) +{ + uint32_t data_orig = data; + int src_bits = 32; + uint32_t base_addr = (voodoo->bltCommand & BLTCMD_DST_TILED) ? ((voodoo->bltDstBaseAddr & 0x3ff) << 12) : (voodoo->bltDstBaseAddr & 0x3ffff8); + uint16_t *dst = (uint16_t *)&voodoo->fb_mem[base_addr + voodoo->blt.dst_y*voodoo->blt.dst_stride]; + + if ((voodoo->bltCommand & BLIT_COMMAND_MASK) != BLIT_COMMAND_CPU_TO_SCREEN) + return; + + while (src_bits && voodoo->blt.cur_x <= voodoo->blt.size_x) + { + int r, g, b; + uint16_t src_dat, dst_dat; + int x = (voodoo->blt.x_dir > 0) ? (voodoo->blt.dst_x + voodoo->blt.cur_x) : (voodoo->blt.dst_x - voodoo->blt.cur_x); + int rop = 0; + + switch (voodoo->bltCommand & BLIT_SRC_FORMAT) + { + case BLIT_SRC_1BPP: case BLIT_SRC_1BPP_BYTE_PACKED: + src_dat = (data & 1) ? voodoo->bltColorFg : voodoo->bltColorBg; + data >>= 1; + src_bits--; + break; + case BLIT_SRC_16BPP: + switch (voodoo->bltCommand & BLIT_SRC_RGB_FORMAT) + { + case BLIT_SRC_RGB_ARGB: case BLIT_SRC_RGB_RGBA: + src_dat = data & 0xffff; + break; + case BLIT_SRC_RGB_ABGR: case BLIT_SRC_RGB_BGRA: + src_dat = ((data & 0xf800) >> 11) | (data & 0x07c0) | ((data & 0x0038) << 11); + break; + } + data >>= 16; + src_bits -= 16; + break; + case BLIT_SRC_24BPP: case BLIT_SRC_24BPP_DITHER_2X2: case BLIT_SRC_24BPP_DITHER_4X4: + switch (voodoo->bltCommand & BLIT_SRC_RGB_FORMAT) + { + case BLIT_SRC_RGB_ARGB: + r = (data >> 16) & 0xff; + g = (data >> 8) & 0xff; + b = data & 0xff; + break; + case BLIT_SRC_RGB_ABGR: + r = data & 0xff; + g = (data >> 8) & 0xff; + b = (data >> 16) & 0xff; + break; + case BLIT_SRC_RGB_RGBA: + r = (data >> 24) & 0xff; + g = (data >> 16) & 0xff; + b = (data >> 8) & 0xff; + break; + case BLIT_SRC_RGB_BGRA: + r = (data >> 8) & 0xff; + g = (data >> 16) & 0xff; + b = (data >> 24) & 0xff; + break; + } + switch (voodoo->bltCommand & BLIT_SRC_FORMAT) + { + case BLIT_SRC_24BPP: + src_dat = (b >> 3) | ((g & 0xfc) << 3) | ((r & 0xf8) << 8); + break; + case BLIT_SRC_24BPP_DITHER_2X2: + r = dither_rb2x2[r][voodoo->blt.dst_y & 1][x & 1]; + g = dither_g2x2[g][voodoo->blt.dst_y & 1][x & 1]; + b = dither_rb2x2[b][voodoo->blt.dst_y & 1][x & 1]; + src_dat = (b >> 3) | ((g & 0xfc) << 3) | ((r & 0xf8) << 8); + break; + case BLIT_SRC_24BPP_DITHER_4X4: + r = dither_rb[r][voodoo->blt.dst_y & 3][x & 3]; + g = dither_g[g][voodoo->blt.dst_y & 3][x & 3]; + b = dither_rb[b][voodoo->blt.dst_y & 3][x & 3]; + src_dat = (b >> 3) | ((g & 0xfc) << 3) | ((r & 0xf8) << 8); + break; + } + src_bits = 0; + break; + } + + if (voodoo->bltCommand & BLIT_CLIPPING_ENABLED) + { + if (x < voodoo->bltClipLeft || x > voodoo->bltClipRight || + voodoo->blt.dst_y < voodoo->bltClipLowY || voodoo->blt.dst_y > voodoo->bltClipHighY) + goto skip_pixel; + } + + dst_dat = dst[x]; + + if (voodoo->bltCommand & BLIT_SRC_CHROMA) + { + r = (src_dat >> 11); + g = (src_dat >> 5) & 0x3f; + b = src_dat & 0x1f; + + if (r >= voodoo->bltSrcChromaMinR && r <= voodoo->bltSrcChromaMaxR && + g >= voodoo->bltSrcChromaMinG && g <= voodoo->bltSrcChromaMaxG && + b >= voodoo->bltSrcChromaMinB && b <= voodoo->bltSrcChromaMaxB) + rop |= BLIT_ROP_SRC_PASS; + } + if (voodoo->bltCommand & BLIT_DST_CHROMA) + { + r = (dst_dat >> 11); + g = (dst_dat >> 5) & 0x3f; + b = dst_dat & 0x1f; + + if (r >= voodoo->bltDstChromaMinR && r <= voodoo->bltDstChromaMaxR && + g >= voodoo->bltDstChromaMinG && g <= voodoo->bltDstChromaMaxG && + b >= voodoo->bltDstChromaMinB && b <= voodoo->bltDstChromaMaxB) + rop |= BLIT_ROP_DST_PASS; + } + + MIX(src_dat, dst_dat, voodoo->bltRop[rop]); + + dst[x] = dst_dat; + +skip_pixel: + voodoo->blt.cur_x++; + } + + if (voodoo->blt.cur_x > voodoo->blt.size_x) + { + voodoo->blt.size_y--; + if (voodoo->blt.size_y >= 0) + { + voodoo->blt.cur_x = 0; + voodoo->blt.dst_y += voodoo->blt.y_dir; + } + } } enum @@ -3301,7 +3980,7 @@ static void voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) chip = 0xf; tempif.i = val; -//pclog("voodoo_write_l: addr=%08x val=%08x(%f) chip=%x\n", addr, val, tempif.f, chip); +//pclog("voodoo_reg_write_l: addr=%08x val=%08x(%f) chip=%x\n", addr, val, tempif.f, chip); addr &= 0x3fc; if ((voodoo->fbiInit3 & FBIINIT3_REMAP) && addr < 0x100 && ad21) @@ -3311,7 +3990,16 @@ static void voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) case SST_swapbufferCMD: // pclog(" start swap buffer command\n"); - voodoo->disp_buffer = !voodoo->disp_buffer; + if (TRIPLE_BUFFER) + { + voodoo->disp_buffer = (voodoo->disp_buffer + 1) % 3; + voodoo->draw_buffer = (voodoo->draw_buffer + 1) % 3; + } + else + { + voodoo->disp_buffer = !voodoo->disp_buffer; + voodoo->draw_buffer = !voodoo->draw_buffer; + } voodoo_recalc(voodoo); voodoo->params.swapbufferCMD = val; @@ -3742,6 +4430,195 @@ static void voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo->params.fogTable[addr+1].fog = (val >> 24) & 0xff; break; + case SST_clutData: + voodoo->clutData[(val >> 24) & 0x3f].b = val & 0xff; + voodoo->clutData[(val >> 24) & 0x3f].g = (val >> 8) & 0xff; + voodoo->clutData[(val >> 24) & 0x3f].r = (val >> 16) & 0xff; + if (val & 0x20000000) + { + voodoo->clutData[(val >> 24) & 0x3f].b = 255; + voodoo->clutData[(val >> 24) & 0x3f].g = 255; + voodoo->clutData[(val >> 24) & 0x3f].r = 255; + } + voodoo->clutData_dirty = 1; + break; + + case SST_sSetupMode: + voodoo->sSetupMode = val; + break; + case SST_sVx: + tempif.i = val; + voodoo->verts[3].sVx = tempif.f; +// pclog("sVx[%i]=%f\n", voodoo->vertex_num, tempif.f); + break; + case SST_sVy: + tempif.i = val; + voodoo->verts[3].sVy = tempif.f; +// pclog("sVy[%i]=%f\n", voodoo->vertex_num, tempif.f); + break; + case SST_sARGB: + voodoo->verts[3].sBlue = (float)(val & 0xff); + voodoo->verts[3].sGreen = (float)((val >> 8) & 0xff); + voodoo->verts[3].sRed = (float)((val >> 16) & 0xff); + voodoo->verts[3].sAlpha = (float)((val >> 24) & 0xff); + break; + case SST_sRed: + tempif.i = val; + voodoo->verts[3].sRed = tempif.f; + break; + case SST_sGreen: + tempif.i = val; + voodoo->verts[3].sGreen = tempif.f; + break; + case SST_sBlue: + tempif.i = val; + voodoo->verts[3].sBlue = tempif.f; + break; + case SST_sAlpha: + tempif.i = val; + voodoo->verts[3].sAlpha = tempif.f; + break; + case SST_sVz: + tempif.i = val; + voodoo->verts[3].sVz = tempif.f; + break; + case SST_sWb: + tempif.i = val; + voodoo->verts[3].sWb = tempif.f; + break; + case SST_sW0: + tempif.i = val; + voodoo->verts[3].sW0 = tempif.f; + break; + case SST_sS0: + tempif.i = val; + voodoo->verts[3].sS0 = tempif.f; + break; + case SST_sT0: + tempif.i = val; + voodoo->verts[3].sT0 = tempif.f; + break; + case SST_sW1: + tempif.i = val; + voodoo->verts[3].sW1 = tempif.f; + break; + case SST_sS1: + tempif.i = val; + voodoo->verts[3].sS1 = tempif.f; + break; + case SST_sT1: + tempif.i = val; + voodoo->verts[3].sT1 = tempif.f; + break; + + case SST_sBeginTriCMD: +// pclog("sBeginTriCMD %i %f\n", voodoo->vertex_num, voodoo->verts[4].sVx); + voodoo->verts[0] = voodoo->verts[3]; + voodoo->vertex_num = 1; + voodoo->num_verticies = 1; + break; + case SST_sDrawTriCMD: +// pclog("sDrawTriCMD %i %i %i\n", voodoo->num_verticies, voodoo->vertex_num, voodoo->sSetupMode & SETUPMODE_STRIP_MODE); + if (voodoo->vertex_num == 3) + voodoo->vertex_num = (voodoo->sSetupMode & SETUPMODE_STRIP_MODE) ? 1 : 0; + voodoo->verts[voodoo->vertex_num] = voodoo->verts[3]; + + voodoo->num_verticies++; + voodoo->vertex_num++; + if (voodoo->num_verticies == 3) + { +// pclog("triangle_setup\n"); + triangle_setup(voodoo); + + voodoo->num_verticies = 2; + } + if (voodoo->vertex_num == 4) + fatal("sDrawTriCMD overflow\n"); + break; + + case SST_bltSrcBaseAddr: + voodoo->bltSrcBaseAddr = val & 0x3fffff; + break; + case SST_bltDstBaseAddr: +// pclog("Write bltDstBaseAddr %08x\n", val); + voodoo->bltDstBaseAddr = val & 0x3fffff; + break; + case SST_bltXYStrides: + voodoo->bltSrcXYStride = val & 0xfff; + voodoo->bltDstXYStride = (val >> 16) & 0xfff; +// pclog("Write bltXYStrides %08x\n", val); + break; + case SST_bltSrcChromaRange: + voodoo->bltSrcChromaRange = val; + voodoo->bltSrcChromaMinR = val & 0x1f; + voodoo->bltSrcChromaMinG = (val >> 5) & 0x3f; + voodoo->bltSrcChromaMinB = (val >> 11) & 0x1f; + voodoo->bltSrcChromaMaxR = (val >> 16) & 0x1f; + voodoo->bltSrcChromaMaxG = (val >> 21) & 0x3f; + voodoo->bltSrcChromaMaxB = (val >> 27) & 0x1f; + break; + case SST_bltDstChromaRange: + voodoo->bltDstChromaRange = val; + voodoo->bltDstChromaMinR = val & 0x1f; + voodoo->bltDstChromaMinG = (val >> 5) & 0x3f; + voodoo->bltDstChromaMinB = (val >> 11) & 0x1f; + voodoo->bltDstChromaMaxR = (val >> 16) & 0x1f; + voodoo->bltDstChromaMaxG = (val >> 21) & 0x3f; + voodoo->bltDstChromaMaxB = (val >> 27) & 0x1f; + break; + case SST_bltClipX: + voodoo->bltClipRight = val & 0xfff; + voodoo->bltClipLeft = (val >> 16) & 0xfff; + break; + case SST_bltClipY: + voodoo->bltClipHighY = val & 0xfff; + voodoo->bltClipLowY = (val >> 16) & 0xfff; + break; + + case SST_bltSrcXY: + voodoo->bltSrcX = val & 0x7ff; + voodoo->bltSrcY = (val >> 16) & 0x7ff; + break; + case SST_bltDstXY: +// pclog("Write bltDstXY %08x\n", val); + voodoo->bltDstX = val & 0x7ff; + voodoo->bltDstY = (val >> 16) & 0x7ff; + if (val & (1 << 31)) + blit_start(voodoo); + break; + case SST_bltSize: +// pclog("Write bltSize %08x\n", val); + voodoo->bltSizeX = val & 0xfff; + if (voodoo->bltSizeX & 0x800) + voodoo->bltSizeX |= 0xfffff000; + voodoo->bltSizeY = (val >> 16) & 0xfff; + if (voodoo->bltSizeY & 0x800) + voodoo->bltSizeY |= 0xfffff000; + if (val & (1 << 31)) + blit_start(voodoo); + break; + case SST_bltRop: + voodoo->bltRop[0] = val & 0xf; + voodoo->bltRop[1] = (val >> 4) & 0xf; + voodoo->bltRop[2] = (val >> 8) & 0xf; + voodoo->bltRop[3] = (val >> 12) & 0xf; + break; + case SST_bltColor: +// pclog("Write bltColor %08x\n", val); + voodoo->bltColorFg = val & 0xffff; + voodoo->bltColorBg = (val >> 16) & 0xffff; + break; + + case SST_bltCommand: + voodoo->bltCommand = val; +// pclog("Write bltCommand %08x\n", val); + if (val & (1 << 31)) + blit_start(voodoo); + break; + case SST_bltData: + blit_data(voodoo, val); + break; + case SST_textureMode: if (chip & CHIP_TREX0) { @@ -4181,6 +5058,10 @@ static void voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) voodoo->ncc_dirty[1] = 1; } break; + + case SST_userIntrCMD: + fatal("userIntrCMD write %08x from FIFO\n", val); + break; } } @@ -4331,7 +5212,7 @@ static void voodoo_fb_writew(uint32_t addr, uint16_t val, void *p) int32_t w_depth = new_depth; int32_t ia = alpha_data << 12; - APPLY_FOG(write_data.r, write_data.g, write_data.b, z, ia); + APPLY_FOG(write_data.r, write_data.g, write_data.b, z, ia, w_depth); } if (params->alphaMode & 1) @@ -4472,7 +5353,7 @@ static void voodoo_fb_writel(uint32_t addr, uint32_t val, void *p) int32_t w_depth = new_depth; int32_t ia = alpha_data[c] << 12; - APPLY_FOG(write_data.r, write_data.g, write_data.b, z, ia); + APPLY_FOG(write_data.r, write_data.g, write_data.b, z, ia, w_depth); } if (params->alphaMode & 1) @@ -4598,10 +5479,10 @@ static inline void queue_command(voodoo_t *voodoo, uint32_t addr_type, uint32_t static uint16_t voodoo_readw(uint32_t addr, void *p) { voodoo_t *voodoo = (voodoo_t *)p; - + addr &= 0xffffff; - cycles -= pci_nonburst_time; + cycles -= voodoo->read_time; if ((addr & 0xc00000) == 0x400000) /*Framebuffer*/ { @@ -4628,7 +5509,7 @@ static uint32_t voodoo_readl(uint32_t addr, void *p) voodoo->rd_count++; addr &= 0xffffff; - cycles -= pci_nonburst_time; + cycles -= voodoo->read_time; if (addr & 0x800000) /*Texture*/ { @@ -4711,6 +5592,40 @@ static uint32_t voodoo_readl(uint32_t addr, void *p) case SST_fbiInit3: temp = voodoo->fbiInit3; break; + + case SST_hvRetrace: + timer_clock(); + temp = voodoo->line & 0x1fff; + temp |= ((((voodoo->line_time - voodoo->timer_count) * voodoo->h_total) / voodoo->timer_count) << 16) & 0x7ff0000; + break; + + case SST_fbiInit5: + temp = voodoo->fbiInit5 & ~0x41ff; + break; + case SST_fbiInit6: + temp = voodoo->fbiInit6; + break; + case SST_fbiInit7: + temp = voodoo->fbiInit7 & ~0xff; + break; + + case SST_cmdFifoBaseAddr: + temp = voodoo->cmdfifo_base >> 12; + temp |= (voodoo->cmdfifo_end >> 12) << 16; + break; + + case SST_cmdFifoRdPtr: + temp = voodoo->cmdfifo_rp; + break; + case SST_cmdFifoAMin: + temp = voodoo->cmdfifo_amin; + break; + case SST_cmdFifoAMax: + temp = voodoo->cmdfifo_amax; + break; + case SST_cmdFifoDepth: + temp = voodoo->cmdfifo_depth_wr - voodoo->cmdfifo_depth_rd; + break; default: fatal("voodoo_readl : bad addr %08X\n", addr); @@ -4727,9 +5642,9 @@ static void voodoo_writew(uint32_t addr, uint16_t val, void *p) addr &= 0xffffff; if (addr == voodoo->last_write_addr+4) - cycles -= pci_burst_time; + cycles -= voodoo->burst_time; else - cycles -= pci_nonburst_time; + cycles -= voodoo->write_time; voodoo->last_write_addr = addr; if ((addr & 0xc00000) == 0x400000) /*Framebuffer*/ @@ -4763,52 +5678,86 @@ static void voodoo_pixelclock_update(voodoo_t *voodoo) static void voodoo_writel(uint32_t addr, uint32_t val, void *p) { voodoo_t *voodoo = (voodoo_t *)p; - voodoo->wr_count++; - addr &= 0xffffff; + union + { + uint32_t i; + float f; + } tempif; + tempif.i = val; + voodoo->wr_count++; + + addr &= 0xffffff; + if (addr == voodoo->last_write_addr+4) - cycles -= pci_burst_time; + cycles -= voodoo->burst_time; else - cycles -= pci_nonburst_time; + cycles -= voodoo->write_time; voodoo->last_write_addr = addr; if (addr & 0x800000) /*Texture*/ { - voodoo->tex_count++; + voodoo->tex_count++; queue_command(voodoo, addr | FIFO_WRITEL_TEX, val); } else if (addr & 0x400000) /*Framebuffer*/ { queue_command(voodoo, addr | FIFO_WRITEL_FB, val); } + else if ((addr & 0x200000) && (voodoo->fbiInit7 & FBIINIT7_CMDFIFO_ENABLE)) + { +// pclog("Write CMDFIFO %08x(%08x) %08x %08x\n", addr, voodoo->cmdfifo_base + (addr & 0x3fffc), val, (voodoo->cmdfifo_base + (addr & 0x3fffc)) & voodoo->fb_mask); + *(uint32_t *)&voodoo->fb_mem[(voodoo->cmdfifo_base + (addr & 0x3fffc)) & voodoo->fb_mask] = val; + voodoo->cmdfifo_depth_wr++; + if ((voodoo->cmdfifo_depth_wr - voodoo->cmdfifo_depth_rd) < 20) + thread_set_event(voodoo->wake_fifo_thread); + } else switch (addr & 0x3fc) { + case SST_intrCtrl: + fatal("intrCtrl write %08x\n", val); + break; + + case SST_userIntrCMD: + fatal("userIntrCMD write %08x\n", val); + break; + case SST_swapbufferCMD: voodoo->cmd_written++; voodoo->swap_count++; + if (voodoo->fbiInit7 & FBIINIT7_CMDFIFO_ENABLE) + return; queue_command(voodoo, addr | FIFO_WRITEL_REG, val); if (!voodoo->voodoo_busy) wake_fifo_thread(voodoo); break; case SST_triangleCMD: + if (voodoo->fbiInit7 & FBIINIT7_CMDFIFO_ENABLE) + return; voodoo->cmd_written++; queue_command(voodoo, addr | FIFO_WRITEL_REG, val); if (!voodoo->voodoo_busy) wake_fifo_thread(voodoo); break; case SST_ftriangleCMD: + if (voodoo->fbiInit7 & FBIINIT7_CMDFIFO_ENABLE) + return; voodoo->cmd_written++; queue_command(voodoo, addr | FIFO_WRITEL_REG, val); if (!voodoo->voodoo_busy) wake_fifo_thread(voodoo); break; case SST_fastfillCMD: + if (voodoo->fbiInit7 & FBIINIT7_CMDFIFO_ENABLE) + return; voodoo->cmd_written++; queue_command(voodoo, addr | FIFO_WRITEL_REG, val); if (!voodoo->voodoo_busy) wake_fifo_thread(voodoo); break; case SST_nopCMD: + if (voodoo->fbiInit7 & FBIINIT7_CMDFIFO_ENABLE) + return; voodoo->cmd_written++; queue_command(voodoo, addr | FIFO_WRITEL_REG, val); if (!voodoo->voodoo_busy) @@ -4817,7 +5766,11 @@ static void voodoo_writel(uint32_t addr, uint32_t val, void *p) case SST_fbiInit4: if (voodoo->initEnable & 0x01) + { voodoo->fbiInit4 = val; + voodoo->read_time = pci_nonburst_time + pci_burst_time * ((voodoo->fbiInit4 & 1) ? 2 : 1); +// pclog("fbiInit4 write %08x - read_time=%i\n", val, voodoo->read_time); + } break; case SST_backPorch: voodoo->backPorch = val; @@ -4832,11 +5785,23 @@ static void voodoo_writel(uint32_t addr, uint32_t val, void *p) { voodoo->fbiInit0 = val; svga_set_override(voodoo->svga, val & 1); + if (val & FBIINIT0_GRAPHICS_RESET) + { + /*Reset display/draw buffer selection. This may not actually + happen here on a real Voodoo*/ + voodoo->disp_buffer = 0; + voodoo->draw_buffer = 1; + } } break; case SST_fbiInit1: if (voodoo->initEnable & 0x01) + { voodoo->fbiInit1 = val; + voodoo->write_time = pci_nonburst_time + pci_burst_time * ((voodoo->fbiInit1 & 2) ? 1 : 0); + voodoo->burst_time = pci_burst_time * ((voodoo->fbiInit1 & 2) ? 2 : 1); +// pclog("fbiInit1 write %08x - write_time=%i burst_time=%i\n", val, voodoo->write_time, voodoo->burst_time); + } break; case SST_fbiInit2: if (voodoo->initEnable & 0x01) @@ -4852,6 +5817,7 @@ static void voodoo_writel(uint32_t addr, uint32_t val, void *p) case SST_hSync: voodoo->hSync = val; + voodoo->h_total = (val & 0xffff) + (val >> 16); voodoo_pixelclock_update(voodoo); break; case SST_vSync: @@ -4863,6 +5829,12 @@ static void voodoo_writel(uint32_t addr, uint32_t val, void *p) voodoo->clutData[(val >> 24) & 0x3f].b = val & 0xff; voodoo->clutData[(val >> 24) & 0x3f].g = (val >> 8) & 0xff; voodoo->clutData[(val >> 24) & 0x3f].r = (val >> 16) & 0xff; + if (val & 0x20000000) + { + voodoo->clutData[(val >> 24) & 0x3f].b = 255; + voodoo->clutData[(val >> 24) & 0x3f].g = 255; + voodoo->clutData[(val >> 24) & 0x3f].r = 255; + } voodoo->clutData_dirty = 1; break; @@ -4907,12 +5879,97 @@ static void voodoo_writel(uint32_t addr, uint32_t val, void *p) } break; + case SST_fbiInit5: + if (voodoo->initEnable & 0x01) + voodoo->fbiInit5 = val; + break; + case SST_fbiInit6: + if (voodoo->initEnable & 0x01) + voodoo->fbiInit6 = val; + break; + case SST_fbiInit7: + if (voodoo->initEnable & 0x01) + voodoo->fbiInit7 = val; + break; + + case SST_cmdFifoBaseAddr: + voodoo->cmdfifo_base = (val & 0x3ff) << 12; + voodoo->cmdfifo_end = ((val >> 16) & 0x3ff) << 12; +// pclog("CMDFIFO base=%08x end=%08x\n", voodoo->cmdfifo_base, voodoo->cmdfifo_end); + break; + + case SST_cmdFifoRdPtr: + voodoo->cmdfifo_rp = val; + break; + case SST_cmdFifoAMin: + voodoo->cmdfifo_amin = val; + break; + case SST_cmdFifoAMax: + voodoo->cmdfifo_amax = val; + break; + case SST_cmdFifoDepth: + voodoo->cmdfifo_depth_rd = 0; + voodoo->cmdfifo_depth_wr = val & 0xffff; + break; + default: - queue_command(voodoo, addr | FIFO_WRITEL_REG, val); + if (voodoo->fbiInit7 & FBIINIT7_CMDFIFO_ENABLE) + { + fatal("Unknown register write in CMDFIFO mode %08x %08x\n", addr, val); + } + else + { + queue_command(voodoo, addr | FIFO_WRITEL_REG, val); + } break; } } +static uint32_t cmdfifo_get(voodoo_t *voodoo) +{ + uint32_t val; + + while (voodoo->cmdfifo_depth_rd == voodoo->cmdfifo_depth_wr) + { + thread_wait_event(voodoo->wake_fifo_thread, -1); + thread_reset_event(voodoo->wake_fifo_thread); + } + + val = *(uint32_t *)&voodoo->fb_mem[voodoo->cmdfifo_rp & voodoo->fb_mask]; + + voodoo->cmdfifo_depth_rd++; + voodoo->cmdfifo_rp += 4; + +// pclog(" CMDFIFO get %08x\n", val); + return val; +} + +static inline float cmdfifo_get_f(voodoo_t *voodoo) +{ + union + { + uint32_t i; + float f; + } tempif; + + tempif.i = cmdfifo_get(voodoo); + return tempif.f; +} + +enum +{ + CMDFIFO3_PC_MASK_RGB = (1 << 10), + CMDFIFO3_PC_MASK_ALPHA = (1 << 11), + CMDFIFO3_PC_MASK_Z = (1 << 12), + CMDFIFO3_PC_MASK_Wb = (1 << 13), + CMDFIFO3_PC_MASK_W0 = (1 << 14), + CMDFIFO3_PC_MASK_S0_T0 = (1 << 15), + CMDFIFO3_PC_MASK_W1 = (1 << 16), + CMDFIFO3_PC_MASK_S1_T1 = (1 << 17), + + CMDFIFO3_PC = (1 << 28) +}; + static void fifo_thread(void *param) { voodoo_t *voodoo = (voodoo_t *)param; @@ -4956,8 +6013,184 @@ static void fifo_thread(void *param) end_time = timer_read(); voodoo_time += end_time - start_time; } - voodoo->voodoo_busy = 0; + while (voodoo->cmdfifo_depth_rd != voodoo->cmdfifo_depth_wr) + { + uint64_t start_time = timer_read(); + uint64_t end_time; + uint32_t header = cmdfifo_get(voodoo); + uint32_t addr; + uint32_t mask; + int smode; + int num; + int num_verticies; + int v_num; + +// pclog(" CMDFIFO header %08x at %08x\n", header, voodoo->cmdfifo_rp); + + switch (header & 7) + { + case 0: +// pclog("CMDFIFO0\n"); + switch ((header >> 3) & 7) + { + case 0: /*NOP*/ + break; + + case 3: /*JMP local frame buffer*/ + voodoo->cmdfifo_rp = (header >> 4) & 0xfffffc; +// pclog("JMP to %08x %04x\n", voodoo->cmdfifo_rp, header); + break; + + default: + fatal("Bad CMDFIFO0 %08x\n", header); + } + break; + + case 1: + num = header >> 16; + addr = (header & 0x7ff8) >> 1; +// pclog("CMDFIFO1 addr=%08x\n",addr); + while (num--) + { + uint32_t val = cmdfifo_get(voodoo); + if ((addr & 0x3ff) == SST_triangleCMD || (addr & 0x3ff) == SST_ftriangleCMD || + (addr & 0x3ff) == SST_fastfillCMD || (addr & 0x3ff) == SST_nopCMD) + voodoo->cmd_written++; + + voodoo_reg_writel(addr, val, voodoo); + + if (header & (1 << 15)) + addr += 4; + } + break; + + case 3: + num = (header >> 29) & 7; + mask = header;//(header >> 10) & 0xff; + smode = (header >> 22) & 0xf; + voodoo_reg_writel(SST_sSetupMode, ((header >> 10) & 0xff) | (smode << 16), voodoo); + num_verticies = (header >> 6) & 0xf; + v_num = 0; + if (((header >> 3) & 7) == 2) + v_num = 1; +// pclog("CMDFIFO3: num=%i verts=%i mask=%02x\n", num, num_verticies, (header >> 10) & 0xff); +// pclog("CMDFIFO3 %02x %i\n", (header >> 10), (header >> 3) & 7); + + while (num_verticies--) + { + voodoo->verts[3].sVx = cmdfifo_get_f(voodoo); + voodoo->verts[3].sVy = cmdfifo_get_f(voodoo); + if (mask & CMDFIFO3_PC_MASK_RGB) + { + if (header & CMDFIFO3_PC) + { + uint32_t val = cmdfifo_get(voodoo); + voodoo->verts[3].sBlue = (float)(val & 0xff); + voodoo->verts[3].sGreen = (float)((val >> 8) & 0xff); + voodoo->verts[3].sRed = (float)((val >> 16) & 0xff); + voodoo->verts[3].sAlpha = (float)((val >> 24) & 0xff); + } + else + { + voodoo->verts[3].sRed = cmdfifo_get_f(voodoo); + voodoo->verts[3].sGreen = cmdfifo_get_f(voodoo); + voodoo->verts[3].sBlue = cmdfifo_get_f(voodoo); + } + } + if ((mask & CMDFIFO3_PC_MASK_ALPHA) && !(header & CMDFIFO3_PC)) + voodoo->verts[3].sAlpha = cmdfifo_get_f(voodoo); + if (mask & CMDFIFO3_PC_MASK_Z) + voodoo->verts[3].sVz = cmdfifo_get_f(voodoo); + if (mask & CMDFIFO3_PC_MASK_Wb) + voodoo->verts[3].sWb = cmdfifo_get_f(voodoo); + if (mask & CMDFIFO3_PC_MASK_W0) + voodoo->verts[3].sW0 = cmdfifo_get_f(voodoo); + if (mask & CMDFIFO3_PC_MASK_S0_T0) + { + voodoo->verts[3].sS0 = cmdfifo_get_f(voodoo); + voodoo->verts[3].sT0 = cmdfifo_get_f(voodoo); + } + if (mask & CMDFIFO3_PC_MASK_W1) + voodoo->verts[3].sW1 = cmdfifo_get_f(voodoo); + if (mask & CMDFIFO3_PC_MASK_S1_T1) + { + voodoo->verts[3].sS1 = cmdfifo_get_f(voodoo); + voodoo->verts[3].sT1 = cmdfifo_get_f(voodoo); + } + if (v_num) + voodoo_reg_writel(SST_sDrawTriCMD, 0, voodoo); + else + voodoo_reg_writel(SST_sBeginTriCMD, 0, voodoo); + v_num++; + if (v_num == 3 && ((header >> 3) & 7) == 0) + v_num = 0; + } + break; + + case 4: + num = (header >> 29) & 7; + mask = (header >> 15) & 0x3fff; + addr = (header & 0x7ff8) >> 1; +// pclog("CMDFIFO4 addr=%08x\n",addr); + while (mask) + { + if (mask & 1) + { + uint32_t val = cmdfifo_get(voodoo); + if ((addr & 0x3ff) == SST_triangleCMD || (addr & 0x3ff) == SST_ftriangleCMD || + (addr & 0x3ff) == SST_fastfillCMD || (addr & 0x3ff) == SST_nopCMD) + voodoo->cmd_written++; + + voodoo_reg_writel(addr, val, voodoo); + } + + addr += 4; + mask >>= 1; + } + while (num--) + cmdfifo_get(voodoo); + break; + + case 5: + if (header & 0x3fc0000) + fatal("CMDFIFO packet 5 has byte disables set %08x\n", header); + num = (header >> 3) & 0x7ffff; + addr = cmdfifo_get(voodoo) & 0xffffff; +// pclog("CMDFIFO5 addr=%08x num=%i\n", addr, num); + switch (header >> 30) + { + case 2: /*Framebuffer*/ + while (num--) + { + uint32_t val = cmdfifo_get(voodoo); + voodoo_fb_writel(addr, val, voodoo); + addr += 4; + } + break; + case 3: /*Texture*/ + while (num--) + { + uint32_t val = cmdfifo_get(voodoo); + voodoo_tex_writel(addr, val, voodoo); + addr += 4; + } + break; + + default: + fatal("CMDFIFO packet 5 bad space %08x %08x\n", header, voodoo->cmdfifo_rp); + } + break; + + default: + fatal("Bad CMDFIFO packet %08x %08x\n", header, voodoo->cmdfifo_rp); + } + + end_time = timer_read(); + voodoo_time += end_time - start_time; + } + + voodoo->voodoo_busy = 0; } } @@ -4979,26 +6212,45 @@ uint8_t voodoo_pci_read(int func, int addr, void *p) { voodoo_t *voodoo = (voodoo_t *)p; - pclog("Voodoo PCI read %08X\n", addr); + if (func) + return 0; + +// pclog("Voodoo PCI read %08X PC=%08x\n", addr, cpu_state.pc); + switch (addr) { case 0x00: return 0x1a; /*3dfx*/ case 0x01: return 0x12; - case 0x02: return 0x01; /*SST-1 (Voodoo Graphics)*/ + case 0x02: + if (voodoo->type == VOODOO_2) + return 0x02; /*Voodoo 2*/ + else + return 0x01; /*SST-1 (Voodoo Graphics)*/ case 0x03: return 0x00; case 0x04: return voodoo->pci_enable ? 0x02 : 0x00; /*Respond to memory accesses*/ case 0x08: return 2; /*Revision ID*/ case 0x09: return 0; /*Programming interface*/ + case 0x0a: return 0; + case 0x0b: return 0x04; case 0x10: return 0x00; /*memBaseAddr*/ case 0x11: return 0x00; case 0x12: return 0x00; case 0x13: return voodoo->memBaseAddr >> 24; - case 0x40: return voodoo->initEnable; + case 0x40: + return voodoo->initEnable & 0xff; + case 0x41: + if (voodoo->type == VOODOO_2) + return 0x50 | ((voodoo->initEnable >> 8) & 0x0f); + return (voodoo->initEnable >> 8) & 0x0f; + case 0x42: + return (voodoo->initEnable >> 16) & 0xff; + case 0x43: + return (voodoo->initEnable >> 24) & 0xff; } return 0; } @@ -5007,7 +6259,11 @@ void voodoo_pci_write(int func, int addr, uint8_t val, void *p) { voodoo_t *voodoo = (voodoo_t *)p; - pclog("Voodoo PCI write %04X %02X\n", addr, val); + if (func) + return; + +// pclog("Voodoo PCI write %04X %02X PC=%08x\n", addr, val, cpu_state.pc); + switch (addr) { case 0x04: @@ -5021,7 +6277,16 @@ void voodoo_pci_write(int func, int addr, uint8_t val, void *p) break; case 0x40: - voodoo->initEnable = val; + voodoo->initEnable = (voodoo->initEnable & ~0x000000ff) | val; + break; + case 0x41: + voodoo->initEnable = (voodoo->initEnable & ~0x0000ff00) | (val << 8); + break; + case 0x42: + voodoo->initEnable = (voodoo->initEnable & ~0x00ff0000) | (val << 16); + break; + case 0x43: + voodoo->initEnable = (voodoo->initEnable & ~0xff000000) | (val << 24); break; } } @@ -5301,12 +6566,15 @@ static void voodoo_speed_changed(void *p) voodoo_t *voodoo = (voodoo_t *)p; voodoo_pixelclock_update(voodoo); + voodoo->read_time = pci_nonburst_time + pci_burst_time * ((voodoo->fbiInit4 & 1) ? 2 : 1); + voodoo->write_time = pci_nonburst_time + pci_burst_time * ((voodoo->fbiInit1 & 2) ? 1 : 0); + voodoo->burst_time = pci_burst_time * ((voodoo->fbiInit1 & 2) ? 2 : 1); +// pclog("Voodoo read_time=%i write_time=%i burst_time=%i %08x %08x\n", voodoo->read_time, voodoo->write_time, voodoo->burst_time, voodoo->fbiInit1, voodoo->fbiInit4); } void *voodoo_init() { int c; - int type; voodoo_t *voodoo = malloc(sizeof(voodoo_t)); memset(voodoo, 0, sizeof(voodoo_t)); @@ -5321,14 +6589,25 @@ void *voodoo_init() #ifndef NO_CODEGEN voodoo->use_recompiler = device_get_config_int("recompiler"); #endif - type = device_get_config_int("type"); - voodoo->dual_tmus = type ? 1 : 0; + voodoo->type = device_get_config_int("type"); + switch (voodoo->type) + { + case VOODOO_1: + voodoo->dual_tmus = 0; + break; + case VOODOO_SB50: + voodoo->dual_tmus = 1; + break; + case VOODOO_2: + voodoo->dual_tmus = 1; + break; + } voodoo_generate_filter(voodoo); /*generate filter lookup tables*/ pci_add(voodoo_pci_read, voodoo_pci_write, voodoo); - mem_mapping_add(&voodoo->mapping, 0, 0, NULL, voodoo_readw, voodoo_readl, NULL, voodoo_writew, voodoo_writel, NULL, 0, voodoo); + mem_mapping_add(&voodoo->mapping, 0, 0, NULL, voodoo_readw, voodoo_readl, NULL, voodoo_writew, voodoo_writel, NULL, MEM_MAPPING_EXTERNAL, voodoo); voodoo->fb_mem = malloc(4 * 1024 * 1024); voodoo->tex_mem[0] = malloc(voodoo->texture_size * 1024 * 1024); @@ -5366,7 +6645,7 @@ void *voodoo_init() voodoo->render_thread[0] = thread_create(render_thread_1, voodoo); if (voodoo->render_threads == 2) voodoo->render_thread[1] = thread_create(render_thread_2, voodoo); - + for (c = 0; c < 0x100; c++) { rgb332[c].r = c & 0xe0; @@ -5418,6 +6697,10 @@ void *voodoo_init() #ifndef NO_CODEGEN voodoo_codegen_init(voodoo); #endif + + voodoo->disp_buffer = 0; + voodoo->draw_buffer = 1; + return voodoo; } @@ -5477,11 +6760,15 @@ static device_config_t voodoo_config[] = { { .description = "Voodoo Graphics", - .value = 0 + .value = VOODOO_1 }, { .description = "Obsidian SB50 + Amethyst (2 TMUs)", - .value = 1 + .value = VOODOO_SB50 + }, + { + .description = "Voodoo 2", + .value = VOODOO_2 }, { .description = "" diff --git a/src/vid_voodoo.h b/src/vid_voodoo.h index 52d786f3a..047978327 100644 --- a/src/vid_voodoo.h +++ b/src/vid_voodoo.h @@ -1,4 +1 @@ -/* Copyright holders: Sarah Walker - see COPYING for more details -*/ extern device_t voodoo_device; diff --git a/src/vid_voodoo_codegen_x86-64.h b/src/vid_voodoo_codegen_x86-64.h index 06f635cd6..14b9dd305 100644 --- a/src/vid_voodoo_codegen_x86-64.h +++ b/src/vid_voodoo_codegen_x86-64.h @@ -21,6 +21,8 @@ #define BLOCK_MASK (BLOCK_NUM-1) #define BLOCK_SIZE 8192 +#define LOD_MASK (LOD_TMIRROR_S | LOD_TMIRROR_T) + typedef struct voodoo_x86_data_t { uint8_t code_block[BLOCK_SIZE]; @@ -29,7 +31,8 @@ typedef struct voodoo_x86_data_t uint32_t fbzMode; uint32_t fogMode; uint32_t fbzColorPath; - uint32_t textureMode; + uint32_t textureMode[2]; + uint32_t tLOD[2]; uint32_t trexInit1; } voodoo_x86_data_t; @@ -250,6 +253,25 @@ static inline int codegen_texture_fetch(uint8_t *code_block, voodoo_t *voodoo, v addbyte(0x8b); /*MOV EBX, state->tex_t[RDI]*/ addbyte(0x9f); addlong(offsetof(voodoo_state_t, tex_t)); + if (params->tLOD[tmu] & LOD_TMIRROR_S) + { + addbyte(0xa9); /*TEST EAX, 0x1000*/ + addlong(0x1000); + addbyte(0x74); /*JZ +*/ + addbyte(2); + addbyte(0xf7); /*NOT EAX*/ + addbyte(0xd0); + } + if (params->tLOD[tmu] & LOD_TMIRROR_T) + { + addbyte(0xf7); /*TEST EBX, 0x1000*/ + addbyte(0xc3); + addlong(0x1000); + addbyte(0x74); /*JZ +*/ + addbyte(2); + addbyte(0xf7); /*NOT EBX*/ + addbyte(0xd3); + } addbyte(0x29); /*SUB EAX, EBP*/ addbyte(0xe8); addbyte(0x29); /*SUB EBX, EBP*/ @@ -567,6 +589,25 @@ static inline int codegen_texture_fetch(uint8_t *code_block, voodoo_t *voodoo, v addbyte(0x8b); /*MOV EBX, state->tex_t[EDI]*/ addbyte(0x9f); addlong(offsetof(voodoo_state_t, tex_t)); + if (params->tLOD[tmu] & LOD_TMIRROR_S) + { + addbyte(0xa9); /*TEST EAX, 0x1000*/ + addlong(0x1000); + addbyte(0x74); /*JZ +*/ + addbyte(2); + addbyte(0xf7); /*NOT EAX*/ + addbyte(0xd0); + } + if (params->tLOD[tmu] & LOD_TMIRROR_T) + { + addbyte(0xf7); /*TEST EBX, 0x1000*/ + addbyte(0xc3); + addlong(0x1000); + addbyte(0x74); /*JZ +*/ + addbyte(2); + addbyte(0xf7); /*NOT EBX*/ + addbyte(0xd3); + } addbyte(0xd3); /*SHR EAX, CL*/ addbyte(0xe8); addbyte(0xd3); /*SHR EBX, CL*/ @@ -898,7 +939,7 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x0f); addbyte(0x6e); addbyte(0xc0); - addbyte(0xc1); /*SHR EAX, 8*/ + addbyte(0xc1); /*SHR EAX, 24*/ addbyte(0xe8); addbyte(24); addbyte(0x89); /*MOV state->tex_a[RDI], EAX*/ @@ -914,7 +955,7 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x0f); addbyte(0x6e); addbyte(0xc0); - addbyte(0xc1); /*SHR EAX, 8*/ + addbyte(0xc1); /*SHR EAX, 24*/ addbyte(0xe8); addbyte(24); addbyte(0x89); /*MOV state->tex_a[RDI], EAX*/ @@ -1224,6 +1265,10 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x0f); addbyte(0x6e); addbyte(0xc0); + addbyte(0x66); /*MOVD XMM7, EAX*/ + addbyte(0x0f); + addbyte(0x6e); + addbyte(0xf8); if (params->textureMode[0] & TEXTUREMODE_TRILINEAR) { @@ -1390,6 +1435,13 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0xd5); addbyte(0xcc); + if (tca_sub_clocal) + { + addbyte(0x66); /*MOV EBX, XMM7*/ + addbyte(0x0f); + addbyte(0x7e); + addbyte(0xfb); + } addbyte(0x66); /*PMULHW XMM5, XMM4*/ addbyte(0x0f); @@ -1409,6 +1461,13 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x6b); addbyte(0xc9); + if (tca_sub_clocal) + { + addbyte(0xc1); /*SHR EBX, 24*/ + addbyte(0xeb); + addbyte(24); + } + if (tc_add_clocal) { addbyte(0x66); /*PADDW XMM1, XMM0*/ @@ -1467,13 +1526,6 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo } if (tca_sub_clocal) { - addbyte(0x66); /*MOV EBX, XMM0*/ - addbyte(0x0f); - addbyte(0x7e); - addbyte(0xc3); - addbyte(0xc1); /*SHR EBX, 24*/ - addbyte(0xeb); - addbyte(24); addbyte(0x29); /*SUB EAX, EBX*/ addbyte(0xd8); } @@ -1484,10 +1536,10 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0xdb); break; case TCA_MSELECT_CLOCAL: - addbyte(0x66); /*MOV EBX, XMM0*/ + addbyte(0x66); /*MOV EBX, XMM7*/ addbyte(0x0f); addbyte(0x7e); - addbyte(0xc3); + addbyte(0xfb); addbyte(0xc1); /*SHR EBX, 24*/ addbyte(0xeb); addbyte(0x24); @@ -1502,10 +1554,10 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x24); break; case TCA_MSELECT_ALOCAL: - addbyte(0x66); /*MOV EBX, XMM0*/ + addbyte(0x66); /*MOV EBX, XMM7*/ addbyte(0x0f); addbyte(0x7e); - addbyte(0xc3); + addbyte(0xfb); addbyte(0xc1); /*SHR EBX, 24*/ addbyte(0xeb); addbyte(0x24); @@ -1555,15 +1607,15 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0xc3); addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); - addbyte(0xc1); /*SHR EAX, 8*/ - addbyte(0xe8); + addbyte(0xc1); /*SAR EAX, 8*/ + addbyte(0xf8); addbyte(8); if (tca_add_clocal || tca_add_alocal) { - addbyte(0x66); /*MOV EBX, XMM0*/ + addbyte(0x66); /*MOV EBX, XMM7*/ addbyte(0x0f); addbyte(0x7e); - addbyte(0xc3); + addbyte(0xfb); addbyte(0xc1); /*SHR EBX, 24*/ addbyte(0xeb); addbyte(24); @@ -2185,40 +2237,9 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0xe3); addbyte(1); - if (params->fogMode & FOG_Z) - { - addbyte(0x8b); /*MOV EAX, state->z[EDI]*/ - addbyte(0x87); - addlong(offsetof(voodoo_state_t, z)); - addbyte(0xc1); /*SHR EAX, 12*/ - addbyte(0xe8); - addbyte(12); - addbyte(0x25); /*AND EAX, 0xff*/ - addlong(0xff); - } - else if (params->fogMode & FOG_ALPHA) - { - addbyte(0x8b); /*MOV EAX, state->ia[EDI]*/ - addbyte(0x87); - addlong(offsetof(voodoo_state_t, ia)); - addbyte(0x31); /*XOR EBX, EBX*/ - addbyte(0xdb); - addbyte(0xc1); /*SAR EAX, 12*/ - addbyte(0xf8); - addbyte(12); - addbyte(0x0f); /*CMOVS EAX, EBX*/ - addbyte(0x48); - addbyte(0xc3); - addbyte(0xbb); /*MOV EBX, 0xff*/ - addlong(0xff); - addbyte(0x3d); /*CMP EAX, 0xff*/ - addlong(0xff); - addbyte(0x0f); /*CMOVAE EAX, EBX*/ - addbyte(0x43); - addbyte(0xc3); - } - else + switch (params->fogMode & (FOG_Z|FOG_ALPHA)) { + case 0: addbyte(0x8b); /*MOV EBX, state->w_depth[EDI]*/ addbyte(0x9f); addlong(offsetof(voodoo_state_t, w_depth)); @@ -2249,6 +2270,66 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(10); addbyte(0x01); /*ADD EAX, EBX*/ addbyte(0xd8); +/* int fog_idx = (w_depth >> 10) & 0x3f; + + fog_a = params->fogTable[fog_idx].fog; + fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10;*/ + break; + + case FOG_Z: + addbyte(0x8b); /*MOV EAX, state->z[EDI]*/ + addbyte(0x87); + addlong(offsetof(voodoo_state_t, z)); + addbyte(0xc1); /*SHR EAX, 12*/ + addbyte(0xe8); + addbyte(12); + addbyte(0x25); /*AND EAX, 0xff*/ + addlong(0xff); +// fog_a = (z >> 20) & 0xff; + break; + + case FOG_ALPHA: + addbyte(0x8b); /*MOV EAX, state->ia[EDI]*/ + addbyte(0x87); + addlong(offsetof(voodoo_state_t, ia)); + addbyte(0x31); /*XOR EBX, EBX*/ + addbyte(0xdb); + addbyte(0xc1); /*SAR EAX, 12*/ + addbyte(0xf8); + addbyte(12); + addbyte(0x0f); /*CMOVS EAX, EBX*/ + addbyte(0x48); + addbyte(0xc3); + addbyte(0xbb); /*MOV EBX, 0xff*/ + addlong(0xff); + addbyte(0x3d); /*CMP EAX, 0xff*/ + addlong(0xff); + addbyte(0x0f); /*CMOVAE EAX, EBX*/ + addbyte(0x43); + addbyte(0xc3); +// fog_a = CLAMP(ia >> 12); + break; + + case FOG_W: + addbyte(0x8b); /*MOV EAX, state->w[EDI]+4*/ + addbyte(0x87); + addlong(offsetof(voodoo_state_t, w)+4); + addbyte(0x31); /*XOR EBX, EBX*/ + addbyte(0xdb); + addbyte(0x09); /*OR EAX, EAX*/ + addbyte(0xc0); + addbyte(0x0f); /*CMOVS EAX, EBX*/ + addbyte(0x48); + addbyte(0xc3); + addbyte(0xbb); /*MOV EBX, 0xff*/ + addlong(0xff); + addbyte(0x3d); /*CMP EAX, 0xff*/ + addlong(0xff); + addbyte(0x0f); /*CMOVAE EAX, EBX*/ + addbyte(0x43); + addbyte(0xc3); +// fog_a = CLAMP(w >> 32); + break; } addbyte(0x01); /*ADD EAX, EAX*/ addbyte(0xc0); @@ -3169,7 +3250,10 @@ static inline void *voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, params->fogMode == data->fogMode && params->fbzColorPath == data->fbzColorPath && (voodoo->trexInit1[0] & (1 << 18)) == data->trexInit1 && - params->textureMode == data->textureMode) + params->textureMode[0] == data->textureMode[0] && + params->textureMode[1] == data->textureMode[1] && + (params->tLOD[0] & LOD_MASK) == data->tLOD[0] && + (params->tLOD[1] & LOD_MASK) == data->tLOD[1]) { last_block[odd_even] = b; return data->code_block; @@ -3189,7 +3273,10 @@ voodoo_recomp++; data->fogMode = params->fogMode; data->fbzColorPath = params->fbzColorPath; data->trexInit1 = voodoo->trexInit1[0] & (1 << 18); - data->textureMode = params->textureMode; + data->textureMode[0] = params->textureMode[0]; + data->textureMode[1] = params->textureMode[1]; + data->tLOD[0] = params->tLOD[0] & LOD_MASK; + data->tLOD[1] = params->tLOD[1] & LOD_MASK; next_block_to_write[odd_even] = (next_block_to_write[odd_even] + 1) & 7; diff --git a/src/vid_voodoo_codegen_x86.h b/src/vid_voodoo_codegen_x86.h index 5e0e10032..4e6756032 100644 --- a/src/vid_voodoo_codegen_x86.h +++ b/src/vid_voodoo_codegen_x86.h @@ -21,6 +21,8 @@ #define BLOCK_MASK (BLOCK_NUM-1) #define BLOCK_SIZE 8192 +#define LOD_MASK (LOD_TMIRROR_S | LOD_TMIRROR_T) + typedef struct voodoo_x86_data_t { uint8_t code_block[BLOCK_SIZE]; @@ -29,7 +31,8 @@ typedef struct voodoo_x86_data_t uint32_t fbzMode; uint32_t fogMode; uint32_t fbzColorPath; - uint32_t textureMode; + uint32_t textureMode[2]; + uint32_t tLOD[2]; uint32_t trexInit1; } voodoo_x86_data_t; @@ -239,6 +242,25 @@ static inline int codegen_texture_fetch(uint8_t *code_block, voodoo_t *voodoo, v addbyte(0x8b); /*MOV EBX, state->tex_t[EDI]*/ addbyte(0x9f); addlong(offsetof(voodoo_state_t, tex_t)); + if (params->tLOD[tmu] & LOD_TMIRROR_S) + { + addbyte(0xa9); /*TEST EAX, 0x1000*/ + addlong(0x1000); + addbyte(0x74); /*JZ +*/ + addbyte(2); + addbyte(0xf7); /*NOT EAX*/ + addbyte(0xd0); + } + if (params->tLOD[tmu] & LOD_TMIRROR_T) + { + addbyte(0xf7); /*TEST EBX, 0x1000*/ + addbyte(0xc3); + addlong(0x1000); + addbyte(0x74); /*JZ +*/ + addbyte(2); + addbyte(0xf7); /*NOT EBX*/ + addbyte(0xd3); + } addbyte(0x29); /*SUB EAX, EBP*/ addbyte(0xe8); addbyte(0x29); /*SUB EBX, EBP*/ @@ -548,6 +570,25 @@ static inline int codegen_texture_fetch(uint8_t *code_block, voodoo_t *voodoo, v addbyte(0x8b); /*MOV EBX, state->tex_t[EDI]*/ addbyte(0x9f); addlong(offsetof(voodoo_state_t, tex_t)); + if (params->tLOD[tmu] & LOD_TMIRROR_S) + { + addbyte(0xa9); /*TEST EAX, 0x1000*/ + addlong(0x1000); + addbyte(0x74); /*JZ +*/ + addbyte(2); + addbyte(0xf7); /*NOT EAX*/ + addbyte(0xd0); + } + if (params->tLOD[tmu] & LOD_TMIRROR_T) + { + addbyte(0xf7); /*TEST EBX, 0x1000*/ + addbyte(0xc3); + addlong(0x1000); + addbyte(0x74); /*JZ +*/ + addbyte(2); + addbyte(0xf7); /*NOT EBX*/ + addbyte(0xd3); + } addbyte(0xd3); /*SHR EAX, CL*/ addbyte(0xe8); addbyte(0xd3); /*SHR EBX, CL*/ @@ -883,7 +924,7 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x0f); addbyte(0x6e); addbyte(0xc0); - addbyte(0xc1); /*SHR EAX, 8*/ + addbyte(0xc1); /*SHR EAX, 24*/ addbyte(0xe8); addbyte(24); addbyte(0x89); /*MOV state->tex_a[EDI], EAX*/ @@ -899,7 +940,7 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x0f); addbyte(0x6e); addbyte(0xc0); - addbyte(0xc1); /*SHR EAX, 8*/ + addbyte(0xc1); /*SHR EAX, 24*/ addbyte(0xe8); addbyte(24); addbyte(0x89); /*MOV state->tex_a[EDI], EAX*/ @@ -1207,6 +1248,10 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x0f); addbyte(0x6e); addbyte(0xc0); + addbyte(0x66); /*MOVD XMM7, EAX*/ + addbyte(0x0f); + addbyte(0x6e); + addbyte(0xf8); if (params->textureMode[0] & TEXTUREMODE_TRILINEAR) { @@ -1371,6 +1416,13 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0xd5); addbyte(0xcc); + if (tca_sub_clocal) + { + addbyte(0x66); /*MOV EBX, XMM7*/ + addbyte(0x0f); + addbyte(0x7e); + addbyte(0xfb); + } addbyte(0x66); /*PMULHW XMM5, XMM4*/ addbyte(0x0f); @@ -1390,6 +1442,13 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x6b); addbyte(0xc9); + if (tca_sub_clocal) + { + addbyte(0xc1); /*SHR EBX, 24*/ + addbyte(0xeb); + addbyte(24); + } + if (tc_add_clocal) { addbyte(0x66); /*PADDW XMM1, XMM0*/ @@ -1448,13 +1507,6 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo } if (tca_sub_clocal) { - addbyte(0x66); /*MOV EBX, XMM0*/ - addbyte(0x0f); - addbyte(0x7e); - addbyte(0xc3); - addbyte(0xc1); /*SHR EBX, 24*/ - addbyte(0xeb); - addbyte(24); addbyte(0x29); /*SUB EAX, EBX*/ addbyte(0xd8); } @@ -1465,10 +1517,10 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0xdb); break; case TCA_MSELECT_CLOCAL: - addbyte(0x66); /*MOV EBX, XMM0*/ + addbyte(0x66); /*MOV EBX, XMM7*/ addbyte(0x0f); addbyte(0x7e); - addbyte(0xc3); + addbyte(0xfb); addbyte(0xc1); /*SHR EBX, 24*/ addbyte(0xeb); addbyte(0x24); @@ -1483,10 +1535,10 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0x24); break; case TCA_MSELECT_ALOCAL: - addbyte(0x66); /*MOV EBX, XMM0*/ + addbyte(0x66); /*MOV EBX, XMM7*/ addbyte(0x0f); addbyte(0x7e); - addbyte(0xc3); + addbyte(0xfb); addbyte(0xc1); /*SHR EBX, 24*/ addbyte(0xeb); addbyte(0x24); @@ -1536,15 +1588,15 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0xc3); addbyte(0x31); /*XOR EDX, EDX*/ addbyte(0xd2); - addbyte(0xc1); /*SHR EAX, 8*/ - addbyte(0xe8); + addbyte(0xc1); /*SAR EAX, 8*/ + addbyte(0xf8); addbyte(8); if (tca_add_clocal || tca_add_alocal) { - addbyte(0x66); /*MOV EBX, XMM0*/ + addbyte(0x66); /*MOV EBX, XMM7*/ addbyte(0x0f); addbyte(0x7e); - addbyte(0xc3); + addbyte(0xfb); addbyte(0xc1); /*SHR EBX, 24*/ addbyte(0xeb); addbyte(24); @@ -2178,42 +2230,9 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo addbyte(0xe3); addbyte(1); - if (params->fogMode & FOG_Z) - { - addbyte(0x8b); /*MOV EAX, state->z[EDI]*/ - addbyte(0x87); - addlong(offsetof(voodoo_state_t, z)); - addbyte(0xc1); /*SHR EAX, 12*/ - addbyte(0xe8); - addbyte(12); - addbyte(0x25); /*AND EAX, 0xff*/ - addlong(0xff); -// fog_a = (z >> 20) & 0xff; - } - else if (params->fogMode & FOG_ALPHA) - { - addbyte(0x8b); /*MOV EAX, state->ia[EDI]*/ - addbyte(0x87); - addlong(offsetof(voodoo_state_t, ia)); - addbyte(0x31); /*XOR EBX, EBX*/ - addbyte(0xdb); - addbyte(0xc1); /*SAR EAX, 12*/ - addbyte(0xf8); - addbyte(12); - addbyte(0x0f); /*CMOVS EAX, EBX*/ - addbyte(0x48); - addbyte(0xc3); - addbyte(0xbb); /*MOV EBX, 0xff*/ - addlong(0xff); - addbyte(0x3d); /*CMP EAX, 0xff*/ - addlong(0xff); - addbyte(0x0f); /*CMOVAE EAX, EBX*/ - addbyte(0x43); - addbyte(0xc3); -// fog_a = CLAMP(ia >> 12); - } - else + switch (params->fogMode & (FOG_Z|FOG_ALPHA)) { + case 0: addbyte(0x8b); /*MOV EBX, state->w_depth[EDI]*/ addbyte(0x9f); addlong(offsetof(voodoo_state_t, w_depth)); @@ -2249,6 +2268,62 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo fog_a = params->fogTable[fog_idx].fog; fog_a += (params->fogTable[fog_idx].dfog * ((w_depth >> 2) & 0xff)) >> 10;*/ + break; + + case FOG_Z: + addbyte(0x8b); /*MOV EAX, state->z[EDI]*/ + addbyte(0x87); + addlong(offsetof(voodoo_state_t, z)); + addbyte(0xc1); /*SHR EAX, 12*/ + addbyte(0xe8); + addbyte(12); + addbyte(0x25); /*AND EAX, 0xff*/ + addlong(0xff); +// fog_a = (z >> 20) & 0xff; + break; + + case FOG_ALPHA: + addbyte(0x8b); /*MOV EAX, state->ia[EDI]*/ + addbyte(0x87); + addlong(offsetof(voodoo_state_t, ia)); + addbyte(0x31); /*XOR EBX, EBX*/ + addbyte(0xdb); + addbyte(0xc1); /*SAR EAX, 12*/ + addbyte(0xf8); + addbyte(12); + addbyte(0x0f); /*CMOVS EAX, EBX*/ + addbyte(0x48); + addbyte(0xc3); + addbyte(0xbb); /*MOV EBX, 0xff*/ + addlong(0xff); + addbyte(0x3d); /*CMP EAX, 0xff*/ + addlong(0xff); + addbyte(0x0f); /*CMOVAE EAX, EBX*/ + addbyte(0x43); + addbyte(0xc3); +// fog_a = CLAMP(ia >> 12); + break; + + case FOG_W: + addbyte(0x8b); /*MOV EAX, state->w[EDI]+4*/ + addbyte(0x87); + addlong(offsetof(voodoo_state_t, w)+4); + addbyte(0x31); /*XOR EBX, EBX*/ + addbyte(0xdb); + addbyte(0x09); /*OR EAX, EAX*/ + addbyte(0xc0); + addbyte(0x0f); /*CMOVS EAX, EBX*/ + addbyte(0x48); + addbyte(0xc3); + addbyte(0xbb); /*MOV EBX, 0xff*/ + addlong(0xff); + addbyte(0x3d); /*CMP EAX, 0xff*/ + addlong(0xff); + addbyte(0x0f); /*CMOVAE EAX, EBX*/ + addbyte(0x43); + addbyte(0xc3); +// fog_a = CLAMP(w >> 32); + break; } addbyte(0x01); /*ADD EAX, EAX*/ addbyte(0xc0); @@ -3147,6 +3222,7 @@ static inline void voodoo_generate(uint8_t *code_block, voodoo_t *voodoo, voodoo cs = cs; } static int voodoo_recomp = 0; + static inline void *voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, voodoo_state_t *state, int odd_even) { int c; @@ -3164,7 +3240,10 @@ static inline void *voodoo_get_block(voodoo_t *voodoo, voodoo_params_t *params, params->fogMode == data->fogMode && params->fbzColorPath == data->fbzColorPath && (voodoo->trexInit1[0] & (1 << 18)) == data->trexInit1 && - params->textureMode[0] == data->textureMode) + params->textureMode[0] == data->textureMode[0] && + params->textureMode[1] == data->textureMode[1] && + (params->tLOD[0] & LOD_MASK) == data->tLOD[0] && + (params->tLOD[1] & LOD_MASK) == data->tLOD[1]) { last_block[odd_even] = b; return data->code_block; @@ -3184,7 +3263,10 @@ voodoo_recomp++; data->fogMode = params->fogMode; data->fbzColorPath = params->fbzColorPath; data->trexInit1 = voodoo->trexInit1[0] & (1 << 18); - data->textureMode = params->textureMode[0]; + data->textureMode[0] = params->textureMode[0]; + data->textureMode[1] = params->textureMode[1]; + data->tLOD[0] = params->tLOD[0] & LOD_MASK; + data->tLOD[1] = params->tLOD[1] & LOD_MASK; next_block_to_write[odd_even] = (next_block_to_write[odd_even] + 1) & 7; diff --git a/src/vid_voodoo_dither.h b/src/vid_voodoo_dither.h index e9e37436c..21baf772b 100644 --- a/src/vid_voodoo_dither.h +++ b/src/vid_voodoo_dither.h @@ -1,6 +1,3 @@ -/* Copyright holders: Sarah Walker - see COPYING for more details -*/ uint8_t dither_rb[256][4][4] = { { diff --git a/src/video.c b/src/video.c index 5b4b28163..3adf96d23 100644 --- a/src/video.c +++ b/src/video.c @@ -28,6 +28,7 @@ #include "vid_et4000w32.h" #include "vid_hercules.h" #include "vid_incolor.h" +#include "vid_colorplus.h" #include "vid_mda.h" #include "vid_nv_riva128.h" #include "vid_nv_rivatnt.h" @@ -86,6 +87,7 @@ static VIDEO_CARD video_cards[] = {"Phoenix S3 Vision864", &s3_phoenix_vision864_device,GFX_PHOENIX_VISION864}, {"Phoenix S3 Trio32", &s3_phoenix_trio32_device, GFX_PHOENIX_TRIO32}, {"Phoenix S3 Trio64", &s3_phoenix_trio64_device, GFX_PHOENIX_TRIO64}, + {"Plantronics ColorPlus", &colorplus_device, GFX_COLORPLUS}, {"S3 ViRGE/DX", &s3_virge_375_device, GFX_VIRGEDX}, {"Trident TVGA8900D", &tvga8900d_device, GFX_TVGA}, {"Tseng ET4000AX", &et4000_device, GFX_ET4000}, diff --git a/src/win-ddraw-screenshot.cc b/src/win-ddraw-screenshot.cc index ee6436051..1942c30cb 100644 --- a/src/win-ddraw-screenshot.cc +++ b/src/win-ddraw-screenshot.cc @@ -57,7 +57,6 @@ void CopySurface(IDirectDrawSurface4 *pDDSurface) void DoubleLines(uint8_t *dst, uint8_t *src) { int i = 0; - uint8_t temp_buf[8320]; for (i = 0; i < ys; i++) { memcpy(dst + (i * xs * 8), src + (i * xs * 4), xs * 4); diff --git a/src/x86_ops_bit.h b/src/x86_ops_bit.h index 9b3d71005..de4c8604b 100644 --- a/src/x86_ops_bit.h +++ b/src/x86_ops_bit.h @@ -1,6 +1,5 @@ static int opBT_w_r_a16(uint32_t fetchdat) { - int tempc; uint16_t temp; fetch_ea_16(fetchdat); diff --git a/src/x86_ops_i686.h b/src/x86_ops_i686.h index 220399fcd..9afb0e5f0 100644 --- a/src/x86_ops_i686.h +++ b/src/x86_ops_i686.h @@ -255,14 +255,14 @@ static int opFXSAVESTOR_a16(uint32_t fetchdat) /* FXSAVE */ // pclog("FXSAVE issued\n"); - if (twd & 0x0003 == 0x0003) ftwb |= 0x01; - if (twd & 0x000C == 0x000C) ftwb |= 0x02; - if (twd & 0x0030 == 0x0030) ftwb |= 0x04; - if (twd & 0x00C0 == 0x00C0) ftwb |= 0x08; - if (twd & 0x0300 == 0x0300) ftwb |= 0x10; - if (twd & 0x0C00 == 0x0C00) ftwb |= 0x20; - if (twd & 0x3000 == 0x3000) ftwb |= 0x40; - if (twd & 0xC000 == 0xC000) ftwb |= 0x80; + if ((twd & 0x0003) == 0x0003) ftwb |= 0x01; + if ((twd & 0x000C) == 0x000C) ftwb |= 0x02; + if ((twd & 0x0030) == 0x0030) ftwb |= 0x04; + if ((twd & 0x00C0) == 0x00C0) ftwb |= 0x08; + if ((twd & 0x0300) == 0x0300) ftwb |= 0x10; + if ((twd & 0x0C00) == 0x0C00) ftwb |= 0x20; + if ((twd & 0x3000) == 0x3000) ftwb |= 0x40; + if ((twd & 0xC000) == 0xC000) ftwb |= 0x80; writememw(easeg,cpu_state.eaaddr,cpu_state.npxc); writememw(easeg,cpu_state.eaaddr+2,cpu_state.npxs); @@ -431,14 +431,14 @@ static int opFXSAVESTOR_a32(uint32_t fetchdat) /* FXSAVE */ // pclog("FXSAVE issued\n"); - if (twd & 0x0003 == 0x0003) ftwb |= 0x01; - if (twd & 0x000C == 0x000C) ftwb |= 0x02; - if (twd & 0x0030 == 0x0030) ftwb |= 0x04; - if (twd & 0x00C0 == 0x00C0) ftwb |= 0x08; - if (twd & 0x0300 == 0x0300) ftwb |= 0x10; - if (twd & 0x0C00 == 0x0C00) ftwb |= 0x20; - if (twd & 0x3000 == 0x3000) ftwb |= 0x40; - if (twd & 0xC000 == 0xC000) ftwb |= 0x80; + if ((twd & 0x0003) == 0x0003) ftwb |= 0x01; + if ((twd & 0x000C) == 0x000C) ftwb |= 0x02; + if ((twd & 0x0030) == 0x0030) ftwb |= 0x04; + if ((twd & 0x00C0) == 0x00C0) ftwb |= 0x08; + if ((twd & 0x0300) == 0x0300) ftwb |= 0x10; + if ((twd & 0x0C00) == 0x0C00) ftwb |= 0x20; + if ((twd & 0x3000) == 0x3000) ftwb |= 0x40; + if ((twd & 0xC000) == 0xC000) ftwb |= 0x80; writememw(easeg,cpu_state.eaaddr,cpu_state.npxc); writememw(easeg,cpu_state.eaaddr+2,cpu_state.npxs); diff --git a/src/x86seg.c b/src/x86seg.c index ab2735840..74e177b9a 100644 --- a/src/x86seg.c +++ b/src/x86seg.c @@ -1636,7 +1636,7 @@ void pmodeint(int num, int soft) else { // pclog("INT out of range\n"); - x86gpf(NULL,(num*8)+2+(soft)?0:1); + x86gpf(NULL,(num*8)+2+((soft)?0:1)); } if (output) pclog("addr >= IDT.limit\n"); return; diff --git a/src/x87_ops_misc.h b/src/x87_ops_misc.h index 894271330..ea31c74e0 100644 --- a/src/x87_ops_misc.h +++ b/src/x87_ops_misc.h @@ -75,7 +75,6 @@ static int opFST(uint32_t fetchdat) static int opFSTP(uint32_t fetchdat) { - int temp; FP_ENTER(); cpu_state.pc++; if (fplog) pclog("FSTP\n"); @@ -507,7 +506,7 @@ static int opFYL2XP1(uint32_t fetchdat) FP_ENTER(); cpu_state.pc++; if (fplog) pclog("FYL2XP1\n"); - ST(1) = ST(1) * (log(ST(0)+1.0) / log(2.0)); + ST(1) = ST(1) * (log1p(ST(0)) / log(2.0)); cpu_state.tag[(cpu_state.TOP + 1) & 7] &= ~TAG_UINT64; x87_pop(); CLOCK_CYCLES(250);