--- trunk/src/devices/dev_lpt.c 2007/10/08 16:19:01 16 +++ trunk/src/devices/dev_lpt.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,11 +25,9 @@ * SUCH DAMAGE. * * - * $Id: dev_lpt.c,v 1.1 2005/10/09 21:32:08 debug Exp $ + * $Id: dev_lpt.c,v 1.9 2006/03/04 12:38:47 debug Exp $ * * LPT (parallel printer) controller. - * - * TODO: This is just a dummy. */ #include @@ -43,19 +41,21 @@ #include "memory.h" #include "misc.h" +#include "lptreg.h" + -#define debug fatal +/* #define debug fatal */ -#define TICK_SHIFT 15 +#define TICK_SHIFT 18 #define DEV_LPT_LENGTH 3 struct lpt_data { - int in_use; int irqnr; char *name; int console_handle; unsigned char data; + unsigned char control; }; @@ -73,32 +73,39 @@ /* * dev_lpt_access(): */ -int dev_lpt_access(struct cpu *cpu, struct memory *mem, - uint64_t relative_addr, unsigned char *data, size_t len, - int writeflag, void *extra) +DEVICE_ACCESS(lpt) { uint64_t idata = 0, odata=0; struct lpt_data *d = extra; - idata = memory_readmax64(cpu, data, len); + if (writeflag == MEM_WRITE) + idata = memory_readmax64(cpu, data, len); switch (relative_addr) { - case 0: if (writeflag == MEM_READ) + case LPT_DATA: + if (writeflag == MEM_READ) odata = d->data; else d->data = idata; break; - default: - if (writeflag == MEM_READ) { - debug("[ lpt (%s): read from %i: UNIMPLEMENTED ]\n", - d->name, (int)relative_addr); - } else { - debug("[ lpt (%s): write to %i, data = 0x%llx: " - "UNIMPLEMENTED ]\n", d->name, (int)relative_addr, - (long long)idata); + case LPT_STATUS: + odata = LPS_NBSY | LPS_NACK | LPS_SELECT | LPS_NERR; + break; + + case LPT_CONTROL: + if (writeflag == MEM_WRITE) { + if (idata != d->control) { + if (idata & LPC_STROBE) { + /* data strobe */ + console_putchar(d->console_handle, + d->data); + } + } + d->control = idata; } + break; } if (writeflag == MEM_READ) @@ -108,10 +115,7 @@ } -/* - * devinit_lpt(): - */ -int devinit_lpt(struct devinit *devinit) +DEVINIT(lpt) { struct lpt_data *d = malloc(sizeof(struct lpt_data)); size_t nlen; @@ -123,10 +127,9 @@ } memset(d, 0, sizeof(struct lpt_data)); d->irqnr = devinit->irq_nr; - d->in_use = devinit->in_use; d->name = devinit->name2 != NULL? devinit->name2 : ""; - d->console_handle = - console_start_slave(devinit->machine, devinit->name); + d->console_handle = console_start_slave(devinit->machine, devinit->name, + CONSOLE_OUTPUT_ONLY); nlen = strlen(devinit->name) + 10; if (devinit->name2 != NULL) @@ -142,8 +145,9 @@ snprintf(name, nlen, "%s", devinit->name); memory_device_register(devinit->machine->memory, name, devinit->addr, - DEV_LPT_LENGTH, dev_lpt_access, d, MEM_DEFAULT, NULL); - machine_add_tickfunction(devinit->machine, dev_lpt_tick, d, TICK_SHIFT); + DEV_LPT_LENGTH, dev_lpt_access, d, DM_DEFAULT, NULL); + machine_add_tickfunction(devinit->machine, dev_lpt_tick, d, + TICK_SHIFT, 0.0); /* * NOTE: Ugly cast into a pointer, because this is a convenient way