mirror of
https://github.com/robmcmullen/atrcopy.git
synced 2024-06-10 06:29:34 +00:00
Replaced fromstring with frombuffer (and copy if necessary)
This commit is contained in:
parent
ce66a0c8b0
commit
dafba8e74c
|
@ -251,7 +251,7 @@ class Dos33Dirent(Dirent):
|
||||||
values[1] = self.sector
|
values[1] = self.sector
|
||||||
values[2] = self.flag
|
values[2] = self.flag
|
||||||
n = min(len(self.filename), 30)
|
n = min(len(self.filename), 30)
|
||||||
data[3:3+n] = np.fromstring(self.filename.encode("ascii"), dtype=np.uint8) | 0x80
|
data[3:3+n] = np.frombuffer(self.filename.encode("ascii"), dtype=np.uint8) | 0x80
|
||||||
data[3+n:] = ord(' ') | 0x80
|
data[3+n:] = ord(' ') | 0x80
|
||||||
if self.deleted:
|
if self.deleted:
|
||||||
data[0x20] = self.track
|
data[0x20] = self.track
|
||||||
|
|
|
@ -86,7 +86,7 @@ xexboot_header = b'\x00\x03\x00\x07\r\x07L\r\x07\x1c[\x00\x00\xa0\x00\x8c\t\x03\
|
||||||
|
|
||||||
|
|
||||||
def insert_bytes(data, offset, string, color):
|
def insert_bytes(data, offset, string, color):
|
||||||
s = np.fromstring(string.upper(), dtype=np.uint8) - 32 # convert to internal
|
s = np.frombuffer(string.upper(), dtype=np.uint8) - 32 # convert to internal
|
||||||
s = s | color
|
s = s | color
|
||||||
count = len(s)
|
count = len(s)
|
||||||
tx = offset + (20 - count) // 2
|
tx = offset + (20 - count) // 2
|
||||||
|
@ -103,7 +103,7 @@ def add_xexboot_header(bytes, bootcode=None, title=b"DEMO", author=b"an atari us
|
||||||
paragraphs = padded_size // 16
|
paragraphs = padded_size // 16
|
||||||
|
|
||||||
if bootcode is None:
|
if bootcode is None:
|
||||||
bootcode = np.fromstring(xexboot_header, dtype=np.uint8)
|
bootcode = np.copy(np.frombuffer(xexboot_header, dtype=np.uint8))
|
||||||
else:
|
else:
|
||||||
# don't insert title or author in user supplied bootcode; would have to
|
# don't insert title or author in user supplied bootcode; would have to
|
||||||
# assume that the user supplied everything desired in their own code!
|
# assume that the user supplied everything desired in their own code!
|
||||||
|
|
|
@ -46,7 +46,7 @@ class MameZipImage(DiskImageBase):
|
||||||
segment_info = []
|
segment_info = []
|
||||||
offset = 0
|
offset = 0
|
||||||
for item in zf.infolist():
|
for item in zf.infolist():
|
||||||
rom = np.fromstring(zf.open(item).read(), dtype=np.uint8)
|
rom = np.frombuffer(zf.open(item).read(), dtype=np.uint8)
|
||||||
roms.append(rom)
|
roms.append(rom)
|
||||||
segment_info.append((offset, item.file_size, item.filename, item.CRC))
|
segment_info.append((offset, item.file_size, item.filename, item.CRC))
|
||||||
offset += item.file_size
|
offset += item.file_size
|
||||||
|
|
|
@ -165,7 +165,7 @@ from . fstbt import fstbt
|
||||||
|
|
||||||
def get_fstbt_code(data, address_list, run_addr):
|
def get_fstbt_code(data, address_list, run_addr):
|
||||||
pointer = len(fstbt)
|
pointer = len(fstbt)
|
||||||
data[0:pointer] = np.fromstring(fstbt, dtype=np.uint8)
|
data[0:pointer] = np.frombuffer(fstbt, dtype=np.uint8)
|
||||||
hi, lo = divmod(run_addr, 256)
|
hi, lo = divmod(run_addr, 256)
|
||||||
data[pointer:pointer + 2] = (lo, hi)
|
data[pointer:pointer + 2] = (lo, hi)
|
||||||
address_list.append(0xc0) # last sector flag
|
address_list.append(0xc0) # last sector flag
|
||||||
|
|
|
@ -29,7 +29,7 @@ def to_numpy(value):
|
||||||
if type(value) is np.ndarray:
|
if type(value) is np.ndarray:
|
||||||
return value
|
return value
|
||||||
elif type(value) is bytes:
|
elif type(value) is bytes:
|
||||||
return np.fromstring(value, dtype=np.uint8)
|
return np.copy(np.frombuffer(value, dtype=np.uint8))
|
||||||
elif type(value) is list:
|
elif type(value) is list:
|
||||||
return np.asarray(value, dtype=np.uint8)
|
return np.asarray(value, dtype=np.uint8)
|
||||||
raise TypeError("Can't convert to numpy data")
|
raise TypeError("Can't convert to numpy data")
|
||||||
|
|
|
@ -25,7 +25,7 @@ class BaseFilesystemModifyTest:
|
||||||
filename = "%s%d.BIN" % (prefix, count)
|
filename = "%s%d.BIN" % (prefix, count)
|
||||||
self.image.write_file(filename, None, data)
|
self.image.write_file(filename, None, data)
|
||||||
assert len(self.image.files) == orig_num_files + count
|
assert len(self.image.files) == orig_num_files + count
|
||||||
data2 = np.fromstring(self.image.find_file(filename), dtype=np.uint8)
|
data2 = np.frombuffer(self.image.find_file(filename), dtype=np.uint8)
|
||||||
assert np.array_equal(data, data2[0:len(data)])
|
assert np.array_equal(data, data2[0:len(data)])
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ class BaseFilesystemModifyTest:
|
||||||
count = 1
|
count = 1
|
||||||
for data in entries:
|
for data in entries:
|
||||||
filename = "%s%d.BIN" % (prefix, count)
|
filename = "%s%d.BIN" % (prefix, count)
|
||||||
data2 = np.fromstring(self.image.find_file(filename), dtype=np.uint8)
|
data2 = np.frombuffer(self.image.find_file(filename), dtype=np.uint8)
|
||||||
assert np.array_equal(data, data2[0:len(data)])
|
assert np.array_equal(data, data2[0:len(data)])
|
||||||
count += 1
|
count += 1
|
||||||
filenames.append(filename)
|
filenames.append(filename)
|
||||||
|
@ -50,7 +50,7 @@ class BaseFilesystemModifyTest:
|
||||||
self.image.write_file("TEST.XEX", None, data)
|
self.image.write_file("TEST.XEX", None, data)
|
||||||
assert len(self.image.files) == self.num_files_in_sample + 1
|
assert len(self.image.files) == self.num_files_in_sample + 1
|
||||||
|
|
||||||
data2 = np.fromstring(self.image.find_file("TEST.XEX"), dtype=np.uint8)
|
data2 = np.frombuffer(self.image.find_file("TEST.XEX"), dtype=np.uint8)
|
||||||
assert np.array_equal(data, data2[0:len(data)])
|
assert np.array_equal(data, data2[0:len(data)])
|
||||||
|
|
||||||
def test_50k(self):
|
def test_50k(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user