Free Hero Mesh

Check-in [d24dfda327]
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.
Overview
Comment:Implement all of the rest of the (LevelTable) block and its displaying and processing, except the string matching, which will be implemented later.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d24dfda327826d0f68667fe7d95afd27f26a68e5
User & Date: user on 2021-12-29 00:29:24
Other Links: manifest | tags
Context
2021-12-30
21:49
Implement pattern strings and some other commands, an da few more corrections, in the (LevelTable) block implementation. check-in: b629fea66f user: user tags: trunk
2021-12-29
00:29
Implement all of the rest of the (LevelTable) block and its displaying and processing, except the string matching, which will be implemented later. check-in: d24dfda327 user: user tags: trunk
00:04
Add a entry to the Frequently Asked Questions section about use of Free Hero Mesh with gdb. check-in: b3b7b53f2b user: user tags: trunk
Changes

Modified class.c from [7cb8ff67cc] to [7243e8c48b].

2393
2394
2395
2396
2397
2398
2399


















2400
2401
2402
2403
2404
2405
2406
  free(aggrc);
  ll_disp=realloc(dispc,(ll_ndisp)*sizeof(DisplayColumn))?:dispc;
  // The next line will result in an invalid pointer if ptr is zero,
  // but this is harmless, since ll_code is never accessed if ptr is zero.
  ll_code=realloc(ll_code,ptr*sizeof(Uint16))?:ll_code;
  for(i=0;i<LOCAL_HASH_SIZE;i++) free(hash[i].txt);
  free(hash);


















}

void load_classes(void) {
  int i;
  int gloptr=0;
  Hash*glolocalhash;
  char*nam=sqlite3_mprintf("%s.class",basefilename);







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
  free(aggrc);
  ll_disp=realloc(dispc,(ll_ndisp)*sizeof(DisplayColumn))?:dispc;
  // The next line will result in an invalid pointer if ptr is zero,
  // but this is harmless, since ll_code is never accessed if ptr is zero.
  ll_code=realloc(ll_code,ptr*sizeof(Uint16))?:ll_code;
  for(i=0;i<LOCAL_HASH_SIZE;i++) free(hash[i].txt);
  free(hash);
  if(main_options['C']) {
    printf("<<<LevelTable>>>\n  Data/Aggregate:\n");
    for(i=0;i<ll_ndata+ll_naggregate;i++) {
      printf("    %d: ",i);
      if(i<ll_ndata) printf(" \"%s\"",ll_data[i].name); else printf(" (%d)",ll_data[i].ag);
      printf(" 0x%04X %c\n",ll_data[i].ptr,ll_data[i].sgn?'s':'u');
    }
    printf("  Display:\n");
    for(i=0;i<ll_ndisp;i++) printf("    %d: data=%d width=%d format=%c%c color=%d flag=%d ptr=0x%04X\n",i
     ,ll_disp[i].data,ll_disp[i].width,ll_disp[i].form[0]?:' ',ll_disp[i].form[1]?:' ',ll_disp[i].color,ll_disp[i].flag,ll_disp[i].ptr);
    printf("  Codes:");
    for(i=0;i<ptr;i++) {
      if(!(i&15)) printf("\n    [%04X]",i);
      printf(" %04X",ll_code[i]);
    }
    putchar('\n');
    printf("---\n\n");
  }
}

void load_classes(void) {
  int i;
  int gloptr=0;
  Hash*glolocalhash;
  char*nam=sqlite3_mprintf("%s.class",basefilename);

Modified class.doc from [e3fcdbff9c] to [6d0262fd53].

2603
2604
2605
2606
2607
2608
2609

2610
2611
2612
2613
2614
2615
2616
2617
  no colums are fill width). The <format> is a string of exactly one or
  two characters; see the below list of possible formats. The <color> is
  the text colour, and is optional; it can be a number from 1 to 255, or
  it can be a sequence of parenthesized pairs of a number (-127 to +127)
  and colour, to mean use those colour if the value of this column is
  in range. It uses the colour for all values up to and including the
  specified number, so the numbers should be listed in ascending order,

  in order to work. The <string> is the heading; it is not allowed to
  include control characters, nor can it include graphic characters with
  code number less than 32.

(<local> <type> <code...>)
  Defines a aggregate calculation. The <local> is the name of the aggregate
  to be referred by other blocks (which must start with a percentage sign,
  like a local variable does). The <type> is the type of aggregate, which







>
|







2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
  no colums are fill width). The <format> is a string of exactly one or
  two characters; see the below list of possible formats. The <color> is
  the text colour, and is optional; it can be a number from 1 to 255, or
  it can be a sequence of parenthesized pairs of a number (-127 to +127)
  and colour, to mean use those colour if the value of this column is
  in range. It uses the colour for all values up to and including the
  specified number, so the numbers should be listed in ascending order,
  in order to work. If the last number is 127 then it is also use for all
  higher numbers too. The <string> is the heading; it is not allowed to
  include control characters, nor can it include graphic characters with
  code number less than 32.

(<local> <type> <code...>)
  Defines a aggregate calculation. The <local> is the name of the aggregate
  to be referred by other blocks (which must start with a percentage sign,
  like a local variable does). The <type> is the type of aggregate, which
2630
2631
2632
2633
2634
2635
2636
2637
2638





















(right aligned) as signed decimal (d), hexadecimal (x/X), octal (o),
unsigned decimal (u). The ones with "0" will pad by 0 instead of spaces,
and the "d-" and "d+" will display a left aligned sign.

If a numeric format is specified but it is a text value, then it is treated
as "L" instead, unless format is "R*" in which case it is treated as "R".

(TODO: Mention valid instructions.)





























|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
(right aligned) as signed decimal (d), hexadecimal (x/X), octal (o),
unsigned decimal (u). The ones with "0" will pad by 0 instead of spaces,
and the "d-" and "d+" will display a left aligned sign.

If a numeric format is specified but it is a text value, then it is treated
as "L" instead, unless format is "R*" in which case it is treated as "R".

Valid instructions in this block include:

 Arithmetic:  + - * ,* / ,/ mod ,mod Delta min ,min max ,max neg

 Bitwise:  band bor bxor bnot lsh rsh ,rsh

 Logical:  land lor lxor lnot

 Compare:  eq ne lt ,lt gt ,gt le ,le ge ,ge

 Misc:  Level _ in nin ret if else then

 Object:  Xloc Yloc Class Dir Misc1 Misc2 Misc3 Misc4 Misc5 Misc6 Misc7
   Temperature Density Player Input Bizarro CollisionLayers

Additionally, you can include numbers, strings (see below for their
meaning, which is different from the meaning in class codes), aggregate
names (with % at first), user flags (with ^ at first), class names, and
message names (both built-in messages and user messages are possible).
Accessing values of objects other than the current one is not possible.

(TODO: Usage of strings as instructions in this block.)

Modified function.c from [3ae0a5eecb] to [89407dfd1e].

1
2
3
4
5
6
7
8
9
10
11
12
13

14
15
16
17
18
19
20
#if 0
gcc ${CFLAGS:--s -O2} -c -fplan9-extensions function.c `sdl-config --cflags`
exit
#endif

#include "SDL.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite3.h"
#include "smallxrm.h"
#include "heromesh.h"
#include "cursorshapes.h"


typedef struct {
  struct sqlite3_vtab_cursor;
  sqlite3_int64 rowid;
  char unique,eof;
  Uint16 arg[4];
} Cursor;

|











>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#if 0
gcc ${CFLAGS:--s -O2} -c -fplan9-extensions -fwrapv function.c `sdl-config --cflags`
exit
#endif

#include "SDL.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sqlite3.h"
#include "smallxrm.h"
#include "heromesh.h"
#include "cursorshapes.h"
#include "instruc.h"

typedef struct {
  struct sqlite3_vtab_cursor;
  sqlite3_int64 rowid;
  char unique,eof;
  Uint16 arg[4];
} Cursor;
1208
1209
1210
1211
1212
1213
1214


















































































































1215
1216
1217





1218
1219






















1220





































































1221
1222
1223
1224
1225
1226
1227

typedef struct {
  Value misc1,misc2,misc3;
  Uint8 x,y,dir,bizarro;
  Uint16 class;
} ObjInfo;



















































































































static void calculate_level_column(sqlite3_stmt*st,const unsigned char*lvl,long sz) {
  ObjInfo ob;
  ObjInfo mru[2];





  mru[0].class=mru[1].class=0;
  ob.x=ob.y=ob.bizarro=0;






















  





































































}

