This commit is contained in:
Zane Kaminski 2022-12-18 08:46:39 -05:00
parent 51d01f815f
commit ef6286d674
36 changed files with 1109 additions and 1745 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.DS_Store
obj/
.vscode/c_cpp_properties.json
.vscode/settings.json

View File

@ -5,12 +5,12 @@ LD=$(PREFIX)-ld
OBJCOPY=$(PREFIX)-objcopy
OBJDUMP=$(PREFIX)-objdump
all: bin/ROMBUS.bin obj/rombus.s obj/driver.s obj/driver_abs.sym
all: bin/ROMBUS_8M.bin obj/rombus.s obj/driver.s obj/driver_abs.sym
obj:
mkdir $@
mkdir -p $@
bin:
mkdir $@
mkdir -p $@
obj/entry.o: entry.s obj
@ -20,14 +20,38 @@ obj/entry_rel.sym: obj obj/entry.o
$(OBJDUMP) -t obj/entry.o > $@
obj/spi.o: spi.c obj
$(CC) -Wall -march=68020 -c -Os $< -o $@
obj/spi_hal.o: spi_hal.s spi_hal_common.s obj
$(AS) $< -o $@
obj/spi_rx8.o: spi_rx8.s spi_hal.s spi_hal_common.s obj
$(AS) $< -o $@
obj/spi_rx16.o: spi_rx16.s spi_hal.s spi_hal_common.s obj
$(AS) $< -o $@
obj/spi_tx8.o: spi_tx8.s spi_hal.s spi_hal_common.s obj
$(AS) $< -o $@
obj/spi_tx16.o: spi_tx16.s spi_hal.s spi_hal_common.s obj
$(AS) $< -o $@
obj/spi_rxtx8.o: spi_rxtx8.s spi_hal.s spi_hal_common.s obj
$(AS) $< -o $@
obj/spi_delay.o: spi_delay.s obj
$(AS) $< -o $@
obj/rombus.o: rombus.c obj
$(CC) -Wall -march=68030 -c -Os $< -o $@
$(CC) -Wall -march=68020 -c -Os $< -o $@
obj/rombus.s: obj obj/rombus.o
$(OBJDUMP) -d obj/rombus.o > $@
obj/driver.o: obj obj/entry.o obj/rombus.o
$(LD) -Ttext=40851D70 -o $@ obj/entry.o obj/rombus.o
obj/driver.o: obj obj/entry.o obj/rombus.o obj/spi.o obj/spi_hal.o \
obj/spi_rx8.o obj/spi_rx16.o \
obj/spi_tx8.o obj/spi_tx16.o \
obj/spi_rxtx8.o
$(LD) -Ttext=40851D70 -o $@ obj/entry.o obj/rombus.o obj/spi.o obj/spi_hal.o \
obj/spi_rx8.o obj/spi_rx16.o \
obj/spi_tx8.o obj/spi_tx16.o \
obj/spi_rxtx8.o
obj/driver.s: obj obj/driver.o
$(OBJDUMP) -d obj/driver.o > $@
@ -35,11 +59,11 @@ obj/driver.s: obj obj/driver.o
obj/driver_abs.sym: obj obj/driver.o
$(OBJDUMP) -t obj/driver.o > $@
bin/driver.bin: bin obj/driver.o
$(OBJCOPY) -O binary obj/driver.o $@
bin/baserom_romdisk_ramtest.bin: bin roms/baserom.bin bin/driver.bin obj/driver_abs.sym obj/entry_rel.sym
bin/baserom_rombus_ramtest.bin: bin roms/baserom.bin bin/driver.bin obj/driver_abs.sym obj/entry_rel.sym
cp roms/baserom.bin $@ # Copy base rom
# Patch driver
dd if=bin/driver.bin of=$@ bs=1 seek=335248 skip=32 conv=notrunc # Copy driver code
@ -51,23 +75,19 @@ bin/baserom_romdisk_ramtest.bin: bin roms/baserom.bin bin/driver.bin obj/driver_
cat obj/entry_rel.sym | grep "[0-9]\s*DStatus" | cut -c5-8 | xxd -r -p - | dd of=$@ bs=1 seek=335230 count=2 conv=notrunc
cat obj/entry_rel.sym | grep "[0-9]\s*DClose" | cut -c5-8 | xxd -r -p - | dd of=$@ bs=1 seek=335232 count=2 conv=notrunc
bin/baserom_romdisk_noramtest.bin: bin bin/baserom_romdisk_ramtest.bin
cp bin/baserom_romdisk_ramtest.bin $@ # Copy base rom
bin/baserom_rombus_noramtest.bin: bin bin/baserom_rombus_ramtest.bin
cp bin/baserom_rombus_ramtest.bin $@ # Copy base rom
# Disable RAM test
printf '\x4E\xD6' | dd of=$@ bs=1 seek=288736 count=2 conv=notrunc
printf '\x4E\xD6' | dd of=$@ bs=1 seek=289016 count=2 conv=notrunc
bin/ROMBUS.bin: bin bin/baserom_romdisk_noramtest.bin disks/RDisk7M5.dsk
bin/ROMBUS_8M.bin: bin bin/baserom_rombus_noramtest.bin disks/RDisk.dsk
# Copy base rom with ROM disk driver
cp bin/baserom_romdisk_noramtest.bin $@
# Patch ROM disk driver parameter table
printf '\x00\x01\x2A\x29' | dd of=$@ bs=1 seek=335260 count=4 conv=notrunc # Patch CDR patch offset
printf '\x40\x89\x2A\x14' | dd of=$@ bs=1 seek=335268 count=4 conv=notrunc # Patch CDR name address
printf '\x44' | dd of=$@ bs=1 seek=335273 count=1 conv=notrunc # Patch CDR disable byte
cp bin/baserom_rombus_noramtest.bin $@
printf '\x00\x78\x00\x00' | dd of=$@ bs=1 seek=335276 count=4 conv=notrunc # Patch ROM disk size
# Copy ROM disk image
dd if=disks/RDisk7M5.dsk of=$@ bs=1024 seek=512 conv=notrunc
dd if=disks/RDisk.dsk of=$@ bs=1024 seek=512 conv=notrunc
.PHONY: clean
clean:

Binary file not shown.

Binary file not shown.

22
entry.s
View File

@ -8,13 +8,27 @@
dc.l 0x00000000, 0x00000000, 0x00000000, 0x00000000
dc.l 0x00000000, 0x00000000, 0x00000000, 0x00000000
SDiskSig:
.ascii "\5SDisk\0"
RDiskSig:
.ascii "\5RDisk\0"
.align 4
RDiskDBGDisPos:
dc.l 0x00000031
RDiskCDRDisPos:
dc.l 0xFFFFFFFF
RDiskDBGNameAddr:
dc.l 0x4088002A
RDiskCDRNameAddr:
dc.l 0x00000000
RDiskDBGDisByte:
dc.b 0x44
RDiskCDRDisByte:
dc.b 0x44
RDiskRAMRequired:
.ascii "16"
.align 4
RDiskSize:
dc.l 0x00780000
SDiskSize:
dc.l 0x80000000
DOpen:
movem.l %A0-%A1, -(%SP)

View File

@ -1,89 +0,0 @@
# path to RETRO68
RETRO68=~/Retro68-build/toolchain
PREFIX=$(RETRO68)/bin/m68k-apple-macos
AS=$(PREFIX)-as
CC=$(PREFIX)-gcc
LD=$(PREFIX)-ld
OBJCOPY=$(PREFIX)-objcopy
OBJDUMP=$(PREFIX)-objdump
CFLAGS=-march=68030 -c -Os
all: bin/rom16M_swap.bin obj/rdisk7M5.s obj/driver7M5.s obj/entry_rel.sym obj/driver_abs.sym
obj:
mkdir obj
bin:
mkdir bin
obj/entry.o: entry.s obj
$(AS) $< -o $@
obj/entry_rel.sym: obj obj/entry.o
$(OBJDUMP) -t obj/entry.o > $@
obj/rdisk7M5.o: rdisk.c obj
$(CC) -Wall -DRDiskSize=7864320 $(CFLAGS) $< -o $@
obj/rdisk7M5.s: obj obj/rdisk7M5.o
$(OBJDUMP) -d obj/rdisk7M5.o > $@
obj/spi.o: spi.c obj
$(CC) -Wall $(CFLAGS) $< -o $@
obj/spi.s: obj obj/spi.o
$(OBJDUMP) -d obj/spi.o > $@
obj/sdmmc.o: sdmmc.c obj
$(CC) -Wall $(CFLAGS) -Os $< -o $@
obj/sdmmc.s: obj obj/sdmmc.o
$(OBJDUMP) -d obj/sdmmc.o > $@
obj/driver7M5.o: obj obj/entry.o obj/rdisk7M5.o
$(LD) -Ttext=40851D70 -o $@ obj/entry.o obj/rdisk7M5.o obj/spi.o obj/sdmmc.o
obj/driver7M5.s: obj obj/driver7M5.o
$(OBJDUMP) -d obj/driver7M5.o > $@
obj/driver_abs.sym: obj obj/driver7M5.o
$(OBJDUMP) -t obj/driver7M5.o > $@
bin/driver7M5.bin: bin obj/driver7M5.o
$(OBJCOPY) -O binary obj/driver7M5.o $@
bin/rom8M.bin: bin baserom.bin RDisk7M5.dsk bin bin/driver7M5.bin obj/driver_abs.sym obj/entry_rel.sym
cp baserom.bin $@ # Copy base rom
# Patch driver
dd if=bin/driver7M5.bin of=$@ bs=1 seek=335248 skip=32 conv=notrunc # Copy driver code
printf '\x78' | dd of=$@ bs=1 seek=335168 count=1 conv=notrunc # Set resource flags
printf '\x4F' | dd of=$@ bs=1 seek=335216 count=1 conv=notrunc # Set driver flags
cat obj/entry_rel.sym | grep "DOpen" | cut -c5-8 | xxd -r -p - | dd of=$@ bs=1 seek=335224 count=2 conv=notrunc
cat obj/entry_rel.sym | grep "DPrime" | cut -c5-8 | xxd -r -p - | dd of=$@ bs=1 seek=335226 count=2 conv=notrunc
cat obj/entry_rel.sym | grep "DControl" | cut -c5-8 | xxd -r -p - | dd of=$@ bs=1 seek=335228 count=2 conv=notrunc
cat obj/entry_rel.sym | grep "DStatus" | cut -c5-8 | xxd -r -p - | dd of=$@ bs=1 seek=335230 count=2 conv=notrunc
cat obj/entry_rel.sym | grep "DClose" | cut -c5-8 | xxd -r -p - | dd of=$@ bs=1 seek=335232 count=2 conv=notrunc
dd if=RDisk7M5.dsk of=$@ bs=1024 seek=512 count=7680 conv=notrunc # copy disk image
bin/rom8M_swap.bin: bin bin/rom8M.bin
dd if=bin/rom8M.bin of=$@ conv=swab # swap bytes
bin/iisi_swap.bin: bin iisi.bin
dd if=iisi.bin of=$@ conv=swab # swap bytes
bin/rom16M_swap.bin: bin/iisi_swap.bin bin/rom8M_swap.bin
cat bin/rom8M_swap.bin > $@
cat bin/iisi_swap.bin >> $@
.PHONY: clean
clean:
rm -fr bin obj

Binary file not shown.

View File

@ -1,84 +0,0 @@
.EQU killCode, 1
.EQU noQueueBit, 9
.EQU kioTrap, 6
.EQU kioResult, 16
.EQU kcsCode, 26
.EQU JIODone, 0x08FC
.GLOBAL RDiskSig
.GLOBAL RDiskDBGNamePos
.GLOBAL RDiskDBGDisPos
.GLOBAL RDiskDBGDisByte
.GLOBAL RDiskCDRNamePos
.GLOBAL RDiskCDRDisPos
.GLOBAL RDiskCDRDisByte
dc.l 0x00000000, 0x00000000, 0x00000000, 0x00000000
dc.l 0x00000000, 0x00000000, 0x00000000, 0x00000000
RDiskSig:
.ascii "\5RDisk\0"
.align 4
RDiskDBGDisPos:
dc.l 0x00000031
RDiskCDRDisPos:
dc.l 0x00012CAF
RDiskDBGNameAddr:
dc.l 0x4088002A
RDiskCDRNameAddr:
dc.l 0x40892C96
RDiskDBGDisByte:
dc.b 0x44
RDiskCDRDisByte:
dc.b 0x44
RDiskRAMRequired:
.ascii "16"
.align 4
DOpen:
movem.l %A0-%A1, -(%SP)
bsr RDOpen
movem.l (%SP)+, %A0-%A1
rts
DClose:
movem.l %A0-%A1, -(%SP)
bsr RDClose
movem.l (%SP)+, %A0-%A1
rts
DPrime:
movem.l %A0-%A1, -(%SP)
bsr RDPrime
movem.l (%SP)+, %A0-%A1
bra.b IOReturn
DControl:
movem.l %A0-%A1, -(%SP)
bsr RDCtl
movem.l (%SP)+, %A0-%A1
cmpi.w #killCode, kcsCode(%A0)
bne.b IOReturn
rts
DStatus:
movem.l %A0-%A1, -(%SP)
bsr RDStat
movem.l (%SP)+, %A0-%A1
IOReturn:
move.w kioTrap(%A0), %D1
btst #noQueueBit, %D1
beq.b Queued
NotQueued:
tst.w %D0
ble.b ImmedRTS
clr.w %D0
ImmedRTS:
move.w %D0, kioResult(%A0)
rts
Queued:
move.l JIODone, -(%SP)
rts

