a2-memory-map 1.0.2 → 1.0.3

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.
@@ -1,19 +1,28 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "type": "node",
9
- "request": "launch",
10
- "name": "Launch Program",
11
- "outFiles": [
12
- "${workspaceFolder}/build/*.js"
13
- ],
14
- "runtimeExecutable": "node",
15
- "args": ["./build/index.js"],
16
- "preLaunchTask": "tsc: build - tsconfig.json"
17
- }
18
- ]
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "node",
9
+ "request": "launch",
10
+ "name": "Launch Program",
11
+ "outFiles": [
12
+ "${workspaceFolder}/build/*.js"
13
+ ],
14
+ "runtimeExecutable": "node",
15
+ "args": ["./build/index.js"],
16
+ "preLaunchTask": "tsc: build - tsconfig.json"
17
+ },
18
+ {
19
+ "name": "Test",
20
+ "type": "node",
21
+ "request": "launch",
22
+ "args": ["./build/test/runTest.js"],
23
+ "outFiles": ["${workspaceRoot}/build/test/**/*.js"],
24
+ "preLaunchTask": "npm: test-compile"
25
+ }
26
+
27
+ ]
19
28
  }
@@ -1,14 +1,24 @@
1
- {
2
- "version": "2.0.0",
3
- "tasks": [
4
- {
5
- "type": "typescript",
6
- "tsconfig": "tsconfig.json",
7
- "problemMatcher": [
8
- "$tsc"
9
- ],
10
- "group": "build",
11
- "label": "tsc: build - tsconfig.json"
12
- }
13
- ]
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "type": "typescript",
6
+ "tsconfig": "tsconfig.json",
7
+ "problemMatcher": [
8
+ "$tsc"
9
+ ],
10
+ "group": "build",
11
+ "label": "tsc: build - tsconfig.json"
12
+ },
13
+ {
14
+ "type": "npm",
15
+ "script": "test-compile",
16
+ "group": {
17
+ "kind": "build",
18
+ "isDefault": true
19
+ },
20
+ "problemMatcher": "$tsc",
21
+ "label": "npm: test-compile"
22
+ }
23
+ ]
14
24
  }
