-
Notifications
You must be signed in to change notification settings - Fork 0
/
readf.mac
115 lines (115 loc) · 4.07 KB
/
readf.mac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
TITLE readf (ref file,ref record) - 26 Nov 91 - MT
SUBTTL 'Read a record from a physical file'
;
INCLUDE SYMBOLS
VERSION 'READF 3.1 - 06 Apr 92'
;
;-- Reads a 128 byte record from a physical device to a buffer. Attempts
; to read from a logical device or file opened for writing will result in
; an error. This procedure assumes that a file header block exists and
; that the file has been opened for reading.
;
; +-+--------+---+-----------+-+-+--------------------------------------+
; | | | | | | | |
; +-+--------+---+-----------+-+-+--------------------------------------+
; | |
; |--- File Control Block ---|| ||----------- DMA Buffer ---------------|
; (36 bytes) | | (128 bytes)
; / \
; Status Buffer pointer
; (1 byte) (1 byte)
;
; This routine can read a record directly into any location in memory, it
; is not necessary to use the default DMA buffer.
;
;-- This program is free software: you can redistribute it and/or modify it
; under the terms of the GNU General Public License as published by the
; Free Software Foundation, either version 3 of the License, or (at your
; option) any later version.
;
; This program is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
; General Public License for more details.
;
;** 6 Apr 92 - Modified to use the usr number held in mode byte - MT
;
;-- Check that the output file has been opened for reading.
;
READF:: PROCEDURE ; All registers preserved.
LD A,(HL) ; Get device code.
OR A ; If the device code has not been set then the file has not been opened.
LD A,ERR$Not_Opened
RET Z
LD A,(HL) ; Get device code.
CP SYS$Console ; Check that we are writing to a physical device, block write to a logical
LD A,ERR$Bad_Device ; device is not possible.
RET NC
PUSH HL ; Save the pointer to the FCB.
LD BC,36 ; Get the file access mode from the
ADD HL,BC ; buffer.
LD A,(HL)
AND 00001111B ; Check that the file was opened for writing.
CP 'R' AND 00001111B
LD A,ERR$Bad_Mode
POP HL ; Restore pointer to FCB.
RET NZ
;
;-- Set up the DMA address and reset the buffer pointer.
;
I$Write_Record: PUSH HL ; Save DMA address and the address of the FCB
PUSH DE ; on the stack.
POP DE
LD C,BDOS$Set_DMA ; DE already points to the record so use it for DMA.
CALL BDOS## ; Set DMA address (no errors to worry about here).
POP DE ; What was the the address FCB ?
LD HL,37 ; Calculate address of buffer pointer
ADD HL,DE ; and reset it.
LD A,128
LD (HL),A
;
;-- Save current usr number on the stack.
;
PUSH DE ; Save the address of the FCB.
LD C,BDOS$Set_Usr_No ; Use set usr number function to get the current usr number
LD E,0FFH ; by putting 0FFH in E.
CALL BDOS##
LD L,A ; Put usr number into HL.
EX (SP),HL ; Save it on the stack and get the pointer to the FCB in HL.
EX DE,HL ; Restore pointer to FCB.
;
;-- Set up usr number of output file.
;
PUSH DE ; Save address of FCB.
LD HL,36 ; Offset to status byte.
ADD HL,DE
XOR A
RLD
LD E,A ; Get usr number of output file.
RLD
RLD
LD C,BDOS$Set_Usr_No ; Set up new usr number.
CALL BDOS##
POP DE ; Restore address of FCB in DE for BDOS write function.
;
;-- Write record to disk.
;
LD C,BDOS$Read_Seq ; Perform a sequential write to transfer the next
CALL BDOS## ; record into the DMA buffer previously defined.
OR A ; Set flags.
;
;-- Reset usr number to current value.
;
POP DE ; Restore current user number from the stack
PUSH AF ; and save the error code.
LD C,BDOS$Set_Usr_No ; Reset the usr number.
CALL BDOS##
POP AF ; Restore the error code.
;
;-- Check for write errors.
;
RET Z ; No problem.
LD A,ERR$Read_Fail ; Set up correct error code for a write error - Disk Full !
RET
;
END