Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**5 Arduino is ROM/RAM for 1802
- Fri Apr 17 16:53:23 NZST 2020. ..e1 works well. Final step would be a disassembler but need to think about space on nan.
- ..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=50; //default. Can be changes via terminal command.
- int val = 0; int bufBytes;
- unsigned int adrByte=0;
- unsigned int adrByteHi =0;
- unsigned int currentAdr;
- 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[100];
- unsigned int breakPointAdr=0,TPBCtr=0,clkCtr = 0,opCode,stopCode;
- unsigned long fetchCtr=0;
- char fetchOrExecuteCh;
- char readOrWriteCh;
- //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}; //memeory 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(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(); while(1) { };
- }
- //--------------------------------------------------------------------------------------
- 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 for a second
- 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 for a second
- }
- //*************************************************
- 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++;
- }
- else {
- fetchOrExecuteCh='E';
- }
- if (digitalRead(readPin)==LOW) {
- DDRC = 0xff; //just for this version. Send nop when clk 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;
- printTPBResults2();
- 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;
- 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");
- }
- }
- 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 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.println(data);
- }
- else{
- if(showExecutes){
- 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 = %u, clkCtr= %u, 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);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement