prjbrook

CDP1802f03.ino Mega shield breadboard

Jun 9th, 2020
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.44 KB | None | 0 0
  1. /**e91 1
  2. Mon May 25 11:41:03 NZST 2020. Got RAM down to 1795bytes with report rewritten sparsely.Now have to practice SPI..
  3. But first lower vRAM[] buf from 1k to 256 bytes. Adjust other routines eg getfile to fit.
  4. Sun May 24 10:41:34 NZST 2020 CDP1802f01.ino works OK. Now going to tidy commands. Reduce RAM req.
  5. Fri May 22 10:07:06 NZST 2020. CDP1802f.ino. Going to integrate progmem7.ono into it so get GROGMEM-based disassembler
  6. 1:03 PM 5/05/2020. Want to pull bytes down from above $4000. Put in there by combinedFil0.bin. Experiment.
  7. Thu Apr 30 11:43:51 NZST 2020. Last code fiddling before big tidy up and memory reduction.
  8. Looking at kludge to simulate INP
  9. e9. Tidy up OUT and start on INP.
  10. Tue Apr 28 13:10:47 NZST 2020. Have been wrestling with OUT 1 but think it's OK now. Needs tidying.
  11. Sun Apr 26 13:41:58 NZST 2020. Timing seems OK but max of 20KHz for clock seems slow. Now onto I/o. Start with..
  12. ..concept of virtual peripherals. eg when an interrupt occurs it can be tuned off with an OUT 1 and send $0f
  13. Fri Apr 24 13:13:07 NZST 2020. Now want to time instructions per second using millis, run and stop (single stepping = stop)
  14. Fri Apr 24 11:12:12 NZST 2020. Still tidying up printLevel3.Done
  15. Thu Apr 23 11:39:37 NZST 2020. Working on disassembler's output. Thinking of 4 levels: Lev0 = print_nothing to Lev3 print_heaps_diagnostics
  16. ..NB space: "Global variables use 2902 bytes (35%) of dynamic memory, leaving 5290 bytes for local variables. Maximum is 8192 bytes."
  17. ..Too much RAM for nano. Might have to use progmem etc.
  18. Tue Apr 21 20:12:55 NZST 2020. Disassember going. Some problems with many switch statements so changed to if,if,if,.
  19. Needs to be tidied up and slimmed down.Starting now in ...e4.
  20. Sun Apr 19 11:02:16 NZST 2020. Extending disassem. but ram memory too high for nano.
  21. Sat Apr 18 12:50:37 NZST 2020. Cosmacuino version 0.2 Now starting on disassembler.
  22. Fri Apr 17 16:53:23 NZST 2020. ..e1 works well. Final step would be a disassembler but need to think about space on nano.
  23. ..all below has been on mega.
  24. Fri Apr 17 12:43:54 NZST 2020.C:\Users\Dell\Documents\Arduino\PB_SketchApril12\CDP1802e0\CDP1802e0.ino. Trying report of all useful vars.
  25. Fri Apr 17 11:41:53 NZST 2020. Going to look at DElay changes and report.
  26. Thu Apr 16 14:26:37 NZST 2020. Sorted, I think, break points, opcode stopping with seial commands. Next:speed changes.
  27. Thu Apr 16 12:25:37 NZST 2020. Working well. Now get break points going in real time...
  28. Tue Apr 14 19:59:13 NZST 202. All code tidied up. Old routines deleted. Next: single stepping.
  29. Tue Apr 14 15:35:00 NZST 2020. Going OK. Just deleting a whole lot of rubbish and carefully retesting.
  30. Tue Apr 14 13:02:36 NZST 2020. Tidy up time, and simplify main loop into easy subroutines.
  31. Mon Apr 13 14:50:01 NZST 2020. version 1802d2.ino now working well. Norway routines have been replaced.
  32. ...by bulletproof ones. Want to make better output each line of code.
  33. ..To form like 0123: F8 F,R,cycles, clocks
  34. Mon Apr 13 13:24:55 NZST 2020. Getting rid of Norwat commands and integrating checkForCommands()
  35. * Sun Apr 12 15:40:21 NZST 2020. Got better serial command routines from bulletProofSerialI. Integrate them.
  36. * Mon Mar 30 15:05:50 NZDT 2020 ..c8. Got long branches, lbr, into page three going OK.
  37. * .. also got sep to work in same way. Jumped in and out of code by changing prog ctr with sep.
  38. * .. next. Try that SCART method of using subroutines on 1802
  39. * Sun Mar 29 14:26:46 NZDT 2020 ..c7. Have big 1024 vRam[] buffer but can't use it yet.
  40. * ..Need TPA time to record Hi adr byte.
  41. * Sorted vRAM[] up to 1024 bytes and got new comand dumpVariableVer(int) to give 256 0r 1024 dumps.
  42. * Sun Mar 29 13:49:17 NZDT 2020 ..c6. Now want to exgtend vRAM[] frolm 256 to 1024 bytes. Fake memory.
  43. * Sat Mar 28 16:23:44 NZDT 2020. This is ...c5. Now going to try fastest baudrate 115200 and fastest DELAY =1.
  44. * All worked. Fast enough for time being. Next increase vRAM[] to 1024 bytes and check Hi address byte on
  45. * ..TPA.
  46. * Sat Mar 28 16:23:44 NZDT 2020 still...c4. Got baudrate up to 57600 and DELAY down to 2. Allworking.
  47. * Sat Mar 28 14:13:16 NZDT 2020 CDP1802c4. Going to try DELAY=4, and baudrate is 38.4K. Works OK but
  48. * ..is too fast in terminal so only print every 10th TPB going-high count. (clocks/8)
  49. * 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
  50. * Now going to try DELAY =8 and baud = 28.8K. Both worked.
  51. * Sat Mar 28 13:14:18 NZDT 2020 CDP1802c2. Need to speed up a bit. Reg dumping works but is slow.
  52. * so going to change DELAY from 50 to 32 then keep halving. Worked OK also shortened message to terminal.
  53. * Also increased serial speed to 14.4K. Working OK. Next continue speed of clock and baudrate.
  54. * The version below is about right for reading programs into mega to act like ROM for 1802.
  55. * Only hesitation is the norway commands where serial strings seem a bit error prone.
  56. *
  57. * Thu Mar 26 14:09:30 NZDT 2020 CDP1802c1. Some problems with Norway commands as serial chars still available from prevuious actions.
  58. * ..Solution might be to flush Rx buffer after each command.
  59. * Wed Mar 25 16:40:32 NZDT 2020 CDP1802c0. Now going to add in serial read into vRAM[] from bin file generated
  60. * ..by a18 assembler. Uses Bray++ terminal to send file. Norway command is "gf" for getfile. Has to be 256 bytes.
  61. * 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.
  62. * * Tue Mar 24 13:09:41 NZDT 2020. All below works. Just a bit worried writeStrobe might turn on after being..
  63. * ..dealt with during TPB. Might get TPA to turn off writeStrobe so any subsequent LOWs of MWR* before TPB time are valid only
  64. * Tue Mar 24 10:20:46 NZDT 2020 CDP18028.Playing with MWR*
  65. * CDP1802b7 works. See 1802 blog. Next version: look at MWR.
  66. * CDP1802b6 21/3/203:47 Issues woth serial.available slowing down reads of 1802 data. Trying new Norwegian code.
  67. * 3:57, works witrh dummy commands.
  68. * . Start of array use for instructions
  69. Had big problems with first TPB cycle. Seemed to get old address outp[ut on address bus low when
  70. ..it should have been zero after reset. Round about the 4th clock after reset, adress goes to old value before reset.
  71. ..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
  72. ..activated on first cycle so maybe just nop in zero position and move on?
  73. ..Next, connect up BUS pins to C port on mega. Initially just output nops, then when needed by instruction fetch, then chnage
  74. .. to little program that plays with Q and does loop involving nops too. This program has too many diagnostic entries so will tidy up
  75. .. before trying next version.
  76. Tidied up and working with resistors connecting data bus to $C4 pattern = nop.
  77. Now going to send constant $C4 via PORTC of Mega2650 to breadboard containing 1802. PORTC-->BUS 1802 all the time. Should be the
  78. ..same as resistor to rail $C4 above. Worked 10:07
  79. Now try sending $c4 only when clk goes low and TPB is high.Worked 10:19.
  80. 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
  81. Now going to select nop from an array of nops. Worked with just one element of arry of instructions called vRAM[]. Do several next.
  82. Key change was [ byte vRAM[5] = {0xc4, 0xc4, 0xc4, 0xc4, 0x00}; ] Next add instructions to turn on and off Q flag.
  83. Now going to put in little sequence of instructions. Key change is: [ byte vRAM[5] = {0xc4, 0x7b, 0xc4, 0x7a, 0x00};
  84. //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}; ]
  85. Now gpoing to turn Q on and off but with branch back to start. Worked OK.
  86. 11:27am 20/3/20. Adding in dump of vertual ram array as well as issuing commands from serial terminal.
  87. ..Practiced some of the routines in dumper3.
  88. Going well, apart from serial read issues, but basic 1820 stuff going well. Try new serial read instruction code.
  89. */
  90. #include <avr/pgmspace.h>
  91. //1802 talks to Arduino Mega
  92. #define clockPin 13
  93. #define clearPin 12
  94. #define waitPIn 11 //not used
  95. #define intPin 10
  96. #define TPBpin A1
  97. #define TPApin A0
  98. #define readPin A15 //the *MRD of 1802
  99. #define writePin A14 //the MWR* of 1802
  100. #define SC0pin A12 //When SC0=LOW it's a fetch, when HI it's executing
  101. #define n0Pin A9 //needed?
  102. #define n1Pin A8
  103. #define n2Pin A10 //these are the n-bus items that are non-zero during I/O OUT and IN.
  104. #define TPBDivisor 1 //50 //1 // 100 //50 //10 //if ten, shows every tenth output line, otherwise too fast to see and act in terminal.
  105. //#define DELAY 50 //16 //1 // 2 //4 //8 //16 //32 //50
  106. byte DELAY=30; //default. Can be changes via terminal command.
  107. int BUFFERLENGTH = 256 ; //1024; //this is how big the vRAM[] array is. Going to be shorter than 1024.
  108.  
  109. int val = 0;// int bufBytes;
  110. unsigned int adrByte=0;
  111. unsigned int adrByteHi =0;
  112. unsigned int currentAdr;
  113. unsigned long time =0;
  114. boolean writeStrobe = false; //should really get TBA to turn this off too; Just in case.
  115. const byte numChars = 32;
  116. char receivedChars[numChars];
  117. byte receivedBytes[numChars];
  118. byte nBus=0;
  119. byte ioAdrLow;
  120. byte ioByte;
  121. byte nextByte;
  122. byte thirdByte;
  123. char data[100] ;
  124. //char data[32] ;
  125. //char data[200];
  126. unsigned int breakPointAdr=0,opCode,stopCode;
  127. unsigned long fetchCtr=0;
  128. unsigned long t0,clkCtr=0,TPBCtr= 0, clockRate=0,t1=0; //used in millis timing.
  129. char fetchOrExecuteCh;
  130. char readOrWriteCh;
  131. char * blankStr ="";
  132. int printLevel=1; //how much detail do you want in serial output for disassembler
  133. char instructionBytes = 1; //some instructions have 1 eg c4 = nop, some have 3 eg lsk 12 34
  134. //byte opCode;
  135. boolean newData = false;
  136. //boolean showExecutes = true;
  137. boolean TPADone = false, TPBDone=true;
  138. boolean singleStepping = false, stepMe=false;
  139. boolean showCommands=true;
  140. boolean doOpStops = false; //breakpoint if opCode=stopCode;
  141.  
  142.  
  143. //byte vRAM[5] = {0x7b, 0x7b, 0x7a, 0x7b, 0x00}; //ie nop,seq,nop,req,idl
  144. //byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0x7a, 0x30, 0x00,0x00}; //ie seq,seq,req,seq,br start, idl
  145. //byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x6A,0x57, 0x30, 0x09,0x00};
  146. //byte vRAM[1024] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x7D,0x57,0xc4,0xc4, 0x30, 0x09,0x00};
  147. byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x7D,0x57,0xc4,0xc4, 0x30, 0x09,0x00};
  148. //byte vRAM[512] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x7D,0x57,0xc4, 0x30, 0x09,0x00}; //memory short on nano
  149. //--------------------globals from progmem7.ino below-----------------------------
  150.  
  151. const char flashHiNib3[] PROGMEM = {"[00idl.][01ldn.L[10inc.L[20dec.L[30br.N[31bq.N[32bz.N[33bdf.N[34b1.N[35b2.N[36b3.N[37b4.N[38skp.][39bnq.N[3Abnz.N[3Bbnf.N[3Cbn1.N[3Dbn2.N[3Ebn3.N[3Fbn4.N[40lda.L[50str.L [60irx.L[61out.L[69inp.L[70ret.]abcd[71dis.][72ldxa.][73stxd][74adc.][75sdb.][76shrc.][77smb.][78sav.][79mark.][7Aseq.][7Breq.][7Caddi.N[7Dsdbi.N[7Eshlc.][7Fsmbi.N[80glo.L[90ghi.L[A0plo.L[B0phi.L[C0lbr.T[C1lbq.T[C2lbz.T[C3lbdf.T[C4nop.][C5lsnq.][C6lsnz.][C7lsnf.][C8lskp.][C9lbnq.T[CAlbnz.T[CBlbnf.T[CClsie.][CDlsq.][CElsz.][CFlsdf.][D0sep.L[E0sex.L[F0ldx.][F1or.][F2and.][F3xor.][F4add.][F5sd.][F6shr.][F7sm.][F8ldi.N[F9ori.N[FAani.N[FBxri.N[FCadi.N[FDsdi.N[FEshl.][FFsmi.N"}; //};
  152.  
  153. char ch1;
  154. char char3 = '7' ;
  155. char char4 ='F';
  156. char oldChar4;
  157. char data0[10] ;
  158. char closingBracket;
  159.  
  160. //byte vRAM[6] = {0x7b, 0x7b, 0x7a, 0xCA,0x7b,0x68};
  161. //byte vRAM[1024] = {0x7B, 0x7A, 0x7B, 0xDD,0xEE,0xC0,0xC1, 0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, 0x60, 0x66, 0x6e, 0x46, 0x56, 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3f,0x16,0x26,0x06,0x86,0x96,0xA6,0xB6,0xF8,0x00,0xB7,0xF8,0x98,0xa7,0xf8,0x7D,0x57,0xc4,0xc4, 0x30, 0x09,0x00};
  162.  
  163. boolean foundOpCode;
  164.  
  165. byte LSNib;
  166. byte MSNib;
  167. //byte nextByte = 0x11;
  168. //byte thirdByte = 0x22;
  169. void setup() {
  170.  
  171. pinMode(clockPin, OUTPUT);
  172. pinMode(clearPin, OUTPUT);
  173. pinMode(intPin,OUTPUT);
  174. pinMode(TPApin,INPUT);
  175. pinMode(TPBpin,INPUT);
  176. pinMode(readPin,INPUT);
  177. pinMode(writePin,INPUT);
  178. pinMode(SC0pin,INPUT);
  179. DDRA=0x00; //DDRA reads Adress port of 1802. All inputs.
  180. DDRC=0x00; //PORTC connects to 1802 data BUS.
  181. DDRK=0x00; //PORTK takes nBus and other signals
  182. Serial.begin(9600); //(115200); //(57600); //38400); //(28800); //(19200); //(14400); //(9600); // // open the serial port at 9600 bps:
  183. serialFlush();
  184. delay(1000); //time to sort out Bray++
  185. Serial.flush();
  186. Serial.println("CDP1802e94.ino");
  187. delay(500);
  188. doReset();
  189. // dumpVariableVert(256);
  190. // doReport();
  191. //experiment0();
  192. //experiment1();
  193. //while(1) { };
  194. printLevel=1; //printlevel = 1 is default. Can be changed via terminal commands.
  195. //experiment1();
  196. //millisExperiment0();
  197. hiMemExp();
  198. }
  199. //--------------------------------------------------------------------------------------
  200. void loop() {
  201. checkForCommands(); //Still a bit clumsy with Serial lib.
  202. doClockCycle();
  203. }//*******************************************
  204.  
  205. void doClockCycle() {
  206. digitalWrite(clockPin, HIGH); // turn the LED on (HIGH is the voltage level)
  207. if(digitalRead(TPApin) ==HIGH) {
  208. doTPAStuff();
  209. }
  210. if (digitalRead(writePin)==LOW){
  211. doWriteStuff();
  212. doInpStuffIfNecess();
  213. }
  214. delay(DELAY); // wait. DELAY is a variable, can be 0
  215.  
  216. digitalWrite(clockPin, LOW); // turn the LED off by making the voltage LOW
  217. DDRC=0x00; //DDRC usually input except when sending instruction
  218. clkCtr++; //how many clocks after reset?
  219.  
  220. if (digitalRead(TPBpin) ==HIGH) {
  221. doTPBWork();
  222. }
  223. delay(DELAY); // wait
  224. }
  225. //*************************************************
  226. void doTPBWork(void) {
  227. TPBCtr++;
  228. adrByte = PINA;
  229. nBus = PINK & 0b0000111; //just want first three bits for n0,1,2
  230. //if ((writeStrobe== true)&& (nBus==0)) {
  231. if (writeStrobe== true) {
  232. writeStrobe = false;
  233. vRAM[adrByte+adrByteHi*256]=PINC; //adrByteHi comes from read of PORTA (!PORTC) during TPA
  234. readOrWriteCh='W';
  235. }
  236. else {
  237. readOrWriteCh='R';
  238. }
  239.  
  240.  
  241. if(digitalRead(SC0pin)==LOW) {
  242. fetchOrExecuteCh='F';
  243. fetchCtr++;
  244. //print1TPBResults1();
  245. }
  246. else {
  247. fetchOrExecuteCh='E';
  248. }
  249.  
  250. //if ((digitalRead(readPin)==LOW)&& (nBus==0) ){
  251. if ((digitalRead(readPin)==LOW)){
  252. DDRC = 0xff; //just for this version. Send nop when clockk goes 1 to 0, TPB =1, MRD=0
  253. currentAdr = adrByte+adrByteHi*256;
  254. if (currentAdr>BUFFERLENGTH) {
  255. PORTC = pgm_read_byte(currentAdr);
  256. opCode=pgm_read_byte(currentAdr);
  257. nextByte = pgm_read_byte(currentAdr+1);
  258. thirdByte = pgm_read_byte(currentAdr+2);
  259. }
  260. else {
  261. //PORTC = vRAM[adrByte+adrByteHi*256] ; // read byte from virtual
  262. //opCode=vRAM[adrByte+adrByteHi*256];
  263. PORTC=vRAM[currentAdr];
  264. opCode=vRAM[currentAdr];
  265. nextByte = vRAM[currentAdr+1];
  266. thirdByte = vRAM[currentAdr+2];
  267. }
  268. if (nBus!=0) { //in case of OUT n, the opcode is the byte taken from MR(X) and put on data bus
  269. //ioByte=vRAM[currentAdr];
  270. Serial.print("## ");Serial.println(opCode,HEX);
  271. doOUT();
  272. }
  273. }/*
  274. if ((digitalRead(readPin)==LOW)&& (nBus!=0) ){ //big slow issues around here.
  275. DDRC = 0xff;
  276. //PORTC=0xa3; //arbitrary
  277.  
  278. ioAdrLow = PINA; //1802 puts adr of M(R(X)) on adr bus=PORTA
  279. // collects adrByteHi in last TPA.
  280. Serial.print("%% ");Serial.print(adrByteHi,HEX); Serial.println(ioAdrLow,HEX);
  281. Serial.print("$$ ") ;Serial.print(adrByteHi,HEX);Serial.println(adrByte,HEX);
  282. ioByte =vRAM[adrByte+adrByteHi*256];
  283. Serial.print("## ");Serial.println(ioByte,HEX);
  284. //currentAdr = adrByte+adrByteHi*256;
  285. PORTC = vRAM[adrByte+adrByteHi*256] ; //OUT 1 is really just READ R(X) with nBus action
  286. //Serial.print("^ ^");Serial.println(PINA+adrByteHi*256,HEX);
  287. //Serial.println("Got an OUT 2instruction ");
  288. //Serial.println(nBus);
  289. //digitalWrite(intPin,LOW); //test.
  290.  
  291. }*/
  292. TPBDone=true;
  293. //print1TPBResults1();
  294. //printTPBResults2();
  295. if(printLevel!=0) {
  296. //printTPBResults3();
  297. printTPBResults4();
  298. }
  299. if((currentAdr==breakPointAdr) && (breakPointAdr>0)) {
  300. Serial.println("Breakpoint address .....");
  301. singleStepping=true;
  302. }
  303. if((doOpStops==true) && (opCode == stopCode)){
  304. Serial.println("Op code stop .....");
  305. singleStepping=true;
  306. }
  307. if(singleStepping==true){
  308. Serial.print("*");
  309. stepMe=false;
  310. while(stepMe==false){
  311. checkForCommands();
  312. }
  313. }
  314. }
  315. void doReset(void){
  316. digitalWrite(intPin,HIGH); //no interrupts yet
  317. digitalWrite(clearPin,LOW); //bring CLEAR low for about 10 clocks to reset 1802
  318. for(int i =0;i<=10;i++) {
  319. digitalWrite(clockPin, HIGH);
  320. delay(DELAY); // wait
  321. digitalWrite(clockPin, LOW);
  322. delay(DELAY);
  323. }// 10 clocks low should reset 1802
  324. digitalWrite(clearPin,HIGH); //bring back to RUN mode
  325. }
  326.  
  327. void serialFlush(void){
  328. while(Serial.available() > 0) { //while there are characters in the serial buffer, because
  329. char t = Serial.read(); // get one character
  330. }
  331. }
  332. void doWriteStuff(void) {
  333. // Serial.print("@W"); //usually happens twice in cycle when
  334. writeStrobe=true;
  335. }
  336. void doTPAStuff(void) {
  337. writeStrobe = false; //before new low-going *MWR causes writeStrobe to go true. Safe.
  338. adrByteHi = PINA; //will be used at TPB time later.
  339. TPADone=true;
  340. }
  341.  
  342. void getFile() { // go to File Send part of Bray++ terminal and put bin file into vRAM[]
  343. int inCtr=0;
  344. byte byteIn=65;
  345. while(inCtr<BUFFERLENGTH){
  346. if(Serial.available()){
  347. byteIn = Serial.read();
  348. vRAM[inCtr]=byteIn;
  349. inCtr++;
  350. }
  351. }
  352. Serial.print("Got "); Serial.println(BUFFERLENGTH);
  353. }
  354.  
  355. void dumpVariableVert(int sizeToDump) { //new version of dumpVert(). Different sizes.
  356. //char data[100];
  357. Serial.print("Col: ");
  358. for(int i=0;i<16;i++) {
  359. sprintf(data, "%02x ",i);
  360. Serial.print(data);
  361. if(i==7) Serial.print(" ");
  362. }
  363. for (int i=0;i<sizeToDump;i++){
  364. if (i%16 == 0){
  365. Serial.println ("");
  366. sprintf(data, "%02x ",i);
  367. Serial.print(data);
  368. }
  369. if(i%8==0) { Serial.print("|"); }
  370. sprintf(data, " %02x ",vRAM[i]);
  371. Serial.print(data);
  372. }
  373. Serial.println(" ");
  374. }
  375. int hexCharToInt2(byte by){ //pb version
  376. int d,r;
  377. d=by-'0';
  378. if(d>=0 && d<=9) {r=d;}
  379. else{
  380. d=by-55; //is it A,B...F?
  381. if (d>=10 && d<=15) {r=d;}
  382. else{
  383. r=by-87; //must be a,b...f. NB No error checking.
  384. }
  385. }
  386. return r;
  387. }
  388.  
  389. void doBreakPoint2(){
  390. int d;
  391. int ctr=0;
  392. unsigned int hexVal[8];
  393. hexVal[2]=hexCharToInt2(receivedBytes[2])*4096;
  394. hexVal[3]=hexCharToInt2(receivedBytes[3])*256;
  395. hexVal[4]=hexCharToInt2(receivedBytes[4])*16;
  396. hexVal[5]=hexCharToInt2(receivedBytes[5])*1;
  397. breakPointAdr=hexVal[2]+hexVal[3]+hexVal[4]+hexVal[5]; //important
  398. Serial.print("Break point adress is : ");
  399. Serial.print(breakPointAdr);
  400. Serial.print(", in hex : 0x");
  401. Serial.println(breakPointAdr,HEX);
  402. }
  403. void doOpStop2(){
  404. // int d;
  405. unsigned int hexVal[8];
  406. hexVal[2]=hexCharToInt2(receivedBytes[2])*16;
  407. hexVal[3]=hexCharToInt2(receivedBytes[3])*1;
  408. stopCode=hexVal[2]+hexVal[3];
  409. Serial.print("Op stop is : ");
  410. Serial.print(stopCode);
  411. Serial.print(", in hex : 0x");
  412. Serial.println(stopCode,HEX);
  413. }
  414. void doDelay() {
  415. unsigned int hexVal[8];
  416. hexVal[2]=hexCharToInt2(receivedBytes[2])*16;
  417. hexVal[3]=hexCharToInt2(receivedBytes[3])*1;
  418. DELAY=hexVal[2]+hexVal[3];
  419. Serial.print("DELAY now is : ");
  420. Serial.print(DELAY);
  421. Serial.print(", in hex : 0x");
  422. Serial.println(DELAY,HEX);
  423. }
  424. void interpretCommand() {
  425. // String Command(receivedChars); //**important
  426. //if(Command.equals("gf")){
  427. if((receivedBytes[0]=='g')&&(receivedBytes[1]=='f')) { //get file
  428. Serial.print("Send file");
  429. getFile();
  430. serialFlush();
  431. doReset();
  432. }
  433.  
  434. //if(Command.equals("dk")){
  435. if((receivedBytes[0]=='d')&&(receivedBytes[1]=='k')) { //dump 1k. Need this with buf =256?
  436. dumpVariableVert(1024);
  437. serialFlush();
  438. //Serial.println("**done dkflush**");
  439. }
  440. //if(Command.equals("du")){
  441. if((receivedBytes[0]=='d')&&(receivedBytes[1]=='u')) { //dump 256 bytes
  442. dumpVariableVert(256);
  443. serialFlush();
  444.  
  445. }
  446. //if(Command.equals("re")){
  447. //if((receivedBytes[0]==0x72)&&(receivedBytes[1]==0x65)) { //re for reset
  448. if((receivedBytes[0]=='r')&&(receivedBytes[1]=='e')) {
  449. doReset();
  450. TPBCtr=0; clkCtr = 0;
  451. serialFlush();
  452. Serial.println(F("**done gf flush** Now resetting"));
  453. }
  454.  
  455. if((receivedBytes[0]==0x62)&&(receivedBytes[1]==0x70)) doBreakPoint2(); //<bpxxxx>
  456. if((receivedBytes[0]==0x6f)&&(receivedBytes[1]==0x70)) doOpStop2(); //<opxx>
  457. if((receivedBytes[0]==0x64)&&(receivedBytes[1]==0x65)) doDelay(); //<dexx>.
  458.  
  459. if((receivedBytes[0]=='s')&&(receivedBytes[1]=='s')){ //single step
  460. singleStepping=true; t1=millis()-time; Serial.print("--> ");Serial.print(t1);
  461. clockRate = (clkCtr*1000)/t1; Serial.print("=&& "); Serial.print(clockRate);
  462. } //go into single stepping but stop clock; presume <run> just finished.
  463. //if(Command.equals("stepMe")) stepMe=true;
  464. if((receivedBytes[0]=='s')&&(receivedBytes[1]=='t')) stepMe=true; //st
  465.  
  466. //if (Command.equals("report")) doReport();
  467. //************
  468. if((receivedBytes[0]=='r')&&(receivedBytes[1]=='p')) doReport2(); //doReport(); //rp
  469.  
  470. if((receivedBytes[0]=='t')&&(receivedBytes[1]=='c')){ //tc
  471. //if(Command.equals("toggleCommandShow")){
  472. if(showCommands==true) showCommands=false;
  473. else showCommands=true;
  474. }
  475. //if(Command.equals("toggleShowExecutes")){
  476. /*if((receivedBytes[0]=='t')&&(receivedBytes[1]=='e')){ //te
  477. if(showExecutes==true) showExecutes=false;
  478. else showExecutes=true;
  479. } */
  480. //if(Command.equals("toggleOpStopping")){
  481. if((receivedBytes[0]=='o')&&(receivedBytes[1]=='s')) { //os
  482. if(doOpStops==true) doOpStops=false;
  483. else doOpStops=true;
  484. }
  485. //if(Command.equals("run")){
  486. if((receivedBytes[0]=='r')&&(receivedBytes[1]=='u')) { //ru
  487. singleStepping=false;
  488. stepMe=true;
  489. Serial.println("Sing step = false");
  490. clkCtr=0; TPBCtr=0; fetchCtr=0; //after "run" we're timing clks/sec
  491. time=millis();
  492. //Serial.print("<> "); Serial.print(time); //start timer. Stopped by going into single stepping.
  493.  
  494. }
  495. //if(Command.equals("pl0")) printLevel=0;
  496. if((receivedBytes[0]=='p')&&(receivedBytes[1]=='0')) printLevel=0; //p0
  497. if((receivedBytes[0]=='p')&&(receivedBytes[1]=='1')) printLevel=1; //p1
  498. if((receivedBytes[0]=='p')&&(receivedBytes[1]=='2')) printLevel=2; //p2
  499. if((receivedBytes[0]=='p')&&(receivedBytes[1]=='3')) printLevel=3; //p3
  500.  
  501. //if(Command.equals("pl1")) printLevel=1;
  502. //if(Command.equals("pl2")) printLevel=2;
  503. //if(Command.equals("pl3")) printLevel=3;
  504. //if(Command.equals("int")) digitalWrite(intPin,LOW); // turn off with OUT 1 (0x0f)
  505. if((receivedBytes[0]=='i')&&(receivedBytes[1]=='n')) digitalWrite(intPin,LOW); //in
  506.  
  507.  
  508. }
  509.  
  510. void checkForCommands(){ //if any inputs from keyboard, push them into buffer and see what command it is.
  511. recvWithStartEndMarkers();
  512. showAndInterpret();
  513. }
  514.  
  515. void recvWithStartEndMarkers() { ////https://forum.arduino.cc/index.php?topic=396450
  516. static boolean recvInProgress = false;
  517. static byte ndx = 0;
  518. char startMarker = '<';
  519. char endMarker = '>';
  520. char rc;
  521. while (Serial.available() > 0 && newData == false) {
  522. rc = Serial.read();
  523.  
  524. if (recvInProgress == true) {
  525. if (rc != endMarker) {
  526. receivedChars[ndx] = rc;
  527. receivedBytes[ndx]=(byte)rc; //PB added this
  528. ndx++;
  529. if (ndx >= numChars) {
  530. ndx = numChars - 1;
  531. }
  532. }
  533. else {
  534. receivedChars[ndx] = '\0'; // terminate the string
  535. recvInProgress = false;
  536. ndx = 0;
  537. newData = true;
  538. }
  539. }
  540.  
  541. else if (rc == startMarker) {
  542. recvInProgress = true;
  543. }
  544. }
  545. }
  546.  
  547. void showAndInterpret() {
  548. if (newData == true) {
  549. if(showCommands==true){
  550. Serial.print("Command received is : ");
  551. Serial.println(receivedChars);
  552. }
  553. else {serialFlush();} //get rid of commands in input buffer
  554. interpretCommand();
  555. //interpretCommand(); //*******put back** just testing for ram size
  556. newData = false;
  557. }
  558. }
  559. void print1TPBResults1(void) {//print disassembled opcode with address: optional
  560. sprintf(data,"Adr1] %02x%02x : ",adrByteHi,adrByte);
  561. Serial.print(data);
  562. doDisAsm(opCode); //new
  563. }
  564. /*void printTPBResults2() { //output adr and opcode and clockc et for each line...
  565. //showExecutes=true;
  566. ///temp!!!
  567. //doReport();
  568. if (fetchOrExecuteCh=='F') {
  569. // sprintf(data,"Adr: %02x%02x : %02x %u, %u %c %c",adrByteHi,adrByte,opCode, TPBCtr,clkCtr, fetchOrExecuteCh,readOrWriteCh);
  570.  
  571. sprintf(data,"Adr) %02x%02x : %02x ",adrByteHi,adrByte,opCode);
  572.  
  573. Serial.print(data);
  574. doDisAsm(opCode); //best place?
  575.  
  576.  
  577.  
  578.  
  579. }
  580. else{
  581. if(boolean showExecutes){ //KLUDGE, TAKE OUT LATER
  582. sprintf(data," Adr2: %x%x : %02x %lu<, %lu> %c %c",adrByteHi,adrByte,opCode,TPBCtr,clkCtr, fetchOrExecuteCh,readOrWriteCh);
  583. Serial.println(data);
  584.  
  585. }
  586. }
  587. } */
  588. void doReport() { //show all useful variables.
  589. sprintf(data, "delay = %02x, op Stop code = %02x, breakpoint = %04x, current address = %04x, op code = %02x", DELAY,stopCode,breakPointAdr,currentAdr,opCode);
  590. Serial.println(data);
  591. sprintf(data, "TPBCtr = %lu, clkCtr= %lu, readOrWriteCh = %c, fetchOrExecuteCh = %c, doOpStops=%d ", TPBCtr,clkCtr,readOrWriteCh,fetchOrExecuteCh,doOpStops);
  592. Serial.println(data);
  593. sprintf(data, "TPADone = %d, TPBDone= %d, singleStepping = %d, stepMe = %d, showCommands = %d, instuction fetches=%lu ", TPADone,TPBDone,singleStepping,stepMe,showCommands,fetchCtr);
  594. Serial.println(data);
  595. sprintf(data,"Print Level %d",printLevel);
  596. Serial.print(data);
  597. }
  598. void doDisAsm(byte bopCode) { //look at op code and disassemble insgtruction. May require reading further bytes
  599. byte LSNib, MSNib;
  600. MSNib = bopCode/16;
  601. LSNib = bopCode%16;
  602. //sprintf(data,"Op code is %x and MSNib is %x and LSNib is %x", bopCode, MSNib, LSNib); //take out later.
  603. //Serial.println(data);
  604. instructionBytes = 1; //default for eg nop, phi, inc. Can be changed at relevant instruction subroutine
  605. switch(MSNib) {
  606. case 0:
  607. if(LSNib==0) sprintf(data,"idl %s",blankStr);
  608. else sprintf(data,"ldn %x",LSNib); break;
  609. case 1:
  610. sprintf(data,"inc %x",LSNib);
  611. break;
  612. case 2:
  613. sprintf(data,"dec %x",LSNib);
  614. break;
  615. case 3:
  616. //sprintf(data,"Tricky branches");
  617. instructionBytes=2;
  618. doHiNib3(LSNib);
  619. break;
  620. case 4:
  621. sprintf(data,"lda %x",LSNib);
  622. break;
  623. case 5:
  624. sprintf(data,"str %x",LSNib);
  625. break;
  626. case 6:
  627. //sprintf(data,"Tricky I/O");
  628. //sprintf(data,"Case 6");
  629. //instructionBytes = 2;
  630. doHiNib6(LSNib);
  631. break;
  632. case 7:
  633. //sprintf(data,"Tricky Hi nib 7");
  634. //doHiNib7(LSNib);
  635. //doHiNib7A(LSNib);
  636. doHiNib7B(LSNib);
  637. break;
  638. case 8:
  639. sprintf(data,"glo %x",LSNib);
  640. break;
  641. case 9:
  642. sprintf(data,"ghi %x",LSNib);
  643. break;
  644. case 0xa:
  645. sprintf(data,"plo %x",LSNib);
  646. break;
  647. case 0xb:
  648. sprintf(data,"phi %x",LSNib);
  649. break;
  650. case 0xc:
  651. instructionBytes=3;
  652. doHiNibcB(LSNib); //long branches and skips :0xc..
  653. break;
  654. case 0xd:
  655. sprintf(data,"sep %x",LSNib);
  656. break;
  657. case 0xe:
  658. sprintf(data,"sex %x",LSNib);
  659. break;
  660. case 0xf:
  661. doHiNibfA(LSNib); //arith logic etc
  662. break;
  663. default:
  664. sprintf(data," not disassenble %x %x",MSNib,LSNib); break; //took "could" out
  665. }
  666. //showData();
  667. Serial.print(data);
  668. //Serial.print("-");
  669. //Serial.print(bopCode,HEX); //output disassembled bopCode,no..maybe only at certain levels
  670. //Serial.println(bopCode,HEX);
  671. //serialFlush();
  672. }
  673. /*void experiment0() {
  674. doDisAsm(0x00);
  675. doDisAsm(0x05);
  676. doDisAsm(0x15);
  677. doDisAsm(0x25);
  678. doDisAsm(0x30);
  679. doDisAsm(0x31);
  680. //doDisAsm(0x31);
  681. doDisAsm(0x32);
  682. doDisAsm(0x33);
  683. doDisAsm(0x34);
  684. //doDisAsm(0x35);
  685. doDisAsm(0x35);
  686. doDisAsm(0x36);
  687. doDisAsm(0x37);
  688. //doDisAsm(0x38);
  689. doDisAsm(0x38);
  690. doDisAsm(0x39);
  691. doDisAsm(0x3a);
  692. doDisAsm(0x3b);
  693. doDisAsm(0x3c);
  694. doDisAsm(0x3d);
  695. doDisAsm(0x3e);
  696. doDisAsm(0x3f);
  697. doDisAsm(0x45);
  698. doDisAsm(0x55);
  699. //doDisAsm(0x60);
  700. doDisAsm(0x60);
  701. doDisAsm(0x61);
  702. doDisAsm(0x68);
  703. doDisAsm(0x69);
  704. doDisAsm(0x6d);
  705. doDisAsm(0x6d);
  706. //doDisAsm(0x70);
  707. doDisAsm(0x3f);
  708. doDisAsm(0x38);
  709. doDisAsm(0x3f);
  710. doDisAsm(0x3f);
  711. doDisAsm(0x60);//
  712. doDisAsm(0x61);
  713. doDisAsm(0x68);
  714. doDisAsm(0x69);
  715. doDisAsm(0x6d);
  716. doDisAsm(0x6d);
  717. doDisAsm(0x60);
  718. doDisAsm(0x60);//------------
  719. doDisAsm(0x6d);
  720. doDisAsm(0x6d);
  721. doDisAsm(0x60);
  722. doDisAsm(0x60);//==========2==
  723. doDisAsm(0x30);
  724. doDisAsm(0x70);//==3==
  725. doDisAsm(0x71);
  726. doDisAsm(0x72);
  727. doDisAsm(0x73);
  728. doDisAsm(0x74);
  729. doDisAsm(0x75);
  730. doDisAsm(0x76);
  731. doDisAsm(0x77);
  732. doDisAsm(0x78);
  733. doDisAsm(0x79);
  734. doDisAsm(0x7a);
  735. doDisAsm(0x7b);
  736. doDisAsm(0x7c);
  737. doDisAsm(0x7d);
  738. doDisAsm(0x7e);
  739. doDisAsm(0x7f);
  740. doDisAsm(0xc0);
  741. doDisAsm(0xc1);
  742. doDisAsm(0xc2);
  743. doDisAsm(0xc3);
  744. doDisAsm(0xc4);
  745. doDisAsm(0xc5);
  746. doDisAsm(0xc6);
  747. doDisAsm(0xc7);
  748. doDisAsm(0xc8);
  749. doDisAsm(0xc9);
  750. doDisAsm(0xca);
  751. doDisAsm(0xcb);
  752. doDisAsm(0xcc);
  753. doDisAsm(0xcd);
  754. doDisAsm(0xce);
  755. doDisAsm(0xcf);
  756. doDisAsm(0xf0);
  757. doDisAsm(0xf1);
  758. doDisAsm(0xf2);
  759. doDisAsm(0xf3);
  760. doDisAsm(0xf4);
  761. doDisAsm(0xf5);
  762. doDisAsm(0xf6);
  763. doDisAsm(0xf7);
  764. doDisAsm(0xf8);
  765. doDisAsm(0xf9);
  766. doDisAsm(0xfa);
  767. doDisAsm(0xfb);
  768. doDisAsm(0xfc);
  769. doDisAsm(0xfd);
  770. doDisAsm(0xfe);
  771. doDisAsm(0xff);
  772.  
  773.  
  774.  
  775.  
  776.  
  777. //doDisAsm(0x71) ;
  778. /*doDisAsm(0x72);
  779. doDisAsm(0x73);
  780. doDisAsm(0x74);
  781. doDisAsm(0x76);
  782. doDisAsm(0x77);
  783. doDisAsm(0x85);
  784. doDisAsm(0x95);
  785. doDisAsm(0xa5);
  786. doDisAsm(0xb5);
  787. doDisAsm(0xc5);
  788. doDisAsm(0xd5);
  789. doDisAsm(0xe5);
  790. doDisAsm(0xf5);
  791. }*/
  792. void doHiNib3(byte secondByte) {
  793. //sprintf(data,"Doing it in subroutine..,,,,Tricky Hi nib 3. Tricky branches");
  794. //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
  795. //instructionBytes=2;
  796. switch(secondByte) {
  797. case 0:
  798. sprintf(data,"br %02x",nextByte); break;
  799.  
  800. case 1:
  801. sprintf(data,"bq %0x",nextByte); break; //!!todo: fix %x to %0x
  802. case 2:
  803. sprintf(data,"bz %x",nextByte); break;
  804. case 3:
  805. sprintf(data,"bdf %x",nextByte); break;
  806. case 4:
  807. sprintf(data,"b1 %x",nextByte); break;
  808. case 5:
  809. sprintf(data,"b2 %x",nextByte); break;
  810. case 6:
  811. sprintf(data,"b3 %x",nextByte); break;
  812. case 7:
  813. sprintf(data,"b4 %x",nextByte); break;
  814. case 8:
  815. sprintf(data,"skp %x",nextByte); break;
  816. case 9:
  817. sprintf(data,"bnq %x",nextByte); break;
  818. case 0xa:
  819. sprintf(data,"bnz %x",nextByte); break;
  820. case 0xb:
  821. sprintf(data,"bnf %x",nextByte); break;
  822. case 0xc:
  823. sprintf(data,"bn1 %x",nextByte); break;
  824. case 0xd:
  825. sprintf(data,"bn2 %x",nextByte); break;
  826. case 0xe:
  827. sprintf(data,"bn3 %x",nextByte); break;
  828. case 0xf:
  829. sprintf(data,"bn4 %x",nextByte); break;
  830. default:
  831. sprintf(data,"--prob-- 0x3 %x",secondByte); break;
  832. }
  833. }
  834. void doHiNib6(byte secondByte) {
  835. //sprintf(data,"Doing it in subroutine..,,,,Tricky Hi nib 7");
  836. if (secondByte==0) sprintf(data,"irx %s",blankStr);
  837. else{
  838. if((secondByte<=7) && (secondByte>0)) sprintf(data,"out %x",secondByte);
  839. else sprintf(data,"inp %x",(secondByte-8));
  840. }
  841. //NB can't have 68
  842. }
  843. void doHiNib7(byte secondByte) {
  844. //sprintf(data,"7xxx");
  845. //Serial.print("hn7");
  846. if (secondByte==1)sprintf(data,"dis %s",blankStr);
  847. else sprintf(data,"Not 1 %s",blankStr);
  848. //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
  849. /*switch(secondByte) {
  850. case 0:
  851. sprintf(data,"br %x",nextByte); break;
  852. //sprintf(data,"ret %s",blankStr); break;
  853. case 1:
  854. sprintf(data,"dis %s",blankStr); break;
  855. case 2:
  856. sprintf(data,"ldxa " ); break;
  857. case 3:
  858. sprintf(data,"stxd " ); break;
  859. case 4:
  860. sprintf(data,"adc " ); break;
  861. case 5:
  862. sprintf(data,"sdb " ); break;
  863. case 6:
  864. sprintf(data,"shrc " ); break;
  865. case 7:
  866. sprintf(data,"smb " ); break;
  867. case 8:
  868. sprintf(data,"sav " ); break;
  869. case 9:
  870. sprintf(data,"mark " ); break;
  871. case 0xa:
  872. sprintf(data,"seq " ); break;
  873. case 0xb:
  874. sprintf(data,"req " ); break;
  875. case 0xc:
  876. sprintf(data,"addi %x",nextByte); break;
  877. case 0xd:
  878. sprintf(data,"sdbi %x",nextByte); break;
  879. case 0xe:
  880. sprintf(data,"shlc"); break;
  881. case 0xf:
  882. sprintf(data,"smbi %x",nextByte); break;
  883. default:
  884. sprintf(data,"--prob-- 0x7 %x",secondByte); break;
  885. }
  886. */
  887. }/*
  888. void doHiNibc() {
  889. sprintf(data,"Doing it in subroutine..,,,,hi nib c; branches and skips");
  890. } */
  891. void doHiNibf() {
  892. sprintf(data,"Doing it in subroutine..,,,,hi nib f;arith logic etc");
  893. }
  894. void showData() {
  895. for (int i=0;i<10;i++) {
  896. Serial.print(data[i]);
  897. }
  898. } /*
  899. void experiment1(void) {
  900. doDisAsm(0x00);
  901. doDisAsm(0x05);
  902. doDisAsm(0x15);
  903. doDisAsm(0x25);
  904. doDisAsm(0x30);
  905. doDisAsm(0x00);
  906. doDisAsm(0x05);
  907. doDisAsm(0x15);
  908. doDisAsm(0x25);
  909. doDisAsm(0x30);
  910. doDisAsm(0x00);
  911. doDisAsm(0x05);
  912. doDisAsm(0x15);
  913. doDisAsm(0x25);
  914. doDisAsm(0x30);
  915. doDisAsm(0x00);
  916. doDisAsm(0x05);
  917. doDisAsm(0x15);
  918. doDisAsm(0x25);
  919. doDisAsm(0x30);
  920. doDisAsm(0x00);
  921. doDisAsm(0x05);
  922. doDisAsm(0x15);
  923. doDisAsm(0x25);
  924. doDisAsm(0x30);
  925. doDisAsm(0x00);
  926. doDisAsm(0x05);
  927. doDisAsm(0x15);
  928. doDisAsm(0x25);
  929. doDisAsm(0x30);
  930. doDisAsm(0x00);
  931. doDisAsm(0x05);
  932. doDisAsm(0x15);
  933. doDisAsm(0x25);
  934. doDisAsm(0x30);
  935. doDisAsm(0x00);
  936. doDisAsm(0x05);
  937. doDisAsm(0x15);
  938. doDisAsm(0x25);
  939. doDisAsm(0x30);
  940. doDisAsm(0x00);
  941. doDisAsm(0x05);
  942. doDisAsm(0x15);
  943. doDisAsm(0x25);
  944. doDisAsm(0x30);
  945. doDisAsm(0x00);
  946. doDisAsm(0x05);
  947. doDisAsm(0x15);
  948. doDisAsm(0x25);
  949. doDisAsm(0x30);
  950. doDisAsm(0x00);
  951. doDisAsm(0x05);
  952. doDisAsm(0x15);
  953. doDisAsm(0x25);
  954. doDisAsm(0x30);
  955. doDisAsm(0x00);
  956. doDisAsm(0x05);
  957. doDisAsm(0x15);
  958. doDisAsm(0x25);
  959. doDisAsm(0x30);
  960. doDisAsm(0x00);
  961. doDisAsm(0x05);
  962. doDisAsm(0x15);
  963. doDisAsm(0x25);
  964. doDisAsm(0x30);
  965. doDisAsm(0x00);
  966. doDisAsm(0x05);
  967. doDisAsm(0x15);
  968. doDisAsm(0x25);
  969. doDisAsm(0x30);
  970. doDisAsm(0x00);
  971. doDisAsm(0x05);
  972. doDisAsm(0x15);
  973. doDisAsm(0x25);
  974. doDisAsm(0x30);
  975. doDisAsm(0x00);
  976. doDisAsm(0x05);
  977. doDisAsm(0x15);
  978. doDisAsm(0x25);
  979. doDisAsm(0x30);
  980. } */
  981. void doHiNib7A(byte secondByte) {
  982. //sprintf(data,"7xxx");
  983. //Serial.print("hn7");
  984. //if (secondByte==1)sprintf(data,"dis %s",blankStr);
  985. //else sprintf(data,"Not 1 %s",blankStr);
  986. byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
  987. switch(secondByte) {
  988. case 0:
  989. //sprintf(data,"br %x",nextByte); break;
  990. sprintf(data,"ret %s",blankStr); break;
  991. case 1:
  992. sprintf(data,"dis %s",blankStr); break;
  993.  
  994. case 2:
  995. sprintf(data,"ldxa %s",blankStr ); break;
  996. case 3:
  997. sprintf(data,"stxd %s",blankStr ); break;
  998. case 4:
  999. sprintf(data,"adc %s",blankStr ); break;
  1000. case 5:
  1001. sprintf(data,"sdb %s",blankStr ); break;
  1002. case 6:
  1003. sprintf(data,"shrc %s",blankStr ); break;
  1004. /* case 7:
  1005. sprintf(data,"smb %s",blankStr ); break;
  1006. /* case 8:
  1007. sprintf(data,"sav " ); break;
  1008. case 9:
  1009. sprintf(data,"mark " ); break;
  1010. case 0xa:
  1011. sprintf(data,"seq " ); break;
  1012. case 0xb:
  1013. sprintf(data,"req " ); break;
  1014. case 0xc:
  1015. sprintf(data,"addi %x",nextByte); break;
  1016. case 0xd:
  1017. sprintf(data,"sdbi %x",nextByte); break;
  1018. case 0xe:
  1019. sprintf(data,"shlc"); break;
  1020. case 0xf:
  1021. sprintf(data,"smbi %x",nextByte); break;*/
  1022. default:
  1023. sprintf(data,"--prob0x07 %x",secondByte); break;
  1024. }
  1025. }
  1026. void doHiNib7B(byte secondByte1) {
  1027. // cpould not get the switch method to work for this one.
  1028. //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
  1029.  
  1030. if (secondByte1==0) sprintf(data,"ret %s",blankStr);
  1031. if (secondByte1==1) sprintf(data,"dis %s",blankStr);
  1032. if (secondByte1==2) sprintf(data,"ldxa %s",blankStr);
  1033. if (secondByte1==3) sprintf(data,"stxd %s",blankStr);
  1034. if (secondByte1==4) sprintf(data,"adc %s",blankStr);
  1035. if (secondByte1==5) sprintf(data,"sdb %s",blankStr);
  1036. if (secondByte1==6) sprintf(data,"shrc %s",blankStr);
  1037. if (secondByte1==7) sprintf(data,"smb %s",blankStr);
  1038. if (secondByte1==8) sprintf(data,"sav %s",blankStr);
  1039. if (secondByte1==9) sprintf(data,"mark %s",blankStr);
  1040. if (secondByte1==0x0a) sprintf(data,"req %s",blankStr);
  1041. if (secondByte1==0x0b) sprintf(data,"seq %s",blankStr);
  1042. if (secondByte1==0x0c) {
  1043. sprintf(data,"adci %0x",nextByte);instructionBytes=2; }
  1044. if (secondByte1==0x0d) {
  1045. sprintf(data,"sdbi %0x",nextByte);instructionBytes=2; }
  1046. if (secondByte1==0x0e) sprintf(data,"shlc %0x",nextByte);
  1047. if (secondByte1==0x0f) {
  1048. sprintf(data,"smbi %0x",nextByte);instructionBytes=2; }
  1049.  
  1050. } /*
  1051. void doHiNibcA(byte secondByte2) { //long branches etc
  1052. //sprintf(data,"Doing it in subroutine..,,,,Tricky Hi nib 3. Tricky branches");
  1053. //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
  1054. //byte thirdByte = vRAM[currentAdr+2];
  1055. switch(secondByte2) {
  1056. case 0:
  1057. sprintf(data,"lbr %x %x",nextByte,thirdByte); break;
  1058. // sprintf(data,"ret %s",blankStr); break; //!!
  1059. case 1:
  1060. sprintf(data,"bq %x%x",nextByte,thirdByte); break;
  1061. case 2:
  1062. sprintf(data,"bz %x",nextByte); break;
  1063. case 3:
  1064. sprintf(data,"bdf %x",nextByte); break;
  1065. case 4:
  1066. sprintf(data,"b1 %x",nextByte); break;
  1067. case 5:
  1068. sprintf(data,"b2 %x",nextByte); break;
  1069. case 6:
  1070. sprintf(data,"b3 %x",nextByte); break;
  1071. case 7:
  1072. sprintf(data,"b4 %x",nextByte); break;
  1073. case 8:
  1074. sprintf(data,"skp %x",nextByte); break;
  1075. case 9:
  1076. sprintf(data,"bnq %x",nextByte); break;
  1077. case 0xa:
  1078. sprintf(data,"bnz %x",nextByte); break;
  1079. case 0xb:
  1080. sprintf(data,"bnf %x",nextByte); break;
  1081. case 0xc:
  1082. sprintf(data,"bn1 %x",nextByte); break;
  1083. case 0xd:
  1084. sprintf(data,"bn2 %x",nextByte); break;
  1085. case 0xe:
  1086. sprintf(data,"bn3 %x",nextByte); break;
  1087. case 0xf:
  1088. sprintf(data,"bn4 %x",nextByte); break;
  1089. default:
  1090. sprintf(data,"--prob-- 0x3 %x",secondByte2); break;
  1091. }
  1092. } */
  1093. void doHiNibcB(byte secondByte2) { //long branches etc
  1094. //sprintf(data,"Doing it in subroutine..,,,,Tricky Hi nib 3. Tricky branches");
  1095. //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
  1096. //byte thirdByte = vRAM[currentAdr+2];
  1097. if (secondByte2==0) sprintf(data,"lbr %0x%0x",nextByte,thirdByte);
  1098. if (secondByte2==1) sprintf(data,"lbq %0x%0x",nextByte,thirdByte);
  1099. if (secondByte2==2) sprintf(data,"lbz %0x %0x",nextByte,thirdByte);
  1100. if (secondByte2==3) sprintf(data,"lbdf %0x %0x",nextByte,thirdByte);
  1101. if (secondByte2==4){
  1102. sprintf(data,"nop %s",blankStr); instructionBytes=1; }
  1103. if (secondByte2==5) sprintf(data,"lsnq %0x%0x",nextByte,thirdByte);
  1104. if (secondByte2==6) sprintf(data,"lsnz %0x %0x",nextByte,thirdByte);
  1105. if (secondByte2==7) sprintf(data,"lsnf %0x %0x",nextByte,thirdByte);
  1106. if (secondByte2==8) sprintf(data,"lskp %0x %0x",nextByte,thirdByte);
  1107. if (secondByte2==9) sprintf(data,"lbnq %0x %0x",nextByte,thirdByte);
  1108. if (secondByte2==0xa) sprintf(data,"lbnz %0x %0x",nextByte,thirdByte);
  1109. if (secondByte2==0xb) sprintf(data,"lbnf %0x %0x",nextByte,thirdByte);
  1110. if (secondByte2==0xc) sprintf(data,"lsie %0x %0x",nextByte,thirdByte);
  1111. if (secondByte2==0xd) sprintf(data,"lsq %0x %0x",nextByte,thirdByte);
  1112. if (secondByte2==0xe) sprintf(data,"lsz %0x %0x",nextByte,thirdByte);
  1113. if (secondByte2==0xf) sprintf(data,"lsdf %0x %0x",nextByte,thirdByte);
  1114.  
  1115.  
  1116. //else sprintf(data,"not yet %s",blankStr);
  1117. /*
  1118. switch(secondByte2) {
  1119. case 0:
  1120. sprintf(data,"lbr %x %x",nextByte,thirdByte); break;
  1121. // sprintf(data,"ret %s",blankStr); break; //!!
  1122. case 1:
  1123. sprintf(data,"bq %x%x",nextByte,thirdByte); break;
  1124. case 2:
  1125. sprintf(data,"bz %x",nextByte); break;
  1126. case 3:
  1127. sprintf(data,"bdf %x",nextByte); break;
  1128. case 4:
  1129. sprintf(data,"b1 %x",nextByte); break;
  1130. case 5:
  1131. sprintf(data,"b2 %x",nextByte); break;
  1132. case 6:
  1133. sprintf(data,"b3 %x",nextByte); break;
  1134. case 7:
  1135. sprintf(data,"b4 %x",nextByte); break;
  1136. case 8:
  1137. sprintf(data,"skp %x",nextByte); break;
  1138. case 9:
  1139. sprintf(data,"bnq %x",nextByte); break;
  1140. case 0xa:
  1141. sprintf(data,"bnz %x",nextByte); break;
  1142. case 0xb:
  1143. sprintf(data,"bnf %x",nextByte); break;
  1144. case 0xc:
  1145. sprintf(data,"bn1 %x",nextByte); break;
  1146. case 0xd:
  1147. sprintf(data,"bn2 %x",nextByte); break;
  1148. case 0xe:
  1149. sprintf(data,"bn3 %x",nextByte); break;
  1150. case 0xf:
  1151. sprintf(data,"bn4 %x",nextByte); break;
  1152. default:
  1153. sprintf(data,"--prob-- 0x3 %x",secondByte2); break;
  1154. }*/
  1155. }
  1156. void doHiNibfA(byte secondByte1) {
  1157. // could not get the switch method to work for this one.
  1158. //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
  1159. if (secondByte1>=8) instructionBytes=2; //otherwise stays at 1
  1160.  
  1161. if (secondByte1==0) sprintf(data,"ldx %s",blankStr);
  1162. if (secondByte1==1) sprintf(data,"or %s",blankStr);
  1163. if (secondByte1==2) sprintf(data,"and %s",blankStr);
  1164. if (secondByte1==3) sprintf(data,"xor %s",blankStr);
  1165. if (secondByte1==4) sprintf(data,"add %s",blankStr);
  1166. if (secondByte1==5) sprintf(data,"sd %s",blankStr);
  1167. if (secondByte1==6) sprintf(data,"shr %s",blankStr);
  1168. if (secondByte1==7) sprintf(data,"sm %s",blankStr);
  1169. //if (secondByte>=8) instructionBytes=2;
  1170. if (secondByte1==8) sprintf(data,"ldi %02x",nextByte);
  1171. if (secondByte1==9) sprintf(data,"ori %02x",nextByte);
  1172. if (secondByte1==0x0a) sprintf(data,"ani %02x",nextByte);
  1173. if (secondByte1==0x0b) sprintf(data,"xri %02x",nextByte);
  1174. if (secondByte1==0x0c) sprintf(data,"adi %02x",nextByte);
  1175. if (secondByte1==0x0d) sprintf(data,"sdi %02x",nextByte);
  1176. if (secondByte1==0x0e) { sprintf(data,"shl %s",blankStr); instructionBytes=1; }
  1177. if (secondByte1==0x0f) sprintf(data,"smi %02x",nextByte);
  1178.  
  1179. }
  1180. void printTPBResults3(void) {
  1181. Serial.print("[");
  1182. if (fetchOrExecuteCh=='F'){
  1183. sprintf(data,"Adr0 %02x%02x : ",adrByteHi,adrByte);
  1184. Serial.print(data);
  1185. //doDisAsm(opCode); //old
  1186. doDisLine(opCode); //BIG connection with new progmem code
  1187. if (printLevel==1) {
  1188. Serial.println("]"); //if level1 finish here with CR.
  1189. }
  1190. if(printLevel>=2) {
  1191. sprintf(data," --%2x ",opCode);
  1192. if (instructionBytes ==1) Serial.println(data);
  1193. if (instructionBytes==2) {
  1194. Serial.print(data);
  1195. //Serial.println(vRAM[currentAdr+1],HEX); //nextByte = vRAM[currentAdr+1];
  1196. Serial.println(nextByte,HEX);
  1197. }
  1198. if (instructionBytes==3) {
  1199. Serial.print(data);
  1200. //Serial.print(vRAM[currentAdr+1],HEX);
  1201. Serial.println(nextByte,HEX);
  1202. //Serial.println(vRAM[currentAdr+2],HEX); //thirdByte = vRAM[currentAdr+2];
  1203. Serial.println(thirdByte,HEX);
  1204. }
  1205. }
  1206. }
  1207. else { // ie it's not 'F', it's an execute line:
  1208. if(printLevel==3) {
  1209. sprintf(data," Adr: %x%x : %02x Ck=%lu, Cy=%lu, In=%lu ; ( %c %c ) M%lu Cr%lu",adrByteHi,adrByte,opCode,clkCtr,TPBCtr,fetchCtr, fetchOrExecuteCh,readOrWriteCh,t1,clockRate);
  1210. //sprintf(data,"Adr: %x%x : %02x %u, %u ,%u ; %c %c",adrByteHi,adrByte,opCode,TPBCtr,clkCtr,fetchCtr, fetchOrExecuteCh,readOrWriteCh);
  1211. //sprintf(data," Adr: %x%x : %02x %u, %u %c %c",adrByteHi,adrByte,opCode,TPBCtr,clkCtr, fetchOrExecuteCh,readOrWriteCh);
  1212. Serial.println(data);
  1213. }
  1214. }
  1215. }
  1216. void millisExperiment0(void){
  1217. unsigned long time;
  1218.  
  1219. for (int i=0;i<10;i++) {
  1220. //Serial.println(millis());
  1221.  
  1222.  
  1223. Serial.print("Time: ");
  1224. time = millis();
  1225.  
  1226. Serial.println(time); //prints time since program started
  1227. delay(1000); // wait a second so as not to send massive amounts of data
  1228. }
  1229. //Notes and Warnings
  1230. }
  1231. void doOUT(void) { //come here when OUT n puts MR(X) on bus. NB nBUS >0 and opCode = mem byte MR(X)
  1232. if (nBus==1) {
  1233. if (opCode==0x0f) { digitalWrite(intPin,HIGH);} //turn interrupts off
  1234.  
  1235. }
  1236. }
  1237. void doInpStuffIfNecess(void) { // when MWR* goes low, it could be INP with nBus != 0
  1238. nBus = PINK & 0b0000111;
  1239. if (nBus !=0) {
  1240. byte jamByte = 0x40+nBus;
  1241. Serial.print("@@" );Serial.print(jamByte,HEX);
  1242. DDRC=0xff;
  1243. PORTC=jamByte; //but PORTC is currently input?
  1244. DDRC=0x00;
  1245. }
  1246. }
  1247.  
  1248. void hiMemExp(void) {
  1249. byte b;
  1250. // b= pgm_read_byte_near(0x4001);
  1251. b= pgm_read_byte(0x3001);
  1252. Serial.print("!!! ~1"); Serial.println(b,HEX);
  1253. }
  1254. //------------------------------------------------------------------------------
  1255. // New progmem7 code goes below here--------------------------------------------
  1256.  
  1257. void doDisLine( byte opC) { //go into big progrmem string and emrge with j pointing opening '[' of menonic substring
  1258. opCodePreProcess(opC);
  1259. int k=0;
  1260. foundOpCode= false;
  1261. while ((k < strlen_P(flashHiNib3)) && (foundOpCode==false)){
  1262. ch1 = pgm_read_byte_near(flashHiNib3+k);
  1263. if (ch1=='[') {
  1264. if( (pgm_read_byte_near(flashHiNib3+k+1)==char3) && (pgm_read_byte_near(flashHiNib3+k+2) ==char4) ){
  1265. foundOpCode=true;
  1266. data0[0] = pgm_read_byte_near(flashHiNib3+k+3); //first char of mnemonic
  1267. data0[1] = pgm_read_byte_near(flashHiNib3+k+4);
  1268. data0[2] = pgm_read_byte_near(flashHiNib3+k+5);
  1269. data0[3] = pgm_read_byte_near(flashHiNib3+k+6);
  1270. data0[4] = pgm_read_byte_near(flashHiNib3+k+7);
  1271. data0[5] = pgm_read_byte_near(flashHiNib3+k+8);
  1272. if (data0[2] == '.') closingBracket = data0[3]; //two char menonic like br
  1273. if (data0[3] == '.') closingBracket = data0[4]; //3 char mnem like lda.
  1274. if (data0[4] == '.') closingBracket = data0[5];
  1275. }
  1276. }
  1277. k++;
  1278. }
  1279. if (foundOpCode==false) {
  1280. Serial.print(F("Don't understandop code "));
  1281. Serial.println(opC,HEX);
  1282. }
  1283. else {
  1284. fixData0(); // now the nemonic ends with trailing \0
  1285. Serial.print (data0); //print the mnemonic..
  1286. doClosingBrackets(); //..and any other addresses etc
  1287. }
  1288. }
  1289. //
  1290. void opCodePreProcess(byte opCo0) {
  1291. MSNib = opCo0/16;
  1292. LSNib = opCo0%16;
  1293. char3 = binToAsc(MSNib);
  1294. char4= binToAsc(LSNib);
  1295. if ((char3 =='8')||(char3 =='9') || (char3 =='A')|| (char3 =='B')) { oldChar4 = char4; char4='0'; } //glo,ghi,plo,phi resp
  1296. if (char3=='0') { if (LSNib>0) {oldChar4 = char4; char4='1';}} //ldn but n!=0
  1297. if ((char3=='1') || (char3=='2')) {oldChar4 = char4; char4='0';} //inc, dec
  1298. if ((char3=='4') || (char3=='5')) {oldChar4 = char4; char4='0';} //lda,str
  1299. if (char3=='6') {
  1300. if ((LSNib>0) && (LSNib<=7)){oldChar4 = char4; char4='1';} //out n but n!=0 and n<=7
  1301. if (LSNib>8) {oldChar4 = char4; char4='9';LSNib=LSNib-8;} //inp n but n>8. NB 68 seems to be invalid opCode
  1302. }
  1303. if ((char3=='D') || (char3=='E')) {oldChar4 = char4; char4='0';} //sep,sex
  1304. }
  1305. byte binToAsc(byte b) { //eg change 0x03 to 0x33 = '3'
  1306. byte temp;
  1307. temp = b + 0x30;
  1308. if (temp > 0x39) temp = temp +7; // adjust for hex. NB outputs capital A,B etc
  1309. return temp;
  1310. }
  1311. //
  1312. void fixData0(void) { //replace dot with space and \0 so it prints OK
  1313. for (int i = 0;i<10;i++) {
  1314. if (data0[i] == '.') {
  1315. data0[i] = ' ';
  1316. data0[i+1] ='\0';
  1317. }
  1318. }
  1319. }
  1320. void doClosingBrackets(void) { //going to change printlns to prints below. To work in with old software display..
  1321. if(closingBracket==']') { }; // Serial.print("."); //nothig after mnemonic eg nop
  1322. if(closingBracket=='L') Serial.print(LSNib,HEX); //eg phi 3
  1323. if(closingBracket=='N') Serial.print(nextByte,HEX); //eg br 34.
  1324. if(closingBracket=='T') {
  1325. Serial.print(nextByte,HEX);
  1326. Serial.print(thirdByte,HEX);
  1327. }
  1328. }
  1329.  
  1330. void printTPBResults4(void) {
  1331. Serial.print("[");
  1332. if (fetchOrExecuteCh=='F'){
  1333. sprintf(data,"Adr) %02x%02x : ",adrByteHi,adrByte);
  1334. Serial.print(data);
  1335. //doDisAsm(opCode); //old .
  1336. doDisLine(opCode); //BIG connection with new progmem code
  1337. if (printLevel==1) {
  1338. Serial.println("]"); //if level1 finish here with CR.
  1339. }
  1340. if(printLevel>=2) {
  1341. sprintf(data," --%2x ",opCode);
  1342. Serial.print(data);
  1343. if(closingBracket==']') {Serial.println(); }
  1344. if(closingBracket=='L') {Serial.println();} //Serial.println(LSNib,HEX);
  1345. if(closingBracket=='N') Serial.println(nextByte,HEX); //eg br 34.
  1346. if(closingBracket=='T') {
  1347. //Serial.print(nextByte,HEX);
  1348. //Serial.println(thirdByte,HEX);
  1349. //Serial.print(closingBracket);
  1350. sprintf(data," %02x%02x ",nextByte,thirdByte);
  1351. Serial.print(data);
  1352.  
  1353. }
  1354. //if (instructionBytes ==1) Serial.println(data);
  1355. if (instructionBytes==2) {
  1356. //Serial.print(data);
  1357. //Serial.println(vRAM[currentAdr+1],HEX); //nextByte = vRAM[currentAdr+1];
  1358. //Serial.println(nextByte,HEX);
  1359. }
  1360. if (instructionBytes==3) {
  1361. //Serial.print(data);
  1362. //Serial.print(vRAM[currentAdr+1],HEX);
  1363. //Serial.println(nextByte,HEX);
  1364. //Serial.println(vRAM[currentAdr+2],HEX); //thirdByte = vRAM[currentAdr+2];
  1365. //Serial.println(thirdByte,HEX);
  1366. }
  1367. }
  1368. }
  1369. else { // ie it's not 'F', it's an execute line:
  1370. if(printLevel==3) { //*************pit back
  1371. sprintf(data," Adr: %x%x : %02x Ck=%lu, Cy=%lu, In=%lu ; ( %c %c ) M%lu Cr%lu",adrByteHi,adrByte,opCode,clkCtr,TPBCtr,fetchCtr, fetchOrExecuteCh,readOrWriteCh,t1,clockRate);
  1372. //sprintf(data,"Adr: %x%x : %02x %u, %u ,%u ; %c %c",adrByteHi,adrByte,opCode,TPBCtr,clkCtr,fetchCtr, fetchOrExecuteCh,readOrWriteCh);
  1373. //sprintf(data," Adr: %x%x : %02x %u, %u %c %c",adrByteHi,adrByte,opCode,TPBCtr,clkCtr, fetchOrExecuteCh,readOrWriteCh);
  1374. Serial.println(data);
  1375. }
  1376. }
  1377. }
  1378. /*
  1379. void doReport() { //show all useful variables.
  1380. sprintf(data, "delay = %02x, op Stop code = %02x, breakpoint = %04x, current address = %04x, op code = %02x", DELAY,stopCode,breakPointAdr,currentAdr,opCode);
  1381. Serial.println(data);
  1382. sprintf(data, "TPBCtr = %lu, clkCtr= %lu, readOrWriteCh = %c, fetchOrExecuteCh = %c, doOpStops=%d ", TPBCtr,clkCtr,readOrWriteCh,fetchOrExecuteCh,doOpStops);
  1383. Serial.println(data);
  1384. sprintf(data, "TPADone = %d, TPBDone= %d, singleStepping = %d, stepMe = %d, showCommands = %d, instuction fetches=%lu ", TPADone,TPBDone,singleStepping,stepMe,showCommands,fetchCtr);
  1385. Serial.println(data);
  1386. sprintf(data,"Print Level %d",printLevel);
  1387. Serial.print(data);
  1388. }
  1389. */
  1390. void doReport2() { //old doReport takes up too much RAM
  1391. Serial.println (F("delay,op-Stop code, breakpoint"));
  1392. Serial.println(DELAY);
  1393. Serial.println(stopCode);
  1394. Serial.println(breakPointAdr);
  1395. }
Add Comment
Please, Sign In to add comment