[Description]

Location = "FLASH\TMS\TMS27C512";
Info = " Автор модуля: fomalex@tut.by";
Buffer1 = "FLASH",65536;
Voltage = 5.0;

[Menu]

Read    = "&Read",ReadButton,"Read chip",F2;
Compare = "&Verify",CheckButton,"Compare with buffer",F3;
Div0    = "-";
Write   = "&Write",WriteButton,"Write chip",F5;
Div1    = "-";
Info    = "&About module",ModuleInfoButton,"Show module info",F1;

[Host]


Proc Read 
{
    var Value,Address;
    print("");
    print("   Reading chip...");
    Value = 1;
    Address = 0;
    PBMax = 65536;
    Run(Read);
    while(Address != 65536) 
    {
        Value = USB;
        FBUF[Address] = Value;
        Address++;
        PBPos++;
    }
    if(ForceCloseAfterRead != 0) { return(0x7FFFFFFF); }
    print("");
    print("   Reading is done. %i bytes were readed.",Address);      
}


Proc Compare 
{
    var Value,Address,Temp,Mismatch;
    print("");
    print("   Verifying chip...");
    Value = 1;
    Address = 0;
    PBMax = 65536;
    Mismatch = 0;
    Run(Read);
    while(Address != 65536) 
    {
        Value = USB;
        Temp = FBUF[Address];
        if(Temp != Value)
        {
            Mismatch++;
            FSEL[Address] = 0;    
        }
        else
        {
            FSEL[Address] = 1;
        }
        Address++;
        PBPos++;
    }
    if(Mismatch = 0)
    {
        if(ForceCloseAfterVerify != 0) { return(0x7FFFFFFF); }
    }
    print("");
    print("   Verifying is done. %i bytes were compared. Mismatch: %i.",Address,Mismatch);
}

[Device]

ereg    ADRL,   0,1
ereg    ADRH,   1,1
ereg    CTRL,   2,1
ereg    DATAIN, 3,0    
ereg    DATAOUT,4,1
ereg    PWRCTRL,5,1

define  CS_AND_OE_LOW       0b11010111
define  CS_AND_OE_HIGH      0b00101000
define  DATA_OUT_ENABLE     0b01111111
define  DATA_OUT_DISABLE    0b10000000

var AL,AH,Value,Temp,Control;

Proc Read
{
    CTRL = 0b11111000;                      // deselect chip
    PWRCTRL = 2;                            // VCC on pin 28
    AH = 0;AL = 0;DATAOUT = 255;
    CTRL = 0b11010000;                      // select chip for read
    while(AH != 256)
    {
        ADRH = AH;AL = 0;
        while(AL != 256)    
        {
            ADRL = AL;Value = DATAIN;USB = Value;AL++;
        }
        AH++;
    }
    CTRL = 0b11111000;                      // deselect chip
    PWRCTRL = 3;                            // power OFF
}

