// Test program for assembly memory operations

// Define CPU Type
#define __MSP430_449__

#include <io.h>

void DisplayBCDASM( unsigned long int *value, unsigned char digit );

/******************************************************************************
  Segment Definitions
******************************************************************************/
#define SEGA 0x080 //   01h
#define SEGB 0x040 //   02h
#define SEGC 0x020 //   04h
#define SEGD 0x001 //   80h
#define SEGE 0x002 //   40h
#define SEGF 0x008 //   10h
#define SEGG 0x004 //   20h
#define SEGH 0x010 //   08h

/******************************************************************************
 ASCII Table for Numbers
******************************************************************************/
// This will reside in ROM
const char LCDASCII[27] = {
                     1                                   ,  //; SPACE
                     SEGB+SEGD                           ,  //; !
                     SEGB+SEGF                           ,  //; "
                     SEGB+SEGC+SEGE+SEGF                 ,  //; #
                     SEGA+SEGC+SEGD+SEGF+SEGG            ,  //; $
                     SEGB+SEGE+SEGG                      ,  //; %
                     SEGB+SEGC+SEGG                      ,  //; & <- Not correct
                     SEGF                                ,  //; '
                     SEGA+SEGD+SEGE+SEGF                 ,  //; (
                     SEGA+SEGC+SEGB+SEGD                 ,  //; )
                     SEGA+SEGC+SEGD                      ,  //; *
                     SEGB+SEGC+SEGG                      ,  //; +
                     SEGC+SEGD                           ,  //; ,
                     SEGG                                ,  //; -
                     SEGD                                ,  //; .
                     SEGB+SEGG+SEGE                      ,  //; /
                     SEGA+SEGB+SEGC+SEGD+SEGE+SEGF       ,  //; 0
                     SEGB+SEGC                           ,  //; 1
                     SEGA+SEGB+SEGD+SEGE+SEGG            ,  //; 2
                     SEGA+SEGB+SEGC+SEGD+SEGG            ,  //; 3
                     SEGB+SEGC+SEGF+SEGG                 ,  //; 4
                     SEGA+SEGC+SEGD+SEGF+SEGG            ,  //; 5
                     SEGA+SEGC+SEGD+SEGE+SEGF+SEGG       ,  //; 6
                     SEGA+SEGB+SEGC                      ,  //; 7
                     SEGA+SEGB+SEGC+SEGD+SEGE+SEGF+SEGG  ,  //; 8
                     SEGA+SEGB+SEGC+SEGF+SEGG            ,  //; 9
                     };

int main( void )
{
unsigned long int i;


    i = 0x1234;
    DisplayBCDASM( &i, 0 );

}

// Two options for GLOBLCDMEM:
// Option 1
// This is wrong since the resulting value in the asm is 0x200 (the RAM location of this pointer)
const unsigned char *GLOBLCDMEM = LCDMEM;
// Option 2
// This simply won't compile.  It gives "C:\/asmtest.c:56: undefined reference to `GLOBLCDMEM'"
//#define GLOBLCDMEM  LCDMEM

// Display a BCD number on the LCD
void DisplayBCDASM( unsigned long int *value, unsigned char digit )
{
// Varialbes from C to Asm are as follows:
// value -> R15
// digit -> R14

    asm (   "\tPUSH.W  R11\n"
            "\tMOV.B   @R15, R11                   ; Get byte again\n"
            "\tRRA.B   R11                         ; move upper nibble to lower nibble\n"
            "\tRRA.B   R11\n"
            "\tRRA.B   R11\n"
            "\tRRA.B   R11\n"
            "\tAND.B   #15, R11                   ; Clear out upper nibble\n"
            "\tBIS.B   LCDASCII+0x10(R11), GLOBLCDMEM(R14)     ; Update number info (Same as OR)\n"
            "\tPOP.W   R11\n"
    );
//      RET

}

