Skip to content
Snippets Groups Projects
Commit 5a350ead authored by Stephen D's avatar Stephen D
Browse files

THIS CODE DOES NOT WORK, just committing it

parent b54472f8
No related branches found
No related tags found
No related merge requests found
......@@ -34,11 +34,28 @@ enum floppy_commands {
CMD_SEEK = 15, // SEEK
};
typedef enum {
flp_dir_read = 1,
flp_dir_write = 2
} floppy_dir;
s8 motor_tick = -1; //Decrements once every 50ms. If it's 40, it'll take 2s to reach 0.
s8 motor = 0;
u32 fl_tick = 0;
s8 floppy_ready = 1;
s8 floppy_queue = 0; //0 -> None, 1-> Read, 2-> Write
unsigned cyl_queue = 0;
void (callback_queue)(char, int);
//Reserve some memory for when we read data
//Can't cross a 64k boundary ):
#define flp_dmalen 0x4800
static const char flp_dmabuf[flp_dmalen] __attribute__((aligned(0x8000)));
int flp_do_track(unsigned cyl, floppy_dir dir);
int floppy_detect_drives()
{
......@@ -55,8 +72,7 @@ void lba_2_chs(u32 lba, u16* cyl, u16* head, u16* sector)
*sector = ((lba % (2 * SECTORS_PER_TRACK)) % SECTORS_PER_TRACK + 1);
}
//u8 motor_countdown = 3; //Time until motor is ready
//u8 motor_running = 0;
void motor_on(int drive) //0 to 3
{
motor_tick = 0;
......@@ -68,9 +84,6 @@ void motor_on(int drive) //0 to 3
//Wait
fl_delay(3);
//motor_countdown = 3;
//motor_running = 1;
}
......@@ -229,11 +242,6 @@ int flp_seek(s32 cyli, s8 head)
return -1;
}
typedef enum {
flp_dir_read = 1,
flp_dir_write = 2
} floppy_dir;
u8 flp_int = 0;
void floppy_int_callback(registers_t regs)
......@@ -270,6 +278,32 @@ void floppy_loop() //Runs every 50 ms
}
}
void flp_main_func() //Has to be executed as a 'main' process, not by interrupts
{
if(floppy_queue == 1)
{
//READ
//todo: memory copy needed?
int code = flp_do_track(cyl_queue, flp_dir_read);
if(code == 0)
{
callback_queue(0, flp_dmabuf);
}
else
{
callback_queue(code, NULL);
}
}
else if(floppy_queue == 2)
{
//WRITE
callback_queue(flp_do_track(cyl_queue, flp_dir_write), NULL);
floppy_ready = 1;
floppy_queue = 2;
}
}
int init_floppy()
{
......@@ -288,11 +322,6 @@ int init_floppy()
return 1;
}
//Reserve some memory for when we read data
//Can't cross a 64k boundary ):
#define flp_dmalen 0x4800
static const char flp_dmabuf[flp_dmalen] __attribute__((aligned(0x8000)));
static void flp_dma_init(floppy_dir dir)
{
union
......@@ -491,18 +520,30 @@ int flp_do_track(unsigned cyl, floppy_dir dir)
}
int floppy_read_track(unsigned cyl, char *data)
int floppy_read_track(unsigned cyl, char *data) //TODO: should call callback func
{
int code = flp_do_track(cyl, flp_dir_read);
if (code == 0)
if(floppy_ready)
{
memory_copy((unsigned char*)&flp_dmabuf, (unsigned char*)data, 0x4800);
int code = flp_do_track(cyl, flp_dir_read);
if (code == 0)
{
memory_copy((unsigned char*)&flp_dmabuf, (unsigned char*)data, 0x4800);
}
return code;
}
return code;
return 27; //Data transfer already in progress
}
int floppy_write_track(unsigned cyl, char *data)
int floppy_write_track(unsigned cyl, char *data, void (callback)(int response, char data)) //TODO: should call callback func
{
memory_copy((unsigned char*)data, (unsigned char*)&flp_dmabuf, 0x4800);
return flp_do_track(cyl, flp_dir_write);
if(floppy_ready)
{
memory_copy((unsigned char*)data, (unsigned char*)&flp_dmabuf, 0x4800);
floppy_ready = 0;
floppy_queue = 2;
cyl_queue = cyl;
callback_queue = callback;
return 0;//flp_do_track(cyl, flp_dir_write);
}
return 27; //Data transfer already in progress
}
......@@ -17,11 +17,8 @@ int floppy_detect_drives();
int init_floppy();
int floppy_read_track(unsigned cyl, char *data);
int floppy_write_track(unsigned cyl, char *data);
//Temporary, for debugging
void motor_on(int drive);
void motor_off();
int floppy_write_track(unsigned cyl, char *data, void (callback)(int, char));
void flp_main_func();
#endif
......@@ -50,13 +50,17 @@ void main() {
register_commands();
char buffer[0x4800];
//char str[] = ;
strcpy(buffer, "writing this to the floppy drive");//(unsigned char*)str);
/*char buffer[0x4800];
strcpy(buffer, "writing this to the floppy drive");
floppy_write_track(4, buffer);
println(buffer);
println(buffer);*/
/*register_loop(loop, 1000);*/ //Used when debugging loop
while(1)
{
//Runs everything that needs it
flp_main_func();
}
}
//Mandelbrot Generator
......
......@@ -89,7 +89,7 @@ void video_debug(char *args)
}
//DEBUGGING ONLY
void motor_control(char *args)
/*void motor_control(char *args)
{
if(args[0] == '0')
{
......@@ -99,7 +99,7 @@ void motor_control(char *args)
{
motor_on(0);
}
}
}*/
void read_disk(char *args)
{
......@@ -118,6 +118,6 @@ void register_commands()
register_command("halt", halt_cpu);
register_command("vinfo", video_debug);
register_command("edit", editor);
register_command("fm", motor_control);
/*register_command("fm", motor_control);*/
register_command("rd", read_disk);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment