[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | sqwrite.c -- librarian - write sequence functions
|
---|
| 4 | Version 2 -- 1988-11-17 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #define DEBUGIT 0
|
---|
| 9 |
|
---|
[6262b5c] | 10 | #include "all.h"
|
---|
[f40a309] | 11 |
|
---|
| 12 | #if DEBUGIT
|
---|
| 13 | extern short debugsw;
|
---|
| 14 | #endif
|
---|
| 15 |
|
---|
[7258c6a] | 16 | extern int32_t chksum(int8_t *area, int32_t len);
|
---|
[f40a309] | 17 |
|
---|
[e225e77] | 18 | extern int16_t wr_ec(FILE *fp, int8_t *from, int32_t len);
|
---|
| 19 | extern void ldwmsg(int8_t *line1, int8_t *line2, int8_t *line3, uint16_t fgcolor, uint16_t bgcolor);
|
---|
| 20 |
|
---|
[f40a309] | 21 | /* |
---|
| 22 |
|
---|
| 23 | */
|
---|
| 24 |
|
---|
| 25 | /*
|
---|
| 26 | =============================================================================
|
---|
| 27 | sqsizer() -- return number of bytes necessary for storing
|
---|
| 28 | active sequence lines
|
---|
| 29 | =============================================================================
|
---|
| 30 | */
|
---|
[7258c6a] | 31 |
|
---|
[f40a309] | 32 | int32_t sqsizer(void)
|
---|
[7258c6a] | 33 | {
|
---|
| 34 | register int16_t i, na;
|
---|
[f40a309] | 35 | register int32_t nb;
|
---|
| 36 |
|
---|
| 37 | nb = 0L;
|
---|
| 38 |
|
---|
| 39 | for (i = 0; i < NSLINES; i++) {
|
---|
| 40 |
|
---|
| 41 | na = 0;
|
---|
| 42 |
|
---|
| 43 | if (seqtab[i].seqtime) /* check the time */
|
---|
| 44 | na += 2L;
|
---|
| 45 |
|
---|
| 46 | if (seqtab[i].seqact1) /* check action 1 */
|
---|
| 47 | na += 4L;
|
---|
| 48 |
|
---|
| 49 | if (seqtab[i].seqact2) /* check action 2 */
|
---|
| 50 | na += 4L;
|
---|
| 51 |
|
---|
| 52 | if (seqtab[i].seqact3) /* check action 3 */
|
---|
| 53 | na += 4L;
|
---|
| 54 |
|
---|
| 55 | if (na) /* tote up the result */
|
---|
| 56 | nb += (na + 3);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | if (nb)
|
---|
| 60 | ++nb;
|
---|
| 61 |
|
---|
| 62 | #if DEBUGIT
|
---|
| 63 | if (debugsw)
|
---|
| 64 | printf("sqsizer(): %ld bytes required\n", nb);
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
| 67 | return(nb);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | /* |
---|
| 71 |
|
---|
| 72 | */
|
---|
| 73 |
|
---|
| 74 | /*
|
---|
| 75 | =============================================================================
|
---|
| 76 | sqwrite() -- store a sequence table
|
---|
| 77 | =============================================================================
|
---|
[7258c6a] | 78 | */
|
---|
[f40a309] | 79 |
|
---|
[7258c6a] | 80 | int16_t sqwrite(FILE *fp)
|
---|
| 81 | {
|
---|
| 82 | int16_t seq;
|
---|
[f40a309] | 83 | int8_t cb, zero;
|
---|
| 84 | int8_t scid[48];
|
---|
| 85 |
|
---|
| 86 | #if DEBUGIT
|
---|
| 87 | if (debugsw)
|
---|
| 88 | printf("sqwrite($%08lX): entered\n", fp);
|
---|
| 89 | #endif
|
---|
| 90 |
|
---|
[7258c6a] | 91 | zero = 0;
|
---|
[f40a309] | 92 |
|
---|
| 93 | ldwmsg("Busy -- Please stand by", (int8_t *)0L, " writing sequences",
|
---|
| 94 | LCFBX10, LCBBX10);
|
---|
| 95 |
|
---|
| 96 | for (seq = 0; seq < NSLINES; seq++) {
|
---|
| 97 |
|
---|
| 98 | cb = 0x00;
|
---|
| 99 |
|
---|
| 100 | if (seqtab[seq].seqtime)
|
---|
| 101 | cb |= 0x08;
|
---|
| 102 |
|
---|
| 103 | if (seqtab[seq].seqact1)
|
---|
| 104 | cb |= 0x04;
|
---|
| 105 |
|
---|
| 106 | if (seqtab[seq].seqact2)
|
---|
| 107 | cb |= 0x02;
|
---|
| 108 |
|
---|
| 109 | if (seqtab[seq].seqact3)
|
---|
| 110 | cb |= 0x01;
|
---|
| 111 |
|
---|
| 112 | if (0 EQ cb)
|
---|
| 113 | continue;
|
---|
| 114 |
|
---|
| 115 | if (wr_ec(fp, &cb, 1L)) /* Control byte */
|
---|
| 116 | return(FAILURE);
|
---|
| 117 |
|
---|
| 118 | if (wr_ec(fp, &seq, 2L)) /* Line number */
|
---|
| 119 | return(FAILURE);
|
---|
| 120 |
|
---|
| 121 | if (cb & 0x08) /* Time */
|
---|
| 122 | if (wr_ec(fp, &seqtab[seq].seqtime, 2L))
|
---|
| 123 | return(FAILURE);
|
---|
| 124 |
|
---|
| 125 | if (cb & 0x04) /* Action 1 */
|
---|
| 126 | if (wr_ec(fp, &seqtab[seq].seqact1, 4L))
|
---|
| 127 | return(FAILURE);
|
---|
| 128 |
|
---|
| 129 | if (cb & 0x02) /* Action 2 */
|
---|
| 130 | if (wr_ec(fp, &seqtab[seq].seqact2, 4L))
|
---|
| 131 | return(FAILURE);
|
---|
| 132 |
|
---|
| 133 | if (cb & 0x01) /* Action 3 */
|
---|
| 134 | if (wr_ec(fp, &seqtab[seq].seqact3, 4L))
|
---|
| 135 | return(FAILURE);
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | if (wr_ec(fp, &zero, 1L)) /* terminator */
|
---|
| 139 | return(FAILURE);
|
---|
| 140 |
|
---|
| 141 | #if DEBUGIT
|
---|
| 142 | if (debugsw)
|
---|
| 143 | printf("sqwrite(): SUCCESS\n");
|
---|
| 144 | #endif
|
---|
| 145 |
|
---|
[6262b5c] | 146 | return(SUCCESS);
|
---|
| 147 | }
|
---|
| 148 |
|
---|