Created
February 13, 2021 02:25
-
-
Save maxdee/b32eb3df3e2b662593acdf4fdf02386b to your computer and use it in GitHub Desktop.
pin2dmd_processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// parse pin2dmd raw files | |
// https://github.com/neophob/wpc-emu/blob/master/client/scripts/lib/pin2DmdExport.js | |
byte raw[]; | |
int offset = 0; | |
int frameSize = 0; | |
void setup(){ | |
size(128,32); | |
raw = loadBytes("../wpc-emu-dump.raw"); | |
if(raw[0] != 'R' && raw[1] != 'A' && raw[0] != 'W'){ | |
println("[parse] header note found"); | |
exit(); | |
} | |
println("[parse] PIN2DMD version : "+raw[3]+raw[4]); | |
println("[parse] size : "+raw[5]+"*"+raw[6]); | |
println("[parse] frames per image: "+raw[7]); | |
offset += 8; | |
frameSize = width/8*height; | |
} | |
int makeInt(byte b0, byte b1, byte b2, byte b3) { | |
return (((b3 ) << 24) | | |
((b2 & 0xff) << 16) | | |
((b1 & 0xff) << 8) | | |
((b0 & 0xff) )); | |
} | |
void updateFrame(){ | |
int del = 0; | |
del = makeInt(raw[offset], raw[offset+1], raw[offset+2], raw[offset+3]); | |
println("[frame] delay : "+del); | |
offset += 4; | |
for(int i = 0; i < (width*height); i++){ | |
int idx = offset+i/8; | |
int c = 0; | |
c += (raw[idx] & (1 << i%8)) != 0 ? 1:0; | |
c += (raw[idx+frameSize] & (1 << i%8)) != 0 ? 1:0; | |
c += (raw[idx+frameSize*2] & (1 << i%8)) != 0 ? 1:0; | |
if(c == 0) { | |
pixels[i] = color(0); | |
} | |
else if(c==1){ | |
pixels[i] = color(75); | |
} | |
else if(c==2){ | |
pixels[i] = color(175); | |
} | |
else if(c==3){ | |
pixels[i] = color(255); | |
} | |
} | |
offset+=(width/8)*height*3; | |
if((offset+2) > raw.length) offset = 8; | |
} | |
void draw(){ | |
loadPixels(); | |
if(frameCount % 3 == 0) { | |
updateFrame(); | |
} | |
pixels[width*10+10] = millis()%500 < 200 ? color(255) : color(0); | |
updatePixels(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment