<> <> <> DIRECTORY Basics USING [LongNumber], Buttons USING [Create, ReLabel], IO, Labels USING [Create], Rope, ViewerTools USING [MakeNewTextViewer, SetContents, SetSelection], SoftcardOps, SoftcardToolPrivate; 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; <<* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * >> <> BuildPeekPokeButtons: PUBLIC PROC[topViewer, sibx: Viewer] RETURNS[Viewer] = { sib: Viewer _ sibx; <<>> <> 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]]; <> 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]]; <> 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]]; <> 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"; dn: ROPE = "DumpNum"; 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]; }; END.