a2-memory-map 1.0.3 → 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 +106 -0
- package/Cargo.toml +19 -0
- package/README-crate.md +84 -0
- package/README.md +25 -9
- package/bindings/rust/lib.rs +278 -0
- 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
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "a2-memory-map"
|
|
7
|
+
version = "1.1.0"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"quote",
|
|
10
|
+
"serde_json",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[[package]]
|
|
14
|
+
name = "itoa"
|
|
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"
|
|
22
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
23
|
+
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
24
|
+
|
|
25
|
+
[[package]]
|
|
26
|
+
name = "proc-macro2"
|
|
27
|
+
version = "1.0.107"
|
|
28
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
29
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
30
|
+
dependencies = [
|
|
31
|
+
"unicode-ident",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[[package]]
|
|
35
|
+
name = "quote"
|
|
36
|
+
version = "1.0.47"
|
|
37
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
38
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
39
|
+
dependencies = [
|
|
40
|
+
"proc-macro2",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[[package]]
|
|
44
|
+
name = "serde"
|
|
45
|
+
version = "1.0.229"
|
|
46
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
47
|
+
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
|
48
|
+
dependencies = [
|
|
49
|
+
"serde_core",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[[package]]
|
|
53
|
+
name = "serde_core"
|
|
54
|
+
version = "1.0.229"
|
|
55
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
+
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
|
57
|
+
dependencies = [
|
|
58
|
+
"serde_derive",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[[package]]
|
|
62
|
+
name = "serde_derive"
|
|
63
|
+
version = "1.0.229"
|
|
64
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
65
|
+
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
|
66
|
+
dependencies = [
|
|
67
|
+
"proc-macro2",
|
|
68
|
+
"quote",
|
|
69
|
+
"syn",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
[[package]]
|
|
73
|
+
name = "serde_json"
|
|
74
|
+
version = "1.0.154"
|
|
75
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
76
|
+
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
|
77
|
+
dependencies = [
|
|
78
|
+
"itoa",
|
|
79
|
+
"memchr",
|
|
80
|
+
"serde",
|
|
81
|
+
"serde_core",
|
|
82
|
+
"zmij",
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
[[package]]
|
|
86
|
+
name = "syn"
|
|
87
|
+
version = "3.0.10"
|
|
88
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
89
|
+
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
|
90
|
+
dependencies = [
|
|
91
|
+
"proc-macro2",
|
|
92
|
+
"quote",
|
|
93
|
+
"unicode-ident",
|
|
94
|
+
]
|
|
95
|
+
|
|
96
|
+
[[package]]
|
|
97
|
+
name = "unicode-ident"
|
|
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"
|
|
105
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
106
|
+
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
package/Cargo.toml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "a2-memory-map"
|
|
3
|
+
description = "Database of Apple II memory addresses"
|
|
4
|
+
version = "1.1.0"
|
|
5
|
+
keywords = ["retro", "apple"]
|
|
6
|
+
categories = []
|
|
7
|
+
repository = "https://github.com/dfgordon/a2-memory-map"
|
|
8
|
+
readme = "README-crate.md"
|
|
9
|
+
edition = "2024"
|
|
10
|
+
rust-version = "1.85"
|
|
11
|
+
build = "build.rs"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
|
|
14
|
+
[lib]
|
|
15
|
+
path = "bindings/rust/lib.rs"
|
|
16
|
+
|
|
17
|
+
[build-dependencies]
|
|
18
|
+
serde_json = "1.0"
|
|
19
|
+
quote = "1.0"
|
package/README-crate.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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 (54). 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.
|
|
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
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|

|
|
4
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.
|
|
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
6
|
|
|
7
|
-
##
|
|
7
|
+
## Map Records
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
The map records correspond to the interface
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
interface AddressInfo {
|
|
@@ -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 `
|
|
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
|
}
|
|
@@ -63,10 +63,26 @@ get_one_and_split(addr: number): Array<AddressInfo> | undefined
|
|
|
63
63
|
|
|
64
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
65
|
|
|
66
|
-
##
|
|
66
|
+
## Docstrings from Vendor Sources
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
Some addresses correspond to entry points where an authentic vendor docstring is available. You can retrieve this docstring using:
|
|
69
69
|
|
|
70
|
-
|
|
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
|
|
71
82
|
|
|
72
|
-
|
|
83
|
+
```ts
|
|
84
|
+
get_vendor_ctx(addr: number): string | undefined
|
|
85
|
+
```
|
|
86
|
+
```ts
|
|
87
|
+
get_vendor_name(addr: number): string | undefined
|
|
88
|
+
```
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
use std::collections::HashMap;
|
|
2
|
+
|
|
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"));
|
|
9
|
+
|
|
10
|
+
#[derive(Clone)]
|
|
11
|
+
pub struct AddressInfo {
|
|
12
|
+
pub brief: Option<String>,
|
|
13
|
+
pub ctx: Option<String>,
|
|
14
|
+
pub desc: String,
|
|
15
|
+
pub label: Option<String>,
|
|
16
|
+
pub note: Option<String>,
|
|
17
|
+
pub subctx: Option<String>,
|
|
18
|
+
pub typ: String
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#[derive(Clone)]
|
|
22
|
+
struct VendorInfo {
|
|
23
|
+
pub ctx: Option<String>,
|
|
24
|
+
pub docstr: String,
|
|
25
|
+
pub vendor: String
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// All interactions are through this object
|
|
29
|
+
pub struct MemoryMap {
|
|
30
|
+
memmap: HashMap<u16,AddressInfo>,
|
|
31
|
+
vendors: HashMap<u16,VendorInfo>
|
|
32
|
+
}
|
|
33
|
+
|
|
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),
|
|
38
|
+
_ => None
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
fn get_contextual_str(str: &String, count: usize) -> String {
|
|
43
|
+
let contexts: Vec<_> = str.split('|').collect();
|
|
44
|
+
if count < contexts.len() {
|
|
45
|
+
contexts[count].trim().to_string()
|
|
46
|
+
} else {
|
|
47
|
+
str.to_string()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
fn get_contextual_str_maybe(maybe_str: &Option<String>, count: usize) -> Option<String> {
|
|
51
|
+
if let Some(str) = maybe_str {
|
|
52
|
+
let contexts: Vec<_> = str.split('|').collect();
|
|
53
|
+
if count < contexts.len() {
|
|
54
|
+
return Some(contexts[count].trim().to_string());
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
None
|
|
58
|
+
}
|
|
59
|
+
fn get_contextual_info(info: &AddressInfo, count: usize) -> AddressInfo {
|
|
60
|
+
AddressInfo {
|
|
61
|
+
brief: get_contextual_str_maybe(&info.brief,count),
|
|
62
|
+
ctx: get_contextual_str_maybe(&info.ctx,count),
|
|
63
|
+
desc: get_contextual_str(&info.desc,count),
|
|
64
|
+
subctx: get_contextual_str_maybe(&info.subctx,count),
|
|
65
|
+
label: get_contextual_str_maybe(&info.label,count),
|
|
66
|
+
note: get_contextual_str_maybe(&info.note,count),
|
|
67
|
+
typ: get_contextual_str(&info.typ,count)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
impl MemoryMap {
|
|
72
|
+
pub fn new() -> Self {
|
|
73
|
+
Self {
|
|
74
|
+
memmap: load_map(),
|
|
75
|
+
vendors: load_vendors()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/// Borrow the underlying address information HashMap
|
|
79
|
+
pub fn get_all(&self) -> &HashMap<u16,AddressInfo> {
|
|
80
|
+
&self.memmap
|
|
81
|
+
}
|
|
82
|
+
/// Get data for one address.
|
|
83
|
+
/// @param addr address in the range -32767 to 65535
|
|
84
|
+
pub fn get_one(&self,addr: i64) -> Option<AddressInfo> {
|
|
85
|
+
let Some(addr16) = normalize_addr(addr) else {
|
|
86
|
+
return None;
|
|
87
|
+
};
|
|
88
|
+
self.memmap.get(&(addr16)).cloned()
|
|
89
|
+
}
|
|
90
|
+
/// Get data for one address and split by context
|
|
91
|
+
/// @param addr Array of AddressInfo objects, one for each context, or undefined
|
|
92
|
+
pub fn get_one_and_split(&self,addr: i64) -> Option<Vec<AddressInfo>> {
|
|
93
|
+
if let Some(obj) = self.get_one(addr) {
|
|
94
|
+
let mut ans = Vec::new();
|
|
95
|
+
let num = match &obj.ctx {
|
|
96
|
+
Some(ctx) => ctx.split('|').collect::<Vec<_>>().len(),
|
|
97
|
+
None => 1
|
|
98
|
+
};
|
|
99
|
+
// if one context do not split anything
|
|
100
|
+
if num == 1 {
|
|
101
|
+
ans.push(obj);
|
|
102
|
+
return Some(ans);
|
|
103
|
+
}
|
|
104
|
+
// if multi-context, split all fields on `|`
|
|
105
|
+
for count in 0..num {
|
|
106
|
+
ans.push(get_contextual_info(&obj, count));
|
|
107
|
+
}
|
|
108
|
+
return Some(ans);
|
|
109
|
+
}
|
|
110
|
+
None
|
|
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
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
#[test]
|
|
168
|
+
fn get_cout() {
|
|
169
|
+
let mem_map = MemoryMap::new();
|
|
170
|
+
let cout = mem_map.get_one(0xfded);
|
|
171
|
+
assert!(cout.unwrap().label==Some("COUT".to_string()));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
#[test]
|
|
175
|
+
fn applesoft_integer() {
|
|
176
|
+
let mem_map = MemoryMap::new();
|
|
177
|
+
let addr = 0xf8;
|
|
178
|
+
match mem_map.get_one_and_split(addr) {
|
|
179
|
+
Some(info_list) => {
|
|
180
|
+
assert_eq!(info_list.len(),2);
|
|
181
|
+
assert_eq!(info_list[0].ctx,Some("Applesoft".to_string()));
|
|
182
|
+
assert_eq!(info_list[1].ctx,Some("Integer BASIC".to_string()));
|
|
183
|
+
assert_eq!(info_list[0].typ,"byte value".to_string());
|
|
184
|
+
assert_eq!(info_list[1].typ,"float32".to_string());
|
|
185
|
+
assert_eq!(info_list[0].label,Some("REMSTK".to_string()));
|
|
186
|
+
assert_eq!(info_list[1].label,Some("FP1".to_string()));
|
|
187
|
+
},
|
|
188
|
+
None => panic!("address not found")
|
|
189
|
+
}
|
|
190
|
+
let addr = 0xdc;
|
|
191
|
+
match mem_map.get_one_and_split(addr) {
|
|
192
|
+
Some(info_list) => {
|
|
193
|
+
assert_eq!(info_list.len(),2);
|
|
194
|
+
assert_eq!(info_list[0].ctx,Some("Applesoft".to_string()));
|
|
195
|
+
assert_eq!(info_list[1].ctx,Some("Integer BASIC".to_string()));
|
|
196
|
+
assert_eq!(info_list[0].typ,"word".to_string());
|
|
197
|
+
assert_eq!(info_list[1].typ,"word".to_string());
|
|
198
|
+
assert_eq!(info_list[0].label,Some("ERRPOS".to_string()));
|
|
199
|
+
assert_eq!(info_list[1].label,Some("CURLIN".to_string()));
|
|
200
|
+
},
|
|
201
|
+
None => panic!("address not found")
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
#[test]
|
|
206
|
+
fn no_split() {
|
|
207
|
+
let mem_map = MemoryMap::new();
|
|
208
|
+
let addr = 0xff70;
|
|
209
|
+
match mem_map.get_one_and_split(addr) {
|
|
210
|
+
Some(info_list) => {
|
|
211
|
+
assert_eq!(info_list.len(),1);
|
|
212
|
+
assert_eq!(info_list[0].typ,"ROM routine".to_string());
|
|
213
|
+
},
|
|
214
|
+
None => panic!("address not found")
|
|
215
|
+
}
|
|
216
|
+
let addr = 0xe597;
|
|
217
|
+
match mem_map.get_one_and_split(addr) {
|
|
218
|
+
Some(info_list) => {
|
|
219
|
+
assert_eq!(info_list.len(),1);
|
|
220
|
+
assert_eq!(info_list[0].typ,"ROM routine".to_string());
|
|
221
|
+
assert_eq!(info_list[0].subctx,Some("parsing & string".to_string()));
|
|
222
|
+
},
|
|
223
|
+
None => panic!("address not found")
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
#[test]
|
|
228
|
+
fn splits_but_one_ctx() {
|
|
229
|
+
let mem_map = MemoryMap::new();
|
|
230
|
+
let addr = 0xc080;
|
|
231
|
+
match mem_map.get_one_and_split(addr) {
|
|
232
|
+
Some(info_list) => {
|
|
233
|
+
assert_eq!(info_list.len(),1);
|
|
234
|
+
assert_eq!(info_list[0].brief,Some("RDRAM | stepper 0".to_string()));
|
|
235
|
+
},
|
|
236
|
+
None => panic!("address not found")
|
|
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()));
|
|
278
|
+
}
|