prjbrook

progmem7.c disassembler now in flash

May 20th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. //Thu May 21 12:11:42 NZST 2020. PROGMEM based disassembler seems to work. Now get memory down.
  2. //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
  3. //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
  4. //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..
  5. //RAM-hog previous disassem code.
  6. // save some unsigned ints.
  7. //const PROGMEM uint16_t charSet[] = { 65000, 32796, 16843, 10, 11234};
  8. //const uint16_t charSetR[] = { 65000, 32796, 16843, 10, 11234};
  9. // save some chars
  10. //const char signMessage[] PROGMEM = {"I AM yy1PREDATOR, UNSEEN COMBATANT. CREATED BY THE UNITED STATES DEPART"};
  11. //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"};
  12. 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"}; //};
  13.  
  14. char ch1;
  15. char char3 = '7' ;
  16. char char4 ='F';
  17. char oldChar4;
  18. char data0[10] ;
  19. char closingBracket;
  20.  
  21. byte vRAM[6] = {0x7b, 0x7b, 0x7a, 0xCA,0x7b,0x68};
  22. //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};
  23.  
  24. boolean foundOpCode;
  25.  
  26. byte LSNib;
  27. byte MSNib;
  28. byte nextByte = 0x11;
  29. byte thirdByte = 0x22;
  30.  
  31. void setup() {
  32. Serial.begin(9600);
  33. Serial.println(F("All ready? "));
  34. }
  35.  
  36. void loop() {
  37. for(int i =0;i<6;i++) doDisLine(vRAM[i]);
  38. while(1) { }
  39. }
  40.  
  41. void doDisLine( byte opC) { //go into big progrmem string and emrge with j pointing opening '[' of menonic substring
  42. opCodePreProcess(opC);
  43. int k=0;
  44. foundOpCode= false;
  45. while ((k < strlen_P(flashHiNib3)) && (foundOpCode==false)){
  46. ch1 = pgm_read_byte_near(flashHiNib3+k);
  47. if (ch1=='[') {
  48. if( (pgm_read_byte_near(flashHiNib3+k+1)==char3) && (pgm_read_byte_near(flashHiNib3+k+2) ==char4) ){
  49. foundOpCode=true;
  50. data0[0] = pgm_read_byte_near(flashHiNib3+k+3); //first char of mnemonic
  51. data0[1] = pgm_read_byte_near(flashHiNib3+k+4);
  52. data0[2] = pgm_read_byte_near(flashHiNib3+k+5);
  53. data0[3] = pgm_read_byte_near(flashHiNib3+k+6);
  54. data0[4] = pgm_read_byte_near(flashHiNib3+k+7);
  55. data0[5] = pgm_read_byte_near(flashHiNib3+k+8);
  56. if (data0[2] == '.') closingBracket = data0[3]; //two char menonic like br
  57. if (data0[3] == '.') closingBracket = data0[4]; //3 char mnem like lda.
  58. if (data0[4] == '.') closingBracket = data0[5];
  59. }
  60. }
  61. k++;
  62. }
  63. if (foundOpCode==false) {
  64. Serial.print(F("Don't understandop code "));
  65. Serial.println(opC,HEX);
  66. }
  67. else {
  68. fixData0(); // now the nemonic ends with trailing \0
  69. Serial.print (data0); //print the mnemonic..
  70. doClosingBrackets(); //..and any other addresses etc
  71. }
  72. }
  73. //
  74. void opCodePreProcess(byte opCo0) {
  75. MSNib = opCo0/16;
  76. LSNib = opCo0%16;
  77. char3 = binToAsc(MSNib);
  78. char4= binToAsc(LSNib);
  79. if ((char3 =='8')||(char3 =='9') || (char3 =='A')|| (char3 =='B')) { oldChar4 = char4; char4='0'; } //glo,ghi,plo,phi resp
  80. if (char3=='0') { if (LSNib>0) {oldChar4 = char4; char4='1';}} //ldn but n!=0
  81. if ((char3=='1') || (char3=='2')) {oldChar4 = char4; char4='0';} //inc, dec
  82. if ((char3=='4') || (char3=='5')) {oldChar4 = char4; char4='0';} //lda,str
  83. if (char3=='6') {
  84. if ((LSNib>0) && (LSNib<=7)){oldChar4 = char4; char4='1';} //out n but n!=0 and n<=7
  85. if (LSNib>8) {oldChar4 = char4; char4='9';LSNib=LSNib-8;} //inp n but n>8. NB 68 seems to be invalid opCode
  86. }
  87. if ((char3=='D') || (char3=='E')) {oldChar4 = char4; char4='0';} //sep,sex
  88. }
  89. byte binToAsc(byte b) { //eg change 0x03 to 0x33 = '3'
  90. byte temp;
  91. temp = b + 0x30;
  92. if (temp > 0x39) temp = temp +7; // adjust for hex. NB outputs capital A,B etc
  93. return temp;
  94. }
  95. //
  96. void fixData0(void) { //replace dot with space and \0 so it prints OK
  97. for (int i = 0;i<10;i++) {
  98. if (data0[i] == '.') {
  99. data0[i] = ' ';
  100. data0[i+1] ='\0';
  101. }
  102. }
  103. }
  104. void doClosingBrackets(void) {
  105. if(closingBracket==']') Serial.println(); //nothig after mnemonic eg nop
  106. if(closingBracket=='L') Serial.println(LSNib,HEX); //eg phi 3
  107. if(closingBracket=='N') Serial.println(nextByte,HEX); //eg br 34.
  108. if(closingBracket=='T') {
  109. Serial.print(nextByte,HEX);
  110. Serial.println(thirdByte,HEX);
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment