Add highlighting, fixed len instructions and more

This commit is contained in:
2025-02-09 21:15:50 +01:00
parent 45653b6372
commit e133c2df3a
17 changed files with 753 additions and 338 deletions

View File

@@ -13,6 +13,7 @@
#include <SDL2/SDL_surface.h>
#include <SDL2/SDL_render.h>
#include "font.h"
#include "../cpu/core.h"
typedef struct {
char *text; // Dynamically allocated string for this line
@@ -22,25 +23,26 @@ typedef struct {
typedef struct {
Line *lines; // Dynamic array of lines
int line_count; // Number of active lines
int max_lines_asm; // Maximum number of lines (e.g. assembly lines)
int maxLines; // Maximum number of lines (e.g. assembly lines)
int max_line_width; // Maximum characters per line (excluding '\0')
int max_lines_display; // Maximum number of lines for display
int displayLineCount; // Maximum number of lines for display
int cursor_line; // Current cursor line
int cursor_line_offset; // Display offset (first line in the display)
int cursor_pos; // Current cursor position in line
char *outputString; // Dynamically allocated output string (size: max_line_width * max_lines_asm + 1)
char *displayString; // Dynamically allocated display string (size: max_line_width * max_lines_display + 1)
char *outputString; // Dynamically allocated output string (size: max_line_width * maxLines + 1)
char *displayString; // Dynamically allocated display string (size: max_line_width * displayLineCount + 1)
SDL_Rect *rect;
SDL_Rect *outRect;
SDL_Texture *texture;
bool readOnly;
BitmapFont *font;
SDL_Rect *cursorRect;
SDL_Rect *highlightedLineRect;
} TextEditor;
// Initialize the text editor. The parameters max_line_width, max_lines_asm, and max_lines_display
// Initialize the text editor. The parameters max_line_width, maxLines, and displayLineCount
// determine the dynamic sizes for the text editor.
void init_editor(TextEditor *editor, BitmapFont *font, int x, int y, SDL_Renderer *renderer,
int max_line_width, int max_lines_asm, int max_lines_display, bool readOnly);
@@ -50,7 +52,7 @@ void insert_line(TextEditor *editor, int position, const char *text, SDL_Rendere
void insert_line_rel(TextEditor *editor, SDL_Renderer *renderer);
void editor_render(TextEditor *editor, SDL_Renderer *renderer, bool isActive, bool cursorBlink);
void editor_render(TextEditor *editor, SDL_Renderer *renderer, CPU *cpu, uint8_t editorIndex, bool isActive, bool cursorBlink);
void remove_character(TextEditor *editor, bool isDelete, SDL_Renderer *renderer);
@@ -64,7 +66,8 @@ void generate_string_display(TextEditor *editor, SDL_Renderer *renderer);
void generate_string(TextEditor *editor);
void fill_editor_from_string(TextEditor *editor, const char *content, SDL_Renderer *renderer);
void fill_editor_from_string(TextEditor *editor, const char *content, int lineStart, bool isComplete,
SDL_Renderer *renderer);
// A cleanup function to free dynamically allocated memory.
void destroy_editor(TextEditor *editor);