Skip to content

Commit

Permalink
Merge pull request #12 from wangds/crop_c
Browse files Browse the repository at this point in the history
Convert CROP ASM to C.
  • Loading branch information
AnimatorPro committed Nov 13, 2013
2 parents 16caf3d + bb5fc49 commit 2f524d3
Show file tree
Hide file tree
Showing 52 changed files with 255 additions and 1,792 deletions.
127 changes: 127 additions & 0 deletions src/COMMON/peekpok_.c
@@ -1,5 +1,6 @@
/* peekpok_.c */

#include <assert.h>
#include <string.h>
#include "peekpok_.h"

Expand Down Expand Up @@ -41,3 +42,129 @@ copy_words(const UWORD *src, UWORD *dst, unsigned int n)
{
memmove(dst, src, 2 * n);
}

unsigned int
bsame(const UBYTE *src, unsigned int n)
{
unsigned int i;

for (i = 0; i < n; i++) {
if (src[i] != src[0])
break;
}

return i;
}

unsigned int
fsame(const UWORD *src, unsigned int n)
{
unsigned int i;

for (i = 0; i < n; i++) {
if (src[i] != src[0])
break;
}

return i;
}

unsigned int
bcontrast(const UBYTE *xs, const UBYTE *ys, unsigned int n)
{
unsigned int i;

for (i = 0; i < n; i++) {
if (xs[i] == ys[i])
break;
}

return i;
}

unsigned int
bcompare(const UBYTE *xs, const UBYTE *ys, unsigned int n)
{
unsigned int i;

for (i = 0; i < n; i++) {
if (xs[i] != ys[i])
break;
}

return i;
}

unsigned int
fcompare(const UWORD *xs, const UWORD *ys, unsigned int n)
{
unsigned int i;

for (i = 0; i < n; i++) {
if (xs[i] != ys[i])
break;
}

return i;
}

unsigned int
til_next_skip(const UBYTE *xs, const UBYTE *ys, unsigned int n,
unsigned int mustmatch)
{
unsigned int diffcount = 0;
assert(mustmatch <= n);

for (;;) {
unsigned int num_same;
unsigned int num_diff;

num_diff = bcontrast(xs, ys, n);
n -= num_diff;
xs += num_diff;
ys += num_diff;
diffcount += num_diff;

/* Check last couple of pixels. */
if (n < mustmatch) {
num_same = bcompare(xs, ys, n);

if (num_same < n)
diffcount += n;

break;
}

num_same = bcompare(xs, ys, mustmatch);

if (num_same == mustmatch)
break;

n -= num_same;
xs += num_same;
ys += num_same;
diffcount += num_same;
}

return diffcount;
}

unsigned int
til_next_same(const UBYTE *src, unsigned int n, unsigned int mustmatch)
{
unsigned int num_remaining = n;
unsigned int num_examined = 0;

while (num_remaining >= mustmatch) {
unsigned int num_same = bsame(src, num_remaining);

if (num_same >= mustmatch)
return num_examined;

src += num_same;
num_examined += num_same;
num_remaining -= num_same;
}

return n;
}
24 changes: 24 additions & 0 deletions src/COMMON/peekpok_.h
Expand Up @@ -18,6 +18,30 @@ extern void exchange_words(UWORD *xs, UWORD *ys, unsigned int n);
/* Function: copy_words */
extern void copy_words(const UWORD *src, UWORD *dst, unsigned int n);

/* Function: bsame */
extern unsigned int bsame(const UBYTE *src, unsigned int n);

/* Function: fsame */
extern unsigned int fsame(const UWORD *src, unsigned int n);

/* Function: bcontrast */
extern unsigned int bcontrast(const UBYTE *xs, const UBYTE *ys, unsigned int n);

/* Function: bcompare */
extern unsigned int bcompare(const UBYTE *xs, const UBYTE *ys, unsigned int n);

/* Function: fcompare */
extern unsigned int fcompare(const UWORD *xs, const UWORD *ys, unsigned int n);

