Created
December 10, 2013 01:44
-
-
Save tylereaves/7884506 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import unsigned | |
| type | |
| TAddrKind = enum | |
| akByte, | |
| akWord, | |
| akPacked, | |
| akPackedRoutine, | |
| akPackedString | |
| TAddr = object | |
| case kind: TAddrKind | |
| of akByte: byteVal: uint16 | |
| of akWord: wordVal: uint16 | |
| of akPacked: packedVal: uint16 | |
| of akPackedRoutine: routineVal: uint16 | |
| of akPackedString: stringVal: uint16 | |
| #1.1 | |
| var data = newseq[uint8]() | |
| var version = 0 | |
| var filename = "" | |
| var highmem = 0 | |
| var dynamicmem = 0 | |
| var staticmem = 0 | |
| var length = 0'u32 | |
| converter | |
| proc getaddr(a: TAddr): uint32 = | |
| case a.kind | |
| of akByte: | |
| if a.byteVal <= length: | |
| return a.byteVal | |
| else: | |
| raise EOutOfRange | |
| of akWord: | |
| let v = a.wordVal * 2 | |
| if v < length: | |
| return v | |
| else: | |
| raise EOutOfRange | |
| of akPacked: | |
| case version | |
| of 1, 2, 3: | |
| let v = a.packedVal * 2 | |
| of 4, 5: | |
| let v = a.packedVal * 4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment