mirror of
https://github.com/rzzzwilson/pymlac.git
synced 2025-06-10 09:32:41 +00:00
Remove old PTR and PTP implementations
This commit is contained in:
parent
d95de1af6c
commit
147a295cff
103
vimlac/ptp.c
103
vimlac/ptp.c
@ -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;
|
||||
}
|
||||
}
|
||||
16
vimlac/ptp.h
16
vimlac/ptp.h
@ -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
|
||||
124
vimlac/ptr.c
124
vimlac/ptr.c
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
16
vimlac/ptr.h
16
vimlac/ptr.h
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user