Posts: 15
Threads: 1
Joined: Jun 2024
Pedroski55.
I'm on Linux, but even so that "looks" like what I'm after, thanks!
I'll get at it tomorrow morning after I better understand Gribouillis's rad50 code which I'm still chasing.
thanks again
curbie
Posts: 924
Threads: 139
Joined: Jul 2017
I don't really know what you want to do with the SD cards. I don't understand that technical stuff!
They said on linuxquestions.org, if you can mount the cards, you can copy the data to your computer.
Assuming the card is mounted at /dev/sdb
Quote:dd if=/dev/sdb of=/path/to/file.img bs=4M
Once on your computer, you can do what you want with the image file, or a copy of it!
Posts: 15
Threads: 1
Joined: Jun 2024
Pedroski55,
first off, Thanks for the code you posted yesterday, after some monkeying around, it works just fine for what I want.
def read_sector(disk, sector_no=0):
"""Read a single sector of the specified disk.
Keyword arguments:
disk -- the physical ID of the disk to read.
curbie -- or full file path to disk image file.
sector_no -- the sector number to read (default: 0).
"""
# curbie -- defined disk sector notes
# D_INFO = 0 # disk info block
# D_LABEL = 1 # disk label
# D_MFD = 2 # disk master file directory
# File operations with `with` syntax. To reduce file handling efforts.
with open(disk, 'rb') as fp: # open file read binary, get file descriptor
fp.seek(sector_no * 512) # seek file to byte (sector * 512)
read = fp.read(512) # read sector
return read # return sector
sector = read_sector("/media/curbie/0012-D687/For Curbie/Zulu/HD.IMG", 2)
print(sector) # print sector as byte array and returns
b'\x02\x01\x19\x00\x00\x00\x00\x00\x04\x01\xa9\x00\x00\x00\x00\x00\x06\x010\n\x00\x00\x00\x00\x02\x02K\x19\x00\x00\x00\x00\x00 which i recognize as BIG endian octal 1,2 on sector x19, then 4 rad50 bytes, 1,4 on sector xa9, then 4 rad50 bytes,...
the SD is a replacement disk for a machine's old ST506 MFM type drive, first i hope to read from it and write to it from my Linux machine, then the sky is the limit, playing with these old machines is my hobby.
Curbie
curbie
Posts: 15
Threads: 1
Joined: Jun 2024
(Jun-03-2024, 09:43 PM)Gribouillis Wrote: r50 = b'ABCDEFGHIJKLMNOPQRSTUVWXYZ.$%0123456789'
illegal = 127
def prepare_table():
s = r50.decode('ascii')
d = {ord(c): i for i, c in enumerate(s)}
d.update({ord(c.lower()): i for i, c in enumerate(s)})
L = [illegal for i in range(256)]
for c, i in d.items():
L[c] = i
table = ''.join(chr(x) for x in L).encode('ascii')
return table
table = prepare_table()
For me when learning a new language, every new piece of knowledge gained comes with at least one new question to chase down. After trying
(and failing) to chase down the best or any logical way to learn libraries, I'm back to just completing and logging tutorials, but this second go round, I'm not rigidly sticking to the tutorial to learn what the author wants to teach, but am chasing down the questions raised by the lessons.
After chasing down a question raised by a lesson, that answer answered a question I had about Gribouillis's code and as always raised a new question:
Is the "table" variable in Gribouillis's code rebuilt every use (through prepare_table()) or is a "static" variable or does python have some sort of smart pseudo-static assignment?
Curbie
Posts: 4,600
Threads: 72
Joined: Jan 2018
(Jun-16-2024, 06:43 PM)Curbie Wrote: Is the "table" variable in Gribouillis's code rebuilt every use (through prepare_table()) or is a "static" variable or does python have some sort of smart pseudo-static assignment? the function prepare_table() is only called once when the statement
table = prepare_table() is executed. This takes 39 microseconds on my computer.
You could go faster by assigning directly the result in the code
table = b'\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x00\x7f\x7f\x7f\x1c\x1d\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x1b\x7f\x1e\x1f !"#$%&\'\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x7f\x7f\x7f\x7f\x7f\x7f\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f\x7f' The 'table' variable has a 256 bytes string value.
'table' is a global variable in this code. Global variables are stored in a global dictionary. You can consider them static variables.
« We can solve any problem by introducing an extra level of indirection »
Posts: 15
Threads: 1
Joined: Jun 2024
Gribouillis thank you,
just what i was trying to figure out, prepare_table() is run once anytime either pack() or unpack() is called and could be made less instruction intensive by a direct table assignment as you listed. Not static.
Like I said, just chasing down answers to any question I don't know. Your implementation runs just fine, just studying the why of your choice of prepare_table().
This old DEC-type directory structures have two rad50 words for the file name, one rad50 word for the file extension, 42 files per full directory block 3 * 42 = 126) and less than 42 the the last directory block. rebuilding a table 100's of times for each directory block read that has maybe 10 directory blocks, triggers a red flag. Not because of speed, but personal practice.
Not to inpune your code which I believe was written to help
thanks again
Curbe
Posts: 4,600
Threads: 72
Joined: Jan 2018
Jun-17-2024, 06:54 AM
(This post was last modified: Jun-17-2024, 06:54 AM by Gribouillis.)
(Jun-16-2024, 09:41 PM)Curbie Wrote: prepare_table() is run once anytime either pack() or unpack() is called and could be made less instruction intensive by a direct table assignment No, prepare_table() is run only once. It is not run again when pack() and unpack() are called. The time taken by prepare_table() is neglectible because it is run only once.
Why didn't you read my reply?
« We can solve any problem by introducing an extra level of indirection »
Posts: 15
Threads: 1
Joined: Jun 2024
I'm confused, Quote:Is the "table" variable in Gribouillis's code rebuilt every use (through prepare_table()) or is a "static" variable or does python have some sort of smart pseudo-static assignment?
Posts: 15
Threads: 1
Joined: Jun 2024
Jun-17-2024, 09:08 PM
(This post was last modified: Jun-17-2024, 09:08 PM by Curbie.)
Posts: 4,600
Threads: 72
Joined: Jan 2018
Jun-17-2024, 09:52 PM
(This post was last modified: Jun-17-2024, 09:52 PM by Gribouillis.)
(Jun-17-2024, 09:08 PM)Curbie Wrote: why is that NOT static? I don't understand the problem. Python is not C. There are no static variables. It is perfecly reasonable to initialize a variable by using a function. What's wrong with that? By looking at the function I can understand why the table contains that data.
If you prefer a literal 256-bytes string in your program, no problem. It won't change the execution of the program. You will just gain a few microseconds at program initialization.
Initialization code exists for libraries in all programming languages.
« We can solve any problem by introducing an extra level of indirection »
|