Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**e7 2
- 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.
- */
- //1802 talks to Arduino Mega
- #define clockPin 13
- #define clearPin 12
- #define intPin 11
- #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 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 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];
- //char data[32] ;
- //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, 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
- 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.
- 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("Arduino talks to 1802. CDP1802c1. Pb 2020");
- delay(500);
- doReset();
- // dumpVariableVert(256);
- // doReport();
- //experiment0();
- //experiment1();
- //while(1) { };
- printLevel=1; //printlevel = 1 is default. Can be changed via terminal commands.
- //experiment1();
- //millisExperiment0();
- }
- //--------------------------------------------------------------------------------------
- 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();
- }
- 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;
- if (writeStrobe== true) {
- writeStrobe = false;
- vRAM[adrByte+adrByteHi*256]=PINC; //adrByteHi comes from read of PORTC during TPA
- readOrWriteCh='W';
- }
- else {
- readOrWriteCh='R';
- }
- if(digitalRead(SC0pin)==LOW) {
- fetchOrExecuteCh='F';
- fetchCtr++;
- //print1TPBResults1();
- }
- else {
- fetchOrExecuteCh='E';
- }
- 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;
- PORTC = vRAM[adrByte+adrByteHi*256] ; // read byte from virtual
- opCode=vRAM[adrByte+adrByteHi*256];
- }
- TPBDone=true;
- //print1TPBResults1();
- //printTPBResults2();
- if(printLevel!=0) {
- printTPBResults3();
- }
- 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<1024){
- if(Serial.available()){
- byteIn = Serial.read();
- vRAM[inCtr]=byteIn;
- inCtr++;
- }
- }
- Serial.print("Got 1024");
- }
- 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")){
- Serial.print("Getting File");
- getFile();
- serialFlush();
- Serial.println("**done gf flush** Now resetting");
- doReset();
- }
- if(Command.equals("dk")){
- dumpVariableVert(1024);
- serialFlush();
- Serial.println("**done dkflush**");
- }
- if(Command.equals("du")){
- dumpVariableVert(256);
- serialFlush();
- Serial.println("**done duflush**");
- }
- if(Command.equals("re")){
- doReset();
- TPBCtr=0; clkCtr = 0;
- serialFlush();
- Serial.println("**did reset flush**");
- }
- 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(Command.equals("singleStep")) {
- 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 (Command.equals("report")) doReport();
- if(Command.equals("toggleCommandShow")){
- if(showCommands==true) showCommands=false;
- else showCommands=true;
- }
- if(Command.equals("toggleShowExecutes")){
- if(showExecutes==true) showExecutes=false;
- else showExecutes=true;
- }
- if(Command.equals("toggleOpStopping")){
- if(doOpStops==true) doOpStops=false;
- else doOpStops=true;
- }
- if(Command.equals("run")){
- 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(Command.equals("pl1")) printLevel=1;
- if(Command.equals("pl2")) printLevel=2;
- if(Command.equals("pl3")) printLevel=3;
- }
- 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();
- 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(showExecutes){
- 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, showExecutes = %d, doOpStops=%d ", TPBCtr,clkCtr,readOrWriteCh,fetchOrExecuteCh,showExecutes, 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,"Adr1 %02x%02x : ",adrByteHi,adrByte);
- Serial.print(data);
- doDisAsm(opCode); //new
- 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);
- }
- if (instructionBytes==3) {
- Serial.print(data);
- Serial.print(vRAM[currentAdr+1],HEX);
- Serial.println(vRAM[currentAdr+2],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
- }
Advertisement
Add Comment
Please, Sign In to add comment