#include "serctrl.h" const char serctrl_txt1[18] = " SERIAL CONTROL \0"; const char serctrl_txt2[18] = " STANDBY \0"; unsigned char charhextochar( unsigned char val ) { if( ( val >= '0') && ( val <= '9')){ return( val - '0' ); } if( ( val >= 'A') && ( val <= 'F')){ return( val - 'A' + 10 ); } if( ( val >= 'a') && ( val <= 'f')){ return( val - 'a' + 10 ); } return(0); } unsigned char char2hextochar( unsigned char * p){ unsigned char v; v = charhextochar( p[0] ); v = v << 4; v = v & 0xf0; v = v + charhextochar( p[1] ); return( v ); } unsigned int char4hextoint( unsigned char * p){ unsigned int v; v = char2hextochar( &p[0] ); v = v << 8; v = v & 0xff00; v = v + char2hextochar( &p[2] ); return( v ); } unsigned int ltr_seg; int loadToRam( void ) { unsigned int addr; unsigned int nr; unsigned char type; unsigned char val; int ct; ct = 1; nr = ( unsigned int ) char2hextochar( &serinbuf[ct] ); ct = ct + 2; addr = char4hextoint( &serinbuf[ct] ); ct = ct + 4; type = char2hextochar( &serinbuf[ct] ); if( type == 1 ){ return( 0 ); } if( type == 2 ){ //8086 segment address record ct = ct + 2; ltr_seg = 0; ltr_seg = char4hextoint( &serinbuf[ct] ) / 0x1000; return(1); } if( type == 4 ){ //extended linear address mode ct = ct + 2; ltr_seg = char4hextoint( &serinbuf[ct] ); return(1); } if( type == 0 ){ while( nr > 0 ){ ct = ct + 2; val = char2hextochar( &serinbuf[ct] ); // now write it to ram writeFarByte( ltr_seg, addr, val ); addr++; nr--; } } return(1); } void serialcontrol( void ) { int hexfile; lcd_clear(); lcd_puts(0,0,serctrl_txt1); lcd_puts(1,0,serctrl_txt2); //init init_serial( Baud57k6 ); serinbuf[0] = 0; hexfile = 0; while( 1 ){ serial_receive(1); if( serinbuf[0] == 'X' ){ break; } if( serinbuf[0] == ':' ){ hexfile = 1; } if( hexfile ){ if( serinbuf[0] != ':'){ break; } if( loadToRam() == 0 ){ seroutbuf[0] = 0x0a; serial_transmit(1); break; } seroutbuf[0] = 0x0a; serial_transmit(0); continue; } } // end deinit_serial(); lcd_clear(); }