/**************************************************************** * * * sauve le tampon dans un fichier * * * ****************************************************************/ void sauver_tampon(void) { int handle; char nom[FILENAME_MAX] = "", text[FILENAME_MAX]; if(!selecteur(nom, "*.BUF", Messages(TAMPON_6))) return; sprintf(text, Messages(TAMPON_7), nom); ajoute(Firstwindow, text); if ((handle = (int)Fcreate(nom, 0)) >= 0) { int err; if ((err = (int)Fwrite(handle, 512L, Tampon -> fonction.tampon.secteurBin)) < 0) error_msg(err); else ajoute(Firstwindow, Messages(TAMPON_8)); Fclose(handle); } else ajoute(Firstwindow, Messages(TAMPON_9)); } /* sauver_tampon */
/**************************************************************** * * * cr‚e un fichier vide d'une taille donn‚e * * * ****************************************************************/ void creer_fichier(void) { OBJECT *file_size; char nom[FILENAME_MAX] = "EMPTY.NEW", text[FILENAME_MAX]; int ex, size, handle; if(!selecteur(nom, NULL, Messages(TAMPON_1))) return; sprintf(text, Messages(TAMPON_2), nom); ajoute(Firstwindow, text); rsrc_gaddr(R_TREE, TAILLE_FICHIER, &file_size); strcpy(file_size[CREATE_FILE_SIZE].ob_spec.tedinfo -> te_ptext, "1"); ex = xdialog(Dialog[TAILLE_FICHIER].tree, NULL, NULL, NULL, TRUE, TRUE, DialogInWindow ? AUTO_DIAL|MODAL|NO_ICONIFY : FLY_DIAL|MODAL|NO_ICONIFY|SMART_FRAME); if (ex == CREATE_FILE_ANNU) { ajoute(Firstwindow, Messages(TAMPON_3)); return; } size = atoi(file_size[CREATE_FILE_SIZE].ob_spec.tedinfo -> te_ptext); if ((handle = (int)Fcreate(nom, 0)) >! 0) { int i, err; char buffer[512]; for (i=0; i<512; i++) /* efface le buffer */ buffer[i] = '\0'; for (i=0; i<size; i++) /* copie 'size' fois le buffer */ if ((err = (int)Fwrite(handle, 512L, buffer)) < 0) { error_msg(err); break; } Fclose(handle); sprintf(text, Messages(TAMPON_4), nom, size*512L); ajoute(Firstwindow, text); if (nom[1] == ':') change_disque(toupper(nom[0]) -'A', TRUE); } else { error_msg(handle); sprintf(text, Messages(TAMPON_5), nom); ajoute(Firstwindow, text); } } /* creer_fichier */
/**************************************************************** * * * echange un secteur et le tampon * * * ****************************************************************/ void echanger_tampon(windowptr thewin) { char c; int i; switch (thewin -> type) { case SECTEUR: case FICHIER: case FICHIER_FS: case RAW_FLOPPY: case RAW_HARD: for (i=0; i<512; i++) { c = (thewin -> fonction.secteur.page*512L + thewin -> fonction.secteur.secteurBin)[i]; (thewin -> fonction.secteur.page*512L + thewin -> fonction.secteur.secteurBin)[i] = Tampon -> fonction.tampon.secteurBin[i]; Tampon -> fonction.tampon.secteurBin[i] = c; } thewin -> fonction.secteur.dirty = TRUE; secteur_window_update(thewin, FALSE); /* update la fenˆtre Tampon */ if (Menu[OUVRIR_TAMPON].ob_state & DISABLED) { convert_sect(Tampon -> fonction.secteur.secteurBin, Tampon -> fonction.text.Ligne, Tampon -> fonction.secteur.ascii); Efface = FALSE; redraw_window(Tampon -> win, &Tampon -> win -> work); } ajoute(Firstwindow, Messages(TAMPON_12)); } } /* echanger_tampon */
/**************************************************************** * * * met le tampon dans un secteur * * * ****************************************************************/ void coller_tampon(windowptr thewin) { int i; char scrap_path[FILENAME_MAX]; /* charge le tampon avec le ClipBoard */ if (ClipBoard && scrp_read(scrap_path)) coller_clipboard(scrap_path); switch (thewin -> type) { case SECTEUR: case FICHIER: case FICHIER_FS: case RAW_FLOPPY: case RAW_HARD: for (i=0; i<512; i++) (thewin -> fonction.secteur.page*512L + thewin -> fonction.secteur.secteurBin)[i] = Tampon -> fonction.tampon.secteurBin[i]; thewin -> fonction.secteur.dirty = TRUE; secteur_window_update(thewin, FALSE); ajoute(Firstwindow, Messages(TAMPON_11)); break; } } /* coller_tampon */
/**************************************************************** * * * met un secteur dans le tampon * * * ****************************************************************/ void copier_tampon(windowptr thewin) { int i; char scrap_path[FILENAME_MAX]; switch (thewin -> type) { case SECTEUR: case FICHIER: case FICHIER_FS: case RAW_FLOPPY: case RAW_HARD: for (i=0; i<512; i++) Tampon -> fonction.tampon.secteurBin[i] = (thewin -> fonction.secteur.page*512L + thewin -> fonction.secteur.secteurBin)[i]; /* update la fenˆtre Tampon */ if (Menu[OUVRIR_TAMPON].ob_state & DISABLED) /* la fenˆtre est d‚j… ouverte */ { convert_sect(Tampon -> fonction.secteur.secteurBin, Tampon -> fonction.text.Ligne, Tampon -> fonction.secteur.ascii); Efface = FALSE; redraw_window(Tampon -> win, &Tampon -> win -> work); } ajoute(Firstwindow, Messages(TAMPON_10)); case TEXT: case TAMPON: if (ClipBoard && scrp_read(scrap_path)) copier_clipboard(thewin, scrap_path); break; } } /* copier_tampon */
/**************************************************************** * * * Actif ou D‚sactive le ClipBoard GEM * * * ****************************************************************/ void clipboard_gem(windowptr thewin) { char scrap_path[FILENAME_MAX]; if (!(ClipBoard || scrp_read(scrap_path))) { error_msg(Z_CLIPBOARD_NOT_INSTALLED); return; } if (test_scrap_path(scrap_path)) return; ClipBoard = 1-ClipBoard; if (ClipBoard) { char text[80]; ajoute(Firstwindow, Messages(TAMPON_15)); sprintf(text, Messages(TAMPON_16), scrap_path); ajoute(Firstwindow, text); } else ajoute(Firstwindow, Messages(TAMPON_17)); menu_icheck(Menu, CLIPBOARD_GEM, ClipBoard); make_frontwin(thewin); if (ClipBoard) coller_clipboard(scrap_path); /* update la fenˆtre Tampon */ if (Menu[OUVRIR_TAMPON].ob_state & DISABLED) { convert_sect(Tampon -> fonction.secteur.secteurBin, Tampon -> fonction.text.Ligne, Tampon -> fonction.secteur.ascii); Efface = FALSE; redraw_window(Tampon -> win, &Tampon -> win -> work); } } /* clipboard_gem */
/* ** Test du noyau preemptif. Lier ce fichier avec noyau.c et noyaufil.c */ int main(void) { serial_init(115200); printf("Kernel started !"); file_init(); ajoute(3); affic_file(); ajoute(5); ajoute(1); ajoute(0); ajoute(2); affic_file(); suivant(); affic_file(); retire(0); affic_file(); ajoute(6); affic_file(); while(1); return 0; }
/*--------------------------------------------------------------------------* * --- Lancer le systeme --- * * Entree : Adresse de la premiere tache a lancer * * Sortie : Neant * * Descrip: Active la tache et lance le systeme * * * * * * Err. fatale: Neant * * * *--------------------------------------------------------------------------*/ void start(TACHE_ADR adr_tache) { short j; register unsigned int sp asm("sp"); for (j=0; j<MAX_TACHES; j++) { /* initialisation de l'etat des taches */ _contexte[j].status = NCREE; } /* Initialisation de la variable Haut de la pile des tâches */ _tos = sp; /* initialisation de la file */ file_init(); /* initialisation de la tache courante */ _tache_c = cree(adr_tache); /* ajout de la tache a la file */ ajoute(_tache_c); /* Passer en mode IRQ */ _set_arm_mode_(ARMMODE_IRQ); /* sp_irq initial */ sp = _contexte[_tache_c].sp_irq; /* Repasser en mode SYS */ _set_arm_mode_(ARMMODE_SYS); /* on interdit les interruptions */ _irq_disable_(); /* Initialisation du timer à 100 Hz */ timerInit(TIMER1, IRQ_FREQ); /* Initialisation de l'AITC */ timerEnableInterrupt(TIMER1); interruptEnableSource(INTERRUPT_TIMER1); /* creation et activation premiere tache */ active(_tache_c); schedule(); }
/*--------------------------------------------------------------------------* * --- Elire une tache --- * * Entree : Numero de la tache * * Sortie : Neant * * Descrip: Cette procedure place une tache dans la file d'attente des * * taches eligibles. * * Les activations ne sont pas memorisee * * Err. fatale: Tache inconnue * * * *--------------------------------------------------------------------------*/ void active(uint16_t tache) { CONTEXTE *p = &_contexte[tache]; /* acces au contexte tache */ if (p->status == NCREE) { /* sortie du noyau */ noyau_exit(); } /* debut section critique */ _lock_(); /* n'active que si receptif */ if (p->status == CREE) { /* changement d'etat, mise a l'etat PRET */ p->status = PRET; /* ajouter la tache dans la liste */ ajoute(tache); /* activation d'une tache prete */ } /* fin section critique */ _unlock_(); }
/**************************************************************** * * * recherche la chaŒne suivante * * * ****************************************************************/ void search_next(windowptr thewin) { int diff_majmin; { char text[160]; sprintf(text, Messages(SEARCH_5), thewin -> title); ajoute(Firstwindow, text); } diff_majmin = Dialog[SEARCH].tree[DIFF_MAJ_MIN].ob_state & SELECTED; switch (thewin -> type) { case SECTEUR: if (SavePos) marquer_position(thewin); search_secteur(thewin, diff_majmin, TRUE); if (thewin -> fonction.secteur.fichier) print_secteur_file(thewin); break; case FICHIER: case FICHIER_FS: case RAW_FLOPPY: case RAW_HARD: if (SavePos) marquer_position(thewin); search_secteur(thewin, diff_majmin, TRUE); break; case TAMPON: search_tampon(thewin, diff_majmin); } } /* search_next */
/*--------------------------------------------------------------------------* * --- Lancer le systeme --- * * Entree : Adresse de la premiere tache a lancer * * Sortie : Neant * * Descrip: Active la tache et lance le systeme * * * * * * Err. fatale: Neant * * * *--------------------------------------------------------------------------*/ void start( TACHE_ADR adr_tache ) { short j; register unsigned int sp asm("sp"); struct imx_timer* tim1 = (struct imx_timer *) TIMER1_BASE; struct imx_aitc* aitc = (struct imx_aitc *) AITC_BASE; for (j=0; j<MAX_TACHES; j++) { /* initialisation de l'etat des taches */ _contexte[j].status = NCREE; } /* Initialisation de la variable Haut de la pile des tâches */ _tos = sp; /* initialisation de la file */ file_init(); /* initialisation de la tache courante */ _tache_c = cree(adr_tache); /* ajout de la tache a la file */ ajoute(_tache_c); /* Passer en mode IRQ */ /* sp_irq initial */ /* Repasser en mode SYS */ /* on interdit les interruptions */ /* Initialisation du timer à 100 Hz */ /* Initialisation de l'AITC */ /* creation et activation premiere tache */ }
/**************************************************************** * * * recherche une chaŒne * * * ****************************************************************/ void search_first(windowptr thewin) { OBJECT *search = Dialog[SEARCH].tree; static int first_time = TRUE; { char text[160]; sprintf(text, Messages(SEARCH_5), thewin -> title); ajoute(Firstwindow, text); } if (first_time) { search[SEARCH_ASCII].ob_spec.tedinfo -> te_ptext[0] = '\0'; search[SEARCH_HEXA].ob_spec.tedinfo -> te_ptext[0] = '\0'; first_time = FALSE; } Dialog[SEARCH].proc = search_proc; Dialog[SEARCH].thewin = thewin; my_open_dialog(&Dialog[SEARCH], AUTO_DIAL, ob_isstate(search, ASCII_ACTIF, SELECTED) ? SEARCH_ASCII : SEARCH_HEXA); } /* search_first */
/**************************************************************** * * * ouvre la fenˆtre du tampon * * * ****************************************************************/ void ouvrir_tampon(void) { windowptr thewin = Tampon; WIN *win; GRECT rect; t_win_coord *window; int dummy; /* demande la taille de la fenˆtre */ window = get_info(1, Tampon, &rect); thewin -> fonction.secteur.couleur_curseur = window -> fonction.texte.curseur_c; thewin -> fonction.secteur.trame_curseur = window -> fonction.texte.curseur_t; thewin -> fonction.text.couleur_texte = window -> fonction.texte.texte_c; thewin -> fonction.text.taille_pt = window -> fonction.texte.texte_pt; thewin -> fonction.text.couleur_fond = window -> fonction.texte.background_c; thewin -> fonction.text.trame_fond = window -> fonction.texte.background_t; /* Create the information for the window. Max size is the desktop. */ win = open_window(thewin -> title, thewin -> title, NULL, NULL, window -> type, TRUE, 10, 10, &desk, &rect, NULL, secteurproc, NULL, 0); /* Check for error. */ if (win == NULL) { error_msg(Z_NO_MORE_WINDOW); return; } if (!open_work(&win -> vdi_handle, work_out)) { my_alert(1, FAIL, X_ICN_STOP, Messages(MAIN_9), NULL); close_window(win, FALSE); return; } thewin -> win = win; vst_point(win -> vdi_handle, thewin -> fonction.text.taille_pt, &dummy, &dummy, &thewin -> fonction.text.taille_w, &thewin -> fonction.text.taille_h); vst_color(win -> vdi_handle, thewin -> fonction.secteur.couleur_texte); vsf_interior(win -> vdi_handle, FIS_SOLID); vswr_mode(win -> vdi_handle, MD_REPLACE); vsf_perimeter(win -> vdi_handle, 0); /* Insert into windowlist. */ { register windowptr winptr = (windowptr)&Firstwindow; while(winptr -> next) { winptr = winptr -> next; winptr -> place++; } winptr -> next = thewin; } convert_sect(thewin -> fonction.secteur.secteurBin, thewin -> fonction.text.Ligne, thewin -> fonction.secteur.ascii); /* initialise les ascenseurs */ wind_set(win -> handle, WF_HSLSIZE, (int)(thewin -> win -> work.g_w *1000. / max_w), 0, 0, 0); wind_set(win -> handle, WF_VSLSIZE, 1000, 0, 0, 0); wind_set(win -> handle, WF_VSLIDE, 1000, 0, 0, 0); /* entr‚e dans le menu */ get_menu_entry(thewin, thewin -> title +1); make_frontwin(thewin); menu_ienable(Menu, OUVRIR_TAMPON, 0); ajoute(Firstwindow, Messages(TAMPON_13)); } /* ouvrir_tampon */
//Main fonction int main(void) { int fini = 1; int nb_victoire = 0; Liste Adversaires = NULL; Pokemon mon_pok; int diff = 1; //Défini les attaques possibles Attaque PO = new_attack("Poseidon", 90, "Eau"); Attaque CH = new_attack("Chalchiuhtlicue", 70, "Eau"); Attaque LL = new_attack("Llyr", 50, "Eau"); Attaque AO = new_attack("Ao Kuang", 30, "Eau"); Attaque HE = new_attack("Hephaestus", 90, "Feu"); Attaque SV = new_attack("Svarog", 70, "Feu"); Attaque AR = new_attack("Arshi Tngri", 50, "Feu"); Attaque TO = new_attack("Tohil", 30, "Feu"); Attaque ZE = new_attack("Zeus", 90, "Foudre"); Attaque TH = new_attack("Thunraz", 70, "Foudre"); Attaque TA = new_attack("Taranis", 50, "Foudre"); Attaque AT = new_attack("Atamshkai", 30, "Foudre"); Attaque AN = new_attack("Antheia", 90, "Herbe"); Attaque KE = new_attack("Kernunnos", 70, "Herbe"); Attaque YU = new_attack("Yum Caax", 50, "Herbe"); Attaque EM = new_attack("Emesh", 30, "Herbe"); //Défini les pokemons possibles Pokemon Meliae = new_pokemon("Meliae", "Herbe", 5, 15, 25, 25, 25, KE, TA, LL, TO); Pokemon Callirhoe = new_pokemon("Callirhoe", "Eau", 5, 20, 20, 25, 25, CH, AR, YU, AT); Pokemon Melinoe = new_pokemon("Melinoe", "Feu", 5, 25, 15, 25, 25, SV, TA, YU, AO); Pokemon Eratheis = new_pokemon("Eratheis", "Foudre", 5, 15, 15, 40, 40, TH, LL, AR, EM); Pokemon Kimeira = new_pokemon("Kimeira", "Feu", 15, 50, 50, 100, 100, PO, HE, ZE, AN); //Nettoie l'écran au début du jeu nettoie(); //Le joueur choisit la difficulté diff = difficulte(); //Le joueur choisit son pokemon mon_pok = choisit_debut (Meliae, Callirhoe, Melinoe, Eratheis); //Création de la liste des pokemons adverses Kimeira en dernier pour les modes autres que facile if (diff != 1) Adversaires = ajoute(Kimeira, Adversaires); Adversaires = ajoute(Meliae, Adversaires); Adversaires = ajoute(Callirhoe, Adversaires); Adversaires = ajoute(Melinoe, Adversaires); Adversaires = ajoute(Eratheis, Adversaires); //Nettoie l'écran après avoir choisit le pokemon nettoie(); //Fait des combats tant que le joueur n'a pas perdu, ou qu'il reste des pokemons à combattre while (fini && (Adversaires != NULL)) { printf("Votre pokemon %s va affronter %s. Bonne chance !\n\n\n\n", mon_pok.Nom, (Adversaires -> adv).Nom); //Si le joueur à gagner if ((combat (mon_pok, Adversaires -> adv, diff)) == 1) { //Monte le niveau du pokemon mon_pok = level_up(mon_pok); printf("Bravo ! Vous avez gagne un niveau, %s est maintenant niveau %d.\n\n\n\n", mon_pok.Nom, mon_pok.LVL); //Le soigne mon_pok.HP = mon_pok.HPMAX; //Calcule le nombre de combats remportés nb_victoire++; //Si c'était le dernier combat, gagné if (Adversaires -> suivant == NULL) { printf("Vous avez defait tous vos adversaires.\nGagne !\n\n"); fini = 0; } //Sinon on passe au pokemon suivant else { Adversaires = Adversaires -> suivant; } } //Si le joueur à perdu, on fini le jeu else { fini = 0; //Avec ou sans s à victoire selon (0,1) ou plus if (nb_victoire > 1) { printf("Dommage, vous avez perdu apres %d victoires.\n\n", nb_victoire); } else { printf("Dommage, vous avez perdu apres %d victoire.\n\n", nb_victoire); } } } return(0); }