View File

@ -1,361 +0,0 @@
#include <Memory.h>
#include <Devices.h>
#include <Files.h>
#include <Disks.h>
#include <Errors.h>
#include <Events.h>
#include <OSUtils.h>
#include "rdisk.h"
// Decode keyboard/PRAM settings
static void RDDecodeSettings(Ptr recoveryEN, Ptr unmountEN, Ptr mountEN) {
// Read PRAM
char legacy_startup;
RBReadXPRAM(1, 4, &legacy_startup);
// Decode settings: boot from recovery, unmount (don't boot), mount (after boot)
if (RBIsRPressed()) { // R boots from ROM recovery
*recoveryEN = 1; // Enable recovery partition
*unmountEN = 0; // Unmount SD so we don't boot from it
*mountEN = 1; // Mount SD later
} else {
*recoveryEN = 0; // Disable recovery partition
if (legacy_startup & 0x10) { // Boot from SD disk
*unmountEN = 0; // Don't unmount so we boot from this drive
*mountEN = 0; // No need to mount later since we are boot disk
} else if (legacy_startup & 0x20) { // Mount SD disk under other boot volume
*unmountEN = 1; // Unmount to not boot from our disk
*mountEN = 1; // Mount in accRun
} else {
*unmountEN = 1; // Unmount
*mountEN = 0; // Don't mount again
}
}
}
// Switch to 32-bit mode and copy
#pragma parameter C24(__A0, __A1, __D0)
void __attribute__ ((noinline)) C24(Ptr sourcePtr, Ptr destPtr, unsigned long byteCount) {
signed char mode = true32b;
SwapMMUMode(&mode);
BlockMove(sourcePtr, destPtr, byteCount);
SwapMMUMode(&mode);
}
// Switch to 32-bit mode and get
#pragma parameter __D0 G24(__A2)
char __attribute__ ((noinline)) G24(Ptr pos) {
long ret;
signed char mode = true32b;
SwapMMUMode(&mode);
ret = *pos; // Peek
SwapMMUMode(&mode);
return ret;
}
// Switch to 32-bit mode and set
#pragma parameter S24(__A2, __D3)
void __attribute__ ((noinline)) S24(Ptr pos, char patch) {
signed char mode = true32b;
SwapMMUMode(&mode);
*pos = patch; // Poke
SwapMMUMode(&mode);
}
// Figure out the first available drive number >= 5
static int RBFindDrvNum() {
DrvQElPtr dq;
int drvNum = 5;
for (dq = (DrvQElPtr)(GetDrvQHdr())->qHead; dq; dq = (DrvQElPtr)dq->qLink) {
if (dq->dQDrive >= drvNum) { drvNum = dq->dQDrive + 1; }
}
return drvNum;
}
static void RBOpenRDisk(RDiskStorage_t *c) {
int drvNum;
// Find first available drive number for ROM recovery
drvNum = RBFindDrvNum();
// Set ROM recovery drive status
//c->rStatus.track = 0;
c->rStatus.writeProt = -1; // nonzero is write protected
c->rStatus.diskInPlace = 8; // 8 is nonejectable disk
c->rStatus.installed = 1; // drive installed
//c->rStatus.sides = 0;
//c->rStatus.qType = 1;
c->rStatus.dQDrive = drvNum;
//c->rStatus.dQFSID = 0;
c->rStatus.dQRefNum = d->dCtlRefNum;
c->rStatus.driveSize = RDiskSize / 512;
//c->rStatus.driveS1 = (RDiskSize / 512) >> 16;
// Decompress icon
#ifdef RDISK_COMPRESS_ICON_ENABLE
char *src = &RDiskIconCompressed[0];
char *dst = &c->rIcon[0];
UnpackBits(&src, &dst, RDISK_ICON_SIZE);
#endif
// Add RDisk to drive queue and return
RDiskAddDrive(c->rStatus.dQRefNum, drvNum, (DrvQElPtr)&c->rStatus.qLink);
}
static void RBOpenSDisk(RDiskStorage_t *c) {
int drvNum;
// Find first available drive number for SD disk
drvNum = RBFindDrvNum();
// Set SD disk drive status
//c->rStatus.track = 0;
c->rStatus.writeProt = 0; // 0 is writable
c->rStatus.diskInPlace = 8; // 8 is nonejectable disk
c->rStatus.installed = 1; // drive installed
//c->rStatus.sides = 0;
c->rStatus.qType = 1;
c->rStatus.dQDrive = drvNum;
//c->rStatus.dQFSID = 0;
c->rStatus.dQRefNum = d->dCtlRefNum;
c->rStatus.driveSize = SDiskSize / 512;
c->rStatus.driveS1 = (SDiskSize / 512) >> 16;
// Decompress icon
#ifdef SDISK_COMPRESS_ICON_ENABLE
char *src = &SDiskIconCompressed[0];
char *dst = &c->sIcon[0];
UnpackBits(&src, &dst, SDISK_ICON_SIZE);
#endif
// Add SDisk to drive queue and return
RDiskAddDrive(c->rstatus.dQRefNum, drvNum, (DrvQElPtr)&c->sStatus.qLink);
}
#pragma parameter __D0 RBOpen(__A0, __A1)
OSErr RBOpen(IOParamPtr p, DCtlPtr d) {
RDiskStorage_t *c;
char legacy_startup;
// Do nothing if already opened
if (d->dCtlStorage) { return noErr; }
// Do nothing if inhibited
RBReadXPRAM(1, 4, &legacy_startup);
if (legacy_startup & 0x40) { return noErr; }
// Allocate storage struct
d->dCtlStorage = NewHandleSysClear(sizeof(RDiskStorage_t));
if (!d->dCtlStorage) { return openErr; }
// Lock our storage struct and get master pointer
HLock(d->dCtlStorage);
c = *(RDiskStorage_t**)d->dCtlStorage;
// Create RDisk and SDisk entries in drive queue, then return
RBOpenRDisk(c);
RBOpenSDisk(c);
return noErr;
}
// Init is called at beginning of first prime (read/write) call
static void RBInit(IOParamPtr p, DCtlPtr d, RDiskStorage_t *c) {
char recoveryEN, unmountEN, mountEN;
// Mark init done
c->initialized = 1;
// Decode settings
RDDecodeSettings(&recoveryEN, &unmountEN, &mountEN);
// Unmount if not booting from ROM disk
if (!recoveryEN) { c->rStatus.diskInPlace = 0; }
// Unmount if not booting from ROM disk
if (unmountEN) { c->SStatus.diskInPlace = 0; }
// If mount enabled, enable accRun to post disk inserted event later
if (mountEN) {
d->dCtlDelay = 150; // Set accRun delay (150 ticks is 2.5 sec.)
d->dCtlFlags |= dNeedTimeMask; // Enable accRun
}
}
static OSErr RDPrime(IOParamPtr p, DCtlPtr d) {
// Get pointer to correct position in ROM disk buffer
Ptr disk = RDiskBuf + d->dCtlPosition;
// Return disk offline error if virtual disk not inserted
if (!c->rStatus.diskInPlace) { return offLinErr; }
// Bounds checking
if (d->dCtlPosition >= RDiskSize || p->ioReqCount >= RDiskSize ||
d->dCtlPosition + p->ioReqCount >= RDiskSize) { return paramErr; }
// Service read or write request
cmd = p->ioTrap & 0x00FF;
if (cmd == aRdCmd) {
if (*MMU32bit) { BlockMove(disk, p->ioBuffer, p->ioReqCount); }
else { copy24(disk, StripAddress(p->ioBuffer), p->ioReqCount); }
} else if (cmd == aWrCmd) { return wPrErr;
} else { return noErr; } //FIXME: Fail if cmd isn't read or write?
// Update count and position/offset, then return
d->dCtlPosition += p->ioReqCount;
p->ioActCount = p->ioReqCount;
return noErr;
}
static OSErr SDPrime(IOParamPtr p, DCtlPtr d) {
}
#pragma parameter __D0 RBPrime(__A0, __A1)
OSErr RBPrime(IOParamPtr p, DCtlPtr d) {
RDiskStorage_t *c;
char cmd;
// Return disk offline error if dCtlStorage null
if (!d->dCtlStorage) { return notOpenErr; }
// Dereference dCtlStorage to get pointer to our context
c = *(RDiskStorage_t**)d->dCtlStorage;
// Initialize if this is the first prime call
if (!c->initialized) { RBInit(p, d, c); }
if (p->ioVRefNum == c->sStatus.dQDrive) {
return SDPrime(p, d, c);
} else if (p->ioVRefNum == c->rStatus.dQDrive) {
return RDPrime(p, d, c);
} else { return nsvErr; }
}
static OSErr RDCtl(CntrlParamPtr p, DCtlPtr d, RDiskStorage_t *c) {
// Handle control request based on csCode
switch (p->csCode) {
case kFormat: return controlErr;
case kVerify:
if (!c->rStatus.diskInPlace) { return controlErr; }
return noErr;
case kEject:
// "Reinsert" disk if ejected illegally
if (c->rStatus.diskInPlace) {
PostEvent(diskEvt, c->status.dQDrive);
}
return controlErr; // Eject not allowed so return error
case kDriveIcon: case kMediaIcon: // Get icon
#ifdef RDISK_COMPRESS_ICON_ENABLE
*(Ptr*)p->csParam = (Ptr)c->rIcon;
#else
*(Ptr*)p->csParam = (Ptr)RDiskIcon;
#endif
return noErr;
case kDriveInfo:
// high word (bytes 2 & 3) clear
// byte 1 = primary + fixed media + internal
// byte 0 = drive type (0x11 is ROM disk)
*(long*)p->csParam = 0x00000411;
return noErr;
case 24: // Return SCSI partition size
*(long*)p->csParam = RDiskSize / 512;
return noErr;
default: return controlErr;
}
}
static OSErr SDCtl(CntrlParamPtr p, DCtlPtr d, RDiskStorage_t *c) {
// Handle control request based on csCode
switch (p->csCode) {
case kFormat:
// FIXME: implement SD format
return controlErr;
case kVerify:
// FIXME: implement SD verify
return noErr;
case kEject:
// "Reinsert" disk if ejected illegally
if (c->sStatus.diskInPlace) {
PostEvent(diskEvt, c->sStatus.dQDrive);
}
return controlErr; // Eject not allowed so return error
case kDriveIcon: case kMediaIcon: // Get icon
#ifdef SDISK_COMPRESS_ICON_ENABLE
*(Ptr*)p->csParam = (Ptr)c->sIcon;
#else
*(Ptr*)p->csParam = (Ptr)SDiskIcon;
#endif
return noErr;
case kDriveInfo:
// high word (bytes 2 & 3) clear
// byte 1 = primary + fixed media + internal
// byte 0 = drive type (0x01 is unspecified drive)
*(long*)p->csParam = 0x00000401;
return noErr;
case 24: // Return SCSI partition size
*(long*)p->csParam = SDiskSize / 512;
return noErr;
default: return controlErr;
}
}
#pragma parameter __D0 RBCtl(__A0, __A1)
OSErr RBCtl(CntrlParamPtr p, DCtlPtr d) {
RDiskStorage_t *c;
// Fail if dCtlStorage null
if (!d->dCtlStorage) { return notOpenErr; }
// Dereference dCtlStorage to get pointer to our context
c = *(RDiskStorage_t**)d->dCtlStorage;
// Handle control request based on csCode
switch (p->csCode) {
case killCode:
return noErr;
case accRun:
d->dCtlFlags &= ~dNeedTimeMask; // Disable accRun
c->sStatus.diskInPlace = 8; // 8 is nonejectable disk
PostEvent(diskEvt, c->sStatus.dQDrive); // Post disk inserted event
return noErr;
case 2351: // Post-boot
c->initialized = 1; // Skip initialization
d->dCtlDelay = 30; // Set accRun delay (30 ticks is 0.5 sec.)
d->dCtlFlags |= dNeedTimeMask; // Enable accRun
return noErr;
}
// Otherwise, dispatch to correct drive
if (p->ioVRefNum == c->sStatus.dQDrive) {
return SDCtl(p, d, c);
} else if (p->ioVRefNum == c->rStatus.dQDrive) {
return RDCtl(p, d, c);
} else { return nsvErr; }
}
#pragma parameter __D0 RBStat(__A0, __A1)
OSErr RBStat(CntrlParamPtr p, DCtlPtr d) {
RDiskStorage_t *c;
// Fail if dCtlStorage null
if (!d->dCtlStorage) { return notOpenErr; }
// Dereference dCtlStorage to get pointer to our context
c = *(RDiskStorage_t**)d->dCtlStorage;
// Handle status request based on csCode
switch (p->csCode) {
case kDriveStatus:
// Otherwise, copy correct drive status
if (p->ioVRefNum == c->sStatus.dQDrive) {
BlockMove(&c->sStatus, &p->csParam, sizeof(DrvSts2));
} else if (p->ioVRefNum == c->rStatus.dQDrive) {
BlockMove(&c->rStatus, &p->csParam, sizeof(DrvSts2));
} else { return nsvErr; }
return noErr;
default: return statusErr;
}
}
#pragma parameter __D0 RBClose(__A0, __A1)
OSErr RBClose(IOParamPtr p, DCtlPtr d) {
// If dCtlStorage not null, dispose of it
if (!d->dCtlStorage) { return noErr; }
//RDiskStorage_t *c = *(RDiskStorage_t**)d->dCtlStorage;
HUnlock(d->dCtlStorage);
DisposeHandle(d->dCtlStorage);
d->dCtlStorage = NULL;
return noErr;
}

