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.

Wednesday, April 29, 2020

avrdude

Want to use avrdude from Arduino files but those files are locked inside Windowsapps folder in Program Files folder of C: drive.

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 -patmega328p -carduino -PCOM14 -b57600 -D -Uflash:w:C:\ardtemp/Blink1.ino.hex:i


How's that for a file name (above). This invokes avrdude that programs a little nano.
The version is:
avrdude: Version 6.3-20190619

Had to unlock Windowsapps folder using instructions found here:

https://answers.microsoft.com/en-us/windows/forum/all/what-is-windows-apps-hidden-folder-and-why-cant-i/40a60508-c409-422a-af92-bd51fe5a4ca9

Might put a copy of avrdude and associated conf file into ardtemp where the file.ino.hex file live. The can do avrdude invokes away from official Arduino folder for safety.

Did this and had no luck til I inserted baud rate. So while in c:\ardtemp dirI wrote on command line:

Dell@DESKTOP-FGA8Q4U C:\ardtemp
$ avrdude -Cavrdude.conf -v -patmega328p -carduino -PCOM14 -b57600 -Uflash:w:Blink1.ino.hex:i

...and it worked.

Now want to read entire file back.

Mega uses following for avrdude in normal mode:
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/CDP1802e91.ino.hex:i

-------------------------------------------------------further research-----------------
Mega uses following for avrdude in normal mode:

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/CDP1802e91.ino.hex:i

revised is:
avrdude -C avrdude.conf -v -patmega2560 -cwiring -PCOM15 -b115200 -D -Uflash:w:CDP1802e91.ino.bin:r

Try this above.
But avrdude, latest copy (avrdude version 6.3-20190619,) now resides in c:\TinyC, as does conf file.So, to revise above, try:
(while in folder containing the arduino bin file below)

$ \tinyc\avrdude -C \tinyc\avrdude.conf -v -patmega2560 -cwiring -PCOM15 -b115200 -D -Uflash:w:CDP1802e91.ino.bin:r

\tinyc\avrdude -C \tinyc\avrdude.conf -v -patmega2560 -cwiring -PCOM15 -b115200 -D -Uflash:w:CDP1802e91.ino.bin:r (<--worked)12:14 PM 5/05/2020

Tuesday, April 28, 2020

ISR works on real 1802

Terminal log file
Date: 28/04/2020 - 8:14:58 PM
-----------------------------------------------
[[Adr1 0003 : phi 2]
[[Adr1 0004 : ldi 45]
[[Adr1 0006 : plo 2]
[[Adr1 0007 : sex 2]
[[Adr1 0008 : ldi 00]
[[Adr1 000a : phi 1]
[[Adr1 000b : ldi 55]
[[Adr1 000d : plo 1]
[[Adr1 000e : ldi 2d]
[[Adr1 0010 : stxd ]
[[Adr1 0011 : inc 2]
[[Adr1 0012 : out 1]
## 2D
[[Adr1 0013 : br 12]          ;just looping at this stage until...
[[Adr1 0012 : out 1]
## 22
[[Adr1 0013 : br 12]
[[Adr1 0012 : out 1]
## 33
[[Adr1 0013 : br 12]
[[Adr1 0012 : out 1]
## F
[[Adr1 0013 : br 12]
[[Adr1 0012 : out 1]
## 55
[[Adr1 0013 : br 12]
[[Adr1 0012 : out 1]
## 0
[Command received is : int              ;terminal command causes int pin to go low
[Adr1 0013 : br 12]              ;finishes that instruction         
[[[Adr1 0055 : dec 2]           ;then jumps to ISR at 0x0055
[[Adr1 0056 : sav ]
[[Adr1 0057 : dec 2]
[[Adr1 0058 : str 2]
[[Adr1 0059 : nop ]
[[[Adr1 005a : br 53]
[[Adr1 0053 : lda 2]
[[Adr1 0054 : dis ]            ;ISR ends here. dis turns off interrupts.
[[Adr1 0012 : out 1]
## 0
[[Adr1 0013 : br 12]
[[Adr1 0012 : out 1]
## 0
[[Adr1 0013 : br 12]
[[Adr1 0012 : out 1]
## 0
[[Adr1 0013 : br 12]
[[Adr1 0012 : out 1]
## 0
[[Adr1 0013 : br 12]
[[Adr1 0012 : out 1]
## 0
[[Adr1 0013 : br 12]
[[Adr1 0012 : out 1]
## 0
[[Adr1 0013 : br 12]
[[Adr1 0012 : out 1]
## 0

-----------------------------------------------
Date: 28/04/2020 - 8:15:42 PM
End log file

ISR working in simulation.

This worked in simulation. Might try in real 1802 with slowish stepping.

C:\Users\Dell\Documents\1802_Data\a18\WorkingApril282020\intsPractice1.lst
   0000                 START ORG 0
   0000   7b            seq
   0001   f8 03          ldi $03 ;careful, we have some nops up there.
   0003   b2            phi 2 ;R2 is stack pointer
   0004   f8 45          ldi $45
   0006   a2            plo 2 ;R2=stack pointer now points to $00ff
   0007   e2            sex 2 ;X now pnts to R2, the stack pointer. 00ff
   0008   f8 00          ldi HIGH(ISR)
   000a   b1            phi 1
   000b   f8 55          ldi LOW(ISR)
   000d   a1            plo 1
                       
   000e                 loop0
   000e   f8 2d          ldi $2d ;want output this byte on channel 1
   0010   73            stxd
   0011   12            inc 2
                        ;here P=0 and X=2
                        ; enableinterrupts
                        ; sex 0 ;P=0 currently
                        ; ret ;
                        ; DB $20 ;ret will use this. Now P=0,X=2. Interrupts enabled
                        ; disableinterrupts
                        ; sex 0 ;P=0 currently
                        ; dis ;
                        ; DB $20 ;dis will use this.Now P=0,X=2 and interrupts disabled
   0012                 loop1
   0012   61            out 1
   0013   30 12          br loop1
   0053                  ORG $0053
   0053                 exit ;leave ISR here
   0053   42            lda 2 ;put back DB
   0054   71            dis ;same as ret but disable interrupts
                        ;ret ;X,P get old values. Enable interrupts
   0055                  ORG $0055
   0055                 ISR ;get R1 to point here for interrupts. T = XP
   0055   22            dec 2 ;R=2 is stack ptr. Point to free space
   0056   78            sav ;T goes to MR(X)
   0057   22            dec 2 ;fresh slot on stack
   0058   52            str 2 ;D goes on stack
   0059   c4            nop ;do other stuff
   005a   30 53          br exit ;leave main part of ISR
                       
                       
   0345                  ORG $345
   0345   11 22 33 0f    DB $11,$22,$33,$0f,$55
   0349   55           
   03fb                  ORG $3fb
   03fb   c4            nop
   03fc   c4            nop
   03fd   c4            nop
   03fe   c4            nop
   03ff   c4            nop
                       
   0400                  END
0055  ISR           0000  START         0053  exit          000e  loop0   



0012  loop1       

Now writing to virtual RAM

Actually, date wrong. Got out of sequence.
Note change in virtual RAM.

 0000                 START ORG 0
   0000   7b            seq
   0001   7a            req
   0002   7b            seq
   0003   f8 00          ldi $00
   0005   b7            phi 7
   0006   f8 98          ldi 98H
   0008   a7            plo 7
   0009   f8 a5         write ldi $A5    ;MADE CHANGE to $5b in above
   000b   57            str 7
   000c   30 09          br write
   0064                  ORG 100
   0064   c4            nop
   0065                  END
0000  START         0009  write       

Pi Pico and other Boards

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