class Z80::TAP::HeaderBody
A class that represents the optional header and the single body chunk of a TAP file.
Instances of this class are produced by methods such as: TAP#to_tap_chunk or TAP.parse_file.
Properties:
-
headeras a Z80::TAP::Header instance ornil -
bodyas a ::Z80::TAP::Body instance
HeaderBody#to_tap produces a TAP blob as a binary string.
Attributes
Public Class Methods
# File lib/z80/tap.rb, line 117 def initialize(header, body) @header = header @body = body end
Creates a HeaderBody of the type TYPE_CODE.
-
nameshould contain max 10 ascii characters. -
codeshould be a binary string. -
orgshould be an integer indicating the starting address of the code.
# File lib/z80/tap.rb, line 176 def new_code(name, code, org) HeaderBody.new( Header.new(TYPE_CODE, name, code.bytesize, org, 0x8000), Body.new(code) ) end
Creates a HeaderBody of the type TYPE_PROGRAM.
-
nameshould contain max 10 ascii characters. -
codeshould be a binary string representing ZX Spectrum's program and variables. -
optional
lineshould be an integer indicating the starting line of the program. -
optional
prog_lengthshould be an integer indicating the length (in bytes) of the program.
# File lib/z80/tap.rb, line 189 def new_program(name, code, line:nil, prog_length:nil) HeaderBody.new( Header.new(TYPE_PROGRAM, name, code.bytesize, line || 32768, prog_length || code.bytesize), Body.new(code) ) end
Creates a HeaderBody of the type TYPE_NUMBER_ARRAY or TYPE_CHAR_ARRAY.
-
nameshould contain max 10 ascii characters. -
codeshould be a binary string representing ZX Spectrum's array variable body. -
headshould be the header octet of the variable data. Based on this number the appropriate type of the tap file is being chosen.
# File lib/z80/tap.rb, line 202 def new_var_array(name, code, head) type = case head & 0b11100000 when 0b10000000 TYPE_NUMBER_ARRAY when 0b11000000 TYPE_CHAR_ARRAY else raise TapeError, "can't guess TAP type from a variable head" end p1 = (head & 0xff) << 8 HeaderBody.new( Header.new(type, name, code.bytesize, p1, 0x8000), Body.new(code) ) end
Public Instance Methods
true if this chunk represents a number or character array
# File lib/z80/tap.rb, line 151 def array? header && header.array? end
true if this chunk represents a code
# File lib/z80/tap.rb, line 161 def code? header && header.code? end
true if this chunk represents a basic program
# File lib/z80/tap.rb, line 156 def program? header && header.program? end
Saves this chunk as a TAP file.
filename specifies the file name to save to. The “.tap” extension may be omitted.
If :append is true the data will be appended to the file. Otherwise the file is being truncated.
# File lib/z80/tap.rb, line 137 def save_tap(filename, append:false) filename+= '.tap' unless File.extname(filename).downcase == '.tap' File.open(filename, append ? 'ab' : 'wb') {|f| f.write to_tap } end
true if this chunk represents a screen data
# File lib/z80/tap.rb, line 166 def screen? header && header.screen? end
For humans.
# File lib/z80/tap.rb, line 123 def to_s if header.nil? "Bytes: ?????????? (#{body.data.bytesize})" else header.to_s end end
Produces a TAP blob as a binary string from this chunk.
# File lib/z80/tap.rb, line 143 def to_tap res = '' res << header.to_tap unless header.nil? res << body.to_tap(header && header.length) unless body.nil? res end