--- trunk/src/devices/dev_8253.c 2007/10/08 16:18:11 6 +++ trunk/src/devices/dev_8253.c 2007/10/08 16:19:56 24 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005 Anders Gavare. All rights reserved. + * Copyright (C) 2005-2006 Anders Gavare. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * - * $Id: dev_8253.c,v 1.4 2005/05/21 07:41:11 debug Exp $ + * $Id: dev_8253.c,v 1.10 2006/03/04 12:38:47 debug Exp $ * * 8253/8254 Programmable Interval Timer. * @@ -51,6 +51,7 @@ struct pit8253_data { int irq_nr; + int in_use; int counter_select; }; @@ -61,6 +62,10 @@ void dev_8253_tick(struct cpu *cpu, void *extra) { struct pit8253_data *d = (struct pit8253_data *) extra; + + if (!d->in_use) + return; + cpu_interrupt(cpu, d->irq_nr); } @@ -68,14 +73,15 @@ /* * dev_8253_access(): */ -int dev_8253_access(struct cpu *cpu, struct memory *mem, - uint64_t relative_addr, unsigned char *data, size_t len, - int writeflag, void *extra) +DEVICE_ACCESS(8253) { struct pit8253_data *d = (struct pit8253_data *) extra; uint64_t idata = 0, odata = 0; - idata = memory_readmax64(cpu, data, len); + if (writeflag == MEM_WRITE) + idata = memory_readmax64(cpu, data, len); + + d->in_use = 1; /* TODO: ack somewhere else */ cpu_interrupt_ack(cpu, d->irq_nr); @@ -86,8 +92,8 @@ /* TODO */ } else { /* TODO */ - odata = 1; -odata = random(); + /* odata = 1; */ + odata = random(); } break; case 0x03: @@ -115,10 +121,7 @@ } -/* - * devinit_8253(): - */ -int devinit_8253(struct devinit *devinit) +DEVINIT(8253) { struct pit8253_data *d = malloc(sizeof(struct pit8253_data)); @@ -128,13 +131,14 @@ } memset(d, 0, sizeof(struct pit8253_data)); d->irq_nr = devinit->irq_nr; + d->in_use = devinit->in_use; memory_device_register(devinit->machine->memory, devinit->name, devinit->addr, DEV_8253_LENGTH, dev_8253_access, (void *)d, - MEM_DEFAULT, NULL); + DM_DEFAULT, NULL); machine_add_tickfunction(devinit->machine, dev_8253_tick, - d, TICK_SHIFT); + d, TICK_SHIFT, 0.0); return 1; }