git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit d211120312c534ac082464c23c95a4a4a070eb49
parent 6ab1be654b4e56db1028b6f5faa1d67543623d2d
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Sat,  7 Jun 2025 14:11:10 +0300

Make 100% CPU frames appear red

Diffstat:
MCocoa/Document.xib12++++++------
MCocoa/GBCPUView.m99++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
2 files changed, 89 insertions(+), 22 deletions(-)

diff --git a/Cocoa/Document.xib b/Cocoa/Document.xib @@ -323,19 +323,19 @@ <rect key="frame" x="0.0" y="0.0" width="329" height="77"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> <subviews> - <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xdx-GC-Tb8"> - <rect key="frame" x="225" y="56" width="100" height="16"/> + <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="F9b-AT-CdX"> + <rect key="frame" x="2" y="59" width="100" height="16"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> - <textFieldCell key="cell" lineBreakMode="clipping" alignment="right" title="100%" id="set-AM-fVX"> + <textFieldCell key="cell" lineBreakMode="clipping" title="CPU Load" id="ai6-8E-Let"> <font key="font" metaFont="smallSystemBold"/> <color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> </textFieldCell> </textField> - <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="F9b-AT-CdX"> - <rect key="frame" x="4" y="56" width="100" height="16"/> + <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xdx-GC-Tb8"> + <rect key="frame" x="2" y="2" width="100" height="16"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/> - <textFieldCell key="cell" lineBreakMode="clipping" title="CPU Load" id="ai6-8E-Let"> + <textFieldCell key="cell" lineBreakMode="clipping" alignment="left" title="100%" id="set-AM-fVX"> <font key="font" metaFont="smallSystemBold"/> <color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> diff --git a/Cocoa/GBCPUView.m b/Cocoa/GBCPUView.m @@ -10,41 +10,108 @@ - (void)drawRect:(NSRect)dirtyRect { - NSSize size = self.bounds.size; + CGRect bounds = self.bounds; + NSSize size = bounds.size; + unsigned factor = [[self.window screen] backingScaleFactor]; + NSBitmapImageRep *maskBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL + pixelsWide:(unsigned)size.width * factor + pixelsHigh:(unsigned)size.height * factor + bitsPerSample:8 + samplesPerPixel:2 + hasAlpha:true + isPlanar:false + colorSpaceName:NSDeviceWhiteColorSpace + bytesPerRow:size.width * 2 * factor + bitsPerPixel:16]; + + + + NSGraphicsContext *mainContext = [NSGraphicsContext currentContext]; + + + NSColor *greenColor, *redColor; + if (@available(macOS 10.10, *)) { + greenColor = [NSColor systemGreenColor]; + redColor = [NSColor systemRedColor]; + } + else { + greenColor = [NSColor colorWithRed:3.0 / 16 green:0.5 blue:5.0 / 16 alpha:1.0]; + redColor = [NSColor colorWithRed:13.0 / 16 green:0.25 blue:0.25 alpha:1.0]; + } + + + NSBitmapImageRep *colorBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL + pixelsWide:SAMPLE_COUNT + pixelsHigh:1 + bitsPerSample:8 + samplesPerPixel:3 + hasAlpha:false + isPlanar:false + colorSpaceName:NSDeviceRGBColorSpace + bytesPerRow:SAMPLE_COUNT * 4 + bitsPerPixel:32]; + + unsigned lastFill = 0; NSBezierPath *line = [NSBezierPath bezierPath]; + bool isRed = false; { double sample = _samples[_position % SAMPLE_COUNT]; - [line moveToPoint:NSMakePoint(size.width * 0.5 / SAMPLE_COUNT, - sample * size.height)]; + [line moveToPoint:NSMakePoint(0, + (sample * (size.height - 1) + 0.5) * factor)]; + isRed = sample == 1; } + + [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:colorBitmap]]; for (unsigned i = 1; i < SAMPLE_COUNT; i++) { double sample = _samples[(i + _position) % SAMPLE_COUNT]; - [line lineToPoint:NSMakePoint(size.width * (i + 0.5) / SAMPLE_COUNT, - sample * size.height)]; + [line lineToPoint:NSMakePoint(size.width * i * factor / (SAMPLE_COUNT - 1), + (sample * (size.height - 1) + 0.5) * factor)]; + + if (isRed != (sample == 1)) { + // Color changed + [(isRed? redColor : greenColor) setFill]; + NSRectFill(CGRectMake(lastFill, 0, i - lastFill, 1)); + lastFill = i; + + isRed ^= true; + } } + [(isRed? redColor : greenColor) setFill]; + NSRectFill(CGRectMake(lastFill, 0, SAMPLE_COUNT - lastFill, 1)); NSBezierPath *fill = [line copy]; - [fill lineToPoint:NSMakePoint(size.width + 0.5, 0)]; - [fill lineToPoint:NSMakePoint(0.5, 0)]; + [fill lineToPoint:NSMakePoint(size.width * factor, 0)]; + [fill lineToPoint:NSMakePoint(0, 0)]; - NSColor *strokeColor; - if (@available(macOS 10.10, *)) { - strokeColor = [NSColor systemGreenColor]; - } - else { - strokeColor = [NSColor colorWithRed:3.0 / 16 green:0.5 blue:5.0 / 16 alpha:1.0]; - } + NSColor *strokeColor = [NSColor whiteColor]; NSColor *fillColor = [strokeColor colorWithAlphaComponent:1 / 3.0]; + [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:maskBitmap]]; [fillColor setFill]; [fill fill]; - [strokeColor setStroke]; + [line setLineWidth:factor]; [line stroke]; - + + CGContextRef maskContext = CGContextRetain([NSGraphicsContext currentContext].graphicsPort); + [NSGraphicsContext setCurrentContext:mainContext]; + CGContextSaveGState(mainContext.graphicsPort); + + CGImageRef maskImage = CGBitmapContextCreateImage(maskContext); + CGContextClipToMask(mainContext.graphicsPort, bounds, maskImage); + CGImageRelease(maskImage); + + NSImage *colors = [[NSImage alloc] initWithSize:NSMakeSize(SAMPLE_COUNT, 1)]; + [colors addRepresentation:colorBitmap]; + [colors drawInRect:bounds]; + + CGContextRestoreGState(mainContext.graphicsPort); + CGContextRelease(maskContext); + + [super drawRect:dirtyRect]; }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.