- HIRESLOWCOLOR -- Color Hires Implementation

This commit is contained in:
Tamas Rudnai 2020-02-25 00:14:05 -08:00
parent 44debeb2d1
commit 206b5a1163
6 changed files with 180 additions and 12 deletions

View File

@ -1206,7 +1206,7 @@
"-DINTERRUPT_CHECK_PER_STEP",
"-DCLK_ABSOLUTE_PRECISE",
);
OTHER_SWIFT_FLAGS = "-DHIRES -DHIRESDRAW -D_NO_HIRESLOW";
OTHER_SWIFT_FLAGS = "-DHIRES -D_NO_HIRESDRAW -D_NO_HIRESLOW -DHIRESLOWCOLOR";
PRODUCT_BUNDLE_IDENTIFIER = com.gamealloy.A2Mac;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
@ -1242,7 +1242,7 @@
"-DINTERRUPT_CHECK_PER_STEP",
"-DCLK_ABSOLUTE_PRECISE",
);
OTHER_SWIFT_FLAGS = "-DHIRES -DHIRESDRAW -D_NO_HIRESLOW";
OTHER_SWIFT_FLAGS = "-DHIRES -D_NO_HIRESDRAW -D_NO_HIRESLOW -DHIRESLOWCOLOR";
PRODUCT_BUNDLE_IDENTIFIER = com.gamealloy.A2Mac;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "A2Mac/A2Mac-Bridging-Header.h";

View File

@ -626,6 +626,12 @@
<action selector="Disk1_Selected:" target="Voe-Tx-rLC" id="c8a-9v-oR4"/>
</connections>
</menuItem>
<menuItem title="Sneakers" identifier="Sneakers" id="iAb-YK-Q8d">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="Disk1_Selected:" target="Voe-Tx-rLC" id="zhC-rp-mN0"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
@ -797,6 +803,11 @@
<customView canDrawConcurrently="YES" translatesAutoresizingMaskIntoConstraints="NO" id="LlM-EV-ruZ" customClass="HiRes" customModule="A2Mac" customModuleProvider="target">
<rect key="frame" x="16" y="8" width="568" height="384"/>
</customView>
<imageView hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="M1E-lz-4q8">
<rect key="frame" x="20" y="8" width="564" height="382"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<imageCell key="cell" enabled="NO" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyUpOrDown" image="NSQuickLookTemplate" id="Zax-kI-rxd"/>
</imageView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="mfd-12-bcR">
<rect key="frame" x="594" y="362" width="82" height="32"/>
<constraints>
@ -989,4 +1000,7 @@
<point key="canvasLocation" x="241" y="1071"/>
</scene>
</scenes>
<resources>
<image name="NSQuickLookTemplate" width="19" height="12"/>
</resources>
</document>

View File

