home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
programs
/
emulator
/
appleonamiga
/
txt
/
applescreen.mod
< prev
next >
Wrap
Text File
|
1995-02-27
|
13KB
|
419 lines
IMPLEMENTATION MODULE AppleScreen;
FROM SYSTEM IMPORT ADDRESS,ADR,BITSET,LONGSET,TAG;
FROM Base37 IMPORT A,B,N;
IMPORT
ACASLReq,d:DosD,D:DosL,e:ExecD,E:ExecL,g:GraphicsD,G:GraphicsL,i:IntuitionD,I:IntuitionL
,u:UtilityD;
CONST
blinkName="AppleBlinkProc";
errNoScreen="No screen";
errNoWindow="No window";
errHeight="Window heigt <192";
errWidth="Window width <280";
kbdName="AppleKBDProc";
screenFont="topaz.font";
title="Apple 2 Emulator V0.1, 03-Jan-1993/cn";
disk1Menu="Disk 1";
disk2Menu="Disk 2";
diskItemLoad="Load Disk...";
diskItemUnLoad="Unload Disk";
diskItemWriteProtect="Write protected";
projectMenu="Project";
projectItemQuit="Quit";
load1="Load Disk 1";
load2="Load Disk 2";
TYPE
Color32=ARRAY [0..32] OF i.ColorSpec;
Palette=ARRAY [0..15] OF [0..31];
Pens=ARRAY [0..12] OF INTEGER;
CONST
appleColors=Color32{
i.ColorSpec{colorIndex:0,red:10,green:10,blue:10}, (* WB 0 *)
i.ColorSpec{colorIndex:1,red:0,green:0,blue:0}, (* WB 1 *)
i.ColorSpec{colorIndex:2,red:15,green:15,blue:15}, (* WB 2 *)
i.ColorSpec{colorIndex:3,red:6,green:8,blue:11}, (* WB 3 *)
i.ColorSpec{colorIndex:4,red:14,green:4,blue:4}, (* WB 4 *)
i.ColorSpec{colorIndex:5,red:5,green:13,blue:5}, (* WB 5 *)
i.ColorSpec{colorIndex:6,red:0,green:4,blue:13}, (* WB 6 *)
i.ColorSpec{colorIndex:7,red:14,green:9,blue:0} (* WB 7 *)
i.ColorSpec{colorIndex:8,red:0,green:0,blue:0}, (* black = hires 0 and 4 *)
i.ColorSpec{colorIndex:9,red:8,green:0,blue:4}, (* magenta *)
i.ColorSpec{colorIndex:10,red:0,green:0,blue:6}, (* dark blue *)
i.ColorSpec{colorIndex:11,red:11,green:0,blue:15}, (* purple = hires 2 *)
i.ColorSpec{colorIndex:12,red:0,green:15,blue:0}, (* dark green *)
i.ColorSpec{colorIndex:13,red:9,green:9,blue:9}, (* grey 1 *)
i.ColorSpec{colorIndex:14,red:0,green:6,blue:12}, (* medium blue = hires 6 *)
i.ColorSpec{colorIndex:15,red:0,green:13,blue:13}, (* light blue *)
i.ColorSpec{colorIndex:16,red:3,green:3,blue:3},
i.ColorSpec{colorIndex:17,red:14,green:4,blue:4}, (* POINTER 1 *)
i.ColorSpec{colorIndex:18,red:0,green:0,blue:0}, (* POINTER 2 *)
i.ColorSpec{colorIndex:19,red:14,green:14,blue:12}, (* POINTER 3 *)
i.ColorSpec{colorIndex:20,red:15,green:15,blue:15}, (* Blinking white/black *)
i.ColorSpec{colorIndex:21,red:0,green:0,blue:0}, (* Blinking black/white *)
i.ColorSpec{colorIndex:22,red:6,green:6,blue:6},
i.ColorSpec{colorIndex:23,red:7,green:7,blue:7},
i.ColorSpec{colorIndex:24,red:8,green:5,blue:0}, (* brown *)
i.ColorSpec{colorIndex:25,red:15,green:8,blue:0}, (* orange = hires 5 *)
i.ColorSpec{colorIndex:26,red:8,green:8,blue:8}, (* grey 2 *)
i.ColorSpec{colorIndex:27,red:15,green:11,blue:11}, (* pink *)
i.ColorSpec{colorIndex:28,red:0,green:13,blue:0}, (* green = hires 1 *)
i.ColorSpec{colorIndex:29,red:15,green:15,blue:0}, (* yellow *)
i.ColorSpec{colorIndex:30,red:0,green:9,blue:13}, (* aqua *)
i.ColorSpec{colorIndex:31,red:15,green:15,blue:15}, (* white = hires 3 and 7 *)
i.ColorSpec{colorIndex:-1,red:0,green:0,blue:0} (* Terminate color list *)
};
applePalette=Palette{8,9,10,11,12,13,14,15,24,25,26,27,28,29,30,31};
black=8; white=31;
blinkBlack=20; blinkWhite=21;
wb0=0; wb1=1; wb2=2; wb3=3; wb4=4; wb5=5; wb6=6; wb7=7;
pens=Pens{wb0,wb1,wb1,wb2,wb1,wb3,wb1,wb0,wb2,wb1,wb2,wb1,-1};
CONST
menuWidth=80;
menu0L=10; menu1L=menu0L+menuWidth; menu2L=menu1L+menuWidth;
menuItemWidth=2*menuWidth;
menuItemHeight=10;
menuItem1T=0;
menuItem2T=menuItem1T+menuItemHeight;
menuItem3T=menuItem2T+menuItemHeight;
VAR
appleMenuItem3:=i.MenuItem{
nextItem:NIL
,leftEdge:0,topEdge:menuItem3T,width:menuItemWidth,height:menuItemHeight
,flags:i.MenuItemFlagSet{i.itemText,i.itemEnabled,i.highComp,i.checkIt,i.menuToggle}
,mutualExclude:LONGSET{}
,itemFill:ADR(i.IntuiText{
frontPen:2,backPen:1,drawMode:g.jam2,leftEdge:i.checkWidth,topEdge:0,iTextFont:NIL
,iText:ADR(diskItemWriteProtect),nextText:NIL
})
,selectFill:NIL,command:" ",subItem:NIL,nextSelect:0
};
appleMenuItem2:=i.MenuItem{
nextItem:ADR(appleMenuItem3)
,leftEdge:0,topEdge:menuItem2T,width:menuItemWidth,height:menuItemHeight
,flags:i.MenuItemFlagSet{i.itemText,i.itemEnabled,i.highComp}
,mutualExclude:LONGSET{}
,itemFill:ADR(i.IntuiText{
frontPen:2,backPen:1,drawMode:g.jam2,leftEdge:0,topEdge:0,iTextFont:NIL
,iText:ADR(diskItemUnLoad),nextText:NIL
})
,selectFill:NIL,command:" ",subItem:NIL,nextSelect:0
};
appleMenuItem1:=i.MenuItem{
nextItem:ADR(appleMenuItem2)
,leftEdge:0,topEdge:menuItem1T,width:menuItemWidth,height:menuItemHeight
,flags:i.MenuItemFlagSet{i.itemText,i.itemEnabled,i.highComp}
,mutualExclude:LONGSET{}
,itemFill:ADR(i.IntuiText{
frontPen:2,backPen:1,drawMode:g.jam2,leftEdge:0,topEdge:0,iTextFont:NIL
,iText:ADR(diskItemLoad),nextText:NIL
})
,selectFill:NIL,command:" ",subItem:NIL,nextSelect:0
};
appleMenuItem6:=i.MenuItem{
nextItem:NIL
,leftEdge:0,topEdge:menuItem3T,width:menuItemWidth,height:menuItemHeight
,flags:i.MenuItemFlagSet{i.itemText,i.itemEnabled,i.highComp,i.checkIt,i.menuToggle}
,mutualExclude:LONGSET{}
,itemFill:ADR(i.IntuiText{
frontPen:2,backPen:1,drawMode:g.jam2,leftEdge:i.checkWidth,topEdge:0,iTextFont:NIL
,iText:ADR(diskItemWriteProtect),nextText:NIL
})
,selectFill:NIL,command:" ",subItem:NIL,nextSelect:0
};
appleMenuItem5:=i.MenuItem{
nextItem:ADR(appleMenuItem6)
,leftEdge:0,topEdge:menuItem2T,width:menuItemWidth,height:menuItemHeight
,flags:i.MenuItemFlagSet{i.itemText,i.itemEnabled,i.highComp}
,mutualExclude:LONGSET{}
,itemFill:ADR(i.IntuiText{
frontPen:2,backPen:1,drawMode:g.jam2,leftEdge:0,topEdge:0,iTextFont:NIL
,iText:ADR(diskItemUnLoad),nextText:NIL
})
,selectFill:NIL,command:" ",subItem:NIL,nextSelect:0
};
appleMenuItem4:=i.MenuItem{
nextItem:ADR(appleMenuItem5)
,leftEdge:0,topEdge:menuItem1T,width:menuItemWidth,height:menuItemHeight
,flags:i.MenuItemFlagSet{i.itemText,i.itemEnabled,i.highComp}
,mutualExclude:LONGSET{}
,itemFill:ADR(i.IntuiText{
frontPen:2,backPen:1,drawMode:g.jam2,leftEdge:0,topEdge:0,iTextFont:NIL
,iText:ADR(diskItemLoad),nextText:NIL
})
,selectFill:NIL,command:" ",subItem:NIL,nextSelect:0
};
appleMenuItem7:=i.MenuItem{
nextItem:NIL
,leftEdge:0,topEdge:menuItem1T,width:menuItemWidth,height:menuItemHeight
,flags:i.MenuItemFlagSet{i.itemText,i.itemEnabled,i.highComp}
,mutualExclude:LONGSET{}
,itemFill:ADR(i.IntuiText{
frontPen:2,backPen:1,drawMode:g.jam2,leftEdge:0,topEdge:0,iTextFont:NIL
,iText:ADR(projectItemQuit),nextText:NIL
})
,selectFill:NIL,command:" ",subItem:NIL,nextSelect:0
};
appleMenu2:=i.Menu{
nextMenu:NIL,leftEdge:menu2L,topEdge:0,width:menuWidth,height:0
,flags:BITSET{i.menuEnabled},menuName:ADR(disk2Menu),firstItem:ADR(appleMenuItem4)
};
appleMenu1:=i.Menu{
nextMenu:ADR(appleMenu2),leftEdge:menu1L,topEdge:0,width:menuWidth,height:0
,flags:BITSET{i.menuEnabled},menuName:ADR(disk1Menu),firstItem:ADR(appleMenuItem1)
};
appleMenu0:=i.Menu{
nextMenu:ADR(appleMenu1),leftEdge:menu0L,topEdge:0,width:menuWidth,height:0
,flags:BITSET{i.menuEnabled},menuName:ADR(projectMenu),firstItem:ADR(appleMenuItem7)
};
VAR
appleMenu:i.MenuPtr;
CONST
textPageStart=0400H;
VAR
appleRastPort:g.RastPortPtr;
appleViewPort:g.ViewPortPtr;
appleWindow:i.WindowPtr;
killBlink,killBlinkReply:LONGINT;
killKBD,killKBDReply:LONGINT;
mainTask:e.TaskPtr;
PROCEDURE BlinkProc;
(*$ LoadA4:=TRUE *)
BEGIN
killBlink:=E.AllocSignal(-1);
REPEAT
G.SetRGB4(appleViewPort,blinkBlack,0,0,0);
G.SetRGB4(appleViewPort,blinkWhite,15,15,15);
D.Delay(15);
G.SetRGB4(appleViewPort,blinkBlack,15,15,15);
G.SetRGB4(appleViewPort,blinkWhite,0,0,0);
D.Delay(15);
UNTIL killBlink IN E.SetSignal(LONGSET{},LONGSET{}); (* Test if killBlink was set. *)
E.FreeSignal(killBlink);
E.Signal(mainTask,LONGSET{killBlinkReply});
END BlinkProc;
PROCEDURE KBDProc;
(*$ LoadA4:=TRUE *)
VAR
ch:CHAR;
class:i.IDCMPFlagSet;
code:CARDINAL;
disk:[1..2];
intuiMsg:i.IntuiMessagePtr;
item:i.MenuItemPtr;
signals:LONGSET;
BEGIN
killKBD:=E.AllocSignal(-1);
(*
KBDProc has to create port
*)
I.ModifyIDCMP(appleWindow,i.IDCMPFlagSet{i.vanillaKey,i.rawKey,i.menuPick});
LOOP
signals:=E.Wait(LONGSET{killKBD,appleWindow^.userPort^.sigBit});
IF appleWindow^.userPort^.sigBit IN signals THEN
LOOP
intuiMsg:=E.GetMsg(appleWindow^.userPort);
IF intuiMsg=NIL THEN EXIT; END;
class:=intuiMsg^.class; code:=intuiMsg^.code;
E.ReplyMsg(intuiMsg);
IF i.menuPick IN class THEN
WHILE code#i.menuNull DO
item:=I.ItemAddress(appleMenu,code);
CASE code MOD 32 OF
| 0:
IF code DIV 32 MOD 64=0 THEN quit(); END;
| 1,2:
disk:=code MOD 32;
CASE (code DIV 32) MOD 64 OF
| 0:
diskLoad(disk);
IF i.checked IN item^.flags THEN diskProtect(disk,TRUE); END;
| 1:
diskUnload(disk);
| 2:
IF i.checked IN item^.flags THEN diskProtect(disk,TRUE);
ELSE diskProtect(disk,FALSE);
END;
END;
END;
code:=item^.nextSelect;
END;
END;
IF i.vanillaKey IN class THEN
ch:=CHR(code MOD 128);
CASE ch OF
| "M": ch:="]";
| "N": ch:="^";
| "P": ch:="@";
| "a".."z": ch:=CAP(ch);
ELSE (* leave it as it is *)
END;
lastKey:=80H+ORD(ch);
END;
IF i.rawKey IN class THEN
CASE code OF
| 05FH: IF reset#NIL THEN reset(); END;
| 04FH: lastKey:=088H;
| 04EH: lastKey:=095H;
ELSE (* ignore all other keys *)
END;
END;
END;
END;
IF killKBD IN signals THEN
EXIT;
END;
END;
(*
KBDProc has to remove port
*)
I.ModifyIDCMP(appleWindow,i.IDCMPFlagSet{});
E.FreeSignal(killKBD);
E.Signal(mainTask,LONGSET{killKBDReply});
END KBDProc;
PROCEDURE RequestDisk(diskNum:DiskNum; VAR name:ARRAY OF CHAR):BOOLEAN;
VAR
title:ARRAY [0..39] OF CHAR;
BEGIN
IF diskNum=1 THEN title:=load1; ELSE title:=load2; END;
RETURN ACASLReq.FileReq(name,title,"",FALSE);
END RequestDisk;
PROCEDURE PutText(line,col:CARDINAL; text:ADDRESS; length:CARDINAL);
VAR
ch:[0..255];
i:CARDINAL;
p:POINTER TO ARRAY [0..9999] OF [0..255];
BEGIN
p:=text;
G.SetDrMd(appleRastPort,g.jam2);
G.Move(appleRastPort,(col+i)*8,line*8+6);
FOR i:=0 TO length-1 DO
ch:=p^[i];
CASE ch DIV 64 OF
| 0: G.SetAPen(appleRastPort,black); G.SetBPen(appleRastPort,white);
| 1: G.SetAPen(appleRastPort,blinkBlack); G.SetBPen(appleRastPort,blinkWhite);
| 2: G.SetAPen(appleRastPort,white); G.SetBPen(appleRastPort,black);
| 3: G.SetAPen(appleRastPort,white); G.SetBPen(appleRastPort,black);
END;
ch:=ch MOD 64; IF ch<32 THEN INC(ch,64); END;
G.Text(appleRastPort,ADR(ch),1);
END;
END PutText;
VAR
appleScreen:i.ScreenPtr;
appleTextAttr:g.TextAttr;
blinkProcess,kbdProcess:d.ProcessPtr;
hasMenu:BOOLEAN;
oldWindow:i.WindowPtr;
proc:d.ProcessPtr;
tagbuf:ARRAY [0..19] OF LONGCARD;
trapHandler:PROC;
BEGIN
(*
Open screen and window.
*)
appleTextAttr.name:=ADR(screenFont);
appleTextAttr.ySize:=8;
appleTextAttr.style:=g.FontStyleSet{};
appleTextAttr.flags:=g.FontFlagSet{};
appleScreen:=I.OpenScreenTagList(
NIL,TAG(
tagbuf,i.saDepth,5,i.saTitle,ADR(title),i.saPens,ADR(pens)
,i.saDisplayID,g.loresKey,i.saColors,ADR(appleColors)
,i.saFont,ADR(appleTextAttr)
(* ,i.saBlockPen,wb0,i.saDetailPen,wb1*)
,u.tagDone
)
);
N(appleScreen,errNoScreen);
appleViewPort:=ADR(appleScreen^.viewPort);
appleWindow:=I.OpenWindowTagList(
NIL
,TAG(
tagbuf,i.waScreenTitle,ADR(title),i.waCustomScreen,appleScreen
,i.waTop,appleScreen^.barHeight+1,i.waHeight,appleScreen^.height-appleScreen^.barHeight-1
,i.waBorderless,TRUE,i.waBackdrop,TRUE,i.waActivate,TRUE
,i.waIDCMP,i.IDCMPFlagSet{} (* No IDCMP, as KBDProc has to open the port *)
,u.tagDone
)
);
N(appleWindow,errNoWindow);
appleMenu:=ADR(appleMenu0);
hasMenu:=I.SetMenuStrip(appleWindow,appleMenu);
A(appleWindow^.width>=280,errWidth);
A(appleWindow^.height>=192,errHeight);
appleRastPort:=appleWindow^.rPort;
proc:=ADDRESS(E.FindTask(NIL));
oldWindow:=proc^.windowPtr;
proc^.windowPtr:=appleWindow;
trapHandler:=proc^.task.trapCode;
(*
Start process for blinking.
*)
mainTask:=E.FindTask(NIL);
killBlinkReply:=E.AllocSignal(-1);
blinkProcess:=D.CreateNewProc(
TAG(tagbuf,d.npEntry,ADR(BlinkProc),d.npName,ADR(blinkName),u.tagDone)
);
blinkProcess^.task.trapCode:=trapHandler;
killKBDReply:=E.AllocSignal(-1);
kbdProcess:=D.CreateNewProc(
TAG(tagbuf,
d.npEntry,ADR(KBDProc),d.npName,ADR(kbdName),d.npPriority,10,u.tagDone
)
);
kbdProcess^.task.trapCode:=trapHandler;
CLOSE
IF blinkProcess#NIL THEN
E.Signal(ADR(blinkProcess^.task),LONGSET{killBlink});
IF E.Wait(LONGSET{killBlinkReply})=LONGSET{} THEN END;
END;
IF kbdProcess#NIL THEN
E.Signal(ADR(kbdProcess^.task),LONGSET{killKBD});
IF E.Wait(LONGSET{killKBDReply})=LONGSET{} THEN END;
END;
E.FreeSignal(killBlinkReply);
(*
NOTE: Close window only after KBDProc terminated.
*)
proc^.windowPtr:=oldWindow;
IF appleWindow#NIL THEN
IF hasMenu THEN I.ClearMenuStrip(appleWindow); END;
I.CloseWindow(appleWindow); appleWindow:=NIL;
END;
IF appleScreen#NIL THEN I.CloseScreen(appleScreen); appleScreen:=NIL; END;
END AppleScreen.