a2-memory-map 1.0.4 → 1.1.0
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/CHANGELOG.md +56 -0
- package/Cargo.lock +41 -23
- package/Cargo.toml +7 -5
- package/README-crate.md +20 -1
- package/README.md +27 -3
- package/bindings/rust/lib.rs +126 -40
- package/build/index.js +86 -45
- package/build/index.js.map +1 -0
- package/build/map.json +336 -136
- package/build/map.schema.json +39 -0
- package/build/vendors.json +263 -0
- package/build/vendors.schema.json +28 -0
- package/build.rs +154 -0
- package/package.json +7 -7
- package/src/index.ts +99 -19
- package/src/map.json +336 -136
- package/src/map.schema.json +39 -0
- package/src/vendors.json +263 -0
- package/src/vendors.schema.json +28 -0
- package/tsconfig.json +12 -107
- package/build/index.d.ts +0 -25
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html) is adhered to starting with v1.0.4.
|
|
7
|
+
|
|
8
|
+
## [1.1.0] - 2026-11-29
|
|
9
|
+
|
|
10
|
+
### Fixes
|
|
11
|
+
|
|
12
|
+
* Update development dependencies
|
|
13
|
+
* Update entries: COUT,RDKEY,GETLN
|
|
14
|
+
* Unambiguous notation for 16 bit words
|
|
15
|
+
* Provide JSON schema for the map
|
|
16
|
+
* TypeScript type safety fixes
|
|
17
|
+
|
|
18
|
+
### New Features
|
|
19
|
+
|
|
20
|
+
* Data includes authentic vendor docstrings
|
|
21
|
+
* Bindings to retrieve vendor docstrings
|
|
22
|
+
* Rust build generates native code from `src/*.json`
|
|
23
|
+
- eliminates runtime parsing and dependencies
|
|
24
|
+
|
|
25
|
+
### New Behaviors
|
|
26
|
+
|
|
27
|
+
* Bumped rust edition to 2024
|
|
28
|
+
* Set the MSRV to 1.85
|
|
29
|
+
|
|
30
|
+
## [1.0.4] - 2024-05-17
|
|
31
|
+
|
|
32
|
+
Add the rust binding
|
|
33
|
+
|
|
34
|
+
## [1.0.3] - 2023-05-06
|
|
35
|
+
|
|
36
|
+
### Fixes
|
|
37
|
+
|
|
38
|
+
* Enable CI workflow
|
|
39
|
+
* Add tests
|
|
40
|
+
* Update entries: $E4, REMSTK
|
|
41
|
+
|
|
42
|
+
### New Features
|
|
43
|
+
|
|
44
|
+
* functions to evaluate an entry's context information
|
|
45
|
+
|
|
46
|
+
## [1.0.2] - 2023-04-30
|
|
47
|
+
|
|
48
|
+
Publish on npmjs
|
|
49
|
+
|
|
50
|
+
## [1.0.1] - 2023-04-30
|
|
51
|
+
|
|
52
|
+
Form the full map
|
|
53
|
+
|
|
54
|
+
## [1.0.0] - 2023-04-30
|
|
55
|
+
|
|
56
|
+
Initial Commit
|
package/Cargo.lock
CHANGED
|
@@ -1,58 +1,68 @@
|
|
|
1
1
|
# This file is automatically @generated by Cargo.
|
|
2
2
|
# It is not intended for manual editing.
|
|
3
|
-
version =
|
|
3
|
+
version = 4
|
|
4
4
|
|
|
5
5
|
[[package]]
|
|
6
6
|
name = "a2-memory-map"
|
|
7
|
-
version = "1.0
|
|
7
|
+
version = "1.1.0"
|
|
8
8
|
dependencies = [
|
|
9
|
+
"quote",
|
|
9
10
|
"serde_json",
|
|
10
11
|
]
|
|
11
12
|
|
|
12
13
|
[[package]]
|
|
13
14
|
name = "itoa"
|
|
14
|
-
version = "1.0.
|
|
15
|
+
version = "1.0.19"
|
|
16
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
17
|
+
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
|
18
|
+
|
|
19
|
+
[[package]]
|
|
20
|
+
name = "memchr"
|
|
21
|
+
version = "2.8.3"
|
|
15
22
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
16
|
-
checksum = "
|
|
23
|
+
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
17
24
|
|
|
18
25
|
[[package]]
|
|
19
26
|
name = "proc-macro2"
|
|
20
|
-
version = "1.0.
|
|
27
|
+
version = "1.0.107"
|
|
21
28
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
22
|
-
checksum = "
|
|
29
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
23
30
|
dependencies = [
|
|
24
31
|
"unicode-ident",
|
|
25
32
|
]
|
|
26
33
|
|
|
27
34
|
[[package]]
|
|
28
35
|
name = "quote"
|
|
29
|
-
version = "1.0.
|
|
36
|
+
version = "1.0.47"
|
|
30
37
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
31
|
-
checksum = "
|
|
38
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
32
39
|
dependencies = [
|
|
33
40
|
"proc-macro2",
|
|
34
41
|
]
|
|
35
42
|
|
|
36
43
|
[[package]]
|
|
37
|
-
name = "
|
|
38
|
-
version = "1.0.
|
|
44
|
+
name = "serde"
|
|
45
|
+
version = "1.0.229"
|
|
39
46
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
40
|
-
checksum = "
|
|
47
|
+
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
|
48
|
+
dependencies = [
|
|
49
|
+
"serde_core",
|
|
50
|
+
]
|
|
41
51
|
|
|
42
52
|
[[package]]
|
|
43
|
-
name = "
|
|
44
|
-
version = "1.0.
|
|
53
|
+
name = "serde_core"
|
|
54
|
+
version = "1.0.229"
|
|
45
55
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
46
|
-
checksum = "
|
|
56
|
+
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
|
47
57
|
dependencies = [
|
|
48
58
|
"serde_derive",
|
|
49
59
|
]
|
|
50
60
|
|
|
51
61
|
[[package]]
|
|
52
62
|
name = "serde_derive"
|
|
53
|
-
version = "1.0.
|
|
63
|
+
version = "1.0.229"
|
|
54
64
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
55
|
-
checksum = "
|
|
65
|
+
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
|
56
66
|
dependencies = [
|
|
57
67
|
"proc-macro2",
|
|
58
68
|
"quote",
|
|
@@ -61,20 +71,22 @@ dependencies = [
|
|
|
61
71
|
|
|
62
72
|
[[package]]
|
|
63
73
|
name = "serde_json"
|
|
64
|
-
version = "1.0.
|
|
74
|
+
version = "1.0.154"
|
|
65
75
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
66
|
-
checksum = "
|
|
76
|
+
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
|
67
77
|
dependencies = [
|
|
68
78
|
"itoa",
|
|
69
|
-
"
|
|
79
|
+
"memchr",
|
|
70
80
|
"serde",
|
|
81
|
+
"serde_core",
|
|
82
|
+
"zmij",
|
|
71
83
|
]
|
|
72
84
|
|
|
73
85
|
[[package]]
|
|
74
86
|
name = "syn"
|
|
75
|
-
version = "
|
|
87
|
+
version = "3.0.10"
|
|
76
88
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
77
|
-
checksum = "
|
|
89
|
+
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
|
78
90
|
dependencies = [
|
|
79
91
|
"proc-macro2",
|
|
80
92
|
"quote",
|
|
@@ -83,6 +95,12 @@ dependencies = [
|
|
|
83
95
|
|
|
84
96
|
[[package]]
|
|
85
97
|
name = "unicode-ident"
|
|
86
|
-
version = "1.0.
|
|
98
|
+
version = "1.0.27"
|
|
99
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
100
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
101
|
+
|
|
102
|
+
[[package]]
|
|
103
|
+
name = "zmij"
|
|
104
|
+
version = "1.0.23"
|
|
87
105
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
88
|
-
checksum = "
|
|
106
|
+
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
package/Cargo.toml
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "a2-memory-map"
|
|
3
3
|
description = "Database of Apple II memory addresses"
|
|
4
|
-
version = "1.0
|
|
4
|
+
version = "1.1.0"
|
|
5
5
|
keywords = ["retro", "apple"]
|
|
6
6
|
categories = []
|
|
7
7
|
repository = "https://github.com/dfgordon/a2-memory-map"
|
|
8
|
-
homepage = "https://github.com/dfgordon/a2-memory-map"
|
|
9
8
|
readme = "README-crate.md"
|
|
10
|
-
edition = "
|
|
9
|
+
edition = "2024"
|
|
10
|
+
rust-version = "1.85"
|
|
11
|
+
build = "build.rs"
|
|
11
12
|
license = "MIT"
|
|
12
13
|
|
|
13
14
|
[lib]
|
|
14
15
|
path = "bindings/rust/lib.rs"
|
|
15
16
|
|
|
16
|
-
[dependencies]
|
|
17
|
-
serde_json = "1.0
|
|
17
|
+
[build-dependencies]
|
|
18
|
+
serde_json = "1.0"
|
|
19
|
+
quote = "1.0"
|
package/README-crate.md
CHANGED
|
@@ -38,7 +38,7 @@ The argument `addr` can range from -32767 to 65535. As an example `get_one(0xfd
|
|
|
38
38
|
```js
|
|
39
39
|
{
|
|
40
40
|
brief: 'Print character in A',
|
|
41
|
-
desc: 'Invoke output routine whose address is in (
|
|
41
|
+
desc: 'Invoke output routine whose address is in (54). Usually prints character in A.',
|
|
42
42
|
label: 'COUT',
|
|
43
43
|
type: 'ROM routine'
|
|
44
44
|
}
|
|
@@ -63,3 +63,22 @@ let maybe_records: Option<Vec<AddressInfo>> = a2map.get_one_and_split(addr);
|
|
|
63
63
|
```
|
|
64
64
|
|
|
65
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.
|
|
66
|
+
|
|
67
|
+
## Docstrings from Vendor Sources
|
|
68
|
+
|
|
69
|
+
Some addresses correspond to entry points where an authentic vendor docstring is available. You can retrieve this docstring as follows:
|
|
70
|
+
|
|
71
|
+
```rs
|
|
72
|
+
let a2map = MemoryMap::new();
|
|
73
|
+
let maybe_docstr = a2map.get_vendor_docstring(addr,Some("Applesoft"),Some("Microsoft"));
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The argument `addr` can range from -32767 to 65535.
|
|
77
|
+
In this case the search is filtered to return only the Applesoft context and Microsoft vendor. Arguments can be set to `None` to remove the filter.
|
|
78
|
+
|
|
79
|
+
You can retrieve the actual context and vendor name using
|
|
80
|
+
|
|
81
|
+
```rs
|
|
82
|
+
let maybe_vendor_name = a2map.get_vendor_name(addr);
|
|
83
|
+
let maybe_ctx = a2map.get_vendor_ctx(addr);
|
|
84
|
+
```
|
package/README.md
CHANGED
|
@@ -32,12 +32,12 @@ To get a single record use
|
|
|
32
32
|
get_one(addr: number): AddressInfo | undefined
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
The argument `addr` can range from -32767 to 65535. As an example `get_one(0xfded)` will give
|
|
35
|
+
The argument `addr` can range from -32767 to 65535 (out of range is coerced). As an example `get_one(0xfded)` will give
|
|
36
36
|
|
|
37
37
|
```js
|
|
38
38
|
{
|
|
39
39
|
brief: 'Print character in A',
|
|
40
|
-
desc: 'Invoke output routine whose address is in (
|
|
40
|
+
desc: 'Invoke output routine whose address is in (54). Usually prints character in A.',
|
|
41
41
|
label: 'COUT',
|
|
42
42
|
type: 'ROM routine'
|
|
43
43
|
}
|
|
@@ -61,4 +61,28 @@ The `map.json` file uses logic expressions to delineate information by context,
|
|
|
61
61
|
get_one_and_split(addr: number): Array<AddressInfo> | undefined
|
|
62
62
|
```
|
|
63
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.
|
|
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
|
+
## Docstrings from Vendor Sources
|
|
67
|
+
|
|
68
|
+
Some addresses correspond to entry points where an authentic vendor docstring is available. You can retrieve this docstring using:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
get_vendor_docstring(
|
|
72
|
+
addr: number,
|
|
73
|
+
ctx?: string,
|
|
74
|
+
vendor?: string
|
|
75
|
+
): string | undefined
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The argument `addr` can range from -32767 to 65535 (out of range is coerced).
|
|
79
|
+
The search is filtered to return only the supplied context and vendor. If the context or vendor are omitted, or set to `undefined`, the filter is removed.
|
|
80
|
+
|
|
81
|
+
You can retrieve the actual context and vendor name using
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
get_vendor_ctx(addr: number): string | undefined
|
|
85
|
+
```
|
|
86
|
+
```ts
|
|
87
|
+
get_vendor_name(addr: number): string | undefined
|
|
88
|
+
```
|
package/bindings/rust/lib.rs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
use serde_json;
|
|
2
1
|
use std::collections::HashMap;
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
// This includes files generated by cargo during the build step.
|
|
4
|
+
// This files contains the project's JSON data in native rust form.
|
|
5
|
+
// This way the parsing only happens at build time, and downstream
|
|
6
|
+
// will not need the serde dependency.
|
|
7
|
+
include!(concat!(env!("OUT_DIR"),"/map_generated.rs"));
|
|
8
|
+
include!(concat!(env!("OUT_DIR"),"/vendors_generated.rs"));
|
|
8
9
|
|
|
9
10
|
#[derive(Clone)]
|
|
10
11
|
pub struct AddressInfo {
|
|
@@ -17,23 +18,34 @@ pub struct AddressInfo {
|
|
|
17
18
|
pub typ: String
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
#[derive(Clone)]
|
|
22
|
+
struct VendorInfo {
|
|
23
|
+
pub ctx: Option<String>,
|
|
24
|
+
pub docstr: String,
|
|
25
|
+
pub vendor: String
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
/// All interactions are through this object
|
|
21
29
|
pub struct MemoryMap {
|
|
22
|
-
memmap: HashMap<u16,AddressInfo
|
|
30
|
+
memmap: HashMap<u16,AddressInfo>,
|
|
31
|
+
vendors: HashMap<u16,VendorInfo>
|
|
23
32
|
}
|
|
24
33
|
|
|
25
|
-
fn
|
|
26
|
-
match
|
|
27
|
-
|
|
34
|
+
fn normalize_addr(addr: i64) -> Option<u16> {
|
|
35
|
+
let pos_addr = match addr < 0 { true => addr + 1 + u16::MAX as i64, false => addr };
|
|
36
|
+
match u16::try_from(pos_addr) {
|
|
37
|
+
Ok(ans) => Some(ans),
|
|
28
38
|
_ => None
|
|
29
39
|
}
|
|
30
40
|
}
|
|
41
|
+
|
|
31
42
|
fn get_contextual_str(str: &String, count: usize) -> String {
|
|
32
43
|
let contexts: Vec<_> = str.split('|').collect();
|
|
33
44
|
if count < contexts.len() {
|
|
34
|
-
|
|
45
|
+
contexts[count].trim().to_string()
|
|
46
|
+
} else {
|
|
47
|
+
str.to_string()
|
|
35
48
|
}
|
|
36
|
-
return str.to_string();
|
|
37
49
|
}
|
|
38
50
|
fn get_contextual_str_maybe(maybe_str: &Option<String>, count: usize) -> Option<String> {
|
|
39
51
|
if let Some(str) = maybe_str {
|
|
@@ -42,7 +54,7 @@ fn get_contextual_str_maybe(maybe_str: &Option<String>, count: usize) -> Option<
|
|
|
42
54
|
return Some(contexts[count].trim().to_string());
|
|
43
55
|
}
|
|
44
56
|
}
|
|
45
|
-
|
|
57
|
+
None
|
|
46
58
|
}
|
|
47
59
|
fn get_contextual_info(info: &AddressInfo, count: usize) -> AddressInfo {
|
|
48
60
|
AddressInfo {
|
|
@@ -58,41 +70,22 @@ fn get_contextual_info(info: &AddressInfo, count: usize) -> AddressInfo {
|
|
|
58
70
|
|
|
59
71
|
impl MemoryMap {
|
|
60
72
|
pub fn new() -> Self {
|
|
61
|
-
|
|
62
|
-
memmap:
|
|
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
|
-
}
|
|
73
|
+
Self {
|
|
74
|
+
memmap: load_map(),
|
|
75
|
+
vendors: load_vendors()
|
|
79
76
|
}
|
|
80
|
-
assert!(m.memmap.len()>0);
|
|
81
|
-
m
|
|
82
77
|
}
|
|
83
|
-
/// Borrow the underlying HashMap
|
|
78
|
+
/// Borrow the underlying address information HashMap
|
|
84
79
|
pub fn get_all(&self) -> &HashMap<u16,AddressInfo> {
|
|
85
|
-
|
|
80
|
+
&self.memmap
|
|
86
81
|
}
|
|
87
82
|
/// Get data for one address.
|
|
88
83
|
/// @param addr address in the range -32767 to 65535
|
|
89
84
|
pub fn get_one(&self,addr: i64) -> Option<AddressInfo> {
|
|
90
|
-
let
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
None
|
|
95
|
-
}
|
|
85
|
+
let Some(addr16) = normalize_addr(addr) else {
|
|
86
|
+
return None;
|
|
87
|
+
};
|
|
88
|
+
self.memmap.get(&(addr16)).cloned()
|
|
96
89
|
}
|
|
97
90
|
/// Get data for one address and split by context
|
|
98
91
|
/// @param addr Array of AddressInfo objects, one for each context, or undefined
|
|
@@ -116,6 +109,59 @@ impl MemoryMap {
|
|
|
116
109
|
}
|
|
117
110
|
None
|
|
118
111
|
}
|
|
112
|
+
/// Get the vendor docstring, if available, that applies to the given `addr`.
|
|
113
|
+
/// If optional arguments are `Some` they are used to restrict the results.
|
|
114
|
+
pub fn get_vendor_docstring(&self,addr: i64,ctx: Option<&str>,vendor: Option<&str>) -> Option<String> {
|
|
115
|
+
let Some(addr16) = normalize_addr(addr) else {
|
|
116
|
+
return None;
|
|
117
|
+
};
|
|
118
|
+
let Some(rec) = self.vendors.get(&addr16) else {
|
|
119
|
+
return None;
|
|
120
|
+
};
|
|
121
|
+
if let Some(requested_ctx) = ctx {
|
|
122
|
+
if let Some(actual_ctx) = &rec.ctx {
|
|
123
|
+
if requested_ctx != actual_ctx {
|
|
124
|
+
return None;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if let Some(requested_vendor) = vendor {
|
|
129
|
+
if rec.vendor != requested_vendor {
|
|
130
|
+
return None;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
Some(rec.docstr.clone()) // the list of strings has already been joined during the build stage
|
|
134
|
+
}
|
|
135
|
+
/// Get the name of the vendor that provides the docstr, if it exists
|
|
136
|
+
pub fn get_vendor_name(&self,addr: i64) -> Option<String> {
|
|
137
|
+
let Some(addr16) = normalize_addr(addr) else {
|
|
138
|
+
return None;
|
|
139
|
+
};
|
|
140
|
+
let Some(rec) = self.vendors.get(&addr16) else {
|
|
141
|
+
return None;
|
|
142
|
+
};
|
|
143
|
+
Some(rec.vendor.to_owned())
|
|
144
|
+
}
|
|
145
|
+
/// Get the context of this docstr, if it exists.
|
|
146
|
+
/// N.b. the context may not exist even if the docstring does.
|
|
147
|
+
pub fn get_vendor_ctx(&self,addr: i64) -> Option<String> {
|
|
148
|
+
let Some(addr16) = normalize_addr(addr) else {
|
|
149
|
+
return None;
|
|
150
|
+
};
|
|
151
|
+
let Some(rec) = self.vendors.get(&addr16) else {
|
|
152
|
+
return None;
|
|
153
|
+
};
|
|
154
|
+
let Some(ctx) = &rec.ctx else {
|
|
155
|
+
return None;
|
|
156
|
+
};
|
|
157
|
+
Some(ctx.to_owned())
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
impl Default for MemoryMap {
|
|
162
|
+
fn default() -> Self {
|
|
163
|
+
Self::new()
|
|
164
|
+
}
|
|
119
165
|
}
|
|
120
166
|
|
|
121
167
|
#[test]
|
|
@@ -189,4 +235,44 @@ fn splits_but_one_ctx() {
|
|
|
189
235
|
},
|
|
190
236
|
None => panic!("address not found")
|
|
191
237
|
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
#[test]
|
|
241
|
+
fn vendor_docs_fndlin() {
|
|
242
|
+
let mem_map = MemoryMap::new();
|
|
243
|
+
let expected =
|
|
244
|
+
r#"FNDLIN SEARCHES THE PROGRAM TEXT FOR THE LINE
|
|
245
|
+
WHOSE NUMBER IS PASSED IN "LINNUM".
|
|
246
|
+
THERE ARE TWO POSSIBLE RETURNS:
|
|
247
|
+
|
|
248
|
+
1) CARRY SET.
|
|
249
|
+
LOWTR POINTS TO THE LINK FIELD IN THE LINE
|
|
250
|
+
WHICH IS THE ONE SEARCHED FOR.
|
|
251
|
+
|
|
252
|
+
2) CARRY NOT SET.
|
|
253
|
+
LINE NOT FOUND. [LOWTR] POINTS TO THE LINE IN THE
|
|
254
|
+
PROGRAM GREATER THAN THE ONE SOUGHT AFTER."#;
|
|
255
|
+
let addr = 0xd61a;
|
|
256
|
+
match mem_map.get_vendor_docstring(addr,None,None) {
|
|
257
|
+
Some(docstr) => assert_eq!(docstr,expected),
|
|
258
|
+
None => panic!("address not found")
|
|
259
|
+
}
|
|
260
|
+
match mem_map.get_vendor_docstring(addr,Some("Applesoft"),None) {
|
|
261
|
+
Some(docstr) => assert_eq!(docstr,expected),
|
|
262
|
+
None => panic!("search failed")
|
|
263
|
+
}
|
|
264
|
+
match mem_map.get_vendor_docstring(addr,None,Some("Microsoft")) {
|
|
265
|
+
Some(docstr) => assert_eq!(docstr,expected),
|
|
266
|
+
None => panic!("search failed")
|
|
267
|
+
}
|
|
268
|
+
match mem_map.get_vendor_docstring(addr,Some("Applesoft"),Some("Microsoft")) {
|
|
269
|
+
Some(docstr) => assert_eq!(docstr,expected),
|
|
270
|
+
None => panic!("search failed")
|
|
271
|
+
}
|
|
272
|
+
match mem_map.get_vendor_docstring(addr,Some("Integer"),Some("Microsoft")) {
|
|
273
|
+
Some(_) => panic!("context restriction failed"),
|
|
274
|
+
None => ()
|
|
275
|
+
}
|
|
276
|
+
assert_eq!(mem_map.get_vendor_name(addr),Some("Microsoft".to_string()));
|
|
277
|
+
assert_eq!(mem_map.get_vendor_ctx(addr),Some("Applesoft".to_string()));
|
|
192
278
|
}
|
package/build/index.js
CHANGED
|
@@ -1,30 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
4
|
};
|
|
25
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
|
|
6
|
+
exports.get_all = get_all;
|
|
7
|
+
exports.get_one = get_one;
|
|
8
|
+
exports.get_one_and_split = get_one_and_split;
|
|
9
|
+
exports.get_vendor_docstring = get_vendor_docstring;
|
|
10
|
+
exports.get_vendor_name = get_vendor_name;
|
|
11
|
+
exports.get_vendor_ctx = get_vendor_ctx;
|
|
12
|
+
const map_json_1 = __importDefault(require("./map.json"));
|
|
13
|
+
const vendors_json_1 = __importDefault(require("./vendors.json"));
|
|
14
|
+
function formatHex16(addr) {
|
|
15
|
+
// AI states that masking with 0xffff cleanly wraps negative numbers and truncates >16-bit values
|
|
16
|
+
const u16 = addr & 0xffff;
|
|
17
|
+
return `0x${u16.toString(16).padStart(4, '0')}`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Converts a raw JSON object with hex keys into a normalized Map, ignoring $schema.
|
|
21
|
+
* This takes care of case sensitivity and gives us type checking.
|
|
22
|
+
*/
|
|
23
|
+
function createHexMap(rawJson) {
|
|
24
|
+
const map = new Map();
|
|
25
|
+
if (!rawJson || typeof rawJson !== 'object') {
|
|
26
|
+
return map;
|
|
27
|
+
}
|
|
28
|
+
for (const [key, value] of Object.entries(rawJson)) {
|
|
29
|
+
if (key === '$schema') {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const numericAddr = Number.parseInt(key, 16);
|
|
33
|
+
if (!Number.isNaN(numericAddr) && value && typeof value === 'object') {
|
|
34
|
+
map.set(formatHex16(numericAddr), value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return map;
|
|
38
|
+
}
|
|
39
|
+
const infoMap = createHexMap(map_json_1.default);
|
|
40
|
+
const vendorMap = createHexMap(vendors_json_1.default);
|
|
28
41
|
function get_contextual_str(str, count) {
|
|
29
42
|
const contexts = str.split('|');
|
|
30
43
|
if (count < contexts.length)
|
|
@@ -51,36 +64,20 @@ function get_contextual_info(info, count) {
|
|
|
51
64
|
};
|
|
52
65
|
}
|
|
53
66
|
/**
|
|
54
|
-
*
|
|
55
|
-
* @returns
|
|
67
|
+
* Get the whole map of AddressInfo objects.
|
|
68
|
+
* @returns shallow copy of the internal map.
|
|
56
69
|
*/
|
|
57
70
|
function get_all() {
|
|
58
|
-
|
|
59
|
-
for (const [key, obj] of Object.entries(memmap)) {
|
|
60
|
-
m.set(key, {
|
|
61
|
-
brief: 'brief' in obj ? obj.brief : undefined,
|
|
62
|
-
ctx: 'ctx' in obj ? obj.ctx : undefined,
|
|
63
|
-
desc: obj.desc,
|
|
64
|
-
label: 'label' in obj ? obj.label : undefined,
|
|
65
|
-
note: 'note' in obj ? obj.note : undefined,
|
|
66
|
-
subctx: 'subctx' in obj ? obj.subctx : undefined,
|
|
67
|
-
type: obj.type
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
return m;
|
|
71
|
+
return new Map(infoMap);
|
|
71
72
|
}
|
|
72
|
-
exports.get_all = get_all;
|
|
73
73
|
/**
|
|
74
74
|
* Get data for one address
|
|
75
75
|
* @param addr address in the range -32767 to 65535
|
|
76
76
|
* @returns AddressInfo object or undefined. Fields may contain logic operators.
|
|
77
77
|
*/
|
|
78
78
|
function get_one(addr) {
|
|
79
|
-
|
|
80
|
-
const hex = '0x' + pos_addr.toString(16).padStart(4, '0');
|
|
81
|
-
return Object(memmap)[hex];
|
|
79
|
+
return infoMap.get(formatHex16(addr));
|
|
82
80
|
}
|
|
83
|
-
exports.get_one = get_one;
|
|
84
81
|
/**
|
|
85
82
|
* Get data for one address and split by context
|
|
86
83
|
* @param addr Array of AddressInfo objects, one for each context, or undefined
|
|
@@ -103,4 +100,48 @@ function get_one_and_split(addr) {
|
|
|
103
100
|
}
|
|
104
101
|
return undefined;
|
|
105
102
|
}
|
|
106
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Get vendor's docstring from the map of entry points
|
|
105
|
+
* @param addr address of the entry point
|
|
106
|
+
* @param ctx optionally restrict the results to a given context
|
|
107
|
+
* @param vendor optionally restrict the results to a specific vendor
|
|
108
|
+
* @returns docstring
|
|
109
|
+
*/
|
|
110
|
+
function get_vendor_docstring(addr, ctx, vendor) {
|
|
111
|
+
const obj = vendorMap.get(formatHex16(addr));
|
|
112
|
+
if (!obj) {
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
if (ctx !== undefined && obj.ctx !== ctx) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
if (vendor !== undefined && obj.vendor !== vendor) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return obj.docstr.join('\n');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get the name of the vendor providing a docstring for the given address
|
|
125
|
+
* @param addr address of the entry point
|
|
126
|
+
* @returns name of vendor providing this docstring
|
|
127
|
+
*/
|
|
128
|
+
function get_vendor_name(addr) {
|
|
129
|
+
const obj = vendorMap.get(formatHex16(addr));
|
|
130
|
+
if (!obj) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
return obj.vendor;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get context of a docstring for the given address
|
|
137
|
+
* @param addr address of the entry point
|
|
138
|
+
* @returns context of this docstring
|
|
139
|
+
*/
|
|
140
|
+
function get_vendor_ctx(addr) {
|
|
141
|
+
const obj = vendorMap.get(formatHex16(addr));
|
|
142
|
+
if (!obj) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
return obj.ctx;
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAuFA,0BAEC;AAOD,0BAEC;AAMD,8CAiBC;AASD,oDAgBC;AAOD,0CAMC;AAOD,wCAMC;AA5KD,0DAA+B;AAC/B,kEAAoC;AAoBpC,SAAS,WAAW,CAAC,IAAY;IAC/B,iGAAiG;IACjG,MAAM,GAAG,GAAG,IAAI,GAAG,MAAM,CAAC;IAC1B,OAAO,KAAK,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;AAClD,CAAC;AAED;;;GAGG;AACH,SAAS,YAAY,CAAmB,OAAgB;IACtD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAa,CAAC;IAEjC,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC5C,OAAO,GAAG,CAAC;IACb,CAAC;IAED,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,SAAS;QACX,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACrE,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,KAAU,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC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