Improvements to the SD Card and EMS drivers. (#31)
* Refactor SD driver the IO to XTMax. * Refactor the EMS driver to support 8MB.
This commit is contained in:
committed by
GitHub
parent
53caec7569
commit
422a4306f2
@@ -24,8 +24,6 @@ typedef enum {
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
|
||||
void setportbase(BYTE val); /* set the port base */
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
#define DOSFAR far
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* driver.c - MSDOS device driver functions */
|
||||
/* */
|
||||
/* Copyright (C) 1994 by Robert Armstrong */
|
||||
/* Copyright (C) 2024 by Ted Fried, Matthieu Bucchianeri */
|
||||
/* */
|
||||
/* 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 */
|
||||
@@ -55,9 +56,6 @@ BOOLEAN InitNeeded = TRUE; /* TRUE if we need to (re) initialize */
|
||||
WORD RebootVector[2]; /* previous INT 19H vector contents */
|
||||
extern DWORD partitionoffset;
|
||||
|
||||
extern BYTE sd_card_check;
|
||||
extern BYTE portbase;
|
||||
|
||||
BYTE partition_number;
|
||||
|
||||
/* fmemcpy */
|
||||
@@ -369,8 +367,8 @@ PUBLIC void Initialize (rh_init_t far *rh)
|
||||
/* The version number is sneakily stored in the device header! */
|
||||
cdprintf("SD Card driver V%c.%c for XTMax (%s)\n based on SD pport device driver (C) 2014 by Dan Marks\n based on TU58 by Robert Armstrong\n",
|
||||
header.name[6], header.name[7],
|
||||
#ifdef USE286
|
||||
"80286+"
|
||||
#ifdef USE186
|
||||
"80186+"
|
||||
#else
|
||||
"8086"
|
||||
#endif
|
||||
@@ -485,9 +483,6 @@ PRIVATE BOOLEAN parse_options (char far *p)
|
||||
switch (*p++) {
|
||||
case 'd', 'D':
|
||||
Debug = TRUE;
|
||||
break;
|
||||
case 'k', 'K':
|
||||
sd_card_check = 1;
|
||||
break;
|
||||
case 'p', 'P':
|
||||
if ((p=option_value(p,&temp)) == NULL) return FALSE;
|
||||
@@ -495,13 +490,6 @@ PRIVATE BOOLEAN parse_options (char far *p)
|
||||
cdprintf("SD: Invalid partition number %x\n",temp);
|
||||
else
|
||||
partition_number = temp;
|
||||
break;
|
||||
case 'b', 'B':
|
||||
if ((p=option_value(p,&temp)) == NULL) return FALSE;
|
||||
if ((temp < 1) || (temp > 5))
|
||||
cdprintf("SD: Invalid port base index %x\n",temp);
|
||||
else
|
||||
portbase = temp;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
|
||||
@@ -5,23 +5,23 @@ ASM=tasm -mx
|
||||
|
||||
DEPS=cprint.c driver.c sd.c sdmm.c cprint.h diskio.h driver.h integer.h sd.h standard.h
|
||||
|
||||
all: sd.sys sd286.sys
|
||||
all: xtsd.sys xtsd186.sys
|
||||
|
||||
.asm.obj:
|
||||
$(ASM) $*
|
||||
|
||||
sd.sys: header.obj $(DEPS)
|
||||
xtsd.sys: header.obj $(DEPS)
|
||||
$(CC) cprint.c
|
||||
$(CC) sd.c
|
||||
$(CC) sdmm.c
|
||||
$(CC) driver.c
|
||||
tlink -t -m -s -n header cprint sd sdmm driver, $@
|
||||
|
||||
sd286.sys: header.obj $(DEPS)
|
||||
$(CC) -1 -DUSE286 cprint.c
|
||||
$(CC) -1 -DUSE286 sd.c
|
||||
$(CC) -1 -DUSE286 sdmm.c
|
||||
$(CC) -1 -DUSE286 driver.c
|
||||
xtsd186.sys: header.obj $(DEPS)
|
||||
$(CC) -1 -DUSE186 cprint.c
|
||||
$(CC) -1 -DUSE186 sd.c
|
||||
$(CC) -1 -DUSE186 sdmm.c
|
||||
$(CC) -1 -DUSE186 driver.c
|
||||
tlink -t -m -s -n header cprint sd sdmm driver, $@
|
||||
|
||||
clean:
|
||||
|
||||
@@ -1,72 +1,23 @@
|
||||
SD card driver for XTMax
|
||||
|
||||
SD card driver for parallel port
|
||||
This driver is based on SDPP cloned from https://github.com/nilseuropa/sdpp.
|
||||
|
||||
I wrote this to simplify data transfer between my IBM PC and my laptop, because my laptop does
|
||||
not have a 360k floppy drive but does have an SD card slot.
|
||||
|
||||
WARNING: I take **no responsibility** for any damage to your computer, parallel port, or SD
|
||||
card, or any data. You use this driver at your own risk. It is highly recommended you use
|
||||
an expendable parallel port card with your expendable SD card, and your expendable data.
|
||||
It is recommended that you use a level converter IC with between your 5 volt parallel port
|
||||
outputs and the SD card 3.3 volt inputs. This project is intended as a fun hack for hobbyists
|
||||
and enthusiasts and not for serious work.
|
||||
|
||||
This driver is made available under the GNU General Public License version 2. It incorporates
|
||||
The original driver is made available under the GNU General Public License version 2. It incorporates
|
||||
modified code from ELM Chan Fat FS (http://elm-chan.org/fsw/ff/00index_e.html).
|
||||
|
||||
Usage:
|
||||
|
||||
In your config.sys file
|
||||
|
||||
DEVICE=SD.SYS /d /k /p=<partition #> /b=<port base index>
|
||||
DEVICE=SD.SYS /d /p=<partition #>
|
||||
|
||||
Loads and installs the SD card driver.
|
||||
|
||||
/d = debugging mode (displays copious debugging messsages)
|
||||
/k = use card detect signal to inform dos that card is attached
|
||||
/p = partition number (1-4) to partition in MBR to use. Default: first available.
|
||||
/b = port base index of parallel port, one of
|
||||
1=0x3BC, 2=0x378, 3=0x278, 4=0x3E8, 5=0x2E8
|
||||
Default: 0x378
|
||||
|
||||
For best results, format your SD card with a FAT16 partition which is less than 32 MB in size.
|
||||
NOTE: Many versions of DOS don't know how to handle FAT32, and many can't have FAT16 with a
|
||||
partition size greater than 32 MB. Therefore, if you want to play with this, make your parition on
|
||||
the card FAT16 and less than 32 MB. This assures the best compatibility. You can have multiple copies of the
|
||||
driver loaded if there are multiple partitions on your SD card you want to use simultaneously.
|
||||
|
||||
I have used Adafruit's microSD adapter
|
||||
(http://www.adafruit.com/products/254?gclid=CLH7l4iEkrwCFQPNOgod7BkAQA)
|
||||
if you want a relatively simple way to interface your PC parallel port to
|
||||
the SD card. The adapter provides the 3.3 volts needed to power the SD card, as well
|
||||
as a the level shifting between the 5 volt parallel port output and the 3.3 volt input.
|
||||
If you directly connect a 5 volt output to a 3.3 volt input, you risk latching up the
|
||||
3.3 volt input and damaging the card or computer from exceesive current.
|
||||
Some have used series resistors instead of the level converters, but I found this
|
||||
to not be that reliable and still may have this problem. Also, some SD cards MISO/DO
|
||||
outputs are unable to drive a TTL input of some parallel ports, so you may need to add
|
||||
a buffer between the two as well. I have found quite a bit of variability in the drive
|
||||
current required for the inputs of various parallel ports.
|
||||
|
||||
The driver uses the very slow serial peripheral interface (SPI) mode of the SD card. The
|
||||
speed, which depends on your PC speed, could be as slow as 10 kilobytes/second. This is
|
||||
not a replacement for your hard drive. Your parallel port should be configured for standard
|
||||
mode (not bidirectional) if applicable.
|
||||
|
||||
The connections between the parallel port and the SD card are as follows:
|
||||
|
||||
Parallel port SD card
|
||||
|
||||
PIN 25 signal GND GND (Vss)
|
||||
+3.3V Vdd (power)
|
||||
PIN 2 signal D0 CMD / MOSI / DI (SPI data in)
|
||||
PIN 3 signal D1 SCLK / CLK (SPI clock)
|
||||
PIN 4 signal D2 DAT3 / CS (SPI chip select)
|
||||
PIN 13 signal SELECT DAT0 / MISO / DO (SPI data out)
|
||||
PIN 11 signal BUSY Card detect (if you SD card slot has one)
|
||||
|
||||
For similar setups, look up parallel port to JTAG adapters which are used for in circuit
|
||||
programming and debugging.
|
||||
|
||||
Good luck and be careful!
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
/-------------------------------------------------------------------------/
|
||||
/
|
||||
/ Copyright (C) 2013, ChaN, all right reserved.
|
||||
/ Copyright (C) 2024, Ted Fried, Matthieu Bucchianeri
|
||||
/
|
||||
/ * This software is a free software and there is NO WARRANTY.
|
||||
/ * No restriction on use. You can use, modify and redistribute it for
|
||||
@@ -26,15 +27,8 @@
|
||||
/* Platform dependent macros and functions needed to be modified */
|
||||
/*-------------------------------------------------------------------------*/
|
||||
|
||||
static WORD portbases[5] = {0x3BC,0x378,0x278,0x3E8,0x2E8};
|
||||
|
||||
BYTE sd_card_check = 0;
|
||||
BYTE portbase = 2;
|
||||
|
||||
WORD DATAPORT=0x378;
|
||||
WORD CONTROLPORT=0x379;
|
||||
|
||||
#define VAR_INIT() {CONTROLPORT=DATAPORT+1;}
|
||||
WORD DATAPORT=0x280;
|
||||
WORD CONTROLPORT=0x282;
|
||||
|
||||
#if 1
|
||||
#define TOUTCHR(x)
|
||||
@@ -71,13 +65,6 @@ static BYTE toutword(WORD x)
|
||||
|
||||
#endif
|
||||
|
||||
void setportbase(BYTE val)
|
||||
{
|
||||
if ((val >= 1) && (val <= (sizeof(portbases)/sizeof(portbases[0])) ))
|
||||
DATAPORT = portbases[val-1];
|
||||
VAR_INIT();
|
||||
}
|
||||
|
||||
static
|
||||
void dly_us (UINT n)
|
||||
{
|
||||
@@ -187,7 +174,10 @@ void xmit_mmc (
|
||||
UINT bc /* Number of bytes to send */
|
||||
)
|
||||
{
|
||||
#ifndef USE286
|
||||
// NOTE: Callers always use buffer sizes multiple of two.
|
||||
bc >>= 1;
|
||||
|
||||
#ifndef USE186
|
||||
_asm {
|
||||
mov cx,bc
|
||||
mov dx,DATAPORT
|
||||
@@ -196,8 +186,8 @@ void xmit_mmc (
|
||||
}
|
||||
repeat:
|
||||
_asm {
|
||||
lodsb
|
||||
out dx, al
|
||||
lodsw
|
||||
out dx, ax
|
||||
loop repeat
|
||||
pop ds
|
||||
}
|
||||
@@ -207,7 +197,7 @@ void xmit_mmc (
|
||||
mov dx,DATAPORT
|
||||
push ds
|
||||
lds si,dword ptr buff
|
||||
rep outsb
|
||||
rep outsw
|
||||
pop ds
|
||||
}
|
||||
#endif
|
||||
@@ -225,7 +215,10 @@ void rcvr_mmc (
|
||||
UINT bc /* Number of bytes to receive */
|
||||
)
|
||||
{
|
||||
#ifndef USE286
|
||||
// NOTE: Callers always use buffer sizes multiple of two.
|
||||
bc >>= 1;
|
||||
|
||||
#ifndef USE186
|
||||
_asm {
|
||||
mov cx,bc
|
||||
mov dx,DATAPORT
|
||||
@@ -234,8 +227,8 @@ void rcvr_mmc (
|
||||
}
|
||||
repeat:
|
||||
_asm {
|
||||
in al, dx
|
||||
stosb
|
||||
in ax, dx
|
||||
stosw
|
||||
loop repeat
|
||||
pop es
|
||||
}
|
||||
@@ -245,7 +238,7 @@ void rcvr_mmc (
|
||||
mov dx,DATAPORT
|
||||
push es
|
||||
les di,dword ptr buff
|
||||
rep insb
|
||||
rep insw
|
||||
pop es
|
||||
}
|
||||
#endif
|
||||
@@ -350,7 +343,7 @@ int xmit_datablock ( /* 1:OK, 0:Failed */
|
||||
if (!wait_ready()) return 0;
|
||||
|
||||
d = token;
|
||||
xmit_mmc(&d, 1); /* Xmit a token */
|
||||
outp(DATAPORT, d); /* Xmit a token */
|
||||
if (token != 0xFD) { /* Is it data token? */
|
||||
xmit_mmc(buff, 512); /* Xmit the 512 byte data block to MMC */
|
||||
(void)inp(DATAPORT); (void)inp(DATAPORT); /* Xmit dummy CRC (0xFF,0xFF) */
|
||||
@@ -448,11 +441,6 @@ DSTATUS disk_status (
|
||||
)
|
||||
{
|
||||
if (drv) return STA_NOINIT;
|
||||
if ((sd_card_check) && (inp(CONTROLPORT) & 0x80))
|
||||
{
|
||||
Stat = STA_NOINIT;
|
||||
return STA_NOINIT;
|
||||
}
|
||||
return Stat;
|
||||
}
|
||||
|
||||
@@ -461,11 +449,6 @@ DRESULT disk_result (
|
||||
)
|
||||
{
|
||||
if (drv) return RES_NOTRDY;
|
||||
if ((sd_card_check) && (inp(CONTROLPORT) & 0x80))
|
||||
{
|
||||
Stat = STA_NOINIT;
|
||||
return RES_NOTRDY;
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
@@ -482,11 +465,7 @@ DSTATUS disk_initialize (
|
||||
UINT tmr;
|
||||
DSTATUS s;
|
||||
|
||||
setportbase(portbase);
|
||||
|
||||
if (drv) return RES_NOTRDY;
|
||||
if ((sd_card_check) && (inp(CONTROLPORT) & 0x80))
|
||||
return RES_NOTRDY;
|
||||
|
||||
ty = 0;
|
||||
for (n = 5; n; n--) {
|
||||
|
||||
Reference in New Issue
Block a user