mirror of
https://github.com/SEPPDROID/Digital-Research-Source-Code.git
synced 2025-10-23 08:24:18 +00:00
Upload
Digital Research
This commit is contained in:
174
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/bdosdef.h
Normal file
174
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/bdosdef.h
Normal file
@@ -0,0 +1,174 @@
|
||||
|
||||
/********************************************************
|
||||
* *
|
||||
* CP/M-68K header file *
|
||||
* Copyright (c) 1982 by Digital Research, Inc. *
|
||||
* Structure definitions for BDOS globals *
|
||||
* and BDOS data structures *
|
||||
* *
|
||||
********************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
The BDOS data structures, especially those relating to global variables,
|
||||
are structured in a way that hopefully will enable this BDOS, in the future,
|
||||
to easily become a re-entrant multi-tasking file system. Consequently,
|
||||
the BDOS global variables are divided into two classes. Those that are
|
||||
truly global, even in the case of multiple tasks using the file system
|
||||
concurrently, are simply declared as global variables in bdosmain.c.
|
||||
Only a few "globals" are really global in this sense.
|
||||
|
||||
The majority of the "global" variables are actually state variables that
|
||||
relate to the state of the task using the file system. In CP/M-68K, these
|
||||
are "global", since there's only one task, but in a multi-thread model they're
|
||||
not. This type of variables is put into a data structure, with the
|
||||
intention that in the multi-task environment this structure will be based.
|
||||
|
||||
The following declarations take this philosophy into account, and define
|
||||
a simple structure for the single thread environment while leaving the
|
||||
possibilities open for the multi-thread environment.
|
||||
****************************************************************************/
|
||||
|
||||
#define snglthrd TRUE
|
||||
/* TRUE for single-thread environment
|
||||
FALSE to create based structure for re-entrant model */
|
||||
#if snglthrd
|
||||
#define GBL gbls
|
||||
/* In single thread case, GBL just names
|
||||
the structure */
|
||||
#define BSETUP EXTERN struct stvars gbls;
|
||||
/* and BSETUP defines the extern structure */
|
||||
#endif
|
||||
|
||||
#if ! snglthrd
|
||||
#define GBL (*statep)
|
||||
/* If multi-task, state vars are based */
|
||||
#define BSETUP REG struct stvars *statep; \
|
||||
statep = &gbls;
|
||||
/* set up pointer to state variables */
|
||||
/* This is intended as an example to show the intent */
|
||||
#endif
|
||||
|
||||
|
||||
/* Note that there are a few critical regions in the file system that must
|
||||
execute without interruption. They pertain mostly to the manipulation of
|
||||
the allocation vector. This isn't a problem in a single-thread model, but
|
||||
must be provided for in a multi-tasking file system. Consequently, the
|
||||
primitives LOCK and UNLOCK are defined and used where necessary in the
|
||||
file system. For the single thread model, they are null routines */
|
||||
|
||||
#define LOCK /**/
|
||||
#define UNLOCK /**/
|
||||
/* Be sure LOCK and UNLOCK are implemented to allow recursive calls to LOCK.
|
||||
That is, if a process that calls LOCK already owns the lock, let it proceed,
|
||||
but remember that only the outer-most call to UNLOCK really releases the
|
||||
file system. */
|
||||
|
||||
|
||||
#define VERSION 0x2022 /* Version number for CP/M-68K */
|
||||
#define robit 0 /* read-only bit in file type field of fcb */
|
||||
#define arbit 2 /* archive bit in file type field of fcb */
|
||||
#define SECLEN 128 /* length of a CP/M sector */
|
||||
|
||||
|
||||
/* File Control Block definition */
|
||||
struct fcb
|
||||
{
|
||||
UBYTE drvcode; /* 0 = default drive, 1..16 are drives A..P */
|
||||
UBYTE fname[8]; /* File name (ASCII) */
|
||||
UBYTE ftype[3]; /* File type (ASCII) */
|
||||
UBYTE extent; /* Extent number (bits 0..4 used) */
|
||||
UBYTE s1; /* Reserved */
|
||||
UBYTE s2; /* Module field (bits 0..5), write flag (7) */
|
||||
UBYTE rcdcnt; /* Nmbr rcrds in last block, 0..128 */
|
||||
union
|
||||
{
|
||||
UBYTE small[16]; /* 16 block numbers of 1 byte */
|
||||
WORD big[8]; /* or 8 block numbers of 1 word */
|
||||
} dskmap;
|
||||
UBYTE cur_rec; /* current record field */
|
||||
UBYTE ran0; /* random record field (3 bytes) */
|
||||
UBYTE ran1;
|
||||
UBYTE ran2;
|
||||
};
|
||||
|
||||
|
||||
/* Declaration of directory entry */
|
||||
struct dirent
|
||||
{
|
||||
UBYTE entry; /* 0 - 15 for user numbers, E5 for empty */
|
||||
/* the rest are reserved */
|
||||
UBYTE fname[8]; /* File name (ASCII) */
|
||||
UBYTE ftype[3]; /* File type (ASCII) */
|
||||
UBYTE extent; /* Extent number (bits 0..4 used) */
|
||||
UBYTE s1; /* Reserved */
|
||||
UBYTE s2; /* Module field (bits 0..5), write flag (7) */
|
||||
UBYTE rcdcnt; /* Nmbr rcrds in last block, 0..128 */
|
||||
union
|
||||
{
|
||||
UBYTE small[16]; /* 16 block numbers of 1 byte */
|
||||
WORD big[8]; /* or 8 block numbers of 1 word */
|
||||
} dskmap;
|
||||
};
|
||||
|
||||
|
||||
/* Declaration of disk parameter tables */
|
||||
struct dpb /* disk parameter table */
|
||||
{
|
||||
UWORD spt; /* sectors per track */
|
||||
UBYTE bsh; /* block shift factor */
|
||||
UBYTE blm; /* block mask */
|
||||
UBYTE exm; /* extent mask */
|
||||
UBYTE dpbdum; /* dummy byte for fill */
|
||||
UWORD dsm; /* max disk size in blocks */
|
||||
UWORD drm; /* max directory entries */
|
||||
UWORD dir_al; /* initial allocation for dir */
|
||||
UWORD cks; /* number dir sectors to checksum */
|
||||
UWORD trk_off; /* track offset */
|
||||
};
|
||||
|
||||
struct dph /* disk parameter header */
|
||||
{
|
||||
UBYTE *xlt; /* pointer to sector translate table */
|
||||
UWORD hiwater; /* high water mark for this disk */
|
||||
UWORD dum1; /* dummy (unused) */
|
||||
UWORD dum2;
|
||||
UBYTE *dbufp; /* pointer to 128 byte directory buffer */
|
||||
struct dpb *dpbp; /* pointer to disk parameter block */
|
||||
UBYTE *csv; /* pointer to check vector */
|
||||
UBYTE *alv; /* pointer to allocation vector */
|
||||
};
|
||||
|
||||
|
||||
/* Declaration of structure containing "global" state variables */
|
||||
struct stvars
|
||||
{
|
||||
UBYTE kbchar; /* One byte keyboard type-ahead buffer */
|
||||
UBYTE delim; /* Delimiter for function 9 */
|
||||
BOOLEAN lstecho; /* True if echoing console output to lst: */
|
||||
BOOLEAN echodel; /* Echo char when getting <del> ? */
|
||||
UWORD column; /* CRT column number for expanding tabs */
|
||||
UBYTE *chainp; /* Used for chain to program call */
|
||||
UBYTE curdsk; /* Currently selected disk */
|
||||
UBYTE dfltdsk; /* Default disk (last selected by fcn 14) */
|
||||
UBYTE user; /* Current user number */
|
||||
struct dph *dphp; /* pointer to disk parm hdr for cur disk */
|
||||
struct dirent *dirbufp; /* pointer for directory buff for process */
|
||||
/* stored here so that each process can */
|
||||
/* have a separate dirbuf. */
|
||||
struct dpb *parmp; /* pointer to disk parameter block for cur */
|
||||
/* disk. Stored here to save ref calc */
|
||||
UWORD srchpos; /* position in directory for search next */
|
||||
UBYTE *dmaadr; /* Disk dma address */
|
||||
struct fcb *srchp; /* Pointer to search FCB for function 17 */
|
||||
UBYTE *excvec[18]; /* Array of exception vectors */
|
||||
};
|
||||
|
||||
|
||||
/* Console buffer structure declaration */
|
||||
struct conbuf
|
||||
{
|
||||
UBYTE maxlen; /* Maximum length from calling routine */
|
||||
UBYTE retlen; /* Length actually found by BDOS */
|
||||
UBYTE cbuf[]; /* Console data */
|
||||
};
|
||||
|
154
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/bdosif.s
Normal file
154
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/bdosif.s
Normal file
@@ -0,0 +1,154 @@
|
||||
|
||||
*****************************************************************
|
||||
* *
|
||||
* CP/M-68K Basic Disk Operating System interface module *
|
||||
* For "C" version of CP/M-68K *
|
||||
* *
|
||||
* Copyright (c) 1982 Digital Research, Inc. *
|
||||
* *
|
||||
* Version 0.2 -- September 22, 1982 *
|
||||
* *
|
||||
*****************************************************************
|
||||
|
||||
* Declare Public Routines
|
||||
|
||||
.globl _bios1 * 6 BIOS entry points from BDOS
|
||||
.globl _bios2
|
||||
.globl _bios3
|
||||
.globl _bios4
|
||||
.globl _bios5
|
||||
.globl _bios6
|
||||
.globl _traphnd * trap #2 handler
|
||||
.globl _swap * byte swapper
|
||||
.globl _udiv * unsigned divide routine
|
||||
|
||||
* Declare external routines
|
||||
.globl __bdos * BDOS entry point in bdosmain
|
||||
|
||||
* The following external references were put in just to make sure that all
|
||||
* the BDOS modules were referenced, so we could put them in a library
|
||||
.globl _constat * references conbdos.o
|
||||
.globl _dirscan * references dskutil.o
|
||||
.globl _create * references fileio.o
|
||||
.globl _bdosrw * references bdosrw.o
|
||||
|
||||
biosf = 50
|
||||
setsupf = 62
|
||||
|
||||
_traphnd:
|
||||
*
|
||||
* first save the registers and
|
||||
* check for functions handled by assembly language routines
|
||||
*
|
||||
cmpi #setsupf,d0
|
||||
beq setsup
|
||||
movem.l d1-d7/a0-a6,-(sp)
|
||||
cmpi #biosf,d0
|
||||
beq bioscall
|
||||
*
|
||||
* function number is passed in D0
|
||||
* byte and word pararmeters are passed in D1.W
|
||||
* address parameters are passed in D1.L
|
||||
*
|
||||
move.l d1,-(a7)
|
||||
move.w d1,-(a7)
|
||||
move.w d0,-(a7)
|
||||
jsr __bdos * call BDOS
|
||||
*
|
||||
* now restore the regs
|
||||
*
|
||||
ext.l d0
|
||||
addq #8,sp * fix up the stack
|
||||
bdone:
|
||||
movem.l (sp)+,a0-a6/d1-d7
|
||||
rte * return from trap call
|
||||
|
||||
*
|
||||
* direct BIOS call function
|
||||
*
|
||||
bioscall:
|
||||
move.l d1,a0 * get address of CPB
|
||||
move.w (a0)+,d0
|
||||
movem.l (a0)+,d1-d2
|
||||
trap #3
|
||||
bra bdone
|
||||
|
||||
*
|
||||
* Set supervisor mode procedure
|
||||
*
|
||||
setsup:
|
||||
ori #$2000,(sp) * turn on supervisor bit in SR
|
||||
rte
|
||||
|
||||
*
|
||||
* BIOS Interface Routines
|
||||
*
|
||||
*
|
||||
* Note - there are 6 BIOS entry points from the BDOS, labelled BIOS1 -
|
||||
* BIOS6, depending on the parameters passed.
|
||||
|
||||
_bios5:
|
||||
* For BIOS functions sectran and set exception vector
|
||||
* Has function number and 2 parameters, a word followed by a long word
|
||||
move.l 8(sp),d2 * get 2nd parameter (long word)
|
||||
bra _bios2 * join common routine
|
||||
|
||||
_bios4:
|
||||
* For BIOS function seldsk
|
||||
* Has function number followed by 2 word parameters
|
||||
move.w 8(sp),d2 * get 2nd parameter (word)
|
||||
bra _bios2 * join common routine
|
||||
|
||||
_bios3:
|
||||
* For BIOS function set dma
|
||||
* Has function number followed by 1 long parameter
|
||||
move.l 6(sp),d1 * get long word parameter
|
||||
bra _bios1 * join common routine
|
||||
|
||||
_bios2:
|
||||
* For all BIOS functions with a word parameter
|
||||
* Word parameter follows function number
|
||||
move.w 6(sp),d1 * get 1st parameter (word)
|
||||
|
||||
_bios6:
|
||||
_bios1:
|
||||
* For all BIOS functions that have no parameter other than function number
|
||||
move.w 4(sp),d0 * get function number
|
||||
movem.l d3-d7/a3-a6,-(sp)
|
||||
* * save C register variables
|
||||
trap #3 * do BIOS call
|
||||
* * returns value in d0
|
||||
movem.l (sp)+,d3-d7/a3-a6
|
||||
rts
|
||||
|
||||
*
|
||||
* Utility Subroutines
|
||||
*
|
||||
|
||||
_swap:
|
||||
* Swap bytes of a word, return swapped value in d0
|
||||
move.b 5(sp),d0
|
||||
lsl #8,d0
|
||||
move.b 4(sp),d0
|
||||
rts
|
||||
|
||||
_udiv:
|
||||
* Unsigned divide routine
|
||||
* returns unsigned quotient in D0.W
|
||||
|
||||
* UWORD udiv( divisor, dividend, remp )
|
||||
*
|
||||
* REG LONG divisor;
|
||||
* UWORD dividend;
|
||||
* UWORD *remp /* pointer to remainder (returned) */
|
||||
|
||||
move.l 4(sp), d0 * get dividend
|
||||
divu 8(sp), d0 * do the divide
|
||||
movea.l 10(sp),a0
|
||||
swap d0
|
||||
move.w d0, (a0) * store remainder
|
||||
clr.w d0
|
||||
swap d0 * word quotient in d0
|
||||
rts
|
||||
|
||||
.end
|
@@ -0,0 +1,68 @@
|
||||
/*****************************************************************************
|
||||
*
|
||||
* C P / M C H E A D E R F I L E
|
||||
* -----------------------------------
|
||||
* Copyright 1982 by Digital Research Inc. All rights reserved.
|
||||
*
|
||||
* This is an include file for assisting the user to write portable
|
||||
* programs for C.
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define ALCYON 1 /* using Alcyon compiler */
|
||||
/*
|
||||
* Standard type definitions
|
||||
*/
|
||||
/***************************/
|
||||
#define BYTE char /* Signed byte */
|
||||
#define BOOLEAN char /* 2 valued (true/false) */
|
||||
#define WORD short /* Signed word (16 bits) */
|
||||
#define UWORD unsigned int /* unsigned word */
|
||||
#define LONG long /* signed long (32 bits) */
|
||||
#define ULONG unsigned long /* Unsigned long */
|
||||
#define REG register /* register variable */
|
||||
#define LOCAL auto /* Local var on 68000 */
|
||||
#define EXTERN extern /* External variable */
|
||||
#define MLOCAL static /* Local to module */
|
||||
#define GLOBAL /**/ /* Global variable */
|
||||
#define VOID /**/ /* Void function return */
|
||||
/***************************/
|
||||
#ifdef ALCYON
|
||||
#define UBYTE char
|
||||
#define UBWORD(a) ((UWORD)a & 0xff)
|
||||
/* Unsigned byte to word cast */
|
||||
#else
|
||||
#define UBYTE unsigned char /* Unsigned byte */
|
||||
#define UBWORD(a) (UWORD)a
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* Miscellaneous Definitions: */
|
||||
/****************************************************************************/
|
||||
#define FAILURE (-1) /* Function failure return val */
|
||||
#define SUCCESS (0) /* Function success return val */
|
||||
#define YES 1 /* "TRUE" */
|
||||
#define NO 0 /* "FALSE" */
|
||||
#define FOREVER for(;;) /* Infinite loop declaration */
|
||||
#define NULL (BYTE *)0 /* Null pointer value */
|
||||
#define EOF (-1) /* EOF Value */
|
||||
#define TRUE (1) /* Function TRUE value */
|
||||
#define FALSE (0) /* Function FALSE value */
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* */
|
||||
/* M A C R O S */
|
||||
/* ----------- */
|
||||
/* */
|
||||
/* Define some stuff as macros .... */
|
||||
/* */
|
||||
/****************************************************************************/
|
||||
|
||||
#define abs(x) ((x) < 0 ? -(x) : (x)) /* Absolute value function */
|
||||
|
||||
#define max(x,y) (((x) > (y)) ? (x) : (y)) /* Max function */
|
||||
#define min(x,y) (((x) < (y)) ? (x) : (y)) /* Min function */
|
||||
|
||||
/*************************** end of stdio.h *********************************/
|
304
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/bdosmain.c
Normal file
304
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/bdosmain.c
Normal file
@@ -0,0 +1,304 @@
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* CP/M-68K BDOS Main Routine *
|
||||
* *
|
||||
* This is the main routine for the BDOS for CP/M-68K *
|
||||
* It has one entry point, _bdos, which is called from *
|
||||
* the assembly language trap handler found in bdosif.s. *
|
||||
* The parameters are a function number (integer) and an *
|
||||
* information parameter (which is passed from bdosif as *
|
||||
* both an integer and a pointer).
|
||||
* The BDOS can potentially return a pointer, long word, *
|
||||
* or word *
|
||||
* *
|
||||
* Configured for Alcyon C on the VAX *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
#include "bdosinc.h" /* Standard I/O declarations */
|
||||
|
||||
#include "bdosdef.h" /* Type and structure declarations for BDOS */
|
||||
|
||||
#include "biosdef.h" /* Declarations of BIOS functions */
|
||||
|
||||
/* Declare EXTERN functions */
|
||||
|
||||
EXTERN warmboot(); /* Warm Boot function */
|
||||
EXTERN BOOLEAN constat(); /* Console status */
|
||||
EXTERN UBYTE conin(); /* Console Input function */
|
||||
EXTERN tabout(); /* Console output with tab expansion */
|
||||
EXTERN UBYTE rawconio(); /* Raw console I/O */
|
||||
EXTERN prt_line(); /* Print line until delimiter */
|
||||
EXTERN readline(); /* Buffered console read */
|
||||
EXTERN seldsk(); /* Select disk */
|
||||
EXTERN BOOLEAN openfile(); /* Open File */
|
||||
EXTERN UWORD close_fi(); /* Close File */
|
||||
EXTERN UWORD search(); /* Search first and next fcns */
|
||||
EXTERN UWORD dirscan(); /* General directory scanning routine */
|
||||
EXTERN UWORD bdosrw(); /* Sequential and Random disk read/write */
|
||||
EXTERN BOOLEAN create(); /* Create file */
|
||||
EXTERN BOOLEAN delete(); /* Delete file */
|
||||
EXTERN BOOLEAN rename(); /* Rename file */
|
||||
EXTERN BOOLEAN set_attr(); /* Set file attributes */
|
||||
EXTERN getsize(); /* Get File Size */
|
||||
EXTERN setran(); /* Set Random Record */
|
||||
EXTERN free_sp(); /* Get Disk Free Space */
|
||||
EXTERN UWORD flushit(); /* Flush Buffers */
|
||||
EXTERN UWORD pgmld(); /* Program Load */
|
||||
EXTERN UWORD setexc(); /* Set Exception Vector */
|
||||
EXTERN set_tpa(); /* Get/Set TPA Limits */
|
||||
EXTERN move(); /* general purpose byte mover */
|
||||
|
||||
|
||||
/* Declare "true" global variables; i.e., those which will pertain to the
|
||||
entire file system and thus will remain global even when this becomes
|
||||
a multi-tasking file system */
|
||||
|
||||
GLOBAL UWORD log_dsk; /* 16-bit vector of logged in drives */
|
||||
GLOBAL UWORD ro_dsk; /* 16-bit vector of read-only drives */
|
||||
GLOBAL UWORD crit_dsk; /* 16-bit vector of drives in "critical"
|
||||
state. Used to control dir checksums */
|
||||
GLOBAL BYTE *tpa_lp; /* TPA lower boundary (permanent) */
|
||||
GLOBAL BYTE *tpa_lt; /* TPA lower boundary (temporary) */
|
||||
GLOBAL BYTE *tpa_hp; /* TPA upper boundary (permanent) */
|
||||
GLOBAL BYTE *tpa_ht; /* TPA upper boundary (temporary) */
|
||||
|
||||
|
||||
/* Declare the "state variables". These are globals for the single-thread
|
||||
version of the file system, but are put in a structure so they can be
|
||||
based, with a pointer coming from the calling process */
|
||||
|
||||
GLOBAL struct stvars gbls;
|
||||
|
||||
struct tempstr
|
||||
{
|
||||
UBYTE tempdisk;
|
||||
BOOLEAN reselect;
|
||||
struct fcb *fptr;
|
||||
};
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* _bdos MAIN ROUTINE *
|
||||
* *
|
||||
* Called with _bdos(func, info, infop) *
|
||||
* *
|
||||
* Where: *
|
||||
* func is the BDOS function number (d0.w) *
|
||||
* info is the word parameter (d1.w) *
|
||||
* infop is the pointer parameter (d1.l) *
|
||||
* note that info is the word form of infop*
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
|
||||
UWORD _bdos(func,info,infop)
|
||||
REG WORD func; /* BDOS function number */
|
||||
REG UWORD info; /* d1.w word parameter */
|
||||
REG UBYTE *infop; /* d1.l pointer parameter */
|
||||
{
|
||||
REG UWORD rtnval;
|
||||
LOCAL struct tempstr temp;
|
||||
BSETUP
|
||||
|
||||
temp.reselect = FALSE;
|
||||
temp.fptr = infop;
|
||||
rtnval = 0;
|
||||
|
||||
switch (func) /* switch on function number */
|
||||
{
|
||||
case 0: warmboot(0); /* warm boot function */
|
||||
/* break; */
|
||||
|
||||
case 1: return((UWORD)conin()); /* console input function */
|
||||
/* break; */
|
||||
|
||||
case 2: tabout((UBYTE)info); /* console output with */
|
||||
break; /* tab expansion */
|
||||
|
||||
case 3: return((UWORD)brdr()); /* get reader from bios */
|
||||
/* break; */
|
||||
|
||||
case 4: bpun((UBYTE)info); /* punch output to bios */
|
||||
break;
|
||||
|
||||
case 5: blstout((UBYTE)info); /* list output from bios */
|
||||
break;
|
||||
|
||||
case 6: return((UWORD)rawconio(info)); /* raw console I/O */
|
||||
/* break; */
|
||||
|
||||
case 7: return(bgetiob()); /* get i/o byte */
|
||||
/* break; */
|
||||
|
||||
case 8: bsetiob(info); /* set i/o byte function */
|
||||
break;
|
||||
|
||||
case 9: prt_line(infop); /* print line function */
|
||||
break;
|
||||
|
||||
case 10: readline(infop); /* read buffered con input */
|
||||
break;
|
||||
|
||||
case 11: return((UWORD)constat()); /* console status */
|
||||
/* break; */
|
||||
|
||||
case 12: return(VERSION); /* return version number */
|
||||
/* break; */
|
||||
|
||||
case 13: log_dsk = 0; /* reset disk system */
|
||||
ro_dsk = 0;
|
||||
crit_dsk= 0;
|
||||
GBL.curdsk = 0xff;
|
||||
GBL.dfltdsk = 0;
|
||||
break;
|
||||
|
||||
case 14: seldsk((UBYTE)info); /* select disk */
|
||||
GBL.dfltdsk = (UBYTE)info;
|
||||
break;
|
||||
|
||||
case 15: tmp_sel(&temp); /* open file */
|
||||
infop->extent = 0;
|
||||
infop->s2 = 0;
|
||||
rtnval = dirscan(openfile, infop, 0);
|
||||
break;
|
||||
|
||||
case 16: tmp_sel(&temp); /* close file */
|
||||
rtnval = close_fi(infop);
|
||||
break;
|
||||
|
||||
case 17: GBL.srchp = infop; /* search first */
|
||||
rtnval = search(infop, 0, &temp);
|
||||
break;
|
||||
|
||||
case 18: infop = GBL.srchp; /* search next */
|
||||
temp.fptr = infop;
|
||||
rtnval = search(infop, 1, &temp);
|
||||
break;
|
||||
|
||||
case 19: tmp_sel(&temp); /* delete file */
|
||||
rtnval = dirscan(delete, infop, 2);
|
||||
break;
|
||||
|
||||
case 20: tmp_sel(&temp); /* read sequential */
|
||||
rtnval = bdosrw(infop, TRUE, 0);
|
||||
break;
|
||||
|
||||
case 21: tmp_sel(&temp); /* write sequential */
|
||||
rtnval = bdosrw(infop, FALSE, 0);
|
||||
break;
|
||||
|
||||
case 22: tmp_sel(&temp); /* create file */
|
||||
infop->extent = 0;
|
||||
infop->s1 = 0;
|
||||
infop->s2 = 0;
|
||||
infop->rcdcnt = 0;
|
||||
/* Zero extent, S1, S2, rcrdcnt. create zeros rest */
|
||||
rtnval = dirscan(create, infop, 8);
|
||||
break;
|
||||
|
||||
case 23: tmp_sel(&temp); /* rename file */
|
||||
rtnval = dirscan(rename, infop, 2);
|
||||
break;
|
||||
|
||||
case 24: return(log_dsk); /* return login vector */
|
||||
/* break; */
|
||||
|
||||
case 25: return(UBWORD(GBL.dfltdsk)); /* return current disk */
|
||||
/* break; */
|
||||
|
||||
case 26: GBL.dmaadr = infop; /* set dma address */
|
||||
break;
|
||||
|
||||
/* No function 27 -- Get Allocation Vector */
|
||||
|
||||
case 28: ro_dsk |= 1<<GBL.dfltdsk; /* set disk read-only */
|
||||
break;
|
||||
|
||||
case 29: return(ro_dsk); /* get read-only vector */
|
||||
/* break; */
|
||||
|
||||
case 30: tmp_sel(&temp); /* set file attributes */
|
||||
rtnval = dirscan(set_attr, infop, 2);
|
||||
break;
|
||||
|
||||
case 31: if (GBL.curdsk != GBL.dfltdsk) seldsk(GBL.dfltdsk);
|
||||
move( (GBL.parmp), infop, sizeof *(GBL.parmp) );
|
||||
break; /* return disk parameters */
|
||||
|
||||
case 32: if ( (info & 0xff) <= 15 ) /* get/set user number */
|
||||
GBL.user = (UBYTE)info;
|
||||
return(UBWORD(GBL.user));
|
||||
/* break; */
|
||||
|
||||
case 33: tmp_sel(&temp); /* random read */
|
||||
rtnval = bdosrw(infop, TRUE, 1);
|
||||
break;
|
||||
|
||||
case 34: tmp_sel(&temp); /* random write */
|
||||
rtnval = bdosrw(infop, FALSE, 1);
|
||||
break;
|
||||
|
||||
case 35: tmp_sel(&temp); /* get file size */
|
||||
getsize(infop);
|
||||
break;
|
||||
|
||||
case 36: tmp_sel(&temp); /* set random record */
|
||||
setran(infop);
|
||||
break;
|
||||
|
||||
case 37: info = ~info; /* reset drive */
|
||||
log_dsk &= info;
|
||||
ro_dsk &= info;
|
||||
crit_dsk &= info;
|
||||
break;
|
||||
|
||||
case 40: tmp_sel(&temp); /* write random with 0 fill */
|
||||
rtnval = bdosrw(infop, FALSE, 2);
|
||||
break;
|
||||
|
||||
case 46: free_sp(info); /* get disk free space */
|
||||
break;
|
||||
|
||||
case 47: GBL.chainp = GBL.dmaadr; /* chain to program */
|
||||
warmboot(0); /* terminate calling program */
|
||||
/* break; */
|
||||
|
||||
case 48: return( flushit() ); /* flush buffers */
|
||||
/* break; */
|
||||
|
||||
case 59: return(pgmld(infop,GBL.dmaadr)); /* program load */
|
||||
/* break; */
|
||||
|
||||
case 61: return(setexc(infop)); /* set exception vector */
|
||||
/* break; */
|
||||
|
||||
case 63: set_tpa(infop); /* get/set TPA limits */
|
||||
break;
|
||||
|
||||
default: return(-1); /* bad function number */
|
||||
/* break; */
|
||||
|
||||
}; /* end of switch statement */
|
||||
if (temp.reselect) infop->drvcode = temp.tempdisk;
|
||||
/* if reselected disk, restore it now */
|
||||
|
||||
return(rtnval); /* return the BDOS return value */
|
||||
} /* end _bdos */
|
||||
|
||||
|
||||
tmp_sel(temptr) /* temporarily select disk pointed to by fcb */
|
||||
REG struct tempstr *temptr;
|
||||
{
|
||||
REG struct fcb *fcbp;
|
||||
REG UBYTE tmp_dsk;
|
||||
BSETUP
|
||||
|
||||
fcbp = temptr->fptr; /* get local copy of fcb pointer */
|
||||
tmp_dsk = (temptr->tempdisk = fcbp->drvcode);
|
||||
seldsk( tmp_dsk ? tmp_dsk - 1 : GBL.dfltdsk );
|
||||
|
||||
fcbp->drvcode = GBL.user;
|
||||
temptr->reselect = TRUE;
|
||||
}
|
307
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/bdosmisc.c
Normal file
307
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/bdosmisc.c
Normal file
@@ -0,0 +1,307 @@
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* CP/M-68K BDOS Miscellaneous Module *
|
||||
* *
|
||||
* This module contains miscellaneous loose ends for *
|
||||
* CP/M-68K. Included are: *
|
||||
* *
|
||||
* bdosinit() - BDOS initialization routine *
|
||||
* called from CCP for system init *
|
||||
* warmboot() - BDOS warm boot exit routine *
|
||||
* error() - BDOS error printing routine *
|
||||
* ro_err() - BDOS read-only file error routine *
|
||||
* setexc() - BDOS set exception vector *
|
||||
* set_tpa() - BDOS get/set TPA limits *
|
||||
* serial # and copyright notice, machine readable *
|
||||
* *
|
||||
* *
|
||||
* Configured for Alcyon C on the VAX *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
#include "bdosinc.h" /* Standard I/O declarations */
|
||||
|
||||
#include "bdosdef.h" /* Type and structure declarations for BDOS */
|
||||
|
||||
#include "biosdef.h" /* BIOS definitions, needed for bios wboot */
|
||||
|
||||
|
||||
/* serial # and copyright notice */
|
||||
|
||||
char *copyrt="CP/M-68K(tm), Version 1.1, Copyright (c) 1983, Digital Research";
|
||||
char *serial="XXXX-0000-654321";
|
||||
|
||||
|
||||
|
||||
/* Declare external functions */
|
||||
EXTERN conout(); /* Console Output function */
|
||||
EXTERN UBYTE conin(); /* Console Input function */
|
||||
EXTERN prt_line(); /* Print String function */
|
||||
EXTERN UWORD _bdos(); /* BDOS main routine */
|
||||
EXTERN UBYTE *traphndl(); /* assembly language trap handler */
|
||||
EXTERN initexc(); /* init the exception handler in */
|
||||
/* exceptn.s */
|
||||
EXTERN UWORD dirscan(); /* Directory scanning routine */
|
||||
EXTERN BOOLEAN set_attr(); /* Set File attributes function */
|
||||
EXTERN UWORD dir_rd(); /* Read directory sector routine */
|
||||
|
||||
/* Declare external variables */
|
||||
EXTERN UWORD log_dsk; /* logged-on disk vector */
|
||||
EXTERN UWORD ro_dsk; /* read-only disk vector */
|
||||
EXTERN UWORD crit_dsk; /* vector of critical disks */
|
||||
EXTERN BYTE *tpa_lt; /* TPA lower limit (temporary) */
|
||||
EXTERN BYTE *tpa_lp; /* TPA lower limit (permanent) */
|
||||
EXTERN BYTE *tpa_ht; /* TPA upper limit (temporary) */
|
||||
EXTERN BYTE *tpa_hp; /* TPA upper limit (permanent) */
|
||||
EXTERN BOOLEAN submit; /* external variables from CCP */
|
||||
EXTERN BOOLEAN morecmds;
|
||||
|
||||
|
||||
#define trap2v 34 /* trap 2 vector number */
|
||||
#define ctrlc 3 /* control-c */
|
||||
|
||||
|
||||
/********************************
|
||||
* bdos initialization routine *
|
||||
********************************/
|
||||
|
||||
bdosinit()
|
||||
/* Initialize the File System */
|
||||
{
|
||||
REG struct
|
||||
{
|
||||
WORD nmbr;
|
||||
BYTE *low;
|
||||
LONG length;
|
||||
} *segp;
|
||||
BSETUP
|
||||
|
||||
bsetvec(trap2v, &traphndl); /* set up trap vector */
|
||||
GBL.kbchar = 0; /* initialize the "global" variables */
|
||||
GBL.delim = '$';
|
||||
GBL.lstecho = FALSE;
|
||||
GBL.echodel = TRUE;
|
||||
GBL.chainp = NULL;
|
||||
_bdos(13); /* reset disk system function */
|
||||
segp = bgetseg(); /* get pointer to memory segment table */
|
||||
tpa_lt = tpa_lp = segp->low;
|
||||
tpa_ht = tpa_hp = tpa_lp + segp->length;
|
||||
initexc( &(GBL.excvec[0]) );
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* warmboot entry point *
|
||||
************************/
|
||||
|
||||
warmboot(parm)
|
||||
/* Warm Boot the system */
|
||||
WORD parm; /* 1 to reset submit flag */
|
||||
{
|
||||
BSETUP
|
||||
|
||||
log_dsk &= ~ro_dsk; /* log off any disk marked read-only */
|
||||
/* note that this code is specifically for a single-
|
||||
thread system. It won't work in a multi-task sys */
|
||||
ro_dsk = 0;
|
||||
crit_dsk = 0;
|
||||
if (parm)
|
||||
submit = morecmds = FALSE;
|
||||
GBL.curdsk = 0xff; /* set current disk to "unknown" */
|
||||
tpa_lt = tpa_lp;
|
||||
tpa_ht = tpa_hp;
|
||||
initexc( &(GBL.excvec[0]) );
|
||||
bwboot();
|
||||
}
|
||||
|
||||
|
||||
/*************************/
|
||||
/* disk error handlers */
|
||||
/*************************/
|
||||
|
||||
prt_err(p)
|
||||
/* print the error message */
|
||||
|
||||
BYTE *p;
|
||||
{
|
||||
BSETUP
|
||||
|
||||
prt_line(p);
|
||||
prt_line(" error on drive $");
|
||||
conout(GBL.curdsk + 'A');
|
||||
}
|
||||
|
||||
|
||||
abrt_err(p)
|
||||
/* print the error message and always abort */
|
||||
|
||||
BYTE *p;
|
||||
{
|
||||
prt_err(p);
|
||||
warmboot(1);
|
||||
}
|
||||
|
||||
|
||||
ext_err(cont,p)
|
||||
/* print the error message, and allow for retry, abort, or ignore */
|
||||
|
||||
REG BOOLEAN cont; /* Boolean for whether continuing is allowed */
|
||||
BYTE *p; /* pointer to error message */
|
||||
{
|
||||
REG UBYTE ch;
|
||||
|
||||
prt_err(p);
|
||||
do
|
||||
{
|
||||
prt_line("\n\rDo you want to: Abort (A), Retry (R)$");
|
||||
if (cont) prt_line(", or Continue with bad data (C)$");
|
||||
prt_line("? $");
|
||||
ch = conin() & 0x5f;
|
||||
prt_line("\r\n$");
|
||||
|
||||
switch ( ch )
|
||||
{
|
||||
case ctrlc: warmboot(1);
|
||||
case 'A': warmboot(1);
|
||||
case 'C': if (cont) return(1);
|
||||
break;
|
||||
case 'R': return(0);
|
||||
}
|
||||
} while (TRUE);
|
||||
}
|
||||
|
||||
|
||||
/********************************/
|
||||
/* Read-only File Error Routine */
|
||||
/********************************/
|
||||
|
||||
ro_err(fcbp,dirindx)
|
||||
/* File R/O error */
|
||||
|
||||
REG struct fcb *fcbp;
|
||||
WORD dirindx;
|
||||
{
|
||||
REG BYTE *p;
|
||||
REG UWORD i;
|
||||
REG UBYTE ch;
|
||||
|
||||
p = (BYTE *)fcbp;
|
||||
prt_line("CP/M Disk file error: $");
|
||||
i = 8;
|
||||
do conout(*++p & 0x7f); while (--i);
|
||||
conout('.');
|
||||
i = 3;
|
||||
do conout(*++p & 0x7f); while (--i);
|
||||
prt_line(" is read-only.$");
|
||||
do
|
||||
{
|
||||
prt_line("\r\nDo you want to: Change it to read/write (C), or Abort (A)? $");
|
||||
ch = conin() & 0x5f;
|
||||
prt_line("\r\n$");
|
||||
|
||||
switch ( ch )
|
||||
{
|
||||
case ctrlc: warmboot(1);
|
||||
case 'A': warmboot(1);
|
||||
case 'C': fcbp->ftype[robit] &= 0x7f;
|
||||
dirscan(set_attr, fcbp, 2);
|
||||
return(dir_rd(dirindx >> 2));
|
||||
} /* Reset the directory buffer !!!! */
|
||||
} while (TRUE);
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* error entry point *
|
||||
************************/
|
||||
|
||||
error(errnum)
|
||||
/* Print error message, do appropriate response */
|
||||
|
||||
UWORD errnum; /* error number */
|
||||
{
|
||||
BSETUP
|
||||
|
||||
prt_line("\r\nCP/M Disk $");
|
||||
switch (errnum)
|
||||
{
|
||||
case 0: return( ext_err(TRUE,"read$") );
|
||||
/* break; */
|
||||
|
||||
case 1: return( ext_err(TRUE,"write$") );
|
||||
/* break; */
|
||||
|
||||
case 2: abrt_err("select$");
|
||||
/* break; */
|
||||
|
||||
case 3: return( ext_err(FALSE,"select$") );
|
||||
/* break; */
|
||||
|
||||
case 4: abrt_err("change$");
|
||||
/* break; */
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************************
|
||||
* set exception entry point *
|
||||
*****************************/
|
||||
|
||||
setexc(epbp)
|
||||
/* Set Exception Vector */
|
||||
REG struct
|
||||
{
|
||||
WORD vecnum;
|
||||
BYTE *newvec;
|
||||
BYTE *oldvec;
|
||||
} *epbp;
|
||||
|
||||
{
|
||||
REG WORD i;
|
||||
BSETUP
|
||||
|
||||
i = epbp->vecnum-2;
|
||||
if ( i==32 || i==33) return(-1);
|
||||
if ( (30 <= i) && (i <= 37) ) i -= 20;
|
||||
else if ( (i < 0) || (i > 9) ) return(255);
|
||||
epbp->oldvec = GBL.excvec[i];
|
||||
GBL.excvec[i] = epbp->newvec;
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/*****************************
|
||||
* get/set TPA entry point *
|
||||
*****************************/
|
||||
|
||||
set_tpa(p)
|
||||
/* Get/Set TPA Limits */
|
||||
REG struct
|
||||
{
|
||||
UWORD parms;
|
||||
BYTE *low;
|
||||
BYTE *high;
|
||||
} *p;
|
||||
|
||||
#define set 1
|
||||
#define sticky 2
|
||||
|
||||
{
|
||||
if (p->parms & set)
|
||||
{
|
||||
tpa_lt = p->low;
|
||||
tpa_ht = p->high;
|
||||
if (p->parms & sticky)
|
||||
{
|
||||
tpa_lp = tpa_lt;
|
||||
tpa_hp = tpa_ht;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
p->low = tpa_lt;
|
||||
p->high = tpa_ht;
|
||||
}
|
||||
}
|
314
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/bdosrw.c
Normal file
314
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/bdosrw.c
Normal file
@@ -0,0 +1,314 @@
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* CP/M-68K BDOS Disk Read/Write Module *
|
||||
* *
|
||||
* This module contains functions to perform sequential *
|
||||
* or random access read or write to the disk for CP/M-68K *
|
||||
* *
|
||||
* It includes the following external functions: *
|
||||
* *
|
||||
* bdosrw() - sequential and random disk I/O *
|
||||
* *
|
||||
* *
|
||||
* Compiled with Alcyon C on the VAX *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
#include "bdosinc.h" /* Standard I/O declarations */
|
||||
|
||||
#include "bdosdef.h" /* Type and structure declarations for BDOS */
|
||||
|
||||
|
||||
/* External function definitions */
|
||||
EXTERN UWORD rdwrt(); /* disk read/write routine */
|
||||
EXTERN WORD getaloc(); /* allocate a block of disk space */
|
||||
EXTERN WORD swap(); /* assembly language byte swapper */
|
||||
EXTERN UWORD dirscan(); /* directory scanning routine */
|
||||
EXTERN BOOLEAN openfile(); /* open file function passed to dirscan */
|
||||
EXTERN UWORD close_fi(); /* close file function */
|
||||
EXTERN BOOLEAN create(); /* create file function passed to dirscan */
|
||||
EXTERN UWORD ro_err(); /* read-only file error handler */
|
||||
|
||||
/* External variable definitions */
|
||||
EXTERN UWORD ro_dsk; /* read-only disk vector */
|
||||
|
||||
|
||||
/**********************************************************/
|
||||
/* First, some utility functions used by seqio and ranio */
|
||||
/**********************************************************/
|
||||
|
||||
/******************************
|
||||
* FCB block number routines *
|
||||
******************************/
|
||||
|
||||
WORD blkindx(fcbp)
|
||||
/* return index into fcb disk map */
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb */
|
||||
{
|
||||
REG struct dpb *dparmp; /* pointer to disk parameter block */
|
||||
REG WORD i;
|
||||
REG WORD blkshf;
|
||||
BSETUP
|
||||
|
||||
dparmp = GBL.parmp;
|
||||
blkshf = dparmp->bsh;
|
||||
i = ((fcbp->extent) & dparmp->exm) << (7 - blkshf);
|
||||
return (i + (UBWORD(fcbp->cur_rec) >> blkshf) );
|
||||
}
|
||||
|
||||
|
||||
UWORD blknum(fcbp, index, wrdfcb)
|
||||
/* return block number in fcb indicated by index */
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb */
|
||||
REG WORD index; /* index into disk map of fcb */
|
||||
WORD wrdfcb; /* boolean, fcb disk map of words */
|
||||
{
|
||||
if (wrdfcb)
|
||||
return( swap(fcbp->dskmap.big[index]) );
|
||||
else return( UBWORD(fcbp->dskmap.small[index]) );
|
||||
}
|
||||
|
||||
|
||||
setblk(fcbp, index, wrdfcb, block)
|
||||
/* put block number into fcb */
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb */
|
||||
REG WORD index; /* index into disk map of fcb */
|
||||
WORD wrdfcb; /* boolean, fcb disk map of words */
|
||||
REG UWORD block; /* block number */
|
||||
{
|
||||
fcbp->s2 &= 0x7f; /* set file write flag */
|
||||
if (wrdfcb)
|
||||
fcbp->dskmap.big[index] = swap(block);
|
||||
else fcbp->dskmap.small[index] = (UBYTE)block;
|
||||
}
|
||||
|
||||
|
||||
/***************************
|
||||
* disk read/write routine *
|
||||
***************************/
|
||||
|
||||
UWORD do_io(block, rcrd, parm)
|
||||
|
||||
UWORD block; /* block number */
|
||||
UBYTE rcrd; /* record number */
|
||||
REG WORD parm; /* write parameter */
|
||||
{
|
||||
REG LONG lsec;
|
||||
REG struct dpb *dparmp;
|
||||
BSETUP
|
||||
|
||||
dparmp = GBL.parmp; /* init dpb pointer */
|
||||
lsec = ((LONG)block << (dparmp->bsh)) +
|
||||
(LONG)(rcrd & (dparmp->blm));
|
||||
return( rdwrt(lsec, GBL.dmaadr, parm) );
|
||||
}
|
||||
|
||||
|
||||
/*******************************************
|
||||
* routine for crossing extent boundaries *
|
||||
*******************************************/
|
||||
|
||||
WORD new_ext(fcbp, reading, ran)
|
||||
/* If sequential I/O, open the next extent */
|
||||
/* If random I/O, compute new extent from random record field */
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb */
|
||||
BOOLEAN reading; /* read/write flag */
|
||||
WORD ran; /* random I/O flag */
|
||||
{
|
||||
REG UBYTE mod; /* module number */
|
||||
REG UBYTE ext; /* extent number */
|
||||
REG UBYTE t_mod; /* temp mod number */
|
||||
REG UBYTE t_ext; /* temp extent */
|
||||
BSETUP
|
||||
|
||||
if (ran)
|
||||
{
|
||||
mod = ( (fcbp->ran0) << 4) | ( (fcbp->ran1) >> 4);
|
||||
ext = ( ((fcbp->ran1) & 0x0f) << 1);
|
||||
if ((fcbp->ran2) & 0x80) ext |= 1;
|
||||
/* the calculation of ext was coded this way because of a */
|
||||
/* compiler bug from Alcyon */
|
||||
}
|
||||
else
|
||||
{
|
||||
mod = (fcbp->s2) & 0x3f;
|
||||
ext = (fcbp->extent) + 1; /* for sequential, incr extent */
|
||||
}
|
||||
if (ext >= 32)
|
||||
{
|
||||
ext = 0;
|
||||
mod += 1;
|
||||
}
|
||||
if (mod >= 64) return(6); /* past maximum file size */
|
||||
if ( mod == ((fcbp->s2) & 0x3f) )
|
||||
if ( ! ((ext ^ (fcbp->extent)) & ~((GBL.parmp)->exm) & 0x1f) )
|
||||
{ /* we're in same logical extent */
|
||||
fcbp->extent = ext;
|
||||
return(0);
|
||||
}
|
||||
/* Extent or Module numbers don't match */
|
||||
/* Close the old extent and open a one */
|
||||
if ( close_fi(fcbp) >= 255 ) return(3);
|
||||
/* can't close old extent */
|
||||
t_mod = fcbp->s2;
|
||||
t_ext = fcbp->extent;
|
||||
fcbp->s2 = mod;
|
||||
fcbp->extent = ext;
|
||||
if ( dirscan(openfile, fcbp, 0) >= 255 ) /* open extent */
|
||||
{
|
||||
if (reading)
|
||||
{ /* reading unwritten extent */
|
||||
fcbp->s2 = t_mod;
|
||||
fcbp->extent = t_ext;
|
||||
return(4);
|
||||
}
|
||||
if ( dirscan(create, fcbp, 8) >= 255 )
|
||||
return(5); /* can't create new extent */
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/************************************
|
||||
* Routine to calculate the maximum *
|
||||
* extent number of an FCB in a *
|
||||
* extent-folded environment *
|
||||
************************************/
|
||||
|
||||
UWORD calcext(fcbp)
|
||||
|
||||
REG struct fcb *fcbp;
|
||||
|
||||
{
|
||||
REG UWORD i;
|
||||
REG BYTE *p;
|
||||
BSETUP
|
||||
|
||||
i = 15;
|
||||
p = &(fcbp->dskmap.small[16]);
|
||||
do
|
||||
{
|
||||
if (*--p) break;
|
||||
i -= 1;
|
||||
} while (i);
|
||||
/* Now i contains the index of the last non-zero block in the FCB */
|
||||
if ((GBL.parmp)->dsm > 255) i >>= 1;
|
||||
i >>= 7 - ((GBL.parmp)->bsh);
|
||||
return ( (fcbp->extent) & ~((GBL.parmp)->exm) & 0x1f | i );
|
||||
}
|
||||
|
||||
|
||||
/*********************************
|
||||
* Routine to get the actual *
|
||||
* record count of the currently *
|
||||
* active logical extent of a FCB *
|
||||
*********************************/
|
||||
|
||||
UWORD get_rc(fcbp)
|
||||
|
||||
REG struct fcb *fcbp;
|
||||
|
||||
{
|
||||
REG UWORD ext;
|
||||
|
||||
ext = calcext(fcbp); /* find last active extent in fcb */
|
||||
if (ext == fcbp->extent) return(UBWORD(fcbp->rcdcnt));
|
||||
/* if this is the last active fcb, return fcb's rc */
|
||||
else if (ext > fcbp->extent) return(128);
|
||||
/* if the fcb has more extents past this one, then */
|
||||
/* the current one is logically full */
|
||||
else return (0);
|
||||
/* if we seeked past the last active extent, rc = 0 */
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* bdosrw entry point *
|
||||
************************/
|
||||
|
||||
UWORD bdosrw(fcbp, reading, random)
|
||||
|
||||
REG struct fcb *fcbp; /* fcbp is a pointer to a fcb */
|
||||
REG BOOLEAN reading; /* boolean to tell whether to read or write */
|
||||
WORD random; /* 0 = sequential, 1 = random (normal), */
|
||||
/* 2 = random with zero fill */
|
||||
{
|
||||
REG UWORD block; /* block number from fcb */
|
||||
REG WORD index; /* index into disk map of fcb */
|
||||
REG BYTE *old_dma; /* temp holding spot for dmaadr */
|
||||
REG WORD parm; /* parameter to do-io */
|
||||
REG WORD bigfile; /* file system is in word mode */
|
||||
REG UWORD rtn; /* return parameter */
|
||||
REG UBYTE rc; /* temp storage for rcdcnt */
|
||||
BSETUP
|
||||
|
||||
bigfile = ((GBL.parmp)->dsm) & ~0xff;
|
||||
if ( ( ! reading) && (fcbp->ftype[robit] & 0x80) )
|
||||
ro_err(fcbp,((GBL.dpbp)->dpbp)->drm);
|
||||
/* check for read-only file */
|
||||
if (random)
|
||||
{
|
||||
if ( rtn = new_ext(fcbp, reading, TRUE) ) return(rtn);
|
||||
/* open new extent if necessary, return if error */
|
||||
fcbp->cur_rec = (fcbp->ran2) & 0x7f;
|
||||
}
|
||||
else /* sequential */
|
||||
if (fcbp->cur_rec == 128)
|
||||
{ /* time to try next extent */
|
||||
if ( new_ext(fcbp, reading, FALSE) )
|
||||
return(1); /* if can't open new extent, error */
|
||||
fcbp->cur_rec = 0; /* opened new extent, zero cur_rec */
|
||||
}
|
||||
|
||||
/* record is now in active fcb */
|
||||
rc = fcbp->rcdcnt;
|
||||
if ( UBWORD(fcbp->cur_rec) >= get_rc(fcbp) )
|
||||
{
|
||||
if (reading) return(1); /* reading unwritten data */
|
||||
fcbp->s2 &= 0x7f; /* set file write flag */
|
||||
rc = fcbp->cur_rec + 1;
|
||||
}
|
||||
index = blkindx(fcbp); /* get index into fcb disk map */
|
||||
block = blknum(fcbp, index, bigfile);
|
||||
if (block) parm = (reading ? 0 : 1);
|
||||
else /* if allocated block, parm is just read or write */
|
||||
{ /* unallocated block */
|
||||
if (reading) return(1); /* reading unwritten data */
|
||||
|
||||
/* Writing to new block */
|
||||
/* The parm passed to getaloc is the previously allocated block */
|
||||
/* or 0, if the previous block is not allocated */
|
||||
|
||||
block = getaloc(blknum(fcbp, (index ? (index - 1) : 0), bigfile));
|
||||
if (block == ~0) return(2); /* out of space */
|
||||
setblk(fcbp, index, bigfile, block);
|
||||
parm = 3;
|
||||
if (random == 2)
|
||||
{ /* Write random with zero fill */
|
||||
old_dma = GBL.dmaadr;
|
||||
GBL.dmaadr = GBL.dirbufp; /* Do DMA from dir_buf */
|
||||
index = SECLEN;
|
||||
do GBL.dmaadr[--index] = 0;
|
||||
while (index); /* zero the dma buffer */
|
||||
for (index = 0; index <= ((GBL.parmp)->blm); index++)
|
||||
{
|
||||
do_io(block, (UBYTE)index, parm);
|
||||
/* write zeros to the block */
|
||||
parm = 1; /* next write is not to new block */
|
||||
}
|
||||
GBL.dmaadr = old_dma; /* restore dma address */
|
||||
}
|
||||
}
|
||||
rtn = do_io(block, fcbp->cur_rec, parm);
|
||||
if ( rtn == 0 )
|
||||
{
|
||||
fcbp->rcdcnt = rc;
|
||||
if ( ! random ) fcbp->cur_rec += 1;
|
||||
}
|
||||
return(rtn);
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
|
||||
/********************************************************
|
||||
* *
|
||||
* BIOS definitions for CP/M-68K *
|
||||
* *
|
||||
* Copyright (c) 1982 Digital Research, Inc. *
|
||||
* *
|
||||
* This include file simply defines the BIOS calls *
|
||||
* *
|
||||
********************************************************/
|
||||
|
||||
EXTERN UBYTE bios1(); /* used for character I/O functions */
|
||||
EXTERN bios2(); /* parm1 is word, no return value */
|
||||
EXTERN bios3(); /* used for set dma only */
|
||||
/* parm1 is a pointer, no return */
|
||||
EXTERN UBYTE *bios4(); /* seldsk only, parm1 and parm2 are */
|
||||
/* words, returns a pointer to dph */
|
||||
EXTERN UWORD bios5(); /* for sectran and set exception */
|
||||
EXTERN BYTE *bios6(); /* for get memory segment table */
|
||||
|
||||
|
||||
#define bwboot() bios1(1) /* warm boot */
|
||||
#define bconstat() bios1(2) /* console status */
|
||||
#define bconin() bios1(3) /* console input */
|
||||
#define bconout(parm) bios2(4,parm) /* console output parm */
|
||||
#define blstout(parm) bios2(5,parm) /* list device output */
|
||||
#define bpun(parm) bios2(6,parm) /* punch char output */
|
||||
#define brdr() bios1(7) /* reader input */
|
||||
#define bhome() bios1(8) /* recalibrate drive */
|
||||
#define bseldsk(parm1,parm2) bios4(9,parm1,parm2)
|
||||
/* select disk and return info */
|
||||
#define bsettrk(parm) bios2(10,parm) /* set track on disk */
|
||||
#define bsetsec(parm) bios2(11,parm) /* set sector for disk */
|
||||
#define bsetdma(parm) bios3(12,parm) /* set dma address */
|
||||
#define bread() bios1(13) /* read sector from disk */
|
||||
#define bwrite(parm) bios2(14,parm) /* write sector to disk */
|
||||
#define blistst() bios1(15) /* list device status */
|
||||
#define bsectrn(parm1,parm2) bios5(16,parm1,parm2)
|
||||
/* sector translate */
|
||||
#define bgetseg() bios6(18) /* get memory segment tbl */
|
||||
#define bgetiob() bios1(19) /* get I/O byte */
|
||||
#define bsetiob(parm) bios2(20,parm) /* set I/O byte */
|
||||
#define bflush() bios1(21) /* flush buffers */
|
||||
#define bsetvec(parm1,parm2) bios5(22,parm1,parm2)
|
||||
/* set exception vector */
|
||||
|
332
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/conbdos.c
Normal file
332
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/conbdos.c
Normal file
@@ -0,0 +1,332 @@
|
||||
|
||||
/********************************************************
|
||||
* *
|
||||
* CP/M-68K BDOS Character I/O Routines *
|
||||
* *
|
||||
* This module does BDOS functions 1 thru 11 *
|
||||
* *
|
||||
* It contains the following functions which *
|
||||
* are called from the BDOS main routine: *
|
||||
* constat(); *
|
||||
* conin(); *
|
||||
* tabout(); *
|
||||
* rawconio(); *
|
||||
* prt_line(); *
|
||||
* readline(); *
|
||||
* *
|
||||
* Copyright (c) 1982 Digital Research, Inc. *
|
||||
* *
|
||||
********************************************************/
|
||||
|
||||
#include "bdosinc.h"
|
||||
|
||||
#include "bdosdef.h"
|
||||
|
||||
#include "biosdef.h"
|
||||
|
||||
|
||||
#define ctrlc 0x03
|
||||
#define ctrle 0x05
|
||||
#define ctrlp 0x10
|
||||
#define ctrlq 0x11
|
||||
#define ctrlr 0x12
|
||||
#define ctrls 0x13
|
||||
#define ctrlu 0x15
|
||||
#define ctrlx 0x18
|
||||
|
||||
#define cr 0x0d
|
||||
#define lf 0x0a
|
||||
#define tab 0x09
|
||||
#define rub 0x7f
|
||||
#define bs 0x08
|
||||
#define space 0x20
|
||||
|
||||
|
||||
EXTERN warmboot(); /* External function definition */
|
||||
|
||||
|
||||
/******************/
|
||||
/* console status */
|
||||
/******************/
|
||||
|
||||
BOOLEAN constat()
|
||||
{
|
||||
BSETUP
|
||||
|
||||
return( GBL.kbchar ? TRUE : bconstat() );
|
||||
}
|
||||
|
||||
/********************/
|
||||
/* check for ctrl/s */
|
||||
/* used internally */
|
||||
/********************/
|
||||
conbrk()
|
||||
{
|
||||
REG UBYTE ch;
|
||||
REG BOOLEAN stop;
|
||||
BSETUP
|
||||
|
||||
stop = FALSE;
|
||||
if ( bconstat() ) do
|
||||
{
|
||||
if ( (ch = bconin()) == ctrlc ) warmboot(1);
|
||||
if ( ch == ctrls ) stop = TRUE;
|
||||
else if (ch == ctrlq) stop = FALSE;
|
||||
else if (ch == ctrlp) GBL.lstecho = !GBL.lstecho;
|
||||
else GBL.kbchar = ch;
|
||||
} while (stop);
|
||||
}
|
||||
|
||||
|
||||
/******************/
|
||||
/* console output */
|
||||
/* used internally*/
|
||||
/******************/
|
||||
|
||||
conout(ch)
|
||||
REG UBYTE ch;
|
||||
{
|
||||
BSETUP
|
||||
|
||||
conbrk(); /* check for control-s break */
|
||||
bconout(ch); /* output character to console */
|
||||
if (GBL.lstecho) blstout(ch); /* if ctrl-p on, echo to list dev */
|
||||
if (ch >= ' ') GBL.column++; /* keep track of screen column */
|
||||
else if (ch == cr) GBL.column = 0;
|
||||
else if (ch == bs) GBL.column--;
|
||||
}
|
||||
|
||||
|
||||
/*************************************/
|
||||
/* console output with tab expansion */
|
||||
/*************************************/
|
||||
|
||||
tabout(ch)
|
||||
REG UBYTE ch; /* character to output to console */
|
||||
{
|
||||
BSETUP
|
||||
|
||||
if (ch == tab) do
|
||||
conout(' ');
|
||||
while (GBL.column & 7);
|
||||
else conout(ch);
|
||||
}
|
||||
|
||||
/*******************************/
|
||||
/* console output with tab and */
|
||||
/* control character expansion */
|
||||
/*******************************/
|
||||
|
||||
cookdout(ch)
|
||||
REG UBYTE ch; /* character to output to console */
|
||||
{
|
||||
if (ch == tab) tabout(ch); /* if tab, expand it */
|
||||
else
|
||||
{
|
||||
if ( (UWORD)ch < (UWORD)' ' )
|
||||
{
|
||||
conout( '^' );
|
||||
ch |= 0x40;
|
||||
}
|
||||
conout(ch); /* output the character */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*****************/
|
||||
/* console input */
|
||||
/*****************/
|
||||
|
||||
UBYTE getch() /* Get char from buffer or bios */
|
||||
/* For internal use only */
|
||||
{
|
||||
REG UBYTE temp;
|
||||
BSETUP
|
||||
|
||||
temp = GBL.kbchar; /* get buffered char */
|
||||
GBL.kbchar = 0; /* clear it */
|
||||
return( temp ? temp : bconin() ); /* if non-zero, return it */
|
||||
/* else get char from bios */
|
||||
}
|
||||
|
||||
UBYTE conin() /* BDOS console input function */
|
||||
{
|
||||
REG UBYTE ch;
|
||||
BSETUP
|
||||
|
||||
conout( ch = getch() );
|
||||
if (ch == ctrlp) GBL.lstecho = !GBL.lstecho;
|
||||
return(ch);
|
||||
}
|
||||
|
||||
/******************
|
||||
* raw console i/o *
|
||||
******************/
|
||||
|
||||
UBYTE rawconio(parm) /* BDOS raw console I/O function */
|
||||
|
||||
REG UWORD parm;
|
||||
{
|
||||
BSETUP
|
||||
|
||||
if (parm == 0xff) return(getch());
|
||||
else if (parm == 0xfe) return(constat());
|
||||
else bconout(parm & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************/
|
||||
/* print line up to delimiter($) with tab expansion */
|
||||
/****************************************************/
|
||||
|
||||
prt_line(p)
|
||||
REG UBYTE *p;
|
||||
{
|
||||
BSETUP
|
||||
|
||||
while( *p != GBL.delim ) tabout( *p++ );
|
||||
}
|
||||
|
||||
|
||||
/**********************************************/
|
||||
/* read line with editing and bounds checking */
|
||||
/**********************************************/
|
||||
|
||||
/* Two subroutines first */
|
||||
|
||||
newline(startcol)
|
||||
REG UWORD startcol;
|
||||
{
|
||||
BSETUP
|
||||
|
||||
conout(cr); /* go to new line */
|
||||
conout(lf);
|
||||
while(startcol)
|
||||
{
|
||||
conout(' ');
|
||||
startcol -= 1; /* start output at starting column */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
backsp(bufp, col)
|
||||
/* backspace one character position */
|
||||
REG struct conbuf *bufp; /* pointer to console buffer */
|
||||
REG WORD col; /* starting console column */
|
||||
{
|
||||
REG UBYTE ch; /* current character */
|
||||
REG WORD i;
|
||||
REG UBYTE *p; /* character pointer */
|
||||
BSETUP
|
||||
|
||||
if (bufp->retlen) --(bufp->retlen);
|
||||
/* if buffer non-empty, decrease it by 1 */
|
||||
i = UBWORD(bufp->retlen); /* get new character count */
|
||||
p = &(bufp->cbuf[0]); /* point to character buffer */
|
||||
while (i--) /* calculate column position */
|
||||
{ /* across entire char buffer */
|
||||
ch = *p++; /* get next char */
|
||||
if ( ch == tab )
|
||||
{
|
||||
col += 8;
|
||||
col &= ~7; /* for tab, go to multiple of 8 */
|
||||
}
|
||||
else if ( (UWORD)ch < (UWORD)' ' ) col += 2;
|
||||
/* control chars put out 2 printable chars */
|
||||
else col += 1;
|
||||
}
|
||||
while (GBL.column > col)
|
||||
{
|
||||
conout(bs); /* backspace until we get to proper column */
|
||||
conout(' ');
|
||||
conout(bs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
readline(p) /* BDOS function 10 */
|
||||
REG struct conbuf *p;
|
||||
|
||||
{
|
||||
REG UBYTE ch;
|
||||
REG UWORD i;
|
||||
REG UWORD j;
|
||||
REG UBYTE *q;
|
||||
UWORD stcol;
|
||||
|
||||
BSETUP
|
||||
|
||||
stcol = GBL.column; /* set up starting column */
|
||||
if (GBL.chainp != NULL) /* chain to program code */
|
||||
{
|
||||
i = UBWORD(*(GBL.chainp++));
|
||||
j = UBWORD(p->maxlen);
|
||||
if (j < i) i = j; /* don't overflow console buffer! */
|
||||
p->retlen = (UBYTE)i;
|
||||
q = p->cbuf;
|
||||
while (i)
|
||||
{
|
||||
cookdout( *q++ = *(GBL.chainp++) );
|
||||
i -= 1;
|
||||
}
|
||||
GBL.chainp = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
p->retlen = 0; /* start out with empty buffer */
|
||||
while ( UBWORD(p->retlen) < UBWORD(p->maxlen) )
|
||||
{ /* main loop for read console buffer */
|
||||
|
||||
if ( ((ch=getch()) == ctrlc) && !(p->retlen) )
|
||||
{
|
||||
cookdout(ctrlc);
|
||||
warmboot(1);
|
||||
}
|
||||
|
||||
else if ( (ch == cr) || (ch == lf) )
|
||||
{ /* if cr or lf, exit */
|
||||
conout(cr);
|
||||
break;
|
||||
}
|
||||
|
||||
else if (ch == bs) backsp(p, stcol); /* backspace */
|
||||
|
||||
else if (ch == rub) /* delete character */
|
||||
{
|
||||
if (GBL.echodel)
|
||||
{
|
||||
if (p->retlen)
|
||||
{
|
||||
i = UBWORD(--(p->retlen));
|
||||
conout( p->cbuf[i] );
|
||||
}
|
||||
}
|
||||
else backsp(p, stcol);
|
||||
}
|
||||
|
||||
else if (ch == ctrlp) GBL.lstecho = !GBL.lstecho;
|
||||
/* control-p */
|
||||
else if (ch == ctrlx) /* control-x */
|
||||
do backsp(p,stcol); while (p->retlen);
|
||||
|
||||
else if (ch == ctrle) newline(stcol); /* control-e */
|
||||
|
||||
else if (ch == ctrlu) /* control-u */
|
||||
{
|
||||
conout('#');
|
||||
newline(stcol);
|
||||
p->retlen = 0;
|
||||
}
|
||||
|
||||
else if (ch == ctrlr) /* control-r */
|
||||
{
|
||||
conout('#');
|
||||
newline(stcol);
|
||||
for (i=0; i < UBWORD(p->retlen); i++)
|
||||
cookdout( p->cbuf[i] );
|
||||
}
|
||||
|
||||
else /* normal character */
|
||||
cookdout( p->cbuf[UBWORD((p->retlen)++)] = ch );
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
|
||||
The following is a list of the modules that form the BDOS for the
|
||||
C language version of CP/M-68K:
|
||||
|
||||
SOURCE FILES
|
||||
|
||||
bdosif.s - assembly language interface, trap handler,
|
||||
BIOS caller, function 62 (set supervisor)
|
||||
|
||||
conbdos.c - BDOS functions 1 thru 11 (console functions)
|
||||
|
||||
bdosmisc.c - BDOS initialization, warmboot, error handler, set exception,
|
||||
(used for miscellaneous BDOS routines)
|
||||
|
||||
dskutil.c - bit map handlers, directory read & write, dirscan
|
||||
(miscellaneous disk handling utilities)
|
||||
|
||||
fileio.c - all file handling calls except read & write
|
||||
includes open, close, delete, rename, etc.
|
||||
|
||||
bdosrw.c - sequential and random read & write
|
||||
|
||||
bdosmain.c - the BDOS case statement, global variable declarations
|
||||
|
||||
iosys.c - packet I/O to BIOS interface
|
||||
|
||||
pgmld.s - program load (function 59)
|
||||
|
||||
exceptn.s - exception handler
|
||||
|
||||
|
||||
INCLUDE FILES
|
||||
|
||||
bdosinc.h - standard i/o stuff, universal declarations
|
||||
|
||||
bdosdef.h - BDOS data structure declarations
|
||||
|
||||
biosdef.h - procedure declarations to interface to BIOS
|
||||
|
||||
pktio.h - definition of data structure for packet I/O
|
||||
|
@@ -0,0 +1,15 @@
|
||||
$ set noon
|
||||
$ diff BDOSMAIN.C drb1:[cpm68k.beta2.bdos]BDOSMAIN.C
|
||||
$ diff BDOSMISC.C drb1:[cpm68k.beta2.bdos]BDOSMISC.C
|
||||
$ diff BDOSRW.C drb1:[cpm68k.beta2.bdos]BDOSRW.C
|
||||
$ diff CONBDOS.C drb1:[cpm68k.beta2.bdos]CONBDOS.C
|
||||
$ diff DSKUTIL.C drb1:[cpm68k.beta2.bdos]DSKUTIL.C
|
||||
$ diff FILEIO.C drb1:[cpm68k.beta2.bdos]FILEIO.C
|
||||
$ diff IOSYS.C drb1:[cpm68k.beta2.bdos]IOSYS.C
|
||||
$ diff BDOSIF.S drb1:[cpm68k.beta2.bdos]BDOSIF.S
|
||||
$ diff EXCEPTN.S drb1:[cpm68k.beta2.bdos]EXCEPTN.S
|
||||
$ diff PGMLD.S drb1:[cpm68k.beta2.bdos]PGMLD.S
|
||||
$ diff BDOSDEF.H drb1:[cpm68k.beta2.bdos]BDOSDEF.H
|
||||
$ diff BDOSINC.H drb1:[cpm68k.beta2.bdos]BDOSINC.H
|
||||
$ diff BIOSDEF.H drb1:[cpm68k.beta2.bdos]BIOSDEF.H
|
||||
$ diff PKTIO.H drb1:[cpm68k.beta2.bdos]PKTIO.H
|
297
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/dskutil.c
Normal file
297
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/dskutil.c
Normal file
@@ -0,0 +1,297 @@
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* CP/M-68K BDOS Disk Utilities Module *
|
||||
* *
|
||||
* This module contains the miscellaneous utilities *
|
||||
* for manipulating the disk in CP/M-68K. Included are: *
|
||||
* *
|
||||
* dirscan() - general purpose dir scanning *
|
||||
* setaloc() - set bit in allocation vector *
|
||||
* clraloc() - clear bit in allocation vector *
|
||||
* getaloc() - get free allocation block *
|
||||
* dchksum() - directory checksum calculator *
|
||||
* dir_rd() - read directory sector *
|
||||
* dir_wr() - write directory sector *
|
||||
* rdwrt() - read/write disk sector *
|
||||
* *
|
||||
* *
|
||||
* Configured for Alcyon C on the VAX *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
#include "bdosinc.h" /* Standard I/O declarations */
|
||||
|
||||
#include "bdosdef.h" /* Type and structure declarations for BDOS */
|
||||
|
||||
#include "pktio.h" /* Packet I/O definitions */
|
||||
|
||||
|
||||
/* declare external functions and variables */
|
||||
EXTERN UWORD do_phio(); /* external physical disk I/O routine */
|
||||
EXTERN UWORD error(); /* external error routine */
|
||||
|
||||
EXTERN UWORD log_dsk; /* logged-on disk vector */
|
||||
EXTERN UWORD ro_dsk; /* read-only disk vector */
|
||||
EXTERN UWORD crit_dsk; /* critical disk vector */
|
||||
|
||||
|
||||
/**********************
|
||||
* read/write routine *
|
||||
**********************/
|
||||
|
||||
UWORD rdwrt(secnum, dma, parm)
|
||||
/* General disk sector read/write routine */
|
||||
/* It simply sets up a I/O packet and sends it to do_phio */
|
||||
|
||||
LONG secnum; /* logical sector number to read/write */
|
||||
UBYTE *dma; /* dma address */
|
||||
REG WORD parm; /* 0 for read, write parm + 1 for write */
|
||||
|
||||
{
|
||||
struct iopb rwpkt;
|
||||
BSETUP
|
||||
|
||||
rwpkt.devnum = GBL.curdsk; /* disk to read/write */
|
||||
if (parm)
|
||||
{
|
||||
rwpkt.iofcn = (BYTE)write; /* if parm non-zero, we're doing a write */
|
||||
rwpkt.ioflags = (BYTE)(parm-1); /* pass write parm */
|
||||
if ( ro_dsk & (1 << (rwpkt.devnum)) ) error(4);
|
||||
/* don't write on read-only disk */
|
||||
}
|
||||
else
|
||||
{
|
||||
rwpkt.iofcn = (BYTE)read;
|
||||
rwpkt.ioflags = (BYTE)0;
|
||||
}
|
||||
rwpkt.devadr = secnum; /* sector number */
|
||||
rwpkt.xferadr = dma; /* dma address */
|
||||
|
||||
/* parameters that are currently not used by do_phio
|
||||
rwpkt.devtype = disk;
|
||||
rwpkt.xferlen = 1;
|
||||
*/
|
||||
rwpkt.infop = GBL.dphp; /* pass ptr to dph */
|
||||
while ( do_phio(&rwpkt) )
|
||||
if ( error( parm ? 1 : 0 ) ) break;
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/***************************
|
||||
* directory read routine *
|
||||
***************************/
|
||||
|
||||
UWORD dir_rd(secnum)
|
||||
|
||||
WORD secnum;
|
||||
{
|
||||
BSETUP
|
||||
|
||||
return( rdwrt((LONG)secnum, GBL.dirbufp, 0) );
|
||||
}
|
||||
|
||||
|
||||
/****************************
|
||||
* directory write routine *
|
||||
****************************/
|
||||
|
||||
UWORD dir_wr(secnum)
|
||||
|
||||
REG WORD secnum;
|
||||
{
|
||||
REG UWORD rtn;
|
||||
BSETUP
|
||||
|
||||
rtn = rdwrt( (LONG)secnum, GBL.dirbufp, 2);
|
||||
if ( secnum < (GBL.parmp)->cks )
|
||||
*((GBL.dphp)->csv + secnum) = dchksum();
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
|
||||
/*******************************
|
||||
* directory checksum routine *
|
||||
*******************************/
|
||||
|
||||
UBYTE dchksum()
|
||||
/* Compute checksum over one directory sector */
|
||||
/* Note that this implementation is dependant on the representation */
|
||||
/* of a LONG and is therefore not very portable. But it's fast */
|
||||
{
|
||||
REG LONG *p; /* local temp variables */
|
||||
REG LONG lsum;
|
||||
REG WORD i;
|
||||
|
||||
BSETUP
|
||||
|
||||
p = GBL.dirbufp; /* point to directory buffer */
|
||||
lsum = 0;
|
||||
i = SECLEN / (sizeof lsum);
|
||||
do
|
||||
{
|
||||
lsum += *p++; /* add next 4 bytes of directory */
|
||||
i -= 1;
|
||||
} while (i);
|
||||
lsum += (lsum >> 16);
|
||||
lsum += (lsum >> 8);
|
||||
return( (UBYTE)(lsum & 0xff) );
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* dirscan entry point *
|
||||
************************/
|
||||
|
||||
UWORD dirscan(funcp, fcbp, parms)
|
||||
|
||||
BOOLEAN (*funcp)(); /* funcp is a pointer to a Boolean function */
|
||||
REG struct fcb *fcbp; /* fcbp is a pointer to a fcb */
|
||||
REG UWORD parms; /* parms is 16 bit set of bit parameters */
|
||||
|
||||
/* Parms & 1 = 0 to start at beginning of dir, 1 to continue from last */
|
||||
/* Parms & 2 = 0 to stop when *funcp is true, 1 to go until end */
|
||||
/* Parms & 4 = 0 to check the dir checksum, 1 to store new checksum */
|
||||
/* Parms & 8 = 0 to stop at hiwater, 1 to go until end of directory */
|
||||
|
||||
#define continue 1
|
||||
#define full 2
|
||||
#define initckv 4
|
||||
#define pasthw 8
|
||||
|
||||
{
|
||||
REG UWORD i; /* loop counter */
|
||||
REG struct dpb *dparmp; /* pointer to disk parm block */
|
||||
REG UWORD dirsec; /* sector number we're working on */
|
||||
REG UWORD rtn; /* return value */
|
||||
REG UBYTE *p; /* scratch pointer */
|
||||
REG UWORD bitvec; /* disk nmbr represented as a vector */
|
||||
|
||||
BSETUP
|
||||
|
||||
dparmp = GBL.parmp; /* init ptr to dpb */
|
||||
rtn = 255; /* assume it doesn't work */
|
||||
|
||||
i = ( (parms & continue) ? GBL.srchpos + 1 : 0 );
|
||||
while ( (parms & pasthw) || (i <= ((GBL.dphp)->hiwater + 1)) )
|
||||
{ /* main directory scanning loop */
|
||||
if ( i > dparmp->drm ) break;
|
||||
if ( ! (i & 3) )
|
||||
{ /* inside loop happens when we need to
|
||||
read another directory sector */
|
||||
retry: dirsec = i >> 2;
|
||||
dir_rd(dirsec); /* read the directory sector */
|
||||
if ( dirsec < (dparmp->cks) ) /* checksumming on this sector? */
|
||||
{
|
||||
p = ((GBL.dphp)->csv) + dirsec;
|
||||
/* point to checksum vector byte */
|
||||
if (parms & initckv) *p = dchksum();
|
||||
else if (*p != dchksum())
|
||||
{ /* checksum error! */
|
||||
(GBL.dphp)->hiwater = dparmp->drm; /* reset hi water */
|
||||
bitvec = 1 << (GBL.curdsk);
|
||||
if (crit_dsk & bitvec) /* if disk in critical mode */
|
||||
ro_dsk |= bitvec; /* then set it to r/o */
|
||||
else
|
||||
{
|
||||
log_dsk &= ~bitvec; /* else log it off */
|
||||
seldsk(GBL.curdsk); /* and re-select it */
|
||||
goto retry; /* and re-do current op */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GBL.srchpos = i;
|
||||
if ( (*funcp)(fcbp, (GBL.dirbufp) + (i&3), i) )
|
||||
/* call function with parms of (1) fcb ptr,
|
||||
(2) pointer to directory entry, and
|
||||
(3) directory index */
|
||||
{
|
||||
if (parms & full) rtn = 0; /* found a match, but keep going */
|
||||
else return(i & 3); /* return directory code */
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
|
||||
/****************************************
|
||||
* Routines to manage allocation vector *
|
||||
* setaloc() *
|
||||
* clraloc() *
|
||||
* getaloc() *
|
||||
****************************************/
|
||||
|
||||
setaloc(bitnum)
|
||||
/* Set bit in allocation vector */
|
||||
REG UWORD bitnum;
|
||||
{
|
||||
BSETUP
|
||||
|
||||
if (bitnum >= 0 && bitnum <= (GBL.parmp)->dsm)
|
||||
*((GBL.dphp)->alv + (bitnum>>3)) |= 0x80 >> (bitnum & 7);
|
||||
}
|
||||
|
||||
|
||||
clraloc(bitnum)
|
||||
/* Clear bit in allocation vector */
|
||||
REG UWORD bitnum;
|
||||
{
|
||||
BSETUP
|
||||
|
||||
if (bitnum > 0 && bitnum <= (GBL.parmp)->dsm)
|
||||
*((GBL.dphp)->alv + (bitnum>>3)) &= ~(0x80 >> (bitnum & 7));
|
||||
}
|
||||
|
||||
|
||||
UWORD chkaloc(i)
|
||||
/* Check bit i in allocation vector */
|
||||
/* Return non-zero if block free, else return zero */
|
||||
REG UWORD i;
|
||||
{
|
||||
BSETUP
|
||||
|
||||
return( ~(*( (GBL.dphp)->alv + (i >> 3) )) & (0x80 >> (i&7)) );
|
||||
}
|
||||
|
||||
|
||||
UWORD getaloc(leftblk)
|
||||
/* Get a free block in the file system and set the bit in allocation vector */
|
||||
/* It is passed the block number of the last block allocated to the file */
|
||||
/* It tries to allocate the block closest to the block that was passed */
|
||||
REG UWORD leftblk;
|
||||
{
|
||||
REG UWORD blk; /* block number to allocate */
|
||||
REG UWORD rtblk; /* high block number to try */
|
||||
REG UWORD diskmax; /* # bits in alv - 1 */
|
||||
|
||||
BSETUP
|
||||
LOCK /* need to lock the file system while messing
|
||||
with the allocation vector */
|
||||
|
||||
diskmax = (GBL.parmp)->dsm;
|
||||
/* get disk max field from dpb */
|
||||
rtblk = leftblk;
|
||||
blk = ~0; /* -1 returned if no free block found */
|
||||
while (leftblk || rtblk < diskmax)
|
||||
{
|
||||
if (leftblk)
|
||||
if (chkaloc(--leftblk))
|
||||
{
|
||||
blk = leftblk;
|
||||
break;
|
||||
}
|
||||
if (rtblk < diskmax)
|
||||
if (chkaloc(++rtblk))
|
||||
{
|
||||
blk = rtblk;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (blk != ~0) setaloc(blk);
|
||||
UNLOCK
|
||||
return(blk);
|
||||
}
|
291
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/exceptn.s
Normal file
291
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/exceptn.s
Normal file
@@ -0,0 +1,291 @@
|
||||
|
||||
*************************************************
|
||||
* *
|
||||
* CP/M-68k Basic Disk Operating System *
|
||||
* Exception Handling Module *
|
||||
* *
|
||||
* Version 0.0 -- July 21, 1982 *
|
||||
* Version 0.1 -- July 25, 1982 *
|
||||
* Version 0.2 -- October 6, 1982 *
|
||||
* Version 0.3 -- December 21, 1982 *
|
||||
* *
|
||||
*************************************************
|
||||
|
||||
|
||||
.globl _initexc
|
||||
.globl _tpa_lp
|
||||
.globl _tpa_hp
|
||||
|
||||
bgetseg = 18
|
||||
bsetexc = 22
|
||||
buserr = 2
|
||||
spurious = 24
|
||||
trap0 = 32
|
||||
trap2 = 34
|
||||
trap3 = 35
|
||||
endvec = 48
|
||||
|
||||
_initexc:
|
||||
* Initialize Exception Vector Handlers
|
||||
* It has 1 passed parameter: the address of the exception vector array
|
||||
move #bsetexc,d0
|
||||
moveq #2,d1
|
||||
move.l #exchndl,d2
|
||||
init1:
|
||||
movem.l d0-d2,-(sp)
|
||||
trap #3 * BIOS call to set exception vector
|
||||
movem.l (sp)+,d0-d2
|
||||
init2: addq #1,d1
|
||||
add.l #4,d2
|
||||
cmpi #spurious,d1
|
||||
bne init3
|
||||
move #trap0,d1
|
||||
init3: cmpi #trap2,d1
|
||||
beq init2 * don't init trap 2 or trap 3
|
||||
cmpi #trap3,d1
|
||||
beq init2
|
||||
cmpi #endvec,d1
|
||||
blt init1
|
||||
* initialize the exception vector array
|
||||
|
||||
moveq #bgetseg,d0
|
||||
trap #3 * get the original TPA limits
|
||||
movea.l d0,a0
|
||||
tst.w (a0)+
|
||||
move.l (a0)+,d1 * d1 = original low TPA limit
|
||||
move.l d1,d2
|
||||
add.l (a0),d2 * d2 = original high TPA limit
|
||||
move.l _tpa_lp,d3 * d3 = new low TPA limit
|
||||
move.l _tpa_hp,d4 * d4 = new high TPA limit
|
||||
move #17,d0
|
||||
movea.l 4(sp),a0
|
||||
move.l a0,evec_adr * save exception vector address
|
||||
init4:
|
||||
cmp.l (a0),d1
|
||||
bhi do_init * if old exception outside orig TPA, clear it
|
||||
cmp.l (a0),d2
|
||||
bls do_init
|
||||
* current exception array entry is in original TPA
|
||||
cmp.l (a0),d3
|
||||
bhi dontinit * if old exception in old TPA but outside new
|
||||
cmp.l (a0),d4 * TPA, don't clear it
|
||||
bls dontinit
|
||||
do_init:
|
||||
clr.l (a0)
|
||||
dontinit:
|
||||
tst.l (a0)+
|
||||
dbf d0,init4
|
||||
rts
|
||||
|
||||
exchndl:
|
||||
bsr.w except
|
||||
excrtn0:
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
bsr.w except
|
||||
|
||||
|
||||
except:
|
||||
clr.w -(sp)
|
||||
movem.l a0/d0,-(sp) * 10 words now on stack in following order:
|
||||
* _______________________________
|
||||
* |____________D0.L_______________|
|
||||
* |____________A0.L_______________|
|
||||
* |____0000______|________________
|
||||
* |_______Handler Return__________|
|
||||
* If bus error, extra 2 longs are here
|
||||
* ______________
|
||||
* |__Status Reg__|________________
|
||||
* |_____Exception Return__________|
|
||||
|
||||
move.l 10(sp),d0 * get return address from above array
|
||||
sub.l #excrtn0,d0 * d0 now has 4 * (encoded excptn nmbr), where
|
||||
* encoded excptn nmbr is in [0..21,22..37]
|
||||
* representing [2..23,32..47]
|
||||
cmpi #36,d0 * if d0/4 is in [0..9,22..29] then
|
||||
ble chkredir * the exception may be redirected
|
||||
cmpi #88,d0
|
||||
blt dfltexc
|
||||
cmpi #116,d0
|
||||
bgt dfltexc
|
||||
* in range of redirected exceptions
|
||||
subi #48,d0 * subtract 4*12 to normalize [0..9,22..29]
|
||||
* into [0..9,10..17]
|
||||
chkredir:
|
||||
movea.l evec_adr,a0
|
||||
adda d0,a0 * index into exception vector array
|
||||
tst.l (a0) * if 00000000, then not redirected
|
||||
bne usrexc
|
||||
* not redirected, do default handler
|
||||
cmpi #40,d0
|
||||
blt dfltexc
|
||||
addi #48,d0 * add 4*12 that was sub'd above
|
||||
dfltexc:
|
||||
adda #14,sp * throw away 7 words that we added to stack
|
||||
asr #2,d0 * divide d0 by 4
|
||||
* now d0 is in [0..21,22..37]
|
||||
* to represent [2..23,32..47]
|
||||
cmpi #2,d0 * bus or address error?
|
||||
bge nobusexc
|
||||
movem.l (sp)+,a0-a1 * if yes, throw away 4 words from stack
|
||||
nobusexc:
|
||||
tst.w (sp)+ * throw away stacked SR
|
||||
addi #2,d0
|
||||
cmpi #23,d0 * get back real excptn nmbr in [2..23,32..47]
|
||||
ble lowexc
|
||||
addi #8,d0
|
||||
lowexc: move d0,-(sp) * save excptn nmbr
|
||||
lea excmsg1,a0
|
||||
bsr print * print default exception message
|
||||
move (sp)+,d0
|
||||
bsr prtbyte
|
||||
lea excmsg2, a0
|
||||
bsr print
|
||||
move.l (sp)+,d0
|
||||
bsr prtlong
|
||||
lea excmsg3, a0
|
||||
bsr print
|
||||
clr.l d0
|
||||
trap #2 * warm boot
|
||||
rte
|
||||
|
||||
usrexc:
|
||||
* Call user exception handler
|
||||
* make sure exception information is on his stack
|
||||
move.l (a0),10(sp) * put user handler address on our stack
|
||||
move.l usp,a0 * user stack pointer to a0
|
||||
cmpi #8,d0 * address or bus error?
|
||||
blt addrexc * if yes, skip
|
||||
btst #13,14(sp) * exception occured in user state?
|
||||
bne supstat1 * if no, go to supervisor handler
|
||||
move.l 16(sp),-(a0) * put exception return on user stack
|
||||
move.w 14(sp),-(a0) * put SR on user stack
|
||||
move.l a0,usp * update user stack pointer
|
||||
movem.l (sp)+,a0/d0 * restore regs
|
||||
move.l 2(sp),8(sp) * move address of user handler to excptn rtn
|
||||
addq #6,sp * clear junk from stack
|
||||
andi #$7fff,(sp) * clear trace bit
|
||||
rte * go to user handler
|
||||
addrexc:
|
||||
btst #13,22(sp) * exception occured in user state?
|
||||
bne supstat2 * if no, go to supervisor handler
|
||||
move.l 24(sp),-(a0) * put exception return on user stack
|
||||
move.w 22(sp),-(a0) * put SR on user stack
|
||||
move.l 18(sp),-(a0) * put extra 2 longs on user stack
|
||||
move.l 14(sp),-(a0)
|
||||
move.l a0,usp * update user stack pointer
|
||||
movem.l (sp)+,a0/d0 * restore regs
|
||||
move.l 2(sp),16(sp) * move address of user handler to excptn rtn
|
||||
adda #14,sp * clear junk from stack
|
||||
andi #$7fff,(sp) * clear trace bit
|
||||
rte * go to user handler
|
||||
|
||||
supstat1:
|
||||
move.w 14(sp),8(sp) * move SR to our exception return
|
||||
bra supstat3
|
||||
supstat2:
|
||||
move.w 22(sp),8(sp)
|
||||
supstat3:
|
||||
movem.l (sp)+,a0/d0
|
||||
rte
|
||||
|
||||
*
|
||||
* Subroutines
|
||||
*
|
||||
|
||||
print:
|
||||
clr.l d1
|
||||
move.b (a0)+, d1
|
||||
beq prtdone
|
||||
move #2, d0
|
||||
trap #2
|
||||
bra print
|
||||
prtdone:
|
||||
rts
|
||||
|
||||
prtlong:
|
||||
* Print d0.l in hex format
|
||||
move d0,-(sp)
|
||||
swap d0
|
||||
bsr prtword
|
||||
move (sp)+,d0
|
||||
|
||||
prtword:
|
||||
* Print d0.w in hex format
|
||||
move d0,-(sp)
|
||||
lsr #8,d0
|
||||
bsr prtbyte
|
||||
move (sp)+,d0
|
||||
|
||||
prtbyte:
|
||||
* Print d0.b in hex format
|
||||
move d0,-(sp)
|
||||
lsr #4,d0
|
||||
bsr prtnib
|
||||
move (sp)+,d0
|
||||
|
||||
prtnib:
|
||||
andi #$f,d0
|
||||
cmpi #10,d0
|
||||
blt lt10
|
||||
addi.b #'A'-'9'-1,d0
|
||||
lt10:
|
||||
addi.b #'0',d0
|
||||
move d0,d1
|
||||
move #2,d0
|
||||
trap #2
|
||||
rts
|
||||
|
||||
|
||||
.data
|
||||
|
||||
excmsg1:
|
||||
.dc.b 13,10,10,'Exception $',0
|
||||
|
||||
excmsg2:
|
||||
.dc.b ' at user address $',0
|
||||
|
||||
excmsg3:
|
||||
.dc.b '. Aborted.',0
|
||||
|
||||
|
||||
.bss
|
||||
|
||||
evec_adr:
|
||||
.ds.l 1
|
||||
|
||||
.end
|
659
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/fileio.c
Normal file
659
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/fileio.c
Normal file
@@ -0,0 +1,659 @@
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* CP/M-68K BDOS File I/O Module *
|
||||
* *
|
||||
* This module contains all file handling BDOS functions *
|
||||
* except for read and write for CP/M-68K. Included are: *
|
||||
* *
|
||||
* seldsk() - select disk *
|
||||
* openfile() - open file *
|
||||
* close_fi() - close file *
|
||||
* search() - search for first/next file match *
|
||||
* create() - create file *
|
||||
* delete() - delete file *
|
||||
* rename() - rename file *
|
||||
* set_attr() - set file attributes *
|
||||
* getsize() - get file size *
|
||||
* setran() - set random record field *
|
||||
* free_sp() - get disk free space *
|
||||
* move() - general purpose byte mover *
|
||||
* *
|
||||
* *
|
||||
* Compiled with Alcyon C on the VAX *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
#include "bdosinc.h" /* Standard I/O declarations */
|
||||
|
||||
#include "bdosdef.h" /* Type and structure declarations for BDOS */
|
||||
|
||||
#include "pktio.h" /* Packet I/O definitions */
|
||||
|
||||
/* declare external fucntions */
|
||||
EXTERN UWORD dirscan(); /* directory scanning routine */
|
||||
EXTERN UWORD error(); /* disk error routine */
|
||||
EXTERN UWORD ro_err(); /* read-only file error routine */
|
||||
EXTERN UWORD do_phio(); /* packet disk i/o handler */
|
||||
EXTERN clraloc(); /* clear bit in allocation vector */
|
||||
EXTERN setaloc(); /* set bit in allocation vector */
|
||||
EXTERN UWORD swap(); /* assembly language byte swapper */
|
||||
EXTERN UWORD dir_wr(); /* directory write routine */
|
||||
EXTERN tmp_sel(); /* temporary select disk routine */
|
||||
EXTERN UWORD calcext(); /* calc max extent allocated for fcb */
|
||||
EXTERN UWORD udiv(); /* unsigned divide routine */
|
||||
|
||||
|
||||
/* declare external variables */
|
||||
EXTERN UWORD log_dsk; /* logged-on disk vector */
|
||||
EXTERN UWORD ro_dsk; /* read-only disk vector */
|
||||
EXTERN UWORD crit_dsk; /* vector of disks in critical state */
|
||||
|
||||
|
||||
/************************************
|
||||
* This function passed to dirscan *
|
||||
* from seldsk (below) *
|
||||
************************************/
|
||||
|
||||
BOOLEAN alloc(fcbp, dirp, dirindx)
|
||||
/* Set up allocation vector for directory entry pointed to by dirp */
|
||||
|
||||
struct fcb *fcbp; /* not used in this function */
|
||||
REG struct dirent *dirp; /* pointer to directory entry */
|
||||
WORD dirindx; /* index into directory for *dirp */
|
||||
{
|
||||
REG WORD i; /* loop counter */
|
||||
BSETUP
|
||||
|
||||
if ( UBWORD(dirp->entry) < 0x10 ) /* skip MP/M 2.x and CP/M 3.x XFCBs */
|
||||
{
|
||||
(GBL.dphp)->hiwater = dirindx; /* set up high water mark for disk */
|
||||
i = 0;
|
||||
if ((GBL.parmp)->dsm < 256)
|
||||
{
|
||||
do setaloc( UBWORD(dirp->dskmap.small[i++]) );
|
||||
while (i <= 15);
|
||||
}
|
||||
else
|
||||
{
|
||||
do setaloc(swap(dirp->dskmap.big[i++]));
|
||||
while (i <= 7);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* seldsk entry point *
|
||||
************************/
|
||||
|
||||
seldsk(dsknum)
|
||||
|
||||
REG UBYTE dsknum; /* disk number to select */
|
||||
|
||||
{
|
||||
struct iopb selpkt;
|
||||
REG WORD i;
|
||||
UWORD j;
|
||||
REG UBYTE logflag;
|
||||
BSETUP
|
||||
|
||||
logflag = ~(log_dsk >> dsknum) & 1;
|
||||
if ((GBL.curdsk != dsknum) || logflag)
|
||||
{ /* if not last used disk or not logged on */
|
||||
selpkt.iofcn = sel_info;
|
||||
GBL.curdsk = (selpkt.devnum = dsknum);
|
||||
if (UBWORD(dsknum) > 15) error(2);
|
||||
selpkt.ioflags = logflag ^ 1;
|
||||
do
|
||||
{
|
||||
do_phio(&selpkt); /* actually do the disk select */
|
||||
if ( (GBL.dphp = selpkt.infop) != NULL ) break;
|
||||
} while ( ! error(3) );
|
||||
|
||||
GBL.dirbufp = (GBL.dphp)->dbufp;
|
||||
/* set up GBL copies of dir_buf and dpb ptrs */
|
||||
GBL.parmp = (GBL.dphp)->dpbp;
|
||||
}
|
||||
if (logflag)
|
||||
{ /* if disk not previously logged on, do it now */
|
||||
LOCK /* must lock the file system while messing with alloc vec */
|
||||
i = (GBL.parmp)->dsm;
|
||||
do clraloc(i); while (i--); /* clear the allocation vector */
|
||||
i = udiv( (LONG)(((GBL.parmp)->drm) + 1),
|
||||
4 * (((GBL.parmp)->blm) + 1), &j);
|
||||
/* calculate nmbr of directory blks */
|
||||
if (j) i++; /* round up */
|
||||
do setaloc(--i); while (i); /* alloc directory blocks */
|
||||
dirscan(alloc, NULL, 0x0e); /* do directory scan & alloc blocks */
|
||||
log_dsk |= 1 << dsknum; /* mark disk as logged in */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*******************************
|
||||
* General purpose byte mover *
|
||||
*******************************/
|
||||
|
||||
move(p1, p2, i)
|
||||
|
||||
REG BYTE *p1;
|
||||
REG BYTE *p2;
|
||||
REG WORD i;
|
||||
{
|
||||
while (i--)
|
||||
*p2++ = *p1++;
|
||||
}
|
||||
|
||||
|
||||
/*************************************
|
||||
* General purpose filename matcher *
|
||||
*************************************/
|
||||
|
||||
BOOLEAN match(p1, p2, chk_ext)
|
||||
|
||||
REG UBYTE *p1;
|
||||
REG UBYTE *p2;
|
||||
BOOLEAN chk_ext;
|
||||
{
|
||||
REG WORD i;
|
||||
REG UBYTE temp;
|
||||
BSETUP
|
||||
|
||||
i = 12;
|
||||
do
|
||||
{
|
||||
temp = (*p1 ^ '?');
|
||||
if ( ((*p1++ ^ *p2++) & 0x7f) && temp )
|
||||
return(FALSE);
|
||||
i -= 1;
|
||||
} while (i);
|
||||
if (chk_ext)
|
||||
{
|
||||
if ( (*p1 != '?') && ((*p1 ^ *p2) & ~((GBL.parmp)->exm)) )
|
||||
return(FALSE);
|
||||
p1 += 2;
|
||||
p2 += 2;
|
||||
if ((*p1 ^ *p2) & 0x3f) return(FALSE);
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* openfile entry point *
|
||||
************************/
|
||||
|
||||
BOOLEAN openfile(fcbp, dirp, dirindx)
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb for file to open */
|
||||
struct dirent *dirp; /* pointer to directory entry */
|
||||
WORD dirindx;
|
||||
|
||||
{
|
||||
REG UBYTE fcb_ext; /* extent field from fcb */
|
||||
REG BOOLEAN rtn;
|
||||
BSETUP
|
||||
|
||||
if ( rtn = match(fcbp, dirp, TRUE) )
|
||||
{
|
||||
fcb_ext = fcbp->extent; /* save extent number from user's fcb */
|
||||
move(dirp, fcbp, sizeof *dirp);
|
||||
/* copy dir entry into user's fcb */
|
||||
fcbp->extent = fcb_ext;
|
||||
fcbp->s2 |= 0x80; /* set hi bit of S2 (write flag) */
|
||||
crit_dsk |= 1 << (GBL.curdsk);
|
||||
}
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
|
||||
/*************************/
|
||||
/* flush buffers routine */
|
||||
/*************************/
|
||||
|
||||
UWORD flushit()
|
||||
{
|
||||
REG UWORD rtn; /* return code from flush buffers call */
|
||||
struct iopb flushpkt; /* I/O packet for flush buffers call */
|
||||
|
||||
flushpkt.iofcn = flush;
|
||||
while ( rtn = do_phio(&flushpkt) )
|
||||
if ( error(1) ) break;
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
|
||||
/*********************************
|
||||
* file close routine for dirscan *
|
||||
*********************************/
|
||||
|
||||
BOOLEAN close(fcbp, dirp, dirindx)
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb */
|
||||
REG struct dirent *dirp; /* pointer to directory entry */
|
||||
WORD dirindx; /* index into directory */
|
||||
|
||||
{
|
||||
REG WORD i;
|
||||
REG UBYTE *fp;
|
||||
REG UBYTE *dp;
|
||||
REG UWORD fcb_ext;
|
||||
REG UWORD dir_ext;
|
||||
BSETUP
|
||||
|
||||
if ( match(fcbp, dirp, TRUE) )
|
||||
{ /* Note that FCB merging is done here as a final
|
||||
confirmation that disks haven't been swapped */
|
||||
LOCK
|
||||
fp = &(fcbp->dskmap.small[0]);
|
||||
dp = &(dirp->dskmap.small[0]);
|
||||
if ((GBL.parmp)->dsm < 256)
|
||||
{ /* Small disk map merge routine */
|
||||
i = 16;
|
||||
do
|
||||
{
|
||||
if (*dp)
|
||||
{
|
||||
if (*fp)
|
||||
{
|
||||
if (*dp != *fp) goto badmerge;
|
||||
}
|
||||
else *fp = *dp;
|
||||
}
|
||||
else *dp = *fp;
|
||||
fp += 1;
|
||||
dp += 1;
|
||||
i -= 1;
|
||||
} while (i);
|
||||
}
|
||||
else
|
||||
{ /* Large disk map merge routine */
|
||||
i = 8;
|
||||
do
|
||||
{
|
||||
if (*(UWORD *)dp)
|
||||
{
|
||||
if (*(UWORD *)fp)
|
||||
{
|
||||
if (*(UWORD *)dp != *(UWORD *)fp) goto badmerge;
|
||||
}
|
||||
else *(UWORD *)fp = *(UWORD *)dp;
|
||||
}
|
||||
else *(UWORD *)dp = *(UWORD *)fp;
|
||||
(UWORD *)fp += 1;
|
||||
(UWORD *)dp += 1;
|
||||
i -= 1;
|
||||
} while (i);
|
||||
}
|
||||
/* Disk map merging complete */
|
||||
fcb_ext = calcext(fcbp); /* calc max extent for fcb */
|
||||
dir_ext = (UWORD)(dirp->extent) & 0x1f;
|
||||
if ( (fcb_ext > dir_ext) ||
|
||||
((fcb_ext == dir_ext) &&
|
||||
(UBWORD(fcbp->rcdcnt) > UBWORD(dirp->rcdcnt))) )
|
||||
/* if fcb points to larger file than dirp */
|
||||
{
|
||||
dirp->rcdcnt = fcbp->rcdcnt; /* set up rc, ext from fcb */
|
||||
dirp->extent = (BYTE)fcb_ext;
|
||||
}
|
||||
dirp->s1 = fcbp->s1;
|
||||
if ( (dirp->ftype[robit]) & 0x80) ro_err(fcbp,dirindx);
|
||||
/* read-only file error */
|
||||
dirp->ftype[arbit] &= 0x7f; /* clear archive bit */
|
||||
dir_wr(dirindx >> 2);
|
||||
UNLOCK
|
||||
return(TRUE);
|
||||
|
||||
badmerge:
|
||||
UNLOCK
|
||||
ro_dsk |= (1 << GBL.curdsk);
|
||||
return(FALSE);
|
||||
}
|
||||
else return(FALSE);
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* close_fi entry point *
|
||||
************************/
|
||||
|
||||
UWORD close_fi(fcbp)
|
||||
|
||||
struct fcb *fcbp; /* pointer to fcb for file to close */
|
||||
{
|
||||
flushit(); /* first, flush the buffers */
|
||||
if ((fcbp->s2) & 0x80) return(0); /* if file write flag not on,
|
||||
don't need to do physical close */
|
||||
return( dirscan(close, fcbp, 0)); /* call dirscan with close function */
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* search entry point *
|
||||
************************/
|
||||
|
||||
/* First two functions for dirscan */
|
||||
|
||||
BOOLEAN alltrue(p1, p2, i)
|
||||
UBYTE *p1;
|
||||
UBYTE *p2;
|
||||
WORD i;
|
||||
{
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
BOOLEAN matchit(p1, p2, i)
|
||||
UBYTE *p1;
|
||||
UBYTE *p2;
|
||||
WORD i;
|
||||
{
|
||||
return(match(p1, p2, TRUE));
|
||||
}
|
||||
|
||||
|
||||
/* search entry point */
|
||||
UWORD search(fcbp, dsparm, p)
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb for file to search */
|
||||
REG UWORD dsparm; /* parameter to pass through to dirscan */
|
||||
UBYTE *p; /* pointer to pass through to tmp_sel */
|
||||
|
||||
{
|
||||
REG UWORD rtn; /* return value */
|
||||
BSETUP
|
||||
|
||||
if (fcbp->drvcode == '?')
|
||||
{
|
||||
seldsk(GBL.dfltdsk);
|
||||
rtn = dirscan(alltrue, fcbp, dsparm);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_sel(p); /* temporarily select disk */
|
||||
if (fcbp->extent != '?') fcbp->extent = 0;
|
||||
fcbp->s2 = 0;
|
||||
rtn = dirscan(matchit, fcbp, dsparm);
|
||||
}
|
||||
move( GBL.dirbufp, GBL.dmaadr, SECLEN);
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* create entry point *
|
||||
************************/
|
||||
|
||||
BOOLEAN create(fcbp, dirp, dirindx)
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb for file to create */
|
||||
REG struct dirent *dirp; /* pointer to directory entry */
|
||||
REG WORD dirindx; /* index into directory */
|
||||
|
||||
{
|
||||
REG BYTE *p;
|
||||
REG WORD i;
|
||||
REG BOOLEAN rtn;
|
||||
BSETUP
|
||||
|
||||
if ( rtn = ((dirp->entry) == 0xe5) )
|
||||
{
|
||||
p = &(fcbp->rcdcnt);
|
||||
i = 17;
|
||||
do
|
||||
{ /* clear fcb rcdcnt and disk map */
|
||||
*p++ = 0;
|
||||
i -= 1;
|
||||
} while (i);
|
||||
move(fcbp, dirp, sizeof *dirp); /* move the fcb to the directory */
|
||||
dir_wr(dirindx >> 2); /* write the directory sector */
|
||||
if ( dirindx > (GBL.dphp)->hiwater )
|
||||
(GBL.dphp)->hiwater = dirindx;
|
||||
crit_dsk |= 1 << (GBL.curdsk);
|
||||
}
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* delete entry point *
|
||||
************************/
|
||||
|
||||
BOOLEAN delete(fcbp, dirp, dirindx)
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb for file to delete */
|
||||
REG struct dirent *dirp; /* pointer to directory entry */
|
||||
REG WORD dirindx; /* index into directory */
|
||||
|
||||
{
|
||||
REG WORD i;
|
||||
REG BOOLEAN rtn;
|
||||
BSETUP
|
||||
|
||||
if ( rtn = match(fcbp, dirp, FALSE) )
|
||||
{
|
||||
if ( (dirp->ftype[robit]) & 0x80 ) ro_err(fcbp,dirindx);
|
||||
/* check for read-only file */
|
||||
dirp->entry = 0xe5;
|
||||
LOCK
|
||||
dir_wr(dirindx >> 2);
|
||||
/* Now free up the space in the allocation vector */
|
||||
if ((GBL.parmp)->dsm < 256)
|
||||
{
|
||||
i = 16;
|
||||
do clraloc(UBWORD(dirp->dskmap.small[--i]));
|
||||
while (i);
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 8;
|
||||
do clraloc(swap(dirp->dskmap.big[--i]));
|
||||
while (i);
|
||||
}
|
||||
UNLOCK
|
||||
}
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* rename entry point *
|
||||
************************/
|
||||
|
||||
BOOLEAN rename(fcbp, dirp, dirindx)
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb for file to delete */
|
||||
REG struct dirent *dirp; /* pointer to directory entry */
|
||||
REG WORD dirindx; /* index into directory */
|
||||
|
||||
{
|
||||
REG UWORD i;
|
||||
REG BYTE *p; /* general purpose pointers */
|
||||
REG BYTE *q;
|
||||
REG BOOLEAN rtn;
|
||||
BSETUP
|
||||
|
||||
if ( rtn = match(fcbp, dirp, FALSE) )
|
||||
{
|
||||
if ( (dirp->ftype[robit]) & 0x80 ) ro_err(fcbp,dirindx);
|
||||
/* check for read-only file */
|
||||
p = &(fcbp->dskmap.small[1]);
|
||||
q = &(dirp->fname[0]);
|
||||
i = 11;
|
||||
do
|
||||
{
|
||||
*q++ = *p++ & 0x7f;
|
||||
i -= 1;
|
||||
} while (i);
|
||||
dir_wr(dirindx >> 2);
|
||||
}
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* set_attr entry point *
|
||||
************************/
|
||||
|
||||
BOOLEAN set_attr(fcbp, dirp, dirindx)
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb for file to delete */
|
||||
REG struct dirent *dirp; /* pointer to directory entry */
|
||||
REG WORD dirindx; /* index into directory */
|
||||
|
||||
{
|
||||
REG BOOLEAN rtn;
|
||||
BSETUP
|
||||
|
||||
if ( rtn = match(fcbp, dirp, FALSE) )
|
||||
{
|
||||
move(&fcbp->fname[0], &dirp->fname[0], 11);
|
||||
dir_wr(dirindx >> 2);
|
||||
}
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
|
||||
/****************************
|
||||
* utility routine used by *
|
||||
* setran and getsize *
|
||||
****************************/
|
||||
|
||||
LONG extsize(fcbp)
|
||||
/* Return size of extent pointed to by fcbp */
|
||||
REG struct fcb *fcbp;
|
||||
|
||||
{
|
||||
return( ((LONG)(fcbp->extent & 0x1f) << 7)
|
||||
| ((LONG)(fcbp->s2 & 0x3f) << 12) );
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* setran entry point *
|
||||
************************/
|
||||
|
||||
setran(fcbp)
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb for file to set ran rec */
|
||||
|
||||
{
|
||||
struct
|
||||
{
|
||||
BYTE b3;
|
||||
BYTE b2;
|
||||
BYTE b1;
|
||||
BYTE b0;
|
||||
};
|
||||
LONG random;
|
||||
|
||||
random = (LONG)UBWORD(fcbp->cur_rec) + extsize(fcbp);
|
||||
/* compute random record field */
|
||||
fcbp->ran0 = random.b2;
|
||||
fcbp->ran1 = random.b1;
|
||||
fcbp->ran2 = random.b0;
|
||||
}
|
||||
|
||||
|
||||
/**********************************/
|
||||
/* fsize is a funtion for dirscan */
|
||||
/* passed from getsize */
|
||||
/**********************************/
|
||||
|
||||
BOOLEAN fsize(fcbp, dirp, dirindx)
|
||||
|
||||
REG struct fcb *fcbp; /* pointer to fcb for file to delete */
|
||||
REG struct dirent *dirp; /* pointer to directory entry */
|
||||
WORD dirindx; /* index into directory */
|
||||
|
||||
{
|
||||
REG BOOLEAN rtn;
|
||||
struct
|
||||
{
|
||||
BYTE b3;
|
||||
BYTE b2;
|
||||
BYTE b1;
|
||||
BYTE b0;
|
||||
};
|
||||
LONG temp;
|
||||
|
||||
if ( rtn = match(fcbp, dirp, FALSE) )
|
||||
{
|
||||
temp = (LONG)UBWORD(dirp->rcdcnt) + extsize(dirp);
|
||||
/* compute file size */
|
||||
fcbp->ran0 = temp.b2;
|
||||
fcbp->ran1 = temp.b1;
|
||||
fcbp->ran2 = temp.b0;
|
||||
}
|
||||
return(rtn);
|
||||
}
|
||||
|
||||
/************************
|
||||
* getsize entry point *
|
||||
************************/
|
||||
|
||||
getsize(fcbp)
|
||||
/* get file size */
|
||||
REG struct fcb *fcbp; /* pointer to fcb to get file size for */
|
||||
|
||||
{
|
||||
LONG maxrcd;
|
||||
LONG temp;
|
||||
REG WORD dsparm;
|
||||
struct
|
||||
{
|
||||
BYTE b3;
|
||||
BYTE b2;
|
||||
BYTE b1;
|
||||
BYTE b0;
|
||||
};
|
||||
|
||||
maxrcd = 0;
|
||||
dsparm = 0;
|
||||
temp = 0;
|
||||
while ( dirscan(fsize, fcbp, dsparm) < 255 )
|
||||
{ /* loop until no more matches */
|
||||
temp.b2 = fcbp->ran0;
|
||||
temp.b1 = fcbp->ran1;
|
||||
temp.b0 = fcbp->ran2;
|
||||
if (temp > maxrcd) maxrcd = temp;
|
||||
dsparm = 1;
|
||||
}
|
||||
fcbp->ran0 = maxrcd.b2;
|
||||
fcbp->ran1 = maxrcd.b1;
|
||||
fcbp->ran2 = maxrcd.b0;
|
||||
}
|
||||
|
||||
|
||||
/************************
|
||||
* free_sp entry point *
|
||||
************************/
|
||||
|
||||
free_sp(dsknum)
|
||||
|
||||
UBYTE dsknum; /* disk number to get free space of */
|
||||
{
|
||||
REG LONG records;
|
||||
REG UWORD *alvec;
|
||||
REG UWORD bitmask;
|
||||
REG UWORD alvword;
|
||||
REG WORD i;
|
||||
BSETUP
|
||||
|
||||
seldsk(dsknum); /* select the disk */
|
||||
records = (LONG)0; /* initialize the variables */
|
||||
alvec = (GBL.dphp)->alv;
|
||||
bitmask = 0;
|
||||
for (i = 0; i <= (GBL.parmp)->dsm; i++) /* for loop to compute */
|
||||
{
|
||||
if ( ! bitmask)
|
||||
{
|
||||
bitmask = 0x8000;
|
||||
alvword = ~(*alvec++);
|
||||
}
|
||||
if ( alvword & bitmask)
|
||||
records += (LONG)( ((GBL.parmp)->blm) + 1 );
|
||||
bitmask >>= 1;
|
||||
}
|
||||
*(LONG *)GBL.dmaadr = records; /* move # records to DMA address */
|
||||
}
|
78
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/iosys.c
Normal file
78
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/iosys.c
Normal file
@@ -0,0 +1,78 @@
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* CP/M-68K BDOS Disk I/O System Module *
|
||||
* *
|
||||
* This module translates from the packet oriented I/O *
|
||||
* passed from the other BDOS modules into BIOS calls. *
|
||||
* *
|
||||
* It includes only one external entry point:
|
||||
* do_phio() - do physical i/o *
|
||||
* *
|
||||
* *
|
||||
* Configured for Alcyon C on the VAX *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
#include "bdosinc.h" /* Standard I/O declarations */
|
||||
|
||||
#include "bdosdef.h" /* Type and structure declarations for BDOS */
|
||||
|
||||
#include "pktio.h" /* Packet I/O definitions */
|
||||
|
||||
#include "biosdef.h" /* Declarations for BIOS entry points */
|
||||
|
||||
EXTERN udiv(); /* Assembly language unsigned divide routine */
|
||||
/* in bdosif.s. It's used because Alcyon C */
|
||||
/* can't do / or % without an external */
|
||||
|
||||
/************************
|
||||
* do_phio entry point *
|
||||
************************/
|
||||
|
||||
UWORD do_phio(iop)
|
||||
|
||||
REG struct iopb *iop; /* iop is a pointer to a i/o parameter block */
|
||||
|
||||
{
|
||||
MLOCAL UBYTE last_dsk; /* static variable to tell which disk
|
||||
was last used, to avoid disk selects */
|
||||
REG struct dph *hdrp; /* pointer to disk parameter header */
|
||||
REG struct dpb *dparmp; /* pointer to disk parameter block */
|
||||
REG UWORD rtn; /* return parameter */
|
||||
UWORD iosect; /* sector number returned from divide rtn */
|
||||
|
||||
LOCK /* lock the disk system while doing physical i/o */
|
||||
|
||||
rtn = 0;
|
||||
switch (iop->iofcn)
|
||||
{
|
||||
case sel_info:
|
||||
last_dsk = iop->devnum;
|
||||
iop->infop = bseldsk(last_dsk, iop->ioflags);
|
||||
break;
|
||||
|
||||
case read:
|
||||
case write:
|
||||
if (last_dsk != iop->devnum)
|
||||
bseldsk((last_dsk = iop->devnum), 0);
|
||||
/* guaranteed disk is logged on, because temp_sel in
|
||||
BDOSMAIN does it */
|
||||
hdrp = iop->infop;
|
||||
dparmp = hdrp->dpbp;
|
||||
|
||||
bsettrk( udiv( iop->devadr, dparmp->spt, &iosect )
|
||||
+ dparmp->trk_off );
|
||||
bsetsec( bsectrn( iosect, hdrp->xlt ) );
|
||||
bsetdma(iop->xferadr);
|
||||
if ((iop->iofcn) == read) rtn = bread();
|
||||
else rtn = bwrite(iop->ioflags);
|
||||
break;
|
||||
|
||||
case flush:
|
||||
rtn = bflush();
|
||||
}
|
||||
|
||||
UNLOCK
|
||||
return(rtn);
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* CP/M-68K BDOS Disk I/O System Module *
|
||||
* *
|
||||
* This module translates from the packet oriented I/O *
|
||||
* passed from the other BDOS modules into BIOS calls. *
|
||||
* *
|
||||
* It includes only one external entry point:
|
||||
* do_phio() - do physical i/o *
|
||||
* *
|
||||
* *
|
||||
* Configured for Alcyon C on the VAX *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
#include "stdio.h" /* Standard I/O declarations */
|
||||
|
||||
#include "bdosdef.h" /* Type and structure declarations for BDOS */
|
||||
|
||||
#include "pktio.h" /* Packet I/O definitions */
|
||||
|
||||
#include "biosdef.h" /* Declarations for BIOS entry points */
|
||||
|
||||
EXTERN udiv(); /* Assembly language unsigned divide routine */
|
||||
/* in bdosif.s. It's used because Alcyon C */
|
||||
/* can't do / or % without an external */
|
||||
|
||||
/************************
|
||||
* do_phio entry point *
|
||||
************************/
|
||||
|
||||
UWORD do_phio(iop)
|
||||
|
||||
REG struct iopb *iop; /* iop is a pointer to a i/o parameter block */
|
||||
|
||||
{
|
||||
MLOCAL UBYTE last_dsk; /* static variable to tell which disk
|
||||
was last used, to avoid disk selects */
|
||||
REG struct dph *hdrp; /* pointer to disk parameter header */
|
||||
REG struct dpb *dparmp; /* pointer to disk parameter block */
|
||||
REG UWORD rtn; /* return parameter */
|
||||
UWORD iosect; /* sector number returned from divide rtn */
|
||||
|
||||
LOCK /* lock the disk system while doing physical i/o */
|
||||
|
||||
rtn = 0;
|
||||
switch (iop->iofcn)
|
||||
{
|
||||
case sel_info:
|
||||
last_dsk = iop->devnum;
|
||||
iop->infop = bseldsk(last_dsk, iop->ioflags);
|
||||
break;
|
||||
|
||||
case read:
|
||||
case write:
|
||||
if (last_dsk != iop->devnum)
|
||||
bseldsk((last_dsk = iop->devnum), 0);
|
||||
/* guaranteed disk is logged on, because temp_sel in
|
||||
BDOSMAIN does it */
|
||||
hdrp = iop->infop;
|
||||
dparmp = hdrp->dpbp;
|
||||
|
||||
bsettrk( udiv( iop->devadr, dparmp->spt, &iosect )
|
||||
+ dparmp->trk_off );
|
||||
bsetsec( bsectrn( iosect, hdrp->xlt ) );
|
||||
bsetdma(iop->xferadr);
|
||||
if ((iop->iofcn) == read) rtn = bread();
|
||||
else rtn = bwrite(iop->ioflags);
|
||||
break;
|
||||
|
||||
case flush:
|
||||
rtn = bflush();
|
||||
}
|
||||
|
||||
UNLOCK
|
||||
return(rtn);
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* CP/M-68K BDOS Disk I/O System Module *
|
||||
* *
|
||||
* This module translates from the packet oriented I/O *
|
||||
* passed from the other BDOS modules into BIOS calls. *
|
||||
* *
|
||||
* It includes only one external entry point:
|
||||
* do_phio() - do physical i/o *
|
||||
* *
|
||||
* *
|
||||
* Configured for Alcyon C on the VAX *
|
||||
* *
|
||||
****************************************************************/
|
||||
|
||||
#include "bdosinc.h" /* Standard I/O declarations */
|
||||
|
||||
#include "bdosdef.h" /* Type and structure declarations for BDOS */
|
||||
|
||||
#include "pktio.h" /* Packet I/O definitions */
|
||||
|
||||
#include "biosdef.h" /* Declarations for BIOS entry points */
|
||||
|
||||
EXTERN udiv(); /* Assembly language unsigned divide routine */
|
||||
/* in bdosif.s. It's used because Alcyon C */
|
||||
/* can't do / or % without an external */
|
||||
|
||||
/************************
|
||||
* do_phio entry point *
|
||||
************************/
|
||||
|
||||
UWORD do_phio(iop)
|
||||
|
||||
REG struct iopb *iop; /* iop is a pointer to a i/o parameter block */
|
||||
|
||||
{
|
||||
REG struct dph *hdrp; /* pointer to disk parameter header */
|
||||
REG struct dpb *dparmp; /* pointer to disk parameter block */
|
||||
REG UWORD rtn; /* return parameter */
|
||||
UWORD iosect; /* sector number returned from divide rtn */
|
||||
|
||||
LOCK /* lock the disk system while doing physical i/o */
|
||||
|
||||
rtn = 0;
|
||||
switch (iop->iofcn)
|
||||
{
|
||||
case sel_info:
|
||||
iop->infop = bseldsk(iop->devnum, iop->ioflags);
|
||||
break;
|
||||
|
||||
case read:
|
||||
case write:
|
||||
bseldsk(iop->devnum, 0);
|
||||
hdrp = iop->infop;
|
||||
dparmp = hdrp->dpbp;
|
||||
|
||||
bsettrk( udiv( iop->devadr, dparmp->spt, &iosect )
|
||||
+ dparmp->trk_off );
|
||||
bsetsec( bsectrn( iosect, hdrp->xlt ) );
|
||||
bsetdma(iop->xferadr);
|
||||
if ((iop->iofcn) == read) rtn = bread();
|
||||
else rtn = bwrite(iop->ioflags);
|
||||
break;
|
||||
|
||||
case flush:
|
||||
rtn = bflush();
|
||||
}
|
||||
|
||||
UNLOCK
|
||||
return(rtn);
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
$ num
|
||||
BDOSDEF.H
|
||||
BDOSDEF.lst
|
||||
$ num
|
||||
BDOSIF.S
|
||||
BDOSIF.lis
|
||||
$ num
|
||||
BDOSINC.H
|
||||
BDOSINC.lst
|
||||
$ num
|
||||
BDOSMAIN.C
|
||||
BDOSMAIN.lis
|
||||
$ num
|
||||
BDOSMISC.C
|
||||
BDOSMISC.lis
|
||||
$ num
|
||||
BDOSRW.C
|
||||
BDOSRW.lis
|
||||
$ num
|
||||
BIOSDEF.H
|
||||
BIOSDEF.lst
|
||||
$ num
|
||||
CONBDOS.C
|
||||
CONBDOS.lis
|
||||
$ num
|
||||
DSKUTIL.C
|
||||
DSKUTIL.lis
|
||||
$ num
|
||||
EXCEPTN.S
|
||||
EXCEPTN.lis
|
||||
$ num
|
||||
FILEIO.C
|
||||
FILEIO.lis
|
||||
$ num
|
||||
IOSYS.C
|
||||
IOSYS.lis
|
||||
$ num
|
||||
PGMLD.S
|
||||
PGMLD.lis
|
||||
$ num
|
||||
PKTIO.H
|
||||
PKTIO.lst
|
537
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/pgmld.s
Normal file
537
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/pgmld.s
Normal file
@@ -0,0 +1,537 @@
|
||||
|
||||
*********************************
|
||||
* *
|
||||
* Function 59 -- Program Load *
|
||||
* Assembly language version *
|
||||
* *
|
||||
* June 8, 1982 *
|
||||
* *
|
||||
*********************************
|
||||
|
||||
.globl _pgmld * this routine is public
|
||||
|
||||
secsize = 128 * CP/M sector size
|
||||
|
||||
* d0 always contains the return parameter from pgmld
|
||||
* d1 is the return register from local subroutines
|
||||
* a0 contains the pointer to the Load Parm Block passed to pgmld
|
||||
|
||||
* Return parameters in d0 are:
|
||||
* 00 - function successful
|
||||
* 01 - insufficient memory or bad header in file
|
||||
* 02 - read error on file
|
||||
* 03 - bad relocation information in file
|
||||
|
||||
|
||||
* Entry point for Program Load routine
|
||||
_pgmld:
|
||||
movem.l d1-d7/a0-a6, -(sp) * save everything, just to be safe
|
||||
move.l 60(sp),a0 * get pointer to LPB
|
||||
clr.l d0 * start with return parm cleared
|
||||
bsr gethdr * get header
|
||||
tst d0
|
||||
bne lddone * if unsuccessful, return
|
||||
bsr setaddr * set up load addresses
|
||||
tst d0
|
||||
bne lddone * if unsuccessful, return
|
||||
bsr rdtxt * read code and data text segments into mem
|
||||
tst d0
|
||||
bne lddone * if unsuccessful, return
|
||||
move.l tstart,d7
|
||||
cmp.l cseg,d7
|
||||
beq noreloc
|
||||
bsr reloc * do relocation if necessary
|
||||
noreloc:
|
||||
tst d0
|
||||
bne lddone
|
||||
bsr setrtn * set up return parameters
|
||||
lddone:
|
||||
move.l 64(sp), d1
|
||||
bsr setdma * restore dma address
|
||||
movem.l (sp)+,d1-d7/a0-a6
|
||||
rts
|
||||
|
||||
* Subroutines
|
||||
|
||||
readseq:
|
||||
* CP/M read sequential function
|
||||
move.l d0,-(sp) * save return parm
|
||||
move.l FCBPtr(a0),d1
|
||||
moveq #20,d0 * read seq function
|
||||
trap #2 * call bdos
|
||||
move.l d0,d1 * return parm in d1
|
||||
move.l (sp)+,d0
|
||||
rts
|
||||
|
||||
|
||||
setdma:
|
||||
* CP/M set dma function
|
||||
move.l d0,-(sp) * save return parm
|
||||
moveq #26,d0 * set dma function
|
||||
trap #2 * call bdos
|
||||
move.l (sp)+,d0 * restore d0
|
||||
rts
|
||||
|
||||
|
||||
gethdr:
|
||||
* Get header into buffer in data segment
|
||||
move.l LoAdr(a0),d1
|
||||
bsr setdma
|
||||
bsr readseq
|
||||
tst d1 * read ok?
|
||||
bne badhdr * if no, return bad
|
||||
moveq #18,d7
|
||||
movea.l LoAdr(a0),a5
|
||||
movea.l #hdr,a6
|
||||
geth1: move.w (a5)+,(a6)+ * move header into hdr
|
||||
dbf d7,geth1
|
||||
rts
|
||||
badhdr: moveq #2,d0
|
||||
rts
|
||||
|
||||
|
||||
conflict:
|
||||
* input parms: d2, d3 = 4 * segment nmbr
|
||||
* if segment d2/4 overlaps segment d3/4, then return 1 in d1
|
||||
* else return 0 in d1
|
||||
* uses d7, a2, a3
|
||||
clr.l d1 * assume it will work
|
||||
movea.l #cseg,a2 * a2 points to start of segment addresses
|
||||
movea.l #csize,a3 * a3 points to start of segment lengths
|
||||
move.l 0(a2,d2),d7 * get 1st seg start
|
||||
cmp.l 0(a2,d3),d7 * is 1st seg above 2nd seg?
|
||||
bge conf1
|
||||
add.l 0(a3,d2),d7 * yes, find top of 1st seg
|
||||
cmp.l 0(a2,d3),d7 * above start of 2nd seg?
|
||||
bgt confbd * if yes, we have a conflict
|
||||
rts * else, return good
|
||||
conf1:
|
||||
move.l 0(a2,d3),d7
|
||||
add.l 0(a3,d3),d7 * find top of 2nd seg
|
||||
cmp.l 0(a2,d2),d7 * above start of 1st seg?
|
||||
ble confgd * if no, we're ok
|
||||
confbd: moveq.l #1,d1
|
||||
confgd: rts
|
||||
|
||||
|
||||
trymemtp:
|
||||
* entry: d2 is a segment nmbr [0..4]
|
||||
* try to fit it at top of memory
|
||||
* uses d3, d6, d7, a5, a6
|
||||
* returns 0 in d1 if ok
|
||||
move.l d2,d6 * d6 is loop counter for chksegs
|
||||
subq #1,d6
|
||||
lsl #2,d2 * multiply d2 by 4
|
||||
move.l HiAdr(a0),d7 * top of mem to d7
|
||||
|
||||
chksegs:
|
||||
* entry: d2 = 4 * (segment nmbr to try)
|
||||
* d6 = (d2/4) - 1 (loop counter)
|
||||
* d7 = address below which to try it
|
||||
* check for conflicts with segments [0..d6] and low memory boundary
|
||||
* return 0 in d1 if no conflicts, else d1 = 1
|
||||
* uses d3, a5, a6
|
||||
movea.l #cseg,a5
|
||||
movea.l #csize,a6
|
||||
sub.l 0(a6,d2),d7 * subtract size of segment to try
|
||||
bclr #0,d7 * make it even address
|
||||
move.l d7,0(a5,d2) * insert address in segment table
|
||||
cmp.l LoAdr(a0),d7 * check for conflict with low memory
|
||||
blt confbd
|
||||
clr.l d3 * check for conflicts with 0..d6
|
||||
chk1:
|
||||
bsr conflict
|
||||
addq.l #4,d3
|
||||
tst.l d1 * conflict with this seg?
|
||||
dbne d6,chk1 * if no, try next
|
||||
rts
|
||||
|
||||
|
||||
fndseg:
|
||||
* entry: d2 is a segment nmbr [0..4]
|
||||
* try to fit segment d2 directly below segments 0..(d2-1)
|
||||
* uses d3-d7, a5, a6
|
||||
move.l d2,d5 * d5 is loop counter to find fit
|
||||
subq.l #1,d5
|
||||
move.l d5,temp
|
||||
lsl.l #2,d2 * multiply segment by 4
|
||||
clr.l d4 * d4 is segment to try to fit below
|
||||
fnd1:
|
||||
move.l temp,d6 * d6 is loop counter for chksegs
|
||||
movea.l #cseg,a5
|
||||
move.l 0(a5,d4),d7 * segment address to d7
|
||||
bsr chksegs * check for conflicts
|
||||
addq.l #4,d4
|
||||
tst.l d1
|
||||
dbeq d5,fnd1 * if conflict, try next
|
||||
rts
|
||||
|
||||
|
||||
setaddr:
|
||||
* Set up load addresses for cseg, dseg, bss, basepg, and stack
|
||||
move.w magic,d6
|
||||
andi.w #$fffe,d6
|
||||
cmpi.w #$601a,d6
|
||||
bne badadr * if magic nmbr <> 601a or 601b, skip
|
||||
move.l bpsize,symsize
|
||||
move.l #256,d7
|
||||
move.l d7,bpsize * base page is 256 bytes
|
||||
lea stksize,a2
|
||||
cmp (a2),d7
|
||||
blt set0 * if stack size < 256, set to 256
|
||||
move.l d7,(a2)
|
||||
set0: cmpi.w #$601b,magic
|
||||
beq seta
|
||||
tst.w rlbflg
|
||||
beq set1
|
||||
seta: move.l tstart,cseg * if not relocatable or hdr = $601b,
|
||||
bra set2 * cseg starts at tstart
|
||||
set1: btst #0,Flags(a0)
|
||||
bne sldhi
|
||||
* relocatable, load low
|
||||
move.l LoAdr(a0),d7
|
||||
add.l #$101,d7 * leave room for base page
|
||||
bclr #0,d7
|
||||
move.l d7,cseg * cseg is bottom of mem + $100 (even boundary)
|
||||
bra set2
|
||||
sldhi:
|
||||
* relocatable, load high
|
||||
move.l HiAdr(a0),d7
|
||||
sub.l csize,d7
|
||||
sub.l dsize,d7
|
||||
sub.l bsize,d7
|
||||
subq.l #4,d7
|
||||
bclr #0,d7 * put cseg at next even address below
|
||||
move.l d7,cseg * high memory - (sum of sizes)
|
||||
set2:
|
||||
* Cseg has been set up. Now do dseg, bseg
|
||||
cmpi.w #$601b,magic
|
||||
bne set3
|
||||
* if magic # = 601b, take addr from hdr
|
||||
move.l dstart,dseg
|
||||
move.l bstart,bseg
|
||||
bra set4
|
||||
set3:
|
||||
* if short header, dseg and bseg follow cseg
|
||||
move.l cseg,d7
|
||||
add.l csize,d7
|
||||
addq.l #1,d7
|
||||
bclr #0,d7
|
||||
move.l d7,dseg
|
||||
add.l dsize,d7
|
||||
addq.l #1,d7
|
||||
bclr #0,d7
|
||||
move.l d7,bseg
|
||||
set4:
|
||||
* cseg, dseg, bseg set up
|
||||
* now find a place for the base page and stack
|
||||
moveq.l #3,d2
|
||||
bsr fndseg * try to fit base page below cseg, dseg, bseg
|
||||
tst.l d1
|
||||
beq set5 * if found, skip
|
||||
moveq.l #3,d2
|
||||
bsr trymemtp * else, try top of memory
|
||||
tst.l d1
|
||||
bne badadr * if fail, exit
|
||||
set5: moveq.l #4,d2
|
||||
bsr trymemtp * try to fit stack at top of memory
|
||||
tst.l d1
|
||||
beq set6 * if ok, skip
|
||||
moveq.l #4,d2
|
||||
bsr fndseg * else, try to fit below other segs
|
||||
tst.l d1
|
||||
bne badadr
|
||||
set6:
|
||||
* now check all segments for conflicts with low and high memory boundaries
|
||||
movea.l #cseg,a5
|
||||
movea.l #csize,a6
|
||||
clr.l d2
|
||||
moveq #4,d3 * loop counter
|
||||
set7: move.l 0(a5,d2),d7 * get segment base
|
||||
cmp.l LoAdr(a0),d7 * above bottom of memory?
|
||||
blt badadr
|
||||
add.l 0(a6,d2),d7 * find top of segment
|
||||
cmp.l HiAdr(a0),d7 * below top of memory?
|
||||
bgt badadr
|
||||
addq.l #4,d2 * point to next segment
|
||||
dbf d3,set7
|
||||
rts
|
||||
badadr: moveq.l #1,d0
|
||||
rts
|
||||
|
||||
|
||||
movebuf:
|
||||
* move (d3) bytes from the base page buffer to (a2)
|
||||
* uses d6
|
||||
movea.l basepg,a1
|
||||
move.l #secsize,d6
|
||||
sub.w bufbyts,d6 * address to move from =
|
||||
adda.w d6,a1 * (basepg) + secsize - (bufbyts)
|
||||
sub.w d3,bufbyts * update # bytes buffered
|
||||
bra moveb2
|
||||
moveb1: move.b (a1)+,(a2)+ * do the move
|
||||
moveb2: dbf d3,moveb1
|
||||
rts
|
||||
|
||||
|
||||
rdtxt:
|
||||
* Read code and data text into memory
|
||||
* during this routine, a2 is always the load address,
|
||||
* d2 is number of bytes left to load
|
||||
moveq #63,d7
|
||||
movea.l LoAdr(a0),a5
|
||||
movea.l basepg,a6
|
||||
rdtxt1: move.w (a5)+,(a6)+ * move header sector to base page
|
||||
dbf d7,rdtxt1
|
||||
move.w #secsize-28,d7
|
||||
cmpi.w #$601a,magic * short header?
|
||||
beq rdtxt2
|
||||
subq.w #8,d7
|
||||
rdtxt2: move.w d7,bufbyts * indicate # bytes of text in buffer
|
||||
move.w #2,loop * do for code, data segments
|
||||
move.l cseg,a2 * start at cseg
|
||||
move.l csize,d2 * for csize bytes
|
||||
rdtxt3:
|
||||
clr.l d3
|
||||
move.w bufbyts,d3
|
||||
cmp.l d2,d3 * # bytes in buffer >= # bytes to load?
|
||||
blt rdtxt4
|
||||
move.l d2,d3
|
||||
bsr movebuf * if yes, move # bytes to load
|
||||
bra finrd
|
||||
rdtxt4:
|
||||
sub.l d3,d2 * if no, update # bytes to load
|
||||
bsr movebuf * move remainder of buffer
|
||||
move.l #secsize,d3 * d3 = secsize fo following loop
|
||||
rdtxt5:
|
||||
cmp.l d3,d2 * have at least one more full sector?
|
||||
blt rdtxt6
|
||||
move.l a2,d1
|
||||
bsr setdma * if yes, set up dma address
|
||||
bsr readseq * read next sector
|
||||
tst.w d1
|
||||
bne rdbad * if no good, exit
|
||||
sub.l d3,d2 * decrement # bytes to load
|
||||
adda.l #secsize,a2 * increment dma address
|
||||
bra rdtxt5
|
||||
rdtxt6:
|
||||
tst.l d2 * any more bytes to read?
|
||||
beq finrd
|
||||
move.l basepg,d1
|
||||
bsr setdma
|
||||
bsr readseq * if yes, read into base page
|
||||
tst.w d1
|
||||
bne rdbad
|
||||
move.w d3,bufbyts * indicate that we've buffered a sector
|
||||
move.l d2,d3
|
||||
bsr movebuf * move remainder of segment
|
||||
finrd:
|
||||
move.l dseg,a2 * set up to load data segment
|
||||
move.l dsize,d2
|
||||
sub.w #1,loop
|
||||
bne rdtxt3
|
||||
move.l bseg,a2 * clear the bss segment
|
||||
move.l bsize,d2
|
||||
beq rdtxt8
|
||||
rdtxt7: clr.b (a2)+
|
||||
subq.l #1,d2
|
||||
bne rdtxt7
|
||||
rdtxt8: rts
|
||||
|
||||
rdbad: moveq.l #2,d0
|
||||
rts
|
||||
|
||||
|
||||
relocword:
|
||||
* relocate word at (a2) based on reloc bits at (a3)
|
||||
* lsb of d2 indicates whether previous word was 1st half of long-word
|
||||
move.w (a3)+,d7 * get relocation info
|
||||
andi.w #7,d7 * strip off symbol table bits
|
||||
lsl #1,d7 * multiply by 2
|
||||
jmp 2(pc,d7)
|
||||
|
||||
bra relabs
|
||||
bra reldata
|
||||
bra relcode
|
||||
bra relbss
|
||||
bra relbad
|
||||
bra rellong
|
||||
bra relbad
|
||||
bra relop
|
||||
|
||||
relbad: move.l (sp)+,d0 * pop return address
|
||||
moveq #3,d0 * return bad relocation to main routine
|
||||
rts
|
||||
|
||||
relabs:
|
||||
relop: bclr #0,d2 * reset long word flag
|
||||
tst.w (a2)+ * point to next word of segment
|
||||
rts
|
||||
|
||||
rellong:
|
||||
bset #0,d2 * set long word flag
|
||||
tst.w (a2)+ * point to next word of segment
|
||||
rts
|
||||
|
||||
reldata:
|
||||
relbss:
|
||||
relcode:
|
||||
bclr #0,d2 * long word flag set?
|
||||
bne relc1 * if yes, skip
|
||||
move.w (a2),d6
|
||||
add.w d5,d6
|
||||
move.w d6,(a2)+
|
||||
rts
|
||||
|
||||
relc1: tst.w -(a2) * point to first word of long
|
||||
move.l (a2),d6
|
||||
add.l d5,d6
|
||||
move.l d6,(a2)+ * note that a2 points past long word
|
||||
rts
|
||||
|
||||
|
||||
reloc:
|
||||
* Modify address references of code and data segments based on relocation bits
|
||||
* During this routine,
|
||||
* a2 points to text file to relocate
|
||||
* a3 points to relocation word in basepg
|
||||
* lsb of d2 is long word flag (set on reloc type 5, reset on next word)
|
||||
* d3 is # words in relocation buffer
|
||||
* d4 is nmbr of words left to relocate
|
||||
* d5 is relocation offset
|
||||
|
||||
move.l basepg,d1
|
||||
bsr setdma * we will always read into base page
|
||||
* skip past the symbol table
|
||||
move.l symsize,d7
|
||||
divu #secsize,d7 * calculate how many sectors to skip
|
||||
* note that max # symbols is 8k, which is 896 sectors of 128 bytes
|
||||
move.w d7,d6 * d6 is nmbr sectors to skip
|
||||
swap d7 * d7 is nmbr bytes to skip
|
||||
move.w bufbyts,d3
|
||||
sub.w d7,d3 * subtract bytes to skip from buffer
|
||||
bge skip1
|
||||
addi #secsize,d3 *if amt in buffer < # bytes to skip,
|
||||
addq #1,d6 * read in 1 extra sector
|
||||
skip1: move.l basepg,a3
|
||||
adda #secsize,a3
|
||||
suba.w d3,a3 * set up a3 to point to buffer
|
||||
lsr #1,d3 * d3 is nmbr words in buffer
|
||||
bra skip3
|
||||
skip2:
|
||||
bsr readseq * read next symbol table sector
|
||||
tst.w d1
|
||||
bne rdbad
|
||||
skip3: dbf d6,skip2
|
||||
* we got past symbol table
|
||||
* a3, d3 are set up
|
||||
move.l cseg,d5
|
||||
move.l d5,a2 * relocate cseg first
|
||||
sub.l tstart,d5 * d5 contains the relocation offset
|
||||
move.l csize,d4 * nmbr of bytes to relocate
|
||||
move.w #2,loop * we're going to relocate 2 segments
|
||||
reloc1:
|
||||
* relocate one segment
|
||||
clr.l d2 * clear long word flag
|
||||
lsr.l #1,d4 * make d4 indicate # words
|
||||
bra reloc4
|
||||
reloc2:
|
||||
subq.w #1,d3
|
||||
bpl reloc3
|
||||
bsr readseq * if no more words in buffer, refill it
|
||||
tst.w d1
|
||||
bne rdbad
|
||||
move.l basepg,a3
|
||||
move.w #(secsize/2)-1,d3
|
||||
reloc3:
|
||||
bsr relocword * relocate one word
|
||||
subq.l #1,d4
|
||||
reloc4:
|
||||
tst.l d4 * any more to relocate in this segment?
|
||||
bne reloc2 * if yes, do it
|
||||
move.l dseg,a2 * else, set up for dseg
|
||||
move.l dsize,d4
|
||||
sub.w #1,loop
|
||||
bne reloc1
|
||||
rts
|
||||
|
||||
|
||||
setrtn:
|
||||
* Set up the return parameters in Ld Parm Blk and Base Page
|
||||
move.l basepg,BasPage(a0)
|
||||
move.l stk,d7
|
||||
add.l stksize,d7
|
||||
bclr #0,d7
|
||||
move.l d7,Stack(a0)
|
||||
move.l basepg,a1
|
||||
move.l LoAdr(a0),(a1)+
|
||||
move.l HiAdr(a0),(a1)+
|
||||
move.l cseg,(a1)+
|
||||
move.l csize,(a1)+
|
||||
move.l dseg,(a1)+
|
||||
move.l dsize,(a1)+
|
||||
move.l bseg,(a1)+
|
||||
move.l bsize,(a1)
|
||||
* find size of free memory after bss segment
|
||||
move.l HiAdr(a0),d7 * d7 contains next segment above bss
|
||||
move.l -4(a1),d6
|
||||
add.l (a1)+,d6 * d6 points to start of free mem after bss
|
||||
movea.l #cseg,a6 * a6 points to segment to try
|
||||
moveq #4,d5 * try for all segments
|
||||
clr.l bseg * but force bss not to appear
|
||||
setb1: cmp.l (a6),d6 * segment above bss?
|
||||
bhi setb2
|
||||
cmp.l (a6),d7 * segment is above bss. Is it below previous?
|
||||
bls setb2
|
||||
move.l (a6),d7
|
||||
setb2: tst.l (a6)+ * point to next segment
|
||||
dbf d5,setb1
|
||||
sub.l d6,d7 * diff between bss top and next segment abv
|
||||
move.l d7,(a1)+
|
||||
* now put disk number that we loaded from into base page
|
||||
movea.l FCBPtr(a0),a2
|
||||
move.b (a2),d0 * get disk select byte
|
||||
bne setb3 * if not auto-select, skip
|
||||
move #25,d0
|
||||
trap #2 * get default disk
|
||||
addq #1,d0 * we want it in range of 1..16
|
||||
setb3: move.b d0,(a1)+ * move disk number into base page
|
||||
clr.l d0 * function OK
|
||||
rts
|
||||
|
||||
|
||||
.bss
|
||||
|
||||
* offsets from start of parameter block
|
||||
FCBPtr = 0
|
||||
LoAdr = 4
|
||||
HiAdr = 8
|
||||
BasPage = 12 * return parameters
|
||||
Stack = 16
|
||||
Flags = 21
|
||||
|
||||
hdr:
|
||||
* load file header is read into here
|
||||
magic: .ds.w 1
|
||||
csize: .ds.l 1
|
||||
dsize: .ds.l 1
|
||||
bsize: .ds.l 1
|
||||
bpsize: .ds.l 1 * symb tbl size is swapped with base page size
|
||||
stksize: .ds.l 1
|
||||
tstart: .ds.l 1
|
||||
rlbflg: .ds.w 1
|
||||
dstart: .ds.l 1
|
||||
bstart: .ds.l 1
|
||||
|
||||
cseg: .ds.l 1
|
||||
dseg: .ds.l 1
|
||||
bseg: .ds.l 1
|
||||
basepg: .ds.l 1
|
||||
stk: .ds.l 1
|
||||
|
||||
symsize: .ds.l 1
|
||||
temp: .ds.l 1
|
||||
loop: .ds.w 1
|
||||
bufbyts: .ds.w 1
|
||||
|
||||
.end
|
57
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/pktio.h
Normal file
57
CPM OPERATING SYSTEMS/CPM 68K/1.0X SOURCES/v101/bdos/pktio.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/********************************************************
|
||||
* *
|
||||
* CP/M-68K header file *
|
||||
* Copyright (c) 1982 by Digital Research, Inc. *
|
||||
* Structure definitions for doing I/O in packets *
|
||||
* *
|
||||
********************************************************/
|
||||
|
||||
/* May use this information structure instead of disk parameter header and
|
||||
disk parameter block in future, but for now it's unused
|
||||
struct dskinfo
|
||||
{
|
||||
UBYTE *dbuffp;
|
||||
UBYTE *csv;
|
||||
UBYTE *alv;
|
||||
UBYTE blksize;
|
||||
UBYTE didummy;
|
||||
UWORD dskmax;
|
||||
UWORD dirmax;
|
||||
UWORD chksize;
|
||||
};
|
||||
*/
|
||||
|
||||
struct iopb
|
||||
{
|
||||
UBYTE iofcn; /* function number, see defines below */
|
||||
UBYTE ioflags; /* used for login flag and write flag */
|
||||
UBYTE devtype; /* device type, see defines below */
|
||||
/* currently unused */
|
||||
UBYTE devnum; /* device number, or, devtype and devnum
|
||||
taken together form int device number */
|
||||
LONG devadr; /* item nmbr on device to start xfer at */
|
||||
/* note -- item is sector for disks, byte for char devs */
|
||||
UWORD xferlen; /* number items to transfer */
|
||||
UBYTE *xferadr; /* memory address to xfer to/from */
|
||||
struct dph *infop; /* pointer to disk parameter header */
|
||||
/* return parm for fcn 0, input for rest */
|
||||
};
|
||||
|
||||
|
||||
/* Definitions for iofcn, the function number */
|
||||
#define sel_info 0 /* select and return info on device */
|
||||
#define read 1
|
||||
#define write 2
|
||||
#define flush 3
|
||||
#define status 4 /* not currently used */
|
||||
|
||||
|
||||
/* Definitions for devtype, the device type */
|
||||
/* This field not currently used */
|
||||
#define console 0
|
||||
#define printer 1
|
||||
#define disk 2
|
||||
#define memory 3 /* gets TPA boundaries */
|
||||
#define redir 4 /* read/write IOByte */
|
||||
#define exc_vec 5 /* set exception vector */
|
||||
|
@@ -0,0 +1,16 @@
|
||||
$ set noon
|
||||
$ vsend BDOSDEF.H
|
||||
$ vsend BDOSIF.S
|
||||
$ vsend BDOSINC.H
|
||||
$ vsend BDOSMAIN.C
|
||||
$ vsend BDOSMISC.C
|
||||
$ vsend BDOSRW.C
|
||||
$ vsend BIOSDEF.H
|
||||
$ vsend CONBDOS.C
|
||||
$ vsend CPMC.DOC
|
||||
$ vsend DSKUTIL.C
|
||||
$ vsend EXCEPTN.S
|
||||
$ vsend FILEIO.C
|
||||
$ vsend IOSYS.C
|
||||
$ vsend PGMLD.S
|
||||
$ vsend PKTIO.H
|
Reference in New Issue
Block a user