/* u.c -- upload DPU code for debugging */ #include #include #include /* codes known by DEBUG class in the DPU */ #include "u.h" static void quit() { com_disable(); exit(0); } static void wait() { long t,t1,pcit(); t=pcit(); for(;;) { task(); t1=pcit(); if(t1= 3) break; } } /* send byte to DPU, expect exact echo */ static void put85(int c) { int r; com_putc(c); while((r=com_getc())<0) { if(kbhit()) if(getch()==27) quit(); } #if 0 if(r != c) { printf("\nPUT85 echo failed -- sent=%X echo=%X\n",c,r); quit(); } #endif } /* used for sending sim files */ static int file_echo() { int r; while((r=com_getc())<0) { if(kbhit()) if(getch()==27) quit(); } return r; } static void send(int c) { put85(0xFE); put85(0x7F); put85(c); } static int get() { int c; for(;;) { task(); if(kbhit()) quit(); c = com_getc(); if(c>=0) return c; } } static FILE *fpl,*fpsim; static int file_id; static int old_file_id=999; static int do_packet() { float Rate,fraction; char klu[6]; unsigned char raw[10]; int kk; int c,bin,i,n,year,doy; int ra,rb,rc,rd,re,rh,rl; unsigned long met,ut,fine; int hour,minute,second; c = get(); if(c != 0x7F) return 0; c = get(); switch(c) { case EXIT_U : return 1; /* exit this U program */ case SHOW_DECIMAL : bin=get(); bin = (bin<<8) + get(); printf("%6d\n",bin); fprintf(fpl,"%6d\n",bin); break; case SHOW_HEX : bin=get(); bin = (bin<<8) + get(); printf("%04X\n",bin); fprintf(fpl,"%04X\n",bin); break; case SHOW_HEXN : /* (no newline) */ bin=get(); bin = (bin<<8) + get(); printf("%04X",bin); fprintf(fpl,"%04X",bin); break; case SHOW_DECN : /* (no newline) */ bin=get(); bin = (bin<<8) + get(); printf("%6d",bin); fprintf(fpl,"%6d",bin); break; case SHOW_HEXA : bin = get(); printf(" A=%02X ",bin); fprintf(fpl," A=%02X ",bin); break; case SHOW_HEX1 : bin = get(); printf("%02X",bin); fprintf(fpl,"%02X",bin); break; case SHOW_REGSET : n=get(); ra=get(); rb=get(); rc=get(); rd=get(); re=get(); rh=get(); rl=get(); printf(" APSW=%02X%02X BC=%02X%02X DE=%02X%02X HL=%02X%02X\n", n,ra,rb,rc,rd,re,rh,rl); fprintf(fpl," APSW=%02X%02X BC=%02X%02X DE=%02X%02X HL=%02X%02X\n", n,ra,rb,rc,rd,re,rh,rl); break; case SHOW_DUMP : n=get(); for(i=0;i>7)/512.)/10.; sprintf(klu,"%0.3f",fraction); printf("MET=%02d:%02d:%02d%s %08lX%04lX\n",hour,minute,second, klu+1,met,fine); fprintf(fpl,"MET=%02d:%02d:%02d%s %08lX%04lX\n",hour,minute,second, klu+1,met,fine); break; case SHOW_UT : for(n=0;n<10;++n) raw[n]=get(); // 2 bytes of year year=raw[0]; year = (year<<8)+raw[1]; // 2 bytes day-of-year doy=raw[2]; doy = (doy<<8)+raw[3]; hour=raw[4]; minute=raw[5]; second=raw[6]; // 1/256 second, 1/256/256 second fine=raw[7]; fine = 256*fine + raw[8]; fraction = ((float)fine)/65536.; sprintf(klu,"%0.3f",fraction); printf("%d %03d/%02d:%02d:%02d%s ", year,doy,hour,minute,second, klu+1); for(n=0;n<9;++n) printf(" %02X",raw[n]); printf("\n"); fprintf(fpl,"%d %03d/%02d:%02d:%02d%s ", year,doy,hour,minute,second, klu+1); for(n=0;n<9;++n) fprintf(fpl," %02X",raw[n]); fprintf(fpl,"\n"); break; } return 0; } #define NBYTES 120 static unsigned char buf[1024]; static int gg() { while(kbhit()==0) task(); return (int)getch(); } void main(int argc, char *argv[]) { FILE *fp,*pm; long t,t1,pcit(); short n,i,c,raddr,waddr,wbyte,count; unsigned short un; short nbytes; int maxbytes; char s[20]; waddr=raddr=0; count=1; fpsim=NULL; printf("U - ISUAL Debug Uploader and Terminal Emulator\n"); kbhit(); /* initialize serial port */ com_init(); if(argc==1) strcpy(s,"dpudcm"); else { if(*argv[1]=='-') goto monitor; else strcpy(s,argv[1]); } strcat(s,".b"); fp = fopen(s,"rb"); if(fp==NULL) { printf("can't open %s\n",s); com_disable(); exit(0); } /* '*' byte signals modified Dunfield Debugger to do a binary upload, then execute */ com_putc('*'); /* if we're talking to "ub" (not DMON), send Bank code */ if(strcmp(argv[1],"debh")==0 || strcmp(argv[1],"DEBH")==0) { com_putc(0x87); /* bank select */ maxbytes=0x500; } else if(strcmp(argv[1],"dmon7")==0 || strcmp(argv[1],"DMON7")==0) { com_putc(0x86); maxbytes=4000; } else if(strcmp(argv[1],"promd1")==0 || strcmp(argv[1],"PROMD1")==0) { com_putc(0x80); maxbytes=4000; } else if(strcmp(argv[1],"promd2")==0 || strcmp(argv[1],"PROMD2")==0) { com_putc(0x83); maxbytes=4000; } else if(strcmp(argv[1],"debhp")==0 || strcmp(argv[1],"DEBHP")==0) { com_putc(0xB2); maxbytes=16384; } else if(strcmp(argv[1],"eeprom")==0 || strcmp(argv[1],"EEPROM")==0) { com_putc(0xB1); maxbytes=16384; } else { com_putc(13); /* debugger expects CR */ maxbytes= 16384; } while(com_getc()!='$') if(kbhit()) quit(); nbytes=0; for(;;) { if(kbhit()) goto monitor; n=fread(buf,1,NBYTES,fp); if(n==0) break; put85(n); for(i=0;imaxbytes) break; } put85(0); fclose(fp); printf("\n\7load complete\n"); /* monitor-loop */ monitor: fpl = fopen("u.log","w"); for(;;) { c = com_getc(); if(c>=0) { if(c==10) { printf("\n"); fprintf(fpl,"\n"); } else if(c==13) continue; /* prefix of FE 7F signals that a packet is coming */ else if(c==0xFE) { if(do_packet()==1) break; } else if(c==7) { printf("\7"); fprintf(fpl,"<7>"); } else if(c<32 && c!=8) { printf("<%02X>",c); fprintf(fpl,"<%02X>",c); } else { putch(c); fprintf(fpl,"%c",c); } } if(kbhit()) { c = getch(); if(c==27) break; /* ESC */ if(c=='\t') { com_putc(27); continue; } if(c != 0) { com_putc(c); continue; } c = getch(); /* Function Key */ if(c==0x3B) send(DC_F1); /* F1 */ else if(c==0x3C) send(DC_READCLOCK); /* F2 */ else if(c==0x3D) send(DC_F3); /* F3 */ else if(c==0x3E) send(DC_F4); /* F4 */ else if(c==0x3F) send(DC_F5); /* F5 */ else if(c==0x40) send(DC_F6); /* F6 */ else if(c==0x41) send(DC_F7); /* F7 */ else if(c==0x42) send(DC_F8); /* F8 */ else if(c==0x43) send(DC_F9); /* F9 */ else if(c==0x44) send(DC_F10); /* F10 */ else if(c==0x85) send(DC_F11); /* F11 */ else if(c==0x5E) send(DC_CF1); /* ctrl-F1 */ else if(c==0x5F) send(DC_CF2); /* ctrl-F2 */ else if(c==0x62) send(DC_CF5); /* ctrl-F5 */ else { printf("%X - not implemented\n",c); continue; } } } /* for(;;) */ com_disable(); fclose(fpl); if(fpsim!=NULL) fclose(fpsim); printf("U terminated normally.\n"); printf(" logfile 'U.LOG' written\n"); }