compile as C
[rofl0r-GfxRip.git] / GfxRip.c
blob1423c066de11e1ab86ad29e6ba78cfe3d9fdf507
1 // #define ALLEGRO_STATICLINK
3 #include <allegro.h>
4 #include "winalleg.h"
5 #include "tdgui.h"
6 #include <stdio.h>
7 #include <string.h>
8 #include <stdbool.h>
10 volatile int target_game_time = 0;
12 int fsize;
13 FILE * file;
15 unsigned char * mem = 0;
17 #define scrW 800
18 #define scrH 600
20 #define hole 2
21 #define legend 9
23 int offset = 0;
24 //int offset = 1322704;
25 int blXSize = 320/8;
26 int blYSize = 200;
27 //int blYSize = 112;
29 int contin_save = 1;
31 int bits = 1;
32 //int bits = 8;
34 int skip = 0;
35 int skipmode = 0; // 0 = skip bytes after picture , 1 = skip bytes after each bitplane
36 char skipmoder;
38 bool reverse = false;
39 int mode = 0;
40 int palsearchmode = 2;
42 char pmoder[4] = { 'S', 'X', 'E', 'A' };
44 BITMAP * bitmap;
46 RGB pal[256];
48 int numX;
49 int numY;
51 bool zoom = false;
53 char goto_num[255];
55 int ttt=0;
56 int palfound = 0;
58 int bplorder[8] = {0,1,2,3,4,5,6,7};
60 char gotottt[256] = "Go To BYTE:";
62 DIALOG goto_dialog[] =
64 /* (dialog proc) (x) (y) (w) (h) (fg)(bg) (key) (flags) (d1) (d2) (dp) */
65 { d_billwin_proc, 0, 0, 180, 60, 255, 0, 0, 0,
66 BW_BUFFEREDUPDATE, 0, gotottt },
68 { d_billbutton_proc, 100, 28, 70, 15, 255, 0, 27, D_EXIT, 0, 0, "DONE"},
70 { d_billedit_proc, 10, 30, 70, 12, 0, 0, 0, 0, 8, 0, goto_num },
72 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL }
75 char save_name[255] = "p.bmp";
76 char save_x[255] = "1";
77 char save_y[255] = "1";
78 char save_border[255] = "0";
79 char save_bcolor[255] = "253";
81 DIALOG save_dialog[] =
83 /* (dialog proc) (x) (y) (w) (h) (fg)(bg) (key) (flags) (d1) (d2) (dp) */
84 { d_billwin_proc, 0, 0, 320, 130, 255, 0, 0, 0,
85 BW_BUFFEREDUPDATE, 0, "Save Picture(s)" },
87 { d_billbutton_proc, 210, 105, 70, 15, 255, 0, 27, D_EXIT, 0, 0, "EXIT"},
89 { d_billtext_proc, 10, 23, 0, 0, 0, 0, 0, 0, 0, 0, "Filename:" },
90 { d_billedit_proc, 90, 21, 220, 12, 0, 0, 0, 0, 200, 0, save_name },
92 { d_billtext_proc, 10, 50, 0, 0, 0, 0, 0, 0, 0, 0, "Pictures in X:" },
93 { d_billedit_proc, 130, 48, 40, 12, 0, 0, 0, 0, 8, 0, save_x },
95 { d_billtext_proc, 10, 70, 0, 0, 0, 0, 0, 0, 0, 0, "Pictures in Y:" },
96 { d_billedit_proc, 130, 68, 40, 12, 0, 0, 0, 0, 8, 0, save_y },
98 { d_billtext_proc, 190, 40, 0, 0, 0, 0, 0, 0, 0, 0, "Save Direction:" },
99 { d_billradio_proc, 190, 55, 60, 12, 0, 0, 0,D_SELECTED, 0, 0, "Left -> Right" },
100 { d_billradio_proc, 190, 70, 60, 12, 0, 0, 0, 0, 0, 0, "Up -> Down" },
102 { d_billbutton_proc, 40, 105, 70, 15, 255, 0, 27, D_EXIT, 0, 0, "SAVE"},
104 { d_billtext_proc, 10, 90, 0, 0, 0, 0, 0, 0, 0, 0, "Border Around:" },
105 { d_billedit_proc, 130, 88, 40, 12, 0, 0, 0, 0, 8, 0, save_border },
107 { d_billtext_proc, 185, 90, 0, 0, 0, 0, 0, 0, 0, 0, "Colour:" },
108 { d_billedit_proc, 250, 88, 40, 12, 0, 0, 0, 0, 8, 0, save_bcolor },
110 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL }
113 int getpixelcol(int pos, int x, int y)
115 bool bit[8];
116 int p;
117 int byte1;
118 int bit1;
119 int nn;
120 int bitn;
121 int i;
123 for (i=0; i < 8; i++)
125 bit[i]=false;
128 for (i=0; i < bits; i++)
130 switch (mode)
132 case 0:
133 // Amiga type bitplanes
134 p = pos+(blXSize*blYSize)*(i);
135 nn = x+(y*(blXSize*8));
136 break;
137 case 1:
138 // ST Type bitplanes
139 p = pos+blXSize*(i);
140 nn = x+(bits*y*(blXSize*8));
141 break;
142 case 2:
143 // mode == 2 // Amiga Sprite !!!
144 if (i < 2)
146 p = pos+blXSize*(i);
147 nn = x+((2*y)*(blXSize*8));
149 else
151 p = pos+blXSize*(i-2)+(blYSize*blXSize)*2;
152 nn = x+((2*y)*(blXSize*8));
154 break;
155 case 3:
156 // mode == 3 // CPC gfx for Bat-Man / HoH
157 p = pos+(x/8)+i;
158 nn = x+((2*y)*(blXSize*8));
159 break;
160 case 4:
161 // mode ==4 // CPC gfx for Ultimate games
162 p = pos+(x/4)+(blXSize*y*2);
163 nn = (i*4)+x%4;
164 break;
166 if (skipmode == 1)
168 p+=skip*i;
170 byte1 = nn/8;
171 bit1 = 7-(nn%8);
172 if (reverse)
174 bitn = (bits-i)-1;
176 else
178 bitn = i;
180 if (p+byte1 < fsize)
182 if (mem[p+byte1] & (1 << bit1))
184 bit[bitn] = true;
186 else
188 bit[bitn] = false;
191 else
193 bit[bitn] = false;
196 int col = 0;
197 for (i=0; i < bits; i++)
199 if (bit[bplorder[i]])
201 col+=1<<i;
204 return col;
207 void drawbitmap(BITMAP * bmp, int pos, int xx, int yy)
209 for (int x = 0; x < blXSize*8; x ++)
211 for (int y = 0; y < blYSize; y++)
213 putpixel(bmp, xx+x, yy+y, getpixelcol(pos, x, y));
218 void drawstuff()
220 int xx, yy;
222 int pos = offset;
224 for (int y=0; y < numY; y++)
226 for (int x=0; x < numX; x++)
228 xx = x*(blXSize*8+hole);
229 yy = legend+y*(blYSize+hole);
231 drawbitmap(bitmap, pos, xx, yy);
232 // pos+=((blXSize*blYSize)*bits)+skip;
233 if (skipmode == 0)
235 pos+=((blXSize*blYSize)*bits)+skip;
237 else
239 pos+=((blXSize*blYSize+skip)*bits);
245 void draw_zoom()
247 int xx, yy;
249 xx = scrW-(blXSize*8*2+4);
250 yy = scrH-(blYSize*2+4);
252 if (xx < scrW/2)
254 xx = scrW/2;
256 if (yy < scrH/2)
258 yy = scrH/2;
260 stretch_blit(bitmap, bitmap, 0, legend, blXSize*8, blYSize, xx+2, yy+2, blXSize*8*2, blYSize*2);
261 rect(bitmap,xx,yy,scrW-1,scrH-1,makecol(0,0,255));
262 rect(bitmap,xx+1,yy+1,scrW-2,scrH-2,253);
265 static BITMAPINFO *get_bitmap_info(BITMAP * bitmap, PALETTE pal)
267 BITMAPINFO *bi;
268 int x;
269 int bpp;
271 bi = (BITMAPINFO *)malloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 256);
273 bpp = 8;
275 ZeroMemory(&bi->bmiHeader, sizeof(BITMAPINFOHEADER));
277 bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
278 bi->bmiHeader.biBitCount = 8;
279 bi->bmiHeader.biPlanes = 1;
280 bi->bmiHeader.biWidth = bitmap->w;
281 bi->bmiHeader.biHeight = -bitmap->h;
282 bi->bmiHeader.biClrUsed = 256;
283 bi->bmiHeader.biCompression = BI_RGB;
285 if (pal) {
286 for (x = 0; x < 256; x++) {
287 bi->bmiColors[x].rgbRed = _rgb_scale_6[pal[x].r];
288 bi->bmiColors[x].rgbGreen = _rgb_scale_6[pal[x].g];
289 bi->bmiColors[x].rgbBlue = _rgb_scale_6[pal[x].b];
290 bi->bmiColors[x].rgbReserved = 0;
294 return bi;
298 static BYTE *get_dib(BITMAP * bitmap)
300 int bpp;
301 int y;
302 int pitch;
303 BYTE *pixels;
305 bpp = 8;
306 pitch = bitmap->w;
307 pitch = (pitch + 3) & ~3; /* align on dword */
309 pixels = (BYTE *) malloc(bitmap->h * pitch);
310 if (!pixels)
311 return NULL;
313 /* this code will probably need optimalization. if anybody can
314 * optimalize it, do so!
316 for (y = 0; y < bitmap->h; y++) {
317 memcpy(pixels + y * pitch, bitmap->line[y], bitmap->w);
319 return pixels;
322 #if 0
323 HBITMAP convert_bitmap_to_hbitmap2(BITMAP * bitmap)
325 HDC hdc;
326 HBITMAP hbmp;
327 BITMAPINFO *bi;
328 HPALETTE hpal, holdpal;
329 BYTE *pixels;
331 pixels = get_dib(bitmap);
333 /* when we have DIB, we can convert it to DDB */
334 hdc = GetDC(NULL);
336 bi = get_bitmap_info(bitmap, _current_palette);
338 hpal = convert_palette_to_hpalette(_current_palette);
339 holdpal = SelectPalette(hdc, hpal, TRUE);
340 RealizePalette(hdc);
341 hbmp = CreateDIBitmap(hdc, &bi->bmiHeader, CBM_INIT, pixels, bi, DIB_RGB_COLORS);
342 ReleaseDC(NULL, hdc);
344 SelectPalette(hdc, holdpal, TRUE);
345 DeleteObject(hpal);
347 free(pixels);
348 free(bi);
350 return hbmp;
352 #endif
354 void copyBitmapToClipboard(BITMAP *bmp) {
355 #if 0
356 if (OpenClipboard(win_get_window())) {
357 if (EmptyClipboard()) {
358 HBITMAP hbmp = convert_bitmap_to_hbitmap2(bmp);
359 if (hbmp) {
360 if (!SetClipboardData(CF_BITMAP, hbmp)) {
361 DeleteObject(hbmp);
363 CloseClipboard();
367 #endif
370 void copy_to_clip()
372 BITMAP * bm = create_bitmap(blXSize*8, blYSize);
374 blit(bitmap, bm, 0, legend, 0, 0, blXSize*8, blYSize);
376 copyBitmapToClipboard(bm);
378 destroy_bitmap(bm);
382 void refresh()
384 clear_to_color(bitmap, 253);
386 text_mode(-1);
388 numX = scrW/(blXSize*8+hole);
389 numY = (scrH-legend)/(blYSize+hole);
391 if (numX == 0)
393 numX = 1;
395 if (numY == 0)
397 numY= 1;
399 char rev;
400 if (reverse)
402 rev = 'R';
404 else
406 rev = 'N';
409 char moder[3];
410 switch (mode)
412 case 0:
413 strcpy(moder, "AM");
414 break;
415 case 1:
416 strcpy(moder, "ST");
417 break;
418 case 2:
419 strcpy(moder, "SP");
420 break;
421 case 3:
422 strcpy(moder, "C+");
423 break;
424 case 4:
425 strcpy(moder, "C-");
426 break;
428 if (skipmode == 0)
430 skipmoder = 'P';
432 else
434 skipmoder = 'B';
436 textprintf(bitmap, font, 0, 0, 254, "Off:%7i Siz: X:%4i Y:%4i Bit:%i Vis.X:%2i Y:%2i Pal%c:%7i Mode:%s Skip-%c:%4i Order:%c %i%i%i%i%i%i%i%i", offset,blXSize*8, blYSize, bits, numX, numY, pmoder[palsearchmode], palfound, moder, skipmoder, skip, rev,
437 bplorder[7], bplorder[6], bplorder[5], bplorder[4], bplorder[3], bplorder[2], bplorder[1], bplorder[0] );
439 drawstuff();
441 if (zoom)
443 draw_zoom();
446 blit(bitmap, screen, 0, 0, 0, 0, scrW, scrH);
449 void genpal()
451 srand(1);
452 for (int i=0; i < 256; i++)
454 pal[i].r = rand()%64;
455 pal[i].g = rand()%64;
456 pal[i].b = rand()%64;
458 pal[1].r = pal[1].g = pal[1].b = 0;
459 pal[0].r = pal[0].g = pal[0].b = 63;
460 pal[254].r = pal[254].g = pal[254].b = 0;
461 pal[253].r = pal[253].g = pal[253].b = 50;
462 pal[253].b = 53;
464 int parse_number(char * str)
466 int t;
468 if (str[0] == 0)
470 return 0;
472 sscanf(str, "%d", &t);
473 return t;
476 void goto_bye()
478 sprintf(gotottt, "Go To BYTE:");
480 sprintf(goto_num, "%i", offset);
481 unscare_mouse();
483 init_moveable(goto_dialog);
485 show_mouse(screen);
487 do_dialog (goto_dialog, 0);
489 shutdown_moveable(goto_dialog);
491 scare_mouse();
493 offset = parse_number(goto_num);
496 void skip_bye()
498 sprintf(gotottt, "Skip Value:");
500 sprintf(goto_num, "%i", offset);
501 unscare_mouse();
503 init_moveable(goto_dialog);
505 show_mouse(screen);
507 do_dialog (goto_dialog, 0);
509 shutdown_moveable(goto_dialog);
511 scare_mouse();
513 skip = parse_number(goto_num);
516 void prepare_save_name()
518 char temp[256];
519 char temp2[256];
520 int t;
521 bool ok;
523 strcpy(temp, save_name);
524 t = strlen(temp);
526 while (t >= 0 && temp[t] != '.')
528 t--;
530 temp[t] = 0;
531 ok = false;
532 if (t > 3)
534 if (temp[t-1] >= '0' && temp[t-1] <= '9' &&
535 temp[t-2] >= '0' && temp[t-2] <= '9' &&
536 temp[t-3] >= '0' && temp[t-3] <= '9')
538 ok = true;
541 if (!ok)
543 strcat(temp, "000.bmp");
544 contin_save = 1;
546 else
548 sprintf(temp2, "%03i.bmp", contin_save);
549 temp[t-3] = 0;
550 strcat(temp, temp2);
551 contin_save++;
553 strcpy(save_name,temp);
556 void save(bool cont)
558 int t;
560 if (cont)
562 prepare_save_name();
565 unscare_mouse();
567 init_moveable(save_dialog);
569 show_mouse(screen);
571 t = do_dialog (save_dialog, 0);
573 shutdown_moveable(save_dialog);
575 scare_mouse();
577 if (t != 1)
579 int numX = parse_number(save_x);
580 int numY = parse_number(save_y);
581 int border = parse_number(save_border);
582 int bcolor = parse_number(save_bcolor);
583 if (numX < 1)
585 numX = 1;
587 if (numY < 1)
589 numY = 1;
591 bool direction = false;
592 if (save_dialog[9].flags & D_SELECTED)
594 direction = true;
596 int xs = (blXSize*8+border)*numX;
597 int ys = (blYSize+border)*numY;
599 BITMAP * temp = create_bitmap(xs, ys);
601 clear_to_color(temp, bcolor);
603 int xx, yy;
604 int pos = offset;
606 if (!direction)
608 for (int x=0; x < numX; x++)
610 for (int y=0; y < numY; y++)
612 xx = x*(blXSize*8+border);
613 yy = y*(blYSize+border);
615 drawbitmap(temp, pos, xx, yy);
616 pos+=(blXSize*blYSize)*bits+skip;
620 else
622 for (int y=0; y < numY; y++)
624 for (int x=0; x < numX; x++)
626 xx = x*(blXSize*8+border);
627 yy = y*(blYSize+border);
629 drawbitmap(temp, pos, xx, yy);
630 pos+=(blXSize*blYSize)*bits+skip;
635 if (exists(save_name))
637 if ( billalert("Question!",
638 "This file already exists !",
639 "Do you want to overwrite it ?",
640 "NO", "YES", 27, 0) == 2)
642 save_bmp(save_name, temp, pal);
643 destroy_bitmap(temp);
645 return;
647 save_bmp(save_name, temp, pal);
648 destroy_bitmap(temp);
652 void grab_uae()
654 // Simpler method to find palettes !
655 bool found = false;
656 while (!found && ttt < fsize-64)
658 if (mem[ttt] == 0x01 && mem[ttt+1] == 0x80 && mem[ttt+4] == 0x01 && mem[ttt+5] == 0x82)
660 found = true;
661 palfound = ttt;
662 int c1, c2;
663 int r,g,b;
664 for (int i=0; i < 32; i++)
666 c1 = mem[ttt+2+i*4];
667 c2 = mem[ttt+3+i*4];
668 r = (c1&0x0f)<<2;
669 g = (c2&0xf0)>>2;
670 b = (c2&0x0f)<<2;
672 r = r|((r>>2)&3);
673 g = g|((g>>2)&3);
674 b = b|((b>>2)&3);
676 pal[i].r = r;
677 pal[i].g = g;
678 pal[i].b = b;
680 set_pallete(pal);
682 ttt++;
684 if (!found)
686 ttt = 0;
690 void grab_uae2()
692 // More advanced method to find palettes !
693 bool colfound[32];
694 bool nomorecols = false;
695 int foundcolors = 0;
697 for (int i=0; i < 32; i++)
699 colfound[i] = false;
701 bool found = false;
702 while (!found && ttt < fsize-64)
704 if (mem[ttt+0] == 0x01 && mem[ttt+1] >= 0x80 && mem[ttt+1] <=0x9f &&
705 mem[ttt+4] == 0x01 && mem[ttt+5] >= 0x80 && mem[ttt+5] <=0x9f &&
706 mem[ttt+8] == 0x01 && mem[ttt+9] >= 0x80 && mem[ttt+9] <=0x9f &&
707 mem[ttt+12] == 0x01 && mem[ttt+13] >= 0x80 && mem[ttt+13] <=0x9f)
709 found = true;
710 palfound = ttt;
711 int c1, c2;
712 int r,g,b;
714 int i=0;
715 int colind = 0;
716 bool ended = false;
718 while (ttt+(i*4) < fsize-2 && !ended)
720 if (mem[ttt+(i*4)+0] == 0xff && mem[ttt+(i*4)+1] == 0xff)
722 ended = true;
724 else
726 if (mem[ttt+1+(i*4)] >= 0x80 && mem[ttt+1+(i*4)] <= 0xbf)
728 colind = (mem[ttt+1+(i*4)]-0x80)>>1;
729 if (!colfound[colind])
731 colfound[colind] = true;
732 c1 = mem[ttt+2+(i*4)];
733 c2 = mem[ttt+3+(i*4)];
734 r = (c1&0x0f)<<2;
735 g = (c2&0xf0)>>2;
736 b = (c2&0x0f)<<2;
738 r = r|((r>>2)&3);
739 g = g|((g>>2)&3);
740 b = b|((b>>2)&3);
742 pal[colind].r = r;
743 pal[colind].g = g;
744 pal[colind].b = b;
745 if (!nomorecols)
747 foundcolors+=4;
750 else
752 nomorecols = true;
755 else
757 nomorecols = true;
760 i++;
762 set_pallete(pal);
764 if (foundcolors > 0)
766 ttt+=foundcolors;
768 else
770 ttt++;
773 if (!found)
775 ttt = 0;
779 int find_chunk(char * name)
781 int pos = 0;
782 int add = 0;
783 int len2;
784 while (pos < fsize)
786 if (!memcmp(name, &mem[pos], 4))
788 // found
789 return pos;
791 add = mem[pos+4]*256*256*256+mem[pos+5]*256*256+mem[pos+6]*256+mem[pos+7]+4;
792 pos += add;
793 /* alignment */
794 len2 = add & 3;
795 pos -= len2;
798 return -1;
801 void grab_uae3()
803 // Grab the palette from the snapshot
804 int pos;
805 pos = find_chunk("CHIP");
806 if (pos != -1)
808 palfound = pos+4+8+4+0x0180 - (64 + 12*8);
809 for (int i=0; i < 63; i++)
811 int c1, c2;
812 int r,g,b;
814 c1 = mem[palfound+i*2];
815 c2 = mem[palfound+i*2+1];
816 r = (c1&0x0f)<<2;
817 g = (c2&0xf0)>>2;
818 b = (c2&0x0f)<<2;
820 r = r|((r>>2)&3);
821 g = g|((g>>2)&3);
822 b = b|((b>>2)&3);
824 pal[i].r = r;
825 pal[i].g = g;
826 pal[i].b = b;
828 set_pallete(pal);
832 void grab_uae3aga()
834 // Grab the AGA palette from the snapshot
835 int pos;
836 pos = find_chunk("AGAC");
837 if (pos != -1)
839 palfound = pos+8+4;
840 for (int i=0; i < 256; i++)
842 int r,g,b;
844 r = mem[palfound+i*4+1];
845 g = mem[palfound+i*4+2];
846 b = mem[palfound+i*4+3];
848 pal[i].r = r>>2;
849 pal[i].g = g>>2;
850 pal[i].b = b>>2;
852 set_pallete(pal);
857 void getpalettefile()
859 BITMAP * t;
861 FILE * f;
862 char buf[255] = "";
863 int ret = billfile_select("Select BMP file", buf, "bmp");
864 if (ret != 0)
866 f = fopen(buf, "rt");
867 if (f != NULL)
869 t = load_bmp(buf, pal);
870 if (t != NULL)
872 set_pallete(pal);
873 destroy_bitmap(t);
879 int main(int argc, char *argv[])
882 install_allegro(SYSTEM_AUTODETECT, &errno, atexit);
885 install_mouse();
886 if(install_keyboard())
888 allegro_exit();
889 allegro_message("Error installing keyboard handler.\nExiting");
890 return -1;
892 set_color_depth(8);
893 if(0 > set_gfx_mode(GFX_SAFE, scrW, scrH, 0, 0))
895 allegro_exit();
896 allegro_message("Error setting graphics mode.\nExiting");
897 return -1;
899 genpal();
901 set_pallete(pal);
903 bill_init();
904 // bill_init_smallpal(17);
905 set_gui_mode(1);
907 char buf[255] = "";
909 if (argc < 2)
911 billfile_select("Select file", buf, NULL);
913 else
915 strcpy(buf, argv[1]);
917 file = fopen(buf, "rb");
918 if (file != NULL)
920 fsize = file_size(buf);
921 if (fsize !=0)
923 mem = (unsigned char *) malloc(fsize);
924 if (mem != 0)
926 fread((void *) mem, 1, fsize, file);
931 if (mem != 0)
933 bitmap = create_bitmap(scrW, scrH);
935 int keyp = 0;
937 centre_dialog(goto_dialog);
938 centre_dialog(save_dialog);
940 while (keyp != KEY_ESC)
942 refresh();
943 keyp = readkey();
944 keyp>>=8;
945 if (keyp >= KEY_0 && keyp <= KEY_8)
947 int nn = keyp-KEY_0;
948 if (key[KEY_LSHIFT] || key[KEY_RSHIFT])
950 bplorder[nn]--;
951 if (bplorder[nn] < 0)
953 bplorder[nn]=7;
956 else
958 bplorder[nn]++;
959 if (bplorder[nn] > 7)
961 bplorder[nn]=0;
965 int modeskip = 1;
966 if (mode == 1)
968 modeskip = bits;
970 switch(keyp)
972 case KEY_B:
973 pal[0].r = pal[0].b = 63;
974 pal[0].g = 0;
975 set_pallete(pal);
976 break;
977 case KEY_MINUS:
978 if (bplorder[0]>0)
980 bplorder[0]--;
982 else
984 bplorder[0]=7;
986 break;
987 case KEY_UP:
988 if (key[KEY_LSHIFT] || key[KEY_RSHIFT])
990 if (offset >= (blXSize*8*modeskip) )
992 offset-=blXSize*8*modeskip;
995 else
997 if (offset >= blXSize*modeskip )
999 offset-=blXSize*modeskip;
1002 break;
1003 case KEY_DOWN:
1004 if (key[KEY_LSHIFT] || key[KEY_RSHIFT])
1006 if (offset < (fsize-blXSize*8*modeskip))
1008 offset+=blXSize*8*modeskip;
1011 else
1013 if (offset < fsize-(blXSize*modeskip))
1015 offset+=blXSize*modeskip;
1018 break;
1019 case KEY_LEFT:
1020 if (key[KEY_LSHIFT] || key[KEY_RSHIFT])
1022 if (offset >= (blXSize*blYSize*bits)+skip )
1024 offset-=(blXSize*blYSize*bits)+skip;
1027 else
1029 if (offset > 0)
1031 offset--;
1034 break;
1035 case KEY_RIGHT:
1036 if (key[KEY_LSHIFT] || key[KEY_RSHIFT])
1038 if (offset < fsize-((blXSize*blYSize*bits)+skip))
1040 offset+=(blXSize*blYSize*bits)+skip;
1043 else
1045 if (offset < fsize)
1047 offset++;
1050 break;
1051 case KEY_E:
1052 if (bits < 8)
1054 bits++;
1056 break;
1057 case KEY_D:
1058 if (bits > 1)
1060 bits--;
1062 break;
1063 case KEY_W:
1064 if (key[KEY_LSHIFT] || key[KEY_RSHIFT])
1066 blYSize+=8;
1068 else
1070 blYSize++;
1072 break;
1073 case KEY_S:
1074 if (key[KEY_LSHIFT] || key[KEY_RSHIFT])
1076 if (blYSize > 9)
1078 blYSize-=8;
1081 else
1083 if (blYSize > 1)
1085 blYSize--;
1088 break;
1089 case KEY_Q:
1090 blXSize++;
1091 break;
1092 case KEY_A:
1093 if (blXSize > 1)
1095 blXSize--;
1097 break;
1098 case KEY_G:
1099 goto_bye();
1100 break;
1101 case KEY_H:
1102 skip_bye();
1103 break;
1105 case KEY_P:
1106 if (key[KEY_LSHIFT] || key[KEY_RSHIFT])
1108 save(true);
1110 else
1112 save(false);
1114 break;
1115 case KEY_L:
1116 switch (palsearchmode)
1118 case 0:
1119 grab_uae();
1120 break;
1121 case 1:
1122 grab_uae2();
1123 break;
1124 case 2:
1125 grab_uae3();
1126 break;
1127 case 3:
1128 grab_uae3aga();
1129 break;
1131 break;
1132 case KEY_J:
1133 ttt = palfound;
1134 switch (palsearchmode)
1136 case 0:
1137 grab_uae();
1138 break;
1139 case 1:
1140 grab_uae2();
1141 break;
1142 case 2:
1143 grab_uae3();
1144 break;
1145 case 3:
1146 grab_uae3aga();
1147 break;
1149 break;
1150 case KEY_K:
1151 genpal();
1152 set_pallete(pal);
1153 break;
1154 case KEY_U:
1155 zoom = !zoom;
1156 break;
1157 case KEY_R:
1158 if (key[KEY_LSHIFT] || key[KEY_RSHIFT])
1160 skip+=8;
1162 else
1164 skip++;
1166 break;
1167 case KEY_F:
1168 if (key[KEY_LSHIFT] || key[KEY_RSHIFT])
1170 if (skip > 7)
1172 skip-=8;
1175 else
1177 if (skip > 0)
1179 skip--;
1182 break;
1183 case KEY_N:
1184 reverse = !reverse;
1185 break;
1186 case KEY_M:
1187 mode+=1;
1188 if (mode == 5)
1190 mode = 0;
1192 break;
1193 case KEY_Z:
1194 palsearchmode+=1;
1195 if (palsearchmode == 4)
1197 palsearchmode = 0;
1199 break;
1200 case KEY_C:
1201 getpalettefile();
1202 break;
1203 case KEY_X:
1204 if (skipmode == 0)
1206 skipmode = 1;
1208 else
1210 skipmode = 0;
1212 break;
1213 case KEY_INSERT:
1214 if (key[KEY_LCONTROL] || key[KEY_RCONTROL])
1216 copy_to_clip();
1218 break;
1220 clear_keybuf();
1223 destroy_bitmap(bitmap);
1224 free (mem);
1226 return 0;
1228 END_OF_MAIN()