-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Custom Dict, comma, emacs major mode, usage examples
It allows finer grained control for setting individual actions eg: - perform side-effects when 'M' register is updated or accessed. - Normalizing register values to 02x and address to 04x etc Add comma support in instructions for compatibility with standard Add emacs major mode workflow. Add extensive command usage examples.
- Loading branch information
1 parent
b63fae0
commit f9922ed
Showing
6 changed files
with
763 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from collections import UserDict | ||
|
||
|
||
class RegisterDict(UserDict): | ||
def __init__(self, state, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.update(*args, **kwargs) | ||
self.state = state | ||
|
||
def __setitem__(self, key: str, value: str): | ||
value = f"0x{int(value, 16):02x}" | ||
if key == "M": | ||
mem_addr = self.state.get_mem_addr_register_pair("H") | ||
self.state.memory[mem_addr] = value | ||
super().__setitem__(key, value) | ||
|
||
def __getitem__(self, key: str): | ||
if key == "M": | ||
return self.state.get_register_pair_value("H") | ||
return super().__getitem__(key) | ||
|
||
def update(self, *args, **kwargs): | ||
if len(args) > 1: | ||
raise TypeError("update expected at most 1 arguments, got %d" % len(args)) | ||
other = dict(*args, **kwargs) | ||
for key in other: | ||
self[key] = other[key] | ||
|
||
|
||
class MemoryDict(UserDict): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.update(*args, **kwargs) | ||
|
||
def __setitem__(self, key: str, value: str): | ||
key = f"0x{int(key, 16):04x}" | ||
value = f"0x{int(value, 16):02x}" | ||
super().__setitem__(key, value) | ||
|
||
def __getitem__(self, key: str): | ||
return super().__getitem__(key) | ||
|
||
def update(self, *args, **kwargs): | ||
if len(args) > 1: | ||
raise TypeError("update expected at most 1 arguments, got %d" % len(args)) | ||
other = dict(*args, **kwargs) | ||
for key in other: | ||
self[key] = other[key] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.