#include "systemc.h"
#include "master_bca.h"

void master_bca::master_f() {
   while(1) {
      wait();
      if(rstp == 0) {
         state = i = 0;
         dat1->req = false;
         data1 = 0;
         outdata = 0;
      } else {
           dat1->req = false;
         switch (state) {
            case 0:
               if (dat1->ack.read() == false) {
                  state = 1;
               }
               else 
                  state = 0;
               break;
            case 1:
               dat1->req = true;
               dat1->d = data1;
               outdata = data1;
               state = 2;
               break;
            case 2:
               dat1->req = false;
               if(dat1->ack == true) {
                  state = 0;
                  data1++;
                  if (data1 >= 100){
                     exit(1);
                  }
               }
               else state = 2;
               break;
         }
          
      }
   }
}

            
            
