Beispiel #1
0
void initialize()
{
	initscr();
	cbreak();
	curs_set(0);
	keypad(stdscr, TRUE);
	
	start_color();
	init_pair(1, COLOR_BLACK, COLOR_GREEN);

	refresh();

	WINDOW* mem_win, *reg_win, *cns_win, *dbg_win;

	mem_win = create_win(LINES-DEBUGWIN_HEIGHT, COLS-REGWIN_WIDTH, 0, 0);
	reg_win = create_win(REGWIN_HEIGHT, REGWIN_WIDTH, 0, COLS-REGWIN_WIDTH);
	cns_win = create_win(LINES-REGWIN_HEIGHT-DEBUGWIN_HEIGHT, REGWIN_WIDTH, REGWIN_HEIGHT, COLS-REGWIN_WIDTH);
	dbg_win = create_win(DEBUGWIN_HEIGHT, COLS, LINES-DEBUGWIN_HEIGHT, 0);

	wprintw(mem_win, "Memory Viewer");
	wprintw(reg_win, "Registers");
	wprintw(cns_win, "Console");
	wprintw(dbg_win, "Debugging");
	
	dbgwin_state = 0;
	memwin_state = 0;
	cnswin_state = 0;

	console = (char*)malloc(CONSOLE_SIZE);
	cns_index = 0;
	cns_max = CONSOLE_SIZE;

	refreshall();
}
Beispiel #2
0
/********************************************************\
 * Description:	Similar to popupWin, only it prmpts the	*
 *		user for a character, such as (y/n)	*
 * Returns:	Returns character pressed		*
\********************************************************/
short int questionWin(char *msg)
{
    WINDOW *tmpwin;
    short int ch;

    int y = (LINES / 2) - 3,				/* calc location      */
        len = strlen(msg),
        x = (COLS - len)/2;

    y = (y < 2) ? 2 : y;				/* minimum height     */

    tmpwin = drawbox(y, x, 5, len + 6);			/* create window      */

    mvwprintw(tmpwin,2,3, msg);
    wmove(tmpwin,2,len+4);
    wrefresh(tmpwin);

    ch = wgetch(tmpwin);

    delwin(tmpwin);

    wtouchln(windows->hex, y - 1, 5, 1);		/* touch the lines    */
    wtouchln(windows->ascii, y - 1, 5, 1);		/* covered by win     */
    wtouchln(windows->address, y - 1, 5, 1);
    wtouchln(windows->hex_outline, y, 5, 1);
    wtouchln(windows->ascii_outline, y, 5, 1);
    wtouchln(windows->scrollbar, y, 5, 1);

    refreshall(windows);				/* refresh all wins   */

    doupdate();

    return ch;
}
Beispiel #3
0
void wait_for_key(int print)
{
	refreshall();
	char ch;
	while(!(ch=getch()));
	regfile[0] = (short)ch;
	if (print) send_to_console(ch);
}
Beispiel #4
0
/******************************************************\
 * Description:	Clears the entire screen              *
\******************************************************/
void clearScreen(WINS *win)
{
    wclear(win->hex);
    wclear(win->ascii);
    wclear(win->address);
    wclear(win->scrollbar);
    wclear(win->hex_outline);
    wclear(win->ascii_outline);
    wclear(win->cur_address);
    refreshall(win);
    doupdate();
}
Beispiel #5
0
void update_dbgwin()
{
	int i, j;
	char goaddr[6];
	char realaddr[7];
	for (i=0; i<DEBUGWIN_HEIGHT-WINDOW_PADDING*2; i++)
		for (j=0; j<COLS-WINDOW_PADDING*2; j++)
			mvwprintw(DBGWIN, i+WINDOW_PADDING, j+WINDOW_PADDING, " ");
	switch (dbgwin_state) {
	case 0:
		mvwprintw(DBGWIN, WINDOW_PADDING, WINDOW_PADDING, "F5 - Step | F6 - Run | F7 - Memory Explorer | F1 - Exit");
		break;
	case 1:
		dbggetstrw(WINDOW_PADDING, WINDOW_PADDING, "Goto address: ", goaddr);
		realaddr[0] = '0';
		strcpy(&realaddr[1], goaddr);
		sscanf(realaddr, "%x", &mem_index);
		dbgwin_state = 0;
		if (!memwin_state)
			memwin_state = 1;
		else if (memwin_state == 2)
			mem_cursor = mem_index;
		refreshall();
		break;
	case 2:
		dbggetstrw(WINDOW_PADDING, WINDOW_PADDING, "New value: ", goaddr);
		realaddr[0] = '0';
		strcpy(&realaddr[1], goaddr);
		short a;
		sscanf(realaddr, "%x", &a);
		mem[mem_cursor] = a;
		dbgwin_state = 0;
		refreshall();
		break;
	}
}
Beispiel #6
0
/******************************************************\
 * Description:	Creates a "window popup" where given  *
 * 		the parameters, and message, it       *
 * 		creates a window and displays the     *
 * 		message.  Some current restrictions   *
 * 		are that it must only be one line, and*
 * 		it is assumed that the text is padded *
 * 		with one space left for the border and*
 * 		another space left for aesthetics     *
\******************************************************/
void popupWin(char *msg, int time)
{
    WINDOW *tmpwin;

    int y = (LINES / 2) - 3,				/* calc location      */
        len = strlen(msg),
        x = (COLS - len)/2;

    y = (y < 2) ? 2 : y;				/* minimum height     */
    time = (!time) ? 2 : time;

    tmpwin = drawbox(y, x, 5, len + 6);			/* create window      */

    keypad(tmpwin, TRUE);

    mvwprintw(tmpwin,2,3, msg);				/* output mesg        */
    wmove(tmpwin,2,len+4);
    wrefresh(tmpwin);

    if (time == -1)
        wgetch(tmpwin);
    else
        sleep(time);					/* wait               */

    delwin(tmpwin);

    wtouchln(windows->hex, y - 1, 5, 1);		/* touch windows      */
    wtouchln(windows->ascii, y - 1, 5, 1);
    wtouchln(windows->address, y - 1, 5, 1);
    wtouchln(windows->hex_outline, y, 5, 1);
    wtouchln(windows->ascii_outline, y, 5, 1);
    wtouchln(windows->scrollbar, y, 5, 1);

    refreshall(windows);				/* refresh all wins   */

    doupdate();
}
Beispiel #7
0
int main(int argc, char* argv[])
{
	if (argc != 2)
	{
		printf("Bad argument! Just give me a filename of a compiled assembly program.\n");
		return -EINVAL;
	}

	enable_udiv = 1;

	FILE* program;
	if (!(program = fopen(argv[1], "r")))
	{
		printf("Bad argument! File not found.\n");
		return -EINVAL;
	}

	build_symbol_table(argv[1]);

	pc = 0x3000;
	running = 1;
	read_program(program);

	int ch;
	initialize();

	while(ch != KEY_F(1))
	{
		ch = getch();
		switch (ch) {
		case KEY_F(2):
			reset_program(program);
			break;
		case KEY_F(3):
			dbgwin_state = 1;
			break;
		case KEY_F(4):
			break;
		case KEY_F(5):
			step_forward();
			break;
		case KEY_F(6):
			run_program();
			break;
		case KEY_F(7):
			memwin_state = (memwin_state == 2 ? 0 : 2);
			mem_cursor = mem_index;
			break;
		case KEY_F(8):
			dbgwin_state = 2;
			break;
		case KEY_UP:
			if (memwin_state == 2)
				mem_cursor--;
			break;
		case KEY_DOWN:
			if (memwin_state == 2)
				mem_cursor++;
			break;
		case KEY_NPAGE:
			if (memwin_state == 2)
				mem_cursor += (LINES-DEBUGWIN_HEIGHT);
			break;
		case KEY_PPAGE:
			if (memwin_state == 2)
				mem_cursor -= (LINES-DEBUGWIN_HEIGHT);
			break;
		case 0xA:
			if (memwin_state ==2)
				brk[(unsigned short)mem_cursor] ^= 1;
			break;
		}
		refreshall();
	}
quit:
	curs_set(1);
	endwin();
	return 0;
}
Beispiel #8
0
int main(int argc, char *argv[])			/* main program       */
{

    int   x, retval = 1;			/* counters, etc.     */
    off_t val, len;					/* len need to be off_t*/

    windows = (WINS *) calloc(1, sizeof(WINS));	/* malloc windows     */
    head = llalloc();							/* malloc list space  */
    fpINfilename = NULL;			/* allocate in and    */
    fpOUTfilename = NULL;			/* out file name ptrs */
    printHex = TRUE;							/* address format     */
    USE_EBCDIC = FALSE;							/*use ascii by default*/

							/* get cmd line args  */
    len = parseArgs(argc, argv);
    MIN_ADDR_LENGTH = getMinimumAddressLength(len);

    use_env(TRUE);					/* use env values     */
    slk_init(0);					/* init menu bar      */
    init_screen();					/* init visuals       */
    init_colors();

    if ((COLS < MIN_COLS) || (LINES < MIN_LINES))	/* screen's too small */
    {
	endwin();
	fprintf(stderr,"\n\nThe screen size too small.\nThe minimum allowable");
	fprintf(stderr," screen size is %dx%d\n\n", MIN_COLS, MIN_LINES + 1);
	exit(-1);
    }
    
    slk_set(6, (printHex) ? "Hex Addr":"Dec Addr", 1);
    init_fkeys();					/* define menu bar    */
    

    while (retval)
    {
	free_windows(windows);
        
	/* calculate screen   */
	BASE                = (resize > 0 && resize < COLS) ? resize:((COLS-6-MIN_ADDR_LENGTH)/4);
	MAXY                = (LINES) - 3;
	hex_win_width       = BASE * 3;
	ascii_win_width     = BASE;
	hex_outline_width   = (BASE * 3) + 3 + MIN_ADDR_LENGTH;
	ascii_outline_width = BASE + 2;
            
	init_menu(windows);				/* init windows       */
	head = freeList(head);				/* free & init head   */
							/* print origin loc   */
	mvwprintw(windows->hex_outline, 0, 1, "%0*d", MIN_ADDR_LENGTH, 0);
    
	if (fpIN != NULL)				/* if no infile...    */
	{
            len = maxLoc(fpIN);				/* get last file loc  */
	    val = maxLines(len); 			/* max file lines     */
            for (x = 0; x <= MAXY && x<=val; x++)       /* output lines       */
		outline(fpIN, x);
	}

	wmove(windows->hex, 0, 0);			/* cursor to origin   */
    
	refreshall(windows);				/* refresh all wins   */
	doupdate();					/* update screen      */
        
	mvwaddch(windows->scrollbar, 1, 0, ACS_CKBOARD);/* clear scroller     */
							/* get user input     */
	retval = wacceptch(windows, len); 
    }
    
    free(fpINfilename);
    free(fpOUTfilename);
    freeList(head);
    
    screen_exit(0);					/* end visualizations */
    return retval;					/* return             */
}
Beispiel #9
0
/******************************************************\
 * Description:	Determines the screen size of the the *
 *		terminal and prompts for the user to  *
 *		change the screen.		      *
\******************************************************/
RETSIGTYPE checkScreenSize(int sig)
{   
    int count;
    
    /* Avoid unused variable warning */
    UNUSED(sig);

    clearScreen(windows);
    endwin();
    init_screen();                                      /* init visuals       */

    slk_clear();                                        /* init menu bar      */
    slk_restore();                                      /* restore bottom menu*/
    slk_noutrefresh();
    doupdate();
							/* recacl these values*/
    BASE                =   (COLS - 6 - MIN_ADDR_LENGTH) / 4;            /*base for the number */
    hex_outline_width   =   (BASE * 3) + 3 + MIN_ADDR_LENGTH;
    MAXY                =   LINES - 3;
    hex_win_width       =   BASE * 3;
    ascii_outline_width =   BASE + 2;
    ascii_win_width     =   BASE;
    maxlines		=   maxLines((fpIN != NULL) ? maxLoc(fpIN) : 0);
    currentLine		=   0;
    SIZE_CH		=   TRUE;
                                                        /* check for term size*/
    if ((COLS < MIN_COLS) || (LINES < MIN_LINES))	
    {    
	/*
        endwin();
        printf("\n\n\n\nscreen size too small\n");
        exit(0);
	*/

	init_fkeys();                                   /* define menu bar    */
	init_menu(windows);                             /* init windows       */
	clearScreen(windows);
	slk_clear();
	mvwprintw(windows->hex, 0, 0, "Your screen is too small");
	/*mvwprintw(windows->hex, 1, 2, "Resize it to continue");*/
	refreshall(windows);
	doupdate();
    }
    else
    {
	init_fkeys();                                   /* define menu bar    */
	init_menu(windows);                             /* init windows       */
	wmove(windows->hex,0,0);
	if (fpIN)					/* if a file is open  */
	{
	    for (count = 0; count <= MAXY && count <= maxLines(maxLoc(fpIN)); 
		 count++)
		outline(fpIN, count);

	    mvwprintw(windows->cur_address, 0, 0, "%0*d", MIN_ADDR_LENGTH, 0);
	    wmove(windows->hex,0,0);
	}

	refreshall(windows);
        wnoutrefresh(windows->cur_address);
	/* this next refresh is to put the cursor in the correct window */
        wnoutrefresh(windows->hex);
	doupdate();
    }
}