\ main.fs
\ 
\ Simple test of both code and hardware setup.
\ The led should be blinking slowly when running.
\ If connected to serial port it will display data.
\ Serial should be 38400 8data/1stop.
\

] \ Target mode.

\ --- buffer display
: $type ( da) p! @p+ begin @p+ emit 1- 0=until drop ;
:m " 34 parse here there place here there [ c@ 1 + ] allot m;
: string pop pop swap $type ;

: .1_header  string " Test120 Display" ;
: .2_header  string " Temperature of CPU in hex is: " ;
: .3_header  string " Temperature of CPU in C   is: " ;
: .4_header  string " Data buffer in xram" ;

\ strings for xram writing
: .1_preamble xstring " <html><body>" ;
: .1_body xstring " <p>temperature is : <b>" ;
: .2_body xstring " &deg;C </b><br><p>" ;
: .1_footer xstring " </body></html> ;


\ clear the screen
: init_scrn
      $1b # emit   \ esc
      $5b # emit   \ [
      $00 # emit   \ n=y
      $3b # emit   \ ;
      $00 # emit   \ n=x
      $48 # emit   \ H ( home)
      $1b # emit   \ esc
      $5b # emit   \ [
      $00 # emit   \ 2=all
      $4a # emit   \ J
      ;

\ main process - get cpu temp and display it two ways.
: process          \ display data with serial connected PC
                   \ positon cursor at top left of screen
      $1b # emit   \ esc
      $5b # emit   \ [
      $00 # emit   \ n=y
      $3b # emit   \ ;
      $00 # emit   \ n=x
      $48 # emit   \ H ( home)

      cr cr
      .1_header cr
      cr
      .2_header 
      .get_temp    \ get cpu temp and display
      cr
      .3_header 
      amactemp     \ in degrees c
      xget_temp    \ get cpu temp and store it
      cr cr        \ couple of blank lines

      led_off
      $ff # delay1  \ wait

     \ lets setup html buffer data...
      bufr_D ## xsetptr            \ r5/r6 to begin of bufr
      .1_preamble                  \ string into bufr
      .1_body
      xmactemp                     \ write temp into bufr
      .2_body
      .1_footer

      .4_header cr
      bufr_S ## .axram \ display buffer in xram

      led_on
      $ff # delay1  \ wait
      
      ;


\ process is mostly comm with PC host..
: mainlp    process ;

\ any local hardware or software to set up...
: init   init_scrn            \ clear the display
         init_rdtmp           \ set up temp ADC routines
         init_bufr            \ setup the buffer space
         ;


\ --- turnkey & standalone
\ only do go if your not using the pc to control operations.
: go  init  begin mainlp again ;  ( turnkeyed for test)

\ --- for when doing it by pc...
\ so the pc would see greeting after setting hardware
\ but be running under interpreter!
: pcgo quit ;


0 [if] ------------------------------[ Notes ]---------------------------------

basic main for testing 120 setup...

[then]


