2022-02-05 14:32:44 +00:00
|
|
|
#include "NuBusFPGADrvr.h"
|
|
|
|
|
2022-09-18 07:10:04 +00:00
|
|
|
#include "ROMDefs.h"
|
|
|
|
|
2022-10-05 20:41:27 +00:00
|
|
|
typedef void(*vblproto)(short);
|
|
|
|
|
|
|
|
#pragma parameter __D0 fbIrq(__A1)
|
|
|
|
short fbIrq(const long sqParameter){
|
|
|
|
/* AuxDCEPtr dce = (AuxDCEPtr)sqParameter; */
|
|
|
|
/* NuBusFPGADriverGlobalsHdl dStoreHdl = (NuBusFPGADriverGlobalsHdl)dce->dCtlStorage; */
|
|
|
|
/* NuBusFPGADriverGlobalsPtr dStore = *dStoreHdl; */
|
|
|
|
vblproto myVbl = *(vblproto**)0x0d28;
|
|
|
|
/* write_reg(dce, GOBOFB_INTR_CLEAR, 0); */
|
|
|
|
*((volatile unsigned int*)(sqParameter+GOBOFB_BASE+GOBOFB_INTR_CLEAR)) = 0;
|
2022-10-05 21:46:28 +00:00
|
|
|
myVbl((sqParameter>>24)&0xf); // cleaner to use dStore->slot ? but require more code...
|
2022-10-05 20:41:27 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-10-05 21:46:28 +00:00
|
|
|
|
|
|
|
#pragma parameter __D0 cNuBusFPGAOpen(__A0, __A1)
|
2022-02-05 14:32:44 +00:00
|
|
|
OSErr cNuBusFPGAOpen(IOParamPtr pb, /* DCtlPtr */ AuxDCEPtr dce)
|
|
|
|
{
|
|
|
|
OSErr ret = noErr;
|
2022-04-17 09:25:48 +00:00
|
|
|
/* write_reg(dce, GOBOFB_DEBUG, 0xBEEF0000); */
|
|
|
|
/* write_reg(dce, GOBOFB_DEBUG, (unsigned long)dce->dCtlDevBase); */
|
2022-02-05 14:32:44 +00:00
|
|
|
|
|
|
|
if (dce->dCtlStorage == nil)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* set up flags in the device control entry */
|
|
|
|
/* dce->dCtlFlags |= (dCtlEnableMask | dStatEnableMask | dWritEnableMask |
|
|
|
|
dReadEnableMask | dNeedLockMask | dRAMBasedMask ); */
|
|
|
|
|
|
|
|
/* initialize dCtlStorage */
|
|
|
|
ReserveMemSys(sizeof(NuBusFPGADriverGlobals));
|
|
|
|
dce->dCtlStorage = NewHandleSysClear(sizeof(NuBusFPGADriverGlobals));
|
|
|
|
if (dce->dCtlStorage == nil)
|
|
|
|
return(openErr);
|
|
|
|
HLock(dce->dCtlStorage);
|
|
|
|
NuBusFPGADriverGlobalsHdl dStoreHdl = (NuBusFPGADriverGlobalsHdl)dce->dCtlStorage;
|
2022-09-18 12:13:25 +00:00
|
|
|
NuBusFPGADriverGlobalsPtr dStore = *dStoreHdl;
|
2022-02-05 14:32:44 +00:00
|
|
|
/* (*dStore)->dce = dce; */
|
|
|
|
|
|
|
|
/* for (i = 0 ; i < 256 ; i++) { */
|
2022-09-18 12:13:25 +00:00
|
|
|
/* dStore->shadowClut[i*3+0] = i; */
|
|
|
|
/* dStore->shadowClut[i*3+1] = i; */
|
|
|
|
/* dStore->shadowClut[i*3+2] = i; */
|
2022-02-05 14:32:44 +00:00
|
|
|
/* } */
|
|
|
|
|
2022-09-18 12:13:25 +00:00
|
|
|
dStore->gray = 0;
|
|
|
|
dStore->irqen = 0;
|
|
|
|
dStore->slot = dce->dCtlSlot;
|
2022-09-17 15:06:15 +00:00
|
|
|
|
|
|
|
/* Get the HW setting for native resolution */
|
2022-09-18 12:13:25 +00:00
|
|
|
dStore->hres[0] = __builtin_bswap32((unsigned int)read_reg(dce, GOBOFB_HRES)); // fixme: endianness
|
|
|
|
dStore->vres[0] = __builtin_bswap32((unsigned int)read_reg(dce, GOBOFB_VRES)); // fixme: endianness
|
2022-02-05 14:32:44 +00:00
|
|
|
|
|
|
|
SlotIntQElement *siqel = (SlotIntQElement *)NewPtrSysClear(sizeof(SlotIntQElement));
|
|
|
|
if (siqel == NULL) {
|
|
|
|
return openErr;
|
|
|
|
}
|
|
|
|
siqel->sqType = sIQType;
|
|
|
|
siqel->sqPrio = 8;
|
|
|
|
//siqel->sqAddr = interruptRoutine;
|
2022-10-05 20:41:27 +00:00
|
|
|
/* not sure how to get the proper result in C... */
|
|
|
|
/* SlotIntServiceProcPtr sqAddr; */
|
|
|
|
/* asm("lea %%pc@(interruptRoutine),%0\n" : "=a"(sqAddr)); */
|
|
|
|
/* siqel->sqAddr = sqAddr; */
|
|
|
|
/* siqel->sqParm = (long)dce->dCtlDevBase; */
|
|
|
|
|
2022-02-05 14:32:44 +00:00
|
|
|
/* not sure how to get the proper result in C... */
|
|
|
|
SlotIntServiceProcPtr sqAddr;
|
2022-10-05 20:41:27 +00:00
|
|
|
asm("lea %%pc@(fbIrq),%0\n" : "=a"(sqAddr));
|
2022-02-05 14:32:44 +00:00
|
|
|
siqel->sqAddr = sqAddr;
|
2022-10-05 20:41:27 +00:00
|
|
|
/* siqel->sqParm = (long)dce; */
|
2022-02-05 14:32:44 +00:00
|
|
|
siqel->sqParm = (long)dce->dCtlDevBase;
|
2022-09-18 12:13:25 +00:00
|
|
|
dStore->siqel = siqel;
|
2022-09-17 12:44:26 +00:00
|
|
|
|
2022-09-18 12:13:25 +00:00
|
|
|
dStore->curPage = 0;
|
|
|
|
dStore->curMode = nativeVidMode;
|
|
|
|
dStore->curDepth = kDepthMode1;
|
2022-09-18 07:10:04 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
OSErr err = noErr;
|
|
|
|
SpBlock spb;
|
|
|
|
UInt8 max = nativeVidMode;
|
|
|
|
|
|
|
|
spb.spParamData = 1<<fall|1<<foneslot;
|
|
|
|
spb.spCategory = catDisplay;
|
|
|
|
spb.spCType = typeVideo;
|
|
|
|
spb.spDrvrSW = drSwApple;
|
|
|
|
spb.spDrvrHW = 0xBEEF;
|
|
|
|
spb.spTBMask = 0; /* match everything above */
|
|
|
|
spb.spSlot = dce->dCtlSlot;
|
|
|
|
spb.spID = nativeVidMode;
|
|
|
|
spb.spExtDev = 0;
|
|
|
|
err = SGetTypeSRsrc(&spb);
|
|
|
|
while ((err == noErr) &&
|
|
|
|
(spb.spSlot == dce->dCtlSlot) &&
|
|
|
|
(((UInt8)spb.spID) > (UInt8)0x80) &&
|
|
|
|
(((UInt8)spb.spID) < (UInt8)0x90)) {
|
|
|
|
/* write_reg(dce, GOBOFB_DEBUG, 0xBEEF0020); */
|
|
|
|
/* write_reg(dce, GOBOFB_DEBUG, spb.spID); */
|
|
|
|
/* write_reg(dce, GOBOFB_DEBUG, err); */
|
|
|
|
|
|
|
|
if (((UInt8)spb.spID) == max) // should not happen
|
|
|
|
err = smNoMoresRsrcs;
|
|
|
|
if (((UInt8)spb.spID) > max)
|
|
|
|
max = spb.spID;
|
|
|
|
err = SGetTypeSRsrc(&spb);
|
|
|
|
}
|
2022-09-18 12:13:25 +00:00
|
|
|
dStore->maxMode = max;
|
2022-09-18 07:10:04 +00:00
|
|
|
}
|
|
|
|
/* write_reg(dce, GOBOFB_DEBUG, 0xBEEF0000); */
|
2022-09-18 12:13:25 +00:00
|
|
|
/* write_reg(dce, GOBOFB_DEBUG, dStore->maxMode); */
|
2022-09-18 07:10:04 +00:00
|
|
|
{
|
|
|
|
OSErr err = noErr;
|
|
|
|
SpBlock spb;
|
|
|
|
/* check for resolution */
|
|
|
|
UInt8 id;
|
2022-09-18 12:13:25 +00:00
|
|
|
for (id = nativeVidMode; id <= dStore->maxMode ; id ++) {
|
2022-09-18 07:10:04 +00:00
|
|
|
/* try every resource, enabled or not */
|
|
|
|
spb.spParamData = 1<<fall; /* wants disabled */
|
|
|
|
spb.spCategory = catDisplay;
|
|
|
|
spb.spCType = typeVideo;
|
|
|
|
spb.spDrvrSW = drSwApple;
|
|
|
|
spb.spDrvrHW = 0xBEEF;
|
|
|
|
spb.spTBMask = 0;
|
|
|
|
spb.spSlot = dce->dCtlSlot;
|
|
|
|
spb.spID = id;
|
|
|
|
spb.spExtDev = 0;
|
|
|
|
err = SGetSRsrc(&spb);
|
|
|
|
|
|
|
|
if (err == noErr) {
|
|
|
|
spb.spID = kDepthMode1;
|
|
|
|
err = SFindStruct(&spb); /* that will give us the Parms block ... */
|
|
|
|
|
|
|
|
if (err == noErr) {
|
|
|
|
/* take the Parms pointer, add the offset to the Modes block and then skip the block size at the beginning to get the structure pointer ... */
|
|
|
|
const unsigned long offset = *(unsigned long*)spb.spsPointer & 0x00FFFFFF;
|
|
|
|
VPBlockPtr vpblock = (VPBlockPtr)(spb.spsPointer + offset + sizeof(long));
|
|
|
|
UInt8 idx = id - nativeVidMode;
|
2022-09-18 12:13:25 +00:00
|
|
|
dStore->hres[idx] = vpblock->vpBounds.right;
|
|
|
|
dStore->vres[idx] = vpblock->vpBounds.bottom;
|
2022-09-18 07:10:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-18 12:13:25 +00:00
|
|
|
linearGamma(dStore);
|
2022-04-17 09:25:48 +00:00
|
|
|
|
2022-09-18 12:13:25 +00:00
|
|
|
/* now check the content of PRAM */
|
|
|
|
if (0) {
|
|
|
|
SpBlock spb;
|
|
|
|
NuBusFPGAPramRecord pram;
|
|
|
|
OSErr err;
|
|
|
|
spb.spSlot = dce->dCtlSlot;
|
|
|
|
spb.spResult = (UInt32)&pram;
|
|
|
|
err = SReadPRAMRec(&spb);
|
|
|
|
if (err == noErr) {
|
|
|
|
err = reconfHW(dce, pram.mode, pram.depth, pram.page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-17 09:25:48 +00:00
|
|
|
write_reg(dce, GOBOFB_VIDEOCTRL, 1);
|
|
|
|
|
2022-02-05 14:32:44 +00:00
|
|
|
ret = changeIRQ(dce, 1, openErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
2022-10-05 21:46:28 +00:00
|
|
|
#pragma parameter __D0 cNuBusFPGAClose(__A0, __A1)
|
2022-02-05 14:32:44 +00:00
|
|
|
OSErr cNuBusFPGAClose(IOParamPtr pb, /* DCtlPtr */ AuxDCEPtr dce)
|
|
|
|
{
|
|
|
|
OSErr ret = noErr;
|
|
|
|
/* write_reg(dce, GOBOFB_DEBUG, 0xBEEF0003); */
|
|
|
|
/* write_reg(dce, GOBOFB_DEBUG, 0x0000DEAD); */
|
|
|
|
asm(".word 0xfe16\n");
|
|
|
|
if (dce->dCtlStorage != nil)
|
|
|
|
{
|
|
|
|
ret = changeIRQ(dce, 0, openErr);
|
2022-04-17 09:25:48 +00:00
|
|
|
write_reg(dce, GOBOFB_VIDEOCTRL, 0);
|
|
|
|
DisposePtr((Ptr)(*(NuBusFPGADriverGlobalsHdl)dce->dCtlStorage)->siqel);
|
2022-02-05 14:32:44 +00:00
|
|
|
DisposeHandle(dce->dCtlStorage);
|
|
|
|
dce->dCtlStorage = nil;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|