1 /* Header file for the basic i/o system. 2 Copyright (C) 1995 Frank D. Cringle. 3 Modifications for CP/M 3.1 Copyright (C) 2000/2003 by Andreas Gerlich (agl) 4 5 This file is part of yaze-ag - yet another Z80 emulator by ag. 6 7 Yaze-ag is free software; you can redistribute it and/or modify it under 8 the terms of the GNU General Public License as published by the Free 9 Software Foundation; either version 2 of the License, or (at your 10 option) any later version. 11 12 This program is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 20 21 22 /* TTY management */ 23 extern struct termios cookedtio, rawtio; 24 #define ISATTY 1 25 #define ISRAW 2 26 extern int ttyflags; 27 extern int interrupt; 28 extern void ttyraw(void), ttycook(void); 29 30 31 /* Table of logical streams */ 32 extern int chn[6]; 33 34 #if 0 35 /* CHNxxxx constants moved to chan.h for separate inclusion */ 36 #define CHNconin 0 37 #define CHNconout 1 38 #define CHNrdr 2 39 #define CHNpun 3 40 #define CHNlst 4 41 #define CHNaux 5 42 #else 43 #include "chan.h" 44 #endif 45 46 /* Table of physical streams */ 47 #define SIOno -1 48 #define TTYin 0 49 #define TTYout 1 50 #define CRTin 2 51 #define CRTout 3 52 #define UC1in 4 53 #define UC1out 5 54 #define RDRin 6 55 #define UR1in 7 56 #define UR2in 8 57 #define PUNout 9 58 #define UP1out 10 59 #define UP2out 11 60 #define LPTout 12 61 #define UL1out 13 62 #define AUX 14 63 #define MAXPSTR 15 64 65 #define ST_IN 0 66 #define ST_OUT 1 67 #define ST_IN2 2 68 #define ST_OUT2 3 69 #define ST_INOUT 4 70 71 #define IOBYTE 0x95 /* agl: standard IOBYTE */ 72 73 /* --------------------------------------------------------------------- */ 74 /* special definitions for comunication between cp/m 3 and yaze: ------- */ 75 76 #define SCB_columns (0x1A) /* Colums address in SCB */ 77 #define SCB_lines (0x1C) /* Lines address in SCB */ 78 79 #define SCB_MEDIA (0x54) /* position of the MEDIA Flag in SCB */ 80 #define SCB_MXTPA (0x62) /* position of MXTPA in SCB */ 81 82 #define DPH_xlt 0 /* position of the translation table (xlt) 83 in DPH (Disk Parameter Header) */ 84 #define DPH_mf 11 /* position of the Media Flag (MF) in DPH */ 85 #define DPH_dpb 12 /* position of the address of the DPB */ 86 /* in the DPH */ 87 88 #define DPB_spt 0 /* position of SPT in Disk Parameter Block */ 89 #define DPB_bsh 2 /* position of BSH in DPB */ 90 #define DPB_dsm 5 /* position of DSM in DPB */ 91 #define DPB_drm 7 /* position of DRM in DPB */ 92 #define DPB_cks 11 /* position of CKS in DPB */ 93 #define DPB_off 13 /* position of OFFSET in DPB */ 94 #define DPB_psh 15 /* position of PSH in DPB */ 95 96 /* -------------------------------------------------------------------*/ 97 /* -------------------------------------------------------------------*/ 98 /* definition for time calculation -----------------------------------*/ 99 100 /* Faktor for date calculation in CP/M 3.1 */ 101 #define DayFaktor_CPMSTART 722449L /* Day Faktor of CP/M start. One day */ 102 /* before start of CP/M 3.0 (1.1.1978). */ 103 /* (I don't know if it's the start of */ 104 /* CP/M 3.0 ) */ 105 /* Calculated with dayfaktor(31.12.1977) */ 106 107 /* -------------------------------------------------------------------*/ 108 109 extern struct sio 110 { 111 FILE *fp; 112 char *filename; 113 char *streamname; 114 char tty; 115 const char strtype; 116 } siotab[]; 117 118 119 /* Disk management */ 120 121 /* There are two kinds of simulated disk: 122 a unix file containing an image of a cp/m disk and 123 a unix directory which is made to look like a cp/m disk on the fly */ 124 #define MNT_ACTIVE 1 125 #define MNT_RDONLY 2 126 #define MNT_UNIXDIR 4 127 128 extern int cpm3; /* flag for CP/M 3.1 */ 129 extern WORD dtbl; /* dtbl */ 130 extern WORD maxdsm; /* maximal DSM supported by the bios */ 131 extern WORD maxdrm; /* maximal DRM supported by the bios */ 132 133 extern struct mnt { /* mount table (simulated drives A..P) */ 134 WORD flags; 135 WORD dph; /* address of disk parameter header in 136 cp/m 2 ram or in cp/m 3 */ 137 WORD xlt; /*agl*/ /* address(z80) of the translation table */ 138 139 WORD dpb; /*agl*/ /* address of Disk Parameter Block in CP/M 2 */ 140 141 WORD bls; /*agl*/ /* will be calculated by bsh an blm */ 142 143 WORD dsm; /*agl*/ /* total storage capacity of the drive */ 144 /* DSM is one less than the total number of */ 145 /* blocks on the drive. */ 146 147 WORD drm; /*agl*/ /* total number of directory entries minus */ 148 /* one that can be stored on this drive */ 149 150 BYTE psh; /*agl*/ /* PSH from the dpb */ 151 152 BYTE buf[128]; /*agl*/ /* Buffer of the first 128-Byte-Sektor of 153 the diskfile - the discriptor page */ 154 155 BYTE *data; /* disk image (if the mounted disk is a unix 156 directory this pointer points to the 157 simulated cp/m - directory) */ 158 159 char *filename; /* filename of disk image or unix directory */ 160 union { 161 struct { /* details of disk image */ 162 char *header; /* header if it's a disk image */ 163 size_t isize; /* size of disk image */ 164 int ifd; /* file descriptor of disk image */ 165 } image; 166 struct { /* details of unix directory */ 167 int nde; /* number of entries in cp/m directory */ 168 int nfds; /* number of files */ 169 struct fdesc { /* descriptor for each file */ 170 char *fullname; 171 unsigned long firstblock; 172 unsigned long lastblock; 173 unsigned long serial; /* unique id to aid caching */ 174 } *fds; 175 } udir; 176 } m; 177 } mnttab[], *curdisk; 178 #define header m.image.header 179 #define isize m.image.isize 180 #define ifd m.image.ifd 181 #define nde m.udir.nde 182 #define nfds m.udir.nfds 183 #define fds m.udir.fds 184 185 /* We always use a block size of 4k for simulated disks constructed from unix 186 directories. The maximum possible number of cp/m directory entries on such a 187 disk is 2032. */ 188 #define BLOCK_SIZE 4096 189 #define N_ENTRIES 2032 190 #define COVER(x,y) (((x)-1)/(y)+1) 191 192 #ifdef DEBUG 193 void sighand(int sig); 194 #endif 195 196 /*-------------------------------------------- prototyping -------------*/ 197 void clearfc(struct mnt *dp); 198 void setup_cpm3_dph_dpb(int disk); 199 unsigned long dayfaktor(unsigned long day, 200 unsigned long month, 201 unsigned long year); 202 203