package/README.md CHANGED
@@ -1,64 +1,72 @@
1
- # Apple II Memory Map
2
-
3
- This is a database of Apple II special addresses intended to be used with language servers. The central element is the file `map.json` which maps addresses to a set of descriptive strings.
4
-
5
- ## TypeScript Interface
6
-
7
- The project includes a Node package that can be used to access the data. The map records correspond to the interface
8
-
9
- ```ts
10
- interface AddressInfo {
11
- brief: string | undefined,
12
- ctx: string | undefined,
13
- desc: string,
14
- label: string | undefined,
15
- note: string | undefined,
16
- subctx: string | undefined,
17
- type: string
18
- }
19
- ```
20
-
21
- Records are retrieved using
22
-
23
- ```ts
24
- get_all() : Map<string,AddressInfo>
25
- ```
26
-
27
- to get the whole database as a `Map`, or
28
-
29
- ```ts
30
- get_one(addr: number): AddressInfo | undefined
31
- ```
32
-
33
- to get a single record. The argument `addr` can range from -32767 to 65535. As an example `get_info(0xfded)` will give
34
-
35
- ```js
36
- {
37
- brief: 'Print character in A',
38
- desc: 'Invoke output routine whose address is in (56). Usually prints character in A.',
39
- label: 'COUT',
40
- type: 'ROM routine'
41
- }
42
- ```
43
-
44
- ## AddressInfo Fields
45
-
46
- * `brief`: short description suitable for display in a selection box
47
- * `ctx`: notes on limiting context, such as hardware requirements, applicability to given language, etc.
48
- * `desc`: long description suitable for hovers
49
- * `label`: suggested assembler label
50
- * `note`: any other notes
51
- * `subctx`: notes on sub context, e.g., specific aspect of a language
52
- * `type`: data type (e.g. `word`) or operation type (e.g. `ROM routine`, `soft switch`)
53
-
54
- ## Multiple Context Addresses
55
-
56
- If the address has multiple contexts, the fields are still strings, i.e., they are not promoted to any other structure such as a list. As an example, if the address has a meaning for both Applesoft and Integer BASIC, we use `ctx = "Applesoft | Integer BASIC"`.
57
-
58
- ## References
59
-
60
- Apple's own documentation is a good starting point. The "Apple IIe Reference Manual" has low level information. The "Applesoft BASIC Programmer's Reference Manual" provides a chapter "Pokes, Peeks, and Calls" with information especially useful to BASIC programmers.
61
-
62
- "All About Applesoft" from [Call-A.P.P.L.E.](https://www.callapple.org/) has a more in depth treatment.
63
-
1
+ # Apple II Memory Map
2
+
3
+ ![unit tests](https://github.com/dfgordon/a2-memory-map/actions/workflows/node.js.yml/badge.svg)
4
+
5
+ This is a database of Apple II special addresses intended to be used with language servers. The central element is the file `map.json` which maps addresses to a set of descriptive strings.
6
+
7
+ ## TypeScript Interface
8
+
9
+ There is a [node package](https://www.npmjs.com/package/a2-memory-map) that can be used to access the data. The map records correspond to the interface
10
+
11
+ ```ts
12
+ interface AddressInfo {
13
+ brief: string | undefined,
14
+ ctx: string | undefined,
15
+ desc: string,
16
+ label: string | undefined,
17
+ note: string | undefined,
18
+ subctx: string | undefined,
19
+ type: string
20
+ }
21
+ ```
22
+
23
+ The whole database is retrieved as a `Map` using
24
+
25
+ ```ts
26
+ get_all() : Map<string,AddressInfo>
27
+ ```
28
+
29
+ To get a single record use
30
+
31
+ ```ts
32
+ get_one(addr: number): AddressInfo | undefined
33
+ ```
34
+
35
+ The argument `addr` can range from -32767 to 65535. As an example `get_info(0xfded)` will give
36
+
37
+ ```js
38
+ {
39
+ brief: 'Print character in A',
40
+ desc: 'Invoke output routine whose address is in (56). Usually prints character in A.',
41
+ label: 'COUT',
42
+ type: 'ROM routine'
43
+ }
44
+ ```
45
+
46
+ ## AddressInfo Fields
47
+
48
+ * `brief`: short description suitable for display in a selection box
49
+ * `ctx`: notes on limiting context, such as hardware requirements, applicability to given language, etc.
50
+ * `desc`: long description suitable for hovers
51
+ * `label`: suggested assembler label
52
+ * `note`: any other notes
53
+ * `subctx`: notes on sub context, e.g., specific aspect of a language
54
+ * `type`: data type (e.g. `word`) or operation type (e.g. `ROM routine`, `soft switch`)
55
+
56
+ ## Multi-context Records
57
+
58
+ The `map.json` file uses logic expressions to delineate information by context, e.g., `ctx` might have the value `"Applesoft | Integer BASIC"`. The TypeScript interface provides a function to parse the logic and produce an array of records, with each element corresponding to a given context:
59
+
60
+ ```ts
61
+ get_one_and_split(addr: number): Array<AddressInfo> | undefined
62
+ ```
63
+
64
+ If there is no splitting of the `ctx` field, no other fields will be split. It is not required to use this function. If `get_one` is used instead, downstream will receive the logic expressions, which can be parsed in any manner desired.
65
+
66
+ ## References
67
+
68
+ Apple's own documentation is a good starting point. The "Apple IIe Reference Manual" has low level information. The "Applesoft BASIC Programmer's Reference Manual" provides a chapter "Pokes, Peeks, and Calls" with information especially useful to BASIC programmers.
69
+
70
+ "All About Applesoft" from [Call-A.P.P.L.E.](https://www.callapple.org/) has a more in depth treatment.
71
+
64
72
  Sometimes an ambiguity is best resolved by studying the relevant disassembly.
package/build/index.d.ts CHANGED
@@ -7,5 +7,19 @@ export interface AddressInfo {
7
7
  subctx: string | undefined;
8
8
  type: string;
9
9
  }
10
+ /**
11
+ * Gather the database into a map, logic strings are unprocessed.
12
+ * @returns Map from address strings to AddressInfo objects.
13
+ */
10
14
  export declare function get_all(): Map<string, AddressInfo>;
15
+ /**
16
+ * Get data for one address
17
+ * @param addr address in the range -32767 to 65535
18
+ * @returns AddressInfo object or undefined. Fields may contain logic operators.
19
+ */
11
20
  export declare function get_one(addr: number): AddressInfo | undefined;
21
+ /**
22
+ * Get data for one address and split by context
23
+ * @param addr Array of AddressInfo objects, one for each context, or undefined
24
+ */
25
+ export declare function get_one_and_split(addr: number): Array<AddressInfo> | undefined;
package/build/index.js CHANGED
@@ -23,8 +23,37 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.get_one = exports.get_all = void 0;
26
+ exports.get_one_and_split = exports.get_one = exports.get_all = void 0;
27
27
  const memmap = __importStar(require("./map.json"));
28
+ function get_contextual_str(str, count) {
29
+ const contexts = str.split('|');
30
+ if (count < contexts.length)
31
+ return contexts[count].trim();
32
+ return str;
33
+ }
34
+ function get_contextual_str_maybe(str, count) {
35
+ if (!str)
36
+ return str;
37
+ const contexts = str.split('|');
38
+ if (count < contexts.length)
39
+ return contexts[count].trim();
40
+ return str;
41
+ }
42
+ function get_contextual_info(info, count) {
43
+ return {
44
+ brief: get_contextual_str_maybe(info.brief, count),
45
+ ctx: get_contextual_str_maybe(info.ctx, count),
46
+ desc: get_contextual_str(info.desc, count),
47
+ subctx: get_contextual_str_maybe(info.subctx, count),
48
+ label: get_contextual_str_maybe(info.label, count),
49
+ note: get_contextual_str_maybe(info.note, count),
50
+ type: get_contextual_str(info.type, count)
51
+ };
52
+ }
53
+ /**
54
+ * Gather the database into a map, logic strings are unprocessed.
55
+ * @returns Map from address strings to AddressInfo objects.
56
+ */
28
57
  function get_all() {
29
58
  let m = new Map();
30
59
  for (const [key, obj] of Object.entries(memmap)) {
@@ -41,9 +70,37 @@ function get_all() {
41
70
  return m;
42
71
  }
43
72
  exports.get_all = get_all;
73
+ /**
74
+ * Get data for one address
75
+ * @param addr address in the range -32767 to 65535
76
+ * @returns AddressInfo object or undefined. Fields may contain logic operators.
77
+ */
44
78
  function get_one(addr) {
45
79
  let pos_addr = addr < 0 ? addr + 2 ** 16 : addr;
46
80
  const hex = '0x' + pos_addr.toString(16).padStart(4, '0');
47
81
  return Object(memmap)[hex];
48
82
  }
49
83
  exports.get_one = get_one;
84
+ /**
85
+ * Get data for one address and split by context
86
+ * @param addr Array of AddressInfo objects, one for each context, or undefined
87
+ */
88
+ function get_one_and_split(addr) {
89
+ const obj = get_one(addr);
90
+ if (obj) {
91
+ let ans = new Array();
92
+ const num = obj.ctx ? obj.ctx.split('|').length : 1;
93
+ // if one context do not split anything
94
+ if (num == 1) {
95
+ ans.push(obj);
96
+ return ans;
97
+ }
98
+ // if multi-context, split all fields on `|`
99
+ for (let count = 0; count < num; count++) {
100
+ ans.push(get_contextual_info(obj, count));
101
+ }
102
+ return ans;
103
+ }
104
+ return undefined;
105
+ }
106
+ exports.get_one_and_split = get_one_and_split;
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.3",
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
+ }