Previous 15994 Revisions Next

r3756 Sunday 7th December, 2008 at 22:52:04 UTC by R. Belmont
[SDLMESS] Sync to SDLMAME 0.128u5.
[src/osd/sdl]debugosx.c debugwin.c dview.c

src/osd/sdl/dview.c
r3755r3756
66
77static gboolean dview_expose(GtkWidget *wdv, GdkEventExpose *event)
88{
9   debug_view_char *viewdata;
9   const debug_view_char *viewdata;
1010   DView *dv = DVIEW(wdv);
1111   DViewClass *dvc = DVIEW_GET_CLASS(dv);
12   //UINT32 trow = debug_view_get_property_UINT32(dv->dw, DVP_TOTAL_ROWS);
13   //UINT32 tcol = debug_view_get_property_UINT32(dv->dw, DVP_TOTAL_COLS);
14   //UINT32 prow = debug_view_get_property_UINT32(dv->dw, DVP_TOP_ROW);
15   //UINT32 pcol = debug_view_get_property_UINT32(dv->dw, DVP_LEFT_COL);
16   UINT32 vrow = debug_view_get_property_UINT32(dv->dw, DVP_VISIBLE_ROWS);
17   UINT32 vcol = debug_view_get_property_UINT32(dv->dw, DVP_VISIBLE_COLS);
12   debug_view_xy vsize;
13   UINT32 vrow;
14   UINT32 vcol;
1815   UINT32 i, j, xx, yy;
1916   GdkColor bg, fg;
2017
18   vsize = debug_view_get_visible_size(dv->dw);
19   vrow = vsize.y;
20   vcol = vsize.x;
21
2122   bg.red = bg.green = bg.blue = 0xffff;
2223   gdk_gc_set_rgb_fg_color(dv->gc, &bg);
2324   gdk_draw_rectangle(GDK_DRAWABLE(wdv->window), dv->gc, TRUE, 0, 0, wdv->allocation.width - (dv->vs ? dv->vsz : 0), wdv->allocation.height - (dv->hs ? dv->hsz : 0));
r3755r3756
2930                     dv->vsz, dv->hsz);
3031   }
3132
32   viewdata = debug_view_get_property_ptr(dv->dw, DVP_VIEW_DATA);
33   viewdata = debug_view_get_chars(dv->dw);
3334
3435   yy = wdv->style->ythickness;
3536   for(j=0; j<vrow; j++) {
r3755r3756
104105
105106static void dview_hadj_changed(GtkAdjustment *adj, DView *dv)
106107{
107   UINT32 pcol = debug_view_get_property_UINT32(dv->dw, DVP_LEFT_COL);
108   debug_view_xy pos;
108109   UINT32 v = (UINT32)(adj->value);
109   if(v != pcol) {
110      debug_view_set_property_UINT32(dv->dw, DVP_LEFT_COL, v);
110
111   pos = debug_view_get_visible_position(dv->dw);
112
113   if (v != pos.x)
114   {
115      pos.x = v;
116      debug_view_set_visible_position(dv->dw, pos);
111117      gtk_widget_queue_draw(GTK_WIDGET(dv));
112118   }
113119}
114120
115121static void dview_vadj_changed(GtkAdjustment *adj, DView *dv)
116122{
117   UINT32 pcol = debug_view_get_property_UINT32(dv->dw, DVP_TOP_ROW);
123   debug_view_xy pos;
118124   UINT32 v = (UINT32)(adj->value);
119   if(v != pcol) {
125
126   pos = debug_view_get_visible_position(dv->dw);
127
128   if (v != pos.y)
129   {
120130      if(dv->this_one_is_stupidly_autoscrolling)
121         debug_view_set_property_UINT32(dv->dw, DVP_TEXTBUF_LINE_LOCK, v);
131      {
132// what is new equivalent here?
133//         debug_view_set_(dv->dw, DVP_TEXTBUF_LINE_LOCK, v);
134      }
122135      else
123         debug_view_set_property_UINT32(dv->dw, DVP_TOP_ROW, v);
136      {
137         pos.y = v;
138         debug_view_set_visible_position(dv->dw, pos);
139      }
124140      gtk_widget_queue_draw(GTK_WIDGET(dv));
125141   }
126142}
r3755r3756
156172{
157173   DView *dv = DVIEW(wdv);
158174   DViewClass *dvc = DVIEW_GET_CLASS(dv);
159   UINT32 trow = debug_view_get_property_UINT32(dv->dw, DVP_TOTAL_ROWS);
160   UINT32 tcol = debug_view_get_property_UINT32(dv->dw, DVP_TOTAL_COLS);
161   int    prow = debug_view_get_property_UINT32(dv->dw, DVP_TOP_ROW);
162   int    pcol = debug_view_get_property_UINT32(dv->dw, DVP_LEFT_COL);
175   UINT32 trow;
176   UINT32 tcol;
177   int    prow;
178   int    pcol;
163179   UINT32 ah   = allocation->height-2*wdv->style->ythickness;
164180   UINT32 aw   = allocation->width-2*wdv->style->xthickness;
165181   UINT32 crow, ccol, vrow, vcol;
166182   int ohs = dv->hs;
167183   int ovs = dv->vs;
184   debug_view_xy size, pos;
168185
186   pos = debug_view_get_visible_position(dv->dw);
187   size = debug_view_get_total_size(dv->dw);
188   trow = size.y;
189   tcol = size.x;
190   prow = pos.y;
191   pcol = pos.x;
192
169193   dv->tr = trow;
170194   dv->tc = tcol;
171195
r3755r3756
207231      vcol = tcol-pcol;
208232   }
209233
210   debug_view_set_property_UINT32(dv->dw, DVP_VISIBLE_ROWS, vrow);
211   debug_view_set_property_UINT32(dv->dw, DVP_VISIBLE_COLS, vcol);
212   debug_view_set_property_UINT32(dv->dw, DVP_TOP_ROW,  prow);
213   debug_view_set_property_UINT32(dv->dw, DVP_LEFT_COL, pcol);
234   size.y = trow;
235   size.x = tcol;
236   pos.y = prow;
237   pos.x = pcol;
214238
239   debug_view_set_visible_position(dv->dw, pos);
240   debug_view_set_visible_size(dv->dw, size);
241
215242   if(GTK_WIDGET_REALIZED(wdv))
216243      gdk_window_move_resize(wdv->window,
217244                        allocation->x, allocation->y,
r3755r3756
239266      dv->hadj->page_increment = span;
240267      dv->hadj->page_size = span;
241268      gtk_adjustment_changed(dv->hadj);
242      debug_view_set_property_UINT32(dv->dw, DVP_LEFT_COL, pcol);
269      pos.y = prow;
270      pos.x = pcol;
271      debug_view_set_visible_position(dv->dw, pos);
243272   } else {
244273      if(ohs)
245274         gtk_widget_hide(dv->hscrollbar);
r3755r3756
267296      dv->vadj->page_increment = span;
268297      dv->vadj->page_size = span;
269298      gtk_adjustment_changed(dv->vadj);
270      debug_view_set_property_UINT32(dv->dw, DVP_TOP_ROW, prow);
299      pos.y = prow;
300      pos.x = pcol;
301      debug_view_set_visible_position(dv->dw, pos);
271302   } else {
272303      if(ovs)
273304         gtk_widget_hide(dv->vscrollbar);
r3755r3756
279310   GtkRequisition req2;
280311   DView *dv = DVIEW(wdv);
281312   DViewClass *dvc = DVIEW_GET_CLASS(dv);
282   UINT32 trow = debug_view_get_property_UINT32(dv->dw, DVP_TOTAL_ROWS);
283   UINT32 tcol = debug_view_get_property_UINT32(dv->dw, DVP_TOTAL_COLS);
313   UINT32 trow;
314   UINT32 tcol;
284315   int vs = 0, hs = 0;
316   debug_view_xy size;
285317
318   size = debug_view_get_total_size(dv->dw);
319   trow = size.y;
320   tcol = size.x;
321
286322   if(tcol > 50) {
287323      tcol = 50;
288324      hs = 1;
r3755r3756
380416   g_signal_connect(dv->vadj, "value-changed", G_CALLBACK(dview_vadj_changed), dv);
381417}
382418
383static void dview_view_update(debug_view *dw)
384{
385   DView *dv = debug_view_get_property_ptr(dw, DVP_OSD_PRIVATE);
386   UINT32 trow = debug_view_get_property_UINT32(dv->dw, DVP_TOTAL_ROWS);
387   UINT32 tcol = debug_view_get_property_UINT32(dv->dw, DVP_TOTAL_COLS);
388
389   if(dv->tr != trow || dv->tc != tcol)
390      gtk_widget_queue_resize(GTK_WIDGET(dv));
391   else
392      gtk_widget_queue_draw(GTK_WIDGET(dv));
393}
394
395419GtkWidget *dview_new(const gchar *widget_name, const gchar *string1, const gchar *string2, gint int1, gint int2)
396420{
397421   GtkWidget *wdv = g_object_new(DVIEW_TYPE, NULL);
r3755r3756
404428void dview_set_debug_view(DView *dv, debug_view *dw)
405429{
406430   dv->dw = dw;
407   debug_view_set_property_ptr(dw, DVP_OSD_PRIVATE, dv);
408   debug_view_set_property_fct(dw, DVP_UPDATE_CALLBACK, (void *)dview_view_update);
409431}
410432
411433void dview_this_one_is_stupidly_autoscrolling(DView *dv)
src/osd/sdl/debugwin.c
r3755r3756
4141   debug_view *console;
4242   debug_view *disasm;
4343   debug_view *registers;
44   int cpu;
45   running_machine *machine;
44   const device_config *cpu;   // current CPU
45   running_machine *machine;   // machine
4646} debugmain_i;
4747
4848typedef struct memorywin_i {
r3755r3756
5353   GtkComboBox *zone_w;
5454   debug_view *memory;
5555   running_machine *machine;
56
5657} memorywin_i;
5758
5859typedef struct disasmwin_i {
r3755r3756
7778{
7879   struct memorycombo_item *next;
7980   char               name[256];
80   UINT8               cpunum;
81   UINT8               spacenum;
82   void *               base;
83   UINT32               length;
84   UINT8               offset_xor;
85   UINT8               little_endian;
8681   UINT8               prefsize;
87   running_machine *machine;
82   running_machine          *machine;   // machine
83   const memory_subview_item      *subview;   // subview
84   const device_config         *device;   // CPU device
8885} memorycombo_item;
8986
9087
r3755r3756
115112      f(p3->win);
116113}
117114
118//============================================================
119//  memory_determine_combo_items
120//============================================================
121
122static void memory_determine_combo_items(running_machine *machine)
123{
124   memorycombo_item **tail = &memorycombo;
125   UINT32 cpunum, spacenum;
126   const char *rgntag;
127   int itemnum;
128
129   // first add all the CPUs' address spaces
130   for (cpunum = 0; cpunum < MAX_CPU; cpunum++)
131   {
132      if (machine->cpu[cpunum] != NULL)
133      {
134                const cpu_debug_data *cpuinfo = cpu_get_debug_data(machine->cpu[cpunum]);
135
136         for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
137         {
138            if (cpuinfo->space[spacenum].databytes)
139            {
140               memorycombo_item *ci = malloc_or_die(sizeof(*ci));
141               memset(ci, 0, sizeof(*ci));
142               ci->cpunum = cpunum;
143               ci->spacenum = spacenum;
144               ci->machine = machine;
145               ci->prefsize = MIN(cpuinfo->space[spacenum].databytes, 8);
146
147               snprintf(ci->name, ARRAY_LENGTH(ci->name), "CPU #%d \"%s\" (%s) %s memory", cpunum, machine->config->cpu[cpunum].tag, cpu_get_name(machine->cpu[cpunum]), address_space_names[spacenum]);
148
149               *tail = ci;
150               tail = &ci->next;
151            }
152         }
153      }
154   }
155
156   // then add all the memory regions
157   for (rgntag = memory_region_next(machine, NULL); rgntag != NULL; rgntag = memory_region_next(machine, rgntag))
158   {
159      memorycombo_item *ci = malloc_or_die(sizeof(*ci));
160      UINT32 flags = memory_region_flags(machine, rgntag);
161      UINT8 little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE);
162      UINT8 width = 1 << ((flags & ROMREGION_WIDTHMASK) >> 8);
163
164      memset(ci, 0, sizeof(*ci));
165      ci->base = memory_region(machine, rgntag);
166      ci->length = memory_region_length(machine, rgntag);
167      ci->prefsize = MIN(width, 8);
168      ci->offset_xor = width - 1;
169      ci->little_endian = little_endian;
170      ci->machine = machine;
171
172      snprintf(ci->name, ARRAY_LENGTH(ci->name), "Region \"%s\"", rgntag);
173
174      *tail = ci;
175      tail = &ci->next;
176   }
177
178   // finally add all global array symbols
179   for (itemnum = 0; itemnum < 10000; itemnum++)
180   {
181      UINT32 valsize, valcount;
182      const char *name;
183      void *base;
184
185      /* stop when we run out of items */
186      name = state_save_get_indexed_item(itemnum, &base, &valsize, &valcount);
187      if (name == NULL)
188         break;
189
190      /* if this is a single-entry global, add it */
191      if (valcount > 1 && strstr(name, "/globals/"))
192      {
193         memorycombo_item *ci = malloc_or_die(sizeof(*ci));
194         memset(ci, 0, sizeof(*ci));
195         ci->base = base;
196         ci->length = valcount * valsize;
197         ci->prefsize = MIN(valsize, 8);
198         ci->little_endian = TRUE;
199         ci->machine = machine;
200         strcpy(ci->name, strrchr(name, '/') + 1);
201         *tail = ci;
202         tail = &ci->next;
203      }
204   }
205}
206
207
208115static void edit_add_hist(edit *e, const char *text)
209116{
210117   if(e->ch)
r3755r3756
338245
339246static void debugmain_update_checks(debugmain_i *info)
340247{
341   int rc = debug_view_get_property_UINT32(info->disasm, DVP_DASM_RIGHT_COLUMN);
342   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "raw_opcodes")), rc == DVP_DASM_RIGHTCOL_RAW);
343   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "enc_opcodes")), rc == DVP_DASM_RIGHTCOL_ENCRYPTED);
344   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "comments")), rc == DVP_DASM_RIGHTCOL_COMMENTS);
248   int rc = disasm_view_get_right_column(info->disasm);
249   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "raw_opcodes")), rc == DASM_RIGHTCOL_RAW);
250   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "enc_opcodes")), rc == DASM_RIGHTCOL_ENCRYPTED);
251   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "comments")), rc == DASM_RIGHTCOL_COMMENTS);
345252}
346253
347254void debugmain_raw_opcodes_activate(GtkMenuItem *item, gpointer user_data)
r3755r3756
349256   debugmain_i *info = user_data;
350257   if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "raw_opcodes")))) {
351258      debug_view_begin_update(info->disasm);
352      debug_view_set_property_UINT32(info->disasm, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_RAW);
259      disasm_view_set_right_column(info->disasm, DASM_RIGHTCOL_RAW);
353260      debug_view_end_update(info->disasm);
354261   }
355262}
r3755r3756
359266   debugmain_i *info = user_data;
360267   if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "enc_opcodes")))) {
361268      debug_view_begin_update(info->disasm);
362      debug_view_set_property_UINT32(info->disasm, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_ENCRYPTED);
269      disasm_view_set_right_column(info->disasm, DASM_RIGHTCOL_ENCRYPTED);
363270      debug_view_end_update(info->disasm);
364271   }
365272}
r3755r3756
369276   debugmain_i *info = user_data;
370277   if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "comments")))) {
371278      debug_view_begin_update(info->disasm);
372      debug_view_set_property_UINT32(info->disasm, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_COMMENTS);
279      disasm_view_set_right_column(info->disasm, DASM_RIGHTCOL_COMMENTS);
373280      debug_view_end_update(info->disasm);
374281   }
375282}
376283
377static void debugmain_set_cpunum(running_machine *machine, int cpunum)
284static void debugmain_set_cpu(const device_config *cpu)
378285{
379   if(cpunum != dmain->cpu) {
286   if (cpu != dmain->cpu)
287   {
380288      char title[256];
381      dmain->cpu = cpunum;
289      const registers_subview_item *regsubitem;
290      const disasm_subview_item *dasmsubitem;
291
292      dmain->cpu = cpu;
382293     
383      // first set all the views to the new cpu number
384      debug_view_set_property_UINT32(dmain->disasm, DVP_DASM_CPUNUM, cpunum);
385      debug_view_set_property_UINT32(dmain->registers, DVP_REGS_CPUNUM, cpunum);
294      // first set all the views to the new cpu
295      for (dasmsubitem = disasm_view_get_subview_list(dmain->disasm); dasmsubitem != NULL; dasmsubitem = dasmsubitem->next)
296         if (dasmsubitem->space->cpu == cpu)
297         {
298            disasm_view_set_subview(dmain->disasm, dasmsubitem->index);
299            break;
300         }
386301
302      for (regsubitem = registers_view_get_subview_list(dmain->registers); regsubitem != NULL; regsubitem = regsubitem->next)
303         if (regsubitem->device == cpu)
304         {
305            registers_view_set_subview(dmain->registers, regsubitem->index);
306            break;
307         }
308
387309      // then update the caption
388      sprintf(title, "Debug: %s - CPU #%d \"%s\" (%s)", machine->gamedrv->name, cpunum, machine->config->cpu[cpunum].tag, cpu_get_name(machine->cpu[cpunum]));
310      snprintf(title, ARRAY_LENGTH(title), "Debug: %s - %s", cpu->machine->gamedrv->name, regsubitem->name);
389311      gtk_window_set_title(GTK_WINDOW(dmain->win), title);
390312      debugmain_update_checks(dmain);
391313   }
392314}
393315
394
395316// The entry point
396317
397void osd_wait_for_debugger(running_machine *machine, int firststop)
318void osd_wait_for_debugger(const device_config *device, int firststop)
398319{
399320   // create a console window
400   if(!dmain) {
321   if(!dmain)
322   {
401323      // GTK init should probably be done earlier
402324      gtk_init(0, 0);
403      debugmain_init(machine);
325      debugmain_init(device->machine);
404326   }
405327
406328   // update the views in the console to reflect the current CPU
407   debugmain_set_cpunum(machine, cpunum_get_active());
329   debugmain_set_cpu(device);
408330
409331   debugwin_show(1);
410332   gtk_main_iteration();
r3755r3756
431353   mame_schedule_exit(dmain->machine);
432354}
433355
356//============================================================
357//  debugwin_console_update
358//============================================================
359
360static void debugwin_console_update(debug_view *view, void *osdprivate)
361{
362   debugmain_i *dbg_main = (debugmain_i *)osdprivate;
363   debug_view_xy size;
364
365   size = debug_view_get_total_size(dbg_main->console);
366   if ((dbg_main->console_w->tr != size.y) || (dbg_main->console_w->tc != size.x))
367   {
368      gtk_widget_queue_resize(GTK_WIDGET(dbg_main->console_w));
369   }
370   else
371   {
372      gtk_widget_queue_draw(GTK_WIDGET(dbg_main->console_w));
373   }
374}
375
376//============================================================
377//  debugwin_disasm_update
378//============================================================
379
380static void debugwin_disasm_update(debug_view *view, void *osdprivate)
381{
382   debugmain_i *dbg_main = (debugmain_i *)osdprivate;
383   debug_view_xy size;
384
385   size = debug_view_get_total_size(dbg_main->disasm);
386   if ((dbg_main->disasm_w->tr != size.y) || (dbg_main->disasm_w->tc != size.x))
387   {
388      gtk_widget_queue_resize(GTK_WIDGET(dbg_main->disasm_w));
389   }
390   else
391   {
392      gtk_widget_queue_draw(GTK_WIDGET(dbg_main->disasm_w));
393   }
394}
395
396//============================================================
397//  debugwin_register_update
398//============================================================
399
400static void debugwin_register_update(debug_view *view, void *osdprivate)
401{
402   debugmain_i *dbg_main = (debugmain_i *)osdprivate;
403   debug_view_xy size;
404
405   size = debug_view_get_total_size(dbg_main->registers);
406   if ((dbg_main->registers_w->tr != size.y) || (dbg_main->registers_w->tc != size.x))
407   {
408      gtk_widget_queue_resize(GTK_WIDGET(dbg_main->registers_w));
409   }
410   else
411   {
412      gtk_widget_queue_draw(GTK_WIDGET(dbg_main->registers_w));
413   }
414}
415
434416static void debugmain_init(running_machine *machine)
435417{
436418   dmain = malloc(sizeof(*dmain));
437419   memset(dmain, 0, sizeof(*dmain));
438420   dmain->win = create_debugmain(machine);
439   dmain->cpu = -1;
421   dmain->cpu = NULL;
440422   dmain->machine = machine;
441423
442424   dmain->console_w   = DVIEW(lookup_widget(dmain->win, "console"));
443425   dmain->disasm_w    = DVIEW(lookup_widget(dmain->win, "disasm"));
444426   dmain->registers_w = DVIEW(lookup_widget(dmain->win, "registers"));
445427
446   dmain->console   = debug_view_alloc(machine, DVT_CONSOLE);
447   dmain->disasm    = debug_view_alloc(machine, DVT_DISASSEMBLY);
448   dmain->registers = debug_view_alloc(machine, DVT_REGISTERS);
428   dmain->console   = debug_view_alloc(machine, DVT_CONSOLE, debugwin_console_update, dmain);
429   dmain->disasm    = debug_view_alloc(machine, DVT_DISASSEMBLY, debugwin_disasm_update, dmain);
430   dmain->registers = debug_view_alloc(machine, DVT_REGISTERS, debugwin_register_update, dmain);
449431
450432   dview_set_debug_view(dmain->console_w,   dmain->console);
451433   dview_set_debug_view(dmain->disasm_w,    dmain->disasm);
r3755r3756
456438   edit_init(machine, &dmain->ed, lookup_widget(dmain->win, "edit"), 0, 0, debugmain_process_string, &dmain);
457439
458440   debug_view_begin_update(dmain->disasm);
459   debug_view_set_property_string(dmain->disasm, DVP_DASM_EXPRESSION, "curpc");
460   debug_view_set_property_UINT32(dmain->disasm, DVP_DASM_TRACK_LIVE, 1);
441   disasm_view_set_expression(dmain->disasm, "curpc");
442//   debug_view_set_property_UINT32(dmain->disasm, DVP_DASM_TRACK_LIVE, 1);
461443   debug_view_end_update(dmain->disasm);
462444
463445   g_signal_connect(dmain->win, "destroy", G_CALLBACK(debugmain_destroy), dmain);
r3755r3756
470452
471453static void memorywin_update_checks(memorywin_i *info)
472454{
473   int bpc = debug_view_get_property_UINT32(info->memory, DVP_MEM_BYTES_PER_CHUNK);
474   int rev = debug_view_get_property_UINT32(info->memory, DVP_MEM_REVERSE_VIEW);
455   int bpc = memory_view_get_bytes_per_chunk(info->memory);
456   int rev = memory_view_get_reverse(info->memory);
475457   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "chunks_1")), bpc == 1);
476458   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "chunks_2")), bpc == 2);
477459   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "chunks_4")), bpc == 4);
478460   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "reverse")), rev);
479461}
480462
481static void memorywin_update_selection(memorywin_i *info, memorycombo_item *ci)
482{
483   debug_view_set_property_UINT32(info->memory, DVP_MEM_CPUNUM, ci->cpunum);
484   debug_view_set_property_UINT32(info->memory, DVP_MEM_SPACENUM, ci->spacenum);
485   debug_view_set_property_ptr(info->memory, DVP_MEM_RAW_BASE, ci->base);
486   debug_view_set_property_UINT32(info->memory, DVP_MEM_RAW_LENGTH, ci->length);
487   debug_view_set_property_UINT32(info->memory, DVP_MEM_RAW_OFFSET_XOR, ci->offset_xor);
488   debug_view_set_property_UINT32(info->memory, DVP_MEM_RAW_LITTLE_ENDIAN, ci->little_endian);
489   debug_view_set_property_UINT32(info->memory, DVP_MEM_BYTES_PER_CHUNK, ci->prefsize);
490   memorywin_update_checks(info);
491   gtk_window_set_title(GTK_WINDOW(info->win), ci->name);
492}
493
494463static void memorywin_zone_changed(GtkComboBox *zone_w, memorywin_i *mem)
495464{
496465   int sel = gtk_combo_box_get_active(mem->zone_w);
497   int i;
498   memorycombo_item *ci;
499   for(i=0, ci=memorycombo; i != sel; i++)
500      ci = ci->next;
501   memorywin_update_selection(mem, ci);
466   char title[256];
467   const memory_subview_item *subview;
468
469   // update the subview
470   memory_view_set_subview(mem->memory, sel);
471
472   // change the checkmarks in the menu
473   memorywin_update_checks(mem);
474
475   // update the window title
476   subview = memory_view_get_current_subview(mem->memory);
477   sprintf(title, "Memory: %s", subview->name);
478   gtk_window_set_title(GTK_WINDOW(mem->win), title);
479
502480}
503481
504482static void memorywin_process_string(running_machine *machine, const char *str, void *memp)
505483{
506484   memorywin_i *mem = memp;
507   debug_view_set_property_string(mem->memory, DVP_MEM_EXPRESSION, str);
485   memory_view_set_expression(mem->memory, str);
508486}
509487
510488static void memorywin_destroy(GtkObject *obj, gpointer user_data)
r3755r3756
521499   free(mem);
522500}
523501
502static void memorywin_view_update(debug_view *view, void *osdprivate)
503{
504   memorywin_i *mem = (memorywin_i *)osdprivate;
505   debug_view_xy size;
506
507   size = debug_view_get_total_size(mem->memory);
508   if ((mem->memory_w->tr != size.y) || (mem->memory_w->tc != size.x))
509   {
510      gtk_widget_queue_resize(GTK_WIDGET(mem->memory_w));
511   }
512   else
513   {
514      gtk_widget_queue_draw(GTK_WIDGET(mem->memory_w));
515   }
516}
517
524518static void memorywin_new(running_machine *machine)
525519{
526520   memorywin_i *mem;
527   int item, cursel, curcpu = cpunum_get_active();
528   memorycombo_item *ci, *selci = NULL;
521   int item, cursel;
522   const device_config *curcpu = debug_cpu_get_visible_cpu(machine);
523   const memory_subview_item *subview;
529524
530525   mem = malloc(sizeof(*mem));
531526   memset(mem, 0, sizeof(*mem));
r3755r3756
537532   mem->memory_w = DVIEW(lookup_widget(mem->win, "memoryview"));
538533   mem->zone_w   = GTK_COMBO_BOX(lookup_widget(mem->win, "zone"));
539534
540   mem->memory = debug_view_alloc(machine, DVT_MEMORY);
535   mem->memory = debug_view_alloc(machine, DVT_MEMORY, memorywin_view_update, mem);
541536
542537   dview_set_debug_view(mem->memory_w, mem->memory);
543538
544539   edit_init(machine, &mem->ed, lookup_widget(mem->win, "edit"), "0", 1, memorywin_process_string, mem);
545540
546541   debug_view_begin_update(mem->memory);
547   debug_view_set_property_string(mem->memory, DVP_MEM_EXPRESSION, "0");
548   debug_view_set_property_UINT32(mem->memory, DVP_MEM_TRACK_LIVE, 1);
542   memory_view_set_expression(mem->memory, "0");
543//   debug_view_set_property_UINT32(mem->memory, DVP_MEM_TRACK_LIVE, 1);
549544   debug_view_end_update(mem->memory);
550545
551546
552547   // populate the combobox
553548   if (!memorycombo)
554      memory_determine_combo_items(machine);
555   item = 0;
556   cursel = 0;
557   for (ci = memorycombo; ci; ci = ci->next)
558549   {
559      gtk_combo_box_append_text(mem->zone_w, ci->name);
560      if (ci->base == NULL && ci->cpunum == curcpu && ci->spacenum == ADDRESS_SPACE_PROGRAM)
550      memorycombo_item **tail = &memorycombo;
551
552      cursel = item = 0;
553
554      for (subview = memory_view_get_subview_list(mem->memory); subview != NULL; subview = subview->next)
561555      {
562         cursel = item;
563         selci = ci;
556         memorycombo_item *ci = malloc_or_die(sizeof(*ci));
557         memset(ci, 0, sizeof(*ci));
558         ci->machine = machine;
559         ci->prefsize = 4;
560         ci->subview = subview;
561         ci->device = curcpu;
562
563         strncpy(ci->name, subview->name, sizeof(ci->name));
564     
565         *tail = ci;
566         tail = &ci->next;
567
568         if (cursel == 0 && subview->space != NULL && subview->space->cpu == curcpu)
569            cursel = item;
570
571         item++;
564572      }
565      item++;
566573
574      memory_view_set_subview(mem->memory, cursel);
575      gtk_combo_box_set_active(mem->zone_w, cursel);
567576   }
568   gtk_combo_box_set_active(mem->zone_w, cursel);
569   memorywin_update_selection(mem, selci);
570577
571578   g_signal_connect(mem->zone_w, "changed", G_CALLBACK(memorywin_zone_changed), mem);
572579   g_signal_connect(lookup_widget(mem->win, "chunks_1"), "activate", G_CALLBACK(on_chunks_1_activate), mem);
r3755r3756
582589
583590static void disasmwin_update_checks(disasmwin_i *info)
584591{
585   int rc = debug_view_get_property_UINT32(info->disasm, DVP_DASM_RIGHT_COLUMN);
586   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "raw_opcodes")), rc == DVP_DASM_RIGHTCOL_RAW);
587   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "enc_opcodes")), rc == DVP_DASM_RIGHTCOL_ENCRYPTED);
588   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "comments")), rc == DVP_DASM_RIGHTCOL_COMMENTS);
592   int rc = disasm_view_get_right_column(info->disasm);
593   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "raw_opcodes")), rc == DASM_RIGHTCOL_RAW);
594   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "enc_opcodes")), rc == DASM_RIGHTCOL_ENCRYPTED);
595   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "comments")), rc == DASM_RIGHTCOL_COMMENTS);
589596}
590597
591static void disasmwin_update_selection(disasmwin_i *info, int cpunum)
598static void disasmwin_cpu_changed(GtkComboBox *cpu_w, disasmwin_i *dis)
592599{
593   char title[4096];
594   debug_view_begin_update(info->disasm);
595   debug_view_set_property_UINT32(info->disasm, DVP_DASM_CPUNUM, (cpunum == -1) ? 0 : cpunum);
596   debug_view_end_update(info->disasm);
600   char title[256];
601   const disasm_subview_item *subview;
597602
598   disasmwin_update_checks(info);
603   disasm_view_set_subview(dis->disasm, gtk_combo_box_get_active(dis->cpu_w));
599604
600   sprintf(title, "Disassembly: CPU #%d \"%s\" (%s)", cpunum, info->machine->config->cpu[cpunum].tag, cpu_get_name(info->machine->cpu[cpunum]));
601   gtk_window_set_title(GTK_WINDOW(info->win), title);
602}
605   disasmwin_update_checks(dis);
603606
604static void disasmwin_cpu_changed(GtkComboBox *cpu_w, disasmwin_i *dis)
605{
606   int sel = gtk_combo_box_get_active(dis->cpu_w);
607   int cpunum, item;
608   item = 0;
609   for (cpunum = 0; cpunum < MAX_CPU; cpunum++)
610   {
611      if (dis->machine->cpu[cpunum] != NULL)
612      {
613         const cpu_debug_data *cpuinfo = cpu_get_debug_data(dis->machine->cpu[cpunum]);
614
615         if (cpuinfo->space[ADDRESS_SPACE_PROGRAM].databytes)
616         {
617            if(item == sel) {
618               disasmwin_update_selection(dis, cpunum);
619               return;
620            }
621            item++;
622         }
623      }
624   }
607   subview = disasm_view_get_current_subview(dis->disasm);
608   sprintf(title, "Disassembly: %s", subview->name);
609   gtk_window_set_title(GTK_WINDOW(dis->win), title);
625610}
626611
627612void disasmwin_raw_opcodes_activate(GtkMenuItem *item, gpointer user_data)
r3755r3756
629614   disasmwin_i *info = user_data;
630615   if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "raw_opcodes")))) {
631616      debug_view_begin_update(info->disasm);
632      debug_view_set_property_UINT32(info->disasm, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_RAW);
617      disasm_view_set_right_column(info->disasm, DASM_RIGHTCOL_RAW);
633618      debug_view_end_update(info->disasm);
634619   }
635620}
r3755r3756
639624   disasmwin_i *info = user_data;
640625   if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "enc_opcodes")))) {
641626      debug_view_begin_update(info->disasm);
642      debug_view_set_property_UINT32(info->disasm, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_ENCRYPTED);
627      disasm_view_set_right_column(info->disasm, DASM_RIGHTCOL_ENCRYPTED);
643628      debug_view_end_update(info->disasm);
644629   }
645630}
r3755r3756
649634   disasmwin_i *info = user_data;
650635   if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "comments")))) {
651636      debug_view_begin_update(info->disasm);
652      debug_view_set_property_UINT32(info->disasm, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_COMMENTS);
637      disasm_view_set_right_column(info->disasm, DASM_RIGHTCOL_COMMENTS);
653638      debug_view_end_update(info->disasm);
654639   }
655640}
r3755r3756
657642static void disasmwin_process_string(running_machine *machine, const char *str, void *disp)
658643{
659644   disasmwin_i *dis = disp;
660   debug_view_set_property_string(dis->disasm, DVP_DASM_EXPRESSION, str);
645   disasm_view_set_expression(dis->disasm, str);
661646}
662647
663648static void disasmwin_destroy(GtkObject *obj, gpointer user_data)
r3755r3756
674659   free(dis);
675660}
676661
662static void disasmwin_view_update(debug_view *view, void *osdprivate)
663{
664   disasmwin_i *dis = (disasmwin_i *)osdprivate;
665   debug_view_xy size;
666
667   size = debug_view_get_total_size(dis->disasm);
668   if ((dis->disasm_w->tr != size.y) || (dis->disasm_w->tc != size.x))
669   {
670      gtk_widget_queue_resize(GTK_WIDGET(dis->disasm_w));
671   }
672   else
673   {
674      gtk_widget_queue_draw(GTK_WIDGET(dis->disasm_w));
675   }
676}
677
677678static void disasmwin_new(running_machine *machine)
678679{
679680   disasmwin_i *dis;
680   int cpunum, curcpu = cpunum_get_active();
681   int item, citem;
681   int item, cursel;
682   const device_config *curcpu = debug_cpu_get_visible_cpu(machine);
683   const disasm_subview_item *subview;
684   char title[256];
682685
683686   dis = malloc(sizeof(*dis));
684687   memset(dis, 0, sizeof(*dis));
r3755r3756
690693   dis->disasm_w = DVIEW(lookup_widget(dis->win, "disasmview"));
691694   dis->cpu_w    = GTK_COMBO_BOX(lookup_widget(dis->win, "cpu"));
692695
693   dis->disasm = debug_view_alloc(machine, DVT_DISASSEMBLY);
696   dis->disasm = debug_view_alloc(machine, DVT_DISASSEMBLY, disasmwin_view_update, dmain);
694697
695698   dview_set_debug_view(dis->disasm_w, dis->disasm);
696699
697700   edit_init(machine, &dis->ed, lookup_widget(dis->win, "edit"), "curpc", 1, disasmwin_process_string, dis);
698701
699702   debug_view_begin_update(dis->disasm);
700   debug_view_set_property_string(dis->disasm, DVP_DASM_EXPRESSION, "curpc");
701   debug_view_set_property_UINT32(dis->disasm, DVP_DASM_TRACK_LIVE, 1);
703   disasm_view_set_expression(dis->disasm, "curpc");
704//   debug_view_set_property_UINT32(dis->disasm, DVP_DASM_TRACK_LIVE, 1);
702705   debug_view_end_update(dis->disasm);
703706
704707   // populate the combobox
705   item = 0;
706   citem = -1;
707   for (cpunum = 0; cpunum < MAX_CPU; cpunum++)
708   cursel = item = 0;
709   for (subview = disasm_view_get_subview_list(dis->disasm); subview != NULL; subview = subview->next)
708710   {
709      if (machine->cpu[cpunum] != NULL)
710      {
711         const cpu_debug_data *cpuinfo = cpu_get_debug_data(machine->cpu[cpunum]);
712         if (cpuinfo->space[ADDRESS_SPACE_PROGRAM].databytes)
713         {
714            char name[100];
715            sprintf(name, "CPU #%d \"%s\" (%s)", cpunum, machine->config->cpu[cpunum].tag, cpu_get_name(machine->cpu[cpunum]));
716            gtk_combo_box_append_text(dis->cpu_w, name);
717            if(cpunum == curcpu)
718               citem = item;
719            item++;
720         }
721      }
722   }
711      gtk_combo_box_append_text(dis->cpu_w, subview->name);
712      if (cursel == 0 && subview->space->cpu == curcpu)
713         cursel = item;
723714
724   if(citem == -1) {
725      citem = 0;
726      curcpu = 0;
715      item++;
727716   }
728717
729   gtk_combo_box_set_active(dis->cpu_w, citem);
730   disasmwin_update_selection(dis, curcpu);
718   gtk_combo_box_set_active(dis->cpu_w, cursel);
719   disasm_view_set_subview(dis->disasm, cursel);
731720
721   subview = disasm_view_get_current_subview(dis->disasm);
722   sprintf(title, "Disassembly: %s", subview->name);
723   gtk_window_set_title(GTK_WINDOW(dis->win), title);
724
732725   g_signal_connect(dis->cpu_w, "changed", G_CALLBACK(disasmwin_cpu_changed), dis);
733726   g_signal_connect(lookup_widget(dis->win, "raw_opcodes"), "activate", G_CALLBACK(disasmwin_raw_opcodes_activate), dis);
734727   g_signal_connect(lookup_widget(dis->win, "enc_opcodes"), "activate", G_CALLBACK(disasmwin_enc_opcodes_activate), dis);
r3755r3756
752745   free(log);
753746}
754747
748static void logwin_view_update(debug_view *view, void *osdprivate)
749{
750   logwin_i *log = (logwin_i *)osdprivate;
751   debug_view_xy size;
752
753   size = debug_view_get_total_size(log->log);
754   if ((log->log_w->tr != size.y) || (log->log_w->tc != size.x))
755   {
756      gtk_widget_queue_resize(GTK_WIDGET(log->log_w));
757   }
758   else
759   {
760      gtk_widget_queue_draw(GTK_WIDGET(log->log_w));
761   }
762}
763
755764static void logwin_new(running_machine *machine)
756765{
757766   logwin_i *log;
r3755r3756
765774
766775   log->log_w = DVIEW(lookup_widget(log->win, "logview"));
767776
768   log->log = debug_view_alloc(machine, DVT_LOG);
777   log->log = debug_view_alloc(machine, DVT_LOG, logwin_view_update, dmain);
769778
779   dview_set_debug_view(log->log_w, log->log);
780
770781   dview_this_one_is_stupidly_autoscrolling(log->log_w);
771   dview_set_debug_view(log->log_w, log->log);
772782   g_signal_connect(log->win, "destroy", G_CALLBACK(logwin_destroy), log);
773783
774784   gtk_widget_show_all(log->win);
r3755r3756
851861   memorywin_i *info = user_data;
852862   if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "chunks_1")))) {
853863      debug_view_begin_update(info->memory);
854      debug_view_set_property_UINT32(info->memory, DVP_MEM_BYTES_PER_CHUNK, 1);
864      memory_view_set_bytes_per_chunk(info->memory, 1);
855865      debug_view_end_update(info->memory);
856866   }
857867}
r3755r3756
861871   memorywin_i *info = user_data;
862872   if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "chunks_2")))) {
863873      debug_view_begin_update(info->memory);
864      debug_view_set_property_UINT32(info->memory, DVP_MEM_BYTES_PER_CHUNK, 2);
874      memory_view_set_bytes_per_chunk(info->memory, 2);
865875      debug_view_end_update(info->memory);
866876   }
867877}
r3755r3756
871881   memorywin_i *info = user_data;
872882   if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "chunks_4")))) {
873883      debug_view_begin_update(info->memory);
874      debug_view_set_property_UINT32(info->memory, DVP_MEM_BYTES_PER_CHUNK, 4);
884      memory_view_set_bytes_per_chunk(info->memory, 4);
875885      debug_view_end_update(info->memory);
876886   }
877887}
r3755r3756
880890{
881891   memorywin_i *info = user_data;
882892   debug_view_begin_update(info->memory);
883   debug_view_set_property_UINT32(info->memory, DVP_MEM_REVERSE_VIEW,
884                           gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "reverse"))));
893   memory_view_set_reverse(info->memory, gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(lookup_widget(info->win, "reverse"))));
894                           
885895   debug_view_end_update(info->memory);
886896}
887897
r3755r3756
889899{
890900   memorywin_i *info = user_data;
891901   debug_view_begin_update(info->memory);
892   debug_view_set_property_UINT32(info->memory, DVP_MEM_WIDTH,
893                           debug_view_get_property_UINT32(info->memory, DVP_MEM_WIDTH) + 1);
902   memory_view_set_chunks_per_row(info->memory, memory_view_get_chunks_per_row(info->memory) + 1);
894903   debug_view_end_update(info->memory);
895904}
896905
r3755r3756
898907{
899908   memorywin_i *info = user_data;
900909   debug_view_begin_update(info->memory);
901   debug_view_set_property_UINT32(info->memory, DVP_MEM_WIDTH,
902                           debug_view_get_property_UINT32(info->memory, DVP_MEM_WIDTH) - 1);
910   memory_view_set_chunks_per_row(info->memory, memory_view_get_chunks_per_row(info->memory) - 1);
903911   debug_view_end_update(info->memory);
904912}
905913
src/osd/sdl/debugosx.c
r3755r3756
1010// NOTES:
1111//
1212// debug_window_proc is called for events on the debugger windows: Must install carbon handler on it
13// debug_view_proc is called for events on the debugger controls: Must install carbon handler on it
13// debugwin_view_proc is called for events on the debugger controls: Must install carbon handler on it
1414//
1515
1616
r3755r3756
198198};
199199
200200
201typedef struct _memorycombo_item memorycombo_item;
202struct _memorycombo_item
203{
204   memorycombo_item *      next;
205   char               name[256];
206   UINT8               cpunum;
207   UINT8               spacenum;
208   void *               base;
209   UINT32               length;
210   UINT8               offset_xor;
211   UINT8               little_endian;
212   UINT8               prefsize;
213};
214
215
216201//============================================================
217202//  GLOBAL VARIABLES
218203//============================================================
r3755r3756
226211static debugwin_info *window_list;
227212static debugwin_info *main_console = NULL;
228213
229static memorycombo_item *memorycombo;
230
231214static UINT8 debugger_active_countdown;
232215static UINT8 waiting_for_debugger;
233216
r3755r3756
253236static void debug_window_free(debugwin_info *info);
254237static OSStatus debug_window_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData);
255238
256static void debug_view_draw_contents(debugview_info *view, CGContextRef dc);
239static void debugwin_view_draw_contents(debugview_info *view, CGContextRef dc);
257240static debugview_info *debug_view_find(debug_view *view);
258static OSStatus debug_view_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData);
259static void debug_view_update(debug_view *view);
260static int debug_view_create(debugwin_info *info, int which, int type);
261static void debug_view_process_scroll(HIViewRef inView, ControlPartCode partCode);
241static OSStatus debugwin_view_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData);
242static void debugwin_view_update(debug_view *view, void *osdprivate);
243static int debugwin_view_create(debugwin_info *info, int which, int type);
244static void debugwin_view_process_scroll(HIViewRef inView, ControlPartCode partCode);
262245
263static OSStatus debug_edit_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData);
246static OSStatus debugwin_edit_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData);
264247
265248#if 0
266249static void generic_create_window(int type);
r3755r3756
273256static void memory_update_checkmarks(debugwin_info *info);
274257static int memory_handle_command(debugwin_info *info, EventRef inEvent);
275258static int memory_handle_key(debugwin_info *info, EventRef inEvent);
259static void memory_update_caption(debugwin_info *info);
276260
277261static void disasm_create_window(running_machine *machine);
278262static void disasm_recompute_children(debugwin_info *info);
r3755r3756
285269static void console_create_window(running_machine *machine);
286270static void console_recompute_children(debugwin_info *info);
287271static void console_process_string(debugwin_info *info, const char *string);
288static void console_set_cpunum(running_machine *machine, int cpunum);
272static void console_set_cpu(const device_config *device);
289273
290274static MenuRef create_standard_menubar(void);
291275static int global_handle_command(debugwin_info *info, EventRef inEvent);
r3755r3756
367351//  osd_wait_for_debugger
368352//============================================================
369353
370void osd_wait_for_debugger(running_machine *machine, int firststop)
354void osd_wait_for_debugger(const device_config *device, int firststop)
371355{
372356   EventRef      message;
373357   EventTargetRef   target = GetEventDispatcherTarget();
374358
375   osx_init_debugger(machine);
359   osx_init_debugger(device->machine);
376360
377361   // create a console window
378362   if (!main_console)
379      console_create_window(machine);
363      console_create_window(device->machine);
380364
381365   // update the views in the console to reflect the current CPU
382366   if (main_console)
383      console_set_cpunum(machine, cpunum_get_active());
367      console_set_cpu(device);
384368
385369   // make sure the debug windows are visible
386370   waiting_for_debugger = TRUE;
r3755r3756
503487            focuswnd = NULL;
504488         }
505489         
506         debugger_break(machine);
507         debug_console_printf("User-initiated break\n");
490         debug_cpu_halt_on_next_instruction(debug_cpu_get_visible_cpu(machine), "User-initiated break\n");
508491
509492         // if we were focused on some window's edit box, reset it to default
510493         for (info = window_list; info; info = info->next)
r3755r3756
853836                  {
854837                     if (info->view[curview].wnd == focusChild )
855838                     {
856                        return debug_view_proc( inHandler, inEvent, &info->view[curview] );
839                        return debugwin_view_proc( inHandler, inEvent, &info->view[curview] );
857840                     }
858841                  }
859842               }
r3755r3756
868851
869852
870853//============================================================
871//  debug_view_create
854//  debugwin_view_create
872855//============================================================
873856
874static int debug_view_create(debugwin_info *info, int which, int type)
857static int debugwin_view_create(debugwin_info *info, int which, int type)
875858{
876859   Rect   bounds;
877860   debugview_info *view = &info->view[which];
878   void *callback = (void *)debug_view_update;
879861
880862   // set the owner
881863   view->owner = info;
r3755r3756
887869   if ( CreateUserPaneControl(info->wnd, &bounds, 0, &view->wnd) != noErr )
888870      goto cleanup;
889871   
890   if ( InstallEventHandler( GetControlEventTarget( view->wnd ), NewEventHandlerUPP(debug_view_proc), sizeof( debug_view_events ) / sizeof( EventTypeSpec ), debug_view_events, view, NULL ) != noErr )
872   if ( InstallEventHandler( GetControlEventTarget( view->wnd ), NewEventHandlerUPP(debugwin_view_proc), sizeof( debug_view_events ) / sizeof( EventTypeSpec ), debug_view_events, view, NULL ) != noErr )
891873      goto cleanup;
892874   
893875   // create the scroll bars
894876   bounds.top = bounds.bottom - hscroll_height;
895877   
896   if ( CreateScrollBarControl(info->wnd, &bounds, 0, 0, 0, 0, TRUE, NewControlActionUPP(debug_view_process_scroll), &view->hscroll ) != noErr )
878   if ( CreateScrollBarControl(info->wnd, &bounds, 0, 0, 0, 0, TRUE, NewControlActionUPP(debugwin_view_process_scroll), &view->hscroll ) != noErr )
897879      goto cleanup;
898880   
899881   SetControlProperty(view->hscroll, 'MAME', 'info', sizeof( view ), &view );
r3755r3756
901883   bounds.top = 0;
902884   bounds.left = bounds.right - vscroll_width;
903885   
904   if ( CreateScrollBarControl(info->wnd, &bounds, 0, 0, 0, 0, TRUE, NewControlActionUPP(debug_view_process_scroll), &view->vscroll ) != noErr )
886   if ( CreateScrollBarControl(info->wnd, &bounds, 0, 0, 0, 0, TRUE, NewControlActionUPP(debugwin_view_process_scroll), &view->vscroll ) != noErr )
905887      goto cleanup;
906888   
907889   SetControlProperty(view->vscroll, 'MAME', 'info', sizeof( view ), &view );
908890
909891   // create the debug view
910   view->view = debug_view_alloc(info->machine, type);
892   view->view = debug_view_alloc(info->machine, type, debugwin_view_update, view);
911893   if (!view->view)
912894      goto cleanup;
913895
914   // set the update handler
915   debug_view_set_property_fct(view->view, DVP_UPDATE_CALLBACK, callback);
916896   return 1;
917897
918898cleanup:
r3755r3756
930910
931911
932912//============================================================
933//  debug_view_set_bounds
913//  debugwin_view_set_bounds
934914//============================================================
935915
936static void debug_view_set_bounds(debugview_info *info, const Rect *newbounds)
916static void debugwin_view_set_bounds(debugview_info *info, const Rect *newbounds)
937917{
938918   // account for the edges and set the bounds
939919   if (info->wnd)
r3755r3756
949929   }
950930
951931   // update
952   debug_view_update(info->view);
932   debugwin_view_update(info->view, info);
953933}
954934
955935
956936
957937//============================================================
958//  debug_view_draw_contents
938//  debugwin_view_draw_contents
959939//============================================================
960940
961static void debug_view_draw_contents(debugview_info *view, CGContextRef dc)
941static void debugwin_view_draw_contents(debugview_info *view, CGContextRef dc)
962942{
963   debug_view_char *viewdata;
964   UINT32 visrows, viscols;
943   const debug_view_char *viewdata = debug_view_get_chars(view->view);
944   debug_view_xy visarea = debug_view_get_visible_size(view->view);
965945   UINT32 col, row;
966946   HIRect client;
967947
r3755r3756
970950   // get the client rect
971951   HIViewGetBounds(view->wnd,&client);
972952   
973   // first get the visible size from the view and a pointer to the data
974   visrows = debug_view_get_property_UINT32(view->view, DVP_VISIBLE_ROWS);
975   viscols = debug_view_get_property_UINT32(view->view, DVP_VISIBLE_COLS);
976   viewdata = debug_view_get_property_ptr(view->view, DVP_VIEW_DATA);
977
978953   if (!viewdata) return;
979954
980955   // set the font
r3755r3756
991966   }
992967
993968   // iterate over rows and columns
994   for (row = 0; row < visrows; row++)
969   for (row = 0; row < visarea.y; row++)
995970   {
996971      int iter;
997972
r3755r3756
1011986         bounds.bottom = bounds.top + debug_font_height;
1012987
1013988         // iterate over columns
1014         for (col = 0; col < viscols; col++)
989         for (col = 0; col < visarea.x; col++)
1015990         {
1016991            // if the attribute changed, adjust the colors
1017992            if (viewdata[col].attrib != last_attrib)
r3755r3756
11051080      }
11061081
11071082      // advance viewdata
1108      viewdata += viscols;
1083      viewdata += visarea.x;
11091084   }
11101085
11111086   // erase anything beyond the bottom with white
11121087   HIViewGetBounds(view->wnd,&client);
1113   client.origin.y = visrows * debug_font_height;
1088   client.origin.y = visarea.y * debug_font_height;
11141089   
11151090   CGContextSetRGBFillColor(dc, 1.0, 1.0, 1.0, 1.0);
11161091   CGContextFillRect(dc, client);
r3755r3756
11201095
11211096
11221097//============================================================
1123//  debug_view_update
1098//  debugwin_view_update
11241099//============================================================
11251100
1126static void debug_view_update(debug_view *view)
1101static void debugwin_view_update(debug_view *view, void *osdprivate)
11271102{
11281103   debugview_info *info = debug_view_find(view);
11291104
r3755r3756
11311106   if (info && info->view)
11321107   {
11331108      HIRect bounds, vscroll_bounds, hscroll_bounds;
1109      debug_view_xy totalsize, visiblesize, topleft;
11341110      int show_vscroll, show_hscroll;
1135      UINT32 visible_rows, visible_cols;
1136      UINT32 total_rows, total_cols;
1137      UINT32 top_row, left_col;
11381111
11391112      // get the view window bounds
11401113      HIViewGetFrame(info->wnd,&bounds);
1141      visible_rows = bounds.size.height / debug_font_height;
1142      visible_cols = bounds.size.width / debug_font_width;
1114      visiblesize.x = bounds.size.width / debug_font_width;
1115      visiblesize.y = bounds.size.height / debug_font_height;
11431116
11441117      // get the updated total rows/cols and left row/col
1145      total_rows = debug_view_get_property_UINT32(view, DVP_TOTAL_ROWS);
1146      total_cols = debug_view_get_property_UINT32(view, DVP_TOTAL_COLS);
1147      top_row = debug_view_get_property_UINT32(view, DVP_TOP_ROW);
1148      left_col = debug_view_get_property_UINT32(view, DVP_LEFT_COL);
1118      totalsize = debug_view_get_total_size(view);
1119      topleft = debug_view_get_visible_position(view);
11491120
11501121      // determine if we need to show the scrollbars
11511122      show_vscroll = show_hscroll = 0;
1152      if (total_rows > visible_rows)
1123      if (totalsize.x > visiblesize.x)
11531124      {
1154         bounds.size.width -= vscroll_width;
1155         visible_cols = bounds.size.width / debug_font_width;
1156         show_vscroll = TRUE;
1157      }
1158      if (total_cols > visible_cols)
1159      {
11601125         bounds.size.height -= hscroll_height;
1161         visible_rows = bounds.size.height / debug_font_height;
1126         visiblesize.y = bounds.size.height / debug_font_height;
11621127         show_hscroll = TRUE;
11631128      }
1164      if (!show_vscroll && total_rows > visible_rows)
1129      if (totalsize.y > visiblesize.y)
11651130      {
11661131         bounds.size.width -= vscroll_width;
1167         visible_cols = bounds.size.width / debug_font_width;
1132         visiblesize.x = bounds.size.width / debug_font_width;
11681133         show_vscroll = TRUE;
11691134      }
1135      if (!show_vscroll && totalsize.y > visiblesize.y)
1136      {
1137         bounds.size.width -= vscroll_width;
1138         visiblesize.x = bounds.size.width / debug_font_width;
1139         show_vscroll = TRUE;
1140      }
11701141     
11711142      // compute the bounds of the scrollbars
11721143      vscroll_bounds = bounds;
r3755r3756
11781149      hscroll_bounds.size.height = hscroll_height;
11791150
11801151      // if we hid the scrollbars, make sure we reset the top/left corners
1181      if (top_row + visible_rows > total_rows)
1182         top_row = (total_rows > visible_rows) ? (total_rows - visible_rows) : 0;
1183      if (left_col + visible_cols > total_cols)
1184         left_col = (total_cols > visible_cols) ? (total_cols - visible_cols) : 0;
1152      if (topleft.y + visiblesize.y > totalsize.y)
1153         topleft.y = MAX(totalsize.y - visiblesize.y, 0);
1154      if (topleft.x + visiblesize.x > totalsize.x)
1155         topleft.x = MAX(totalsize.x - visiblesize.x, 0);
11851156
11861157      // fill out the scroll info struct for the vertical scrollbar
11871158      if ( show_vscroll )
11881159      {
11891160#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
11901161         HIViewSetMinimum(info->vscroll,0);
1191         HIViewSetMaximum(info->vscroll,total_rows-visible_rows);
1192         HIViewSetValue(info->vscroll,top_row);
1193         HIViewSetViewSize(info->vscroll,visible_rows);
1162         HIViewSetMaximum(info->vscroll,totalsize.y-visiblesize.y);
1163         HIViewSetValue(info->vscroll,topleft.y);
1164         HIViewSetViewSize(info->vscroll,visiblesize.y);
11941165#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
11951166         SetControl32BitMinimum(info->vscroll,0);
1196         SetControl32BitMaximum(info->vscroll,total_rows-visible_rows);
1197         SetControl32BitValue(info->vscroll,top_row);
1167         SetControl32BitMaximum(info->vscroll,totalsize.y-visiblesize.y);
1168         SetControl32BitValue(info->vscroll,topleft.y);
11981169#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
11991170      }
12001171     
r3755r3756
12031174      {
12041175#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
12051176         HIViewSetMinimum(info->hscroll,0);
1206         HIViewSetMaximum(info->hscroll,total_cols-visible_cols);
1207         HIViewSetValue(info->hscroll,left_col);
1208         HIViewSetViewSize(info->hscroll,visible_cols);
1177         HIViewSetMaximum(info->hscroll,totalsize.x-visiblesize.x);
1178         HIViewSetValue(info->hscroll,topleft.x);
1179         HIViewSetViewSize(info->hscroll,visiblesize.x);
12091180#else // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
12101181         SetControl32BitMinimum(info->hscroll,0);
1211         SetControl32BitMaximum(info->hscroll,total_cols-visible_cols);
1212         SetControl32BitValue(info->hscroll,left_col);
1182         SetControl32BitMaximum(info->hscroll,totalsize.x-visiblesize.x);
1183         SetControl32BitValue(info->hscroll,topleft.x);
12131184#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
12141185      }
12151186
12161187      // update window info
1217      visible_rows++;
1218      visible_cols++;
1219      debug_view_set_property_UINT32(view, DVP_VISIBLE_ROWS, visible_rows);
1220      debug_view_set_property_UINT32(view, DVP_VISIBLE_COLS, visible_cols);
1221      debug_view_set_property_UINT32(view, DVP_TOP_ROW, top_row);
1222      debug_view_set_property_UINT32(view, DVP_LEFT_COL, left_col);
1188      visiblesize.y++;
1189      visiblesize.x++;
1190      debug_view_set_visible_size(view, visiblesize);
1191      debug_view_set_visible_position(view, topleft);
12231192
12241193      // invalidate the bounds
12251194      HIViewSetNeedsDisplay(info->wnd, TRUE);
r3755r3756
12821251}
12831252
12841253//============================================================
1285//  debug_view_process_scroll
1254//  debugwin_view_process_scroll
12861255//============================================================
12871256
1288static void debug_view_process_scroll(HIViewRef inView, ControlPartCode partCode)
1257static void debugwin_view_process_scroll(HIViewRef inView, ControlPartCode partCode)
12891258{
12901259   debugview_info *info;
12911260   INT32      result;
r3755r3756
13211290     
13221291      case kAppearancePartPageUpArea:
13231292         if ( isHorz )
1324            result -= debug_view_get_property_UINT32(info->view, DVP_VISIBLE_COLS);
1293            result -= debug_view_get_visible_size(info->view).x;
13251294         else
1326            result -= debug_view_get_property_UINT32(info->view, DVP_VISIBLE_ROWS);
1295            result -= debug_view_get_visible_size(info->view).y;
13271296      break;
13281297     
13291298      case kAppearancePartPageDownArea:
13301299         if ( isHorz )
1331            result += debug_view_get_property_UINT32(info->view, DVP_VISIBLE_COLS);
1300            result += debug_view_get_visible_size(info->view).x;
13321301         else
1333            result += debug_view_get_property_UINT32(info->view, DVP_VISIBLE_ROWS);
1302            result += debug_view_get_visible_size(info->view).y;
13341303      break;
13351304   }
13361305   
r3755r3756
13411310   
13421311   if ( isHorz )
13431312   {
1344      debug_view_set_property_UINT32(info->view, DVP_LEFT_COL, result);
1313      debug_view_xy topleft = debug_view_get_visible_position(info->view);
1314      topleft.x = result;
1315      debug_view_set_visible_position(info->view, topleft);
13451316   }
13461317   else
13471318   {
1348      if (info->is_textbuf)
1319//      if (info->is_textbuf)
1320//      {
1321//         if( result == maxval )
1322//              result = -1;
1323//           debug_view_set_property_UINT32(info->view, DVP_TEXTBUF_LINE_LOCK, result);
1324//      }
1325//      else
13491326      {
1350         if( result == maxval )
1351              result = -1;
1352           debug_view_set_property_UINT32(info->view, DVP_TEXTBUF_LINE_LOCK, result);
1327         debug_view_xy topleft = debug_view_get_visible_position(info->view);
1328         topleft.y = result;
1329         debug_view_set_visible_position(info->view, topleft);
13531330      }
1354      else
1355         debug_view_set_property_UINT32(info->view, DVP_TOP_ROW, result);
13561331   }
13571332}
13581333
13591334
13601335//============================================================
1361//  debug_view_prev_view
1336//  debugwin_view_prev_view
13621337//============================================================
13631338
1364static void debug_view_prev_view(debugwin_info *info, debugview_info *curview)
1339static void debugwin_view_prev_view(debugwin_info *info, debugview_info *curview)
13651340{
13661341   int curindex = 1;
13671342   int numviews;
r3755r3756
13911366      }
13921367
13931368      // positive numbers mean a view
1394      else if (curindex >= 0 && info->view[curindex].wnd != NULL && debug_view_get_property_UINT32(info->view[curindex].view, DVP_SUPPORTS_CURSOR))
1369      else if (curindex >= 0 && info->view[curindex].wnd != NULL && debug_view_get_cursor_supported(info->view[curindex].view))
13951370      {
13961371         osx_SetFocus(info->view[curindex].wnd);
13971372         break;
r3755r3756
14021377
14031378
14041379//============================================================
1405//  debug_view_next_view
1380//  debugwin_view_next_view
14061381//============================================================
14071382
1408static void debug_view_next_view(debugwin_info *info, debugview_info *curview)
1383static void debugwin_view_next_view(debugwin_info *info, debugview_info *curview)
14091384{
14101385   int curindex = -1;
14111386   int numviews;
r3755r3756
14351410      }
14361411
14371412      // positive numbers mean a view
1438      else if (curindex >= 0 && info->view[curindex].wnd != NULL && debug_view_get_property_UINT32(info->view[curindex].view, DVP_SUPPORTS_CURSOR))
1413      else if (curindex >= 0 && info->view[curindex].wnd != NULL && debug_view_get_cursor_supported(info->view[curindex].view))
14391414      {
14401415         osx_SetFocus(info->view[curindex].wnd);
14411416         HIViewSetNeedsDisplay(info->view[curindex].wnd, TRUE);
r3755r3756
14471422
14481423
14491424//============================================================
1450//  debug_view_proc
1425//  debugwin_view_proc
14511426//============================================================
14521427
1453static OSStatus debug_view_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData)
1428static OSStatus debugwin_view_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData)
14541429{
14551430   debugview_info *info = (debugview_info *)inUserData;
14561431   UInt32         eventClass = GetEventClass( inEvent );
r3755r3756
14711446               exit( -1 );
14721447            }
14731448         
1474            debug_view_draw_contents(info, dc);
1449            debugwin_view_draw_contents(info, dc);
14751450            return noErr;
14761451         }
14771452         break;
r3755r3756
14851460            {
14861461               if ( part == kControlFocusNoPart )   // losing focus
14871462               {
1488                  if (debug_view_get_property_UINT32(info->view, DVP_SUPPORTS_CURSOR))
1489                     debug_view_set_property_UINT32(info->view, DVP_CURSOR_VISIBLE, 0);
1463                  if (debug_view_get_cursor_supported(info->view))
1464                     debug_view_set_cursor_visible(info->view, FALSE);
14901465               }
14911466               else // gaining focus
14921467               {
1493                  if (debug_view_get_property_UINT32(info->view, DVP_SUPPORTS_CURSOR))
1494                     debug_view_set_property_UINT32(info->view, DVP_CURSOR_VISIBLE, 1);
1495           
1468                  if (debug_view_get_cursor_supported(info->view))
1469                     debug_view_set_cursor_visible(info->view, TRUE);
1470
14961471                  part = kControlLabelPart;
14971472                  SetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, sizeof(part), &part );
14981473               }
r3755r3756
15181493               {
15191494                  if ( button == kEventMouseButtonPrimary )
15201495                  {
1521                     int x = viewPos.x / debug_font_width;
1522                     int y = viewPos.y / debug_font_height;
1523                     debug_view_begin_update(info->view);
1524                     debug_view_set_property_UINT32(info->view, DVP_CURSOR_ROW, debug_view_get_property_UINT32(info->view, DVP_TOP_ROW) + y);
1525                     debug_view_set_property_UINT32(info->view, DVP_CURSOR_COL, debug_view_get_property_UINT32(info->view, DVP_LEFT_COL) + x);
1526                     debug_view_end_update(info->view);
1527                     osx_SetFocus(info->wnd);
1496                     if (debug_view_get_cursor_supported(info->view))
1497                     {
1498//                        debug_view_xy topleft = debug_view_get_visible_position(info->view);
1499                        debug_view_xy newpos;
1500                        newpos.x = viewPos.x / debug_font_width;
1501                        newpos.y = viewPos.y / debug_font_height;
1502                        debug_view_set_cursor_position(info->view, newpos);
1503                        osx_SetFocus(info->wnd);
1504                     }
15281505                     return noErr;
15291506                  }
15301507               }
r3755r3756
15931570           
15941571            if ( axis == kEventMouseWheelAxisX && info->hscroll )
15951572            {
1596               debug_view_set_property_UINT32(info->view, DVP_LEFT_COL, result);
1573               debug_view_xy topleft = debug_view_get_visible_position(info->view);
1574               topleft.x = result;
1575               debug_view_set_visible_position(info->view, topleft);
15971576            }
15981577            else if ( axis == kEventMouseWheelAxisY && info->vscroll != NULL )
15991578            {
1600               if (info->is_textbuf)
1601                  debug_view_set_property_UINT32(info->view, DVP_TEXTBUF_LINE_LOCK, result);
1602               else
1603                  debug_view_set_property_UINT32(info->view, DVP_TOP_ROW, result);
1579//               if (info->is_textbuf)
1580//                  debug_view_set_property_UINT32(info->view, DVP_TEXTBUF_LINE_LOCK, result);
1581//               else
1582               {
1583                  debug_view_xy topleft = debug_view_get_visible_position(info->view);
1584                  topleft.y = result;
1585                  debug_view_set_visible_position(info->view, topleft);
1586               }
16041587            }
16051588         }
16061589      }
r3755r3756
16151598         {
16161599            case kUpArrowCharCode:
16171600            {
1618               debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_UP);
1601               debug_view_type_character(info->view, DCH_UP);
16191602               return noErr;
16201603            }
16211604            break;
16221605           
16231606            case kDownArrowCharCode:
16241607            {
1625               debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_DOWN);
1608               debug_view_type_character(info->view, DCH_DOWN);
16261609               return noErr;
16271610            }
16281611            break;
r3755r3756
16301613            case kLeftArrowCharCode:
16311614            {
16321615               if ( event.modifiers & cmdKey )
1633                  debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_CTRLLEFT);
1616                  debug_view_type_character(info->view, DCH_CTRLLEFT);
16341617               else
1635                  debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_LEFT);
1618                  debug_view_type_character(info->view, DCH_LEFT);
16361619               
16371620               return noErr;
16381621            }
r3755r3756
16411624            case kRightArrowCharCode:
16421625            {
16431626               if ( event.modifiers & cmdKey )
1644                  debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_CTRLRIGHT);
1627                  debug_view_type_character(info->view, DCH_CTRLRIGHT);
16451628               else
1646                  debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_RIGHT);
1629                  debug_view_type_character(info->view, DCH_RIGHT);
16471630               
16481631               return noErr;
16491632            }
r3755r3756
16511634           
16521635            case kPageUpCharCode:
16531636            {
1654               debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_PUP);
1637               debug_view_type_character(info->view, DCH_PUP);
16551638               return noErr;
16561639            }
16571640            break;
16581641           
16591642            case kPageDownCharCode:
16601643            {
1661               debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_PDOWN);
1644               debug_view_type_character(info->view, DCH_PDOWN);
16621645               return noErr;
16631646            }
16641647            break;
r3755r3756
16661649            case kHomeCharCode:
16671650            {
16681651               if ( event.modifiers & cmdKey )
1669                  debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_CTRLHOME);
1652                  debug_view_type_character(info->view, DCH_CTRLHOME);
16701653               else
1671                  debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_HOME);
1654                  debug_view_type_character(info->view, DCH_HOME);
16721655               
16731656               return noErr;
16741657            }
r3755r3756
16771660            case kEndCharCode:
16781661            {
16791662               if ( event.modifiers & cmdKey )
1680                  debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_CTRLEND);
1663                  debug_view_type_character(info->view, DCH_CTRLEND);
16811664               else
1682                  debug_view_set_property_UINT32(info->view, DVP_CHARACTER, DCH_END);
1665                  debug_view_type_character(info->view, DCH_END);
16831666               
16841667               return noErr;
16851668            }
r3755r3756
16961679            case kTabCharCode:
16971680            {
16981681               if ( event.modifiers & shiftKey )
1699                  debug_view_prev_view(info->owner, info);
1682                  debugwin_view_prev_view(info->owner, info);
17001683               else
1701                  debug_view_next_view(info->owner, info);
1684                  debugwin_view_next_view(info->owner, info);
17021685               return noErr;
17031686            }
17041687            break;
r3755r3756
17071690            {
17081691               char   code = event.message & charCodeMask;
17091692               
1710               if (code >= 32 && code < 127 && debug_view_get_property_UINT32(info->view, DVP_SUPPORTS_CURSOR))
1693               if (code >= 32 && code < 127 && debug_view_get_cursor_supported(info->view))
17111694               {
1712                  debug_view_set_property_UINT32(info->view, DVP_CHARACTER, code);
1695                  debug_view_type_character(info->view, code);
17131696                  return noErr;
17141697               }
17151698            }
r3755r3756
17241707
17251708
17261709//============================================================
1727//  debug_edit_proc
1710//  debugwin_edit_proc
17281711//============================================================
17291712
1730static OSStatus debug_edit_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData)
1713static OSStatus debugwin_edit_proc(EventHandlerCallRef inHandler, EventRef inEvent, void * inUserData)
17311714{
17321715   debugwin_info *info = (debugwin_info *)inUserData;
17331716   char buffer[MAX_EDIT_STRING];
r3755r3756
17841767            case kTabCharCode:
17851768            {
17861769               if (event.modifiers & shiftKey)
1787                  debug_view_prev_view(info, NULL);
1770                  debugwin_view_prev_view(info, NULL);
17881771               else
1789                  debug_view_next_view(info, NULL);
1772                  debugwin_view_next_view(info, NULL);
17901773               
17911774               return noErr;
17921775            }
r3755r3756
18461829
18471830static void generic_recompute_children(debugwin_info *info)
18481831{
1832   debug_view_xy totalsize = debug_view_get_total_size(info->view[0].view);
18491833   Rect parent;
18501834   Rect bounds;
18511835   HIRect   hibounds;
1852   UINT32 width;
18531836
1854   // get the view width
1855   width = debug_view_get_property_UINT32(info->view[0].view, DVP_TOTAL_COLS);
1856
18571837   // compute a client rect
18581838   bounds.top = bounds.left = 0;
1859   bounds.right = width * debug_font_width + vscroll_width + 2 * EDGE_WIDTH;
1839   bounds.right = totalsize.x * debug_font_width + vscroll_width + 2 * EDGE_WIDTH;
18601840   bounds.bottom = 200;
18611841//   AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX);
18621842
r3755r3756
18741854   parent.top += EDGE_WIDTH; parent.left += EDGE_WIDTH;
18751855   parent.bottom -= EDGE_WIDTH; parent.right -= EDGE_WIDTH;
18761856   
1877   debug_view_set_bounds(&info->view[0], &parent);
1857   debugwin_view_set_bounds(&info->view[0], &parent);
18781858}
18791859
18801860
r3755r3756
18851865
18861866static void log_create_window(running_machine *machine)
18871867{
1868   debug_view_xy totalsize;
18881869   debugwin_info *info;
18891870   char title[256];
18901871   UINT32 width, height;
r3755r3756
18931874   // create the window
18941875   snprintf(title, ARRAY_LENGTH(title), "Errorlog: %s [%s]", machine->gamedrv->description, machine->gamedrv->name);
18951876   info = debug_window_create(machine, title, NULL);
1896   if (!info || !debug_view_create(info, 0, DVT_LOG))
1877   if (info == NULL || !debugwin_view_create(info, 0, DVT_LOG))
18971878      return;
1898   info->view->is_textbuf = TRUE;
18991879
19001880   // set the child function
19011881   info->recompute_children = generic_recompute_children;
19021882
19031883   // get the view width
1904   width = debug_view_get_property_UINT32(info->view[0].view, DVP_TOTAL_COLS);
1884   totalsize = debug_view_get_total_size(info->view[0].view);
19051885
19061886   // compute a client rect
19071887   bounds.top = bounds.left = 0;
1908   bounds.right = width * debug_font_width + vscroll_width + 2 * EDGE_WIDTH;
1888   bounds.right = totalsize.x * debug_font_width + vscroll_width + 2 * EDGE_WIDTH;
19091889   bounds.bottom = 200;
19101890//   AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX);
19111891
r3755r3756
19311911
19321912
19331913//============================================================
1934//  memory_determine_combo_items
1935//============================================================
1936
1937static void memory_determine_combo_items(running_machine *machine)
1938{
1939   memorycombo_item **tail = &memorycombo;
1940   UINT32 cpunum, spacenum;
1941   const char *rgntag;
1942   int itemnum;
1943
1944   // first add all the CPUs' address spaces
1945   for (cpunum = 0; cpunum < MAX_CPU; cpunum++)
1946   {
1947      if (machine->cpu[cpunum] != NULL)
1948      {
1949                const cpu_debug_data *cpuinfo = cpu_get_debug_data(machine->cpu[cpunum]);
1950         for (spacenum = 0; spacenum < ADDRESS_SPACES; spacenum++)
1951         {
1952            if (cpuinfo->space[spacenum].databytes)
1953            {
1954               memorycombo_item *ci = malloc_or_die(sizeof(*ci));
1955               memset(ci, 0, sizeof(*ci));
1956               ci->cpunum = cpunum;
1957               ci->spacenum = spacenum;
1958               ci->prefsize = MIN(cpuinfo->space[spacenum].databytes, 8);
1959               snprintf(ci->name, ARRAY_LENGTH(ci->name), "CPU #%d \"%s\" (%s) %s memory", cpunum, machine->config->cpu[cpunum].tag, cpu_get_name(machine->cpu[cpunum]), address_space_names[spacenum]);
1960               *tail = ci;
1961               tail = &ci->next;
1962            }
1963         }
1964      }
1965   }
1966
1967   // then add all the memory regions
1968   for (rgntag = memory_region_next(machine, NULL); rgntag != NULL; rgntag = memory_region_next(machine, rgntag))
1969   {
1970      memorycombo_item *ci = malloc_or_die(sizeof(*ci));
1971      UINT32 flags = memory_region_flags(machine, rgntag);
1972      UINT8 little_endian = ((flags & ROMREGION_ENDIANMASK) == ROMREGION_LE);
1973      UINT8 width = 1 << ((flags & ROMREGION_WIDTHMASK) >> 8);
1974
1975      memset(ci, 0, sizeof(*ci));
1976      ci->base = memory_region(machine, rgntag);
1977      ci->length = memory_region_length(machine, rgntag);
1978      ci->prefsize = MIN(width, 8);
1979      ci->offset_xor = width - 1;
1980      ci->little_endian = little_endian;
1981
1982      snprintf(ci->name, ARRAY_LENGTH(ci->name), "Regio \"%s\"", rgntag);
1983
1984      *tail = ci;
1985      tail = &ci->next;
1986   }
1987
1988   // finally add all global array symbols
1989   for (itemnum = 0; itemnum < 10000; itemnum++)
1990   {
1991      UINT32 valsize, valcount;
1992      const char *name;
1993      void *base;
1994
1995      /* stop when we run out of items */
1996      name = state_save_get_indexed_item(itemnum, &base, &valsize, &valcount);
1997      if (name == NULL)
1998         break;
1999
2000      /* if this is a single-entry global, add it */
2001      if (valcount > 1 && strstr(name, "/globals/"))
2002      {
2003         memorycombo_item *ci = malloc_or_die(sizeof(*ci));
2004         memset(ci, 0, sizeof(*ci));
2005         ci->base = base;
2006         ci->length = valcount * valsize;
2007         ci->prefsize = MIN(valsize, 8);
2008         ci->little_endian = TRUE;
2009         strcpy(ci->name, strrchr(name, '/') + 1);
2010         *tail = ci;
2011         tail = &ci->next;
2012      }
2013   }
2014}
2015
2016
2017//============================================================
2018//  memory_update_selection
2019//============================================================
2020
2021static void memory_update_selection(debugwin_info *info, memorycombo_item *ci)
2022{
2023   CFStringRef      title;
2024   
2025   debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_CPUNUM, ci->cpunum);
2026   debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_SPACENUM, ci->spacenum);
2027   debug_view_set_property_ptr(info->view[0].view, DVP_MEM_RAW_BASE, ci->base);
2028   debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_RAW_LENGTH, ci->length);
2029   debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_RAW_OFFSET_XOR, ci->offset_xor);
2030   debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_RAW_LITTLE_ENDIAN, ci->little_endian);
2031   debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK, ci->prefsize);
2032   
2033   title = CFStringCreateWithCString( NULL, ci->name, CFStringGetSystemEncoding() );
2034   
2035   if ( title )
2036   {
2037      SetWindowTitleWithCFString(info->wnd, title);
2038      CFRelease( title );
2039   }
2040}
2041
2042
2043//============================================================
20441914//  memory_create_window
20451915//============================================================
20461916
20471917static void memory_create_window(running_machine *machine)
20481918{
2049   int curcpu = cpunum_get_active(), cursel = 0;
2050   memorycombo_item *ci, *selci = NULL;
1919   const device_config *curcpu = debug_cpu_get_visible_cpu(machine);
1920   const memory_subview_item *subview;
1921   int cursel = -1;
20511922   debugwin_info *info;
20521923   MenuRef optionsmenu,popupmenu;
20531924   Rect   bounds;
r3755r3756
20581929
20591930   // create the window
20601931   info = debug_window_create(machine, "Memory", NULL);
2061   if (!info || !debug_view_create(info, 0, DVT_MEMORY))
1932   if (!info || !debugwin_view_create(info, 0, DVT_MEMORY))
20621933      return;
20631934
20641935   // set the handlers
r3755r3756
21031974   memory_update_checkmarks(info);
21041975
21051976   // set up the view to track the initial expression
2106   debug_view_begin_update(info->view[0].view);
2107   debug_view_set_property_string(info->view[0].view, DVP_MEM_EXPRESSION, "0");
1977   memory_view_set_expression(info->view[0].view, "0");
21081978   strcpy(info->edit_defstr, "0");
2109   debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_TRACK_LIVE, 1);
2110   debug_view_end_update(info->view[0].view);
21111979
21121980   fontName[0] = strlen( OSX_DEBUGGER_FONT_NAME );
21131981   strcpy( (char*)&fontName[1], OSX_DEBUGGER_FONT_NAME );
r3755r3756
21211989   bounds.bottom = bounds.right = 100;
21221990   CreateEditUnicodeTextControl(info->wnd, &bounds, CFSTR("0"), false, NULL, &info->editwnd);
21231991   SetControlFontStyle(info->editwnd,&style);
2124   InstallEventHandler( GetControlEventTarget(info->editwnd), NewEventHandlerUPP(debug_edit_proc), sizeof( debug_keyboard_events ) / sizeof( EventTypeSpec ), debug_keyboard_events, info, NULL );
1992   InstallEventHandler( GetControlEventTarget(info->editwnd), NewEventHandlerUPP(debugwin_edit_proc), sizeof( debug_keyboard_events ) / sizeof( EventTypeSpec ), debug_keyboard_events, info, NULL );
21251993
21261994   // create action menu and attach the contextual menu
21271995   content.contentType = kControlContentTextOnly;
r3755r3756
21482016   }
21492017
21502018   // populate the combobox
2151   if (!memorycombo)
2152      memory_determine_combo_items(machine);
2153   for (ci = memorycombo; ci; ci = ci->next)
2019   for (subview = memory_view_get_subview_list(info->view[0].view); subview != NULL; subview = subview->next)
21542020   {
2155      CFStringRef      cfName = CFStringCreateWithCString( NULL, ci->name, CFStringGetSystemEncoding() );
2021      CFStringRef      cfName = CFStringCreateWithCString( NULL, subview->name, CFStringGetSystemEncoding() );
21562022      UInt16   item;
21572023     
21582024      AppendMenuItemTextWithCFString( popupmenu, cfName, 0, 0, &item );
21592025     
21602026      CFRelease( cfName );
21612027     
2162      if (ci->base == NULL && ci->cpunum == curcpu && ci->spacenum == ADDRESS_SPACE_PROGRAM)
2028      if (cursel == -1 && subview->space != NULL && subview->space->cpu == curcpu)
21632029      {
21642030         cursel = item;
2165         selci = ci;
21662031      }
21672032   }
2033   if (cursel == -1)   cursel = 0;
21682034   
21692035   SetControlData(info->otherwnd[0], kControlEntireControl, kControlPopupButtonOwnedMenuRefTag, sizeof(popupmenu),&popupmenu);
21702036#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
r3755r3756
21812047   info->recompute_children = memory_recompute_children;
21822048   info->process_string = memory_process_string;
21832049
2184   // set the CPUnum and spacenum properties
2185   if (selci == NULL)
2186      selci = memorycombo;
2187   memory_update_selection(info, selci);
2050   // set the caption
2051   memory_update_caption(info);
21882052
21892053   // recompute the children once to get the maxwidth
21902054   memory_recompute_children(info);
r3755r3756
22132077
22142078static void memory_recompute_children(debugwin_info *info)
22152079{
2080   debug_view_xy totalsize = debug_view_get_total_size(info->view[0].view);
22162081   Rect      parent, memrect, editrect, comborect, actionrect;
22172082   Rect      bounds;
22182083   HIRect      hibounds;
2219   UINT32      width;
22202084
2221   // get the view width
2222   width = debug_view_get_property_UINT32(info->view[0].view, DVP_TOTAL_COLS);
2223
22242085   // compute a client rect
22252086   bounds.top = bounds.left = 0;
2226   bounds.right = width * debug_font_width + vscroll_width + 2 * EDGE_WIDTH;
2087   bounds.right = totalsize.x * debug_font_width + vscroll_width + 2 * EDGE_WIDTH;
22272088   bounds.bottom = 200;
22282089//   AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX);
22292090
r3755r3756
22632124   memrect.right = parent.right - EDGE_WIDTH;
22642125
22652126   // set the bounds of things
2266   debug_view_set_bounds(&info->view[0], &memrect);
2127   debugwin_view_set_bounds(&info->view[0], &memrect);
22672128   
22682129   osx_RectToHIRect( &editrect, &hibounds );
22692130   smart_set_view_bounds(info->editwnd, &hibounds);
r3755r3756
22822143static void memory_process_string(debugwin_info *info, const char *string)
22832144{
22842145   // set the string to the memory view
2285   debug_view_set_property_string(info->view[0].view, DVP_MEM_EXPRESSION, string);
2146   memory_view_set_expression(info->view[0].view, string);
22862147
22872148   // select everything in the edit text box
22882149   {
r3755r3756
23112172      MenuItemIndex   menuindex;
23122173     
23132174      GetIndMenuItemWithCommandID( info->contextualMenu, ID_1_BYTE_CHUNKS, 1, NULL, &menuindex );
2314      CheckMenuItem(info->contextualMenu, menuindex, (debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK) == 1));
2175      CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_bytes_per_chunk(info->view[0].view) == 1));
23152176      GetIndMenuItemWithCommandID( info->contextualMenu, ID_2_BYTE_CHUNKS, 1, NULL, &menuindex);
2316      CheckMenuItem(info->contextualMenu, menuindex, (debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK) == 2));
2177      CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_bytes_per_chunk(info->view[0].view) == 2));
23172178      GetIndMenuItemWithCommandID( info->contextualMenu, ID_4_BYTE_CHUNKS, 1, NULL, &menuindex);
2318      CheckMenuItem(info->contextualMenu, menuindex, (debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK) == 4));
2179      CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_bytes_per_chunk(info->view[0].view) == 4));
23192180      GetIndMenuItemWithCommandID( info->contextualMenu, ID_8_BYTE_CHUNKS, 1, NULL, &menuindex);
2320      CheckMenuItem(info->contextualMenu, menuindex, (debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK) == 8));
2181      CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_bytes_per_chunk(info->view[0].view) == 8));
23212182      GetIndMenuItemWithCommandID( info->contextualMenu, ID_LOGICAL_ADDRESSES, 1, NULL, &menuindex);
2322      CheckMenuItem(info->contextualMenu, menuindex, (debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_NO_TRANSLATION) == 0));
2183      CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_physical(info->view[0].view) == 0));
23232184      GetIndMenuItemWithCommandID( info->contextualMenu, ID_PHYSICAL_ADDRESSES, 1, NULL, &menuindex);
2324      CheckMenuItem(info->contextualMenu, menuindex, (debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_NO_TRANSLATION) != 0));
2185      CheckMenuItem(info->contextualMenu, menuindex, (memory_view_get_physical(info->view[0].view) != 0));
23252186      GetIndMenuItemWithCommandID( info->contextualMenu, ID_REVERSE_VIEW, 1, NULL, &menuindex);
2326      CheckMenuItem(info->contextualMenu, menuindex, (debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_REVERSE_VIEW)));
2187      CheckMenuItem(info->contextualMenu, menuindex, memory_view_get_reverse(info->view[0].view));
23272188   }
23282189}
23292190
r3755r3756
23362197static int memory_handle_command(debugwin_info *info, EventRef inEvent)
23372198{
23382199   HICommand   cmd;
2339   Rect   bounds;
23402200   
23412201   if ( GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( cmd ), NULL, &cmd ) != noErr )
23422202      return global_handle_command(info, inEvent);
r3755r3756
23532213         
23542214         if ( sel > 0 )
23552215         {
2356            // find the matching entry
2357            memorycombo_item *ci;
2358            for (ci = memorycombo; ci; ci = ci->next)
2359               if (--sel == 0)
2360               {
2361                  debug_view_begin_update(info->view[0].view);
2362                  memory_update_selection(info, ci);
2363                  debug_view_end_update(info->view[0].view);
2364               }
2216            memory_view_set_subview(info->view[0].view, sel);
2217            memory_update_caption(info);
23652218
23662219            // reset the focus
23672220            osx_SetFocus(info->focuswnd);
r3755r3756
23722225   
23732226   
23742227      case ID_1_BYTE_CHUNKS:
2375         debug_view_begin_update(info->view[0].view);
2376         debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK, 1);
2377         debug_view_end_update(info->view[0].view);
2378         memory_update_checkmarks(info);
2228         memory_view_set_bytes_per_chunk(info->view[0].view, 1);
23792229         return 1;
23802230
23812231      case ID_2_BYTE_CHUNKS:
2382         debug_view_begin_update(info->view[0].view);
2383         debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK, 2);
2384         debug_view_end_update(info->view[0].view);
2385         memory_update_checkmarks(info);
2232         memory_view_set_bytes_per_chunk(info->view[0].view, 2);
23862233         return 1;
23872234
23882235      case ID_4_BYTE_CHUNKS:
2389         debug_view_begin_update(info->view[0].view);
2390         debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK, 4);
2391         debug_view_end_update(info->view[0].view);
2392         memory_update_checkmarks(info);
2236         memory_view_set_bytes_per_chunk(info->view[0].view, 4);
23932237         return 1;
23942238
23952239      case ID_8_BYTE_CHUNKS:
2396         debug_view_begin_update(info->view[0].view);
2397         debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK, 8);
2398         debug_view_end_update(info->view[0].view);
2399         memory_update_checkmarks(info);
2240         memory_view_set_bytes_per_chunk(info->view[0].view, 8);
24002241         return 1;
24012242
24022243      case ID_LOGICAL_ADDRESSES:
2403         debug_view_begin_update(info->view[0].view);
2404         debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_NO_TRANSLATION, FALSE);
2405         debug_view_end_update(info->view[0].view);
2406         memory_update_checkmarks(info);
2244         memory_view_set_physical(info->view[0].view, FALSE);
24072245         return 1;
24082246
24092247      case ID_PHYSICAL_ADDRESSES:
2410         debug_view_begin_update(info->view[0].view);
2411         debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_NO_TRANSLATION, TRUE);
2412         debug_view_end_update(info->view[0].view);
2413         memory_update_checkmarks(info);
2248         memory_view_set_physical(info->view[0].view, TRUE);
24142249         return 1;
24152250
24162251      case ID_REVERSE_VIEW:
2417         debug_view_begin_update(info->view[0].view);
2418         debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_REVERSE_VIEW, !debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_REVERSE_VIEW));
2419         debug_view_end_update(info->view[0].view);
2420         memory_update_checkmarks(info);
2252         memory_view_set_reverse(info->view[0].view, !memory_view_get_reverse(info->view[0].view));
24212253         return 1;
24222254
24232255      case ID_INCREASE_MEM_WIDTH:
2424         GetWindowBounds(info->wnd, kWindowStructureRgn, &bounds );
2425         bounds.right += 4*debug_font_width;
2426         SetWindowBounds(info->wnd, kWindowStructureRgn, &bounds );
2427
2428         debug_view_begin_update(info->view[0].view);
2429         debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_WIDTH, debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_WIDTH) + 1);
2430         debug_view_end_update(info->view[0].view);
2431         
2432         memory_recompute_children(info);
2256         memory_view_set_chunks_per_row(info->view[0].view, memory_view_get_chunks_per_row(info->view[0].view) + 1);
24332257         return 1;
24342258
24352259      case ID_DECREASE_MEM_WIDTH:
2436         GetWindowBounds(info->wnd, kWindowStructureRgn, &bounds );
2437         bounds.right -= 4*debug_font_width;
2438         SetWindowBounds(info->wnd, kWindowStructureRgn, &bounds );
2439
2440         debug_view_begin_update(info->view[0].view);
2441         debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_WIDTH, debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_WIDTH) - 1);
2442         debug_view_end_update(info->view[0].view);
2443         
2444         memory_recompute_children(info);
2260         memory_view_set_chunks_per_row(info->view[0].view, memory_view_get_chunks_per_row(info->view[0].view) - 1);
24452261         return 1;
24462262   }
24472263   
r3755r3756
24572273static int memory_handle_key(debugwin_info *info, EventRef inEvent)
24582274{
24592275   EventRecord      event;
2460   Rect   bounds;
24612276   
24622277   if ( ConvertEventRefToEventRecord( inEvent, &event ) )
24632278   {
r3755r3756
24662281         switch( event.message & charCodeMask )
24672282         {
24682283            case '1':
2469               debug_view_begin_update(info->view[0].view);
2470               debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK, 1);
2471               debug_view_end_update(info->view[0].view);
2472               memory_update_checkmarks(info);
2284               memory_view_set_bytes_per_chunk(info->view[0].view, 1);
24732285               return 1;
24742286
24752287            case '2':
2476               debug_view_begin_update(info->view[0].view);
2477               debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK, 2);
2478               debug_view_end_update(info->view[0].view);
2479               memory_update_checkmarks(info);
2288               memory_view_set_bytes_per_chunk(info->view[0].view, 2);
24802289               return 1;
24812290
24822291            case '4':
2483               debug_view_begin_update(info->view[0].view);
2484               debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK, 4);
2485               debug_view_end_update(info->view[0].view);
2486               memory_update_checkmarks(info);
2292               memory_view_set_bytes_per_chunk(info->view[0].view, 4);
24872293               return 1;
24882294
24892295            case '8':
2490               debug_view_begin_update(info->view[0].view);
2491               debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_BYTES_PER_CHUNK, 8);
2492               debug_view_end_update(info->view[0].view);
2493               memory_update_checkmarks(info);
2296               memory_view_set_bytes_per_chunk(info->view[0].view, 8);
24942297               return 1;
24952298
24962299            case 'l':
24972300            case 'L':
2498               debug_view_begin_update(info->view[0].view);
2499               debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_NO_TRANSLATION, FALSE);
2500               debug_view_end_update(info->view[0].view);
2501               memory_update_checkmarks(info);
2301               memory_view_set_physical(info->view[0].view, FALSE);
25022302               return 1;
25032303
25042304            case 'y':
25052305            case 'Y':
2506               debug_view_begin_update(info->view[0].view);
2507               debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_NO_TRANSLATION, TRUE);
2508               debug_view_end_update(info->view[0].view);
2509               memory_update_checkmarks(info);
2306               memory_view_set_physical(info->view[0].view, TRUE);
25102307               return 1;
25112308
25122309            case 'r':
25132310            case 'R':
2514               debug_view_begin_update(info->view[0].view);
2515               debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_REVERSE_VIEW, !debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_REVERSE_VIEW));
2516               debug_view_end_update(info->view[0].view);
2517               memory_update_checkmarks(info);
2311               memory_view_set_reverse(info->view[0].view, !memory_view_get_reverse(info->view[0].view));
25182312               return 1;
25192313
25202314            case 'p':
25212315            case 'P':
2522               GetWindowBounds(info->wnd, kWindowStructureRgn, &bounds );
2523               bounds.right += 4*debug_font_width;
2524               SetWindowBounds(info->wnd, kWindowStructureRgn, &bounds );
2525
2526               debug_view_begin_update(info->view[0].view);
2527               debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_WIDTH, debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_WIDTH) + 1);
2528               debug_view_end_update(info->view[0].view);
2529               
2530               memory_recompute_children(info);
2316               memory_view_set_chunks_per_row(info->view[0].view, memory_view_get_chunks_per_row(info->view[0].view) + 1);
25312317               return 1;
25322318
25332319            case 'o':
25342320            case 'O':
2535               GetWindowBounds(info->wnd, kWindowStructureRgn, &bounds );
2536               bounds.right -= 4*debug_font_width;
2537               SetWindowBounds(info->wnd, kWindowStructureRgn, &bounds );
2538
2539               debug_view_begin_update(info->view[0].view);
2540               debug_view_set_property_UINT32(info->view[0].view, DVP_MEM_WIDTH, debug_view_get_property_UINT32(info->view[0].view, DVP_MEM_WIDTH) - 1);
2541               debug_view_end_update(info->view[0].view);
2542               
2543               memory_recompute_children(info);
2321               memory_view_set_chunks_per_row(info->view[0].view, memory_view_get_chunks_per_row(info->view[0].view) - 1);
25442322               return 1;
25452323         }
25462324      }
r3755r3756
25522330
25532331
25542332//============================================================
2333//  memory_update_caption
2334//============================================================
2335
2336static void memory_update_caption(debugwin_info *info)
2337{
2338   const memory_subview_item *subview = memory_view_get_current_subview(info->view[0].view);
2339   CFStringRef cftitle;
2340   char title[256];
2341
2342   // update the caption
2343   snprintf(title, ARRAY_LENGTH(title), "Memory: %s", subview->name);
2344
2345   cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() );
2346
2347   if ( cftitle )
2348   {
2349      SetWindowTitleWithCFString( info->wnd, cftitle);
2350      CFRelease( cftitle );
2351   }
2352}
2353
2354
2355
2356//============================================================
25552357//  disasm_create_window
25562358//============================================================
25572359
25582360static void disasm_create_window(running_machine *machine)
25592361{
2560   int curcpu = cpunum_get_active(), cursel = 0;
2362   const device_config *curcpu = debug_cpu_get_visible_cpu(machine);
2363   const disasm_subview_item *subview;
2364   int cursel = 0;
25612365   debugwin_info *info;
25622366   MenuRef optionsmenu, popupmenu;
2563   UINT32 cpunum;
25642367   Rect   bounds;
25652368   ControlFontStyleRec      style;
25662369   Str255      fontName;
r3755r3756
25692372
25702373   // create the window
25712374   info = debug_window_create(machine, "Disassembly", NULL);
2572   if (!info || !debug_view_create(info, 0, DVT_DISASSEMBLY))
2375   if (!info || !debugwin_view_create(info, 0, DVT_DISASSEMBLY))
25732376      return;
25742377
25752378   // create the options menu
r3755r3756
26042407   info->handle_key = disasm_handle_key;
26052408
26062409   // set up the view to track the initial expression
2607   debug_view_begin_update(info->view[0].view);
2608   debug_view_set_property_string(info->view[0].view, DVP_DASM_EXPRESSION, "curpc");
2410   disasm_view_set_expression(info->view[0].view, "curpc");
26092411   strcpy(info->edit_defstr, "curpc");
2610   debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_TRACK_LIVE, 1);
2611   debug_view_end_update(info->view[0].view);
26122412   
26132413   fontName[0] = strlen( OSX_DEBUGGER_FONT_NAME );
26142414   strcpy( (char*)&fontName[1], OSX_DEBUGGER_FONT_NAME );
r3755r3756
26222422   bounds.bottom = bounds.right = 100;
26232423   CreateEditUnicodeTextControl(info->wnd, &bounds, CFSTR("0"), false, NULL, &info->editwnd);
26242424   SetControlFontStyle(info->editwnd,&style);
2625   InstallEventHandler( GetControlEventTarget(info->editwnd), NewEventHandlerUPP(debug_edit_proc), sizeof( debug_keyboard_events ) / sizeof( EventTypeSpec ), debug_keyboard_events, info, NULL );
2425   InstallEventHandler( GetControlEventTarget(info->editwnd), NewEventHandlerUPP(debugwin_edit_proc), sizeof( debug_keyboard_events ) / sizeof( EventTypeSpec ), debug_keyboard_events, info, NULL );
26262426   
26272427   // create action menu and attach the contextual menu
26282428   content.contentType = kControlContentTextOnly;
r3755r3756
26492449   }
26502450
26512451   // populate the combobox
2652   for (cpunum = 0; cpunum < MAX_CPU; cpunum++)
2452   for (subview = disasm_view_get_subview_list(info->view[0].view); subview != NULL; subview = subview->next)
26532453   {
2654      if (machine->cpu[cpunum] != NULL)
2655      {
2656                const cpu_debug_data *cpuinfo = cpu_get_debug_data(machine->cpu[cpunum]);
2657         if (cpuinfo->space[ADDRESS_SPACE_PROGRAM].databytes)
2658         {
2659            CFStringRef      cfName;
2660            char         name[100];
2661            UInt16         item;
2454      CFStringRef      cfName;
2455      char         name[100];
2456      UInt16         item;
26622457
2663            snprintf(name, ARRAY_LENGTH(name), "CPU #%d \"%s\" (%s)", cpunum, machine->config->cpu[cpunum].tag, cpu_get_name(machine->cpu[cpunum]));
2458      snprintf(name, ARRAY_LENGTH(name), "%s", subview->name);
26642459           
2665            cfName = CFStringCreateWithCString( NULL, name, CFStringGetSystemEncoding() );
2666            AppendMenuItemTextWithCFString( popupmenu, cfName, 0, 0, &item );
2667            CFRelease( cfName );
2460      cfName = CFStringCreateWithCString( NULL, name, CFStringGetSystemEncoding() );
2461      AppendMenuItemTextWithCFString( popupmenu, cfName, 0, 0, &item );
2462      CFRelease( cfName );
26682463           
2669            if (cpunum == curcpu)
2670               cursel = item;
2671         }
2672      }
2464      if (cursel == 0 && subview->space->cpu == curcpu)
2465         cursel = item;
26732466   }
2467   disasm_view_set_subview(info->view[0].view, cursel);
26742468   
26752469   SetControlData(info->otherwnd[0], kControlEntireControl, kControlPopupButtonOwnedMenuRefTag, sizeof(popupmenu),&popupmenu);
26762470#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
r3755r3756
26872481   info->recompute_children = disasm_recompute_children;
26882482   info->process_string = disasm_process_string;
26892483
2690   // set the CPUnum and spacenum properties
2691   debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_CPUNUM, (curcpu == -1) ? 0 : curcpu);
2692
26932484   // set the caption
26942485   disasm_update_caption(info);
26952486
r3755r3756
27202511
27212512static void disasm_recompute_children(debugwin_info *info)
27222513{
2514   debug_view_xy totalsize = debug_view_get_total_size(info->view[0].view);
27232515   Rect      parent, dasmrect, editrect, comborect, actionrect;
27242516   Rect      bounds;
27252517   HIRect      hibounds;
2726   UINT32      width;
27272518
2728   // get the view width
2729   width = debug_view_get_property_UINT32(info->view[0].view, DVP_TOTAL_COLS);
2730
27312519   // compute a client rect
27322520   bounds.top = bounds.left = 0;
2733   bounds.right = width * debug_font_width + vscroll_width + 2 * EDGE_WIDTH;
2521   bounds.right = totalsize.x * debug_font_width + vscroll_width + 2 * EDGE_WIDTH;
27342522   bounds.bottom = 200;
27352523//   AdjustWindowRectEx(&bounds, DEBUG_WINDOW_STYLE, FALSE, DEBUG_WINDOW_STYLE_EX);
27362524
r3755r3756
27692557   dasmrect.right = parent.right - EDGE_WIDTH;
27702558
27712559   // set the bounds of things
2772   debug_view_set_bounds(&info->view[0], &dasmrect);
2560   debugwin_view_set_bounds(&info->view[0], &dasmrect);
27732561   
27742562   osx_RectToHIRect( &editrect, &hibounds );
27752563   smart_set_view_bounds(info->editwnd, &hibounds);
r3755r3756
27902578static void disasm_process_string(debugwin_info *info, const char *string)
27912579{
27922580   // set the string to the disasm view
2793   debug_view_set_property_string(info->view[0].view, DVP_DASM_EXPRESSION, string);
2581   disasm_view_set_expression(info->view[0].view, string);
27942582
27952583   // select everything in the edit text box
27962584   {
r3755r3756
28182606   {
28192607      MenuItemIndex   menuindex;
28202608     
2821      int rightcol = debug_view_get_property_UINT32(info->view[0].view, DVP_DASM_RIGHT_COLUMN);
2609      disasm_right_column rightcol = disasm_view_get_right_column(info->view[0].view);
28222610           
28232611      GetIndMenuItemWithCommandID( info->contextualMenu, ID_SHOW_RAW, 1, NULL, &menuindex );
2824      CheckMenuItem(info->contextualMenu, menuindex, (rightcol == DVP_DASM_RIGHTCOL_RAW));
2612      CheckMenuItem(info->contextualMenu, menuindex, (rightcol == DASM_RIGHTCOL_RAW));
28252613      GetIndMenuItemWithCommandID( info->contextualMenu, ID_SHOW_ENCRYPTED, 1, NULL, &menuindex );
2826      CheckMenuItem(info->contextualMenu, menuindex, (rightcol == DVP_DASM_RIGHTCOL_ENCRYPTED));
2614      CheckMenuItem(info->contextualMenu, menuindex, (rightcol == DASM_RIGHTCOL_ENCRYPTED));
28272615      GetIndMenuItemWithCommandID( info->contextualMenu, ID_SHOW_COMMENTS, 1, NULL, &menuindex );
2828      CheckMenuItem(info->contextualMenu, menuindex, (rightcol == DVP_DASM_RIGHTCOL_COMMENTS));
2616      CheckMenuItem(info->contextualMenu, menuindex, (rightcol == DASM_RIGHTCOL_COMMENTS));
28292617   }
28302618}
28312619
r3755r3756
28392627{
28402628   HICommand   cmd;
28412629   char command[64];
2842   UINT32 active_address = 0x00;
28432630
28442631   if ( GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( cmd ), NULL, &cmd ) != noErr )
28452632      return global_handle_command(info, inEvent);
r3755r3756
28562643         
28572644         if ( sel > 0 )
28582645         {
2859            // find the matching entry
2860            UINT32 cpunum;
2861            for (cpunum = 0; cpunum < MAX_CPU; cpunum++)
2862            {
2863               if (info->machine->cpu[cpunum] != NULL)
2864               {
2865                         const cpu_debug_data *cpuinfo = cpu_get_debug_data(info->machine->cpu[cpunum]);
2866                  if (cpuinfo->space[ADDRESS_SPACE_PROGRAM].databytes)
2867                  {
2868                     if (--sel == 0)
2869                     {
2870                        debug_view_begin_update(info->view[0].view);
2871                        debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_CPUNUM, cpunum);
2872                        debug_view_end_update(info->view[0].view);
2873                        disasm_update_caption(info);
2874                     }
2875                  }
2876               }
2877            }
2646            disasm_view_set_subview(info->view[0].view, sel);
2647            disasm_update_caption(info);
28782648
28792649            // reset the focus
28802650            osx_SetFocus(info->focuswnd);
r3755r3756
28842654      break;
28852655           
28862656      case ID_SHOW_RAW:
2887         debug_view_begin_update(info->view[0].view);
2888         debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_RAW);
2889         debug_view_end_update(info->view[0].view);
2890         disasm_update_checkmarks(info);
2657         disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_RAW);
28912658         (*info->recompute_children)(info);
28922659         return 1;
28932660     
28942661      case ID_SHOW_ENCRYPTED:
2895         debug_view_begin_update(info->view[0].view);
2896         debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_ENCRYPTED);
2897         debug_view_end_update(info->view[0].view);
2898         disasm_update_checkmarks(info);
2662         disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_ENCRYPTED);
28992663         (*info->recompute_children)(info);
29002664         return 1;
29012665
29022666      case ID_SHOW_COMMENTS:
2903         debug_view_begin_update(info->view[0].view);
2904         debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_COMMENTS);
2905         debug_view_end_update(info->view[0].view);
2906         disasm_update_checkmarks(info);
2667         disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_COMMENTS);
29072668         (*info->recompute_children)(info);
29082669         return 1;
29092670
29102671      case ID_RUN_TO_CURSOR:
2911         if (debug_view_get_property_UINT32(info->view[0].view, DVP_CURSOR_VISIBLE))
2672         if (debug_view_get_cursor_visible(info->view[0].view))
29122673         {
2913            active_address = debug_view_get_property_UINT32(info->view[0].view, DVP_DASM_ACTIVE_ADDRESS);
2914            sprintf(command, "go %X", active_address);
2915            debug_console_execute_command(info->machine, command, 1);
2674            const address_space *space = disasm_view_get_current_subview(info->view[0].view)->space;
2675            if (debug_cpu_get_visible_cpu(info->machine) == space->cpu)
2676            {
2677               offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(info->view[0].view));
2678               sprintf(command, "go %X", address);
2679               debug_console_execute_command(info->machine, command, 1);
2680            }
29162681         }
29172682         return 1;
29182683
29192684      case ID_TOGGLE_BREAKPOINT:
2920         if (debug_view_get_property_UINT32(info->view[0].view, DVP_CURSOR_VISIBLE))
2685         if (debug_view_get_cursor_visible(info->view[0].view))
29212686         {
2922            UINT32 cpu_num = 0;
2923            cpu_debug_data *cpuinfo ;
2924            debug_cpu_breakpoint *bp;
2925            INT8 bp_exists = 0;
2926            UINT32 bp_num = 0;
2687            const address_space *space = disasm_view_get_current_subview(info->view[0].view)->space;
2688            if (debug_cpu_get_visible_cpu(info->machine) == space->cpu)
2689            {
2690               offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(info->view[0].view));
2691               cpu_debug_data *cpuinfo = cpu_get_debug_data(space->cpu);
2692               debug_cpu_breakpoint *bp;
2693               INT32 bpindex = -1;
29272694
2928            /* what address are we dealing with? */
2929            active_address = debug_view_get_property_UINT32(info->view[0].view, DVP_DASM_ACTIVE_ADDRESS);
2695               /* first find an existing breakpoint at this address */
2696               for (bp = cpuinfo->bplist; bp != NULL; bp = bp->next)
2697                  if (address == bp->address)
2698                  {
2699                     bpindex = bp->index;
2700                     break;
2701                  }
29302702
2931            /* is there already a breakpoint there? */
2932            cpu_num = debug_view_get_property_UINT32(info->view[0].view, DVP_DASM_CPUNUM);
2933            cpuinfo = (cpu_debug_data*)cpu_get_debug_data(info->machine->cpu[cpu_num]);
2934
2935            for (bp = cpuinfo->bplist; bp; bp = bp->next)
2936            {
2937               if (BYTE2ADDR(active_address, cpuinfo, ADDRESS_SPACE_PROGRAM) == bp->address)
2938               {
2939                  bp_exists = 1;
2940                  bp_num = bp->index;
2941               }
2703               /* if it doesn't exist, add a new one */
2704               if (bpindex == -1)
2705                  sprintf(command, "bpset %X", address);
2706               else
2707                  sprintf(command, "bpclear %X", bpindex);
2708               debug_console_execute_command(info->machine, command, 1);
29422709            }
2943
2944            /* Toggle */
2945            if (!bp_exists)
2946               sprintf(command, "bpset %X", BYTE2ADDR(active_address, cpuinfo, ADDRESS_SPACE_PROGRAM));
2947            else
2948               sprintf(command, "bpclear %X", bp_num);
2949            debug_console_execute_command(info->machine, command, 1);
29502710         }
29512711         return 1;
29522712   }
r3755r3756
29622722{
29632723   EventRecord      event;
29642724   char command[64];
2965   UINT32 active_address = 0x00;
29662725
29672726   if ( ConvertEventRefToEventRecord( inEvent, &event ) )
29682727   {
r3755r3756
29722731         {
29732732            case 'r':
29742733            case 'R':
2975               debug_view_begin_update(info->view[0].view);
2976               debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_RAW);
2977               debug_view_end_update(info->view[0].view);
2978               disasm_update_checkmarks(info);
2734               disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_RAW);
29792735               (*info->recompute_children)(info);
29802736               return 1;
29812737           
29822738            case 'e':
29832739            case 'E':
2984               debug_view_begin_update(info->view[0].view);
2985               debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_ENCRYPTED);
2986               debug_view_end_update(info->view[0].view);
2987               disasm_update_checkmarks(info);
2740               disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_ENCRYPTED);
29882741               (*info->recompute_children)(info);
29892742               return 1;
29902743           
29912744            case 'n':
29922745            case 'N':
2993               debug_view_begin_update(info->view[0].view);
2994               debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_RIGHT_COLUMN, DVP_DASM_RIGHTCOL_COMMENTS);
2995               debug_view_end_update(info->view[0].view);
2996               disasm_update_checkmarks(info);
2746               disasm_view_set_right_column(info->view[0].view, DASM_RIGHTCOL_COMMENTS);
29972747               (*info->recompute_children)(info);
29982748               return 1;
29992749         }
r3755r3756
30022752      switch( ( ( event.message & keyCodeMask ) >> 8 ) & 0xFF )
30032753      {
30042754         case KEY_F4:
3005            if (debug_view_get_property_UINT32(info->view[0].view, DVP_CURSOR_VISIBLE))
2755            if (debug_view_get_cursor_visible(info->view[0].view))
30062756            {
3007               active_address = debug_view_get_property_UINT32(info->view[0].view, DVP_DASM_ACTIVE_ADDRESS);
3008               sprintf(command, "go %X", active_address);
3009               debug_console_execute_command(info->machine, command, 1);
2757               const address_space *space = disasm_view_get_current_subview(info->view[0].view)->space;
2758               if (debug_cpu_get_visible_cpu(info->machine) == space->cpu)
2759               {
2760                  offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(info->view[0].view));
2761                  sprintf(command, "go %X", address);
2762                  debug_console_execute_command(info->machine, command, 1);
2763               }
30102764            }
30112765            return 1;
30122766         
30132767         case KEY_F9:
3014            if (debug_view_get_property_UINT32(info->view[0].view, DVP_CURSOR_VISIBLE))
2768            if (debug_view_get_cursor_visible(info->view[0].view))
30152769            {
3016               UINT32 cpu_num = 0;
3017               cpu_debug_data *cpuinfo ;
3018               debug_cpu_breakpoint *bp;
3019               INT8 bp_exists = 0;
3020               UINT32 bp_num = 0;
2770               const address_space *space = disasm_view_get_current_subview(info->view[0].view)->space;
2771               if (debug_cpu_get_visible_cpu(info->machine) == space->cpu)
2772               {
2773                  offs_t address = memory_byte_to_address(space, disasm_view_get_selected_address(info->view[0].view));
2774                  cpu_debug_data *cpuinfo = cpu_get_debug_data(space->cpu);
2775                  debug_cpu_breakpoint *bp;
2776                  INT32 bpindex = -1;
30212777
3022               /* what address are we dealing with? */
3023               active_address = debug_view_get_property_UINT32(info->view[0].view, DVP_DASM_ACTIVE_ADDRESS);
2778                  /* first find an existing breakpoint at this address */
2779                  for (bp = cpuinfo->bplist; bp != NULL; bp = bp->next)
2780                     if (address == bp->address)
2781                     {
2782                        bpindex = bp->index;
2783                        break;
2784                     }
30242785
3025               /* is there already a breakpoint there? */
3026               cpu_num = debug_view_get_property_UINT32(info->view[0].view, DVP_DASM_CPUNUM);
3027               cpuinfo = (cpu_debug_data*)cpu_get_debug_data(info->machine->cpu[cpu_num]);
3028
3029               for (bp = cpuinfo->bplist; bp; bp = bp->next)
3030               {
3031                  if (BYTE2ADDR(active_address, cpuinfo, ADDRESS_SPACE_PROGRAM) == bp->address)
3032                  {
3033                     bp_exists = 1;
3034                     bp_num = bp->index;
3035                  }
2786                  /* if it doesn't exist, add a new one */
2787                  if (bpindex == -1)
2788                     sprintf(command, "bpset %X", address);
2789                  else
2790                     sprintf(command, "bpclear %X", bpindex);
2791                  debug_console_execute_command(info->machine, command, 1);
30362792               }
3037
3038               /* Toggle */
3039               if (!bp_exists)
3040                  sprintf(command, "bpset %X", BYTE2ADDR(active_address, cpuinfo, ADDRESS_SPACE_PROGRAM));
3041               else
3042                  sprintf(command, "bpclear %X", bp_num);
3043               debug_console_execute_command(info->machine, command, 1);
30442793            }
30452794            return 1;
30462795      }
30472796     
30482797      if ( ( event.message & charCodeMask ) == kReturnCharCode )
30492798      {
3050         if (debug_view_get_property_UINT32(info->view[0].view, DVP_CURSOR_VISIBLE))
2799         if (debug_view_get_cursor_visible(info->view[0].view))
30512800         {
30522801            debug_cpu_single_step(info->machine, 1);
30532802            return 1;
r3755r3756
30662815
30672816static void disasm_update_caption(debugwin_info *info)
30682817{
2818   const disasm_subview_item *subview = disasm_view_get_current_subview(info->view[0].view);
30692819   CFStringRef      cftitle;
30702820   char         title[100];
3071   UINT32         cpunum;
30722821
3073   // get the properties
3074   cpunum = debug_view_get_property_UINT32(info->view[0].view, DVP_DASM_CPUNUM);
2822   // update the caption
2823   snprintf(title, ARRAY_LENGTH(title), "Disassembly: %s", subview->name);
30752824
3076   // then update the caption
3077   snprintf(title, ARRAY_LENGTH(title), "Disassembly: CPU #%d \"%s\" (%s)", cpunum, info->machine->config->cpu[cpunum].tag, cpu_get_name(info->machine->cpu[cpunum]));
3078
30792825   cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() );
30802826   
30812827   if ( cftitle )
r3755r3756
30932839
30942840void console_create_window(running_machine *machine)
30952841{
2842   const registers_subview_item *regsubview;
2843   const disasm_subview_item *dasmsubview;
30962844   debugwin_info *info;
30972845   int bestwidth, bestheight;
30982846   Rect bounds, work_bounds;
30992847   MenuRef optionsmenu, popupmenu;
3100   UINT32 cpunum;
31012848   ControlFontStyleRec      style;
31022849   Str255      fontName;
31032850   CGDirectDisplayID   mainID = CGMainDisplayID();
r3755r3756
31062853
31072854   // create the window
31082855   info = debug_window_create(machine, "Debug", NULL);
3109   if (!info)
2856   if (info == NULL)
31102857      return;
31112858   main_console = info;
3112   console_set_cpunum(machine, 0);
2859   console_set_cpu(machine->cpu[0]);
31132860
31142861   // create the views
3115   if (!debug_view_create(info, 0, DVT_DISASSEMBLY))
2862   if (!debugwin_view_create(info, 0, DVT_DISASSEMBLY))
31162863      goto cleanup;
3117   if (!debug_view_create(info, 1, DVT_REGISTERS))
2864   if (!debugwin_view_create(info, 1, DVT_REGISTERS))
31182865      goto cleanup;
3119   if (!debug_view_create(info, 2, DVT_CONSOLE))
2866   if (!debugwin_view_create(info, 2, DVT_CONSOLE))
31202867      goto cleanup;
31212868
31222869   // create the options menu
r3755r3756
31632910   info->view[2].is_textbuf = TRUE;
31642911
31652912   // set up the disassembly view to track the current pc
3166   debug_view_begin_update(info->view[0].view);
3167   debug_view_set_property_string(info->view[0].view, DVP_DASM_EXPRESSION, "curpc");
3168   debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_TRACK_LIVE, 1);
3169   debug_view_end_update(info->view[0].view);
2913   disasm_view_set_expression(info->view[0].view, "curpc");
31702914   
31712915   fontName[0] = strlen( OSX_DEBUGGER_FONT_NAME );
31722916   strcpy( (char*)&fontName[1], OSX_DEBUGGER_FONT_NAME );
r3755r3756
31802924   bounds.bottom = bounds.right = 100;
31812925   CreateEditUnicodeTextControl(info->wnd, &bounds, CFSTR("0"), false, NULL, &info->editwnd);
31822926   SetControlFontStyle(info->editwnd,&style);
3183   InstallEventHandler( GetControlEventTarget(info->editwnd), NewEventHandlerUPP(debug_edit_proc), sizeof( debug_keyboard_events ) / sizeof( EventTypeSpec ), debug_keyboard_events, info, NULL );
2927   InstallEventHandler( GetControlEventTarget(info->editwnd), NewEventHandlerUPP(debugwin_edit_proc), sizeof( debug_keyboard_events ) / sizeof( EventTypeSpec ), debug_keyboard_events, info, NULL );
31842928
31852929   // create popup menu and attach the contextual menu
31862930   content.contentType = kControlContentTextOnly;
r3755r3756
31962940   // loop over all CPUs and compute the sizes
31972941   info->minwidth = 0;
31982942   info->maxwidth = 0;
3199   for (cpunum = MAX_CPU - 1; (INT32)cpunum >= 0; cpunum--)
3200      if (machine->config->cpu[cpunum].type != CPU_DUMMY)
3201      {
3202         UINT32 regchars, dischars, conchars;
3203         UINT32 minwidth, maxwidth;
2943   for (dasmsubview = disasm_view_get_subview_list(info->view[0].view); dasmsubview != NULL; dasmsubview = dasmsubview->next)
2944      for (regsubview = registers_view_get_subview_list(info->view[1].view); regsubview != NULL; regsubview = regsubview->next)
2945         if (dasmsubview->space->cpu == regsubview->device)
2946         {
2947            UINT32 regchars, dischars, conchars;
2948            UINT32 minwidth, maxwidth;
32042949
3205         // point all views to the new CPU number
3206         debug_view_set_property_UINT32(info->view[0].view, DVP_DASM_CPUNUM, cpunum);
3207         debug_view_set_property_UINT32(info->view[1].view, DVP_REGS_CPUNUM, cpunum);
2950            // point all views to the new CPU number
2951            disasm_view_set_subview(info->view[0].view, dasmsubview->index);
2952            registers_view_set_subview(info->view[1].view, regsubview->index);
32082953
3209         // get the total width of all three children
3210         dischars = debug_view_get_property_UINT32(info->view[0].view, DVP_TOTAL_COLS);
3211         regchars = debug_view_get_property_UINT32(info->view[1].view, DVP_TOTAL_COLS);
3212         conchars = debug_view_get_property_UINT32(info->view[2].view, DVP_TOTAL_COLS);
2954            // get the total width of all three children
2955            dischars = debug_view_get_total_size(info->view[0].view).x;
2956            regchars = debug_view_get_total_size(info->view[1].view).x;
2957            conchars = debug_view_get_total_size(info->view[2].view).x;
32132958
3214         // compute the preferred width
3215         minwidth = EDGE_WIDTH + regchars * debug_font_width + vscroll_width + 2 * EDGE_WIDTH + 100 + EDGE_WIDTH;
3216         maxwidth = EDGE_WIDTH + regchars * debug_font_width + vscroll_width + 2 * EDGE_WIDTH + ((dischars > conchars) ? dischars : conchars) * debug_font_width + vscroll_width + EDGE_WIDTH;
3217         if (minwidth > info->minwidth)
3218            info->minwidth = minwidth;
3219         if (maxwidth > info->maxwidth)
3220            info->maxwidth = maxwidth;
3221      }
2959            // compute the preferred width
2960            minwidth = EDGE_WIDTH + regchars * debug_font_width + vscroll_width + 2 * EDGE_WIDTH + 100 + EDGE_WIDTH;
2961            maxwidth = EDGE_WIDTH + regchars * debug_font_width + vscroll_width + 2 * EDGE_WIDTH + ((dischars > conchars) ? dischars : conchars) * debug_font_width + vscroll_width + EDGE_WIDTH;
2962            if (minwidth > info->minwidth)
2963               info->minwidth = minwidth;
2964            if (maxwidth > info->maxwidth)
2965               info->maxwidth = maxwidth;
2966         }
32222967
32232968   // get the work bounds
32242969   {
r3755r3756
32953040   parent.right = hibounds.origin.x + hibounds.size.width;
32963041   
32973042   // get the total width of all three children
3298   dischars = debug_view_get_property_UINT32(info->view[0].view, DVP_TOTAL_COLS);
3299   regchars = debug_view_get_property_UINT32(info->view[1].view, DVP_TOTAL_COLS);
3300   conchars = debug_view_get_property_UINT32(info->view[2].view, DVP_TOTAL_COLS);
3043   dischars = debug_view_get_total_size(info->view[0].view).x;
3044   regchars = debug_view_get_total_size(info->view[1].view).x;
3045   conchars = debug_view_get_total_size(info->view[2].view).x;
33013046
33023047   // registers always get their desired width, and span the entire height
33033048   regrect.top = parent.top + EDGE_WIDTH;
r3755r3756
33333078   conrect.right = parent.right - EDGE_WIDTH;
33343079
33353080   // set the bounds of things
3336   debug_view_set_bounds(&info->view[0], &disrect);
3337   debug_view_set_bounds(&info->view[1], &regrect);
3338   debug_view_set_bounds(&info->view[2], &conrect);
3081   debugwin_view_set_bounds(&info->view[0], &disrect);
3082   debugwin_view_set_bounds(&info->view[1], &regrect);
3083   debugwin_view_set_bounds(&info->view[2], &conrect);
33393084   
33403085   osx_RectToHIRect( &editrect, &hibounds );
33413086   smart_set_view_bounds(info->editwnd, &hibounds);
r3755r3756
33693114
33703115
33713116//============================================================
3372//  console_set_cpunum
3117//  console_set_cpu
33733118//============================================================
33743119
3375static void console_set_cpunum(running_machine *machine, int cpunum)
3120static void console_set_cpu(const device_config *device)
33763121{
3122   const registers_subview_item *regsubitem = NULL;
3123   const disasm_subview_item *dasmsubitem;
33773124   char title[256];
33783125   CFStringRef      cftitle;
33793126
33803127   // first set all the views to the new cpu number
3381   if (main_console->view[0].view)
3382      debug_view_set_property_UINT32(main_console->view[0].view, DVP_DASM_CPUNUM, cpunum);
3383   if (main_console->view[1].view)
3384      debug_view_set_property_UINT32(main_console->view[1].view, DVP_REGS_CPUNUM, cpunum);
3128   if (main_console->view[0].view != NULL)
3129      for (dasmsubitem = disasm_view_get_subview_list(main_console->view[0].view); dasmsubitem != NULL; dasmsubitem = dasmsubitem->next)
3130         if (dasmsubitem->space->cpu == device)
3131         {
3132            disasm_view_set_subview(main_console->view[0].view, dasmsubitem->index);
3133            break;
3134         }
3135   if (main_console->view[1].view != NULL)
3136      for (regsubitem = registers_view_get_subview_list(main_console->view[1].view); regsubitem != NULL; regsubitem = regsubitem->next)
3137         if (regsubitem->device == device)
3138         {
3139            registers_view_set_subview(main_console->view[1].view, regsubitem->index);
3140            break;
3141         }
33853142
33863143   // then update the caption
3387   snprintf(title, ARRAY_LENGTH(title), "Debug: %s - CPU #%d \"%s\" (%s)", machine->gamedrv->name, cpunum, machine->config->cpu[cpunum].tag, cpu_get_name(machine->cpu[cpunum]));
3144   if (regsubitem != NULL)
3145   {
3146      snprintf(title, ARRAY_LENGTH(title), "Debug: %s - %s", device->machine->gamedrv->name, regsubitem->name);
33883147   
3389   cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() );
3148      cftitle = CFStringCreateWithCString( NULL, title, CFStringGetSystemEncoding() );
33903149   
3391   if ( cftitle )
3392   {
3393      SetWindowTitleWithCFString( main_console->wnd, cftitle);
3394      CFRelease( cftitle );
3150      if ( cftitle )
3151      {
3152         SetWindowTitleWithCFString( main_console->wnd, cftitle);
3153         CFRelease( cftitle );
3154      }
33953155   }
33963156}
33973157

Previous 15994 Revisions Next


© 1998-2018 The MESS Team