 }
 
 #ifdef HAYES
+// ----------------------------------------------------------
+// Simple Hayes Emulation
+// Portions of this code are adapted from Payton Byrd's Hayesduino - thanks!
+
+boolean Modem_isCommandMode = true;
+boolean Modem_isConnected = false;
+boolean Modem_isRinging = false;
+//boolean Modem_EchoOn = EEPROM.read(ADDR_MODEM_ECHO);
+boolean Modem_EchoOn = true;
+boolean Modem_VerboseResponses = true;
+boolean Modem_QuietMode = false;
+boolean Modem_isDcdInverted = false;
+boolean Modem_S0_AutoAnswer = false;
+char    Modem_S2_EscapeCharacter = '+';
+
+#define COMMAND_BUFFER_SIZE  81
+char Modem_LastCommandBuffer[COMMAND_BUFFER_SIZE];
+char Modem_CommandBuffer[COMMAND_BUFFER_SIZE];
+
+int Modem_EscapeCount = 0;
 
 void HayesEmulationMode()
 {


int main(void) {
    init();
    {        
        uView.begin(); // begin of MicroView
        uView.setFontType(0);
        uView.clear(ALL); // erase hardware memory inside the OLED controller

#ifdef HAYES
        if (EEPROM.read(ADDR_FIRST_TIME_CHECK) != 222) {
            // First time - reset to defaults
            Modem_LoadDefaults();
            Modem_Save_Settings(0);
            EEPROM.write(ADDR_FIRST_TIME_CHECK, 222);
            EEPROM.write(ADDR_RECOVERY, 0);
        }
        else
        {
            Modem_Load_Settings(0);
        }

        Modem_Recovery = EEPROM.read(ADDR_RECOVERY);
        if (Modem_Recovery > 2)   // 2 = 3 times
        {
            Modem_LoadDefaults();
            Modem_Save_Settings(0);
            delay(1000);
            EEPROM.write(ADDR_RECOVERY, 0);
        }
        Modem_Recovery++;
        EEPROM.write(ADDR_RECOVERY, Modem_Recovery);        
#endif  // HAYES

        // Always setup pins for flow control
        pinModeFast(C64_RTS, INPUT);


    Modem_EscapeCount = 0;

    Modem_LoadDefaults();
    Modem_ResetCommandBuffer();

    C64Println();