@ -142,7 +142,7 @@ class HiRes: NSView {
scaleUnitSquare(to: NSSize(width: scaleSizeW, height: scaleSizeH))
// create smaller box views for draw optimization
//createHiRes()
createHiRes()
#if METAL_YES
initMetal()
@ -385,7 +385,7 @@ class HiRes: NSView {
}
}
#if HIRESLOW
#if HIRESLOW || HIRESLOWCOLOR
static let ScreenBitmapSize = (PixelWidth * PixelHeight * 4)
static let context = createBitmapContext(pixelsWide: PixelWidth, PixelHeight)
static let pixels = UnsafeMutableRawBufferPointer(start: context?.data, count: ScreenBitmapSize) // UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: byteCount)
@ -439,7 +439,7 @@ class HiRes: NSView {
HiRes.pixels[pixelAddr + R] = 0x08;
HiRes.pixels[pixelAddr + G] = 0xA2;
HiRes.pixels[pixelAddr + B] = 0x12;
HiRes.pixels[pixelAddr + A] = 0x7F;
HiRes.pixels[pixelAddr + A] = 0xFF;
}
if ( minX > x ) { minX = x }
@ -465,6 +465,149 @@ class HiRes: NSView {
let boundingBox = CGRect(x: 0, y: 0, width: CGFloat(HiRes.PixelWidth), height: CGFloat(HiRes.PixelHeight))
currentContext!.draw (image, in: boundingBox)
}
#elseif HIRESLOWCOLOR
func hiresColorPixel ( pixelAddr : Int, pixel : Int ) {
switch ( pixel ) {
case 0x00: // black
HiRes.pixels[pixelAddr + R] = 0x00;
HiRes.pixels[pixelAddr + G] = 0x00;
HiRes.pixels[pixelAddr + B] = 0x00;
HiRes.pixels[pixelAddr + A] = 0x00;
case 0x01: // purple (bits are in reverse!)
HiRes.pixels[pixelAddr + R] = 0xBB;
HiRes.pixels[pixelAddr + G] = 0x11;
HiRes.pixels[pixelAddr + B] = 0xEE;
HiRes.pixels[pixelAddr + A] = 0xFF;
case 0x02: // green
HiRes.pixels[pixelAddr + R] = 0x08;
HiRes.pixels[pixelAddr + G] = 0xA2;
HiRes.pixels[pixelAddr + B] = 0x12;
HiRes.pixels[pixelAddr + A] = 0xFF;
case 0x03: // white
HiRes.pixels[pixelAddr + R] = 0xFF;
HiRes.pixels[pixelAddr + G] = 0xFF;
HiRes.pixels[pixelAddr + B] = 0xFF;
HiRes.pixels[pixelAddr + A] = 0xFF;
case 0x04: // black 2
HiRes.pixels[pixelAddr + R] = 0x00;
HiRes.pixels[pixelAddr + G] = 0x00;
HiRes.pixels[pixelAddr + B] = 0x00;
HiRes.pixels[pixelAddr + A] = 0x00;
case 0x05: // blue
HiRes.pixels[pixelAddr + R] = 0x11;
HiRes.pixels[pixelAddr + G] = 0x66;
HiRes.pixels[pixelAddr + B] = 0xEE;
HiRes.pixels[pixelAddr + A] = 0xFF;
case 0x06: // orange
HiRes.pixels[pixelAddr + R] = 0xEE;
HiRes.pixels[pixelAddr + G] = 0x22;
HiRes.pixels[pixelAddr + B] = 0x11;
HiRes.pixels[pixelAddr + A] = 0xFF;
case 0x07: // white 2
HiRes.pixels[pixelAddr + R] = 0xFF;
HiRes.pixels[pixelAddr + G] = 0xFF;
HiRes.pixels[pixelAddr + B] = 0xFF;
HiRes.pixels[pixelAddr + A] = 0xFF;
default:
HiRes.pixels[pixelAddr + R] = 0x00;
HiRes.pixels[pixelAddr + G] = 0x00;
HiRes.pixels[pixelAddr + B] = 0x00;
HiRes.pixels[pixelAddr + A] = 0x00;
}
}
override func draw(_ rect: CGRect) {
// print("HIRESSLOW\n")
// if was > 100 {
// return
// }
// was += 1
var pixelAddr = 0
var minX = 9999
var minY = 9999
var maxX = 0
var maxY = 0
var x = 0
var y = 0
for lineAddr in HiResLineAddrTbl {
for blockAddr in 0 ..< HiRes.blockCols / 2 {
let blockH = Int(HiResBufferPointer[ Int(lineAddr + blockAddr * 2) ])
let blockH7 = ( blockH >> 5 ) & 0x04
let blockL = Int(HiResBufferPointer[ Int(lineAddr + blockAddr * 2) + 1 ])
let blockL7 = ( blockL >> 5 ) & 0x04
let block = ( blockL << 7 ) | ( blockH & 0x7F ) & 0x3FFF
let screenIdx = y * HiRes.blockCols + x
// if ( shadowScreen[ screenIdx ] != block ) {
shadowScreen[ screenIdx ] = block
for px in 0 ... 2 {
// let bitMask = 3 << ( px * 2 )
hiresColorPixel(pixelAddr: pixelAddr, pixel: ( blockH7 | ( (block >> (px * 2)) & 3 ) ) )
pixelAddr += 4
hiresColorPixel(pixelAddr: pixelAddr, pixel: ( blockH7 | ( (block >> (px * 2)) & 3 ) ) )
pixelAddr += 4
// if ( minX > x ) { minX = x }
// if ( minY > y ) { minY = y }
// if ( maxX < x ) { maxX = x }
// if ( maxY < y ) { maxY = y }
//
// x += 2
}
hiresColorPixel(pixelAddr: pixelAddr, pixel: ( blockH7 | ( (block >> (3 * 2)) & 3 ) ) )
pixelAddr += 4
hiresColorPixel(pixelAddr: pixelAddr, pixel: ( blockL7 | ( (block >> (3 * 2)) & 3 ) ) )
pixelAddr += 4
for px in 4 ... 6 {
// let bitMask = 3 << ( px * 2 )
hiresColorPixel(pixelAddr: pixelAddr, pixel: ( blockL7 | ( (block >> (px * 2)) & 3 ) ) )
pixelAddr += 4
hiresColorPixel(pixelAddr: pixelAddr, pixel: ( blockL7 | ( (block >> (px * 2)) & 3 ) ) )
pixelAddr += 4
// if ( minX > x ) { minX = x }
// if ( minY > y ) { minY = y }
// if ( maxX < x ) { maxX = x }
// if ( maxY < y ) { maxY = y }
//
// x += 2
}
// }
// else {
// pixelAddr += 4 * 7
// x += 7
// }
}
y += 1
x = 0
}
guard let image = HiRes.context?.makeImage() else { return }
let boundingBox = CGRect(x: 0, y: 0, width: CGFloat(HiRes.PixelWidth), height: CGFloat(HiRes.PixelHeight))
currentContext!.draw (image, in: boundingBox)
}
#elseif HIRESDRAWCOLOR
let colorPalette : [NSColor] = [
@ -672,7 +815,7 @@ class HiRes: NSView {
blockNeedsDisplay = true
var x = blockX * HiRes.blockWidth
for bit in stride(from: 0, through: 6, by: 1) {
for bit in 0 ... 6 { // stride(from: 0, through: 6, by: 1) {
let bitMask = 1 << bit
if (block & bitMask) == 0 {
pixels[pixelAddr + R] = 0x00;

View File

@ -36,7 +36,7 @@ unsigned long long int inst_cnt = 0;
//const unsigned int fps = 30;
const unsigned long long default_MHz_6502 = 1.023 * M; // 2 * M; // 4 * M; // 8 * M; // 16 * M; // 128 * M; // 256 * M; // 512 * M;
unsigned long long MHz_6502 = default_MHz_6502;
unsigned long long clk_6502_per_frm = default_MHz_6502 / fps;
unsigned long long clk_6502_per_frm = 25 * M; //default_MHz_6502 / fps;
unsigned long long clk_6502_per_frm_set = default_MHz_6502 / fps;
@ -804,9 +804,13 @@ void m6502_Run() {
}
// if ( m6502.clktime - disk.clk_last_access > clk_diskAcceleratorTimeout ) {
clk_6502_per_frm = clk_6502_per_frm_set;
// }
if( diskAccelerator_count ) {
if( --diskAccelerator_count <= 0 ) {
// make sure we only adjust clock once to get back to normal
diskAccelerator_count = 0;
clk_6502_per_frm = clk_6502_per_frm_set;
}
}
// clock_t end = clock();

View File

@ -17,7 +17,9 @@ disk_t disk = {
0, // clk_since_last_read
};
int diskAccelerator_speed = 25; // 0 means no acceleration
const int diskAccelerator_frames = 2;
int diskAccelerator_count = 10;
int diskAccelerator_speed = 25; // less than actual CPU speed means no acceleration
//const unsigned long long clk_6502_per_frm_diskAccelerator = 25 * M / fps; // disk acceleration bumps up CPU clock to 25 MHz
//const unsigned long long clk_diskAcceleratorTimeout = 1000ULL;
@ -65,6 +67,7 @@ void disk_phase() {
if ( diskAccelerator_speed > clk_6502_per_frm ) {
// clk_6502_per_frm = clk_6502_per_frm_diskAccelerator;
clk_6502_per_frm = diskAccelerator_speed * M / fps; // clk_6502_per_frm_diskAccelerator;
diskAccelerator_count = diskAccelerator_frames;
}
}
@ -81,6 +84,7 @@ uint8_t disk_read() {
disk.clk_last_access = m6502.clktime;
if ( diskAccelerator_speed > 2 ) {
clk_6502_per_frm = diskAccelerator_speed * M / fps; // clk_6502_per_frm_diskAccelerator;
diskAccelerator_count = diskAccelerator_frames;
}
return woz_read();

View File

@ -53,7 +53,10 @@ extern disk_t disk;
extern const int magnet_to_Poistion[16];
extern const int position_to_direction[8][8];
extern int diskAccelerator_speed; // 0 means no acceleration
extern const int diskAccelerator_frames; // number of frames disk acceleration will be on
extern int diskAccelerator_count; // counter for the disk acceleration frames
extern int diskAccelerator_speed; // if less than the actual CPU speed, no acceleration
//extern const unsigned long long clk_6502_per_frm_diskAccelerator;
//extern const unsigned long long clk_diskAcceleratorTimeout;