Browse Source

Floppy drive can be used from any thread!

Stephen Downward 9 months ago
parent
commit
62abcdcd74
3 changed files with 45 additions and 30 deletions
  1. 32 25
      drivers/floppy.c
  2. 2 2
      drivers/floppy.h
  3. 11 3
      util/commands.c

+ 32 - 25
drivers/floppy.c

@ -47,7 +47,8 @@ u32 fl_tick = 0;
47 47
s8 floppy_ready = 1;
48 48
s8 floppy_queue = 0; //0 -> None, 1-> Read, 2-> Write
49 49
unsigned cyl_queue = 0;
50
void (callback_queue)(char, int);
50
char *data_queue = 0;
51
void (*callback_queue)(int);
51 52
52 53
//Reserve some memory for when we read data
53 54
//Can't cross a 64k boundary ):
@ -281,27 +282,34 @@ void floppy_loop() //Runs every 50 ms
281 282
282 283
void flp_main_func() //Has to be executed as a 'main' process, not by interrupts
283 284
{
284
	if(floppy_queue == 1)
285
	if(!floppy_ready)
285 286
	{
286
		//READ
287
		//todo: memory copy needed?
288
		int code = flp_do_track(cyl_queue, flp_dir_read);
289
		if(code == 0)
287
		if(floppy_queue == 1)
290 288
		{
291
			callback_queue(0, flp_dmabuf);
289
			//READ
290
			//todo: memory copy needed?
291
			int code = flp_do_track(cyl_queue, flp_dir_read);
292
			if(code == 0)
293
			{
294
				memory_copy((unsigned char*)&flp_dmabuf, (unsigned char*)data_queue, 0x4800);
295
				callback_queue(0);
296
			}
297
			else
298
			{
299
				callback_queue(code);
300
			}
301
			data_queue = 0; //Clear pointer
302
			floppy_ready = 1;
303
			floppy_queue = 0;
292 304
		}
293
		else
305
		else if(floppy_queue == 2)
294 306
		{
295
			callback_queue(code, NULL);
307
			//WRITE
308
			callback_queue(flp_do_track(cyl_queue, flp_dir_write));
309
			floppy_ready = 1;
310
			floppy_queue = 0;
296 311
		}
297 312
	}
298
	else if(floppy_queue == 2)
299
	{
300
		//WRITE
301
		callback_queue(flp_do_track(cyl_queue, flp_dir_write), NULL);
302
		floppy_ready = 1;
303
		floppy_queue = 2;
304
	}
305 313
}
306 314
307 315
int init_floppy()
@ -520,21 +528,20 @@ int flp_do_track(unsigned cyl, floppy_dir dir)
520 528
521 529
}
522 530
523
int floppy_read_track(unsigned cyl, char *data) //TODO: should call callback func
531
int floppy_read_track(unsigned cyl, char *data, void(*callback)(int response)) //TODO: should call callback func
524 532
{
525 533
	if(floppy_ready)
526 534
	{
527
		int code = flp_do_track(cyl, flp_dir_read);
528
		if (code == 0)
529
		{
530
			memory_copy((unsigned char*)&flp_dmabuf, (unsigned char*)data, 0x4800);
531
		}
532
		return code;
535
		floppy_ready = 0;
536
		floppy_queue = 1;
537
		cyl_queue = cyl;
538
		callback_queue = callback;
539
		data_queue = data;
533 540
	}
534 541
	return 27; //Data transfer already in progress
535 542
}
536 543
537
int floppy_write_track(unsigned cyl, char *data, void (callback)(int response, char data)) //TODO: should call callback func
544
int floppy_write_track(unsigned cyl, char *data, void (*callback)(int response))
538 545
{
539 546
	if(floppy_ready)
540 547
	{
@ -543,7 +550,7 @@ int floppy_write_track(unsigned cyl, char *data, void (callback)(int response, c
543 550
		floppy_queue = 2;
544 551
		cyl_queue = cyl;
545 552
		callback_queue = callback;
546
		return 0;//flp_do_track(cyl, flp_dir_write);
553
		return 0;
547 554
	}
548 555
	return 27; //Data transfer already in progress
549 556
}

+ 2 - 2
drivers/floppy.h

@ -16,8 +16,8 @@
16 16
int floppy_detect_drives();
17 17
int init_floppy();
18 18
19
int floppy_read_track(unsigned cyl, char *data);
20
int floppy_write_track(unsigned cyl, char *data, void (callback)(int, char));
19
int floppy_read_track(unsigned cyl, char *data, void (*callback)(int));
20
int floppy_write_track(unsigned cyl, char *data, void (*callback)(int));
21 21
22 22
void flp_main_func();
23 23

+ 11 - 3
util/commands.c

@ -101,12 +101,20 @@ void video_debug(char *args)
101 101
	}
102 102
	}*/
103 103
104
char buffer[0x4800];
105
106
void read_callback(int p)
107
{
108
	println(&buffer[0x3c47]);
109
	println("done");
110
	UNUSED(p);
111
}
112
104 113
void read_disk(char *args)
105 114
{
106 115
	UNUSED(args);
107
	char buffer[0x4800];
108
	floppy_read_track(3, buffer);
109
	println(buffer);
116
	
117
	floppy_read_track(1, buffer, read_callback);
110 118
}
111 119
112 120
void register_commands()