From b72dc79eec3d369a38202522165f5ef4cfa5b98b Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Tue, 9 Apr 2019 02:40:05 +0100 Subject: Support IOC commands for disk/drum devices Thanks to Kevin Brunelle There is a minor fix included with regards to tape devices. The test was failing if M == 0, when it should fail when M != 0. NOTICE: This patch changes the behavior of the VM and changes the function parameters for the ioc_ function. Documentation changes are included. Permits the following: LDX BLKNUM IOC 0(8) OUT ADDR(8) Write block from ADDR into disk[BLKNUM] IOC 0(8) IN ADDR(8) Read block from disk[BLKNUM] into ADDR ... BLKNUM CON 45000 Example possible block on disk I was having an issue writing a block to a drive and then reading back the same block. Because it is impossible to move the SEEK_CUR pointer backwards on a disk device, there was no way for a program to read back a block that it wrote to a disk without restarting or fiddling with ~/.mdk/disk?.dev files and symbolic links. I have added a function parameter to the ioc_ function and used it to pass the value of rX to ioc_. This permits us to use IOC commands to move the read/write head on a disk/drum device. I believe that this conforms to the potential meaning of Knuth's description of IOC for disk/drum devices. I have put in tests to verify that rX is positive and M = 0. I have updated the documentation to reflect this new behavior. This makes disks much more usable. Note: I won't be offended if this patch is rejected because it changed the behavior of the VM. I think it fits the spirit and enhances the functionality in a way that some might find useful. I wanted it for something I was working on, and I felt others might want the same. The thing with the paper-tape should be fixed, though. --- mixlib/xmix_device.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'mixlib/xmix_device.c') diff --git a/mixlib/xmix_device.c b/mixlib/xmix_device.c index 8d4084c..6fb085f 100644 --- a/mixlib/xmix_device.c +++ b/mixlib/xmix_device.c @@ -143,14 +143,20 @@ read_ (mix_device_t *dev, mix_word_t *block) } static gboolean -ioc_ (mix_device_t *dev, mix_short_t arg) +ioc_ (mix_device_t *dev, mix_short_t arg, mix_word_t val) { int m; FILE *file; + long diskblock; m = mix_short_magnitude(arg); if (mix_short_is_negative(arg)) m = -m; m *= sizeof (mix_word_t) * SIZES_[dev->type]; + + diskblock = mix_word_magnitude(val); + if (mix_word_is_negative(val)) diskblock = -diskblock; + diskblock *= sizeof (mix_word_t) * SIZES_[dev->type]; + file = mix_io_to_FILE (GET_CHANNEL_(dev)); if (dev->type >= mix_dev_TAPE_0 && dev->type <= mix_dev_TAPE_7) @@ -160,12 +166,13 @@ ioc_ (mix_device_t *dev, mix_short_t arg) } if (dev->type >= mix_dev_DISK_0 && dev->type <= mix_dev_DISK_7) { - if (m == 0) return FALSE; - // position disk + // move read/write head to block + if (m != 0 || diskblock < 0) return FALSE; + else fseek (file, diskblock, SEEK_SET); } if (dev->type == mix_dev_PAPER_TAPE) { - if (m == 0) return FALSE; + if (m != 0) return FALSE; rewind (file); } return TRUE; -- cgit v1.2.3