View File

@ -1,179 +0,0 @@
#ifndef ROMBUS_H
#define ROMBUS_H
#define RDiskBuf ((char*)0x408C0000)
#define SDiskSize (0x80000000L)
#define BufPtr ((Ptr*)0x10C)
#define MemTop ((Ptr*)0x108)
#define MMU32bit ((char*)0xCB2)
#pragma parameter __D0 RBReadXPRAM(__D0, __D1, __A0)
OSErr RBReadXPRAM(short numBytes, short whichByte, Ptr dest) = {0x4840, 0x3001, 0xA051};
#pragma parameter __D0 RBAddDrive(__D1, __D0, __A0)
OSErr RBAddDrive(short drvrRefNum, short drvNum, DrvQElPtr dq) = {0x4840, 0x3001, 0xA04E};
static inline char RBIsRPressed() { return *((char*)0x175) & 0x80; }
typedef struct RBStorage_s {
DrvSts2 sStatus;
DrvSts2 rStatus;
char initialized;
} RBStorage_t;
typedef void (*RDiskCopy_t)(Ptr, Ptr, unsigned long);
#define copy24(s, d, b) { RDiskCopy_t f = C24; f(s, d, b); }
typedef char (*RDiskPeek_t)(Ptr);
#define peek24(a, d) { RDiskPeek_t f = G24; d = f(a); }
typedef void (*RDiskPoke_t)(Ptr, char);
#define poke24(a, d) { RDiskPoke_t f = S24; f(a, d); }
#define RDISK_ICON_SIZE (285)
const char RDiskIcon[RDISK_ICON_SIZE] = {
// Icon
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b10000000, 0b00000000, 0b00000000, 0b00000001,
0b10001111, 0b00011110, 0b00111100, 0b01111001,
0b10001001, 0b00010010, 0b00100100, 0b01001001,
0b10001001, 0b00010010, 0b00100100, 0b01001001,
0b10001001, 0b00010010, 0b00100100, 0b01001001,
0b10001111, 0b00011110, 0b00111100, 0b01111001,
0b11000000, 0b00000000, 0b00000000, 0b00000001,
0b01010101, 0b01010101, 0b11010101, 0b01010101,
0b01111111, 0b11111111, 0b01111111, 0b11111111,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
// Mask
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b11111111, 0b11111111, 0b11111111, 0b11111111,
0b01111111, 0b11111111, 0b11111111, 0b11111111,
0b01111111, 0b11111111, 0b11111111, 0b11111111,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
27, 'G', 'a', 'r', 'r', 'e', 't', 't', '\'', 's', ' ',
'W', 'o', 'r', 'k', 's', 'h', 'o', 'p', ' ',
'R', 'O', 'M', ' ', 'D', 'i', 's', 'k', 0
};
#define SDISK_ICON_SIZE (283)
const char const SDiskIcon[SDISK_ICON_SIZE] = {
// Icon
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000001, 0b00000000, 0b00000000, 0b00010000,
0b00000001, 0b00000001, 0b10000000, 0b11010000,
0b00000001, 0b01101101, 0b10110110, 0b11010000,
0b00000001, 0b01101101, 0b10110110, 0b11010000,
0b00000001, 0b01101101, 0b10110110, 0b11010000,
0b00000001, 0b01101101, 0b10110110, 0b11010000,
0b00000001, 0b01101101, 0b10110110, 0b11010000,
0b00000001, 0b00000000, 0b00000000, 0b00010000,
0b00000001, 0b00000000, 0b00000000, 0b00010000,
0b00000010, 0b00000000, 0b00000000, 0b00010000,
0b00000100, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001110, 0b00000000, 0b00000000, 0b00010000,
0b00000010, 0b00000000, 0b00000000, 0b00010000,
0b00000010, 0b00000000, 0b00000000, 0b00010000,
0b00000010, 0b00000000, 0b00000000, 0b00010000,
0b00000100, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001000, 0b00000000, 0b00000000, 0b00010000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
// Mask
0b00000000, 0b00000000, 0b00000000, 0b00000000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000001, 0b11111111, 0b11111111, 0b11110000,
0b00000011, 0b11111111, 0b11111111, 0b11110000,
0b00000111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00000011, 0b11111111, 0b11111111, 0b11110000,
0b00000011, 0b11111111, 0b11111111, 0b11110000,
0b00000011, 0b11111111, 0b11111111, 0b11110000,
0b00000111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00001111, 0b11111111, 0b11111111, 0b11110000,
0b00000000, 0b00000000, 0b00000000, 0b00000000,
25, 'G', 'a', 'r', 'r', 'e', 't', 't', '\'', 's', ' ',
'W', 'o', 'r', 'k', 's', 'h', 'o', 'p', ' ',
'R', 'O', 'M', 'B', 'U', 'S', 0
};
#endif

