Multos Forums

   

How to initialise more than one variable with halugen.

RankRankRank

Total Posts: 74

Joined 2012-02-21

PM

This post tells you how you can personalise more than one static data item using halugen.

halugen has a -init option that allows you to set the value of a variable in your MULTOS application by reference to its variable name.

In many instances you may wish to set more than one variable. This is easy to do. Simply put the variables you want to initialise into a structure, then use the structure name in the -init option.

#pragma melstatic
char scheme[8] "Big Bank";
struct
{
 int points
;
 
char name[8];
} perso_data

hcl -g eloyalty.c
halugen -init perso_data=01F4536D697468000000 eloyalty.hzx

The initial value for points is shown in bold (500 decimal), the remainder is the initial value for name (in this case Smith). Note that the string is padded to its full length.

—-

This is the full source code for the example.

#pragma attribute("aid", "f0 00 00 01")
#pragma attribute("dir", "61 10 4f 4 f0 00 00 01 50 8 65 6c 6f 79 61 6c 74 79")

#include <multoscomms.h>
#include <string.h>

#define ERR_OK          0x9000
#define ERR_WRONGCLASS  0x6402
#define ERR_BAD_INS     0x6404

#define CMD_READPTS      0x10  /* Read points */
#define CMD_READSCM      0x20  /* Read scheme */
#define CMD_READNAM      0x30  /* Read name */

#define MYAPP_CLA       0x70

#pragma melpublic
// Response data
union
{
  int pts
;
  
char text[8];
} apdu_data;

#pragma melstatic
char scheme[8] "Big Bank";
struct
{
 int points
;
 
char name[8];
} perso_data;

void
main
(void)
{
  
if (CLA != MYAPP_CLA)
    
ExitSW(ERR_WRONGCLASS);

  switch (
INS)
    
{
    
case CMD_READPTS:
      if (!
CheckCase(2))
        
ExitSW(ERR_WRONGCLASS);

      
apdu_data.pts perso_data.points;
      
ExitLa(sizeof(perso_data.points));

    case 
CMD_READSCM:
      if (!
CheckCase(2))
        
ExitSW(ERR_WRONGCLASS);

      
strcpy(apdu_data.text,scheme);
      
ExitLa(strlen(scheme));

    case 
CMD_READNAM:
      if (!
CheckCase(2))
        
ExitSW(ERR_WRONGCLASS);

      
strcpy(apdu_data.text,perso_data.name);
      
ExitLa(strlen(perso_data.name));

    default:
      
ExitSW(ERR_BAD_INS);
  
}