Skip to content

Commit

Permalink
More terminal changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyDiGirolamo committed Feb 14, 2021
1 parent 646d752 commit f5fab49
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "terminal.h"
#include "GD2Terminal.h"

// 120 character strings
char terminal_linebuffer[] = " ";

uint8_t *const linebuffer_const = (uint8_t*)terminal_linebuffer;

Terminal::Terminal() {
GD2Terminal::GD2Terminal() {
scrollback_length = 100;
foreground_color = 15;
background_color = 0;
Expand All @@ -17,7 +17,7 @@ Terminal::Terminal() {
reset();
}

void Terminal::begin(uint8_t initial_font_mode) {
void GD2Terminal::begin(uint8_t initial_font_mode) {
if (initial_font_mode == TEXTVGA) {
set_font_vga();
}
Expand All @@ -27,10 +27,10 @@ void Terminal::begin(uint8_t initial_font_mode) {
set_size_fullscreen();
}

void Terminal::set_size_fullscreen() {
void GD2Terminal::set_size_fullscreen() {
int character_width = 8;
int character_height = 8;
if (current_font = TEXTVGA) {
if (current_font == TEXTVGA) {
character_height = 16;
}
int row_count = floor(GD.h / character_height);
Expand All @@ -39,31 +39,31 @@ void Terminal::set_size_fullscreen() {
}


void Terminal::set_window_bg_color(uint32_t color) {
void GD2Terminal::set_window_bg_color(uint32_t color) {
terminal_window_bg_color = color;
}

void Terminal::set_window_opacity(uint8_t opacity) {
void GD2Terminal::set_window_opacity(uint8_t opacity) {
terminal_window_opacity = opacity;
}

void Terminal::enable_vga_background_colors() {
void GD2Terminal::enable_vga_background_colors() {
background_colors_enabled = true;
}

void Terminal::disable_vga_background_colors() {
void GD2Terminal::disable_vga_background_colors() {
background_colors_enabled = false;
}

uint32_t Terminal::bitmap_byte_size() {
uint32_t GD2Terminal::bitmap_byte_size() {
return scrollback_length * bytes_per_line;
}

uint32_t Terminal::ram_end_address() {
uint32_t GD2Terminal::ram_end_address() {
return bitmap_byte_size()+2;
}

void Terminal::change_size(uint16_t rows, uint16_t columns){
void GD2Terminal::change_size(uint16_t rows, uint16_t columns){
lines_per_screen = rows;
characters_per_line = columns;
bytes_per_line = characters_per_line;
Expand All @@ -84,17 +84,17 @@ void Terminal::change_size(uint16_t rows, uint16_t columns){
reset();
}

void Terminal::set_font_8x8() {
void GD2Terminal::set_font_8x8() {
current_font = TEXT8X8;
line_pixel_height = 8;
}

void Terminal::set_font_vga() {
void GD2Terminal::set_font_vga() {
current_font = TEXTVGA;
line_pixel_height = 16;
}

void Terminal::reset() {
void GD2Terminal::reset() {
// // set all line history to spaces
// strncpy(terminal_linebuffer, terminal_blank_line, characters_per_line);
// for (uint16_t i = 0; i<scrollback_length; i++) {
Expand All @@ -111,11 +111,11 @@ void Terminal::reset() {
set_scrollbar_handle_size();
}

void Terminal::ring_bell() {
bell = 40;
void GD2Terminal::ring_bell() {
bell = 60;
}

void Terminal::update_scrollbar_position(uint16_t new_position) {
void GD2Terminal::update_scrollbar_position(uint16_t new_position) {
scrollbar_position = new_position;
if (scrollbar_position < scrollbar_size_half)
scrollbar_position = scrollbar_size_half;
Expand All @@ -134,12 +134,12 @@ void Terminal::update_scrollbar_position(uint16_t new_position) {
}
}

void Terminal::upload_to_graphics_ram() {
void GD2Terminal::upload_to_graphics_ram() {
GD.cmd_memwrite(last_line_address*bytes_per_line, bytes_per_line);
GD.copy(linebuffer_const, bytes_per_line);
}

void Terminal::set_scrollbar_handle_size() {
void GD2Terminal::set_scrollbar_handle_size() {
lines_per_screen_percent = ((float) lines_per_screen) / ((float) line_count);
if (lines_per_screen_percent > 1.0)
lines_per_screen_percent = 1.0;
Expand All @@ -148,7 +148,7 @@ void Terminal::set_scrollbar_handle_size() {
update_scrollbar_position(65535);
}

void Terminal::erase_line_buffer() {
void GD2Terminal::erase_line_buffer() {
// erase current line
for (uint8_t i=0; i<120; i++) {
terminal_linebuffer[i] = ' ';
Expand All @@ -162,7 +162,7 @@ void Terminal::erase_line_buffer() {
}
}

void Terminal::new_line() {
void GD2Terminal::new_line() {
// copy terminal_linebuffer to FT810 RAM
upload_to_graphics_ram();
cursor_index = 0;
Expand All @@ -177,7 +177,7 @@ void Terminal::new_line() {
set_scrollbar_handle_size();
}

void Terminal::append_string(const char* str) {
void GD2Terminal::append_string(const char* str) {
for(uint16_t i=0; i<strlen(str); i++) {
append_character(str[i]);
}
Expand All @@ -187,7 +187,7 @@ void Terminal::append_string(const char* str) {
// append_character((char) 13);
}

void Terminal::put_char(char newchar) {
void GD2Terminal::put_char(char newchar) {
if (current_font == TEXTVGA) {
terminal_linebuffer[cursor_index*2+1] = (background_color << 4) | foreground_color;
terminal_linebuffer[cursor_index*2] = newchar;
Expand All @@ -197,7 +197,7 @@ void Terminal::put_char(char newchar) {
}
}

uint8_t Terminal::append_character(char newchar) {
uint8_t GD2Terminal::append_character(char newchar) {
if (cursor_index >= characters_per_line
|| newchar == TERMINAL_KEY_CR
|| newchar == TERMINAL_KEY_LF) {
Expand All @@ -222,16 +222,16 @@ uint8_t Terminal::append_character(char newchar) {
return CHAR_READ;
}

void Terminal::set_position(int x, int y) {
void GD2Terminal::set_position(int x, int y) {
draw_x_coord = x;
draw_y_coord = y;
}

void Terminal::draw() {
void GD2Terminal::draw() {
draw(draw_x_coord, draw_y_coord);
}

void Terminal::draw(int startx, int starty) {
void GD2Terminal::draw(int startx, int starty) {
// Upload any lingering data from append_character calls.
upload_to_graphics_ram();

Expand Down Expand Up @@ -289,7 +289,7 @@ void Terminal::draw(int startx, int starty) {
// GD.Vertex2ii(DISPLAY_WIDTH, DISPLAY_HEIGHT);
}

GD.ColorRGB(WHITE);
GD.ColorRGB(COLOR_WHITE);

// Draw Terminal Text

Expand All @@ -307,8 +307,8 @@ void Terminal::draw(int startx, int starty) {

GD.BlendFunc(SRC_ALPHA, ONE_MINUS_SRC_ALPHA);
GD.ColorA(128); // alpha to 128/256
GD.cmd_bgcolor(VALHALLA);
GD.cmd_fgcolor(LIGHT_STEEL_BLUE);
GD.cmd_bgcolor(COLOR_VALHALLA);
GD.cmd_fgcolor(COLOR_LIGHT_STEEL_BLUE);

GD.Tag(TAG_SCROLLBAR);
GD.cmd_scrollbar(draw_x_coord + draw_width - SCROLLBAR_WIDTH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
#define TERMINAL_BITMAP_HANDLE_TEXT 14
#define TERMINAL_BITMAP_HANDLE_BACKGROUND 13

class Terminal {
class GD2Terminal {
public:
Terminal();
GD2Terminal();

uint16_t cursor_index;
uint16_t line_count;
Expand Down
6 changes: 3 additions & 3 deletions terminal_test/src/SystemSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "SystemSettings.h"

extern GDClass GD;
extern Terminal terminal;
extern GD2Terminal terminal;
extern Input controller;

SystemSettings::SystemSettings(void) {
Expand Down Expand Up @@ -120,7 +120,7 @@ void SystemSettings::draw() {
sprintf(line_buffer, "%c%c%c%c%c%c%c%c\n", BYTE_TO_BINARY(controller.buttons));
terminal.foreground_color = TERMINAL_VGA_BRIGHT_CYAN;
terminal.append_string(line_buffer);
if (controller.buttons & 1 == 0) {
if ((controller.buttons & 1) == 0) {
terminal.ring_bell();
}
}
Expand All @@ -131,7 +131,7 @@ void SystemSettings::draw() {
// Be sure to reset the bitmap_handle afterwards
terminal.draw(position_x, position_y);

GD.ColorRGB(WHITE);
GD.ColorRGB(COLOR_WHITE);

// Draw Brightness Slider
GD.Tag(TAG_BRIGHTNESS_SLIDER);
Expand Down
2 changes: 1 addition & 1 deletion terminal_test/src/SystemSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <SPI.h>
#include <GD2.h>
#include <TimeLib.h>
#include "terminal.h"
#include "GD2Terminal.h"
#include "input.h"

#define BATTERY_VOLTAGE_DIVIDER_PIN A8
Expand Down
10 changes: 5 additions & 5 deletions terminal_test/src/terminal_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ template<> inline Print& operator <<(Print &obj, float arg) { obj.print(a
#include <stdlib.h>
#include <stdio.h>

#include "terminal.h"
#include "GD2Terminal.h"

#include "input.h"

Expand All @@ -23,7 +23,7 @@ time_t getTeensy3Time() {


Input controller;
Terminal terminal;
GD2Terminal terminal;
SystemSettings system_settings;
Munch munch;

Expand Down Expand Up @@ -74,7 +74,7 @@ void setup() {
terminal.begin(TEXTVGA);
// terminal.begin(TEXT8X8);
terminal.set_window_bg_color(0x000000); // Background window color
terminal.set_window_opacity(255); // 0-255
terminal.set_window_opacity(128); // 0-255

// Changing Fonts -------------------------------------------------
// 8X8 Monochrome
Expand Down Expand Up @@ -139,12 +139,12 @@ void loop() {
"FPS: %.2f --- DisplayList: %3.2f%% (%u / 8192)",
1.0 / delta_time, 100.0 * ((float)display_list_offset/8192), display_list_offset);
// Draw white text with a black outline.
GD.ColorRGB(BLACK);
GD.ColorRGB(COLOR_BLACK);
GD.cmd_text(0, GD.h-23, 18, 0, system_settings.line_buffer);
GD.cmd_text(2, GD.h-23, 18, 0, system_settings.line_buffer);
GD.cmd_text(1, GD.h-23-1, 18, 0, system_settings.line_buffer);
GD.cmd_text(1, GD.h-23+1, 18, 0, system_settings.line_buffer);
GD.ColorRGB(WHITE);
GD.ColorRGB(COLOR_WHITE);
GD.cmd_text(1, GD.h-23, 18, 0, system_settings.line_buffer);

// Get the size (current position) of the display list.
Expand Down

0 comments on commit f5fab49

Please sign in to comment.