Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Thu May 21 12:11:42 NZST 2020. PROGMEM based disassembler seems to work. Now get memory down.
- //Thu May 21 10:08:37 NZST 2020. Filling in more of the menonics table.C:\Users\Dell\Documents\Arduino\PB_New_Sketch_Folder_2\progmem6\progmem6.ino
- //Sat May 16 13:00:51 NZST 2020 New version of PROGMEM disassembler going well with little vRAM[]. C:\Users\Dell\Documents\Arduino\PB_New_Sketch_Folder_2\progmem3\progmem3.ino
- //Now going to tidy up and get dissassembly stuff read to put back into C:\Users\Dell\Documents\Arduino\PB_SketchApril12\CDP1802e94\CDP1802e94.ino to replace..
- //RAM-hog previous disassem code.
- // save some unsigned ints.
- //const PROGMEM uint16_t charSet[] = { 65000, 32796, 16843, 10, 11234};
- //const uint16_t charSetR[] = { 65000, 32796, 16843, 10, 11234};
- // save some chars
- //const char signMessage[] PROGMEM = {"I AM yy1PREDATOR, UNSEEN COMBATANT. CREATED BY THE UNITED STATES DEPART"};
- //const char flashHiNib3[] PROGMEM = {"[00idl.][30br.N[31bq.N[70ret.]abcd[71dis.][72ldxa.][73stxd][74adc.][75sdb.][76shrc.][77smb.][78sav.][79mark.][7Aseq.][7Breq.][7Caddi.N[7Dsdbi.N[7Eshlc.][7Fsmbi.N[B0phi.L[F0ldx.][F1or.][F2and.][F3xor.][F4add.][F5sd.][F6shr.][F7sm.][F8ldi.N[F9ori.N[FAani.N[FBxri.N[FCadi.N[FDsdi.N[FEshl.][FFsmi.N"};
- 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() {
- Serial.begin(9600);
- Serial.println(F("All ready? "));
- }
- void loop() {
- for(int i =0;i<6;i++) doDisLine(vRAM[i]);
- while(1) { }
- }
- 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) {
- if(closingBracket==']') Serial.println(); //nothig after mnemonic eg nop
- if(closingBracket=='L') Serial.println(LSNib,HEX); //eg phi 3
- if(closingBracket=='N') Serial.println(nextByte,HEX); //eg br 34.
- if(closingBracket=='T') {
- Serial.print(nextByte,HEX);
- Serial.println(thirdByte,HEX);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment