jsbeeb 1.1.1
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/.editorconfig +15 -0
- package/.git-blame-ignore-revs +3 -0
- package/.github/copilot-instructions.md +94 -0
- package/.github/workflows/claude-issue-triage.yml +105 -0
- package/.github/workflows/claude.yml +63 -0
- package/.github/workflows/release-please.yml +75 -0
- package/.github/workflows/test-and-deploy.yml +86 -0
- package/.gitmodules +6 -0
- package/.husky/pre-commit +1 -0
- package/.idea/codeStyleSettings.xml +9 -0
- package/.idea/codeStyles/Project.xml +62 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/compiler.xml +22 -0
- package/.idea/copyright/profiles_settings.xml +3 -0
- package/.idea/encodings.xml +6 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/jsLibraryMappings.xml +6 -0
- package/.idea/jsLinters/jshint.xml +85 -0
- package/.idea/jsLinters/jslint.xml +15 -0
- package/.idea/jsbeeb.iml +11 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +7 -0
- package/.idea/runConfigurations/Debug.xml +5 -0
- package/.idea/scopes/scope_settings.xml +5 -0
- package/.idea/vcs.xml +8 -0
- package/.prettierignore +4 -0
- package/.prettierrc.json +1 -0
- package/.release-please-manifest.json +3 -0
- package/.vscode/launch.json +14 -0
- package/.vscode/settings.json +6 -0
- package/CHANGELOG.md +32 -0
- package/CLAUDE.md +136 -0
- package/COPYING +674 -0
- package/Dockerfile +22 -0
- package/Makefile +30 -0
- package/README.md +259 -0
- package/docker/nginx-default.conf +10 -0
- package/docs/pal-comb-filter-research.md +129 -0
- package/docs/pal-simulation-design.md +368 -0
- package/eslint.config.js +35 -0
- package/index.html +954 -0
- package/jsconfig.json +10 -0
- package/package.json +102 -0
- package/public/discs/README.Irq-Timing +3 -0
- package/public/discs/README.bcdtest +5 -0
- package/public/discs/README.elite +6 -0
- package/public/discs/README.eng_test +3 -0
- package/public/discs/README.protection +7 -0
- package/public/favicon.ico +0 -0
- package/public/images/botbar.png +0 -0
- package/public/images/cub-monitor.png +0 -0
- package/public/images/jsbeeb-example.png +0 -0
- package/public/images/placeholder.png +0 -0
- package/public/images/red-off-16.png +0 -0
- package/public/images/red-on-16.png +0 -0
- package/public/images/sb/CD-left.jpg +0 -0
- package/public/images/sb/CD-right.jpg +0 -0
- package/public/images/sidebar.png +0 -0
- package/public/images/tv.png +0 -0
- package/public/images/yellow-off-16.png +0 -0
- package/public/images/yellow-on-16.png +0 -0
- package/public/jsbeeb-icon.png +0 -0
- package/public/robots.txt +3 -0
- package/public/roms/ADFS1-53.rom +0 -0
- package/public/roms/BASIC.ROM +0 -0
- package/public/roms/README +4 -0
- package/public/roms/a01/BASIC1.rom +0 -0
- package/public/roms/ample.rom +0 -0
- package/public/roms/ats-3.0.rom +0 -0
- package/public/roms/b/DFS-0.9.rom +0 -0
- package/public/roms/b/DFS-1.2.rom +0 -0
- package/public/roms/b1770/dfs1770.rom +0 -0
- package/public/roms/b1770/zADFS.ROM +0 -0
- package/public/roms/bp/dfs.rom +0 -0
- package/public/roms/bp/zADFS.ROM +0 -0
- package/public/roms/bpos.rom +0 -0
- package/public/roms/compact/adfs210.rom +0 -0
- package/public/roms/compact/basic48.rom +0 -0
- package/public/roms/compact/basic486.rom +0 -0
- package/public/roms/compact/os51.rom +0 -0
- package/public/roms/compact/utils.rom +0 -0
- package/public/roms/deos.rom +0 -0
- package/public/roms/master/anfs-4.25.rom +0 -0
- package/public/roms/master/mos.txt +68819 -0
- package/public/roms/master/mos3.20 +0 -0
- package/public/roms/os.rom +0 -0
- package/public/roms/os01.rom +0 -0
- package/public/roms/tube/6502Tube.rom +0 -0
- package/public/roms/tube/ARMeval_100.rom +0 -0
- package/public/roms/tube/BIOS.ROM +0 -0
- package/public/roms/tube/ReCo6502ROM_816 +0 -0
- package/public/roms/tube/Z80_120.rom +0 -0
- package/public/roms/us/USBASIC.rom +0 -0
- package/public/roms/us/USDNFS.rom +0 -0
- package/public/roms/usmos.rom +0 -0
- package/public/sounds/disc525/motor.wav +0 -0
- package/public/sounds/disc525/motoroff.wav +0 -0
- package/public/sounds/disc525/motoron.wav +0 -0
- package/public/sounds/disc525/seek.wav +0 -0
- package/public/sounds/disc525/seek2.wav +0 -0
- package/public/sounds/disc525/seek3.wav +0 -0
- package/public/sounds/disc525/step.wav +0 -0
- package/public/teletext/txt0.dat +0 -0
- package/public/teletext/txt1.dat +0 -0
- package/public/teletext/txt2.dat +0 -0
- package/public/teletext/txt3.dat +0 -0
- package/release-please-config.json +13 -0
- package/run-container.sh +92 -0
- package/src/6502.js +1347 -0
- package/src/6502.opcodes.js +1411 -0
- package/src/acia.js +261 -0
- package/src/adc.js +149 -0
- package/src/analogue-source.js +21 -0
- package/src/app/app.js +175 -0
- package/src/app/electron.js +20 -0
- package/src/app/preload.js +8 -0
- package/src/app-bench.js +33 -0
- package/src/basic/multiline-tetris +9 -0
- package/src/basic-tokenise.js +104 -0
- package/src/canvas.js +177 -0
- package/src/cmos.js +141 -0
- package/src/config.js +165 -0
- package/src/ddnoise.js +138 -0
- package/src/disc-drive.js +371 -0
- package/src/disc-hfe.js +396 -0
- package/src/disc.js +997 -0
- package/src/econet/L3FS.dat +0 -0
- package/src/econet/scsi.dat +0 -0
- package/src/econet.js +714 -0
- package/src/fake6502.js +32 -0
- package/src/fdc.js +248 -0
- package/src/filestore.js +666 -0
- package/src/gamepad-source.js +59 -0
- package/src/gamepads.js +268 -0
- package/src/google-drive.js +160 -0
- package/src/intel-fdc.js +1717 -0
- package/src/jsbeeb.css +363 -0
- package/src/keyboard.js +411 -0
- package/src/lib/README +1 -0
- package/src/lib/webgl-debug.js +911 -0
- package/src/main.js +1759 -0
- package/src/microphone-input.js +149 -0
- package/src/models.js +200 -0
- package/src/mouse-joystick-source.js +107 -0
- package/src/music5000-worklet.js +43 -0
- package/src/music5000.js +207 -0
- package/src/scheduler.js +148 -0
- package/src/serial.js +31 -0
- package/src/soundchip.js +314 -0
- package/src/sth.js +59 -0
- package/src/tapes.js +265 -0
- package/src/teletext.js +348 -0
- package/src/teletext_adaptor.js +172 -0
- package/src/teletext_data.js +1064 -0
- package/src/touchscreen.js +86 -0
- package/src/tube.js +349 -0
- package/src/url-params.js +256 -0
- package/src/utils.js +1090 -0
- package/src/via.js +702 -0
- package/src/video-filters/pal-composite.js +94 -0
- package/src/video-filters/passthrough-filter.js +70 -0
- package/src/video-filters/shaders/pal-composite.frag.glsl +147 -0
- package/src/video-filters/shaders/pal-composite.vert.glsl +8 -0
- package/src/video-filters/shaders/passthrough.frag.glsl +6 -0
- package/src/video-filters/shaders/passthrough.vert.glsl +7 -0
- package/src/video.js +794 -0
- package/src/wd-fdc.js +1344 -0
- package/src/web/audio-handler.js +146 -0
- package/src/web/audio-renderer.js +115 -0
- package/src/web/debug.js +529 -0
- package/tests/integration/RmwX.asm +47 -0
- package/tests/integration/TestInstructionsSource +27 -0
- package/tests/integration/TestTimingsResults +27 -0
- package/tests/integration/TestTimingsSource +61 -0
- package/tests/integration/bcd.js +23 -0
- package/tests/integration/dormann.js +101 -0
- package/tests/integration/dp111timing.js +42 -0
- package/tests/integration/ensure-submodules.js +25 -0
- package/tests/integration/nops.bas +119 -0
- package/tests/integration/nops.js +24 -0
- package/tests/integration/protection.js +26 -0
- package/tests/integration/rmw.js +69 -0
- package/tests/integration/teletext/expected_bug_469.png +0 -0
- package/tests/integration/teletext/expected_flash_0.png +0 -0
- package/tests/integration/teletext/expected_flash_1.png +0 -0
- package/tests/integration/teletext/expected_hoglet_held_char.png +0 -0
- package/tests/integration/teletext/expected_reveal_flash_0.png +0 -0
- package/tests/integration/teletext/expected_reveal_flash_1.png +0 -0
- package/tests/integration/teletext.js +126 -0
- package/tests/integration/timings.js +56 -0
- package/tests/integration/via.js +1125 -0
- package/tests/suite/README.md +7 -0
- package/tests/suite/Test Suite 2.15.txt +373 -0
- package/tests/suite/bin/ start +0 -0
- package/tests/suite/bin/adca +0 -0
- package/tests/suite/bin/adcax +0 -0
- package/tests/suite/bin/adcay +0 -0
- package/tests/suite/bin/adcb +0 -0
- package/tests/suite/bin/adcix +0 -0
- package/tests/suite/bin/adciy +0 -0
- package/tests/suite/bin/adcz +0 -0
- package/tests/suite/bin/adczx +0 -0
- package/tests/suite/bin/alrb +0 -0
- package/tests/suite/bin/ancb +0 -0
- package/tests/suite/bin/anda +0 -0
- package/tests/suite/bin/andax +0 -0
- package/tests/suite/bin/anday +0 -0
- package/tests/suite/bin/andb +0 -0
- package/tests/suite/bin/andix +0 -0
- package/tests/suite/bin/andiy +0 -0
- package/tests/suite/bin/andz +0 -0
- package/tests/suite/bin/andzx +0 -0
- package/tests/suite/bin/aneb +0 -0
- package/tests/suite/bin/arrb +0 -0
- package/tests/suite/bin/asla +0 -0
- package/tests/suite/bin/aslax +0 -0
- package/tests/suite/bin/asln +0 -0
- package/tests/suite/bin/aslz +0 -0
- package/tests/suite/bin/aslzx +0 -0
- package/tests/suite/bin/asoa +0 -0
- package/tests/suite/bin/asoax +0 -0
- package/tests/suite/bin/asoay +0 -0
- package/tests/suite/bin/asoix +0 -0
- package/tests/suite/bin/asoiy +0 -0
- package/tests/suite/bin/asoz +0 -0
- package/tests/suite/bin/asozx +0 -0
- package/tests/suite/bin/axsa +0 -0
- package/tests/suite/bin/axsix +0 -0
- package/tests/suite/bin/axsz +0 -0
- package/tests/suite/bin/axszy +0 -0
- package/tests/suite/bin/bccr +0 -0
- package/tests/suite/bin/bcsr +0 -0
- package/tests/suite/bin/beqr +0 -0
- package/tests/suite/bin/bita +0 -0
- package/tests/suite/bin/bitz +0 -0
- package/tests/suite/bin/bmir +0 -0
- package/tests/suite/bin/bner +0 -0
- package/tests/suite/bin/bplr +0 -0
- package/tests/suite/bin/branchwrap +0 -0
- package/tests/suite/bin/brkn +0 -0
- package/tests/suite/bin/bvcr +0 -0
- package/tests/suite/bin/bvsr +0 -0
- package/tests/suite/bin/cia1pb6 +0 -0
- package/tests/suite/bin/cia1pb7 +0 -0
- package/tests/suite/bin/cia1ta +0 -0
- package/tests/suite/bin/cia1tab +0 -0
- package/tests/suite/bin/cia1tb +0 -0
- package/tests/suite/bin/cia1tb123 +0 -0
- package/tests/suite/bin/cia2pb6 +0 -0
- package/tests/suite/bin/cia2pb7 +0 -0
- package/tests/suite/bin/cia2ta +0 -0
- package/tests/suite/bin/cia2tb +0 -0
- package/tests/suite/bin/cia2tb123 +0 -0
- package/tests/suite/bin/clcn +0 -0
- package/tests/suite/bin/cldn +0 -0
- package/tests/suite/bin/clin +0 -0
- package/tests/suite/bin/clvn +0 -0
- package/tests/suite/bin/cmpa +0 -0
- package/tests/suite/bin/cmpax +0 -0
- package/tests/suite/bin/cmpay +0 -0
- package/tests/suite/bin/cmpb +0 -0
- package/tests/suite/bin/cmpix +0 -0
- package/tests/suite/bin/cmpiy +0 -0
- package/tests/suite/bin/cmpz +0 -0
- package/tests/suite/bin/cmpzx +0 -0
- package/tests/suite/bin/cntdef +0 -0
- package/tests/suite/bin/cnto2 +0 -0
- package/tests/suite/bin/cpuport +0 -0
- package/tests/suite/bin/cputiming +0 -0
- package/tests/suite/bin/cpxa +0 -0
- package/tests/suite/bin/cpxb +0 -0
- package/tests/suite/bin/cpxz +0 -0
- package/tests/suite/bin/cpya +0 -0
- package/tests/suite/bin/cpyb +0 -0
- package/tests/suite/bin/cpyz +0 -0
- package/tests/suite/bin/dcma +0 -0
- package/tests/suite/bin/dcmax +0 -0
- package/tests/suite/bin/dcmay +0 -0
- package/tests/suite/bin/dcmix +0 -0
- package/tests/suite/bin/dcmiy +0 -0
- package/tests/suite/bin/dcmz +0 -0
- package/tests/suite/bin/dcmzx +0 -0
- package/tests/suite/bin/deca +0 -0
- package/tests/suite/bin/decax +0 -0
- package/tests/suite/bin/decz +0 -0
- package/tests/suite/bin/deczx +0 -0
- package/tests/suite/bin/dexn +0 -0
- package/tests/suite/bin/deyn +0 -0
- package/tests/suite/bin/eora +0 -0
- package/tests/suite/bin/eorax +0 -0
- package/tests/suite/bin/eoray +0 -0
- package/tests/suite/bin/eorb +0 -0
- package/tests/suite/bin/eorix +0 -0
- package/tests/suite/bin/eoriy +0 -0
- package/tests/suite/bin/eorz +0 -0
- package/tests/suite/bin/eorzx +0 -0
- package/tests/suite/bin/finish +0 -0
- package/tests/suite/bin/flipos +0 -0
- package/tests/suite/bin/icr01 +0 -0
- package/tests/suite/bin/imr +0 -0
- package/tests/suite/bin/inca +0 -0
- package/tests/suite/bin/incax +0 -0
- package/tests/suite/bin/incz +0 -0
- package/tests/suite/bin/inczx +0 -0
- package/tests/suite/bin/insa +0 -0
- package/tests/suite/bin/insax +0 -0
- package/tests/suite/bin/insay +0 -0
- package/tests/suite/bin/insix +0 -0
- package/tests/suite/bin/insiy +0 -0
- package/tests/suite/bin/insz +0 -0
- package/tests/suite/bin/inszx +0 -0
- package/tests/suite/bin/inxn +0 -0
- package/tests/suite/bin/inyn +0 -0
- package/tests/suite/bin/irq +0 -0
- package/tests/suite/bin/jmpi +0 -0
- package/tests/suite/bin/jmpw +0 -0
- package/tests/suite/bin/jsrw +0 -0
- package/tests/suite/bin/lasay +0 -0
- package/tests/suite/bin/laxa +0 -0
- package/tests/suite/bin/laxay +0 -0
- package/tests/suite/bin/laxix +0 -0
- package/tests/suite/bin/laxiy +0 -0
- package/tests/suite/bin/laxz +0 -0
- package/tests/suite/bin/laxzy +0 -0
- package/tests/suite/bin/ldaa +0 -0
- package/tests/suite/bin/ldaax +0 -0
- package/tests/suite/bin/ldaay +0 -0
- package/tests/suite/bin/ldab +0 -0
- package/tests/suite/bin/ldaix +0 -0
- package/tests/suite/bin/ldaiy +0 -0
- package/tests/suite/bin/ldaz +0 -0
- package/tests/suite/bin/ldazx +0 -0
- package/tests/suite/bin/ldxa +0 -0
- package/tests/suite/bin/ldxay +0 -0
- package/tests/suite/bin/ldxb +0 -0
- package/tests/suite/bin/ldxz +0 -0
- package/tests/suite/bin/ldxzy +0 -0
- package/tests/suite/bin/ldya +0 -0
- package/tests/suite/bin/ldyax +0 -0
- package/tests/suite/bin/ldyb +0 -0
- package/tests/suite/bin/ldyz +0 -0
- package/tests/suite/bin/ldyzx +0 -0
- package/tests/suite/bin/loadth +0 -0
- package/tests/suite/bin/lsea +0 -0
- package/tests/suite/bin/lseax +0 -0
- package/tests/suite/bin/lseay +0 -0
- package/tests/suite/bin/lseix +0 -0
- package/tests/suite/bin/lseiy +0 -0
- package/tests/suite/bin/lsez +0 -0
- package/tests/suite/bin/lsezx +0 -0
- package/tests/suite/bin/lsra +0 -0
- package/tests/suite/bin/lsrax +0 -0
- package/tests/suite/bin/lsrn +0 -0
- package/tests/suite/bin/lsrz +0 -0
- package/tests/suite/bin/lsrzx +0 -0
- package/tests/suite/bin/lxab +0 -0
- package/tests/suite/bin/mmu +0 -0
- package/tests/suite/bin/mmufetch +0 -0
- package/tests/suite/bin/nmi +0 -0
- package/tests/suite/bin/nopa +0 -0
- package/tests/suite/bin/nopax +0 -0
- package/tests/suite/bin/nopb +0 -0
- package/tests/suite/bin/nopn +0 -0
- package/tests/suite/bin/nopz +0 -0
- package/tests/suite/bin/nopzx +0 -0
- package/tests/suite/bin/oneshot +0 -0
- package/tests/suite/bin/oraa +0 -0
- package/tests/suite/bin/oraax +0 -0
- package/tests/suite/bin/oraay +0 -0
- package/tests/suite/bin/orab +0 -0
- package/tests/suite/bin/oraix +0 -0
- package/tests/suite/bin/oraiy +0 -0
- package/tests/suite/bin/oraz +0 -0
- package/tests/suite/bin/orazx +0 -0
- package/tests/suite/bin/phan +0 -0
- package/tests/suite/bin/phpn +0 -0
- package/tests/suite/bin/plan +0 -0
- package/tests/suite/bin/plpn +0 -0
- package/tests/suite/bin/rlaa +0 -0
- package/tests/suite/bin/rlaax +0 -0
- package/tests/suite/bin/rlaay +0 -0
- package/tests/suite/bin/rlaix +0 -0
- package/tests/suite/bin/rlaiy +0 -0
- package/tests/suite/bin/rlaz +0 -0
- package/tests/suite/bin/rlazx +0 -0
- package/tests/suite/bin/rola +0 -0
- package/tests/suite/bin/rolax +0 -0
- package/tests/suite/bin/roln +0 -0
- package/tests/suite/bin/rolz +0 -0
- package/tests/suite/bin/rolzx +0 -0
- package/tests/suite/bin/rora +0 -0
- package/tests/suite/bin/rorax +0 -0
- package/tests/suite/bin/rorn +0 -0
- package/tests/suite/bin/rorz +0 -0
- package/tests/suite/bin/rorzx +0 -0
- package/tests/suite/bin/rraa +0 -0
- package/tests/suite/bin/rraax +0 -0
- package/tests/suite/bin/rraay +0 -0
- package/tests/suite/bin/rraix +0 -0
- package/tests/suite/bin/rraiy +0 -0
- package/tests/suite/bin/rraz +0 -0
- package/tests/suite/bin/rrazx +0 -0
- package/tests/suite/bin/rtin +0 -0
- package/tests/suite/bin/rtsn +0 -0
- package/tests/suite/bin/sbca +0 -0
- package/tests/suite/bin/sbcax +0 -0
- package/tests/suite/bin/sbcay +0 -0
- package/tests/suite/bin/sbcb +0 -0
- package/tests/suite/bin/sbcb(eb) +0 -0
- package/tests/suite/bin/sbcix +0 -0
- package/tests/suite/bin/sbciy +0 -0
- package/tests/suite/bin/sbcz +0 -0
- package/tests/suite/bin/sbczx +0 -0
- package/tests/suite/bin/sbxb +0 -0
- package/tests/suite/bin/secn +0 -0
- package/tests/suite/bin/sedn +0 -0
- package/tests/suite/bin/sein +0 -0
- package/tests/suite/bin/shaay +0 -0
- package/tests/suite/bin/shaiy +0 -0
- package/tests/suite/bin/shsay +0 -0
- package/tests/suite/bin/shxay +0 -0
- package/tests/suite/bin/shyax +0 -0
- package/tests/suite/bin/staa +0 -0
- package/tests/suite/bin/staax +0 -0
- package/tests/suite/bin/staay +0 -0
- package/tests/suite/bin/staix +0 -0
- package/tests/suite/bin/staiy +0 -0
- package/tests/suite/bin/staz +0 -0
- package/tests/suite/bin/stazx +0 -0
- package/tests/suite/bin/stxa +0 -0
- package/tests/suite/bin/stxz +0 -0
- package/tests/suite/bin/stxzy +0 -0
- package/tests/suite/bin/stya +0 -0
- package/tests/suite/bin/styz +0 -0
- package/tests/suite/bin/styzx +0 -0
- package/tests/suite/bin/taxn +0 -0
- package/tests/suite/bin/tayn +0 -0
- package/tests/suite/bin/trap1 +0 -0
- package/tests/suite/bin/trap10 +0 -0
- package/tests/suite/bin/trap11 +0 -0
- package/tests/suite/bin/trap12 +0 -0
- package/tests/suite/bin/trap13 +0 -0
- package/tests/suite/bin/trap14 +0 -0
- package/tests/suite/bin/trap15 +0 -0
- package/tests/suite/bin/trap16 +0 -0
- package/tests/suite/bin/trap17 +0 -0
- package/tests/suite/bin/trap2 +0 -0
- package/tests/suite/bin/trap3 +0 -0
- package/tests/suite/bin/trap4 +0 -0
- package/tests/suite/bin/trap5 +0 -0
- package/tests/suite/bin/trap6 +0 -0
- package/tests/suite/bin/trap7 +0 -0
- package/tests/suite/bin/trap8 +0 -0
- package/tests/suite/bin/trap9 +0 -0
- package/tests/suite/bin/tsxn +0 -0
- package/tests/suite/bin/txan +0 -0
- package/tests/suite/bin/txsn +0 -0
- package/tests/suite/bin/tyan +0 -0
- package/tests/suite/cbm-hackers-post.html +178 -0
- package/tests/suite/cbm-hackers-post.md +78 -0
- package/tests/test-machine.js +288 -0
- package/tests/test-suite.js +147 -0
- package/tests/test.css +7 -0
- package/tests/unit/gzip/test-1 +0 -0
- package/tests/unit/gzip/test-1.gz +0 -0
- package/tests/unit/gzip/test-2 +0 -0
- package/tests/unit/gzip/test-2.gz +0 -0
- package/tests/unit/gzip/test-3 +0 -0
- package/tests/unit/gzip/test-3.gz +0 -0
- package/tests/unit/gzip/test-4 +0 -0
- package/tests/unit/gzip/test-4.gz +0 -0
- package/tests/unit/test-adc.js +307 -0
- package/tests/unit/test-bcd.js +30 -0
- package/tests/unit/test-cmos.js +266 -0
- package/tests/unit/test-disc-drive.js +85 -0
- package/tests/unit/test-disc-hfe.js +347 -0
- package/tests/unit/test-disc.js +232 -0
- package/tests/unit/test-fifo.js +35 -0
- package/tests/unit/test-gamepad-source.js +67 -0
- package/tests/unit/test-gzip.js +22 -0
- package/tests/unit/test-intel-fdc.js +93 -0
- package/tests/unit/test-keyboard.js +410 -0
- package/tests/unit/test-mouse-joystick-source.js +128 -0
- package/tests/unit/test-scheduler.js +190 -0
- package/tests/unit/test-serial.js +154 -0
- package/tests/unit/test-teletext-adaptor.js +359 -0
- package/tests/unit/test-tokenise.js +65 -0
- package/tests/unit/test-url-params.js +398 -0
- package/tests/unit/test-utils.js +276 -0
- package/tests/unit/test-video.js +498 -0
- package/tests/unit/test-zip.js +56 -0
- package/tests/unit/zip/test-mixed.zip +0 -0
- package/tests/unit/zip/test-rom.zip +0 -0
- package/tests/unit/zip/test-ssd.zip +0 -0
- package/tools/fir-generator.js +80 -0
- package/tools/vite-plugin-fir-shader.js +131 -0
- package/vite.config.js +34 -0
package/src/intel-fdc.js
ADDED
|
@@ -0,0 +1,1717 @@
|
|
|
1
|
+
// Translated from beebjit by Chris Evans.
|
|
2
|
+
// https://github.com/scarybeasts/beebjit
|
|
3
|
+
// eslint-disable-next-line no-unused-vars
|
|
4
|
+
import { Cpu6502 } from "./6502.js";
|
|
5
|
+
// eslint-disable-next-line no-unused-vars
|
|
6
|
+
import { Disc, IbmDiscFormat } from "./disc.js";
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line no-unused-vars
|
|
9
|
+
import { BaseDiscDrive, DiscDrive } from "./disc-drive.js";
|
|
10
|
+
// eslint-disable-next-line no-unused-vars
|
|
11
|
+
import { Scheduler } from "./scheduler.js";
|
|
12
|
+
import * as utils from "./utils.js";
|
|
13
|
+
|
|
14
|
+
// TODOs remaining for intel-fdc and related functionality
|
|
15
|
+
// - support loading other disc formats
|
|
16
|
+
// - support "writeback" to SSD (at least); tested with
|
|
17
|
+
// - google drive - broken currently :'()
|
|
18
|
+
// - download disc image DONE
|
|
19
|
+
// - ideally support "writeback" to high fidelity output formats
|
|
20
|
+
// - UI elements for visualisation
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Register indices.
|
|
24
|
+
*
|
|
25
|
+
* @readonly
|
|
26
|
+
* @enum {Number}
|
|
27
|
+
*/
|
|
28
|
+
const Registers = Object.freeze({
|
|
29
|
+
internalPointer: 0x00,
|
|
30
|
+
internalCountMsbCopy: 0x00,
|
|
31
|
+
internalParamCount: 0x01,
|
|
32
|
+
internalSeekRetryCount: 0x01,
|
|
33
|
+
internalParamDataMarker: 0x02,
|
|
34
|
+
internalParam_5: 0x03,
|
|
35
|
+
internalParam_4: 0x04,
|
|
36
|
+
internalParam_3: 0x05,
|
|
37
|
+
currentSector: 0x06,
|
|
38
|
+
internalParam_2: 0x06,
|
|
39
|
+
internalParam_1: 0x07,
|
|
40
|
+
internalHeaderPointer: 0x08,
|
|
41
|
+
internalMsCountHi: 0x08,
|
|
42
|
+
internalMsCountLo: 0x09,
|
|
43
|
+
internalSeekCount: 0x0a,
|
|
44
|
+
internalIdSector: 0x0a,
|
|
45
|
+
internalSeekTarget_1: 0x0b,
|
|
46
|
+
internalDynamicDispatch: 0x0b,
|
|
47
|
+
internalSeekTarget_2: 0x0c,
|
|
48
|
+
internalIdTrack: 0x0c,
|
|
49
|
+
headStepRate: 0x0d,
|
|
50
|
+
headSettleTime: 0x0e,
|
|
51
|
+
headLoadUnload: 0x0f,
|
|
52
|
+
badTrack_1Drive_0: 0x10,
|
|
53
|
+
badTrack_2Drive_0: 0x11,
|
|
54
|
+
trackDrive_0: 0x12,
|
|
55
|
+
internalCountLsb: 0x13,
|
|
56
|
+
internalCountMsb: 0x14,
|
|
57
|
+
internalDriveInCopy: 0x15,
|
|
58
|
+
internalWriteRunData: 0x15,
|
|
59
|
+
internalGap2Skip: 0x15,
|
|
60
|
+
internalResult: 0x16,
|
|
61
|
+
mode: 0x17,
|
|
62
|
+
internalStatus: 0x17,
|
|
63
|
+
badTrack_1Drive_1: 0x18,
|
|
64
|
+
badTrack_2Drive_1: 0x19,
|
|
65
|
+
trackDrive_1: 0x1a,
|
|
66
|
+
internalDriveInLatched: 0x1b,
|
|
67
|
+
internalIndexPulseCount: 0x1c,
|
|
68
|
+
internalData: 0x1d,
|
|
69
|
+
internalParameter: 0x1e,
|
|
70
|
+
internalCommand: 0x1f,
|
|
71
|
+
|
|
72
|
+
mmioDriveIn: 0x22,
|
|
73
|
+
mmioDriveOut: 0x23,
|
|
74
|
+
mmioClocks: 0x24,
|
|
75
|
+
mmioData: 0x25,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Drive output bitmask.
|
|
80
|
+
*
|
|
81
|
+
* @readonly
|
|
82
|
+
* @enum {Number}
|
|
83
|
+
*/
|
|
84
|
+
const DriveOut = Object.freeze({
|
|
85
|
+
select_1: 0x80,
|
|
86
|
+
select_0: 0x40,
|
|
87
|
+
side: 0x20,
|
|
88
|
+
lowHeadCurrent: 0x10,
|
|
89
|
+
loadHead: 0x08,
|
|
90
|
+
direction: 0x04,
|
|
91
|
+
step: 0x02,
|
|
92
|
+
writeEnable: 0x01,
|
|
93
|
+
selectFlags: 0xc0,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Floppy disc controller mode.
|
|
98
|
+
*
|
|
99
|
+
* @readonly
|
|
100
|
+
* @enum {Number}
|
|
101
|
+
*/
|
|
102
|
+
const FdcMode = Object.freeze({
|
|
103
|
+
singleActuator: 0x02,
|
|
104
|
+
noDma: 0x01,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Register address.
|
|
109
|
+
*
|
|
110
|
+
* @readonly
|
|
111
|
+
* @enum {Number}
|
|
112
|
+
*/
|
|
113
|
+
const Address = Object.freeze({
|
|
114
|
+
// Read.
|
|
115
|
+
status: 0,
|
|
116
|
+
result: 1,
|
|
117
|
+
unknown_read_2: 2,
|
|
118
|
+
unknown_read_3: 3,
|
|
119
|
+
|
|
120
|
+
// Write.
|
|
121
|
+
command: 0,
|
|
122
|
+
parameter: 1,
|
|
123
|
+
reset: 2,
|
|
124
|
+
|
|
125
|
+
// Read / write.
|
|
126
|
+
data: 4,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Result bitmask.
|
|
131
|
+
*
|
|
132
|
+
* @readonly
|
|
133
|
+
* @enum {Number}
|
|
134
|
+
*/
|
|
135
|
+
const Result = Object.freeze({
|
|
136
|
+
ok: 0x00,
|
|
137
|
+
clockError: 0x08,
|
|
138
|
+
lateDma: 0x0a,
|
|
139
|
+
idCrcError: 0x0c,
|
|
140
|
+
dataCrcError: 0x0e,
|
|
141
|
+
driveNotReady: 0x10,
|
|
142
|
+
writeProtected: 0x12,
|
|
143
|
+
sectorNotFound: 0x18,
|
|
144
|
+
flagDeletedData: 0x20,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Command number.
|
|
149
|
+
*
|
|
150
|
+
* @readonly
|
|
151
|
+
* @enum {Number}
|
|
152
|
+
*/
|
|
153
|
+
const Command = Object.freeze({
|
|
154
|
+
scanData: 0,
|
|
155
|
+
scanDataAndDeleted: 1,
|
|
156
|
+
writeData: 2,
|
|
157
|
+
writeDeletedData: 3,
|
|
158
|
+
readData: 4,
|
|
159
|
+
readDataAndDeleted: 5,
|
|
160
|
+
readId: 6,
|
|
161
|
+
verify: 7,
|
|
162
|
+
format: 8,
|
|
163
|
+
unused_9: 9,
|
|
164
|
+
seek: 10,
|
|
165
|
+
readDriveStatus: 11,
|
|
166
|
+
unused_12: 12,
|
|
167
|
+
specify: 13,
|
|
168
|
+
writeSpecialRegister: 14,
|
|
169
|
+
readSpecialRegister: 15,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Status flags
|
|
174
|
+
*
|
|
175
|
+
* @readonly
|
|
176
|
+
* @enum {Number}
|
|
177
|
+
*/
|
|
178
|
+
const StatusFlag = Object.freeze({
|
|
179
|
+
busy: 0x80,
|
|
180
|
+
commandFull: 0x40,
|
|
181
|
+
paramFull: 0x20,
|
|
182
|
+
resultReady: 0x10,
|
|
183
|
+
nmi: 0x08,
|
|
184
|
+
needData: 0x04,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Parameter acceptance state machine.
|
|
189
|
+
*
|
|
190
|
+
* @readonly
|
|
191
|
+
* @enum {Number}
|
|
192
|
+
*/
|
|
193
|
+
const ParamAccept = Object.freeze({
|
|
194
|
+
none: 0,
|
|
195
|
+
command: 1,
|
|
196
|
+
specify: 2,
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Index pulse state machine.
|
|
201
|
+
*
|
|
202
|
+
* @readonly
|
|
203
|
+
* @enum {Number}
|
|
204
|
+
*/
|
|
205
|
+
const IndexPulse = Object.freeze({
|
|
206
|
+
none: 1,
|
|
207
|
+
timeout: 2,
|
|
208
|
+
spindown: 3,
|
|
209
|
+
startReadId: 4,
|
|
210
|
+
startFormat: 5,
|
|
211
|
+
stopFormat: 6,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Timer state machine.
|
|
216
|
+
*
|
|
217
|
+
* @readonly
|
|
218
|
+
* @enum {Number}
|
|
219
|
+
*/
|
|
220
|
+
const TimerState = Object.freeze({
|
|
221
|
+
none: 0,
|
|
222
|
+
seekStep: 1,
|
|
223
|
+
postSeek: 2,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Overall state machine.
|
|
228
|
+
*
|
|
229
|
+
* @readonly
|
|
230
|
+
* @enum {Number}
|
|
231
|
+
*/
|
|
232
|
+
const State = Object.freeze({
|
|
233
|
+
null: 0,
|
|
234
|
+
idle: 1,
|
|
235
|
+
syncingForIdWait: 2,
|
|
236
|
+
syncingForId: 3,
|
|
237
|
+
checkIdMarker: 4,
|
|
238
|
+
inId: 5,
|
|
239
|
+
inIdCrc: 6,
|
|
240
|
+
syncingForData: 7,
|
|
241
|
+
checkDataMarker: 8,
|
|
242
|
+
inData: 9,
|
|
243
|
+
inDataCrc: 10,
|
|
244
|
+
skipGap_2: 11,
|
|
245
|
+
writeRun: 12,
|
|
246
|
+
writeDataMark: 13,
|
|
247
|
+
writeSectorData: 14,
|
|
248
|
+
writeCrc_2: 15,
|
|
249
|
+
writeCrc_3: 16,
|
|
250
|
+
dynamicDispatch: 17,
|
|
251
|
+
formatWriteIdMarker: 18,
|
|
252
|
+
formatIdCrc_2: 19,
|
|
253
|
+
formatIdCrc_3: 20,
|
|
254
|
+
formatWriteDataMarker: 21,
|
|
255
|
+
formatDataCrc_2: 22,
|
|
256
|
+
formatDataCrc_3: 23,
|
|
257
|
+
formatGap_4: 24,
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Callback state machine.
|
|
262
|
+
*
|
|
263
|
+
* @readonly
|
|
264
|
+
* @enum {Number}
|
|
265
|
+
*/
|
|
266
|
+
const Call = Object.freeze({
|
|
267
|
+
uninitialised: 0,
|
|
268
|
+
unchanged: 1,
|
|
269
|
+
seek: 2,
|
|
270
|
+
readId: 3,
|
|
271
|
+
read: 4,
|
|
272
|
+
write: 5,
|
|
273
|
+
format: 6,
|
|
274
|
+
formatGap1OrGap3FFs: 7,
|
|
275
|
+
formatGap1orGap300s: 8,
|
|
276
|
+
formatGap2_FFs: 9,
|
|
277
|
+
formatGap2_00s: 10,
|
|
278
|
+
formatData: 11,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
export class IntelFdc {
|
|
282
|
+
static get NumRegisters() {
|
|
283
|
+
return 32;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* @param {Cpu6502} cpu
|
|
288
|
+
* @param {Scheduler} scheduler
|
|
289
|
+
* @param {BaseDiscDrive[] | undefined} drives
|
|
290
|
+
* @param {*} debugFlags
|
|
291
|
+
*/
|
|
292
|
+
constructor(cpu, scheduler, drives, debugFlags) {
|
|
293
|
+
this._cpu = cpu;
|
|
294
|
+
if (drives) this._drives = drives;
|
|
295
|
+
else this._drives = [new DiscDrive(0, scheduler), new DiscDrive(1, scheduler)];
|
|
296
|
+
/** @type {BaseDiscDrive} */
|
|
297
|
+
this._currentDrive = null;
|
|
298
|
+
|
|
299
|
+
this._paramCallback = ParamAccept.none;
|
|
300
|
+
this._indexPulseCallback = IndexPulse.none;
|
|
301
|
+
this._timerState = TimerState.none;
|
|
302
|
+
this._callContext = Call.uninitialised;
|
|
303
|
+
this._didSeekStep = false;
|
|
304
|
+
|
|
305
|
+
this._regs = new Uint8Array(IntelFdc.NumRegisters);
|
|
306
|
+
this._isResultReady = false;
|
|
307
|
+
// Derived from one of the regs plus _isResultReady.
|
|
308
|
+
this._status = 0;
|
|
309
|
+
this._mmioData = 0;
|
|
310
|
+
this._mmioClocks = 0;
|
|
311
|
+
this._driveOut = 0;
|
|
312
|
+
|
|
313
|
+
this._shiftRegister = 0;
|
|
314
|
+
this._numShifts = 0;
|
|
315
|
+
|
|
316
|
+
this._state = State.null;
|
|
317
|
+
this._stateCount = 0;
|
|
318
|
+
this._stateIsIndexPulse = false;
|
|
319
|
+
this._crc = 0;
|
|
320
|
+
this._onDiscCrc = 0;
|
|
321
|
+
|
|
322
|
+
this._logCommands = debugFlags ? !!debugFlags.logFdcCommands : false;
|
|
323
|
+
this._logStateChanges = debugFlags ? !!debugFlags.logFdcStateChanges : false;
|
|
324
|
+
|
|
325
|
+
this._timerTask = scheduler.newTask(() => this._timerFired());
|
|
326
|
+
|
|
327
|
+
const callback = (pulses, count) => this._pulsesCallback(pulses, count);
|
|
328
|
+
for (const drive of this._drives) drive.setPulsesCallback(callback);
|
|
329
|
+
|
|
330
|
+
this.powerOnReset();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
_commandAbort() {
|
|
334
|
+
// If we're aborting a command in the middle of writing data, it usually
|
|
335
|
+
// doesn't leave a clean byte end on the disc. This is not particularly
|
|
336
|
+
// important to emulate at all, but it does help create new copy protection
|
|
337
|
+
// schemes under emulation.
|
|
338
|
+
if (this._driveOut & DriveOut.writeEnable) {
|
|
339
|
+
this._currentDrive.writePulses(IbmDiscFormat.fmTo2usPulses(0xff, 0xff));
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Lower any NMI assertion. This is particularly important for error $0A,
|
|
343
|
+
// aka. late DMA, which will abort the command while NMI is asserted. We
|
|
344
|
+
// therefore need to de-assert NMI so that the NMI for command completion
|
|
345
|
+
// isn't lost.
|
|
346
|
+
// TODO(matt) - we don't model NMIs properly here, each device should have its own nmi line
|
|
347
|
+
this._cpu.NMI(false);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
powerOnReset() {
|
|
351
|
+
// The reset line does most things.
|
|
352
|
+
this.reset();
|
|
353
|
+
this._regs.fill(0);
|
|
354
|
+
this._isResultReady = false;
|
|
355
|
+
this._mmioData = 0;
|
|
356
|
+
this._mmioClocks = 0;
|
|
357
|
+
this._stateCount = 0;
|
|
358
|
+
this._stateIsIndexPulse = false;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
reset() {
|
|
362
|
+
// Abort any in-progress command.
|
|
363
|
+
this._commandAbort();
|
|
364
|
+
this._clearCallbacks();
|
|
365
|
+
// Deselect any drive; ensures spin-down.
|
|
366
|
+
this._setDriveOut(0);
|
|
367
|
+
// On a real machine, status appears to be cleared but result and data not.
|
|
368
|
+
this._statusLower(this.internalStatus);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
get internalStatus() {
|
|
372
|
+
return this._regs[Registers.internalStatus];
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* @param {Number} addr hardware address
|
|
377
|
+
* @returns {Number} byte at the given hardware address
|
|
378
|
+
*/
|
|
379
|
+
read(addr) {
|
|
380
|
+
switch (addr & 0x07) {
|
|
381
|
+
case Address.status:
|
|
382
|
+
return this._status;
|
|
383
|
+
case Address.result: {
|
|
384
|
+
const result = this._result;
|
|
385
|
+
this._resultConsumed();
|
|
386
|
+
this._statusLower(StatusFlag.nmi);
|
|
387
|
+
return result;
|
|
388
|
+
}
|
|
389
|
+
case Address.data:
|
|
390
|
+
case Address.data + 1:
|
|
391
|
+
case Address.data + 2:
|
|
392
|
+
case Address.data + 3:
|
|
393
|
+
this._statusLower(StatusFlag.needData | StatusFlag.nmi);
|
|
394
|
+
return this._regs[Registers.internalData];
|
|
395
|
+
// Register address 2 and 3 are not documented as having anything
|
|
396
|
+
// wired up for reading, BUT on a model B, they appear to give the MSB and
|
|
397
|
+
// LSB of the sector byte counter in internal registers 19 ($13) and 20 ($14).
|
|
398
|
+
case Address.unknown_read_2:
|
|
399
|
+
return this._regs[Registers.internalCountMsb];
|
|
400
|
+
case Address.unknown_read_3:
|
|
401
|
+
return this._regs[Registers.internalCountLsb];
|
|
402
|
+
default:
|
|
403
|
+
throw new Error(`"Unexpected read of addr ${utils.hexword(addr)}"`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
_log(message) {
|
|
408
|
+
console.log(`8271: ${message}`);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
_logCommand(message) {
|
|
412
|
+
if (this._logCommands) this._log(message);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* @param {Number} addr hardware address
|
|
417
|
+
* @param {Number} val byte to write
|
|
418
|
+
*/
|
|
419
|
+
write(addr, val) {
|
|
420
|
+
switch (addr & 7) {
|
|
421
|
+
case Address.command:
|
|
422
|
+
this._commandWritten(val);
|
|
423
|
+
break;
|
|
424
|
+
case Address.parameter:
|
|
425
|
+
this._paramWritten(val);
|
|
426
|
+
break;
|
|
427
|
+
case Address.data:
|
|
428
|
+
case Address.data + 1:
|
|
429
|
+
case Address.data + 2:
|
|
430
|
+
case Address.data + 3:
|
|
431
|
+
this._statusLower(StatusFlag.needData | StatusFlag.nmi);
|
|
432
|
+
this._regs[Registers.internalData] = val;
|
|
433
|
+
break;
|
|
434
|
+
case Address.reset:
|
|
435
|
+
//On a real 8271, crazy things happen if you write 2 or especially 4 to this register.
|
|
436
|
+
if (val !== 0 && val !== 1) {
|
|
437
|
+
this._log("funky reset");
|
|
438
|
+
}
|
|
439
|
+
if (val === 1) {
|
|
440
|
+
this._logCommand("reset");
|
|
441
|
+
this.reset();
|
|
442
|
+
}
|
|
443
|
+
break;
|
|
444
|
+
case 3:
|
|
445
|
+
default:
|
|
446
|
+
this._log(`Not supported: ${utils.hexword(addr)}=${utils.hexbyte(val)}`);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
_checkIndexPulse() {
|
|
451
|
+
const wasIndexPulse = this._stateIsIndexPulse;
|
|
452
|
+
this._stateIsIndexPulse = this._index;
|
|
453
|
+
|
|
454
|
+
// Looking for pulse going high
|
|
455
|
+
if (!this._stateIsIndexPulse || wasIndexPulse) return;
|
|
456
|
+
|
|
457
|
+
switch (this._indexPulseCallback) {
|
|
458
|
+
case IndexPulse.none:
|
|
459
|
+
break;
|
|
460
|
+
case IndexPulse.timeout:
|
|
461
|
+
// If we see too many index pulses without the progress of a sector, the command times out with 0x18.
|
|
462
|
+
// Interestingly enough, something like an e.g. 8192 byte sector read /times out because such a crazy
|
|
463
|
+
// read hits the default 3 index pulse limit.
|
|
464
|
+
if (--this._regs[Registers.internalIndexPulseCount] === 0) {
|
|
465
|
+
this._finishCommand(Result.sectorNotFound);
|
|
466
|
+
}
|
|
467
|
+
break;
|
|
468
|
+
case IndexPulse.spindown:
|
|
469
|
+
if (--this._regs[Registers.internalIndexPulseCount] === 0) {
|
|
470
|
+
this._logCommand("automatic head unload");
|
|
471
|
+
this._spinDown();
|
|
472
|
+
this._indexPulseCallback = IndexPulse.none;
|
|
473
|
+
}
|
|
474
|
+
break;
|
|
475
|
+
case IndexPulse.startFormat:
|
|
476
|
+
// Note that format doesn't set an index pulse timeout. No matter how
|
|
477
|
+
// large the format sector size request, even 16384, the command never
|
|
478
|
+
// exits due to 2 index pulses counted. This differs from read _and_
|
|
479
|
+
// write. Format will exit on the next index pulse after all the sectors
|
|
480
|
+
// have been written.
|
|
481
|
+
// Disc Duplicator III needs this to work correctly when deformatting
|
|
482
|
+
// tracks.
|
|
483
|
+
if (this._regs[Registers.internalParam_4] !== 0) {
|
|
484
|
+
throw new Error("format GAP5 not supported");
|
|
485
|
+
}
|
|
486
|
+
// Decrement GAP3 as the CRC generator emits a third byte as 0xff.
|
|
487
|
+
this._regs[Registers.internalParam_2]--;
|
|
488
|
+
this._regs[Registers.internalDynamicDispatch] = 4;
|
|
489
|
+
// This will start writing immediately because we check index pulse callbacks
|
|
490
|
+
// before we process read/write state.
|
|
491
|
+
this._indexPulseCallback = IndexPulse.none;
|
|
492
|
+
// param_5 is GAP1.
|
|
493
|
+
this._writeFFsAnd00s(Call.formatGap1OrGap3FFs, this._regs[Registers.internalParam_5]);
|
|
494
|
+
break;
|
|
495
|
+
case IndexPulse.stopFormat:
|
|
496
|
+
this._checkCompletion();
|
|
497
|
+
break;
|
|
498
|
+
case IndexPulse.startReadId:
|
|
499
|
+
this._startIndexPulseTimeout();
|
|
500
|
+
this._startSyncingForHeader();
|
|
501
|
+
break;
|
|
502
|
+
default:
|
|
503
|
+
throw new Error(`Unexpected index pulse callback ${this._indexPulseCallback}`);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
_pulsesCallback(pulses, count) {
|
|
508
|
+
if (count !== 32) throw new Error("Expected FM pulses only");
|
|
509
|
+
this._checkIndexPulse();
|
|
510
|
+
|
|
511
|
+
// All writing occurs here.
|
|
512
|
+
// NOTE: a nice 8271 quirk: if the write gate is open outside a command, it
|
|
513
|
+
// still writes to disc, often effectively creating weak bits.
|
|
514
|
+
if (this._driveOut & DriveOut.writeEnable) {
|
|
515
|
+
const clocks = this._mmioClocks;
|
|
516
|
+
const data = this._mmioData;
|
|
517
|
+
const pulses = IbmDiscFormat.fmTo2usPulses(clocks, data);
|
|
518
|
+
if (clocks !== 0xff && clocks !== IbmDiscFormat.markClockPattern)
|
|
519
|
+
this._log(`writing unusual clocks=${utils.hexbyte(clocks)} data=${utils.hexbyte(data)}`);
|
|
520
|
+
this._currentDrive.writePulses(pulses);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// The external data register is always copied across to the bit processor's
|
|
524
|
+
// MMIO data register. If a write command is in a state where it needed to
|
|
525
|
+
// provide a data byte internally (i.e. a GAP byte, marker, etc.), it
|
|
526
|
+
// overrides by re-writing the MMIO data register in the state machine below.
|
|
527
|
+
this._mmioData = this._regs[Registers.internalData];
|
|
528
|
+
|
|
529
|
+
switch (this._state) {
|
|
530
|
+
case State.idle:
|
|
531
|
+
break;
|
|
532
|
+
case State.syncingForIdWait:
|
|
533
|
+
case State.syncingForId:
|
|
534
|
+
case State.checkIdMarker:
|
|
535
|
+
case State.inId:
|
|
536
|
+
case State.inIdCrc:
|
|
537
|
+
case State.skipGap_2:
|
|
538
|
+
case State.syncingForData:
|
|
539
|
+
case State.checkDataMarker:
|
|
540
|
+
case State.inData:
|
|
541
|
+
case State.inDataCrc: {
|
|
542
|
+
for (let i = 0; i < 16; ++i) {
|
|
543
|
+
const bit = !!(pulses & 0xc0000000);
|
|
544
|
+
pulses = (pulses << 2) & 0xffffffff;
|
|
545
|
+
this._shiftDataBit(bit);
|
|
546
|
+
}
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
case State.writeRun:
|
|
550
|
+
case State.writeDataMark:
|
|
551
|
+
case State.dynamicDispatch:
|
|
552
|
+
case State.writeSectorData:
|
|
553
|
+
case State.writeCrc_2:
|
|
554
|
+
case State.writeCrc_3:
|
|
555
|
+
case State.formatWriteIdMarker:
|
|
556
|
+
case State.formatIdCrc_2:
|
|
557
|
+
case State.formatIdCrc_3:
|
|
558
|
+
case State.formatWriteDataMarker:
|
|
559
|
+
case State.formatDataCrc_2:
|
|
560
|
+
case State.formatDataCrc_3:
|
|
561
|
+
case State.formatGap_4:
|
|
562
|
+
this._byteCallbackWriting();
|
|
563
|
+
break;
|
|
564
|
+
default:
|
|
565
|
+
throw new Error(`Unknown state ${this._state}`);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
_shiftDataBit(bit) {
|
|
570
|
+
const state = this._state;
|
|
571
|
+
switch (state) {
|
|
572
|
+
case State.syncingForIdWait:
|
|
573
|
+
this._stateCount++;
|
|
574
|
+
// THe controller seems to need recovery time after a sector header before
|
|
575
|
+
// it can sync to another one. Measuring the "read sector IDs" command, 0x1b,
|
|
576
|
+
// it needs 4 bytes to recover prior to the 2 byte sync.
|
|
577
|
+
if (this._stateCount === 4 * 8 * 2) {
|
|
578
|
+
this._startSyncingForHeader();
|
|
579
|
+
}
|
|
580
|
+
break;
|
|
581
|
+
case State.syncingForId:
|
|
582
|
+
case State.syncingForData: {
|
|
583
|
+
const stateCount = this._stateCount;
|
|
584
|
+
// Need to see bit pattern of 1010101010... to gather sync. This
|
|
585
|
+
// represents a string of 1 clock bits followed by 0 data bits.
|
|
586
|
+
if (bit === !(stateCount & 1)) {
|
|
587
|
+
this._stateCount++;
|
|
588
|
+
} else if (stateCount >= 32 && stateCount & 1) {
|
|
589
|
+
// Here we hit a 1 data bit while in sync, so it's the start of a marker byte.
|
|
590
|
+
if (!bit) {
|
|
591
|
+
throw new Error("Assertion failed; was expecting a one bit");
|
|
592
|
+
}
|
|
593
|
+
this._setState(state === State.syncingForId ? State.checkIdMarker : State.checkDataMarker);
|
|
594
|
+
this._shiftRegister = 3;
|
|
595
|
+
this._numShifts = 2;
|
|
596
|
+
} else {
|
|
597
|
+
// Restart sync.
|
|
598
|
+
this._stateCount = bit ? 1 : 0;
|
|
599
|
+
}
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
case State.checkIdMarker:
|
|
603
|
+
case State.inId:
|
|
604
|
+
case State.inIdCrc:
|
|
605
|
+
case State.checkDataMarker:
|
|
606
|
+
case State.inData:
|
|
607
|
+
case State.inDataCrc:
|
|
608
|
+
case State.skipGap_2: {
|
|
609
|
+
const shiftRegister = ((this._shiftRegister << 1) & 0xffffffff) | (bit ? 1 : 0);
|
|
610
|
+
this._shiftRegister = shiftRegister;
|
|
611
|
+
this._numShifts++;
|
|
612
|
+
if (this._numShifts !== 16) break;
|
|
613
|
+
const clockByte = IntelFdc.extractBits(shiftRegister);
|
|
614
|
+
const dataByte = IntelFdc.extractBits(shiftRegister << 1);
|
|
615
|
+
if (
|
|
616
|
+
clockByte !== 0xff &&
|
|
617
|
+
state !== State.checkIdMarker &&
|
|
618
|
+
state !== State.checkDataMarker &&
|
|
619
|
+
state !== State.skipGap_2
|
|
620
|
+
) {
|
|
621
|
+
// Nothing. From testing the 8271 doesn't deliver bytes with missing
|
|
622
|
+
// clock bits in the middle of a synced byte stream.
|
|
623
|
+
} else {
|
|
624
|
+
this._byteCallbackReading(dataByte, clockByte);
|
|
625
|
+
}
|
|
626
|
+
this._shiftRegister = 0;
|
|
627
|
+
this._numShifts = 0;
|
|
628
|
+
break;
|
|
629
|
+
}
|
|
630
|
+
case State.idle:
|
|
631
|
+
case State.writeRun:
|
|
632
|
+
break;
|
|
633
|
+
default:
|
|
634
|
+
throw new Error(`"Unexpected state ${state}"`);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
static extractBits(bits) {
|
|
639
|
+
let byte = 0;
|
|
640
|
+
if (bits & 0x8000) byte |= 0x80;
|
|
641
|
+
if (bits & 0x2000) byte |= 0x40;
|
|
642
|
+
if (bits & 0x0800) byte |= 0x20;
|
|
643
|
+
if (bits & 0x0200) byte |= 0x10;
|
|
644
|
+
if (bits & 0x0080) byte |= 0x08;
|
|
645
|
+
if (bits & 0x0020) byte |= 0x04;
|
|
646
|
+
if (bits & 0x0008) byte |= 0x02;
|
|
647
|
+
if (bits & 0x0002) byte |= 0x01;
|
|
648
|
+
return byte;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
_checkDataLossOk() {
|
|
652
|
+
let ok = true;
|
|
653
|
+
|
|
654
|
+
// Abort if DMA transfer is selected. This is not supported in a BBC.
|
|
655
|
+
if (!(this._regs[Registers.mode] & FdcMode.noDma)) ok = false;
|
|
656
|
+
|
|
657
|
+
// Abort command if it's any type of scan. The 8271 requires DMA to be wired
|
|
658
|
+
// up for scan commands, which is not done in the BBC application.
|
|
659
|
+
const command = this._internalCommand;
|
|
660
|
+
if (command === Command.scanData || command === Command.scanDataAndDeleted) ok = false;
|
|
661
|
+
|
|
662
|
+
// Abort command if previous data byte wasn't picked up.
|
|
663
|
+
if (this.internalStatus & StatusFlag.needData) ok = false;
|
|
664
|
+
|
|
665
|
+
if (ok) return true;
|
|
666
|
+
|
|
667
|
+
this._commandAbort();
|
|
668
|
+
this._finishCommand(Result.lateDma);
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
_byteCallbackReading(dataByte, clockByte) {
|
|
673
|
+
const command = this._internalCommand;
|
|
674
|
+
if (this._irqCallbacks) {
|
|
675
|
+
if (!this._checkDataLossOk()) return;
|
|
676
|
+
this._regs[Registers.internalData] = dataByte;
|
|
677
|
+
this._statusRaise(StatusFlag.nmi | StatusFlag.needData);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
switch (this._state) {
|
|
681
|
+
case State.skipGap_2:
|
|
682
|
+
// The controller requires a minimum byte count of 12 before sync then
|
|
683
|
+
// sector data. 2 bytes of sync are needed, so absolute minimum gap here is
|
|
684
|
+
// 14. The controller formats to 17 (not user controllable).
|
|
685
|
+
|
|
686
|
+
// The controller enforced gap skip is 11 bytes of read, as per the
|
|
687
|
+
// ROM. The practical count of 12 is likely because the controller takes
|
|
688
|
+
// some number of microseconds to start the sync detector after this
|
|
689
|
+
// counter expires.
|
|
690
|
+
if (--this._regs[Registers.internalGap2Skip]) break;
|
|
691
|
+
if (this._callContext === Call.read) this._setState(State.syncingForData);
|
|
692
|
+
else if (this._callContext === Call.write) this._doWriteRun(Call.write, 0x00);
|
|
693
|
+
else throw new Error(`Unexpected call context ${this._callContext}`);
|
|
694
|
+
break;
|
|
695
|
+
case State.checkIdMarker:
|
|
696
|
+
if (clockByte === IbmDiscFormat.markClockPattern && dataByte === IbmDiscFormat.idMarkDataPattern) {
|
|
697
|
+
this._crc = IbmDiscFormat.crcAddByte(IbmDiscFormat.crcInit(false), dataByte);
|
|
698
|
+
if (command === Command.readId) this._startIrqCallbacks();
|
|
699
|
+
this._setState(State.inId);
|
|
700
|
+
} else {
|
|
701
|
+
this._startSyncingForHeader();
|
|
702
|
+
}
|
|
703
|
+
break;
|
|
704
|
+
case State.inId:
|
|
705
|
+
this._crc = IbmDiscFormat.crcAddByte(this._crc, dataByte);
|
|
706
|
+
this._writeRegister(this._regs[Registers.internalHeaderPointer], dataByte);
|
|
707
|
+
this._regs[Registers.internalHeaderPointer]--;
|
|
708
|
+
if ((this._regs[Registers.internalHeaderPointer] & 0x07) === 0) {
|
|
709
|
+
this._onDiscCrc = 0;
|
|
710
|
+
this._stopIrqCallbacks();
|
|
711
|
+
this._setState(State.inIdCrc);
|
|
712
|
+
}
|
|
713
|
+
break;
|
|
714
|
+
case State.inIdCrc:
|
|
715
|
+
this._onDiscCrc = ((this._onDiscCrc << 8) | dataByte) & 0xffffffff;
|
|
716
|
+
if (++this._stateCount === 2) {
|
|
717
|
+
// On a real 8271, an ID CRC error seems to end things decisively
|
|
718
|
+
// even if a subsequent ok ID would match.
|
|
719
|
+
if (!this._checkCrc(Result.idCrcError)) {
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
// This is a test for the READ ID command.
|
|
723
|
+
if (this._regs[Registers.internalCommand] === 0x18) {
|
|
724
|
+
this._checkCompletion();
|
|
725
|
+
} else if (this._regs[Registers.internalIdTrack] !== this._regs[Registers.internalParam_1]) {
|
|
726
|
+
// Upon any mismatch of found track vs. expected track, the drive will try
|
|
727
|
+
// twice more on the next two tracks.
|
|
728
|
+
if (++this._regs[Registers.internalSeekRetryCount] === 3) {
|
|
729
|
+
this._finishCommand(Result.sectorNotFound);
|
|
730
|
+
} else {
|
|
731
|
+
this._logCommand("stepping due to track mismatch");
|
|
732
|
+
this._doSeek(Call.unchanged);
|
|
733
|
+
}
|
|
734
|
+
} else if (this._regs[Registers.internalIdSector] === this._regs[Registers.internalParam_2]) {
|
|
735
|
+
this._regs[Registers.internalGap2Skip] = 11;
|
|
736
|
+
if (this._callContext === Call.write) {
|
|
737
|
+
// Set up for the first 5 bytes of the 0x00 sync.
|
|
738
|
+
this._regs[Registers.internalCountMsb] = 0;
|
|
739
|
+
this._regs[Registers.internalCountLsb] = 5;
|
|
740
|
+
}
|
|
741
|
+
this._setState(State.skipGap_2);
|
|
742
|
+
} else {
|
|
743
|
+
this._setState(State.syncingForIdWait);
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
break;
|
|
747
|
+
case State.checkDataMarker:
|
|
748
|
+
if (
|
|
749
|
+
clockByte === IbmDiscFormat.markClockPattern &&
|
|
750
|
+
(dataByte === IbmDiscFormat.dataMarkDataPattern ||
|
|
751
|
+
dataByte === IbmDiscFormat.deletedDataMarkDataPattern)
|
|
752
|
+
) {
|
|
753
|
+
let doIrqs = true;
|
|
754
|
+
if (dataByte === IbmDiscFormat.deletedDataMarkDataPattern) {
|
|
755
|
+
if ((this._regs[Registers.internalCommand] & 0x0f) === 0) doIrqs = false;
|
|
756
|
+
this._setResult(Result.flagDeletedData);
|
|
757
|
+
}
|
|
758
|
+
// No IRQ callbacks if 'verify'.
|
|
759
|
+
if (this._regs[Registers.internalCommand] === 0x1c) doIrqs = false;
|
|
760
|
+
if (doIrqs) this._startIrqCallbacks();
|
|
761
|
+
this._crc = IbmDiscFormat.crcAddByte(IbmDiscFormat.crcInit(false), dataByte);
|
|
762
|
+
this._setState(State.inData);
|
|
763
|
+
} else {
|
|
764
|
+
this._finishCommand(Result.clockError);
|
|
765
|
+
}
|
|
766
|
+
break;
|
|
767
|
+
case State.inData: {
|
|
768
|
+
this._crc = IbmDiscFormat.crcAddByte(this._crc, dataByte);
|
|
769
|
+
if (this._decrementCounter()) {
|
|
770
|
+
this._onDiscCrc = 0;
|
|
771
|
+
this._setState(State.inDataCrc);
|
|
772
|
+
}
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
case State.inDataCrc:
|
|
776
|
+
this._onDiscCrc = ((this._onDiscCrc << 8) | dataByte) & 0xffffffff;
|
|
777
|
+
if (++this._stateCount === 2) {
|
|
778
|
+
if (!this._checkCrc(Result.dataCrcError)) break;
|
|
779
|
+
this._checkCompletion();
|
|
780
|
+
}
|
|
781
|
+
break;
|
|
782
|
+
default:
|
|
783
|
+
throw new Error(`Unexpected state ${this._state}`);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
_callbackWriteRun() {
|
|
788
|
+
if (!this._decrementCounter()) {
|
|
789
|
+
this._mmioData = this._regs[Registers.internalWriteRunData];
|
|
790
|
+
this._crc = IbmDiscFormat.crcAddByte(this._crc, this._mmioData);
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
switch (this._callContext) {
|
|
794
|
+
case Call.write:
|
|
795
|
+
this._mmioData = 0;
|
|
796
|
+
this._startIrqCallbacks();
|
|
797
|
+
this._setState(State.writeDataMark);
|
|
798
|
+
break;
|
|
799
|
+
case Call.formatGap1OrGap3FFs:
|
|
800
|
+
// Flip from writing ffs to 00s.
|
|
801
|
+
this._regs[Registers.internalCountLsb] = 5;
|
|
802
|
+
this._doWriteRun(Call.formatGap1orGap300s, 0x00);
|
|
803
|
+
break;
|
|
804
|
+
case Call.formatGap1orGap300s:
|
|
805
|
+
this._mmioData = 0x00;
|
|
806
|
+
this._startIrqCallbacks();
|
|
807
|
+
this._setState(State.formatWriteIdMarker);
|
|
808
|
+
break;
|
|
809
|
+
case Call.formatGap2_FFs:
|
|
810
|
+
// Flip from writing ffs to 00s.
|
|
811
|
+
this._regs[Registers.internalCountLsb] = 5;
|
|
812
|
+
this._doWriteRun(Call.formatGap2_00s, 0x00);
|
|
813
|
+
break;
|
|
814
|
+
case Call.formatGap2_00s:
|
|
815
|
+
this._mmioData = 0;
|
|
816
|
+
this._setState(State.formatWriteDataMarker);
|
|
817
|
+
break;
|
|
818
|
+
case Call.formatData:
|
|
819
|
+
this._mmioData = (this._crc >>> 8) & 0xff;
|
|
820
|
+
this._setState(State.formatDataCrc_2);
|
|
821
|
+
break;
|
|
822
|
+
default:
|
|
823
|
+
throw new Error(`Unexpected call context ${this._callContext}`);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
_callbackDynamicDispatch() {
|
|
828
|
+
const routine = this._regs[Registers.internalDynamicDispatch]++;
|
|
829
|
+
switch (routine) {
|
|
830
|
+
// Routines 0 - 2 used for write sector.
|
|
831
|
+
case 0:
|
|
832
|
+
this._crc = IbmDiscFormat.crcAddByte(this._crc, this._mmioData);
|
|
833
|
+
break;
|
|
834
|
+
case 1:
|
|
835
|
+
this._mmioData = (this._crc >>> 8) & 0xff;
|
|
836
|
+
this._setState(State.writeCrc_2);
|
|
837
|
+
break;
|
|
838
|
+
case 2:
|
|
839
|
+
this._checkCompletion();
|
|
840
|
+
break;
|
|
841
|
+
// Routines 4 - 11 used for format.
|
|
842
|
+
// 4 - 7 write the 4 user-supplied sector header bytes.
|
|
843
|
+
case 4:
|
|
844
|
+
this._mmioClocks = 0xff;
|
|
845
|
+
// fallthrough
|
|
846
|
+
case 5:
|
|
847
|
+
case 6:
|
|
848
|
+
case 7:
|
|
849
|
+
if (routine === 6) this._stopIrqCallbacks();
|
|
850
|
+
this._crc = IbmDiscFormat.crcAddByte(this._crc, this._mmioData);
|
|
851
|
+
break;
|
|
852
|
+
// write the sector header CRC
|
|
853
|
+
case 8:
|
|
854
|
+
this._mmioData = (this._crc >>> 8) & 0xff;
|
|
855
|
+
this._setState(State.formatIdCrc_2);
|
|
856
|
+
break;
|
|
857
|
+
// write GAP2
|
|
858
|
+
case 9:
|
|
859
|
+
// This value 10 is GAP2 0xff length minus 1. The CRC generator emits a third
|
|
860
|
+
// byte of 0xff.
|
|
861
|
+
// The other -1 here is because we will we set the count registers ourselves. In the ROM,
|
|
862
|
+
// LSB is written here but not MSB.
|
|
863
|
+
this._regs[Registers.internalCountLsb] = 10;
|
|
864
|
+
this._writeFFsAnd00s(Call.formatGap2_FFs, -1);
|
|
865
|
+
break;
|
|
866
|
+
case 10:
|
|
867
|
+
this._resetSectorByteCount();
|
|
868
|
+
this._doWriteRun(Call.formatData, 0xe5);
|
|
869
|
+
break;
|
|
870
|
+
// 11 is after the sector data CRC is written.
|
|
871
|
+
case 11:
|
|
872
|
+
this._mmioData = 0xff;
|
|
873
|
+
if ((--this._regs[Registers.internalParam_3] & 0x1f) === 0) {
|
|
874
|
+
// Format sectors done. Write GAP4 until end of track.
|
|
875
|
+
// Reset param 3 to 1, to ensure immediate exit in the command exit
|
|
876
|
+
// path in intel_fdc_check_completion().
|
|
877
|
+
this._regs[Registers.internalParam_3] = 1;
|
|
878
|
+
this._indexPulseCallback = IndexPulse.stopFormat;
|
|
879
|
+
this._setState(State.formatGap_4);
|
|
880
|
+
} else {
|
|
881
|
+
// Format sectors not done. Next one. Reset state machine index, param2 is GAP3.
|
|
882
|
+
this._regs[Registers.internalDynamicDispatch] = 4;
|
|
883
|
+
this._writeFFsAnd00s(Call.formatGap1OrGap3FFs, this._regs[Registers.internalParam_2]);
|
|
884
|
+
}
|
|
885
|
+
break;
|
|
886
|
+
default:
|
|
887
|
+
throw new Error(`Dodgy routine number ${routine}`);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
_byteCallbackWriting() {
|
|
892
|
+
if (this._irqCallbacks) {
|
|
893
|
+
if (!this._checkDataLossOk()) return;
|
|
894
|
+
this._statusRaise(StatusFlag.nmi | StatusFlag.needData);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
switch (this._state) {
|
|
898
|
+
case State.writeRun:
|
|
899
|
+
this._callbackWriteRun();
|
|
900
|
+
break;
|
|
901
|
+
case State.writeDataMark:
|
|
902
|
+
this._mmioData = this._regs[Registers.internalParamDataMarker];
|
|
903
|
+
this._crc = IbmDiscFormat.crcAddByte(IbmDiscFormat.crcInit(false), this._mmioData);
|
|
904
|
+
this._mmioClocks = IbmDiscFormat.markClockPattern;
|
|
905
|
+
this._resetSectorByteCount(); /////
|
|
906
|
+
// This strange decrement is how the ROM does it.
|
|
907
|
+
this._regs[Registers.internalCountLsb]--;
|
|
908
|
+
this._setState(State.writeSectorData);
|
|
909
|
+
break;
|
|
910
|
+
case State.writeSectorData:
|
|
911
|
+
this._mmioClocks = 0xff;
|
|
912
|
+
this._crc = IbmDiscFormat.crcAddByte(this._crc, this._mmioData);
|
|
913
|
+
if (this._decrementCounter()) {
|
|
914
|
+
this._regs[Registers.internalDynamicDispatch] = 0;
|
|
915
|
+
this._setState(State.dynamicDispatch);
|
|
916
|
+
}
|
|
917
|
+
break;
|
|
918
|
+
case State.writeCrc_2:
|
|
919
|
+
this._mmioData = this._crc & 0xff;
|
|
920
|
+
this._setState(State.writeCrc_3);
|
|
921
|
+
break;
|
|
922
|
+
case State.writeCrc_3:
|
|
923
|
+
this._mmioData = 0xff;
|
|
924
|
+
this._setState(State.dynamicDispatch);
|
|
925
|
+
break;
|
|
926
|
+
case State.dynamicDispatch:
|
|
927
|
+
this._callbackDynamicDispatch();
|
|
928
|
+
break;
|
|
929
|
+
case State.formatWriteIdMarker:
|
|
930
|
+
this._mmioData = IbmDiscFormat.idMarkDataPattern;
|
|
931
|
+
this._mmioClocks = IbmDiscFormat.markClockPattern;
|
|
932
|
+
this._crc = IbmDiscFormat.crcAddByte(IbmDiscFormat.crcInit(false), this._mmioData);
|
|
933
|
+
this._setState(State.dynamicDispatch);
|
|
934
|
+
break;
|
|
935
|
+
case State.formatIdCrc_2:
|
|
936
|
+
this._mmioData = this._crc & 0xff;
|
|
937
|
+
this._setState(State.formatIdCrc_3);
|
|
938
|
+
break;
|
|
939
|
+
case State.formatIdCrc_3:
|
|
940
|
+
this._mmioData = 0xff;
|
|
941
|
+
this._setState(State.dynamicDispatch);
|
|
942
|
+
break;
|
|
943
|
+
case State.formatWriteDataMarker:
|
|
944
|
+
this._mmioData = IbmDiscFormat.dataMarkDataPattern;
|
|
945
|
+
this._mmioClocks = IbmDiscFormat.markClockPattern;
|
|
946
|
+
this._crc = IbmDiscFormat.crcAddByte(IbmDiscFormat.crcInit(false), this._mmioData);
|
|
947
|
+
this._setState(State.dynamicDispatch);
|
|
948
|
+
break;
|
|
949
|
+
case State.formatDataCrc_2:
|
|
950
|
+
this._mmioData = this._crc & 0xff;
|
|
951
|
+
this._setState(State.formatDataCrc_3);
|
|
952
|
+
break;
|
|
953
|
+
case State.formatDataCrc_3:
|
|
954
|
+
this._mmioData = 0xff;
|
|
955
|
+
this._setState(State.dynamicDispatch);
|
|
956
|
+
break;
|
|
957
|
+
case State.formatGap_4:
|
|
958
|
+
// GAP 4 writes until the index pulse, handled in the callback there.
|
|
959
|
+
this._mmioData = 0xff;
|
|
960
|
+
break;
|
|
961
|
+
default:
|
|
962
|
+
throw new Error(`Bad write state ${this._state}`);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
_resetSectorByteCount() {
|
|
967
|
+
this._regs[Registers.internalCountMsb] = this._regs[Registers.internalCountMsbCopy];
|
|
968
|
+
this._regs[Registers.internalCountLsb] = 0x80;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
_checkCompletion() {
|
|
972
|
+
if (!this._checkDriveReady()) return;
|
|
973
|
+
|
|
974
|
+
// Lower write enable.
|
|
975
|
+
this._driveOutLower(DriveOut.writeEnable);
|
|
976
|
+
this._clearCallbacks();
|
|
977
|
+
|
|
978
|
+
// One less sector to go. Specifying 0 sectors seems to result in 32 read, due
|
|
979
|
+
// to underflow of the 5-bit counter. On commands other than read id, any underflow
|
|
980
|
+
// has other side effects such as modifying the sector size.
|
|
981
|
+
if ((--this._regs[Registers.internalParam_3] & 0x1f) === 0) {
|
|
982
|
+
this._finishCommand(Result.ok);
|
|
983
|
+
} else {
|
|
984
|
+
// This looks strange as it is set up to be just an increment (R4==1 in sector
|
|
985
|
+
// operations). but it's what the 8271 ROM does.
|
|
986
|
+
this._regs[Registers.internalParam_2] += this._regs[Registers.internalParam_4] & 0x3f;
|
|
987
|
+
// This is also what the 8271 ROM does, just re-dispatches the current command.
|
|
988
|
+
this._doCommandDispatch();
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* @param {Result|Number} error error if invalid
|
|
994
|
+
*/
|
|
995
|
+
_checkCrc(error) {
|
|
996
|
+
if (this._crc === this._onDiscCrc) return true;
|
|
997
|
+
this._finishCommand(error);
|
|
998
|
+
return false;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
_statusRaise(statusFlags) {
|
|
1002
|
+
this._regs[Registers.internalStatus] |= statusFlags;
|
|
1003
|
+
if (statusFlags & StatusFlag.nmi) {
|
|
1004
|
+
this._updateNmi();
|
|
1005
|
+
}
|
|
1006
|
+
this._updateExternalStatus();
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
_statusLower(statusFlags) {
|
|
1010
|
+
this._regs[Registers.internalStatus] &= ~statusFlags;
|
|
1011
|
+
if (statusFlags & StatusFlag.nmi) {
|
|
1012
|
+
this._updateNmi();
|
|
1013
|
+
}
|
|
1014
|
+
this._updateExternalStatus();
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
_setResult(result) {
|
|
1018
|
+
this._regs[Registers.internalResult] = result;
|
|
1019
|
+
this._isResultReady = true;
|
|
1020
|
+
this._updateExternalStatus();
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
get _result() {
|
|
1024
|
+
return this._regs[Registers.internalResult];
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
_updateNmi() {
|
|
1028
|
+
const status = this.internalStatus;
|
|
1029
|
+
const level = !!(status & StatusFlag.nmi);
|
|
1030
|
+
if (this._cpu.nmi && level) {
|
|
1031
|
+
this._log("edge triggered NMI already high");
|
|
1032
|
+
}
|
|
1033
|
+
this._cpu.NMI(level);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
_updateExternalStatus() {
|
|
1037
|
+
// EMU NOTE: currently, the emulation responds instantly to getting commands
|
|
1038
|
+
// started, accepting parameters, transitioning between states, etc.
|
|
1039
|
+
// This is inaccurate.
|
|
1040
|
+
// The real 8271 is an asynchronously running general purpose microcontroller,
|
|
1041
|
+
// where each instruction takes 2us+ and processing between states uses a
|
|
1042
|
+
// large and variable number of instructions.
|
|
1043
|
+
// Some food for though, latency timings on a BBC + 8271, including setup:
|
|
1044
|
+
// WRITE SPECIAL REGISTER: 211us
|
|
1045
|
+
// WRITE SPECIAL REGISTER (0 param version): 157us
|
|
1046
|
+
// READ DRIVE STATUS: 188us
|
|
1047
|
+
// write $35 to parameter register: 31us
|
|
1048
|
+
// write 3rd SPECIFY parameter: 27us
|
|
1049
|
+
let status = this.internalStatus;
|
|
1050
|
+
// The internal status register appears to be shared with some mode bits that
|
|
1051
|
+
// must be masked out.
|
|
1052
|
+
status &= ~0x03;
|
|
1053
|
+
// Current best thinking is that the internal register uses bit value 0x10 for
|
|
1054
|
+
// something different, and that "result ready" is maintained by the external
|
|
1055
|
+
// register logic.
|
|
1056
|
+
status &= ~StatusFlag.resultReady;
|
|
1057
|
+
if (this._isResultReady) {
|
|
1058
|
+
status |= StatusFlag.resultReady;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// TODO: "command register full", bit value 0x40, isn't understood. In
|
|
1062
|
+
// particular, the mode register (shared with the status register we
|
|
1063
|
+
// believe) is set to 0xC1 in typical operation. This would seem to raise
|
|
1064
|
+
// 0x40 after it has been lowered at command register acceptance. However,
|
|
1065
|
+
// the bit is not returned.
|
|
1066
|
+
// Don't return it, ever, for now.
|
|
1067
|
+
// Also avoid "parameter register full".
|
|
1068
|
+
status &= ~0x60;
|
|
1069
|
+
|
|
1070
|
+
this._status = status;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
_commandWritten(command) {
|
|
1074
|
+
const status = this.internalStatus;
|
|
1075
|
+
if (status & StatusFlag.busy) {
|
|
1076
|
+
this._log(
|
|
1077
|
+
`command ${utils.hexbyte(command)} while busy with ${utils.hexbyte(this._regs[Registers.internalCommand])}`,
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
// Set command.
|
|
1082
|
+
this._regs[Registers.internalCommand] = command;
|
|
1083
|
+
|
|
1084
|
+
// Set busy, lower command full in status, result to 0.
|
|
1085
|
+
this._statusRaise(StatusFlag.busy);
|
|
1086
|
+
this._statusLower(StatusFlag.commandFull);
|
|
1087
|
+
this._setResult(0);
|
|
1088
|
+
|
|
1089
|
+
// Default parameters. This supports the 1x128 byte sector commands.
|
|
1090
|
+
this._regs[Registers.internalParam_3] = 1;
|
|
1091
|
+
this._regs[Registers.internalParam_4] = 1;
|
|
1092
|
+
|
|
1093
|
+
// Calculate parameters expected. Taken from the logic in the 8271 ROM.
|
|
1094
|
+
const numParams = command & 0x18 ? command & 0x3 : 5;
|
|
1095
|
+
this._regs[Registers.internalParamCount] = numParams;
|
|
1096
|
+
|
|
1097
|
+
// Are we waiting for parameters?
|
|
1098
|
+
if (numParams) {
|
|
1099
|
+
// Parameters write from R7 downwards.
|
|
1100
|
+
this._regs[Registers.internalPointer] = Registers.internalParam_1;
|
|
1101
|
+
this._paramCallback = ParamAccept.command;
|
|
1102
|
+
} else {
|
|
1103
|
+
this._startCommand();
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
_resultConsumed() {
|
|
1108
|
+
this._isResultReady = false;
|
|
1109
|
+
this._updateExternalStatus();
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
_paramWritten(param) {
|
|
1113
|
+
this._regs[Registers.internalParameter] = param;
|
|
1114
|
+
this._resultConsumed();
|
|
1115
|
+
|
|
1116
|
+
switch (this._paramCallback) {
|
|
1117
|
+
case ParamAccept.none:
|
|
1118
|
+
break;
|
|
1119
|
+
case ParamAccept.command: {
|
|
1120
|
+
this._writeRegister(this._regs[Registers.internalPointer], param);
|
|
1121
|
+
--this._regs[Registers.internalPointer];
|
|
1122
|
+
if (--this._regs[Registers.internalParamCount] === 0) {
|
|
1123
|
+
this._startCommand();
|
|
1124
|
+
}
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
case ParamAccept.specify: {
|
|
1128
|
+
this._logCommand(`specify param ${utils.hexbyte(param)}`);
|
|
1129
|
+
this._writeRegister(this._regs[Registers.internalPointer], param);
|
|
1130
|
+
++this._regs[Registers.internalPointer];
|
|
1131
|
+
if (--this._regs[Registers.internalParamCount] === 0) {
|
|
1132
|
+
this._finishSimpleCommand();
|
|
1133
|
+
}
|
|
1134
|
+
break;
|
|
1135
|
+
}
|
|
1136
|
+
default:
|
|
1137
|
+
throw new Error(`Unexpected param callback ${this._paramCallback}`);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
_readRegister(reg) {
|
|
1142
|
+
reg &= 0x3f;
|
|
1143
|
+
if (reg < IntelFdc.NumRegisters) {
|
|
1144
|
+
return this._regs[reg];
|
|
1145
|
+
}
|
|
1146
|
+
reg &= 0x07;
|
|
1147
|
+
switch (reg) {
|
|
1148
|
+
case Registers.mmioDriveIn & 0x07:
|
|
1149
|
+
return this._driveIn;
|
|
1150
|
+
case Registers.mmioDriveOut & 0x07:
|
|
1151
|
+
// DFS-1.2 reads drive out in normal operation.
|
|
1152
|
+
return this._driveOut;
|
|
1153
|
+
case Registers.mmioClocks & 0x07:
|
|
1154
|
+
return this._mmioClocks;
|
|
1155
|
+
case Registers.mmioData & 0x07:
|
|
1156
|
+
return this._mmioData;
|
|
1157
|
+
default:
|
|
1158
|
+
this._log(`direct read from MMIO register ${utils.hexbyte(reg)}`);
|
|
1159
|
+
break;
|
|
1160
|
+
}
|
|
1161
|
+
return 0;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
_writeRegister(reg, val) {
|
|
1165
|
+
reg &= 0x3f;
|
|
1166
|
+
if (reg < IntelFdc.NumRegisters) {
|
|
1167
|
+
this._regs[reg] = val;
|
|
1168
|
+
return;
|
|
1169
|
+
}
|
|
1170
|
+
reg &= 0x07;
|
|
1171
|
+
switch (reg) {
|
|
1172
|
+
case Registers.mmioDriveOut & 0x07:
|
|
1173
|
+
// Bit 0x20 is important as it's used to select the side of the disc for
|
|
1174
|
+
// double-sided discs.
|
|
1175
|
+
// Bit 0x08 is important as it provides manual head load / unload control,
|
|
1176
|
+
// which includes motor spin up / down.
|
|
1177
|
+
// The parameter also includes drive select bits which override those in
|
|
1178
|
+
// the command.
|
|
1179
|
+
this._setDriveOut(val);
|
|
1180
|
+
break;
|
|
1181
|
+
case Registers.mmioClocks & 0x07:
|
|
1182
|
+
this._mmioClocks = val;
|
|
1183
|
+
break;
|
|
1184
|
+
case Registers.mmioData & 0x07:
|
|
1185
|
+
this._mmioData = val;
|
|
1186
|
+
break;
|
|
1187
|
+
default:
|
|
1188
|
+
this._log(`direct write to MMIO register ${utils.hexbyte(reg)}`);
|
|
1189
|
+
break;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
_driveOutRaise(bits) {
|
|
1194
|
+
this._setDriveOut(bits | this._driveOut);
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
_driveOutLower(bits) {
|
|
1198
|
+
this._setDriveOut(this._driveOut & ~bits);
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* @param {DriveOut|Number} driveOut
|
|
1203
|
+
*/
|
|
1204
|
+
_setDriveOut(driveOut) {
|
|
1205
|
+
if (this._currentDrive) this._currentDrive.stopSpinning();
|
|
1206
|
+
this._currentDrive = null;
|
|
1207
|
+
|
|
1208
|
+
// Note: unclear what to do if both drives are selected. We select no drive
|
|
1209
|
+
// for now, to avoid shenanigans.
|
|
1210
|
+
const selectBits = driveOut & DriveOut.selectFlags;
|
|
1211
|
+
if (selectBits === DriveOut.select_0) this._currentDrive = this._drives[0];
|
|
1212
|
+
else if (selectBits === DriveOut.select_1) this._currentDrive = this._drives[1];
|
|
1213
|
+
|
|
1214
|
+
if (this._currentDrive) {
|
|
1215
|
+
if (driveOut & DriveOut.loadHead) this._currentDrive.startSpinning();
|
|
1216
|
+
this._currentDrive.selectSide(!!(driveOut & DriveOut.side));
|
|
1217
|
+
}
|
|
1218
|
+
this._driveOut = driveOut;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* @param {State|Number} state
|
|
1223
|
+
*/
|
|
1224
|
+
_setState(state) {
|
|
1225
|
+
if (this._state !== state && this._logStateChanges) {
|
|
1226
|
+
this._log(`State ${this._state} -> ${state}`);
|
|
1227
|
+
}
|
|
1228
|
+
this._state = state;
|
|
1229
|
+
this._stateCount = 0;
|
|
1230
|
+
if (state === State.syncingForId || state === State.syncingForData) {
|
|
1231
|
+
this._shiftRegister = 0;
|
|
1232
|
+
this._numShifts = 0;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
/**
|
|
1237
|
+
* @param {Call|Number} callContext
|
|
1238
|
+
*/
|
|
1239
|
+
_doSeek(callContext) {
|
|
1240
|
+
if (callContext !== Call.unchanged) this._callContext = callContext;
|
|
1241
|
+
let newTrack = this._regs[Registers.internalParam_1] + this._regs[Registers.internalSeekRetryCount];
|
|
1242
|
+
const trackRegOffset =
|
|
1243
|
+
this._driveOut & DriveOut.select_1 ? Registers.badTrack_1Drive_1 : Registers.badTrack_1Drive_0;
|
|
1244
|
+
// Add one to requested track for each bad track covered. */
|
|
1245
|
+
// EMU NOTE: this is based on a disassembly of the real 8271 ROM and yes,
|
|
1246
|
+
// integer overflow does occur!
|
|
1247
|
+
if (newTrack > 0) {
|
|
1248
|
+
if (this._regs[trackRegOffset + 0] <= newTrack) {
|
|
1249
|
+
newTrack = (newTrack + 1) & 0xff;
|
|
1250
|
+
}
|
|
1251
|
+
if (this._regs[trackRegOffset + 1] <= newTrack) {
|
|
1252
|
+
newTrack = (newTrack + 1) & 0xff;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
this._regs[Registers.internalSeekTarget_1] = newTrack;
|
|
1256
|
+
this._regs[Registers.internalSeekTarget_2] = newTrack;
|
|
1257
|
+
// Set low head current in drive output depending on track.
|
|
1258
|
+
if (newTrack >= 43) this._driveOut |= DriveOut.lowHeadCurrent;
|
|
1259
|
+
else this._driveOut &= ~DriveOut.lowHeadCurrent;
|
|
1260
|
+
// Work out seek direction and total number of steps. Pretend current track is 255 if a seek to 0.
|
|
1261
|
+
const curTrack = newTrack === 0 ? 255 : this._regs[trackRegOffset + 2];
|
|
1262
|
+
this._didSeekStep = false;
|
|
1263
|
+
|
|
1264
|
+
// Skip to head load if there's no seek.
|
|
1265
|
+
if (newTrack === curTrack) {
|
|
1266
|
+
this._doLoadHead();
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
if (newTrack > curTrack) {
|
|
1271
|
+
this._regs[Registers.internalSeekCount] = newTrack - curTrack;
|
|
1272
|
+
this._driveOut |= DriveOut.direction;
|
|
1273
|
+
} else {
|
|
1274
|
+
this._regs[Registers.internalSeekCount] = curTrack - newTrack;
|
|
1275
|
+
this._driveOut &= ~DriveOut.direction;
|
|
1276
|
+
}
|
|
1277
|
+
if (this._currentDrive) this._currentDrive.notifySeek(newTrack);
|
|
1278
|
+
|
|
1279
|
+
// Seek pulses on the 8271 are about 10us, so let's just lower the output bit and make them unobservable
|
|
1280
|
+
// as we suspect they are on a real machine.
|
|
1281
|
+
this._driveOut &= ~DriveOut.step;
|
|
1282
|
+
// Current track registers are updated here before the actual step sequence.
|
|
1283
|
+
this._regs[trackRegOffset + 2] = this._regs[Registers.internalSeekTarget_2];
|
|
1284
|
+
// Update both track registers if "single actuator" flag is set.
|
|
1285
|
+
if (this._regs[Registers.mode] & FdcMode.singleActuator) {
|
|
1286
|
+
this._regs[Registers.trackDrive_0] = this._regs[Registers.internalSeekTarget_2];
|
|
1287
|
+
this._regs[Registers.trackDrive_1] = this._regs[Registers.internalSeekTarget_2];
|
|
1288
|
+
}
|
|
1289
|
+
this._doSeekStep();
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
_doSeekStep() {
|
|
1293
|
+
if (
|
|
1294
|
+
(this._trk0 && this._regs[Registers.internalSeekTarget_2] === 0) || // Seek to 0 done, TRK0 detected
|
|
1295
|
+
this._regs[Registers.internalSeekCount] === 0
|
|
1296
|
+
) {
|
|
1297
|
+
this._doLoadHead();
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
// We're going to actually step, so we'll need settle if the head is already loaded.
|
|
1301
|
+
this._didSeekStep = true;
|
|
1302
|
+
this._regs[Registers.internalSeekCount]--;
|
|
1303
|
+
|
|
1304
|
+
if (this._currentDrive) this._currentDrive.seekOneTrack(this._driveOut & DriveOut.direction ? 1 : -1);
|
|
1305
|
+
|
|
1306
|
+
let stepRate = this._regs[Registers.headStepRate];
|
|
1307
|
+
if (stepRate === 0) {
|
|
1308
|
+
// Step rate is up to the drive. Let's say 3ms.
|
|
1309
|
+
stepRate = 3;
|
|
1310
|
+
} else {
|
|
1311
|
+
// The datasheet is ambiguous about whether the units are 1ms or 2ms for 5.25" drives. 1ms might
|
|
1312
|
+
// be your best guess from the datasheet, but timing on a real machine, it appears to be 2ms.
|
|
1313
|
+
stepRate *= 2;
|
|
1314
|
+
}
|
|
1315
|
+
this._setTimerMs(TimerState.seekStep, stepRate);
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
_doLoadHead() {
|
|
1319
|
+
let postSeekTimeMs = 0;
|
|
1320
|
+
// The head load time replaces the settle time if there is both.
|
|
1321
|
+
if (!(this._driveOut & DriveOut.loadHead)) {
|
|
1322
|
+
this._driveOutRaise(DriveOut.loadHead);
|
|
1323
|
+
// Head load units are 4ms.
|
|
1324
|
+
postSeekTimeMs = 4 * (this._regs[Registers.headLoadUnload] & 0xf);
|
|
1325
|
+
} else if (this._didSeekStep) {
|
|
1326
|
+
// All references state the units are 2ms for 5.25" drives.
|
|
1327
|
+
postSeekTimeMs = 2 * this._regs[Registers.headSettleTime];
|
|
1328
|
+
}
|
|
1329
|
+
if (postSeekTimeMs) {
|
|
1330
|
+
this._setTimerMs(TimerState.postSeek, postSeekTimeMs);
|
|
1331
|
+
} else {
|
|
1332
|
+
this._postSeekDispatch();
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
_postSeekDispatch() {
|
|
1337
|
+
this._timerState = TimerState.none;
|
|
1338
|
+
if (!this._checkDriveReady()) return;
|
|
1339
|
+
switch (this._callContext) {
|
|
1340
|
+
case Call.seek:
|
|
1341
|
+
this._finishCommand(Result.ok);
|
|
1342
|
+
break;
|
|
1343
|
+
case Call.readId:
|
|
1344
|
+
this._indexPulseCallback = IndexPulse.startReadId;
|
|
1345
|
+
break;
|
|
1346
|
+
case Call.format:
|
|
1347
|
+
this._setupSectorSize();
|
|
1348
|
+
this._indexPulseCallback = IndexPulse.startFormat;
|
|
1349
|
+
this._checkWriteProtect();
|
|
1350
|
+
break;
|
|
1351
|
+
case Call.read:
|
|
1352
|
+
case Call.write:
|
|
1353
|
+
this._setupSectorSize();
|
|
1354
|
+
this._startIndexPulseTimeout();
|
|
1355
|
+
this._startSyncingForHeader();
|
|
1356
|
+
if (this._callContext === Call.write) this._checkWriteProtect();
|
|
1357
|
+
break;
|
|
1358
|
+
default:
|
|
1359
|
+
throw new Error(`Surprising call context post seek ${this._callContext}`);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
get _sectorSize() {
|
|
1364
|
+
const size = this._regs[Registers.internalParam_3] >>> 5;
|
|
1365
|
+
return 128 << size;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
_setupSectorSize() {
|
|
1369
|
+
const msb = (this._sectorSize >>> 7) - 1;
|
|
1370
|
+
this._regs[Registers.internalCountLsb] = 0x80;
|
|
1371
|
+
this._regs[Registers.internalCountMsb] = msb;
|
|
1372
|
+
// Note the is R0, i.e. R0 is trashed here.
|
|
1373
|
+
this._regs[Registers.internalCountMsbCopy] = msb;
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
_setTimerMs(state, timerMs) {
|
|
1377
|
+
this._timerTask.cancel();
|
|
1378
|
+
this._timerState = state;
|
|
1379
|
+
this._timerTask.schedule(timerMs * 2000);
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
_startIndexPulseTimeout() {
|
|
1383
|
+
this._regs[Registers.internalIndexPulseCount] = 3;
|
|
1384
|
+
this._indexPulseCallback = IndexPulse.timeout;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
_startSyncingForHeader() {
|
|
1388
|
+
this._regs[Registers.internalHeaderPointer] = 0x0c;
|
|
1389
|
+
this._setState(State.syncingForId);
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
_checkDriveReady() {
|
|
1393
|
+
this._doReadDriveStatus();
|
|
1394
|
+
const mask = this._driveOut & DriveOut.select_1 ? 0x40 : 0x04;
|
|
1395
|
+
if (!(this._regs[Registers.internalDriveInLatched] & mask)) {
|
|
1396
|
+
this._finishCommand(Result.driveNotReady);
|
|
1397
|
+
return false;
|
|
1398
|
+
}
|
|
1399
|
+
return true;
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
_checkWriteProtect() {
|
|
1403
|
+
if (this._regs[Registers.internalDriveInLatched] & 0x08) {
|
|
1404
|
+
this._finishCommand(Result.writeProtected);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
_startCommand() {
|
|
1409
|
+
let commandReg = this._regs[Registers.internalCommand];
|
|
1410
|
+
const origCommand = commandReg;
|
|
1411
|
+
|
|
1412
|
+
// This update R21 and R27. R27 is later referenced for checking the write protect bit.
|
|
1413
|
+
this._doReadDriveStatus();
|
|
1414
|
+
|
|
1415
|
+
this._paramCallback = ParamAccept.none;
|
|
1416
|
+
|
|
1417
|
+
// Select the drive before logging so that head position is reported.
|
|
1418
|
+
// The MMIO clocks register really is used as a temporary storage for this.
|
|
1419
|
+
const selectBits = commandReg & DriveOut.selectFlags;
|
|
1420
|
+
this._mmioClocks = selectBits;
|
|
1421
|
+
if (selectBits !== (this._driveOut & DriveOut.selectFlags)) {
|
|
1422
|
+
// A change of drive select bits clears all drive out bits other than side select.
|
|
1423
|
+
// For example, the newly selected drive won't have the load head signal
|
|
1424
|
+
// active. This spins down any previously selected drive.
|
|
1425
|
+
const newSelectBits = selectBits | (this._driveOut & DriveOut.side);
|
|
1426
|
+
this._setDriveOut(newSelectBits);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// Mask out drive select bits from the command register, and parameter count.
|
|
1430
|
+
commandReg &= ~(DriveOut.selectFlags | 0x03);
|
|
1431
|
+
this._regs[Registers.internalCommand] = commandReg;
|
|
1432
|
+
this._logCommand(
|
|
1433
|
+
`command ${utils.hexbyte(origCommand & 0x3f)} ` +
|
|
1434
|
+
`sel ${utils.hexbyte(selectBits)} ` +
|
|
1435
|
+
`params ${utils.hexbyte(this._regs[Registers.internalParam_1])} ` +
|
|
1436
|
+
`${utils.hexbyte(this._regs[Registers.internalParam_2])} ` +
|
|
1437
|
+
`${utils.hexbyte(this._regs[Registers.internalParam_3])} ` +
|
|
1438
|
+
`${utils.hexbyte(this._regs[Registers.internalParam_4])} ` +
|
|
1439
|
+
`${utils.hexbyte(this._regs[Registers.internalParam_5])} ` +
|
|
1440
|
+
`ptrk ${this._currentDrive ? this._currentDrive.track : -1} ` +
|
|
1441
|
+
`hpos ${this._currentDrive ? this._currentDrive.headPosition : -1}`,
|
|
1442
|
+
);
|
|
1443
|
+
|
|
1444
|
+
const command = this._internalCommand;
|
|
1445
|
+
if (command === Command.scanData || command === Command.scanDataAndDeleted) {
|
|
1446
|
+
this._log("scan sectors doesn't work in a beeb");
|
|
1447
|
+
}
|
|
1448
|
+
this._doCommandDispatch();
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
get _internalCommand() {
|
|
1452
|
+
return (this._regs[Registers.internalCommand] & ~(DriveOut.selectFlags | 0x03)) >>> 2;
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
get _currentDiscIsSpinning() {
|
|
1456
|
+
return this._currentDrive ? this._currentDrive.spinning : false;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
get _trk0() {
|
|
1460
|
+
return this._currentDrive ? this._currentDrive.track === 0 : false;
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
get _index() {
|
|
1464
|
+
return this._currentDrive ? this._currentDrive.indexPulse : false;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
get _wrProt() {
|
|
1468
|
+
// A real drive would likely return `true` if no disc was inserted.
|
|
1469
|
+
return this._currentDrive ? this._currentDrive.writeProtect : false;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
get _driveIn() {
|
|
1473
|
+
// Note: on @scarybeasts machine, bit 7 and bit 0 appear to be always set.
|
|
1474
|
+
let driveIn = 0x81;
|
|
1475
|
+
if (this._currentDiscIsSpinning) {
|
|
1476
|
+
// TRK0
|
|
1477
|
+
if (this._trk0) driveIn |= 0x02;
|
|
1478
|
+
// RDY0
|
|
1479
|
+
if (this._driveOut & DriveOut.select_0) driveIn |= 0x04;
|
|
1480
|
+
// RDY1
|
|
1481
|
+
if (this._driveOut & DriveOut.select_1) driveIn |= 0x40;
|
|
1482
|
+
// WR PROT
|
|
1483
|
+
if (this._wrProt) driveIn |= 0x08;
|
|
1484
|
+
// INDEX
|
|
1485
|
+
if (this._index) driveIn |= 0x10;
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
return driveIn;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
_doReadDriveStatus() {
|
|
1492
|
+
let driveIn = this._driveIn;
|
|
1493
|
+
this._regs[Registers.internalDriveInCopy] = driveIn;
|
|
1494
|
+
this._regs[Registers.internalDriveInLatched] |= 0xbb;
|
|
1495
|
+
driveIn &= this._regs[Registers.internalDriveInLatched];
|
|
1496
|
+
this._regs[Registers.internalDriveInLatched] = driveIn;
|
|
1497
|
+
return driveIn;
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
_doCommandDispatch() {
|
|
1501
|
+
const command = this._internalCommand;
|
|
1502
|
+
|
|
1503
|
+
switch (command) {
|
|
1504
|
+
case Command.unused_9:
|
|
1505
|
+
case Command.unused_12:
|
|
1506
|
+
throw new Error("Unused 8271 command");
|
|
1507
|
+
case Command.readDriveStatus: {
|
|
1508
|
+
const status = this._doReadDriveStatus();
|
|
1509
|
+
this._setResult(status);
|
|
1510
|
+
this._regs[Registers.internalDriveInLatched] = this._regs[Registers.internalDriveInCopy];
|
|
1511
|
+
this._finishSimpleCommand();
|
|
1512
|
+
break;
|
|
1513
|
+
}
|
|
1514
|
+
case Command.specify:
|
|
1515
|
+
this._regs[Registers.internalPointer] = this._regs[Registers.internalParam_1];
|
|
1516
|
+
this._regs[Registers.internalParamCount] = 3;
|
|
1517
|
+
this._paramCallback = ParamAccept.specify;
|
|
1518
|
+
break;
|
|
1519
|
+
case Command.writeSpecialRegister:
|
|
1520
|
+
this._writeRegister(this._regs[Registers.internalParam_1], this._regs[Registers.internalParam_2]);
|
|
1521
|
+
// WRITE_SPECIAL_REGISTER tidies up in a much simpler way than other commands.
|
|
1522
|
+
this._lowerBusyAndLog();
|
|
1523
|
+
break;
|
|
1524
|
+
case Command.readSpecialRegister:
|
|
1525
|
+
this._setResult(this._readRegister(this._regs[Registers.internalParam_1]));
|
|
1526
|
+
this._finishSimpleCommand();
|
|
1527
|
+
break;
|
|
1528
|
+
case Command.readId:
|
|
1529
|
+
// First dispatch for the command, we go through the seek / wait for index /
|
|
1530
|
+
// etc. rigamarole. The command is re-dispatched for the second and further
|
|
1531
|
+
// headers, where we just straight to searching for header sync.
|
|
1532
|
+
// This can also be used as an undocumented mode of READ_ID where a
|
|
1533
|
+
// non-zero value to the second parameter will skip syncing to the index
|
|
1534
|
+
// pulse.
|
|
1535
|
+
if (this._regs[Registers.internalParam_2] === 0) {
|
|
1536
|
+
this._doSeek(Call.readId);
|
|
1537
|
+
} else {
|
|
1538
|
+
this._startSyncingForHeader();
|
|
1539
|
+
}
|
|
1540
|
+
break;
|
|
1541
|
+
case Command.seek:
|
|
1542
|
+
this._doSeek(Call.seek);
|
|
1543
|
+
break;
|
|
1544
|
+
case Command.readData:
|
|
1545
|
+
case Command.readDataAndDeleted:
|
|
1546
|
+
case Command.verify:
|
|
1547
|
+
case Command.scanData:
|
|
1548
|
+
case Command.scanDataAndDeleted:
|
|
1549
|
+
this._doSeek(Call.read);
|
|
1550
|
+
break;
|
|
1551
|
+
case Command.writeData:
|
|
1552
|
+
this._regs[Registers.internalParamDataMarker] = IbmDiscFormat.dataMarkDataPattern;
|
|
1553
|
+
this._doSeek(Call.write);
|
|
1554
|
+
break;
|
|
1555
|
+
case Command.writeDeletedData:
|
|
1556
|
+
this._regs[Registers.internalParamDataMarker] = IbmDiscFormat.deletedDataMarkDataPattern;
|
|
1557
|
+
this._doSeek(Call.write);
|
|
1558
|
+
break;
|
|
1559
|
+
case Command.format:
|
|
1560
|
+
this._doSeek(Call.format);
|
|
1561
|
+
break;
|
|
1562
|
+
default:
|
|
1563
|
+
throw new Error(`Unexpected command ${command}`);
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
_finishSimpleCommand() {
|
|
1568
|
+
this._lowerBusyAndLog();
|
|
1569
|
+
this._stopIrqCallbacks();
|
|
1570
|
+
this._clearCallbacks();
|
|
1571
|
+
|
|
1572
|
+
const headUnloadCount = this._regs[Registers.headLoadUnload] >>> 4;
|
|
1573
|
+
if (headUnloadCount === 0) {
|
|
1574
|
+
// Unload immediately.
|
|
1575
|
+
this._spinDown();
|
|
1576
|
+
} else if (headUnloadCount === 0xf) {
|
|
1577
|
+
// Never automatically unload.
|
|
1578
|
+
} else {
|
|
1579
|
+
this._regs[Registers.internalIndexPulseCount] = headUnloadCount;
|
|
1580
|
+
this._indexPulseCallback = IndexPulse.spindown;
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
_finishCommand(result) {
|
|
1585
|
+
if (result !== Result.ok) {
|
|
1586
|
+
this._driveOutLower(DriveOut.direction | DriveOut.step | DriveOut.writeEnable);
|
|
1587
|
+
}
|
|
1588
|
+
this._setResult(result | this._result);
|
|
1589
|
+
// Raise command completion IRQ.
|
|
1590
|
+
this._statusRaise(StatusFlag.nmi);
|
|
1591
|
+
this._finishSimpleCommand();
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
get _irqCallbacks() {
|
|
1595
|
+
return (this._regs[Registers.internalStatus] & 0x30) === 0x30;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
_startIrqCallbacks() {
|
|
1599
|
+
// These bits don't affect the external status, so no need to re-calculate.
|
|
1600
|
+
this._regs[Registers.internalStatus] |= 0x30;
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
_stopIrqCallbacks() {
|
|
1604
|
+
// These bits don't affect the external status, so no need to re-calculate.
|
|
1605
|
+
this._regs[Registers.internalStatus] &= ~0x30;
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
_decrementCounter() {
|
|
1609
|
+
if (--this._regs[Registers.internalCountLsb]) return false;
|
|
1610
|
+
// Javascript's clamping for Uint8Array happens on assignment; so I can do if (--regs[x] !== 0xff) here.
|
|
1611
|
+
--this._regs[Registers.internalCountMsb];
|
|
1612
|
+
if (this._regs[Registers.internalCountMsb] !== 0xff) {
|
|
1613
|
+
this._regs[Registers.internalCountLsb] = 0x80;
|
|
1614
|
+
return false;
|
|
1615
|
+
}
|
|
1616
|
+
this._regs[Registers.internalCountMsb] = 0;
|
|
1617
|
+
this._stopIrqCallbacks();
|
|
1618
|
+
return true;
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
_clearCallbacks() {
|
|
1622
|
+
this._paramCallback = ParamAccept.none;
|
|
1623
|
+
this._indexPulseCallback = IndexPulse.none;
|
|
1624
|
+
if (this._timerState !== TimerState.none) {
|
|
1625
|
+
this._timerTask.cancel();
|
|
1626
|
+
this._timerState = TimerState.none;
|
|
1627
|
+
}
|
|
1628
|
+
// Think of this as the read/write callback from the bit processor.
|
|
1629
|
+
this._setState(State.idle);
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
_lowerBusyAndLog() {
|
|
1633
|
+
this._statusLower(StatusFlag.busy);
|
|
1634
|
+
this._logCommand(`status ${utils.hexbyte(this._status)} result ${utils.hexbyte(this._result)}`);
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
_spinDown() {
|
|
1638
|
+
this._driveOutLower(DriveOut.selectFlags | DriveOut.loadHead);
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
_timerFired() {
|
|
1642
|
+
// Counting milliseconds is done with r8 and r9, which are left at zero after a busy wait.
|
|
1643
|
+
this._regs[Registers.internalMsCountHi] = 0;
|
|
1644
|
+
this._regs[Registers.internalMsCountLo] = 0;
|
|
1645
|
+
switch (this._timerState) {
|
|
1646
|
+
case TimerState.seekStep:
|
|
1647
|
+
this._doSeekStep();
|
|
1648
|
+
break;
|
|
1649
|
+
case TimerState.postSeek:
|
|
1650
|
+
this._postSeekDispatch();
|
|
1651
|
+
break;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
_doWriteRun(callContext, byte) {
|
|
1656
|
+
this._mmioData = byte & 0xff;
|
|
1657
|
+
this._mmioClocks = 0xff;
|
|
1658
|
+
this._crc = IbmDiscFormat.crcAddByte(this._crc, this._mmioData);
|
|
1659
|
+
this._regs[Registers.internalWriteRunData] = this._mmioData;
|
|
1660
|
+
this._driveOutRaise(DriveOut.writeEnable);
|
|
1661
|
+
this._callContext = callContext;
|
|
1662
|
+
this._setState(State.writeRun);
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
_writeFFsAnd00s(callContext, numFFs) {
|
|
1666
|
+
if (numFFs !== -1) {
|
|
1667
|
+
this._regs[Registers.internalCountLsb] = numFFs;
|
|
1668
|
+
this._regs[Registers.internalCountMsb] = 0;
|
|
1669
|
+
}
|
|
1670
|
+
this._doWriteRun(callContext, 0xff);
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/// jsbeeb compatibility stuff
|
|
1674
|
+
/**
|
|
1675
|
+
*
|
|
1676
|
+
* @param {Number} drive
|
|
1677
|
+
* @param {Disc} disc
|
|
1678
|
+
*/
|
|
1679
|
+
loadDisc(drive, disc) {
|
|
1680
|
+
this._drives[drive].setDisc(disc);
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
get motorOn() {
|
|
1684
|
+
return [this._drives[0] ? this._drives[0].spinning : false, this._drives[0] ? this._drives[1].spinning : false];
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
get drives() {
|
|
1688
|
+
return this._drives;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
export class NoiseAwareIntelFdc extends IntelFdc {
|
|
1693
|
+
constructor(cpu, ddNoise, scheduler, debugFlags) {
|
|
1694
|
+
super(cpu, scheduler, undefined, debugFlags);
|
|
1695
|
+
let nextSeekTime = 0;
|
|
1696
|
+
let numSpinning = 0;
|
|
1697
|
+
// Update the spin status shortly after the drive state changes to debounce it slightly.
|
|
1698
|
+
const updateSpinStatus = () => {
|
|
1699
|
+
if (numSpinning) ddNoise.spinUp();
|
|
1700
|
+
else ddNoise.spinDown();
|
|
1701
|
+
};
|
|
1702
|
+
for (const drive of this.drives) {
|
|
1703
|
+
drive.addEventListener("startSpinning", () => {
|
|
1704
|
+
numSpinning++;
|
|
1705
|
+
setTimeout(updateSpinStatus, 2);
|
|
1706
|
+
});
|
|
1707
|
+
drive.addEventListener("stopSpinning", () => {
|
|
1708
|
+
--numSpinning;
|
|
1709
|
+
setTimeout(updateSpinStatus, 2);
|
|
1710
|
+
});
|
|
1711
|
+
drive.addEventListener("step", (evt) => {
|
|
1712
|
+
const now = Date.now();
|
|
1713
|
+
if (now > nextSeekTime) nextSeekTime = now + ddNoise.seek(evt.stepAmount) * 1000;
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
}
|