Skip to content

Commit

Permalink
Moire effect final (for now)
Browse files Browse the repository at this point in the history
  • Loading branch information
reenigne committed Apr 14, 2014
1 parent f747890 commit 783b182
Show file tree
Hide file tree
Showing 10 changed files with 2,039 additions and 1,006 deletions.
4 changes: 3 additions & 1 deletion 8088/demo/moire/build.bat
@@ -1,4 +1,6 @@
@echo off
copy moire.asm+tables.asm combined.asm
nasm -o moire.com -f bin combined.asm
yasm -o moire.com -f bin combined.asm
copy moire_xtserver.asm+tables.asm combined_xtserver.asm
yasm -o moire_xtserver.bin -f bin combined_xtserver.asm

18 changes: 18 additions & 0 deletions 8088/demo/moire/inner_loop.asm
@@ -0,0 +1,18 @@
cpu 8086
org 0x100

pop ax ; 58
xor ax,[bp+12] ; 33 46 xx
stosb ; AA
inc di ; 47
mov al,ah ; 88 E0
stosb ; AA
inc di ; 47

add sp,10 ; 83 C4 xx
add bp,10 ; 83 C4 xx


To remove both bytes, replace "xor ax,[bp+12]" with "mov ax,0"


142 changes: 102 additions & 40 deletions 8088/demo/moire/make_table.cpp
Expand Up @@ -7,45 +7,76 @@ class Program : public ProgramBase
int colour(Vector p)
{
int palette[16] =
{ 0, 8, 9, 1, 5, 13, 12, 4, 6, 14, 15, 7, 3, 11, 10, 2 };
double d = /*sqrt(*/static_cast<double>(p.modulus2())/64 /*)*/;
// { 0, 8, 9, 1, 5, 13, 12, 4, 6, 14, 15, 7, 3, 11, 10, 2 };
{ 0, 1, 5, 4, 6, 7, 3, 2, 10, 11, 15, 14, 12, 13, 9, 8 };
double d = sqrt(static_cast<double>(p.modulus2()));
return palette[static_cast<int>(d) & 15];
}
//int colour(Vector p)
//{
// int t = static_cast<int>(17 * 6 * atan2(p.y, p.x) / tau + 17 * 6);
// int bayer[16] = {
// 0, 8, 2, 10,
// 12, 4, 14, 6,
// 3, 11, 1, 9,
// 15, 7, 13, 5 };
// int palette[6] = { 12, 14, 10, 11, 9, 13 };
// int c1 = (t / 17) % 6;
// int c2 = (c1 + 1) % 6;
// int dither = t % 17;
// int xd = p.x & 3;
// int yd = p.y & 3;
// int b = bayer[yd * 4 + xd];
// //return palette[dither > b ? c2 : c1];
// return palette[c2];
//}