static int vt1_levels_open(sqlite3_vtab*vt,sqlite3_vtab_cursor**cur) {
  sqlite3_str*str;
  sqlite3_stmt*st1;
  sqlite3_stmt*st2;
  const unsigned char*d;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|


>
>
>
>
>

|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438

typedef struct {
  Value misc1,misc2,misc3;
  Uint8 x,y,dir,bizarro;
  Uint16 class;
} ObjInfo;

#define ArithOp1(aa) ({ if(sp<1 || stack[sp-1].t) goto bad; Value t1=stack[sp-1]; stack[sp-1]=NVALUE(aa); })
#define ArithOp2(aa) ({ if(sp<2 || stack[sp-1].t || stack[sp-2].t) goto bad; Value t1=stack[sp-2]; Value t2=stack[sp-1]; sp--; stack[sp-1]=NVALUE(aa); })
#define ArithDivOp2(aa) ({ if(sp<2 || stack[sp-1].t || stack[sp-2].t || !stack[sp-1].u) goto bad; Value t1=stack[sp-2]; Value t2=stack[sp-1]; sp--; stack[sp-1]=NVALUE(aa); })
#define OtherOp1(aa) ({ if(sp<1) goto bad; Value t1=stack[sp-1]; stack[sp-1]=(aa); })
#define OtherOp2(aa) ({ if(sp<2) goto bad; Value t1=stack[sp-2]; Value t2=stack[sp-1]; sp--; stack[sp-1]=(aa); })

static inline Uint32 ll_in(Value*stack,Sint16 top,Sint16 m) {
  while(--top>m) if(stack[top].t==stack[m-1].t && stack[top].u==stack[m-1].u) return 1;
  return 0;
}

static Sint16 level_table_exec(Uint16 ptr,const unsigned char*lvl,long sz,ObjInfo*ob,Value*stack,Value*agg) {
  Sint16 sp=0;
  Uint32 k,m;
  while(sp<62) switch(ll_code[ptr++]) {
    case 0 ... 255: stack[sp++]=NVALUE(ll_code[ptr-1]); break;
    case 0x0200 ... 0x02FF: stack[sp++]=MVALUE(ll_code[ptr-1]&255); break;
    case 0x4000 ... 0x7FFF: stack[sp++]=CVALUE(ll_code[ptr-1]&0x3FFF); break;
    case 0xC000 ... 0xFFFF: stack[sp++]=MVALUE((ll_code[ptr-1]&0x3FFF)+256); break;
    case OP_ADD: ArithOp2(t1.u+t2.u); break;
    case OP_BAND: ArithOp2(t1.u&t2.u); break;
    case OP_BIZARRO: if(!ob) goto bad; stack[sp++]=NVALUE(ob->bizarro); break;
    case OP_BNOT: ArithOp1(~t1.u); break;
    case OP_BOR: ArithOp2(t1.u|t2.u); break;
    case OP_BXOR: ArithOp2(t1.u^t2.u); break;
    case OP_CLASS: if(!ob) goto bad; stack[sp++]=CVALUE(ob->class); break;
    case OP_COLLISIONLAYERS: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->collisionLayers); break;
    case OP_DELTA: ArithOp2(t1.u>t2.u?t1.u-t2.u:t2.u-t1.u); break;
    case OP_DENSITY: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->density); break;
    case OP_DIR: if(!ob) goto bad; stack[sp++]=NVALUE(ob->dir); break;
    case OP_DIV: ArithDivOp2(t1.u/t2.u); break;
    case OP_DIV_C: ArithDivOp2(t1.s/t2.s); break;
    case OP_EQ: OtherOp2(NVALUE((t1.u==t2.u && t1.t==t2.t)?1:0)); break;
    case OP_GE: ArithOp2(t1.u>=t2.u?1:0); break;
    case OP_GE_C: ArithOp2(t1.s>=t2.s?1:0); break;
    case OP_GOTO: ptr=ll_code[ptr]; break;
    case OP_GT: ArithOp2(t1.u>t2.u?1:0); break;
    case OP_GT_C: ArithOp2(t1.s>t2.s?1:0); break;
    case OP_IF:
      if(!sp--) goto bad;
      if(stack[sp].t || stack[sp].u) ptr++; else ptr=ll_code[ptr];
      break;
    case OP_IN: case OP_NIN:
      if(sp<2) goto bad;
      for(m=sp-1;m;m--) if(stack[m].t==TY_MARK) {
        k=ll_in(stack,sp,m);
        sp=m;
        stack[sp-1].t=TY_NUMBER;
        stack[sp-1].u=(ll_code[ptr-1]==OP_IN?0:1)^k;
      }
      if(!m) goto bad;
      break;
    case OP_INPUT: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->cflags&CF_INPUT?1:0); break;
    case OP_INT16: stack[sp++]=NVALUE(ll_code[ptr]); ptr++; break;
    case OP_INT32: stack[sp++]=NVALUE(ll_code[ptr+1]); stack[sp-1].u|=ll_code[ptr]<<16; ptr+=2; break;
    case OP_LAND: OtherOp2(NVALUE(((t1.u || t1.t) && (t2.u || t2.t))?1:0)); break;
    case OP_LE: ArithOp2(t1.u<=t2.u?1:0); break;
    case OP_LE_C: ArithOp2(t1.s<=t2.s?1:0); break;
    case OP_LEVEL: stack[sp++]=NVALUE(lvl[2]|(lvl[3]<<8)); break;
    case OP_LNOT: OtherOp1(NVALUE((t1.u || t1.t)?0:1)); break;
    case OP_LOCAL: if(!agg) goto bad; stack[sp++]=agg[ll_code[ptr++]]; break;
    case OP_LOR: OtherOp2(NVALUE((t1.u || t1.t || t2.u || t2.t)?1:0)); break;
    case OP_LSH: ArithOp2(t2.u&~31?0:t1.u<<t2.u); break;
    case OP_LT: ArithOp2(t1.u<t2.u?1:0); break;
    case OP_LT_C: ArithOp2(t1.s<t2.s?1:0); break;
    case OP_LXOR: OtherOp2(NVALUE(((t1.u || t1.t)?1:0)^((t2.u || t2.t)?1:0))); break;
    case OP_MARK: stack[sp++]=UVALUE(0,TY_MARK); break;
    case OP_MAX: ArithOp2(t1.u<t2.u?t2.u:t1.u); break;
    case OP_MAX_C: ArithOp2(t1.s<t2.s?t2.s:t1.s); break;
    case OP_MIN: ArithOp2(t1.u>t2.u?t2.u:t1.u); break;
    case OP_MIN_C: ArithOp2(t1.s>t2.s?t2.s:t1.s); break;
    case OP_MISC1: if(!ob) goto bad; stack[sp++]=ob->misc1; break;
    case OP_MISC2: if(!ob) goto bad; stack[sp++]=ob->misc2; break;
    case OP_MISC3: if(!ob) goto bad; stack[sp++]=ob->misc3; break;
    case OP_MISC4: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->misc4); break;
    case OP_MISC5: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->misc5); break;
    case OP_MISC6: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->misc6); break;
    case OP_MISC7: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->misc7); break;
    case OP_MOD: ArithDivOp2(t1.u%t2.u); break;
    case OP_MOD_C: ArithDivOp2(t1.s%t2.s); break;
    case OP_MUL: ArithOp2(t1.u*t2.u); break;
    case OP_MUL_C: ArithOp2(t1.s*t2.s); break;
    case OP_NE: OtherOp2(NVALUE((t1.u==t2.u && t1.t==t2.t)?0:1)); break;
    case OP_NEG: ArithOp1(-t1.s); break;
    case OP_PLAYER: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->cflags&CF_PLAYER?1:0); break;
    case OP_RET: return sp;
    case OP_RSH: ArithOp2(t2.u&~31?0:t1.u>>t2.u); break;
    case OP_RSH_C: ArithOp2(t2.u&~31?(t1.s<0?-1:0):t1.s>>t2.u); break;
    case OP_STRING:
      // If starting with @ then a literal string, otherwise match a part of the level title.
      //TODO
      break;
    case OP_SUB: ArithOp2(t1.u-t2.u); break;
    case OP_TEMPERATURE: if(!ob) goto bad; stack[sp++]=NVALUE(classes[ob->class]->temperature); break;
    case OP_USERFLAG:
      if(!ob) goto bad;
      if(ll_code[ptr]<0x1020) k=classes[ob->class]->misc4;
      else if(ll_code[ptr]<0x1040) k=classes[ob->class]->misc5;
      else if(ll_code[ptr]<0x1060) k=classes[ob->class]->misc6;
      else if(ll_code[ptr]<0x1080) k=classes[ob->class]->misc7;
      else k=classes[ob->class]->collisionLayers;
      stack[sp].t=TY_NUMBER;
      stack[sp].u=(k&(1LL<<(ll_code[ptr++]&31)))?1:0;
      sp++;
      break;
    case OP_XLOC: if(!ob) goto bad; stack[sp++]=NVALUE(ob->x); break;
    case OP_YLOC: if(!ob) goto bad; stack[sp++]=NVALUE(ob->y); break;
    default: goto bad;
  }
  bad:
  if(main_options['v']) fprintf(stderr,"Error in LevelTable definition (at 0x%04X)\n",ptr);
  return -1;
}

static void calculate_level_columns(sqlite3_stmt*st,const unsigned char*lvl,long sz) {
  ObjInfo ob;
  ObjInfo mru[2];
  Value stack[64];
  Value agg[64];
  int i,j,n,z;
  const unsigned char*end=lvl+sz;
  const unsigned char*p;
  mru[0].class=mru[1].class=0;
  ob.x=ob.bizarro=ob.class=0; ob.y=1;
  n=0;
  for(i=0;i<64;i++) agg[i]=UVALUE(1,TY_MARK);
  p=lvl+6;
  while(*p && p<end) p++; // skip text for now
  if(p>=end) return;
  p++; // skip null terminator
  // Object loop
  if(ll_naggregate) while(p<end) {
    if(n) {
      ob.class=mru->class;
      ob.misc1=mru->misc1;
      ob.misc2=mru->misc2;
      ob.misc3=mru->misc3;
      ob.dir=mru->dir;
      n--;
      ob.x++;
    } else {
      z=*p++;
      if(z==0xFF) break;
      if(z==0xFE) {
        ob.x=0; ob.y=1; ob.bizarro^=1;
        continue;
      }
      if(z&0x20) ob.x=*p++;
      if(z&0x10) ob.y=*p++;
      if(z&0x40) ob.x++;
      n=z&0x70?0:1;
      if(z&0x80) {
        // MRU
        ob.class=mru[n].class;
        ob.misc1=mru[n].misc1;
        ob.misc2=mru[n].misc2;
        ob.misc3=mru[n].misc3;
        ob.dir=mru[n].dir;
        n=z&15;
      } else {
        // Not MRU
        i=*p++;
        i|=*p++<<8;
        ob.class=i&0x3FFF;
        if(!classes[ob.class]) {
          if(main_options['v']) fprintf(stderr,"Class %d at 0x%X (while loading level table aggregate values) not valid\n",ob.class,(int)(p-lvl));
          return;
        }
        if(!(i&0x8000)) p++;
        ob.dir=z&7;
        ob.misc1=ob.misc2=ob.misc3=NVALUE(0);
        if(z&8) {
          z=*p++;
          if(z&0xC0) ob.misc1=UVALUE(p[0]|(p[1]<<8),(z>>0)&3),p+=2;
          if((z&0xC0)!=0x40) ob.misc2=UVALUE(p[0]|(p[1]<<8),(z>>2)&3),p+=2;
          if(!((z&0xC0)%0xC0)) ob.misc3=UVALUE(p[0]|(p[1]<<8),(z>>4)&3),p+=2;
        }
        if(n!=2) {
          mru[n].class=ob.class;
          mru[n].misc1=ob.misc1;
          mru[n].misc2=ob.misc2;
          mru[n].misc3=ob.misc3;
          mru[n].dir=ob.dir;
        }
        n=0;
      }
    }
    for(i=ll_ndata;i<ll_naggregate+ll_ndata;i++) {
      j=level_table_exec(ll_data[i].ptr,lvl,sz,&ob,stack,0);
      if(j<0) return;
      if(!j) continue;
      z=ll_data[i].sgn;
      if(agg[i-ll_ndata].t==TY_MARK) {
        agg[i-ll_ndata]=*stack;
      } else if(stack->t==TY_NUMBER && agg[i-ll_ndata].t==TY_NUMBER) switch(ll_data[i].ag) {
        case 1: agg[i-ll_ndata].u+=stack->u; break;
        case 2: if(z?(stack->s<agg[i-ll_ndata].s):(stack->u<agg[i-ll_ndata].u)) agg[i-ll_ndata]=*stack; break;
        case 3: if(z?(stack->s>agg[i-ll_ndata].s):(stack->u>agg[i-ll_ndata].u)) agg[i-ll_ndata]=*stack; break;
      }
    }
  }
  // Data column values
  for(i=0;i<ll_ndata;i++) {
    j=level_table_exec(ll_data[i].ptr,lvl,sz,0,stack,agg);
    if(j<=0 || stack->t==TY_MARK) {
      sqlite3_bind_null(st,i+8);
    } else if(j>1 && (stack->t==TY_STRING || stack->t==TY_FOR)) {
      //TODO
    } else if(stack->t==TY_FOR) {
      sqlite3_bind_blob(st,i+8,lvl+(stack->u>>16)+6,stack->u&0xFFFF,SQLITE_TRANSIENT);
    } else if(stack->t==TY_STRING) {
      sqlite3_bind_blob(st,i+8,stringpool[stack->u]+1,strlen(stringpool[stack->u]+1),0);
    } else {
      if(ll_data[i].sgn) sqlite3_bind_int64(st,i+8,stack->s); else sqlite3_bind_int64(st,i+8,stack->u); break;
    }
  }
}

static int vt1_levels_open(sqlite3_vtab*vt,sqlite3_vtab_cursor**cur) {
  sqlite3_str*str;
  sqlite3_stmt*st1;
  sqlite3_stmt*st2;
  const unsigned char*d;
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
    if(n<7 || !d) continue;
    sqlite3_bind_int(st2,2,d[2]|(d[3]<<8));
    sqlite3_bind_int(st2,3,(d[4]&63)+1);
    sqlite3_bind_int(st2,4,(d[5]&63)+1);
    for(i=6;i<n && d[i];i++);
    j=d[0]|(d[1]<<8);
    sqlite3_bind_blob(st2,5,d+6,i-6,0);
    calculate_level_column(st2,d,n);
    p=read_lump(FIL_SOLUTION,sqlite3_column_int(st1,0),&n);
    if(p) {
      sqlite3_bind_int(st2,7,(n>2 && d[0]==p[0] && d[1]==p[1]));
      free(p);
    } else {
      sqlite3_bind_int(st2,7,0);
    }







|







1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
    if(n<7 || !d) continue;
    sqlite3_bind_int(st2,2,d[2]|(d[3]<<8));
    sqlite3_bind_int(st2,3,(d[4]&63)+1);
    sqlite3_bind_int(st2,4,(d[5]&63)+1);
    for(i=6;i<n && d[i];i++);
    j=d[0]|(d[1]<<8);
    sqlite3_bind_blob(st2,5,d+6,i-6,0);
    calculate_level_columns(st2,d,n);
    p=read_lump(FIL_SOLUTION,sqlite3_column_int(st1,0),&n);
    if(p) {
      sqlite3_bind_int(st2,7,(n>2 && d[0]==p[0] && d[1]==p[1]));
      free(p);
    } else {
      sqlite3_bind_int(st2,7,0);
    }

Modified game.c from [b19cf21fe8] to [7219595d81].

735
736
737
738
739
740
741
742




743
744
745
746
747
748
749
    if(dc->form[0]=='R') a=w-i;
    if(dc->flag&2) co=0xFF;
  } else {
    // This implementation does not check that the format is necessarily valid.
    // You should not rely on the use of any undocumented format.
    v=sqlite3_column_int64(st,nc);
    if(dc->flag&2) {
      //TODO: colours




    }
    switch(dc->form[0]) {
      case 'L': case 'R':
        if(dc->form[1]) {
          if(v<0 || v>w) v=w;
          memset(buf,dc->form[1],v);
          buf[v]=0;







|
>
>
>
>







735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
    if(dc->form[0]=='R') a=w-i;
    if(dc->flag&2) co=0xFF;
  } else {
    // This implementation does not check that the format is necessarily valid.
    // You should not rely on the use of any undocumented format.
    v=sqlite3_column_int64(st,nc);
    if(dc->flag&2) {
      co=0xFF;
      for(i=0;i<dc->color;i++) if(ll_code[dc->ptr+i]>=0xFF00 || v+128<=(ll_code[dc->ptr+i]>>8)) {
        co=ll_code[dc->ptr+i]&0xFF;
        break;
      }
    }
    switch(dc->form[0]) {
      case 'L': case 'R':
        if(dc->form[1]) {
          if(v<0 || v>w) v=w;
          memset(buf,dc->form[1],v);
          buf[v]=0;