/[gxemul]/trunk/src/devices/dev_lpt.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/devices/dev_lpt.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 16 by dpavlin, Mon Oct 8 16:19:01 2007 UTC revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-2006  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *   *
27   *   *
28   *  $Id: dev_lpt.c,v 1.1 2005/10/09 21:32:08 debug Exp $   *  $Id: dev_lpt.c,v 1.8 2006/02/09 20:02:59 debug Exp $
29   *   *
30   *  LPT (parallel printer) controller.   *  LPT (parallel printer) controller.
  *  
  *  TODO: This is just a dummy.  
31   */   */
32    
33  #include <stdio.h>  #include <stdio.h>
# Line 43  Line 41 
41  #include "memory.h"  #include "memory.h"
42  #include "misc.h"  #include "misc.h"
43    
44    #include "lptreg.h"
45    
46    
47  #define debug fatal  /*  #define debug fatal  */
48    
49  #define TICK_SHIFT              15  #define TICK_SHIFT              18
50  #define DEV_LPT_LENGTH          3  #define DEV_LPT_LENGTH          3
51    
52  struct lpt_data {  struct lpt_data {
         int             in_use;  
53          int             irqnr;          int             irqnr;
54          char            *name;          char            *name;
55          int             console_handle;          int             console_handle;
56    
57          unsigned char   data;          unsigned char   data;
58            unsigned char   control;
59  };  };
60    
61    
# Line 73  void dev_lpt_tick(struct cpu *cpu, void Line 73  void dev_lpt_tick(struct cpu *cpu, void
73  /*  /*
74   *  dev_lpt_access():   *  dev_lpt_access():
75   */   */
76  int dev_lpt_access(struct cpu *cpu, struct memory *mem,  DEVICE_ACCESS(lpt)
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
77  {  {
78          uint64_t idata = 0, odata=0;          uint64_t idata = 0, odata=0;
79          struct lpt_data *d = extra;          struct lpt_data *d = extra;
80    
81          idata = memory_readmax64(cpu, data, len);          if (writeflag == MEM_WRITE)
82                    idata = memory_readmax64(cpu, data, len);
83    
84          switch (relative_addr) {          switch (relative_addr) {
85    
86          case 0: if (writeflag == MEM_READ)          case LPT_DATA:
87                    if (writeflag == MEM_READ)
88                          odata = d->data;                          odata = d->data;
89                  else                  else
90                          d->data = idata;                          d->data = idata;
91                  break;                  break;
92    
93          default:          case LPT_STATUS:
94                  if (writeflag == MEM_READ) {                  odata = LPS_NBSY | LPS_NACK | LPS_SELECT | LPS_NERR;
95                          debug("[ lpt (%s): read from %i: UNIMPLEMENTED ]\n",                  break;
96                              d->name, (int)relative_addr);  
97                  } else {          case LPT_CONTROL:
98                          debug("[ lpt (%s): write to %i, data = 0x%llx: "                  if (writeflag == MEM_WRITE) {
99                              "UNIMPLEMENTED ]\n", d->name, (int)relative_addr,                          if (idata != d->control) {
100                              (long long)idata);                                  if (idata & LPC_STROBE) {
101                                            /*  data strobe  */
102                                            console_putchar(d->console_handle,
103                                                d->data);
104                                    }
105                            }
106                            d->control = idata;
107                  }                  }
108                    break;
109          }          }
110    
111          if (writeflag == MEM_READ)          if (writeflag == MEM_READ)
# Line 108  int dev_lpt_access(struct cpu *cpu, stru Line 115  int dev_lpt_access(struct cpu *cpu, stru
115  }  }
116    
117    
118  /*  DEVINIT(lpt)
  *  devinit_lpt():  
  */  
 int devinit_lpt(struct devinit *devinit)  
119  {  {
120          struct lpt_data *d = malloc(sizeof(struct lpt_data));          struct lpt_data *d = malloc(sizeof(struct lpt_data));
121          size_t nlen;          size_t nlen;
# Line 123  int devinit_lpt(struct devinit *devinit) Line 127  int devinit_lpt(struct devinit *devinit)
127          }          }
128          memset(d, 0, sizeof(struct lpt_data));          memset(d, 0, sizeof(struct lpt_data));
129          d->irqnr        = devinit->irq_nr;          d->irqnr        = devinit->irq_nr;
         d->in_use       = devinit->in_use;  
130          d->name         = devinit->name2 != NULL? devinit->name2 : "";          d->name         = devinit->name2 != NULL? devinit->name2 : "";
131          d->console_handle =          d->console_handle = console_start_slave(devinit->machine, devinit->name,
132              console_start_slave(devinit->machine, devinit->name);              CONSOLE_OUTPUT_ONLY);
133    
134          nlen = strlen(devinit->name) + 10;          nlen = strlen(devinit->name) + 10;
135          if (devinit->name2 != NULL)          if (devinit->name2 != NULL)
# Line 142  int devinit_lpt(struct devinit *devinit) Line 145  int devinit_lpt(struct devinit *devinit)
145                  snprintf(name, nlen, "%s", devinit->name);                  snprintf(name, nlen, "%s", devinit->name);
146    
147          memory_device_register(devinit->machine->memory, name, devinit->addr,          memory_device_register(devinit->machine->memory, name, devinit->addr,
148              DEV_LPT_LENGTH, dev_lpt_access, d, MEM_DEFAULT, NULL);              DEV_LPT_LENGTH, dev_lpt_access, d, DM_DEFAULT, NULL);
149          machine_add_tickfunction(devinit->machine, dev_lpt_tick, d, TICK_SHIFT);          machine_add_tickfunction(devinit->machine, dev_lpt_tick, d, TICK_SHIFT);
150    
151          /*          /*

Legend:
Removed from v.16  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.26