summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/debugger/osx/debugconsole.mm
blob: f6d013754030d6eabb702507ab7db4a3d0ba5f97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
// license:BSD-3-Clause
// copyright-holders:Vas Crabb
//============================================================
//
//  debugconsole.m - MacOS X Cocoa debug window handling
//
//============================================================

#include "emu.h"
#import "debugconsole.h"

#import "debugcommandhistory.h"
#import "consoleview.h"
#import "debugview.h"
#import "deviceinfoviewer.h"
#import "devicesviewer.h"
#import "disassemblyview.h"
#import "disassemblyviewer.h"
#import "errorlogviewer.h"
#import "memoryviewer.h"
#import "pointsviewer.h"
#import "registersview.h"

#include "debugger.h"
#include "debug/debugcon.h"
#include "debug/debugcpu.h"
#include "debug/points.h"

#include "util/xmlfile.h"


@implementation MAMEDebugConsole

- (id)initWithMachine:(running_machine &)m {
	NSScrollView    *regScroll, *dasmScroll, *consoleScroll;
	NSView          *consoleContainer;
	NSPopUpButton   *actionButton;
	NSRect          rct;

	// initialise superclass
	if (!(self = [super initWithMachine:m title:@"Debug"]))
		return nil;
	history = [[MAMEDebugCommandHistory alloc] init];
	auxiliaryWindows = [[NSMutableArray alloc] init];
	NSFont *const defaultFont = [[MAMEDebugView class] defaultFontForMachine:m];

	// create the register view
	regView = [[MAMERegistersView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) machine:*machine];
	regScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
	[regScroll setHasHorizontalScroller:YES];
	[regScroll setHasVerticalScroller:YES];
	[regScroll setAutohidesScrollers:YES];
	[regScroll setBorderType:NSBezelBorder];
	[regScroll setDrawsBackground:NO];
	[regScroll setDocumentView:regView];
	[regView release];

	// create the disassembly view
	dasmView = [[MAMEDisassemblyView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) machine:*machine];
	[dasmView setExpression:@"curpc"];
	dasmScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
	[dasmScroll setHasHorizontalScroller:YES];
	[dasmScroll setHasVerticalScroller:YES];
	[dasmScroll setAutohidesScrollers:YES];
	[dasmScroll setBorderType:NSBezelBorder];
	[dasmScroll setDrawsBackground:NO];
	[dasmScroll setDocumentView:dasmView];
	[dasmView release];

	// create the console view
	consoleView = [[MAMEConsoleView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) machine:*machine];
	consoleScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
	[consoleScroll setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
	[consoleScroll setHasHorizontalScroller:YES];
	[consoleScroll setHasVerticalScroller:YES];
	[consoleScroll setAutohidesScrollers:YES];
	[consoleScroll setBorderType:NSBezelBorder];
	[consoleScroll setDrawsBackground:NO];
	[consoleScroll setDocumentView:consoleView];
	[consoleView release];

	// create the command field
	commandField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 19)];
	[commandField setAutoresizingMask:(NSViewWidthSizable | NSViewMaxYMargin)];
	[commandField setFont:defaultFont];
	[commandField setFocusRingType:NSFocusRingTypeNone];
	[commandField setTarget:self];
	[commandField setAction:@selector(doCommand:)];
	[commandField setDelegate:self];
	[commandField sizeToFit];
	rct = [commandField frame];
	[commandField setFrame:NSMakeRect(rct.size.height, 0, 100 - rct.size.height, rct.size.height)];

	// create the action pull-down button
	actionButton = [[self class] newActionButtonWithFrame:NSMakeRect(0, 0, rct.size.height, rct.size.height)];
	[actionButton setAutoresizingMask:(NSViewMaxXMargin | NSViewMaxYMargin)];
	[actionButton setFont:[NSFont systemFontOfSize:[defaultFont pointSize]]];
	[dasmView insertActionItemsInMenu:[actionButton menu] atIndex:1];

	// create the container for the console and command input field
	consoleContainer = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
	[consoleScroll setFrame:NSMakeRect(0,
									   rct.size.height,
									   100,
									   [consoleContainer bounds].size.height - rct.size.height)];
	[consoleContainer addSubview:consoleScroll];
	[consoleContainer addSubview:commandField];
	[consoleContainer addSubview:actionButton];
	[consoleScroll release];
	[commandField release];
	[actionButton release];

	// create the split between the disassembly and the console
	dasmSplit = [[NSSplitView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
	[dasmSplit setDelegate:self];
	[dasmSplit setVertical:NO];
	[dasmSplit addSubview:dasmScroll];
	[dasmSplit addSubview:consoleContainer];
	[dasmScroll release];
	[consoleContainer release];

	// create the split between the registers and the console
	regSplit = [[NSSplitView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
	[regSplit setDelegate:self];
	[regSplit setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
	[regSplit setVertical:YES];
	[regSplit addSubview:regScroll];
	[regSplit addSubview:dasmSplit];
	[regScroll release];
	[dasmSplit release];

	// put the split views in the window and get them into a half-reasonable state
	[window setContentView:regSplit];
	[regSplit release];
	[regSplit adjustSubviews];
	[dasmSplit adjustSubviews];

	// keyboard focus should start on the command field
	[window makeFirstResponder:commandField];

	// calculate the optimal size for everything
	NSRect const    available = [[NSScreen mainScreen] visibleFrame];
	NSSize const    regCurrent = [regScroll frame].size;
	NSSize const    regSize = [NSScrollView frameSizeForContentSize:[regView maximumFrameSize]
											  hasHorizontalScroller:YES
												hasVerticalScroller:YES
														 borderType:[regScroll borderType]];
	NSSize const    dasmCurrent = [dasmScroll frame].size;
	NSSize const    dasmSize = [NSScrollView frameSizeForContentSize:[dasmView maximumFrameSize]
											  hasHorizontalScroller:YES
												hasVerticalScroller:YES
														 borderType:[dasmScroll borderType]];
	NSSize const    consoleCurrent = [consoleContainer frame].size;
	NSSize          consoleSize = [NSScrollView frameSizeForContentSize:[consoleView maximumFrameSize]
												  hasHorizontalScroller:YES
													hasVerticalScroller:YES
															 borderType:[consoleScroll borderType]];
	NSRect          windowFrame = [window frame];
	NSSize          adjustment;

	consoleSize.width += consoleCurrent.width - [consoleScroll frame].size.width;
	consoleSize.height += consoleCurrent.height - [consoleScroll frame].size.height;
	adjustment.width = regSize.width - regCurrent.width;
	adjustment.height = regSize.height - regCurrent.height;
	adjustment.width += std::max(dasmSize.width - dasmCurrent.width, consoleSize.width - consoleCurrent.width);

	windowFrame.size.width += adjustment.width;
	windowFrame.size.height += adjustment.height; // not used - better to go for fixed height
	windowFrame.size.height = std::min(CGFloat(512.0), available.size.height);
	windowFrame.size.width = std::min(windowFrame.size.width, available.size.width);
	windowFrame.origin.x = available.origin.x + available.size.width - windowFrame.size.width;
	windowFrame.origin.y = available.origin.y;
	[window setFrame:windowFrame display:YES];

	NSRect lhsFrame = [regScroll frame];
	NSRect rhsFrame = [dasmSplit frame];
	adjustment.width = std::min(regSize.width, ([regSplit frame].size.width - [regSplit dividerThickness]) / 2);
	rhsFrame.origin.x -= lhsFrame.size.width - adjustment.width;
	rhsFrame.size.width += lhsFrame.size.width - adjustment.width;
	lhsFrame.size.width = adjustment.width;
	[regScroll setFrame:lhsFrame];
	[dasmSplit setFrame:rhsFrame];

	// select the current processor
	[self setCPU:machine->debugger().console().get_visible_cpu()];

	[[NSNotificationCenter defaultCenter] addObserver:self
											 selector:@selector(auxiliaryWindowWillClose:)
												 name:MAMEAuxiliaryDebugWindowWillCloseNotification
											   object:nil];

	// don't forget the return value
	return self;
}


- (void)dealloc {
	[[NSNotificationCenter defaultCenter] removeObserver:self];

	if (history != nil)
		[history release];
	if (auxiliaryWindows != nil)
		[auxiliaryWindows release];

	[super dealloc];
}


- (void)setCPU:(device_t *)device {
	[regView selectSubviewForDevice:device];
	[dasmView selectSubviewForDevice:device];
	[window setTitle:[NSString stringWithFormat:@"Debug: %s - %s '%s'",
												device->machine().system().name,
												device->name(),
												device->tag()]];
}


- (IBAction)doCommand:(id)sender {
	NSString *command = [sender stringValue];
	if ([command length] == 0)
	{
		machine->debugger().console().get_visible_cpu()->debug()->single_step();
		[history reset];
	}
	else
	{
		machine->debugger().console().execute_command([command UTF8String], 1);
		[history add:command];
		[history edit];
	}
	[sender setStringValue:@""];
}


- (IBAction)debugToggleBreakpoint:(id)sender {
	device_t &device = *[dasmView source]->device();
	if ([dasmView cursorVisible] && (machine->debugger().console().get_visible_cpu() == &device))
	{
		offs_t const address = [dasmView selectedAddress];
		const debug_breakpoint *bp = [dasmView source]->device()->debug()->breakpoint_find(address);

		// if it doesn't exist, add a new one
		NSString *command;
		if (bp == nullptr)
			command = [NSString stringWithFormat:@"bpset 0x%lX", (unsigned long)address];
		else
			command = [NSString stringWithFormat:@"bpclear 0x%X", (unsigned)bp->index()];
		machine->debugger().console().execute_command([command UTF8String], 1);
	}
}


- (IBAction)debugToggleBreakpointEnable:(id)sender {
	device_t &device = *[dasmView source]->device();
	if ([dasmView cursorVisible] && (machine->debugger().console().get_visible_cpu() == &device))
	{
		const debug_breakpoint *bp = [dasmView source]->device()->debug()->breakpoint_find([dasmView selectedAddress]);
		if (bp != nullptr)
		{
			NSString *command;
			if (bp->enabled())
				command = [NSString stringWithFormat:@"bpdisable 0x%X", (unsigned)bp->index()];
			else
				command = [NSString stringWithFormat:@"bpenable 0x%X", (unsigned)bp->index()];
			machine->debugger().console().execute_command([command UTF8String], 1);
		}
	}
}


- (IBAction)debugRunToCursor:(id)sender {
	device_t &device = *[dasmView source]->device();
	if ([dasmView cursorVisible] && (machine->debugger().console().get_visible_cpu() == &device))
	{
		NSString *command = [NSString stringWithFormat:@"go 0x%lX", (unsigned long)[dasmView selectedAddress]];
		machine->debugger().console().execute_command([command UTF8String], 1);
	}
}


- (IBAction)debugNewMemoryWindow:(id)sender {
	MAMEMemoryViewer *win = [[MAMEMemoryViewer alloc] initWithMachine:*machine console:self];
	[auxiliaryWindows addObject:win];
	[win release];
	[win activate];
}


- (IBAction)debugNewDisassemblyWindow:(id)sender {
	MAMEDisassemblyViewer *win = [[MAMEDisassemblyViewer alloc] initWithMachine:*machine console:self];
	[auxiliaryWindows addObject:win];
	[win release];
	[win activate];
}


- (IBAction)debugNewErrorLogWindow:(id)sender {
	MAMEErrorLogViewer *win = [[MAMEErrorLogViewer alloc] initWithMachine:*machine console:self];
	[auxiliaryWindows addObject:win];
	[win release];
	[win activate];
}


- (IBAction)debugNewPointsWindow:(id)sender{
	MAMEPointsViewer *win = [[MAMEPointsViewer alloc] initWithMachine:*machine console:self];
	[auxiliaryWindows addObject:win];
	[win release];
	[win activate];
}


- (IBAction)debugNewDevicesWindow:(id)sender {
	MAMEDevicesViewer *win = [[MAMEDevicesViewer alloc] initWithMachine:*machine console:self];
	[auxiliaryWindows addObject:win];
	[win release];
	[win activate];
}


- (void)debugNewMemoryWindowForSpace:(address_space *)space device:(device_t *)device expression:(NSString *)expression {
	MAMEMemoryViewer *win = [[MAMEMemoryViewer alloc] initWithMachine:*machine console:self];
	[auxiliaryWindows addObject:win];
	[win release];
	if ([win selectSubviewForSpace:space])
	{
		if (expression != nil)
			[win setExpression:expression];
	}
	else
	{
		[win selectSubviewForDevice:device];
	}
	[win activate];
}


- (void)debugNewDisassemblyWindowForSpace:(address_space *)space device:(device_t *)device expression:(NSString *)expression {
	MAMEDisassemblyViewer *win = [[MAMEDisassemblyViewer alloc] initWithMachine:*machine console:self];
	[auxiliaryWindows addObject:win];
	[win release];
	if ([win selectSubviewForSpace:space])
	{
		if (expression != nil)
			[win setExpression:expression];
	}
	else
	{
		[win selectSubviewForDevice:device];
	}
	[win activate];
}


- (void)debugNewInfoWindowForDevice:(device_t &)device {
	MAMEDeviceInfoViewer *win = [[MAMEDeviceInfoViewer alloc] initWithDevice:device
																	 machine:*machine
																	 console:self];
	[auxiliaryWindows addObject:win];
	[win release];
	[win activate];
}


- (void)showDebugger:(NSNotification *)notification {
	device_t *device = (device_t * )[[[notification userInfo] objectForKey:@"MAMEDebugDevice"] pointerValue];
	if (&device->machine() == machine)
	{
		[self setCPU:device];
		[window makeKeyAndOrderFront:self];
	}
}


- (void)auxiliaryWindowWillClose:(NSNotification *)notification {
	[auxiliaryWindows removeObjectIdenticalTo:[notification object]];
}


- (void)loadConfiguration:(util::xml::data_node const *)parentnode {
	util::xml::data_node const *node = nullptr;
	for (node = parentnode->get_child(osd::debugger::NODE_WINDOW); node; node = node->get_next_sibling(osd::debugger::NODE_WINDOW))
	{
		MAMEDebugWindowHandler *win = nil;
		switch (node->get_attribute_int(osd::debugger::ATTR_WINDOW_TYPE, -1))
		{
		case osd::debugger::WINDOW_TYPE_CONSOLE:
			[self restoreConfigurationFromNode:node];
			break;
		case osd::debugger::WINDOW_TYPE_MEMORY_VIEWER:
			win = [[MAMEMemoryViewer alloc] initWithMachine:*machine console:self];
			break;
		case osd::debugger::WINDOW_TYPE_DISASSEMBLY_VIEWER:
			win = [[MAMEDisassemblyViewer alloc] initWithMachine:*machine console:self];
			break;
		case osd::debugger::WINDOW_TYPE_ERROR_LOG_VIEWER:
			win = [[MAMEErrorLogViewer alloc] initWithMachine:*machine console:self];
			break;
		case osd::debugger::WINDOW_TYPE_POINTS_VIEWER:
			win = [[MAMEPointsViewer alloc] initWithMachine:*machine console:self];
			break;
		case osd::debugger::WINDOW_TYPE_DEVICES_VIEWER:
			win = [[MAMEDevicesViewer alloc] initWithMachine:*machine console:self];
			break;
		case osd::debugger::WINDOW_TYPE_DEVICE_INFO_VIEWER:
			// FIXME: needs device info on init, make another variant
			//win = [[MAMEDeviceInfoViewer alloc] initWithMachine:*machine console:self];
			break;
		default:
			break;
		}
		if (win)
		{
			[auxiliaryWindows addObject:win];
			[win restoreConfigurationFromNode:node];
			[win release];
			[win activate];
		}
	}
}


- (void)saveConfigurationToNode:(util::xml::data_node *)node {
	[super saveConfigurationToNode:node];
	node->set_attribute_int(osd::debugger::ATTR_WINDOW_TYPE, osd::debugger::WINDOW_TYPE_CONSOLE);
	util::xml::data_node *const splits = node->add_child(osd::debugger::NODE_WINDOW_SPLITS, nullptr);
	if (splits)
	{
		splits->set_attribute_float(osd::debugger::ATTR_SPLITS_CONSOLE_STATE,
									[regSplit isSubviewCollapsed:[[regSplit subviews] objectAtIndex:0]]
								  ? 0.0
								  : NSMaxX([[[regSplit subviews] objectAtIndex:0] frame]));
		splits->set_attribute_float(osd::debugger::ATTR_SPLITS_CONSOLE_DISASSEMBLY,
									[dasmSplit isSubviewCollapsed:[[dasmSplit subviews] objectAtIndex:0]]
								  ? 0.0
								  : NSMaxY([[[dasmSplit subviews] objectAtIndex:0] frame]));
	}
	[dasmView saveConfigurationToNode:node];
}


- (void)restoreConfigurationFromNode:(util::xml::data_node const *)node {
	[super restoreConfigurationFromNode:node];
	util::xml::data_node const *const splits = node->get_child(osd::debugger::NODE_WINDOW_SPLITS);
	if (splits)
	{
		[regSplit setPosition:splits->get_attribute_float(osd::debugger::ATTR_SPLITS_CONSOLE_STATE, NSMaxX([[[regSplit subviews] objectAtIndex:0] frame]))
			 ofDividerAtIndex:0];
		[dasmSplit setPosition:splits->get_attribute_float(osd::debugger::ATTR_SPLITS_CONSOLE_DISASSEMBLY, NSMaxY([[[dasmSplit subviews] objectAtIndex:0] frame]))
			  ofDividerAtIndex:0];
	}
	[dasmView restoreConfigurationFromNode:node];
}



- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor {
	if (control == commandField)
		[history edit];

	return YES;
}


- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command {
	if (control == commandField) {
		if (command == @selector(cancelOperation:)) {
			[commandField setStringValue:@""];
			[history reset];
			return YES;
		} else if (command == @selector(moveUp:)) {
			NSString *hist = [history previous:[commandField stringValue]];
			if (hist != nil) {
				[commandField setStringValue:hist];
				[commandField selectText:self];
				[(NSText *)[window firstResponder] setSelectedRange:NSMakeRange([hist length], 0)];
			}
			return YES;
		} else if (command == @selector(moveDown:)) {
			NSString *hist = [history next:[commandField stringValue]];
			if (hist != nil) {
				[commandField setStringValue:hist];
				[commandField selectText:self];
				[(NSText *)[window firstResponder] setSelectedRange:NSMakeRange([hist length], 0)];
			}
			return YES;
		}
	}
	return NO;
}


- (void)windowWillClose:(NSNotification *)notification {
	if ([notification object] == window)
	{
		NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:[NSValue valueWithPointer:machine],
																		@"MAMEDebugMachine",
																		nil];
		[[NSNotificationCenter defaultCenter] postNotificationName:MAMEHideDebuggerNotification
															object:self
														  userInfo:info];
		machine->debugger().console().get_visible_cpu()->debug()->go();
	}
}


- (CGFloat)splitView:(NSSplitView *)sender constrainMinCoordinate:(CGFloat)min ofSubviewAt:(NSInteger)offs {
	return (min < 100) ? 100 : min;
}


- (CGFloat)splitView:(NSSplitView *)sender constrainMaxCoordinate:(CGFloat)max ofSubviewAt:(NSInteger)offs {
	NSSize  sz = [sender bounds].size;
	CGFloat allowed = ([sender isVertical] ? sz.width : sz.height) - 100 - [sender dividerThickness];
	return (max > allowed) ? allowed : max;
}


- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview {
	// allow registers or disassembly to be collapsed, but not console
	return [[sender subviews] indexOfObjectIdenticalTo:subview] == 0;
}


- (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize {
	// This can only deal with a single split, but that's all we use, anyway
	NSRect first, second;
	[sender adjustSubviews];
	first = [[[sender subviews] objectAtIndex:0] frame];
	second = [[[sender subviews] objectAtIndex:1] frame];
	if ([sender isVertical]) {
		if (first.size.width < 100) {
			CGFloat diff = 100 - first.size.width;
			first.size.width = 100;
			second.origin.x += diff;
			second.size.width -= diff;
		} else if (second.size.width < 100) {
			CGFloat diff = 100 - second.size.width;
			second.size.width = 100;
			second.origin.x -= diff;
			first.size.width -= diff;
		}
	} else {
		if (first.size.height < 100) {
			CGFloat diff = 100 - first.size.height;
			first.size.height = 100;
			second.origin.y += diff;
			second.size.height -= diff;
		} else if (second.size.height < 100) {
			CGFloat diff = 100 - second.size.height;
			second.size.height = 100;
			second.origin.y -= diff;
			first.size.height -= diff;
		}
	}
	[[[sender subviews] objectAtIndex:0] setFrame:first];
	[[[sender subviews] objectAtIndex:1] setFrame:second];
}


- (BOOL)validateMenuItem:(NSMenuItem *)item {
	SEL const action = [item action];
	BOOL const inContextMenu = ([item menu] == [dasmView menu]);
	BOOL const haveCursor = [dasmView cursorVisible];
	BOOL const isCurrent = (machine->debugger().console().get_visible_cpu() == [dasmView source]->device());

	const debug_breakpoint *breakpoint = nullptr;
	if (haveCursor)
	{
		breakpoint = [dasmView source]->device()->debug()->breakpoint_find([dasmView selectedAddress]);
	}

	if (action == @selector(debugToggleBreakpoint:))
	{
		if (haveCursor)
		{
			if (breakpoint != nullptr)
			{
				if (inContextMenu)
					[item setTitle:@"Clear Breakpoint"];
				else
					[item setTitle:@"Clear Breakpoint at Cursor"];
			}
			else
			{
				if (inContextMenu)
					[item setTitle:@"Set Breakpoint"];
				else
					[item setTitle:@"Set Breakpoint at Cursor"];
			}
		}
		else
		{
			if (inContextMenu)
				[item setTitle:@"Toggle Breakpoint"];
			else
				[item setTitle:@"Toggle Breakpoint at Cursor"];
		}
		return haveCursor && isCurrent;
	}
	else if (action == @selector(debugToggleBreakpointEnable:))
	{
		if ((breakpoint != nullptr) && !breakpoint->enabled())
		{
			if (inContextMenu)
				[item setTitle:@"Enable Breakpoint"];
			else
				[item setTitle:@"Enable Breakpoint at Cursor"];
		}
		else
		{
			if (inContextMenu)
				[item setTitle:@"Disable Breakpoint"];
			else
				[item setTitle:@"Disable Breakpoint at Cursor"];
		}
		return (breakpoint != nullptr) && isCurrent;
	}
	else if (action == @selector(debugRunToCursor:))
	{
		return isCurrent;
	}
	else
	{
		return YES;
	}
}

@end