Advertisement
ENDERFLAG3

6502Monitor

Oct 28th, 2021
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const char ADDR[] = {22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52};   //address pins connected to arduino.
  2. const char DATA[] = {39, 41, 43, 45, 47, 49, 51, 53};   //data pins connected to arduino.
  3. #define CLOCK 2   //pulse from the clock circuit is connected to pin 2 of the arduino.
  4. #define READ_WRITE 3    //the read/write pin on the processor (pin 34) is connected to pin 3 on the arduino.
  5.  
  6. void setup() {
  7.   for (int n = 0; n < 16; n += 1) {
  8.     pinMode(ADDR[n], INPUT);    //setting all the address pins to inputs.
  9.   }
  10.  
  11.   for (int n = 0; n < 8; n += 1) {
  12.     pinMode(DATA[n], INPUT);    //setting all the data pins to inputs.
  13.   }
  14.  
  15.   pinMode(CLOCK, INPUT);    //setting the clock and read/write pins to inputs.
  16.   pinMode(READ_WRITE, INPUT);
  17.  
  18.   attachInterrupt(digitalPinToInterrupt(CLOCK), onClock, RISING);   //trigger an interrupt when a clock pulse is received and call the onClock function.
  19.  
  20.   Serial.begin(57600);  //'baud rate'. not a clue what it does.
  21. }
  22.  
  23. void onClock() {      //execute all the code in this function when the onClock function is called.
  24.   char output[15];
  25.  
  26.   unsigned int address = 0;
  27.   for (int n = 0; n < 16; n += 1) {
  28.     int bit = digitalRead(ADDR[n]) ? 1 : 0;   //read from an address pin. if 5v, return 1. if 0v, return 0.
  29.     Serial.print(bit);    //print the bit read from the the address pin to the serial monitor.
  30.     address = (address << 1) + bit;
  31.   }
  32.   Serial.print("  ");   //prints white space for that nice text formatting.
  33.  
  34.   unsigned int data = 0;
  35.   for (int n = 0; n < 8; n += 1) {
  36.     int bit = digitalRead(DATA[n]) ? 1 : 0;   //read from all the data pins. if 5v, return 1. if 0v, return 0.
  37.     Serial.print(bit);    //print the bit read from the the address pin to the serial monitor.
  38.     data = (data << 1) + bit;
  39.   }
  40.  
  41.   sprintf(output, " %04x  %c  %02x", address, digitalRead(READ_WRITE) ? 'r' : 'W', data);   //prints the data read from the address and data lines and prints it in
  42.   Serial.println(output);                                                                   //hexadecimal. this will make it much easier to interpret instructions.
  43. }                                                                                           //also prints an 'r' if the data lines are reading or a 'W' if writing.
  44.  
  45. void loop() {
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement