$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__))) require 'PatchedPNG' class AppleHiResPic0x04, NADOLDos=>:any, PascalDos=>0x07 } end is_valid_file_if lambda { is_valid=true if file_system_image.file_system==AppleDos then load_address=AppleBinary.load_address(contents) is_valid=((contents.length>=8184) && (contents.length<=9000) && ((load_address==0x2000) || load_address==0x4000)) end if file_system_image.file_system==NADOLDos then is_valid=(contents.length==8192) end is_valid } #colours cribbed from http://groups.google.com.au/group/comp.sys.apple2/browse_thread/thread/b9aa36ead6935c42/faa0f4df3e89060f HGR_BLACK=PNG::Color::Black #color=0,4 HGR_GREEN=PNG::Color.new(0x2F,0xB8,0x1F,0xFF) #color=1 HGR_VIOLET=PNG::Color.new(0xC8,0x47,0xE4,0xFF) #color=2 HGR_WHITE=PNG::Color::White #color=3,7 HGR_ORANGE=PNG::Color.new(0xC7,0x70,0x28,0xFF) #color=5 HGR_BLUE=PNG::Color.new(0x30,0x8F,0xE3,0xFF) #color=6 HGR_COLS=40*7 HGR_ROWS=8*8*3 SCALE=1 #per Apple // Reference Manual for //e chapter 2, pages 22-35 #also TechNote - Apple IIe #3 Double High-Resolution Graphics - http://web.pdx.edu/~heiss/technotes/aiie/tn.aiie.03.html #HGR screen consists of 3 bands of 8 rows of 8 scanlines #for each absolute scanline, what is the offset into screen ram that the 40 bytes for this scanline is stored? @@scanline_offsets=Array.new(HGR_ROWS) 0.upto(2) do |band| 0.upto(7) do |row| 0.upto(7) do |relative_scanline| band_ram_offset=band*40 band_scanline_offset=band*64 scanline_ram_offset=relative_scanline*1024 scanline_scanline_offset=relative_scanline row_ram_offset=128*row row_scanline_offset=8*row scanline_offset=band_scanline_offset+scanline_scanline_offset+row_scanline_offset ram_offset=band_ram_offset+scanline_ram_offset+row_ram_offset @@scanline_offsets[scanline_offset]=ram_offset end end end def self.matching_score [AppleBinary.matching_score+1,NADOLFile.matching_score+1].max end #Apple DOS Binary files have the load address stored in first two bytes of the file, in LO, HI order def load_address if file_system_image.file_system==AppleDos then return contents[0]+contents[1]*256 else return 0x2000 end end def to_png if file_system_image.file_system==AppleDos then buffer=contents[4,contents.length-4] else buffer=contents end canvas = PNG::Canvas.new HGR_COLS*SCALE, HGR_ROWS*SCALE, PNG::Color::Black 0.upto(HGR_ROWS-1) do |y| last_bit_set=false 0.upto(39) do |x_byte| offset=@@scanline_offsets[y]+x_byte current_byte=buffer[offset] current_byte=0 if current_byte.nil? #if we overrun the buffer then assume it's black 0.upto(6) do |x_bit| x=x_byte*7+x_bit bit_set=((current_byte & (2**x_bit))>0) if (bit_set) then if (last_bit_set) then #adjacent pixels should both be white AppleHiResPic.set_pixel(canvas,x-1,y,HGR_WHITE) AppleHiResPic.set_pixel(canvas,x,y,HGR_WHITE) else if current_byte>=0x80 then pallete=[HGR_BLUE,HGR_ORANGE] else pallete=[HGR_VIOLET,HGR_GREEN] end this_pixel_colour=pallete[x%2] AppleHiResPic.set_pixel(canvas,x,y,this_pixel_colour) AppleHiResPic.set_pixel(canvas,x+1,y,this_pixel_colour) unless x>=HGR_ROWS end end last_bit_set=bit_set end end end png = PNG.new canvas result=png.raw_bytes result end def png_width HGR_COLS*SCALE end def png_height HGR_ROWS*SCALE end private def self.set_pixel(canvas,x,y,colour) 0.upto(SCALE-1) do |row| 0.upto(SCALE-1) do |col| canvas[x*SCALE+col, y*SCALE+row]= colour end end end end # == Author # Jonno Downes (jonno@jamtronix.com) # # == Copyright # Copyright (c) 2008 Jonno Downes (jonno@jamtronix.com) # #Permission is hereby granted, free of charge, to any person obtaining #a copy of this software and associated documentation files (the #"Software"), to deal in the Software without restriction, including #without limitation the rights to use, copy, modify, merge, publish, #distribute, sublicense, and/or sell copies of the Software, and to #permit persons to whom the Software is furnished to do so, subject to #the following conditions: # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.