OBONO’s Diary

へっぽこプログラマの戯言

Rupo

昨年、MZ-2500 で使用していたフロッピーディスクのイメージ化作業をしたわけだが、その際に、東芝 Rupo JW03 で使用していたディスクも一緒にイメージ化してたりする。
いろいろ調べた結果、文章データは基本的に JIS で格納されているらしい。そこで、エンディアン変換と JIS → Shift-JIS の変換に加えて、Rupo 独自の仕様も加味した変換プログラムを C で書いてみた。

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

typedef unsigned char   uchar;
typedef unsigned short  ushort;
typedef unsigned int    uint;

ushort jis2sjis(ushort c);

int main(int argc, char **argv) {
    int i;
    int fd_in;
    int fd_out;
    ushort code;

    if (argc < 3) {
        printf("usage: %s input_file output_file\n", argv[0]);
        return -1;
    }
    fd_in = open(argv[1], O_RDONLY);
    fd_out = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0644);

    for (i = 0; i < 640 * 1024 / 2; i++) {
        read(fd_in, &code, 2);
        code = jis2sjis(code);
        if (code) {
            write(fd_out, &code, 2);
        }
    }
    close(fd_in);
    close(fd_out);

    return 0;
}

ushort jis2sjis(ushort c) {
    uchar c1 = (c >> 8) & 0x7f;
    uchar c2 = c & 0xff;

    /*  special case  */
    if (c == 0x2668) {
        return 0x0a0d; // CRLF
    }
    if (c == 0x2325 || c== 0x2578) {
        return 0; // ignore
    }

    /*  out of range  */
    if (c1 < 0x20 || c1 > 0x7e || c2 < 0x20 || c2 > 0x7e) {
        return 0;
    }

    /*  half-width  */
    if (c & 0x8000) {
        return c2 << 8 | c1;
    }

    /*  full-width  */
    if (c1 % 2) {
        c1 = ((c1 + 1) / 2) + 0x70;
        c2 = c2 + 0x1f;
    } else {
        c1 = (c1 / 2) + 0x70;
        c2 = c2 + 0x7d;
    }
    if (c1 >= 0xa0) {
        c1 = c1 + 0x40;
    }
    if (c2 >= 0x7f) {
        c2 = c2 + 1;
    }
    if (c1 < 0x80 || c2 < 0x40 || c2 > 0xfc) {
        return 0;   // out of range
    }
    return c2 << 8 | c1;
}

少し乱暴ではあるが、ディスクイメージを丸ごと変換してみたところ、それっぽい文章データが出力された。ゴミデータを除去して適宜整形して、文章ごとに別個のテキストファイルにして保存。
作業しながら文章を斜め読みしたんだけど、十数年前に作成されたものなので、当時を思い出してしまい、少し懐かしさに浸ってしまった。


ところで、世の中にはワープロフロッピーディスクから、データをサルベージするサービスやらパソコンのソフトやらがあるんだけど、どれもこれも料金が足元を見てるよなぁ。実際 2DD のフロッピーを読める環境が稀少だろうから、仕方ないのかもしれないけど。


参考サイト