View File

@ -1,220 +0,0 @@
#include "sdmmc.h"
/*--------------------------------------------------------------------------
Module Private Functions
---------------------------------------------------------------------------*/
#define INIT_PORT() init_port() /* Initialize MMC control port (CS/CLK/DI:output, DO:input) */
#define DLY_US(n) dly_us(n) /* Delay n microseconds */
#define FORWARD(d) forward(d) /* Data in-time processing function (depends on the project) */
/* Definitions for MMC/SDC command */
#define CMD0 (0x40+0) /* GO_IDLE_STATE */
#define CMD1 (0x40+1) /* SEND_OP_COND (MMC) */
#define ACMD41 (0xC0+41) /* SEND_OP_COND (SDC) */
#define CMD8 (0x40+8) /* SEND_IF_COND */
#define CMD16 (0x40+16) /* SET_BLOCKLEN */
#define CMD17 (0x40+17) /* READ_SINGLE_BLOCK */
#define CMD24 (0x40+24) /* WRITE_BLOCK */
#define CMD55 (0x40+55) /* APP_CMD */
#define CMD58 (0x40+58) /* READ_OCR */
/* Card type flags (CardType) */
#define CT_MMC 0x01 /* MMC ver 3 */
#define CT_SD1 0x02 /* SD ver 1 */
#define CT_SD2 0x04 /* SD ver 2 */
#define CT_SDC (CT_SD1|CT_SD2) /* SD */
#define CT_BLOCK 0x08 /* Block addressing */
static char CardType; /* 0:MMC, 1:SDv1, 2:SDv2, 3:Block addressing */
/*-----------------------------------------------------------------------*/
/* Send a command packet to MMC */
/*-----------------------------------------------------------------------*/
static char send_cmd(char cmd, long arg)
{
char n, res;
if (cmd & 0x80) { /* ACMD<n> is the command sequense of CMD55-CMD<n> */
cmd &= 0x7F;
res = send_cmd(CMD55, 0);
if (res > 1) return res;
}
/* Select the card */
CS_H(); spi_rx();
CS_L(); spi_rx();
/* Send a command packet */
spi_tx(cmd); /* Start + Command index */
s((BYTE)(arg >> 24)); /* Argument[31..24] */
spi_tx((BYTE)(arg >> 16)); /* Argument[23..16] */
spi_tx((BYTE)(arg >> 8)); /* Argument[15..8] */
spi_tx((BYTE)arg); /* Argument[7..0] */
n = 0x01; /* Dummy CRC + Stop */
if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */
if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */
spi_tx(n);
/* Receive a command response */
n = 10; /* Wait for a valid response in timeout of 10 attempts */
do {
res = spi_rx();
} while ((res & 0x80) && --n);
return res; /* Return with the response value */
}
/*--------------------------------------------------------------------------
Public Functions
---------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
sdstatus_t sdmmc_init()
{
char n, cmd, ty, buf[4];
uint tmr;
CS_H();
spi_skip(10); /* Dummy clocks */
ty = 0;
if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
if (send_cmd(CMD8, 0x1AA) == 1) { /* SDv2 */
for (n = 0; n < 4; n++) buf[n] = spi_rx(); /* Get trailing return value of R7 resp */
if (buf[2] == 0x01 && buf[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */
for (tmr = 1000; tmr; tmr--) { /* Wait for leaving idle state (ACMD41 with HCS bit) */
if (send_cmd(ACMD41, 1UL << 30) == 0) break;
DLY_US(1000);
}
if (tmr && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */
for (n = 0; n < 4; n++) buf[n] = spi_rx();
ty = (buf[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* SDv2 (HC or SC) */
}
}
} else { /* SDv1 or MMCv3 */
if (send_cmd(ACMD41, 0) <= 1) {
ty = CT_SD1; cmd = ACMD41; /* SDv1 */
} else {
ty = CT_MMC; cmd = CMD1; /* MMCv3 */
}
for (tmr = 1000; tmr; tmr--) { /* Wait for leaving idle state */
if (send_cmd(cmd, 0) == 0) break;
DLY_US(1000);
}
if (!tmr || send_cmd(CMD16, 512) != 0) /* Set R/W block length to 512 */
ty = 0;
}
}
CardType = ty;
release_spi();
return ty ? 0 : STA_NOINIT;
}
/*-----------------------------------------------------------------------*/
/* Read partial sector */
/*-----------------------------------------------------------------------*/
sdresult_t sdmmc_readp(Ptr buf, long sector, uint offset, uint count)
{
DRESULT res;
char d;
uint bc, tmr;
if (!(CardType & CT_BLOCK)) sector *= 512; /* Convert to byte address if needed */
res = RES_ERROR;
if (send_cmd(CMD17, sector) == 0) { /* READ_SINGLE_BLOCK */
tmr = 1000;
do { /* Wait for data packet in timeout of 100ms */
DLY_US(100);
d = spi_rx();
} while (d == 0xFF && --tmr);
if (d == 0xFE) { /* A data packet arrived */
bc = 514 - offset - count;
/* Skip leading bytes */
if (offset) spi_skip(offset);
/* Receive a part of the sector */
if (buff) { /* Store data to the memory */
do
*buff++ = spi_rx();
while (--count);
} else { /* Forward data to the outgoing stream */
do {
d = spi_rx();
FORWARD(d);
} while (--count);
}
/* Skip trailing bytes and CRC */
spi_skip(bc);
res = RES_OK;
}
}
release_spi();
return res;
}
/*-----------------------------------------------------------------------*/
/* Write partial sector */
/*-----------------------------------------------------------------------*/
sdresult_t sdmmc_writep(const Ptr buf, long sc)
{
DRESULT res;
UINT bc, tmr;
static UINT wc;
res = RES_ERROR;
if (buff) { /* Send data bytes */
bc = (UINT)sc;
while (bc && wc) { /* Send data bytes to the card */
spi_tx(*buff++);
wc--; bc--;
}
res = RES_OK;
} else {
if (sc) { /* Initiate sector write transaction */
if (!(CardType & CT_BLOCK)) sc *= 512; /* Convert to byte address if needed */
if (send_cmd(CMD24, sc) == 0) { /* WRITE_SINGLE_BLOCK */
spi_tx(0xFF); spi_tx(0xFE); /* Data block header */
wc = 512; /* Set byte counter */
res = RES_OK;
}
} else { /* Finalize sector write transaction */
bc = wc + 2;
while (bc--) spi_tx(0); /* Fill left bytes and CRC with zeros */
if ((spi_rx() & 0x1F) == 0x05) { /* Receive data resp and wait for end of write process in timeout of 300ms */
for (tmr = 10000; spi_rx() != 0xFF && tmr; tmr--) /* Wait for ready (max 1000ms) */
DLY_US(100);
if (tmr) res = RES_OK;
}
release_spi();
}
}
return res;
}

View File

@ -1,29 +0,0 @@
#ifndef SDMMC_H
#define SDMMC_H
/* Status of Disk Functions */
typedef char sdstatus_t;
#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
/* Results of Disk Functions */
typedef enum sdmmc_result_e {
RES_OK = 0, /* 0: Function succeeded */
RES_ERROR, /* 1: Disk error */
RES_NOTRDY, /* 2: Not ready */
RES_PARERR /* 3: Invalid parameter */
} sdresult_t;
/*---------------------------------------*/
/* Prototypes for disk control functions */
/*---------------------------------------*/
sdstatus_t sdmmc_init();
sdresult_t sdmmc_readp(Ptr buf, long sector, uint offset, uint count);
sdresult_t sdmmc_writep(const Ptr buf, long sc);
#endif

164
old/spi.c
View File

@ -1,164 +0,0 @@
#include "spi.h"
/*-------------------------------------------------------------------------*/
/* Platform dependent macros and functions needed to be modified */
/*-------------------------------------------------------------------------*/
#define CS_H() bset(P0) /* Set MMC CS "high" */
#define CS_L() bclr(P0) /* Set MMC CS "low" */
#define CK_H() bset(P1) /* Set MMC SCLK "high" */
#define CK_L() bclr(P1) /* Set MMC SCLK "low" */
#define DI_H() bset(P2) /* Set MMC DI "high" */
#define DI_L() bclr(P2) /* Set MMC DI "low" */
#define DO btest(P3) /* Test MMC DO (high:true, low:false) */
// Command listing
/* T16: Transfer 16-bit
* First, the 16-bit value encoded in the address bits A[17:2] is latched.
* The data output mux is set to the current RXR and the cycle completes.
* Shortly after /AS rises, the SPI transfer engine begins
* transferring the latched value.
*/
/* T16S: Transfer 16-bit Swapped
* Same as T16L but read data is byte-swapped.
*/
/* MERT: Measure Elapsed time and Reset Timer
* The elapsed time since the last MERT command is returned in D[31:24]
* and the timer is reset.
*/
/* SKIP1: Skip Clocks with MOSI "1"
*
*/
/* SKIP0: Skip Clocks with MOSI "0"
*
*/
/* T8S: Transfer 8-bit Swapped
* Same as T8 but read data is byte-swapped.
*/
/* T8: Transfer 8-bit
* First, the 8-bit value encoded in the address bits A[9:2] is latched.
* The data output mux is set to the current RXR and the cycle completes.
* Shortly after /AS rises, the SPI transfer engine begins
* transferring the latched value.
*/
/* WRC: Write Command
* The command encoded in address bits A[9:2] is sent to the command target
* corresponding to the address bits A[15:10].
* Command targets:
* $00 - Set bitbang
* A[2] - SCS value
*/
/* RDRXR: Read Receive Data Register
* The the current RXR is returned in D[31:16] and the cycle completes.
*/
/* RDRXRS: Read Receive Data Register Swapped
* Same as RDRXR but read data is byte-swapped.
*/
/* MAGIC: Write Command
* Write sequence $FF $00 $55 $AA $C1 $AD
* to enable registers at $40890000-$4097FFFF.
* Write anything else to disable them.
* Always reads 0xC1AD
*/
// SPI controller address map:
// 40940000-4097FFFF (256 kB, D[31:16]) T16S. Write transfer data in A[17:2].
// 40900000-4093FFFF (256 kB, D[31:16]) T16. Write transfer data in A[17:2].
// 408C0000-408FFFFF (320 kB) reserved
// 408A0000-408AFFFF ( 64 kB, D[31:24]) WRC. Write port address in A[15:10] and data in A[9:2].
// 40891C00-4089FFFF ( 55 kB) reserved
// 40892000-408923FF ( 1 kB, D[31:24]) MERT.
// 40891C00-40891FFF ( 1 kB) SKIP1. Write bytes to skip in A[9:2].
// 40891800-40891BFF ( 1 kB) SKIP0. Write bytes to skip in A[9:2].
// 40891400-408917FF ( 1 kB, D[31:16]) T8S. Write transfer data in A[9:2].
// 40891000-408913FF ( 1 kB, D[31:16]) T8. Write transfer data in A[9:2].
// 40890C00-40890FFF ( 1 kB, D[31:16]) RDRXRS.
// 40890800-40890BFF ( 1 kB, D[31:16]) RDRXR.
// 40890400-408907FF ( 1 kB) reserved
// 40890000-408903FF ( 1 kB, D[31:24]) MAGIC. Write magic numbers in A[9:2].
// 40880000-408FFFFF ( 64 kB, D[31:00]) ROMBUS driver data
#define RB_T16S(x) (*(volatile int*) (0x40940000 + ((x && 0xFFFF)<<02)) )
#define RB_T16(x) (*(volatile int*) (0x40900000 + ((x && 0xFFFF)<<02)) )
#define RB_RDS(a) (*(volatile char*) (0x408B0000 + ((a && 0x003F)<<10)) )
#define RB_WRC(a,d) (*(volatile char*) (0x408A0000 + ((a && 0x003F)<<10)
+ ((d && 0x00FF)<<02)) )
#define RB_MERT(x) (*(volatile char*) (0x40892000 + ((x && 0xFFFF)<<02)) )
#define RB_SKIP1(n) (*(volatile char*) (0x40891C00 + ((x && 0xFFFF)<<02)) )
#define RB_SKIP0(n) (*(volatile char*) (0x40891800 + ((x && 0xFFFF)<<02)) )
#define RB_T8S(x) (*(volatile int*) (0x40891400 + ((x && 0xFFFF)<<02)) )
#define RB_T8(x) (*(volatile int*) (0x40891000 + ((x && 0xFFFF)<<02)) )
#define RB_RDRXRS (*(volatile int*) (0x40890C00 + ((x && 0xFFFF)<<02)) )
#define RB_RDRXR (*(volatile int*) (0x40890800 + ((x && 0xFFFF)<<02)) )
#define RB_WRMOSI(x) (*(volatile char*) (0x40890400 + ((x && 0x0001)<<02)) )
#define RB_MAGIC(x) (*(volatile char*) (0x40890000 + ((x && 0xFFFF)<<02)) )
#define SPI_GET_MISO(d) (d & 1)
void spi_select() {
ret = *SPI_CMD_SEL0;
ret = *SPI_CMD_SEL1;
ret = *SPI_CMD_SEL2;
ret = *SPI_CMD_SEL3;
}
void spi_deselect() {
ret = *SPI_CMD_DES0;
ret = *SPI_CMD_DES1;
ret = *SPI_CMD_DES2;
ret = *SPI_CMD_DES3;
}
void spi_tx_slow(char d) {
for (int i = 0; i < 8; i++) {
*SPI_CMD_BBA((0 & 0x02) | (d & 0x01));
*SPI_CMD_BBA((1 & 0x02) | (d & 0x01));
d >>= 1;
}
*SPI_CMD_BBA((0 & 0x02) | (0 & 0x01));
}
char spi_rx_slow() {
char ret = 0;
for (int i = 0; i < 8; i++) {
*SPI_CMD_BBA((0 & 0x02) | (1 & 0x01));
*SPI_CMD_BBA((1 & 0x02) | (1 & 0x01));
ret = (ret << 1) + (*SPI_CMD_BBA((1 & 0x02) | (1 & 0x01)) & 1);
}
return ret;
}
void spi_skip_slow(int n) {
while (n-- > 0) {
for (int i = 0; i < 8; i++) {
*SPI_CMD_BBA((0 & 0x02) | (1 & 0x01));
*SPI_CMD_BBA((1 & 0x02) | (1 & 0x01));
}
}
*SPI_CMD_BBA((0 & 0x02) | (1 & 0x01));
}
void spi_tx_8(char d) {
*SPI_CMD_SH8(d);
}
char spi_rx_8() {
*SPI_CMD_SH8(0xFF);
return *SPI_CMD_RD & 0xFF;
}
void spi_tx_16(int d) {
*SPI_CMD_SH16(d);
}
int spi_rx_16() {
*SPI_CMD_SH16(0xFFFF);
return *SPI_CMD_RD & 0xFFFF;
}
void spi_skip(int n) {
while (n-- > 0) {
for (int i = 0; i < 8; i++) {
*SPI_CMD_SH8(0xFF);
}
}
}

