Remove console, add keyboard and mouse values to advanced mode

This commit is contained in:
jimmystones
2021-10-19 13:00:55 +01:00
parent 1ed93fed60
commit 7fa3a3b24e
7 changed files with 1068 additions and 1005 deletions

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -207,7 +207,7 @@ wire ps2_mouse_cs = cpu_addr[15:8] == 8'b01110110;
wire timestamp_cs = cpu_addr[15:8] == 8'b01110111;
wire timer_cs = cpu_addr[15:8] == 8'b01111000;
// always @(posedge timestamp[32]) begin
//always @(posedge timestamp[32]) begin
// $display("%b", timestamp);
// end
//always @(posedge clk_sys) begin
@@ -223,6 +223,9 @@ wire timer_cs = cpu_addr[15:8] == 8'b01111000;
// if(ps2_key_cs) $display("ps2_key %b %x", ps2_key_data_out, cpu_addr[3:0]);
// $display("%x", cpu_addr);
//end
always @(posedge ps2_mouse[24]) begin
$display("%b", ps2_mouse);
end
// CPU data mux
assign cpu_din = pgrom_cs ? pgrom_data_out :

View File

@@ -35,6 +35,11 @@ unsigned char px_last[6];
signed char sx_toggle_last[6];
signed char sx_last[6];
unsigned long sx_pos[6];
unsigned char kbd_lastscan_cache;
unsigned char kbd_lastascii_cache;
char mse_button_last;
char mse_x_last;
char mse_y_last;
// Console constants
#define con_cursorfreq 30
@@ -44,7 +49,7 @@ unsigned char con_y; // Console cursor X position
unsigned char con_l = 2; // Console left edge X
unsigned char con_t = 22; // Console top edge Y
unsigned char con_r = 37; // Console right edge X
unsigned char con_b = 36; // Console bottom edge Y
unsigned char con_b = 26; // Console bottom edge Y
bool con_cursor;
unsigned char con_cursortimer = 1;
@@ -89,7 +94,7 @@ char button_name[BUTTON_COUNT][12] = {
char button_x[BUTTON_COUNT] = {6, 2, 4, 4, 24, 22, 22, 20, 3, 23, 9, 13};
char button_y[BUTTON_COUNT] = {5, 5, 6, 4, 5, 6, 4, 5, 1, 1, 5, 5};
#define color_button_active 0xFF
#define color_button_inactive 0b11100000
#define color_button_inactive 0b01010010
char analog_offset_x[PAD_COUNT] = {1, 20};
char analog_offset_y[PAD_COUNT] = {5, 5};
@@ -195,7 +200,14 @@ void page_inputtester_advanced()
sprintf(label, "SPN%d", j + 1);
write_string(label, 0xFF - (j * 2), 14, 14 + j);
}
write_string("CON", 0xFF, 2, 21);
write_string("SCAN ASC", 0xFF, 6, 21);
write_string("KBD", 0xFF, 2, 22);
write_char('X', 0xFF, 21, 21);
write_char('Y', 0xFF, 25, 21);
write_string("BUTTONS", 0xFF, 27, 21);
write_string("MSE", 0xFF, 15, 22);
}
// Draw static elements for button test page
@@ -352,8 +364,8 @@ bool modeswitcher()
void inputtester_digital()
{
// Handle PS/2 inputs whenever possible to improve latency
handle_ps2();
// // Handle PS/2 inputs whenever possible to improve latency
// handle_ps2();
// Handle secret code detection (joypad 1 directions)
if (HBLANK_RISING)
@@ -389,13 +401,13 @@ void inputtester_analog()
{
// Handle PS/2 inputs whenever possible to improve latency
handle_ps2();
// handle_ps2();
if (HBLANK_RISING)
{
basic_input();
handle_codes();
// Pad selection
if (!input_a && input_a_last)
{
@@ -584,71 +596,104 @@ void inputtester_advanced()
sx_toggle_last[inputindex] = sx_toggle;
}
// Keyboard test console
if (kbd_buffer_len > 0)
// // Keyboard test console
// if (kbd_buffer_len > 0)
// {
// // Clear existing cursor if visible
// if (con_cursor)
// {
// write_char(' ', 0xFF, con_x, con_y);
// }
// // Write characters in buffer
// for (char k = 0; k < kbd_buffer_len; k++)
// {
// if (kbd_buffer[k] == '\n')
// {
// // New line
// con_x = con_l;
// con_y++;
// if (con_y > con_b)
// {
// // Wrap to top
// con_y = con_t;
// }
// }
// else if (kbd_buffer[k] == '\b')
// {
// // Backspace - only if not at beginning of line
// if (con_x > con_l)
// {
// con_x--;
// // Clear existing character
// write_char(' ', 0xFF, con_x, con_y);
// }
// }
// else
// {
// // Write character
// write_char(kbd_buffer[k], 0xFF, con_x, con_y);
// // Move cursor right
// con_x++;
// if (con_x > con_r)
// {
// // New line
// con_x = con_l;
// con_y++;
// if (con_y > con_b)
// {
// // Wrap to top
// con_y = con_t;
// }
// }
// }
// }
// // Clear buffer and enable cursor
// kbd_buffer_len = 0;
// con_cursor = 0;
// con_cursortimer = 1;
// }
// Scancode output
if (kbd_lastscan != kbd_lastscan_cache || kbd_lastascii != kbd_lastascii_cache)
{
// Clear existing cursor if visible
if (con_cursor)
{
write_char(' ', 0xFF, con_x, con_y);
}
// Write characters in buffer
for (char k = 0; k < kbd_buffer_len; k++)
{
if (kbd_buffer[k] == '\n')
{
// New line
con_x = con_l;
con_y++;
if (con_y > con_b)
{
// Wrap to top
con_y = con_t;
}
}
else if (kbd_buffer[k] == '\b')
{
// Backspace - only if not at beginning of line
if (con_x > con_l)
{
con_x--;
// Clear existing character
write_char(' ', 0xFF, con_x, con_y);
}
}
else
{
// Write character
write_char(kbd_buffer[k], 0xFF, con_x, con_y);
// Move cursor right
con_x++;
if (con_x > con_r)
{
// New line
con_x = con_l;
con_y++;
if (con_y > con_b)
{
// Wrap to top
con_y = con_t;
}
}
}
}
// Clear buffer and enable cursor
kbd_buffer_len = 0;
con_cursor = 0;
con_cursortimer = 1;
write_stringfs("%3x", 0xFF, 7, 22, kbd_lastscan);
write_char(kbd_lastascii, 0xFF, 13, 22);
kbd_lastscan_cache = kbd_lastscan;
kbd_lastascii_cache = kbd_lastascii;
}
// Cursor blink timer
con_cursortimer--;
if (con_cursortimer <= 0)
if (mse_x_last != mse_x)
{
con_cursor = !con_cursor;
con_cursortimer = con_cursorfreq;
write_char(con_cursor ? '|' : ' ', 0xFF, con_x, con_y);
write_stringfs("%4d", 0xFF, 18, 22, mse_x);
mse_x_last = mse_x;
}
if (mse_y_last != mse_y)
{
write_stringfs("%4d", 0xFF, 22, 22, mse_y);
mse_y_last = mse_y;
}
if (mse_button_last != mse_button)
{
char x = 26;
char m = 0b00000001;
for (char i = 0; i < 8; i++)
{
x++;
write_char((mse_button & m) ? asc_1 : asc_0, 0xFF, x, 22);
m <<= 1;
}
mse_button_last = mse_button;
}
// // Cursor blink timer
// con_cursortimer--;
// if (con_cursortimer <= 0)
// {
// con_cursor = !con_cursor;
// con_cursortimer = con_cursorfreq;
// write_char(con_cursor ? '|' : ' ', 0xFF, con_x, con_y);
// }
}
}

View File

@@ -193,12 +193,13 @@ char kbd_pressed;
char kbd_extend;
char kbd_lastscan = 0;
char kbd_lastascii = 0;
char kbd_clock_index = 10;
// char mse_in[6];
// char mse_lastclock = 0;
// char mse_a1;
// char mse_a2;
// char mse_a3;
char mse_lastclock = 0;
char mse_x;
char mse_y;
char mse_button;
char mse_clock_index = 24;
char kbd_buffer[128];
char kbd_buffer_len = 0;
@@ -219,7 +220,6 @@ void get_ascii(char scan)
}
}
char kbd_clock_index = 10;
void handle_ps2()
{
@@ -262,10 +262,12 @@ void handle_ps2()
}
kbd_lastclock = kbd_clock;
// bool mse_clock = CHECK_BIT(ps2_mouse[3], 0);
// if (mse_clock != mse_lastclock)
// {
// mse_a1++;
// }
// mse_lastclock = mse_clock;
bool mse_clock = CHECK_BIT(ps2_mouse[mse_clock_index], 0);
if (mse_clock != mse_lastclock)
{
mse_button = ps2_mouse[0];
mse_x = ps2_mouse[8];
mse_y = ps2_mouse[16];
}
mse_lastclock = mse_clock;
}

