Class: HGR
- Inherits:
-
Object
- Object
- HGR
- Defined in:
- lib/HGR.rb
Constant Summary collapse
- PALLETE_MODES =
[:white,:green,:amber,:colour]
- PALLETE =
{ :white=>PNG::Color::White, :green=>PNG::Color.new(0x00, 0x99, 0x00, 0xFF), :amber=>PNG::Color::Orange }
- HGR_BLACK =
PNG::Color::Black
- HGR_GREEN =
color=0,4
PNG::Color.new(0x2F,0xB8,0x1F,0xFF)
- HGR_VIOLET =
color=2
PNG::Color.new(0xC8,0x47,0xE4,0xFF)
- HGR_WHITE =
color=3,7
PNG::Color::White
- HGR_ORANGE =
color=5
PNG::Color.new(0xC7,0x70,0x28,0xFF)
- HGR_BLUE =
color=6
PNG::Color.new(0x30,0x8F,0xE3,0xFF)
- HGR_COLS =
40*7
- HGR_ROWS =
8*8*3
- SCALE =
2
- @@scanline_offsets =
per Apple // Reference Manual for //e chapter 2, pages 22-35 also TechNote - Apple IIe #3 Double High-Resolution Graphics - 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?
Array.new(HGR_ROWS)
Class Method Summary collapse
- .buffer_to_png(buffer, pallete_mode = :amber) ⇒ Object
-
.can_be_hgr_screen?(buffer, memory_location = nil) ⇒ Boolean
HGR screen is 8192 bytes stored at either $2000 (page 1) or $4000 (page 2).
Class Method Details
.buffer_to_png(buffer, pallete_mode = :amber) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/HGR.rb', line 94 def HGR.buffer_to_png(buffer,pallete_mode=:amber) 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 pallete_mode==:colour then if (last_bit_set) then #adjacent pixels should both be white set_pixel(canvas,x-1,y,HGR_WHITE) 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] set_pixel(canvas,x,y,this_pixel_colour) set_pixel(canvas,x+1,y,this_pixel_colour) end else this_pixel_colour=PALLETE[pallete_mode] this_pixel_colour=PALLETE.values[0] if this_pixel_colour.nil? set_pixel(canvas,x,y,this_pixel_colour) end end last_bit_set=bit_set end end end png = PNG.new canvas png.raw_bytes end |
.can_be_hgr_screen?(buffer, memory_location = nil) ⇒ Boolean
HGR screen is 8192 bytes stored at either $2000 (page 1) or $4000 (page 2)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/HGR.rb', line 69 def HGR.can_be_hgr_screen?(buffer,memory_location=nil) #because only 120 out of every 128 bytes are shown, the last 8 bytes are not needed #in order to save a sector under dos 3.3 it was common to only store 8192=8184 (0x1FF8) bytes #sometimes an extra sector was included by mistake if (buffer.length>=8184 && buffer.length<=8192) && ((memory_location.nil?) || (memory_location==0)) return true end if (buffer.length>=8184) && ((memory_location==0x2000) || (memory_location==0x4000)) return true end false end |