Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**e91 1
- Mon May 25 11:41:03 NZST 2020. Got RAM down to 1795bytes with report rewritten sparsely.Now have to practice SPI..
- But first lower vRAM[] buf from 1k to 256 bytes. Adjust other routines eg getfile to fit.
- Sun May 24 10:41:34 NZST 2020 CDP1802f01.ino works OK. Now going to tidy commands. Reduce RAM req.
- Fri May 22 10:07:06 NZST 2020. CDP1802f.ino. Going to integrate progmem7.ono into it so get GROGMEM-based disassembler
- 1:03 PM 5/05/2020. Want to pull bytes down from above $4000. Put in there by combinedFil0.bin. Experiment.
- Thu Apr 30 11:43:51 NZST 2020. Last code fiddling before big tidy up and memory reduction.
- Looking at kludge to simulate INP
- e9. Tidy up OUT and start on INP.
- Tue Apr 28 13:10:47 NZST 2020. Have been wrestling with OUT 1 but think it's OK now. Needs tidying.
- 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..
- ..concept of virtual peripherals. eg when an interrupt occurs it can be tuned off with an OUT 1 and send $0f
- Fri Apr 24 13:13:07 NZST 2020. Now want to time instructions per second using millis, run and stop (single stepping = stop)
- Fri Apr 24 11:12:12 NZST 2020. Still tidying up printLevel3.Done
- 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
- ..NB space: "Global variables use 2902 bytes (35%) of dynamic memory, leaving 5290 bytes for local variables. Maximum is 8192 bytes."
- ..Too much RAM for nano. Might have to use progmem etc.
- Tue Apr 21 20:12:55 NZST 2020. Disassember going. Some problems with many switch statements so changed to if,if,if,.
- Needs to be tidied up and slimmed down.Starting now in ...e4.
- Sun Apr 19 11:02:16 NZST 2020. Extending disassem. but ram memory too high for nano.
- Sat Apr 18 12:50:37 NZST 2020. Cosmacuino version 0.2 Now starting on disassembler.
- 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.
- ..all below has been on mega.
- Fri Apr 17 12:43:54 NZST 2020.C:\Users\Dell\Documents\Arduino\PB_SketchApril12\CDP1802e0\CDP1802e0.ino. Trying report of all useful vars.
- Fri Apr 17 11:41:53 NZST 2020. Going to look at DElay changes and report.
- Thu Apr 16 14:26:37 NZST 2020. Sorted, I think, break points, opcode stopping with seial commands. Next:speed changes.
- Thu Apr 16 12:25:37 NZST 2020. Working well. Now get break points going in real time...
- Tue Apr 14 19:59:13 NZST 202. All code tidied up. Old routines deleted. Next: single stepping.
- Tue Apr 14 15:35:00 NZST 2020. Going OK. Just deleting a whole lot of rubbish and carefully retesting.
- Tue Apr 14 13:02:36 NZST 2020. Tidy up time, and simplify main loop into easy subroutines.
- Mon Apr 13 14:50:01 NZST 2020. version 1802d2.ino now working well. Norway routines have been replaced.
- ...by bulletproof ones. Want to make better output each line of code.
- ..To form like 0123: F8 F,R,cycles, clocks
- Mon Apr 13 13:24:55 NZST 2020. Getting rid of Norwat commands and integrating checkForCommands()
- * Sun Apr 12 15:40:21 NZST 2020. Got better serial command routines from bulletProofSerialI. Integrate them.
- * Mon Mar 30 15:05:50 NZDT 2020 ..c8. Got long branches, lbr, into page three going OK.
- * .. also got sep to work in same way. Jumped in and out of code by changing prog ctr with sep.
- * .. next. Try that SCART method of using subroutines on 1802
- * Sun Mar 29 14:26:46 NZDT 2020 ..c7. Have big 1024 vRam[] buffer but can't use it yet.
- * ..Need TPA time to record Hi adr byte.
- * Sorted vRAM[] up to 1024 bytes and got new comand dumpVariableVer(int) to give 256 0r 1024 dumps.
- * Sun Mar 29 13:49:17 NZDT 2020 ..c6. Now want to exgtend vRAM[] frolm 256 to 1024 bytes. Fake memory.
- * Sat Mar 28 16:23:44 NZDT 2020. This is ...c5. Now going to try fastest baudrate 115200 and fastest DELAY =1.
- * All worked. Fast enough for time being. Next increase vRAM[] to 1024 bytes and check Hi address byte on
- * ..TPA.
- * Sat Mar 28 16:23:44 NZDT 2020 still...c4. Got baudrate up to 57600 and DELAY down to 2. Allworking.
- * Sat Mar 28 14:13:16 NZDT 2020 CDP1802c4. Going to try DELAY=4, and baudrate is 38.4K. Works OK but
- * ..is too fast in terminal so only print every 10th TPB going-high count. (clocks/8)
- * 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
- * Now going to try DELAY =8 and baud = 28.8K. Both worked.
- * Sat Mar 28 13:14:18 NZDT 2020 CDP1802c2. Need to speed up a bit. Reg dumping works but is slow.
- * so going to change DELAY from 50 to 32 then keep halving. Worked OK also shortened message to terminal.
- * Also increased serial speed to 14.4K. Working OK. Next continue speed of clock and baudrate.
- * 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.
- */
- #include <avr/pgmspace.h>
- //1802 talks to Arduino Mega
- #define clockPin 13
- #define clearPin 12
- #define waitPIn 11 //not used
- #define intPin 10
- #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 n0Pin A9 //needed?
- #define n1Pin A8
- #define n2Pin A10 //these are the n-bus items that are non-zero during I/O OUT and IN.
- #define TPBDivisor 1 //50 //1 // 100 //50 //10 //if ten, shows every tenth output line, otherwise too fast to see and act in terminal.
- //#define DELAY 50 //16 //1 // 2 //4 //8 //16 //32 //50
- byte DELAY=30; //default. Can be changes via terminal command.
- int BUFFERLENGTH = 256 ; //1024; //this is how big the vRAM[] array is. Going to be shorter than 1024.
- int val = 0;// int bufBytes;
- unsigned int adrByte=0;
- unsigned int adrByteHi =0;
- unsigned int currentAdr;
- unsigned long time =0;
- boolean writeStrobe = false; //should really get TBA to turn this off too; Just in case.
- const byte numChars = 32;
- char receivedChars[numChars];
- byte receivedBytes[numChars];
- byte nBus=0;
- byte ioAdrLow;
- byte ioByte;
- byte nextByte;
- byte thirdByte;
- char data[100] ;
- //char data[32] ;
- //char data[200];
- unsigned int breakPointAdr=0,opCode,stopCode;
- unsigned long fetchCtr=0;
- unsigned long t0,clkCtr=0,TPBCtr= 0, clockRate=0,t1=0; //used in millis timing.
- char fetchOrExecuteCh;
- char readOrWriteCh;
- char * blankStr ="";
- int printLevel=1; //how much detail do you want in serial output for disassembler
- char instructionBytes = 1; //some instructions have 1 eg c4 = nop, some have 3 eg lsk 12 34
- //byte opCode;
- boolean newData = false;
- //boolean showExecutes = true;
- boolean TPADone = false, TPBDone=true;
- boolean singleStepping = false, stepMe=false;
- boolean showCommands=true;
- boolean doOpStops = false; //breakpoint if opCode=stopCode;
- //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,0x6A,0x57, 0x30, 0x09,0x00};
- //byte vRAM[1024] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x7D,0x57,0xc4,0xc4, 0x30, 0x09,0x00};
- byte vRAM[256] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x7D,0x57,0xc4,0xc4, 0x30, 0x09,0x00};
- //byte vRAM[512] = {0x7b, 0x7a, 0x7b, 0xf8,0x00,0xb7,0xf8,0x98,0xa7,0xf8,0x7D,0x57,0xc4, 0x30, 0x09,0x00}; //memory short on nano
- //--------------------globals from progmem7.ino below-----------------------------
- 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"}; //};
- char ch1;
- char char3 = '7' ;
- char char4 ='F';
- char oldChar4;
- char data0[10] ;
- char closingBracket;
- //byte vRAM[6] = {0x7b, 0x7b, 0x7a, 0xCA,0x7b,0x68};
- //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};
- boolean foundOpCode;
- byte LSNib;
- byte MSNib;
- //byte nextByte = 0x11;
- //byte thirdByte = 0x22;
- void setup() {
- pinMode(clockPin, OUTPUT);
- pinMode(clearPin, OUTPUT);
- pinMode(intPin,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.
- DDRK=0x00; //PORTK takes nBus and other signals
- Serial.begin(9600); //(115200); //(57600); //38400); //(28800); //(19200); //(14400); //(9600); // // open the serial port at 9600 bps:
- serialFlush();
- delay(1000); //time to sort out Bray++
- Serial.flush();
- Serial.println("CDP1802e94.ino");
- delay(500);
- doReset();
- // dumpVariableVert(256);
- // doReport();
- //experiment0();
- //experiment1();
- //while(1) { };
- printLevel=1; //printlevel = 1 is default. Can be changed via terminal commands.
- //experiment1();
- //millisExperiment0();
- hiMemExp();
- }
- //--------------------------------------------------------------------------------------
- void loop() {
- checkForCommands(); //Still a bit clumsy with Serial lib.
- doClockCycle();
- }//*******************************************
- void doClockCycle() {
- digitalWrite(clockPin, HIGH); // turn the LED on (HIGH is the voltage level)
- if(digitalRead(TPApin) ==HIGH) {
- doTPAStuff();
- }
- if (digitalRead(writePin)==LOW){
- doWriteStuff();
- doInpStuffIfNecess();
- }
- delay(DELAY); // wait. DELAY is a variable, can be 0
- 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
- }
- //*************************************************
- void doTPBWork(void) {
- TPBCtr++;
- adrByte = PINA;
- nBus = PINK & 0b0000111; //just want first three bits for n0,1,2
- //if ((writeStrobe== true)&& (nBus==0)) {
- if (writeStrobe== true) {
- writeStrobe = false;
- vRAM[adrByte+adrByteHi*256]=PINC; //adrByteHi comes from read of PORTA (!PORTC) during TPA
- readOrWriteCh='W';
- }
- else {
- readOrWriteCh='R';
- }
- if(digitalRead(SC0pin)==LOW) {
- fetchOrExecuteCh='F';
- fetchCtr++;
- //print1TPBResults1();
- }
- else {
- fetchOrExecuteCh='E';
- }
- //if ((digitalRead(readPin)==LOW)&& (nBus==0) ){
- if ((digitalRead(readPin)==LOW)){
- DDRC = 0xff; //just for this version. Send nop when clockk goes 1 to 0, TPB =1, MRD=0
- currentAdr = adrByte+adrByteHi*256;
- if (currentAdr>BUFFERLENGTH) {
- PORTC = pgm_read_byte(currentAdr);
- opCode=pgm_read_byte(currentAdr);
- nextByte = pgm_read_byte(currentAdr+1);
- thirdByte = pgm_read_byte(currentAdr+2);
- }
- else {
- //PORTC = vRAM[adrByte+adrByteHi*256] ; // read byte from virtual
- //opCode=vRAM[adrByte+adrByteHi*256];
- PORTC=vRAM[currentAdr];
- opCode=vRAM[currentAdr];
- nextByte = vRAM[currentAdr+1];
- thirdByte = vRAM[currentAdr+2];
- }
- if (nBus!=0) { //in case of OUT n, the opcode is the byte taken from MR(X) and put on data bus
- //ioByte=vRAM[currentAdr];
- Serial.print("## ");Serial.println(opCode,HEX);
- doOUT();
- }
- }/*
- if ((digitalRead(readPin)==LOW)&& (nBus!=0) ){ //big slow issues around here.
- DDRC = 0xff;
- //PORTC=0xa3; //arbitrary
- ioAdrLow = PINA; //1802 puts adr of M(R(X)) on adr bus=PORTA
- // collects adrByteHi in last TPA.
- Serial.print("%% ");Serial.print(adrByteHi,HEX); Serial.println(ioAdrLow,HEX);
- Serial.print("$$ ") ;Serial.print(adrByteHi,HEX);Serial.println(adrByte,HEX);
- ioByte =vRAM[adrByte+adrByteHi*256];
- Serial.print("## ");Serial.println(ioByte,HEX);
- //currentAdr = adrByte+adrByteHi*256;
- PORTC = vRAM[adrByte+adrByteHi*256] ; //OUT 1 is really just READ R(X) with nBus action
- //Serial.print("^ ^");Serial.println(PINA+adrByteHi*256,HEX);
- //Serial.println("Got an OUT 2instruction ");
- //Serial.println(nBus);
- //digitalWrite(intPin,LOW); //test.
- }*/
- TPBDone=true;
- //print1TPBResults1();
- //printTPBResults2();
- if(printLevel!=0) {
- //printTPBResults3();
- printTPBResults4();
- }
- if((currentAdr==breakPointAdr) && (breakPointAdr>0)) {
- Serial.println("Breakpoint address .....");
- singleStepping=true;
- }
- if((doOpStops==true) && (opCode == stopCode)){
- Serial.println("Op code stop .....");
- singleStepping=true;
- }
- if(singleStepping==true){
- Serial.print("*");
- stepMe=false;
- while(stepMe==false){
- checkForCommands();
- }
- }
- }
- void doReset(void){
- digitalWrite(intPin,HIGH); //no interrupts yet
- 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
- char t = Serial.read(); // get one character
- }
- }
- 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.
- adrByteHi = PINA; //will be used at TPB time later.
- TPADone=true;
- }
- void getFile() { // go to File Send part of Bray++ terminal and put bin file into vRAM[]
- int inCtr=0;
- byte byteIn=65;
- while(inCtr<BUFFERLENGTH){
- if(Serial.available()){
- byteIn = Serial.read();
- vRAM[inCtr]=byteIn;
- inCtr++;
- }
- }
- Serial.print("Got "); Serial.println(BUFFERLENGTH);
- }
- void dumpVariableVert(int sizeToDump) { //new version of dumpVert(). Different sizes.
- //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<sizeToDump;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(" ");
- }
- int hexCharToInt2(byte by){ //pb version
- int d,r;
- d=by-'0';
- if(d>=0 && d<=9) {r=d;}
- else{
- d=by-55; //is it A,B...F?
- if (d>=10 && d<=15) {r=d;}
- else{
- r=by-87; //must be a,b...f. NB No error checking.
- }
- }
- return r;
- }
- void doBreakPoint2(){
- int d;
- int ctr=0;
- unsigned int hexVal[8];
- hexVal[2]=hexCharToInt2(receivedBytes[2])*4096;
- hexVal[3]=hexCharToInt2(receivedBytes[3])*256;
- hexVal[4]=hexCharToInt2(receivedBytes[4])*16;
- hexVal[5]=hexCharToInt2(receivedBytes[5])*1;
- breakPointAdr=hexVal[2]+hexVal[3]+hexVal[4]+hexVal[5]; //important
- Serial.print("Break point adress is : ");
- Serial.print(breakPointAdr);
- Serial.print(", in hex : 0x");
- Serial.println(breakPointAdr,HEX);
- }
- void doOpStop2(){
- // int d;
- unsigned int hexVal[8];
- hexVal[2]=hexCharToInt2(receivedBytes[2])*16;
- hexVal[3]=hexCharToInt2(receivedBytes[3])*1;
- stopCode=hexVal[2]+hexVal[3];
- Serial.print("Op stop is : ");
- Serial.print(stopCode);
- Serial.print(", in hex : 0x");
- Serial.println(stopCode,HEX);
- }
- void doDelay() {
- unsigned int hexVal[8];
- hexVal[2]=hexCharToInt2(receivedBytes[2])*16;
- hexVal[3]=hexCharToInt2(receivedBytes[3])*1;
- DELAY=hexVal[2]+hexVal[3];
- Serial.print("DELAY now is : ");
- Serial.print(DELAY);
- Serial.print(", in hex : 0x");
- Serial.println(DELAY,HEX);
- }
- void interpretCommand() {
- // String Command(receivedChars); //**important
- //if(Command.equals("gf")){
- if((receivedBytes[0]=='g')&&(receivedBytes[1]=='f')) { //get file
- Serial.print("Send file");
- getFile();
- serialFlush();
- doReset();
- }
- //if(Command.equals("dk")){
- if((receivedBytes[0]=='d')&&(receivedBytes[1]=='k')) { //dump 1k. Need this with buf =256?
- dumpVariableVert(1024);
- serialFlush();
- //Serial.println("**done dkflush**");
- }
- //if(Command.equals("du")){
- if((receivedBytes[0]=='d')&&(receivedBytes[1]=='u')) { //dump 256 bytes
- dumpVariableVert(256);
- serialFlush();
- }
- //if(Command.equals("re")){
- //if((receivedBytes[0]==0x72)&&(receivedBytes[1]==0x65)) { //re for reset
- if((receivedBytes[0]=='r')&&(receivedBytes[1]=='e')) {
- doReset();
- TPBCtr=0; clkCtr = 0;
- serialFlush();
- Serial.println(F("**done gf flush** Now resetting"));
- }
- if((receivedBytes[0]==0x62)&&(receivedBytes[1]==0x70)) doBreakPoint2(); //<bpxxxx>
- if((receivedBytes[0]==0x6f)&&(receivedBytes[1]==0x70)) doOpStop2(); //<opxx>
- if((receivedBytes[0]==0x64)&&(receivedBytes[1]==0x65)) doDelay(); //<dexx>.
- if((receivedBytes[0]=='s')&&(receivedBytes[1]=='s')){ //single step
- singleStepping=true; t1=millis()-time; Serial.print("--> ");Serial.print(t1);
- clockRate = (clkCtr*1000)/t1; Serial.print("=&& "); Serial.print(clockRate);
- } //go into single stepping but stop clock; presume <run> just finished.
- //if(Command.equals("stepMe")) stepMe=true;
- if((receivedBytes[0]=='s')&&(receivedBytes[1]=='t')) stepMe=true; //st
- //if (Command.equals("report")) doReport();
- //************
- if((receivedBytes[0]=='r')&&(receivedBytes[1]=='p')) doReport2(); //doReport(); //rp
- if((receivedBytes[0]=='t')&&(receivedBytes[1]=='c')){ //tc
- //if(Command.equals("toggleCommandShow")){
- if(showCommands==true) showCommands=false;
- else showCommands=true;
- }
- //if(Command.equals("toggleShowExecutes")){
- /*if((receivedBytes[0]=='t')&&(receivedBytes[1]=='e')){ //te
- if(showExecutes==true) showExecutes=false;
- else showExecutes=true;
- } */
- //if(Command.equals("toggleOpStopping")){
- if((receivedBytes[0]=='o')&&(receivedBytes[1]=='s')) { //os
- if(doOpStops==true) doOpStops=false;
- else doOpStops=true;
- }
- //if(Command.equals("run")){
- if((receivedBytes[0]=='r')&&(receivedBytes[1]=='u')) { //ru
- singleStepping=false;
- stepMe=true;
- Serial.println("Sing step = false");
- clkCtr=0; TPBCtr=0; fetchCtr=0; //after "run" we're timing clks/sec
- time=millis();
- //Serial.print("<> "); Serial.print(time); //start timer. Stopped by going into single stepping.
- }
- //if(Command.equals("pl0")) printLevel=0;
- if((receivedBytes[0]=='p')&&(receivedBytes[1]=='0')) printLevel=0; //p0
- if((receivedBytes[0]=='p')&&(receivedBytes[1]=='1')) printLevel=1; //p1
- if((receivedBytes[0]=='p')&&(receivedBytes[1]=='2')) printLevel=2; //p2
- if((receivedBytes[0]=='p')&&(receivedBytes[1]=='3')) printLevel=3; //p3
- //if(Command.equals("pl1")) printLevel=1;
- //if(Command.equals("pl2")) printLevel=2;
- //if(Command.equals("pl3")) printLevel=3;
- //if(Command.equals("int")) digitalWrite(intPin,LOW); // turn off with OUT 1 (0x0f)
- if((receivedBytes[0]=='i')&&(receivedBytes[1]=='n')) digitalWrite(intPin,LOW); //in
- }
- void checkForCommands(){ //if any inputs from keyboard, push them into buffer and see what command it is.
- recvWithStartEndMarkers();
- showAndInterpret();
- }
- void recvWithStartEndMarkers() { ////https://forum.arduino.cc/index.php?topic=396450
- static boolean recvInProgress = false;
- static byte ndx = 0;
- char startMarker = '<';
- char endMarker = '>';
- char rc;
- while (Serial.available() > 0 && newData == false) {
- rc = Serial.read();
- if (recvInProgress == true) {
- if (rc != endMarker) {
- receivedChars[ndx] = rc;
- receivedBytes[ndx]=(byte)rc; //PB added this
- ndx++;
- if (ndx >= numChars) {
- ndx = numChars - 1;
- }
- }
- else {
- receivedChars[ndx] = '\0'; // terminate the string
- recvInProgress = false;
- ndx = 0;
- newData = true;
- }
- }
- else if (rc == startMarker) {
- recvInProgress = true;
- }
- }
- }
- void showAndInterpret() {
- if (newData == true) {
- if(showCommands==true){
- Serial.print("Command received is : ");
- Serial.println(receivedChars);
- }
- else {serialFlush();} //get rid of commands in input buffer
- interpretCommand();
- //interpretCommand(); //*******put back** just testing for ram size
- newData = false;
- }
- }
- void print1TPBResults1(void) {//print disassembled opcode with address: optional
- sprintf(data,"Adr1] %02x%02x : ",adrByteHi,adrByte);
- Serial.print(data);
- doDisAsm(opCode); //new
- }
- /*void printTPBResults2() { //output adr and opcode and clockc et for each line...
- //showExecutes=true;
- ///temp!!!
- //doReport();
- if (fetchOrExecuteCh=='F') {
- // sprintf(data,"Adr: %02x%02x : %02x %u, %u %c %c",adrByteHi,adrByte,opCode, TPBCtr,clkCtr, fetchOrExecuteCh,readOrWriteCh);
- sprintf(data,"Adr) %02x%02x : %02x ",adrByteHi,adrByte,opCode);
- Serial.print(data);
- doDisAsm(opCode); //best place?
- }
- else{
- if(boolean showExecutes){ //KLUDGE, TAKE OUT LATER
- sprintf(data," Adr2: %x%x : %02x %lu<, %lu> %c %c",adrByteHi,adrByte,opCode,TPBCtr,clkCtr, fetchOrExecuteCh,readOrWriteCh);
- Serial.println(data);
- }
- }
- } */
- void doReport() { //show all useful variables.
- sprintf(data, "delay = %02x, op Stop code = %02x, breakpoint = %04x, current address = %04x, op code = %02x", DELAY,stopCode,breakPointAdr,currentAdr,opCode);
- Serial.println(data);
- sprintf(data, "TPBCtr = %lu, clkCtr= %lu, readOrWriteCh = %c, fetchOrExecuteCh = %c, doOpStops=%d ", TPBCtr,clkCtr,readOrWriteCh,fetchOrExecuteCh,doOpStops);
- Serial.println(data);
- sprintf(data, "TPADone = %d, TPBDone= %d, singleStepping = %d, stepMe = %d, showCommands = %d, instuction fetches=%lu ", TPADone,TPBDone,singleStepping,stepMe,showCommands,fetchCtr);
- Serial.println(data);
- sprintf(data,"Print Level %d",printLevel);
- Serial.print(data);
- }
- void doDisAsm(byte bopCode) { //look at op code and disassemble insgtruction. May require reading further bytes
- byte LSNib, MSNib;
- MSNib = bopCode/16;
- LSNib = bopCode%16;
- //sprintf(data,"Op code is %x and MSNib is %x and LSNib is %x", bopCode, MSNib, LSNib); //take out later.
- //Serial.println(data);
- instructionBytes = 1; //default for eg nop, phi, inc. Can be changed at relevant instruction subroutine
- switch(MSNib) {
- case 0:
- if(LSNib==0) sprintf(data,"idl %s",blankStr);
- else sprintf(data,"ldn %x",LSNib); break;
- case 1:
- sprintf(data,"inc %x",LSNib);
- break;
- case 2:
- sprintf(data,"dec %x",LSNib);
- break;
- case 3:
- //sprintf(data,"Tricky branches");
- instructionBytes=2;
- doHiNib3(LSNib);
- break;
- case 4:
- sprintf(data,"lda %x",LSNib);
- break;
- case 5:
- sprintf(data,"str %x",LSNib);
- break;
- case 6:
- //sprintf(data,"Tricky I/O");
- //sprintf(data,"Case 6");
- //instructionBytes = 2;
- doHiNib6(LSNib);
- break;
- case 7:
- //sprintf(data,"Tricky Hi nib 7");
- //doHiNib7(LSNib);
- //doHiNib7A(LSNib);
- doHiNib7B(LSNib);
- break;
- case 8:
- sprintf(data,"glo %x",LSNib);
- break;
- case 9:
- sprintf(data,"ghi %x",LSNib);
- break;
- case 0xa:
- sprintf(data,"plo %x",LSNib);
- break;
- case 0xb:
- sprintf(data,"phi %x",LSNib);
- break;
- case 0xc:
- instructionBytes=3;
- doHiNibcB(LSNib); //long branches and skips :0xc..
- break;
- case 0xd:
- sprintf(data,"sep %x",LSNib);
- break;
- case 0xe:
- sprintf(data,"sex %x",LSNib);
- break;
- case 0xf:
- doHiNibfA(LSNib); //arith logic etc
- break;
- default:
- sprintf(data," not disassenble %x %x",MSNib,LSNib); break; //took "could" out
- }
- //showData();
- Serial.print(data);
- //Serial.print("-");
- //Serial.print(bopCode,HEX); //output disassembled bopCode,no..maybe only at certain levels
- //Serial.println(bopCode,HEX);
- //serialFlush();
- }
- /*void experiment0() {
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x31);
- //doDisAsm(0x31);
- doDisAsm(0x32);
- doDisAsm(0x33);
- doDisAsm(0x34);
- //doDisAsm(0x35);
- doDisAsm(0x35);
- doDisAsm(0x36);
- doDisAsm(0x37);
- //doDisAsm(0x38);
- doDisAsm(0x38);
- doDisAsm(0x39);
- doDisAsm(0x3a);
- doDisAsm(0x3b);
- doDisAsm(0x3c);
- doDisAsm(0x3d);
- doDisAsm(0x3e);
- doDisAsm(0x3f);
- doDisAsm(0x45);
- doDisAsm(0x55);
- //doDisAsm(0x60);
- doDisAsm(0x60);
- doDisAsm(0x61);
- doDisAsm(0x68);
- doDisAsm(0x69);
- doDisAsm(0x6d);
- doDisAsm(0x6d);
- //doDisAsm(0x70);
- doDisAsm(0x3f);
- doDisAsm(0x38);
- doDisAsm(0x3f);
- doDisAsm(0x3f);
- doDisAsm(0x60);//
- doDisAsm(0x61);
- doDisAsm(0x68);
- doDisAsm(0x69);
- doDisAsm(0x6d);
- doDisAsm(0x6d);
- doDisAsm(0x60);
- doDisAsm(0x60);//------------
- doDisAsm(0x6d);
- doDisAsm(0x6d);
- doDisAsm(0x60);
- doDisAsm(0x60);//==========2==
- doDisAsm(0x30);
- doDisAsm(0x70);//==3==
- doDisAsm(0x71);
- doDisAsm(0x72);
- doDisAsm(0x73);
- doDisAsm(0x74);
- doDisAsm(0x75);
- doDisAsm(0x76);
- doDisAsm(0x77);
- doDisAsm(0x78);
- doDisAsm(0x79);
- doDisAsm(0x7a);
- doDisAsm(0x7b);
- doDisAsm(0x7c);
- doDisAsm(0x7d);
- doDisAsm(0x7e);
- doDisAsm(0x7f);
- doDisAsm(0xc0);
- doDisAsm(0xc1);
- doDisAsm(0xc2);
- doDisAsm(0xc3);
- doDisAsm(0xc4);
- doDisAsm(0xc5);
- doDisAsm(0xc6);
- doDisAsm(0xc7);
- doDisAsm(0xc8);
- doDisAsm(0xc9);
- doDisAsm(0xca);
- doDisAsm(0xcb);
- doDisAsm(0xcc);
- doDisAsm(0xcd);
- doDisAsm(0xce);
- doDisAsm(0xcf);
- doDisAsm(0xf0);
- doDisAsm(0xf1);
- doDisAsm(0xf2);
- doDisAsm(0xf3);
- doDisAsm(0xf4);
- doDisAsm(0xf5);
- doDisAsm(0xf6);
- doDisAsm(0xf7);
- doDisAsm(0xf8);
- doDisAsm(0xf9);
- doDisAsm(0xfa);
- doDisAsm(0xfb);
- doDisAsm(0xfc);
- doDisAsm(0xfd);
- doDisAsm(0xfe);
- doDisAsm(0xff);
- //doDisAsm(0x71) ;
- /*doDisAsm(0x72);
- doDisAsm(0x73);
- doDisAsm(0x74);
- doDisAsm(0x76);
- doDisAsm(0x77);
- doDisAsm(0x85);
- doDisAsm(0x95);
- doDisAsm(0xa5);
- doDisAsm(0xb5);
- doDisAsm(0xc5);
- doDisAsm(0xd5);
- doDisAsm(0xe5);
- doDisAsm(0xf5);
- }*/
- void doHiNib3(byte secondByte) {
- //sprintf(data,"Doing it in subroutine..,,,,Tricky Hi nib 3. Tricky branches");
- //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
- //instructionBytes=2;
- switch(secondByte) {
- case 0:
- sprintf(data,"br %02x",nextByte); break;
- case 1:
- sprintf(data,"bq %0x",nextByte); break; //!!todo: fix %x to %0x
- case 2:
- sprintf(data,"bz %x",nextByte); break;
- case 3:
- sprintf(data,"bdf %x",nextByte); break;
- case 4:
- sprintf(data,"b1 %x",nextByte); break;
- case 5:
- sprintf(data,"b2 %x",nextByte); break;
- case 6:
- sprintf(data,"b3 %x",nextByte); break;
- case 7:
- sprintf(data,"b4 %x",nextByte); break;
- case 8:
- sprintf(data,"skp %x",nextByte); break;
- case 9:
- sprintf(data,"bnq %x",nextByte); break;
- case 0xa:
- sprintf(data,"bnz %x",nextByte); break;
- case 0xb:
- sprintf(data,"bnf %x",nextByte); break;
- case 0xc:
- sprintf(data,"bn1 %x",nextByte); break;
- case 0xd:
- sprintf(data,"bn2 %x",nextByte); break;
- case 0xe:
- sprintf(data,"bn3 %x",nextByte); break;
- case 0xf:
- sprintf(data,"bn4 %x",nextByte); break;
- default:
- sprintf(data,"--prob-- 0x3 %x",secondByte); break;
- }
- }
- void doHiNib6(byte secondByte) {
- //sprintf(data,"Doing it in subroutine..,,,,Tricky Hi nib 7");
- if (secondByte==0) sprintf(data,"irx %s",blankStr);
- else{
- if((secondByte<=7) && (secondByte>0)) sprintf(data,"out %x",secondByte);
- else sprintf(data,"inp %x",(secondByte-8));
- }
- //NB can't have 68
- }
- void doHiNib7(byte secondByte) {
- //sprintf(data,"7xxx");
- //Serial.print("hn7");
- if (secondByte==1)sprintf(data,"dis %s",blankStr);
- else sprintf(data,"Not 1 %s",blankStr);
- //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
- /*switch(secondByte) {
- case 0:
- sprintf(data,"br %x",nextByte); break;
- //sprintf(data,"ret %s",blankStr); break;
- case 1:
- sprintf(data,"dis %s",blankStr); break;
- case 2:
- sprintf(data,"ldxa " ); break;
- case 3:
- sprintf(data,"stxd " ); break;
- case 4:
- sprintf(data,"adc " ); break;
- case 5:
- sprintf(data,"sdb " ); break;
- case 6:
- sprintf(data,"shrc " ); break;
- case 7:
- sprintf(data,"smb " ); break;
- case 8:
- sprintf(data,"sav " ); break;
- case 9:
- sprintf(data,"mark " ); break;
- case 0xa:
- sprintf(data,"seq " ); break;
- case 0xb:
- sprintf(data,"req " ); break;
- case 0xc:
- sprintf(data,"addi %x",nextByte); break;
- case 0xd:
- sprintf(data,"sdbi %x",nextByte); break;
- case 0xe:
- sprintf(data,"shlc"); break;
- case 0xf:
- sprintf(data,"smbi %x",nextByte); break;
- default:
- sprintf(data,"--prob-- 0x7 %x",secondByte); break;
- }
- */
- }/*
- void doHiNibc() {
- sprintf(data,"Doing it in subroutine..,,,,hi nib c; branches and skips");
- } */
- void doHiNibf() {
- sprintf(data,"Doing it in subroutine..,,,,hi nib f;arith logic etc");
- }
- void showData() {
- for (int i=0;i<10;i++) {
- Serial.print(data[i]);
- }
- } /*
- void experiment1(void) {
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- doDisAsm(0x00);
- doDisAsm(0x05);
- doDisAsm(0x15);
- doDisAsm(0x25);
- doDisAsm(0x30);
- } */
- void doHiNib7A(byte secondByte) {
- //sprintf(data,"7xxx");
- //Serial.print("hn7");
- //if (secondByte==1)sprintf(data,"dis %s",blankStr);
- //else sprintf(data,"Not 1 %s",blankStr);
- byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
- switch(secondByte) {
- case 0:
- //sprintf(data,"br %x",nextByte); break;
- sprintf(data,"ret %s",blankStr); break;
- case 1:
- sprintf(data,"dis %s",blankStr); break;
- case 2:
- sprintf(data,"ldxa %s",blankStr ); break;
- case 3:
- sprintf(data,"stxd %s",blankStr ); break;
- case 4:
- sprintf(data,"adc %s",blankStr ); break;
- case 5:
- sprintf(data,"sdb %s",blankStr ); break;
- case 6:
- sprintf(data,"shrc %s",blankStr ); break;
- /* case 7:
- sprintf(data,"smb %s",blankStr ); break;
- /* case 8:
- sprintf(data,"sav " ); break;
- case 9:
- sprintf(data,"mark " ); break;
- case 0xa:
- sprintf(data,"seq " ); break;
- case 0xb:
- sprintf(data,"req " ); break;
- case 0xc:
- sprintf(data,"addi %x",nextByte); break;
- case 0xd:
- sprintf(data,"sdbi %x",nextByte); break;
- case 0xe:
- sprintf(data,"shlc"); break;
- case 0xf:
- sprintf(data,"smbi %x",nextByte); break;*/
- default:
- sprintf(data,"--prob0x07 %x",secondByte); break;
- }
- }
- void doHiNib7B(byte secondByte1) {
- // cpould not get the switch method to work for this one.
- //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
- if (secondByte1==0) sprintf(data,"ret %s",blankStr);
- if (secondByte1==1) sprintf(data,"dis %s",blankStr);
- if (secondByte1==2) sprintf(data,"ldxa %s",blankStr);
- if (secondByte1==3) sprintf(data,"stxd %s",blankStr);
- if (secondByte1==4) sprintf(data,"adc %s",blankStr);
- if (secondByte1==5) sprintf(data,"sdb %s",blankStr);
- if (secondByte1==6) sprintf(data,"shrc %s",blankStr);
- if (secondByte1==7) sprintf(data,"smb %s",blankStr);
- if (secondByte1==8) sprintf(data,"sav %s",blankStr);
- if (secondByte1==9) sprintf(data,"mark %s",blankStr);
- if (secondByte1==0x0a) sprintf(data,"req %s",blankStr);
- if (secondByte1==0x0b) sprintf(data,"seq %s",blankStr);
- if (secondByte1==0x0c) {
- sprintf(data,"adci %0x",nextByte);instructionBytes=2; }
- if (secondByte1==0x0d) {
- sprintf(data,"sdbi %0x",nextByte);instructionBytes=2; }
- if (secondByte1==0x0e) sprintf(data,"shlc %0x",nextByte);
- if (secondByte1==0x0f) {
- sprintf(data,"smbi %0x",nextByte);instructionBytes=2; }
- } /*
- void doHiNibcA(byte secondByte2) { //long branches etc
- //sprintf(data,"Doing it in subroutine..,,,,Tricky Hi nib 3. Tricky branches");
- //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
- //byte thirdByte = vRAM[currentAdr+2];
- switch(secondByte2) {
- case 0:
- sprintf(data,"lbr %x %x",nextByte,thirdByte); break;
- // sprintf(data,"ret %s",blankStr); break; //!!
- case 1:
- sprintf(data,"bq %x%x",nextByte,thirdByte); break;
- case 2:
- sprintf(data,"bz %x",nextByte); break;
- case 3:
- sprintf(data,"bdf %x",nextByte); break;
- case 4:
- sprintf(data,"b1 %x",nextByte); break;
- case 5:
- sprintf(data,"b2 %x",nextByte); break;
- case 6:
- sprintf(data,"b3 %x",nextByte); break;
- case 7:
- sprintf(data,"b4 %x",nextByte); break;
- case 8:
- sprintf(data,"skp %x",nextByte); break;
- case 9:
- sprintf(data,"bnq %x",nextByte); break;
- case 0xa:
- sprintf(data,"bnz %x",nextByte); break;
- case 0xb:
- sprintf(data,"bnf %x",nextByte); break;
- case 0xc:
- sprintf(data,"bn1 %x",nextByte); break;
- case 0xd:
- sprintf(data,"bn2 %x",nextByte); break;
- case 0xe:
- sprintf(data,"bn3 %x",nextByte); break;
- case 0xf:
- sprintf(data,"bn4 %x",nextByte); break;
- default:
- sprintf(data,"--prob-- 0x3 %x",secondByte2); break;
- }
- } */
- void doHiNibcB(byte secondByte2) { //long branches etc
- //sprintf(data,"Doing it in subroutine..,,,,Tricky Hi nib 3. Tricky branches");
- //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
- //byte thirdByte = vRAM[currentAdr+2];
- if (secondByte2==0) sprintf(data,"lbr %0x%0x",nextByte,thirdByte);
- if (secondByte2==1) sprintf(data,"lbq %0x%0x",nextByte,thirdByte);
- if (secondByte2==2) sprintf(data,"lbz %0x %0x",nextByte,thirdByte);
- if (secondByte2==3) sprintf(data,"lbdf %0x %0x",nextByte,thirdByte);
- if (secondByte2==4){
- sprintf(data,"nop %s",blankStr); instructionBytes=1; }
- if (secondByte2==5) sprintf(data,"lsnq %0x%0x",nextByte,thirdByte);
- if (secondByte2==6) sprintf(data,"lsnz %0x %0x",nextByte,thirdByte);
- if (secondByte2==7) sprintf(data,"lsnf %0x %0x",nextByte,thirdByte);
- if (secondByte2==8) sprintf(data,"lskp %0x %0x",nextByte,thirdByte);
- if (secondByte2==9) sprintf(data,"lbnq %0x %0x",nextByte,thirdByte);
- if (secondByte2==0xa) sprintf(data,"lbnz %0x %0x",nextByte,thirdByte);
- if (secondByte2==0xb) sprintf(data,"lbnf %0x %0x",nextByte,thirdByte);
- if (secondByte2==0xc) sprintf(data,"lsie %0x %0x",nextByte,thirdByte);
- if (secondByte2==0xd) sprintf(data,"lsq %0x %0x",nextByte,thirdByte);
- if (secondByte2==0xe) sprintf(data,"lsz %0x %0x",nextByte,thirdByte);
- if (secondByte2==0xf) sprintf(data,"lsdf %0x %0x",nextByte,thirdByte);
- //else sprintf(data,"not yet %s",blankStr);
- /*
- switch(secondByte2) {
- case 0:
- sprintf(data,"lbr %x %x",nextByte,thirdByte); break;
- // sprintf(data,"ret %s",blankStr); break; //!!
- case 1:
- sprintf(data,"bq %x%x",nextByte,thirdByte); break;
- case 2:
- sprintf(data,"bz %x",nextByte); break;
- case 3:
- sprintf(data,"bdf %x",nextByte); break;
- case 4:
- sprintf(data,"b1 %x",nextByte); break;
- case 5:
- sprintf(data,"b2 %x",nextByte); break;
- case 6:
- sprintf(data,"b3 %x",nextByte); break;
- case 7:
- sprintf(data,"b4 %x",nextByte); break;
- case 8:
- sprintf(data,"skp %x",nextByte); break;
- case 9:
- sprintf(data,"bnq %x",nextByte); break;
- case 0xa:
- sprintf(data,"bnz %x",nextByte); break;
- case 0xb:
- sprintf(data,"bnf %x",nextByte); break;
- case 0xc:
- sprintf(data,"bn1 %x",nextByte); break;
- case 0xd:
- sprintf(data,"bn2 %x",nextByte); break;
- case 0xe:
- sprintf(data,"bn3 %x",nextByte); break;
- case 0xf:
- sprintf(data,"bn4 %x",nextByte); break;
- default:
- sprintf(data,"--prob-- 0x3 %x",secondByte2); break;
- }*/
- }
- void doHiNibfA(byte secondByte1) {
- // could not get the switch method to work for this one.
- //byte nextByte = vRAM[currentAdr+1]; //eg br 40 will have codes 30 40 and 40 is "nextByte"
- if (secondByte1>=8) instructionBytes=2; //otherwise stays at 1
- if (secondByte1==0) sprintf(data,"ldx %s",blankStr);
- if (secondByte1==1) sprintf(data,"or %s",blankStr);
- if (secondByte1==2) sprintf(data,"and %s",blankStr);
- if (secondByte1==3) sprintf(data,"xor %s",blankStr);
- if (secondByte1==4) sprintf(data,"add %s",blankStr);
- if (secondByte1==5) sprintf(data,"sd %s",blankStr);
- if (secondByte1==6) sprintf(data,"shr %s",blankStr);
- if (secondByte1==7) sprintf(data,"sm %s",blankStr);
- //if (secondByte>=8) instructionBytes=2;
- if (secondByte1==8) sprintf(data,"ldi %02x",nextByte);
- if (secondByte1==9) sprintf(data,"ori %02x",nextByte);
- if (secondByte1==0x0a) sprintf(data,"ani %02x",nextByte);
- if (secondByte1==0x0b) sprintf(data,"xri %02x",nextByte);
- if (secondByte1==0x0c) sprintf(data,"adi %02x",nextByte);
- if (secondByte1==0x0d) sprintf(data,"sdi %02x",nextByte);
- if (secondByte1==0x0e) { sprintf(data,"shl %s",blankStr); instructionBytes=1; }
- if (secondByte1==0x0f) sprintf(data,"smi %02x",nextByte);
- }
- void printTPBResults3(void) {
- Serial.print("[");
- if (fetchOrExecuteCh=='F'){
- sprintf(data,"Adr0 %02x%02x : ",adrByteHi,adrByte);
- Serial.print(data);
- //doDisAsm(opCode); //old
- doDisLine(opCode); //BIG connection with new progmem code
- if (printLevel==1) {
- Serial.println("]"); //if level1 finish here with CR.
- }
- if(printLevel>=2) {
- sprintf(data," --%2x ",opCode);
- if (instructionBytes ==1) Serial.println(data);
- if (instructionBytes==2) {
- Serial.print(data);
- //Serial.println(vRAM[currentAdr+1],HEX); //nextByte = vRAM[currentAdr+1];
- Serial.println(nextByte,HEX);
- }
- if (instructionBytes==3) {
- Serial.print(data);
- //Serial.print(vRAM[currentAdr+1],HEX);
- Serial.println(nextByte,HEX);
- //Serial.println(vRAM[currentAdr+2],HEX); //thirdByte = vRAM[currentAdr+2];
- Serial.println(thirdByte,HEX);
- }
- }
- }
- else { // ie it's not 'F', it's an execute line:
- if(printLevel==3) {
- 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);
- //sprintf(data,"Adr: %x%x : %02x %u, %u ,%u ; %c %c",adrByteHi,adrByte,opCode,TPBCtr,clkCtr,fetchCtr, fetchOrExecuteCh,readOrWriteCh);
- //sprintf(data," Adr: %x%x : %02x %u, %u %c %c",adrByteHi,adrByte,opCode,TPBCtr,clkCtr, fetchOrExecuteCh,readOrWriteCh);
- Serial.println(data);
- }
- }
- }
- void millisExperiment0(void){
- unsigned long time;
- for (int i=0;i<10;i++) {
- //Serial.println(millis());
- Serial.print("Time: ");
- time = millis();
- Serial.println(time); //prints time since program started
- delay(1000); // wait a second so as not to send massive amounts of data
- }
- //Notes and Warnings
- }
- void doOUT(void) { //come here when OUT n puts MR(X) on bus. NB nBUS >0 and opCode = mem byte MR(X)
- if (nBus==1) {
- if (opCode==0x0f) { digitalWrite(intPin,HIGH);} //turn interrupts off
- }
- }
- void doInpStuffIfNecess(void) { // when MWR* goes low, it could be INP with nBus != 0
- nBus = PINK & 0b0000111;
- if (nBus !=0) {
- byte jamByte = 0x40+nBus;
- Serial.print("@@" );Serial.print(jamByte,HEX);
- DDRC=0xff;
- PORTC=jamByte; //but PORTC is currently input?
- DDRC=0x00;
- }
- }
- void hiMemExp(void) {
- byte b;
- // b= pgm_read_byte_near(0x4001);
- b= pgm_read_byte(0x3001);
- Serial.print("!!! ~1"); Serial.println(b,HEX);
- }
- //------------------------------------------------------------------------------
- // New progmem7 code goes below here--------------------------------------------
- void doDisLine( byte opC) { //go into big progrmem string and emrge with j pointing opening '[' of menonic substring
- opCodePreProcess(opC);
- int k=0;
- foundOpCode= false;
- while ((k < strlen_P(flashHiNib3)) && (foundOpCode==false)){
- ch1 = pgm_read_byte_near(flashHiNib3+k);
- if (ch1=='[') {
- if( (pgm_read_byte_near(flashHiNib3+k+1)==char3) && (pgm_read_byte_near(flashHiNib3+k+2) ==char4) ){
- foundOpCode=true;
- data0[0] = pgm_read_byte_near(flashHiNib3+k+3); //first char of mnemonic
- data0[1] = pgm_read_byte_near(flashHiNib3+k+4);
- data0[2] = pgm_read_byte_near(flashHiNib3+k+5);
- data0[3] = pgm_read_byte_near(flashHiNib3+k+6);
- data0[4] = pgm_read_byte_near(flashHiNib3+k+7);
- data0[5] = pgm_read_byte_near(flashHiNib3+k+8);
- if (data0[2] == '.') closingBracket = data0[3]; //two char menonic like br
- if (data0[3] == '.') closingBracket = data0[4]; //3 char mnem like lda.
- if (data0[4] == '.') closingBracket = data0[5];
- }
- }
- k++;
- }
- if (foundOpCode==false) {
- Serial.print(F("Don't understandop code "));
- Serial.println(opC,HEX);
- }
- else {
- fixData0(); // now the nemonic ends with trailing \0
- Serial.print (data0); //print the mnemonic..
- doClosingBrackets(); //..and any other addresses etc
- }
- }
- //
- void opCodePreProcess(byte opCo0) {
- MSNib = opCo0/16;
- LSNib = opCo0%16;
- char3 = binToAsc(MSNib);
- char4= binToAsc(LSNib);
- if ((char3 =='8')||(char3 =='9') || (char3 =='A')|| (char3 =='B')) { oldChar4 = char4; char4='0'; } //glo,ghi,plo,phi resp
- if (char3=='0') { if (LSNib>0) {oldChar4 = char4; char4='1';}} //ldn but n!=0
- if ((char3=='1') || (char3=='2')) {oldChar4 = char4; char4='0';} //inc, dec
- if ((char3=='4') || (char3=='5')) {oldChar4 = char4; char4='0';} //lda,str
- if (char3=='6') {
- if ((LSNib>0) && (LSNib<=7)){oldChar4 = char4; char4='1';} //out n but n!=0 and n<=7
- if (LSNib>8) {oldChar4 = char4; char4='9';LSNib=LSNib-8;} //inp n but n>8. NB 68 seems to be invalid opCode
- }
- if ((char3=='D') || (char3=='E')) {oldChar4 = char4; char4='0';} //sep,sex
- }
- byte binToAsc(byte b) { //eg change 0x03 to 0x33 = '3'
- byte temp;
- temp = b + 0x30;
- if (temp > 0x39) temp = temp +7; // adjust for hex. NB outputs capital A,B etc
- return temp;
- }
- //
- void fixData0(void) { //replace dot with space and \0 so it prints OK
- for (int i = 0;i<10;i++) {
- if (data0[i] == '.') {
- data0[i] = ' ';
- data0[i+1] ='\0';
- }
- }
- }
- void doClosingBrackets(void) { //going to change printlns to prints below. To work in with old software display..
- if(closingBracket==']') { }; // Serial.print("."); //nothig after mnemonic eg nop
- if(closingBracket=='L') Serial.print(LSNib,HEX); //eg phi 3
- if(closingBracket=='N') Serial.print(nextByte,HEX); //eg br 34.
- if(closingBracket=='T') {
- Serial.print(nextByte,HEX);
- Serial.print(thirdByte,HEX);
- }
- }
- void printTPBResults4(void) {
- Serial.print("[");
- if (fetchOrExecuteCh=='F'){
- sprintf(data,"Adr) %02x%02x : ",adrByteHi,adrByte);
- Serial.print(data);
- //doDisAsm(opCode); //old .
- doDisLine(opCode); //BIG connection with new progmem code
- if (printLevel==1) {
- Serial.println("]"); //if level1 finish here with CR.
- }
- if(printLevel>=2) {
- sprintf(data," --%2x ",opCode);
- Serial.print(data);
- if(closingBracket==']') {Serial.println(); }
- if(closingBracket=='L') {Serial.println();} //Serial.println(LSNib,HEX);
- if(closingBracket=='N') Serial.println(nextByte,HEX); //eg br 34.
- if(closingBracket=='T') {
- //Serial.print(nextByte,HEX);
- //Serial.println(thirdByte,HEX);
- //Serial.print(closingBracket);
- sprintf(data," %02x%02x ",nextByte,thirdByte);
- Serial.print(data);
- }
- //if (instructionBytes ==1) Serial.println(data);
- if (instructionBytes==2) {
- //Serial.print(data);
- //Serial.println(vRAM[currentAdr+1],HEX); //nextByte = vRAM[currentAdr+1];
- //Serial.println(nextByte,HEX);
- }
- if (instructionBytes==3) {
- //Serial.print(data);
- //Serial.print(vRAM[currentAdr+1],HEX);
- //Serial.println(nextByte,HEX);
- //Serial.println(vRAM[currentAdr+2],HEX); //thirdByte = vRAM[currentAdr+2];
- //Serial.println(thirdByte,HEX);
- }
- }
- }
- else { // ie it's not 'F', it's an execute line:
- if(printLevel==3) { //*************pit back
- 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);
- //sprintf(data,"Adr: %x%x : %02x %u, %u ,%u ; %c %c",adrByteHi,adrByte,opCode,TPBCtr,clkCtr,fetchCtr, fetchOrExecuteCh,readOrWriteCh);
- //sprintf(data," Adr: %x%x : %02x %u, %u %c %c",adrByteHi,adrByte,opCode,TPBCtr,clkCtr, fetchOrExecuteCh,readOrWriteCh);
- Serial.println(data);
- }
- }
- }
- /*
- void doReport() { //show all useful variables.
- sprintf(data, "delay = %02x, op Stop code = %02x, breakpoint = %04x, current address = %04x, op code = %02x", DELAY,stopCode,breakPointAdr,currentAdr,opCode);
- Serial.println(data);
- sprintf(data, "TPBCtr = %lu, clkCtr= %lu, readOrWriteCh = %c, fetchOrExecuteCh = %c, doOpStops=%d ", TPBCtr,clkCtr,readOrWriteCh,fetchOrExecuteCh,doOpStops);
- Serial.println(data);
- sprintf(data, "TPADone = %d, TPBDone= %d, singleStepping = %d, stepMe = %d, showCommands = %d, instuction fetches=%lu ", TPADone,TPBDone,singleStepping,stepMe,showCommands,fetchCtr);
- Serial.println(data);
- sprintf(data,"Print Level %d",printLevel);
- Serial.print(data);
- }
- */
- void doReport2() { //old doReport takes up too much RAM
- Serial.println (F("delay,op-Stop code, breakpoint"));
- Serial.println(DELAY);
- Serial.println(stopCode);
- Serial.println(breakPointAdr);
- }
Add Comment
Please, Sign In to add comment