/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2002 Gilles Roux * 2003 Garrett Derner * 2010 Yoshihisa Uchida * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ #include "plugin.h" #include "lib/pluginlib_exit.h" #include "tv_action.h" #include "tv_button.h" #include "tv_preferences.h" enum plugin_status plugin_start(const void* file) { int button; #if defined(TV_AUTOSCROLL_PRE) int lastbutton = BUTTON_NONE; #endif bool autoscroll = false; long old_tick; bool done = false; bool display_update = true; size_t size; unsigned char *plugin_buf; old_tick = *rb->current_tick; if (!file) return PLUGIN_ERROR; /* get the plugin buffer */ plugin_buf = rb->plugin_get_buffer(&size); if (!tv_init_action(&plugin_buf, &size)) { rb->splash(HZ, "Error initialize"); return PLUGIN_ERROR; } if (!tv_load_file(file)) { rb->splash(HZ, "Error opening file"); return PLUGIN_ERROR; } atexit(tv_exit); while (!done) { #ifdef HAVE_LCD_BITMAP if (preferences->statusbar) rb->send_event(GUI_EVENT_ACTIONUPDATE, NULL); #endif if (display_update) tv_draw(); display_update = true; button = rb->button_get_w_tmo(HZ/10); switch (button) { case TV_MENU: #ifdef TV_MENU2 case TV_MENU2: #endif { unsigned res = tv_menu(); if (res != TV_MENU_RESULT_EXIT_MENU) { if (res == TV_MENU_RESULT_ATTACHED_USB) return PLUGIN_USB_CONNECTED; else if (res == TV_MENU_RESULT_ERROR) return PLUGIN_ERROR; else done = true; } } break; case TV_AUTOSCROLL: #ifdef TV_AUTOSCROLL_PRE if (lastbutton != TV_AUTOSCROLL_PRE) break; #endif autoscroll = !autoscroll; break; case TV_SCROLL_UP: case TV_SCROLL_UP | BUTTON_REPEAT: #ifdef TV_SCROLL_UP2 case TV_SCROLL_UP2: case TV_SCROLL_UP2 | BUTTON_REPEAT: #endif tv_scroll_up(TV_VERTICAL_SCROLL_PREFS); old_tick = *rb->current_tick; break; case TV_SCROLL_DOWN: case TV_SCROLL_DOWN | BUTTON_REPEAT: #ifdef TV_PAGE_DOWN2 case TV_SCROLL_DOWN2: case TV_SCROLL_DOWN2 | BUTTON_REPEAT: #endif tv_scroll_down(TV_VERTICAL_SCROLL_PREFS); old_tick = *rb->current_tick; break; case TV_SCREEN_LEFT: case TV_SCREEN_LEFT | BUTTON_REPEAT: if (preferences->windows > 1) { /* Screen left */ tv_scroll_left(TV_HORIZONTAL_SCROLL_PREFS); } else { /* prefs->windows == 1 */ if (preferences->narrow_mode == NM_PAGE) { /* scroll to previous page */ tv_scroll_up(TV_VERTICAL_SCROLL_PAGE); } else { /* Top of file */ tv_top(); } } break; case TV_SCREEN_RIGHT: case TV_SCREEN_RIGHT | BUTTON_REPEAT: if (preferences->windows > 1) { /* Screen right */ tv_scroll_right(TV_HORIZONTAL_SCROLL_PREFS); } else { /* prefs->windows == 1 */ if (preferences->narrow_mode == NM_PAGE) { /* scroll to next page */ tv_scroll_down(TV_VERTICAL_SCROLL_PAGE); } else { /* Bottom of file */ tv_bottom(); } } break; #ifdef TV_LINE_UP case TV_LINE_UP: case TV_LINE_UP | BUTTON_REPEAT: /* Scroll up one line */ tv_scroll_up(TV_VERTICAL_SCROLL_LINE); old_tick = *rb->current_tick; break; case TV_LINE_DOWN: case TV_LINE_DOWN | BUTTON_REPEAT: /* Scroll down one line */ tv_scroll_down(TV_VERTICAL_SCROLL_LINE); old_tick = *rb->current_tick; break; #endif #ifdef TV_COLUMN_LEFT case TV_COLUMN_LEFT: case TV_COLUMN_LEFT | BUTTON_REPEAT: /* Scroll left one column */ tv_scroll_left(TV_HORIZONTAL_SCROLL_COLUMN); break; case TV_COLUMN_RIGHT: case TV_COLUMN_RIGHT | BUTTON_REPEAT: /* Scroll right one column */ tv_scroll_right(TV_HORIZONTAL_SCROLL_COLUMN); break; #endif #ifdef TV_RC_QUIT case TV_RC_QUIT: #endif case TV_QUIT: #ifdef TV_QUIT2 case TV_QUIT2: #endif done = true; break; case TV_BOOKMARK: tv_add_or_remove_bookmark(); break; default: exit_on_usb(button); display_update = false; break; } if (button != BUTTON_NONE) { #if defined(TV_AUTOSCROLL_PRE) lastbutton = button; #endif rb->yield(); } if (autoscroll) { if(old_tick <= *rb->current_tick - (110 - preferences->autoscroll_speed * 10)) { tv_scroll_down(TV_VERTICAL_SCROLL_PREFS); old_tick = *rb->current_tick; display_update = true; } } } return PLUGIN_OK; } 21' href='#n121'>121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
/*
** $Id$
** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h
*/
#ifndef lopcodes_h
#define lopcodes_h
#include "llimits.h"
/*===========================================================================
We assume that instructions are unsigned numbers.
All instructions have an opcode in the first 6 bits.
Instructions can have the following fields:
`A' : 8 bits
`B' : 9 bits
`C' : 9 bits
`Bx' : 18 bits (`B' and `C' together)
`sBx' : signed Bx
A signed argument is represented in excess K; that is, the number
value is the unsigned value minus K. K is exactly the maximum value
for that argument (so that -max is represented by 0, and +max is
represented by 2*max), which is half the maximum for the corresponding
unsigned argument.
===========================================================================*/
enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */
/*
** size and position of opcode arguments.
*/
#define SIZE_C 9
#define SIZE_B 9
#define SIZE_Bx (SIZE_C + SIZE_B)
#define SIZE_A 8
#define SIZE_OP 6
#define POS_OP 0
#define POS_A (POS_OP + SIZE_OP)
#define POS_C (POS_A + SIZE_A)
#define POS_B (POS_C + SIZE_C)
#define POS_Bx POS_C
/*
** limits for opcode arguments.
** we use (signed) int to manipulate most arguments,
** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
*/
#if SIZE_Bx < LUAI_BITSINT-1
#define MAXARG_Bx ((1<<SIZE_Bx)-1)
#define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */
#else
#define MAXARG_Bx MAX_INT
#define MAXARG_sBx MAX_INT
#endif