static void videoPutChar( char ch ) { switch ( ch ) { case '\b': { if ( column ) column--; /* Move cursor on the previous location */ wr_cursor( row, column ); return; } case '\t': { int i; i = TAB_SPACE - ( column & ( TAB_SPACE - 1 ) ); while ( i-- ) { video_drawchars( row, column, ' ' ); column += 1; if ( column >= maxCol ) { doCRNL( 1, 1 ); return; } } wr_cursor( row, column ); return; } case '\n': { doCRNL( 0, 1 ); return; } case 7: { /* Bell code must be inserted here */ return; } case '\r': { doCRNL( 1, 0 ); return; } case BLANK: { video_drawchars( row, column, ' ' ); wr_cursor( row, column ); return; } default: { // *pt_bitmap = (unsigned char)ch | attribute; video_drawchars( row, column, ch ); advanceCursor(); return; } } }
int main(void) { init_IO(); init_interrupts(); oledInit(); _delay_ms(200); oledSetCursor(cursX, cursY); putChar(66,1); advanceCursor(6); compose(); initMenu(); while(1) { static uint16_t butCounter = 0; if (butCounter++ > 65000) { //FIXME: Proper button debounce and handling butCounter = 0; uint8_t readButtons = BUT_PIN; if (~readButtons & BUT_LEFT) { ++goLeft; } if (~readButtons & BUT_SEL) { ++goSel; } } if (knobChange) { if (knobChange > 0) { //menuUp(); knobLeft(); } else { //menuDn(); knobRight(); } knobChange = 0; } if (goSel) { //Lookup and execute action doSelect[optionIndex](); goSel = 0; } else if (goLeft) { doBack(); goLeft = 0; } } }
static void videoPutChar(char car) { unsigned short *pt_bitmap = bitMapBaseAddr + row * maxCol + column; switch (car) { case '\b': { if (column) column--; /* Move cursor on the previous location */ wr_cursor(row * maxCol + column, ioCrtBaseAddr); return; } case '\t': { int i; i = TAB_SPACE - (column & (TAB_SPACE - 1)); column += i; if (column >= maxCol) { doCRNL(1,1); return; } while (i--) *pt_bitmap++ = ' ' | attribute; wr_cursor(row * maxCol + column, ioCrtBaseAddr); return; } case '\n': { doCRNL(0,1); return; } case 7: { /* Bell code must be inserted here */ return; } case '\r' : { doCRNL(1,0); return; } case BLANK: { *pt_bitmap = ' ' | attribute; /* DONT move the cursor... */ return; } default: { *pt_bitmap = (unsigned char)car | attribute; advanceCursor(); return; } } }
// dest: MUST already contain a string, even if empty. // maxLineLength: Must include room for terminating NUL. // Returns TRUE if the user pressed Enter, FALSE if Break. // byte getLineFromUser(char *dest, word maxLineLength, word initIndex) { saveCursorPosition(); word index = initIndex; // offset of cursor in 'dest' // Print the existing string, if any. // word curLen = strlen(dest); putstr(dest, curLen); // Put the cursor at 'initIndex'. // restoreCursorPosition(); advanceCursor(initIndex); char key; for (;;) { animateCursor(); key = (char) tolower(inkey()); if (!key) continue; if (key == '\r' || key == '\n' || key == BREAK_CHAR) // if Enter (CoCo or PC) or Break { dest[curLen] = 0; break; } removeCursor(); if (key == CLEAR_CHAR) // if backspace { if (index > 0) { word numCharsToMove = curLen - index; moveBackwardOneByte(dest + index, numCharsToMove); --index; --curLen; putchar('\b'); byte finalX = textPosX, finalY = textPosY; putstr(dest + index, numCharsToMove); putchar(' '); // erase last char from screen moveCursor(finalX, finalY); // place cursor at erased char } continue; } if (key == SHIFT_CLEAR_CHAR) // if delete { if (index < curLen) { word numCharsToMove = curLen - index - 1; moveBackwardOneByte(dest + index + 1, numCharsToMove); --curLen; byte finalX = textPosX, finalY = textPosY; putstr(dest + index, numCharsToMove); putchar(' '); // erase last char from screen moveCursor(finalX, finalY); // place cursor at erased char } continue; } if (key == LEFT_CHAR) // if move cursor left { if (index > 0) { --index; putchar('\b'); } continue; } if (key == RIGHT_CHAR) // if move cursor right { if (index < curLen) { ++index; advanceCursor(1); } continue; } if (key == KILL_LINE_CHAR) // if shift-backspace { for (word i = 0; i < index; ++i) // back up cursor to beginning putchar('\b'); byte finalX = textPosX, finalY = textPosY; for (word i = 0; i < curLen; ++i) // erase entire line putchar(' '); moveCursor(finalX, finalY); // put cursor at beginning index = 0; curLen = 0; continue; } if (key < ' ' || key >= 127) continue; // ignore invalid characters if (curLen < maxLineLength - 1) // if still room { moveForwardOneByte(dest + index, curLen + 1 - index); // include terminating NUL dest[index] = key; ++curLen; saveCursorPosition(); putstr(dest + index, curLen - index); restoreCursorPosition(); advanceCursor(1); ++index; } } removeCursor(); return key != BREAK_CHAR; }