void run()
{
int stride = 80;
_screenSize = Vector(80, 50);
Vector screenSize(80, 50);
int frames = 13125000 * 14 / (11 * 76 * 262);
int maxRadius = 20;

_o1s.allocate(frames);
_o2s.allocate(frames);
int minO = 0, maxO = 0;
// Center of screen
Vector2<double> c = Vector2Cast<double>(screenSize) / 2;

// Positions of screen top-left relative to centre of each picture
Array<Vector> p1s(frames);
Array<Vector> p2s(frames);
int minX = 0, maxX = 0;
for (int t = 0; t < frames; ++t) {
double f = static_cast<double>(t) / frames;
double r = maxRadius; // *(1 - cos(f * tau)) / 2;
Rotor2<double> z1(f * 3);
Rotor2<double> z2(f * 4);
Rotor2<double> z1(f * 6);
Rotor2<double> z2(f * 7);
Vector2<double> a1 = Vector2<double>(r, 0) * z1;
Vector2<double> a2 = Vector2<double>(r, 0) * z2;

Vector2<double> c = Vector2Cast<double>(_screenSize) / 2;

// Positions of picture centres relative to screen top-left
Vector2<double> p1 = c + a1;
Vector2<double> p2 = c + a2;
Vector p1 = -Vector2Cast<int>(c + a1);
Vector p2 = -Vector2Cast<int>(c + a2);
p1s[t] = p1;
p2s[t] = p2;

minX = min(min(minX, p1.x), p2.x);
maxX = max(max(maxX, p1.x + screenSize.x), p2.x + screenSize.x);
}
int stride = (3 + maxX - minX) & ~3;

// Offset in picture from start of screen to end
int ss = (screenSize.y - 1)*stride + screenSize.x;

// Positions of screen top-left on relative to pictures center
Vector s1 = -Vector2Cast<int>(p1);
Vector s2 = -Vector2Cast<int>(p2);
Array<int> o1s(frames);
Array<int> o2s(frames);
int minO = 0, maxO = 0;
for (int t = 0; t < frames; ++t) {
Vector p1 = p1s[t];
Vector p2 = p2s[t];

// Offsets of screen top-left into pictures relative to pictures
// center.
int o1 = s1.y*stride + s1.x;
int o2 = s2.y*stride + s2.x;

// Offset in picture from start of screen to end
int ss = (_screenSize.y - 1)*stride + _screenSize.x;
int o1 = p1.y*stride + p1.x;
int o2 = p2.y*stride + p2.x;

int o1e = o1 + ss;
int o2e = o2 + ss;
Expand All @@ -54,8 +85,8 @@ class Program : public ProgramBase
minO = min(min(minO, o1), o2);
maxO = max(max(maxO, o1e), o2e);

_o1s[t] = o1;
_o2s[t] = o2;
o1s[t] = o1;
o2s[t] = o2;
}

FileHandle output = File("tables.asm").openWrite();
Expand All @@ -81,33 +112,68 @@ class Program : public ProgramBase
console.write("Picture size: " + decimal(bytes) + "\n");
console.write("Motion size: " + decimal(4 * frames) + "\n");

output.write("frames: dw " + decimal(frames) + "\n\n");
output.write("frames equ " + decimal(frames) + "\n");
output.write("stride equ " + decimal(stride/2) + "\n");
output.write("p equ picture\n");
output.write(
"p2 equ pictureEnd+(pictureEnd-picture)+(headerEnd-header)\n\n");

output.write("motion:");
for (int t = 0; t < frames; ++t) {
int o1 = _o1s[t] - minO;
int o2 = _o2s[t] - minO;
int o1 = o1s[t] - minO;
int o2 = o2s[t] - minO;

int si = o1/2;
int sp = o1 / 2;
if ((o1 & 1) != 0)
si += bytes;
sp += bytes;
int bp = o2 / 2;
if ((o2 & 1) != 0)
si |= 0x8000;
if ((o2 & 2) != 0)
si |= 0x4000;

int ip = (o2 / 4) * 10;
bp += bytes;

if (t % 4 == 0)
if (t % 3 == 0)
output.write("\n dw ");
else
output.write(", ");
output.write(hex(si, 4) + ", " + hex(ip, 4));
output.write("p+" + hex(sp, 4) + ", p+" + hex(bp, 4));
}

int lastX = 20;
output.write("\n\n");
output.write("picture:");

int p2 = (maxO + 1 - minO) / 2;
p2 += p2 - 1;

output.write("transition:");
Array<bool> cleared(20 * 13);
for (int p = 0; p < 20 * 13; ++p)
cleared[p] = false;
int pp = 0;
for (int t = 0; t < 1000000; ++t) {
int r = 999 - t / 1000;
int theta = t % 1000;
Vector2<double> z =
Vector2<double>(r/20.0, 0)*Rotor2<double>(theta / 1000.0);
Vector p = Vector2Cast<int>(z + Vector2<double>(10, 6.25));
if (p.x >= 0 && p.x < 20 && p.y >= 0 && p.y < 13) {
int aa = p.y * 20 + p.x;
if (cleared[aa])
continue;
int a = p.y * 206 * 4 + p.x * 10;
if (pp % 3 == 0)
output.write("\n dw ");
else
output.write(", ");
++pp;
output.write("p2+" + hex(a, 4) + ", ");
if (p.y == 12)
output.write("p2+" + hex(a, 4));
else
output.write("p2+" + hex(a + 206*2, 4));
cleared[aa] = true;
}
}
console.write("pp = " + decimal(pp) + " \n");
output.write("\n\npicture:");
for (int o = minO; o < maxO + 1; o += 2) {
int x = (o + d) % stride;
int y = (o + d - x) / stride - d/stride;
Expand All @@ -131,8 +197,4 @@ class Program : public ProgramBase
output.write("\n");
output.write("pictureEnd:\n");
}
private:
Vector _screenSize;
Array<int> _o1s;
Array<int> _o2s;
};
1 change: 1 addition & 0 deletions 8088/demo/moire/make_table.vcxproj
Expand Up @@ -80,6 +80,7 @@
<ClCompile Include="make_table.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\include\alfe\array.h" />
<ClInclude Include="..\..\..\include\alfe\file.h" />
<ClInclude Include="..\..\..\include\alfe\handle.h" />
<ClInclude Include="..\..\..\include\alfe\main.h" />
Expand Down
3 changes: 3 additions & 0 deletions 8088/demo/moire/make_table.vcxproj.filters
Expand Up @@ -35,5 +35,8 @@
<ClInclude Include="..\..\..\include\alfe\vectors.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\include\alfe\array.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

0 comments on commit 783b182

Please sign in to comment.