Join/Login

Business Software

Open Source Software

For Vendors

Blog

About

More

Articles

Create

SourceForge Podcast

Site Documentation

Subscribe to our Newsletter

Support Request

For Vendors Help Create Join Login

Business Software

Open Source Software

SourceForge Podcast

Resources

Articles

Case Studies

Blog

Menu

Help

Create

Join

Login

Home

Browse

Fuse for macOS

FuseGenerator

Fuse for macOS FuseGenerator

Brought to you by: fredm

Summary

Files

Reviews

Support

Mailing Lists

Tickets ▾

Bugs

Feature Requests

News

Discussion

Git ▾

libspectrum

FuseImporter

FuseGenerator

audiofile

libgcrypt

fuse

Fuse for macOS

Code

Menu ▾ ▴

Browse Commits

Fork

Merge Requests 0

Branches

master

[313809]: / JWSpectrumScreen / JWSpectrumScreen.m  Maximize  Restore  History

Download this file

280 lines (240 with data), 7.0 kB

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

//

// JWSpectrumScreen.m

// Mac2SpecQLPlugin

//

// Created by James Weatherley on 09/11/2007.

// Copyright 2007 James Weatherley. All rights reserved.

//

#import "JWSpectrumScreen.h"

#import "ColourMacros.h"

typedef struct BitmapOffsets {

int bitmapOffset;

int attrOffset;

} BitmapOffsets;

// Internal method to get the offsets for the bitmap and attribute

// for a byte in the Spectrum screen file.

BitmapOffsets bitmapOffsets(int x, int y, ScreenMode mode);

@implementation JWSpectrumScreen

- (BOOL)initialise:(int)mltHint

{

if(zxScreen) {

if([zxScreen length] == SCREEN_STANDARD_BYTES) {

canvasSize.width = SCREEN_STANDARD_WIDTH;

canvasSize.height = SCREEN_STANDARD_HEIGHT;

mode = ScreenModeSinclair;

} else if([zxScreen length] == SCREEN_TIMEX_HI_COL_BYTES) {

canvasSize.width = SCREEN_STANDARD_WIDTH;

canvasSize.height = SCREEN_STANDARD_HEIGHT;

mode = ScreenModeTimexHiCol;

if(mltHint) {

mode = ScreenModeMLT;

}

} else if([zxScreen length] == SCREEN_TIMEX_HI_RES_BYTES) {

canvasSize.width = SCREEN_TIMEX_HIRES_WIDTH;

canvasSize.height = SCREEN_STANDARD_HEIGHT * 2;

mode = ScreenModeTimexHiRes;

} else {

// Invalid length.

return NO;

}

return YES;

}

return NO;

}

- (id)initFromData:(NSData*)scrData mltHint:(int)mltHint

{

self = [super init];

if(self) {

zxScreen = [[NSMutableData alloc] init];

[zxScreen setData:scrData];

if( [self initialise:mltHint] == NO ) {

NSLog( @"JWSpectrumScreen: initFromData : Some problem with the source scrData.\n" );

// Some problem with the source scrData.

[self release];

self = nil;

}

}

return self;

}

- (NSBitmapImageRep*)imageRep

{

NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:0

pixelsWide:canvasSize.width

pixelsHigh:canvasSize.height

bitsPerSample:8

samplesPerPixel:3

hasAlpha:NO

isPlanar:NO

colorSpaceName:NSDeviceRGBColorSpace

bytesPerRow:canvasSize.width * 3

bitsPerPixel:24];

if(imageRep) {

unsigned char* imageBytes = [imageRep bitmapData];

BitmapByteData bitmapByteData;

for(int y = 0; y < canvasSize.height; ++y) {

for(int x = 0; x < canvasSize.width; x += 8) {

bitmapByteData = [self bitmapByteDataAtX:x y:y];

for(int bit = 0; bit < 8; ++bit) {

unsigned char mask = 1 << (7 - bit);

int colour;

if(bitmapByteData.bitmapByte & mask) {

colour = spectrumColourFromIndex(bitmapByteData.ink);

} else {

colour = spectrumColourFromIndex(bitmapByteData.paper);

}

*imageBytes++ = RED(colour);

*imageBytes++ = GREEN(colour);

*imageBytes++ = BLUE(colour);

}

}

}

}

return [imageRep autorelease];

}

- (BitmapByteData)bitmapByteDataAtX:(int)x y:(int)y

