// Internet Downloader #include #include #include #include #include #include #include "conio.h" #include "downloader.h" #define redbus 0x0300 void download_file(char* file) { unsigned int i; unsigned int x; con->cursor_mode = 0; conprint("Downloading file, please wait warmly.", 0, 6); rb_map_device(0x05); memset(internet->url, 0, 50); strcpy(internet->url, buffer); internet->command = 1; while(internet->command == 1); if(internet->command == 0xFF){ conprint("Error in file download, please try again", 0, 7); } else { sectorcount = internet->sector_count; conprint(strcat(strcat("The file downloaded is of size ", itoa(sectorcount, 0, 10)), " Kilobytes"), 0, 7); conprint("Transferring data", 0, 8); for(i = 0; i <= sectorcount; ++i){ rb_map_device(0x05); internet->sector_num = i; memcpy(databuf, internet->webbuf, 128); rb_map_device(0x02); disk->sector_num = i; memcpy(disk->sector, databuf, 128); disk->command = (char)5; while(disk->command != 0x00 && disk->command != 0xFF); } conprint("Data transferred!", 0, 8); } } void main() { memset(buffer, 0, 50); memset(ynbuf, 0, 50); memset(databuf, 0, 50); internet = (Internet*)redbus; disk = (Disk*)redbus; con = (Console*)redbus; rb_set_window((void*)redbus); rb_enable(); conclear(); conprint("Internet Disk Retrieval System V1.3", 0, 0); conprint("Please remove disk now", 0, 1); conprint("Enter a URL to download from: ", 0, 2); con->cursor_y = 3; strcpy(buffer, read_keyboard()); conprint("You are trying to download a file from: ", 0, 3); conprint(buffer, 0, 4); con->cursor_x = 23; con->cursor_y = 5; conprint("Is this correct? (Y/N)", 0, 5); memset(ynbuf, 0, 50); strcpy(ynbuf, read_keyboard()); if(ynbuf[0] == 'Y' || ynbuf[0] == 'y') { download_file(buffer); } else{ conprint("Download cancelled", 0, 6); } }