<p>peepaws computer does nothing</p>
<ol type="1">
<li>who's peepaw, whats the goal
<ul>
<li>to build and understand the inner workings of an 8 bit computer and
maybe one day pass it on to a grand kid</li>
</ul></li>
<li>this episode -nop test
<ul>
<li>do a nop test, that is get the z80 up and running executing the nop
instruction</li>
<li>using the facilities of an arduino mega board running flash forth to
do that, talk about pictures</li>
<li>why? flash forth is interactive, without being such a big
application itself. Happily runs on an atmega328</li>
<li>why the mega, oodles and oodles of io, so emulating hardware should
be a snap</li>
<li>use the microcontroller board to provide 5 volts, clock signal and
data to get the z80 up and running</li>
<li>use the logic probe to see if there is activity on the address
bus</li>
</ul></li>
<li>wiring up
<ul>
<li>hot glued solderless breadboard on to an arduino mega protoshield,
white wire is the logicprobe input</li>
<li>power and ground first</li>
<li>clock, blue</li>
<li>control lines int, nmi, wait busrq and reset</li>
<li>orange wires data bus</li>
<li>address lines go around the chip clockwise from the clock signal
(blue wire) we'll be probing A0, next to the ground line</li>
</ul></li>
</ol>
<p><em>1.logicprobe.jpg</em><br />
<img src="https://hackerpublicradio.org/eps/hpr3812/1.logicprobe.jpg"
alt="1.logicprobe.jpg" /></p>
<p><em>2.power.jpg</em><br />
<img src="https://hackerpublicradio.org/eps/hpr3812/2.power.jpg"
alt="2.power.jpg" /></p>
<p><em>3.clock.jpg</em><br />
<img src="https://hackerpublicradio.org/eps/hpr3812/3.clock.jpg"
alt="3.clock.jpg" /></p>
<p><em>4.control.signals.jpg</em><br />
<img
src="https://hackerpublicradio.org/eps/hpr3812/4.control.signals.jpg"
alt="4.control.signals.jpg" /></p>
<p><em>5.data.jpg</em><br />
<img src="https://hackerpublicradio.org/eps/hpr3812/5.data.jpg"
alt="5.data.jpg" /></p>
<p><em>6.ready.to.probe.jpg</em><br />
<img
src="https://hackerpublicradio.org/eps/hpr3812/6.ready.to.probe.jpg"
alt="6.ready.to.probe.jpg" /></p>
<p><em>z80-pinout.jpg</em><br />
<img src="https://hackerpublicradio.org/eps/hpr3812/z80-pinout.jpg"
alt="z80-pinout.jpg" /></p>
<p><em>2560-pinout.jpg</em><br />
<a href="https://hackerpublicradio.org/eps/hpr3812/2560-pinout.jpg"><img
src="https://hackerpublicradio.org/eps/hpr3812/2560-pinout_thumbnail.jpg"
alt="2560-pinout.jpg" /></a> <br/><small><small><em>Click the thumbnail
to see the full-sized image</em></small></small></p>
<ol start="6" type="1">
<li>fixing some words, refactoring some words, defining new words
<ul>
<li>fixed the data processing word to us the input on pin e4 (digital 2)
not the output on pin h6 (digital 9)</li>
<li>changed freq= some value to simply pulse, not interested in the
specific frequency</li>
<li>split clock and logic probe init words</li>
<li>added some words to control the reset line reset and run</li>
<li>added a word step that allows for single clock pulses</li>
</ul></li>
<li>the test, mega board plugged into laptop, seral terminal running
<ul>
<li>spool up the logic probe</li>
<li>spool up the microcontroller board setting up a port to provide data
on the z80 data bus (rudimentary rom)</li>
<li>add 5 volts</li>
<li>initialize and start the clock</li>
<li>probe the clock line</li>
<li>probe a0 line</li>
</ul></li>
<li>a little more to see what else we can discern
<ul>
<li>single step to reset</li>
<li>probe m1</li>
<li>single step to reset</li>
<li>add halt instruction</li>
<li>probe halt line</li>
</ul></li>
<li>this is output captured from the tests run on the show. lines that
begin with a back slash are comments used as narration
<code>ok&lt;#,ram&gt;</code> is the forth interpreter reporting it has
successfully processed the proceeding word(s), including comments pulse,
high and low are output from the logicprobe, all other words are defined
in the source text and the end of the notes</li>
</ol>
<pre><code>E FlashForth 5 ATmega2560 13.06.2022

