!****************************************************************
!*                                                              *
!*      IBOL:   EYEBALL board (BEPI version) test program       *
!*                                                              *
!*                  Version 1.1 23 Jan 1989                     *
!*                                                              *
!****************************************************************

%include "inc:util.imp"
%begin

@16_420 %routine pstr(%string(255)s)
@16_41c %routine psym(%integer k)

!BEPI interface addresses (Thanks Rainer)
%constinteger pgfc = 16_400400
@pgfc %bytearray page FC(0:255)

%constinteger pgfd = 16_400500
@pgfd %bytearray page FD(0:255)

%constinteger camera = 16_400600
@camera+16_00 %byte acia cont;  @camera+16_02 %byte acia data

%constinteger int = 16_400700
@int+0 %byte int6off; @int+1 %byte int7off
@int+2 %byte int6on; @int+3 %byte int7on

@16_1078 %integer ih6, ih7
%integer oldih6, oldih7
%label newih6, newih7

%recordformat ptm -
  (%byte cr1 %or %byte cr3,*,cr2,*,
         ct1h,*,ct1l,*, ct2h,*,ct2l,*, ct3h,*,ct3l,*)
@16_400100 %record(ptm)timer

%byteinteger b,c,cont,data
%integer i

%routine printline(%string (255) s)
   pstr(s); psym(13)
%end

%routine newline
   psym(13)
%end

%routine wait(%integer msec)
   %integer i
   %for i = 1,1,msec*100 %cycle; %repeat
%end

%predicate wait for(%byte char)
   %integer c
   %string(255) s
   %if char = ' ' %then s = "space" %elseif char=10 %then s = "return" %c
   %else s = tostring(char)
   printline("Press <".s."> to continue, <space> to stop, <return> to skip to next test")
   char=char-' ' %if 'a'<=char<='z'
   %cycle
     c=testsymbol; c=c-' ' %if 'a'<=c<='z'
     %false %if c=10
   %repeatuntil c=char
   %true
%end

%routine open acia
   %constinteger acset = 16_03, {master reset}
                 acopt = 16_14  {div 1, 8 bits 1 stop bit}
   acia cont = acset
   acia cont = acopt
%end

printline("EYEBALL board test program.")

newline
printline("Hard loop reading BBC page FC byte 0")
printline("The top and fifth LEDs should come on")
%while wait for(' ') %cycle
   %while testsymbol#' ' %cycle
      b=page FC(0)
   %repeat
%repeat

newline
printline("Hard loop reading BBC page FD byte 0")
printline("The second and sixth LEDs down should come on")
%while wait for(' ') %cycle
   %while testsymbol#' ' %cycle
      b=page FD(1)
   %repeat
%repeat

newline
printline("Master reset ACIA, set control to 16_14 (div 1,8 bits 1 stop bit)")
printline("then read status and data registers twice.  Results: ")
open acia
printstring("st="); phex2(acia cont)
printstring(" da="); phex2(acia data)
printstring(" st="); phex2(acia cont)
printstring(" da="); phex2(acia data); newline
cont = acia cont; data = acia data
printline("Hard loop reading camera port 0")
printline("The third LED down should come on")
%while wait for(' ') %cycle
   %while testsymbol#' ' %cycle
      b=acia cont
      c=acia data
      phex2(b) %and space %and phex2(c) %and newline %if b # cont %or c # data
   %repeat
%repeat

newline
printline("Hard loop reading intsel byte 0 (disable int 6)")
printline("The fourth LED down should come on")
%while wait for(' ') %cycle
   %while testsymbol#' ' %cycle
      b=int6off
   %repeat
%repeat

newline
printline("Now some Rainer interrupt magic")
printline("Don't abort the program till we finish")
oldih6 = ih6; oldih7 = ih7
ih6 = addr(newih6); ih7 = addr(newih7)

newline
printline("IRQ6 enabled")
int6on = 0
wait(5000)
int6off = 0
printline("IRQ7 enabled")
int7on = 0
wait(5000)
int7off = 0
ih6 = oldih6; ih7 = oldih7
printline("OK, relax")

%stop

newih6:
  *movem d0/a0,-(sp)
  %if timer_cr2&4#0 %start
    *otsr #16_700
    *lea timer_ct3h,a0
    *movep.w 0(a0),d0
  %else
pstr("IRQ");  psym(nl)
  %finish
  *movem (sp)+,d0/a0; *rte

newih7:
  *movem d0/a0,-(sp)
  pstr("FIRQ"); psym(nl)
  *movem (sp)+,d0/a0; *rte

%endofprogram

