OpenCores
URL https://opencores.org/ocsvn/tv80/tv80/trunk

Subversion Repositories tv80

[/] [tv80/] [trunk/] [sc_env/] [tv_responder.cpp] - Diff between revs 94 and 111

Only display areas with differences | Details | Blame | View Log

Rev 94 Rev 111
#include "tv_responder.h"
#include "tv_responder.h"
 
 
 
uint64_t get_time_stamp () {
 
        sc_time t;
 
 
 
        t = sc_time_stamp();
 
        return t.value();
 
}
 
 
void tv_responder::event ()
void tv_responder::event ()
{
{
        // init
        // init
        //reset_n = 0;
        //reset_n = 0;
        /*
        /*
        wait_n = 1;
        wait_n = 1;
        int_n = 1;
        int_n = 1;
        nmi_n = 1;
        nmi_n = 1;
        busrq_n = 1;
        busrq_n = 1;
        di_resp = 0;
        di_resp = 0;
        */
        */
 
        uint8_t oldval;
 
 
        if (reset_time > 0) {
        if (reset_time > 0) {
                reset_n = 0;
                reset_n = 0;
            wait_n = 1;
            wait_n = 1;
                int_n = 1;
                int_n = 1;
                nmi_n = 1;
                nmi_n = 1;
                busrq_n = 1;
                busrq_n = 1;
                di_resp = 0;
                di_resp = 0;
                reset_time--;
                reset_time--;
                if (reset_time == 0)
                if (reset_time == 0)
                        printf ("Initialization complete.\n");
                        printf ("Initialization complete.\n");
                return;
                return;
        } else {
        } else {
                if (reset_time == 0) {
                if (reset_time == 0) {
                        reset_n = 1;
                        reset_n = 1;
                        reset_time--;
                        reset_time--;
                }
                }
        }
        }
 
 
 
 
    if (!iorq_n & !rd_n)
    if (!iorq_n & !rd_n)
        {
        {
          switch (addr) {
          switch (addr) {
            case (0x82) : di_resp = timeout_ctl; break;
            case (0x82) : di_resp = timeout_ctl; break;
                        case(0x83) : di_resp = max_timeout & 0xff; break;
                        case(0x83) : di_resp = max_timeout & 0xff; break;
                        case(0x84) : di_resp = max_timeout >> 8; break;
                        case(0x84) : di_resp = max_timeout >> 8; break;
 
 
                case(0x90) : di_resp = int_countdown; break;
                case(0x90) : di_resp = int_countdown; break;
            case(0x91) : di_resp = checksum; break;
            case(CKSUM_VALUE) :
 
                di_resp = checksum;
 
                                //printf ("%2.6f: Read checksum value of %02x\n", sc_time_stamp().to_seconds(), checksum);
 
                break;
            case(0x93) : di_resp = ior_value; break;
            case(0x93) : di_resp = ior_value; break;
            case(0x94) : di_resp = rand();  break;
            case(0x94) : di_resp = rand();  break;
            case(0x95) : di_resp = nmi_countdown; break;
            case(0x95) : di_resp = nmi_countdown; break;
            case(0xA0) : di_resp = nmi_trigger; break;
            case(0xA0) : di_resp = nmi_trigger; break;
            default : di_resp = 0;
            default : di_resp = 0;
          }
          }
        } // if (!iorq_n & !rd_n)
        } // if (!iorq_n & !rd_n)
 
 
//  wire wr_stb;
//  wire wr_stb;
//  reg last_iowrite;
//  reg last_iowrite;
 
 
//  assign wr_stb = (!iorq_n & !wr_n);
//  assign wr_stb = (!iorq_n & !wr_n);
 
 
//  always @(posedge clk)
//  always @(posedge clk)
//   begin
//   begin
      //last_iowrite <= #1 wr_stb;
      //last_iowrite <= #1 wr_stb;
    //if (!iorq_n && !wr_n)
    //if (!iorq_n && !wr_n)
    //  printf ("DEBUG:  I/O Write detected addr=%02x\n", 0xff & (int) addr.read());
    //  printf ("DEBUG:  I/O Write detected addr=%02x\n", 0xff & (int) addr.read());
 
 
    if (!iorq_n && !wr_n && !last_iowrite) {
    if (!iorq_n && !wr_n && !last_iowrite) {
        int l_dout, l_addr;
        int l_dout, l_addr;
 
 
        l_addr = addr.read();
        l_addr = addr.read();
        l_dout = dout.read();
        l_dout = dout.read();
 
 
        last_iowrite = true;
        last_iowrite = true;
                switch ( l_addr & 0xff) {
                switch ( l_addr & 0xff) {
                        case(0x80) :
                        case(SIM_CTL_PORT) :
                        // dump control deprecated
                        // dump control deprecated
                        if (l_dout == 1) {
                        if (l_dout == 1) {
                                printf ("%8d: --- TEST PASSED ---\n", 0);
                                printf ("%2.6f: --- TEST PASSED ---\n", sc_time_stamp().to_seconds());
                                sc_stop();
                                sc_stop();
                        } else if (l_dout == 2) {
                        } else if (l_dout == 2) {
                                printf ("%8d: !!! TEST FAILED !!!\n", 0);
                                printf ("%2.6f: !!! TEST FAILED !!!\n", sc_time_stamp().to_seconds());
                                sc_stop();
                                sc_stop();
                        }
                        }
                        break;
                        break;
 
 
                        case(0x81) :
                        case(MSG_PORT) :
 
 
                        //printf ("%s: DEBUG   : Detected write of character %x\n", sc_time_stamp().to_string(), l_dout);
 
                        //cout << sc_time_stamp().to_string() << "DEBUG   : Detected write of character " << l_dout << endl;
 
                        if (l_dout == 0x0A) {
                        if (l_dout == 0x0A) {
                                        //printf ("%8d: PROGRAM : ", sc_simulation_time());
                                        printf ("%2.6f: PROGRAM : ", sc_time_stamp().to_seconds());
                                        cout << sc_time_stamp() << ": PROGRAM : ";
 
 
 
                                        for (int i=0; i<buf_ptr; i=i+1)
                                        for (int i=0; i<buf_ptr; i=i+1)
                                                //printf ("%s", str_buf[i]);
                                                printf ("%c", str_buf[i]);
                                                cout << str_buf[i];
 
 
 
                                        //printf ("\n");
                                        printf ("\n");
                                        cout << endl;
 
                                        buf_ptr = 0;
                                        buf_ptr = 0;
                                } else {
                                } else {
                                str_buf[buf_ptr] = (char) (l_dout & 0xff);
                                str_buf[buf_ptr] = (char) (l_dout & 0xff);
                                buf_ptr = buf_ptr + 1;
                                buf_ptr = buf_ptr + 1;
                        }
                        }
                    break;
                    break;
 
 
                        case(0x82) :
                        case(TIMEOUT_PORT) :
                        timeout_ctl = l_dout;
                        timeout_ctl = l_dout;
                                break;
                                break;
 
 
                        case(0x83) :
                        case(MAX_TIMEOUT_LOW) :
                                max_timeout = l_dout | (max_timeout & 0xFF00);
                                max_timeout = l_dout | (max_timeout & 0xFF00);
                                break;
                                break;
 
 
                        case(0x84) :
                        case(MAX_TIMEOUT_HIGH) :
                                max_timeout = l_dout << 8 | (max_timeout & 0x00FF);
                                max_timeout = (l_dout << 8) | (max_timeout & 0x00FF);
 
                                printf ("%2.6f: ENVIRON : Timeout reset to %d (dout=%d)\n", sc_time_stamp().to_seconds(), max_timeout, l_dout);
                                break;
                                break;
 
 
                        case(0x90) : int_countdown = dout; break;
                        case(0x90) : int_countdown = dout; break;
                        case(0x91) : checksum = dout; break;
                        case(CKSUM_VALUE) : checksum = dout; break;
                        case(0x92) : checksum = checksum + dout; break;
                        case(CKSUM_ACCUM) :
 
                                oldval = checksum;
 
                                checksum = checksum + dout;
 
                                //printf ("%2.6f: ENVIRON : cksum %02x=%02x + %02x\n", sc_time_stamp().to_seconds(), checksum, oldval, l_dout);
 
                                break;
                        case(0x93) : ior_value = dout; break;
                        case(0x93) : ior_value = dout; break;
                        case(0x95) : nmi_countdown = dout; break;
                        case(0x95) : nmi_countdown = dout; break;
                        case(0xA0) : nmi_trigger = dout; break;
                        case(0xA0) : nmi_trigger = dout; break;
                }
                }
    } else if (iorq_n)
    } else if (iorq_n)
        last_iowrite = false;
        last_iowrite = false;
 
 
        if (timeout_ctl & 0x2)
        if (timeout_ctl & 0x2) {
                cur_timeout = 0;
                cur_timeout = 0;
    else if (timeout_ctl & 0x1)
                timeout_ctl = timeout_ctl & 1;
 
        } else if (timeout_ctl & 0x1)
                cur_timeout = cur_timeout + 1;
                cur_timeout = cur_timeout + 1;
 
 
    if (cur_timeout >= max_timeout) {
    if (cur_timeout >= max_timeout) {
          printf ("%8d: ERROR   : Reached timeout %d cycles\n", 0, max_timeout);
          printf ("%2.6f: ERROR   : Reached timeout %d cycles\n", sc_time_stamp().to_seconds(), max_timeout);
          //tb_top.test_fail;
          //tb_top.test_fail;
          sc_stop();
          sc_stop();
    }
    }
 
 
        if (int_countdown == 0) {
        if (int_countdown == 0) {
                int_n = 1;
                int_n = 1;
        } else if (int_countdown == 1)
        } else if (int_countdown == 1)
                int_n  = 0;
                int_n  = 0;
    else if (int_countdown > 1) {
    else if (int_countdown > 1) {
          int_countdown = int_countdown - 1;
          int_countdown = int_countdown - 1;
          int_n  = 1;
          int_n  = 1;
    }
    }
 
 
    // when nmi countdown reaches 1, an NMI will be issued.
    // when nmi countdown reaches 1, an NMI will be issued.
    // to clear the interrupt, write nmi_countdown to 0.
    // to clear the interrupt, write nmi_countdown to 0.
    if ((nmi_countdown == 0) && (nmi_trigger == 0))
    if ((nmi_countdown == 0) && (nmi_trigger == 0))
                nmi_n = 1;
                nmi_n = 1;
    else if (nmi_countdown == 1)
    else if (nmi_countdown == 1)
                nmi_n = 0;
                nmi_n = 0;
    else if (nmi_countdown > 1) {
    else if (nmi_countdown > 1) {
                nmi_countdown = nmi_countdown - 1;
                nmi_countdown = nmi_countdown - 1;
                nmi_n = 1;
                nmi_n = 1;
    }
    }
 
 
    // when IR equals the target instruction, an NMI will be
    // when IR equals the target instruction, an NMI will be
    // issued.  To clear the interrupt, write nmi_trigger to
    // issued.  To clear the interrupt, write nmi_trigger to
    // zero.
    // zero.
    /*  can't do this in systemc
    /*  can't do this in systemc
    if (nmi_trigger != 0) {
    if (nmi_trigger != 0) {
          if (nmi_trigger === tb_top.tv80s_inst.i_tv80_core.IR[7:0])
          if (nmi_trigger === tb_top.tv80s_inst.i_tv80_core.IR[7:0])
            begin
            begin
              tb_top.nmi_n <= #80 0;
              tb_top.nmi_n <= #80 0;
              tb_top.nmi_n <= #160 1;
              tb_top.nmi_n <= #160 1;
            end
            end
    } else if (nmi_countdown == 0)
    } else if (nmi_countdown == 0)
        nmi_n = 1;
        nmi_n = 1;
     */
     */
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.