That is just what I don't want to do. I don't want to change the sketch code 
this was my proof of concept:
debug.h containing the new routines
/**
* debug.h
*
* Created on : 24 aug. 2013
* Author : Nico Verduin
* Email : info@verelec.com
* Website : www.verelec.nl
*
* Revision Control
*
* Latest Revsion
* ____________________
*
* Revision : $Revision$
* Date : $Date$
* Author : $Author$
*
*/
//
// test cases
//
int inputs[] = {0,1,2,3,4,5,6,7,8,9};
int input_index = 0;
#ifndef DEBUG_H_
#define DEBUG_H_
// Forcing this inline keeps the callers from having to push their own stuff
// on the stack. It is a good performance win and only takes 1 more byte per
// user than calling. (It will take more bytes on the 168.)
//
// But shouldn't this be moved into pinMode? Seems silly to check and do on
// each digitalread or write.
//
// Mark Sproul:
// - Removed inline. Save 170 bytes on atmega1280
// - changed to a switch statment; added 32 bytes but much easier to read and maintain.
// - Added more #ifdefs, now compiles for atmega645
//
//static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
//static inline void turnOffPWM(uint8_t timer)
static void turnOffPWM(uint8_t timer) {
switch (timer) {
#if defined(TCCR1A) && defined(COM1A1)
case TIMER1A: cbi(TCCR1A, COM1A1); break;
#endif
#if defined(TCCR1A) && defined(COM1B1)
case TIMER1B: cbi(TCCR1A, COM1B1); break;
#endif
#if defined(TCCR2) && defined(COM21)
case TIMER2: cbi(TCCR2, COM21); break;
#endif
#if defined(TCCR0A) && defined(COM0A1)
case TIMER0A: cbi(TCCR0A, COM0A1); break;
#endif
#if defined(TIMER0B) && defined(COM0B1)
case TIMER0B: cbi(TCCR0A, COM0B1); break;
#endif
#if defined(TCCR2A) && defined(COM2A1)
case TIMER2A: cbi(TCCR2A, COM2A1); break;
#endif
#if defined(TCCR2A) && defined(COM2B1)
case TIMER2B: cbi(TCCR2A, COM2B1); break;
#endif
#if defined(TCCR3A) && defined(COM3A1)
case TIMER3A: cbi(TCCR3A, COM3A1); break;
#endif
#if defined(TCCR3A) && defined(COM3B1)
case TIMER3B: cbi(TCCR3A, COM3B1); break;
#endif
#if defined(TCCR3A) && defined(COM3C1)
case TIMER3C: cbi(TCCR3A, COM3C1); break;
#endif
#if defined(TCCR4A) && defined(COM4A1)
case TIMER4A: cbi(TCCR4A, COM4A1); break;
#endif
#if defined(TCCR4A) && defined(COM4B1)
case TIMER4B: cbi(TCCR4A, COM4B1); break;
#endif
#if defined(TCCR4A) && defined(COM4C1)
case TIMER4C: cbi(TCCR4A, COM4C1); break;
#endif
#if defined(TCCR4C) && defined(COM4D1)
case TIMER4D: cbi(TCCR4C, COM4D1); break;
#endif
#if defined(TCCR5A)
case TIMER5A: cbi(TCCR5A, COM5A1); break;
case TIMER5B: cbi(TCCR5A, COM5B1); break;
case TIMER5C: cbi(TCCR5A, COM5C1); break;
#endif
}
}
/**
* @name digitalRead(uint_8 pin)
* @param pin pin number on Arduino board
* @returns int value of pin reading
*
* This function translates the pin number to the correct pin and port numbers. Switches off a PWM if it exists
* reads the pin.
* The value is returned as an integer.
*
* This source is copied from the original Arduino core sources and adapted to be able to fake a reading
*/
int digitalRead(int pin){
//
// get all the necessary data about this pin including
// mappings to different Arduino's
//
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
uint8_t status = 0; // return value of this operation
//
// if it is not a pin just return a LOW
//
if (port == NOT_A_PIN) return LOW;
//
// if this pin supports a PWM we need to turn the PWM output off
// before getting a digital reading
//
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
//
// get the port value and return the correct reading
//
if (*portInputRegister(port) & bit) {
status = HIGH;
} else {
status = LOW;
}
//
// fake status field
//
status = inputs[input_index];
input_index++;
if (input_index == 10) input_index = 0;
Serial.print("digitalRead took place value = ");
Serial.println(status);
return status;
}
/**
* @name digitalWrite(uint_8 pin, uint8_t val)
* @param pin pin number on Arduino board
* @param val value to write to pin ("0" or "1")
*
* This function translates the pin number to the correct pin and port numbers. Switches off a PWM if it exists
* reads the pin.
* The value is returned as an integer.
*
* This source is copied from the original Arduino core sources and adapted to be able to fake a reading
*/
void digitalWrite(int pin, int val) {
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;
//
// check if this port is valid
//
if (port == NOT_A_PIN)return;
//
// If the pin that support PWM output, we need to turn it off
// before doing a digital write.
//
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
//
// get the right output register
//
out = portOutputRegister(port);
//
// save SREG
//
uint8_t oldSREG = SREG;
//
// disable interrupts(). This has no effect after processing the pin as we restore the SREG back
//
cli();
//
// clear or set the bit in the output register thus setting the right port pin
//
if (val == LOW) {
*out &= ~bit;
} else {
*out |= bit;
}
//
// restore SREG so that the global interrupt flag (bit 7) is restored and interrupts (if set) work again
//
SREG = oldSREG;
//
// add own code
//
Serial.print("DigitalWrite took place value = ");
Serial.println(val);
}
#endif /* DEBUG_H_ */
And this is the actual program. It does not know the difference.
// Do not remove the include below
#include "testOverload.h"
#include "debug.h"
//The setup function is called once at startup of the sketch
void setup()
{
// Add your initialization code here
Serial.begin(115200);
pinMode(3, INPUT);
pinMode(4, OUTPUT);
}
// The loop function is called in an endless loop
void loop()
{
digitalWrite(4,digitalRead(6));
//Add your repeated code here
}