Wednesday, May 20, 2020

Disassmbler now in flash PROGMEM

Running out of nano memory in RAM, only 2K bytes so rewrote 1802 disassembler so that all the disassembly information is in flash ROM.
Here's the side-program that disassembles 1802 hex codes;
https://pastebin.com/nVu7iVYz

New lines used look like this:
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"}; //};

and..

 Serial.println(F("All ready? "));

Got whole disassembler plus a few helper routines and sample data down to about 209 bytes.

Friday, May 8, 2020

Cosmacuino works with embedded 1802 code in high flash

Managed to get a short 1802 program going that starts off in mega's RAM and carries on above avr program in flash. PLan is to have RAM as just a place to leap up to$4000 and above on the 32K m328p, as well as a stack and short buffer place.

This program:
C:\Users\Dell\Documents\Arduino\PB_SketchApril12\CDP1802e93\CDP1802e93.ino

acts as ROM and RAM for 1802. Delivers instructions. Problem is there's not enough ram on Arduino nano, 2k, where this program is eventually going to live so I've just used a ram buffer called vRAM[] to start things off then hand over to program above $4000. Currently, on the mega which has 8K of static ram, a buffer of 1024 called vRAM[1024] holds temporary 1802 code.

This is the report from avrdude:
Sketch uses 13118 bytes (5%) of program storage space. Maximum is 253952 bytes.
Global variables use 3077 bytes (37%) of dynamic memory, leaving 5115 bytes for local variables. Maximum is 8192 bytes.
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avrdude -CC:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM15 -b115200 -D -Uflash:w:C:\ardtemp/CDP1802e93.ino.hex:i

The .ino file above is actually extended up to $4000 where main 1802 code is burned in. In the gap between the last byte of the arduino code viz. $333E=13118, and $4000, filler bytes are inserted. Currently zeros.

The file that cuts up the 1802 bin

....not sure where this post was going so will leave it as is then publish it ..

Combined file seems to work on Mega

Wanted system where big arduino program that talks to CDP1802 can be surrounded by 1802 code that can be fed, slowly, into real 1802. Had problems feeding arduino program eg CDP1802e93.hex that talks to 1802 and the 1802 asm program eg tackOn0.hex both into avrdude burning. Tried various ways as it seemed to work ok, at least for blink.hex type programs on arduino nano.
Finally wrote a c program that takes two hex files and combines them into one combined hex file and then that gets burned into arduino mega. Seems to work.

C program https://pastebin.com/w6y0RjyC C:\TinyC\MyFiles9May20\combine6.c
Mega program: https://pastebin.com/mxUWzfzD  C:\Users\Dell\Documents\Arduino\PB_SketchApril12\CDP1802e93\CDP1802e93.ino

1802 program: https://pastebin.com/JewvwYKZ  C:\TinyC\MyFiles9May20\tackOn0.asm

The avrdude line that burned in the combinedFilo.hex was:

Dell@DESKTOP-FGA8Q4U C:\TinyC\MyFiles9May20
$ \tinyc\avrdude -C \tinyc\avrdude.conf -v -patmega2560 -cwiring -PCOM14 -b115200 -D -Uflash:w:combinedFile0.bin:r

C program invoked like this:
Dell@DESKTOP-FGA8Q4U C:\TinyC\MyFiles9May20
$ combine6.exe CDP1802e93.ino.bin tackOn0.bin

Note it was the bin files that get combined.

Hex files were changed to bin like this:
Dell@DESKTOP-FGA8Q4U C:\TinyC\MyFiles9May20
$ ..\hex2bin.exe CDP1802e93.ino.hex

Picture of some of the above:


