kimdos 0.2.0__tar.gz

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.
Files changed (43) hide show
  1. kimdos-0.2.0/LICENSE +201 -0
  2. kimdos-0.2.0/PKG-INFO +98 -0
  3. kimdos-0.2.0/README.md +76 -0
  4. kimdos-0.2.0/pyproject.toml +57 -0
  5. kimdos-0.2.0/setup.cfg +4 -0
  6. kimdos-0.2.0/src/kimdos/__init__.py +1 -0
  7. kimdos-0.2.0/src/kimdos/bench.py +97 -0
  8. kimdos-0.2.0/src/kimdos/board.py +58 -0
  9. kimdos-0.2.0/src/kimdos/build.py +75 -0
  10. kimdos-0.2.0/src/kimdos/c/Dockerfile +1 -0
  11. kimdos-0.2.0/src/kimdos/c/include/kimdos.h +86 -0
  12. kimdos-0.2.0/src/kimdos/c/kim1/crt.s +8 -0
  13. kimdos-0.2.0/src/kimdos/c/kim1/link.ld +25 -0
  14. kimdos-0.2.0/src/kimdos/c/src/con.s +36 -0
  15. kimdos-0.2.0/src/kimdos/c/src/dir.c +43 -0
  16. kimdos-0.2.0/src/kimdos/c/src/dos.c +150 -0
  17. kimdos-0.2.0/src/kimdos/c/src/iec.s +573 -0
  18. kimdos-0.2.0/src/kimdos/c/src/kdint.h +9 -0
  19. kimdos-0.2.0/src/kimdos/cli.py +111 -0
  20. kimdos-0.2.0/src/kimdos/clib.py +21 -0
  21. kimdos-0.2.0/src/kimdos/host.py +298 -0
  22. kimdos-0.2.0/src/kimdos/iec.py +786 -0
  23. kimdos-0.2.0/src/kimdos/images/kimdos-0400.bin +0 -0
  24. kimdos-0.2.0/src/kimdos/images/kimdos-0400.lbl +211 -0
  25. kimdos-0.2.0/src/kimdos/images/kimdos-0400.ptp +128 -0
  26. kimdos-0.2.0/src/kimdos/images/kimdos-2000.bin +0 -0
  27. kimdos-0.2.0/src/kimdos/images/kimdos-2000.lbl +211 -0
  28. kimdos-0.2.0/src/kimdos/images/kimdos-2000.ptp +128 -0
  29. kimdos-0.2.0/src/kimdos/images/kimdos-C000.bin +0 -0
  30. kimdos-0.2.0/src/kimdos/images/kimdos-C000.lbl +211 -0
  31. kimdos-0.2.0/src/kimdos/images/kimdos-C000.ptp +128 -0
  32. kimdos-0.2.0/src/kimdos/sim.py +252 -0
  33. kimdos-0.2.0/src/kimdos.egg-info/PKG-INFO +98 -0
  34. kimdos-0.2.0/src/kimdos.egg-info/SOURCES.txt +41 -0
  35. kimdos-0.2.0/src/kimdos.egg-info/dependency_links.txt +1 -0
  36. kimdos-0.2.0/src/kimdos.egg-info/entry_points.txt +2 -0
  37. kimdos-0.2.0/src/kimdos.egg-info/requires.txt +10 -0
  38. kimdos-0.2.0/src/kimdos.egg-info/top_level.txt +1 -0
  39. kimdos-0.2.0/tests/test_cli.py +35 -0
  40. kimdos-0.2.0/tests/test_clib.py +144 -0
  41. kimdos-0.2.0/tests/test_jiffy.py +206 -0
  42. kimdos-0.2.0/tests/test_kimdos.py +312 -0
  43. kimdos-0.2.0/tests/test_sim.py +400 -0
kimdos-0.2.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
kimdos-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.4
2
+ Name: kimdos
3
+ Version: 0.2.0
4
+ Summary: Commodore serial bus disk library and shell for the KIM-1 and its replicas
5
+ Author: anarkiwi
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/anarkiwi/kimdos
8
+ Keywords: kim-1,6502,iec,1541,sd2iec,pal-ii,retrocomputing
9
+ Requires-Python: >=3.11
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: kimtape>=0.1.1
13
+ Requires-Dist: py65
14
+ Requires-Dist: tqdm
15
+ Provides-Extra: dev
16
+ Requires-Dist: black; extra == "dev"
17
+ Requires-Dist: pylint; extra == "dev"
18
+ Requires-Dist: pytest; extra == "dev"
19
+ Requires-Dist: pytest-cov; extra == "dev"
20
+ Requires-Dist: pytest-xdist; extra == "dev"
21
+ Dynamic: license-file
22
+
23
+ # kimdos
24
+
25
+ Commodore serial bus (IEC) disk access for the KIM-1, PAL-1/PAL-II and other
26
+ replicas: a 6502 library, and a shell built on it, that load and save CBM DOS
27
+ files on a 1541, an SD2IEC/uIEC or anything else that speaks the bus, with
28
+ JiffyDOS for devices that have it. Written from the protocol, not from
29
+ Commodore's code.
30
+
31
+ The library uses no zero page, preserves the user port's spare bits, and links
32
+ anywhere with ld65; an llvm-mos C version comes with a KIM-1 platform for that
33
+ compiler. The shell runs over the monitor's TTY:
34
+
35
+ ```
36
+ KIMDOS
37
+ >S PROG,2000,290D
38
+ 00, OK,00,00
39
+ >L PROG,4000
40
+ $4000-$490D
41
+ >$
42
+ 1 " " 32 2A
43
+ 10 "PROG" PRG
44
+ 65535 BLOCKS FREE.
45
+ >S PROG,2000,2001
46
+ 63,FILE EXISTS,00,00
47
+ ```
48
+
49
+ ## Install
50
+
51
+ ```sh
52
+ pip install kimdos
53
+ kimtape load --port /dev/ttyUSB0 https://github.com/anarkiwi/kimdos/releases/latest/download/kimdos-2000.ptp --go 2000
54
+ ```
55
+
56
+ Each release has the shell at $0400, $2000 and $C000 (`kimdos-<org>.ptp`,
57
+ `.bin`, `.lbl`), also in the package (`kimdos.build.packaged`); it needs
58
+ about 2.5K of RAM there. The package ships the llvm-mos C library:
59
+ `python -m kimdos.clib` prints its directory.
60
+
61
+ To build, with cc65: `make ORG=2000` writes `build/kimdos-2000.{bin,ptp,lbl,map}`
62
+ and `build/kimdos.lib`; `make clib` builds `build/c/libkimdos.a` with llvm-mos
63
+ in docker.
64
+
65
+ ## Shell
66
+
67
+ | Command | |
68
+ | --- | --- |
69
+ | `$[pattern]` | directory, e.g. `$`, `$0:A*` |
70
+ | `@` | drive status |
71
+ | `@command` | DOS command, e.g. `@S:OLD`, `@R:NEW=OLD`, `@CD:GAMES` |
72
+ | `L name[,addr]` | load, to the file's own address or to `addr` |
73
+ | `V name[,addr]` | verify against memory |
74
+ | `S name,start,end` | save `start`-`end` inclusive; `@0:name` replaces |
75
+ | `#[device]` | show or set the device number (decimal, default 8) |
76
+ | `J[0\|1]` | show, or turn off or on, JiffyDOS (default on) |
77
+ | `Q` | return to the monitor; `G` then runs what was loaded |
78
+
79
+ Names may be quoted. From the keypad, put the KIM tape ID in $17F9 and run
80
+ `ORG+3` to load the file named by its two hex digits, or set $17F5-$17F8 as
81
+ for a tape save and run `ORG+6` to save.
82
+
83
+ ## Simulator
84
+
85
+ ```sh
86
+ kimdos sim --dir ./disk # the shell against .prg files in ./disk
87
+ kimdos sim --no-jiffy # against a drive without JiffyDOS
88
+ kimdos bench # cycles per byte and JiffyDOS margins
89
+ kimdos board --port /dev/ttyUSB0 --install '$' '@'
90
+ ```
91
+
92
+ ## Documentation
93
+
94
+ - [docs/hardware.md](docs/hardware.md) — the adapter and its wiring
95
+ - [docs/library.md](docs/library.md) — linking the library into a program, the API
96
+ - [docs/clibrary.md](docs/clibrary.md) — the llvm-mos C library and KIM-1 platform
97
+ - [docs/protocol.md](docs/protocol.md) — the bus protocol as implemented
98
+ - [docs/development.md](docs/development.md) — tests, the simulator, releases
kimdos-0.2.0/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # kimdos
2
+
3
+ Commodore serial bus (IEC) disk access for the KIM-1, PAL-1/PAL-II and other
4
+ replicas: a 6502 library, and a shell built on it, that load and save CBM DOS
5
+ files on a 1541, an SD2IEC/uIEC or anything else that speaks the bus, with
6
+ JiffyDOS for devices that have it. Written from the protocol, not from
7
+ Commodore's code.
8
+
9
+ The library uses no zero page, preserves the user port's spare bits, and links
10
+ anywhere with ld65; an llvm-mos C version comes with a KIM-1 platform for that
11
+ compiler. The shell runs over the monitor's TTY:
12
+
13
+ ```
14
+ KIMDOS
15
+ >S PROG,2000,290D
16
+ 00, OK,00,00
17
+ >L PROG,4000
18
+ $4000-$490D
19
+ >$
20
+ 1 " " 32 2A
21
+ 10 "PROG" PRG
22
+ 65535 BLOCKS FREE.
23
+ >S PROG,2000,2001
24
+ 63,FILE EXISTS,00,00
25
+ ```
26
+
27
+ ## Install
28
+
29
+ ```sh
30
+ pip install kimdos
31
+ kimtape load --port /dev/ttyUSB0 https://github.com/anarkiwi/kimdos/releases/latest/download/kimdos-2000.ptp --go 2000
32
+ ```
33
+
34
+ Each release has the shell at $0400, $2000 and $C000 (`kimdos-<org>.ptp`,
35
+ `.bin`, `.lbl`), also in the package (`kimdos.build.packaged`); it needs
36
+ about 2.5K of RAM there. The package ships the llvm-mos C library:
37
+ `python -m kimdos.clib` prints its directory.
38
+
39
+ To build, with cc65: `make ORG=2000` writes `build/kimdos-2000.{bin,ptp,lbl,map}`
40
+ and `build/kimdos.lib`; `make clib` builds `build/c/libkimdos.a` with llvm-mos
41
+ in docker.
42
+
43
+ ## Shell
44
+
45
+ | Command | |
46
+ | --- | --- |
47
+ | `$[pattern]` | directory, e.g. `$`, `$0:A*` |
48
+ | `@` | drive status |
49
+ | `@command` | DOS command, e.g. `@S:OLD`, `@R:NEW=OLD`, `@CD:GAMES` |
50
+ | `L name[,addr]` | load, to the file's own address or to `addr` |
51
+ | `V name[,addr]` | verify against memory |
52
+ | `S name,start,end` | save `start`-`end` inclusive; `@0:name` replaces |
53
+ | `#[device]` | show or set the device number (decimal, default 8) |
54
+ | `J[0\|1]` | show, or turn off or on, JiffyDOS (default on) |
55
+ | `Q` | return to the monitor; `G` then runs what was loaded |
56
+
57
+ Names may be quoted. From the keypad, put the KIM tape ID in $17F9 and run
58
+ `ORG+3` to load the file named by its two hex digits, or set $17F5-$17F8 as
59
+ for a tape save and run `ORG+6` to save.
60
+
61
+ ## Simulator
62
+
63
+ ```sh
64
+ kimdos sim --dir ./disk # the shell against .prg files in ./disk
65
+ kimdos sim --no-jiffy # against a drive without JiffyDOS
66
+ kimdos bench # cycles per byte and JiffyDOS margins
67
+ kimdos board --port /dev/ttyUSB0 --install '$' '@'
68
+ ```
69
+
70
+ ## Documentation
71
+
72
+ - [docs/hardware.md](docs/hardware.md) — the adapter and its wiring
73
+ - [docs/library.md](docs/library.md) — linking the library into a program, the API
74
+ - [docs/clibrary.md](docs/clibrary.md) — the llvm-mos C library and KIM-1 platform
75
+ - [docs/protocol.md](docs/protocol.md) — the bus protocol as implemented
76
+ - [docs/development.md](docs/development.md) — tests, the simulator, releases
@@ -0,0 +1,57 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "kimdos"
7
+ version = "0.2.0"
8
+ description = "Commodore serial bus disk library and shell for the KIM-1 and its replicas"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.11"
12
+ authors = [{ name = "anarkiwi" }]
13
+ keywords = ["kim-1", "6502", "iec", "1541", "sd2iec", "pal-ii", "retrocomputing"]
14
+ dependencies = [
15
+ "kimtape>=0.1.1",
16
+ "py65",
17
+ "tqdm",
18
+ ]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/anarkiwi/kimdos"
22
+
23
+ [project.scripts]
24
+ kimdos = "kimdos.cli:main"
25
+
26
+ [project.optional-dependencies]
27
+ dev = ["black", "pylint", "pytest", "pytest-cov", "pytest-xdist"]
28
+
29
+ [tool.setuptools.packages.find]
30
+ where = ["src"]
31
+
32
+ [tool.setuptools.package-data]
33
+ kimdos = ["c/Dockerfile", "c/include/*.h", "c/src/*", "c/kim1/*", "images/*"]
34
+
35
+ [tool.pytest.ini_options]
36
+ addopts = "-n auto --cov=kimdos --cov-report=term-missing --cov-fail-under=85"
37
+ testpaths = ["tests"]
38
+
39
+ [tool.coverage.run]
40
+ # needs a board on a serial line
41
+ omit = ["*/board.py"]
42
+
43
+ [tool.black]
44
+ line-length = 88
45
+ target-version = ["py311"]
46
+
47
+ [tool.pylint.main]
48
+ source-roots = ["src"]
49
+
50
+ [tool.pylint.format]
51
+ max-line-length = 88
52
+
53
+ [tool.pylint."messages control"]
54
+ disable = ["consider-using-f-string"]
55
+
56
+ [tool.pylint.basic]
57
+ no-docstring-rgx = "^(test_|_)"
kimdos-0.2.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ """KIM-1 DOS test oracle: serial bus drive model and KIM-1 machine simulator."""
@@ -0,0 +1,97 @@
1
+ """Throughput and JiffyDOS timing margins of the 6502 library, simulated."""
2
+
3
+ from tqdm import tqdm
4
+
5
+ from .iec import JIFFY_AVR_EARLY, JIFFY_AVR_LATE, JIFFY_LPC, Drive
6
+ from .sim import RETURN, Kim
7
+
8
+ TIMINGS = {"lpc": JIFFY_LPC, "avr-early": JIFFY_AVR_EARLY, "avr-late": JIFFY_AVR_LATE}
9
+ BUF = 0x4000
10
+ NAME = 0x3F00
11
+ SIZES = (1016, 2032)
12
+ OPS = ("read", "write", "load")
13
+
14
+
15
+ def _kim(image, files, **kw):
16
+ kim = Kim(image.binary, image.org, drives=Drive(files=files, **kw))
17
+ return kim, kim.drive
18
+
19
+
20
+ def _call(kim, image, name, **kw):
21
+ r = kim.call(image[name], max_cycles=100_000_000, **kw)
22
+ assert r.reason == RETURN, name
23
+ return r
24
+
25
+
26
+ def _setnam(kim, image, name):
27
+ kim.write(NAME, name)
28
+ _call(kim, image, "dos_setnam", a=len(name), x=NAME & 0xFF, y=NAME >> 8)
29
+
30
+
31
+ def _range(kim, image, beg, end):
32
+ kim.write(image["dos_beg"], beg.to_bytes(2, "little") + end.to_bytes(2, "little"))
33
+
34
+
35
+ def op_cycles(image, op, n, **kw):
36
+ """CPU cycles for one library operation moving n bytes: dos_read of an
37
+ open file, dos_write to one, or a whole dos_load (open, transfer, close)."""
38
+ data = bytes(i * 7 & 0xFF for i in range(n))
39
+ kim, drive = _kim(image, {b"F": b"\x00\x40" + data}, **kw)
40
+ if op == "load":
41
+ _setnam(kim, image, b"F")
42
+ c = _call(kim, image, "dos_load").cycles
43
+ assert kim.read(BUF, n) == data
44
+ else:
45
+ _setnam(kim, image, b"F" if op == "read" else b"G,S,W")
46
+ _call(kim, image, "dos_open", a=2)
47
+ if op == "write":
48
+ kim.write(BUF, data)
49
+ _range(kim, image, BUF, BUF + n + 2 if op == "read" else BUF + n)
50
+ c = _call(kim, image, "dos_" + op, a=2).cycles
51
+ _call(kim, image, "dos_close", a=2)
52
+ got = kim.read(BUF, n + 2)[2:] if op == "read" else drive.files[b"G"]
53
+ assert got == data, op
54
+ assert not drive.errors, drive.errors
55
+ return c
56
+
57
+
58
+ def per_byte(image, op, **kw):
59
+ """Cycles per byte of op, fixed costs cancelled over two sizes."""
60
+ lo, hi = (op_cycles(image, op, n, **kw) for n in SIZES)
61
+ return (hi - lo) / (SIZES[1] - SIZES[0])
62
+
63
+
64
+ def margin_ok(image, margin, **kw):
65
+ """Whether a load, a save and a status read stay margin us clear of
66
+ every device edge and sample point."""
67
+ data = bytes(range(256)) * 2
68
+ kim, drive = _kim(image, {b"F": b"\x00\x40" + data}, margin=margin, **kw)
69
+ _setnam(kim, image, b"F")
70
+ _call(kim, image, "dos_load")
71
+ _setnam(kim, image, b"G")
72
+ _range(kim, image, BUF, BUF + len(data))
73
+ _call(kim, image, "dos_save")
74
+ _call(kim, image, "dos_status")
75
+ return not drive.errors and drive.files.get(b"G", b"")[2:] == data
76
+
77
+
78
+ def max_margin(image, step=0.25, **kw):
79
+ """Largest margin, in steps of step us, at which margin_ok holds."""
80
+ m = 0
81
+ while margin_ok(image, m + step, **kw):
82
+ m += step
83
+ return m
84
+
85
+
86
+ def report(image, latencies=(0, 1, 2)):
87
+ """Throughput rows (op, standard, Jiffy) and margin rows (timing,
88
+ latency, margin), with progress bars."""
89
+ rows = []
90
+ for op in tqdm(OPS, desc="throughput"):
91
+ rows.append((op, per_byte(image, op, jiffy=None), per_byte(image, op)))
92
+ cases = [(t, lat) for t in TIMINGS for lat in latencies]
93
+ margins = [
94
+ (t, lat, max_margin(image, jiffy=TIMINGS[t], latency=lat))
95
+ for t, lat in tqdm(cases, desc="margins")
96
+ ]
97
+ return rows, margins
@@ -0,0 +1,58 @@
1
+ """Drive the KIMDOS shell on a real board over its TTY line."""
2
+
3
+ import re
4
+ import sys
5
+ import time
6
+
7
+ from kimtape import Monitor, Port, Tape
8
+
9
+ PROMPT = b"\r\n>"
10
+
11
+
12
+ class Board:
13
+ """A KIM-1 running the KIMDOS shell, reached through the monitor."""
14
+
15
+ def __init__(self, dev, baud=1200, trace=False):
16
+ self.port = Port(dev, baud, trace=trace)
17
+ self.mon = Monitor(self.port, log=sys.stderr)
18
+
19
+ def install(self, ptp, org):
20
+ """Load a tape image with the monitor, verify it and start the shell."""
21
+ self.mon.sync()
22
+ tape = Tape("kimdos", ptp)
23
+ for _ in range(3):
24
+ self.mon.load(tape)
25
+ if self.mon.verify(tape):
26
+ break
27
+ else:
28
+ raise RuntimeError("image did not verify")
29
+ self.start(org)
30
+
31
+ def start(self, org):
32
+ """Run the shell at org and wait for its prompt."""
33
+ self.mon.sync()
34
+ self.port.take()
35
+ self.mon.go(org)
36
+ self.wait_prompt(10)
37
+
38
+ def wait_prompt(self, timeout):
39
+ """Collect output up to the next shell prompt."""
40
+ deadline = time.time() + timeout
41
+ while PROMPT not in self.port.rx and time.time() < deadline:
42
+ self.port.poll(0.1)
43
+ if PROMPT not in self.port.rx:
44
+ raise TimeoutError(Port.show(bytes(self.port.rx)))
45
+ out = bytes(self.port.rx)
46
+ self.port.take()
47
+ return out[: out.index(PROMPT)]
48
+
49
+ def command(self, line, timeout=60):
50
+ """Type a shell command and return its output without the echo."""
51
+ self.port.take()
52
+ self.port.write(line.encode() + b"\r")
53
+ out = self.wait_prompt(timeout).decode("ascii", "replace")
54
+ return re.sub(r"^.*?\r\n", "", out, count=1, flags=re.S).strip("\r\n")
55
+
56
+ def close(self):
57
+ """Release the serial line."""
58
+ self.port.close()
@@ -0,0 +1,75 @@
1
+ """Build the 6502 image with cc65 and read back its symbols."""
2
+
3
+ import fcntl
4
+ import subprocess
5
+ from dataclasses import dataclass
6
+ from pathlib import Path
7
+
8
+ ROOT = Path(__file__).resolve().parents[2]
9
+ IMAGES = Path(__file__).resolve().parent / "images"
10
+
11
+
12
+ @dataclass(frozen=True)
13
+ class Image:
14
+ """A linked KIMDOS image: binary, tape, load address and symbol table."""
15
+
16
+ binary: bytes
17
+ ptp: Path
18
+ labels: dict
19
+ org: int
20
+
21
+ @classmethod
22
+ def load(cls, stem):
23
+ """Read the .bin, .ptp and .lbl files an ld65 build left at stem."""
24
+ stem = Path(stem)
25
+ labels = read_labels(stem.with_suffix(".lbl"))
26
+ return cls(
27
+ stem.with_suffix(".bin").read_bytes(),
28
+ stem.with_suffix(".ptp"),
29
+ labels,
30
+ labels["__RAM_START__"],
31
+ )
32
+
33
+ def __getitem__(self, name):
34
+ return self.labels[name]
35
+
36
+
37
+ def read_labels(path):
38
+ """Parse an ld65 -Ln (VICE) label file into {name: address}."""
39
+ labels = {}
40
+ for line in Path(path).read_text(encoding="ascii").splitlines():
41
+ _, addr, name = line.split()
42
+ labels[name.lstrip(".")] = int(addr, 16)
43
+ return labels
44
+
45
+
46
+ def _make(build_dir, *args):
47
+ build_dir.mkdir(parents=True, exist_ok=True)
48
+ with open(build_dir / ".lock", "w", encoding="ascii") as lock:
49
+ fcntl.flock(lock, fcntl.LOCK_EX)
50
+ subprocess.run(
51
+ ["make", "-s", "-C", str(ROOT), "BUILD=%s" % build_dir, *args],
52
+ check=True,
53
+ stdout=subprocess.DEVNULL,
54
+ )
55
+
56
+
57
+ def build_c():
58
+ """Build the C library and its test program (llvm-mos in docker) under the
59
+ repository's build directory, which docker can mount; return kdtest.bin."""
60
+ build_dir = ROOT / "build"
61
+ _make(build_dir, "clib")
62
+ return (build_dir / "c" / "kdtest.bin").read_bytes()
63
+
64
+
65
+ def build(org=0x2000, build_dir=None):
66
+ """Run make for an image at org and return it."""
67
+ build_dir = Path(build_dir or ROOT / "build")
68
+ _make(build_dir, "ORG=%04X" % org)
69
+ return Image.load(build_dir / ("kimdos-%04X" % org))
70
+
71
+
72
+ def packaged(org=0x2000):
73
+ """The prebuilt shell image at org shipped in the wheel ($0400, $2000,
74
+ $C000; `make images` in a checkout)."""
75
+ return Image.load(IMAGES / ("kimdos-%04X" % org))
@@ -0,0 +1 @@
1
+ FROM ghcr.io/anarkiwi/docker-mos-llvm-sdk:23.3.0