#include "stdio.h" #include "ctype.h" #include "stdlib.h" #include "string.h" #include "conio.h" #include "viewer.h" #define SHOW_FIRST_COLUMN 3 #define SHOW_SECOND_COLUMN 43 #define SHOW_FIRST_DATA_COLUMN SHOW_FIRST_COLUMN + 3 #define SHOW_SECOND_DATA_COLUMN SHOW_SECOND_COLUMN + 3 void Show_Names( int *varStart, int *varEnd ) { int row, column, index; char colStr[ 99 ]; row = SHOW_FIRST_ROW; column = SHOW_FIRST_COLUMN; index = *varStart; do { // display on-screen variables and their address sprintf( colStr, "%2X) %s", Variables [ index ].address, Variables [ index ].name ); Display_String ( colStr, row, column ); row = row + 1; if ( row > SHOW_LAST_ROW ) { if ( column == SHOW_FIRST_COLUMN ) { row = SHOW_FIRST_ROW; column = SHOW_SECOND_COLUMN; } } index++; } while (( index < *varEnd ) && ( row <= SHOW_LAST_ROW )); // can't display any more, return number displayed *varEnd = index; } void show_variable( int varIndex, int varStart ) { int row, column; int varData; // load data based on length (one or two bytes only) varData = OnChipData[ Variables[ varIndex ].address ]; if ( Variables[ varIndex ].length == 2 ) { varData = varData + (OnChipData[ Variables[ varIndex ].address + 1 ] * 256); } // calculate position based on start variable column = SHOW_FIRST_DATA_COLUMN; row = ( varIndex - varStart ); if ( row > SHOW_NUMBER_ROWS ) { row = row - SHOW_NUMBER_ROWS - 1; column = SHOW_SECOND_DATA_COLUMN; } row = row + SHOW_FIRST_ROW; // display the data Display_Data( varData, Variables[ varIndex ].length, row, column ); } #define HEX_START_COLUMN 2 #define HEX_START_ROW 18 #define HEX_HEADER_STR " 00 01 02 03 04 05 06 07 -- 08 09 0A 0B 0C 0D 0E 0F" #define HEX_DUMP_BK0_START 0x20 #define HEX_DUMP_BK1_START 0xA0 #define HEX_MAX_ROWS 7 #define HEX_MAX_BYTES 16 #define HEX_ASCII_COLUMN 60 void show_hex_dump( int startAddr ) { int row; int column; int i, j, k; int colIndex; char asciiStr[ 20 ]; column = HEX_START_COLUMN; row = HEX_START_ROW; // display row Header Display_String( HEX_HEADER_STR, row, column ); // display all data of requested bank i = startAddr; row++; for ( ; row < (HEX_MAX_ROWS + HEX_START_ROW); row++ ) { // identify row start address Display_Data( i, 1, row, column ); // dump first 8 bytes of row data for ( colIndex = 1; colIndex <= HEX_MAX_BYTES / 2; colIndex++ ) { Display_Data( OnChipData[ i++ ], 1, row, column + (colIndex * 3) ); } // add row spacing Display_String( " ", row, column + colIndex * 3 ); colIndex++; // dump last 8 bytes of row; for ( ; colIndex <= (HEX_MAX_BYTES + 1); colIndex++ ) { Display_Data( OnChipData[ i++ ], 1, row, column + (colIndex * 3) ); } // display in ASCII for ( j = i - 16, k= 0; j < i; j++, k++ ) { if ( isprint( OnChipData[ j ] ) ) sprintf( &asciiStr[ k ],"%c", OnChipData[ j ] ); else sprintf( &asciiStr[ k ], "." ); } Display_String( asciiStr, row, HEX_ASCII_COLUMN ); } } void Show_Data( int varStart, int varEnd, int hexBank ) { int varIndex; // display variables by name for ( varIndex = varStart; varIndex < varEnd; varIndex++ ) { show_variable( varIndex, varStart ); } // dump all data for given bank if ( hexBank == 0 ) show_hex_dump( HEX_DUMP_BK0_START ); else if ( hexBank == 1 ) show_hex_dump( HEX_DUMP_BK1_START ); // else don't display it! }