boolsoft message board Forum Index
String Input Routine

 
Post new topic   Reply to topic    boolsoft message board Forum Index -> Software
View previous topic :: View next topic  
Author Message
bfr
Junior
Junior


Joined: 28 Dec 2007
Posts: 10

PostPosted: Mon Jun 16, 2008 6:16 pm    Post subject: String Input Routine Reply with quote

Would any of you happen to have a TIGCC/C string input routine that lets you set the X and Y coordinates of the prompt (kind of like MoveTo(x,y) and then using getsn()) and works when interrupts 1, 5, and 6 are redirected?
_________________
bfr's website - http://bfr.tifreakware.net
Back to top
View user's profile Send private message Visit poster's website
pinhead
Member
Member


Joined: 03 Jun 2006
Posts: 31
Location: Diepoldsau, Switzerland

PostPosted: Wed Jun 18, 2008 1:07 pm    Post subject: Reply with quote

No, not really, but I adapted the TIGCC Docu example to fit most of your needs. However, my code requires AUTO_INT_1, but are you sure you can't enable this interrupt for a short time? Otherwise you would have to write a getKey replacement working without AUTO_INT_1.

c:
  1.  
  2. // ----------------------------------------------------------------- //
  3. // checks for keypresses and turns the calc of if APD expired
  4. // originally taken from TICT sources
  5. // ----------------------------------------------------------------- //
  6. short getKey(void)
  7. {
  8.         void *kbq = kbd_queue();
  9.         unsigned short key;
  10.        
  11.         // restart the APD timer now
  12.         OSTimerRestart(APD_TIMER);
  13.        
  14.         // get an input
  15.         while (OSdequeue(&key, kbq))
  16.         {
  17.                 // check if it is necessary to turn the calc off
  18.                 if (OSTimerExpired(APD_TIMER))
  19.                 {
  20.                         off();
  21.                         OSTimerRestart(APD_TIMER);
  22.                 }
  23.         }
  24.        
  25.         // erase the status line
  26.         ST_eraseHelp();
  27.        
  28.         // allow key repetition
  29.         return key & 0xF7FF;
  30. }
  31.  
  32. // Custom String Input Function
  33. void InputStr(char *buffer, unsigned short maxlen, short x, short y)
  34. {
  35.         SCR_STATE ss;
  36.         short key;
  37.         unsigned short i = 0;
  38.         buffer[0] = 0;
  39.         MoveTo(x,y);
  40.         SaveScrState(&ss);
  41.         do {
  42.                 MoveTo(ss.CurX, ss.CurY);
  43.                 // Note that two spaces are required only if the F_4x6 font is used
  44.                 printf("%s_  ", buffer);
  45.                 key = getKey();
  46.                 if (key >= ' ' && key <= '~' && i < maxlen)
  47.                         buffer[i++] = key;
  48.                 else if (key == KEY_BACKSPACE && i)
  49.                         i--;
  50.                 buffer[i] = 0;
  51.         } while (key != KEY_ENTER);
  52. }
  53.  
  54. // Main Function
  55. void _main(void)
  56. {
  57.   char s[21]; // NOTE: <s> must be 21 bytes long (zero byte at the end of the string! this is a bug in the tigcc docu!
  58.   clrscr();
  59.   InputStr(s, 20, 10, 10);
  60.   printf("\n%s", s);
  61.   ngetchx();
  62. }
  63.  


// EDIT by saubue: fancy coloring

_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    boolsoft message board Forum Index -> Software All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Powered by phpBB and Ad Infinitum v1.03


Anti Bot Question MOD - phpBB MOD against Spam Bots