/* ======================================================================== main: This is the main entry point for the VirtualT application. ======================================================================== */ int main(int argc, char **argv) { if (process_args(argc, argv)) /* Parse command line args */ return 1; setup_working_path(argv); /* Create a working dir path */ setup_unix_signals(); /* Setup Unix signal handling */ // Added by JV for prefs init_pref(); /* load user Menu preferences */ check_installation(); /* Test if install needs to be performed */ load_setup_preferences(); /* Load user Peripheral setup preferences */ load_memory_preferences(); /* Load user Memory setup preferences */ load_remote_preferences(); /* Load user Remote Socket preferences */ /* Perform initialization */ init_mem(); /* Initialize Memory */ init_io(); /* Initialize I/O structures */ init_sound(); /* Initialize Sound system */ init_display(); /* Initialize the Display */ init_cpu(); /* Initialize the CPU */ init_throttle_timer(); /* Initialize the throttle timer */ init_remote(); /* Initialize the remote control */ init_lpt(); /* Initialize the printer subsystem */ init_other_windows(); /* Initialize other windows that were opened (memedit, regs, etc. */ get_model_time(); /* Load the emulated time for current model */ /* Perform Emulation */ emulate(); /* Main emulation loop */ /* Save RAM contents after emulation */ save_ram(); save_model_time(); /* Save the emulated time */ /* Cleanup */ deinit_io(); /* Deinitialize I/O */ deinit_sound(); /* Deinitialize sound */ deinit_lpt(); /* Deinitialize the printer */ deinit_throttle_timer(); /* Deinitialize the throttle timer */ deinit_display(); /* Deinitialze and free the main window */ free_mem(); /* Free memory used by ReMem and/or Rampac */ return 0; }
int main(int argc, char* argv[]) { int is_running = 1; int x_terminal_size, y_terminal_size; int is_lurking = 0; int is_yelling = 0; int in_deepsix = 0; int sending_im = 0; int i; /* josh-note: These need to be uncommented for the client connection to work. */ /* int client_id = init_client("Henry"); create a client. */ /* init_user_list(client_id); init the client size user list. */ log_init(); log_writeln(" --------------------------- "); log_writeln(" > Starting BlackChat"); signal(SIGALRM, scroll_ended_handler); for(i = 0; i < 26; i ++) { /* set our message to null */ memset(yell_messages[i], '\0', MAX_MESSAGE_LENGTH * sizeof(wchar_t)); } transcript_buffer = (wchar_t*)malloc(sizeof(wchar_t)*transcript_buffer_size); f_transcript_buffer = (wchar_t*)malloc(sizeof(wchar_t)*f_transcript_buffer_size); memset(client_buffer, '\0', sizeof(client_buffer)); memset(transcript_buffer, '\0', sizeof(transcript_buffer)); get_terminal_size(&x_terminal_size, &y_terminal_size); log_writeln(" > ... detecting current terminal size xy:(%d,%d)", x_terminal_size, y_terminal_size); log_writeln(" > ... initializing ncurses screen in raw mode"); initscr(); // start_color(); init_pair(0, COLOR_WHITE, COLOR_BLACK); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(2, COLOR_YELLOW, COLOR_BLACK); init_pair(3, COLOR_CYAN, COLOR_BLACK); init_pair(4, COLOR_MAGENTA, COLOR_BLACK); raw(); keypad(stdscr, TRUE); noecho(); color_set(0, NULL); log_writeln(" > ... creating transcript and client window"); transcript_window = newwin(TRANSCRIPT_MAX_ROWS,TRANSCRIPT_MAX_COLUMNS, 0,0); fullscreen_transcript_window = newwin(TRANSCRIPT_MAX_ROWS,TRANSCRIPT_MAX_COLUMNS*2, 0,0); client_chat_window = newwin(MAX_ROWS,MAX_COLUMNS,24,0); lurk_win = newwin(MAX_ROWS,MAX_COLUMNS,24,0); yell_win = newwin(23,40,0,0); deepsix_win = newwin(23,40,0,0); im_win = newwin(TRANSCRIPT_MAX_ROWS,TRANSCRIPT_MAX_COLUMNS, 0,0); status_win = newwin(3,40,21,40); info_win = newwin(3,40,0,40); // box(yell_win, '|', '-'); set_yell_message(0, L"Hello World"); set_yell_message(1, L"Yo dog!"); set_yell_message(2, L"Hey everyone!"); set_yell_message(3, L"Whats up?"); set_yell_message(12,L"I agree."); wcolor_set(lurk_win, 4, NULL); wcolor_set(transcript_window, 3, NULL); wcolor_set(client_chat_window, 4, NULL); wcolor_set(yell_win, 2, NULL); wprintw(lurk_win, "Lurking... Use CTRL-L to unLurk or CTRL-Q to quit."); log_writeln(" > ... creating other 9 windows"); init_other_windows(); log_writeln(" > ... [beginning transcript]"); write_to_transcript_window(L"***************************************"); write_to_transcript_window(L"******** Wecome to BlackChat! *********"); write_to_transcript_window(L"***************************************"); set_window_user_name(0, L"chris"); set_window_user_name(1, L"sue"); set_window_user_name(2, L"dan"); set_window_user_name(3, L"joe"); append_text_to_window(0, L"Sup!"); append_text_to_window(1, L"yo everyone, I'm in love with blackchat!"); append_text_to_window(2, L"hey, my name is Dan!"); append_text_to_window(3, L"Hey!?"); can_deepsix_user(0, 0); set_user_status(1, 'L'); set_user_status(2, 'L'); /* Set our info window text. */ wprintw(info_win, " Black Chat v1.0\n"); wprintw(info_win, "UI: Henry Stratmann|Client: Josh Hartman\n"); wprintw(info_win, "Server: Tyler Reid |Protocol: Tim Rhoads\n"); while(is_running) { int ch = getch(); /* wchar_t buf[512]; //get wchar_ts sprintf(buf, "key pressed: '%c' int value: %d\n", ch, ch); write_to_transcript_window(buf); */ //end get wchar_t /* Check if were in "Lurk" mode. */ if(is_lurking) { switch(ch) { case 12: /* lurk-off */ is_lurking = 0; print_client_chat_buffer(); break; case 17: /* quit */ is_running = 0; break; default: wrefresh(lurk_win); } } /* Check if were in IM mode. */ else if(sending_im) { /* TODO: Display list of users (like deepsix) to send IM to. All IM's will be displayed on the main transcript with some type of "marker" indicating that this was an IM. */ if(ch >= 48 && ch <= 57) { /* josh-note: Have josh send IM based on "ch" */ } /* quit */ if(ch == 17) { is_running = 0; } /* exit IM */ sending_im = 0; window_page_up(transcript_window, &transcript_current_line, TRANSCRIPT_MAX_COLUMNS, transcript_buffer); window_page_up(fullscreen_transcript_window, &transcript_current_line, TRANSCRIPT_MAX_COLUMNS*2, f_transcript_buffer); } /* Check if were in deepsix mode. */ else if(in_deepsix) { /* kick user */ if(ch >= 48 && ch <= 57) { /* josh-note: Have josh make a "kick_user(ch-48)" command. Also, have josh keep track of who user voted for and display message on transcript as to how user voted and/or if they already voted for the user. */ } /* quit */ if(ch == 17) { is_running = 0; } /* exit deepsix */ in_deepsix = 0; window_page_up(transcript_window, &transcript_current_line, TRANSCRIPT_MAX_COLUMNS, transcript_buffer); window_page_up(fullscreen_transcript_window, &transcript_current_line, TRANSCRIPT_MAX_COLUMNS*2, f_transcript_buffer); } /* Check if were yelling. */ else if(is_yelling) { // redrawwin(yell_win); // wrefresh(yell_win); int index = ch - 97; /* Write our comment to our transcript window. */ if(index >= 0 && index < 26) { if( yell_messages[index][0] != '\0' ) { write_to_transcript_window( yell_messages[index] ); } } is_yelling = 0; redrawwin(client_chat_window); wrefresh(client_chat_window); redrawwin(transcript_window); wrefresh(transcript_window); } else { /* Check what keys we pressed. */ switch(ch) { /* * Check if we pressed a control key. */ if(iscntrl(ch)) { case 7: /* CTRL-G */ gaudy_mode_on = (gaudy_mode_on == 1) ? 0 : 1; if(gaudy_mode_on) { client_buffer[ client_cursor_position++ ] = 2; } else { client_buffer[ client_cursor_position++ ] = 3; } /* Print out updates to the window. */ print_client_chat_buffer(); break; case 127:/* Backsapce Key (grok hack) */ case 8: /* CTRL-H */ client_buffer[ wcslen(client_buffer)-1 ] = '\0'; print_client_chat_buffer(); break; case 9: /* CTRL-I / TAB */ if(!sending_im) { sending_im = 1; draw_im_window(); } break; case 10: /* CTRL-J and CTRL-M */ /* UNCOMMENT ME FOR USE WITH SERVER */ { wchar_t *buf = NULL; /* If we had gaudy mode on, we need to disable it. */ if(gaudy_mode_on) { client_buffer[ client_cursor_position++ ] = 3; client_buffer[ client_cursor_position++ ] = ' '; gaudy_mode_on = 0; } /* Get our buffer togther to write to the transcript window. */ buf = (wchar_t*)malloc( (wcslen(L"[Client Says]: ")+wcslen(client_buffer)+1) * sizeof(wchar_t) ); write_to_transcript_window(L"[Client Says]: "); write_to_transcript_window(client_buffer); // sprintf(buf, "[Client Says]: %ls", client_buffer); // write_to_transcript_window(buf); } clear_text_from_client_typing_window(); /* write_out(client_id); enter key is pressed so send a message to the server. */ break; case 11: /* CTRL-K */ { int i; for(i = client_cursor_position+1; i < wcslen(client_buffer); i ++) { client_buffer[i] = '\0'; } } break; case 12: /* CTRL-L */ if(!is_lurking) { redrawwin(lurk_win); wrefresh(lurk_win); is_lurking = 1; } break; case 14: /* CTRL-N */ alarm(5); user_is_scrolling = 1; transcript_current_line ++; window_page_down( transcript_window, &transcript_current_line, TRANSCRIPT_MAX_COLUMNS, transcript_buffer ); window_page_down( fullscreen_transcript_window, &transcript_current_line, TRANSCRIPT_MAX_COLUMNS*2, f_transcript_buffer ); break; case 16: /* CTRL-P */ alarm(5); user_is_scrolling = 1; transcript_current_line --; window_page_up( transcript_window, &transcript_current_line, TRANSCRIPT_MAX_COLUMNS, transcript_buffer ); window_page_up( fullscreen_transcript_window, &transcript_current_line, TRANSCRIPT_MAX_COLUMNS*2, f_transcript_buffer ); break; case 17: /* CTRL-Q */ log_writeln(" > ... recived quit signal from client"); is_running = 0; break; case 20: /* CTRL-T */ if(transcript_maxed) { transcript_maxed = 0; window_page_up(transcript_window, &transcript_current_line, TRANSCRIPT_MAX_COLUMNS, transcript_buffer); wclear(fullscreen_transcript_window); wrefresh(fullscreen_transcript_window); } else { transcript_maxed = 1; window_page_up(fullscreen_transcript_window, &transcript_current_line, TRANSCRIPT_MAX_COLUMNS*2, f_transcript_buffer); wclear(transcript_window); wrefresh(transcript_window); } break; case 21: /* CTRL-U */ client_current_line = 0; client_cursor_position = 0; memset(client_buffer, '\0', wcslen(client_buffer)+1); print_client_chat_buffer(); break; case 23: /* CTRL-W */ delete_last_word_in_buffer(client_buffer); print_client_chat_buffer(); break; case 25: /* CTRL-Y */ { if(!is_yelling) { redrawwin(yell_win); wrefresh(yell_win); is_yelling = 1; } } break; case 29: /* CTRL-] */ alarm(0); user_is_scrolling = 0; print_transcript_chat_buffer(); break; case 30: /* CTRL-6 */ if(!in_deepsix) { draw_deepsix_window(); in_deepsix = 1; } break; /* * If we encountered an unkown escape wchar_tcter, break out of here so we don't * print it. */ break; /* TODO: Fix me! */ } #if 0 /* Scroll the clients typing window down. */ case KEY_DOWN: client_current_line ++; if(client_current_line*MAX_COLUMNS > wcslen(client_buffer)) client_current_line --; wclear(client_chat_window); wprintw(client_chat_window, &client_buffer[client_current_line*MAX_COLUMNS]); break; /* Scroll the clients typing window up. */ case KEY_UP: client_current_line --; if(client_current_line < 0) client_current_line = 0; wclear(client_chat_window); wprintw(client_chat_window, &client_buffer[client_current_line*MAX_COLUMNS]); break; #endif /* Delete the previous chracter. */ case KEY_BACKSPACE: /* Check if were deleting the last wchar_tacter. */ if( client_cursor_position == wcslen(client_buffer) ) { client_buffer[ client_cursor_position-1 ] = '\0'; client_cursor_position --; print_client_chat_buffer(); } else { /* If were here, that means were NOT deleting the last wchar_tacter. */ int i; for(i = client_cursor_position-1; i < wcslen(client_buffer); i ++) { client_buffer[i] = client_buffer[i+1]; } client_cursor_position --; print_client_chat_buffer(); } break; /* If were here, that means we didn't press any "special" keys so that means were * trying to write some generic wchar_tacters to our chat window. */ default: /* Make sure we don't print a control wchar_tacter. */ if(!iscntrl(ch)) { /* Check if were inserting a wchar_tacter before the end of our client * typing buffer. */ if( client_cursor_position != wcslen(client_buffer) ) { /* Move all wchar_tacters in front of the cursor up one. */ int i; for(i = wcslen(client_buffer)+1; i > client_cursor_position; i --) { client_buffer[i] = client_buffer[i-1]; } } /* Add the wchar_tacter to our buffer. */ client_buffer[ client_cursor_position++ ] = ch; /* Print our new/updated buffer. */ print_client_chat_buffer(); break; } } } /* Read from the server. */ /* josh-note Uncomment this! */ /* read_from_server(client_id); */ refresh_all_windows(is_lurking); } log_writeln(" > ... [ending transcript]"); log_writeln(" > ... freeing resources"); free_other_windows(); free(transcript_buffer); delwin(transcript_window); delwin(fullscreen_transcript_window); delwin(client_chat_window); delwin(status_win); delwin(info_win); delwin(im_win); delwin(deepsix_win); delwin(yell_win); endwin(); /* josh-note This should be uncommented to close down the client socket. */ /* close_client(client_id); */ log_writeln(" > ... closing client log"); log_writeln(" > ... bye bye for now!"); log_close(); return 0; }