2 * Copyright (C) 2006 Paul Davis
3 * Copyright (C) 2007 Michael Taht
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <tranzport_control_protocol.h>
24 TranzportControlProtocol::screen_clear ()
26 const char *blank = " ";
31 void TranzportControlProtocol::screen_invalidate ()
34 for(int row = 0; row < ROWS; row++) {
35 for(int col = 0; col < COLUMNS; col++) {
36 screen_current[row][col] = 0x7f;
37 screen_pending[row][col] = ' ';
38 screen_flash[row][col] = ' ';
43 void TranzportControlProtocol::screen_validate ()
47 void TranzportControlProtocol::screen_init ()
52 // FIXME: Switch to a column oriented flush to make the redraw of the
56 TranzportControlProtocol::screen_flush ()
58 int cell = 0, row=0, col_base, pending = 0;
59 const unsigned long CELL_BITS = 0x0F;
60 if ( _device_status == STATUS_OFFLINE) { return (-1); }
62 std::bitset<ROWS*COLUMNS> mask(CELL_BITS);
63 std::bitset<ROWS*COLUMNS> imask(CELL_BITS);
64 for(cell = 0; cell < 10 && pending == 0; cell++) {
65 mask = imask << (cell*4);
66 if((screen_invalid & mask).any()) {
67 /* something in this cell is different, so dump the cell to the device. */
68 #if DEBUG_TRANZPORT_SCREEN
69 printf("MASK : %s\n", mask.to_string().c_str());
71 if(cell > 4) { row = 1; } else { row = 0; }
72 col_base = (cell*4)%COLUMNS;
78 cmd[3] = screen_pending[row][col_base];
79 cmd[4] = screen_pending[row][col_base+1];
80 cmd[5] = screen_pending[row][col_base+2];
81 cmd[6] = screen_pending[row][col_base+3];
84 if((pending = lcd_write(cmd)) == 0) {
85 /* successful write: copy to current cached display */
86 screen_invalid &= mask.flip();
87 memcpy (&screen_current[row][col_base], &screen_pending[row][col_base], 4);