Free Hero Mesh

Diff
Login
This is a mirror of the main repository for Free Hero Mesh. New tickets and changes will not be accepted at this mirror.

Differences From Artifact [db5cb1b03f]:

To Artifact [3ffe8990f0]:


42
43
44
45
46
47
48









49
50
51
52
53
54
55
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64







+
+
+
+
+
+
+
+
+







  "CREATE UNIQUE INDEX IF NOT EXISTS `USERCACHEDATA_I1` ON `USERCACHEDATA`(`FILE`, `LEVEL`);"
  "CREATE TRIGGER IF NOT EXISTS `USERCACHEINDEX_DELETION` AFTER DELETE ON `USERCACHEINDEX` BEGIN DELETE FROM `USERCACHEDATA` WHERE `FILE` = OLD.`ID`; END;"
  "CREATE TEMPORARY TABLE `PICTURES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT COLLATE NOCASE, `OFFSET` INT, `DEPENDENT` INT, `MISC` BLOB);"
  "CREATE TEMPORARY TABLE `VARIABLES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT);"
  "CREATE TEMPORARY TABLE `DIVISIONS`(`HEADING` BLOB NOT NULL, `FIRST` INT NOT NULL);"
  "COMMIT;"
;

const char jispunct[0x60]=
  "  ,.,. :;?!  '` "
  "^~_         ---/"
  "\\~||  ''\"\"()  []"
  "{}<>        +-  "
  " = <>       '\" \\"
  "$ #%#&*@        "
;

sqlite3*userdb;
xrm_db*resourcedb;
const char*basefilename;
xrm_quark optionquery[16];
char main_options[128];
Uint8 message_trace[0x4100/8];
762
763
764
765
766
767
768














































































































































769
770
771
772
773
774
775
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







}

void set_cursor(int id) {
  id>>=1;
  if(!cursor[id]) cursor[id]=SDL_CreateCursor((void*)cursorimg+(id<<6),(void*)cursorimg+(id<<6)+32,16,16,cursorhot[id]>>4,cursorhot[id]&15);
  SDL_SetCursor(cursor[id]);
}

Uint32*tron8to32(const Uint8*si) {
  // This function does not interpret the internal-only 0xFF code, which will be implemented in picture.c instead.
  Uint16 cs=0;
  int n=0;
  Uint32*so=0;
  int k=0;
  if(*si==0xFE) {
    // TRON
    for(k=0;si[k];k++) {
      if(si[k]==31 && si[k+1]) {
        n+=2;
        k++;
      } else if(si[k]==14 || si[k]==30) {
        while(si[k] && si[k]!='\\') {
          n+=2;
          k++;
        }
        n+=2;
      } else if(si[k]==0xFE) {
        n--;
        while(si[k+1]==0xFE) k++;
      } else {
        n++;
        if(si[k]<=0x20) n++;
      }
    }
    so=calloc(sizeof(Uint32),(n>>=1)+2);
    if(!so) fatal("Allocation failed\n");
    n++; k=0;
    while(*si && k<n) {
      if(*si==0xFE) {
        cs=-0x100;
        while(*si==0xFE) cs+=0x100,si++;
        if(*si) cs|=*si++;
      } else if((*si==16 || *si==31 || *si==127) && si[1]) {
        so[k++]=(si[0]<<8)|si[1];
        si+=2;
      } else if(*si==14 || *si==30) {
        while(*si && *si!='\\' && *si!=0xFE) so[k++]=*si++;
        if(*si=='\\') so[k++]=*si++;
      } else if(*si<=0x20) {
        so[k++]=*si++;
      } else if(*si<0xFE && si[1]<0xFE && si[1]>0x20) {
        so[k++]=(si[0]<<8)|si[1]|(cs<<16);
        si+=2;
      } else {
        si++;
      }
    }
  } else {
    // ASCII
    so=calloc(sizeof(Uint32),(n=strlen(si))+1);
    if(!so) fatal("Allocation failed\n");
    while(*si) {
      if(*si==16 || *si==31 || *si==127) {
        if(!si[1]) break;
        so[k++]=(si[0]<<8)|si[1];
        si+=2;
      } else {
        so[k++]=*si++;
      }
    }
  }
  return so;
}

