Home » Archimedes archive » Archimedes World » AW-1995-06_Disc2.adf » June95_2 » InTheMag/AcornAns/DeepDeep/QuikDith/!QuikDith/c/main
InTheMag/AcornAns/DeepDeep/QuikDith/!QuikDith/c/main
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Archimedes World » AW-1995-06_Disc2.adf » June95_2 |
Filename: | InTheMag/AcornAns/DeepDeep/QuikDith/!QuikDith/c/main |
Read OK: | ✔ |
File size: | 1522 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
#define TRACE 0 #include "trace.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include "kernel.h" #include "sprite.h" #include "werr.h" #include "wimpt.h" #include "wimp.h" #include "bbc.h" #include "flex.h" #include "colourtran.h" #include "os.h" #include "visdelay.h" sprite_area *ditharea=0; char lut[32768]; unsigned int pal256def[256]; /****************************** INITIALISATION ******************************/ /*--- Initialise the program, returning TRUE if it was all OK. ---*/ static BOOL initialise(int argc, char *argv[]) { os_filestr f; flex_init(); if (!flex_alloc((flex_ptr)&ditharea, sizeof(sprite_area))) { werr(0, "ditharea init failed"); return FALSE; } sprite_area_initialise(ditharea, flex_size((flex_ptr)&ditharea)); f.action=255; f.name="<QuikDith$Dir>.resources.lut"; f.loadaddr=(int)lut; f.execaddr=0; if (wimpt_complain(os_file(&f))) return FALSE; if (f.start!=32768) { /*f.start is r4, here holding file length*/ werr(0, "Internal: resources.lut file corrupted - should be 32768 bytes long"); return FALSE; } f.action=255; f.name="<QuikDith$Dir>.resources.pal256def"; f.loadaddr=(int)pal256def; f.execaddr=0; if (wimpt_complain(os_file(&f))) return FALSE; if (f.start!=1024) { /*f.start is r4, here holding file length*/ werr(0, "Internal: resources.pal256def file corrupted - should be 1024 bytes long"); return FALSE; } /* All went ok */ return TRUE; } /******************************* MAIN PROGRAM ********************************/ typedef struct { signed char er; signed char eg; signed char eb; signed char byte4; /*reminder that struct will be word sized*/ } compact_dither_error; extern void g256wnp_internal(int x, int y, char *dp, char *sp, compact_dither_error *de, char *lut, unsigned int *pal256def); BOOL gen_256withnopalette(flex_ptr sa, char *name) { int newsize; os_error *e; compact_dither_error *de; int x, y; sprite_id si; sprite_header *sh, *dh; char *sp, *dp; unsigned int modeword, type, xres, yres; int sprsize, extra; #if TRACE==1 int tim; trace_on(); #endif si.tag = sprite_id_name; si.s.name = name; if (wimpt_complain(sprite_select_rp((sprite_area *)*sa, &si, (sprite_ptr *)&sh))) return FALSE; modeword = sh->mode; type = modeword>>27; xres = (modeword>> 1)&0x1fff; yres = (modeword>>14)&0x1fff; if (type!=5) { werr(0, "Sprite is not new type 5 (16bpp) - I only understand these!"); return FALSE; } x = ( (1+sh->width)*4 - (31-sh->rbit)/8 ) / 2; y = sh->height + 1; sprsize = sizeof(sprite_header)+y*((x+3)&~3); extra = sprsize - (ditharea->size - ditharea->freeoff); if (extra>0) { newsize = ditharea->size + extra; if (!flex_extend((flex_ptr)&ditharea, newsize)) { werr(0, "No room for destination sprite"); return FALSE; } ditharea->size = newsize; /*above flex will likely have invalidated sh, so recalc*/ if (wimpt_complain(sprite_select_rp((sprite_area *)*sa, &si, (sprite_ptr *)&sh))) return FALSE; } de = malloc(x*sizeof(compact_dither_error)); if (de==0) { werr(0, "No room for dither error line buffer"); return FALSE; } e=sprite_create_rp(ditharea, name, sprite_nopalette, x, y, xres==2*yres ? 15 : 28, (sprite_ptr *)&dh); if (e) { free(de); wimpt_complain(e); return FALSE; } dp = (char *)dh + dh->image; sp = (char *)sh + sh->image; #if TRACE==1 tim = clock(); #endif g256wnp_internal(x, y, dp, sp, de, lut, pal256def); #if TRACE==1 tim = clock()-tim; tracef1("time taken: %i\n", tim); #endif free(de); return TRUE; } BOOL process_sprite_file(char *filein, char *fileout) { sprite_area *sa=0; os_filestr f; int filesize, filetype, offset; os_error *e; char sname[13]; int i, l; f.action=5; f.name=filein; if (e=os_file(&f), e) { werr(0, "Internal error: unable to read file information (%s)\n", e->errmess); return FALSE; } if (f.action!=1) { werr(0, "Object is not a file or does not exist\n"); return FALSE; } filetype=(f.loadaddr>>8)&0xfff; if (filetype!=0xff9) { werr(0, "This object is not a sprite file\n"); return FALSE; } offset = 4; filesize = f.start + offset; if (sa) flex_free((flex_ptr)&sa); if (!flex_alloc((flex_ptr)&sa, filesize)) { werr(0, "Insufficient memory to load file\n"); return FALSE; } sa->size = filesize; f.action=255; f.name=filein; f.loadaddr=(int)sa + offset; f.execaddr=0; if (e=os_file(&f), e) { flex_free((flex_ptr)&sa); werr(0, "Internal error: unable to load file (%s)\n", e->errmess); return FALSE; } visdelay_begin(); for (i=1; i<=sa->number; i++) { l = 13; if (wimpt_complain(sprite_getname(sa, sname, &l, i))) break; if (!gen_256withnopalette((flex_ptr)&sa, sname)) { werr(0, "gen_256withnopalette failed on sprite %s", sname); } } visdelay_end(); if (e=sprite_area_save(ditharea, fileout), e) { flex_free((flex_ptr)&sa); werr(0, "Internal error: unable to save output file (%s)\n", e->errmess); return FALSE; } flex_free((flex_ptr)&sa); return TRUE; } /*--- Main entry point. ---*/ int main(int argc, char *argv[]) { if (initialise(argc, argv)) { process_sprite_file("<QuikDith$Dir>.^.Input", "<QuikDith$Dir>.^.Output"); } return 0; }
00000000 23 64 65 66 69 6e 65 20 54 52 41 43 45 20 30 0a |#define TRACE 0.| 00000010 23 69 6e 63 6c 75 64 65 20 22 74 72 61 63 65 2e |#include "trace.| 00000020 68 22 0a 0a 23 69 6e 63 6c 75 64 65 20 3c 73 74 |h"..#include <st| 00000030 64 69 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 |dio.h>.#include | 00000040 3c 73 74 64 6c 69 62 2e 68 3e 0a 23 69 6e 63 6c |<stdlib.h>.#incl| 00000050 75 64 65 20 3c 73 74 72 69 6e 67 2e 68 3e 0a 0a |ude <string.h>..| 00000060 23 69 6e 63 6c 75 64 65 20 22 6b 65 72 6e 65 6c |#include "kernel| 00000070 2e 68 22 0a 23 69 6e 63 6c 75 64 65 20 22 73 70 |.h".#include "sp| 00000080 72 69 74 65 2e 68 22 0a 23 69 6e 63 6c 75 64 65 |rite.h".#include| 00000090 20 22 77 65 72 72 2e 68 22 0a 23 69 6e 63 6c 75 | "werr.h".#inclu| 000000a0 64 65 20 22 77 69 6d 70 74 2e 68 22 0a 23 69 6e |de "wimpt.h".#in| 000000b0 63 6c 75 64 65 20 22 77 69 6d 70 2e 68 22 0a 23 |clude "wimp.h".#| 000000c0 69 6e 63 6c 75 64 65 20 22 62 62 63 2e 68 22 0a |include "bbc.h".| 000000d0 23 69 6e 63 6c 75 64 65 20 22 66 6c 65 78 2e 68 |#include "flex.h| 000000e0 22 0a 23 69 6e 63 6c 75 64 65 20 22 63 6f 6c 6f |".#include "colo| 000000f0 75 72 74 72 61 6e 2e 68 22 0a 23 69 6e 63 6c 75 |urtran.h".#inclu| 00000100 64 65 20 22 6f 73 2e 68 22 0a 23 69 6e 63 6c 75 |de "os.h".#inclu| 00000110 64 65 20 22 76 69 73 64 65 6c 61 79 2e 68 22 0a |de "visdelay.h".| 00000120 0a 73 70 72 69 74 65 5f 61 72 65 61 20 2a 64 69 |.sprite_area *di| 00000130 74 68 61 72 65 61 3d 30 3b 0a 63 68 61 72 20 6c |tharea=0;.char l| 00000140 75 74 5b 33 32 37 36 38 5d 3b 0a 75 6e 73 69 67 |ut[32768];.unsig| 00000150 6e 65 64 20 69 6e 74 20 70 61 6c 32 35 36 64 65 |ned int pal256de| 00000160 66 5b 32 35 36 5d 3b 0a 0a 2f 2a 2a 2a 2a 2a 2a |f[256];../******| 00000170 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a |****************| 00000180 2a 2a 2a 2a 2a 2a 2a 2a 20 49 4e 49 54 49 41 4c |******** INITIAL| 00000190 49 53 41 54 49 4f 4e 20 2a 2a 2a 2a 2a 2a 2a 2a |ISATION ********| 000001a0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a |****************| 000001b0 2a 2a 2a 2a 2a 2a 2f 0a 0a 2f 2a 2d 2d 2d 20 49 |******/../*--- I| 000001c0 6e 69 74 69 61 6c 69 73 65 20 74 68 65 20 70 72 |nitialise the pr| 000001d0 6f 67 72 61 6d 2c 20 72 65 74 75 72 6e 69 6e 67 |ogram, returning| 000001e0 20 54 52 55 45 20 69 66 20 69 74 20 77 61 73 20 | TRUE if it was | 000001f0 61 6c 6c 20 4f 4b 2e 20 2d 2d 2d 2a 2f 0a 73 74 |all OK. ---*/.st| 00000200 61 74 69 63 20 42 4f 4f 4c 20 69 6e 69 74 69 61 |atic BOOL initia| 00000210 6c 69 73 65 28 69 6e 74 20 61 72 67 63 2c 20 63 |lise(int argc, c| 00000220 68 61 72 20 2a 61 72 67 76 5b 5d 29 0a 7b 0a 20 |har *argv[]).{. | 00000230 20 6f 73 5f 66 69 6c 65 73 74 72 20 66 3b 0a 0a | os_filestr f;..| 00000240 20 20 66 6c 65 78 5f 69 6e 69 74 28 29 3b 0a 20 | flex_init();. | 00000250 20 69 66 20 28 21 66 6c 65 78 5f 61 6c 6c 6f 63 | if (!flex_alloc| 00000260 28 28 66 6c 65 78 5f 70 74 72 29 26 64 69 74 68 |((flex_ptr)&dith| 00000270 61 72 65 61 2c 20 73 69 7a 65 6f 66 28 73 70 72 |area, sizeof(spr| 00000280 69 74 65 5f 61 72 65 61 29 29 29 20 7b 0a 20 20 |ite_area))) {. | 00000290 20 20 77 65 72 72 28 30 2c 20 22 64 69 74 68 61 | werr(0, "ditha| 000002a0 72 65 61 20 69 6e 69 74 20 66 61 69 6c 65 64 22 |rea init failed"| 000002b0 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 46 41 |);. return FA| 000002c0 4c 53 45 3b 0a 20 20 7d 0a 20 20 73 70 72 69 74 |LSE;. }. sprit| 000002d0 65 5f 61 72 65 61 5f 69 6e 69 74 69 61 6c 69 73 |e_area_initialis| 000002e0 65 28 64 69 74 68 61 72 65 61 2c 20 66 6c 65 78 |e(ditharea, flex| 000002f0 5f 73 69 7a 65 28 28 66 6c 65 78 5f 70 74 72 29 |_size((flex_ptr)| 00000300 26 64 69 74 68 61 72 65 61 29 29 3b 0a 0a 20 20 |&ditharea));.. | 00000310 66 2e 61 63 74 69 6f 6e 3d 32 35 35 3b 0a 20 20 |f.action=255;. | 00000320 66 2e 6e 61 6d 65 3d 22 3c 51 75 69 6b 44 69 74 |f.name="<QuikDit| 00000330 68 24 44 69 72 3e 2e 72 65 73 6f 75 72 63 65 73 |h$Dir>.resources| 00000340 2e 6c 75 74 22 3b 0a 20 20 66 2e 6c 6f 61 64 61 |.lut";. f.loada| 00000350 64 64 72 3d 28 69 6e 74 29 6c 75 74 3b 0a 20 20 |ddr=(int)lut;. | 00000360 66 2e 65 78 65 63 61 64 64 72 3d 30 3b 0a 20 20 |f.execaddr=0;. | 00000370 69 66 20 28 77 69 6d 70 74 5f 63 6f 6d 70 6c 61 |if (wimpt_compla| 00000380 69 6e 28 6f 73 5f 66 69 6c 65 28 26 66 29 29 29 |in(os_file(&f)))| 00000390 20 72 65 74 75 72 6e 20 46 41 4c 53 45 3b 0a 20 | return FALSE;. | 000003a0 20 69 66 20 28 66 2e 73 74 61 72 74 21 3d 33 32 | if (f.start!=32| 000003b0 37 36 38 29 20 7b 20 2f 2a 66 2e 73 74 61 72 74 |768) { /*f.start| 000003c0 20 69 73 20 72 34 2c 20 68 65 72 65 20 68 6f 6c | is r4, here hol| 000003d0 64 69 6e 67 20 66 69 6c 65 20 6c 65 6e 67 74 68 |ding file length| 000003e0 2a 2f 0a 20 20 20 20 77 65 72 72 28 30 2c 20 22 |*/. werr(0, "| 000003f0 49 6e 74 65 72 6e 61 6c 3a 20 72 65 73 6f 75 72 |Internal: resour| 00000400 63 65 73 2e 6c 75 74 20 66 69 6c 65 20 63 6f 72 |ces.lut file cor| 00000410 72 75 70 74 65 64 20 2d 20 73 68 6f 75 6c 64 20 |rupted - should | 00000420 62 65 20 33 32 37 36 38 20 62 79 74 65 73 20 6c |be 32768 bytes l| 00000430 6f 6e 67 22 29 3b 0a 20 20 20 20 72 65 74 75 72 |ong");. retur| 00000440 6e 20 46 41 4c 53 45 3b 0a 20 20 7d 0a 0a 20 20 |n FALSE;. }.. | 00000450 66 2e 61 63 74 69 6f 6e 3d 32 35 35 3b 0a 20 20 |f.action=255;. | 00000460 66 2e 6e 61 6d 65 3d 22 3c 51 75 69 6b 44 69 74 |f.name="<QuikDit| 00000470 68 24 44 69 72 3e 2e 72 65 73 6f 75 72 63 65 73 |h$Dir>.resources| 00000480 2e 70 61 6c 32 35 36 64 65 66 22 3b 0a 20 20 66 |.pal256def";. f| 00000490 2e 6c 6f 61 64 61 64 64 72 3d 28 69 6e 74 29 70 |.loadaddr=(int)p| 000004a0 61 6c 32 35 36 64 65 66 3b 0a 20 20 66 2e 65 78 |al256def;. f.ex| 000004b0 65 63 61 64 64 72 3d 30 3b 0a 20 20 69 66 20 28 |ecaddr=0;. if (| 000004c0 77 69 6d 70 74 5f 63 6f 6d 70 6c 61 69 6e 28 6f |wimpt_complain(o| 000004d0 73 5f 66 69 6c 65 28 26 66 29 29 29 20 72 65 74 |s_file(&f))) ret| 000004e0 75 72 6e 20 46 41 4c 53 45 3b 0a 20 20 69 66 20 |urn FALSE;. if | 000004f0 28 66 2e 73 74 61 72 74 21 3d 31 30 32 34 29 20 |(f.start!=1024) | 00000500 7b 20 2f 2a 66 2e 73 74 61 72 74 20 69 73 20 72 |{ /*f.start is r| 00000510 34 2c 20 68 65 72 65 20 68 6f 6c 64 69 6e 67 20 |4, here holding | 00000520 66 69 6c 65 20 6c 65 6e 67 74 68 2a 2f 0a 20 20 |file length*/. | 00000530 20 20 77 65 72 72 28 30 2c 20 22 49 6e 74 65 72 | werr(0, "Inter| 00000540 6e 61 6c 3a 20 72 65 73 6f 75 72 63 65 73 2e 70 |nal: resources.p| 00000550 61 6c 32 35 36 64 65 66 20 66 69 6c 65 20 63 6f |al256def file co| 00000560 72 72 75 70 74 65 64 20 2d 20 73 68 6f 75 6c 64 |rrupted - should| 00000570 20 62 65 20 31 30 32 34 20 62 79 74 65 73 20 6c | be 1024 bytes l| 00000580 6f 6e 67 22 29 3b 0a 20 20 20 20 72 65 74 75 72 |ong");. retur| 00000590 6e 20 46 41 4c 53 45 3b 0a 20 20 7d 0a 0a 20 20 |n FALSE;. }.. | 000005a0 2f 2a 20 41 6c 6c 20 77 65 6e 74 20 6f 6b 20 2a |/* All went ok *| 000005b0 2f 0a 20 20 72 65 74 75 72 6e 20 54 52 55 45 3b |/. return TRUE;| 000005c0 0a 7d 0a 0a 2f 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a |.}../***********| 000005d0 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a |****************| 000005e0 2a 2a 2a 2a 20 4d 41 49 4e 20 50 52 4f 47 52 41 |**** MAIN PROGRA| 000005f0 4d 20 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a |M **************| 00000600 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a |****************| 00000610 2a 2a 2f 0a 0a 74 79 70 65 64 65 66 20 73 74 72 |**/..typedef str| 00000620 75 63 74 20 7b 0a 20 20 73 69 67 6e 65 64 20 63 |uct {. signed c| 00000630 68 61 72 20 65 72 3b 0a 20 20 73 69 67 6e 65 64 |har er;. signed| 00000640 20 63 68 61 72 20 65 67 3b 0a 20 20 73 69 67 6e | char eg;. sign| 00000650 65 64 20 63 68 61 72 20 65 62 3b 0a 20 20 73 69 |ed char eb;. si| 00000660 67 6e 65 64 20 63 68 61 72 20 62 79 74 65 34 3b |gned char byte4;| 00000670 20 20 2f 2a 72 65 6d 69 6e 64 65 72 20 74 68 61 | /*reminder tha| 00000680 74 20 73 74 72 75 63 74 20 77 69 6c 6c 20 62 65 |t struct will be| 00000690 20 77 6f 72 64 20 73 69 7a 65 64 2a 2f 0a 7d 20 | word sized*/.} | 000006a0 63 6f 6d 70 61 63 74 5f 64 69 74 68 65 72 5f 65 |compact_dither_e| 000006b0 72 72 6f 72 3b 0a 0a 65 78 74 65 72 6e 20 76 6f |rror;..extern vo| 000006c0 69 64 20 67 32 35 36 77 6e 70 5f 69 6e 74 65 72 |id g256wnp_inter| 000006d0 6e 61 6c 28 69 6e 74 20 78 2c 20 69 6e 74 20 79 |nal(int x, int y| 000006e0 2c 20 63 68 61 72 20 2a 64 70 2c 20 63 68 61 72 |, char *dp, char| 000006f0 20 2a 73 70 2c 20 63 6f 6d 70 61 63 74 5f 64 69 | *sp, compact_di| 00000700 74 68 65 72 5f 65 72 72 6f 72 20 2a 64 65 2c 20 |ther_error *de, | 00000710 63 68 61 72 20 2a 6c 75 74 2c 0a 20 20 20 20 20 |char *lut,. | 00000720 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 00000730 20 20 20 20 20 20 20 20 75 6e 73 69 67 6e 65 64 | unsigned| 00000740 20 69 6e 74 20 2a 70 61 6c 32 35 36 64 65 66 29 | int *pal256def)| 00000750 3b 0a 0a 42 4f 4f 4c 20 67 65 6e 5f 32 35 36 77 |;..BOOL gen_256w| 00000760 69 74 68 6e 6f 70 61 6c 65 74 74 65 28 66 6c 65 |ithnopalette(fle| 00000770 78 5f 70 74 72 20 73 61 2c 20 63 68 61 72 20 2a |x_ptr sa, char *| 00000780 6e 61 6d 65 29 0a 7b 0a 20 20 69 6e 74 20 6e 65 |name).{. int ne| 00000790 77 73 69 7a 65 3b 0a 20 20 6f 73 5f 65 72 72 6f |wsize;. os_erro| 000007a0 72 20 2a 65 3b 0a 20 20 63 6f 6d 70 61 63 74 5f |r *e;. compact_| 000007b0 64 69 74 68 65 72 5f 65 72 72 6f 72 20 2a 64 65 |dither_error *de| 000007c0 3b 0a 20 20 69 6e 74 20 78 2c 20 79 3b 0a 20 20 |;. int x, y;. | 000007d0 73 70 72 69 74 65 5f 69 64 20 73 69 3b 0a 20 20 |sprite_id si;. | 000007e0 73 70 72 69 74 65 5f 68 65 61 64 65 72 20 2a 73 |sprite_header *s| 000007f0 68 2c 20 2a 64 68 3b 0a 20 20 63 68 61 72 20 2a |h, *dh;. char *| 00000800 73 70 2c 20 2a 64 70 3b 0a 20 20 75 6e 73 69 67 |sp, *dp;. unsig| 00000810 6e 65 64 20 69 6e 74 20 6d 6f 64 65 77 6f 72 64 |ned int modeword| 00000820 2c 20 74 79 70 65 2c 20 78 72 65 73 2c 20 79 72 |, type, xres, yr| 00000830 65 73 3b 0a 20 20 69 6e 74 20 73 70 72 73 69 7a |es;. int sprsiz| 00000840 65 2c 20 65 78 74 72 61 3b 0a 0a 20 20 23 69 66 |e, extra;.. #if| 00000850 20 54 52 41 43 45 3d 3d 31 0a 20 20 69 6e 74 20 | TRACE==1. int | 00000860 74 69 6d 3b 0a 20 20 74 72 61 63 65 5f 6f 6e 28 |tim;. trace_on(| 00000870 29 3b 0a 20 20 23 65 6e 64 69 66 0a 0a 20 20 73 |);. #endif.. s| 00000880 69 2e 74 61 67 20 3d 20 73 70 72 69 74 65 5f 69 |i.tag = sprite_i| 00000890 64 5f 6e 61 6d 65 3b 0a 20 20 73 69 2e 73 2e 6e |d_name;. si.s.n| 000008a0 61 6d 65 20 3d 20 6e 61 6d 65 3b 0a 20 20 69 66 |ame = name;. if| 000008b0 20 28 77 69 6d 70 74 5f 63 6f 6d 70 6c 61 69 6e | (wimpt_complain| 000008c0 28 73 70 72 69 74 65 5f 73 65 6c 65 63 74 5f 72 |(sprite_select_r| 000008d0 70 28 28 73 70 72 69 74 65 5f 61 72 65 61 20 2a |p((sprite_area *| 000008e0 29 2a 73 61 2c 20 26 73 69 2c 20 28 73 70 72 69 |)*sa, &si, (spri| 000008f0 74 65 5f 70 74 72 20 2a 29 26 73 68 29 29 29 20 |te_ptr *)&sh))) | 00000900 72 65 74 75 72 6e 20 46 41 4c 53 45 3b 0a 20 20 |return FALSE;. | 00000910 6d 6f 64 65 77 6f 72 64 20 3d 20 73 68 2d 3e 6d |modeword = sh->m| 00000920 6f 64 65 3b 0a 20 20 74 79 70 65 20 3d 20 6d 6f |ode;. type = mo| 00000930 64 65 77 6f 72 64 3e 3e 32 37 3b 0a 20 20 78 72 |deword>>27;. xr| 00000940 65 73 20 3d 20 28 6d 6f 64 65 77 6f 72 64 3e 3e |es = (modeword>>| 00000950 20 31 29 26 30 78 31 66 66 66 3b 0a 20 20 79 72 | 1)&0x1fff;. yr| 00000960 65 73 20 3d 20 28 6d 6f 64 65 77 6f 72 64 3e 3e |es = (modeword>>| 00000970 31 34 29 26 30 78 31 66 66 66 3b 0a 0a 20 20 69 |14)&0x1fff;.. i| 00000980 66 20 28 74 79 70 65 21 3d 35 29 20 7b 0a 20 20 |f (type!=5) {. | 00000990 20 20 77 65 72 72 28 30 2c 20 22 53 70 72 69 74 | werr(0, "Sprit| 000009a0 65 20 69 73 20 6e 6f 74 20 6e 65 77 20 74 79 70 |e is not new typ| 000009b0 65 20 35 20 28 31 36 62 70 70 29 20 2d 20 49 20 |e 5 (16bpp) - I | 000009c0 6f 6e 6c 79 20 75 6e 64 65 72 73 74 61 6e 64 20 |only understand | 000009d0 74 68 65 73 65 21 22 29 3b 0a 20 20 20 20 72 65 |these!");. re| 000009e0 74 75 72 6e 20 46 41 4c 53 45 3b 0a 20 20 7d 0a |turn FALSE;. }.| 000009f0 0a 20 20 78 20 3d 20 28 20 28 31 2b 73 68 2d 3e |. x = ( (1+sh->| 00000a00 77 69 64 74 68 29 2a 34 20 2d 20 28 33 31 2d 73 |width)*4 - (31-s| 00000a10 68 2d 3e 72 62 69 74 29 2f 38 20 29 20 2f 20 32 |h->rbit)/8 ) / 2| 00000a20 3b 0a 20 20 79 20 3d 20 73 68 2d 3e 68 65 69 67 |;. y = sh->heig| 00000a30 68 74 20 2b 20 31 3b 0a 20 20 73 70 72 73 69 7a |ht + 1;. sprsiz| 00000a40 65 20 3d 20 73 69 7a 65 6f 66 28 73 70 72 69 74 |e = sizeof(sprit| 00000a50 65 5f 68 65 61 64 65 72 29 2b 79 2a 28 28 78 2b |e_header)+y*((x+| 00000a60 33 29 26 7e 33 29 3b 0a 0a 20 20 65 78 74 72 61 |3)&~3);.. extra| 00000a70 20 3d 20 73 70 72 73 69 7a 65 20 2d 20 28 64 69 | = sprsize - (di| 00000a80 74 68 61 72 65 61 2d 3e 73 69 7a 65 20 2d 20 64 |tharea->size - d| 00000a90 69 74 68 61 72 65 61 2d 3e 66 72 65 65 6f 66 66 |itharea->freeoff| 00000aa0 29 3b 0a 20 20 69 66 20 28 65 78 74 72 61 3e 30 |);. if (extra>0| 00000ab0 29 20 7b 0a 20 20 20 20 6e 65 77 73 69 7a 65 20 |) {. newsize | 00000ac0 3d 20 64 69 74 68 61 72 65 61 2d 3e 73 69 7a 65 |= ditharea->size| 00000ad0 20 2b 20 65 78 74 72 61 3b 0a 20 20 20 20 69 66 | + extra;. if| 00000ae0 20 28 21 66 6c 65 78 5f 65 78 74 65 6e 64 28 28 | (!flex_extend((| 00000af0 66 6c 65 78 5f 70 74 72 29 26 64 69 74 68 61 72 |flex_ptr)&dithar| 00000b00 65 61 2c 20 6e 65 77 73 69 7a 65 29 29 20 7b 0a |ea, newsize)) {.| 00000b10 20 20 20 20 20 20 77 65 72 72 28 30 2c 20 22 4e | werr(0, "N| 00000b20 6f 20 72 6f 6f 6d 20 66 6f 72 20 64 65 73 74 69 |o room for desti| 00000b30 6e 61 74 69 6f 6e 20 73 70 72 69 74 65 22 29 3b |nation sprite");| 00000b40 0a 20 20 20 20 20 20 72 65 74 75 72 6e 20 46 41 |. return FA| 00000b50 4c 53 45 3b 0a 20 20 20 20 7d 0a 20 20 20 20 64 |LSE;. }. d| 00000b60 69 74 68 61 72 65 61 2d 3e 73 69 7a 65 20 3d 20 |itharea->size = | 00000b70 6e 65 77 73 69 7a 65 3b 0a 20 20 20 20 2f 2a 61 |newsize;. /*a| 00000b80 62 6f 76 65 20 66 6c 65 78 20 77 69 6c 6c 20 6c |bove flex will l| 00000b90 69 6b 65 6c 79 20 68 61 76 65 20 69 6e 76 61 6c |ikely have inval| 00000ba0 69 64 61 74 65 64 20 73 68 2c 20 73 6f 20 72 65 |idated sh, so re| 00000bb0 63 61 6c 63 2a 2f 0a 20 20 20 20 69 66 20 28 77 |calc*/. if (w| 00000bc0 69 6d 70 74 5f 63 6f 6d 70 6c 61 69 6e 28 73 70 |impt_complain(sp| 00000bd0 72 69 74 65 5f 73 65 6c 65 63 74 5f 72 70 28 28 |rite_select_rp((| 00000be0 73 70 72 69 74 65 5f 61 72 65 61 20 2a 29 2a 73 |sprite_area *)*s| 00000bf0 61 2c 20 26 73 69 2c 20 28 73 70 72 69 74 65 5f |a, &si, (sprite_| 00000c00 70 74 72 20 2a 29 26 73 68 29 29 29 20 72 65 74 |ptr *)&sh))) ret| 00000c10 75 72 6e 20 46 41 4c 53 45 3b 0a 20 20 7d 0a 0a |urn FALSE;. }..| 00000c20 20 20 64 65 20 3d 20 6d 61 6c 6c 6f 63 28 78 2a | de = malloc(x*| 00000c30 73 69 7a 65 6f 66 28 63 6f 6d 70 61 63 74 5f 64 |sizeof(compact_d| 00000c40 69 74 68 65 72 5f 65 72 72 6f 72 29 29 3b 0a 20 |ither_error));. | 00000c50 20 69 66 20 28 64 65 3d 3d 30 29 20 7b 0a 20 20 | if (de==0) {. | 00000c60 20 20 77 65 72 72 28 30 2c 20 22 4e 6f 20 72 6f | werr(0, "No ro| 00000c70 6f 6d 20 66 6f 72 20 64 69 74 68 65 72 20 65 72 |om for dither er| 00000c80 72 6f 72 20 6c 69 6e 65 20 62 75 66 66 65 72 22 |ror line buffer"| 00000c90 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 46 41 |);. return FA| 00000ca0 4c 53 45 3b 0a 20 20 7d 0a 0a 20 20 65 3d 73 70 |LSE;. }.. e=sp| 00000cb0 72 69 74 65 5f 63 72 65 61 74 65 5f 72 70 28 64 |rite_create_rp(d| 00000cc0 69 74 68 61 72 65 61 2c 20 6e 61 6d 65 2c 20 73 |itharea, name, s| 00000cd0 70 72 69 74 65 5f 6e 6f 70 61 6c 65 74 74 65 2c |prite_nopalette,| 00000ce0 20 78 2c 20 79 2c 20 78 72 65 73 3d 3d 32 2a 79 | x, y, xres==2*y| 00000cf0 72 65 73 20 3f 20 31 35 20 3a 20 32 38 2c 20 28 |res ? 15 : 28, (| 00000d00 73 70 72 69 74 65 5f 70 74 72 20 2a 29 26 64 68 |sprite_ptr *)&dh| 00000d10 29 3b 0a 20 20 69 66 20 28 65 29 20 7b 0a 20 20 |);. if (e) {. | 00000d20 20 20 66 72 65 65 28 64 65 29 3b 0a 20 20 20 20 | free(de);. | 00000d30 77 69 6d 70 74 5f 63 6f 6d 70 6c 61 69 6e 28 65 |wimpt_complain(e| 00000d40 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 46 41 |);. return FA| 00000d50 4c 53 45 3b 0a 20 20 7d 0a 20 20 64 70 20 3d 20 |LSE;. }. dp = | 00000d60 28 63 68 61 72 20 2a 29 64 68 20 2b 20 64 68 2d |(char *)dh + dh-| 00000d70 3e 69 6d 61 67 65 3b 0a 20 20 73 70 20 3d 20 28 |>image;. sp = (| 00000d80 63 68 61 72 20 2a 29 73 68 20 2b 20 73 68 2d 3e |char *)sh + sh->| 00000d90 69 6d 61 67 65 3b 0a 0a 20 20 23 69 66 20 54 52 |image;.. #if TR| 00000da0 41 43 45 3d 3d 31 0a 20 20 74 69 6d 20 3d 20 63 |ACE==1. tim = c| 00000db0 6c 6f 63 6b 28 29 3b 0a 20 20 23 65 6e 64 69 66 |lock();. #endif| 00000dc0 0a 20 20 67 32 35 36 77 6e 70 5f 69 6e 74 65 72 |. g256wnp_inter| 00000dd0 6e 61 6c 28 78 2c 20 79 2c 20 64 70 2c 20 73 70 |nal(x, y, dp, sp| 00000de0 2c 20 64 65 2c 20 6c 75 74 2c 20 70 61 6c 32 35 |, de, lut, pal25| 00000df0 36 64 65 66 29 3b 0a 20 20 23 69 66 20 54 52 41 |6def);. #if TRA| 00000e00 43 45 3d 3d 31 0a 20 20 74 69 6d 20 3d 20 63 6c |CE==1. tim = cl| 00000e10 6f 63 6b 28 29 2d 74 69 6d 3b 0a 20 20 74 72 61 |ock()-tim;. tra| 00000e20 63 65 66 31 28 22 74 69 6d 65 20 74 61 6b 65 6e |cef1("time taken| 00000e30 3a 20 25 69 5c 6e 22 2c 20 74 69 6d 29 3b 0a 20 |: %i\n", tim);. | 00000e40 20 23 65 6e 64 69 66 0a 0a 20 20 66 72 65 65 28 | #endif.. free(| 00000e50 64 65 29 3b 0a 20 20 72 65 74 75 72 6e 20 54 52 |de);. return TR| 00000e60 55 45 3b 0a 7d 0a 0a 42 4f 4f 4c 20 70 72 6f 63 |UE;.}..BOOL proc| 00000e70 65 73 73 5f 73 70 72 69 74 65 5f 66 69 6c 65 28 |ess_sprite_file(| 00000e80 63 68 61 72 20 2a 66 69 6c 65 69 6e 2c 20 63 68 |char *filein, ch| 00000e90 61 72 20 2a 66 69 6c 65 6f 75 74 29 0a 7b 0a 20 |ar *fileout).{. | 00000ea0 20 73 70 72 69 74 65 5f 61 72 65 61 20 2a 73 61 | sprite_area *sa| 00000eb0 3d 30 3b 0a 20 20 6f 73 5f 66 69 6c 65 73 74 72 |=0;. os_filestr| 00000ec0 20 66 3b 0a 20 20 69 6e 74 20 66 69 6c 65 73 69 | f;. int filesi| 00000ed0 7a 65 2c 20 66 69 6c 65 74 79 70 65 2c 20 6f 66 |ze, filetype, of| 00000ee0 66 73 65 74 3b 0a 20 20 6f 73 5f 65 72 72 6f 72 |fset;. os_error| 00000ef0 20 2a 65 3b 0a 20 20 63 68 61 72 20 73 6e 61 6d | *e;. char snam| 00000f00 65 5b 31 33 5d 3b 0a 20 20 69 6e 74 20 69 2c 20 |e[13];. int i, | 00000f10 6c 3b 0a 0a 20 20 66 2e 61 63 74 69 6f 6e 3d 35 |l;.. f.action=5| 00000f20 3b 0a 20 20 66 2e 6e 61 6d 65 3d 66 69 6c 65 69 |;. f.name=filei| 00000f30 6e 3b 0a 20 20 69 66 20 28 65 3d 6f 73 5f 66 69 |n;. if (e=os_fi| 00000f40 6c 65 28 26 66 29 2c 20 65 29 20 7b 0a 20 20 20 |le(&f), e) {. | 00000f50 20 77 65 72 72 28 30 2c 20 22 49 6e 74 65 72 6e | werr(0, "Intern| 00000f60 61 6c 20 65 72 72 6f 72 3a 20 75 6e 61 62 6c 65 |al error: unable| 00000f70 20 74 6f 20 72 65 61 64 20 66 69 6c 65 20 69 6e | to read file in| 00000f80 66 6f 72 6d 61 74 69 6f 6e 20 28 25 73 29 5c 6e |formation (%s)\n| 00000f90 22 2c 20 65 2d 3e 65 72 72 6d 65 73 73 29 3b 0a |", e->errmess);.| 00000fa0 20 20 20 20 72 65 74 75 72 6e 20 46 41 4c 53 45 | return FALSE| 00000fb0 3b 0a 20 20 7d 0a 20 20 69 66 20 28 66 2e 61 63 |;. }. if (f.ac| 00000fc0 74 69 6f 6e 21 3d 31 29 20 7b 0a 20 20 20 20 77 |tion!=1) {. w| 00000fd0 65 72 72 28 30 2c 20 22 4f 62 6a 65 63 74 20 69 |err(0, "Object i| 00000fe0 73 20 6e 6f 74 20 61 20 66 69 6c 65 20 6f 72 20 |s not a file or | 00000ff0 64 6f 65 73 20 6e 6f 74 20 65 78 69 73 74 5c 6e |does not exist\n| 00001000 22 29 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 46 |");. return F| 00001010 41 4c 53 45 3b 0a 20 20 7d 0a 20 20 66 69 6c 65 |ALSE;. }. file| 00001020 74 79 70 65 3d 28 66 2e 6c 6f 61 64 61 64 64 72 |type=(f.loadaddr| 00001030 3e 3e 38 29 26 30 78 66 66 66 3b 0a 20 20 69 66 |>>8)&0xfff;. if| 00001040 20 28 66 69 6c 65 74 79 70 65 21 3d 30 78 66 66 | (filetype!=0xff| 00001050 39 29 20 7b 0a 20 20 20 20 77 65 72 72 28 30 2c |9) {. werr(0,| 00001060 20 22 54 68 69 73 20 6f 62 6a 65 63 74 20 69 73 | "This object is| 00001070 20 6e 6f 74 20 61 20 73 70 72 69 74 65 20 66 69 | not a sprite fi| 00001080 6c 65 5c 6e 22 29 3b 0a 20 20 20 20 72 65 74 75 |le\n");. retu| 00001090 72 6e 20 46 41 4c 53 45 3b 0a 20 20 7d 0a 20 20 |rn FALSE;. }. | 000010a0 6f 66 66 73 65 74 20 3d 20 34 3b 0a 20 20 66 69 |offset = 4;. fi| 000010b0 6c 65 73 69 7a 65 20 3d 20 66 2e 73 74 61 72 74 |lesize = f.start| 000010c0 20 2b 20 6f 66 66 73 65 74 3b 0a 20 20 69 66 20 | + offset;. if | 000010d0 28 73 61 29 20 66 6c 65 78 5f 66 72 65 65 28 28 |(sa) flex_free((| 000010e0 66 6c 65 78 5f 70 74 72 29 26 73 61 29 3b 0a 20 |flex_ptr)&sa);. | 000010f0 20 69 66 20 28 21 66 6c 65 78 5f 61 6c 6c 6f 63 | if (!flex_alloc| 00001100 28 28 66 6c 65 78 5f 70 74 72 29 26 73 61 2c 20 |((flex_ptr)&sa, | 00001110 66 69 6c 65 73 69 7a 65 29 29 20 7b 0a 20 20 20 |filesize)) {. | 00001120 20 77 65 72 72 28 30 2c 20 22 49 6e 73 75 66 66 | werr(0, "Insuff| 00001130 69 63 69 65 6e 74 20 6d 65 6d 6f 72 79 20 74 6f |icient memory to| 00001140 20 6c 6f 61 64 20 66 69 6c 65 5c 6e 22 29 3b 0a | load file\n");.| 00001150 20 20 20 20 72 65 74 75 72 6e 20 46 41 4c 53 45 | return FALSE| 00001160 3b 0a 20 20 7d 0a 20 20 73 61 2d 3e 73 69 7a 65 |;. }. sa->size| 00001170 20 3d 20 66 69 6c 65 73 69 7a 65 3b 0a 0a 20 20 | = filesize;.. | 00001180 66 2e 61 63 74 69 6f 6e 3d 32 35 35 3b 0a 20 20 |f.action=255;. | 00001190 66 2e 6e 61 6d 65 3d 66 69 6c 65 69 6e 3b 0a 20 |f.name=filein;. | 000011a0 20 66 2e 6c 6f 61 64 61 64 64 72 3d 28 69 6e 74 | f.loadaddr=(int| 000011b0 29 73 61 20 2b 20 6f 66 66 73 65 74 3b 0a 20 20 |)sa + offset;. | 000011c0 66 2e 65 78 65 63 61 64 64 72 3d 30 3b 0a 20 20 |f.execaddr=0;. | 000011d0 69 66 20 28 65 3d 6f 73 5f 66 69 6c 65 28 26 66 |if (e=os_file(&f| 000011e0 29 2c 20 65 29 20 7b 0a 20 20 20 20 66 6c 65 78 |), e) {. flex| 000011f0 5f 66 72 65 65 28 28 66 6c 65 78 5f 70 74 72 29 |_free((flex_ptr)| 00001200 26 73 61 29 3b 0a 20 20 20 20 77 65 72 72 28 30 |&sa);. werr(0| 00001210 2c 20 22 49 6e 74 65 72 6e 61 6c 20 65 72 72 6f |, "Internal erro| 00001220 72 3a 20 75 6e 61 62 6c 65 20 74 6f 20 6c 6f 61 |r: unable to loa| 00001230 64 20 66 69 6c 65 20 28 25 73 29 5c 6e 22 2c 20 |d file (%s)\n", | 00001240 65 2d 3e 65 72 72 6d 65 73 73 29 3b 0a 20 20 20 |e->errmess);. | 00001250 20 72 65 74 75 72 6e 20 46 41 4c 53 45 3b 0a 20 | return FALSE;. | 00001260 20 7d 0a 0a 20 20 76 69 73 64 65 6c 61 79 5f 62 | }.. visdelay_b| 00001270 65 67 69 6e 28 29 3b 0a 20 20 66 6f 72 20 28 69 |egin();. for (i| 00001280 3d 31 3b 20 69 3c 3d 73 61 2d 3e 6e 75 6d 62 65 |=1; i<=sa->numbe| 00001290 72 3b 20 69 2b 2b 29 20 7b 0a 20 20 20 20 6c 20 |r; i++) {. l | 000012a0 3d 20 31 33 3b 0a 20 20 20 20 69 66 20 28 77 69 |= 13;. if (wi| 000012b0 6d 70 74 5f 63 6f 6d 70 6c 61 69 6e 28 73 70 72 |mpt_complain(spr| 000012c0 69 74 65 5f 67 65 74 6e 61 6d 65 28 73 61 2c 20 |ite_getname(sa, | 000012d0 73 6e 61 6d 65 2c 20 26 6c 2c 20 69 29 29 29 20 |sname, &l, i))) | 000012e0 62 72 65 61 6b 3b 0a 20 20 20 20 69 66 20 28 21 |break;. if (!| 000012f0 67 65 6e 5f 32 35 36 77 69 74 68 6e 6f 70 61 6c |gen_256withnopal| 00001300 65 74 74 65 28 28 66 6c 65 78 5f 70 74 72 29 26 |ette((flex_ptr)&| 00001310 73 61 2c 20 73 6e 61 6d 65 29 29 20 7b 0a 20 20 |sa, sname)) {. | 00001320 20 20 20 20 77 65 72 72 28 30 2c 20 22 67 65 6e | werr(0, "gen| 00001330 5f 32 35 36 77 69 74 68 6e 6f 70 61 6c 65 74 74 |_256withnopalett| 00001340 65 20 66 61 69 6c 65 64 20 6f 6e 20 73 70 72 69 |e failed on spri| 00001350 74 65 20 25 73 22 2c 20 73 6e 61 6d 65 29 3b 0a |te %s", sname);.| 00001360 20 20 20 20 7d 0a 20 20 7d 0a 20 20 76 69 73 64 | }. }. visd| 00001370 65 6c 61 79 5f 65 6e 64 28 29 3b 0a 0a 20 20 69 |elay_end();.. i| 00001380 66 20 28 65 3d 73 70 72 69 74 65 5f 61 72 65 61 |f (e=sprite_area| 00001390 5f 73 61 76 65 28 64 69 74 68 61 72 65 61 2c 20 |_save(ditharea, | 000013a0 66 69 6c 65 6f 75 74 29 2c 20 65 29 20 7b 0a 20 |fileout), e) {. | 000013b0 20 20 20 66 6c 65 78 5f 66 72 65 65 28 28 66 6c | flex_free((fl| 000013c0 65 78 5f 70 74 72 29 26 73 61 29 3b 0a 20 20 20 |ex_ptr)&sa);. | 000013d0 20 77 65 72 72 28 30 2c 20 22 49 6e 74 65 72 6e | werr(0, "Intern| 000013e0 61 6c 20 65 72 72 6f 72 3a 20 75 6e 61 62 6c 65 |al error: unable| 000013f0 20 74 6f 20 73 61 76 65 20 6f 75 74 70 75 74 20 | to save output | 00001400 66 69 6c 65 20 28 25 73 29 5c 6e 22 2c 20 65 2d |file (%s)\n", e-| 00001410 3e 65 72 72 6d 65 73 73 29 3b 0a 20 20 20 20 72 |>errmess);. r| 00001420 65 74 75 72 6e 20 46 41 4c 53 45 3b 0a 20 20 7d |eturn FALSE;. }| 00001430 0a 0a 20 20 66 6c 65 78 5f 66 72 65 65 28 28 66 |.. flex_free((f| 00001440 6c 65 78 5f 70 74 72 29 26 73 61 29 3b 0a 20 20 |lex_ptr)&sa);. | 00001450 72 65 74 75 72 6e 20 54 52 55 45 3b 0a 7d 0a 0a |return TRUE;.}..| 00001460 2f 2a 2d 2d 2d 20 4d 61 69 6e 20 65 6e 74 72 79 |/*--- Main entry| 00001470 20 70 6f 69 6e 74 2e 20 2d 2d 2d 2a 2f 0a 69 6e | point. ---*/.in| 00001480 74 20 6d 61 69 6e 28 69 6e 74 20 61 72 67 63 2c |t main(int argc,| 00001490 20 63 68 61 72 20 2a 61 72 67 76 5b 5d 29 0a 7b | char *argv[]).{| 000014a0 0a 20 20 69 66 20 28 69 6e 69 74 69 61 6c 69 73 |. if (initialis| 000014b0 65 28 61 72 67 63 2c 20 61 72 67 76 29 29 20 7b |e(argc, argv)) {| 000014c0 0a 20 20 20 20 70 72 6f 63 65 73 73 5f 73 70 72 |. process_spr| 000014d0 69 74 65 5f 66 69 6c 65 28 22 3c 51 75 69 6b 44 |ite_file("<QuikD| 000014e0 69 74 68 24 44 69 72 3e 2e 5e 2e 49 6e 70 75 74 |ith$Dir>.^.Input| 000014f0 22 2c 20 22 3c 51 75 69 6b 44 69 74 68 24 44 69 |", "<QuikDith$Di| 00001500 72 3e 2e 5e 2e 4f 75 74 70 75 74 22 29 3b 0a 20 |r>.^.Output");. | 00001510 20 7d 0a 0a 20 20 72 65 74 75 72 6e 20 30 3b 0a | }.. return 0;.| 00001520 7d 0a |}.| 00001522