<ol type="1">
<li>intro
<ul>
<li>who is peepaw?<br />
Me!</li>
<li>why a retro computer?<br />
help a kid understand computers</li>
<li>why z80?<br />
cheap, available, cheap</li>
</ul></li>
<li>the plan
<ul>
<li>build from scratch</li>
<li>build something like a tec1<br />
<a href="https://en.wikipedia.org/wiki/TEC-1"
class="uri">https://en.wikipedia.org/wiki/TEC-1</a></li>
<li>a great guide is the 1981 book build your own z80 computer<br />
<a
href="https://archive.org/details/BuildYourOwnZ80ComputerSteveCiarcia">Build
Your Own Z80 Computer Steve Ciarcia/</a></li>
<li>get started with nop tester<br />
<a href="http://www.z80.info/z80test0.htm"
class="uri">http://www.z80.info/z80test0.htm</a></li>
<li>want an expandable system</li>
<li>keep the cost down</li>
<li>work up to a system like the jupiter ace (which is like a zx-81
sinclair computer)<br />
<a href="https://en.wikipedia.org/wiki/Jupiter_Ace"
class="uri">https://en.wikipedia.org/wiki/Jupiter_Ace</a></li>
</ul></li>
<li>getting started, the nop test
<ul>
<li>use an arduino mega board and some forth to spin up the most basic
z80 system<br />
<a
href="https://gitlab.com/8bitforce/retroshield-hw/-/tree/master/hardware"
class="uri">https://gitlab.com/8bitforce/retroshield-hw/-/tree/master/hardware</a></li>
<li>give the z80 5 volts, a clock and the right data and it will happily
start up and run through its address space doing nothing</li>
</ul></li>
<li>the nop tester, in software
<ul>
<li>make a forth logic probe<br />
<a href="https://en.wikipedia.org/wiki/Logic_probe"
class="uri">https://en.wikipedia.org/wiki/Logic_probe</a></li>
<li>use a gate method of frequency counting<br />
<a href="https://ww1.microchip.com/downloads/en/Appnotes/doc8365.pdf"
class="uri">https://ww1.microchip.com/downloads/en/Appnotes/doc8365.pdf</a></li>
<li>create a few forth words to make a "logic probe" and test that
probe<br />
<a
href="https://pajacobs-ghub.github.io/flashforth/ff5-tutorial-guide.html#_counting_button_presses"
class="uri">https://pajacobs-ghub.github.io/flashforth/ff5-tutorial-guide.html#_counting_button_presses</a></li>
<li>need an arduino mega running flashforth<br />
<a href="https://store.arduino.cc/products/arduino-mega-2560-rev3"
class="uri">https://store.arduino.cc/products/arduino-mega-2560-rev3</a><br />
<a href="https://flashforth.com/atmega.html"
class="uri">https://flashforth.com/atmega.html</a></li>
<li>datasheet<br />
<a href="https://store.arduino.cc/products/arduino-mega-2560-rev3"
class="uri">https://store.arduino.cc/products/arduino-mega-2560-rev3</a><br />
<a
href="https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf"
class="uri">https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf</a></li>
<li>some jumper wires</li>
<li>z80</li>
<li>solderless bread board</li>
</ul></li>
<li>the code walk through, start from the bottom up note: ( -- ) are
stack effect comments, back slashes are plain comments
<ul>
<li>constants</li>
<li>variable</li>
<li><code>@ ! mset mclr mtst</code></li>
<li>set up external interrupt, int4, arduino board pin4</li>
</ul></li>
</ol>
<pre><code>\ the source code
\ declare some constants and variable as labels
variable Compare
variable Count

$100 constant PINH      \ these labels come from the atmega2560 datasheet
$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  \ the frequency counter

: logicprobe-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
    %0 DDRE c! \ e input
    0001.0000 PORTE mset \ pullup on e4
    %0000.0010 %EICRB mset \ falling edge
    [&#39;] ext4.irq #6 int!
;

\ helper words

: start-clock ( -- )  %0100.0000 TCCR4A c! %0000.1011 TCCR4B c! ;    \ the bit manipulation does what the word says
: 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 !       \ clean up value in Count
  Count @ dup 0 &gt; if       \ is Count greater than 0, if so its pulsing
     cr .&quot; freq=&quot; 10 * .
  else                     \ otherwise its not so is it high or low?
      drop
      %0000.1000 PINH mtst
      if
         .&quot; high&quot;
       else
          .&quot; low&quot;
      then then
 ;

 : wait ( -- ) 100 ms ;

 : sample-pin ( -- ) open-gate wait close-gate process-data ;  \ the &#39;logic probe&#39;</code></pre>
<ol start="6" type="1">
<li><p>test<br />
<em>Arduino</em><br />
<img src="https://hackerpublicradio.org/eps/hpr3807/setup.jpg"
alt="Arduino" /></p>
<ul>
<li>clock, using 16 bit timer4, its output is on pin6, running at
100hz</li>
<li>need to be able to start and stop the clock, and set the output pin
high or low</li>
<li>sample-pin is the word that does the work</li>
<li>ouput from the serial terminal exercising the logic probe ( comments
add after the fact):</li>
</ul>
<pre><code>E FlashForth 5 ATmega2560 13.06.2022

ok&lt;#,ram&gt;
logicprobe-init ok&lt;#,ram&gt;    (start up the logic probe)
sample-pin                   (sample the pin)
freq=100 ok&lt;#,ram&gt;           ( its oscilating at 100hz)
stop-clock ok&lt;#,ram&gt;
sample-pin low ok&lt;#,ram&gt;     ( after stopping the clock the pin is low)
pin-high ok&lt;#,ram&gt;
sample-pin
high ok&lt;#,ram&gt;               ( now its high)
125 set-frequency ok&lt;#,ram&gt;
start-clock ok&lt;#,ram&gt;
sample-pin
freq=1000 ok&lt;#,ram&gt;          ( after changing the frequency its 1000hz)</code></pre></li>
<li><p>next time</p>
<ul>
<li>repurpose the 16bit clock and use it to drive the z80, we'll hook up
the data port of the z80 to the arduino mega and use the logic probe to
see if the z80 is working</li>
</ul></li>
</ol>
