-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHRTmonPrefs.c
488 lines (358 loc) · 10.5 KB
/
HRTmonPrefs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/*********************************/
/* HRTmon preferences and loader */
/* by Hornet of Alcatraz */
/* Alain Malek */
/*********************************/
/*
This was my first C program, that's why it is so badly coded ...
Maybe the whole HRTmonPrefs program should be recoded from scratch
*/
// compiled with DICE
// dcc HRTmonPrefs.c HRTmonGUI.o assembler.o HRTboot.o HRTmonLoad.o reqtoolss.lib
#include "HRTmonLoad.h"
#include "HRTmonGUI2.h"
#include "assembler.h"
#define nb_sectors 300 // nb sectors to write for boot-disk
__far extern int BootBlock[];
#include <devices/trackdisk.h>
#include <dos/dos.h>
#include <libraries/reqtools.h>
#include <proto/reqtools.h>
/*******************************************************************/
struct IntuitionBase *IntuitionBase;
struct Library *GadToolsBase;
struct ReqToolsBase *ReqToolsBase;
int ShowReq(char *text,char*choice); // Show EZRequest. from reqtools
int WriteSec(void * Buffer,int Offset,int Len);
/*******************************************************************/
int main()
{
GadToolsBase = OpenLibrary ("gadtools.library", 37);
IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 37);
ReqToolsBase = (struct ReqToolsBase *) OpenLibrary (REQTOOLSNAME, REQTOOLSVERSION);
if (!GadToolsBase | !IntuitionBase | !ReqToolsBase) return 20;
LoadInit();
MainGTags[7]=(config.autoa & 1); // disable address field
MainGTags[10]=(config.abs & 1);
MainGTags[14]=(config.right & 1);
MainGTags[19]=config.keyboard;
MainGTags[22]=config.ide & 1;
MainGTags[25]=config.autoa & 1;
MainGTags[29]=config.key & 1;
MainGTags[32]=(config.insert & 1);
MainGTags[39]=config.delay;
MainGTags[52]=(config.lview & 1);
MainGTags[57]=config.screenmode;
MainGTags[60]=(config.vbr & 1);
MainGTags[63]=(config.hexmode & 1);
SetupScreen();
OpenMainWindow();
sprintf( ((struct StringInfo*) (MainGadgets[GD_address] -> SpecialInfo)) -> Buffer
,"$%x",config.address);
RefreshGList(MainGadgets[GD_address],MainWnd,NULL,1);
if ( RemHRTmon() )
ShowReq("HRTmon located\n"
"and removed.","OK");
do
WaitPort( MainWnd->UserPort );
while ( HandleMainIDCMP() );
CloseMainWindow();
CloseDownScreen();
CloseLibrary(GadToolsBase);
CloseLibrary((struct Library *)IntuitionBase);
CloseLibrary((struct Library *)ReqToolsBase);
return 0;
}
/*******************************************************************/
int ShowReq(char *text,char*choice)
{
struct TagItem myTags[4]={
RT_Window,(int)MainWnd,
RT_LockWindow,TRUE, // show busy pointer on parent window
RTEZ_ReqTitle,(int)"HRTmon requester",
TAG_DONE
};
return rtEZRequestA (text,choice,NULL,NULL,myTags);
}
/*******************************************************************/
int MainCloseWindow ()
{
return (FALSE);
}
/*******************************************************************/
// Menu save
int MainSave()
{
BPTR cf1,cf2;
BPTR lock;
memset(config.path, 0, 512);
if ( !(cf1=Open("ENV:HRTmon.prefs",MODE_NEWFILE)) ) {
ShowReq("Couldn't save prefs.","OK");
return (TRUE);
}
if ( !(cf2=Open("ENVARC:HRTmon.prefs",MODE_NEWFILE)) ) {
ShowReq("Couldn't save prefs.","OK");
Close (cf1);
return (TRUE);
}
lock = GetProgramDir();
if (lock)
NameFromLock(lock, config.path, 510);
Write(cf1, &config, sizeof(CONFIG));
Write(cf2, &config, sizeof(CONFIG));
Close(cf1);
Close(cf2);
return (TRUE);
}
/*******************************************************************/
// Menu quit
int MainQuit()
{
return (FALSE);
}
/*******************************************************************/
int RightClicked()
{
config.right = !config.right;
return (TRUE);
}
/*******************************************************************/
int BootDiskClicked()
{
char *Buffer;
BPTR filelock,filehandle;
struct FileInfoBlock infoblock;
char EmptyBlock[512];
int i;
int autoaddr;
if (config.autoa)
autoaddr = 0;
else
autoaddr = config.address;
if ( ! (filelock=Lock("HRTmon.data",ACCESS_READ)) ) { // Lock file
ShowReq("Can't open file HRTmon.data","OK");
return (TRUE);
}
if ( Examine(filelock,&infoblock) == FALSE ) { // Examine file
ShowReq("Can't open file HRTmon.data","OK");
UnLock(filelock);
return (TRUE);
}
UnLock(filelock); // UnLock file
if ( (Buffer=AllocMem(infoblock.fib_Size,MEMF_ANY)) == NULL ) {
ShowReq("Not enough memory to proceed.","OK");
return (TRUE);
}
if ( filehandle=Open("HRTmon.data",MODE_OLDFILE) ) {
Read(filehandle,Buffer,infoblock.fib_Size); // Read file
Close(filehandle);
}
else { // if Can't Open
ShowReq("Can't open file HRTmon.data","OK");
return (TRUE);
}
if ( LoadABS((APTR)Buffer,&autoaddr) == FALSE ) {
FreeMem(Buffer,infoblock.fib_Size);
return (TRUE);
}
FreeMem(Buffer,infoblock.fib_Size);
// **** End of loading of HRTmon to 'address' *************
// **** Now we will make the boot-disk ! ******************
if (!Inhibit("DF0:",DOSTRUE)) {
ShowReq("Couldn't allocate DF0:","OK");
if (config.abs || config.autoa)
FreeMem( (APTR)autoaddr, ((ULONG*)autoaddr)[5] );
return (TRUE); //Cancel clicked
}
if ( !ShowReq("Insert a formatted floppy disk in df0:\n"
"Warning ! The disk will be erased.","OK|Cancel") ) {
if (config.abs || config.autoa)
FreeMem( (APTR)autoaddr, ((ULONG*)autoaddr)[5] );
Inhibit("DF0:",FALSE);
return (TRUE); //Cancel clicked
}
if ( !WriteSec((APTR)autoaddr,2,nb_sectors) ) {
if (config.abs || config.autoa)
FreeMem( (APTR)autoaddr, ((ULONG*)autoaddr)[5] );
ShowReq("Couldn't write to disk !","OK");
Inhibit("DF0:",FALSE);
return (TRUE);
}
if (config.abs || config.autoa)
FreeMem( (APTR)autoaddr, ((ULONG*)autoaddr)[5] );
BootBlock[2]=autoaddr; // Load address for monitor
BootBlock[1]=0; // clear checksum
BootBlock[1]=BootSum(BootBlock);
WriteSec(BootBlock,0,2);
for (i=0;i<512;i++)
EmptyBlock[i]=0;
WriteSec(EmptyBlock,880,1);
Inhibit("DF0:",FALSE);
ShowReq ("HRTmon Boot-Disk\n"
"succesfully installed.","OK");
return (TRUE);
}
/*******************************************************************/
int InstallClicked()
{
return Load("");
}
/*******************************************************************/
int WriteSec(void * Buffer,int Offset,int Len) { // Offset and Len in sector
static struct IOExtTD diskio;
static struct MsgPort replyport;
char *clear;
int i,result;
memset(&diskio,0,sizeof(struct IOExtTD));
memset(&replyport,0,sizeof(struct MsgPort));
replyport.mp_SigTask=FindTask( NULL );
AddPort(&replyport);
if (OpenDevice(TD_NAME,0,(struct IORequest*)&diskio,0)) {
ShowReq("Couldn't open trackdisk.device !","OK");
RemPort(&replyport);
return (FALSE);
}
diskio.iotd_Req.io_Message.mn_ReplyPort=&replyport;
diskio.iotd_Req.io_Command=CMD_WRITE;
diskio.iotd_Req.io_Data=Buffer;
diskio.iotd_Req.io_Offset=Offset*512;
diskio.iotd_Req.io_Length=Len*512;
if ( DoIO((struct IORequest*)&diskio) )
result=FALSE;
else
result=TRUE;
diskio.iotd_Req.io_Command=CMD_UPDATE;
diskio.iotd_Req.io_Data=NULL;
diskio.iotd_Req.io_Offset=0;
diskio.iotd_Req.io_Length=0;
DoIO((struct IORequest*)&diskio);
diskio.iotd_Req.io_Command=9; // Switch motor OFF
diskio.iotd_Req.io_Data=NULL;
diskio.iotd_Req.io_Offset=0;
diskio.iotd_Req.io_Length=0;
DoIO((struct IORequest*)&diskio);
CloseDevice((struct IORequest*)&diskio);
RemPort(&replyport);
return (result);
}
/*******************************************************************/
int CancelClicked()
{
return (FALSE);
}
/*******************************************************************/
int addressClicked()
{
char *my_string,*p;
int val=0;
my_string=((struct StringInfo*) (MainGadgets[GD_address] -> SpecialInfo)) -> Buffer;
if (*my_string != '$') {
sprintf(my_string,"$%x",config.address);
RefreshGList(MainGadgets[GD_address],MainWnd,NULL,1);
ShowReq("address must start with '$'","OK");
return (TRUE);
}
/* convert string in hex and check if really in hex */
for (p=my_string+1 ; *p != 0 ; p++) {
val=val*16;
if (*p>='0' && *p<='9')
val=val+(*p-'0');
else
if (*p>='a' && *p<='f')
val=val+(*p-'a'+10);
else
if (*p>='A' && *p<='F')
val=val+(*p-'A'+10);
else {
sprintf(my_string,"$%x",config.address);
RefreshGList(MainGadgets[GD_address],MainWnd,NULL,1);
ShowReq("Not an hex number !","OK");
return(TRUE);
}
}
if ( val & 0xf ) {
sprintf(my_string,"$%x",config.address);
RefreshGList(MainGadgets[GD_address],MainWnd,NULL,1);
ShowReq("Not a multiple of 16 !","OK");
return(TRUE);
}
config.address=val;
return (TRUE);
}
/*******************************************************************/
int AllocAbsClicked()
{
config.abs=!config.abs;
return (TRUE);
}
/*******************************************************************/
int VBRClicked()
{
config.vbr=!config.vbr;
return (TRUE);
}
/*******************************************************************/
int hexmodeClicked()
{
config.hexmode=!config.hexmode;
return (TRUE);
}
/*******************************************************************/
int keyboardClicked()
{
config.keyboard = MainMsg.Code;
return (TRUE);
}
/*******************************************************************/
int screenmodeClicked()
{
config.screenmode = MainMsg.Code;
return (TRUE);
}
/*******************************************************************/
int SaveBClicked() {
return (MainSave());
}
/*******************************************************************/
int IDEClicked()
{
config.ide=!config.ide;
return (TRUE);
}
/*******************************************************************/
int InsertClicked()
{
config.insert=!config.insert;
return (TRUE);
}
/*******************************************************************/
int AutoAllocClicked()
{
config.autoa=!config.autoa;
if (config.autoa) {
(MainGadgets[GD_address] -> Flags) |= GFLG_DISABLED;
} else {
(MainGadgets[GD_address] -> Flags) &= (~GFLG_DISABLED);
}
RefreshGList(MainGadgets[GD_address],MainWnd,NULL,1);
return (TRUE);
}
/*******************************************************************/
int KeyClicked()
{
config.key=!config.key;
return (TRUE);
}
/*******************************************************************/
int repClicked()
{
config.delay = MainMsg.Code;
return (TRUE);
}
/*******************************************************************/
int LViewClicked()
{
config.lview = !config.lview;
return (TRUE);
}
/*******************************************************************/