Exemplo n.º 1
0
void disc_load(int drive, char *fn)
{
        int c = 0, size;
        char *p;
        FILE *f;
//        pclog("disc_load %i %s\n", drive, fn);
//        setejecttext(drive, "");
        if (!fn) return;
        p = get_extension(fn);
        if (!p) return;
//        setejecttext(drive, fn);
        pclog("Loading :%i %s %s\n", drive, fn,p);
        f = fopen(fn, "rb");
        if (!f) return;
        fseek(f, -1, SEEK_END);
        size = ftell(f) + 1;
        fclose(f);        
        while (loaders[c].ext)
        {
                if (!strcasecmp(p, loaders[c].ext) && (size == loaders[c].size || loaders[c].size == -1))
                {
                        pclog("Loading as %s\n", p);
                        driveloaders[drive] = c;
                        loaders[c].load(drive, fn);
                        drive_empty[drive] = 0;
                        disc_changed[drive] = 1;
                        strcpy(discfns[drive], fn);
                        return;
                }
                c++;
        }
        pclog("Couldn't load %s %s\n",fn,p);
        drive_empty[drive] = 1;
        discfns[drive][0] = 0;
}
Exemplo n.º 2
0
void *
dynld_module(const char *name, dllimp_t *table)
{
    HMODULE h;
    dllimp_t *imp;
    void *func;
    /* char **foo; */

    /* See if we can load the desired module. */
    if ((h = LoadLibrary(name)) == NULL) {
	pclog("DynLd(\"%s\"): library not found!\n", name);
	return(NULL);
    }

    /* Now load the desired function pointers. */
    for (imp=table; imp->name!=NULL; imp++) {
	func = GetProcAddress(h, imp->name);
	if (func == NULL) {
		pclog("DynLd(\"%s\"): function '%s' not found!\n",
						name, imp->name);
		CloseHandle(h);
		return(NULL);
	}

	/* To overcome typing issues.. */
	*(char **)imp->func = (char *)func;
    }

    /* All good. */
    return((void *)h);
}
Exemplo n.º 3
0
Arquivo: model.c Projeto: Wack0/PCem-X
void model_init()
{
        pclog("Initting as %s\n", model_getname());
        io_init();
        
        models[model].init();

	pclog("PCI: %02X, Max IDE: %02X, 386: %02X\n", PCI, maxide, is386);
}
Exemplo n.º 4
0
int rom_init_interleaved(rom_t *rom, char *fn_low, char *fn_high, uint32_t address, int size, int mask, int file_offset, uint32_t flags)
{
        FILE *f_low  = romfopen(fn_low, "rb");
        FILE *f_high = romfopen(fn_high, "rb");
        int c;
        
        if (!f_low || !f_high)
        {
#ifndef RELEASE_BUILD
                if (!f_low)
                        pclog("ROM image not found : %s\n", fn_low);
                else
#else
		if (f_low)
#endif
                        fclose(f_low);
#ifndef RELEASE_BUILD
                if (!f_high)
                        pclog("ROM image not found : %s\n", fn_high);
                else
#else
		if (f_high)
#endif
                        fclose(f_high);
                return -1;
        }
        
        rom->rom = malloc(size);
        fseek(f_low, file_offset, SEEK_SET);
        fseek(f_high, file_offset, SEEK_SET);
        for (c = 0; c < size; c += 2)
        {
                rom->rom[c]     = getc(f_low);
                rom->rom[c + 1] = getc(f_high);
        }
        fclose(f_high);
        fclose(f_low);
        
        rom->mask = mask;
        
        mem_mapping_add(&rom->mapping, address, size, rom_read,
                                                      rom_readw,
                                                      rom_readl,
                                                      mem_write_null,
                                                      mem_write_nullw,
                                                      mem_write_nulll,
                                                      rom->rom,
                                                      flags,
                                                      rom);

        return 0;
}
Exemplo n.º 5
0
/* Flush the serial port. */
static void
bug_spflsh(void)
{
    *bug_bptr = '\0';
    pclog("BUGGER- serial port [%s]\n", bug_buff);
    bug_bptr = bug_buff;
}
Exemplo n.º 6
0
/* Close up shop. */
void
network_pcap_close(void)
{
    pcap_t *pc;

    if (pcap != NULL) {
	pclog("Closing WinPcap\n");

	/* Tell the polling thread to shut down. */
	pc = pcap; pcap = NULL;
#if 1
	/* Terminate the polling thread. */
	if (poll_tid != NULL) {
		thread_kill(poll_tid);
		poll_tid = NULL;
	}
#else
	/* Wait for the polling thread to shut down. */
	while (poll_tid != NULL)
		;
#endif

	/* OK, now shut down WinPcap itself. */
	f_pcap_close(pc);

	/* Unload the DLL if possible. */
	if (pcap_handle != NULL) {
		dynld_close(pcap_handle);
		pcap_handle = NULL;
	}
    }
    poll_rx = NULL;
    poll_arg = NULL;
}
Exemplo n.º 7
0
static void QueueByte(mpu_t *mpu, uint8_t data) 
{
	if (mpu->state.block_ack) 
	{
		mpu->state.block_ack=0;
		return;
	}
	
	if (mpu->queue_used == 0 && mpu->intelligent) 
	{
		mpu->state.irq_pending=1;
		//PIC_ActivateIRQ(mpu->irq);
		picint(1 << mpu->irq);
	}
	if (mpu->queue_used < MPU401_QUEUE) 
	{
		int pos = mpu->queue_used+mpu->queue_pos;
		
		if (mpu->queue_pos >= MPU401_QUEUE) 
			mpu->queue_pos -= MPU401_QUEUE;
		
		if (pos>=MPU401_QUEUE) 
			pos-=MPU401_QUEUE;
		
		mpu->queue_used++;
		mpu->queue[pos]=data;
	} 
	else
		pclog("MPU401:Data queue full\n");
}
Exemplo n.º 8
0
/* Handle a write to the Serial Port Configuration register. */
static void
bug_wspcfg(uint8_t val)
{
    bug_spcfg = val;

    pclog("BUGGER- spcfg %02x\n", bug_spcfg);
}
Exemplo n.º 9
0
//Updates counters and requests new data on "End of Input"
static void MPU401_EOIHandler(void *p)
{
	mpu_t *mpu = (mpu_t *)p;
	uint8_t i;

	pclog("MPU-401 end of input callback\n");
	
	mpu401_eoi_callback = 0;
	mpu->state.eoi_scheduled=0;
	if (mpu->state.send_now) 
	{
		mpu->state.send_now=0;
		if (mpu->state.cond_req) UpdateConductor(mpu);
		else UpdateTrack(mpu, mpu->state.channel);
	}
	mpu->state.irq_pending=0;
	if (!mpu->state.playing || !mpu->state.req_mask)  return;
	i=0;
	do {
		if (mpu->state.req_mask&(1<<i)) {
			QueueByte(mpu, 0xf0+i);
			mpu->state.req_mask&=~(1<<i);
			break;
		}
	} while ((i++)<16);
}
Exemplo n.º 10
0
/* Handle a write to the data register. */
static void
bug_wdata(uint8_t val)
{
    bug_data = val;

    if (bug_ctrl & CTRL_SPCFG)
	bug_wspcfg(val);
      else if (bug_ctrl & CTRL_SPORT)
	bug_wsport(val);
      else {
	if (bug_ctrl & CTRL_SEG2)
		bug_seg2 = val;
	  else if (bug_ctrl & CTRL_SEG1)
		bug_seg1 = val;
	  else if (bug_ctrl & CTRL_GLED)
		bug_ledg = val;
	  else
		bug_ledr = val;

	pclog("BUGGER- data %02x\n", bug_data);
    }

    /* Update the UI with active settings. */
    bug_setui();
}
Exemplo n.º 11
0
void keyboard_xt_write(uint16_t port, uint8_t val, void *priv)
{
        switch (port)
        {
                case 0x61:
                if (!(keyboard_xt.pb & 0x40) && (val & 0x40)) /*Reset keyboard*/
                {
                        pclog("keyboard_xt : reset keyboard\n");
			key_queue_end = key_queue_start;
                        keyboard_xt_adddata(0xaa);
                }
		if ((keyboard_xt.pb & 0x80)==0 && (val & 0x80)!=0)
		{
			keyboard_xt.pa = 0;
			keyboard_xt.blocked = 0;
			picintc(2);
		}
                keyboard_xt.pb = val;
                ppi.pb = val;

                timer_process();
                timer_update_outstanding();
        
		speaker_update();
                speaker_gated = val & 1;
                speaker_enable = val & 2;
                if (speaker_enable) 
                        was_speaker_enable = 1;
                pit_set_gate(&pit, 2, val & 1);
                   
                break;
        }
}
Exemplo n.º 12
0
void keyboard_xt_adddata(uint8_t val)
{
        key_queue[key_queue_end] = val;
        pclog("keyboard_xt : %02X added to key queue at %i\n", val, key_queue_end);
        key_queue_end = (key_queue_end + 1) & 0xf;
        return;
}
Exemplo n.º 13
0
void mpu401_init(mpu_t *mpu, uint16_t addr, int irq, int mode)
{
#if 0
	if (mode != M_INTELLIGENT)
	{
		mpu401_uart_init(mpu, addr);
		return;
	}
#endif

	mpu->status = STATUS_INPUT_NOT_READY;
	mpu->irq = irq;
	mpu->queue_used = 0;
	mpu->queue_pos = 0;
	mpu->mode = M_UART;

	mpu->intelligent = (mode == M_INTELLIGENT) ? 1 : 0;
	pclog("Starting as %s (mode is %s)\n", mpu->intelligent ? "INTELLIGENT" : "UART", (mode == M_INTELLIGENT) ? "INTELLIGENT" : "UART");

	mpu401_event_callback = 0;
	mpu401_eoi_callback = 0;
	mpu401_reset_callback = 0;

	io_sethandler(addr, 0x0002, mpu401_read, NULL, NULL, mpu401_write, NULL, NULL, mpu);
	io_sethandler(0x2A20, 0x0010, NULL, NULL, NULL, imf_write, NULL, NULL, mpu);
	timer_add(MPU401_Event, &mpu401_event_callback, &mpu401_event_callback, mpu);
	timer_add(MPU401_EOIHandler, &mpu401_eoi_callback, &mpu401_eoi_callback, mpu);
	timer_add(MPU401_ResetDone, &mpu401_reset_callback, &mpu401_reset_callback, mpu);
	
	MPU401_Reset(mpu);
}
Exemplo n.º 14
0
/* Initialize the (Win)Pcap module for use. */
int
network_pcap_init(netdev_t *list)
{
    char errbuf[PCAP_ERRBUF_SIZE];
    pcap_if_t *devlist, *dev;
    int i = 0;

    /* Local variables. */
    pcap = NULL;

    /* Try loading the DLL. */
    pcap_handle = dynld_module("wpcap.dll", pcap_imports);
    if (pcap_handle == NULL) return(-1);

    /* Retrieve the device list from the local machine */
    if (f_pcap_findalldevs(&devlist, errbuf) == -1) {
	pclog("PCAP: error in pcap_findalldevs: %s\n", errbuf);
	return(-1);
    }

    for (dev=devlist; dev!=NULL; dev=dev->next) {
	strcpy(list->device, dev->name);
	if (dev->description)
		strcpy(list->description, dev->description);
	  else
		memset(list->description, '\0', sizeof(list->description));
	list++; i++;
    }

    /* Release the memory. */
    f_pcap_freealldevs(devlist);

    return(i);
}
Exemplo n.º 15
0
uint8_t keyboard_pcjr_read(uint16_t port, void *priv)
{
        uint8_t temp;
        switch (port)
        {
                case 0x60:
                temp = keyboard_pcjr.pa;
                break;
                
                case 0x61:
                temp = keyboard_pcjr.pb;
                break;
                
                case 0x62:
                temp = (keyboard_pcjr.latched ? 1 : 0);
                temp |= 0x02; /*Modem card not installed*/
                temp |= (ppispeakon ? 0x10 : 0);
                temp |= (ppispeakon ? 0x20 : 0);
                temp |= (keyboard_pcjr.data ? 0x40: 0);
                if (keyboard_pcjr.data)
                        temp |= 0x40;
                break;
                
                case 0xa0:
                keyboard_pcjr.latched = 0;
		temp = 0;
                break;
                
                default:
                pclog("\nBad XT keyboard read %04X\n", port);
		temp = 0xff;
        }
        return temp;
}
Exemplo n.º 16
0
int rom_init(rom_t *rom, char *fn, uint32_t address, int size, int mask, int file_offset, uint32_t flags)
{
        FILE *f = romfopen(fn, "rb");
        
        if (!f)
        {
#ifndef RELEASE_BUILD
                pclog("ROM image not found : %s\n", fn);
#endif
                return -1;
        }
        
        rom->rom = malloc(size);
        fseek(f, file_offset, SEEK_SET);
        fread(rom->rom, size, 1, f);
        fclose(f);
        
        rom->mask = mask;
        
        mem_mapping_add(&rom->mapping, address, size, rom_read,
                                                      rom_readw,
                                                      rom_readl,
                                                      mem_write_null,
                                                      mem_write_nullw,
                                                      mem_write_nulll,
                                                      rom->rom,
                                                      flags,
                                                      rom);

        return 0;
}
Exemplo n.º 17
0
void timer_reset()
{
	pclog("timer_reset\n");
	timers_present = 0;
	timer_latch = timer_count = 0;
//	timer_process();
}
Exemplo n.º 18
0
/* Handle the receiving of frames from the channel. */
static void
poll_thread(void *arg)
{
    uint8_t *mac = (uint8_t *)arg;
    const uint8_t *data = NULL;
    struct pcap_pkthdr h;
    uint32_t mac_cmp32[2];
    uint16_t mac_cmp16[2];
    event_t *evt;

    pclog("PCAP: polling thread started, arg %08lx\n", arg);

    /* Create a waitable event. */
    evt = thread_create_event();

    /* As long as the channel is open.. */
    while (pcap != NULL) {
	/* Wait for the next packet to arrive. */
	data = f_pcap_next(pcap, &h);
	if (data != NULL) {
		/* Received MAC. */
		mac_cmp32[0] = *(uint32_t *)(data+6);
		mac_cmp16[0] = *(uint16_t *)(data+10);

		/* Local MAC. */
		mac_cmp32[1] = *(uint32_t *)mac;
		mac_cmp16[1] = *(uint16_t *)(mac+4);
		if ((mac_cmp32[0] != mac_cmp32[1]) ||
		    (mac_cmp16[0] != mac_cmp16[1])) {
			if (poll_rx != NULL)
				poll_rx(poll_arg, (uint8_t *)data, h.caplen); 
		} else {
			/* Mark as invalid packet. */
			data = NULL;
		}
	}

	/* If we did not get anything, wait a while. */
	if (data == NULL)
		thread_wait_event(evt, 10);
    }

    thread_destroy_event(evt);
    poll_tid = NULL;

    pclog("PCAP: polling stopped.\n");
}
Exemplo n.º 19
0
void model_init()
{
        pclog("Initting as %s\n", model_getname());
        AMSTRAD = AT = PCI = TANDY = 0;
        io_init();
        
        models[model].init();
}
Exemplo n.º 20
0
static void MPU401_Event(void *p) 
{
	mpu_t *mpu = (mpu_t *)p;
	uint8_t i;
	int new_time;

	pclog("MPU-401 event callback\n");
	
	if (mpu->mode==M_UART)
	{
		mpu401_event_callback = 0;
		return;
	}
	if (mpu->state.irq_pending) goto next_event;
	for (i=0;i<8;i++) { /* Decrease counters */
		if (mpu->state.amask&(1<<i)) {
			mpu->playbuf[i].counter--;
			if (mpu->playbuf[i].counter<=0) UpdateTrack(mpu, i);
		}
	}		
	if (mpu->state.conductor) {
		mpu->condbuf.counter--;
		if (mpu->condbuf.counter<=0) UpdateConductor(mpu);
	}
	if (mpu->clock.clock_to_host) {
		mpu->clock.cth_counter++;
		if (mpu->clock.cth_counter >= mpu->clock.cth_rate) {
			mpu->clock.cth_counter=0;
			mpu->state.req_mask|=(1<<13);
		}
	}
	if (!mpu->state.irq_pending && mpu->state.req_mask) MPU401_EOIHandler(mpu);
next_event:
	/* mpu401_event_callback = 0; */
	new_time = (mpu->clock.tempo * mpu->clock.timebase);
	if (new_time == 0)
	{
		mpu401_event_callback = 0;
		return;
	}
	else
	{
		mpu401_event_callback += (MPU401_TIMECONSTANT/new_time) * 1000 * TIMER_USEC;
		pclog("Next event after %i us (time constant: %i)\n", (int) ((MPU401_TIMECONSTANT/new_time) * 1000 * TIMER_USEC), (int) MPU401_TIMECONSTANT);
	}
}
Exemplo n.º 21
0
/**
 * cpu_suspend
 *
 * @arg: argument to pass to the finisher function
 */
