cvsuser     03/06/22 20:40:07

  Modified:    languages/BASIC/compiler COMP_expressions.pm
                        RT_builtins.pasm RT_platform.pasm
                        RT_platform_win32.pasm
  Log:
  Almost got INKEY working
  
  Revision  Changes    Path
  1.13      +1 -1      parrot/languages/BASIC/compiler/COMP_expressions.pm
  
  Index: COMP_expressions.pm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/BASIC/compiler/COMP_expressions.pm,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -w -r1.12 -r1.13
  --- COMP_expressions.pm       17 Jun 2003 02:24:48 -0000      1.12
  +++ COMP_expressions.pm       23 Jun 2003 03:40:07 -0000      1.13
  @@ -17,7 +17,7 @@
                erdev$          erl             err
                exp             fileattr        fix
                fre             freefile        hex$
  -             inkey_NOTYET$
  +             inkey$
                space_NOTYET$
                time_NOTYET$
                inp             input$
  
  
  
  1.6       +16 -0     parrot/languages/BASIC/compiler/RT_builtins.pasm
  
  Index: RT_builtins.pasm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/BASIC/compiler/RT_builtins.pasm,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -r1.5 -r1.6
  --- RT_builtins.pasm  12 Jun 2003 02:52:59 -0000      1.5
  +++ RT_builtins.pasm  23 Jun 2003 03:40:07 -0000      1.6
  @@ -309,7 +309,19 @@
        .param string substr
        length $I0, substr
        eq $I0, 0, ENDINSTR
  +     print "Index "
  +     print $I0
  +     print " full='"
  +     print full
  +     print "' substr='"
  +     print substr
  +     print "' start='"
  +     print start
  +     print "'\n"
        index $I0, full, substr, start
  +     print "Result = "
  +     print $I0
  +     print "\n"
        set $N0, $I0
        
   ENDINSTR:inc $N0
  @@ -567,3 +579,7 @@
        restoreall
        ret
   .end
  +.sub _BUILTIN_INKEY_STRING
  +     call _inkey_string
  +     ret
  +.end
  \ No newline at end of file
  
  
  
  1.11      +13 -0     parrot/languages/BASIC/compiler/RT_platform.pasm
  
  Index: RT_platform.pasm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/BASIC/compiler/RT_platform.pasm,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -w -r1.10 -r1.11
  --- RT_platform.pasm  8 Jun 2003 17:25:25 -0000       1.10
  +++ RT_platform.pasm  23 Jun 2003 03:40:07 -0000      1.11
  @@ -76,6 +76,19 @@
   END: restoreall
        ret
   .end
  +.sub _inkey_string           # string inkey$(void)
  +     saveall
  +     .local string sys
  +     sysinfo sys, 4
  +     ne sys, "MSWin32", NOTWIN
  +     call _WIN32_INKEY
  +     branch END
  +END: restoreall
  +     ret
  +
  +NOTWIN: print "Not supported yet\n"
  +     end
  +.end
   ## Problem in ANSI
   #SCREEN_GETFORE:
   #    sysinfo S0, 4
  
  
  
  1.9       +75 -0     parrot/languages/BASIC/compiler/RT_platform_win32.pasm
  
  Index: RT_platform_win32.pasm
  ===================================================================
  RCS file: /cvs/public/parrot/languages/BASIC/compiler/RT_platform_win32.pasm,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -w -r1.8 -r1.9
  --- RT_platform_win32.pasm    8 Jun 2003 17:25:25 -0000       1.8
  +++ RT_platform_win32.pasm    23 Jun 2003 03:40:07 -0000      1.9
  @@ -9,6 +9,10 @@
        invoke
        store_global "kernel32", P1
        store_global "Win32handle", P5
  +     set I0, 1
  +     set I5, -10
  +     invoke
  +     store_global "Win32Inputhandle", P5
        $P0= new PerlHash
        store_global "Win32console", $P0
        call _WIN32_CONSOLE_INFO
  @@ -225,6 +229,77 @@
        set I0, 1
        invoke
        call _WIN32_CONSOLE_INFO  # refresh this.
  +     restoreall
  +     ret
  +.end
  +.const int SIZEOF_INPUT_RECORD = 20
  +.const int NUMBER_OF_EVENTS = 128
  +# buffer is INPUT_RECORD * EVENTS
  +.const int INPUT_BUFFER = 2560
  +.sub _WIN32_INKEY    # string Win32_inkey(void)
  +     saveall
  +     set S0, ""
  +     set I9, 0
  +     find_global P1, "kernel32"
  +     dlfunc P0, P1, "SetConsoleMode", "ipi"
  +     set I0, 1
  +     find_global P5, "Win32Inputhandle"
  +     set I5, 0
  +     invoke
  +INKEY:  
  +     dlfunc P9, P1,  "PeekConsoleInputA",  "ippip"
  +        dlfunc P10, P1, "ReadConsoleInputA", "ippip"
  +     find_global P5, "Win32Inputhandle"
  +     P6=new ManagedStruct
  +     P7=new ManagedStruct
  +     set P6, INPUT_BUFFER
  +     set P7, SIZEOF_DWORD
  +
  +     # Are there any events?
  +     set P0, P9      # Peek
  +     set I0, 1
  +     set I5, NUMBER_OF_EVENTS        # sizeof read buffer
  +     invoke
  +
  +     # Peek down the event queue to see if there's a key event
  +     set I0, P7[0]   # Number of events.
  +     eq I0, 0, NO_EVENTS
  +     set I5, -1
  +NEXT_EVENT:
  +     inc I5
  +     eq I5, I0, END_EVENTS
  +     mul I7, I5, SIZEOF_INPUT_RECORD
  +     set I1, P6[I7]
  +     ne I1, 1, NEXT_EVENT
  +
  +     # Got a key event, was it a key down?
  +     add I8, I7, SIZEOF_DWORD
  +     set I1, P6[I8]
  +     ne I1, 1, NEXT_EVENT    # Nope, a key up
  +
  +     # Is it a special-key thingy? (shift, alt...)
  +     add I8, I7, 14
  +     set I1, P6[I8]
  +     eq I1, 0, NEXT_EVENT
  +
  +     # Cool.  Grab the key.
  +     set I9, I1
  +     chr S0, I9
  +
  +     # I6 is the event we're interested in!
  +     # 
  +     # There *was* a key event.  Pull everything up to that event
  +     #
  +     inc I5
  +     set P0, P10     # ReadConsoleInput
  +        set I0, 1
  +     find_global P5, "Win32Inputhandle"
  +     invoke
  +     branch END
  +
  +NO_EVENTS:
  +END_EVENTS:
  +END: .return S0
        restoreall
        ret
   .end
  
  
  

Reply via email to