Model subclass: #TD4Simulator instanceVariableNames: 'cpu isAuto isFast' classVariableNames: '' poolDictionaries: '' category: 'TD4-UI'! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/8/2006 22:32'! buttonMorphLabel: aString selector: aSymbol | aButton | aButton := SimpleButtonMorph new. aButton target: self; label: aString; actionSelector: aSymbol; borderColor: #raised; borderWidth: 2; color: Color transparent. ^ aButton! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/9/2006 12:04'! defaultBackgroundColor ^ Color r: 0.935 g: 0.581 b: 0.0! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/8/2006 23:40'! inputBit: aBitNumber morph: aMorph | value mask | value := cpu input. mask := 1 << aBitNumber. value := value bitXor: mask. cpu input: value. aMorph state: ((value bitAnd: mask) > 0 ifTrue: [#on] ifFalse: [#off])! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/9/2006 12:07'! makeArithmeticMorph | col row morph | col := AlignmentMorph newColumn color: Color transparent. col hResizing: #spaceFill; vResizing: #shrinkWrap. row := AlignmentMorph newRow color: Color magenta. row addMorphBack: (StringMorph contents: 'Arithmetic'). row addMorphBack: AlignmentMorph newVariableTransparentSpacer. col addMorphBack: row. row := AlignmentMorph newRow color: Color transparent. morph := UpdatingStringMorph on: self selector: #adderInput. morph useStringFormat. row addMorphBack: morph. col addMorphBack: row. row := AlignmentMorph newRow color: Color transparent. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. row addMorphBack: (StringMorph contents: '='). morph := UpdatingStringMorph on: self selector: #adderOutput. morph useStringFormat. row addMorphBack: morph. col addMorphBack: row. ^ col! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/14/2006 17:48'! makeClockButtons | row morph onColor offColor | onColor := Color cyan. offColor := Color lightGray. row := AlignmentMorph newRow color: Color transparent. row hResizing: #spaceFill. morph := PluggableButtonMorph on: self getState: #manualIndicated action: #beManual. morph label: 'manual'; askBeforeChanging: false; borderWidth: 0; onColor: onColor offColor: offColor. row addMorphBack: morph. morph := PluggableButtonMorph on: self getState: #autoIndicated action: #beAuto. morph label: 'auto'; askBeforeChanging: false; borderWidth: 0; onColor: onColor offColor: offColor. row addMorphBack: morph. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. morph := PluggableButtonMorph on: self getState: #slowIndicated action: #beSlow. morph label: 'slow'; askBeforeChanging: false; borderWidth: 0; onColor: onColor offColor: offColor. row addMorphBack: morph. morph := PluggableButtonMorph on: self getState: #fastIndicated action: #beFast. morph label: 'fast'; askBeforeChanging: false; borderWidth: 0; onColor: onColor offColor: offColor. row addMorphBack: morph. ^ row! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/14/2006 17:53'! makeControllerMorph | col row morph | col := AlignmentMorph newColumn color: Color transparent. col hResizing: #spaceFill; vResizing: #shrinkWrap. row := AlignmentMorph newRow color: Color green. row addMorphBack: (StringMorph contents: 'Controller'). row addMorphBack: AlignmentMorph newVariableTransparentSpacer. col addMorphBack: row. row := AlignmentMorph newRow color: Color transparent. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. row addMorphBack: (StringMorph contents: 'PC='). morph := UpdatingStringMorph on: self selector: #pc. morph useStringFormat. row addMorphBack: morph. col addMorphBack: row. col addMorphBack: self makeClockButtons. row := AlignmentMorph newRow color: Color transparent. row addMorphBack: ((self buttonMorphLabel: 'Reset' selector: #reset) color: Color red; yourself). row addMorphBack: AlignmentMorph newVariableTransparentSpacer. row addMorphBack: ((self buttonMorphLabel: 'Step' selector: #clock) color: Color green; yourself). col addMorphBack: row. ^ col! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/9/2006 16:35'! makeFooterPane | row | row := AlignmentMorph newRow color: Color transparent. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. row addMorphBack: (self buttonMorphLabel: 'About' selector: #openAbout). ^ row! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/9/2006 12:06'! makeInputMorph | col row morph | col := AlignmentMorph newColumn color: Color transparent. col hResizing: #spaceFill; vResizing: #shrinkWrap. row := AlignmentMorph newRow color: Color yellow. row addMorphBack: (StringMorph contents: 'Input'). row addMorphBack: AlignmentMorph newVariableTransparentSpacer. col addMorphBack: row. row := AlignmentMorph newRow color: Color transparent. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. 3 to: 0 by: -1 do: [:each | morph := ThreePhaseButtonMorph checkBox. morph target: self; actionSelector: #inputBit:morph:; arguments: (Array with: each with: morph); actWhen: #buttonDown. row addMorphBack: morph]. col addMorphBack: row. ^ col! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/9/2006 21:16'! makeLowerPane | col row | col := AlignmentMorph newColumn color: Color transparent. col vResizing: #spaceFill. row := AlignmentMorph newRow color: (Color r: 1.0 g: 0.8 b: 0). row addMorphBack: (StringMorph contents: 'ROM'). row addMorphBack: AlignmentMorph newVariableTransparentSpacer. col addMorphBack: row. 0 to: 3 do: [:each1 | row := AlignmentMorph newRow color: Color transparent. 0 to: 3 do: [:each2 | row addMorphBack: (self makeRomEntryAt: each1 * 4 + each2)]. col addMorphBack: row]. ^ col! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/14/2006 17:28'! makeOutputMorph | col row morph | col := AlignmentMorph newColumn color: Color transparent. col hResizing: #spaceFill; vResizing: #shrinkWrap. row := AlignmentMorph newRow color: (Color r: 0.3 g: 0.3 b: 1.0). row addMorphBack: (StringMorph contents: 'Output'). row addMorphBack: AlignmentMorph newVariableTransparentSpacer. col addMorphBack: row. row := AlignmentMorph newRow color: Color transparent. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. morph := PluggableButtonMorph on: self getState: #outputBit3 action: nil. morph label: '3'; askBeforeChanging: false; borderWidth: 0; extent: 20 @ 20; onColor: Color red offColor: Color lightGray. row addMorphBack: morph. morph := PluggableButtonMorph on: self getState: #outputBit2 action: nil. morph label: '2'; askBeforeChanging: false; borderWidth: 0; extent: 20 @ 20; onColor: Color red offColor: Color lightGray. row addMorphBack: morph. morph := PluggableButtonMorph on: self getState: #outputBit1 action: nil. morph label: '1'; extent: 20 @ 20; askBeforeChanging: false; borderWidth: 0; onColor: Color red offColor: Color lightGray. row addMorphBack: morph. morph := PluggableButtonMorph on: self getState: #outputBit0 action: nil. morph label: '0'; extent: 20 @ 20; askBeforeChanging: false; borderWidth: 0; onColor: Color red offColor: Color lightGray. row addMorphBack: morph. col addMorphBack: row. ^ col! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/9/2006 12:06'! makeRegisterMorph | col row morph | col := AlignmentMorph newColumn color: Color transparent. col hResizing: #spaceFill; vResizing: #shrinkWrap. row := AlignmentMorph newRow color: Color orange. row addMorphBack: (StringMorph contents: 'Register'). row addMorphBack: AlignmentMorph newVariableTransparentSpacer. col addMorphBack: row. row := AlignmentMorph newRow color: Color transparent. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. row addMorphBack: (StringMorph contents: 'A='). morph := UpdatingStringMorph on: self selector: #registerA. morph useStringFormat. row addMorphBack: morph. col addMorphBack: row. row := AlignmentMorph newRow color: Color transparent. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. row addMorphBack: (StringMorph contents: 'B='). morph := UpdatingStringMorph on: self selector: #registerB. morph useStringFormat. row addMorphBack: morph. col addMorphBack: row. ^ col! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/8/2006 22:56'! makeRomEntryAt: aNumber | row column morph | column := AlignmentMorph newColumn color: Color transparent. column addMorphBack: (StringMorph contents: (aNumber printStringBase: 2 length: 4 padded: true)). row := AlignmentMorph newRow color: Color transparent. 7 to: 0 by: -1 do: [:each | morph := ThreePhaseButtonMorph checkBox. morph target: self; actionSelector: #romAddress:bit:morph:; arguments: (Array with: aNumber with: each with: morph); actWhen: #buttonDown. row addMorphBack: morph]. column addMorphBack: row. ^ column! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/9/2006 00:08'! makeUpperPane | row | row := AlignmentMorph newRow color: Color transparent. row cellPositioning: #topCenter. row addMorphBack: self makeControllerMorph. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. row addMorphBack: self makeInputMorph. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. row addMorphBack: self makeRegisterMorph. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. row addMorphBack: self makeArithmeticMorph. row addMorphBack: AlignmentMorph newVariableTransparentSpacer. row addMorphBack: self makeOutputMorph. ^ row! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/9/2006 16:35'! makeWindow | col | col := AlignmentMorph newColumn color: Color transparent. col addMorphBack: self makeUpperPane. col addMorphBack: self makeLowerPane. col addMorphBack: self makeFooterPane. ^ col! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/9/2006 16:19'! openAsMorph | window | window _ (SystemWindow labelled: 'TD4Simulator') model: self. window addMorph: self makeWindow frame: (0 @ 0 corner: 1 @ 1). "window addMorph: self makeUpperPane frame: (0 @ 0 corner: 1 @ 0.4). window addMorph: self makeLowerPane frame: (0 @ 0.4 corner: 1 @ 1)." ^ window! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/14/2006 17:21'! outputBit0 ^ self outputBit: 0! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/14/2006 17:21'! outputBit1 ^ self outputBit: 1! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/14/2006 17:21'! outputBit2 ^ self outputBit: 2! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/14/2006 17:21'! outputBit3 ^ self outputBit: 3! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/14/2006 17:21'! outputBit: aBitNumber | value mask | value := cpu output. mask := 1 << aBitNumber. ^ (value bitAnd: mask) > 0! ! !TD4Simulator methodsFor: 'morphic interface' stamp: 'ei 9/7/2006 22:29'! romAddress: anAddressNumber bit: aBitNumber morph: aMorph | value mask | value := cpu rom at: anAddressNumber. mask := 1 << aBitNumber. value := value bitXor: mask. cpu rom at: anAddressNumber put: value. aMorph state: ((value bitAnd: mask) > 0 ifTrue: [#on] ifFalse: [#off])! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/8/2006 23:21'! adderInput ^ (cpu adderInputA printStringBase: 2 length: 4 padded: true) , '+' , (cpu adderInputB printStringBase: 2 length: 4 padded: true)! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/8/2006 23:23'! adderOutput ^ '(' , cpu carry asString , ')' , (cpu adderOutput printStringBase: 2 length: 4 padded: true)! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/14/2006 17:38'! autoIndicated ^ isAuto! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/14/2006 17:43'! beAuto isAuto := true. self changed! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/14/2006 17:43'! beFast isFast := true. self changed! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/14/2006 17:43'! beManual isAuto := false. self changed! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/14/2006 17:43'! beSlow isFast := false. self changed! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/14/2006 17:20'! clock cpu clock. self changed! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/14/2006 17:36'! fastIndicated ^ isFast! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/14/2006 17:38'! manualIndicated ^ isAuto not! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/8/2006 22:27'! pc ^ cpu pc printStringBase: 2 length: 4 padded: true! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/8/2006 23:05'! registerA ^ cpu registerA printStringBase: 2 length: 4 padded: true! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/8/2006 23:05'! registerB ^ cpu registerB printStringBase: 2 length: 4 padded: true! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/8/2006 22:34'! reset cpu reset! ! !TD4Simulator methodsFor: 'private' stamp: 'ei 9/14/2006 17:36'! slowIndicated ^ isFast not! ! !TD4Simulator methodsFor: 'initialization' stamp: 'ei 9/14/2006 17:39'! initialize cpu := TD4CPU new. isAuto := false. isFast := false. cpu setup! ! !TD4Simulator methodsFor: 'stepping' stamp: 'ei 9/14/2006 17:42'! step isAuto ifFalse: [^ self]. self clock! ! !TD4Simulator methodsFor: 'stepping' stamp: 'ei 9/14/2006 17:42'! stepTimeIn: anObject isFast ifTrue: [^ 100]. ^ 1000! ! !TD4Simulator methodsFor: 'stepping' stamp: 'ei 9/9/2006 00:14'! wantsSteps ^ true! ! !TD4Simulator methodsFor: 'copyright' stamp: 'ei 9/14/2006 17:53'! about ^ 'TD4Simulator: TD4 CPU Simulator for Squeak V0.02. Copyright (C) 2006 Eiichiro ITO(GHC02331 at nifty.com). This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.'! ! !TD4Simulator methodsFor: 'copyright' stamp: 'ei 9/9/2006 16:31'! openAbout (Workspace new contents: self about) openLabel: 'TD4Simulator: about'! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! TD4Simulator class instanceVariableNames: ''! !TD4Simulator class methodsFor: 'parts bin' stamp: 'ei 9/9/2006 21:42'! descriptionForPartsBin ^ self partName: 'TD4Simulator' categories: #('Useful' ) documentation: 'TD4 CPU Simulator'! ! !TD4Simulator class methodsFor: 'parts bin' stamp: 'ei 9/9/2006 21:44'! newStandAlone self new openAsMorph openInWorld! !