mam OS robeny v C a mam s nim 1 problem s otvorenim exernej .exe aplikacie....ked ju spustim tak mi zamrzne cely OS...toto je funkcia na otvorenie tej aplikacie kde je chyba???
#ifndef _EXEC_INCLUDED_
#define _EXEC_INCLUDED_
#include <fat.h>
#include <disk.h>
#include <malloc.h>
#include <printf.h>
#define seg 0x2000 /* segment, kam se program nahraje :) */
#define far_seg 0x20000000 /* far segment, (seg << 16) */
/*
* exec()
* najde na disku soubor <filename>, pokud ho najde
* zjisti, jestli to je soubor a ne treba slozka,
* pokud to je soubor, nahreje ho do pameti na adresu
* seg:0000 a provede call na toto misto
*
* navratove hodnoty:
* 0 - program spusten
* 1 - program nenalezen
*/
int exec(char *filename) {
unsigned int t;
unsigned int cluster;
unsigned int sp_zaloha;
unsigned int ds_zaloha;
char *dummy = (char*)0x0000;
int i=0;
DirectoryEntry *file = malloc(sizeof(DirectoryEntry));
while((i = findfile(file, i)) != -1) {
if(!strcmp(file->realname, filename)) { /* soubor nalezen */
if(file->attr == 0x20) { /* soubor je soubor (neni treba slozka..) */
cluster = file->ClstrNo;
t = cluster;
goto vypis;
}
}
}
free(file);
return 1;
vypis:
i=0;
while(1) { /* rutina pro nahrani souboru do pameti :)) */
ds_zaloha = _DS;
_DS = seg;
readdisk((StartSector + (cluster - 2)), 1, dummy);
dummy += 0x200;
_DS = ds_zaloha;
cluster = *((unsigned int*)(fat+((cluster * 3) / 2)));
if (t & 1) cluster >>= 4;
else cluster &= 0x0fff;
if (fat_end(cluster)) break;
t = cluster;
i++;
}
dummy -= (0x200*(i+1));
asm mov sp_zaloha, sp;
asm mov ax, seg ;
asm mov ds, ax ;
asm mov es, ax ;
asm mov ss, ax ;
asm mov sp, 0xFFFE ;
asm db 0x9a ; /* call far seg:0000 */
asm dw 0000 ;
asm dw seg ;
/* tu se vratime :) */
asm mov ax, cs ;
asm mov ds, ax ;
asm mov es, ax ;
asm mov ss, ax ;
asm mov sp, sp_zaloha;
free(file);
return 0;
}
#endif