beampos=0;
samples=0;
beampos=video_silence(framebuffer,beampos,362000);
samples=audio_silence(audiobuffer,samples,362000);
beampos=video_leader(framebuffer,beampos,2);
samples=audio_leader(audiobuffer,samples,2);
checksum=0;
for (n=0 ; n<18 ; n++) {
header_byte="\x00\x03MYFILENAME\x00\x1B\x00\x40\x00\x80"[n];
beampos=video_byte_out(framebuffer,beampos,header_byte);
samples=audio_byte_out(audiobuffer,samples,header_byte);
checksum=(checksum^header_byte);
}
beampos=video_byte_out(framebuffer,beampos,checksum);
samples=audio_byte_out(audiobuffer,samples,checksum);
beampos=video_silence(framebuffer,beampos,3500000);
samples=audio_silence(audiobuffer,samples,3500000);
beampos=video_leader(framebuffer,beampos,2);
samples=audio_leader(audiobuffer,samples,2);
/* A data block begins with a byte set to 255. Header blocks begin with a byte set to 0. */
beampos=video_byte_out(framebuffer,beampos,255);
samples=audio_byte_out(audiobuffer,samples,255);
checksum=255;
/* Now we output the supplied PBM file as bitmap in the layout of the spectrum screen memory. */
for (n=0;n<6144;n++) {
/* To convert between a linear layout and the non-linear layout a spectrum bitmap, we need to swap bits 5-7 with bits 8-10. */
/* AACCCBBBAAAAA */
/* A bitmask = 31+2048+4096 = 6175 */
/* B bitmask = 32+64+128 = 224 */
/* C bitmask = 256+512+1024= 1792 */
bitmaskB=(n & 224) << 3;
bitmaskC=(n & 1794) >> 3;
m=(n & 6175) | bitmaskB | bitmaskC;
beampos=video_byte_out(framebuffer,beampos,*(input_bitmap+m));
framebuffer_set_pixels(framebuffer,m,255^*(input_bitmap+m));
samples=audio_byte_out(audiobuffer,samples,*(input_bitmap+m));
checksum=(checksum^(*(input_bitmap+m)));
}
/* In a real spectrum screen image, attribute data follows the bitmap data. */
/* Since we are going to draw the 24-bit RGB image from the supplied PPM file into the framebuffer, there is obviously no real attribute data. */
/* Rather than just using random data, we generate bytes that are based on the average RGB color values of the pixels in each 8x8 pixel block. */
/* This at least makes the sound and visual waveforms relate to the 24-bit RGB image being drawn in some way. */
for (n=0 ; n<768 ; n++) {
false_attribute=average_block_color(input_rgb_pixelmap,n);
beampos=video_byte_out(framebuffer, beampos, false_attribute);
samples=audio_byte_out(audiobuffer, samples, false_attribute);
checksum=(checksum^false_attribute);
framebuffer_set_block(framebuffer, input_rgb_pixelmap, n);
}
beampos=video_byte_out(framebuffer,beampos,checksum);
samples=audio_byte_out(audiobuffer,samples,checksum);
beampos=video_silence(framebuffer,beampos,350000);
samples=audio_silence(audiobuffer,samples,350000);