Msg: 6381 *Conference*

03-26-96 16:31:59

From: RON WIESEN

To : ANTHONY FEST

Subj: FIXING RAMPAC

Ah, you're refreshing my memory regarding Rampac file format.  You said sector
227 is the first sector of a file, and I assume that's based on what you found
in the "directory" sector (sector 0 I think).  As I recall, the format for a
"first sector" has ten overhead bytes.  You can confirm this via Rampac
documentation, but I think these bytes are as follows:

Byte 0 ... byte 5    6-character file name, space padded if necessary Byte 6
... byte 7    2-character file name extension, and the first character
                     determines file type:
                     B for BASIC tokenized
                     C for Command file (6-byte header for Top, Len, and EXE)
                     D for ASCII file with EOF character at file end Byte 8
Low order byte of 16-bit File_length Byte 9               High order byte of
16-bit File_length

The remaining bytes of the first sector (1,014 of 1,024) are file content.
Where File_length exceeds 1,014, content continues in another sector and
"Continuation sectors" do not have any overhead so all 1,024 bytes of such
sectors contain file content.  Of course in the Directory sector, the chaining
relationship of how a sector chains to another continuation sector is found.
Don't remember exactly the format of the Directory sector but obviously with
1,024 bytes (like every sector) that must account for 255 sectors, groups of
four bytes account for each sector and one of those four bytes must be the
"chain to next" byte and it's zero if no further chaining is needed (last
sector in the chain of sectors that form a particular file).

As to low order and high order, it's a very common arrangement that applies to
many things other than the Rampac.  A 16-bit vaule must be expressed.  Hardware
architecture is bundled in 8-bit chunks (i.e., bytes).  So a series of two
chunks expresses a 16-bit value.  The question is: which one is the lower 8-bit
portion (low order) and which one is the next significant 8-bit portion (high
order).  The example below shows the typical arrangement where the low order
portion preceeds, with respect to it's address or it's arrival time on a serial
medium, the high order portion.

 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0 2  2  2  2  2  2  2  2  2  2
2  2  2  2  2  2
------------------------------------------------
 1  0  0  1  0  1  1  0  1  1  1  0  0  1  1  1    16 bit value
\______________________/\______________________/
     High order              Low order
     follows                 leads

With an 8-bit modulus, only values 0 through 255 can be expressed.  With a
16-bit modulus, values 0 through 65535 can be expressed.  Naturally a
File_length can exceed 255, so a 16-bit modulus is used and it can express well
beyond the maximum possible File_length of any file you could form in the
memory of the Model 100.

As for "integer math" in BASIC, the range of values from -32768 to +32767 is in
fact a full 16-bit modulus which covers 65536 values: half of them considered
to be positive in sign (0 through 32767) and the other half considered to be
negative in sign (-1 through -32768).

I think your best bet is to alter the Directory so that sector 227 is marked as
free, rather than as a "first sector" of some file.  After all, you said the
file name is garbled so you can't tell what it may have been and its
File_length is implausible.  Consider this file lost.  Alter the Directory
overhead of sector 227 so it appears "free".  Then run N-DKTR.BA again.  You
may get more ERR and ERL stops and need to "free" the "first sector" of other
files.  More likely than not, N-DKTR.BA will not stop and it may report some
"orphan" sectors that are (were) "continuation sectors" of the file (assuming
its true File_length was more than 1,014).  Just tell N-DKTR.BA to free them
and you're done.

As to how to manually alter anything in a Rampac, check the documentation.  As
I recall, Rampac hardware has two I/O ports: one for setting a sector number,
one to either read or write sector content CONSECUTIVELY within the sector.
You write the sector number to one port.  This selects a particular sector (0
to 255) and it initializes a sequential address counter by setting it to 0.
Then for each read or write of the other port, content transfers from or to the
current address within the sector (0 through 1,023) and THE ADDRESS COUNTER
INCREMENTS in preparation for subsequent content transfer with the next address
within the sector.

I think the ports are 129 and 131: 129 written to establish the sector number;
131 read or written to transfer content.  Don't trust my memory, check the
documentation Tony.  You must know which byte(s) you wish to change (write new
content) and beginning with byte 0 (the first byte) of the sector YOU MUST READ
the port for each byte you do not want to alter until these CONSECUTIVE port
reads have incremented the address counter so that the content you wish to
alter is now the current byte.  Then you WRITE the port with the new content.
In summary, it's you who must know exactly how many bytes preceed the byte you
wish to change and it's you who must READ exactly this many bytes before you
WRITE the byte of interest.

Nuts and bolts of BASIC for ports is simple.  The INP and OUT commands
respectively read and write an I/O port.  The INP command has only one
argument: port number.  The OUT command has two arguments: port number, and
byte of content to write.  For example, say within sector 123 you want to alter
byte 9 (the tenth byte) so its content becomes 209.  I think the following
BASIC statement does the trick.

OUT129,123:FORB=0TO8:C=INP(131):NEXT:OUT131,209

Because you must deal with altering the "Directory" sector, I recommend you
make a few "dry runs" through it by only reading its content.  That way you can
assure yourself that you in fact know exactly which byte(s) to change before
you take the plunge.  If you are careless, your situation with the Rampac is
made worse.  Here's a statement you can use to READ all 1,024 bytes of the
Directory sector.

OUT129,0:FORB=0TO1023:C=INP(131):PRINTB,C:NEXT

This displays a two-column list with the byte address at the left and the
content at the right.

-= Ron =-