/* ================================================================================== */
/* Copyright (c) 1998-1999 3Com Corporation or its subsidiaries. All rights reserved. */
/* ================================================================================== */

#ifndef __CPU_MT_H__
#define __CPU_MT_H__

#include "AppPreferences.h"		// AppPreferences::Configuration
#include "ErrorHandling.h"
#include "Platform_Files.h"
#include "omnithread.h"

class CPU : public omni_thread
{

public:

    // -----------------------------------------------------------------------------
    // constructor / destructor
    // -----------------------------------------------------------------------------

    CPU();

    // -----------------------------------------------------------------------------
    // public methods
    // -----------------------------------------------------------------------------

    void reset( void );
    void run( void );
    bool stop( void );
    void pen( bool down, int x, int y );
    void button( bool down, int button );
    void hotsync( bool down );
    void putkey( unsigned char key );
    void dispose( void );
    bool executeuntilatrap( void );
    ErrCode initialize(const AppPreferences::Configuration&);
	ErrCode load(const FileReference&);

protected:

    virtual ~CPU( void );

  private:

    // -----------------------------------------------------------------------------
    // omni_thread overrides
    // -----------------------------------------------------------------------------

    virtual void* run_undetached(void* arg);

    // -----------------------------------------------------------------------------
    // private data members
    // -----------------------------------------------------------------------------

    omni_semaphore _beginSemaphore;
    omni_semaphore _endSemaphore;
    bool _running;
    bool _quitRequest;
  
};


// -----------------------------------------------------------------------------
// Stack object which is used to briefly stop the emulator:
// -----------------------------------------------------------------------------

class CPUStopper
{
    
  public:
    CPUStopper( CPU *cpu, const char* msg );
    ~CPUStopper();
    
    bool Stopped() { return _ok; }
    
  private:
    
    bool _ok;
    CPU *_cpu;
};

#endif /* __CPU_MT_H__ */
