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:

HeaderBody#to_tap produces a TAP blob as a binary string.

Attributes

body[R]
header[R]

Public Class Methods

new(header, body) click to toggle source
# File lib/z80/tap.rb, line 117
def initialize(header, body)
        @header = header
        @body = body
end
new_code(name, code, org) click to toggle source

Creates a HeaderBody of the type TYPE_CODE.

  • name should contain max 10 ascii characters.

  • code should be a binary string.

  • org should 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
new_program(name, code, line:nil, prog_length:nil) click to toggle source

Creates a HeaderBody of the type TYPE_PROGRAM.

  • name should contain max 10 ascii characters.

  • code should be a binary string representing ZX Spectrum's program and variables.

  • optional line should be an integer indicating the starting line of the program.

  • optional prog_length should 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
new_var_array(name, code, head) click to toggle source

Creates a HeaderBody of the type TYPE_NUMBER_ARRAY or TYPE_CHAR_ARRAY.

  • name should contain max 10 ascii characters.

  • code should be a binary string representing ZX Spectrum's array variable body.

  • head should 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

array?() click to toggle source

true if this chunk represents a number or character array

# File lib/z80/tap.rb, line 151
def array?
        header && header.array?
end
code?() click to toggle source

true if this chunk represents a code

# File lib/z80/tap.rb, line 161
def code?
        header && header.code?
end
program?() click to toggle source

true if this chunk represents a basic program

# File lib/z80/tap.rb, line 156
def program?
        header && header.program?
end
save_tap(filename, append:false) click to toggle source

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
screen?() click to toggle source

true if this chunk represents a screen data

# File lib/z80/tap.rb, line 166
def screen?
        header && header.screen?
end
to_s() click to toggle source

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
to_tap() click to toggle source

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