Changeset 53c4be3 in thomson for elec/CrO2/software/gui.cpp


Ignore:
Timestamp:
Feb 5, 2012, 3:25:32 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
1b74fa2
Parents:
c2a9854
Message:
  • Support for ZX spectrup TAP files.

git-svn-id: svn://localhost/thomson@17 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • elec/CrO2/software/gui.cpp

    rc2a9854 r53c4be3  
    1313#include <string.h>
    1414#include <sstream>
    15 #include <iostream>
     15#include <ios>
    1616
    1717#include <iupcontrols.h>
     
    9494        Callback<Gui, int, int, int>::create(blocklist, "SELECTION_CB", this, &Gui::selectBlock);
    9595
    96         Ihandle* hexEd = IupMatrix(NULL);
     96        hexEd = IupMatrix(NULL);
    9797
    9898        // Setup title cells
    99         IupSetAttribute(hexEd, "NUMLIN", "16");
     99        IupSetAttribute(hexEd, "FONT", "Courier, 10");
     100        IupSetAttribute(hexEd, "FONT*:17", "Courier, 10");
    100101        IupSetAttribute(hexEd, "NUMCOL", "17");
    101         IupSetAttribute(hexEd, "WIDTHDEF", "12");
    102         IupSetAttribute(hexEd, "WIDTH17", "48");
    103         IupSetAttribute(hexEd, "USETITLESIZE", "YES");
    104         IupSetAttribute(hexEd, "FONT", "Courier, Bold 12");
     102        IupSetAttribute(hexEd, "WIDTHDEF", "10");
     103        IupSetAttribute(hexEd, "WIDTH17", "105");
     104        IupSetAttribute(hexEd, "WIDTH0", "12");
     105        IupSetAttribute(hexEd, "HEIGHT0", "8");
     106        IupSetAttribute(hexEd, "SIZE", "400x230");
    105107        IupSetAttribute(hexEd, "EXPAND", "YES");
     108        IupSetAttribute(hexEd, "ALIGNMENT", "ALEFT");
    106109        Callback<Gui, const char*, int, int>::create(hexEd, "VALUE_CB", this, &Gui::matVal);
    107110       
     
    173176        {
    174177                // Load file
    175                 file = new K5(name);
     178                try {
     179                        file = Tape::load(name);
     180                } catch (const char* error) {
     181                        puts(error);
     182                        return IUP_DEFAULT;
     183                }
    176184
    177185                // Fill in EXPLORE tab
     
    179187                int lastfile = -1;
    180188
     189                IupSetAttribute(blocklist, "DELNODE", "ALL");
     190
    181191                for (int i = 0; i < count; ++i)
    182192                {
    183                         const K5::Block& blk = file->getBlock(i);
    184                         switch(blk.type)
     193                        const Tape::Block& blk = file->getBlock(i);
     194                        if (blk.isFile())
    185195                        {
    186                                 case 0:
    187                                         //start block
    188                                         char name[12];
    189                                         memcpy(name, blk.data, 11);
    190                                         name[11] = 0;
    191                                        
    192                                         IupSetAttributeId(blocklist, "INSERTBRANCH", lastfile, name);
    193                                         lastfile = i;
    194                                         break;
    195                                 case 0xFF:
    196                                         // end block
    197                                         IupSetAttributeId(blocklist, "ADDLEAF", i-1, "EOF");
     196                                IupSetAttributeId(blocklist, "INSERTBRANCH", lastfile, blk.getName().c_str());
     197                                lastfile = i;
     198                        } else {
     199                                IupSetAttributeId(blocklist, "ADDLEAF", i-1, blk.getName().c_str());
     200                                if (blk.isControl())
    198201                                        IupSetAttributeId(blocklist, "IMAGE", i, "IMGLEAF");
    199                                         break;
    200                                 default:
    201                                         // regular block
    202                                         IupSetAttributeId(blocklist, "ADDLEAF", i-1, "DATA");
    203                                         break;
    204202                        }
    205203                }
     
    217215        if (what)
    218216        {
    219                 IupSetAttribute(hexEd, "REDRAW", "ALL");
     217                selblock = id;
     218                std::ostringstream att;
     219                att << (file->getBlock(id).length / 16);
     220                IupSetAttribute(hexEd, "NUMLIN", att.str().c_str());
     221
     222                IupSetAttribute(hexEd, IUP_REDRAW, "ALL");
     223        } else if (selblock == id) {
     224                selblock = -1;
    220225        }
    221226
     
    223228}
    224229
    225 const char* Gui::matVal(int x, int y)
    226 {
    227         if (x == 0)
    228         {
    229                 switch(y)
     230const char* Gui::matVal(int y, int x)
     231{
     232        if (y == 0)
     233        {
     234                switch(x)
    230235                {
    231236                        case 0:
     
    237242                                std::ostringstream name;
    238243                                name << std::hex;
    239                                 name << (y-1);
     244                                name << (x-1);
    240245                                return name.str().c_str();
    241246                        }
     
    243248        }
    244249
    245         if (y == 0)
    246         {
    247                 return "C";
    248         }
    249 
    250         return "V";
     250        if (x == 0)
     251        {
     252                std::ostringstream name;
     253                name << std::hex;
     254                name << (y-1)*16;
     255                return name.str().c_str();
     256        }
     257
     258        if (file == NULL || selblock < 0 || selblock >= file->getBlockCount())
     259                return "";
     260        const Tape::Block& block = file->getBlock(selblock);
     261
     262        if (x == 17)
     263        {
     264                int off = (y-1)*16;
     265                std::ostringstream txt;
     266                for(int j = 0; j < 16; j++)
     267                {
     268                        if (off + j >= block.length)
     269                                break;
     270                        char c = block.data[off+j];
     271                        if (isprint(c))
     272                                txt << c;
     273                        else
     274                                txt << '.';
     275                }
     276                return txt.str().c_str();
     277        } else {
     278
     279                int pos = (y-1) * 16 + (x-1);
     280                if (pos >= block.length)
     281                        return "";
     282
     283                return toHex(block.data[pos]);
     284        }
    251285}
    252286
     
    263297        return IUP_DEFAULT;
    264298}
     299
     300const char* Gui::toHex(int val)
     301{
     302        std::ostringstream str;
     303        str.flags(std::ios_base::hex | std::ios_base::uppercase);
     304        str.width(2);
     305        str.fill('0');
     306        str << val;
     307        return str.str().c_str();
     308}
Note: See TracChangeset for help on using the changeset viewer.