From
Ivan Roshin
→
To
All
20 July 2002
Hello, All!
═══════════════════ del_tail.1 ══════════════════
(c) Ivan Roshchin, Moscow
Fido: 2:5020/689.53
ZXNet: 500:95/462.53
E-mail: asder_ffc@softhome.net
WWW: http://www.ivr.da.ru
We cut off the “tail” of the files
═══════════════════════
("Radiomir. Your computer" 4/2002)
In [1] the problem associated with the use of
text editor Microsoft Word. Let me remind you: it was about
that in certain cases in the saved text file
fragments of text remain that were deleted during editing, and
the author of the text may not even be aware of this. And the recipient
anyone who reads this file can find out information that is relevant to him
was not intended at all.
A similar problem is relevant for many text messages.
editors on the ZX Spectrum, although the reason for its occurrence is not
the same as in MS Word. Here's the thing: for storage on disk
file, regardless of its length, an integer number of sectors are allocated.
Thus, the remainder of the last sector ("tail") of the file can
contain information not related to this file. When we
we save the text in the editor, the whole is simply written to disk
number of sectors from the beginning of the text buffer. And if the text length
is not a multiple of 256 bytes, the remainder of the last sector will be that
was in the text buffer after the actual end of the text.By loading the file into a text editor, we will not see this information
(because the directory specifies the exact length of the file), but when
viewing the contents of the last sector using some
disk editor it can be read.
What is in the buffer after the end of the text? It could be
and the remainder of the previous file loaded into the editor (after all, before
loading a new file does not reset the buffer to zero - why do
extra work?), and text fragments deleted when
editing. And if the buffer is not cleared when the editor starts,
there may remain what was placed there during work
previous program. Even if this program was an ordinary
"boot", the directory of the disk from which you came may remain in memory.
editor is running. It is clear what to do with this information
I wouldn't want it to be public.
However, when copying a file, sending it to
formats hobeta, scl, (and, of course, in disk image files:
trd, fdi, td0), as well as when packing files using an archiver
The HRIP remainder of the last sector also participates in the operation.
Thus, unwanted information may be
distributed along with the file itself, and access to it can
get a lot of people.
If the memory area after the end of the text were reset to zero before
by writing the file, the problem would be completely solved. That's exactly what I am
and I will advise the editor creators. What to do simple
to users?There is a way out - use a special program,
zeroing out the "tail" of the specified file. Here is her text:
SECTOR EQU #C000 ;#100 bytes
CATALOG EQU #C100 ;#800 bytes
FILE_LIST EQU #C900 ;#800 bytes
ORG #8000
;Initialization:
LD A,(23611) ;system
OR %00001100 ;variables
LD (23611),A ;handler
XOR A ;keyboard
LD (23658),A
LD A,(23562)
PUSH AF
LD A,1
LD (23562),A
BEGIN XOR A ;CLS
OUT(254),A
LD HL,#4000
LD(HL),L
LD DE,#4001
LD BC,#17FF
LDIR
LD HL,#5800
LD (HL),7
LD DE,#5801
LD BC,#2FF
LDIR
;Read the directory and identify it
;checksum:
CALL READ_CAT
;We create a list of files:
CALL MAKE_LIST
;File selection:
SELECT LD A,(ALL_FILES)
AND A ;if not
JR Z,SELECT_NF ;files...
XOR A
LD (FIRST),A
LD(NUM_F),A
CALL PRINT_LIST
SELECT_1 CALL CURSOR_ON
WAIT_K CALL GETSYM
CP "q"
JR Z,SEL_UP
CP 11
JR Z,SEL_UP
CP "a"
JR Z,SEL_DN
CP 10
JR Z,SEL_DNCP 13
JR Z,WORK_FILE
CP 7
JP Z,EXIT
CP "r"
JR Z,BEGIN
JR WAIT_K
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
20 July 2002
Hello, All!
═══════════════════ del_tail.1 ══════════════════
(c) Ivan Roshchin, Moscow
Fido: 2:5020/689.53
ZXNet: 500:95/462.53
E-mail: asder_ffc@softhome.net
WWW: http://www.ivr.da.ru
We cut off the “tail” of the files
═══════════════════════
("Radiomir. Your computer" 4/2002)
In [1] the problem associated with the use of
text editor Microsoft Word. Let me remind you: we were talking about
that in certain cases in the saved text file
fragments of text remain that were deleted during editing, and
the author of the text may not even be aware of this. And the recipient
anyone who reads this file can find out information that is relevant to him
was not intended at all.
A similar problem is relevant for many text messages.
editors on the ZX Spectrum, although the reason for its occurrence is not
the same as in MS Word. Here's the thing: for storage on disk
file, regardless of its length, an integer number of sectors are allocated.
Thus, the remainder of the last sector ("tail") of the file can
contain information not related to this file. When we
we save the text in the editor, the whole is simply written to disk
number of sectors from the beginning of the text buffer. And if the text length
is not a multiple of 256 bytes, the remainder of the last sector will be that
was in the text buffer after the actual end of the text.By loading the file into a text editor, we will not see this information
(because the directory specifies the exact length of the file), but when
viewing the contents of the last sector using some
disk editor it can be read.
What is in the buffer after the end of the text? It could be
and the remainder of the previous file loaded into the editor (after all, before
loading a new file does not reset the buffer to zero - why do
extra work?), and text fragments deleted when
editing. And if the buffer is not cleared when the editor starts,
there may remain what was placed there during work
previous program. Even if this program was an ordinary
"boot", the directory of the disk from which you came may remain in memory.
editor is running. It is clear what to do with this information
I wouldn't want it to be public.
However, when copying a file, sending it to
formats hobeta, scl, (and, of course, in disk image files:
trd, fdi, td0), as well as when packing files using an archiver
The HRIP remainder of the last sector also participates in the operation.
Thus, unwanted information may be
distributed along with the file itself, and access to it can
get a lot of people.
If the memory area after the end of the text were reset to zero before
by writing the file, the problem would be completely solved. That's exactly what I am
and I will advise the editor creators. What to do simple
to users?There is a way out - use a special program,
zeroing out the "tail" of the specified file. Here is her text:
SECTOR EQU #C000 ;#100 bytes
CATALOG EQU #C100 ;#800 bytes
FILE_LIST EQU #C900 ;#800 bytes
ORG #8000
;Initialization:
LD A,(23611) ;system
OR %00001100 ;variables
LD (23611),A ;handler
XOR A ;keyboard
LD (23658),A
LD A,(23562)
PUSH AF
LD A,1
LD (23562),A
BEGIN XOR A ;CLS
OUT(254),A
LD HL,#4000
LD(HL),L
LD DE,#4001
LD BC,#17FF
LDIR
LD HL,#5800
LD (HL),7
LD DE,#5801
LD BC,#2FF
LDIR
;Read the directory and identify it
;checksum:
CALL READ_CAT
;We create a list of files:
CALL MAKE_LIST
;File selection:
SELECT LD A,(ALL_FILES)
AND A ;if not
JR Z,SELECT_NF ;files...
XOR A
LD (FIRST),A
LD(NUM_F),A
CALL PRINT_LIST
SELECT_1 CALL CURSOR_ON
WAIT_K CALL GETSYM
CP "q"
JR Z,SEL_UP
CP 11
JR Z,SEL_UP
CP "a"
JR Z,SEL_DN
CP 10
JR Z,SEL_DNCP 13
JR Z,WORK_FILE
CP 7
JP Z,EXIT
CP "r"
JR Z,BEGIN
JR WAIT_K
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
20 July 2002
Hello, All!
═══════════════════ del_tail.2 ══════════════════
;"Вверх":
SEL_UP LD A,(NUM_F)
AND A
JR Z,WAIT_K
CALL CURSOR_OFF
LD HL,NUM_F
DEC (HL)
LD A,(FIRST)
SUB (HL)
JR C,SELECT_1
JR Z,SELECT_1
LD HL,FIRST
DEC (HL)
CALL PRINT_LIST
JR SELECT_1
;"Вниз":
SEL_DN LD A,(NUM_F)
INC A
LD HL,ALL_FILES
CP (HL)
JR Z,WAIT_K
CALL CURSOR_OFF
LD HL,NUM_F
INC (HL)
LD A,(FIRST)
ADD A,17
SUB (HL)
JR NC,SELECT_1
LD HL,FIRST
INC (HL)
CALL PRINT_LIST
JR SELECT_1
;Если на диске нет файлов, ждем нажатия
;"R" или "EDIT":
SELECT_NF CALL GETSYM
CP 7
JP Z,EXIT
CP "r"
JP Z,BEGIN
JR SELECT_NF
;Обработка файла.
WORK_FILE LD A,(NUM_F)
LD H,0
LD L,A
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,HL ;*16
LD DE,FILE_LIST
ADD HL,DE
PUSH HL
POP IX
;Проверка, можно ли обрабатывать файл:
LD A,(IX+8) ;это Бейсик?CP "B"
JP Z,WAIT_K
LD A,(IX+11) ;low byte
AND A ;length = 0?
LD (USED),A
JP Z,WAIT_K
LD A,(IX+12) ;length in sect.
INC A ;corresponds
CP (IX+13) ;length
JP NZ,WAIT_K ;in bytes?
;Determine the track-sector address
;last sector of the file:
LD D,0
DEC A
LD B,A
AND 15
ADD A,(IX+14)
BIT 4.A
RES 4,A
LD E,A ;sector
JR Z,WORK_1
INC D
WORK_1 LD A,B
RRCA
RRCA
RRCA
RRCA
AND 15
ADD A,(IX+15)
ADD A,D
LD D,A ;track
LD (DISK_ADR),DE
;Check by checksum
;catalog: suddenly there is another one in the drive
;disk? If so, re-read the catalog.
LD HL,(SUM)
PUSH HL
CALL READ_CAT
LD HL,(SUM)
POP DE
AND A
SBC HL,DE
JP NZ,BEGIN
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
20 July 2002
Hello, All!
═══════════════════ del_tail.3 ══════════════════
;Reset unused space to zero
;in the last sector of the file:
LD DE,0
DISK_ADR EQU $-2
LD HL,SECTOR
LD B,1
LD C,5
PUSH DE
PUSH HL
CALL #3D13
LD H,SECTOR/256
LD L,0
USED EQU $-1
WORK_2 LD (HL),0
INC L
JR NZ,WORK_2
POP HL
POP DE
LD B,1
LD C,6
CALL #3D13
;After processing - again select a file:
JP WAIT_K
;Exit the program:
EXIT LD HL,#2758
EXX
POP AF ;restore period
LD (23562),A ;auto repeat
RET
;---------------------------------------
;Variables:
SUM DS 2 ;checksum
ALL_FILES DS 1 ;number of files
FIRST DS 1 ;N top file
NUM_F DS 1 ;N selected file
;---------------------------------------
;The READ_CAT procedure reads the disk directory
;and calculates its checksum.
READ_CAT LD C,0 ;reset
CALL #3D13 ;controller
LD C,#18 ;setting
CALL #3D13 ;to disk
LD B,8 ;read
LD DE,0 ;eight
LD HL,CATALOG ;sectors
LD C,5 ; catalogCALL #3D13
;Checksum calculation:
LD IX,CATALOG;address. started
LD BC,#800 ;counter
LD HL,0 ;start amount
LD D,0
CALC_SUM LD E,(IX) ;add
ADD HL,DE ;next byte
INC IX
DEC B.C.
LD A,B
OR C
JR NZ,CALC_SUM
LD (SUM),HL
RET
;---------------------------------------
;The MAKE_LIST procedure generates a list
;files and counts their number.
MAKE_LIST LD HL,CATALOG
LD DE,FILE_LIST
LD IX,#8000
;XH - directory item counter (128),
;XL - file counter.
MAKE_M1 LD A,(HL) ;files
AND A ;finished?
JR Z,MAKE_M4
DEC A ;remote
JR Z,MAKE_M2 ;file?
LD BC,16 ;transfer
LDIR ;descriptor
INC XL ;increased quantity
JR MAKE_M3
MAKE_M2 LD BC,16
ADD HL,BC
MAKE_M3 DEC XH ;counter
JR NZ,MAKE_M1
MAKE_M4 LD A,XL
LD(ALL_FILES),A
RET
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
20 July 2002
Hello, All!
═══════════════════ del_tail.4 ══════════════════
;---------------------------------------
;Procedures for displaying the cursor:
;CURSOR_ON - draw,
;CURSOR_OFF - erase.
CURSOR_ON LD B,%00111000
JR CURSOR_1
CURSOR_OFF LD B,%00000111
CURSOR_1 LD A,(NUM_F)
LD HL,FIRST
SUB (HL)
ADD A,4
LD E,A
LD D,1
CALL GET_A_A
LD(HL),B
LD D,H
LD E,L
INC DE
LD BC,11
LDIR
RET
;---------------------------------------
;The PRINT_LIST procedure prints
;filenames starting with FIRST until
;18 names will be displayed or not yet
;files will run out.
PRINT_LIST LD XH,0 ;counter
LD DE,FILE_LIST
LD H,0
LD A,(FIRST)
LD L,A
ADD HL,HL
ADD HL,HL
ADD HL,HL
ADD HL,HL ;*16
ADD HL,DE
;HL indicates the file name.
NEXT_OT LD B,8
LD D,2
LD A,XH
ADD A,4
LD E,A
PUSH HL
LOOP_P2 LD A,(HL)
INC HL
CALL PRINT_SYM
INC D
DJNZ LOOP_P2
LD A,(HL)
INC D
CALL PRINT_SYM
POP HL
LD A,(FIRST)ADD A,XH
LD B,A
LD A,(ALL_FILES)
DEC A
CP B
RET Z
INC XH
LD A,XH
CP 18
RET Z
LD DE,16
ADD HL,DE
JR NEXT_OT
;---------------------------------------
;The PRINT_SYM procedure prints to the screen
;one character (no attributes).
;
;Input: A - character code,
; D - X coordinate,
; E - Y coordinate.
;
;Output: registers not modified.
PRINT_SYM PUSH BC
PUSH DE
PUSH HL
PUSH AF
LD L,A
LD H,0
ADD HL,HL
ADD HL,HL
ADD HL,HL ;*8
LD BC,#3C00
ADD HL,BC
PUSH HL
CALL GET_A_S
POP DE
LD B,8
LOOP_PR_S LD A,(DE)
LD(HL),A
INC DE
INC H
DJNZ LOOP_PR_S
POP AF
POP HL
POP DE
POP B.C.
RET
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
20 July 2002
Hello, All!
═══════════════════ del_tail.5 ══════════════════
;---------------------------------------
;Procedure GET_A_S calculates the address
;on the screen.
;
;Input: D - X, E - Y.
;Output: HL - address.
GET_A_S LD A,E
AND #18
OR#40
LD H,A
LD A,E
AND 7
RRA
RRA
RRA
RRA
ADD A,D
LD L,A
RET
;---------------------------------------
;Procedure GET_A_A calculates the address
;in the attributes area.
;
;Input: D - X, E - Y.
;Output: HL - address.
GET_A_A LD A,E
RRA
RRA
RRA
AND 3
OR#58
LD H,A
LD A,E
AND 7
RRA
RRA
RRA
RRA
ADD A,D
LD L,A
RET
;---------------------------------------
;The GETSYM procedure waits for a key to be pressed.
GETSYM XOR A
LD (23560),A
GET_1 LD A,(23560)
AND A
JR Z,GET_1
RET
After compilation, save the object code, for example, under
name del_tail and write the simplest BASIC loader:
10 CLEAR 32767: RANDOMIZE USR 15619: REM: LOAD "del_tail"
CODE
20 RANDOMIZE USR 32768
30 RANDOMIZE USR 15616
The program is very easy to use. After launchthe disk directory is displayed, you can select the desired file using
"Q", "A" and cursor keys; "ENTER" - start processing the file,
"R" - reread the directory, "EDIT" - exit to TR-DOS.
Before starting processing the selected file, the program
checks: has the disk been replaced since the directory was read?
If yes, then the directory is simply re-read.
There is one more check: if a BASIC file is selected,
or the file length in bytes does not match the length in sectors, or
length in bytes is equal to the integer number of sectors, file processing is not
is produced.
The program can be used not only for processing
text files. But I want to warn you so that you are sure of
format of the processed files: it happens that the “tail” of the file
contains any necessary data.
The program can be improved: add drive selection,
the ability to process several marked files at once,
resetting unused disk sectors and information about erased ones
files in the disk directory...
Literature
──────────
1. “The word is not a sparrow.” "Radiomir. Your computer" 10/2001,
page 36.
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.
From
Ivan Roshin
→
To
All
20 July 2002
Hello, All!
═══════════════════ del_tail.5 ══════════════════
;---------------------------------------
;Procedure GET_A_S calculates the address
;on the screen.
;
;Input: D - X, E - Y.
;Output: HL - address.
GET_A_S LD A,E
AND #18
OR#40
LD H,A
LD A,E
AND 7
RRA
RRA
RRA
RRA
ADD A,D
LD L,A
RET
;---------------------------------------
;Procedure GET_A_A calculates the address
;in the attributes area.
;
;Input: D - X, E - Y.
;Output: HL - address.
GET_A_A LD A,E
RRA
RRA
RRA
AND 3
OR#58
LD H,A
LD A,E
AND 7
RRA
RRA
RRA
RRA
ADD A,D
LD L,A
RET
;---------------------------------------
;The GETSYM procedure waits for a key to be pressed.
GETSYM XOR A
LD (23560),A
GET_1 LD A,(23560)
AND A
JR Z,GET_1
RET
After compilation, save the object code, for example, under
name del_tail and write the simplest BASIC loader:
10 CLEAR 32767: RANDOMIZE USR 15619: REM: LOAD "del_tail"
CODE
20 RANDOMIZE USR 32768
30 RANDOMIZE USR 15616
The program is very easy to use. After launchthe disk directory is displayed, you can select the desired file using
"Q", "A" and cursor keys; "ENTER" - start processing the file,
"R" - reread the directory, "EDIT" - exit to TR-DOS.
Before starting processing the selected file, the program
checks: has the disk been replaced since the directory was read?
If yes, then the directory is simply re-read.
There is one more check: if a BASIC file is selected,
or the file length in bytes does not match the length in sectors, or
length in bytes is equal to the integer number of sectors, file processing is not
is produced.
The program can be used not only for processing
text files. But I want to warn you so that you are sure of
format of the processed files: it happens that the “tail” of the file
contains any necessary data.
The program can be improved: add drive selection,
the ability to process several marked files at once,
resetting unused disk sectors and information about erased ones
files in the disk directory...
Literature
──────────
1. “The word is not a sparrow.” "Radiomir. Your computer" 10/2001,
page 36.
════════════════════════ ════════════════════════
Best regards, Ivan Roshchin.