public void addByte(Address address, byte b) {
        if (done) {
            throw new IllegalStateException("cannot addByte() after finish()");
        }

        if (isSegmented == null) {
            if (address.getAddressSpace() instanceof SegmentedAddressSpace) {
                isSegmented = true;
            } else {
                isSegmented = false;
            }
        }

        long offset;
        long newSegment;
        if (isSegmented) {
            offset = ((SegmentedAddress)address).getSegmentOffset();
            newSegment = ((SegmentedAddress)address).getSegment();
        } else {
            offset = address.getOffset();
            newSegment = offset & 0xffff0000;
        }
        boolean changeSegment = false;

        if (oldSegment == null) {
            changeSegment = true;
        } else {
            if (newSegment != oldSegment) {
                changeSegment = true;
            }
        }

        if (changeSegment) {
            emitData();
            byte[] data = new byte[2];
            if (isSegmented) {
                SegmentedAddress saddress = (SegmentedAddress) address;
                int segment = saddress.getSegment();
                data[0] = (byte) ((segment >> 8) & 0xff);
                data[1] = (byte) (segment & 0xff);
                results.add(new IntelHexRecord(2, 0, 2, data));
            } else {
                data[0] = (byte) ((offset >> 24) & 0xff);
                data[1] = (byte) ((offset >> 16) & 0xff);
                results.add(new IntelHexRecord(2, 0, 4, data));
            }
            oldSegment = newSegment;
        }

        if (startAddress == null) {
            startAddress = address;
        }

        bytes.add(b);

        if (bytes.size() >= maxBytesPerLine) {
            emitData();
        }
    }
Constructor

@param maxBytesPerLine the maximum number of bytes to write per line in the hex output
@param dropExtraBytes if true, only lines matching {@link #maxBytesPerLine} will be output; 
remaining bytes will be left out
Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/IntelHexRecordWriter.java