mirror of
https://github.com/mnaberez/py65.git
synced 2024-11-18 15:06:35 +00:00
Added Windows support for nonblocking character input.
This commit is contained in:
parent
c2c08d62d2
commit
b28bbe787a
@ -1,3 +1,8 @@
|
||||
Next Release
|
||||
|
||||
- When using the monitor, the nonblocking character input at
|
||||
$F004 should now work on the Microsoft Windows platform.
|
||||
|
||||
0.6 (2009-08-11)
|
||||
|
||||
- Added monitor shortcut "a" for "assemble".
|
||||
|
2
TODO.txt
2
TODO.txt
@ -6,5 +6,3 @@ Instructions needing unit tests:
|
||||
Better error messages when assembling fails.
|
||||
|
||||
Ability to assemble more than one instruction at a time.
|
||||
|
||||
Windows support for non-blocking character input.
|
||||
|
@ -1,32 +1,48 @@
|
||||
import select
|
||||
import os
|
||||
import sys
|
||||
|
||||
def getch(stdin):
|
||||
""" Performs a nonblocking read of one byte from stdin and returns
|
||||
its ordinal value. If no byte is available, 0 is returned.
|
||||
"""
|
||||
if sys.platform[:3] == "win":
|
||||
import msvcrt
|
||||
|
||||
def getch(stdin):
|
||||
""" Performs a nonblocking read of one byte from the Windows
|
||||
console and returns its ordinal value. The stdin argument
|
||||
is for function signature compatibility and is ignored. If
|
||||
no byte is available, 0 is returned.
|
||||
"""
|
||||
if msvcrt.kbhit():
|
||||
return ord(msvcrt.getch())
|
||||
return 0
|
||||
|
||||
else:
|
||||
import select
|
||||
import os
|
||||
import termios
|
||||
import fcntl
|
||||
|
||||
def getch(stdin):
|
||||
""" Performs a nonblocking read of one byte from stdin and returns
|
||||
its ordinal value. If no byte is available, 0 is returned.
|
||||
"""
|
||||
|
||||
fd = stdin.fileno()
|
||||
fd = stdin.fileno()
|
||||
|
||||
oldterm = termios.tcgetattr(fd)
|
||||
newattr = oldterm[:]
|
||||
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
|
||||
termios.tcsetattr(fd, termios.TCSANOW, newattr)
|
||||
oldterm = termios.tcgetattr(fd)
|
||||
newattr = oldterm[:]
|
||||
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
|
||||
termios.tcsetattr(fd, termios.TCSANOW, newattr)
|
||||
|
||||
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
|
||||
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
|
||||
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
|
||||
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
|
||||
|
||||
try:
|
||||
byte = 0
|
||||
r, w, e = select.select([fd], [], [], 0.1)
|
||||
if r:
|
||||
c = stdin.read(1)
|
||||
byte = ord(c)
|
||||
if byte == 0x0a:
|
||||
byte = 0x0d
|
||||
finally:
|
||||
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
|
||||
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
|
||||
return byte
|
||||
try:
|
||||
byte = 0
|
||||
r, w, e = select.select([fd], [], [], 0.1)
|
||||
if r:
|
||||
c = stdin.read(1)
|
||||
byte = ord(c)
|
||||
if byte == 0x0a:
|
||||
byte = 0x0d
|
||||
finally:
|
||||
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
|
||||
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
|
||||
return byte
|
||||
|
Loading…
Reference in New Issue
Block a user