home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
programs
/
disk
/
misc
/
tracked
/
source.lha
/
sources
/
SupRout.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
7KB
|
328 lines
/* SupRout.c Support routines for main loop */
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <libraries/gadtools.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
extern struct Window *Window;
extern struct RastPort *RPort;
extern UBYTE *BB;
extern UBYTE CursorX, CursorY, OldCursorX, OldCursorY, RealCursorY;
extern int drive, lastdrive;
extern ULONG CurBlock;
UBYTE TDErrText[] = "Trackdisk error ";
UBYTE *TD_Error_Txt[] =
{
"Not specified",
"No sector header",
"Bad sector preamble",
"Bad sector",
"Bad header checksum",
"Bad sector checksum",
"Too few sectors",
"Bad sector header",
"Write protected",
"Disk changed",
"Seek error",
"Not enough memory",
"Bad unit number",
"Bad drive type",
"Drive in use",
"Post reset"
};
extern struct IntuiText Cursor, TestText, TestText2;
#define FourDigs 5
#define TwoDigs 3
extern UBYTE TrackBuffer[], SectorBuffer[], BlockBuffer[];
extern struct Border FourBorder, FourBorderInv, BoxBorder, TitleBorder,
DrivesBorder;
extern struct PropInfo Schuif_info;
extern struct StringInfo Track_info, Sector_info, Block_info;
#define g_DF0 1
#define g_DF1 2
#define g_DF2 3
#define g_DF3 4
#define g_Track 5
#define g_Sector 6
#define g_Block 7
#define g_Schuif 8
#define g_TrUp 9
#define g_TrDown 10
#define g_SeUp 11
#define g_SeDown 12
#define g_BlUp 13
#define g_BlDown 14
extern struct Gadget SchuifGadget, BlDownGadget, BlUpGadget, SeDownGadget,
SeUpGadget, TrDownGadget, TrUpGadget, BlockGadget,
SectorGadget, TrackGadget, DF3Gadget, DF2Gadget,
DF1Gadget, DF0Gadget;
extern struct Gadget *DriveGadgets[];
extern struct NewWindow NewWindow;
struct Requester *BlockInput(window)
struct Window *window;
{
struct Requester *req;
req = (struct Requester *) AllocMem(sizeof(struct Requester), MEMF_PUBLIC);
if (req)
{
InitRequester(req);
Request(req, window);
return(req);
}
else return(NULL);
}
void UnBlockInput(req, window)
struct Requester *req;
struct Window *window;
{
if (req)
{
EndRequest(req, window);
FreeMem(req, sizeof(struct Requester));
}
}
void ProcessTDError(error)
int error;
{
UBYTE *ErrExpl;
if (error != 0)
{
TDErrText[18] = TDErrText[19] = ' ';
sprintf(&TDErrText[16], "%d", error);
if ((error >= 20) && (error <= 35)) ErrExpl = TD_Error_Txt[error - 20];
else ErrExpl = "Unknown error";
ShowText2(Window, TDErrText, ErrExpl, NULL);
}
}
UBYTE CXPos(x)
UBYTE x;
{
UBYTE RX;
if (x < 32) RX = 5 + 3*(x/2) + (x % 2);
else RX = 55 + (x - 32);
return(RX);
}
void UpDateCursor()
{
if ((CursorX != OldCursorX) || (CursorY != OldCursorY))
{
if (OldCursorX < 128)
PrintIText(RPort, &Cursor, CXPos(OldCursorX)*8+23L, OldCursorY*8+18L);
PrintIText(RPort, &Cursor, CXPos(CursorX)*8+23L, CursorY*8+18L);
OldCursorX = CursorX;
OldCursorY = CursorY;
}
}
void ByteToHex(byte, string)
UBYTE byte;
UBYTE *string;
{
UBYTE a;
a = (byte & 0xf0) >> 4;
if (a >= 10) a += 'A'-10;
else a += '0';
string[0] = a;
a = byte & 0x0f;
if (a >= 10) a += 'A'-10;
else a += '0';
string[1] = a;
}
void ShowLine(Memory, line, os)
UBYTE *Memory;
int line;
UWORD os;
{
int i;
UBYTE ch;
TestText.IText[0] = ((os+16*line) >> 8) + '0';
if (TestText.IText[0] > '9') TestText.IText[0] += 'A'-'0';
ByteToHex((UBYTE) os+16*line, &TestText.IText[1]);
for (i = 0; i < 16; i++)
{
ch = Memory[i+16*line];
ByteToHex(ch, &TestText.IText[5+3*i]);
if ((ch & 0x7f) < 32) ch = '.';
TestText2.IText[i] = ch;
}
PrintIText(RPort, &TestText, 23L, 8*line+18L);
}
void ShowBuffer(buffer, offset)
UBYTE *buffer;
UWORD offset;
{
int j;
for (j = 0; j < 16; j++) ShowLine(buffer, j, offset);
}
void UpDateSB()
{
ULONG L;
int i;
L = (ULONG) Schuif_info.VertPot*16 / 65535;
i = (int) L;
ShowBuffer(BB+16*i, 16*i);
RealCursorY = CursorY + (UWORD) L;
OldCursorX = 255;
UpDateCursor();
}
void UpDateBlockG()
{
Block_info.LongInt = Track_info.LongInt*11+Sector_info.LongInt;
sprintf(BlockBuffer, "%d\x00", Block_info.LongInt);
RefreshGList(&BlockGadget, Window, NULL, 1);
}
void UpDateTrSeG()
{
Track_info.LongInt = Block_info.LongInt / 11;
Sector_info.LongInt = Block_info.LongInt % 11;
sprintf(TrackBuffer, "%d\x00", Track_info.LongInt);
sprintf(SectorBuffer, "%d\x00", Sector_info.LongInt);
RefreshGList(&TrackGadget, Window, NULL, 1);
RefreshGList(&SectorGadget, Window, NULL, 1);
}
void CheckBlock()
{
int td_err;
if ((CurBlock != Block_info.LongInt) || (drive != lastdrive))
{
CurBlock = Block_info.LongInt;
lastdrive = drive;
td_err = ReadBlocks(drive, (WORD) CurBlock, 1, BB);
if (td_err) ProcessTDError(td_err);
UpDateSB();
}
}
void Cursor_Neer()
{
ULONG L;
if (RealCursorY < 31)
{
RealCursorY++;
if (CursorY < 15)
{
CursorY++;
UpDateCursor();
}
else
{
L = (ULONG) (RealCursorY - 14) * 65535 / 17;
NewModifyProp(&SchuifGadget, Window, NULL,
Schuif_info.Flags, 0, (UWORD) L, 0,
Schuif_info.VertBody, 1);
UpDateSB();
}
}
}
void Scroll_Rechts()
{
if ((CursorX < 47) && (CursorX != 31)) CursorX++;
else if (CursorX == 31)
{
if (RealCursorY < 31)
{
CursorX = 0;
Cursor_Neer();
}
}
else if (CursorX == 47)
{
if (RealCursorY < 31)
{
CursorX = 32;
Cursor_Neer();
}
}
UpDateCursor();
}
BYTE Hexcode(ch)
UBYTE ch;
{
UBYTE rch;
if ((ch >= '0') && (ch <= '9')) rch = ch - '0';
else if ((ch >= 'A') && (ch <= 'F')) rch = ch - 'A' + 10;
else if ((ch >= 'a') && (ch <= 'f')) rch = ch - 'a' + 10;
else rch = -1;
return(rch);
}
void Process_VKey(key)
UBYTE key;
{
if ((key >= 32) && (key <= 127))
{
if (CursorX >= 32)
{
BB[CursorX-32 + 16*RealCursorY] = key;
ShowLine(BB + (RealCursorY-CursorY)*16, CursorY,
(RealCursorY-CursorY)*16);
OldCursorX = 255;
Scroll_Rechts();
}
else
{
if (Hexcode(key) >= 0)
{
if (CursorX % 2 == 0) BB[CursorX/2 + 16*RealCursorY] =
BB[CursorX/2 + 16*RealCursorY] & 0x0f | 16*Hexcode(key);
else BB[CursorX/2 + 16*RealCursorY] =
BB[CursorX/2 + 16*RealCursorY] & 0xf0 | Hexcode(key);
ShowLine(BB + (RealCursorY-CursorY)*16, CursorY,
(RealCursorY-CursorY)*16);
OldCursorX = 255;
Scroll_Rechts();
}
}
}
}
void Process_MPos(MuisX, MuisY)
WORD MuisX, MuisY;
{
UBYTE CX;
if (MuisX >= 50) CX = MuisX - 50 + 32;
else if (MuisX <= 47) CX = (MuisX/3)*2 + MuisX % 3;
else CX = 32;
CursorX = CX;
CursorY = MuisY;
RealCursorY += MuisY - OldCursorY;
UpDateCursor();
}