prjbrook

CDP1802c7

Mar 29th, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.82 KB | None | 0 0
  1. /**
  2. * Sun Mar 29 14:26:46 NZDT 2020 ..c7. Have big 1024 vRam[] buffer but can't use it yet.
  3. * ..Need TPA time to record Hi adr byte.
  4. * Sorted vRAM[] up to 1024 bytes and got new comand dumpVariableVer(int) to give 256 0r 1024 dumps.
  5. * Sun Mar 29 13:49:17 NZDT 2020 ..c6. Now want to exgtend vRAM[] frolm 256 to 1024 bytes. Fake memory.
  6. * Sat Mar 28 16:23:44 NZDT 2020. This is ...c5. Now going to try fastest baudrate 115200 and fastest DELAY =1.
  7. * All worked. Fast enough for time being. Next increase vRAM[] to 1024 bytes and check Hi address byte on
  8. * ..TPA.
  9. * Sat Mar 28 16:23:44 NZDT 2020 still...c4. Got baudrate up to 57600 and DELAY down to 2. Allworking.
  10. * Sat Mar 28 14:13:16 NZDT 2020 CDP1802c4. Going to try DELAY=4, and baudrate is 38.4K. Works OK but
  11. * ..is too fast in terminal so only print every 10th TPB going-high count. (clocks/8)
  12. * Sat Mar 28 13:37:04 NZDT 2020 CDP1802c3. Going to increase speed all round. First DELAY to 16. Baud to 19.2K Both OK
  13. * Now going to try DELAY =8 and baud = 28.8K. Both worked.
  14. * Sat Mar 28 13:14:18 NZDT 2020 CDP1802c2. Need to speed up a bit. Reg dumping works but is slow.
  15. * so going to change DELAY from 50 to 32 then keep halving. Worked OK also shortened message to terminal.
  16. * Also increased serial speed to 14.4K. Working OK. Next continue speed of clock and baudrate.
  17. * The version below is about right for reading programs into mega to act like ROM for 1802.
  18. * Only hesitation is the norway commands where serial strings seem a bit error prone.
  19. *
  20. * Thu Mar 26 14:09:30 NZDT 2020 CDP1802c1. Some problems with Norway commands as serial chars still available from prevuious actions.
  21. * ..Solution might be to flush Rx buffer after each command.
  22. * Wed Mar 25 16:40:32 NZDT 2020 CDP1802c0. Now going to add in serial read into vRAM[] from bin file generated
  23. * ..by a18 assembler. Uses Bray++ terminal to send file. Norway command is "gf" for getfile. Has to be 256 bytes.
  24. * 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.
  25. * * Tue Mar 24 13:09:41 NZDT 2020. All below works. Just a bit worried writeStrobe might turn on after being..
  26. * ..dealt with during TPB. Might get TPA to turn off writeStrobe so any subsequent LOWs of MWR* before TPB time are valid only
  27. * Tue Mar 24 10:20:46 NZDT 2020 CDP18028.Playing with MWR*
  28. * CDP1802b7 works. See 1802 blog. Next version: look at MWR.
  29. * CDP1802b6 21/3/203:47 Issues woth serial.available slowing down reads of 1802 data. Trying new Norwegian code.
  30. * 3:57, works witrh dummy commands.
  31. * . Start of array use for instructions
  32. Had big problems with first TPB cycle. Seemed to get old address outp[ut on address bus low when
  33. ..it should have been zero after reset. Round about the 4th clock after reset, adress goes to old value before reset.
  34. ..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
  35. ..activated on first cycle so maybe just nop in zero position and move on?
  36. ..Next, connect up BUS pins to C port on mega. Initially just output nops, then when needed by instruction fetch, then chnage
  37. .. to little program that plays with Q and does loop involving nops too. This program has too many diagnostic entries so will tidy up
  38. .. before trying next version.
  39. Tidied up and working with resistors connecting data bus to $C4 pattern = nop.
  40. Now going to send constant $C4 via PORTC of Mega2650 to breadboard containing 1802. PORTC-->BUS 1802 all the time. Should be the
  41. ..same as resistor to rail $C4 above. Worked 10:07
  42. Now try sending $c4 only when clk goes low and TPB is high.Worked 10:19.
  43. 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
  44. Now going to select nop from an array of nops. Worked with just one element of arry of instructions called vRAM[]. Do several next.
  45. Key change was [ byte vRAM[5] = {0xc4, 0xc4, 0xc4, 0xc4, 0x00}; ] Next add instructions to turn on and off Q flag.
  46. Now going to put in little sequence of instructions. Key change is: [ byte vRAM[5] = {0xc4, 0x7b, 0xc4, 0x7a, 0x00};
  47. //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}; ]
  48. Now gpoing to turn Q on and off but with branch back to start. Worked OK.
  49. 11:27am 20/3/20. Adding in dump of vertual ram array as well as issuing commands from serial terminal.
  50. ..Practiced some of the routines in dumper3.
  51. Going well, apart from serial read issues, but basic 1820 stuff going well. Try new serial read instruction code.
  52. */
  53.  
  54. //1802 talks to Arduino Mega
  55. #define clockPin 13
  56. #define clearPin 12
  57. #define TPBpin A1
  58. #define TPApin A0
  59. #define readPin A15 //the *MRD of 1802
  60. #define writePin A14 //the MWR* of 1802
  61. #define SC0pin A12 //When SC0=LOW it's a fetch, when HI it's executing
  62. #define TPBDivisor 1 // 100 //50 //10 //if ten, shows every tenth output line, otherwise too fast to see and act in terminal
  63. #define DELAY 50 //1 // 2 //4 //8 //16 //32 //50
  64.  
  65. int val = 0; int bufBytes, TPBCtr, clkCtr = 0;
  66. int adrByte=0;
  67. int adrByteHi =0;
  68. boolean writeStrobe = false; //should really get TBA to turn this off too. Just in case.
  69.  
  70. //byte vRAM[5] = {0x7b, 0x7b, 0x7a, 0x7b, 0x00}; //ie nop,seq,nop,req,idl
  71. //byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0x7a, 0x30, 0x00,0x00}; //ie seq,seq,req,seq,br start, idl
  72. //byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x6A,0x57, 0x30, 0x09,0x00};
  73. byte vRAM[1024] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x7D,0x57, 0x30, 0x09,0x00};
  74. void setup() {
  75.  
  76. pinMode(clockPin, OUTPUT);
  77. pinMode(clearPin, OUTPUT);
  78. pinMode(TPApin,INPUT);
  79. pinMode(TPBpin,INPUT);
  80. pinMode(readPin,INPUT);
  81. pinMode(writePin,INPUT);
  82. pinMode(SC0pin,INPUT);
  83. DDRA=0x00; //DDRA reads Adress port of 1802. All inputs
  84. DDRC=0x00; //PORTC connects to 1802 data BUS.
  85. Serial.begin(115200); //(57600); //38400); //(28800); //(19200); //(14400); //(9600); // open the serial port at 9600 bps:
  86. serialFlush();
  87. delay(1000); //time to sort out Bray++
  88. Serial.flush();
  89. Serial.println("Arduino talks to 1802. CDP1802c1. Pb 2020");
  90. delay(500);
  91. doReset();
  92. dumpVariableVert(256);
  93. }
  94.  
  95. //--------------------------------------------------------------------------------------
  96. void loop() {
  97. norwayCommand(); //Still a bit clumsy with Serial lib.
  98.  
  99. //*******************************************
  100. digitalWrite(clockPin, HIGH); // turn the LED on (HIGH is the voltage level)
  101. if(digitalRead(TPApin) ==HIGH) {
  102. doTPAStuff();
  103. }
  104. if (digitalRead(writePin)==LOW){
  105. doWriteStuff();
  106. }
  107. delay(DELAY); // wait for a second
  108. digitalWrite(clockPin, LOW); // turn the LED off by making the voltage LOW
  109. DDRC=0x00; //DDRC usually input except when sending instruction
  110. clkCtr++; //how many clocks after reset?
  111.  
  112. if (digitalRead(TPBpin) ==HIGH) {
  113. doTPBWork();
  114. }
  115. delay(DELAY); // wait for a second
  116. }
  117. //*************************************************
  118. void doTPBWork(void) {
  119. boolean printMe= false ;
  120. TPBCtr++;
  121. if(TPBCtr%TPBDivisor ==0) { //slow down terminal output. If %10 then print evetry tenth line.
  122. printMe = true;
  123. }
  124. adrByte = PINA;
  125. if (writeStrobe== true) {
  126. writeStrobe = false;
  127. vRAM[adrByte+adrByteHi*256]=PINC; //adrByteHi comes from read of PORTC during TPA
  128. }
  129. if (printMe) {
  130. Serial.print("TPB1 Clk0 Num=");
  131. Serial.print(TPBCtr);
  132. Serial.print(" Clocks=");
  133. Serial.print(clkCtr);
  134. Serial.print(" AdrL=");
  135. Serial.print(PINA,HEX);
  136. Serial.print(" AdrH=");
  137. Serial.print(adrByteHi,HEX); //get this from TPAwork
  138. if(digitalRead(SC0pin)==LOW) {
  139. Serial.print(" F "); //fetching instruction
  140. }
  141. else {
  142. Serial.print(" E "); //executing instruction
  143. }
  144. }
  145. if (digitalRead(readPin)==LOW) {
  146. DDRC = 0xff; //just for this version. Send nop when clk goes 1 to 0, TPB =1, MRD=0
  147. //PORTC = vRAM[adrByte] ; // read byte from virtual
  148. PORTC = vRAM[adrByte+adrByteHi*256] ; // read byte from virtual
  149. if(printMe) {
  150. Serial.print(" (R ");
  151. Serial.print(vRAM[adrByte],HEX);
  152. }
  153. }
  154. if (printMe) Serial.println(" ]"); //finish off line with ]
  155. }
  156. void doReset(void){
  157. digitalWrite(clearPin,LOW); //bring CLEAR low for about 10 clocks to reset 1802
  158. for(int i =0;i<=10;i++) {
  159. digitalWrite(clockPin, HIGH);
  160. delay(DELAY); // wait
  161. digitalWrite(clockPin, LOW);
  162. delay(DELAY);
  163. }// 10 clocks low should reset 1802
  164. digitalWrite(clearPin,HIGH); //bring back to RUN mode
  165. }
  166.  
  167. void serialFlush(void){
  168. while(Serial.available() > 0) { //while there are characters in the serial buffer, because Serial.available is >0
  169. char t = Serial.read(); // get one character
  170. }
  171. }
  172. void showLenOfTxBuffer(void) {
  173. bufBytes=Serial.availableForWrite();
  174. Serial.print(bufBytes);
  175. Serial.println("~");
  176. }
  177.  
  178. void doDump(void) {
  179. Serial.println("Got a dump");
  180. dumpVariableVert(256);
  181. }
  182. void doGetProgram(void){
  183. Serial.println("Doing getProgram.");
  184. }
  185. void doWriteStuff(void) {
  186. // Serial.print("@W"); //usually happens twice in cycle when
  187. writeStrobe=true;
  188. }
  189. void doTPAStuff(void) {
  190. writeStrobe = false; //before new low-going *MWR causes writeStrobe to go true. Safe.
  191. adrByteHi = PINA; //will be used at TPB time later
  192.  
  193. }
  194.  
  195. void getFile() { // go to File Send part of Bray++ terminal and put bin file into vRAM[]
  196. int inCtr=0;
  197. byte byteIn=65;
  198. // while(inCtr<256){
  199. while(inCtr<1024){
  200. if(Serial.available()){
  201. byteIn = Serial.read();
  202. vRAM[inCtr]=byteIn;
  203. inCtr++;
  204. }
  205. }
  206. Serial.print("Got 111256");
  207. }
  208. void norwayCommand(void){ //trying better instruction method from serial https://www.norwegiancreations.com/2017/12/arduino-tutorial-serial-inputs/
  209. String command;
  210.  
  211. if(Serial.available()){
  212. command = Serial.readStringUntil('\n'); //Not happy with this method but works if exactly 256 bytes sent.
  213.  
  214. if(command.equals("gf")){
  215. Serial.print("Getting File");
  216. getFile();
  217. serialFlush();
  218. Serial.println("**done gf flush** Now resetting");
  219. doReset();
  220. }
  221.  
  222. else if(command.equals("du")){
  223. // dumpVert();
  224. dumpVariableVert(256);
  225. serialFlush();
  226. Serial.println("**done duflush**");
  227. }
  228. else if(command.equals("dk")){
  229. dumpVariableVert(1024);
  230. serialFlush();
  231. Serial.println("**done dkflush**");
  232. }
  233. else if(command.equals("re")){
  234. //dumpVariableVert(1024);
  235. doReset();
  236. serialFlush();
  237. Serial.println("**did reset flush**");
  238. }
  239. else{
  240. Serial.println("Invalid command");
  241. Serial.println(command);
  242. }
  243. }
  244. }
  245. void dumpVariableVert(int sizeToDump) { //new version of dumpVert(). Different sizes.
  246. char data[100];
  247. Serial.print("Col: ");
  248. for(int i=0;i<16;i++) {
  249. sprintf(data, "%02x ",i);
  250. Serial.print(data);
  251. if(i==7) Serial.print(" ");
  252. }
  253. for (int i=0;i<sizeToDump;i++){
  254. if (i%16 == 0){
  255. Serial.println ("");
  256. sprintf(data, "%02x ",i);
  257. Serial.print(data);
  258. }
  259. if(i%8==0) { Serial.print("|"); }
  260. sprintf(data, " %02x ",vRAM[i]);
  261. Serial.print(data);
  262. }
  263. Serial.println(" ");
  264. }
Advertisement
Add Comment
Please, Sign In to add comment