-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenScreen.c
255 lines (193 loc) · 5.32 KB
/
OpenScreen.c
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
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/layers.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/diskfont.h>
#include <exec/emulation.h>
#include <graphics/modeid.h>
#include "common.h"
#include "modeid.h"
#include "helper/screen.h"
void initColors( struct ViewPort *vp)
{
struct ColorMap *cm = vp -> ColorMap;
SetRGB32( vp, 0, 0x55555555,0x55555555,0x55555555 );
SetRGB32( vp, 1, 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF );
if (cm -> Count>2) // 4 colors or up.
{
SetRGB32( vp, 2, 0x00000000,0x00000000,0x00000000 );
SetRGB32( vp, 3, 0xFFFFFFFF,0x00000000,0x00000000 );
}
if (cm -> Count>4) // 8 colors or up.
{
SetRGB32( vp, 4, 0x00000000,0xFFFFFFFF,0x00000000 );
SetRGB32( vp, 5, 0x00000000,0x00000000,0xFFFFFFFF );
SetRGB32( vp, 6, 0x00000000,0x00000000,0x00000000 );
SetRGB32( vp, 7, 0x00000000,0x00000000,0x00000000 );
}
}
void fake_initRasInfo( struct RasInfo *ri, struct BitMap *bm )
{
ri -> BitMap = bm;
}
void fake_initViewPort( struct Screen *s , int depth )
{
struct ViewPort *vp = &s-> ViewPort;
if (vp -> DWidth == 0) vp -> DWidth = s -> Width;
if (vp -> DHeight == 0) vp -> DHeight = s -> Height;
vp -> ColorMap = GetColorMap( 1L << depth);
if (vp -> ColorMap)
{
vp -> ColorMap -> cm_vp = vp;
initColors( vp );
}
vp -> RasInfo = new_struct( RasInfo );
if (vp -> RasInfo) fake_initRasInfo( vp -> RasInfo, s -> RastPort.BitMap );
}
#if use_fake_bitmap == 1
#warning using fake bitmap
struct BitMap *_new_fake_bitmap(int Width,int Height, int Depth)
{
int d;
struct BitMap *bm = new_struct( BitMap);
int sizeOfPlane;
unsigned char *data;
if (bm == NULL) return NULL;
InitBitMap( bm, Depth, Width, Height );
bm -> pad = 0xFA8E; // Fake BitMap!!
sizeOfPlane = bm -> BytesPerRow * bm -> Rows;
data = AllocVecTags( sizeOfPlane * Depth , AVT_Type, MEMF_SHARED, AVT_ClearWithValue, 0, TAG_END);
for (d=0;d<Depth;d++)
{
bm -> Planes[d] = data + sizeOfPlane*d ;
}
return bm;
}
#endif
void _init_fake_screen(struct Screen *s,int Depth )
{
s -> Width = s -> Width & 15 ? (s -> Width + 16) & 0xFFFE : s -> Width ; // Round up closes 16 pixels.
#if use_fake_bitmap == 1
if (s -> RastPort.BitMap == NULL)
{
s -> RastPort.BitMap = _new_fake_bitmap( s-> Width, s -> Height, Depth );
}
#else
s -> RastPort.BitMap = AllocBitMapTags( s-> Width, s -> Height, Depth,
BMATags_PixelFormat, PIXF_NONE,
BMATags_UserPrivate, TRUE,
TAG_END );
#endif
if (s -> Font == NULL) // no font set.
{
s -> Font = default_font;
SetFont( &s -> RastPort , s -> Font );
}
s -> BitMap = * (s -> RastPort.BitMap);
FPrintf( output, "BytesPerRow: %ld\n", s ->RastPort.BitMap -> BytesPerRow );
fake_initViewPort( s, Depth);
// need to fill in the struct as best as I can.
}
void add_LayerInfo( int screenIndex, struct Screen *s )
{
allocatedScreen[screenIndex] = true;
LayerInfos[screenIndex] = NewLayerInfo();
if (LayerInfos[screenIndex])
{
memcpy( &s -> LayerInfo, LayerInfos[screenIndex] , sizeof(struct Layer_Info) );
}
}
void init_screen_from_newScreen( const struct NewScreen * newScreen, struct Screen *s, ULONG *depth )
{
s -> Width = newScreen -> Width;
s -> Height = newScreen -> Height;
*depth = newScreen -> Depth;
if (newScreen -> CustomBitMap)
{
s -> RastPort.BitMap = newScreen -> CustomBitMap;
}
if (newScreen -> DefaultTitle)
{
s -> Title = strdup(newScreen -> DefaultTitle);
}
if (newScreen -> Font)
{
s -> Font = OpenDiskFont( newScreen -> Font );
if ( ! s -> Font ) s -> Font = default_font;
SetFont( &s -> RastPort , s -> Font );
}
/*
newScreen -> Type,
newScreen -> ViewModes );
*/
}
void update_screen_from_taglist(const struct TagItem * tagList, struct Screen *s, ULONG *depth)
{
int s_w, s_h, s_d, s_monitor;
const struct TagItem * tag;
for (tag = tagList; tag -> ti_Tag != TAG_DONE; tag++)
{
switch (tag -> ti_Tag)
{
case SA_Width:
s_w = tag -> ti_Data;
s -> Width = s_w;
break;
case SA_Height:
s_h = tag -> ti_Data;
s -> Height = s_w;
break;
case SA_Depth:
s_d = tag -> ti_Data;
*depth = s_d;
break;
case SA_DisplayID:
s -> ViewPort.Modes = tag -> ti_Data;
s_monitor = tag -> ti_Data & MONITOR_ID_MASK;
break;
}
}
{
struct modeT *mode;
mode = bestMode( s_monitor, s_w, s_h);
if (mode)
{
s -> ViewPort.DWidth = mode -> w;
s -> ViewPort.DHeight = mode -> h;
FPrintf( output, "ViewPort %ld,%ld\n", mode -> w, mode -> h);
}
}
}
struct Screen * _new_fake_OpenScreenTagList( const struct NewScreen * newScreen, const struct TagItem * tagList)
{
ULONG depth = 0;
int screenIndex;
struct Screen *s;
screenIndex = alloc_screen_in_list();
s = screenIndex >-1 ? screens+screenIndex : NULL;
if (s)
{
InitVPort( &s -> ViewPort );
InitRastPort( &s -> RastPort );
s -> ViewPort.DHeight = 0;
s -> ViewPort.DWidth = 0;
s -> FirstWindow = NULL;
if (s -> Title) s -> Title = strdup("Hello World");
add_LayerInfo( screenIndex, s );
if (newScreen) init_screen_from_newScreen( newScreen, s, &depth );
if (tagList)
{
dump_tags( tagList , screen_info_tags);
update_screen_from_taglist(tagList, s, &depth);
}
if (s -> Width == 0) s -> Width = 320;
if (s -> Height == 0) s -> Height = 200;
_init_fake_screen(s,depth);
return s;
}
return NULL;
}