Advertisement
ZoriaRPG

Keyboard_Parsing_Test.zh for 2.54 (Alpha 21+)

Dec 25th, 2017
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.87 KB | None | 0 0
  1. import "std.zh"
  2.  
  3. const int SFX_KEYPRESS = 58;           
  4.  
  5. const int LINKTILEOFFSET = -261; const int KEY_DELAY = 7; //Trying this as 6.5 and timer changes as 1.0, using 65 and 10
  6. const int LINE_LENGTH = 54; const int BUFFER_LENGTH = 55;
  7. //int b1[55]; int b2[55]; int b3[55]; int b4[55]; int b5[55];
  8. //int b6[55]; int b7[55]; int b8[55]; int b9[55]; int b10[55];
  9. //int bufptr;
  10.  
  11. const int CHAR_WIDTH = 4;
  12. const int CURSOR_WIDTH = 4;
  13. const int CURSOR_POINT_CHAR = 62;
  14. const int CURSOR_Y_OFFSET = 4;
  15. const int CURSOR_X_OFFSET = 4;
  16. const int BUFFER_OUTPUT_X = 0;
  17. const int BUFFER_OUTPUT_Y = 0;
  18. const int CURSOR_BLINK_DUR = 70;
  19. const int CURSOR_Y_OFS = 1;
  20. const int TAB_WIDTH = 4; //number of spaces in a tab keypress.
  21.         //! The actual 'CHAR_TAB' shors as '^' in some fonts, hence doing it this way.
  22.  
  23. int ram[64]; const int RAM_q = 0; const int RAM_lastchar = 1; const int RAM_cursorspacing = 2; const int RAM_cursorposition = 3;
  24.  
  25.  
  26. int buffer[214747]; //={CURSOR_POINT_CHAR, CHAR_SPACE};
  27. int bufferoverlay[214747]; //handles the cursor.
  28. bool ShiftKey;
  29. //int curbuffer = 0;
  30. int q; int timer = KEY_DELAY; bool cantype = true;
  31.  
  32. int temp_q; int cursorblink = 0;
  33.  
  34.  
  35. //CursorAdv(RAM_q);
  36. void CursorAdv(int n){
  37.     if ( ram[RAM_cursorposition] == SizeOfArray(ram) ) return;
  38.     bufferoverlay[ram[n]] = CHAR_SPACE;
  39.     ram[n]++;
  40.     //bufferoverlay[ram[n]] = '_'; //Cursor.
  41.     ram[RAM_cursorposition] += ram[RAM_cursorspacing];
  42. }
  43.  
  44. //CursorRev(RAM_q);
  45. void CursorRev(int n){
  46.     if ( ram[RAM_cursorposition] == 0 ) return;
  47.     bufferoverlay[ram[n]] = 0;
  48.     ram[n]--;
  49.     if ( ram[RAM_cursorposition] >= ram[RAM_cursorspacing] ) ram[RAM_cursorposition] -= ram[RAM_cursorspacing];
  50.     if ( ram[RAM_cursorposition] < 0 ) ram[RAM_cursorposition] = 0;
  51.     //bufferoverlay[ram[n]] = '_'; //Cursor.
  52. }
  53.  
  54. void ResetCursor(){
  55.     //bufferoverlay[ram[]] = 0;
  56.     ram[RAM_q] = 0;
  57.     ram[RAM_cursorposition] = 0;
  58.     ram[RAM_cursorspacing] = 0;
  59. }
  60.  
  61. global script a{
  62.     void run(){
  63. //int buffers[]={b1, b2, b3, b4, b5, b6, b7, b8, b9, b10};
  64.     //bufptr = buffers;
  65.     //int curbuffer = bufptr[ram[RAM_q]];
  66.         Link->Y = 90;
  67.         //Game->Cheat = 4;
  68.         while(true){
  69.             if ( PressControl() && Input->Key[KEY_I] ) Game->TypingMode = true;
  70.            
  71.             if ( timer ) cantype = false;
  72.             if ( !timer ) cantype = true;
  73.             if ( Input->Key[115] || Input->Key[116] ) ShiftKey = true;
  74.             else ShiftKey = false;
  75.             if ( timer > 0 ) timer --;
  76.             if ( timer <= 0 ) timer = 0;
  77.             if ( cursorblink > 0 ) cursorblink--;
  78.             if ( cursorblink <= 0 ) cursorblink = 100;
  79.             if ( cantype && Game->TypingMode ) {
  80.                 if ( !PressControl() )
  81.                 {
  82.                     //NoAction(); //Link->PressMap = false; Link->InputMap = false;
  83.                     for ( int qq = 1; qq <= 26; qq++ ) {
  84.                         if ( Input->Key[qq] ){
  85.                             NoAction();
  86.                             if ( ram[RAM_q] < 214746 ) {
  87.                                 if ( (Input->Key[115] || Input->Key[116]))
  88.                                 {
  89.                                     buffer[ram[RAM_q]] = CHAR_A-1+qq; CursorAdv(RAM_q); temp_q++;
  90.                                     if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  91.                                     timer = KEY_DELAY;
  92.                                     break;
  93.                                 }
  94.                                 else {
  95.                                     buffer[ram[RAM_q]] = CHAR_a-1+qq; CursorAdv(RAM_q); temp_q++;
  96.                                     if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  97.                                     timer = KEY_DELAY;
  98.                                     break;
  99.                                 }
  100.                             }
  101.                            
  102.                         }
  103.                     }
  104.                     if ( Input->Key[27] ){
  105.                         if ( ram[RAM_q] < 214746 ) {
  106.                             if ( (Input->Key[115] || Input->Key[116]))
  107.                             {   buffer[ram[RAM_q]] = ')'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  108.                             else { buffer[ram[RAM_q]] = '0'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  109.                             timer = KEY_DELAY;
  110.                         }
  111.                     }
  112.                     if ( Input->Key[28] ){
  113.                         if ( ram[RAM_q] < 214746 ) {
  114.                             if ( (Input->Key[115] || Input->Key[116]))
  115.                             {   buffer[ram[RAM_q]] = '!'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  116.                             else { buffer[ram[RAM_q]] = '1'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  117.                             timer = KEY_DELAY;
  118.                         }
  119.                     }
  120.                     if ( Input->Key[29] ){
  121.                         if ( ram[RAM_q] < 214746 ) {
  122.                             if ( (Input->Key[115] || Input->Key[116]))
  123.                             {   buffer[ram[RAM_q]] = '"'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  124.                             else { buffer[ram[RAM_q]] = '2'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  125.                             timer = KEY_DELAY;
  126.                         }
  127.                     }
  128.                     if ( Input->Key[30] ){
  129.                         if ( ram[RAM_q] < 214746 ) {
  130.                             if ( (Input->Key[115] || Input->Key[116]))
  131.                             {   buffer[ram[RAM_q]] = '#'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  132.                             else { buffer[ram[RAM_q]] = '3'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  133.                             timer = KEY_DELAY;
  134.                         }
  135.                     }
  136.                     if ( Input->Key[31] ){
  137.                         if ( ram[RAM_q] < 214746 ) {
  138.                             if ( (Input->Key[115] || Input->Key[116]))
  139.                             {   buffer[ram[RAM_q]] = '$'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  140.                             else { buffer[ram[RAM_q]] = '4'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  141.                             timer = KEY_DELAY;
  142.                         }
  143.                     }
  144.                     if ( Input->Key[32] ){
  145.                         if ( ram[RAM_q] < 214746 ) {
  146.                             if ( (Input->Key[115] || Input->Key[116]))
  147.                             {   buffer[ram[RAM_q]] = '%'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  148.                             else { buffer[ram[RAM_q]] = '5'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  149.                             timer = KEY_DELAY;
  150.                         }
  151.                     }
  152.                     if ( Input->Key[33] ){
  153.                         if ( ram[RAM_q] < 214746 ) {
  154.                             if ( (Input->Key[115] || Input->Key[116]))
  155.                             {   buffer[ram[RAM_q]] = '^'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  156.                             else { buffer[ram[RAM_q]] = '6'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  157.                             timer = KEY_DELAY;
  158.                         }
  159.                     }
  160.                     if ( Input->Key[34] ){
  161.                         if ( ram[RAM_q] < 214746 ) {
  162.                             if ( (Input->Key[115] || Input->Key[116]))
  163.                             {   buffer[ram[RAM_q]] = '&'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  164.                             else { buffer[ram[RAM_q]] = '7'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  165.                             timer = KEY_DELAY;
  166.                         }
  167.                     }
  168.                     if ( Input->Key[35] ){
  169.                         if ( ram[RAM_q] < 214746 ) {
  170.                             if ( (Input->Key[115] || Input->Key[116]))
  171.                             {   buffer[ram[RAM_q]] = '*'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  172.                             else { buffer[ram[RAM_q]] = '8'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  173.                             timer = KEY_DELAY;
  174.                         }
  175.                     }
  176.                     if ( Input->Key[36] ){
  177.                         if ( ram[RAM_q] < 214746 ) {
  178.                             if ( (Input->Key[115] || Input->Key[116]))
  179.                             {   buffer[ram[RAM_q]] = '('; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  180.                             else { buffer[ram[RAM_q]] = '9'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  181.                             timer = KEY_DELAY;
  182.                         }
  183.                     }
  184.                     if ( Input->Key[37] ){ //tilde -- this might have issues unless we can set uncap false.
  185.                         if ( ram[RAM_q] < 214746 ) {
  186.                             buffer[ram[RAM_q]] = '0'; CursorAdv(RAM_q); temp_q++;
  187.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  188.                             timer = KEY_DELAY;
  189.                         }
  190.                     }
  191.                     if ( Input->Key[38] ){ //tilde -- this might have issues unless we can set uncap false.
  192.                         if ( ram[RAM_q] < 214746 ) {
  193.                             buffer[ram[RAM_q]] = '1'; CursorAdv(RAM_q); temp_q++;
  194.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  195.                             timer = KEY_DELAY;
  196.                         }
  197.                     }
  198.                     if ( Input->Key[39] ){ //tilde -- this might have issues unless we can set uncap false.
  199.                         if ( ram[RAM_q] < 214746 ) {
  200.                             buffer[ram[RAM_q]] = '2'; CursorAdv(RAM_q); temp_q++;
  201.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  202.                             timer = KEY_DELAY;
  203.                         }
  204.                     }
  205.                     if ( Input->Key[40] ){ //tilde -- this might have issues unless we can set uncap false.
  206.                         if ( ram[RAM_q] < 214746 ) {
  207.                             buffer[ram[RAM_q]] = '3'; CursorAdv(RAM_q); temp_q++;
  208.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  209.                             timer = KEY_DELAY;
  210.                         }
  211.                     }
  212.                     if ( Input->Key[41] ){ //tilde -- this might have issues unless we can set uncap false.
  213.                         if ( ram[RAM_q] < 214746 ) {
  214.                             buffer[ram[RAM_q]] = '4'; CursorAdv(RAM_q); temp_q++;
  215.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  216.                             timer = KEY_DELAY;
  217.                         }
  218.                     }
  219.                     if ( Input->Key[42] ){ //tilde -- this might have issues unless we can set uncap false.
  220.                         if ( ram[RAM_q] < 214746 ) {
  221.                             buffer[ram[RAM_q]] = '5'; CursorAdv(RAM_q); temp_q++;
  222.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  223.                             timer = KEY_DELAY;
  224.                         }
  225.                     }
  226.                     if ( Input->Key[43] ){ //tilde -- this might have issues unless we can set uncap false.
  227.                         if ( ram[RAM_q] < 214746 ) {
  228.                             buffer[ram[RAM_q]] = '6'; CursorAdv(RAM_q); temp_q++;
  229.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  230.                             timer = KEY_DELAY;
  231.                         }
  232.                     }
  233.                     if ( Input->Key[44] ){ //tilde -- this might have issues unless we can set uncap false.
  234.                         if ( ram[RAM_q] < 214746 ) {
  235.                             buffer[ram[RAM_q]] = '7'; CursorAdv(RAM_q); temp_q++;
  236.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  237.                             timer = KEY_DELAY;
  238.                         }
  239.                     }
  240.                     if ( Input->Key[45] ){ //tilde -- this might have issues unless we can set uncap false.
  241.                         if ( ram[RAM_q] < 214746 ) {
  242.                             buffer[ram[RAM_q]] = '8'; CursorAdv(RAM_q); temp_q++;
  243.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  244.                             timer = KEY_DELAY;
  245.                         }
  246.                     }              
  247.                     if ( Input->Key[46] ){ //tilde -- this might have issues unless we can set uncap false.
  248.                         if ( ram[RAM_q] < 214746 ) {
  249.                             buffer[ram[RAM_q]] = '9'; CursorAdv(RAM_q); temp_q++;
  250.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  251.                             timer = KEY_DELAY;
  252.                         }
  253.                     }
  254.                     if ( Input->Key[60] ){ //tilde -- this might have issues unless we can set uncap false.
  255.                         if ( ram[RAM_q] < 214746 ) {
  256.                             buffer[ram[RAM_q]] = '~'; CursorAdv(RAM_q); temp_q++;
  257.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  258.                             timer = KEY_DELAY;
  259.                         }
  260.                     }
  261.                     if ( Input->Key[61] ){
  262.                         if ( ram[RAM_q] < 214746 ) {
  263.                             if ( (Input->Key[115] || Input->Key[116]))
  264.                             {   buffer[ram[RAM_q]] = '_'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  265.                             else { buffer[ram[RAM_q]] = '-'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  266.                             timer = KEY_DELAY;
  267.                         }
  268.                     }
  269.                     if ( Input->Key[62] ){
  270.                         if ( ram[RAM_q] < 214746 ) {
  271.                             if ( (Input->Key[115] || Input->Key[116]))
  272.                             {   buffer[ram[RAM_q]] = '+'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  273.                             else { buffer[ram[RAM_q]] = '='; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  274.                             timer = KEY_DELAY;
  275.                         }
  276.                     }
  277.                     if ( Input->Key[63] ){ //backspace key
  278.                         //Do not permit backspace is we reach the first character of the buffer!
  279.                         if ( ram[RAM_q] < 214746 && ram[RAM_q] > 0 ) {
  280.                             CursorRev(RAM_q); temp_q--; buffer[ram[RAM_q]] = 0; //clear the last character typed.
  281.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  282.                             timer = KEY_DELAY;
  283.                         }
  284.                     }  
  285.  
  286.                     if ( Input->Key[64] ){ //tab
  287.                         if ( ram[RAM_q] < 214746 ) {
  288.                             for ( int w = 0; w < TAB_WIDTH; w++ ) { buffer[ram[RAM_q]] = CHAR_SPACE; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  289.                             timer = KEY_DELAY;
  290.                         }
  291.                     }
  292.                     if ( Input->Key[65] ){
  293.                         if ( ram[RAM_q] < 214746 ) {
  294.                             if ( (Input->Key[115] || Input->Key[116]))
  295.                             {   buffer[ram[RAM_q]] = '{'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  296.                             else { buffer[ram[RAM_q]] = '['; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  297.                             timer = KEY_DELAY;
  298.                         }
  299.                     }
  300.                     if ( Input->Key[66] ){
  301.                         if ( ram[RAM_q] < 214746 ) {
  302.                             if ( (Input->Key[115] || Input->Key[116]))
  303.                             {   buffer[ram[RAM_q]] = '}'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  304.                             else { buffer[ram[RAM_q]] = ']'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  305.                             timer = KEY_DELAY;
  306.                         }
  307.                     }
  308.                     if ( Input->Key[68] ){
  309.                         if ( ram[RAM_q] < 214746 ) {
  310.                             if ( (Input->Key[115] || Input->Key[116]))
  311.                             {   buffer[ram[RAM_q]] = ':'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  312.                             else { buffer[ram[RAM_q]] = ';'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  313.                             timer = KEY_DELAY;
  314.                         }
  315.                     }
  316.                     if ( Input->Key[69] ){
  317.                         if ( ram[RAM_q] < 214746 ) {
  318.                             if ( (Input->Key[115] || Input->Key[116]))
  319.                             {   buffer[ram[RAM_q]] = CHAR_DQUOTE; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  320.                             else { buffer[ram[RAM_q]] = CHAR_QUOTE; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  321.                             timer = KEY_DELAY;
  322.                         }
  323.                     }
  324.                     if ( Input->Key[70] ){
  325.                         if ( ram[RAM_q] < 214746 ) {
  326.                             if ( (Input->Key[115] || Input->Key[116]))
  327.                             {   buffer[ram[RAM_q]] = '|'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  328.                             else { buffer[ram[RAM_q]] = CHAR_BSLASH; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  329.                             timer = KEY_DELAY;
  330.                         }
  331.                     }
  332.                     if ( Input->Key[71] ){
  333.                         if ( ram[RAM_q] < 214746 ) {
  334.                             if ( (Input->Key[115] || Input->Key[116]))
  335.                             {   buffer[ram[RAM_q]] = '|'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  336.                             else { buffer[ram[RAM_q]] = CHAR_BSLASH; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  337.                             timer = KEY_DELAY;
  338.                         }
  339.                     }
  340.                     if ( Input->Key[72] ){
  341.                         if ( ram[RAM_q] < 214746 ) {
  342.                             if ( (Input->Key[115] || Input->Key[116]))
  343.                             {   buffer[ram[RAM_q]] = '<'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  344.                             else { buffer[ram[RAM_q]] = ','; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  345.                             timer = KEY_DELAY;
  346.                         }
  347.                     }
  348.                     if ( Input->Key[73] ){
  349.                         if ( ram[RAM_q] < 214746 ) {
  350.                             if ( (Input->Key[115] || Input->Key[116]))
  351.                             {   buffer[ram[RAM_q]] = '>'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  352.                             else { buffer[ram[RAM_q]] = '.'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  353.                             timer = KEY_DELAY;
  354.                         }
  355.                     }
  356.                     if ( Input->Key[74] ){
  357.                         if ( ram[RAM_q] < 214746 ) {
  358.                             if ( (Input->Key[115] || Input->Key[116]))
  359.                             {   buffer[ram[RAM_q]] = '?'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  360.                             else { buffer[ram[RAM_q]] = '/'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  361.                             timer = KEY_DELAY;
  362.                         }
  363.                     }
  364.                    
  365.                     if ( Input->Key[75] ){
  366.                         if ( ram[RAM_q] < 214746 ) {
  367.                             buffer[ram[RAM_q]] = CHAR_SPACE; CursorAdv(RAM_q); temp_q++;
  368.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  369.                             timer = KEY_DELAY;
  370.                         }
  371.                     }
  372.                     if ( Input->Key[77] ){ //delete
  373.                         if ( ram[RAM_q] < 214746 ) {
  374.                             for ( int w = ram[RAM_q]; w >= 0; w-- ) buffer[w] = 0;
  375.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  376.                             ResetCursor(); temp_q = 0;
  377.                             timer = KEY_DELAY;
  378.                         }
  379.                     }
  380.                     if ( Input->Key[78] ){
  381.                         if ( ram[RAM_q] < 214746 ) {
  382.                             if ( (Input->Key[115] || Input->Key[116]))
  383.                             {   buffer[ram[RAM_q]] = '~'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  384.                             else { buffer[ram[RAM_q]] = '`'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  385.                             timer = KEY_DELAY;
  386.                         }
  387.                     }
  388.                     if ( Input->Key[82] ){ //leftarrow
  389.                         if ( ram[RAM_q] < 214746 ) {
  390.                             //ram[RAM_q]--;
  391.                             CursorRev(RAM_q);
  392.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);//temp_q--;
  393.                             timer = KEY_DELAY;
  394.                         }
  395.                     }
  396.                     if ( Input->Key[83] ){ //leftarrow
  397.                         if ( ram[RAM_q] < 214746 ) {
  398.                             CursorAdv(RAM_q);
  399.                             //ram[RAM_q]++;
  400.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);//temp_q--; //needs to operate on temp_q so that the highest position is recorded.
  401.                             timer = KEY_DELAY;
  402.                         }
  403.                     }
  404.                     if ( Input->Key[84] ){ //up
  405.                         //find the previous command in the list
  406.                         /* if ( ram[RAM_q] < 214746 ) {
  407.                             if ( (Input->Key[115] || Input->Key[116]))
  408.                             {   buffer[ram[RAM_q]] = '|'; q++; temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  409.                             else { buffer[ram[RAM_q]] = CHAR_BSLASH; q++; temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  410.                             timer = KEY_DELAY;
  411.                         }
  412.                         */
  413.                     }
  414.                     if ( Input->Key[85] ){ //up
  415.                         //find the next command in the list, clear if none
  416.                         /* if ( ram[RAM_q] < 214746 ) {
  417.                             if ( (Input->Key[115] || Input->Key[116]))
  418.                             {   buffer[ram[RAM_q]] = '|'; q++; temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  419.                             else { buffer[ram[RAM_q]] = CHAR_BSLASH; q++; temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  420.                             timer = KEY_DELAY;
  421.                         }
  422.                         */
  423.                     }
  424.                     if ( Input->Key[86] ){
  425.                         if ( ram[RAM_q] < 214746 ) {
  426.                             buffer[ram[RAM_q]] = '/'; CursorAdv(RAM_q); temp_q++;
  427.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  428.                             timer = KEY_DELAY;
  429.                         }
  430.                     }
  431.                     if ( Input->Key[87] ){
  432.                         if ( ram[RAM_q] < 214746 ) {
  433.                             buffer[ram[RAM_q]] = '*'; CursorAdv(RAM_q); temp_q++;
  434.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  435.                             timer = KEY_DELAY;
  436.                         }
  437.                     }          
  438.                     if ( Input->Key[88] ){
  439.                         if ( ram[RAM_q] < 214746 ) {
  440.                             buffer[ram[RAM_q]] = '-'; CursorAdv(RAM_q); temp_q++;
  441.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  442.                             timer = KEY_DELAY;
  443.                         }
  444.                     }  
  445.                     if ( Input->Key[89] ){
  446.                         if ( ram[RAM_q] < 214746 ) {
  447.                             buffer[ram[RAM_q]] = '+'; CursorAdv(RAM_q); temp_q++;
  448.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  449.                             timer = KEY_DELAY;
  450.                         }
  451.                     }  
  452.                     if ( Input->Key[90] ){ //delete key, num pad
  453.                         if ( ram[RAM_q] < 214746 ) {
  454.                             buffer[ram[RAM_q]] = '/'; CursorAdv(RAM_q); temp_q++;
  455.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  456.                             timer = KEY_DELAY;
  457.                         }
  458.                     }  
  459.                     if ( Input->Key[91] ){
  460.                         if ( ram[RAM_q] < 214746 ) {
  461.                             for ( int w = q; w >= 0; w-- ) buffer[w] = 0;
  462.                             if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  463.                             q = 0; temp_q = 0;
  464.                             timer = KEY_DELAY;
  465.                         }
  466.                     }  
  467.                     if ( Input->Key[101] ){
  468.                         if ( ram[RAM_q] < 214746 ) {
  469.                             if ( (Input->Key[115] || Input->Key[116]))
  470.                             {   buffer[ram[RAM_q]] = ':'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  471.                             else { buffer[ram[RAM_q]] = ';'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  472.                             timer = KEY_DELAY;
  473.                         }
  474.                     }
  475.                    
  476.                     if ( Input->Key[105] ){
  477.                         if ( ram[RAM_q] < 214746 ) {
  478.                             if ( (Input->Key[115] || Input->Key[116]))
  479.                             {   buffer[ram[RAM_q]] = ':'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  480.                             else { buffer[ram[RAM_q]] = ';'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  481.                             timer = KEY_DELAY;
  482.                         }
  483.                     }
  484.                     //for ( int qqq = 0; qqram[RAM_q] < SizeOfArray(bufferoverlay); qqq++ ) bufferoverlay[ram[RAM_q]] = CHAR_SPACE;
  485.                     //bufferoverlay[ram[RAM_q]] = '_'; //Cursor.
  486.                 }
  487.             }
  488.            
  489.             //Adjust the cursor position based on the size of the last typed character.
  490.             if ( ram[RAM_q] > 0 ) {
  491.                 ram[RAM_lastchar] = buffer[ram[RAM_q]-1];
  492.                 ram[RAM_cursorspacing] = GetCursorSpacing(ram[RAM_lastchar]);
  493.             }
  494.             //If we backspace all the way, rfeser the cursor position to 0 in all respects.
  495.             if ( ram[RAM_q] == 0 ) {
  496.                 ram[RAM_lastchar] = 0;
  497.                 ram[RAM_cursorspacing] = 0;
  498.                
  499.             }
  500.            
  501.             if ( timer == KEY_DELAY ) {
  502.                 Trace(ram[RAM_lastchar]);
  503.                 Trace(GetCursorSpacing(ram[RAM_lastchar]));
  504.                 Trace(ram[RAM_cursorspacing]);
  505.                 Trace(ram[RAM_cursorposition]);
  506.             }
  507.                
  508.             if ( Game->TypingMode )
  509.             {
  510.                 Screen->DrawString(6,0,0,2, 0x01, -1, 0, GetBuffer(),128);
  511.    
  512.                 if ( cursorblink > CURSOR_BLINK_DUR ) {
  513.                     int cursor[] = "_";
  514.                     Screen->DrawString(6,ram[RAM_cursorposition]+ram[RAM_cursorspacing],0+CURSOR_Y_OFS,2, 0x01, -1, 0, cursor,128); //cursor
  515.                     //Screen->DrawString(6,0,0+CURSOR_Y_OFS,2, 0x01, -1, 0, GetCursorOverlay(),128); //cursor
  516.                     /*
  517.                     Screen->Line(6,
  518.                         0+0+(q*CHAR_WIDTH),
  519.                         //BUFFER_OUTPUT_X+CURSOR_X_OFFSET+(q*CHAR_WIDTH),
  520.                         //BUFFER_OUTPUT_Y+CURSOR_Y_OFFSET,
  521.                         6,
  522.                         0+0+(q*CHAR_WIDTH)+4,
  523.                         //BUFFER_OUTPUT_X+CURSOR_X_OFFSET+(q*CHAR_WIDTH) + CURSOR_WIDTH,
  524.                         6,
  525.                         //BUFFER_OUTPUT_Y+CURSOR_Y_OFFSET,
  526.                         0x01, 1, 0, 0, 0, 128);
  527.                     */
  528.                 }  
  529.                 if ( PressControl() && Input->Key[KEY_C] ) { Game->TypingMode = false; }
  530.                 //if ( Input->Key[KEY_F6] )
  531.                 //{
  532.                 //  Input->Key[KEY_F6] = false; //works.
  533.                 //  TraceS("Pressed F6");
  534.                 //}
  535.             }
  536.             else
  537.             {
  538.                 Screen->DrawString(6,0,0,2, 0x01, -1, 0, "Press Ctl+I to insert text, Ctl+C to break",128);
  539.             }
  540.             if ( Input->Key[KEY_F6] ) TraceS("Pressed F6");
  541.             Waitdraw(); Waitframe();
  542.         }
  543.     }
  544. }  
  545.  
  546. int GetCursorSpacing(int chr, int font){
  547.     if ( font == 0 ) {
  548.         int spacing[]={
  549.             0, 0, 0, 0, 0, 0, 0, 0, 0, 16, //tab
  550.             0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  551.             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //(29)
  552.             0, 0, // (31)
  553.             4, 2, 4, 6, 6, 4, 5, 2, 3, 3,
  554.             4, 4, 3, 4, 2, 0, 4, 3, 4, 4, //literal 3
  555.             4, 4, 4, 4, 4, 4, 2, 2, 4, 4, //equals
  556.             4, 4, 5, //@ sign
  557.             //A
  558.             5, 5, 4, 5, 4, 4, 5, 4, 2, 4,
  559.             //K
  560.             5, 4, 6, 6, 5, 5, 5, 5, 5, 4,
  561.             //U
  562.             5, 6, 6, 6, 4, 4, //Z
  563.             //lbrace
  564.             4, 5, 4, 4, 4, 4,
  565.             //a
  566.             5, 5, 4, 5, 4, 4, 5, 4, 2, 4,
  567.             //k
  568.             5, 4, 6, 6, 5, 5, 5, 5, 5, 4,
  569.             //u
  570.             5, 6, 6, 4, 4, 4, //z
  571.             //{
  572.             4, 2, 4, 5,
  573.             //127
  574.             0,
  575.             //Forward Del
  576.             0
  577.         };
  578.         return spacing[chr];
  579.     }
  580. }
  581.  
  582. int GetCursorSpacing(int chr){
  583.     //Custom kerning... Organised by English-language, and C-Programming linguistic frequency for short-circuiting,
  584.      
  585.     if ( chr == ' ' ) return 4;
  586.    
  587.     if ( chr == 'E' ) return 4; if ( chr == 'T' ) return 4; if ( chr == 'A' ) return 5; if ( chr == 'O' ) return 5; if ( chr == 'I' ) return 2;
  588.     if ( chr == 'N' ) return 6; if ( chr == 'S' ) return 5; if ( chr == 'H' ) return 4; if ( chr == 'R' ) return 5; if ( chr == 'D' ) return 5;
  589.     if ( chr == 'L' ) return 4; if ( chr == 'C' ) return 4; if ( chr == 'U' ) return 5; if ( chr == 'M' ) return 6; if ( chr == 'W' ) return 6;
  590.     if ( chr == 'F' ) return 4; if ( chr == 'G' ) return 5; if ( chr == 'Y' ) return 4; if ( chr == 'P' ) return 5; if ( chr == 'B' ) return 5;  
  591.     if ( chr == 'V' ) return 6; if ( chr == 'K' ) return 5; if ( chr == 'J' ) return 4; if ( chr == 'X' ) return 6; if ( chr == 'Q' ) return 5;
  592.     if ( chr == 'Z' ) return 4;
  593.    
  594.     if ( chr == 'e' ) return 4; if ( chr == 't' ) return 4; if ( chr == 'a' ) return 5; if ( chr == 'o' ) return 5; if ( chr == 'i' ) return 2;
  595.     if ( chr == 'n' ) return 6; if ( chr == 's' ) return 5; if ( chr == 'h' ) return 4; if ( chr == 'r' ) return 5; if ( chr == 'd' ) return 5;
  596.     if ( chr == 'l' ) return 4; if ( chr == 'c' ) return 4; if ( chr == 'u' ) return 5; if ( chr == 'm' ) return 6; if ( chr == 'w' ) return 6;
  597.     if ( chr == 'f' ) return 4; if ( chr == 'g' ) return 5; if ( chr == 'y' ) return 4; if ( chr == 'p' ) return 5; if ( chr == 'b' ) return 5;
  598.     if ( chr == 'v' ) return 6; if ( chr == 'k' ) return 5; if ( chr == 'j' ) return 4; if ( chr == 'x' ) return 4; if ( chr == 'q' ) return 5;
  599.     if ( chr == 'z' ) return 4;
  600.    
  601.     if ( chr == '.' ) return 2; if ( chr == '!' ) return 2; if ( chr == ',' ) return 3; if ( chr == '?' ) return 4; if ( chr == ':' ) return 2;
  602.    
  603.     if ( chr == '1' ) return 3; if ( chr == '2' ) return 4; if ( chr == '3' ) return 4; if ( chr == '4' ) return 4; if ( chr == '5' ) return 4;
  604.     if ( chr == '6' ) return 4; if ( chr == '7' ) return 4; if ( chr == '8' ) return 4; if ( chr == '9' ) return 4; if ( chr == '0' ) return 4;
  605.    
  606.     if ( chr == ';' ) return 2; if ( chr == '(' ) return 3; if ( chr == ')' ) return 3; if ( chr == '-' ) return 4;
  607.    
  608.     if ( chr == CHAR_QUOTE ) return 2; //Zeelda to be a parser bug. Comparing the buffer character ' ' ' to 'A' returned 5.
  609.     if ( chr == CHAR_DQUOTE ) return 4;
  610.    
  611.     if ( chr == '{' ) return 4; if ( chr == '}' ) return 4; if ( chr == '&' ) return 5; if ( chr == '|' ) return 2; if ( chr == '_' ) return 4;
  612.     if ( chr == '=' ) return 4; if ( chr == '*' ) return 4; if ( chr == '+' ) return 4; if ( chr == '/' ) return 4; if ( chr == '%' ) return 4;
  613.     if ( chr == '<' ) return 4; if ( chr == '>' ) return 4; if ( chr == '[' ) return 4; if ( chr == ']' ) return 4; if ( chr == '~' ) return 5;
  614.      
  615.    
  616.     if ( chr == '@' ) return 5; if ( chr == '#' ) return 6; if ( chr == '$' ) return 6; if ( chr == CHAR_POUNDS ) return 5;  if ( chr == '^' ) return 4;
  617.      
  618.     if ( chr == CHAR_BSLASH ) return 5; if ( chr == '`' ) return 4;
  619.    
  620. }
  621.    
  622. int GetBuffer(){
  623.     //int ptr = bufptr;
  624.     //return bufptr[buffer];
  625.     return buffer;
  626.    
  627. }  
  628.  
  629. int GetCursorOverlay(){
  630.     return bufferoverlay;
  631. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement