static int _init_sd() { filesystem_present=0; if((sdcard_present=spi_init())) { printf("SD card successfully initialised\n"); filesystem_present=FindDrive(); } else printf("No SD card found\n"); return(filesystem_present); }
HRESULT OpenDiskOrVolumeOrFile(HANDLE & h, LPWSTR name, bool isRead, UINT64 * psize = nullptr) { DWORD desiredAccess = isRead ? GENERIC_READ : GENERIC_READ|GENERIC_WRITE; DWORD devFlags = isRead ? FILE_FLAG_NO_BUFFERING : FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH; DWORD fileCreation = isRead ? OPEN_EXISTING : CREATE_ALWAYS; auto v = FindVolume(name); if (v) { auto hr = v->Open(desiredAccess, devFlags, h); if (hr) return hr; if (psize) *psize = v->size; return 0; } auto d = FindDrive(name); if (d) { auto hr = d->Open(isRead, desiredAccess, devFlags, h); if (hr) return hr; if (psize) *psize = d->size; return 0; } auto p = FindPartition(name); if (p) { auto hr = p->Open(isRead, desiredAccess, devFlags, h); if (hr) return hr; if (psize) *psize = p->size; return 0; } h = CreateFile( name, desiredAccess, FILE_SHARE_READ, nullptr, fileCreation, FILE_FLAG_SEQUENTIAL_SCAN, nullptr); if (h==INVALID_HANDLE_VALUE) return GetLastError(); if (psize) { LARGE_INTEGER large; if (!GetFileSizeEx(h, &large)) return GetLastError(); *psize = large.QuadPart; } return 0; }
static int _init_sd() { filesystem_present=0; #ifdef DISABLE_FILESYSTEM printf("Filesystem disabled\n"); #else if((sdcard_present=spi_init())) { printf("SD card successfully initialised\n"); filesystem_present=FindDrive(); } else printf("No SD card found\n"); #endif return(filesystem_present); }
void main(void) { DEBUG_FUNC_IN(); fileTYPE ft; int i; // !!! a pointer to start of RAM unsigned char * ram = ((unsigned char *)0x400000); // initialize SD card LEDS(led=0xf); if (!MMC_Init()) FatalError(); // find drive LEDS(led=0x8); if (!FindDrive()) FatalError(); // open file LEDS(led=0x3); LoadFile(firmware,ram); #if 0 if (!FileOpen(&ft, firmware)) FatalError(); // load firmware to RAM LEDS(led=0x1); for(i=0; i<((ft.size>>9)+1); i++) { FileRead(&ft, ram+(i*512)); FileNextSector(&ft); } #endif // jump to RAM firmware LEDS(led=0x0); DisableCard(); sys_jump(0x400004); // loop forever while(1); DEBUG_FUNC_OUT(); }
static int Boot(enum boot_settings settings) { int result=0; int opened; OSD_Puts("Initializing SD card\n"); if(spi_init()) { int dipsw=GetDIPSwitch(); if(!FindDrive()) return(0); if(sd_ishc()) { OSD_Puts("SDHC not supported;"); OSD_Puts("\ndisabling SD card\n\x10 OK\n"); WaitEnter(); dipsw|=4; // Disable SD card. HW_HOST(HW_HOST_CTRL)=HW_HOST_CTRLF_RESET; // Put OCMSX into Reset again HW_HOST(HW_HOST_SW)=dipsw; SetDIPSwitch(dipsw); } else if(IsFat32()) { OSD_Puts("Fat32 not supported;"); OSD_Puts("\ndisabling SD card\n\x10 OK\n"); WaitEnter(); dipsw|=4; // Disable SD card. HW_HOST(HW_HOST_CTRL)=HW_HOST_CTRLF_RESET; // Put OCMSX into Reset again HW_HOST(HW_HOST_SW)=dipsw; SetDIPSwitch(dipsw); } HW_HOST(HW_HOST_CTRL)=HW_HOST_CTRLF_SDCARD; // Release reset but steal SD card if(opened=FileOpen(&file,"OCMSX CFG")) // Do we have a configuration file? { if(settings==BOOT_SAVESETTINGS) // If so, are we saving to it, or loading from it? { int i; int *p=(int *)sector_buffer; *p++=dipsw; *p++=GetVolumes(); *p++=GetMouseSettings(); for(i=0;i<125;++i) // Clear remainder of buffer *p++=0; FileWrite(&file,sector_buffer); } else if(settings==BOOT_LOADSETTINGS) { FileRead(&file,sector_buffer); dipsw=*(int *)(§or_buffer[0]); SetVolumes(*(int *)(§or_buffer[4])); SetMouseSettings(*(int *)(§or_buffer[8])); HW_HOST(HW_HOST_SW)=dipsw; SetDIPSwitch(dipsw); } // printf("DIP %d, Vol %d\n",dipsw,GetVolumes()); } OSD_Puts("Trying MSX3BIOS.SYS\n"); if(!(opened=FileOpen(&file,"MSX3BIOSSYS"))) // Try and load MSX3 BIOS first { OSD_Puts("Trying BIOS_M2P.ROM\n"); opened=FileOpen(&file,"BIOS_M2PROM"); // If failure, load MSX2 BIOS. } if(opened) { OSD_Puts("Loading BIOS\n"); int filesize=file.size; unsigned int c=0; int bits; bits=0; c=filesize; while(c) { ++bits; c>>=1; } bits-=9; while(filesize>0) { OSD_ProgressBar(c,bits); if(FileRead(&file,sector_buffer)) { int i; int *p=(int *)§or_buffer; for(i=0;i<(filesize<512 ? filesize : 512) ;i+=4) { int t=*p++; int t1=t&255; int t2=(t>>8)&255; int t3=(t>>16)&255; int t4=(t>>24)&255; HW_HOST(HW_HOST_BOOTDATA)=t4; HW_HOST(HW_HOST_BOOTDATA)=t3; HW_HOST(HW_HOST_BOOTDATA)=t2; HW_HOST(HW_HOST_BOOTDATA)=t1; } } else { OSD_Puts("Read failed\n"); return(0); } FileNextSector(&file); filesize-=512; ++c; } HW_HOST(HW_HOST_CTRL)=HW_HOST_CTRLF_BOOTDONE; // Release SD card and early-terminate any remaining requests for boot data return(1); }
int main(int argc,char **argv) { int i; HW_VGA(FRAMEBUFFERPTR)=0x00000; puts("Initializing SD card\n"); if(spi_init()) { puts("Hunting for partition\n"); FindDrive(); if(LoadFile("MANIFESTMST",Manifest)) { unsigned char *buffer=Manifest; int ptr; puts("Parsing manifest\n"); while(1) { unsigned char c=0; ptr=0; // Parse address while((c=*buffer++)!=' ') { HW_UART(REG_UART)=c; if(c=='#') // Comment line? break; if(c=='G') _boot(); if(c=='\n') _break(); // Halt CPU if(c=='L') buffer=Manifest; c=(c&~32)-('0'-32); // Convert to upper case if(c>='9') c-='A'-'0'; ptr<<=4; ptr|=c; } // Parse filename if(c!='#') { int i; while((c=*buffer++)==' ') ; --buffer; // c-1 is now the filename pointer // printf("Loading file %s to %d\n",fn,(long)ptr); // buffer[11]=0; LoadFile(buffer,(unsigned char *)ptr); HW_VGA(FRAMEBUFFERPTR)=ptr; } // Hunt for newline character while((c=*buffer++)!='\n') ; } } else { puts("Loading manifest failed\n"); } } puts("Returning\n"); return(0); }
__geta4 void main(void) #endif { DEBUG_FUNC_IN(); uint32_t spiclk; fileTYPE sd_boot_file; HideSplash(); SPI_fast(); // boot message draw_boot_logo(); BootPrintEx("**** MINIMIG-DE1 ****"); BootPrintEx("Minimig by Dennis van Weeren"); BootPrintEx("Updates by Jakub Bednarski, Tobias Gubener, Sascha Boing, A.M. Robinson & others"); BootPrintEx("DE1 port by Rok Krajnc ([email protected])"); BootPrintEx(" "); sprintf(s, "Build git commit: %s", __BUILD_REV); BootPrintEx(s); sprintf(s, "Build git tag: %s", __BUILD_TAG); BootPrintEx(s); BootPrintEx(" "); BootPrintEx("For updates & code see https://github.com/rkrajnc/minimig-de1"); BootPrintEx("For support, see http://www.minimig.net"); BootPrintEx(" "); printf("\r\r**** MINIMIG-DE1 ****\r\r"); printf("Minimig by Dennis van Weeren\r"); printf("Updates by Jakub Bednarski, Tobias Gubener, Sascha Boing, A.M. Robinson & others\r"); printf("DE1 port by Rok Krajnc ([email protected])\r\r"); printf("Build no. "); printf(__BUILD_NUM); //printf(" by "); //printf(__BUILD_USER); printf("\rgit commit "); printf(__BUILD_REV); printf("\rgit tag"); printf(__BUILD_TAG); printf("\r\r"); printf("For updates & code see https://github.com/rkrajnc/minimig-de1\r"); printf("For support, see http://www.minimig.net/\r\r"); spiclk = 100000 / (20*(read32(REG_SPI_DIV_ADR) + 2)); printf("SPI divider: %u\r", read32(REG_SPI_DIV_ADR)); sprintf(s, "SPI clock: %u.%uMHz", spiclk/100, spiclk%100); BootPrintEx(s); printf("%s\r", s); if (!MMC_Init()) FatalError(1); BootPrintEx("SD card found ..."); printf("SD card found ...\r"); if (!FindDrive()) FatalError(2); BootPrintEx("Drive found ..."); printf("Drive found ...\r"); ChangeDirectory(DIRECTORY_ROOT); //eject all disk df[0].status = 0; df[1].status = 0; df[2].status = 0; df[3].status = 0; BootPrintEx("Booting ..."); printf("Booting ...\r"); TIMER_wait(8000); config.kickstart.name[0]=0; SetConfigurationFilename(0); // Use default config LoadConfiguration(0); // Use slot-based config filename // main loop while (1) { HandleFpga(); HandleUI(); } DEBUG_FUNC_OUT(); }