diff --git a/vimlac/ptp.c b/vimlac/ptp.c deleted file mode 100755 index 191b784..0000000 --- a/vimlac/ptp.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Implementation for the vimlac PTP (papertape punch). - */ - -#include "vimlac.h" -#include "ptp.h" - - -/***** - * constants for the PTP device - * - * The device punches at 300 chars/second, so we work out how many - * machine cycles device is not ready after punch starts. - ******/ - -#define CHARS_PER_SECOND 300 -#define NOT_READY_CYCLES (int) (CPU_HERZ / CHARS_PER_SECOND) - -/***** - * State variables for the PTR device - ******/ - -static bool motor_on = false; -static bool device_ready = false; -static FILE *open_file; -static char *filename = NULL; -static long cycle_count = 0; - - -int ptp_mount(char *fname) -{ - filename = fname; - open_file = fopen(fname, "wb"); - if (open_file == NULL) - { - ptp_dismount(); - return errno; - } - motor_on = false; - device_ready = false; - cycle_count = NOT_READY_CYCLES; - - return 0; -} - - -void ptp_dismount(void) -{ - if (open_file) - if (fclose(open_file) != 0) - filename = NULL; - open_file = NULL; - motor_on = false; - device_ready = true; -} - - -void ptp_start(void) -{ - motor_on = true; - device_ready = false; - cycle_count = NOT_READY_CYCLES; -} - - -void ptp_stop(void) -{ - motor_on = false; - cycle_count = NOT_READY_CYCLES; -} - - -void ptp_punch(BYTE value) -{ - if (motor_on && open_file != NULL) - { - putc(value, open_file); - cycle_count = NOT_READY_CYCLES; - } -} - - -bool ptp_ready(void) -{ - return device_ready; -} - - -void ptp_tick(long cycles) -{ - /* if no state change */ - if (!motor_on || open_file == NULL) - return; - - /* tape in, motor on */ - cycle_count -= cycles; - if (cycle_count <= 0L) - { - if (!device_ready) - device_ready = true; - cycle_count = 0; - } -} diff --git a/vimlac/ptp.h b/vimlac/ptp.h deleted file mode 100755 index 9443213..0000000 --- a/vimlac/ptp.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Interface for the vimlac PTP (papertape punch). - */ - -#ifndef PTP_H -#define PTP_H - -int ptp_mount(char *fname); -void ptp_dismount(void); -void ptp_start(void); -void ptp_stop(void); -void ptp_punch(BYTE byte); -void ptp_tick(long cycles); -bool ptp_ready(void); - -#endif diff --git a/vimlac/ptr.c b/vimlac/ptr.c deleted file mode 100755 index 41fb647..0000000 --- a/vimlac/ptr.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Implementation for the vimlac PTR (papertape reader). - */ - -#include "vimlac.h" -#include "ptr.h" - - -/***** - * constants for the PTR device - * - * The device reads at 300 chars/second, so we work out how many - * machine cycles data is ready/notready at a 30%/70% ready cycle. - ******/ - -#define CHARS_PER_SECOND 300 -#define CYCLES_PER_CHAR (CPU_HERZ / CHARS_PER_SECOND) -#define READY_CYCLES (int)((3 * CYCLES_PER_CHAR) / 10) -#define NOT_READY_CYCLES (int)((7 * CYCLES_PER_CHAR) / 10) - -#define PTR_EOF 0377 - -/***** - * State variables for the PTR device - ******/ - -static bool motor_on = false; -static bool device_ready = false; -static FILE *open_file; -static char *filename = NULL; -static bool at_eof = false; -static BYTE value = PTR_EOF; -static long cycle_count = 0; - - -int ptr_mount(char *fname) -{ - filename = fname; - open_file = fopen(fname, "rb"); - if (open_file == NULL) - { - ptr_dismount(); - return errno; - } - motor_on = false; - device_ready = false; - at_eof = false; - value = PTR_EOF; - cycle_count = NOT_READY_CYCLES; - - return 0; -} - - -void ptr_dismount(void) -{ - if (open_file) - if (fclose(open_file) != 0) - filename = NULL; - open_file = NULL; - motor_on = false; - device_ready = true; - at_eof = true; - value = PTR_EOF; -} - - -void ptr_start(void) -{ - motor_on = true; - device_ready = false; - cycle_count = NOT_READY_CYCLES; -} - - -void ptr_stop(void) -{ - motor_on = false; - cycle_count = NOT_READY_CYCLES; -} - - -int ptr_read(void) -{ - return value; -} - - -bool ptr_ready(void) -{ - return device_ready; -} - - -void ptr_tick(long cycles) -{ - /* if no state change */ - if (!motor_on || at_eof || open_file == NULL) - return; - - /* tape in, motor on */ - cycle_count -= cycles; - if (cycle_count <= 0L) - { - if (device_ready) - { - device_ready = false; - cycle_count += NOT_READY_CYCLES; - value = 0; - } - else - { - device_ready = true; - cycle_count += READY_CYCLES; - if (fread(&value, sizeof(BYTE), 1, open_file) != 1) - { /* assume EOF on file, dismount tape */ - fclose(open_file); - open_file = NULL; - at_eof = true; - value = PTR_EOF; - } - } - } -} diff --git a/vimlac/ptr.h b/vimlac/ptr.h deleted file mode 100755 index d555b8b..0000000 --- a/vimlac/ptr.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Interface for the vimlac PTR (papertape reader). - */ - -#ifndef PTR_H -#define PTR_H - -int ptr_mount(char *fname); -void ptr_dismount(void); -void ptr_start(void); -void ptr_stop(void); -int ptr_read(void); -void ptr_tick(long cycles); -bool ptr_ready(void); - -#endif