Class: HostSystem
- Inherits:
-
Object
- Object
- HostSystem
- Extended by:
- SubclassTracking
- Defined in:
- lib/HostSystem.rb
Constant Summary collapse
- MAX_SCREENDUMP_LINES =
200
Class Method Summary collapse
- .all_host_systems ⇒ Object
-
.default_background_colour ⇒ Object
default - should be overridden by each host system.
-
.default_foreground_colour ⇒ Object
default - should be overridden by each host system.
-
.default_screen_width ⇒ Object
default - should be overridden by each host system.
- .font_data ⇒ Object
-
.font_height ⇒ Object
default - should be overridden by each host system.
-
.font_width ⇒ Object
default - should be overridden by each host system.
-
.full_name ⇒ Object
each subclass should override this method with a 2-5 word description of this host system.
-
.hex_dump(buffer) ⇒ Object
given a buffer (e.g a sector or a file), produce a formatted hex dump which includes chars converted to ASCII.
- .line_break_chars ⇒ Object
- .max_screen_width ⇒ Object
-
.pixels_between_characters ⇒ Object
default - should be overridden by each host system.
- .possible_file_systems ⇒ Object
- .s_to_ascii(s) ⇒ Object
-
.screen_rows ⇒ Object
default - should be overridden by each host system.
-
.start_track ⇒ Object
does counting of tracks start at track 0 (e.g. Apple 2) or track 1 (e.g. C64)?.
-
.to_ascii(byte) ⇒ Object
each subclass should override to_ascii with a function that converts a character in the native format to an ASCII equivalent.
- .to_screendump(text, screen_width) ⇒ Object
Methods included from SubclassTracking
Class Method Details
.all_host_systems ⇒ Object
26 27 28 |
# File 'lib/HostSystem.rb', line 26 def HostSystem.all_host_systems HostSystem.subclasses end |
.default_background_colour ⇒ Object
default - should be overridden by each host system
109 110 111 |
# File 'lib/HostSystem.rb', line 109 def self.default_background_colour PNG::Color::Black end |
.default_foreground_colour ⇒ Object
default - should be overridden by each host system
104 105 106 |
# File 'lib/HostSystem.rb', line 104 def self.default_foreground_colour PNG::Color::White end |
.default_screen_width ⇒ Object
default - should be overridden by each host system
80 81 82 |
# File 'lib/HostSystem.rb', line 80 def self.default_screen_width 40 end |
.font_data ⇒ Object
69 70 71 72 |
# File 'lib/HostSystem.rb', line 69 def self.font_data @font_data=File.new(font_data_filename,"rb").read if @font_data.nil? @font_data end |
.font_height ⇒ Object
default - should be overridden by each host system
94 95 96 |
# File 'lib/HostSystem.rb', line 94 def self.font_height 8 end |
.font_width ⇒ Object
default - should be overridden by each host system
89 90 91 |
# File 'lib/HostSystem.rb', line 89 def self.font_width 8 end |
.full_name ⇒ Object
each subclass should override this method with a 2-5 word description of this host system
13 14 15 |
# File 'lib/HostSystem.rb', line 13 def self.full_name nil end |
.hex_dump(buffer) ⇒ Object
given a buffer (e.g a sector or a file), produce a formatted hex dump which includes chars converted to ASCII
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/HostSystem.rb', line 44 def HostSystem.hex_dump(buffer) s="" (0..(buffer.length/16)).each {|line_number| lhs="" rhs="" start_byte=line_number*16 line=buffer[start_byte,16] if line.length>0 then line.each_byte {|byte| lhs+= sprintf("%02X ", byte) rhs+= to_ascii(byte).sub(/[\x00-\x1f]/,'.') } lhs+=" "*(16-line.length)*3 s+=sprintf("%02X\t%s %s\n",start_byte,lhs,rhs) end } s end |
.line_break_chars ⇒ Object
129 130 131 |
# File 'lib/HostSystem.rb', line 129 def self.line_break_chars [0x0D] end |
.max_screen_width ⇒ Object
84 85 86 |
# File 'lib/HostSystem.rb', line 84 def self.max_screen_width 80 end |
.pixels_between_characters ⇒ Object
default - should be overridden by each host system
99 100 101 |
# File 'lib/HostSystem.rb', line 99 def self.pixels_between_characters 0 end |
.possible_file_systems ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/HostSystem.rb', line 17 def HostSystem.possible_file_systems results=[] FileSystem.all_file_systems.each do |candidate| results<<candidate if self==candidate.host_system end results end |
.s_to_ascii(s) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/HostSystem.rb', line 35 def HostSystem.s_to_ascii(s) r="" s.each_byte do |b| r+=to_ascii(b) end r end |
.screen_rows ⇒ Object
default - should be overridden by each host system
75 76 77 |
# File 'lib/HostSystem.rb', line 75 def self.screen_rows 25 end |
.start_track ⇒ Object
does counting of tracks start at track 0 (e.g. Apple 2) or track 1 (e.g. C64)?
64 65 66 |
# File 'lib/HostSystem.rb', line 64 def HostSystem.start_track 0 end |
.to_ascii(byte) ⇒ Object
each subclass should override to_ascii with a function that converts a character in the native format to an ASCII equivalent
31 32 33 |
# File 'lib/HostSystem.rb', line 31 def HostSystem.to_ascii(byte) byte.chr end |
.to_screendump(text, screen_width) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/HostSystem.rb', line 113 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| draw_char_at(canvas,char,line_number,col) col+=1 end line_number+=1 end PNG.new(canvas).raw_bytes end |