Uint8*tron32to8(const Uint32*si) {
  Uint16 cs=0;
  int i;
  Uint8*so=0;
  size_t sz=0;
  FILE*f=open_memstream((char**)&so,&sz);
  if(!f) fatal("Allocation failed\n");
  for(i=0;si[i];i++) if(si[i]>0x200000) goto nonascii;
  while(*si) {
    if(*si<0x7F) {
      fputc(*si++,f);
    } else if(*si>=0x1000 && *si<=0x10FF) {
      fputc(16,f);
      fputc((*si++&0xFF)?:0x20,f);
    } else if(*si>=0x1F00 && *si<=0x1FFF) {
      fputc(31,f);
      fputc((*si++&0xFF)?:0xFF,f);
    } else if(*si>=0x7F20 && *si<0x7F7F) {
      fputc('%',f);
      fputc(*si++&0xFF,f);
    }
  }
  nonascii:
  while(*si) {
    if(*si>0x200000) {
      if(cs!=(*si>>16)) {
        cs=*si>>16;
        for(i=cs>>8;i>=0;i--) fputc(0xFE,f);
        fputc(cs,f);
      }
      fputc(*si>>8,f);
      fputc(*si++,f);
    } else if(*si<0x21) {
      fputc(i=*si++,f);
      if(i==14 || i==30) while(*si) {
        if(*si=='\\') {
          fputc(*si++,f);
          break;
        } else if(*si<0xFE || (*si>=0x702221 && *si<0x70227F) || (*si>=0x212330 && *si<0x21237B)) {
          fputc(*si++,f);
        } else if(*si>=0x212121 && *si<0x21217F) {
          fputc(jispunct[*si++-0x212120],f);
        } else if(*si<0xFE) {
          fputc(*si++,f);
        } else {
          fputc(' ',f);
          si++;
        }
      }
    } else if(*si<0x7F) {
      if(cs!=0x70) {
        cs=0x70;
        fputc(0xFE,f);
        fputc(0x70,f);
      }
      fputc(0x22,f);
      fputc(*si++,f);
    } else if(*si>=0x1000 && *si<=0x10FF) {
      fputc(16,f);
      fputc(*si++?:0x20,f);
    } else if(*si>=0x1F00 && *si<=0x1FFF) {
      fputc(31,f);
      fputc(*si++?:0xFF,f);
    } else if(*si>=0x7F20 && *si<0x7F7F) {
      fputc(127,f);
      fputc(*si++,f);
    } else {
      si++;
    }
  }
  fputc(0,f);
  fclose(f);
  if(!so) fatal("Allocation failed\n");
  return so;
}

static void set_path(const char*arg) {
  const char*s;
  if(main_options['h']) goto home;
  if((s=getenv("HEROMESH_PREFIX")) && *s) {
    hpath=malloc(strlen(s)+32);
    if(!hpath) fatal("Allocation failed\n");
850
851
852
853
854
855
856
857
858
859

860
861
862
863
864
865

866
867
868






869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886














887
888
889
890
891
892
893
1001
1002
1003
1004
1005
1006
1007



1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063







-
-
-
+






+



+
+
+
+
+
+


















+
+
+
+
+
+
+
+
+
+
+
+
+
+







  SDL_UnlockSurface(screen);
  SDL_Flip(screen);
  while(SDL_WaitEvent(&ev)) switch(ev.type) {
    case SDL_KEYDOWN:
      switch(ev.key.keysym.sym) {
        case SDLK_BACKSPACE:
          n/=10;
          snprintf(buf,30,"%u",n);
          SDL_WM_SetCaption(buf,buf);
          break;
          goto setnum;
        case SDLK_SPACE:
          n=0;
          SDL_WM_SetCaption("0","0");
          break;
        case SDLK_0 ... SDLK_9:
          n=10*n+ev.key.keysym.sym-SDLK_0;
        setnum:
          snprintf(buf,30,"%u",n);
          SDL_WM_SetCaption(buf,buf);
          break;
        case SDLK_KP_MINUS:
          if(n) n--;
          goto setnum;
        case SDLK_KP_PLUS:
          n++;
          goto setnum;
        case SDLK_c:
          SDL_FillRect(screen,0,n);
          SDL_Flip(screen);
          break;
        case SDLK_e:
          n=1;
          goto keytest;
        case SDLK_g:
          n=0;
          goto keytest;
        case SDLK_i:
          SDL_FillRect(screen,0,5);
          for(i=j=0;;i++) {
            if(picture_size*(i+1)>screen->w) i=0,j++;
            if(picture_size*(j+1)>screen->h) break;
            draw_picture(picture_size*i,picture_size*j,n++);
          }
          SDL_Flip(screen);
          break;
        case SDLK_o:
          if(n<0x4000 && classes[n] && classes[n]->gamehelp) {
            Uint32*a=tron8to32(classes[n]->gamehelp);
            Uint8*b=tron32to8(a);
            for(i=0;classes[n]->gamehelp[i];i++) printf("%02X ",classes[n]->gamehelp[i]&0xFF);
            puts(";");
            for(i=0;a[i];i++) printf("%08X ",a[i]);
            puts(";");
            for(i=0;b[i];i++) printf("%02X ",b[i]);
            puts(".");
            free(a);
            free(b);
          }
          break;
        case SDLK_p:
          sqlite3_exec(userdb,"SELECT * FROM `PICTURES`;",test_sql_callback,0,0);
          break;
        case SDLK_q:
          exit(0);
          break;
1139
1140
1141
1142
1143
1144
1145

1146
1147
1148
1149
1150
1151
1152
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323







+







    return 0;
  }
  if(main_options['z']) init_composite();
  load_pictures();
  if(main_options['T']) {
    printf("argv[0] = %s\n",argv[0]);
    init_sound();
    if(main_options['+']) load_classes();
    test_mode();
    return 0;
  }
  if(main_options['n']) {
    new_puzzle_set();
    return 0;
  }