SoftcardToolPeekPokeImpl:
CEDAR
PROGRAM
IMPORTS
Buttons, IO, Labels, ViewerTools,
SoftcardOps, SoftcardToolPrivate
EXPORTS
SoftcardToolPrivate
= BEGIN OPEN IO, SoftcardToolPrivate;
peekPokeAddrText: Viewer;
peekPokeValText: Viewer;
peekPokeShortLabel: Viewer;
isShort: BOOL ← TRUE;
AddressingMode: TYPE = { dragonWord, dragonByte, mesaAddr };
peekPokeAddrTypeLabel: Viewer;
whichAddrPP: AddressingMode;
dumpAddrText, dumpNumText: Viewer;
dumpAddrTypeLabel: Viewer;
whichAddrDump: AddressingMode;
mesaMapIndexText, mesaMapValText: Viewer;
dragonMapIndexText, dragonMapValText: Viewer;
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
builds the miscellaneous buttons - sib is the last button created
BuildPeekPokeButtons:
PUBLIC
PROC[topViewer, sibx: Viewer]
RETURNS[Viewer] = {
sib: Viewer ← sibx;
Peek/Poke-Short/Long
sib ← Buttons.Create[
info: [ name: " Peek ", parent: topViewer,
wx: leftEdge, wy: sib.wy+sib.wh+betweenHeight, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: activeFont, proc: PeekProc ];
sib ← Buttons.Create[
info: [ name: " Poke ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: activeFont, proc: PokeProc ];
sib ← peekPokeShortLabel ← Buttons.Create[
info: [ name: " short ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: selectFont, proc: ShortOrLongProc ];
sib ← peekPokeAddrTypeLabel ← Buttons.Create[
info: [ name: " dragonWord ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: selectFont, proc: PPAddrTypeProc ];
sib ← Buttons.Create[
info: [ name: " Addr: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE],
font: selectFont, proc: PeekPokeAddrProc ];
sib ← peekPokeAddrText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy,
ww: 80, wh: entryHeight, border: FALSE, scrollable: FALSE]];
sib ← Buttons.Create[
info: [ name: " Val: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE],
font: selectFont, proc: PeekPokeValProc ];
sib ← peekPokeValText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy,
ww: 120, wh: entryHeight, border: FALSE, scrollable: FALSE]];
DumpShort/Long
sib ← Buttons.Create[
info: [ name: " DumpShort ", parent: topViewer,
wx: leftEdge, wy: sib.wy+sib.wh+betweenHeight, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: activeFont, proc: DumpShortProc ];
sib ← Buttons.Create[
info: [ name: " DumpLong ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: activeFont, proc: DumpLongProc ];
sib ← dumpAddrTypeLabel ← Buttons.Create[
info: [ name: " dragonWord ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: selectFont, proc: DumpAddrTypeProc ];
sib ← Buttons.Create[
info: [ name: " Addr: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE],
font: selectFont, proc: DumpAddrProc ];
sib ← dumpAddrText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy,
ww: 100, wh: entryHeight, border: FALSE, scrollable: FALSE]];
sib ← Buttons.Create[
info: [ name: " Num: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE],
font: selectFont, proc: DumpNumProc ];
sib ← dumpNumText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy,
ww: 60, wh: entryHeight, border: FALSE, scrollable: FALSE]];
MesaMap
sib ← Labels.Create[
info: [ name: " MesaMap ", parent: topViewer,
wx: leftEdge, wy: sib.wy+sib.wh+betweenHeight, wh: entryHeight,
border: FALSE, scrollable: FALSE],
font: labelFont ];
sib ← Buttons.Create[
info: [ name: " Read ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: activeFont, proc: ReadMMProc ];
sib ← Buttons.Create[
info: [ name: " ReadAll ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: activeFont, proc: ReadAllMMProc ];
sib ← Buttons.Create[
info: [ name: " Write ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: activeFont, proc: WriteMMProc ];
sib ← Buttons.Create[
info: [ name: " Index [0..3]: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE],
font: selectFont, proc: MesaMapIndexProc ];
sib ← mesaMapIndexText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy,
ww: 20, wh: entryHeight, border: FALSE, scrollable: FALSE]];
sib ← Buttons.Create[
info: [ name: " dp [0..7]: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE],
font: selectFont, proc: MesaMapValProc ];
sib ← mesaMapValText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy,
ww: 30, wh: entryHeight, border: FALSE, scrollable: FALSE]];
DragonMap
sib ← Labels.Create[
info: [ name: " DragonMap ", parent: topViewer,
wx: leftEdge, wy: sib.wy+sib.wh+betweenHeight, wh: entryHeight,
border: FALSE, scrollable: FALSE],
font: labelFont ];
sib ← Buttons.Create[
info: [ name: " Read ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: activeFont, proc: ReadDrMProc ];
sib ← Buttons.Create[
info: [ name: " Write ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: TRUE, scrollable: FALSE],
font: activeFont, proc: WriteDrMProc ];
sib ← Buttons.Create[
info: [ name: " Index [0..3fffH]: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE],
font: selectFont, proc: DragonMapIndexProc ];
sib ← dragonMapIndexText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy,
ww: 50, wh: entryHeight, border: FALSE, scrollable: FALSE]];
sib ← Buttons.Create[
info: [ name: " rp [0..3ffH]: ", parent: topViewer,
wx: sib.wx+sib.ww+xFudge, wy: sib.wy, wh: entryHeight,
border: FALSE, scrollable: FALSE],
font: selectFont, proc: DragonMapValProc ];
sib ← dragonMapValText ← ViewerTools.MakeNewTextViewer[
info: [parent: topViewer, wx: sib.wx+sib.ww+xFudge+6, wy: sib.wy,
ww: 300, wh: entryHeight, border: FALSE, scrollable: FALSE]];
RETURN[sib];
};
errorMessage:
ROPE = "\n\t***Softcard Error during %g - reason is: %g\n\n";
PeekProc: ClickProc = {
addr: CARD32;
mesaAddr: CARD32;
longVal: CARD32;
ok: BOOL;
BEGIN
ENABLE SoftcardOps.SCError => {
TSOutPutF[errorMessage, [rope["Peek"]], [rope[explanation]] ];
GOTO exit
};
[ok, addr] ← CheckedGetAsCard[peekPokeAddrText, "PeekAddr", 0];
IF ~ok THEN RETURN;
mesaAddr ← ConvertToMesaAddr[addr, whichAddrPP];
IF isShort
THEN longVal ← SoftcardOps.ReadShort[mesaAddr]
ELSE longVal ← SoftcardOps.ReadLong[mesaAddr];
EXITS exit => RETURN;
END;
TSOutPutF[" The %g value of addr: %xH is %xH\n",
[rope[IF isShort THEN "short" ELSE "long"]], [cardinal[addr]], [cardinal[longVal]] ];
ViewerTools.SetContents[peekPokeValText, IO.PutFR["%xH", [cardinal[longVal]]] ];
};
PokeProc: ClickProc = {
addr, longVal: CARD32;
mesaAddr: CARD32;
ok: BOOL;
BEGIN
ENABLE SoftcardOps.SCError => {
TSOutPutF[errorMessage, [rope["Poke"]], , [rope[explanation]]];
GOTO exit
};
[ok, addr] ← CheckedGetAsCard[peekPokeAddrText, "PokeAddr", 0];
IF ~ok THEN RETURN;
[ok, longVal] ← CheckedGetAsCard[peekPokeValText, "PokeVal", 0];
IF ~ok THEN RETURN;
mesaAddr ← ConvertToMesaAddr[addr, whichAddrDump];
IF isShort
THEN {
shortVal: CARD16 ← longVal;
SoftcardOps.WriteShort[mesaAddr, shortVal];
}
ELSE SoftcardOps.WriteLong[mesaAddr, longVal];
EXITS exit => RETURN;
END;
TSOutPutF[" The %g value of addr: %xH has been set to %xH\n",
[rope[IF isShort THEN "short" ELSE "long"]], [cardinal[addr]], [cardinal[longVal]] ];
};
ShortOrLongProc: ClickProc = {
IF isShort
THEN Buttons.ReLabel[peekPokeShortLabel, " long "]
ELSE Buttons.ReLabel[peekPokeShortLabel, " short "];
isShort ← ~isShort;
};
PPAddrTypeProc : ClickProc = {
newLabel: ROPE;
SELECT whichAddrPP
FROM
dragonWord => { newLabel ← " dragonByte "; whichAddrPP ← dragonByte };
dragonByte => { newLabel ← " mesaAddr "; whichAddrPP ← mesaAddr };
mesaAddr => { newLabel ← " dragonWord "; whichAddrPP ← dragonWord };
ENDCASE => NULL;
Buttons.ReLabel[peekPokeAddrTypeLabel, newLabel];
};
PeekPokeAddrProc: ClickProc =
{ ViewerTools.SetSelection[peekPokeAddrText, NIL] };
PeekPokeValProc: ClickProc =
{ ViewerTools.SetSelection[peekPokeValText, NIL] };
da: ROPE = "DumpAddr";
DumpShortProc: ClickProc = {
addr, num: CARD32;
mesaAddr: CARD32;
ok: BOOL;
shortNum: CARD16;
count: CARD16;
index: CARD16 ← 0;
seq: SoftcardOps.SeqShort;
format: ROPE = " %04x";
[ok, addr] ← CheckedGetAsCard[dumpAddrText, da, 0];
IF ~ok THEN RETURN;
[ok, num] ← CheckedGetAsCard[dumpNumText, dn,
LAST[
CARD16]];
IF ~ok THEN RETURN;
mesaAddr ← ConvertToMesaAddr[addr, whichAddrDump];
shortNum ← num;
count ← shortNum;
BEGIN
ENABLE SoftcardOps.SCError => {
TSOutPutF[errorMessage, [rope["DumpShort"]], [rope[explanation]]];
GOTO exit
};
seq ← SoftcardOps.DumpShort[mesaAddr, shortNum];
EXITS exit => RETURN;
END;
TSOutPutF["\n Dumping %g short numbers starting at addr: %xH\n",
[cardinal[num]], [cardinal[addr]] ];
WHILE count >= 8
DO
TSOutPutF["%xH:", [cardinal[addr+index]] ];
FOR i:
CARD16
IN [0..8)
DO
TSOutPutF[format, [cardinal[seq[index+i]]] ];
ENDLOOP;
TSOutPutChar['\n];
index ← index + 8;
count ← count - 8;
ENDLOOP;
IF count # 0
THEN {
TSOutPutF["%xH:", [cardinal[addr+index]] ];
FOR i:
CARD16
IN [0..count)
DO
TSOutPutF[format, [cardinal[seq[index+i]]] ];
ENDLOOP;
TSOutPutChar['\n];
};
};
DumpLongProc: ClickProc = {
addr, num: CARD32;
mesaAddr: CARD32;
ok: BOOL;
shortNum: CARD16;
count: CARD16;
index: CARD16 ← 0;
seq: SoftcardOps.SeqLong;
format: ROPE = " %08x";
[ok, addr] ← CheckedGetAsCard[dumpAddrText, da, 0];
IF ~ok THEN RETURN;
[ok, num] ← CheckedGetAsCard[dumpNumText, dn,
LAST[
CARD16]];
IF ~ok THEN RETURN;
mesaAddr ← ConvertToMesaAddr[addr, whichAddrDump];
shortNum ← num;
count ← shortNum;
BEGIN
ENABLE SoftcardOps.SCError => {
TSOutPutF[errorMessage, [rope["DumpLong"]], [rope[explanation]]];
GOTO exit
};
seq ← SoftcardOps.DumpLong[mesaAddr, shortNum];
IF seq =
NIL
THEN {
TSOutPutRope[" DumpLong not yet implemented\n"];
RETURN
};
EXITS exit => RETURN;
END;
TSOutPutF["\n Dumping %g long numbers starting at addr: %xH\n",
[cardinal[num]], [cardinal[addr]] ];
WHILE count >= 8
DO
TSOutPutF["%xH:", [cardinal[addr+index]] ];
FOR i:
CARD16
IN [0..8)
DO
TSOutPutF[format, [cardinal[seq[index+i]]] ];
ENDLOOP;
TSOutPutChar['\n];
index ← index + 8;
count ← count - 8;
ENDLOOP;
IF count # 0
THEN {
TSOutPutF["%xH:", [cardinal[addr+index]] ];
FOR i:
CARD16
IN [0..count)
DO
TSOutPutF[format, [cardinal[seq[index+i]]] ];
ENDLOOP;
TSOutPutChar['\n];
};
};
DumpAddrTypeProc: ClickProc = {
newLabel: ROPE;
SELECT whichAddrDump
FROM
dragonWord => { newLabel ← " dragonByte "; whichAddrDump ← dragonByte };
dragonByte => { newLabel ← " mesaAddr "; whichAddrDump ← mesaAddr };
mesaAddr => { newLabel ← " dragonWord "; whichAddrDump ← dragonWord };
ENDCASE => NULL;
Buttons.ReLabel[dumpAddrTypeLabel, newLabel]
};
DumpAddrProc: ClickProc =
{ ViewerTools.SetSelection[dumpAddrText, NIL] };
DumpNumProc: ClickProc =
{ ViewerTools.SetSelection[dumpNumText, NIL] };
mmi:
ROPE = "MesaMapIndex";
ReadMMProc: ClickProc = {
longIndex: CARD32;
index: SoftcardOps.MesaMapIndex;
entry: SoftcardOps.MesaMapEntry;
ok: BOOL;
[ok, longIndex] ← CheckedGetAsCard[mesaMapIndexText, mmi, 3];
IF ~ok THEN RETURN;
index ← longIndex;
PrintMM[index, entry ← SoftcardOps.ReadMesaMap[index]];
ViewerTools.SetContents[mesaMapValText, IO.PutFR["%g", [cardinal[entry.dp]]] ];
};
ReadAllMMProc: ClickProc = {
TSOutPutRope["\n Reading all the MesaMap entries\n"];
FOR index: SoftcardOps.MesaMapIndex
IN [0..3]
DO
PrintMM[index, SoftcardOps.ReadMesaMap[index]];
ENDLOOP;
TSOutPutChar['\n];
};
PrintMM:
PROC[index: SoftcardOps.MesaMapIndex, entry: SoftcardOps.MesaMapEntry] = {
TSOutPutF[" MesaMap[%g] has value [dp: %g]\n", [cardinal[index]], [cardinal[entry.dp]] ];
};
WriteMMProc: ClickProc = {
longIndex, val: CARD32;
ok: BOOL;
index: SoftcardOps.MesaMapIndex;
entry: SoftcardOps.MesaMapEntry;
[ok, longIndex] ← CheckedGetAsCard[mesaMapIndexText, mmi, 3];
IF ~ok THEN RETURN;
[ok, val] ← CheckedGetAsCard[mesaMapValText, "MesaMapVal", 7];
IF ~ok THEN RETURN;
index ← longIndex;
entry.dp ← LOOPHOLE[LOOPHOLE[val, Basics.LongNumber].lo];
SoftcardOps.WriteMesaMap[index, entry];
TSOutPutF[" MesaMap[%g] has been set to value [dp: %g]\n",
[cardinal[index]], [cardinal[entry.dp]] ];
};
MesaMapIndexProc: ClickProc =
{ ViewerTools.SetSelection[mesaMapIndexText, NIL] };
MesaMapValProc: ClickProc =
{ ViewerTools.SetSelection[mesaMapValText, NIL] };
drmi: ROPE = "DragonMapIndex";
ReadDrMProc: ClickProc = {
longIndex: CARD32;
index: SoftcardOps.DragonMapIndex;
entry: SoftcardOps.DragonMapEntry;
ok: BOOL;
[ok, longIndex] ← CheckedGetAsCard[dragonMapIndexText, drmi, 3fffH];
IF ~ok THEN RETURN;
entry ← SoftcardOps.ReadDragonMap[index];
TSOutPutF[" DragonMap[%g] has value [rp: %g]\n",
[cardinal[index]], [cardinal[entry.rp]] ];
ViewerTools.SetContents[dragonMapValText, IO.PutFR["%g", [cardinal[entry.rp]]] ];
};
WriteDrMProc: ClickProc = {
longIndex, val: CARD32;
ok: BOOL;
index: SoftcardOps.DragonMapIndex;
entry: SoftcardOps.DragonMapEntry;
[ok, longIndex] ← CheckedGetAsCard[dragonMapIndexText, drmi, 3fffH];
IF ~ok THEN RETURN;
[ok, val] ← CheckedGetAsCard[dragonMapValText, "DragonMapVal", 3ffH];
IF ~ok THEN RETURN;
entry.rp ← LOOPHOLE[LOOPHOLE[val, Basics.LongNumber].lo];
SoftcardOps.WriteDragonMap[index, entry];
TSOutPutF[" DragonMap[%g] has been set to value [rp: %g]\n",
[cardinal[index]], [cardinal[entry.rp]] ];
};
DragonMapIndexProc: ClickProc =
{ ViewerTools.SetSelection[dragonMapIndexText, NIL] };
DragonMapValProc: ClickProc =
{ ViewerTools.SetSelection[dragonMapValText, NIL] };
DragonToSoftcardAddr:
PUBLIC
PROC[addr:
CARD32]
RETURNS[softAddr:
CARD32] = {
softAddr ← 100000H + 2*(addr MOD 40000H);
};
ByteToSoftcardAddr:
PUBLIC
PROC[addr:
CARD32]
RETURNS[softAddr:
CARD32] = {
softAddr ← 100000H + (addr MOD 100000H)/2;
};
ConvertToMesaAddr:
PROC[addr:
CARD32, which: AddressingMode]
RETURNS[
CARD32] = {
SELECT which
FROM
dragonWord => RETURN[DragonToSoftcardAddr[addr]];
dragonByte => RETURN[ByteToSoftcardAddr[addr]];
mesaAddr => RETURN[addr];
ENDCASE => RETURN[addr];