1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-11-18 15:06:35 +00:00

Renamed getch() to getch_noblock(). It now returns a string with the character instead of the ordinal value.

This commit is contained in:
Mike Naberezny 2009-08-18 22:19:05 -07:00
parent b063782906
commit bd1aae66e3
2 changed files with 24 additions and 17 deletions

View File

@ -11,7 +11,7 @@ from py65.devices.mpu65c02 import MPU as CMOS65C02
from py65.disassembler import Disassembler
from py65.assembler import Assembler
from py65.utils.addressing import AddressParser
from py65.utils.console import getch
from py65.utils.console import getch_noblock
from py65.utils.conversions import itoa
from py65.memory import ObservableMemory
@ -92,7 +92,12 @@ class Monitor(cmd.Cmd):
self.stdout.flush()
def getc(address):
return getch(self.stdin)
char = getch_noblock(self.stdin)
if char:
byte = ord(char)
else:
byte = 0
return byte
m = ObservableMemory()
m.subscribe_to_write([0xF001], putc)

View File

@ -3,15 +3,15 @@ import sys
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.
def getch_noblock(stdin):
""" Performs a nonblocking read of one character from the Windows
console and returns it. The stdin argument is for function
signature compatibility and is ignored. If no character is
available, an empty string is returned.
"""
if msvcrt.kbhit():
return ord(msvcrt.getch())
return 0
return msvcrt.getch()
return ''
else:
import select
@ -19,9 +19,10 @@ else:
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.
def getch_noblock(stdin):
""" Performs a nonblocking read of one character from stdin
returns it. If no character is available, an empty string
is returned.
"""
fd = stdin.fileno()
@ -38,11 +39,12 @@ else:
byte = 0
r, w, e = select.select([fd], [], [], 0.1)
if r:
c = stdin.read(1)
byte = ord(c)
if byte == 0x0a:
byte = 0x0d
char = stdin.read(1)
if char == "\n":
char = "\r"
else:
char = ''
finally:
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
return byte
return char