\ initialize the logic probe  ok&lt;#,ram&gt;
logicprobe.init  ok&lt;#,ram&gt;
\ initialize the clock  ok&lt;#,ram&gt;
clock.init  ok&lt;#,ram&gt;
\ initialize arduinomega ports that interact with z80  ok&lt;#,ram&gt;
z80.ports.init  ok&lt;#,ram&gt;
\ add power on the board  ok&lt;#,ram&gt;
\ probe the clock pin to see if there is activity  ok&lt;#,ram&gt;
sample
pulse ok&lt;#,ram&gt;
\ success!  ok&lt;#,ram&gt;
\ probe adrress line A0, pin 30 on the z80  ok&lt;#,ram&gt;
sample
pulse ok&lt;#,ram&gt;
\ pulse means there is activity on the bus  ok&lt;#,ram&gt;
\ stop the clock and probe A0 again, should see either a static high or low
signal ok&lt;#,ram&gt;
stop.clock sample
low ok&lt;#,ram&gt;
\ now move logic probe to pin 27, the M1 signal  ok&lt;#,ram&gt;
\ put the z80 in reset and give three clock steps  ok&lt;#,ram&gt;
reset  ok&lt;#,ram&gt;
step  ok&lt;#,ram&gt;
step  ok&lt;#,ram&gt;
step  ok&lt;#,ram&gt;
\ the z80 should be reset, now put in run  ok&lt;#,ram&gt;
run  ok&lt;#,ram&gt;
\ now single step the clock to see the M1  ok&lt;#,ram&gt;
\ signal go from high to low as the z80 begins   ok&lt;#,ram&gt;
\ fetching data fro the data bus at address 0  ok&lt;#,ram&gt;
step sample
high ok&lt;#,ram&gt;
step sample
high ok&lt;#,ram&gt;
step sample
low ok&lt;#,ram&gt;
step sample
low ok&lt;#,ram&gt;
step sample
high ok&lt;#,ram&gt;
\ success! the M1 signal is working as expected  ok&lt;#,ram&gt;
\ now reset the z80 and see what happens when  ok&lt;#,ram&gt;
\ we give a different instruction this time hex 76  ok&lt;#,ram&gt;
\ the halt instruction. We should see the halt signal go from   ok&lt;#,ram&gt;
\ high to low  ok&lt;#,ram&gt;
reset step step step  ok&lt;#,ram&gt;
\ put hat instruction on data lines  ok&lt;#,ram&gt;
$76 DATA c!  ok&lt;#,ram&gt;
\ now run mode  ok&lt;#,ram&gt;
run  ok&lt;#,ram&gt;
\ step clock and sample pin 18 the halt line  ok&lt;#,ram&gt;
step sample
high ok&lt;#,ram&gt;
step sample
high ok&lt;#,ram&gt;
step sample
high ok&lt;#,ram&gt;
step sample
high ok&lt;#,ram&gt;
step sample
high ok&lt;#,ram&gt;
step sample
low ok&lt;#,ram&gt;
step sample
low ok&lt;#,ram&gt;
\ 4 clock cycles and halt line goes low and stays low, success!  ok&lt;#,ram&gt;
\ thanks for listening  ok&lt;#,ram&gt;</code></pre>
<ol start="8" type="1">
<li>Forth source code</li>
</ol>
<pre><code>-logicprobe
marker -logicprobe

variable Compare
variable Count

$100 constant PINH
$101 constant DDRH
$102 constant PORTH

$a0 constant TCCR4A
$a1 constant TCCR4B
$a8 constant OCR4A

$2c constant PINE
$2d constant DDRE
$2e constant PORTE

$6a constant EICRB
$3d constant EIMSK

: ext4.irq ( -- ) Count @ 1+ Count ! ;i

: logicprobe.init ( -- )
  %0 DDRE c! \ e input
  %0000.0010 EICRB mset \ falling edge
  [&#39;] ext4.irq #6 int! \ attach interrupt
;

: clock.init ( -- )
  1249 Compare ! \ 100 hz
  %0000.1000 DDRH mset \ h3 output
  %0100.0000 TCCR4A c!  \ toggle d6, ph3 on compare match
  %0000.1011 TCCR4B c!  \ set ctc mode, clk/64
  Compare @ OCR4A !    \ set compare value
;

\ helper words
: start.clock ( -- )  %0100.0000 TCCR4A c! %0000.1011 TCCR4B c! ;
: stop.clock ( -- )   %0000.0000 TCCR4A c!  %0000.0000 TCCR4B c! ;
: set.frequency ( n -- )  OCR4A ! ;    \ set compare value
: pin.high ( -- )  %0000.1000 PORTH mset ;
: pin.low ( -- )    %0000.1000 PORTH mclr ;
: open.gate ( -- )   0 Count ! %0001.0000 EIMSK mset ;
: close.gate ( -- )   %0001.0000 EIMSK mclr ;

: process.data ( -- )
  Count @ 1-
  Count !
  Count @ 0 &gt; if
    \ cr .&quot; freq=&quot; 10 * .
    cr .&quot; pulse&quot;
  else
    %0001.0000 PINE mtst if
      cr .&quot; high&quot;
    else
      cr .&quot; low&quot;
    then then
;

: wait 100 ms ;

: sample ( -- ) open.gate wait close.gate process.data ;

\ nop tester
-nop
marker -nop

$20 constant PINA
$21 constant DDR.DATA
$22 constant DATA

$23 constant PINB
$24 constant DDRB
$25 constant PORTB

$2f constant PINF
$30 constant DDRF
$31 constant PORTF

%0000.0001 constant WAIT
%0000.0010 constant BUSRQ
%0000.0100 constant RESET
%0001.0000 constant INT
%0010.0000 constant NMI

: z80.ports.init ( -- )
  \ data port output
  $ff DDR.DATA c!
  \ control signals, output
  NMI INT or DDRB mset
  WAIT BUSRQ RESET or or DDRF mset
  \ nop instruction on data port
  $ff DATA mclr
  \ control lines high
  NMI INT or PORTB mset
  WAIT BUSRQ RESET or or PORTF mset
;

: reset ( -- ) RESET PORTF mclr ;
: run ( -- ) RESET PORTF mset ;
: step ( -- ) pin.high 1 ms pin.low ;

\ logicprobe.init
\ clock.init
\ z80.ports.init
\ sample</code></pre>
