/[gxemul]/trunk/src/devices/dev_bt459.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_bt459.c

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

revision 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2007  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_bt459.c,v 1.61 2005/11/13 00:14:08 debug Exp $   *  $Id: dev_bt459.c,v 1.70 2007/06/15 18:44:19 debug Exp $
29   *     *  
30   *  Brooktree 459 vdac, used by TURBOchannel graphics cards.   *  COMMENT: Brooktree BT459, used by TURBOchannel graphics cards
31   */   */
32    
33  #include <stdio.h>  #include <stdio.h>
# Line 65  struct bt459_data { Line 65  struct bt459_data {
65          int             planes;          int             planes;
66          int             type;          int             type;
67    
68          int             irq_nr;          struct interrupt irq;
69          int             interrupts_enable;          int             interrupts_enable;
70          int             interrupt_time;          int             interrupt_time;
71          int             interrupt_time_reset_value;          int             interrupt_time_reset_value;
# Line 101  struct bt459_data { Line 101  struct bt459_data {
101    
102    
103  /*  /*
  *  bt459_state():  
  */  
 int bt459_state(struct cpu *cpu, struct memory *mem, void *extra, int wf,  
         int nr, int *type, char **namep, void **data, size_t *len)  
 {  
         struct bt459_data *d = (struct bt459_data *) extra;  
   
         switch (nr) {  
         case 0: if (wf) {  
                         memcpy(&d->cursor_on, *data, *len);  
                 } else {  
                         (*namep) = "cursor_on";  
                         (*type) = DEVICE_STATE_TYPE_INT;  
                         *len = sizeof(d->cursor_on);  
                         *data = &d->cursor_on;  
                 }  
                 break;  
         case 1: if (wf) {  
                         memcpy(&d->cursor_x, *data, *len);  
                 } else {  
                         (*namep) = "cursor_x";  
                         (*type) = DEVICE_STATE_TYPE_INT;  
                         *len = sizeof(d->cursor_x);  
                         *data = &d->cursor_x;  
                 }  
                 break;  
         case 2: if (wf) {  
                         memcpy(&d->cursor_y, *data, *len);  
                 } else {  
                         (*namep) = "cursor_y";  
                         (*type) = DEVICE_STATE_TYPE_INT;  
                         *len = sizeof(d->cursor_y);  
                         *data = &d->cursor_y;  
                 }  
                 break;  
         case 3: if (wf) {  
                         memcpy(&d->cursor_xsize, *data, *len);  
                 } else {  
                         (*namep) = "cursor_xsize";  
                         (*type) = DEVICE_STATE_TYPE_INT;  
                         *len = sizeof(d->cursor_xsize);  
                         *data = &d->cursor_xsize;  
                 }  
                 break;  
         case 4: if (wf) {  
                         memcpy(&d->cursor_ysize, *data, *len);  
                 } else {  
                         (*namep) = "cursor_ysize";  
                         (*type) = DEVICE_STATE_TYPE_INT;  
                         *len = sizeof(d->cursor_ysize);  
                         *data = &d->cursor_ysize;  
                 }  
                 break;  
         default:  
                 return 0;  
         }  
   
         return 1;  
 }  
   
   
 /*  
104   *  bt459_update_X_cursor():   *  bt459_update_X_cursor():
105   *   *
106   *  This routine takes the color values in the cursor RAM area, and put them   *  This routine takes the color values in the cursor RAM area, and put them
# Line 207  static void bt459_update_X_cursor(struct Line 145  static void bt459_update_X_cursor(struct
145           */           */
146    
147  #ifdef WITH_X11  #ifdef WITH_X11
148          if (cpu->machine->use_x11 && d->vfb_data->fb_window != NULL) {          if (cpu->machine->x11_md.in_use && d->vfb_data->fb_window != NULL) {
149                  for (y=0; y<=ymax; y++) {                  for (y=0; y<=ymax; y++) {
150                          for (x=0; x<=xmax; x+=4) {                          for (x=0; x<=xmax; x+=4) {
151                                  struct fb_window *win = d->vfb_data->fb_window;                                  struct fb_window *win = d->vfb_data->fb_window;
# Line 306  static void bt459_update_cursor_position Line 244  static void bt459_update_cursor_position
244  }  }
245    
246    
247  /*  DEVICE_TICK(bt459)
  *  dev_bt459_tick():  
  */  
 void dev_bt459_tick(struct cpu *cpu, void *extra)  
248  {  {
249          struct bt459_data *d = extra;          struct bt459_data *d = extra;
250          int old_cursor_on = d->cursor_on;          int old_cursor_on = d->cursor_on;
# Line 336  void dev_bt459_tick(struct cpu *cpu, voi Line 271  void dev_bt459_tick(struct cpu *cpu, voi
271           *  or after another tick has passed.  (This is to prevent           *  or after another tick has passed.  (This is to prevent
272           *  lockups from unhandled interrupts.)           *  lockups from unhandled interrupts.)
273           */           */
274          if (d->type != BT459_PX && d->interrupts_enable && d->irq_nr > 0) {          if (d->type != BT459_PX && d->interrupts_enable) {
275                  d->interrupt_time --;                  d->interrupt_time --;
276                  if (d->interrupt_time < 0) {                  if (d->interrupt_time < 0) {
277                          d->interrupt_time = d->interrupt_time_reset_value;                          d->interrupt_time = d->interrupt_time_reset_value;
278                          cpu_interrupt(cpu, d->irq_nr);                          INTERRUPT_ASSERT(d->irq);
279                  } else                  } else
280                          cpu_interrupt_ack(cpu, d->irq_nr);                          INTERRUPT_DEASSERT(d->irq);
281          }          }
282  }  }
283    
284    
285  /*  DEVICE_ACCESS(bt459_irq)
  *  dev_bt459_irq_access():  
  */  
 int dev_bt459_irq_access(struct cpu *cpu, struct memory *mem,  
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
286  {  {
287          struct bt459_data *d = (struct bt459_data *) extra;          struct bt459_data *d = extra;
288          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
289    
290          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
# Line 365  int dev_bt459_irq_access(struct cpu *cpu Line 295  int dev_bt459_irq_access(struct cpu *cpu
295  #endif  #endif
296    
297          d->interrupts_enable = 1;          d->interrupts_enable = 1;
298          if (d->irq_nr > 0)  
299                  cpu_interrupt_ack(cpu, d->irq_nr);          INTERRUPT_DEASSERT(d->irq);
300    
301          if (writeflag == MEM_READ)          if (writeflag == MEM_READ)
302                  memory_writemax64(cpu, data, len, odata);                  memory_writemax64(cpu, data, len, odata);
# Line 375  int dev_bt459_irq_access(struct cpu *cpu Line 305  int dev_bt459_irq_access(struct cpu *cpu
305  }  }
306    
307    
308  /*  DEVICE_ACCESS(bt459)
  *  dev_bt459_access():  
  */  
 int dev_bt459_access(struct cpu *cpu, struct memory *mem,  
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
309  {  {
310          struct bt459_data *d = (struct bt459_data *) extra;          struct bt459_data *d = extra;
311          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
312          int btaddr, old_cursor_on = d->cursor_on, modified;          int btaddr, old_cursor_on = d->cursor_on, modified;
313    
# Line 399  int dev_bt459_access(struct cpu *cpu, st Line 324  int dev_bt459_access(struct cpu *cpu, st
324           *  accessing a normal BT459 register, or the irq register,           *  accessing a normal BT459 register, or the irq register,
325           *  or by simply "missing" it.           *  or by simply "missing" it.
326           */           */
327          if (d->irq_nr > 0)          INTERRUPT_DEASSERT(d->irq);
                 cpu_interrupt_ack(cpu, d->irq_nr);  
328    
329          /*  ID register is read-only, should always be 0x4a or 0x4a4a4a:  */          /*  ID register is read-only, should always be 0x4a or 0x4a4a4a:  */
330          if (d->planes == 24)          if (d->planes == 24)
# Line 599  int dev_bt459_access(struct cpu *cpu, st Line 523  int dev_bt459_access(struct cpu *cpu, st
523   */   */
524  void dev_bt459_init(struct machine *machine, struct memory *mem,  void dev_bt459_init(struct machine *machine, struct memory *mem,
525          uint64_t baseaddr, uint64_t baseaddr_irq, struct vfb_data *vfb_data,          uint64_t baseaddr, uint64_t baseaddr_irq, struct vfb_data *vfb_data,
526          int planes, int irq_nr, int type)          int planes, char *irq_path, int type)
527  {  {
528          struct bt459_data *d = malloc(sizeof(struct bt459_data));          struct bt459_data *d;
         if (d == NULL) {  
                 fprintf(stderr, "out of memory\n");  
                 exit(1);  
         }  
529    
530            CHECK_ALLOCATION(d = malloc(sizeof(struct bt459_data)));
531          memset(d, 0, sizeof(struct bt459_data));          memset(d, 0, sizeof(struct bt459_data));
532    
533            INTERRUPT_CONNECT(irq_path, d->irq);
534    
535          d->vfb_data     = vfb_data;          d->vfb_data     = vfb_data;
536          d->rgb_palette  = vfb_data->rgb_palette;          d->rgb_palette  = vfb_data->rgb_palette;
537          d->planes       = planes;          d->planes       = planes;
         d->irq_nr       = irq_nr;  
538          d->type         = type;          d->type         = type;
539          d->cursor_x     = -1;          d->cursor_x     = -1;
540          d->cursor_y     = -1;          d->cursor_y     = -1;
# Line 655  void dev_bt459_init(struct machine *mach Line 577  void dev_bt459_init(struct machine *mach
577                  memory_device_register(mem, "bt459_irq", baseaddr_irq, 0x10000,                  memory_device_register(mem, "bt459_irq", baseaddr_irq, 0x10000,
578                      dev_bt459_irq_access, (void *)d, DM_DEFAULT, NULL);                      dev_bt459_irq_access, (void *)d, DM_DEFAULT, NULL);
579    
580          machine_add_tickfunction(machine, dev_bt459_tick, d, BT459_TICK_SHIFT);          machine_add_tickfunction(machine, dev_bt459_tick, d,
581                BT459_TICK_SHIFT);
         memory_device_register_statefunction(mem, d, bt459_state);  
582  }  }
583    

Legend:
Removed from v.20  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26