§ Код конвертера

1<?php
2
3$im   = imagecreatetruecolor(256, 192);
4$data = @ file_get_contents($argv[1]);
5$mem  = [];
6
7if ($data) {
8
9    for ($i = 0; $i < strlen($data); $i++) $mem[$i] = ord($data[$i]);
10    for ($i = 0; $i < 6144; $i++) update_charline($im, $mem, $i);
11    imagepng($im, "{$argv[1]}.png");
12}
13
14// Обновить определенную линию
15function update_charline(& $im, $mem, $address) {
16
17    $address &= 0x3FFF;
18
19    $byte = $mem[$address];
20
21    $Ya = ($address & 0x0700) >> 8;
22    $Yb = ($address & 0x00E0) >> 5;
23    $Yc = ($address & 0x1800) >> 11;
24
25    $y = $Ya + $Yb*8 + $Yc*64;
26    $x = $address & 0x1F;
27
28    $attr    = $mem[$x + 0x1800 + (($address & 0x1800) >> 3) + ($address & 0xE0)];
29    $bgcolor = get_color(($attr & 0x78) >> 3);
30    $frcolor = get_color(($attr & 0x07) + (($attr & 0x40) >> 3));
31    $flash   = ($attr & 0x80) ? 1 : 0;
32
33    for ($j = 0; $j < 8; $j++) {
34
35        $pix = ($byte & (0x80 >> $j)) ? 1 : 0;
36        $clr = $pix ? $frcolor : $bgcolor;
37        imagesetpixel($im, 8 * $x + $j, $y, $clr);
38    }
39};
40
41function get_color($color) {
42
43    switch ($color) {
44
45        // Lo
46        case 0: return 0x000000;
47        case 1: return 0x0000c0;
48        case 2: return 0xc00000;
49        case 3: return 0xc000c0;
50        case 4: return 0x00c000;
51        case 5: return 0x00c0c0;
52        case 6: return 0xc0c000;
53        case 7: return 0xc0c0c0;
54        // Hi
55        case 8: return 0x000000;
56        case 9: return 0x0000FF;
57        case 10: return 0xFF0000;
58        case 11: return 0xFF00FF;
59        case 12: return 0x00FF00;
60        case 13: return 0x00FFFF;
61        case 14: return 0xFFFF00;
62        case 15: return 0xFFFFFF;
63    }
64
65    return 0;
66};