Object subclass: #TD4CPU instanceVariableNames: 'registerA registerB inPort outPort carry pc adder rom' classVariableNames: '' poolDictionaries: '' category: 'TD4-CPU'! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/8/2006 23:21'! adderInputA ^ adder inputA! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/8/2006 23:21'! adderInputB ^ adder inputB! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/8/2006 23:16'! adderOutput ^ adder value! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/6/2006 20:58'! carry ^ carry value! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/7/2006 16:10'! clock pc clock1. carry clock1. registerA clock1. registerB clock1. outPort clock1. pc clock2. carry clock2. registerA clock2. registerB clock2. outPort clock2! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/8/2006 23:36'! input ^ inPort value! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/8/2006 23:39'! input: anObject inPort outBuffer: anObject! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/8/2006 23:39'! output ^ outPort value! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/6/2006 20:58'! pc ^ pc value! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/6/2006 20:58'! registerA ^ registerA value! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/8/2006 23:05'! registerB ^ registerB value! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/6/2006 21:01'! reset pc reset. registerA reset. registerB reset. outPort reset. carry reset! ! !TD4CPU methodsFor: 'accessing' stamp: 'ei 9/6/2006 20:58'! rom ^ rom! ! !TD4CPU methodsFor: 'initialization' stamp: 'ei 9/8/2006 23:38'! initialize registerA := TD4FlipFlop new. registerB := TD4FlipFlop new. inPort := TD4Buffer new. outPort := TD4FlipFlop new. pc := TD4Counter new. pc base: 16. carry := TD4FlipFlop new. carry defaultLoad: 0. rom := TD4Rom new: 16! ! !TD4CPU methodsFor: 'initialization' stamp: 'ei 9/8/2006 23:38'! setup | sel obj iDecoder conn | "carry debug: true." sel := TD4Selector4 new. registerA output: (TD4Output target: sel selector: #input0:). registerB output: (TD4Output target: sel selector: #input1:). inPort output: (TD4Output target: sel selector: #input2:). obj := TD4FlipFlop new. obj output: (TD4Output target: sel selector: #input3:). pc output: (TD4Output target: rom selector: #pc:). adder := TD4FullAdder new. adder base: 16. sel output: (TD4Output target: adder selector: #inputA:). rom outputL: (TD4Output target: adder selector: #inputB:). conn := TD4Connector new. conn addOutputTarget: registerA selector: #input:. conn addOutputTarget: registerB selector: #input:. conn addOutputTarget: outPort selector: #input:. conn addOutputTarget: pc selector: #input:. adder output: conn. adder outputCarry: (TD4Output target: carry selector: #input:). iDecoder := TD4IDecoder new. rom outputH: (TD4Output target: iDecoder selector: #romH:). carry output: (TD4Output target: iDecoder selector: #carry:). iDecoder outputLoad0: (TD4Output target: registerA selector: #load:). iDecoder outputLoad1: (TD4Output target: registerB selector: #load:). iDecoder outputLoad2: (TD4Output target: outPort selector: #load:). iDecoder outputLoad3: (TD4Output target: pc selector: #load:). iDecoder outputSelection: (TD4Output target: sel selector: #selection:). inPort reset! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! TD4CPU class instanceVariableNames: ''! !TD4CPU class methodsFor: 'as yet unclassified' stamp: 'ei 9/6/2006 20:59'! new ^ self basicNew initialize! ! Object subclass: #TD4IDecoder instanceVariableNames: 'romH carry outputLoad0 outputLoad1 outputLoad2 outputLoad3 outputSelection' classVariableNames: '' poolDictionaries: '' category: 'TD4-CPU'! !TD4IDecoder methodsFor: 'accessing' stamp: 'ei 9/6/2006 13:59'! carry: aNumber carry := aNumber. self doOutput! ! !TD4IDecoder methodsFor: 'accessing' stamp: 'ei 9/6/2006 18:02'! outputLoad0: anObject outputLoad0 := anObject! ! !TD4IDecoder methodsFor: 'accessing' stamp: 'ei 9/6/2006 18:03'! outputLoad1: anObject outputLoad1 := anObject! ! !TD4IDecoder methodsFor: 'accessing' stamp: 'ei 9/6/2006 18:03'! outputLoad2: anObject outputLoad2 := anObject! ! !TD4IDecoder methodsFor: 'accessing' stamp: 'ei 9/6/2006 18:03'! outputLoad3: anObject outputLoad3 := anObject! ! !TD4IDecoder methodsFor: 'accessing' stamp: 'ei 9/6/2006 18:03'! outputSelection: anObject outputSelection := anObject! ! !TD4IDecoder methodsFor: 'accessing' stamp: 'ei 9/6/2006 13:59'! romH: aNumber romH := aNumber. self doOutput! ! !TD4IDecoder methodsFor: 'private' stamp: 'ei 9/7/2006 14:59'! decode | load0 load1 load2 load3 selection opCode | opCode := romH + 1. load0 := #(0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 ) at: opCode. load1 := #(1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 ) at: opCode. load2 := #(1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 ) at: opCode. load3 := #(1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 ) at: opCode. (romH = 14 or: [romH = 12]) ifTrue: [load3 := carry]. selection := #(0 1 2 3 0 1 2 3 1 1 3 3 1 1 3 3 ) at: opCode. ^ Array with: load0 with: load1 with: load2 with: load3 with: selection! ! !TD4IDecoder methodsFor: 'private' stamp: 'ei 9/6/2006 18:04'! doOutput | ret | ret := self decode. outputLoad0 input: (ret at: 1). outputLoad1 input: (ret at: 2). outputLoad2 input: (ret at: 3). outputLoad3 input: (ret at: 4). outputSelection input: (ret at: 5)! ! !TD4IDecoder methodsFor: 'initialization' stamp: 'ei 9/6/2006 17:47'! initialize romH := 0. carry := 0! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! TD4IDecoder class instanceVariableNames: ''! !TD4IDecoder class methodsFor: 'as yet unclassified' stamp: 'ei 9/6/2006 17:48'! new ^ self basicNew initialize! ! Object subclass: #TD4Rom instanceVariableNames: 'collection pc outputL outputH' classVariableNames: '' poolDictionaries: '' category: 'TD4-CPU'! !TD4Rom methodsFor: 'accessing' stamp: 'ei 9/7/2006 22:22'! at: aNumber ^ collection at: (aNumber + 1)! ! !TD4Rom methodsFor: 'accessing' stamp: 'ei 9/7/2006 22:22'! at: aNumber put: anObject collection at: (aNumber + 1) put: anObject. pc = aNumber ifTrue: [self doOutput]! ! !TD4Rom methodsFor: 'accessing' stamp: 'ei 9/6/2006 22:36'! clear collection doWithIndex: [:each :index | collection at: index put: 0]. pc := 0! ! !TD4Rom methodsFor: 'accessing' stamp: 'ei 9/6/2006 18:29'! outputH: anObject outputH := anObject! ! !TD4Rom methodsFor: 'accessing' stamp: 'ei 9/6/2006 18:29'! outputL: anObject outputL := anObject! ! !TD4Rom methodsFor: 'accessing' stamp: 'ei 9/6/2006 18:21'! pc: aNumber pc := aNumber. self doOutput! ! !TD4Rom methodsFor: 'private' stamp: 'ei 9/6/2006 18:27'! doOutput | v high low | v := collection at: pc + 1. high := v // 16. low := v \\ 16. outputL ifNotNil: [outputL input: low]. outputH ifNotNil: [outputH input: high]! ! !TD4Rom methodsFor: 'initialization' stamp: 'ei 9/6/2006 18:27'! initialize: aNumber collection := Array new: aNumber withAll: 0. pc := 0 ! ! !TD4Rom methodsFor: 'example' stamp: 'ei 9/6/2006 22:24'! sample1 self at: 1 put: 179; at: 2 put: 182; at: 3 put: 188; at: 4 put: 184; at: 5 put: 184; at: 6 put: 188; at: 7 put: 182; at: 8 put: 179; at: 9 put: 177; at: 10 put: 240! ! !TD4Rom methodsFor: 'example' stamp: 'ei 9/9/2006 14:42'! sample2 #(183 1 225 1 227 182 1 230 1 232 176 180 1 234 184 255 ) doWithIndex: [:each :index | self at: index put: each]! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! TD4Rom class instanceVariableNames: ''! !TD4Rom class methodsFor: 'as yet unclassified' stamp: 'ei 9/6/2006 21:07'! new self shouldNotImplement! ! !TD4Rom class methodsFor: 'as yet unclassified' stamp: 'ei 9/6/2006 18:18'! new: aNumber ^ self basicNew initialize: aNumber! !