BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
ritrackdisklib.c File Reference
#include "blitzlib.h"
#include "blitzexec.h"
#include <exec/io.h>
#include <exec/execbase.h>
#include <devices/trackdisk.h>
#include <devices/bootblock.h>

Macros

#define LVO_DoIO   (-456)
#define REQSIZE   200
#define NUMSECS   11
#define TRACKBYTES   (NUMSECS * 512)
#define ROOTBLOCK   880

Functions

void ritrackdisklib_libinit (void)
void ritrackdisklib_libfinit (void)
void opentrack (void)
void opentrack2 (void)
void motoron (void)
void closedisk (void)
void readsector1 (void)
void readsector2 (void)
void motoroff (void)
void writesector1 (void)
void writesector2 (void)
void formatsector1 (void)
void formatsector2 (void)
void install1 (void)
void install2 (void)
void iostatus (void)
void ioreq (void)
void bootprog (void)
void diskmotor (void)
static struct IOStdReq * getioreq (LONG unit)
static void putioreq (LONG unit, struct IOStdReq *req)
static struct MsgPort * newport (void)
static void freeport (struct MsgPort *mp)
static struct IOStdReq * newreq (void)
static void freereq (struct IOStdReq *req)
static ULONG doio (struct IOStdReq *req)
static void c_libinit (void)
 init: clear the request table and create the reply port.
ULONG c_motoroff (LONG unit)
 MotorOff unit#: write the track buffer to the disk (CMD_UPDATE), then switch the drive motor off (TD_MOTOR, length 0).
BB_BOOL c_closedisk (LONG unit)
 CloseDisk unit#: switch the motor off, close the device, free the request.
static void c_libfinit (void)
 finit: CloseDisk 0-3 and free the reply port.
static BB_BOOL opendisk (LONG unit, const char *name)
BB_BOOL c_opentrack (LONG unit)
 OpenDisk unit#: open trackdisk.device for a unit with a new request.
BB_BOOL c_opentrack2 (LONG unit, const char *name)
 OpenDisk unit#,devicename$: c_opentrack() with another device.
static ULONG trackpos (ULONG off)
static int needsbounce (const UBYTE *buffer, ULONG len, UWORD cmd)
static ULONG bounceio (struct IOStdReq *req, ULONG offset, UBYTE *buffer, ULONG len, UWORD cmd)
static ULONG sectorio (LONG unit, ULONG offset, APTR buffer, ULONG num, UWORD cmd)
ULONG c_readsector2 (LONG unit, ULONG sector, APTR buffer, ULONG num)
 ReadSector unit#,sector#,buffer,numsectors: read sectors (CMD_READ).
ULONG c_readsector1 (LONG unit, ULONG sector, APTR buffer)
 ReadSector unit#,sector#,buffer: read one sector.
ULONG c_writesector2 (LONG unit, ULONG sector, APTR buffer, ULONG num)
 WriteSector unit#,sector#,buffer,numsectors: write sectors (CMD_WRITE).
ULONG c_writesector1 (LONG unit, ULONG sector, APTR buffer)
 WriteSector unit#,sector#,buffer: write one sector.
ULONG c_formatsector2 (LONG unit, ULONG track, APTR buffer, ULONG num)
 FormatTrack unit#,track#,buffer,numsectors: format tracks (TD_FORMAT).
ULONG c_formatsector1 (LONG unit, ULONG track, APTR buffer)
 FormatTrack unit#,track#,buffer: format one track.
static void checksum (UBYTE *mem)
ULONG c_install1 (LONG unit)
 WriteBoot unit#: write a bootable standard boot block (sectors 0-1).
ULONG c_install2 (LONG unit, APTR buffer)
 WriteBoot unit#,bootdata: write 1024 bytes of bootdata to the boot block (sectors 0-1).
ULONG c_bootprog (LONG unit, UBYTE *mem)
 BootProg unit#,memoryaddress: make a boot block of 1024 bytes in memory bootable and write it.
ULONG c_iostatus (LONG unit)
 DiskStatus unit#: CheckIO of the unit's request.
ULONG c_ioreq (LONG unit)
 DiskIO unit#: the unit's IOStdReq.
ULONG c_motoron (LONG unit)
 MotorOn unit#: switch the drive motor on (TD_MOTOR, length 1).
ULONG c_diskmotor (void)
 DiskMotor: -1 if the motor of a unit the library has open is on, as the library knows it.

Variables

struct { 
   struct IOStdReq *   iorequests [4] 
   struct MsgPort *   msgport 
   UBYTE   motor [4] 
} td
static const UBYTE bootcode []

