SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
Cocoa/GBObjectView.m
1 #import "GBObjectView.h"
2
3 @interface GBObjectViewItem : NSObject
4 @property IBOutlet NSView *view;
5 @property IBOutlet NSImageView *image;
6 @property IBOutlet NSTextField *oamAddress;
7 @property IBOutlet NSTextField *position;
8 @property IBOutlet NSTextField *attributes;
9 @property IBOutlet NSTextField *tile;
10 @property IBOutlet NSTextField *tileAddress;
11 @property IBOutlet NSImageView *warningIcon;
12 @property IBOutlet NSBox *verticalLine;
13 @end
14
15 @implementation GBObjectViewItem
16 {
17 @public
18 uint32_t _lastImageData[128];
19 uint8_t _lastHeight;
20 }
21 @end
22
23 @implementation GBObjectView
24 {
25 NSMutableArray<GBObjectViewItem *> *_items;
26 }
27
28 - (instancetype)initWithCoder:(NSCoder *)coder
29 {
30 self = [super initWithCoder:coder];
31 _items = [NSMutableArray array];
32 CGFloat height = self.frame.size.height;
33 for (unsigned i = 0; i < 40; i++) {
34 GBObjectViewItem *item = [[GBObjectViewItem alloc] init];
35 [_items addObject:item];
36 [[NSBundle mainBundle] loadNibNamed:@"GBObjectViewItem" owner:item topLevelObjects:nil];
37 item.view.hidden = true;
38 [self addSubview:item.view];
39 [item.view setFrameOrigin:NSMakePoint((i % 4) * 120, height - (i / 4 * 68) - 68)];
40 item.oamAddress.toolTip = @"OAM address";
41 item.position.toolTip = @"Position";
42 item.attributes.toolTip = @"Attributes";
43 item.tile.toolTip = @"Tile index";
44 item.tileAddress.toolTip = @"Tile address";
45 item.warningIcon.toolTip = @"Dropped: too many objects in line";
46 if ((i % 4) == 3) {
47 [item.verticalLine removeFromSuperview];
48 }
49 item.view.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin;
50 }
51 return self;
52 }
53
54 - (void)reloadData:(Document *)document
55 {
56 GB_oam_info_t *info = document.oamInfo;
57 uint8_t length = document.oamCount;
58 bool cgb = GB_is_cgb(document.gb);
59 uint8_t height = document.oamHeight;
60 NSFont *font = [document debuggerFontOfSize:11];
61 NSFont *boldFont = [[NSFontManager sharedFontManager] convertFont:font toHaveTrait:NSBoldFontMask];
62
63 for (unsigned i = 0; i < 40; i++) {
64 GBObjectViewItem *item = _items[i];
65 if (i >= length) {
66 item.view.hidden = true;
67 }
68 else {
69 item.view.hidden = false;
70
71 item.oamAddress.font = boldFont;
72 item.position.font = font;
73 item.attributes.font = font;
74 item.tile.font = font;
75 item.tileAddress.font = font;
76
77 item.oamAddress.stringValue = [NSString stringWithFormat:@"$%04X", info[i].oam_addr];
78 item.position.stringValue = [NSString stringWithFormat:@"(%d, %d)",
79 ((signed)(unsigned)info[i].x) - 8,
80 ((signed)(unsigned)info[i].y) - 16];
81 item.tile.stringValue = [NSString stringWithFormat:@"$%02X", info[i].tile];
82 item.tileAddress.stringValue = [NSString stringWithFormat:@"$%04X", 0x8000 + info[i].tile * 0x10];
83 item.warningIcon.hidden = !info[i].obscured_by_line_limit;
84 if (cgb) {
85 item.attributes.stringValue = [NSString stringWithFormat:@"%c%c%c%d%d",
86 info[i].flags & 0x80? 'P' : '-',
87 info[i].flags & 0x40? 'Y' : '-',
88 info[i].flags & 0x20? 'X' : '-',
89 info[i].flags & 0x08? 1 : 0,
90 info[i].flags & 0x07];
91 }
92 else {
93 item.attributes.stringValue = [NSString stringWithFormat:@"%c%c%c%d",
94 info[i].flags & 0x80? 'P' : '-',
95 info[i].flags & 0x40? 'Y' : '-',
96 info[i].flags & 0x20? 'X' : '-',
97 info[i].flags & 0x10? 1 : 0];
98 }
99 size_t imageSize = 8 * 4 * height;
100 if (height == item->_lastHeight && memcmp(item->_lastImageData, info[i].image, imageSize) == 0) {
101 continue;
102 }
103 memcpy(item->_lastImageData, info[i].image, imageSize);
104 item->_lastHeight = height;
105 item.image.image = [Document imageFromData:[NSData dataWithBytesNoCopy:info[i].image
106 length:64 * 4 * 2
107 freeWhenDone:false]
108 width:8
109 height:height
110 scale:32.0 / height];
111 }
112 }
113
114 NSRect frame = self.frame;
115 CGFloat newHeight = MAX(68 * ((length + 3) / 4), self.superview.frame.size.height);
116 frame.origin.y -= newHeight - frame.size.height;
117 frame.size.height = newHeight;
118 self.frame = frame;
119 }
120
121 - (void)drawRect:(NSRect)dirtyRect
122 {
123 if (@available(macOS 10.14, *)) {
124 [[NSColor alternatingContentBackgroundColors].lastObject setFill];
125 }
126 else {
127 [[NSColor colorWithDeviceWhite:0.96 alpha:1] setFill];
128 }
129 NSRect frame = self.frame;
130 for (unsigned i = 1; i <= 5; i++) {
131 NSRectFill(NSMakeRect(0, frame.size.height - i * 68 * 2, frame.size.width, 68));
132 }
133 }
134 @end
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.