View File

@@ -158,9 +158,10 @@ int verilate() {
return 0;
}
char ps2_scancode = 0;
char ps2_toggle = 0;
char ps2_timer = 0;
unsigned char mouse_clock = 0;
unsigned char mouse_buttons= 0;
unsigned char mouse_x = 0;
unsigned char mouse_y = 0;
char spinner_toggle = 0;
@@ -370,15 +371,25 @@ int main(int argc, char** argv, char** env) {
if (input.inputs[0] || input.inputs[1]) {
spinner_toggle = !spinner_toggle;
top->spinner_0 = (input.inputs[0]) ? 16 : -16;
top->spinner_0 = (input.inputs[0]) ? 4 : -4;
for (char b = 8; b < 16; b++) {
top->spinner_0 &= ~(1UL << b);
}
if (spinner_toggle) { top->spinner_0 |= 1UL << 8; }
}
top->ps2_mouse += 1;
top->ps2_mouse_ext -= 1;
mouse_buttons += 1;
mouse_x += 1;
mouse_y -= 1;
unsigned long mouse_temp = mouse_buttons;
mouse_temp += (mouse_x << 8);
mouse_temp += (mouse_y << 16);
if (mouse_clock) { mouse_temp |= (1UL << 24); }
mouse_clock = !mouse_clock;
top->ps2_mouse = mouse_temp;
//top->ps2_mouse_ext -= 1;
// Run simulation
if (run_enable) {