/*
* JR-IDE Project
* - (c) 2017 Alan Hightower
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef __PIMOUNT_H__
#define __PIMOUNT_H__
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "rpc.h"
extern int verbose;
#define VERSION_MAJOR 1
#define VERSION_MINOR 1
#define PIMOUNT_MAGIC 0x481a
#define LOGERR(fmt, ...) fprintf(stderr, "\nERROR: " fmt "\n\n", ## __VA_ARGS__)
#define FPDRF(ptr) MK_FP(((ptr)[3] << 8) | (ptr)[2], ((ptr)[1] << 8) | (ptr)[0]);
#define SECTOR_SIZE 512
typedef enum
{
DOS_SUCCESS = 0, // OK
DOS_INVALID_FUNC = 1, // Invalid function number
DOS_FILENOTFND = 2, // File not found
DOS_PATHNOTFND = 3, // Path not found
DOS_TOOMANY = 4, // Too many open files
DOS_ACCESS = 5, // Access denied
DOS_INVLDHNDL = 6, // Invalid handle
DOS_MCBDESTRY = 7, // Memory control blocks shot
DOS_NOMEM = 8, // Insufficient memory
DOS_INVLDMCB = 9, // Invalid memory control block
DOS_INVLDENV = 10, // Invalid enviornment
DOS_INVLDFMT = 11, // Invalid format
DOS_INVLDACC = 12, // Invalid access
DOS_INVLDDATA = 13, // Invalid data
DOS_INVLDDRV = 15, // Invalid drive
DOS_RMVCUDIR = 16, // Attempt remove current dir
DOS_DEVICE = 17, // Not same device
DOS_NFILES = 18, // No more files
DOS_WRTPRTCT = 19, // Write protected
DOS_UNKUNIT = 20, // Unknown unit (FreeDOS defines this as DE_BLKINVLD "Invalid block")
DOS_NOTREADY = 21, // Drive not ready
DOS_UNKCMD = 22, // Unknown command
DOS_CRCERR = 23, // Data error (CRC)
DOS_INVLDBUF = 24, // invalid buffer size, ext fnc
DOS_SEEK = 25, // error on file seek
DOS_GENERAL = 31, // General failure
DOS_SHARE = 32, // Sharing violation
DOS_ENOSPACE = 39, // Disk full (In FreeDOS it's 28)
DOS_FILEEXISTS = 80,
DOS_INVLDPARM = 87, // Invalid parameter
} DOS_ERRORS;
// Extended Open actions
//
#define EXTENDED_CREATE 0x10
#define EXTENDED_OPEN 0x01
#define EXTENDED_REPLACE 0x02
#pragma pack(push, 1)
typedef struct // 88 bytes - DOS drive list
{
uint8_t path[67]; // eg. D:\SOMEDIR\...
uint16_t flags;
uint8_t far *dpb;
void far *context;
uint16_t magic;
uint16_t bsoffset;
uint8_t pad[7];
} dlist_t;
// DOS 2+ Search Data Block entry used by Int 21/AH=4Eh
// http://www.ctyme.com/intr/rb-2977.htm#Table1626
// 21 bytes - Search data block 01626 at ah=4e
typedef struct
{
uint8_t driveno; // 00: drive letter / remote if bit 7 set
char search_mask[11]; // 01:
uint8_t attr_mask; // 0c: search attributes
uint16_t entryno; // 0d: entry count within directory
} SDB_t;
// DOS 2+ Find Data Block entry used by Int 21/AH=4Eh
// http://www.ctyme.com/intr/rb-2576.htm#Table1352
// directory entry for found file - see 01352 at ah=11
typedef struct
{
char name[11]; // 00: found file name
uint8_t attr; // 0b: file attributes
uint8_t reserved; // 0c:
uint8_t time_deca; // 0d: Tenths of a second
uint16_t ctime; // 0e: time of creation
uint16_t cdate; // 10: date of creation
uint16_t adate; // 12: date of last access
uint16_t cluster_hi; // 14: start cluster number (high word)
uint16_t mtime; // 16: time of last update [hhhhhmmm mmmsssss]
uint16_t mdate; // 18: data of last update [YYYYYYYM MMMDDDDD]
uint16_t cluster_lo; // 1a: start cluster number (low word)
uint32_t size; // 1c: file size
} FDB_t;
#define DOS_ATTR_READ_ONLY 0x01
#define DOS_ATTR_HIDDEN 0x02
#define DOS_ATTR_SYSTEM 0x04
#define DOS_ATTR_VOLUME_ID 0x08
#define DOS_ATTR_DIRECTORY 0x10
#define DOS_ATTR_ARCHIVE 0x20
#pragma pack(pop)
typedef struct
{
#define SIGNATURE_TEXT "JRIDE_PIMOUNT"
char signature[14]; // 000: NULL terminated SIGNATURE_TEXT
uint8_t driveno; // 00e: 0=A, 1=B, 2=C, etc...
uint8_t reserved1; // 00f:
uint16_t psp; // 010: Our PSP
uint8_t prev_pull; // 012: Previous pull command to pi
uint8_t reserved2; // 013:
void far *curr_handler; // 014: Our redirector
void far *prev_handler; // 018: Previous/chain redirector
dlist_t far *drive; // 01c: Drive list entry
char far *path; // 020: Current path
uint8_t far *sda; // 024: DOS Swappable Disk Area (SDA)
uint8_t far *filename1; // 028: SDA - file name argument 1
uint8_t far *filename2; // 02c: SDA - file name argument 2
SDB_t far *sdb; // 030: SDA - search data block (find)
FDB_t far *fdb; // 034: SDA - find data block entry
char far *fcbname1; // 038: SDA - file control block 1
char far *fcbname2; // 03c: SDA - file control block 2
uint16_t unicode[128]; // 040: Current code page for name xlat
uint8_t scratch[512]; // 100: Transfer to/from IDE scratch buff
} ctx_t; // 768 bytes
extern ctx_t ctx;
extern volatile uint16_t far *ide_sector;
extern volatile uint8_t far *ide_window;
extern uint16_t _get_resident_psize (void);
extern void __interrupt redirector (union INTPACK );
extern int _redir_pull (uint8_t subcmd);
extern int _redir_push (uint8_t subcmd);
#endif