{

// x must be byte aligned.

// x and y must be within the canvas.

assert(x % 8 == 0);

assert(x < canvasSize.width);

assert(y < canvasSize.height);

const char* bitmapBytes = [zxScreen bytes];

BitmapByteData data;

BitmapOffsets offsets = bitmapOffsets(x, y, mode);

data.bitmapByte = bitmapBytes[offsets.bitmapOffset];

if(mode == ScreenModeSinclair || mode == ScreenModeTimexHiCol || mode == ScreenModeMLT) {

char attribute = bitmapBytes[offsets.attrOffset];

bool bright = attribute & (1 << 6);

int ink = attribute & 0x7;

int paper = (attribute & (0x7 << 3)) >> 3;

if(bright) {

if(ink) {

ink += 7;

}

if(paper) {

paper += 7;

}

}

data.ink = ink;

data.paper = paper;

} else if(mode == ScreenModeTimexHiRes) {

int outValue = bitmapBytes[SCREEN_TIMEX_HI_RES_BYTES - 1];

// Mask out the non-colour related bits

outValue &= 0x38;

switch(outValue) {

case TimexHiResBlackWhite:

data.ink = spectrumIndexFromRGB(SPEC_BLACK);

data.paper = spectrumIndexFromRGB(SPEC_BRIGHT_WHITE);

break;

case TimexHiResBlueYellow:

data.ink = spectrumIndexFromRGB(SPEC_BRIGHT_BLUE);

data.paper = spectrumIndexFromRGB(SPEC_BRIGHT_YELLOW);

break;

case TimexHiResRedCyan:

data.ink = spectrumIndexFromRGB(SPEC_BRIGHT_RED);

data.paper = spectrumIndexFromRGB(SPEC_BRIGHT_CYAN);

break;

case TimexHiResMagentaGreen:

data.ink = spectrumIndexFromRGB(SPEC_BRIGHT_MAGENTA);

data.paper = spectrumIndexFromRGB(SPEC_BRIGHT_GREEN);

break;

case TimexHiResGreenMagenta:

data.ink = spectrumIndexFromRGB(SPEC_BRIGHT_GREEN);

data.paper = spectrumIndexFromRGB(SPEC_BRIGHT_MAGENTA);

break;

case TimexHiResCyanRed:

data.ink = spectrumIndexFromRGB(SPEC_BRIGHT_CYAN);

data.paper = spectrumIndexFromRGB(SPEC_BRIGHT_RED);

break;

case TimexHiResYellowBlue:

data.ink = spectrumIndexFromRGB(SPEC_BRIGHT_YELLOW);

data.paper = spectrumIndexFromRGB(SPEC_BRIGHT_BLUE);

break;

case TimexHiResWhiteBlack:

data.ink = spectrumIndexFromRGB(SPEC_BRIGHT_WHITE);

data.paper = spectrumIndexFromRGB(SPEC_BLACK);

break;

default:

NSLog(@"JWSpectrumScreen: unknown attribute:%d\n", outValue);

assert(0);

}

} else {

// WTF?

assert(0);

}

return data;

}

- (BOOL)saveScrFile:(NSURL*)url

{

BOOL success = NO;

if([zxScreen length]) {

success = [zxScreen writeToURL:url atomically:NO];

}

return success;

}

- (NSSize)canvasSize

{

return canvasSize;

}

- (ScreenMode)mode

{

return mode;

}

- (void)dealloc

{

[zxScreen release];

[super dealloc];

}

@end

BitmapOffsets bitmapOffsets(int x, int y, ScreenMode mode)

{

BitmapOffsets offsets = {0, 0};

int attrX = x / 8;

int attrY = 0;

int attrRows = 0;

int screenThird = 0;

int attrRowInThird = 0;

int rowInAttr = 0;

if(mode == ScreenModeSinclair || mode == ScreenModeTimexHiCol || mode == ScreenModeMLT) {

if(mode == ScreenModeSinclair) {

attrY = y / 8;

attrRows = SCREEN_STANDARD_HEIGHT / 8;

screenThird = 3 * attrY / attrRows;

attrRowInThird = attrY % 8;

} else {

attrY = y;

attrRows = SCREEN_STANDARD_HEIGHT;

screenThird = 3 * y / attrRows;

attrRowInThird = y / 8 % 8;

}

rowInAttr = y % 8;

offsets.bitmapOffset = 0x800 * screenThird;

offsets.bitmapOffset += 0x20 * attrRowInThird;

offsets.bitmapOffset += 0x100 * rowInAttr;

offsets.bitmapOffset += attrX;

if(mode == ScreenModeSinclair || mode == ScreenModeMLT) {

offsets.attrOffset = SCREEN_BITMAP_SIZE + attrX + attrY * SCREEN_STANDARD_WIDTH / 8;

} else {

offsets.attrOffset = SCREEN_BITMAP_SIZE + offsets.bitmapOffset;

}

} else if(mode == ScreenModeTimexHiRes) {

y /= 2;

attrRows = SCREEN_STANDARD_HEIGHT;

screenThird = 3 * y / attrRows;

attrRowInThird = y / 8 % 8;

rowInAttr = y % 8;

offsets.bitmapOffset = 0x800 * screenThird;

offsets.bitmapOffset += 0x20 * attrRowInThird;

offsets.bitmapOffset += 0x100 * rowInAttr;

if(attrX & 1) {

offsets.bitmapOffset += SCREEN_BITMAP_SIZE;

offsets.bitmapOffset += (attrX - 1) / 2;

} else {

offsets.bitmapOffset += attrX / 2;

}

} else {

// WTF?

assert(0);

}

return offsets;

}

SourceForge

Create a Project

Open Source Software

Business Software

Top Downloaded Projects

Company

About

Team

SourceForge Headquarters
225 Broadway Suite 1600
San Diego, CA 92101
+1 (858) 422-6466

Resources

Support

Site Documentation

Site Status

SourceForge Reviews

© 2025 Slashdot Media. All Rights Reserved.

Terms Privacy Opt Out Advertise

×
Want the latest updates on software, tech news, and AI?

Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.

Submit