Advertisement
ZoriaRPG

Keyboard Input Parser v6

May 2nd, 2017
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 25.50 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.     bufferoverlay[ram[n]] = CHAR_SPACE;
  38.     ram[n]++;
  39.     //bufferoverlay[ram[n]] = '_'; //Cursor.
  40.     ram[RAM_cursorposition] += ram[RAM_cursorspacing];
  41. }
  42.  
  43. //CursorRev(RAM_q);
  44. void CursorRev(int n){
  45.     bufferoverlay[ram[n]] = 0;
  46.     ram[n]--;
  47.     if ( ram[RAM_cursorposition] >= ram[RAM_cursorspacing] ) ram[RAM_cursorposition] -= ram[RAM_cursorspacing];
  48.     if ( ram[RAM_cursorposition] < 0 ) ram[RAM_cursorposition] = 0;
  49.     //bufferoverlay[ram[n]] = '_'; //Cursor.
  50. }
  51.  
  52. void ResetCursor(){
  53.     //bufferoverlay[ram[]] = 0;
  54.     ram[RAM_q] = 0;
  55.     ram[RAM_cursorposition] = 0;
  56.     ram[RAM_cursorspacing] = 0;
  57. }
  58.  
  59. global script a{
  60.     void run(){
  61. //int buffers[]={b1, b2, b3, b4, b5, b6, b7, b8, b9, b10};
  62.     //bufptr = buffers;
  63.     //int curbuffer = bufptr[ram[RAM_q]];
  64.         Link->Y = 90;
  65.         //Game->Cheat = 4;
  66.         while(true){
  67.             //Link->PressMap = false;
  68.             Link->InputMap = false;
  69.             if ( timer ) cantype = false;
  70.             if ( !timer ) cantype = true;
  71.             if ( Game->KeyPress[115] || Game->KeyPress[116] ) ShiftKey = true;
  72.             else ShiftKey = false;
  73.             if ( timer > 0 ) timer --;
  74.             if ( timer <= 0 ) timer = 0;
  75.             if ( cursorblink > 0 ) cursorblink--;
  76.             if ( cursorblink <= 0 ) cursorblink = 100;
  77.             if ( cantype ) {
  78.                 //NoAction(); //Link->PressMap = false; Link->InputMap = false;
  79.                 for ( int qq = 1; qq <= 26; qq++ ) {
  80.                     if ( Game->KeyPress[qq] ){
  81.                         NoAction();
  82.                         if ( ram[RAM_q] < 214746 ) {
  83.                             if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  84.                             {
  85.                                 buffer[ram[RAM_q]] = CHAR_A-1+qq; CursorAdv(RAM_q); temp_q++;
  86.                                 if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  87.                                 timer = KEY_DELAY;
  88.                                 break;
  89.                             }
  90.                             else {
  91.                                 buffer[ram[RAM_q]] = CHAR_a-1+qq; CursorAdv(RAM_q); temp_q++;
  92.                                 if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  93.                                 timer = KEY_DELAY;
  94.                                 break;
  95.                             }
  96.                         }
  97.                        
  98.                     }
  99.                 }
  100.                 if ( Game->KeyPress[27] ){
  101.                     if ( ram[RAM_q] < 214746 ) {
  102.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  103.                         {   buffer[ram[RAM_q]] = ')'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  104.                         else { buffer[ram[RAM_q]] = '0'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  105.                         timer = KEY_DELAY;
  106.                     }
  107.                 }
  108.                 if ( Game->KeyPress[28] ){
  109.                     if ( ram[RAM_q] < 214746 ) {
  110.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  111.                         {   buffer[ram[RAM_q]] = '!'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  112.                         else { buffer[ram[RAM_q]] = '1'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  113.                         timer = KEY_DELAY;
  114.                     }
  115.                 }
  116.                 if ( Game->KeyPress[29] ){
  117.                     if ( ram[RAM_q] < 214746 ) {
  118.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  119.                         {   buffer[ram[RAM_q]] = '"'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  120.                         else { buffer[ram[RAM_q]] = '2'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  121.                         timer = KEY_DELAY;
  122.                     }
  123.                 }
  124.                 if ( Game->KeyPress[30] ){
  125.                     if ( ram[RAM_q] < 214746 ) {
  126.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  127.                         {   buffer[ram[RAM_q]] = '#'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  128.                         else { buffer[ram[RAM_q]] = '3'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  129.                         timer = KEY_DELAY;
  130.                     }
  131.                 }
  132.                 if ( Game->KeyPress[31] ){
  133.                     if ( ram[RAM_q] < 214746 ) {
  134.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  135.                         {   buffer[ram[RAM_q]] = '$'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  136.                         else { buffer[ram[RAM_q]] = '4'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  137.                         timer = KEY_DELAY;
  138.                     }
  139.                 }
  140.                 if ( Game->KeyPress[32] ){
  141.                     if ( ram[RAM_q] < 214746 ) {
  142.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  143.                         {   buffer[ram[RAM_q]] = '%'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  144.                         else { buffer[ram[RAM_q]] = '5'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  145.                         timer = KEY_DELAY;
  146.                     }
  147.                 }
  148.                 if ( Game->KeyPress[33] ){
  149.                     if ( ram[RAM_q] < 214746 ) {
  150.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  151.                         {   buffer[ram[RAM_q]] = '^'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  152.                         else { buffer[ram[RAM_q]] = '6'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  153.                         timer = KEY_DELAY;
  154.                     }
  155.                 }
  156.                 if ( Game->KeyPress[34] ){
  157.                     if ( ram[RAM_q] < 214746 ) {
  158.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  159.                         {   buffer[ram[RAM_q]] = '&'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  160.                         else { buffer[ram[RAM_q]] = '7'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  161.                         timer = KEY_DELAY;
  162.                     }
  163.                 }
  164.                 if ( Game->KeyPress[35] ){
  165.                     if ( ram[RAM_q] < 214746 ) {
  166.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  167.                         {   buffer[ram[RAM_q]] = '*'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  168.                         else { buffer[ram[RAM_q]] = '8'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  169.                         timer = KEY_DELAY;
  170.                     }
  171.                 }
  172.                 if ( Game->KeyPress[36] ){
  173.                     if ( ram[RAM_q] < 214746 ) {
  174.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  175.                         {   buffer[ram[RAM_q]] = '('; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  176.                         else { buffer[ram[RAM_q]] = '9'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  177.                         timer = KEY_DELAY;
  178.                     }
  179.                 }
  180.                 if ( Game->KeyPress[37] ){ //tilde -- this might have issues unless we can set uncap false.
  181.                     if ( ram[RAM_q] < 214746 ) {
  182.                         buffer[ram[RAM_q]] = '0'; CursorAdv(RAM_q); temp_q++;
  183.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  184.                         timer = KEY_DELAY;
  185.                     }
  186.                 }
  187.                 if ( Game->KeyPress[38] ){ //tilde -- this might have issues unless we can set uncap false.
  188.                     if ( ram[RAM_q] < 214746 ) {
  189.                         buffer[ram[RAM_q]] = '1'; CursorAdv(RAM_q); temp_q++;
  190.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  191.                         timer = KEY_DELAY;
  192.                     }
  193.                 }
  194.                 if ( Game->KeyPress[39] ){ //tilde -- this might have issues unless we can set uncap false.
  195.                     if ( ram[RAM_q] < 214746 ) {
  196.                         buffer[ram[RAM_q]] = '2'; CursorAdv(RAM_q); temp_q++;
  197.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  198.                         timer = KEY_DELAY;
  199.                     }
  200.                 }
  201.                 if ( Game->KeyPress[40] ){ //tilde -- this might have issues unless we can set uncap false.
  202.                     if ( ram[RAM_q] < 214746 ) {
  203.                         buffer[ram[RAM_q]] = '3'; CursorAdv(RAM_q); temp_q++;
  204.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  205.                         timer = KEY_DELAY;
  206.                     }
  207.                 }
  208.                 if ( Game->KeyPress[41] ){ //tilde -- this might have issues unless we can set uncap false.
  209.                     if ( ram[RAM_q] < 214746 ) {
  210.                         buffer[ram[RAM_q]] = '4'; CursorAdv(RAM_q); temp_q++;
  211.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  212.                         timer = KEY_DELAY;
  213.                     }
  214.                 }
  215.                 if ( Game->KeyPress[42] ){ //tilde -- this might have issues unless we can set uncap false.
  216.                     if ( ram[RAM_q] < 214746 ) {
  217.                         buffer[ram[RAM_q]] = '5'; CursorAdv(RAM_q); temp_q++;
  218.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  219.                         timer = KEY_DELAY;
  220.                     }
  221.                 }
  222.                 if ( Game->KeyPress[43] ){ //tilde -- this might have issues unless we can set uncap false.
  223.                     if ( ram[RAM_q] < 214746 ) {
  224.                         buffer[ram[RAM_q]] = '6'; CursorAdv(RAM_q); temp_q++;
  225.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  226.                         timer = KEY_DELAY;
  227.                     }
  228.                 }
  229.                 if ( Game->KeyPress[44] ){ //tilde -- this might have issues unless we can set uncap false.
  230.                     if ( ram[RAM_q] < 214746 ) {
  231.                         buffer[ram[RAM_q]] = '7'; CursorAdv(RAM_q); temp_q++;
  232.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  233.                         timer = KEY_DELAY;
  234.                     }
  235.                 }
  236.                 if ( Game->KeyPress[45] ){ //tilde -- this might have issues unless we can set uncap false.
  237.                     if ( ram[RAM_q] < 214746 ) {
  238.                         buffer[ram[RAM_q]] = '8'; CursorAdv(RAM_q); temp_q++;
  239.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  240.                         timer = KEY_DELAY;
  241.                     }
  242.                 }              
  243.                 if ( Game->KeyPress[46] ){ //tilde -- this might have issues unless we can set uncap false.
  244.                     if ( ram[RAM_q] < 214746 ) {
  245.                         buffer[ram[RAM_q]] = '9'; CursorAdv(RAM_q); temp_q++;
  246.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  247.                         timer = KEY_DELAY;
  248.                     }
  249.                 }
  250.                 if ( Game->KeyPress[60] ){ //tilde -- this might have issues unless we can set uncap false.
  251.                     if ( ram[RAM_q] < 214746 ) {
  252.                         buffer[ram[RAM_q]] = '~'; CursorAdv(RAM_q); temp_q++;
  253.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  254.                         timer = KEY_DELAY;
  255.                     }
  256.                 }
  257.                 if ( Game->KeyPress[61] ){
  258.                     if ( ram[RAM_q] < 214746 ) {
  259.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  260.                         {   buffer[ram[RAM_q]] = '_'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  261.                         else { buffer[ram[RAM_q]] = '-'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  262.                         timer = KEY_DELAY;
  263.                     }
  264.                 }
  265.                 if ( Game->KeyPress[62] ){
  266.                     if ( ram[RAM_q] < 214746 ) {
  267.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  268.                         {   buffer[ram[RAM_q]] = '+'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  269.                         else { buffer[ram[RAM_q]] = '='; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  270.                         timer = KEY_DELAY;
  271.                     }
  272.                 }
  273.                 if ( Game->KeyPress[63] ){ //backspace key
  274.                     //Do not permit backspace is we reach the first character of the buffer!
  275.                     if ( ram[RAM_q] < 214746 && ram[RAM_q] > 0 ) {
  276.                         CursorRev(RAM_q); temp_q--; buffer[ram[RAM_q]] = 0; //clear the last character typed.
  277.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  278.                         timer = KEY_DELAY;
  279.                     }
  280.                 }  
  281.  
  282.                 if ( Game->KeyPress[64] ){ //tab
  283.                     if ( ram[RAM_q] < 214746 ) {
  284.                         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);}
  285.                         timer = KEY_DELAY;
  286.                     }
  287.                 }
  288.                 if ( Game->KeyPress[65] ){
  289.                     if ( ram[RAM_q] < 214746 ) {
  290.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  291.                         {   buffer[ram[RAM_q]] = '{'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  292.                         else { buffer[ram[RAM_q]] = '['; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  293.                         timer = KEY_DELAY;
  294.                     }
  295.                 }
  296.                 if ( Game->KeyPress[66] ){
  297.                     if ( ram[RAM_q] < 214746 ) {
  298.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  299.                         {   buffer[ram[RAM_q]] = '}'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  300.                         else { buffer[ram[RAM_q]] = ']'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  301.                         timer = KEY_DELAY;
  302.                     }
  303.                 }
  304.                 if ( Game->KeyPress[68] ){
  305.                     if ( ram[RAM_q] < 214746 ) {
  306.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  307.                         {   buffer[ram[RAM_q]] = ':'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  308.                         else { buffer[ram[RAM_q]] = ';'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  309.                         timer = KEY_DELAY;
  310.                     }
  311.                 }
  312.                 if ( Game->KeyPress[69] ){
  313.                     if ( ram[RAM_q] < 214746 ) {
  314.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  315.                         {   buffer[ram[RAM_q]] = CHAR_DQUOTE; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  316.                         else { buffer[ram[RAM_q]] = CHAR_QUOTE; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  317.                         timer = KEY_DELAY;
  318.                     }
  319.                 }
  320.                 if ( Game->KeyPress[70] ){
  321.                     if ( ram[RAM_q] < 214746 ) {
  322.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  323.                         {   buffer[ram[RAM_q]] = '|'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  324.                         else { buffer[ram[RAM_q]] = CHAR_BSLASH; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  325.                         timer = KEY_DELAY;
  326.                     }
  327.                 }
  328.                 if ( Game->KeyPress[71] ){
  329.                     if ( ram[RAM_q] < 214746 ) {
  330.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  331.                         {   buffer[ram[RAM_q]] = '|'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  332.                         else { buffer[ram[RAM_q]] = CHAR_BSLASH; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  333.                         timer = KEY_DELAY;
  334.                     }
  335.                 }
  336.                 if ( Game->KeyPress[72] ){
  337.                     if ( ram[RAM_q] < 214746 ) {
  338.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  339.                         {   buffer[ram[RAM_q]] = '<'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  340.                         else { buffer[ram[RAM_q]] = ','; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  341.                         timer = KEY_DELAY;
  342.                     }
  343.                 }
  344.                 if ( Game->KeyPress[73] ){
  345.                     if ( ram[RAM_q] < 214746 ) {
  346.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  347.                         {   buffer[ram[RAM_q]] = '>'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  348.                         else { buffer[ram[RAM_q]] = '.'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  349.                         timer = KEY_DELAY;
  350.                     }
  351.                 }
  352.                 if ( Game->KeyPress[74] ){
  353.                     if ( ram[RAM_q] < 214746 ) {
  354.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  355.                         {   buffer[ram[RAM_q]] = '?'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  356.                         else { buffer[ram[RAM_q]] = '/'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  357.                         timer = KEY_DELAY;
  358.                     }
  359.                 }
  360.                
  361.                 if ( Game->KeyPress[75] ){
  362.                     if ( ram[RAM_q] < 214746 ) {
  363.                         buffer[ram[RAM_q]] = CHAR_SPACE; CursorAdv(RAM_q); temp_q++;
  364.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  365.                         timer = KEY_DELAY;
  366.                     }
  367.                 }
  368.                 if ( Game->KeyPress[77] ){ //delete
  369.                     if ( ram[RAM_q] < 214746 ) {
  370.                         for ( int w = ram[RAM_q]; w >= 0; w-- ) buffer[w] = 0;
  371.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);
  372.                         ResetCursor(); temp_q = 0;
  373.                         timer = KEY_DELAY;
  374.                     }
  375.                 }
  376.                 if ( Game->KeyPress[78] ){
  377.                     if ( ram[RAM_q] < 214746 ) {
  378.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  379.                         {   buffer[ram[RAM_q]] = '~'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  380.                         else { buffer[ram[RAM_q]] = '`'; CursorAdv(RAM_q); temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  381.                         timer = KEY_DELAY;
  382.                     }
  383.                 }
  384.                 if ( Game->KeyPress[82] ){ //leftarrow
  385.                     Link->PressLeft = false; Link->InputLeft = false;
  386.                     if ( ram[RAM_q] < 214746 ) {
  387.                         //ram[RAM_q]--;
  388.                         CursorRev(RAM_q);
  389.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);//temp_q--;
  390.                         timer = KEY_DELAY;
  391.                     }
  392.                 }
  393.                 if ( Game->KeyPress[83] ){ //leftarrow
  394.                     Link->PressRight = false; Link->InputRight = false;
  395.                     if ( ram[RAM_q] < 214746 ) {
  396.                         CursorAdv(RAM_q);
  397.                         //ram[RAM_q]++;
  398.                         if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);//temp_q--; //needs to operate on temp_q so that the highest position is recorded.
  399.                         timer = KEY_DELAY;
  400.                     }
  401.                 }
  402.                 if ( Game->KeyPress[84] ){ //up
  403.                     Link->PressUp = false; Link->InputUp = false;
  404.                     //find the previous command in the list
  405.                     /* if ( ram[RAM_q] < 214746 ) {
  406.                         if ( (Game->KeyPress[115] || Game->KeyPress[116]))
  407.                         {   buffer[ram[RAM_q]] = '|'; q++; temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  408.                         else { buffer[ram[RAM_q]] = CHAR_BSLASH; q++; temp_q++; if ( SFX_KEYPRESS > 0 ) Game->PlaySound(SFX_KEYPRESS);}
  409.                         timer = KEY_DELAY;
  410.                     }
  411.                     */
  412.                 }
  413.                 if ( Game->KeyPress[85] ){ //up
  414.                     Link->PressDown = false; Link->InputDown = false;
  415.                     //find the next command in the list, clear if none
  416.                     /* if ( ram[RAM_q] < 214746 ) {
  417.                         if ( (Game->KeyPress[115] || Game->KeyPress[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 ( Game->KeyPress[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 ( Game->KeyPress[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 ( Game->KeyPress[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 ( Game->KeyPress[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 ( Game->KeyPress[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 ( Game->KeyPress[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 ( Game->KeyPress[101] ){
  468.                     if ( ram[RAM_q] < 214746 ) {
  469.                         if ( (Game->KeyPress[115] || Game->KeyPress[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 ( Game->KeyPress[105] ){
  477.                     if ( ram[RAM_q] < 214746 ) {
  478.                         if ( (Game->KeyPress[115] || Game->KeyPress[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.             //Adjust the cursor position based on the size of the last typed character.
  489.             if ( ram[RAM_q] > 0 ) {
  490.                 ram[RAM_lastchar] = buffer[ram[RAM_q]-1];
  491.                 ram[RAM_cursorspacing] = GetCursorSpacing(ram[RAM_lastchar]);
  492.             }
  493.             //If we backspace all the way, rfeser the cursor position to 0 in all respects.
  494.             if ( ram[RAM_q] == 0 ) {
  495.                 ram[RAM_lastchar] = 0;
  496.                 ram[RAM_cursorspacing] = 0;
  497.                
  498.             }
  499.            
  500.             if ( timer == KEY_DELAY ) {
  501.                 Trace(ram[RAM_lastchar]);
  502.                 Trace(GetCursorSpacing(ram[RAM_lastchar]));
  503.                 Trace(ram[RAM_cursorspacing]);
  504.                 Trace(ram[RAM_cursorposition]);
  505.             }
  506.                
  507.             Screen->DrawString(6,0,0,2, 0x01, -1, 0, GetBuffer(),128);
  508.    
  509.             if ( cursorblink > CURSOR_BLINK_DUR ) {
  510.                 int cursor[] = "_";
  511.                 Screen->DrawString(6,ram[RAM_cursorposition]+ram[RAM_cursorspacing],0+CURSOR_Y_OFS,2, 0x01, -1, 0, cursor,128); //cursor
  512.                 //Screen->DrawString(6,0,0+CURSOR_Y_OFS,2, 0x01, -1, 0, GetCursorOverlay(),128); //cursor
  513.                 /*
  514.                 Screen->Line(6,
  515.                     0+0+(q*CHAR_WIDTH),
  516.                     //BUFFER_OUTPUT_X+CURSOR_X_OFFSET+(q*CHAR_WIDTH),
  517.                     //BUFFER_OUTPUT_Y+CURSOR_Y_OFFSET,
  518.                     6,
  519.                     0+0+(q*CHAR_WIDTH)+4,
  520.                     //BUFFER_OUTPUT_X+CURSOR_X_OFFSET+(q*CHAR_WIDTH) + CURSOR_WIDTH,
  521.                     6,
  522.                     //BUFFER_OUTPUT_Y+CURSOR_Y_OFFSET,
  523.                     0x01, 1, 0, 0, 0, 128);
  524.                 */
  525.             }  
  526.             Waitdraw(); Waitframe();
  527.         }
  528.     }
  529. }  
  530.  
  531. int GetCursorSpacing(int chr, int font){
  532.     if ( font == 0 ) {
  533.         int spacing[]={
  534.             0, 0, 0, 0, 0, 0, 0, 0, 0, 16, //tab
  535.             0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  536.             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //(29)
  537.             0, 0, // (31)
  538.             4, 2, 4, 6, 6, 4, 5, 2, 3, 3,
  539.             4, 4, 3, 4, 2, 0, 4, 3, 4, 4, //literal 3
  540.             4, 4, 4, 4, 4, 4, 2, 2, 4, 4, //equals
  541.             4, 4, 5, //@ sign
  542.             //A
  543.             5, 5, 4, 5, 4, 4, 5, 4, 2, 4,
  544.             //K
  545.             5, 4, 6, 6, 5, 5, 5, 5, 5, 4,
  546.             //U
  547.             5, 6, 6, 6, 4, 4, //Z
  548.             //lbrace
  549.             4, 5, 4, 4, 4, 4,
  550.             //a
  551.             5, 5, 4, 5, 4, 4, 5, 4, 2, 4,
  552.             //k
  553.             5, 4, 6, 6, 5, 5, 5, 5, 5, 4,
  554.             //u
  555.             5, 6, 6, 4, 4, 4, //z
  556.             //{
  557.             4, 2, 4, 5,
  558.             //127
  559.             0,
  560.             //Forward Del
  561.             0
  562.         };
  563.         return spacing[chr];
  564.     }
  565. }
  566.  
  567. int GetCursorSpacing(int chr){
  568.     //Custom kerning... Organised by English-language, and C-Programming linguistic frequency for short-circuiting,
  569.      
  570.     if ( chr == ' ' ) return 4;
  571.    
  572.     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;
  573.     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;
  574.     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;
  575.     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;  
  576.     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;
  577.     if ( chr == 'Z' ) return 4;
  578.    
  579.     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;
  580.     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;
  581.     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;
  582.     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;
  583.     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;
  584.     if ( chr == 'z' ) return 4;
  585.    
  586.     if ( chr == '.' ) return 2; if ( chr == '!' ) return 2; if ( chr == ',' ) return 3; if ( chr == '?' ) return 4; if ( chr == ':' ) return 2;
  587.    
  588.     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;
  589.     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;
  590.    
  591.     if ( chr == ';' ) return 2;  f ( chr == '(' ) return 3; if ( chr == ')' ) return 3; if ( chr == '-' ) return 4;
  592.    
  593.     if ( chr == CHAR_QUOTE ) return 2; //Zeelda to be a parser bug. Comparing the buffer character ' ' ' to 'A' returned 5.
  594.     if ( chr == CHAR_DQUOTE ) return 4;
  595.    
  596.     if ( chr == '{' ) return 4; if ( chr == '}' ) return 4; if ( chr == '&' ) return 5; if ( chr == '|' ) return 2; if ( chr == '_' ) return 4;
  597.     if ( chr == '=' ) return 4; if ( chr == '*' ) return 4; if ( chr == '+' ) return 4; if ( chr == '/' ) return 4; if ( chr == '%' ) return 4;
  598.     if ( chr == '<' ) return 4; if ( chr == '>' ) return 4; if ( chr == '[' ) return 4; if ( chr == ']' ) return 4; if ( chr == '~' ) return 5;
  599.      
  600.    
  601.     if ( chr == '@' ) return 5; if ( chr == '#' ) return 6; if ( chr == '$' ) return 6; if ( chr == CHAR_POUNDS ) return 5;  if ( chr == '^' ) return 4;
  602.      
  603.     if ( chr == CHAR_BSLASH ) return 5; if ( chr == '`' ) return 4;
  604.    
  605. }
  606.    
  607. int GetBuffer(){
  608.     //int ptr = bufptr;
  609.     //return bufptr[buffer];
  610.     return buffer;
  611.    
  612. }  
  613.  
  614. int GetCursorOverlay(){
  615.     return bufferoverlay;
  616. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement