Bit pattern mini-language for instruction encodings. Bytes in, IR out!
Project description
Bit pattern mini-language for instruction encodings. Bytes in, IR out!
See docs for a step-by-step tutorial and API reference. Here's a complete example:
>>> import bitspec
>>> @bitspec.bitspec('11 xy:1 11101 0xCB nn:s8 00 000 r:3', op='RLC')
... @bitspec.bitspec('11 xy:1 11101 0xCB nn:s8 00 001 r:3', op='RRC')
... @bitspec.bitspec('11 xy:1 11101 0xCB nn:s8 00 010 r:3', op='RL ')
... @bitspec.bitspec('11 xy:1 11101 0xCB nn:s8 00 011 r:3', op='RR ')
... @bitspec.bitspec('11 xy:1 11101 0xCB nn:s8 00 100 r:3', op='SLA')
... @bitspec.bitspec('11 xy:1 11101 0xCB nn:s8 00 101 r:3', op='SRA')
... @bitspec.bitspec('11 xy:1 11101 0xCB nn:s8 00 110 r:3', op='SL1') # "SLL"
... @bitspec.bitspec('11 xy:1 11101 0xCB nn:s8 00 111 r:3', op='SRL')
... @bitspec.bitspec('11 xy:1 11101 0xCB nn:s8 10 b:3 r:3', op='RES')
... @bitspec.bitspec('11 xy:1 11101 0xCB nn:s8 11 b:3 r:3', op='SET')
... class Z80UndocBitOps: # NORTHERN BYTES Volume 3 #10 (October 1982)
... def __str__(self): # mirrored at http://z80.info/z80undoc.htm
... dst = ['B,', 'C,', 'D,', 'E,', 'H,', 'L,', '', 'A,'][self.r]
... bit = '' if self.b == None else f'{self.b},'
... src = ['IX', 'IY'][self.xy]
... return f'{self.op} {dst}{bit}({src}{self.nn:+})'
... def __repr__(self): return f'<{self!s}>'
... def __init__(self, xy, nn, r, op, b=None):
... self.xy, self.nn, self.r, self.op, self.b = xy, nn, r, op, b
>>> code = bytes.fromhex('fdCB7f17 ddCBfe88 fdCB0125')
>>> Z80UndocBitOps.from_bytes(code)
<RL A,(IY+127)>
>>> {hex(op.addr):op for op in Z80UndocBitOps.iter_bytes(code, addr=0x50)}
{'0x50': <RL A,(IY+127)>, '0x54': <RES B,1,(IX-2)>, '0x58': <SLA L,(IY+1)>}
Install from Pypi or just copy bitspec.py
into your project. Bugs, questions,
or other feedback are welcome!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bitspec-0.4.4.tar.gz.
File metadata
- Download URL: bitspec-0.4.4.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.27.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d18de629778a2a31859cb90dabab98dccf031acbb614be9dab6f11d253e85bf
|
|
| MD5 |
d95cfae0098b7b43de8fad8aebda84ab
|
|
| BLAKE2b-256 |
b06e3298edbd166ca479f1fabaf925cd1bc7727690de01ef93db52e88b18b1e0
|
File details
Details for the file bitspec-0.4.4-py3-none-any.whl.
File metadata
- Download URL: bitspec-0.4.4-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.27.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36242daf1c1099a08b96853529d25fb43dc98e1845f48ed639a38d6602f078c1
|
|
| MD5 |
c363757fcfdb71a888060647c2b66f29
|
|
| BLAKE2b-256 |
521c3fba09f8474e913a8ce941ed7de9c866acb3b3039098f14f7d7fc07c5cc5
|