View File

@ -1,17 +0,0 @@
#ifndef SPI_H
#define SPI_H
void spi_select();
void spi_deselect();
void spi_tx_slow(char d);
char spi_rx_slow();
void spi_skip_slow(int n);
void spi_tx_8(char d);
char spi_rx_8();
void spi_tx_16(int d);
int spi_rx_16();
void spi_skip(int n);
#endif

View File

@ -1,11 +0,0 @@
#ifndef RDISK_H
#define RDISK_H
#pragma parameter xfer_s_256(__A0, __A1)
void xfer_s_256(Ptr srcreg, Ptr destmem);
#pragma parameter xfer_s(__D0, __A0, __A1)
void xfer_s(uint8_t numBytes, Ptr srcreg, Ptr destmem);
#endif

View File

@ -1,34 +0,0 @@
.macro xfer_in from, to
move.w (%A0), (%A1)+
nop
nop
nop
.if \to-\from
xfer_in "(\from+1)"
.else
.endif
.endm
;pragma parameter xfer_s_256(__A0, __A1)
;void xfer_s_256(Ptr srcreg, Ptr destmem);
xfer_256:
movem.l %D0/%A1-%A2, -(%SP)
xfer_256_loop:
xfer_s_in 0, 255
xfer_256_end:
movem.l (%SP)+, %D0/%A1-%A2
;pragma parameter xfer_s(__D0, __A0, __A1)
;void xfer_s(uint8_t numBytes, Ptr srcreg, Ptr destmem);
xfer:
movem.l %D0/%A1-%A2, -(%SP)
andi.l #0xFF, %D0
subi.l #256, %D0
neg.l %D0
lsl.l #2, %D0
addi.l #xfer_256, %D0
movea.l %D0, %A2
jmp %A2