/* Function: til_next_skip */
extern unsigned int
til_next_skip(const UBYTE *xs, const UBYTE *ys, unsigned int n,
unsigned int mustmatch);

/* Function: til_next_same */
extern unsigned int
til_next_same(const UBYTE *src, unsigned int n, unsigned int mustmatch);

#define zero_structure(s, size) \
stuff_words(0, s, ((unsigned int)(size))>>1)

Expand Down
18 changes: 9 additions & 9 deletions src/CROP/LINKIT
@@ -1,13 +1,13 @@
a1blit.obj+
a2blit.obj+
a1blit_.obj+
a2blit_.obj+
blit.obj+
blit8.obj+
blit8_.obj+
brush.obj+
cblock.obj+
cblock_.obj+
cel.obj+
choices.obj+
clipit.obj+
closestc.obj+
clipit_.obj+
closest_.obj+
cursorda.obj+
diskerr.obj+
dosstuff.obj+
Expand All @@ -23,6 +23,7 @@ main.obj+
mmouse.obj+
names.obj+
peekpoke.obj+
peekpok_.obj+
qnumber.obj+
rfont.obj+
scroller.obj+
Expand All @@ -37,20 +38,19 @@ wordwrap.obj+
memory.obj+
pull.obj+
croppull.obj+
urif.obj+
unrif.obj+
readrif.obj+
jfile.obj+
bfile.obj+
crop.obj+
comp.obj+
unbrun.obj+
comp_.obj+
unbrun_.obj+
fli.obj+
writefli.obj+
pcx.obj+
fccomp.obj+
lccomp.obj+
skip.obj+
screen.obj+
seq.obj+
gif.obj+
Expand Down
22 changes: 16 additions & 6 deletions src/CROP/Makefile
@@ -1,15 +1,15 @@


CFLAGS= -O -w-par -wstv -c -ml -I$(INCLUDE) -d
CFLAGS= -O -w-par -wstv -c -ml -I$(INCLUDE) -d -I. -I..\COMMON

.c.obj:
tcc $(CFLAGS) $*.c
.asm.obj:
tasm /Ml $*.asm;


O= a1blit.obj a2blit.obj blit.obj blit8.obj brush.obj \
cel.obj cblock.obj choices.obj clipit.obj closestc.obj cursorda.obj \
O= blit.obj brush.obj \
cel.obj choices.obj cursorda.obj \
diskerr.obj dosstuff.obj feelmenu.obj \
filedata.obj filemenu.obj gfx.obj \
init.obj initcmap.obj input.obj \
Expand All @@ -18,16 +18,26 @@ scroller.obj seeme.obj seemenu.obj sixhi.obj slider.obj stringq.obj \
wordwrap.obj \
crop.obj croppull.obj stubs.obj globals.obj pull.obj memory.obj \
qnumber.obj cpack.obj rgbcmap.obj scale.obj slide.obj \
amigapic.obj urif.obj unrif.obj readrif.obj \
amigapic.obj unrif.obj readrif.obj \
seq.obj stpic.obj \
pcx.obj \
vision.obj \
macpic.obj \
anim.obj \
writegif.obj gif.obj decoder.obj comprs.obj \
skip.obj fccomp.obj lccomp.obj comp.obj unbrun.obj fli.obj writefli.obj \
fccomp.obj lccomp.obj comp.obj \
fli.obj writefli.obj \
screen.obj jfile.obj bfile.obj \
foolwcc2.obj summa.obj textbox.obj
foolwcc2.obj summa.obj textbox.obj \
..\COMMON\a1blit_.obj \
..\COMMON\a2blit_.obj \
..\COMMON\blit8_.obj \
..\COMMON\clipit_.obj \
..\COMMON\cblock_.obj \
..\COMMON\closest_.obj \
..\COMMON\comp_.obj \
..\COMMON\peekpok_.obj \
..\COMMON\unbrun_.obj

fast: $(O)
tlink $(LIB)c0l @linkit, crop, crop, $(LIB)cl
Expand Down

0 comments on commit 2f524d3

Please sign in to comment.