|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
ECRITURE D'UN *.COM 16 BITS
Information sur la source
Description
Ce programme écrit un simple *.com ;-) Voila pour les gros boutoneux qui tape du clavier H24 bah peu etre que ma source n'a pas d'interet encore une fois
mais ce programme peut plaire à d'aute... (si vous cherchez la petite bête vous trouverez surement des fautes d'orthographe cherchez bien lol)
PS: si la source vous semble pas assez commenté, c'est parceque je n'ai pas voulu la submerger de commentaire, mais si vous avez des questions je suis là.
Source
- // En-têtes:
- #include <stdio.h>
- #include <list>
-
-
- // Classe CCode:
- class CCode
- {
- private:
-
- // Structure:
- struct txxh
- {
- int xxh[3];
- int adr[3];
- };
-
- public:
-
- // Constructeur par défaut:
- CCode(char* buffer = 0, int adr = 0, int num_xxh = 0, int xxh_1 = 0, int xxh_2 = 0, int xxh_3 = 0)
- {
- this->buffer = buffer;
- this->adr = adr;
- this->num_xxh = num_xxh;
-
- this->xxh.xxh[0] = xxh_1;
- this->xxh.adr[0] = adr + 0;
-
- this->xxh.xxh[1] = xxh_2;
- this->xxh.adr[1] = adr + 1;
-
- this->xxh.xxh[2] = xxh_3;
- this->xxh.adr[2] = adr + 2;
- }
-
- // Données:
- char* buffer;
- int adr;
- int num_xxh;
- txxh xxh;
- };
-
-
- // Types:
- typedef std::list<CCode*> LCODE;
-
-
- // Classe CCom16b:
- class CCom16b
- {
- public:
-
- // Constructeur par défaut:
- CCom16b()
- {
- // Création du fichier en mode écriture:
- m_pFile = fopen("code_16_bits.com", "w");
-
- // Initialisation des adresses:
- m_Adr = 0x00;
- }
-
- // Destructeur:
- ~CCom16b()
- {
- // Fermeture du fichier en mode écriture:
- fclose(m_pFile);
-
- // Lance le fichier:
- printf("\nLancement du code:\n");
- system("code_16_bits.com");
- }
-
- // mov ah,xxh:
- void Set_mov_ah_xxh(int xxh)
- {
- char* buffer = new char[256];
- sprintf(buffer, "mov ah,%.2xh", xxh);
-
- m_pCode.push_back(new CCode(buffer, m_Adr, 2, 0xB4, xxh));
- m_Adr += 2;
- }
-
- // int xxh:
- void Set_int_xxh(int xxh)
- {
- char* buffer = new char[256];
- sprintf(buffer, "int %.2xh", xxh);
-
- m_pCode.push_back(new CCode(buffer, m_Adr, 2, 0xCD, xxh));
- m_Adr += 2;
- }
-
- // mov dx,xxh:
- void Set_mov_dx_xxh(int xxh)
- {
- int xxh_1 = 0, xxh_2 = 0, xxh_3 = 0;
- LittleEndian(xxh, &xxh_1, &xxh_2, &xxh_3);
-
- char* buffer = new char[256];
- sprintf(buffer, "mov dx,%.2xh", xxh);
-
- if (xxh_2 == 0x00 && xxh_3 == 0x00)
- {
- m_pCode.push_back(new CCode(buffer, m_Adr, 2, 0xBA, xxh_1));
- m_Adr += 2;
- }
- else if (xxh_3 == 0x00)
- {
- m_pCode.push_back(new CCode(buffer, m_Adr, 3, 0xBA, xxh_1, xxh_2));
- m_Adr += 3;
- }
- }
-
- // Variable buffer:
- void SetBuffer(int adr, char* buffer)
- {
- m_Adr = adr - 0x0100; // Car l'adresse du début du code com16b est 0x0100:
- for (int i = 0; i < (int)strlen(buffer); i++)
- {
- m_pCode.push_back(new CCode(buffer, m_Adr, 1, buffer[i]));
- m_Adr++;
- }
- }
-
- // Ecriture du code:
- void WriteCode()
- {
- for (LCODE::iterator itor = m_pCode.begin(); itor != m_pCode.end(); ++itor)
- {
- if ( (*itor)->num_xxh == 1)
- {
- fseek(m_pFile, (*itor)->xxh.adr[0], SEEK_SET);
- fprintf(m_pFile, "%c", (*itor)->xxh.xxh[0]);
- }
- else if ( (*itor)->num_xxh == 2)
- {
- fseek(m_pFile, (*itor)->xxh.adr[0], SEEK_SET);
- fprintf(m_pFile, "%c", (*itor)->xxh.xxh[0]);
-
- fseek(m_pFile, (*itor)->xxh.adr[1], SEEK_SET);
- fprintf(m_pFile, "%c", (*itor)->xxh.xxh[1]);
- }
- else if ( (*itor)->num_xxh == 3)
- {
- fseek(m_pFile, (*itor)->xxh.adr[0], SEEK_SET);
- fprintf(m_pFile, "%c", (*itor)->xxh.xxh[0]);
-
- fseek(m_pFile, (*itor)->xxh.adr[1], SEEK_SET);
- fprintf(m_pFile, "%c", (*itor)->xxh.xxh[1]);
-
- fseek(m_pFile, (*itor)->xxh.adr[2], SEEK_SET);
- fprintf(m_pFile, "%c", (*itor)->xxh.xxh[2]);
- }
- }
- }
-
- // Affichege du code:
- void ShowCode()
- {
- printf("ADR\t\tHEXA\t\tASM\n");
-
- for (LCODE::iterator itor = m_pCode.begin(); itor != m_pCode.end(); ++itor)
- {
- if ( (*itor)->num_xxh == 1)
- {
- printf("%.4X\t|\t%.6X%\t|\t%s\n", (*itor)->adr + 0x0100,
- (*itor)->xxh.xxh[0],
- (*itor)->buffer);
- }
- if ( (*itor)->num_xxh == 2)
- {
- printf("%.4X\t|\t00%.2X%.2X\t|\t%s\n", (*itor)->adr + 0x0100,
- (*itor)->xxh.xxh[0],
- (*itor)->xxh.xxh[1],
- (*itor)->buffer);
- }
- else if ( (*itor)->num_xxh == 3)
- {
- printf("%.4X\t|\t%.2X%.2X%.2X\t|\t%s\n", (*itor)->adr + 0x0100,
- (*itor)->xxh.xxh[0],
- (*itor)->xxh.xxh[1],
- (*itor)->xxh.xxh[2],
- (*itor)->buffer);
- }
- }
- }
-
- private:
-
- // LittleEndian:
- /*
- lsb msb
- -------------
- |78|56|34|12|
- -------------
- .
- /|\
- |
- |
- Adresse du suivant
- |
- |
- ---- |
- msb |12| <--
- ----
- |34|
- ----
- |56|
- ----
- lsb |78|
- ----
-
- Ex: 0x0210h -> 0x10 0x02
- */
- void LittleEndian(int xxh, int* xxh_1, int* xxh_2, int* xxh_3)
- {
- char buffer[6] = {0};
- sprintf(buffer, "%.6X", xxh);
-
- char part1[2] = {0};
- for (int i = 0; i < 2; i++) part1[i - 0] = buffer[i];
- (*xxh_3) = BufferToHexa(part1);
-
- char part2[2] = {0};
- for (int i = 2; i < 4; i++) part2[i - 2] = buffer[i];
- (*xxh_2) = BufferToHexa(part2);
-
- char part3[2] = {0};
- for (int i = 4; i < 6; i++) part3[i - 4] = buffer[i];
- (*xxh_1) = BufferToHexa(part3);
- }
-
- // Convertion d'une chaine de caractères en hexadécimal:
- int BufferToHexa(char* buffer)
- {
- int c[2];
-
- for (int i = 0; i < 2; i++)
- {
- switch (buffer[i])
- {
- case '0' : c[i] = 0; break;
- case '1' : c[i] = 1; break;
- case '2' : c[i] = 2; break;
- case '3' : c[i] = 3; break;
- case '4' : c[i] = 4; break;
- case '5' : c[i] = 5; break;
- case '6' : c[i] = 6; break;
- case '7' : c[i] = 7; break;
- case '8' : c[i] = 8; break;
- case '9' : c[i] = 9; break;
- case 'A' : c[i] = 10; break;
- case 'a' : c[i] = 10; break;
- case 'B' : c[i] = 11; break;
- case 'b' : c[i] = 11; break;
- case 'C' : c[i] = 12; break;
- case 'c' : c[i] = 12; break;
- case 'D' : c[i] = 13; break;
- case 'd' : c[i] = 13; break;
- case 'E' : c[i] = 14; break;
- case 'e' : c[i] = 14; break;
- case 'f' : c[i] = 15; break;
- case 'F' : c[i] = 15; break;
- }
- }
-
- return ( (c[0] * 16) + c[1] );
- }
-
- private:
-
- // Données membres:
- FILE* m_pFile;
- LCODE m_pCode;
- unsigned int m_Adr;
- };
-
-
- int main(void)
- {
- CCom16b com16b;
-
- com16b.Set_mov_ah_xxh(0x09);
- com16b.Set_mov_dx_xxh(0x10F);
- com16b.Set_int_xxh(0x21);
-
- com16b.Set_mov_ah_xxh(0x00);
- com16b.Set_int_xxh(0x16);
-
- com16b.Set_mov_ah_xxh(0x00);
- com16b.Set_int_xxh(0x21);
-
- com16b.SetBuffer(0x10F, "Hello World !$");
-
- com16b.WriteCode();
-
- com16b.ShowCode();
-
- return 0;
- }
// En-têtes:
#include <stdio.h>
#include <list>
// Classe CCode:
class CCode
{
private:
// Structure:
struct txxh
{
int xxh[3];
int adr[3];
};
public:
// Constructeur par défaut:
CCode(char* buffer = 0, int adr = 0, int num_xxh = 0, int xxh_1 = 0, int xxh_2 = 0, int xxh_3 = 0)
{
this->buffer = buffer;
this->adr = adr;
this->num_xxh = num_xxh;
this->xxh.xxh[0] = xxh_1;
this->xxh.adr[0] = adr + 0;
this->xxh.xxh[1] = xxh_2;
this->xxh.adr[1] = adr + 1;
this->xxh.xxh[2] = xxh_3;
this->xxh.adr[2] = adr + 2;
}
// Données:
char* buffer;
int adr;
int num_xxh;
txxh xxh;
};
// Types:
typedef std::list<CCode*> LCODE;
// Classe CCom16b:
class CCom16b
{
public:
// Constructeur par défaut:
CCom16b()
{
// Création du fichier en mode écriture:
m_pFile = fopen("code_16_bits.com", "w");
// Initialisation des adresses:
m_Adr = 0x00;
}
// Destructeur:
~CCom16b()
{
// Fermeture du fichier en mode écriture:
fclose(m_pFile);
// Lance le fichier:
printf("\nLancement du code:\n");
system("code_16_bits.com");
}
// mov ah,xxh:
void Set_mov_ah_xxh(int xxh)
{
char* buffer = new char[256];
sprintf(buffer, "mov ah,%.2xh", xxh);
m_pCode.push_back(new CCode(buffer, m_Adr, 2, 0xB4, xxh));
m_Adr += 2;
}
// int xxh:
void Set_int_xxh(int xxh)
{
char* buffer = new char[256];
sprintf(buffer, "int %.2xh", xxh);
m_pCode.push_back(new CCode(buffer, m_Adr, 2, 0xCD, xxh));
m_Adr += 2;
}
// mov dx,xxh:
void Set_mov_dx_xxh(int xxh)
{
int xxh_1 = 0, xxh_2 = 0, xxh_3 = 0;
LittleEndian(xxh, &xxh_1, &xxh_2, &xxh_3);
char* buffer = new char[256];
sprintf(buffer, "mov dx,%.2xh", xxh);
if (xxh_2 == 0x00 && xxh_3 == 0x00)
{
m_pCode.push_back(new CCode(buffer, m_Adr, 2, 0xBA, xxh_1));
m_Adr += 2;
}
else if (xxh_3 == 0x00)
{
m_pCode.push_back(new CCode(buffer, m_Adr, 3, 0xBA, xxh_1, xxh_2));
m_Adr += 3;
}
}
// Variable buffer:
void SetBuffer(int adr, char* buffer)
{
m_Adr = adr - 0x0100; // Car l'adresse du début du code com16b est 0x0100:
for (int i = 0; i < (int)strlen(buffer); i++)
{
m_pCode.push_back(new CCode(buffer, m_Adr, 1, buffer[i]));
m_Adr++;
}
}
// Ecriture du code:
void WriteCode()
{
for (LCODE::iterator itor = m_pCode.begin(); itor != m_pCode.end(); ++itor)
{
if ( (*itor)->num_xxh == 1)
{
fseek(m_pFile, (*itor)->xxh.adr[0], SEEK_SET);
fprintf(m_pFile, "%c", (*itor)->xxh.xxh[0]);
}
else if ( (*itor)->num_xxh == 2)
{
fseek(m_pFile, (*itor)->xxh.adr[0], SEEK_SET);
fprintf(m_pFile, "%c", (*itor)->xxh.xxh[0]);
fseek(m_pFile, (*itor)->xxh.adr[1], SEEK_SET);
fprintf(m_pFile, "%c", (*itor)->xxh.xxh[1]);
}
else if ( (*itor)->num_xxh == 3)
{
fseek(m_pFile, (*itor)->xxh.adr[0], SEEK_SET);
fprintf(m_pFile, "%c", (*itor)->xxh.xxh[0]);
fseek(m_pFile, (*itor)->xxh.adr[1], SEEK_SET);
fprintf(m_pFile, "%c", (*itor)->xxh.xxh[1]);
fseek(m_pFile, (*itor)->xxh.adr[2], SEEK_SET);
fprintf(m_pFile, "%c", (*itor)->xxh.xxh[2]);
}
}
}
// Affichege du code:
void ShowCode()
{
printf("ADR\t\tHEXA\t\tASM\n");
for (LCODE::iterator itor = m_pCode.begin(); itor != m_pCode.end(); ++itor)
{
if ( (*itor)->num_xxh == 1)
{
printf("%.4X\t|\t%.6X%\t|\t%s\n", (*itor)->adr + 0x0100,
(*itor)->xxh.xxh[0],
(*itor)->buffer);
}
if ( (*itor)->num_xxh == 2)
{
printf("%.4X\t|\t00%.2X%.2X\t|\t%s\n", (*itor)->adr + 0x0100,
(*itor)->xxh.xxh[0],
(*itor)->xxh.xxh[1],
(*itor)->buffer);
}
else if ( (*itor)->num_xxh == 3)
{
printf("%.4X\t|\t%.2X%.2X%.2X\t|\t%s\n", (*itor)->adr + 0x0100,
(*itor)->xxh.xxh[0],
(*itor)->xxh.xxh[1],
(*itor)->xxh.xxh[2],
(*itor)->buffer);
}
}
}
private:
// LittleEndian:
/*
lsb msb
-------------
|78|56|34|12|
-------------
.
/|\
|
|
Adresse du suivant
|
|
---- |
msb |12| <--
----
|34|
----
|56|
----
lsb |78|
----
Ex: 0x0210h -> 0x10 0x02
*/
void LittleEndian(int xxh, int* xxh_1, int* xxh_2, int* xxh_3)
{
char buffer[6] = {0};
sprintf(buffer, "%.6X", xxh);
char part1[2] = {0};
for (int i = 0; i < 2; i++) part1[i - 0] = buffer[i];
(*xxh_3) = BufferToHexa(part1);
char part2[2] = {0};
for (int i = 2; i < 4; i++) part2[i - 2] = buffer[i];
(*xxh_2) = BufferToHexa(part2);
char part3[2] = {0};
for (int i = 4; i < 6; i++) part3[i - 4] = buffer[i];
(*xxh_1) = BufferToHexa(part3);
}
// Convertion d'une chaine de caractères en hexadécimal:
int BufferToHexa(char* buffer)
{
int c[2];
for (int i = 0; i < 2; i++)
{
switch (buffer[i])
{
case '0' : c[i] = 0; break;
case '1' : c[i] = 1; break;
case '2' : c[i] = 2; break;
case '3' : c[i] = 3; break;
case '4' : c[i] = 4; break;
case '5' : c[i] = 5; break;
case '6' : c[i] = 6; break;
case '7' : c[i] = 7; break;
case '8' : c[i] = 8; break;
case '9' : c[i] = 9; break;
case 'A' : c[i] = 10; break;
case 'a' : c[i] = 10; break;
case 'B' : c[i] = 11; break;
case 'b' : c[i] = 11; break;
case 'C' : c[i] = 12; break;
case 'c' : c[i] = 12; break;
case 'D' : c[i] = 13; break;
case 'd' : c[i] = 13; break;
case 'E' : c[i] = 14; break;
case 'e' : c[i] = 14; break;
case 'f' : c[i] = 15; break;
case 'F' : c[i] = 15; break;
}
}
return ( (c[0] * 16) + c[1] );
}
private:
// Données membres:
FILE* m_pFile;
LCODE m_pCode;
unsigned int m_Adr;
};
int main(void)
{
CCom16b com16b;
com16b.Set_mov_ah_xxh(0x09);
com16b.Set_mov_dx_xxh(0x10F);
com16b.Set_int_xxh(0x21);
com16b.Set_mov_ah_xxh(0x00);
com16b.Set_int_xxh(0x16);
com16b.Set_mov_ah_xxh(0x00);
com16b.Set_int_xxh(0x21);
com16b.SetBuffer(0x10F, "Hello World !$");
com16b.WriteCode();
com16b.ShowCode();
return 0;
}
Sources du même auteur
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
ecriture de champ de bits dans un fichier [ par obasileus ]
Salut, est-ce que quelqu'un sait comment ecrire un champ de bits (9 bits) dans un fichier ?merci d'avance@+obasileus
mode insertion en ecriture [ par loopy ]
Salut, je voudrais savoir comment faire pour ajouter des infos dans un fichier (n'importe ou) en mode insertion. (pour stegano...)merciloopy
ecriture en mode insertion [ par loopy ]
Salut, je voudrais savoir s'il est possible de rajouter des infos dans un fichier (en mode texte) sans que cela efface les infos precedentes car je do
ecriture/lecture Port série [ par bryg ]
Salu, Voila je dois exploiter le port série de mon Pc sous win 2000 pour recevoir et envoyer des données comment faire ?Si quelqu'un aurai un program
ecriture/lecture Port série VC++ [ par bryg ]
Salut,La prog c pas mon fort je recherche desésperement un exemple de programme pour ecrire et lire sur mon port série sous windows 2000 avec VC++.Mer
ecriture/lecture Port série VC++ [ par bryg ]
Salut,La prog c pas mon fort je recherche desésperement un exemple de programme pour ecrire et lire sur mon port série sous windows 2000 avec VC++.Mer
Ecriture du contenu d'une classe dans un fichier [ par bidule ]
Bonjour,Je dois ecrire un programme en C++ qui utilise des fichiers.En fait, une fois que j'ai renseigné les variables (num, nom, prenom...) de ma cla
help sur lecture/ecriture sur fichier sur c++ [ par overfun ]
Bonjour à tous et à toutes, je suis nouveau dans la programmation et voudrait savoir comment écrire dans un fichier seulement sur quelques lignes !!Co
Utilisation de DLL dans un système 16 Bits DOS 6.22 [ par yass007 ]
Voila,je voudrai savoir tt dabord sil ya des tutoriaux sur comment creer des Dlls sous Turbo C++ 3.0 et compatibles avec un système 16 Bits , en l'occ
probleme d'ecriture sous visual c++ [ par f1cobra ]
Salut J'ai un probleme avec ma base de donnees, quand je veux enregistrer dans un recordset comprenant plus d'une table, il refuse me disant que la ta
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version

HTC Touch HD
Entre 25€ et 605€
|