int cpu_suspend(unsigned long arg)
{
	struct mm_struct *mm = current->active_mm;
	int ret, cpu = smp_processor_id();
	unsigned long flags;

	/*
	 * If cpu_ops have not been registered or suspend
	 * has not been initialized, cpu_suspend call fails early.
	 */
	if (!cpu_ops[cpu] || !cpu_ops[cpu]->cpu_suspend)
		return -EOPNOTSUPP;

	/*
	 * From this point debug exceptions are disabled to prevent
	 * updates to mdscr register (saved and restored along with
	 * general purpose registers) from kernel debuggers.
	 */
	local_dbg_save(flags);

	/*
	 * mm context saved on the stack, it will be restored when
	 * the cpu comes out of reset through the identity mapped
	 * page tables, so that the thread address space is properly
	 * set-up on function return.
	 */
	ret = __cpu_suspend(arg);
        pclog();

	if (ret == 0) {
		cpu_switch_mm(mm->pgd, mm);
		flush_tlb_all();

		/*
		 * Restore per-cpu offset before any kernel
		 * subsystem relying on it has a chance to run.
		 */
		set_my_cpu_offset(per_cpu_offset(cpu));

		/*
		 * Restore HW breakpoint registers to sane values
		 * before debug exceptions are possibly reenabled
		 * through local_dbg_restore.
		 */
		if (hw_breakpoint_restore)
			hw_breakpoint_restore(NULL);
	}

	/*
	 * Restore pstate flags. OS lock and mdscr have been already
	 * restored, so from this point onwards, debugging is fully
	 * renabled if it was enabled when core started shutdown.
	 */
	local_dbg_restore(flags);

	return ret;
}
Exemplo n.º 22
0
static uint8_t
sio_detect_read(uint16_t port, void *priv)
{
    sio_detect_t *dev = (sio_detect_t *) priv;

    pclog("sio_detect_read : port=%04x = %02X\n", port, dev->regs[port & 1]);

    return dev->regs[port & 1];
}
Exemplo n.º 23
0
static void mpu401_write(uint16_t addr, uint8_t val, void *p)
{
	mpu_t *mpu = (mpu_t *)p;
        
	/* pclog("MPU401 Write Port %04X, val %x\n", addr, val); */
		
	switch (addr & 1) 
	{
		case 0: /*Data*/
		MPU401_WriteData(mpu, val);
		pclog("Write Data (0x330) %X\n", val);
		break;
		
		case 1: /*Command*/
		MPU401_WriteCommand(mpu, val);
		pclog("Write Command (0x331) %x\n", val);
		break;
	}
}
Exemplo n.º 24
0
/* Initialize the ISA BusBugger emulator. */
void
bugger_init(void)
{
    pclog("ISA Bus (de)Bugger, I/O=%04x\n", BUGGER_ADDR);

    /* Initialize local registers. */
    bug_reset();

    io_sethandler(BUGGER_ADDR, BUGGER_ADDRLEN,
		  bug_read, NULL, NULL, bug_write, NULL, NULL,  NULL);
}
Exemplo n.º 25
0
uint8_t keyboard_xt_read(uint16_t port, void *priv)
{
        uint8_t temp;
        switch (port)
        {
                case 0x60:
		if ((romset == ROM_IBMPC) && (keyboard_xt.pb & 0x80))
		{
			if (VGA || gfxcard == GFX_EGA)
				temp = 0x4D;
			else if (MDA)
				temp = 0x7D;
			else
				temp = 0x6D;
		}
		else
			temp = keyboard_xt.pa;
                break;
                
                case 0x61:
                temp = keyboard_xt.pb;
                break;
                
                case 0x62:
                if (romset == ROM_IBMPC)
                {
                        if (keyboard_xt.pb & 0x04)
                                temp = ((mem_size-64) / 32) & 0xf;
                        else
                                temp = ((mem_size-64) / 32) >> 4;
                }
                else
                {
                        if (keyboard_xt.pb & 0x08)
                        {
                                if (VGA || gfxcard == GFX_EGA)
                                        temp = 4;
                                else if (MDA)
                                        temp = 7;
                                else
                                        temp = 6;
                        }
                        else
                                temp = 0xD;
                }
                temp |= (ppispeakon ? 0x20 : 0);
                if (keyboard_xt.tandy)
                        temp |= (tandy_eeprom_read() ? 0x10 : 0);
                break;
                
                default:
                pclog("\nBad XT keyboard read %04X\n", port);
		temp = 0xff;
        }
Exemplo n.º 26
0
static void
sio_detect_write(uint16_t port, uint8_t val, void *priv)
{
    sio_detect_t *dev = (sio_detect_t *) priv;

    pclog("sio_detect_write : port=%04x = %02X\n", port, val);

    dev->regs[port & 1] = val;

    return;
}
Exemplo n.º 27
0
void keyboard_xt_poll()
{
        keybsenddelay += (1000 * TIMER_USEC);
        if (key_queue_start != key_queue_end && !keyboard_xt.blocked)
        {
                keyboard_xt.pa = key_queue[key_queue_start];
		picint(2);
                pclog("Reading %02X from the key queue at %i\n", keyboard_xt.pa, key_queue_start);
                key_queue_start = (key_queue_start + 1) & 0xf;
                keyboard_xt.blocked = 1;
        }                
}
Exemplo n.º 28
0
void *ssi2001_init()
{
        ssi2001_t *ssi2001 = malloc(sizeof(ssi2001_t));
        memset(ssi2001, 0, sizeof(ssi2001_t));
        
        pclog("ssi2001_init\n");
        ssi2001->psid = sid_init();
        sid_reset(ssi2001->psid);
        io_sethandler(0x0280, 0x0020, ssi2001_read, NULL, NULL, ssi2001_write, NULL, NULL, ssi2001);
        sound_add_handler(ssi2001_get_buffer, ssi2001);
        return ssi2001;
}
Exemplo n.º 29
0
void *mpu401_standalone_init()
{
        mpu_t *mpu;

	mpu = malloc(sizeof(mpu_t));
        memset(mpu, 0, sizeof(mpu_t));
        
        pclog("mpu_init\n");
        mpu401_init(mpu, device_get_config_hex16("base"), device_get_config_int("irq"), device_get_config_int("mode"));

        return mpu;
}
Exemplo n.º 30
0
Arquivo: io.c Projeto: startmenu/PCemN
void io_init()
{
        int c;
        pclog("io_init\n");
        for (c = 0; c < 0x10000; c++)
        {
                port_inb[c][0]  = port_inw[c][0]  = port_inl[c][0]  = NULL;
                port_outb[c][0] = port_outw[c][0] = port_outl[c][0] = NULL;
                port_inb[c][1]  = port_inw[c][1]  = port_inl[c][1]  = NULL;
                port_outb[c][1] = port_outw[c][1] = port_outl[c][1] = NULL;
                port_priv[c][0] = port_priv[c][1] = NULL;
        }
}