prjbrook

CDP1802b7 1802 and mega

Mar 23rd, 2020
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.98 KB | None | 0 0
  1. /**
  2. * Tue Mar 24 13:09:41 NZDT 2020. All below works. Just a bit worried writeStrobe might turn on after being..
  3. * ..dealt with during TPB. Might get TPA to turn off writeStrobe so any subsequent LOWs of MWR* before TPB time are valid only
  4. * Tue Mar 24 10:20:46 NZDT 2020 CDP18028.Playing with MWR*
  5. * CDP1802b7 works. See 1802 blog. Next version: look at MWR.
  6. * CDP1802b6 21/3/203:47 Issues woth serial.available slowing down reads of 1802 data. Trying new Norwegian code.
  7. * 3:57, works witrh dummy commands.
  8. * . Start of array use for instructions
  9. Had big problems with first TPB cycle. Seemed to get old address outp[ut on address bus low when
  10. ..it should have been zero after reset. Round about the 4th clock after reset, adress goes to old value before reset.
  11. ..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
  12. ..activated on first cycle so maybe just nop in zero position and move on?
  13. ..Next, connect up BUS pins to C port on mega. Initially just output nops, then when needed by instruction fetch, then chnage
  14. .. to little program that plays with Q and does loop involving nops too. This program has too many diagnostic entries so will tidy up
  15. .. before trying next version.
  16. Tidied up and working with resistors connecting data bus to $C4 pattern = nop.
  17. Now going to send constant $C4 via PORTC of Mega2650 to breadboard containing 1802. PORTC-->BUS 1802 all the time. Should be the
  18. ..same as resistor to rail $C4 above. Worked 10:07
  19. Now try sending $c4 only when clk goes low and TPB is high.Worked 10:19.
  20. 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
  21. Now going to select nop from an array of nops. Worked with just one element of arry of instructions called vRAM[]. Do several next.
  22. Key change was [ byte vRAM[5] = {0xc4, 0xc4, 0xc4, 0xc4, 0x00}; ] Next add instructions to turn on and off Q flag.
  23. Now going to put in little sequence of instructions. Key change is: [ byte vRAM[5] = {0xc4, 0x7b, 0xc4, 0x7a, 0x00};
  24. //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}; ]
  25. Now gpoing to turn Q on and off but with branch back to start. Worked OK.
  26. 11:27am 20/3/20. Adding in dump of vertual ram array as well as issuing commands from serial terminal.
  27. ..Practiced some of the routines in dumper3.
  28. Going well, apart from serial read issues, but basic 1820 stuff going well. Try new serial read instruction code.
  29. */
  30.  
  31. //1802 talks to Arduino Mega
  32. #define clockPin 13
  33. #define clearPin 12
  34. #define TPBpin A1
  35. #define readPin A15 //the *MRD of 1802
  36. #define writePin A14 //the MWR* of 1802
  37. #define SC0pin A12 //When SC0=LOW it's a fetch, when HI it's executing
  38. #define DELAY 50
  39.  
  40. int val = 0; int bufBytes, TPBCtr, clkCtr = 0;
  41. int adrByte=0;
  42. boolean writeStrobe = false; //should really get TBA to turn this off too. Just in case.
  43.  
  44. //byte vRAM[5] = {0x7b, 0x7b, 0x7a, 0x7b, 0x00}; //ie nop,seq,nop,req,idl
  45. //byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0x7a, 0x30, 0x00,0x00}; //ie seq,seq,req,seq,br start, idl
  46. byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x5b,0x57, 0x30, 0x09,0x00};
  47. void setup() {
  48.  
  49. pinMode(clockPin, OUTPUT);
  50. pinMode(clearPin, OUTPUT);
  51. pinMode(TPBpin,INPUT);
  52. pinMode(readPin,INPUT);
  53. pinMode(writePin,INPUT);
  54. pinMode(SC0pin,INPUT);
  55. DDRA=0x00; //DDRA reads Adress port of 1802. All inputs
  56. DDRC=0x00; //PORTC connects to 1802 data BUS.
  57. Serial.begin(9600); // open the serial port at 9600 bps:
  58. serialFlush();
  59. delay(1000); //time to sort out Bray++
  60. Serial.flush();
  61. Serial.println("Arduino talks to 1802. Pb 2020");
  62. delay(500);
  63. doReset();
  64. dumpVert();
  65. }
  66.  
  67.  
  68. void loop() {
  69. // SRB();
  70. norwayCommand();
  71. digitalWrite(clockPin, HIGH); // turn the LED on (HIGH is the voltage level)
  72. if (digitalRead(writePin)==LOW){
  73. //Serial.print("~W");
  74. doWriteStuff();
  75. }
  76. delay(DELAY); // wait for a second
  77. digitalWrite(clockPin, LOW); // turn the LED off by making the voltage LOW
  78. DDRC=0x00; //DDRC usually input except when sending instruction
  79. clkCtr++; //how many clocks after reset?
  80.  
  81. if (digitalRead(TPBpin) ==HIGH) {
  82. doTPBWork();
  83. }
  84. delay(DELAY); // wait for a second
  85. }
  86. void doTPBWork(void) {
  87. TPBCtr++;
  88. //DDRC=0xff; //make mega data port output
  89. //PORTC = 0xc4; //send nop
  90. // if (digitalRead(writePin)==LOW) Serial.print("@W");
  91. adrByte = PINA;
  92. if (writeStrobe== true) {
  93. writeStrobe = false;
  94. vRAM[adrByte]=PINC;
  95. }
  96. Serial.print("TPB with clock low. Num=");
  97. Serial.print(TPBCtr);
  98. Serial.print(" Clocks=");
  99. Serial.print(clkCtr);
  100. Serial.print(" AdrL=");
  101.  
  102. Serial.print(PINA,HEX);
  103. if (digitalRead(readPin)==LOW) {
  104. DDRC = 0xff; //just for this version. Send nop when clk goes 1 to 0, TPB =1, MRD=0
  105. PORTC = vRAM[adrByte] ; // read byte from virtual
  106. Serial.print(" *R ");
  107. Serial.print(vRAM[adrByte],HEX);
  108. }
  109.  
  110. if(digitalRead(SC0pin)==LOW) {
  111. Serial.print(" F "); //fetching instruction
  112. }
  113. else {
  114. Serial.print(" E "); //executing instruction
  115. }
  116. Serial.println(" ]");
  117. }
  118. void doReset(void){
  119. digitalWrite(clearPin,LOW); //bring CLEAR low for about 10 clocks to reset 1802
  120. for(int i =0;i<=10;i++) {
  121. digitalWrite(clockPin, HIGH);
  122. delay(DELAY); // wait
  123. digitalWrite(clockPin, LOW);
  124. delay(DELAY);
  125. }// 10 clocks low should reset 1802
  126. digitalWrite(clearPin,HIGH); //bring back to RUN mode
  127.  
  128. }
  129. void serialFlush(void){
  130. while(Serial.available() > 0) { //while there are characters in the serial buffer, because Serial.available is >0
  131. char t = Serial.read(); // get one character
  132. }
  133. }
  134. void showLenOfTxBuffer(void) {
  135. bufBytes=Serial.availableForWrite();
  136. Serial.print(bufBytes);
  137. Serial.println("~");
  138. }
  139.  
  140. void dumpVert(void) {
  141. char data[100];
  142. Serial.print("Col: ");
  143. for(int i=0;i<16;i++) {
  144. sprintf(data, "%02x ",i);
  145. Serial.print(data);
  146. if(i==7) Serial.print(" ");
  147. }
  148. for (int i=0;i<256;i++){
  149. if (i%16 == 0){
  150. Serial.println ("");
  151. sprintf(data, "%02x ",i);
  152. Serial.print(data);
  153. }
  154. if(i%8==0) { Serial.print("|"); }
  155. sprintf(data, " %02x ",vRAM[i]);
  156. Serial.print(data);
  157. }
  158. Serial.println(" ");
  159. }
  160. void doDump(void) {
  161. Serial.println("Got a dump");
  162. dumpVert();
  163. }
  164. void doGetProgram(void){
  165. Serial.println("Doing getProgram.");
  166. }
  167. void doWriteStuff(void) {
  168. Serial.print("@W");
  169. writeStrobe=true;
  170.  
  171. }
  172. /*void SRB(){
  173. byte k;
  174. byte buff[10];
  175. k = Serial.readBytes(buff, 3);
  176. if (k>0) {
  177. //Serial.println(k);
  178.  
  179. for (int i = 0;i<k;i++) {
  180. // Serial.println(buff[i],HEX);
  181. }
  182. if ((buff[0] ==0x64) && (buff[1] == 0x75 )) doDump(); //"du" = dump array
  183. if ((buff[0] ==0x67) && (buff[1] == 0x70 )) doGetProgram(); //"gp = get program, via serial
  184. //Serial.println("Got a dump");
  185. }
  186. } */
  187. void norwayCommand(void){ //trying better instruction method from serial https://www.norwegiancreations.com/2017/12/arduino-tutorial-serial-inputs/
  188. String command;
  189. if(Serial.available()){
  190. command = Serial.readStringUntil('\n');
  191.  
  192. if(command.equals("init")){
  193. Serial.print("i"); //nitialize();
  194. }
  195. else if(command.equals("send")){
  196. Serial.print("s");
  197. }
  198. else if(command.equals("data")){
  199. Serial.print("d");
  200. }
  201. else if(command.equals("reboot")){
  202. Serial.print("r");
  203. }
  204. else if(command.equals("du")){
  205. //Serial.print("Dumper");
  206. dumpVert();
  207. }
  208. else{
  209. Serial.println("Invalid command");
  210. }
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment