mirror of
https://github.com/mnaberez/py65.git
synced 2025-08-07 07:29:02 +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:
@@ -11,7 +11,7 @@ from py65.devices.mpu65c02 import MPU as CMOS65C02
|
|||||||
from py65.disassembler import Disassembler
|
from py65.disassembler import Disassembler
|
||||||
from py65.assembler import Assembler
|
from py65.assembler import Assembler
|
||||||
from py65.utils.addressing import AddressParser
|
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.utils.conversions import itoa
|
||||||
from py65.memory import ObservableMemory
|
from py65.memory import ObservableMemory
|
||||||
|
|
||||||
@@ -92,7 +92,12 @@ class Monitor(cmd.Cmd):
|
|||||||
self.stdout.flush()
|
self.stdout.flush()
|
||||||
|
|
||||||
def getc(address):
|
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 = ObservableMemory()
|
||||||
m.subscribe_to_write([0xF001], putc)
|
m.subscribe_to_write([0xF001], putc)
|
||||||
|
@@ -3,15 +3,15 @@ import sys
|
|||||||
if sys.platform[:3] == "win":
|
if sys.platform[:3] == "win":
|
||||||
import msvcrt
|
import msvcrt
|
||||||
|
|
||||||
def getch(stdin):
|
def getch_noblock(stdin):
|
||||||
""" Performs a nonblocking read of one byte from the Windows
|
""" Performs a nonblocking read of one character from the Windows
|
||||||
console and returns its ordinal value. The stdin argument
|
console and returns it. The stdin argument is for function
|
||||||
is for function signature compatibility and is ignored. If
|
signature compatibility and is ignored. If no character is
|
||||||
no byte is available, 0 is returned.
|
available, an empty string is returned.
|
||||||
"""
|
"""
|
||||||
if msvcrt.kbhit():
|
if msvcrt.kbhit():
|
||||||
return ord(msvcrt.getch())
|
return msvcrt.getch()
|
||||||
return 0
|
return ''
|
||||||
|
|
||||||
else:
|
else:
|
||||||
import select
|
import select
|
||||||
@@ -19,9 +19,10 @@ else:
|
|||||||
import termios
|
import termios
|
||||||
import fcntl
|
import fcntl
|
||||||
|
|
||||||
def getch(stdin):
|
def getch_noblock(stdin):
|
||||||
""" Performs a nonblocking read of one byte from stdin and returns
|
""" Performs a nonblocking read of one character from stdin
|
||||||
its ordinal value. If no byte is available, 0 is returned.
|
returns it. If no character is available, an empty string
|
||||||
|
is returned.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fd = stdin.fileno()
|
fd = stdin.fileno()
|
||||||
@@ -38,11 +39,12 @@ else:
|
|||||||
byte = 0
|
byte = 0
|
||||||
r, w, e = select.select([fd], [], [], 0.1)
|
r, w, e = select.select([fd], [], [], 0.1)
|
||||||
if r:
|
if r:
|
||||||
c = stdin.read(1)
|
char = stdin.read(1)
|
||||||
byte = ord(c)
|
if char == "\n":
|
||||||
if byte == 0x0a:
|
char = "\r"
|
||||||
byte = 0x0d
|
else:
|
||||||
|
char = ''
|
||||||
finally:
|
finally:
|
||||||
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
|
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
|
||||||
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
|
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
|
||||||
return byte
|
return char
|
||||||
|
Reference in New Issue
Block a user