Annotation of nono/util/autoserial/gen-rtc-mk48.cpp, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <time.h>
        !             3: 
        !             4: void
        !             5: X(struct tm& tm)
        !             6: {
        !             7:        printf("450007f8;l,80%02x%02x%02x\n",
        !             8:                tm.tm_sec, tm.tm_min, tm.tm_hour);
        !             9:        printf("450007fc;l,%02x%02x%02x%02x\n",
        !            10:                tm.tm_wday, tm.tm_mday, tm.tm_mon, tm.tm_year);
        !            11:        printf("450007f8;,0\n");
        !            12:        printf("@1010\n");
        !            13:        printf("450007f8\n");
        !            14:        return;
        !            15: }
        !            16: 
        !            17: // x が正常な BCD でかつ start <= x <= end ならば true
        !            18: bool
        !            19: BCDCheck(int x, int start, int end)
        !            20: {
        !            21:        int xh = (x >> 4) & 0xf;
        !            22:        int xl = x & 0xf;
        !            23: 
        !            24:        if ((0 <= xh && xh <= 9) && (0 <= xl && xl <= 9)) {
        !            25:                int v = xh * 10 + xl;
        !            26:                return (start <= v && v <= end);
        !            27:        }
        !            28:        return false;
        !            29: }
        !            30: 
        !            31: 
        !            32: int
        !            33: main(int ac, char *av[])
        !            34: {
        !            35:        struct tm tm {};
        !            36: 
        !            37:        // 0 リセット
        !            38:        X(tm);
        !            39: 
        !            40:        // 秒テスト
        !            41:        for (int i = 0; i <= 0x7f; i++) {
        !            42:                if (BCDCheck(i, 0, 58)) {
        !            43:                        continue;
        !            44:                }
        !            45:                tm.tm_sec = i;
        !            46:                X(tm);
        !            47:        }
        !            48:        tm.tm_sec = 0x59;
        !            49: 
        !            50:        // 分テスト
        !            51:        for (int i = 0; i <= 0x7f; i++) {
        !            52:                if (BCDCheck(i, 0, 58)) {
        !            53:                        continue;
        !            54:                }
        !            55:                tm.tm_min = i;
        !            56:                X(tm);
        !            57:        }
        !            58:        tm.tm_min = 0x59;
        !            59: 
        !            60:        // 時テスト
        !            61:        for (int i = 0; i <= 0x3f; i++) {
        !            62:                if (BCDCheck(i, 0, 22)) {
        !            63:                        continue;
        !            64:                }
        !            65:                tm.tm_hour = i;
        !            66:                X(tm);
        !            67:        }
        !            68:        tm.tm_hour = 0x23;
        !            69: 
        !            70:        // 曜日テスト
        !            71:        for (int i = 0; i <= 7; i++) {
        !            72:                tm.tm_wday = i;
        !            73:                X(tm);
        !            74:        }
        !            75: 
        !            76:        // 年月日テスト
        !            77:        for (int y = 0; y <= 1; y++) {
        !            78:                tm.tm_year = y;
        !            79:                for (int m = 0; m <= 0x1f; m++) {
        !            80:                        tm.tm_mon = m;
        !            81:                        for (int d = 0; d <= 0x3f; d++) {
        !            82:                                if (BCDCheck(d, 2, 27)) {
        !            83:                                        continue;
        !            84:                                }
        !            85:                                tm.tm_mday = d;
        !            86:                                X(tm);
        !            87:                        }
        !            88:                }
        !            89:        }
        !            90:        return 0;
        !            91: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.