looking for stuck bits in ROM dumps

I have been playing around with disassembling some code that was apparently the bootstrap PROM for the SacState 8008 machine. The code was given to me as 8 BIN files, 256 bytes each, one for each PROM dump. One section of the code looked very odd, and I began to suspect a faulty read. One common error when reading old chips is a single pin can be shorted, or broken, such that every bit from that chip is read as the same value. So I put this script together to see if any of the files, every byte had the same value in 1 bit.

My hunch was correct – in one of the files, bit 5 was always 1, and that file coincided exactly with the very odd looking code. So to continue disassembling that file, I needed to select the value for bit 5 that made the most sense based on context.

#!/usr/bin/ruby
def abort(s)
	puts s
	Process.exit
end

abort "no filename specified" unless ARGV.length>0
ARGV.each do |filename|
	abort "#{filename} not found" unless File.exists?(filename)

	s=File.open(filename).read
	puts "#{filename}: #{s.length} bytes"
	8.times do |bit|
		bitmask= (1 << bit)
		set_found=false
		clear_found=false
		s.each_byte do |byte|
			set_found=true if (byte & bitmask >0)
			clear_found=true if (byte & bitmask ==0)
		end
		puts "bit #{bit} always 0 in file #{filename}" unless set_found
		puts "bit #{bit} always 1 in file #{filename}" unless clear_found

	end
	
end