this repo has no description
1/*
2 VIDEMDEV.c
3
4 Copyright (C) 2008 Paul C. Pratt
5
6 You can redistribute this file and/or modify it under the terms
7 of version 2 of the GNU General Public License as published by
8 the Free Software Foundation. You should have received a copy
9 of the license along with this file; see the file COPYING.
10
11 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 license for more details.
15*/
16
17/*
18 VIDeo card EMulated DEVice
19
20 Emulation of video card for Macintosh II.
21
22 Written referring to:
23 Sample firmware code in "Designing Cards and Drivers
24 for Macintosh II and Macintosh SE", Apple Computer,
25 page 8-20.
26
27 Basilisk II source code, especially slot_rom.cpp
28*/
29
30#include "PICOMMON.h"
31
32#if EmVidCard
33
34#include "MINEM68K.h"
35#include "SONYEMDV.h"
36
37#include "VIDEMDEV.h"
38
39/*
40 ReportAbnormalID unused 0x0A08 - 0x0AFF
41*/
42
43#define VID_dolog (dbglog_HAVE && 0)
44
45LOCALVAR const ui3b VidDrvr_contents[] = {
460x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
470x00, 0x2A, 0x00, 0x00, 0x00, 0xE2, 0x00, 0xEC,
480x00, 0xB6, 0x15, 0x2E, 0x44, 0x69, 0x73, 0x70,
490x6C, 0x61, 0x79, 0x5F, 0x56, 0x69, 0x64, 0x65,
500x6F, 0x5F, 0x53, 0x61, 0x6D, 0x70, 0x6C, 0x65,
510x00, 0x00, 0x24, 0x48, 0x26, 0x49, 0x70, 0x04,
520xA4, 0x40, 0x70, 0x04, 0xA7, 0x22, 0x66, 0x00,
530x00, 0x50, 0x27, 0x48, 0x00, 0x14, 0xA0, 0x29,
540x49, 0xFA, 0x00, 0x4A, 0x70, 0x10, 0xA7, 0x1E,
550x66, 0x00, 0x00, 0x3E, 0x31, 0x7C, 0x00, 0x06,
560x00, 0x04, 0x21, 0x4C, 0x00, 0x08, 0x21, 0x4B,
570x00, 0x0C, 0x70, 0x00, 0x10, 0x2B, 0x00, 0x28,
580xA0, 0x75, 0x66, 0x24, 0x22, 0x6B, 0x00, 0x14,
590x22, 0x51, 0x22, 0x88, 0x3F, 0x3C, 0x00, 0x01,
600x55, 0x4F, 0x3F, 0x3C, 0x00, 0x03, 0x41, 0xFA,
610x00, 0x9C, 0x2F, 0x18, 0x20, 0x50, 0x20, 0x8F,
620xDE, 0xFC, 0x00, 0x0A, 0x70, 0x00, 0x60, 0x02,
630x70, 0xE9, 0x4E, 0x75, 0x2F, 0x08, 0x55, 0x4F,
640x3F, 0x3C, 0x00, 0x04, 0x41, 0xFA, 0x00, 0x7E,
650x2F, 0x18, 0x20, 0x50, 0x20, 0x8F, 0x50, 0x4F,
660x20, 0x29, 0x00, 0x2A, 0xE1, 0x98, 0x02, 0x40,
670x00, 0x0F, 0x20, 0x78, 0x0D, 0x28, 0x4E, 0x90,
680x20, 0x5F, 0x70, 0x01, 0x4E, 0x75, 0x2F, 0x0B,
690x26, 0x69, 0x00, 0x14, 0x42, 0x67, 0x55, 0x4F,
700x3F, 0x3C, 0x00, 0x03, 0x41, 0xFA, 0x00, 0x4E,
710x2F, 0x18, 0x20, 0x50, 0x20, 0x8F, 0xDE, 0xFC,
720x00, 0x0A, 0x20, 0x53, 0x20, 0x50, 0xA0, 0x76,
730x20, 0x4B, 0xA0, 0x23, 0x70, 0x00, 0x26, 0x5F,
740x4E, 0x75, 0x2F, 0x08, 0x55, 0x4F, 0x3F, 0x3C,
750x00, 0x06, 0x60, 0x08, 0x2F, 0x08, 0x55, 0x4F,
760x3F, 0x3C, 0x00, 0x05, 0x41, 0xFA, 0x00, 0x1E,
770x2F, 0x18, 0x20, 0x50, 0x20, 0x8F, 0x5C, 0x4F,
780x30, 0x1F, 0x20, 0x5F, 0x08, 0x28, 0x00, 0x09,
790x00, 0x06, 0x67, 0x02, 0x4E, 0x75, 0x20, 0x78,
800x08, 0xFC, 0x4E, 0xD0
81};
82
83LOCALPROC ChecksumSlotROM(void)
84{
85 /* Calculate CRC */
86 /* assuming check sum field initialized to zero */
87 int i;
88 ui3p p = VidROM;
89 ui5b crc = 0;
90
91 for (i = kVidROM_Size; --i >= 0; ) {
92 crc = ((crc << 1) | (crc >> 31)) + *p++;
93 }
94 do_put_mem_long(p - 12, crc);
95}
96
97LOCALVAR ui3p pPatch;
98
99LOCALPROC PatchAByte(ui3b v)
100{
101 *pPatch++ = v;
102}
103
104LOCALPROC PatchAWord(ui4r v)
105{
106 PatchAByte(v >> 8);
107 PatchAByte(v & 0x00FF);
108}
109
110LOCALPROC PatchALong(ui5r v)
111{
112 PatchAWord(v >> 16);
113 PatchAWord(v & 0x0000FFFF);
114}
115
116#if 0
117LOCALPROC PatchAOSLstEntry0(ui3r Id, ui5r Offset)
118{
119 PatchALong((Id << 24) | (Offset & 0x00FFFFFF));
120}
121#endif
122
123LOCALPROC PatchAOSLstEntry(ui3r Id, ui3p Offset)
124{
125 PatchALong((Id << 24) | ((Offset - pPatch) & 0x00FFFFFF));
126}
127
128LOCALFUNC ui3p ReservePatchOSLstEntry(void)
129{
130 ui3p v = pPatch;
131 pPatch += 4;
132 return v;
133}
134
135LOCALPROC PatchAReservedOSLstEntry(ui3p p, ui3r Id)
136{
137 ui3p pPatchSave = pPatch;
138 pPatch = p;
139 PatchAOSLstEntry(Id, pPatchSave);
140 pPatch = pPatchSave;
141}
142
143LOCALPROC PatchADatLstEntry(ui3r Id, ui5r Data)
144{
145 PatchALong((Id << 24) | (Data & 0x00FFFFFF));
146}
147
148LOCALPROC PatchAnEndOfLst(void)
149{
150 PatchADatLstEntry(0xFF /* endOfList */, 0x00000000);
151}
152
153GLOBALFUNC blnr Vid_Init(void)
154{
155 int i;
156 ui5r UsedSoFar;
157
158 ui3p pAt_sRsrcDir;
159 ui3p pTo_sRsrc_Board;
160 ui3p pTo_BoardType;
161 ui3p pTo_BoardName;
162 ui3p pTo_VenderInfo;
163 ui3p pTo_VendorID;
164 ui3p pTo_RevLevel;
165 ui3p pTo_PartNum;
166 ui3p pTo_sRsrc_Video;
167 ui3p pTo_VideoType;
168 ui3p pTo_VideoName;
169 ui3p pTo_MinorBase;
170 ui3p pTo_MinorLength;
171#if 0
172 ui3p pTo_MajorBase;
173 ui3p pTo_MajorLength;
174#endif
175 ui3p pTo_VidDrvrDir;
176 ui3p pTo_sMacOS68020;
177 ui3p pTo_OneBitMode;
178 ui3p pTo_OneVidParams;
179#if 0 != vMacScreenDepth
180 ui3p pTo_ColorBitMode = nullpr;
181 ui3p pTo_ColorVidParams;
182#endif
183
184 pPatch = VidROM;
185
186 pAt_sRsrcDir = pPatch;
187 pTo_sRsrc_Board = ReservePatchOSLstEntry();
188 pTo_sRsrc_Video = ReservePatchOSLstEntry();
189 PatchAnEndOfLst();
190
191 PatchAReservedOSLstEntry(pTo_sRsrc_Board, 0x01 /* sRsrc_Board */);
192 pTo_BoardType = ReservePatchOSLstEntry();
193 pTo_BoardName = ReservePatchOSLstEntry();
194 PatchADatLstEntry(0x20 /* BoardId */, 0x0000764D);
195 /* 'vM', for Mini vMac */
196 pTo_VenderInfo = ReservePatchOSLstEntry();
197 PatchAnEndOfLst();
198
199 PatchAReservedOSLstEntry(pTo_BoardType, 0x01 /* sRsrcType */);
200 PatchAWord(0x0001);
201 PatchAWord(0x0000);
202 PatchAWord(0x0000);
203 PatchAWord(0x0000);
204
205 PatchAReservedOSLstEntry(pTo_BoardName, 0x02 /* sRsrcName */);
206 /*
207 'Mini vMac video card' as ascii c string
208 (null terminated), and
209 zero padded to end aligned long.
210 */
211 PatchALong(0x4D696E69);
212 PatchALong(0x20764D61);
213 PatchALong(0x63207669);
214 PatchALong(0x64656F20);
215 PatchALong(0x63617264);
216 PatchALong(0x00000000);
217
218 PatchAReservedOSLstEntry(pTo_VenderInfo, 0x24 /* vendorInfo */);
219
220 pTo_VendorID = ReservePatchOSLstEntry();
221 pTo_RevLevel = ReservePatchOSLstEntry();
222 pTo_PartNum = ReservePatchOSLstEntry();
223 PatchAnEndOfLst();
224
225 PatchAReservedOSLstEntry(pTo_VendorID, 0x01 /* vendorId */);
226 /*
227 'Paul C. Pratt' as ascii c string
228 (null terminated), and
229 zero padded to end aligned long.
230 */
231 PatchALong(0x5061756C);
232 PatchALong(0x20432E20);
233 PatchALong(0x50726174);
234 PatchALong(0x74000000);
235
236 PatchAReservedOSLstEntry(pTo_RevLevel, 0x03 /* revLevel */);
237 /*
238 '1.0' as ascii c string
239 (null terminated), and
240 zero padded to end aligned long.
241 */
242 PatchALong(0x312E3000);
243
244 PatchAReservedOSLstEntry(pTo_PartNum, 0x04 /* partNum */);
245 /*
246 'TFB-1' as ascii c string
247 (null terminated), and
248 zero padded to end aligned long.
249 */
250 PatchALong(0x5446422D);
251 PatchALong(0x31000000);
252
253 PatchAReservedOSLstEntry(pTo_sRsrc_Video, 0x80 /* sRsrc_Video */);
254
255 pTo_VideoType = ReservePatchOSLstEntry();
256 pTo_VideoName = ReservePatchOSLstEntry();
257 pTo_VidDrvrDir = ReservePatchOSLstEntry();
258 PatchADatLstEntry(0x08 /* sRsrcHWDevId */, 0x00000001);
259 pTo_MinorBase = ReservePatchOSLstEntry();
260 pTo_MinorLength = ReservePatchOSLstEntry();
261#if 0
262 pTo_MajorBase = ReservePatchOSLstEntry();
263 pTo_MajorLength = ReservePatchOSLstEntry();
264#endif
265 pTo_OneBitMode = ReservePatchOSLstEntry();
266#if 0 != vMacScreenDepth
267 if (ColorModeWorks) {
268 pTo_ColorBitMode = ReservePatchOSLstEntry();
269 }
270#endif
271 PatchAnEndOfLst();
272
273 PatchAReservedOSLstEntry(pTo_VideoType, 0x01 /* sRsrcType */);
274
275 PatchAWord(0x0003); /* catDisplay */
276 PatchAWord(0x0001); /* typVideo */
277 PatchAWord(0x0001); /* drSwApple */
278 PatchAWord(0x0001); /* drHwTFB */
279
280 PatchAReservedOSLstEntry(pTo_VideoName, 0x02 /* sRsrcName */);
281 /*
282 'Display_Video_Apple_TFB' as ascii c string
283 (null terminated), and
284 zero padded to end aligned long.
285 */
286 PatchALong(0x44697370);
287 PatchALong(0x6C61795F);
288 PatchALong(0x56696465);
289 PatchALong(0x6F5F4170);
290 PatchALong(0x706C655F);
291 PatchALong(0x54464200);
292
293 PatchAReservedOSLstEntry(pTo_MinorBase, 0x0A /* MinorBaseOS */);
294 PatchALong(0x00000000);
295
296 PatchAReservedOSLstEntry(pTo_MinorLength, 0x0B /* MinorLength */);
297 PatchALong(kVidMemRAM_Size);
298
299#if 0
300 PatchAReservedOSLstEntry(pTo_MajorBase, 0x0C /* MinorBaseOS */);
301 PatchALong(0x00000000);
302
303 PatchAReservedOSLstEntry(pTo_MajorLength, 0x0D /* MinorLength */);
304 PatchALong(kVidMemRAM_Size);
305#endif
306
307 PatchAReservedOSLstEntry(pTo_VidDrvrDir, 0x04 /* sRsrcDrvrDir */);
308 pTo_sMacOS68020 = ReservePatchOSLstEntry();
309 PatchAnEndOfLst();
310
311 PatchAReservedOSLstEntry(pTo_sMacOS68020, 0x02 /* sMacOS68020 */);
312
313 PatchALong(4 + sizeof(VidDrvr_contents) + 8);
314 MyMoveBytes((ui3p)VidDrvr_contents,
315 pPatch, sizeof(VidDrvr_contents));
316 pPatch += sizeof(VidDrvr_contents);
317 PatchAWord(kcom_callcheck);
318 PatchAWord(kExtnVideo);
319 PatchALong(kExtn_Block_Base);
320
321 PatchAReservedOSLstEntry(pTo_OneBitMode, 0x80 /* oneBitMode */);
322 pTo_OneVidParams = ReservePatchOSLstEntry();
323 PatchADatLstEntry(0x03 /* mVidParams */, 0x00000001);
324 PatchADatLstEntry(0x04 /* mDevType */, 0x00000000);
325 PatchAnEndOfLst();
326
327 PatchAReservedOSLstEntry(pTo_OneVidParams, 0x01 /* mVidParams */);
328 PatchALong(0x0000002E); /* physical Block Size */
329 PatchALong(0x00000000); /* defmBaseOffset */
330 PatchAWord(vMacScreenWidth / 8);
331 /* (Bounds.R-Bounds.L)*PixelSize/8 */
332 PatchAWord(0x0000); /* Bounds.T */
333 PatchAWord(0x0000); /* Bounds.L */
334 PatchAWord(vMacScreenHeight); /* Bounds.B */
335 PatchAWord(vMacScreenWidth); /* Bounds.R */
336 PatchAWord(0x0000); /* bmVersion */
337 PatchAWord(0x0000); /* packType not used */
338 PatchALong(0x00000000); /* packSize not used */
339 PatchALong(0x00480000); /* bmHRes */
340 PatchALong(0x00480000); /* bmVRes */
341 PatchAWord(0x0000); /* bmPixelType */
342 PatchAWord(0x0001); /* bmPixelSize */
343 PatchAWord(0x0001); /* bmCmpCount */
344 PatchAWord(0x0001); /* bmCmpSize */
345 PatchALong(0x00000000); /* bmPlaneBytes */
346
347#if 0 != vMacScreenDepth
348 if (ColorModeWorks) {
349
350 PatchAReservedOSLstEntry(pTo_ColorBitMode, 0x81);
351 pTo_ColorVidParams = ReservePatchOSLstEntry();
352 PatchADatLstEntry(0x03 /* mVidParams */, 0x00000001);
353 PatchADatLstEntry(0x04 /* mDevType */,
354 (vMacScreenDepth < 4) ? 0x00000000 : 0x00000002);
355 /* 2 for direct devices, according to Basilisk II */
356 PatchAnEndOfLst();
357
358 PatchAReservedOSLstEntry(pTo_ColorVidParams, 0x01);
359 PatchALong(0x0000002E); /* physical Block Size */
360 PatchALong(0x00000000); /* defmBaseOffset */
361 PatchAWord(vMacScreenByteWidth);
362 PatchAWord(0x0000); /* Bounds.T */
363 PatchAWord(0x0000); /* Bounds.L */
364 PatchAWord(vMacScreenHeight); /* Bounds.B */
365 PatchAWord(vMacScreenWidth); /* Bounds.R */
366 PatchAWord(0x0000); /* bmVersion */
367 PatchAWord(0x0000); /* packType not used */
368 PatchALong(0x00000000); /* packSize not used */
369 PatchALong(0x00480000); /* bmHRes */
370 PatchALong(0x00480000); /* bmVRes */
371 PatchAWord((vMacScreenDepth < 4) ? 0x0000 : 0x0010);
372 /* bmPixelType */
373 PatchAWord(1 << vMacScreenDepth); /* bmPixelSize */
374 PatchAWord((vMacScreenDepth < 4) ? 0x0001 : 0x0003);
375 /* bmCmpCount */
376#if 4 == vMacScreenDepth
377 PatchAWord(0x0005); /* bmCmpSize */
378#elif 5 == vMacScreenDepth
379 PatchAWord(0x0008); /* bmCmpSize */
380#else
381 PatchAWord(1 << vMacScreenDepth); /* bmCmpSize */
382#endif
383 PatchALong(0x00000000); /* bmPlaneBytes */
384
385 }
386#endif
387
388 UsedSoFar = (pPatch - VidROM) + 20;
389 if (UsedSoFar > kVidROM_Size) {
390 ReportAbnormalID(0x0A01, "kVidROM_Size too small");
391 return falseblnr;
392 }
393
394 for (i = kVidROM_Size - UsedSoFar; --i >= 0; ) {
395 PatchAByte(0);
396 }
397
398 pPatch = (kVidROM_Size - 20) + VidROM;
399 PatchALong((pAt_sRsrcDir - pPatch) & 0x00FFFFFF);
400 PatchALong(/* 0x0000041E */ kVidROM_Size);
401 PatchALong(0x00000000);
402 PatchAByte(0x01);
403 PatchAByte(0x01);
404 PatchALong(0x5A932BC7);
405 PatchAByte(0x00);
406 PatchAByte(0x0F);
407
408 ChecksumSlotROM();
409
410#if (0 != vMacScreenDepth) && (vMacScreenDepth < 4)
411 CLUT_reds[0] = 0xFFFF;
412 CLUT_greens[0] = 0xFFFF;
413 CLUT_blues[0] = 0xFFFF;
414 CLUT_reds[CLUT_size - 1] = 0;
415 CLUT_greens[CLUT_size - 1] = 0;
416 CLUT_blues[CLUT_size - 1] = 0;
417#endif
418
419 return trueblnr;
420}
421
422IMPORTPROC Vid_VBLinterrupt_PulseNotify(void);
423
424GLOBALPROC Vid_Update(void)
425{
426 if (! Vid_VBLintunenbl) {
427 Vid_VBLinterrupt = 0;
428 Vid_VBLinterrupt_PulseNotify();
429 }
430}
431
432LOCALFUNC ui4r Vid_GetMode(void)
433{
434 return
435#if 0 != vMacScreenDepth
436 UseColorMode ? 129 :
437#endif
438 128;
439}
440
441LOCALFUNC tMacErr Vid_SetMode(ui4r v)
442{
443#if 0 == vMacScreenDepth
444 UnusedParam(v);
445#else
446 if (UseColorMode != ((v != 128) && ColorModeWorks)) {
447 UseColorMode = ! UseColorMode;
448 ColorMappingChanged = trueblnr;
449 }
450#endif
451 return mnvm_noErr;
452}
453
454GLOBALFUNC ui4r Vid_Reset(void)
455{
456#if 0 != vMacScreenDepth
457 UseColorMode = falseblnr;
458#endif
459 return 128;
460}
461
462#define kCmndVideoFeatures 1
463#define kCmndVideoGetIntEnbl 2
464#define kCmndVideoSetIntEnbl 3
465#define kCmndVideoClearInt 4
466#define kCmndVideoStatus 5
467#define kCmndVideoControl 6
468
469#define CntrlParam_csCode 0x1A /* control/status code [word] */
470#define CntrlParam_csParam 0x1C /* operation-defined parameters */
471
472#define VDPageInfo_csMode 0
473#define VDPageInfo_csData 2
474#define VDPageInfo_csPage 6
475#define VDPageInfo_csBaseAddr 8
476
477#define VDSetEntryRecord_csTable 0
478#define VDSetEntryRecord_csStart 4
479#define VDSetEntryRecord_csCount 6
480
481#define VDGammaRecord_csGTable 0
482
483#define VidBaseAddr 0xF9900000
484 /* appears to be completely ignored */
485
486LOCALVAR blnr UseGrayTones = falseblnr;
487
488LOCALPROC FillScreenWithGrayPattern(void)
489{
490 int i;
491 int j;
492 ui5b *p1 = (ui5b *)VidMem;
493
494#if 0 != vMacScreenDepth
495 if (UseColorMode) {
496#if 1 == vMacScreenDepth
497 ui5b pat = 0xCCCCCCCC;
498#elif 2 == vMacScreenDepth
499 ui5b pat = 0xF0F0F0F0;
500#elif 3 == vMacScreenDepth
501 ui5b pat = 0xFF00FF00;
502#elif 4 == vMacScreenDepth
503 ui5b pat = 0x00007FFF;
504#elif 5 == vMacScreenDepth
505 ui5b pat = 0x00000000;
506#endif
507 for (i = vMacScreenHeight; --i >= 0; ) {
508 for (j = vMacScreenByteWidth >> 2; --j >= 0; ) {
509 *p1++ = pat;
510#if 5 == vMacScreenDepth
511 pat = (~ pat) & 0x00FFFFFF;
512#endif
513 }
514 pat = (~ pat)
515#if 4 == vMacScreenDepth
516 & 0x7FFF7FFF
517#elif 5 == vMacScreenDepth
518 & 0x00FFFFFF
519#endif
520 ;
521 }
522 } else
523#endif
524 {
525 ui5b pat = 0xAAAAAAAA;
526
527 for (i = vMacScreenHeight; --i >= 0; ) {
528 for (j = vMacScreenMonoByteWidth >> 2; --j >= 0; ) {
529 *p1++ = pat;
530 }
531 pat = ~ pat;
532 }
533 }
534}
535
536GLOBALPROC ExtnVideo_Access(CPTR p)
537{
538 tMacErr result = mnvm_controlErr;
539
540 switch (get_vm_word(p + ExtnDat_commnd)) {
541 case kCmndVersion:
542#if VID_dolog
543 dbglog_WriteNote("Video_Access kCmndVersion");
544#endif
545 put_vm_word(p + ExtnDat_version, 1);
546 result = mnvm_noErr;
547 break;
548 case kCmndVideoGetIntEnbl:
549#if VID_dolog
550 dbglog_WriteNote("Video_Access kCmndVideoGetIntEnbl");
551#endif
552 put_vm_word(p + 8,
553 Vid_VBLintunenbl ? 0 : 1);
554 result = mnvm_noErr;
555 break;
556 case kCmndVideoSetIntEnbl:
557#if VID_dolog
558 dbglog_WriteNote("Video_Access kCmndVideoSetIntEnbl");
559#endif
560 Vid_VBLintunenbl =
561 (0 == get_vm_word(p + 8))
562 ? 1 : 0;
563 result = mnvm_noErr;
564 break;
565 case kCmndVideoClearInt:
566#if VID_dolog && 0 /* frequent */
567 dbglog_WriteNote("Video_Access kCmndVideoClearInt");
568#endif
569 Vid_VBLinterrupt = 1;
570 result = mnvm_noErr;
571 break;
572 case kCmndVideoControl:
573 {
574 CPTR CntrlParams = get_vm_long(p + 8);
575 CPTR csParam =
576 get_vm_long(CntrlParams + CntrlParam_csParam);
577 ui4r csCode =
578 get_vm_word(CntrlParams + CntrlParam_csCode);
579
580 switch (csCode) {
581 case 0: /* VidReset */
582#if VID_dolog
583 dbglog_WriteNote(
584 "Video_Access kCmndVideoControl, VidReset");
585#endif
586 put_vm_word(csParam + VDPageInfo_csMode,
587 Vid_GetMode());
588 put_vm_word(csParam + VDPageInfo_csPage, 0);
589 /* page is always 0 */
590 put_vm_long(csParam + VDPageInfo_csBaseAddr,
591 VidBaseAddr);
592
593 result = mnvm_noErr;
594 break;
595 case 1: /* KillIO */
596#if VID_dolog
597 dbglog_WriteNote(
598 "Video_Access kCmndVideoControl, KillIO");
599#endif
600 result = mnvm_noErr;
601 break;
602 case 2: /* SetVidMode */
603#if VID_dolog
604 dbglog_WriteNote(
605 "Video_Access kCmndVideoControl, "
606 "SetVidMode");
607#endif
608 if (0 != get_vm_word(
609 csParam + VDPageInfo_csPage))
610 {
611 /* return mnvm_controlErr, page must be 0 */
612 ReportAbnormalID(0x0A02,
613 "SetVidMode not page 0");
614 } else {
615 result = Vid_SetMode(get_vm_word(
616 csParam + VDPageInfo_csMode));
617 put_vm_long(csParam + VDPageInfo_csBaseAddr,
618 VidBaseAddr);
619 }
620 break;
621 case 3: /* SetEntries */
622#if VID_dolog
623 dbglog_WriteNote(
624 "Video_Access kCmndVideoControl, "
625 "SetEntries");
626#endif
627#if (0 != vMacScreenDepth) && (vMacScreenDepth < 4)
628 if (UseColorMode) {
629 CPTR csTable = get_vm_long(
630 csParam + VDSetEntryRecord_csTable);
631 ui4r csStart = get_vm_word(
632 csParam + VDSetEntryRecord_csStart);
633 ui4r csCount = 1 + get_vm_word(
634 csParam + VDSetEntryRecord_csCount);
635
636 if (((ui4r) 0xFFFF) == csStart) {
637 int i;
638
639 result = mnvm_noErr;
640 for (i = 0; i < csCount; ++i) {
641 ui4r j = get_vm_word(csTable + 0);
642 if (j == 0) {
643 /* ignore input, leave white */
644 } else
645 if (j == CLUT_size - 1) {
646 /* ignore input, leave black */
647 } else
648 if (j >= CLUT_size) {
649 /* out of range */
650 result = mnvm_paramErr;
651 } else
652 {
653 ui4r r =
654 get_vm_word(csTable + 2);
655 ui4r g =
656 get_vm_word(csTable + 4);
657 ui4r b =
658 get_vm_word(csTable + 6);
659 CLUT_reds[j] = r;
660 CLUT_greens[j] = g;
661 CLUT_blues[j] = b;
662 }
663 csTable += 8;
664 }
665 ColorMappingChanged = trueblnr;
666 } else
667 if (csStart + csCount < csStart) {
668 /* overflow */
669 result = mnvm_paramErr;
670 } else
671 if (csStart + csCount > CLUT_size) {
672 result = mnvm_paramErr;
673 } else
674 {
675 int i;
676
677 for (i = 0; i < csCount; ++i) {
678 int j = i + csStart;
679
680 if (j == 0) {
681 /* ignore input, leave white */
682 } else
683 if (j == CLUT_size - 1) {
684 /* ignore input, leave black */
685 } else
686 {
687 ui4r r =
688 get_vm_word(csTable + 2);
689 ui4r g =
690 get_vm_word(csTable + 4);
691 ui4r b =
692 get_vm_word(csTable + 6);
693 CLUT_reds[j] = r;
694 CLUT_greens[j] = g;
695 CLUT_blues[j] = b;
696 }
697 csTable += 8;
698 }
699 ColorMappingChanged = trueblnr;
700 result = mnvm_noErr;
701 }
702 } else
703#endif
704 {
705 /* not implemented */
706 }
707 break;
708 case 4: /* SetGamma */
709#if VID_dolog
710 dbglog_WriteNote(
711 "Video_Access kCmndVideoControl, SetGamma");
712#endif
713 {
714#if 0
715 CPTR csTable = get_vm_long(
716 csParam + VDGammaRecord_csGTable);
717 /* not implemented */
718#endif
719 }
720#if 0
721 ReportAbnormalID(0x0A03,
722 "Video_Access SetGamma not implemented");
723#else
724 result = mnvm_noErr;
725#endif
726 break;
727 case 5: /* GrayScreen */
728#if VID_dolog
729 dbglog_WriteNote(
730 "Video_Access kCmndVideoControl, "
731 "GrayScreen");
732#endif
733 {
734#if 0
735 ui4r csPage = get_vm_word(
736 csParam + VDPageInfo_csPage);
737 /* not implemented */
738#endif
739 FillScreenWithGrayPattern();
740 result = mnvm_noErr;
741 }
742 break;
743 case 6: /* SetGray */
744#if VID_dolog
745 dbglog_WriteNote(
746 "Video_Access kCmndVideoControl, SetGray");
747#endif
748 {
749 ui3r csMode = get_vm_byte(
750 csParam + VDPageInfo_csMode);
751 /*
752 "Designing Cards and Drivers" book
753 says this is a word, but it seems
754 to be a byte.
755 */
756
757 UseGrayTones = (csMode != 0);
758 result = mnvm_noErr;
759 }
760 break;
761 case 9: /* SetDefaultMode */
762#if VID_dolog
763 dbglog_WriteNote(
764 "Video_Access kCmndVideoControl, "
765 "SetDefaultMode");
766#endif
767 /* not handled yet */
768 /*
769 seen when close Monitors control panel
770 in system 7.5.5
771 */
772 break;
773 case 16: /* SavePreferredConfiguration */
774#if VID_dolog
775 dbglog_WriteNote(
776 "Video_Access kCmndVideoControl, "
777 "SavePreferredConfiguration");
778#endif
779 /* not handled yet */
780 /*
781 seen when close Monitors control panel
782 in system 7.5.5
783 */
784 break;
785 default:
786 ReportAbnormalID(0x0A04,
787 "kCmndVideoControl, unknown csCode");
788#if dbglog_HAVE
789 dbglog_writelnNum("csCode", csCode);
790#endif
791 break;
792 }
793 }
794 break;
795 case kCmndVideoStatus:
796 {
797 CPTR CntrlParams = get_vm_long(p + 8);
798 CPTR csParam = get_vm_long(
799 CntrlParams + CntrlParam_csParam);
800 ui4r csCode = get_vm_word(
801 CntrlParams + CntrlParam_csCode);
802
803 result = mnvm_statusErr;
804 switch (csCode) {
805 case 2: /* GetMode */
806#if VID_dolog
807 dbglog_WriteNote(
808 "Video_Access kCmndVideoStatus, GetMode");
809#endif
810 put_vm_word(csParam + VDPageInfo_csMode,
811 Vid_GetMode());
812 put_vm_word(csParam + VDPageInfo_csPage, 0);
813 /* page is always 0 */
814 put_vm_long(csParam + VDPageInfo_csBaseAddr,
815 VidBaseAddr);
816 result = mnvm_noErr;
817 break;
818 case 3: /* GetEntries */
819#if VID_dolog
820 dbglog_WriteNote(
821 "Video_Access kCmndVideoStatus, "
822 "GetEntries");
823#endif
824 {
825#if 0
826 CPTR csTable = get_vm_long(
827 csParam + VDSetEntryRecord_csTable);
828 put_vm_word(
829 csParam + VDSetEntryRecord_csStart,
830 csStart);
831 put_vm_word(
832 csParam + VDSetEntryRecord_csCount,
833 csCount);
834#endif
835 ReportAbnormalID(0x0A05,
836 "GetEntries not implemented");
837 }
838 break;
839 case 4: /* GetPages */
840#if VID_dolog
841 dbglog_WriteNote(
842 "Video_Access kCmndVideoStatus, GetPages");
843#endif
844 put_vm_word(csParam + VDPageInfo_csPage, 1);
845 /* always 1 page */
846 result = mnvm_noErr;
847 break;
848 case 5: /* GetPageAddr */
849#if VID_dolog
850 dbglog_WriteNote(
851 "Video_Access kCmndVideoStatus,"
852 " GetPageAddr");
853#endif
854 {
855 ui4r csPage = get_vm_word(
856 csParam + VDPageInfo_csPage);
857 if (0 != csPage) {
858 /*
859 return mnvm_statusErr,
860 page must be 0
861 */
862 } else {
863 put_vm_long(
864 csParam + VDPageInfo_csBaseAddr,
865 VidBaseAddr);
866 result = mnvm_noErr;
867 }
868 }
869 break;
870 case 6: /* GetGray */
871#if VID_dolog
872 dbglog_WriteNote(
873 "Video_Access kCmndVideoStatus, GetGray");
874#endif
875 put_vm_word(csParam + VDPageInfo_csMode,
876 UseGrayTones ? 0x0100 : 0);
877 /*
878 "Designing Cards and Drivers" book
879 says this is a word, but it seems
880 to be a byte.
881 */
882 result = mnvm_noErr;
883 break;
884 case 8: /* GetGamma */
885#if VID_dolog
886 dbglog_WriteNote(
887 "Video_Access kCmndVideoStatus, "
888 "GetGamma");
889#endif
890 /* not handled yet */
891 /*
892 seen when close Monitors control panel
893 in system 7.5.5
894 */
895 break;
896 case 9: /* GetDefaultMode */
897#if VID_dolog
898 dbglog_WriteNote(
899 "Video_Access kCmndVideoStatus, "
900 "GetDefaultMode");
901#endif
902 /* not handled yet */
903 /* seen in System 7.5.5 boot */
904 break;
905 case 10: /* GetCurrentMode */
906#if VID_dolog
907 dbglog_WriteNote(
908 "Video_Access kCmndVideoStatus, "
909 "GetCurrentMode");
910#endif
911#if 0
912 put_vm_word(csParam + VDPageInfo_csMode,
913 Vid_GetMode());
914 put_vm_long(csParam + VDPageInfo_csData, 0);
915 /* what is this ? */
916 put_vm_word(csParam + VDPageInfo_csPage, 0);
917 /* page is always 0 */
918 put_vm_long(csParam + VDPageInfo_csBaseAddr,
919 VidBaseAddr);
920
921 result = mnvm_noErr;
922#endif
923 break;
924 case 12: /* GetConnection */
925#if VID_dolog
926 dbglog_WriteNote(
927 "Video_Access kCmndVideoStatus, "
928 "GetConnection");
929#endif
930 /* not handled yet */
931 /* seen in System 7.5.5 boot */
932 break;
933 case 13: /* GetCurrentMode */
934#if VID_dolog
935 dbglog_WriteNote(
936 "Video_Access kCmndVideoStatus, "
937 "GetCurrentMode");
938#endif
939 /* not handled yet */
940 /* seen in System 7.5.5 boot */
941 break;
942 case 14: /* GetModeBaseAddress */
943#if VID_dolog
944 dbglog_WriteNote(
945 "Video_Access kCmndVideoStatus, "
946 "GetModeBaseAddress");
947#endif
948 /* not handled yet */
949 /*
950 seen in System 7.5.5 Monitors control panel
951 */
952 break;
953 case 16: /* GetPreferredConfiguration */
954#if VID_dolog
955 dbglog_WriteNote(
956 "Video_Access kCmndVideoStatus, "
957 "GetPreferredConfiguration");
958#endif
959 /* not handled yet */
960 /* seen in System 7.5.5 boot */
961 break;
962 case 17: /* GetNextResolution */
963#if VID_dolog
964 dbglog_WriteNote(
965 "Video_Access kCmndVideoStatus, "
966 "GetNextResolution");
967#endif
968 /* not handled yet */
969 /*
970 seen in System 7.5.5 monitors control panel
971 option button
972 */
973 break;
974 case 18: /* GetVideoParameters */
975#if VID_dolog
976 dbglog_WriteNote(
977 "Video_Access kCmndVideoStatus, "
978 "GetVideoParameters");
979#endif
980 /* not handled yet */
981 /* seen in System 7.5.5 boot */
982 break;
983 default:
984 ReportAbnormalID(0x0A06,
985 "Video_Access kCmndVideoStatus, "
986 "unknown csCode");
987#if dbglog_HAVE
988 dbglog_writelnNum("csCode", csCode);
989#endif
990 break;
991 }
992 }
993 break;
994 default:
995 ReportAbnormalID(0x0A07,
996 "Video_Access, unknown commnd");
997 break;
998 }
999
1000 put_vm_word(p + ExtnDat_result, result);
1001}
1002
1003#endif /* EmVidCard */