23
priv_syscall.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef _PRIV_SYSCALL_H
#define _PRIV_SYSCALL_H
#include <Disks.h>
#include <OSUtils.h>
#pragma parameter __D0 PSReadXPRAM(__D0, __D1, __A0)
OSErr PSReadXPRAM(short numBytes, short whichByte, Ptr dest) = {0x4840, 0x3001, 0xA051};
#pragma parameter __D0 PSAddDrive(__D1, __D0, __A0)
OSErr PSAddDrive(short drvrRefNum, short drvNum, DrvQElPtr dq) = {0x4840, 0x3001, 0xA04E};
// Figure out the first available drive number >= 5
static int PSFindDrvNum() {
DrvQElPtr dq;
int drvNum = 5;
for (dq = (DrvQElPtr)(GetDrvQHdr())->qHead; dq; dq = (DrvQElPtr)dq->qLink) {
if (dq->dQDrive >= drvNum) { drvNum = dq->dQDrive + 1; }
}
return drvNum;
}
#endif

100
rdisk.c
View File

@ -1,100 +0,0 @@
#include <Memory.h>
#include <Devices.h>
#include <Files.h>
#include <Disks.h>
#include <Errors.h>
#include <Events.h>
#include <OSUtils.h>
#include <Quickdraw.h>
#include "rombus.h"
#include "rdisk.h"
OSErr RDOpen(IOParamPtr p, DCtlPtr d, RBStorage_t *c) {
// Find first available drive number for ROM drive
drvNum = RBFindDrvNum();
// Set ROM drive status
c->rdStatus.track = 0;
c->rdStatus.writeProt = -1; // nonzero is write protected
c->rdStatus.diskInPlace = 8; // 8 is nonejectable disk
c->rdStatus.installed = 1; // drive installed
c->rdStatus.sides = 0;
c->rdStatus.qType = 0;
c->rdStatus.dQDrive = drvNum;
c->rdStatus.dQFSID = 0;
c->rdStatus.dQRefNum = d->dCtlRefNum;
c->rdStatus.driveSize = RDiskSize / 512;
//c->rdStatus.driveS1 = (RDiskSize / 512) >> 16;
// Decompress ROM disk icon
src = &RDiskIconCompressed[0];
dst = &c->rdIcon[0];