2024-01-23 13:33:04 +00:00
|
|
|
|
/* gui.c
|
|
|
|
|
|
|
|
|
|
This file is part of the "First" CPU simulator project.
|
|
|
|
|
|
|
|
|
|
Copyright (c) 2024 Efthymios Kritikos
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
|
#include <ncurses.h>
|
2024-01-23 17:38:44 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "simdata.h"
|
2024-01-29 12:48:53 +00:00
|
|
|
|
#include "assembly.h"
|
|
|
|
|
#include <stdlib.h>
|
2024-02-05 21:25:00 +00:00
|
|
|
|
#include "cpu.h"
|
2024-02-14 02:42:10 +00:00
|
|
|
|
#include <locale.h>
|
2024-01-22 12:11:07 +00:00
|
|
|
|
|
2024-01-26 16:11:57 +00:00
|
|
|
|
#define GENERAL_STACK_MAX_WIDTH 16
|
2024-01-29 12:48:53 +00:00
|
|
|
|
#define GENERAL_DISAS_WIDTH 41
|
2024-01-26 16:11:57 +00:00
|
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
|
int terminal_width;
|
|
|
|
|
int terminal_height;
|
|
|
|
|
|
|
|
|
|
WINDOW *tabs;
|
2024-01-23 19:35:57 +00:00
|
|
|
|
WINDOW *general_memdump;
|
2024-01-26 16:11:57 +00:00
|
|
|
|
WINDOW *general_stack;
|
2024-01-29 12:48:53 +00:00
|
|
|
|
WINDOW *general_disas;
|
2024-02-05 21:25:00 +00:00
|
|
|
|
WINDOW *general_registers;
|
2024-02-13 21:28:42 +00:00
|
|
|
|
WINDOW *general_terminal_output;
|
2024-01-22 12:11:07 +00:00
|
|
|
|
|
2024-01-23 13:33:04 +00:00
|
|
|
|
int monochrome;
|
|
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
|
int get_terminal_size(){
|
|
|
|
|
int new_height,new_width;
|
|
|
|
|
getmaxyx(stdscr,new_height,new_width);
|
|
|
|
|
int changed=(new_width!=terminal_width)||(new_height!=terminal_height);
|
|
|
|
|
terminal_width=new_width;
|
|
|
|
|
terminal_height=new_height;
|
|
|
|
|
return changed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int gui_ncurses_refresh(){
|
|
|
|
|
if(refresh()==ERR)
|
|
|
|
|
return 1;
|
|
|
|
|
if(wrefresh(tabs)==ERR)
|
|
|
|
|
return 1;
|
2024-01-23 19:35:57 +00:00
|
|
|
|
if(wrefresh(general_memdump)==ERR)
|
|
|
|
|
return 1;
|
2024-01-26 16:11:57 +00:00
|
|
|
|
if(wrefresh(general_stack)==ERR)
|
|
|
|
|
return 1;
|
2024-01-29 12:48:53 +00:00
|
|
|
|
if(wrefresh(general_disas)==ERR)
|
|
|
|
|
return 1;
|
2024-02-05 21:25:00 +00:00
|
|
|
|
if(wrefresh(general_registers)==ERR)
|
|
|
|
|
return 1;
|
2024-02-13 21:28:42 +00:00
|
|
|
|
if(wrefresh(general_terminal_output)==ERR)
|
|
|
|
|
return 1;
|
2024-01-22 12:11:07 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-23 19:35:57 +00:00
|
|
|
|
char *tab_name[]={"Overview","Memory","Internal"};
|
2024-01-23 17:38:44 +00:00
|
|
|
|
|
|
|
|
|
unsigned int CURRENT_TAB=0;
|
|
|
|
|
|
2024-02-06 23:14:33 +00:00
|
|
|
|
enum GUI_CPU_STATE_t CPU_STATE=GUI_CPU_SINGLE_STEPPING;
|
2024-01-23 17:38:44 +00:00
|
|
|
|
|
|
|
|
|
void update_tabs(){
|
2024-01-26 16:11:57 +00:00
|
|
|
|
wattron(tabs,A_BOLD);
|
2024-01-23 17:38:44 +00:00
|
|
|
|
wattron(tabs,COLOR_PAIR(2));
|
|
|
|
|
for(int i=0;i<terminal_width;i++)
|
2024-01-23 19:35:57 +00:00
|
|
|
|
mvwprintw(tabs,0,i," ");
|
2024-01-23 17:38:44 +00:00
|
|
|
|
|
2024-01-23 19:35:57 +00:00
|
|
|
|
int x=2;
|
2024-01-23 17:38:44 +00:00
|
|
|
|
for(unsigned int i=0;i<sizeof(tab_name)/sizeof(tab_name[0]);i++){
|
|
|
|
|
if(i==CURRENT_TAB)
|
|
|
|
|
wattron(tabs,COLOR_PAIR(4));
|
|
|
|
|
else
|
|
|
|
|
wattron(tabs,COLOR_PAIR(5));
|
|
|
|
|
mvwprintw(tabs,0,x," %1d",i);
|
|
|
|
|
x+=2;
|
|
|
|
|
if(i==CURRENT_TAB)
|
|
|
|
|
wattron(tabs,COLOR_PAIR(3));
|
2024-01-26 16:11:57 +00:00
|
|
|
|
else{
|
2024-01-23 17:38:44 +00:00
|
|
|
|
wattron(tabs,COLOR_PAIR(2));
|
2024-01-26 16:11:57 +00:00
|
|
|
|
wattroff(tabs,A_BOLD);
|
|
|
|
|
}
|
2024-01-23 17:38:44 +00:00
|
|
|
|
mvwprintw(tabs,0,x," %s ",tab_name[i]);
|
2024-01-26 16:11:57 +00:00
|
|
|
|
wattron(tabs,A_BOLD);
|
2024-01-23 17:38:44 +00:00
|
|
|
|
x+=strlen(tab_name[i])+2+3;
|
|
|
|
|
}
|
|
|
|
|
switch(CPU_STATE){
|
2024-02-06 23:14:33 +00:00
|
|
|
|
case GUI_CPU_RUNNING:
|
2024-01-23 17:38:44 +00:00
|
|
|
|
wattron(tabs,COLOR_PAIR(6));
|
|
|
|
|
mvwprintw(tabs,0,terminal_width-13,"[ RUNNING ");
|
|
|
|
|
break;
|
2024-02-06 23:14:33 +00:00
|
|
|
|
case GUI_CPU_SINGLE_STEPPING:
|
2024-01-23 17:38:44 +00:00
|
|
|
|
wattron(tabs,COLOR_PAIR(7));
|
|
|
|
|
mvwprintw(tabs,0,terminal_width-21,"[ SINGLE-STEPPING ");
|
|
|
|
|
break;
|
2024-02-06 23:14:33 +00:00
|
|
|
|
case GUI_CPU_STOPPED:
|
2024-01-23 17:38:44 +00:00
|
|
|
|
wattron(tabs,COLOR_PAIR(8));
|
|
|
|
|
mvwprintw(tabs,0,terminal_width-13,"[ STOPPED ");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
mvwprintw(tabs,0,terminal_width-3,"]");
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
|
int start_gui(){
|
2024-02-14 02:42:10 +00:00
|
|
|
|
setlocale(LC_ALL, "");
|
2024-01-22 12:11:07 +00:00
|
|
|
|
if(!initscr())
|
|
|
|
|
return 1;
|
2024-01-23 13:33:04 +00:00
|
|
|
|
monochrome=( has_colors() == FALSE );
|
2024-01-23 17:38:44 +00:00
|
|
|
|
init_color(8, 700, 700, 700);
|
|
|
|
|
init_color(COLOR_WHITE, 100, 1000, 1000);
|
2024-01-23 13:33:04 +00:00
|
|
|
|
if(!monochrome){
|
|
|
|
|
start_color();
|
|
|
|
|
init_pair(1, COLOR_RED, COLOR_BLACK);
|
2024-01-23 17:38:44 +00:00
|
|
|
|
|
|
|
|
|
//tab colors
|
|
|
|
|
init_pair(2, COLOR_BLACK, 8);
|
|
|
|
|
init_pair(3, 8, COLOR_BLACK);
|
|
|
|
|
init_pair(4, COLOR_WHITE, COLOR_BLACK);
|
|
|
|
|
init_pair(5, COLOR_WHITE, 8);
|
|
|
|
|
init_pair(6, COLOR_BLACK,COLOR_GREEN);
|
|
|
|
|
init_pair(7, COLOR_BLACK,COLOR_YELLOW);
|
|
|
|
|
init_pair(8, COLOR_BLACK,COLOR_RED);
|
2024-02-07 00:31:23 +00:00
|
|
|
|
|
|
|
|
|
//cpu instruction pipline location colors
|
|
|
|
|
init_pair(9, COLOR_MAGENTA,COLOR_BLACK); //fetch
|
|
|
|
|
init_pair(10, COLOR_YELLOW,COLOR_BLACK); //decode
|
|
|
|
|
init_pair(11, COLOR_GREEN,COLOR_BLACK); //exec
|
|
|
|
|
init_pair(12, COLOR_BLACK,COLOR_MAGENTA); //fetch
|
|
|
|
|
init_pair(13, COLOR_BLACK,COLOR_YELLOW); //decode
|
|
|
|
|
init_pair(14, COLOR_BLACK,COLOR_GREEN); //exec
|
2024-01-23 13:33:04 +00:00
|
|
|
|
}
|
2024-01-23 16:06:28 +00:00
|
|
|
|
noecho();
|
2024-01-22 12:11:07 +00:00
|
|
|
|
curs_set(0);
|
|
|
|
|
get_terminal_size();
|
|
|
|
|
mvprintw((terminal_height-3)/2+3,terminal_width/2-15,"Initialising the simulator...");
|
2024-01-23 17:38:44 +00:00
|
|
|
|
tabs = newwin(1,terminal_width,0,0);
|
|
|
|
|
update_tabs();
|
2024-01-29 12:48:53 +00:00
|
|
|
|
int len;
|
2024-02-05 21:25:00 +00:00
|
|
|
|
|
2024-02-13 21:28:42 +00:00
|
|
|
|
int y1_divider,y2_divider;
|
2024-02-05 21:25:00 +00:00
|
|
|
|
|
|
|
|
|
int border=4;
|
|
|
|
|
|
2024-02-13 21:28:42 +00:00
|
|
|
|
if( (terminal_height-2*border-1)*0.2 < 8 )
|
2024-02-05 21:25:00 +00:00
|
|
|
|
y1_divider=terminal_height-border-8;
|
|
|
|
|
else if ( ( terminal_height - 2*border )*0.2 < 15 )
|
|
|
|
|
y1_divider=terminal_height-border-11;
|
|
|
|
|
else
|
|
|
|
|
y1_divider=(terminal_height-border*2)*0.8;
|
|
|
|
|
|
2024-02-13 21:28:42 +00:00
|
|
|
|
y2_divider=(3*(terminal_height-2*border-1)/4);
|
|
|
|
|
|
2024-02-05 21:25:00 +00:00
|
|
|
|
int x=border;
|
2024-02-13 21:28:42 +00:00
|
|
|
|
int middle;
|
2024-02-05 21:25:00 +00:00
|
|
|
|
|
|
|
|
|
general_memdump=newwin(y1_divider,terminal_width/2,x,border);
|
2024-01-26 16:11:57 +00:00
|
|
|
|
x+=terminal_width/2;
|
2024-01-29 12:48:53 +00:00
|
|
|
|
x++;
|
|
|
|
|
|
|
|
|
|
x+=3;
|
2024-02-13 21:28:42 +00:00
|
|
|
|
middle=x;
|
2024-01-29 12:48:53 +00:00
|
|
|
|
len=(terminal_width/6)>GENERAL_DISAS_WIDTH?GENERAL_DISAS_WIDTH:(terminal_width/6);
|
2024-02-13 21:28:42 +00:00
|
|
|
|
general_disas=newwin(y2_divider,len,4,x);
|
2024-01-29 12:48:53 +00:00
|
|
|
|
x+=len;
|
2024-01-26 16:11:57 +00:00
|
|
|
|
|
|
|
|
|
x+=3;
|
2024-01-29 12:48:53 +00:00
|
|
|
|
len=(terminal_width/6)>GENERAL_STACK_MAX_WIDTH?GENERAL_STACK_MAX_WIDTH:(terminal_width/6);
|
2024-02-13 21:28:42 +00:00
|
|
|
|
general_stack=newwin(y2_divider,len,4,x);
|
2024-01-26 16:11:57 +00:00
|
|
|
|
x+=len;
|
|
|
|
|
|
2024-02-05 21:25:00 +00:00
|
|
|
|
general_registers=newwin(terminal_height-y1_divider-border-1,terminal_width/2,y1_divider+border+1,border);
|
|
|
|
|
x+=terminal_width/2;
|
|
|
|
|
x++;
|
|
|
|
|
|
2024-02-13 21:28:42 +00:00
|
|
|
|
general_terminal_output=newwin(terminal_height-y2_divider-border-1,terminal_width/2-3*border,y2_divider+border+1,middle);
|
|
|
|
|
scrollok(general_terminal_output,TRUE);
|
|
|
|
|
x+=terminal_width/2;
|
|
|
|
|
x++;
|
|
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
|
if(gui_ncurses_refresh())
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-13 21:28:42 +00:00
|
|
|
|
|
2024-01-23 13:33:04 +00:00
|
|
|
|
int gui_error(char *str){
|
|
|
|
|
WINDOW *error_win = newwin(3,40,terminal_height/2-1,terminal_width/2-20);
|
|
|
|
|
box(error_win, 0 , 0);
|
|
|
|
|
if(!monochrome)
|
|
|
|
|
wattron(error_win,COLOR_PAIR(1));
|
|
|
|
|
mvwprintw(error_win,1,1,"%s",str);
|
|
|
|
|
if(wrefresh(error_win)==ERR)
|
|
|
|
|
return 1;
|
|
|
|
|
getch();
|
|
|
|
|
delwin(error_win);
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if(!monochrome)
|
|
|
|
|
wattroff(error_win,COLOR_PAIR(1));
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-13 21:28:42 +00:00
|
|
|
|
//// WARNING!! THIS ASSUMES THAT ADDRESS IS CORRECTLY ALIGNED WITH THE INSTRUCTION START/END!!
|
2024-02-07 00:31:23 +00:00
|
|
|
|
int select_instruction_color(struct simdata_t *simdata, WINDOW* window,uint32_t ADDRESS, int applyremove){
|
|
|
|
|
if(simdata->cpu_gui_hints){
|
|
|
|
|
struct instr_list_t* pointer;
|
|
|
|
|
pointer=simdata->cpu_gui_hints->fetching_list;
|
|
|
|
|
while(pointer!=NULL){
|
|
|
|
|
if(pointer->address==ADDRESS){
|
|
|
|
|
if(applyremove)
|
|
|
|
|
wattron(window,COLOR_PAIR(9));
|
|
|
|
|
else
|
|
|
|
|
wattroff(window,COLOR_PAIR(9));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
pointer=pointer->next;
|
|
|
|
|
}
|
|
|
|
|
pointer=simdata->cpu_gui_hints->decoding_list;
|
|
|
|
|
while(pointer!=NULL){
|
|
|
|
|
if(pointer->address==ADDRESS){
|
|
|
|
|
if(applyremove)
|
|
|
|
|
wattron(window,COLOR_PAIR(10));
|
|
|
|
|
else
|
|
|
|
|
wattroff(window,COLOR_PAIR(10));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
pointer=pointer->next;
|
|
|
|
|
}
|
|
|
|
|
pointer=simdata->cpu_gui_hints->executing_list;
|
|
|
|
|
while(pointer!=NULL){
|
|
|
|
|
if(pointer->address==ADDRESS){
|
|
|
|
|
if(applyremove)
|
|
|
|
|
wattron(window,COLOR_PAIR(11));
|
|
|
|
|
else
|
|
|
|
|
wattroff(window,COLOR_PAIR(11));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
pointer=pointer->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 12:48:53 +00:00
|
|
|
|
int update_general_disas(struct simdata_t *simdata){
|
2024-02-03 23:49:45 +00:00
|
|
|
|
werase(general_disas);
|
2024-01-29 12:48:53 +00:00
|
|
|
|
int width,height;
|
|
|
|
|
getmaxyx(general_disas,height,width);
|
|
|
|
|
box(general_disas, 0 , 0);
|
2024-02-12 14:16:41 +00:00
|
|
|
|
mvwprintw(general_disas,0,width/2-7,"[ DISASSEMBLY ]");
|
|
|
|
|
if(simdata->registers==NULL||simdata->RAM==NULL){
|
|
|
|
|
mvwprintw(general_disas,1,1,"Data not initialised");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2024-01-29 12:48:53 +00:00
|
|
|
|
int offset_arrow;
|
2024-02-07 00:31:23 +00:00
|
|
|
|
|
|
|
|
|
int have_legend=(width>29);
|
|
|
|
|
|
|
|
|
|
int usable_height=height-2-have_legend;
|
|
|
|
|
|
2024-01-29 12:48:53 +00:00
|
|
|
|
if(width<41)
|
|
|
|
|
offset_arrow=2;
|
|
|
|
|
else
|
|
|
|
|
offset_arrow=3;
|
|
|
|
|
if(width<18){
|
|
|
|
|
mvwprintw(general_disas,1,1,"too small window");
|
|
|
|
|
}else{
|
2024-02-12 14:16:41 +00:00
|
|
|
|
uint32_t ADDRESS=(simdata->registers->PC-(usable_height/2-2)*4)&0x00FFFFFF;
|
2024-02-07 00:31:23 +00:00
|
|
|
|
for (int i=2;i<usable_height;i++){
|
2024-01-29 12:48:53 +00:00
|
|
|
|
int overall_offset=offset_arrow-2;
|
|
|
|
|
|
|
|
|
|
mvwaddch(general_disas,i,11+overall_offset,ACS_VLINE);
|
|
|
|
|
|
2024-02-12 14:16:41 +00:00
|
|
|
|
if(ADDRESS==simdata->registers->PC)
|
2024-01-29 12:48:53 +00:00
|
|
|
|
wattron(general_disas,A_BOLD);
|
|
|
|
|
mvwprintw(general_disas,i,4+overall_offset,"%06X",ADDRESS);
|
|
|
|
|
char* disas=disassemble(*(uint32_t*)(simdata->RAM+ADDRESS));
|
|
|
|
|
int space_left=width-14-2+(overall_offset?0:1);
|
|
|
|
|
if(space_left<25)
|
|
|
|
|
disas[space_left+1]=0;
|
2024-02-07 00:31:23 +00:00
|
|
|
|
|
|
|
|
|
select_instruction_color(simdata,general_disas,ADDRESS,1);
|
2024-01-29 12:48:53 +00:00
|
|
|
|
mvwprintw(general_disas,i,13+overall_offset,"%s",disas);
|
2024-02-07 00:31:23 +00:00
|
|
|
|
select_instruction_color(simdata,general_disas,ADDRESS,0);
|
|
|
|
|
|
2024-02-12 14:16:41 +00:00
|
|
|
|
if(ADDRESS==simdata->registers->PC)
|
2024-01-29 12:48:53 +00:00
|
|
|
|
wattroff(general_disas,A_BOLD);
|
|
|
|
|
|
2024-01-31 18:28:36 +00:00
|
|
|
|
ADDRESS=(ADDRESS+4)&0xFFFFFF;
|
2024-01-29 12:48:53 +00:00
|
|
|
|
free(disas);
|
|
|
|
|
}
|
2024-02-07 00:31:23 +00:00
|
|
|
|
mvwaddch(general_disas,usable_height/2,offset_arrow,ACS_RARROW);
|
|
|
|
|
mvwaddch(general_disas,usable_height/2,offset_arrow-1,ACS_ULCORNER);
|
|
|
|
|
mvwaddch(general_disas,usable_height/2+1,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
mvwaddch(general_disas,usable_height/2+2,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
mvwaddch(general_disas,usable_height/2+3,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
mvwaddch(general_disas,usable_height/2+4,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
mvwaddch(general_disas,usable_height/2+5,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
mvwaddch(general_disas,usable_height/2+6,offset_arrow-1,'P');
|
2024-01-29 12:48:53 +00:00
|
|
|
|
if(offset_arrow==2)
|
2024-02-07 00:31:23 +00:00
|
|
|
|
mvwaddch(general_disas,usable_height/2+7,offset_arrow-1,'C');
|
2024-01-29 12:48:53 +00:00
|
|
|
|
else
|
2024-02-07 00:31:23 +00:00
|
|
|
|
mvwaddch(general_disas,usable_height/2+6,offset_arrow,'C');
|
|
|
|
|
if(have_legend){
|
|
|
|
|
wattron(general_disas,COLOR_PAIR(12));
|
|
|
|
|
mvwprintw(general_disas,height-2,2," ");
|
|
|
|
|
wattroff(general_disas,COLOR_PAIR(12));
|
|
|
|
|
mvwprintw(general_disas,height-2,4,"=Fetch");
|
|
|
|
|
|
|
|
|
|
wattron(general_disas,COLOR_PAIR(13));
|
|
|
|
|
mvwprintw(general_disas,height-2,11," ");
|
|
|
|
|
wattroff(general_disas,COLOR_PAIR(13));
|
|
|
|
|
mvwprintw(general_disas,height-2,13,"=Decode");
|
|
|
|
|
|
|
|
|
|
wattron(general_disas,COLOR_PAIR(14));
|
|
|
|
|
mvwprintw(general_disas,height-2,21," ");
|
|
|
|
|
wattroff(general_disas,COLOR_PAIR(14));
|
|
|
|
|
mvwprintw(general_disas,height-2,23,"=Exec");
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 12:48:53 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 16:11:57 +00:00
|
|
|
|
int update_general_stack(struct simdata_t *simdata){
|
|
|
|
|
int width,height;
|
|
|
|
|
getmaxyx(general_stack,height,width);
|
|
|
|
|
box(general_stack, 0 , 0);
|
|
|
|
|
mvwprintw(general_stack,0,width/2-4,"[ STACK ]");
|
2024-02-12 14:16:41 +00:00
|
|
|
|
if(simdata->registers==NULL||simdata->RAM==NULL){
|
|
|
|
|
mvwprintw(general_stack,1,1,"Data not initialised");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2024-01-26 16:11:57 +00:00
|
|
|
|
if(width<13){
|
|
|
|
|
mvwprintw(general_stack,1,1,"too small window");
|
|
|
|
|
}else{
|
|
|
|
|
// Calculate config based on window size
|
|
|
|
|
int offset_data,offset_arrow;
|
|
|
|
|
if(width<14){
|
|
|
|
|
offset_data=3;
|
|
|
|
|
offset_arrow=2;
|
|
|
|
|
}else{
|
|
|
|
|
offset_data=5;
|
|
|
|
|
offset_arrow=3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// draw data
|
2024-02-12 14:16:41 +00:00
|
|
|
|
uint32_t ADDRESS=(simdata->registers->SP-(height/2-2)*4)&0x00FFFFFF;
|
2024-01-26 16:11:57 +00:00
|
|
|
|
|
|
|
|
|
for(int i=0;i<height-4;i++){
|
2024-02-12 14:16:41 +00:00
|
|
|
|
if(ADDRESS==simdata->registers->SP)
|
2024-01-26 16:11:57 +00:00
|
|
|
|
wattron(general_stack,A_BOLD);
|
|
|
|
|
mvwprintw(general_stack,i+2,offset_data,"%08X",*(uint32_t*)(simdata->RAM+ADDRESS));
|
2024-02-12 14:16:41 +00:00
|
|
|
|
if(ADDRESS==simdata->registers->SP)
|
2024-01-26 16:11:57 +00:00
|
|
|
|
wattroff(general_stack,A_BOLD);
|
|
|
|
|
ADDRESS=(ADDRESS+4)&0xFFFFFF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// draw graphics
|
|
|
|
|
mvwaddch(general_stack,height/4-2,offset_arrow-1,ACS_UARROW);
|
|
|
|
|
mvwaddch(general_stack,height/4-1,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
mvwaddch(general_stack,height/4 ,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
mvwaddch(general_stack,height/4+1,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
if(offset_arrow!=2)
|
|
|
|
|
mvwprintw(general_stack,height/4+2,1,"(+)");
|
|
|
|
|
else
|
|
|
|
|
mvwprintw(general_stack,height/4+2,offset_arrow-1,"+");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mvwaddch(general_stack,height/2,offset_arrow,ACS_RARROW);
|
|
|
|
|
mvwaddch(general_stack,height/2,offset_arrow-1,ACS_ULCORNER);
|
|
|
|
|
|
|
|
|
|
mvwaddch(general_stack,height/2+1,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
mvwaddch(general_stack,height/2+2,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
mvwaddch(general_stack,height/2+3,offset_arrow-1,ACS_VLINE);
|
|
|
|
|
mvwaddch(general_stack,height/2+4,offset_arrow-1,'S');
|
|
|
|
|
if(offset_arrow==2)
|
|
|
|
|
mvwaddch(general_stack,height/2+5,offset_arrow-1,'P');
|
|
|
|
|
else
|
|
|
|
|
mvwaddch(general_stack,height/2+4,offset_arrow,'P');
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-23 19:35:57 +00:00
|
|
|
|
int update_general_memdump(struct simdata_t *simdata){
|
|
|
|
|
int width,height;
|
|
|
|
|
getmaxyx(general_memdump,height,width);
|
|
|
|
|
box(general_memdump, 0 , 0);
|
|
|
|
|
mvwprintw(general_memdump,0,terminal_width/4-6,"[ MEMDUMP ]");
|
2024-02-12 14:16:41 +00:00
|
|
|
|
if(simdata->registers==NULL||simdata->RAM==NULL){
|
|
|
|
|
mvwprintw(general_memdump,1,1,"Data not initialised");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2024-01-23 19:35:57 +00:00
|
|
|
|
if(width<16){
|
|
|
|
|
mvwprintw(general_memdump,1,1,"too small window");
|
|
|
|
|
}else{
|
2024-01-23 23:56:40 +00:00
|
|
|
|
int n=(width-12)/4; // bytes in each line
|
|
|
|
|
int usable_height=height-3-(width-12)%2;
|
|
|
|
|
|
2024-02-12 14:16:41 +00:00
|
|
|
|
uint32_t ADDRESS=(simdata->registers->PC-n*usable_height/2)&0x00FFFFFF;
|
2024-02-07 00:31:23 +00:00
|
|
|
|
|
|
|
|
|
uint32_t color_addr;
|
|
|
|
|
int have_color;
|
2024-01-23 23:56:40 +00:00
|
|
|
|
for(int h=0;h<usable_height;h++){
|
2024-01-23 19:35:57 +00:00
|
|
|
|
wmove(general_memdump,h+2,2+(width-12)%2);
|
2024-01-29 13:21:56 +00:00
|
|
|
|
wattroff(general_memdump,A_BOLD);
|
2024-01-23 19:35:57 +00:00
|
|
|
|
wprintw(general_memdump,"%06x ",ADDRESS);
|
|
|
|
|
uint32_t temp_address=ADDRESS;
|
2024-01-26 12:24:43 +00:00
|
|
|
|
for (int i=0;i<n;i++){
|
2024-02-12 14:16:41 +00:00
|
|
|
|
if(ADDRESS>=simdata->registers->PC&&ADDRESS<=simdata->registers->PC+3)
|
2024-01-29 13:21:56 +00:00
|
|
|
|
wattron(general_memdump,A_BOLD);
|
|
|
|
|
else
|
|
|
|
|
wattroff(general_memdump,A_BOLD);
|
2024-02-07 00:31:23 +00:00
|
|
|
|
if(select_instruction_color(simdata,general_memdump,ADDRESS,1)==0){
|
|
|
|
|
have_color=5;
|
|
|
|
|
color_addr=ADDRESS;
|
|
|
|
|
}else if(have_color)
|
|
|
|
|
select_instruction_color(simdata,general_memdump,color_addr,1);
|
|
|
|
|
if(have_color){
|
|
|
|
|
have_color--;
|
|
|
|
|
if(!have_color)
|
|
|
|
|
select_instruction_color(simdata,general_memdump,color_addr,0);
|
|
|
|
|
}
|
2024-01-26 12:24:43 +00:00
|
|
|
|
wprintw(general_memdump,"%02x ",simdata->RAM[ADDRESS]);
|
|
|
|
|
ADDRESS=(ADDRESS+1)&0xFFFFFF;
|
|
|
|
|
}
|
2024-02-07 00:31:23 +00:00
|
|
|
|
if(have_color)
|
|
|
|
|
select_instruction_color(simdata,general_memdump,color_addr,0);
|
2024-01-26 12:24:43 +00:00
|
|
|
|
ADDRESS=temp_address;
|
2024-01-23 19:35:57 +00:00
|
|
|
|
for (int i=0;i<n;i++){
|
2024-02-12 14:16:41 +00:00
|
|
|
|
if(ADDRESS>=simdata->registers->PC&&ADDRESS<=simdata->registers->PC+3)
|
2024-01-29 13:21:56 +00:00
|
|
|
|
wattron(general_memdump,A_BOLD);
|
|
|
|
|
else
|
|
|
|
|
wattroff(general_memdump,A_BOLD);
|
2024-01-23 19:35:57 +00:00
|
|
|
|
wprintw(general_memdump,"%c",(simdata->RAM[ADDRESS]>=0x20&&simdata->RAM[ADDRESS]<0x7F)?simdata->RAM[ADDRESS]:'.');
|
2024-01-23 23:56:40 +00:00
|
|
|
|
ADDRESS=(ADDRESS+1)&0xFFFFFF;
|
2024-01-23 19:35:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-05 21:25:00 +00:00
|
|
|
|
int update_general_registers(struct simdata_t *simdata){
|
|
|
|
|
int width,height;
|
2024-02-06 17:43:17 +00:00
|
|
|
|
werase(general_registers);
|
2024-02-05 21:25:00 +00:00
|
|
|
|
getmaxyx(general_registers,height,width);
|
|
|
|
|
box(general_registers, 0 , 0);
|
|
|
|
|
mvwprintw(general_registers,0,terminal_width/4-7,"[ REGISTERS ]");
|
2024-02-12 14:16:41 +00:00
|
|
|
|
if(simdata->registers==NULL){
|
|
|
|
|
mvwprintw(general_registers,1,1,"Data not initialised");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2024-02-05 21:25:00 +00:00
|
|
|
|
if(simdata->registers==NULL)
|
|
|
|
|
mvwprintw(general_registers,1,1,"Registers data structure not initialised");
|
|
|
|
|
else{
|
|
|
|
|
int per_line=width/35;
|
|
|
|
|
if(per_line==0)
|
|
|
|
|
mvwprintw(general_registers,1,1,"too small window");
|
|
|
|
|
else{
|
|
|
|
|
int center_x_offset=((width-2)-35*per_line)/2;
|
|
|
|
|
int lines_used=(8/(int)per_line<8/(float)per_line)?8/per_line+1:8/per_line;
|
|
|
|
|
|
2024-02-12 15:15:54 +00:00
|
|
|
|
int lines_for_special_registers;
|
|
|
|
|
lines_for_special_registers=( width < 22+27+8 )?2:1;
|
|
|
|
|
|
|
|
|
|
int center_y_offset=((height-2)-(lines_used+lines_for_special_registers+1))/2;
|
|
|
|
|
|
|
|
|
|
if((lines_used+lines_for_special_registers+1)>(height-2)||width<37)
|
2024-02-05 21:25:00 +00:00
|
|
|
|
mvwprintw(general_registers,1,1,"too small window");
|
|
|
|
|
else{
|
|
|
|
|
int n=0,y=0;
|
|
|
|
|
while(y!=lines_used){
|
|
|
|
|
for(int i=0;i<per_line;i++){
|
|
|
|
|
if(n<8){
|
2024-02-06 20:55:39 +00:00
|
|
|
|
float float_equiv=*(float*)(simdata->registers->GPR+n);
|
2024-02-14 02:45:28 +00:00
|
|
|
|
if(float_equiv<9999999999.0&&float_equiv>-9999999999.0)
|
2024-02-06 20:55:39 +00:00
|
|
|
|
mvwprintw(general_registers,1+y+center_y_offset,1+i*35+center_x_offset,"R%d: %08X (%08f) ",n,simdata->registers->GPR[n],float_equiv);
|
|
|
|
|
else
|
|
|
|
|
mvwprintw(general_registers,1+y+center_y_offset,1+i*35+center_x_offset,"R%d: %08X (%cinf) ",n,simdata->registers->GPR[n],(float_equiv>0)?'+':'-');
|
2024-02-05 21:25:00 +00:00
|
|
|
|
n++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
y++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<35*per_line;i++)
|
|
|
|
|
mvwaddch(general_registers,1+center_y_offset+lines_used,center_x_offset+i,ACS_HLINE);
|
|
|
|
|
|
2024-02-12 15:15:54 +00:00
|
|
|
|
int spec_reg_1_offset, spec_reg_2_offset;
|
|
|
|
|
|
|
|
|
|
if(lines_for_special_registers==2){
|
|
|
|
|
spec_reg_1_offset=((width-2)/2)-(23/2);
|
|
|
|
|
spec_reg_2_offset=((width-2)/2)-(27/2);
|
|
|
|
|
}else{
|
|
|
|
|
spec_reg_1_offset=((width-2)/2)-(22+27+8)/2;
|
|
|
|
|
spec_reg_2_offset=spec_reg_1_offset+22+8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wattron(general_registers,A_BOLD);
|
|
|
|
|
mvwprintw(general_registers,1+center_y_offset+lines_used+1,spec_reg_1_offset," PC");
|
|
|
|
|
wattroff(general_registers,A_BOLD);
|
|
|
|
|
wprintw(general_registers,": %06X ",simdata->registers->PC);
|
|
|
|
|
|
|
|
|
|
wattron(general_registers,A_BOLD);
|
|
|
|
|
wprintw(general_registers,"SP");
|
|
|
|
|
wattroff(general_registers,A_BOLD);
|
|
|
|
|
wprintw(general_registers,": %06X ",simdata->registers->SP);
|
|
|
|
|
|
2024-02-05 21:25:00 +00:00
|
|
|
|
wattron(general_registers,A_BOLD);
|
2024-02-12 15:15:54 +00:00
|
|
|
|
mvwprintw(general_registers,center_y_offset+lines_used+1+lines_for_special_registers,spec_reg_2_offset," ZERO");
|
2024-02-05 21:25:00 +00:00
|
|
|
|
wattroff(general_registers,A_BOLD);
|
|
|
|
|
wprintw(general_registers,": %c ",(simdata->registers->FLAGS&1)?'1':'0');
|
|
|
|
|
|
|
|
|
|
wattron(general_registers,A_BOLD);
|
|
|
|
|
wprintw(general_registers,"CARRY");
|
|
|
|
|
wattroff(general_registers,A_BOLD);
|
|
|
|
|
wprintw(general_registers,": %c ",(simdata->registers->FLAGS&2)?'1':'0');
|
|
|
|
|
|
|
|
|
|
wattron(general_registers,A_BOLD);
|
|
|
|
|
wprintw(general_registers,"SIGN");
|
|
|
|
|
wattroff(general_registers,A_BOLD);
|
|
|
|
|
wprintw(general_registers,": %c ",(simdata->registers->FLAGS&4)?'1':'0');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-13 21:28:42 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int term_curs_x,term_curs_y;
|
|
|
|
|
|
2024-02-14 02:42:10 +00:00
|
|
|
|
wchar_t braille_lookup[256]={
|
|
|
|
|
L'⠀',L'⠁',L'⠂',L'⠃',L'⠄',L'⠅',L'⠆',L'⠇',L'⠈',L'⠉',L'⠊',L'⠋',L'⠌',L'⠍',L'⠎',L'⠏',L'⠐',L'⠑',L'⠒',L'⠓',L'⠔',L'⠕',L'⠖',L'⠗',L'⠘',L'⠙',L'⠚',L'⠛',L'⠜',L'⠝',L'⠞',L'⠟',
|
|
|
|
|
L'⠠',L'⠡',L'⠢',L'⠣',L'⠤',L'⠥',L'⠦',L'⠧',L'⠨',L'⠩',L'⠪',L'⠫',L'⠬',L'⠭',L'⠮',L'⠯',L'⠰',L'⠱',L'⠲',L'⠳',L'⠴',L'⠵',L'⠶',L'⠷',L'⠸',L'⠹',L'⠺',L'⠻',L'⠼',L'⠽',L'⠾',L'⠿',
|
|
|
|
|
L'⡀',L'⡁',L'⡂',L'⡃',L'⡄',L'⡅',L'⡆',L'⡇',L'⡈',L'⡉',L'⡊',L'⡋',L'⡌',L'⡍',L'⡎',L'⡏',L'⡐',L'⡑',L'⡒',L'⡓',L'⡔',L'⡕',L'⡖',L'⡗',L'⡘',L'⡙',L'⡚',L'⡛',L'⡜',L'⡝',L'⡞',L'⡟',L'⡠',L'⡡',L'⡢',L'⡣',L'⡤',L'⡥',L'⡦',L'⡧',L'⡨',L'⡩',L'⡪',L'⡫',L'⡬',L'⡭',L'⡮',L'⡯',L'⡰',L'⡱',L'⡲',L'⡳',L'⡴',L'⡵',L'⡶',L'⡷',L'⡸',L'⡹',L'⡺',L'⡻',L'⡼',L'⡽',L'⡾',L'⡿',
|
|
|
|
|
L'⢀',L'⢁',L'⢂',L'⢃',L'⢄',L'⢅',L'⢆',L'⢇',L'⢈',L'⢉',L'⢊',L'⢋',L'⢌',L'⢍',L'⢎',L'⢏',L'⢐',L'⢑',L'⢒',L'⢓',L'⢔',L'⢕',L'⢖',L'⢗',L'⢘',L'⢙',L'⢚',L'⢛',L'⢜',L'⢝',L'⢞',L'⢟',L'⢠',L'⢡',L'⢢',L'⢣',L'⢤',L'⢥',L'⢦',L'⢧',L'⢨',L'⢩',L'⢪',L'⢫',L'⢬',L'⢭',L'⢮',L'⢯',L'⢰',L'⢱',L'⢲',L'⢳',L'⢴',L'⢵',L'⢶',L'⢷',L'⢸',L'⢹',L'⢺',L'⢻',L'⢼',L'⢽',L'⢾',L'⢿',
|
|
|
|
|
L'⣀',L'⣁',L'⣂',L'⣃',L'⣄',L'⣅',L'⣆',L'⣇',L'⣈',L'⣉',L'⣊',L'⣋',L'⣌',L'⣍',L'⣎',L'⣏',L'⣐',L'⣑',L'⣒',L'⣓',L'⣔',L'⣕',L'⣖',L'⣗',L'⣘',L'⣙',L'⣚',L'⣛',L'⣜',L'⣝',L'⣞',L'⣟',L'⣠',L'⣡',L'⣢',L'⣣',L'⣤',L'⣥',L'⣦',L'⣧',L'⣨',L'⣩',L'⣪',L'⣫',L'⣬',L'⣭',L'⣮',L'⣯',L'⣰',L'⣱',L'⣲',L'⣳',L'⣴',L'⣵',L'⣶',L'⣷',L'⣸',L'⣹',L'⣺',L'⣻',L'⣼',L'⣽',L'⣾',L'⣿',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int print_braille_frame_buffer(WINDOW* win,uint8_t *buffer,int width,int height){
|
|
|
|
|
for(int h=0;h<height/4;h++){
|
|
|
|
|
for(int w=0;w<width/2;w++){
|
|
|
|
|
uint8_t select=0;
|
|
|
|
|
if(buffer[w*2 +width*(h*4 )])
|
|
|
|
|
select|=0x01;
|
|
|
|
|
if(buffer[w*2 +width*(h*4+1)])
|
|
|
|
|
select|=0x02;
|
|
|
|
|
if(buffer[w*2 +width*(h*4+2)])
|
|
|
|
|
select|=0x04;
|
|
|
|
|
if(buffer[w*2 +width*(h*4+3)])
|
|
|
|
|
select|=0x40;
|
|
|
|
|
if(buffer[w*2+1 +width*(h*4 )])
|
|
|
|
|
select|=0x08;
|
|
|
|
|
if(buffer[w*2+1 +width*(h*4+1 )])
|
|
|
|
|
select|=0x10;
|
|
|
|
|
if(buffer[w*2+1 +width*(h*4+2 )])
|
|
|
|
|
select|=0x20;
|
|
|
|
|
if(buffer[w*2+1 +width*(h*4+3 )])
|
|
|
|
|
select|=0x80;
|
|
|
|
|
mvwprintw(win,h+1,w+1,"%lc",braille_lookup[select]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void braille_frame_buffer_line(uint8_t *buffer,int buffer_width,int buffer_height,int x0, int y0, int x1, int y1){
|
|
|
|
|
int dx,dy,p,x,y;
|
|
|
|
|
dx=x1-x0;
|
|
|
|
|
dy=y1-y0;
|
|
|
|
|
x=x0;
|
|
|
|
|
y=y0;
|
|
|
|
|
p=2*dy-dx;
|
|
|
|
|
uint32_t addr;
|
|
|
|
|
while(x<x1){
|
|
|
|
|
if(p>=0){
|
|
|
|
|
addr=x+y*buffer_width;
|
|
|
|
|
if(addr>0&&addr<(uint64_t)(buffer_width*buffer_height)&&x<buffer_width&&x>0)
|
|
|
|
|
buffer[addr]=1;
|
|
|
|
|
y=y+1;
|
|
|
|
|
p=p+2*dy-2*dx;
|
|
|
|
|
}else{
|
|
|
|
|
addr=x+y*buffer_width;
|
|
|
|
|
if(addr>0&&addr<(uint64_t)(buffer_width*buffer_height)&&x<buffer_width&&x>0)
|
|
|
|
|
buffer[addr]=1;
|
|
|
|
|
p=p+2*dy;
|
|
|
|
|
}
|
|
|
|
|
x=x+1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-13 21:28:42 +00:00
|
|
|
|
int update_general_terminal_output(struct simdata_t *simdata){
|
|
|
|
|
int width,height;
|
|
|
|
|
werase(general_terminal_output);
|
|
|
|
|
getmaxyx(general_terminal_output,height,width);
|
|
|
|
|
|
|
|
|
|
term_curs_x=0;
|
|
|
|
|
term_curs_y=0;
|
2024-02-14 02:42:10 +00:00
|
|
|
|
uint8_t* vector_frame_buffer=malloc((height*4)*(width*2));
|
|
|
|
|
memset(vector_frame_buffer,0,(height*4)*(width*2));
|
|
|
|
|
|
|
|
|
|
int vector=0;
|
|
|
|
|
int vstate=0;
|
|
|
|
|
|
|
|
|
|
int vfb_width=(width-2)*2;
|
|
|
|
|
int vfb_height=(height-2)*4;
|
|
|
|
|
for(uint64_t i=0;i < simdata->terminal_output_size;i+=4){
|
|
|
|
|
uint32_t c=simdata->terminal_output[i/4];
|
|
|
|
|
if(vector){
|
|
|
|
|
float x0,y0,x1,y1;
|
|
|
|
|
switch(vstate){
|
|
|
|
|
case 0: /*start of line*/
|
|
|
|
|
if(c==0x00000001)
|
|
|
|
|
vector=0;
|
|
|
|
|
else if(c==0x00000002)
|
|
|
|
|
memset(vector_frame_buffer,0,(height*4)*(width*2));
|
|
|
|
|
else
|
|
|
|
|
vstate++;
|
|
|
|
|
break;
|
|
|
|
|
case 1: /*x of start*/
|
|
|
|
|
x0=*(float*)&c;
|
|
|
|
|
vstate++;
|
|
|
|
|
break;
|
|
|
|
|
case 2: /*y of start*/
|
|
|
|
|
y0=*(float*)&c;
|
|
|
|
|
vstate++;
|
|
|
|
|
break;
|
|
|
|
|
case 3: /*x of end*/
|
|
|
|
|
x1=*(float*)&c;
|
|
|
|
|
vstate++;
|
|
|
|
|
break;
|
|
|
|
|
case 4: /*y of end*/
|
|
|
|
|
y1=*(float*)&c;
|
|
|
|
|
float min_dim=(vfb_width>vfb_height)?vfb_height:vfb_width;
|
|
|
|
|
int xoff=0,yoff=0;
|
|
|
|
|
x0*=1.25;
|
|
|
|
|
x1*=1.25;
|
|
|
|
|
if(vfb_width>vfb_height)
|
|
|
|
|
xoff=(vfb_width-vfb_height)/2;
|
|
|
|
|
else
|
|
|
|
|
yoff=(vfb_height-vfb_width)/2;
|
|
|
|
|
braille_frame_buffer_line(vector_frame_buffer,vfb_width,vfb_height,xoff+(x0+1)*(min_dim/2),yoff+(y0+1)*(min_dim/2),xoff+(x1+1)*(min_dim/2),yoff+(y1+1)*(min_dim/2));
|
|
|
|
|
vstate=0;
|
|
|
|
|
break;
|
2024-02-13 21:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
}else{
|
2024-02-14 02:42:10 +00:00
|
|
|
|
if(c>=' '&&c<='~'){
|
|
|
|
|
mvwprintw(general_terminal_output,term_curs_y+1,term_curs_x+1,"%c",c);
|
|
|
|
|
term_curs_x++;
|
|
|
|
|
if(term_curs_x>=width-2){
|
2024-02-13 21:28:42 +00:00
|
|
|
|
term_curs_x=0;
|
|
|
|
|
term_curs_y++;
|
2024-02-14 02:42:10 +00:00
|
|
|
|
}
|
|
|
|
|
if(term_curs_y>=height-2){
|
|
|
|
|
wscrl(general_terminal_output,1);
|
|
|
|
|
term_curs_y--;
|
|
|
|
|
for(int i=0;i<width;i++){
|
|
|
|
|
mvwprintw(general_terminal_output,term_curs_y+1,i," ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
switch(c){
|
|
|
|
|
case 0xffffffff:
|
|
|
|
|
vector=1;
|
|
|
|
|
break;
|
|
|
|
|
case 0x0a:
|
|
|
|
|
term_curs_x=0;
|
|
|
|
|
term_curs_y++;
|
|
|
|
|
if(term_curs_y>=height-2){
|
|
|
|
|
wscrl(general_terminal_output,1);
|
|
|
|
|
term_curs_y--;
|
|
|
|
|
box(general_terminal_output, 0 , 0);
|
|
|
|
|
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
|
2024-02-13 21:28:42 +00:00
|
|
|
|
}
|
2024-02-14 02:42:10 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
werase(general_terminal_output);
|
2024-02-13 21:28:42 +00:00
|
|
|
|
box(general_terminal_output, 0 , 0);
|
|
|
|
|
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
|
2024-02-14 02:42:10 +00:00
|
|
|
|
mvwprintw(general_terminal_output,1,1,"Invalid output");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2024-02-13 21:28:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-14 02:42:10 +00:00
|
|
|
|
box(general_terminal_output, 0 , 0);
|
|
|
|
|
if(!vector){
|
|
|
|
|
mvwchgat(general_terminal_output,term_curs_y+1,term_curs_x+1, 1, A_REVERSE, 0, NULL);
|
|
|
|
|
mvwprintw(general_terminal_output,0,width/2-7,"[ TERM OUTPUT ]");
|
|
|
|
|
}else{
|
|
|
|
|
print_braille_frame_buffer(general_terminal_output,vector_frame_buffer,(width-2)*2,(height-2)*4);
|
|
|
|
|
mvwprintw(general_terminal_output,0,width/2-9,"[ VECTOR DISPLAY ]");
|
|
|
|
|
}
|
|
|
|
|
free(vector_frame_buffer);
|
2024-02-13 21:28:42 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
2024-02-05 21:25:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-03 23:49:45 +00:00
|
|
|
|
int clear_back_window=1;
|
|
|
|
|
|
2024-01-23 19:35:57 +00:00
|
|
|
|
int update_gui(struct simdata_t *simdata){
|
2024-02-06 23:14:33 +00:00
|
|
|
|
if(simdata->cpu_state==CPU_HALTED)
|
|
|
|
|
CPU_STATE=GUI_CPU_STOPPED;
|
2024-02-03 23:49:45 +00:00
|
|
|
|
if(clear_back_window){
|
|
|
|
|
clear();
|
|
|
|
|
clear_back_window=0;
|
|
|
|
|
}
|
2024-01-23 19:35:57 +00:00
|
|
|
|
update_tabs();
|
|
|
|
|
if(update_general_memdump(simdata))
|
|
|
|
|
return 1;
|
2024-01-26 16:11:57 +00:00
|
|
|
|
if(update_general_stack(simdata))
|
|
|
|
|
return 1;
|
2024-01-29 12:48:53 +00:00
|
|
|
|
if(update_general_disas(simdata))
|
|
|
|
|
return 1;
|
2024-02-05 21:25:00 +00:00
|
|
|
|
if(update_general_registers(simdata))
|
|
|
|
|
return 1;
|
2024-02-13 21:28:42 +00:00
|
|
|
|
if(update_general_terminal_output(simdata))
|
|
|
|
|
return 1;
|
2024-01-23 19:35:57 +00:00
|
|
|
|
if(gui_ncurses_refresh())
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 23:14:33 +00:00
|
|
|
|
int gui_continue_request(struct simdata_t *simdata){
|
2024-02-13 21:28:42 +00:00
|
|
|
|
int inch;
|
2024-02-05 12:34:28 +00:00
|
|
|
|
int release=0;
|
|
|
|
|
while(release==0){
|
|
|
|
|
if(((inch=getch())==ERR)){
|
2024-02-06 23:14:33 +00:00
|
|
|
|
if(CPU_STATE==GUI_CPU_SINGLE_STEPPING)
|
2024-02-05 12:34:28 +00:00
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
release=1;
|
|
|
|
|
}
|
|
|
|
|
switch(inch){
|
|
|
|
|
case 'r':
|
2024-02-06 23:14:33 +00:00
|
|
|
|
if(simdata->cpu_state!=CPU_HALTED){
|
|
|
|
|
if(CPU_STATE==GUI_CPU_RUNNING){
|
|
|
|
|
CPU_STATE=GUI_CPU_SINGLE_STEPPING;
|
|
|
|
|
nodelay(stdscr, FALSE);
|
|
|
|
|
}else{
|
|
|
|
|
CPU_STATE=GUI_CPU_RUNNING;
|
|
|
|
|
nodelay(stdscr, TRUE);
|
|
|
|
|
}
|
2024-02-05 12:34:28 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'q':
|
|
|
|
|
return 2;
|
|
|
|
|
case '\n':
|
|
|
|
|
release=1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2024-02-14 02:42:10 +00:00
|
|
|
|
break;
|
2024-02-05 12:34:28 +00:00
|
|
|
|
}
|
2024-02-03 23:49:45 +00:00
|
|
|
|
}
|
2024-01-22 12:11:07 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int end_gui(){
|
|
|
|
|
if(endwin()==ERR)
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|