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/.vscode/launch.json +27 -18
- package/.vscode/tasks.json +23 -13
- package/Cargo.lock +88 -0
- package/Cargo.toml +17 -0
- package/README-crate.md +65 -0
- package/README.md +64 -64
- package/bindings/rust/lib.rs +192 -0
- package/build/index.d.ts +14 -0
- package/build/index.js +58 -1
- package/build/map.json +3 -3
- package/package.json +35 -31
- package/src/index.ts +93 -33
- package/src/map.json +2406 -2406
- package/tsconfig.json +109 -109
package/.vscode/launch.json
CHANGED
|
@@ -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
|
}
|
package/.vscode/tasks.json
CHANGED
|
@@ -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/Cargo.lock
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 3
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "a2-memory-map"
|
|
7
|
+
version = "1.0.4"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"serde_json",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[[package]]
|
|
13
|
+
name = "itoa"
|
|
14
|
+
version = "1.0.11"
|
|
15
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
16
|
+
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
|
|
17
|
+
|
|
18
|
+
[[package]]
|
|
19
|
+
name = "proc-macro2"
|
|
20
|
+
version = "1.0.82"
|
|
21
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
22
|
+
checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b"
|
|
23
|
+
dependencies = [
|
|
24
|
+
"unicode-ident",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[[package]]
|
|
28
|
+
name = "quote"
|
|
29
|
+
version = "1.0.36"
|
|
30
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
31
|
+
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
|
|
32
|
+
dependencies = [
|
|
33
|
+
"proc-macro2",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[[package]]
|
|
37
|
+
name = "ryu"
|
|
38
|
+
version = "1.0.18"
|
|
39
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
40
|
+
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
|
41
|
+
|
|
42
|
+
[[package]]
|
|
43
|
+
name = "serde"
|
|
44
|
+
version = "1.0.202"
|
|
45
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
46
|
+
checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395"
|
|
47
|
+
dependencies = [
|
|
48
|
+
"serde_derive",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
[[package]]
|
|
52
|
+
name = "serde_derive"
|
|
53
|
+
version = "1.0.202"
|
|
54
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
55
|
+
checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838"
|
|
56
|
+
dependencies = [
|
|
57
|
+
"proc-macro2",
|
|
58
|
+
"quote",
|
|
59
|
+
"syn",
|
|
60
|
+
]
|
|
61
|
+
|
|
62
|
+
[[package]]
|
|
63
|
+
name = "serde_json"
|
|
64
|
+
version = "1.0.117"
|
|
65
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
66
|
+
checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3"
|
|
67
|
+
dependencies = [
|
|
68
|
+
"itoa",
|
|
69
|
+
"ryu",
|
|
70
|
+
"serde",
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
[[package]]
|
|
74
|
+
name = "syn"
|
|
75
|
+
version = "2.0.64"
|
|
76
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
77
|
+
checksum = "7ad3dee41f36859875573074334c200d1add8e4a87bb37113ebd31d926b7b11f"
|
|
78
|
+
dependencies = [
|
|
79
|
+
"proc-macro2",
|
|
80
|
+
"quote",
|
|
81
|
+
"unicode-ident",
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
[[package]]
|
|
85
|
+
name = "unicode-ident"
|
|
86
|
+
version = "1.0.12"
|
|
87
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
88
|
+
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
package/Cargo.toml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "a2-memory-map"
|
|
3
|
+
description = "Database of Apple II memory addresses"
|
|
4
|
+
version = "1.0.4"
|
|
5
|
+
keywords = ["retro", "apple"]
|
|
6
|
+
categories = []
|
|
7
|
+
repository = "https://github.com/dfgordon/a2-memory-map"
|
|
8
|
+
homepage = "https://github.com/dfgordon/a2-memory-map"
|
|
9
|
+
readme = "README-crate.md"
|
|
10
|
+
edition = "2021"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
|
|
13
|
+
[lib]
|
|
14
|
+
path = "bindings/rust/lib.rs"
|
|
15
|
+
|
|
16
|
+
[dependencies]
|
|
17
|
+
serde_json = "1.0.116"
|
package/README-crate.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Apple II Memory Map
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This is the rust binding to 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
|
+
## Map Records
|
|
8
|
+
|
|
9
|
+
The map records correspond to the structure
|
|
10
|
+
|
|
11
|
+
```rs
|
|
12
|
+
pub struct AddressInfo {
|
|
13
|
+
pub brief: Option<String>,
|
|
14
|
+
pub ctx: Option<String>,
|
|
15
|
+
pub desc: String,
|
|
16
|
+
pub label: Option<String>,
|
|
17
|
+
pub note: Option<String>,
|
|
18
|
+
pub subctx: Option<String>,
|
|
19
|
+
pub typ: String
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Information is accessed through the opaque `struct MemoryMap`. The whole database can be borrowed as a `HashMap` as follows:
|
|
24
|
+
|
|
25
|
+
```rs
|
|
26
|
+
let a2map = MemoryMap::new();
|
|
27
|
+
let full_map: &HashMap<u16,AddressInfo> = a2map.get_all();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
To get a single record use
|
|
31
|
+
|
|
32
|
+
```rs
|
|
33
|
+
let maybe_info: Option<AddressInfo> = a2map.get_one(addr);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The argument `addr` can range from -32767 to 65535. As an example `get_one(0xfded)` will give the rust equivalent of
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
{
|
|
40
|
+
brief: 'Print character in A',
|
|
41
|
+
desc: 'Invoke output routine whose address is in (56). Usually prints character in A.',
|
|
42
|
+
label: 'COUT',
|
|
43
|
+
type: 'ROM routine'
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## AddressInfo Fields
|
|
48
|
+
|
|
49
|
+
* `brief`: short description suitable for display in a selection box
|
|
50
|
+
* `ctx`: notes on limiting context, such as hardware requirements, applicability to given language, etc.
|
|
51
|
+
* `desc`: long description suitable for hovers
|
|
52
|
+
* `label`: suggested assembler label
|
|
53
|
+
* `note`: any other notes
|
|
54
|
+
* `subctx`: notes on sub context, e.g., specific aspect of a language
|
|
55
|
+
* `type`: data type (e.g. `word`) or operation type (e.g. `ROM routine`, `soft switch`)
|
|
56
|
+
|
|
57
|
+
## Multi-context Records
|
|
58
|
+
|
|
59
|
+
The `map.json` file uses logic expressions to delineate information by context, e.g., `ctx` might have the value `"Applesoft | Integer BASIC"`. The rust binding provides a function to parse the logic and produce an array of records, with each element corresponding to a given context:
|
|
60
|
+
|
|
61
|
+
```rs
|
|
62
|
+
let maybe_records: Option<Vec<AddressInfo>> = a2map.get_one_and_split(addr);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
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.
|
package/README.md
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
# Apple II Memory Map
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* `
|
|
49
|
-
* `
|
|
50
|
-
* `
|
|
51
|
-
* `
|
|
52
|
-
* `
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
# Apple II Memory Map
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
This is the TypeScript binding to 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
|
+
## Map Records
|
|
8
|
+
|
|
9
|
+
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_one(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.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
use serde_json;
|
|
2
|
+
use std::collections::HashMap;
|
|
3
|
+
|
|
4
|
+
#[cfg(windows)]
|
|
5
|
+
const JSON_MAP: &str = include_str!("..\\..\\src\\map.json");
|
|
6
|
+
#[cfg(not(windows))]
|
|
7
|
+
const JSON_MAP: &str = include_str!("../../src/map.json");
|
|
8
|
+
|
|
9
|
+
#[derive(Clone)]
|
|
10
|
+
pub struct AddressInfo {
|
|
11
|
+
pub brief: Option<String>,
|
|
12
|
+
pub ctx: Option<String>,
|
|
13
|
+
pub desc: String,
|
|
14
|
+
pub label: Option<String>,
|
|
15
|
+
pub note: Option<String>,
|
|
16
|
+
pub subctx: Option<String>,
|
|
17
|
+
pub typ: String
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// All interactions are through this object
|
|
21
|
+
pub struct MemoryMap {
|
|
22
|
+
memmap: HashMap<u16,AddressInfo>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fn get_val(key: &str,val: &serde_json::Value) -> Option<String> {
|
|
26
|
+
match &val[key] {
|
|
27
|
+
serde_json::Value::String(s) => Some(s.to_string()),
|
|
28
|
+
_ => None
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
fn get_contextual_str(str: &String, count: usize) -> String {
|
|
32
|
+
let contexts: Vec<_> = str.split('|').collect();
|
|
33
|
+
if count < contexts.len() {
|
|
34
|
+
return contexts[count].trim().to_string();
|
|
35
|
+
}
|
|
36
|
+
return str.to_string();
|
|
37
|
+
}
|
|
38
|
+
fn get_contextual_str_maybe(maybe_str: &Option<String>, count: usize) -> Option<String> {
|
|
39
|
+
if let Some(str) = maybe_str {
|
|
40
|
+
let contexts: Vec<_> = str.split('|').collect();
|
|
41
|
+
if count < contexts.len() {
|
|
42
|
+
return Some(contexts[count].trim().to_string());
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return None;
|
|
46
|
+
}
|
|
47
|
+
fn get_contextual_info(info: &AddressInfo, count: usize) -> AddressInfo {
|
|
48
|
+
AddressInfo {
|
|
49
|
+
brief: get_contextual_str_maybe(&info.brief,count),
|
|
50
|
+
ctx: get_contextual_str_maybe(&info.ctx,count),
|
|
51
|
+
desc: get_contextual_str(&info.desc,count),
|
|
52
|
+
subctx: get_contextual_str_maybe(&info.subctx,count),
|
|
53
|
+
label: get_contextual_str_maybe(&info.label,count),
|
|
54
|
+
note: get_contextual_str_maybe(&info.note,count),
|
|
55
|
+
typ: get_contextual_str(&info.typ,count)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
impl MemoryMap {
|
|
60
|
+
pub fn new() -> Self {
|
|
61
|
+
let mut m = Self {
|
|
62
|
+
memmap: HashMap::new()
|
|
63
|
+
};
|
|
64
|
+
let temp = serde_json::from_str::<serde_json::Value>(JSON_MAP).unwrap();
|
|
65
|
+
if let Some(obj) = temp.as_object() {
|
|
66
|
+
for (key,val) in obj {
|
|
67
|
+
let addr = u16::from_str_radix(&key[2..],16).expect("bad address in memory map");
|
|
68
|
+
let addr_info = AddressInfo {
|
|
69
|
+
brief: get_val("brief",val),
|
|
70
|
+
ctx: get_val("ctx",val),
|
|
71
|
+
desc: get_val("desc",val).unwrap(),
|
|
72
|
+
subctx: get_val("subctx",val),
|
|
73
|
+
label: get_val("label",val),
|
|
74
|
+
note: get_val("note",val),
|
|
75
|
+
typ: get_val("type",val).unwrap(),
|
|
76
|
+
};
|
|
77
|
+
m.memmap.insert(addr,addr_info);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
assert!(m.memmap.len()>0);
|
|
81
|
+
m
|
|
82
|
+
}
|
|
83
|
+
/// Borrow the underlying HashMap
|
|
84
|
+
pub fn get_all(&self) -> &HashMap<u16,AddressInfo> {
|
|
85
|
+
return &self.memmap;
|
|
86
|
+
}
|
|
87
|
+
/// Get data for one address.
|
|
88
|
+
/// @param addr address in the range -32767 to 65535
|
|
89
|
+
pub fn get_one(&self,addr: i64) -> Option<AddressInfo> {
|
|
90
|
+
let pos_addr = match addr < 0 { true => addr + 1 + u16::MAX as i64, false => addr };
|
|
91
|
+
if pos_addr >=0 && pos_addr < u16::MAX as i64 {
|
|
92
|
+
self.memmap.get(&(pos_addr as u16)).cloned()
|
|
93
|
+
} else {
|
|
94
|
+
None
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/// Get data for one address and split by context
|
|
98
|
+
/// @param addr Array of AddressInfo objects, one for each context, or undefined
|
|
99
|
+
pub fn get_one_and_split(&self,addr: i64) -> Option<Vec<AddressInfo>> {
|
|
100
|
+
if let Some(obj) = self.get_one(addr) {
|
|
101
|
+
let mut ans = Vec::new();
|
|
102
|
+
let num = match &obj.ctx {
|
|
103
|
+
Some(ctx) => ctx.split('|').collect::<Vec<_>>().len(),
|
|
104
|
+
None => 1
|
|
105
|
+
};
|
|
106
|
+
// if one context do not split anything
|
|
107
|
+
if num == 1 {
|
|
108
|
+
ans.push(obj);
|
|
109
|
+
return Some(ans);
|
|
110
|
+
}
|
|
111
|
+
// if multi-context, split all fields on `|`
|
|
112
|
+
for count in 0..num {
|
|
113
|
+
ans.push(get_contextual_info(&obj, count));
|
|
114
|
+
}
|
|
115
|
+
return Some(ans);
|
|
116
|
+
}
|
|
117
|
+
None
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#[test]
|
|
122
|
+
fn get_cout() {
|
|
123
|
+
let mem_map = MemoryMap::new();
|
|
124
|
+
let cout = mem_map.get_one(0xfded);
|
|
125
|
+
assert!(cout.unwrap().label==Some("COUT".to_string()));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
#[test]
|
|
129
|
+
fn applesoft_integer() {
|
|
130
|
+
let mem_map = MemoryMap::new();
|
|
131
|
+
let addr = 0xf8;
|
|
132
|
+
match mem_map.get_one_and_split(addr) {
|
|
133
|
+
Some(info_list) => {
|
|
134
|
+
assert_eq!(info_list.len(),2);
|
|
135
|
+
assert_eq!(info_list[0].ctx,Some("Applesoft".to_string()));
|
|
136
|
+
assert_eq!(info_list[1].ctx,Some("Integer BASIC".to_string()));
|
|
137
|
+
assert_eq!(info_list[0].typ,"byte value".to_string());
|
|
138
|
+
assert_eq!(info_list[1].typ,"float32".to_string());
|
|
139
|
+
assert_eq!(info_list[0].label,Some("REMSTK".to_string()));
|
|
140
|
+
assert_eq!(info_list[1].label,Some("FP1".to_string()));
|
|
141
|
+
},
|
|
142
|
+
None => panic!("address not found")
|
|
143
|
+
}
|
|
144
|
+
let addr = 0xdc;
|
|
145
|
+
match mem_map.get_one_and_split(addr) {
|
|
146
|
+
Some(info_list) => {
|
|
147
|
+
assert_eq!(info_list.len(),2);
|
|
148
|
+
assert_eq!(info_list[0].ctx,Some("Applesoft".to_string()));
|
|
149
|
+
assert_eq!(info_list[1].ctx,Some("Integer BASIC".to_string()));
|
|
150
|
+
assert_eq!(info_list[0].typ,"word".to_string());
|
|
151
|
+
assert_eq!(info_list[1].typ,"word".to_string());
|
|
152
|
+
assert_eq!(info_list[0].label,Some("ERRPOS".to_string()));
|
|
153
|
+
assert_eq!(info_list[1].label,Some("CURLIN".to_string()));
|
|
154
|
+
},
|
|
155
|
+
None => panic!("address not found")
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#[test]
|
|
160
|
+
fn no_split() {
|
|
161
|
+
let mem_map = MemoryMap::new();
|
|
162
|
+
let addr = 0xff70;
|
|
163
|
+
match mem_map.get_one_and_split(addr) {
|
|
164
|
+
Some(info_list) => {
|
|
165
|
+
assert_eq!(info_list.len(),1);
|
|
166
|
+
assert_eq!(info_list[0].typ,"ROM routine".to_string());
|
|
167
|
+
},
|
|
168
|
+
None => panic!("address not found")
|
|
169
|
+
}
|
|
170
|
+
let addr = 0xe597;
|
|
171
|
+
match mem_map.get_one_and_split(addr) {
|
|
172
|
+
Some(info_list) => {
|
|
173
|
+
assert_eq!(info_list.len(),1);
|
|
174
|
+
assert_eq!(info_list[0].typ,"ROM routine".to_string());
|
|
175
|
+
assert_eq!(info_list[0].subctx,Some("parsing & string".to_string()));
|
|
176
|
+
},
|
|
177
|
+
None => panic!("address not found")
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#[test]
|
|
182
|
+
fn splits_but_one_ctx() {
|
|
183
|
+
let mem_map = MemoryMap::new();
|
|
184
|
+
let addr = 0xc080;
|
|
185
|
+
match mem_map.get_one_and_split(addr) {
|
|
186
|
+
Some(info_list) => {
|
|
187
|
+
assert_eq!(info_list.len(),1);
|
|
188
|
+
assert_eq!(info_list[0].brief,Some("RDRAM | stepper 0".to_string()));
|
|
189
|
+
},
|
|
190
|
+
None => panic!("address not found")
|
|
191
|
+
}
|
|
192
|
+
}
|
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;
|