Macro Definition Documentation

◆ LVO_DoIO

#define LVO_DoIO   (-456)

◆ NUMSECS

#define NUMSECS   11

◆ REQSIZE

#define REQSIZE   200

◆ ROOTBLOCK

#define ROOTBLOCK   880

◆ TRACKBYTES

#define TRACKBYTES   (NUMSECS * 512)

Function Documentation

◆ bootprog()

void bootprog ( void )

◆ bounceio()

ULONG bounceio ( struct IOStdReq * req,
ULONG offset,
UBYTE * buffer,
ULONG len,
UWORD cmd )
static

◆ c_bootprog()

ULONG c_bootprog ( LONG unit,
UBYTE * mem )

BootProg unit#,memoryaddress: make a boot block of 1024 bytes in memory bootable and write it.

Writes "DOS",0, the root block long 0 and the checksum (checksum()), then sectors 0-1 (WriteSector). Fixed (#856): the checksum of the block as Kickstart checks it (the original stored the plain sum with carry including the old checksum long, and cleared the root block long after the sum).

Parameters
unitd0: unit# (0-3)
memd1: the boot block (1024 bytes)
Returns
d0: as c_writesector2(), 0 without port

◆ c_closedisk()

BB_BOOL c_closedisk ( LONG unit)

CloseDisk unit#: switch the motor off, close the device, free the request.

Parameters
unitd0: unit# (0-3)
Returns
d0: BB_TRUE if the unit was open, else BB_FALSE

◆ c_diskmotor()

ULONG c_diskmotor ( void )

DiskMotor: -1 if the motor of a unit the library has open is on, as the library knows it.

Fixed (#857): the state is the library's own knowledge: on after a MotorOn or a ReadSector, WriteSector, FormatTrack, WriteBoot or BootProg that worked (trackdisk.device switches the motor on for them and leaves it on), off after a MotorOff that worked and after CloseDisk. What other programs do with the drives is not seen. The original returned SNE of bit 7 of CIAB PRB ($BFD100, /MTR), which trackdisk.device leaves 1 after every request (it deselects the drives): always -1.

Returns
d0: $FF (-1) if a unit's motor is on, else 0 (a byte result)

◆ c_formatsector1()

ULONG c_formatsector1 ( LONG unit,
ULONG track,
APTR buffer )

FormatTrack unit#,track#,buffer: format one track.

Fixed (#858): 11 sectors (5632 bytes), one track of a DD disk; the original asked for 1 sector, which trackdisk.device refuses (-4).

Parameters
unitd0: unit# (0-3)
trackd1: the track
bufferd2: the data (5632 bytes)
Returns
d0: as c_formatsector2()

◆ c_formatsector2()

ULONG c_formatsector2 ( LONG unit,
ULONG track,
APTR buffer,
ULONG num )

FormatTrack unit#,track#,buffer,numsectors: format tracks (TD_FORMAT).

The first sector is track * 11 (MULU.w: the low word of the track), the length numsectors * 512, as in the original: the count is in sectors, though the declaration calls it numtracks. trackdisk.device formats whole tracks only (5632 bytes = 11 sectors on a DD disk) and refuses another length with -4 (IOERR_BADLENGTH): 11 formats one track, 22 two (#858, decided: the count stays in sectors).

Parameters
unitd0: unit# (0-3)
trackd1: the first track
bufferd2: the data (numsectors * 512 bytes)
numd3: the number of sectors (a multiple of 11)
Returns
d0: the result of the sector and motor commands (#1155): DoIO's d0 with io_Error as its low byte, so the byte is 0 when the request worked and the trackdisk.device error otherwise (28 write protected, 29 no disk, -4 a length the device refuses, ...); 0 also when the unit is not open or there is no reply port, so 0 does not tell "done" from "not open" (unlike OpenDisk, whose -1 is success)

◆ c_install1()

ULONG c_install1 ( LONG unit)

WriteBoot unit#: write a bootable standard boot block (sectors 0-1).

Fixed (#865): reads sectors 0-1 first and keeps the flag byte of the disk's boot block (byte 3, the file system: 0 OFS, 1 FFS, ...) if it starts with "DOS", else 0; then writes "DOS" and that byte, root block 880, the boot code above and the checksum (checksum()). The buffer is chip memory (1024 bytes, freed again). The original wrote its 8 byte block ("DOS",0, -1) and the 1016 bytes behind it. Fixed (#858): with CMD_WRITE (the original's TD_FORMAT of 1024 bytes was refused).

Parameters
unitd0: unit# (0-3)
Returns
d0: as c_writesector2(); 0 without port or request, TDERR_NoMem (31) without chip memory for the buffer

◆ c_install2()

ULONG c_install2 ( LONG unit,
APTR buffer )

WriteBoot unit#,bootdata: write 1024 bytes of bootdata to the boot block (sectors 0-1).

The block is written as it is (no checksum: BootProg makes one). Fixed (#864): from bootdata (the original set d1 = 0, the sector, over bootdata and wrote from the caller's d2, which is no argument). Fixed (#858): with CMD_WRITE (the original's TD_FORMAT of 1024 bytes was refused).

Parameters
unitd0: unit# (0-3)
bufferd1: bootdata, 1024 bytes
Returns
d0: as c_writesector2()

◆ c_ioreq()

ULONG c_ioreq ( LONG unit)

DiskIO unit#: the unit's IOStdReq.

Parameters
unitd0: unit# (0-3)
Returns
d0: the request, 0 without port or request

◆ c_iostatus()

ULONG c_iostatus ( LONG unit)

DiskStatus unit#: CheckIO of the unit's request.

Parameters
unitd0: unit# (0-3)
Returns
d0: CheckIO's result (the request if it is done, else 0), 0 without port or request

◆ c_libfinit()

void c_libfinit ( void )
static

finit: CloseDisk 0-3 and free the reply port.

Fixed (#863): unit 3 too (the original closed 0-2 only).

◆ c_libinit()

void c_libinit ( void )
static

init: clear the request table and create the reply port.

Fixed (#863): all four entries (the original cleared 0-2 only). Without a port (msgport 0) every command returns 0.

◆ c_motoroff()

ULONG c_motoroff ( LONG unit)

MotorOff unit#: write the track buffer to the disk (CMD_UPDATE), then switch the drive motor off (TD_MOTOR, length 0).

Fixed (#1154): CMD_UPDATE first (the original only switched the motor off: the last track written stayed in trackdisk.device's buffer). Its result is not looked at; the motor goes off in any case. CloseDisk and finit switch the motor off through this routine.

Parameters
unitd0: unit# (0-3)
Returns
d0: the result of the sector and motor commands (#1155): DoIO's d0 with io_Error as its low byte, so the byte is 0 when the request worked and the trackdisk.device error otherwise (28 write protected, 29 no disk, -4 a length the device refuses, ...); 0 also when the unit is not open or there is no reply port, so 0 does not tell "done" from "not open" (unlike OpenDisk, whose -1 is success)

◆ c_motoron()

ULONG c_motoron ( LONG unit)

MotorOn unit#: switch the drive motor on (TD_MOTOR, length 1).

Parameters
unitd0: unit# (0-3)
Returns
d0: the result of the sector and motor commands (#1155): DoIO's d0 with io_Error as its low byte, so the byte is 0 when the request worked and the trackdisk.device error otherwise (28 write protected, 29 no disk, -4 a length the device refuses, ...); 0 also when the unit is not open or there is no reply port, so 0 does not tell "done" from "not open" (unlike OpenDisk, whose -1 is success)

◆ c_opentrack()

BB_BOOL c_opentrack ( LONG unit)

OpenDisk unit#: open trackdisk.device for a unit with a new request.

A new request (newreq(), 200 bytes) on the reply port, then OpenDevice of "trackdisk.device". Fixed (#859): always trackdisk.device (the original opened the device of the last OpenDisk unit,name$). A unit that is open, or outside 0-3, gives 0 (#862, #861).

Parameters
unitd0: unit# (0-3)
Returns
d0: BB_TRUE if the device opened, else BB_FALSE

◆ c_opentrack2()

BB_BOOL c_opentrack2 ( LONG unit,
const char * name )

OpenDisk unit#,devicename$: c_opentrack() with another device.

Fixed (#860, #859): the name goes to OpenDevice as it is (the original copied it into a buffer of 58 bytes without a limit, a longer name overwrote the request table and the port, and kept it for later OpenDisks without a name).

Parameters
unitd0: unit# (0-3)
named1: the device name
Returns
d0: as c_opentrack()

◆ c_readsector1()

ULONG c_readsector1 ( LONG unit,
ULONG sector,
APTR buffer )

ReadSector unit#,sector#,buffer: read one sector.

Parameters
unitd0: unit# (0-3)
sectord1: the sector
bufferd2: the buffer
Returns
d0: as c_readsector2()

◆ c_readsector2()

ULONG c_readsector2 ( LONG unit,
ULONG sector,
APTR buffer,
ULONG num )

ReadSector unit#,sector#,buffer,numsectors: read sectors (CMD_READ).

Offset sector# * 512, length numsectors * 512.

Parameters
unitd0: unit# (0-3)
sectord1: the first sector
bufferd2: the buffer
numd3: the number of sectors
Returns
d0: the result of the sector and motor commands (#1155): DoIO's d0 with io_Error as its low byte, so the byte is 0 when the request worked and the trackdisk.device error otherwise (28 write protected, 29 no disk, -4 a length the device refuses, ...); 0 also when the unit is not open or there is no reply port, so 0 does not tell "done" from "not open" (unlike OpenDisk, whose -1 is success)

◆ c_writesector1()

ULONG c_writesector1 ( LONG unit,
ULONG sector,
APTR buffer )

WriteSector unit#,sector#,buffer: write one sector.

Parameters
unitd0: unit# (0-3)
sectord1: the sector
bufferd2: the data
Returns
d0: as c_writesector2()

◆ c_writesector2()

ULONG c_writesector2 ( LONG unit,
ULONG sector,
APTR buffer,
ULONG num )

WriteSector unit#,sector#,buffer,numsectors: write sectors (CMD_WRITE).

Parameters
unitd0: unit# (0-3)
sectord1: the first sector
bufferd2: the data
numd3: the number of sectors
Returns
d0: the result of the sector and motor commands (#1155): DoIO's d0 with io_Error as its low byte, so the byte is 0 when the request worked and the trackdisk.device error otherwise (28 write protected, 29 no disk, -4 a length the device refuses, ...); 0 also when the unit is not open or there is no reply port, so 0 does not tell "done" from "not open" (unlike OpenDisk, whose -1 is success)

◆ checksum()

void checksum ( UBYTE * mem)
static

◆ closedisk()

void closedisk ( void )

◆ diskmotor()

void diskmotor ( void )

◆ doio()

ULONG doio ( struct IOStdReq * req)
static

◆ formatsector1()

void formatsector1 ( void )

◆ formatsector2()

void formatsector2 ( void )

◆ freeport()

void freeport ( struct MsgPort * mp)
static

◆ freereq()

void freereq ( struct IOStdReq * req)
static

◆ getioreq()

struct IOStdReq * getioreq ( LONG unit)
static

◆ install1()

void install1 ( void )

◆ install2()

void install2 ( void )

◆ ioreq()

void ioreq ( void )

◆ iostatus()

void iostatus ( void )

◆ motoroff()

void motoroff ( void )

◆ motoron()

void motoron ( void )

◆ needsbounce()

int needsbounce ( const UBYTE * buffer,
ULONG len,
UWORD cmd )
static

◆ newport()

struct MsgPort * newport ( void )
static

◆ newreq()

struct IOStdReq * newreq ( void )
static

◆ opendisk()

BB_BOOL opendisk ( LONG unit,
const char * name )
static

◆ opentrack()

void opentrack ( void )

◆ opentrack2()

void opentrack2 ( void )

◆ putioreq()

void putioreq ( LONG unit,
struct IOStdReq * req )
static

◆ readsector1()

void readsector1 ( void )

◆ readsector2()

void readsector2 ( void )

◆ ritrackdisklib_libfinit()

void ritrackdisklib_libfinit ( void )

◆ ritrackdisklib_libinit()

void ritrackdisklib_libinit ( void )

◆ sectorio()

ULONG sectorio ( LONG unit,
ULONG offset,
APTR buffer,
ULONG num,
UWORD cmd )
static

◆ trackpos()

ULONG trackpos ( ULONG off)
static

◆ writesector1()

void writesector1 ( void )

◆ writesector2()

void writesector2 ( void )

Variable Documentation

◆ bootcode

const UBYTE bootcode[]
static
Initial value:
= {
0x43, 0xfa, 0x00, 0x18, 0x4e, 0xae, 0xff, 0xa0, 0x4a, 0x80, 0x67, 0x0a,
0x20, 0x40, 0x20, 0x68, 0x00, 0x16, 0x70, 0x00, 0x4e, 0x75, 0x70, 0xff,
0x4e, 0x75, 'd', 'o', 's', '.', 'l', 'i', 'b', 'r', 'a', 'r', 'y', 0
}

◆ iorequests

struct IOStdReq* iorequests[4]

◆ motor

UBYTE motor[4]

◆ msgport

struct MsgPort* msgport

◆ [struct]

struct { ... } td