-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain_Decoder.m
119 lines (113 loc) · 4.33 KB
/
Main_Decoder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
% Raphael BOICHOT 10/08/2021 Game Boy printer emulator
% multi OS compatibility improved by Cristofer Cruz 2022/06/21
% code can handle compression, palette tricks and multiple images
% for any question : raphael.boichot@gmail.com
% update V3 to follow compatibility with https://github.com/mofosyne/arduino-gameboy-printer-emulator
clear
clc
% Here you enter some parameters
%------------------------------------------------------------------------
paper_color=1;%6=random, 5=purple, 4=pink, 3=regular blue, 2=regular yellow or 1=regular white
%watermarking='Raphaël BOICHOT 2021';
file='Entry_file.txt';% enter text file to decode
color_option=1; %1 for Black and white, 2 for Game Boy Color, 3 for Game Boy DMG, 4 for CGA, 5 for salmon, for pixel perfect output
darkness=10; %1=lightest 10=darkest
scale_percentage=30; %100=full size, smaller values scale down image
Timeout_printing=0; %0 to separate images automatically if margin >0
%1 for continuous printing with TimeOut or Manual dode, ignore margin > 0);
%------------------------------------------------------------------------
try
pkg load image % for compatibility with Octave in case the code directly targets a Putty log file for example
catch
% Nothing to do
end
[ID]=get_unique_ID(8);
DateString = date;
copyfile (file,['Backups/',DateString,'_',ID,'.txt']);
raw_image=[];
num_image=0;
colored=[];
colored_image=[];
BandW=[];
BandW_image=[];
fid = fopen(file,'r');
while ~feof(fid)
a=fgets(fid);
% str='88 33 01';
% if not(isempty(strfind(a,str)))
% disp('INIT command received')
% end
% str='88 33 0F';
% if not(isempty(strfind(a,str)))
% disp('STATUS command received')
% end
str='88 33 04';
if not(isempty(strfind(a,str)))
if a(13:17)=='00 00'
disp('Empty DATA packet received')
else
disp('DATA packet to process received')
packet=decode_packet(a);
raw_image=[raw_image;packet];
%imagesc(raw_image);
drawnow
end
end
str='88 33 02';
if not(isempty(strfind(a,str)))&¬(isempty(raw_image))
disp('PRINT command received')
[colored, margin]= color_packet(a,raw_image,color_option);
colored_image=[colored_image;colored];
[BandW, margin]= color_packet(a,raw_image,1);
BandW_image=[BandW_image;BandW];
[epaper,alpha]=epaper_packet(BandW_image,paper_color,darkness,scale_percentage);
disp(['The after margin is 0x',num2str(dec2hex(margin))])
raw_image=[];
if not(margin==0)&¬(Timeout_printing);
num_image=num_image+1;
imwrite(epaper,['GameBoy e-paper_',num2str(num_image),'_',DateString,'_',ID,'.png'],'Alpha',alpha)
imwrite(colored_image,['GameBoy pixel perfect_',num2str(num_image),'_',DateString,'_',ID,'.png'])
imagesc(colored_image)
pause(1)
disp('Images written')
raw_image=[];
colored_image=[];
colored=[];
BandW=[];
BandW_image=[];
disp('Flush spooler by Print command')
end
end
str='Memory Waterline';
if not(isempty(strfind(a,str)))&¬(isempty(colored_image))&&(Timeout_printing)
disp('Cut paper command received')
num_image=num_image+1;
imwrite(epaper,['GameBoy e-paper_',num2str(num_image),'_',DateString,'_',ID,'.png'],'Alpha',alpha)
imwrite(colored_image,['GameBoy pixel perfect_',num2str(num_image),'_',DateString,'_',ID,'.png'])
disp('Images written')
imagesc(colored_image)
pause(1)
raw_image=[];
colored_image=[];
colored=[];
BandW=[];
BandW_image=[];
disp('Flush spooler by Timed Out')
end
end
if not(isempty(colored_image))
num_image=num_image+1;
imwrite(epaper,['GameBoy e-paper_',num2str(num_image),'_',DateString,'_',ID,'.png'],'Alpha',alpha)
imwrite(colored_image,['GameBoy pixel perfect_',num2str(num_image),'_',DateString,'_',ID,'.png'])
disp('Images written')
imagesc(colored_image)
pause(1)
raw_image=[];
colored_image=[];
colored=[];
BandW=[];
BandW_image=[];
disp('Flush spooler by force')
end
fclose(fid);
disp('Normal termination')