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

View file

@ -1,15 +1,23 @@
#!/bin/bash -ex
#!/bin/bash -e
PROJECT=ifengine
DATA=(8x8thin.sta gamedata.z5)
# --- HERE BE DRAGONS ---
TARGET=${JOEY}/sdks/iix/IIgs/out/${PROJECT}
GSTARGET=31:/out/${PROJECT}
AC=${JOEY}/sdks/iix/ac/
IMPORT=/tmp/import.po
if [ -d ${TARGET} ]; then
rm -rf ${TARGET}
fi
mkdir -p ${TARGET}
rm JLSTATS || true
rm /tmp/import.po || true
cp -f ${JOEY}/dist/joey.h .
CFILES=($(ls -1 *.c))
OFILES=""
@ -24,3 +32,17 @@ rm joey.h
cp -f ${JOEY}/dist/IIgs/joeylib#b20000 ${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}
${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

102
joeyio.c
View file

@ -3,7 +3,10 @@
#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) {
@ -72,95 +75,68 @@ void initialize_screen(void) {
int input_character(int timeout) {
char k = 0;
(void)timeout; // In 1/10ths of a second
if (!jlKeyPressed()) {
while (!jlKeyPressed() && !jlUtilMustExit()) {
//***TODO*** Animate cursor here?
// Animate cursor
if (_cursorTime != jlUtilTimer()) {
display_char(_cursor[_cursorIndex++]);
display_char(8);
if (_cursorIndex >= _cursorSize) {
_cursorIndex = 0;
}
if (jlKeyPressed()) {
while (jlKeyPressed()) {
_cursorTime = jlUtilTimer();
}
}
display_char(32);
display_char(8);
}
while (jlKeyPressed() && !jlUtilMustExit()) {
// Wait for key to be released
}
k = jlKeyRead();
} else {
if (jlUtilMustExit() && (interpreter_state == RUN)) {
interpreter_state = STOP;
}
return (int)k;
}
int input_line(int buflen, char *buffer, int timeout, int *read_size) {
int c = -1;
int col;
int row;
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;
int c = 0;
int curr_char_pos = 0;
(void)timeout;
while (!jlUtilMustExit()) {
c = input_character(0);
if (c > 0) {
if (c == 8) {
// Backspace
get_cursor_position(&row, &col);
if (col > head_col) {
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);
if (*read_size == 0) {
//***TODO*** Flash border or ding or something
} else {
--*read_size;
--curr_char_pos;
display_char(8);
display_char(32);
display_char(8);
}
} else {
// Normal key
// Normal Key
if (*read_size == (buflen - 1)) {
//***TODO*** Buffer full - Flash border?
//***TODO*** Flash border or ding or something
} else {
if (c == 13) {
// CR
scroll_line();
return c;
} else {
// Used if the cursor is not at the end of the line
if (col < tail_col) {
// Moves the input line one character to the right
for (loop = *read_size; loop >= curr_char_pos; loop--) {
buffer[loop + 1] = buffer[loop];
}
// Puts the character into the space created by the "for" loop above
buffer[curr_char_pos] = (char)c;
// Increment the end of the line values
(*read_size)++;
tail_col++;
// 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 {
// Used if the cursor is at the end of the line
buffer[curr_char_pos++] = (char)c;
if (*read_size < curr_char_pos) {
*read_size = curr_char_pos;
}
display_char(c);
(*read_size)++;
tail_col++;
}
}
}

3
main.c
View file

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