Added this few days later. Look at this Bray++ logfile:
Terminal log file
Date: 12/05/2020 - 11:20:51 AM
-----------------------------------------------
[[[Adr1 000d : nop ]
[[[Adr1 000e : lbr 400]
[[[Adr1 4000 : ldi 01]
[[Adr1 4002 : phi 7]
[[Adr1 4003 : lbr 0c]
[[[Adr1 000c : nop ]
[[[Adr1 000d : nop ]
[[[Adr1 000e : lbr 400]
[[[Adr1 4000 : ldi 01]
[[Adr1 4002 : phi 7]
[[Adr1 4003 : lbr 0c]
[[[Adr1 000c : nop ]
[[[Adr1 000d : nop ]
[[[Adr1 000e : lbr 400]
[[[Adr1 4000 : ldi 01]
[[Adr1 4002 : phi 7]
[[Adr1 4003 : lbr 0c]
[[[Adr1 000c : nop ]
[[[Adr1 000d : nop ]
[[[Adr1 000e : lbr 400]

-----------------------------------------------
Date: 12/05/2020 - 11:21:19 AM
End log file

There is a jump from low memory, around, $000e, to high memory $4000 then back again.
This is the tackon file that's split into two parts. One part goes into vRAM[] and the high part is birned up in $4000 by invoking avrdude the combined file with the normal arduino part CDP1802e93.hex with tackOn0.hex.
When the mega starts up it runs a default little loop of 1802.asm commands that start off in vRAM[] declaration. To get it to use above code you press M2 in terminal that asks for a block of 1802 bytes. Chose low1802.bin that gets sliced off bottom of tackOn0.bin automatically by combine6.exe. Once this low little program gets installed it does a reset and then joins up with rest of tackOn but jumping up to $4000 and back down again. We do this to jump over arduino code.

Thursday, May 7, 2020

Maybe have to go back to merging files.

Going to try:
c:\tinyc\avrdude -CC:\tinyc\avrdude.conf -v -patmega328p -carduino -PCOM15 -b57600  -Uflash:w:high2.hex:i -Uflash:r:dump6.bin:r
This seems to work. But it doesn't on mega. Not sure why.Changed high2.asm around and it still works. around $5000. NB old stuff around $4000 still there too.

Better go back to merged files. Am creating quite a good c file that takes two files and merges them.

C:\TinyC\MyFiles5May20_0\combine5.c

//https://stackoverflow.com/questions/16479006/can-i-use-fgetc-or-fputc-in-a-binary-file
//Tue May  5 11:39:35 NZST 2020. Now want to chop 1802 bin file into lower and upper parts. 0-$400 and $4000-endoffile
//Wed May  6 15:55:34 NZST 2020. Looking at command linelist of files.
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
void ttest1(void);
int fileIsReal(char* );
int exists(const char *fname);
int k;
char str1[32] ;
int main( int argc, char *argv[])
{ k=argc; 
strcpy(str1, argv[1]); //copies argv[1] into str1. May be useful.
printf("Argc is %d.\n",argc);
if( argc == 3 ) {
printf("The first argument supplied is file %s.  ", argv[1]);
printf(" Its length is %d, ",strlen(argv[1]));
char c1 =  argv[1][strlen(argv[1])-1];
printf("and the last character is '%c'. \n" , c1) ; //argv[1][strlen(argv[1])-1]);
//if(c1!='x') system ("Notepad.exe");
printf("The second argument supplied is file %s.  ", argv[2]);
printf(" Its length is %d, ",strlen(argv[2]));
char c2 =  argv[2][strlen(argv[2])-1];
printf("and the last character is '%c'. \n" , c2) ; //argv[1][strlen(argv[1])-1]);
}
   else if( argc > 3 ) {
      printf("Too many arguments supplied.\n");
  exit(4);
   }
   else {
      printf("Two arguments expected.\n");
  exit(5);
   }
/*printf("Argc is %d,  ",argc);
printf("argv[1]  is %s, ",argv[1]);
printf("argv[2]  is %s.\n ",argv[2]); */
    //FILE * fptr = fopen("BlinkNew3.ino.bin", "rb");  // open existingblink file for nano
//FILE * fptr = fopen("CDP1802e91.ino.bin", "rb");  // open existingblink file for nano
//FILE * fptr = fopen("CDP1802e93.ino.bin", "rb");  // open existingblink file for nano
//printf("Result of exists() function for %s is %d\n",argv[1],exists(argv[1]));
if(exists(argv[1] )) printf("File %s can be used. ",argv[1]);
else {
printf(" Can't find file %s.",argv[1]); 
exit(3);
}
if(exists(argv[2] )) printf(" File %s can be used.\n",argv[2]);
else {
printf(" Can't find file %s.",argv[2]); 
exit(3);
}
FILE * fptr = fopen(argv[1], "rb");  // open existingblink file for nano
FILE * fptr1 = fopen( argv[2], "rb");  // open long file with 1802 code above $4000 and $0 to 1K
    //char buffer[10000] = {0}; // the pic is 6kb or so, so 10k bytes will hold it
    FILE * fptr2 = fopen("combinedFile0.bin", "wb"); // open a new binary file to be sent to mega
FILE * fptr3 = fopen("low1802.bin", "wb"); // open a new binary file for vRAM[] insertion via terminal
                                                      
    unsigned long fileLen, fileLen1;
    unsigned long counter;

    fseek(fptr, 0, SEEK_END);
    fileLen=ftell(fptr);      // get the exact size of the blink file
    fseek(fptr, 0, SEEK_SET);
printf("The size of argv[1], %s, is  %d bytes.  ",argv[1],fileLen);
 
fseek(fptr1, 0, SEEK_END);
    fileLen1=ftell(fptr1);      // get the exact size of the blink file
    fseek(fptr1, 0, SEEK_SET);
printf("The size of argv[2], %s, is  %d bytes.\n ",argv[2],fileLen1);

    for(counter=0; counter<fileLen; counter++)
        fputc(fgetc(fptr),fptr2);  // read each byte of the arduino file. Put into combinedFile0
                                           
for(counter=fileLen; counter<0x4000; counter++) //fill in the gap between arduino file and 1802asm.bin
        fputc(0x00,fptr2);  
fseek(fptr1,0x4000,SEEK_SET);
for(counter=0x4000; counter<fileLen1; counter++)
        fputc(fgetc(fptr1),fptr2);  //Put bytes from 1802.asm file that are above $4000 into combinedFile0
fseek(fptr1,0,SEEK_SET);
for(counter=0; counter<0x400; counter++)
        fputc(fgetc(fptr1),fptr3);  //Put bytes from 1802.asm file that are below $400 into low1802.bin .

    fclose(fptr);
fclose(fptr1);
    fclose(fptr2);
fclose(fptr3);
return 0;
}
void ttest1(void) {
printf("The fttttirst argument supplied is %d", k);
}
/*int fileIsReal(char* filename) {
int j;
FILE * fptr = fopen(argv[1], "rb");
}*/
int exists(const char *fname)
{
    FILE *file;
    if ((file = fopen(fname, "r")))
    {
        fclose(file);
        return 1;
    }
    return 0;
}

Or use sreccat :
 srec_cat.exe HexFile1.hex -Intel HexFile2.hex -Intel -o MergedHexFile.hex -Intel

Just flash 1802.hex file above arduino file.

Thought it was good that both arduinoFile.hex and 1802asm.hex could be flashed together. But it's easier than that. Just flash 1802asm.hex file into existing arduino nano flash containing normal blink.hex or other. Like this:


c:\tinyc\avrdude -CC:\tinyc\avrdude.conf -v -patmega328p -carduino -PCOM15 -b57600  -Uflash:w:hi.hex:i -Uflash:r:dump0.bin:r

The file dump0.bin not really needed but it was good to check whole 32K read back.

Still not tried on mega with big 13k cdp1802e93.hex program. Next task.

Didn't work on mega. This did on nano.:

Going to try:
c:\tinyc\avrdude -CC:\tinyc\avrdude.conf -v -patmega328p -carduino -PCOM15 -b57600  -Uflash:w:high2.hex:i -Uflash:r:dump6.bin:r
This seems to work. But it doesn't on mega. Not sure why.Changed high2.asm around and it still works. around $5000. NB old stuff around $4000 still there too.

Wednesday, May 6, 2020

flashed hi and low using avrdude and two hex files.

Wrote normal blink program for nano and also assembled a 1802 program called hi.asm into hi.hex.

Used avrdude to burn both into nano and read back contents with this command:

$ c:\tinyc\avrdude -CC:\tinyc\avrdude.conf -v -patmega328p -carduino -PCOM15 -b57600 -Uflash:w:Blink1.ino.hex:i -Uflash:w:hi.hex:i -Uflash:r:dump.bin:r

Looked at big dump file, dump.bin and both the avr code and the little 1802 program were there.

Means we don't have to combine files in software. Just assemble 1802.asm into 1802.hex then combine and burn with one avrdude command.



c:\tinyc\avrdude -CC:\tinyc\avrdude.conf -v -patmega328p -carduino -PCOM15 -b57600 -Uflash:w:Blink1.ino.hex:i -Uflash:w:hi.hex:i -Uflash:r:dump.bin:r

Note two files flashed (one normal blink.hex-type file and one assembled 1802.hex file), one big file read back.

Pi Pico and other Boards

 Got a new Pi Pico and it looks very promising. Want to use Oled display with it.