Class: Coco

Inherits:
HostSystem show all
Defined in:
lib/host_systems/Coco.rb

Constant Summary collapse

COCO_COLOURS =
[
PNG::Color.new(90, 211, 49,0xFF), #green
PNG::Color.new(247, 227, 99,0xFF),#yellow
PNG::Color.new(24, 0, 140,0xFF),#blue
PNG::Color.new(140,0,16,0xFF),#red
PNG::Color.new(0xff,0xfb,0xff,0xff),#white/buff
PNG::Color.new(33, 195, 115,0xFF),#cyan
PNG::Color.new(0x63,0x00,0x63,0xFF),#magenta
PNG::Color.new(255, 146, 140,0xFF),#orange
]
COCO_BLOCK_QUADRANT_OFFSETS =
[
  [4,6],  
  [0,6],
  [4,0],
  [0,0],
]

Constants inherited from HostSystem

HostSystem::MAX_SCREENDUMP_LINES

Class Method Summary collapse

Methods inherited from HostSystem

all_host_systems, font_data, hex_dump, line_break_chars, possible_file_systems, s_to_ascii

Methods included from SubclassTracking

extended

Class Method Details

.default_background_colourObject



56
57
58
# File 'lib/host_systems/Coco.rb', line 56

def self.default_background_colour
  COCO_COLOURS[0]
end

.default_foreground_colourObject



52
53
54
# File 'lib/host_systems/Coco.rb', line 52

def self.default_foreground_colour  
    PNG::Color::Black
end

.default_screen_widthObject



32
33
34
# File 'lib/host_systems/Coco.rb', line 32

def self.default_screen_width
  32
end

.font_data_filenameObject



24
25
26
# File 'lib/host_systems/Coco.rb', line 24

def self.font_data_filename
File.dirname(__FILE__) +'/coco-font.bin'
end

.font_heightObject



44
45
46
# File 'lib/host_systems/Coco.rb', line 44

def self.font_height
  12
end

.font_widthObject



40
41
42
# File 'lib/host_systems/Coco.rb', line 40

def self.font_width
  8
end

.full_nameObject



12
13
14
# File 'lib/host_systems/Coco.rb', line 12

def self.full_name
    "Tandy Colour Computer"
end

.max_screen_widthObject



36
37
38
# File 'lib/host_systems/Coco.rb', line 36

def self.max_screen_width
  32
end

.pixels_between_charactersObject



48
49
50
# File 'lib/host_systems/Coco.rb', line 48

def self.pixels_between_characters
  0
end

.screen_rowsObject



28
29
30
# File 'lib/host_systems/Coco.rb', line 28

def self.screen_rows
  16
end

.start_trackObject



16
17
18
# File 'lib/host_systems/Coco.rb', line 16

def Coco.start_track
    0
end

.to_ascii(b) ⇒ Object



20
21
22
# File 'lib/host_systems/Coco.rb', line 20

def Coco.to_ascii(b)    
  b.chr
end

.to_screendump(text, screen_width) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/host_systems/Coco.rb', line 78

def self.to_screendump(text,screen_width)
  lines=split_into_lines(text,screen_width)  
  canvas = PNG::Canvas.new font_width*screen_width, (pixels_between_characters+font_height)*[lines.length,screen_rows].max, default_background_colour
  line_number=0
  lines.each do |line|
    col=0
    line.each_byte do |char|
      if (char>=0x80) then
        colour_mask=((char & 0b01110000)>>4)
        foreground_colour=COCO_COLOURS[colour_mask]
        4.times do |quadrant|
          quadrant_mask=1<<quadrant
          if (char & quadrant_mask)>0 then
            block_colour=foreground_colour
          else 
            block_colour=PNG::Color::Black
          end
        
          start_x=(col*8)+COCO_BLOCK_QUADRANT_OFFSETS[quadrant][0]
          start_y=(line_number*12)+COCO_BLOCK_QUADRANT_OFFSETS[quadrant][1]
          6.times do |y_offset|
            4.times do |x_offset|
                canvas[start_x+x_offset, start_y+y_offset]=block_colour
              end
            end
        end
      else #if char is 0..0x3F it's an inverse uppercase char
        case char
        when 0x00..0x3F then
          draw_char_at(canvas,char,line_number,col,default_background_colour,default_foreground_colour) 
        else
          draw_char_at(canvas,char-0x40,line_number,col,default_foreground_colour,default_background_colour) 
        end
      end     
     col+=1 
    end    
    line_number+=1
  end  
  PNG.new(canvas).raw_bytes
end