Changeset 3601
- Timestamp:
- Aug 2, 2009, 1:09:05 PM (14 years ago)
- Location:
- libcaca/trunk/caca
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca/caca_conio.c
r3596 r3601 32 32 static caca_display_t *dp; 33 33 34 static caca_timer_t refresh_timer = {0, 0}; 35 static uint64_t refresh_ticks; 36 34 37 static int unget_ch = -1; 35 38 static int kbhit_ch = -1; … … 41 44 static void conio_fini(void); 42 45 46 int caca_conio_directvideo; 47 int caca_conio__wscroll; 48 43 49 /** \brief DOS conio.h cgets() equivalent */ 44 50 char * caca_conio_cgets(char *str) … … 57 63 conio_init(); 58 64 59 /* TODO: implement this function */ 65 /* FIXME: must work within the currently active text window */ 66 caca_fill_box(cv, caca_wherex(cv), caca_wherey(cv), 67 caca_get_width(cv), caca_wherey(cv), ' '); 68 69 conio_refresh(); 60 70 } 61 71 … … 110 120 } 111 121 112 /** \brief DOS conio.h delay() equivalent */ 113 void caca_conio_delay(int i) 114 { 115 conio_init(); 116 117 _caca_sleep(i * 1000); 122 /** \brief DOS dos.h delay() equivalent */ 123 void caca_conio_delay(unsigned int milliseconds) 124 { 125 int64_t usec = (int64_t)milliseconds * 1000; 126 caca_timer_t timer = {0, 0}; 127 128 conio_init(); 129 130 _caca_getticks(&timer); 131 132 /* Refresh screen as long as we have enough time */ 133 while(usec > 5000) 134 { 135 conio_refresh(); 136 _caca_sleep(5000); 137 usec -= _caca_getticks(&timer); 138 } 139 140 if(usec > 0) 141 _caca_sleep(usec); 142 143 conio_refresh(); 118 144 } 119 145 … … 130 156 { 131 157 caca_event_t ev; 158 int ret; 132 159 133 160 conio_init(); … … 147 174 } 148 175 149 caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, -1); 150 return caca_get_event_key_ch(&ev); 176 while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 1000) == 0) 177 conio_refresh(); 178 179 ret = caca_get_event_key_ch(&ev); 180 181 conio_refresh(); 182 183 return ret; 151 184 } 152 185 … … 220 253 int caca_conio_kbhit(void) 221 254 { 255 static caca_timer_t timer = {0, 0}; 256 static int last_failed = 0; 222 257 caca_event_t ev; 223 258 224 259 conio_init(); 260 261 /* If last call failed and this call is made less than 100µs 262 * afterwards, we assume the caller is in a busy loop and we 263 * delay it slightly to avoid resource leakage. */ 264 if(last_failed && _caca_getticks(&timer) < 100) 265 { 266 _caca_sleep(1000); 267 conio_refresh(); 268 } 269 270 last_failed = 0; 225 271 226 272 if(kbhit_ch >= 0) … … 232 278 return 1; 233 279 } 280 281 last_failed = 1; 234 282 235 283 return 0; … … 263 311 } 264 312 265 /** \brief DOS conio.h nosound() equivalent */313 /** \brief DOS dos.h nosound() equivalent */ 266 314 void caca_conio_nosound(void) 267 315 { … … 318 366 } 319 367 320 /** \brief DOS conio.h sound() equivalent */ 321 void caca_conio_sound(int i) 368 /** \brief DOS dos.h sleep() equivalent */ 369 void caca_conio_sleep(unsigned int seconds) 370 { 371 int64_t usec = (int64_t)seconds * 1000000; 372 caca_timer_t timer = {0, 0}; 373 374 conio_init(); 375 376 _caca_getticks(&timer); 377 378 /* Refresh screen as long as we have enough time */ 379 while(usec > 5000) 380 { 381 conio_refresh(); 382 _caca_sleep(5000); 383 usec -= _caca_getticks(&timer); 384 } 385 386 if(usec > 0) 387 _caca_sleep(usec); 388 389 conio_refresh(); 390 } 391 392 /** \brief DOS dos.h sound() equivalent */ 393 void caca_conio_sound(unsigned int frequency) 322 394 { 323 395 conio_init(); … … 406 478 { 407 479 dp = caca_create_display(cv); 480 caca_refresh_display(dp); 408 481 caca_set_cursor(dp, 1); 482 _caca_getticks(&refresh_timer); 483 refresh_ticks = 0; 409 484 #if defined HAVE_ATEXIT 410 485 atexit(conio_fini); … … 415 490 static void conio_refresh(void) 416 491 { 417 caca_refresh_display(dp); 492 refresh_ticks += _caca_getticks(&refresh_timer); 493 if(refresh_ticks > 10000) 494 { 495 refresh_ticks -= 10000; 496 caca_refresh_display(dp); 497 } 418 498 } 419 499 -
libcaca/trunk/caca/caca_conio.h
r3592 r3601 39 39 #endif 40 40 41 /* conio.h defines and global variables */ 42 #define CACA_CONIO_BLINK 128 43 #define CACA_CONIO_BLACK 0 44 #define CACA_CONIO_BLUE 1 45 #define CACA_CONIO_GREEN 2 46 #define CACA_CONIO_CYAN 3 47 #define CACA_CONIO_RED 4 48 #define CACA_CONIO_MAGENTA 5 49 #define CACA_CONIO_BROWN 6 50 #define CACA_CONIO_LIGHTGRAY 7 51 #define CACA_CONIO_DARKGRAY 8 52 #define CACA_CONIO_LIGHTBLUE 9 53 #define CACA_CONIO_LIGHTGREEN 10 54 #define CACA_CONIO_LIGHTCYAN 11 55 #define CACA_CONIO_LIGHTRED 12 56 #define CACA_CONIO_LIGHTMAGENTA 13 57 #define CACA_CONIO_YELLOW 14 58 #define CACA_CONIO_WHITE 15 41 /* conio.h enums and global variables */ 42 enum CACA_CONIO_COLORS 43 { 44 CACA_CONIO_BLINK = 128, 45 CACA_CONIO_BLACK = 0, 46 CACA_CONIO_BLUE = 1, 47 CACA_CONIO_GREEN = 2, 48 CACA_CONIO_CYAN = 3, 49 CACA_CONIO_RED = 4, 50 CACA_CONIO_MAGENTA = 5, 51 CACA_CONIO_BROWN = 6, 52 CACA_CONIO_LIGHTGRAY = 7, 53 CACA_CONIO_DARKGRAY = 8, 54 CACA_CONIO_LIGHTBLUE = 9, 55 CACA_CONIO_LIGHTGREEN = 10, 56 CACA_CONIO_LIGHTCYAN = 11, 57 CACA_CONIO_LIGHTRED = 12, 58 CACA_CONIO_LIGHTMAGENTA = 13, 59 CACA_CONIO_YELLOW = 14, 60 CACA_CONIO_WHITE = 15, 61 }; 59 62 __extern int caca_conio_directvideo; 60 #define CACA_CONIO__NOCURSOR 0 61 #define CACA_CONIO__SOLIDCURSOR 1 62 #define CACA_CONIO__NORMALCURSOR 2 63 enum CACA_CONIO_CURSOR 64 { 65 CACA_CONIO__NOCURSOR = 0, 66 CACA_CONIO__SOLIDCURSOR = 1, 67 CACA_CONIO__NORMALCURSOR = 2, 68 }; 63 69 struct caca_conio_text_info 64 70 { … … 76 82 unsigned char cury; /* y-coordinate in current window */ 77 83 }; 78 #define CACA_CONIO_LASTMODE -1 79 #define CACA_CONIO_BW40 0 80 #define CACA_CONIO_C40 1 81 #define CACA_CONIO_BW80 2 82 #define CACA_CONIO_C80 3 83 #define CACA_CONIO_MONO 7 84 #define CACA_CONIO_C4350 64 84 enum CACA_CONIO_MODE 85 { 86 CACA_CONIO_LASTMODE = -1, 87 CACA_CONIO_BW40 = 0, 88 CACA_CONIO_C40 = 1, 89 CACA_CONIO_BW80 = 2, 90 CACA_CONIO_C80 = 3, 91 CACA_CONIO_MONO = 7, 92 CACA_CONIO_C4350 = 64, 93 }; 85 94 __extern int caca_conio__wscroll; 86 95 … … 155 164 __extern int caca_conio_cputs(const char *str); 156 165 __extern int caca_conio_cscanf(char *format, ...); 157 __extern void caca_conio_delay( int);166 __extern void caca_conio_delay(unsigned int); 158 167 __extern void caca_conio_delline(void); 159 168 __extern int caca_conio_getch(void); … … 177 186 void *destin); 178 187 __extern void caca_conio__setcursortype(int cur_t); 179 __extern void caca_conio_sound(int); 188 __extern void caca_conio_sleep(unsigned int); 189 __extern void caca_conio_sound(unsigned int); 180 190 __extern void caca_conio_textattr(int newattr); 181 191 __extern void caca_conio_textbackground(int newcolor); … … 238 248 # undef _setcursortype 239 249 # define _setcursortype caca_conio__setcursortype 250 # undef sleep 251 # define sleep caca_conio_sleep 240 252 # undef sound 241 253 # define sound caca_conio_sound
Note: See TracChangeset
for help on using the changeset viewer.