First working build. Speed issues. Lots of debug code.

This commit is contained in:
Scott Duensing 2018-09-09 18:53:42 -05:00
parent c4e3fb7939
commit b30c9d5f62
5 changed files with 128 additions and 90 deletions

View file

@ -9,6 +9,9 @@ segment "ansiterm";
#include "ansiterm.h" #include "ansiterm.h"
// http://ansi-bbs.org/ansi-bbs-core-server.html
typedef struct { typedef struct {
int x; int x;
int y; int y;
@ -24,6 +27,7 @@ static bool _inEscape = false;
static bool _bold = false; static bool _bold = false;
static bool _blink = false; static bool _blink = false;
static bool _reverse = false; static bool _reverse = false;
static bool _destructiveBS = false;
static int _foreground = 7; static int _foreground = 7;
static int _background = 0; static int _background = 0;
static int _fColor = 7; static int _fColor = 7;
@ -31,15 +35,15 @@ static int _bColor = 0;
static int _number = 0; static int _number = 0;
static int _parameters[5]; static int _parameters[5];
static int _parameterCount = 0; static int _parameterCount = 0;
static jlStaT *_ansiFont = NULL;
static Vector2T _cursorSave; static Vector2T _cursorSave;
static Vector2T _cursor; static Vector2T _cursor;
static jlStaT *_ansiFont = NULL; static Vector2T *_screenBuffer = NULL;
static int *_screenBuffer = NULL;
void termDebug(const char *what, ...); void termDebug(const char *what, ...);
bool termParseANSI(char c); bool termParseANSI(char c);
void termRenderCharacterAtCursor(char c); void termRenderCharacterAtCursor(byte c);
void termRepaint(void); void termRepaint(void);
void termResetSequence(void); void termResetSequence(void);
void termScrollUp(void); void termScrollUp(void);
@ -47,7 +51,15 @@ void termUpdateColors(void);
void termClearScreen(void) { void termClearScreen(void) {
memset(_screenBuffer, 0, (size_t)(2 * _columns * _rows)); int i = 0;
int x;
int y;
for (y=0; y<_rows; y++) {
for (x=0; x<_columns; x++) {
_screenBuffer[i].x = 0;
_screenBuffer[i].y = 0;
}
}
} }
@ -64,6 +76,11 @@ void termDebug(const char *what, ...) {
} }
void termDestruciveBackspace(bool dbs) {
_destructiveBS = dbs;
}
void termGetCursor(int *x, int *y) { void termGetCursor(int *x, int *y) {
*x = _cursor.x; *x = _cursor.x;
*y = _cursor.y; *y = _cursor.y;
@ -387,8 +404,21 @@ bool termParseANSI(char c) {
break; break;
case (char)8: case (char)8:
case (char)127: case (char)127:
//***TODO*** Backspace // Backspace
termDebug("Unimplemented backspace"); if (cursor.x > 1) {
cursor.x--;
} else {
if (cursor.y > 1) {
termDebug("Cursor wrapped off left");
cursor.y--;
cursor.x = _columns;
}
}
termMoveCursor(cursor.x, cursor.y);
if (_destructiveBS) {
termRenderCharacterAtCursor(' ');
updateDisplay = true;
}
break; break;
case (char)9: case (char)9:
//***TODO*** TAB //***TODO*** TAB
@ -418,15 +448,17 @@ bool termParseANSI(char c) {
break; break;
default: default:
updateDisplay = true; updateDisplay = true;
termRenderCharacterAtCursor(c); termRenderCharacterAtCursor((byte)c);
if (_blink) { if (_blink) {
//***TODO*** Not handled //***TODO*** Not handled
} }
cursor.x++; cursor.x++;
if (cursor.x > _columns) { if (cursor.x > _columns) {
termDebug("Cursor wrapped off right");
cursor.x = 1; cursor.x = 1;
cursor.y++; cursor.y++;
if (cursor.y > _rows) { if (cursor.y > _rows) {
termDebug("Cursor went off bottom");
cursor.y--; cursor.y--;
termScrollUp(); termScrollUp();
} }
@ -456,11 +488,13 @@ void termPrintChar(char c) {
} }
void termRenderCharacterAtCursor(char c) { void termRenderCharacterAtCursor(byte c) {
int r = (_reverse ? 7 : 0); int r = (_reverse ? 7 : 0);
int cx = c % 40; int cx = c % 40;
int cy = (c / 40) + r; int cy = (c / 40) + r;
_screenBuffer[(_cursor.y * _columns) + _cursor.x] = (cy * 40) + cx; int i = ((_cursor.y - 1) * _columns) + (_cursor.x - 1);
_screenBuffer[i].x = cx;
_screenBuffer[i].y = cy;
jlDrawBlit8x8(_ansiFont, cx, cy, _cursor.x - 1 + _xoff, _cursor.y - 1 + _yoff); jlDrawBlit8x8(_ansiFont, cx, cy, _cursor.x - 1 + _xoff, _cursor.y - 1 + _yoff);
} }
@ -471,7 +505,7 @@ void termRepaint(void) {
int y; int y;
for (y=0; y<_rows; y++) { for (y=0; y<_rows; y++) {
for (x=0; x<_columns; x++) { for (x=0; x<_columns; x++) {
jlDrawBlit8x8(_ansiFont, _screenBuffer[i] % 40, _screenBuffer[i] / 40, x, y); jlDrawBlit8x8(_ansiFont, _screenBuffer[i].x, _screenBuffer[i].y, x, y);
i++; i++;
} }
} }
@ -498,11 +532,16 @@ void termSaveCursor(void) {
void termScrollUp(void) { void termScrollUp(void) {
int x; int x;
int c = _columns * (_rows - 1);
int i = 0; int i = 0;
int j = _columns; int j = _columns;
for (x=0; x < (_rows - 1) * _columns; x++) { for (x=0; x < c; x++) {
_screenBuffer[i++] = _screenBuffer[j++]; _screenBuffer[i++] = _screenBuffer[j++];
} }
for (x=0; x<_columns; x++) {
_screenBuffer[i].x = 32;
_screenBuffer[i++].y = 0;
}
termRepaint(); termRepaint();
} }
@ -517,7 +556,8 @@ void termStart(jlStaT *font, int xoff, int yoff, int cols, int rows) {
_cursorSave.y = 1; _cursorSave.y = 1;
_cursor.x = 1; _cursor.x = 1;
_cursor.y = 1; _cursor.y = 1;
_screenBuffer = (int *)jlMalloc((size_t)(2 * _columns * _rows)); _screenBuffer = (Vector2T *)jlMalloc(sizeof(Vector2T) * (size_t)(_columns * _rows));
termClearScreen();
} }

View file

@ -4,6 +4,7 @@
#include "joey.h" #include "joey.h"
void termClearScreen(void); void termClearScreen(void);
void termDestruciveBackspace(bool dbs);
void termGetCursor(int *x, int *y); void termGetCursor(int *x, int *y);
void termMoveCursor(int x, int y); void termMoveCursor(int x, int y);
void termPrint(char *string); void termPrint(char *string);

View file

@ -1,15 +1,23 @@
#!/bin/bash -ex #!/bin/bash -e
PROJECT=ifengine PROJECT=ifengine
DATA=(8x8thin.sta gamedata.z5)
# --- HERE BE DRAGONS ---
TARGET=${JOEY}/sdks/iix/IIgs/out/${PROJECT} TARGET=${JOEY}/sdks/iix/IIgs/out/${PROJECT}
GSTARGET=31:/out/${PROJECT} GSTARGET=31:/out/${PROJECT}
AC=${JOEY}/sdks/iix/ac/
IMPORT=/tmp/import.po
if [ -d ${TARGET} ]; then if [ -d ${TARGET} ]; then
rm -rf ${TARGET} rm -rf ${TARGET}
fi fi
mkdir -p ${TARGET} mkdir -p ${TARGET}
rm JLSTATS || true
rm /tmp/import.po || true
cp -f ${JOEY}/dist/joey.h . cp -f ${JOEY}/dist/joey.h .
CFILES=($(ls -1 *.c)) CFILES=($(ls -1 *.c))
OFILES="" OFILES=""
@ -24,3 +32,17 @@ rm joey.h
cp -f ${JOEY}/dist/IIgs/joeylib#b20000 ${JOEY}/sdks/iix/IIgs/Libraries/joeylib cp -f ${JOEY}/dist/IIgs/joeylib#b20000 ${JOEY}/sdks/iix/IIgs/Libraries/joeylib
iix chtyp -t lib ${JOEY}/sdks/iix/IIgs/Libraries/joeylib iix chtyp -t lib ${JOEY}/sdks/iix/IIgs/Libraries/joeylib
iix -DKeepType=S16 link ${OFILES} 13:joeylib keep=${GSTARGET}/${PROJECT} iix -DKeepType=S16 link ${OFILES} 13:joeylib keep=${GSTARGET}/${PROJECT}
${AC}/import.sh ${TARGET}/${PROJECT} S16
for F in "${DATA[@]}"; do
${AC}/import.sh ${F} BIN
done
if [ -z $1 ]; then
pushd ${JOEY}/sdks/iix/gsplus
./gsplus -config IIgsTest.cfg || true
popd
echo ""
${AC}/export.sh JLSTATS
cat JLSTATS
fi

126
joeyio.c
View file

@ -3,7 +3,10 @@
#include "ztypes.h" #include "ztypes.h"
static int head_col; static int _cursorIndex = 0;
static int _cursorSize = 9;
static unsigned int _cursorTime = 0;
static byte _cursor[] = { 32, 176, 177, 178, 219, 178, 177, 176, 32 };
void clear_line(void) { void clear_line(void) {
@ -72,95 +75,68 @@ void initialize_screen(void) {
int input_character(int timeout) { int input_character(int timeout) {
char k = 0; char k = 0;
(void)timeout; // In 1/10ths of a second (void)timeout; // In 1/10ths of a second
while (!jlKeyPressed() && !jlUtilMustExit()) { if (!jlKeyPressed()) {
//***TODO*** Animate cursor here? while (!jlKeyPressed() && !jlUtilMustExit()) {
} // Animate cursor
if (jlKeyPressed()) { if (_cursorTime != jlUtilTimer()) {
while (jlKeyPressed()) { display_char(_cursor[_cursorIndex++]);
// Wait for key to be released display_char(8);
if (_cursorIndex >= _cursorSize) {
_cursorIndex = 0;
}
_cursorTime = jlUtilTimer();
}
} }
k = jlKeyRead(); display_char(32);
} else { display_char(8);
}
while (jlKeyPressed() && !jlUtilMustExit()) {
// Wait for key to be released
}
k = jlKeyRead();
if (jlUtilMustExit() && (interpreter_state == RUN)) {
interpreter_state = STOP; interpreter_state = STOP;
} }
return (int)k; return (int)k;
} }
int input_line(int buflen, char *buffer, int timeout, int *read_size) { int input_line(int buflen, char *buffer, int timeout, int *read_size) {
int c = -1; int c = 0;
int col; int curr_char_pos = 0;
int row; (void)timeout;
int init_char_pos;
int curr_char_pos;
int loop;
int tail_col;
(void)timeout; // In 1/10ths of a second
get_cursor_position(&row, &col);
head_col = tail_col = col;
init_char_pos = curr_char_pos = *read_size;
while (!jlUtilMustExit()) { while (!jlUtilMustExit()) {
c = input_character(0); c = input_character(0);
if (c > 0) {
if (c == 8) { if (c == 8) {
// Backspace // Backspace
get_cursor_position(&row, &col); if (*read_size == 0) {
if (col > head_col) { //***TODO*** Flash border or ding or something
move_cursor(row, --col);
for (loop = curr_char_pos; loop < *read_size; loop++) {
buffer[loop - 1] = buffer[loop];
display_char(buffer[loop - 1]);
}
display_char(' ');
curr_char_pos--;
tail_col--;
(*read_size)--;
move_cursor(row, col);
}
} else {
// Normal key
if (*read_size == ( buflen - 1 )) {
//***TODO*** Buffer full - Flash border?
} else {
if (c == 13) {
// CR
scroll_line();
return c;
} else { } else {
// Used if the cursor is not at the end of the line --*read_size;
if (col < tail_col) { --curr_char_pos;
// Moves the input line one character to the right display_char(8);
for (loop = *read_size; loop >= curr_char_pos; loop--) { display_char(32);
buffer[loop + 1] = buffer[loop]; display_char(8);
} }
} else {
// Puts the character into the space created by the "for" loop above // Normal Key
buffer[curr_char_pos] = (char)c; if (*read_size == (buflen - 1)) {
//***TODO*** Flash border or ding or something
// Increment the end of the line values } else {
(*read_size)++; if (c == 13) {
tail_col++; scroll_line();
return c;
// Move the cursor back to its original position
move_cursor(row, col);
// Redisplays the input line from the point of insertion
for (loop = curr_char_pos; loop < *read_size; loop++) {
display_char(buffer[loop]);
}
// Moves the cursor to the next position
move_cursor(row, ++col);
curr_char_pos++;
} else { } else {
// Used if the cursor is at the end of the line
buffer[curr_char_pos++] = (char)c; buffer[curr_char_pos++] = (char)c;
if (*read_size < curr_char_pos) {
*read_size = curr_char_pos;
}
display_char(c); display_char(c);
(*read_size)++;
tail_col++;
} }
} }
} }

3
main.c
View file

@ -100,6 +100,7 @@ int main(void) {
jlStaLoad(font, "8x8thin.sta"); jlStaLoad(font, "8x8thin.sta");
termStart(font, 0, 0, 40, 25); termStart(font, 0, 0, 40, 25);
termDestruciveBackspace(false);
process_arguments("gamedata.z5"); process_arguments("gamedata.z5");
configure(V1, V8); configure(V1, V8);
@ -114,8 +115,6 @@ int main(void) {
termStop(); termStop();
jlDisplayPresent();
jlKeyWaitForAny();
jlStaFree(font); jlStaFree(font);
jlUtilShutdown(); jlUtilShutdown();