Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * The version below is about right for reading programs into mega to act like ROM for 1802.
- * Only hesitation is the norway commands where serial strings seem a bit error prone.
- * Thu Mar 26 14:09:30 NZDT 2020 CDP1802c1. Some problems with Norway commands as serial chars still available from prevuious actions.
- * ..Solution might be to flush Rx buffer after each command.
- * Wed Mar 25 16:40:32 NZDT 2020 CDP1802c0. Now going to add in serial read into vRAM[] from bin file generated
- * ..by a18 assembler. Uses Bray++ terminal to send file. Norway command is "gf" for getfile. Has to be 256 bytes.
- * Wed Mar 25 16:01:41 NZDT 2020 CDP1802b9. All working except for TPA signal and MWR* pin turning on writeStrobe but being tirned off by TPA.
- * * Tue Mar 24 13:09:41 NZDT 2020. All below works. Just a bit worried writeStrobe might turn on after being..
- * ..dealt with during TPB. Might get TPA to turn off writeStrobe so any subsequent LOWs of MWR* before TPB time are valid only
- * Tue Mar 24 10:20:46 NZDT 2020 CDP18028.Playing with MWR*
- * CDP1802b7 works. See 1802 blog. Next version: look at MWR.
- * CDP1802b6 21/3/203:47 Issues woth serial.available slowing down reads of 1802 data. Trying new Norwegian code.
- * 3:57, works witrh dummy commands.
- * . Start of array use for instructions
- Had big problems with first TPB cycle. Seemed to get old address outp[ut on address bus low when
- ..it should have been zero after reset. Round about the 4th clock after reset, adress goes to old value before reset.
- ..Settles down into next cycles with consistent addresses 1,2,3,4. But adr=0 remains a problem. The read line doesn't seem to be
- ..activated on first cycle so maybe just nop in zero position and move on?
- ..Next, connect up BUS pins to C port on mega. Initially just output nops, then when needed by instruction fetch, then chnage
- .. to little program that plays with Q and does loop involving nops too. This program has too many diagnostic entries so will tidy up
- .. before trying next version.
- Tidied up and working with resistors connecting data bus to $C4 pattern = nop.
- Now going to send constant $C4 via PORTC of Mega2650 to breadboard containing 1802. PORTC-->BUS 1802 all the time. Should be the
- ..same as resistor to rail $C4 above. Worked 10:07
- Now try sending $c4 only when clk goes low and TPB is high.Worked 10:19.
- Now try sending nop from mega to 1802 bus only when 1) clock goes low,2) TPB is high and 3) read is low. Worked 10:24
- Now going to select nop from an array of nops. Worked with just one element of arry of instructions called vRAM[]. Do several next.
- Key change was [ byte vRAM[5] = {0xc4, 0xc4, 0xc4, 0xc4, 0x00}; ] Next add instructions to turn on and off Q flag.
- Now going to put in little sequence of instructions. Key change is: [ byte vRAM[5] = {0xc4, 0x7b, 0xc4, 0x7a, 0x00};
- //ie nop,seq,nop,req,idl ] Worked and got Q flag going on and off with this; [byte vRAM[5] = {0x7b, 0x7b, 0x7a, 0x7b, 0x00}; ]
- Now gpoing to turn Q on and off but with branch back to start. Worked OK.
- 11:27am 20/3/20. Adding in dump of vertual ram array as well as issuing commands from serial terminal.
- ..Practiced some of the routines in dumper3.
- Going well, apart from serial read issues, but basic 1820 stuff going well. Try new serial read instruction code.
- */
- //1802 talks to Arduino Mega
- #define clockPin 13
- #define clearPin 12
- #define TPBpin A1
- #define TPApin A0
- #define readPin A15 //the *MRD of 1802
- #define writePin A14 //the MWR* of 1802
- #define SC0pin A12 //When SC0=LOW it's a fetch, when HI it's executing
- #define DELAY 50
- int val = 0; int bufBytes, TPBCtr, clkCtr = 0;
- int adrByte=0;
- boolean writeStrobe = false; //should really get TBA to turn this off too. Just in case.
- //byte vRAM[5] = {0x7b, 0x7b, 0x7a, 0x7b, 0x00}; //ie nop,seq,nop,req,idl
- //byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0x7a, 0x30, 0x00,0x00}; //ie seq,seq,req,seq,br start, idl
- byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x5b,0x57, 0x30, 0x09,0x00};
- void setup() {
- pinMode(clockPin, OUTPUT);
- pinMode(clearPin, OUTPUT);
- pinMode(TPApin,INPUT);
- pinMode(TPBpin,INPUT);
- pinMode(readPin,INPUT);
- pinMode(writePin,INPUT);
- pinMode(SC0pin,INPUT);
- DDRA=0x00; //DDRA reads Adress port of 1802. All inputs
- DDRC=0x00; //PORTC connects to 1802 data BUS.
- Serial.begin(9600); // open the serial port at 9600 bps:
- serialFlush();
- delay(1000); //time to sort out Bray++
- Serial.flush();
- Serial.println("Arduino talks to 1802. CDP1802c1. Pb 2020");
- delay(500);
- doReset();
- dumpVert();
- }
- //--------------------------------------------------------------------------------------
- void loop() {
- norwayCommand();
- digitalWrite(clockPin, HIGH); // turn the LED on (HIGH is the voltage level)
- if(digitalRead(TPApin) ==HIGH) {
- doTPAStuff();
- }
- if (digitalRead(writePin)==LOW){
- doWriteStuff();
- }
- delay(DELAY); // wait for a second
- digitalWrite(clockPin, LOW); // turn the LED off by making the voltage LOW
- DDRC=0x00; //DDRC usually input except when sending instruction
- clkCtr++; //how many clocks after reset?
- if (digitalRead(TPBpin) ==HIGH) {
- doTPBWork();
- }
- delay(DELAY); // wait for a second
- }
- void doTPBWork(void) {
- TPBCtr++;
- adrByte = PINA;
- if (writeStrobe== true) {
- writeStrobe = false;
- vRAM[adrByte]=PINC;
- }
- Serial.print("TPB with clock low. Num=");
- Serial.print(TPBCtr);
- Serial.print(" Clocks=");
- Serial.print(clkCtr);
- Serial.print(" AdrL=");
- Serial.print(PINA,HEX);
- if (digitalRead(readPin)==LOW) {
- DDRC = 0xff; //just for this version. Send nop when clk goes 1 to 0, TPB =1, MRD=0
- PORTC = vRAM[adrByte] ; // read byte from virtual
- Serial.print(" (R ");
- Serial.print(vRAM[adrByte],HEX);
- }
- if(digitalRead(SC0pin)==LOW) {
- Serial.print(" F "); //fetching instruction
- }
- else {
- Serial.print(" E "); //executing instruction
- }
- Serial.println(" ]");
- }
- void doReset(void){
- digitalWrite(clearPin,LOW); //bring CLEAR low for about 10 clocks to reset 1802
- for(int i =0;i<=10;i++) {
- digitalWrite(clockPin, HIGH);
- delay(DELAY); // wait
- digitalWrite(clockPin, LOW);
- delay(DELAY);
- }// 10 clocks low should reset 1802
- digitalWrite(clearPin,HIGH); //bring back to RUN mode
- }
- void serialFlush(void){
- while(Serial.available() > 0) { //while there are characters in the serial buffer, because Serial.available is >0
- char t = Serial.read(); // get one character
- }
- }
- void showLenOfTxBuffer(void) {
- bufBytes=Serial.availableForWrite();
- Serial.print(bufBytes);
- Serial.println("~");
- }
- void dumpVert(void) {
- char data[100];
- Serial.print("Col: ");
- for(int i=0;i<16;i++) {
- sprintf(data, "%02x ",i);
- Serial.print(data);
- if(i==7) Serial.print(" ");
- }
- for (int i=0;i<256;i++){
- if (i%16 == 0){
- Serial.println ("");
- sprintf(data, "%02x ",i);
- Serial.print(data);
- }
- if(i%8==0) { Serial.print("|"); }
- sprintf(data, " %02x ",vRAM[i]);
- Serial.print(data);
- }
- Serial.println(" ");
- }
- void doDump(void) {
- Serial.println("Got a dump");
- dumpVert();
- }
- void doGetProgram(void){
- Serial.println("Doing getProgram.");
- }
- void doWriteStuff(void) {
- // Serial.print("@W"); //usually happens twice in cycle when
- writeStrobe=true;
- }
- void doTPAStuff(void) {
- writeStrobe = false; //before new low-going *MWR causes writeStrobe to go true. Safe.
- }
- void getFile() { // go to File Send part of Bray++ terminal and put bin file into vRAM[]
- int inCtr=0;
- byte byteIn=65;
- while(inCtr<256){
- if(Serial.available()){
- byteIn = Serial.read();
- vRAM[inCtr]=byteIn;
- inCtr++;
- }
- }
- Serial.print("Got 256");
- }
- void norwayCommand(void){ //trying better instruction method from serial https://www.norwegiancreations.com/2017/12/arduino-tutorial-serial-inputs/
- String command;
- if(Serial.available()){
- command = Serial.readStringUntil('\n'); //Not happy with this method but works if exactly 256 bytes sent.
- if(command.equals("gf")){
- Serial.print("Getting File");
- getFile();
- serialFlush();
- Serial.println("**done gf flush** Now resetting");
- doReset();
- }
- else if(command.equals("du")){
- dumpVert();
- serialFlush();
- Serial.println("**done flush**");
- }
- else{
- Serial.println("Invalid command");
- Serial.println(command);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement