summaryrefslogtreecommitdiff
path: root/programs/c-ports
diff options
context:
space:
mode:
Diffstat (limited to 'programs/c-ports')
-rw-r--r--programs/c-ports/subasm.c24
-rw-r--r--programs/c-ports/subeditor.c205
-rw-r--r--programs/c-ports/subeditor.h19
3 files changed, 206 insertions, 42 deletions
diff --git a/programs/c-ports/subasm.c b/programs/c-ports/subasm.c
index 89d1507..73bb74c 100644
--- a/programs/c-ports/subasm.c
+++ b/programs/c-ports/subasm.c
@@ -1,18 +1,7 @@
#include "subeditor.h"
-struct line {
- uint8_t dir;
- uint8_t mne;
- uint8_t am;
- uint8_t opbase;
- uint16_t com;
- uint16_t label;
- uint64_t op;
-};
-char *label[0x1000];
+
uint64_t label_addr[0x1000];
-/*char *comment[0x1000];*/
-/*char *string[0x1000];*/
enum dir {
DIR_ORG,
@@ -52,9 +41,8 @@ enum base {
};
-char lexeme[0x100];
+char lexeme[0x200];
uint8_t lex_type;
-struct line tokline[0x1000];
uint16_t linenum = 10;
static const char *mne_t[90] = {
@@ -258,7 +246,7 @@ uint8_t lex(char *str) {
uint16_t j = 0;
lex_type = 0xFF;
uint8_t k = 0;
- int line = 40;
+ int line = 56;
int16_t ln = -1;
int y, x;
char lnum[6];
@@ -333,12 +321,12 @@ uint8_t lex(char *str) {
case ';':
i++;
while (str[i] != '\0') {
- lexeme[j++] = str[i++];
+ lexeme[j] = str[i];
/*comment[linenum][j] = str[i];*/
- /*j++, i++;*/
+ j++, i++;
}
lexeme[j] = '\0';
- /*comment[linenum][j] = '\0';*/
+ comment[linenum][j] = '\0';
lex_type = TOK_COMMENT;
break;
case '#':
diff --git a/programs/c-ports/subeditor.c b/programs/c-ports/subeditor.c
index 76ee544..44ca288 100644
--- a/programs/c-ports/subeditor.c
+++ b/programs/c-ports/subeditor.c
@@ -45,6 +45,7 @@ uint8_t scr_trow = 0;
uint8_t scr_tcol = 0;
uint16_t scr_ptr = 0;
uint16_t scr_ptr2 = 0;
+uint16_t scr_ptr3 = 0;
uint8_t byte = 0;
uint8_t mask = 0;
@@ -141,6 +142,62 @@ void clr_cbuf() {
}
}
+#define dir(a) tokline[a].dir
+#define mne(a) tokline[a].mne
+#define amo(a) tokline[a].am
+#define opb(a) tokline[a].opbase
+#define com(a) tokline[a].com
+#define lab(a) tokline[a].label
+#define opc(a) tokline[a].op
+
+#define tok(a) { \
+ dir(a) = 0xFF; \
+ mne(a) = 0xFF; \
+ amo(a) = 0xFF; \
+ opb(a) = 0xFF; \
+ com(a) = 0xFFFF; \
+ lab(a) = 0xFFFF; \
+ opc(a) = 0xFF; \
+}
+void clr_tokline() {
+ uint16_t i = 0;
+ for (; i < 0x2000;) {
+ tok(i+0x00);
+ tok(i+0x01);
+ tok(i+0x02);
+ tok(i+0x03);
+ tok(i+0x04);
+ tok(i+0x05);
+ tok(i+0x06);
+ tok(i+0x07);
+ tok(i+0x08);
+ tok(i+0x09);
+ tok(i+0x0A);
+ tok(i+0x0B);
+ tok(i+0x0C);
+ tok(i+0x0D);
+ tok(i+0x0E);
+ tok(i+0x0F);
+ tok(i+0x10);
+ tok(i+0x11);
+ tok(i+0x12);
+ tok(i+0x13);
+ tok(i+0x14);
+ tok(i+0x15);
+ tok(i+0x16);
+ tok(i+0x17);
+ tok(i+0x18);
+ tok(i+0x19);
+ tok(i+0x1A);
+ tok(i+0x1B);
+ tok(i+0x1C);
+ tok(i+0x1D);
+ tok(i+0x1E);
+ tok(i+0x1F);
+ i+=0x20;
+ }
+}
+
void update_pos() {
scr_ptr = (scr_row+scr_str)*80;
scr_ptr += scr_col;
@@ -163,12 +220,26 @@ void rdrw_row() {
}
scr_col++;
if (!buffer[ptr+i]) {
- update_pos();
+ #if !debug
+ waddch(scr, ' ');
+ #endif
}
}
scr_col = 0;
}
+void rdrw_ln(uint8_t start, uint8_t end) {
+ uint8_t tmp_row = scr_row;
+ uint8_t tmp_col = scr_col;
+ scr_row = start;
+ for (; scr_row <= end; ) {
+ rdrw_row();
+ ++scr_row;
+ }
+ scr_row = tmp_row;
+ scr_col = tmp_col;
+}
+
void scrl_down() {
scr_str++;
scr_end++;
@@ -201,9 +272,6 @@ void bitpos(uint8_t row) {
bit = row & 7;
mask = bits[bit];
byte = bitmask >> 3;
- #if debug
- /*mvwprintw(scr, 2, 0, "bit: $%02X, row: $%02X, byte: $%02X, mask: $%02X, bitmask: $%02X\r", bit, row, byte, mask, bitmask);*/
- #endif
}
void clrbit (uint8_t row) {
@@ -231,28 +299,68 @@ uint8_t getbit() {
return (mask & bitabl[byte]);
}
-void findst() {
+uint8_t findst() {
+ uint8_t line_count = 0;
while (getbit()) {
+ line_count++;
scr_row--;
if ((int8_t)scr_row < 0) {
+ line_count--;
scr_row++;
+ break;
}
}
+ return line_count;
}
+void fndend() {
+ uint16_t i = scr_ptr;
+ for (; buffer[i] != '\0'; i++);
+ scr_ptr3 = i;
+}
+
+void findend() {
+ fndend();
+ c = (uint16_t)(scr_ptr3/80);
+}
+
+
void shftln(uint16_t src, uint16_t dst, uint8_t flag) {
if (!flag) {
while (buffer[src] != '\0') {
buffer[dst++] = buffer[src];
buffer[src++] = '\0';
}
+ scr_ptr2 = scr_ptr;
+ scr_ptr = src;
+ findend();
+ scr_ptr = scr_ptr2;
+ if ((scr_ptr3 % 80 == 0) && (c > scr_row)) {
+ clrbit(c);
+ }
} else {
while (scr_ptr <= src) {
- mvwprintw(scr, 2, 0, "buffer[0x%04X]: $%02X, buffer[0x%04X]: $%02X, src: $%04X, dst: $%04X, scr_ptr: $%04X\r", src, buffer[src], dst, buffer[dst], src, dst, scr_ptr);
- wrefresh(scr);
+ if ((int16_t) src < 0) {
+ src = 0;
+ buffer[src] = '\0';
+ break;
+ }
buffer[dst--] = buffer[src];
buffer[src--] = '\0';
}
+ if (buffer[src+1] == '\0') {
+ buffer[src+1] = ' ';
+ }
+ scr_ptr2 = scr_ptr;
+ scr_ptr = src;
+ findend();
+ scr_ptr = scr_ptr2;
+ if (buffer[src+1] == ' ') {
+ buffer[src+1] = '\0';
+ }
+ if (c > scr_row) {
+ setbit(c);
+ }
}
}
@@ -262,6 +370,8 @@ void print_char(char ch) {
uint8_t is_esc = 0;
uint8_t done = 0;
uint16_t i = 0;
+ uint16_t x = 0;
+ uint16_t y = 0;
a = ch;
switch (ch) {
case 0x1B:
@@ -387,6 +497,7 @@ void print_char(char ch) {
scr_str = 0;
clr_bitabl();
clr_buf();
+ clr_tokline();
clr_cbuf();
scr_row = 0;
scr_col = 0;
@@ -409,7 +520,6 @@ void print_char(char ch) {
break;
}
}
- clrbit(scr_row+scr_str);
scr_row--;
scr_col = 80;
update_pos();
@@ -417,23 +527,52 @@ void print_char(char ch) {
break;
}
}
- scr_col--;
- update_pos();
- buffer[scr_ptr] = 0;
+ e = 0;
+ scr_trow = scr_row;
+ findend();
+ scr_row = c;
+ e = findst();
+ buffer[--scr_ptr] = 0;
shftln(scr_ptr+1, scr_ptr, 0);
#if !debug
- wdelch(scr);
+ int y, x;
+ getyx(scr, y, x);
+ if (x > 0) {
+ wmove(scr, y, x-1);
+ }
+ wdelch(scr);
#endif
+ if (e) {
+ findend();
+ scr_tcol = scr_col;
+ rdrw_ln(scr_row, c);
+ scr_col = scr_tcol;
+ }
+ scr_row = scr_trow;
+ scr_col--;
+ update_pos();
break;
default:
- if (buffer[scr_ptr] != '\0') {
- for (i = scr_ptr; buffer[i] != '\0'; i++);
- scr_ptr2 = scr_ptr-1;
- shftln(i-1, i, 1);
- i = 0;
+ d = 0;
+ if (buffer[scr_ptr] != '\0' && !b) {
+ fndend();
+ scr_ptr3++;
+ shftln(scr_ptr3-2, scr_ptr3-1, 1);
+ scr_trow = scr_row;
+ scr_tcol = scr_col;
+ a = ch;
+ buffer[scr_ptr] = ch;
+ findend();
+ scr_row = c;
+ findst();
+ rdrw_ln(scr_row, c);
+ scr_row = scr_trow;
+ scr_col = scr_tcol;
+ update_pos();
+ } else {
+ a = ch;
+ buffer[scr_ptr] = ch;
}
- a = ch;
- buffer[scr_ptr] = ch;
scr_col++;
#if !debug
waddch(scr, ch);
@@ -457,19 +596,26 @@ void print_char(char ch) {
uint8_t getkey(char ch) {
e = 0;
+ b = 0;
if (ch == '\n') {
uint16_t i = 0;
uint16_t ptr;
+ scr_trow = scr_row;
+ findend();
+ scr_row = c;
e = scr_row;
- findst(scr_row);
+ findst();
ptr = (scr_row+scr_str)*80;
for (;buffer[ptr+i] != '\0';i++) {
cmd_buf[i] = buffer[ptr+i];
}
+ if (e <= 23) {
+ scr_row = e;
+ } else {
+ scr_row = 23;
+ }
}
- if (e) {
- scr_row = e;
- }
+
print_char(ch);
wrefresh(scr);
if (a == '\n') {
@@ -481,9 +627,11 @@ uint8_t getkey(char ch) {
void print_str(const char *str) {
uint16_t i = 0;
+ b = 1;
for (;str[i] != '\0'; i++) {
print_char(str[i]);
}
+ b = 0;
}
uint8_t dabbed() {
@@ -525,6 +673,7 @@ int main() {
cmd_buf = malloc(0x400);
clr_bitabl();
clr_buf();
+ clr_tokline();
uint8_t end = 0;
uint8_t next = 1;
char ch;
@@ -541,6 +690,7 @@ int main() {
#define maxline 24
#endif
uint8_t ln = 0;
+ int row, col;
mvwprintw(scr, ln++, 0, "scr_row: $%02X, scr_col: $%02X\r", scr_row, scr_col);
mvwprintw(scr, ln++, 0, "scr_str: $%02X, scr_end: $%02X, scr_ptr: $%04X\r", scr_str, scr_end, scr_ptr);
wmove(scr, ++ln, 0);
@@ -550,6 +700,15 @@ int main() {
for (uint16_t i = 0; i < maxline; i++) {
for (uint16_t j = 0; j < 80; j++) {
wprintw(scr, "%02x", buffer[(j+(i*80))]);
+ if (j == scr_col && i == scr_row) {
+ getyx(scr, row, col);
+ wmove(scr, ln++, 0);
+ wclrtoeol(scr);
+ wmove(scr, row+1, col-2);
+ wprintw(scr, "/\\\r");
+ wmove(scr, row, col);
+ wrefresh(scr);
+ }
}
wprintw(scr, ", i: $%02X\r", i);
wmove(scr, ln++, 0);
diff --git a/programs/c-ports/subeditor.h b/programs/c-ports/subeditor.h
index ddb8947..452dfb3 100644
--- a/programs/c-ports/subeditor.h
+++ b/programs/c-ports/subeditor.h
@@ -4,11 +4,12 @@
#include <string.h>
#include <curses.h>
-#define debug 0
+#define debug 1
#define debug_cmd_buf 0
extern WINDOW *scr;
+/* SuBEditor Stuff. */
extern char *buffer;
extern char *cmd_buf;
@@ -35,6 +36,22 @@ extern uint8_t scr_str;
extern uint8_t scr_end;
extern uint8_t wrapped;
+/* SuBAsm Stuff. */
+struct line {
+ uint8_t dir;
+ uint8_t mne;
+ uint8_t am;
+ uint8_t opbase;
+ uint16_t com;
+ uint16_t label;
+ uint64_t op;
+};
+
+char *label[0x1000];
+char *comment[0x1000];
+char *str[0x1000];
+struct line tokline[0x1000];
+
extern void print_str(const char *str);
extern int str_cmp(const char *s0, const char *s1);
extern uint8_t subasm();