a2-memory-map 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/map.json CHANGED
@@ -450,8 +450,8 @@
450
450
  },
451
451
  "0x00e4": {
452
452
  "ctx": "Applesoft | Integer BASIC",
453
- "desc": "color masking word | line number address",
454
- "type": "byte value"
453
+ "desc": "color masking byte | line number address",
454
+ "type": "byte value | word"
455
455
  },
456
456
  "0x00e5": {
457
457
  "ctx": "Applesoft",
@@ -502,7 +502,7 @@
502
502
  "ctx": "Applesoft | Integer BASIC",
503
503
  "desc": "Stack pointer prior to current statement execution | Floating point register 1",
504
504
  "label": "REMSTK | FP1",
505
- "type": "float32"
505
+ "type": "byte value | float32"
506
506
  },
507
507
  "0x00f9": {
508
508
  "ctx": "Applesoft",
package/package.json CHANGED
@@ -1,31 +1,35 @@
1
- {
2
- "name": "a2-memory-map",
3
- "repository": {
4
- "type": "git",
5
- "url": "https://github.com/dfgordon/a2-memory-map.git"
6
- },
7
- "version": "1.0.2",
8
- "description": "Database of Apple II memory addresses",
9
- "main": "build/index.js",
10
- "types": "build/index.d.ts",
11
- "scripts": {
12
- "test": "echo \"Error: no test specified\" && exit 1",
13
- "prepublish": "tsc"
14
- },
15
- "keywords": [
16
- "retro",
17
- "apple"
18
- ],
19
- "author": "Daniel Gordon",
20
- "license": "MIT",
21
- "bugs": {
22
- "url": "https://github.com/dfgordon/a2-memory-map/issues"
23
- },
24
- "homepage": "https://github.com/dfgordon/a2-memory-map#readme",
25
- "devDependencies": {
26
- "@types/node": "^18.16.3",
27
- "rimraf": "^5.0.0",
28
- "typescript": "^5.0.4"
29
- },
30
- "build": "rimraf ./build && tsc"
31
- }
1
+ {
2
+ "name": "a2-memory-map",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "https://github.com/dfgordon/a2-memory-map.git"
6
+ },
7
+ "version": "1.0.4",
8
+ "description": "Database of Apple II memory addresses",
9
+ "main": "build/index.js",
10
+ "types": "build/index.d.ts",
11
+ "scripts": {
12
+ "test-compile": "npx rimraf ./build && tsc",
13
+ "test": "node ./build/test/runTest.js",
14
+ "build": "rimraf ./build && tsc"
15
+ },
16
+ "keywords": [
17
+ "retro",
18
+ "apple"
19
+ ],
20
+ "author": "Daniel Gordon",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/dfgordon/a2-memory-map/issues"
24
+ },
25
+ "homepage": "https://github.com/dfgordon/a2-memory-map#readme",
26
+ "devDependencies": {
27
+ "@types/node": "^18.16.3",
28
+ "@types/mocha": "^10.0.1",
29
+ "@types/glob": "^7.2.0",
30
+ "rimraf": "^5.0.0",
31
+ "mocha": "^10.2.0",
32
+ "glob": "^7.2.0",
33
+ "typescript": "^5.0.4"
34
+ }
35
+ }
package/src/index.ts CHANGED
@@ -1,33 +1,93 @@
1
- import * as memmap from "./map.json"
2
-
3
- export interface AddressInfo {
4
- brief: string | undefined,
5
- ctx: string | undefined,
6
- desc: string,
7
- label: string | undefined,
8
- note: string | undefined,
9
- subctx: string | undefined,
10
- type: string
11
- }
12
-
13
- export function get_all(): Map<string, AddressInfo> {
14
- let m = new Map<string, AddressInfo>();
15
- for (const [key, obj] of Object.entries(memmap)) {
16
- m.set(key, {
17
- brief: 'brief' in obj ? obj.brief : undefined,
18
- ctx: 'ctx' in obj ? obj.ctx : undefined,
19
- desc: obj.desc,
20
- label: 'label' in obj ? obj.label : undefined,
21
- note: 'note' in obj ? obj.note : undefined,
22
- subctx: 'subctx' in obj ? obj.subctx : undefined,
23
- type: obj.type
24
- });
25
- }
26
- return m;
27
- }
28
-
29
- export function get_one(addr: number): AddressInfo | undefined {
30
- let pos_addr = addr < 0 ? addr + 2 ** 16 : addr;
31
- const hex = '0x' + pos_addr.toString(16).padStart(4, '0');
32
- return Object(memmap)[hex];
33
- }
1
+ import * as memmap from "./map.json"
2
+
3
+ export interface AddressInfo {
4
+ brief: string | undefined,
5
+ ctx: string | undefined,
6
+ desc: string,
7
+ label: string | undefined,
8
+ note: string | undefined,
9
+ subctx: string | undefined,
10
+ type: string
11
+ }
12
+
13
+ function get_contextual_str(str: string, count: number): string {
14
+ const contexts = str.split('|');
15
+ if (count < contexts.length)
16
+ return contexts[count].trim();
17
+ return str;
18
+ }
19
+
20
+ function get_contextual_str_maybe(str: string | undefined, count: number): string | undefined {
21
+ if (!str)
22
+ return str;
23
+ const contexts = str.split('|');
24
+ if (count < contexts.length)
25
+ return contexts[count].trim();
26
+ return str;
27
+ }
28
+
29
+ function get_contextual_info(info: AddressInfo, count: number): AddressInfo {
30
+ return {
31
+ brief: get_contextual_str_maybe(info.brief,count),
32
+ ctx: get_contextual_str_maybe(info.ctx,count),
33
+ desc: get_contextual_str(info.desc,count),
34
+ subctx: get_contextual_str_maybe(info.subctx,count),
35
+ label: get_contextual_str_maybe(info.label,count),
36
+ note: get_contextual_str_maybe(info.note,count),
37
+ type: get_contextual_str(info.type,count)
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Gather the database into a map, logic strings are unprocessed.
43
+ * @returns Map from address strings to AddressInfo objects.
44
+ */
45
+ export function get_all(): Map<string, AddressInfo> {
46
+ let m = new Map<string, AddressInfo>();
47
+ for (const [key, obj] of Object.entries(memmap)) {
48
+ m.set(key, {
49
+ brief: 'brief' in obj ? obj.brief : undefined,
50
+ ctx: 'ctx' in obj ? obj.ctx : undefined,
51
+ desc: obj.desc,
52
+ label: 'label' in obj ? obj.label : undefined,
53
+ note: 'note' in obj ? obj.note : undefined,
54
+ subctx: 'subctx' in obj ? obj.subctx : undefined,
55
+ type: obj.type
56
+ });
57
+ }
58
+ return m;
59
+ }
60
+
61
+ /**
62
+ * Get data for one address
63
+ * @param addr address in the range -32767 to 65535
64
+ * @returns AddressInfo object or undefined. Fields may contain logic operators.
65
+ */
66
+ export function get_one(addr: number): AddressInfo | undefined {
67
+ let pos_addr = addr < 0 ? addr + 2 ** 16 : addr;
68
+ const hex = '0x' + pos_addr.toString(16).padStart(4, '0');
69
+ return Object(memmap)[hex];
70
+ }
71
+
72
+ /**
73
+ * Get data for one address and split by context
74
+ * @param addr Array of AddressInfo objects, one for each context, or undefined
75
+ */
76
+ export function get_one_and_split(addr: number): Array<AddressInfo> | undefined {
77
+ const obj = get_one(addr);
78
+ if (obj) {
79
+ let ans = new Array<AddressInfo>();
80
+ const num = obj.ctx ? obj.ctx.split('|').length : 1;
81
+ // if one context do not split anything
82
+ if (num == 1) {
83
+ ans.push(obj);
84
+ return ans;
85
+ }
86
+ // if multi-context, split all fields on `|`
87
+ for (let count = 0; count < num; count++) {
88
+ ans.push(get_contextual_info(obj, count));
89
+ }
90
+ return ans;
91
+ }
92
+ return undefined
93
+ }