/* * Writes a 16-bit word, low-order byte first, at the given pointer. * * w the word to write out (upper 16 bits are ignored) * pp address of pointer to write w at; incremented on exit */ static void w_out(uint16_t w, uint8_t **pp) { assert(pp); b_out((uint8_t)w,pp); w >>= 8; b_out((uint8_t)w,pp); }
/* * Writes a catalog-sector link at the given pointer. * * sect sector number, or zero to mean "no link" * track catalog track number * pp address of pointer to start writing at; incremented on exit */ static void sector_link_out(uint8_t sect, uint8_t track, uint8_t **pp) { assert(pp); b_out(0,pp); if (sect) { b_out(track,pp); } else { b_out(0,pp); } b_out(sect,pp); }
static void map_out(uint16_t m, uint8_t **pp) { assert(pp); b_out((uint8_t)(m >> 8),pp); b_out((uint8_t)m,pp); w_out(UINT16_C(0),pp); }
/* * Writes n 8-bit bytes at the given pointer. * * n the number of times to write b * b the byte to write out * pp address of pointer to start writing b's at; incremented on exit */ static void n_b_out(uint_fast32_t n, uint8_t b, uint8_t **pp) { assert(pp); while (n--) { b_out(b,pp); } }
static void catalog_VTOC_out(uint_fast16_t version, uint8_t catalog_track, uint_fast8_t used, uint8_t volume, uint8_t **pp) { assert(pp); sector_link_out((uint8_t)(sectors_per_track(version)-1),catalog_track,pp); b_out(calc_dos_version_byte(version),pp); n_b_out(2,0,pp); b_out(volume,pp); n_b_out(0x20,0,pp); b_out(get_max_ts_in_filemap(),pp); n_b_out(8,0,pp); b_out(catalog_track,pp); b_out(1,pp); n_b_out(2,0,pp); b_out(TRACKS_PER_DISK,pp); b_out(sectors_per_track(version),pp); w_out(BYTES_PER_SECTOR,pp); volume_sector_map_out(version,catalog_track,used,pp); n_b_out(60,0,pp); }
static void test_b_out(ctest_ctx *ctx) { const uint8_t SENTINEL = UINT8_C(0xFD); uint8_t image[3]; const uint8_t TAG = UINT8_C(0xa5); const uint8_t b = TAG; uint8_t *p = image+1; image[0] = SENTINEL; image[1] = SENTINEL; image[2] = SENTINEL; b_out(b,&p); CTEST(ctx,image[1]==TAG); CTEST(ctx,image[0]==SENTINEL); CTEST(ctx,image[2]==SENTINEL); CTEST(ctx,p==image+2); }
static void output_data(int32 *buf, int32 count) { int ocount; if (!(dpm.encoding & PE_MONO)) count*=2; /* Stereo samples */ ocount = count; if (ocount) { if (dpm.encoding & PE_16BIT) { /* Convert data to signed 16-bit PCM */ s32tos16(buf, count); ocount *= 2; } else { /* Convert to 8-bit unsigned and write out. */ s32tou8(buf, count); } } b_out(dpm.fd, (int *)buf, ocount); }