VEServer.py: Added 2MG file support.

This commit is contained in:
Bobbi Webber-Manners 2021-08-29 22:40:04 -04:00
parent fb2d438958
commit 039224dcea

View File

@ -45,6 +45,7 @@ prevdrv = -1 # Last drive read/written
prevop = -1 # Last operation (read or write) prevop = -1 # Last operation (read or write)
prevcs = -1 # Previous checksum prevcs = -1 # Previous checksum
col = 0 # Used to control logging printout col = 0 # Used to control logging printout
skip = 0 # Bytes to skip over header
# #
# Get date/time bytes # Get date/time bytes
@ -121,7 +122,7 @@ def read3(sock, addr, d):
err = False err = False
try: try:
with open(file, 'rb') as f: with open(file, 'rb') as f:
b = blknum * BLKSZ b = blknum * BLKSZ + skip
f.seek(b) f.seek(b)
block = f.read(BLKSZ) block = f.read(BLKSZ)
except: except:
@ -180,7 +181,7 @@ def write(sock, addr, d):
if cs == d[517]: if cs == d[517]:
try: try:
with open(file, 'r+b') as f: with open(file, 'r+b') as f:
b = blknum * BLKSZ b = blknum * BLKSZ + skip
f.seek(b) f.seek(b)
for i in range (0, BLKSZ): for i in range (0, BLKSZ):
f.write(bytes([d[i+5]])) f.write(bytes([d[i+5]]))
@ -208,6 +209,18 @@ def write(sock, addr, d):
b = sock.sendto(bytearray(l), addr) b = sock.sendto(bytearray(l), addr)
#print('Sent {} bytes to {}'.format(b, addr)) #print('Sent {} bytes to {}'.format(b, addr))
# See if file is a 2MG and, if so, that it contains .PO image
def check2MG(file):
try:
with open(file, 'rb') as f:
hdr = f.read(16)
except:
return
if (hdr[0] == 0x32) and (hdr[1] == 0x49) and (hdr[2] == 0x4d) and (hdr[3] == 0x47):
print('** ' + file + ' is a 2MG file **')
if hdr[0x0c] != 0x01:
print('** Warning NOT in ProDOS order **')
skip = 64
def usage(): def usage():
print('usage: veserver [OPTION]...') print('usage: veserver [OPTION]...')
@ -253,6 +266,9 @@ else:
print("Disk 1: {}".format(file1)) print("Disk 1: {}".format(file1))
print("Disk 2: {}".format(file2)) print("Disk 2: {}".format(file2))
check2MG(file1)
check2MG(file2)
with socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) as s: with socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) as s:
s.bind((IP, PORT)) s.bind((IP, PORT))
print("veserver - listening on UDP port {}".format(PORT)) print("veserver - listening on UDP port {}".format(PORT))