1 | ; $Id: buffer.asm,v 1.2 2000-02-18 19:27:31 bird Exp $
|
---|
2 | ;
|
---|
3 | ; Simple resident buffer for use when overloading tkExecPgm.
|
---|
4 | ;
|
---|
5 | ; Copyright (c) 2000 knut st. osmundsen
|
---|
6 | ;
|
---|
7 | ; Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | ;
|
---|
9 | .486p
|
---|
10 |
|
---|
11 | ;
|
---|
12 | ; Include files
|
---|
13 | ;
|
---|
14 | include devsegdf.inc
|
---|
15 |
|
---|
16 | ;
|
---|
17 | ; Exported symbols
|
---|
18 | ;
|
---|
19 | public AcquireBuffer
|
---|
20 | public ReleaseBuffer
|
---|
21 | public QueryBufferSegmentOffset
|
---|
22 | ; public cbBuffer
|
---|
23 |
|
---|
24 |
|
---|
25 | ;
|
---|
26 | ; Global Variables
|
---|
27 | ;
|
---|
28 | DATA16 SEGMENT
|
---|
29 | ;DATA32 SEGMENT
|
---|
30 | achBuffer db 4096 dup(?)
|
---|
31 | DATA16 ENDS
|
---|
32 | ;DATA32 ENDS
|
---|
33 |
|
---|
34 | ;DATA16 SEGMENT
|
---|
35 | DATA32 SEGMENT
|
---|
36 | fBuffer db 0 ;Access "semaphore"
|
---|
37 | DATA32 ENDS
|
---|
38 |
|
---|
39 |
|
---|
40 | CODE32 segment
|
---|
41 | assume CS:CODE32, DS:NOTHING, SS:NOTHING
|
---|
42 |
|
---|
43 | ;;
|
---|
44 | ; Aquires a resident buffer. (intended use for tkExecPgm)
|
---|
45 | ; @cproto assembly only for time being.
|
---|
46 | ; @returns Pointer to buffer
|
---|
47 | ; @uses eax
|
---|
48 | ; @sketch if fBuffer == 0 then
|
---|
49 | ; ok!
|
---|
50 | ; fBuffer <- 1
|
---|
51 | ; return pointer to buffer
|
---|
52 | ; else
|
---|
53 | ; fail
|
---|
54 | ; return NULL
|
---|
55 | ; endif
|
---|
56 | ; @status completely implemented.
|
---|
57 | ; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
58 | ; @remark cbBuffer holds the size of the buffer.
|
---|
59 | AcquireBuffer PROC NEAR
|
---|
60 | push ds
|
---|
61 | ;mov ax,
|
---|
62 | ; push FLAT
|
---|
63 | pop ds
|
---|
64 | ;mov ds, ax
|
---|
65 | ASSUME DS:FLAT
|
---|
66 | mov al, 0
|
---|
67 | mov ah, 1
|
---|
68 | lock cmpxchg fBuffer, ah
|
---|
69 | jnz AcquireBuffer_nok
|
---|
70 | AcquireBuffer_ok:
|
---|
71 | mov eax, offset achBuffer
|
---|
72 | pop ds
|
---|
73 | ret
|
---|
74 | AcquireBuffer_nok:
|
---|
75 | xor eax,eax
|
---|
76 | pop ds
|
---|
77 | ret
|
---|
78 | AcquireBuffer ENDP
|
---|
79 |
|
---|
80 | ;;
|
---|
81 | ; Release the resident buffer pointed to by eax from use.
|
---|
82 | ; @cproto assembly only for time being.
|
---|
83 | ; @returns 0 on success, 87 on error.
|
---|
84 | ; @param eax Pointer to buffer.
|
---|
85 | ; @uses eax
|
---|
86 | ; @equiv
|
---|
87 | ; @sketch if eax == achBuffer then
|
---|
88 | ; set fBuffer to 0 if 1.
|
---|
89 | ; if fBuffer was not 1 then fail with rc = 87!
|
---|
90 | ; else
|
---|
91 | ; fail with rc = 87
|
---|
92 | ; endif
|
---|
93 | ; @status
|
---|
94 | ; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
95 | ; @remark
|
---|
96 | ReleaseBuffer PROC NEAR
|
---|
97 | ASSUME DS:NOTHING
|
---|
98 | push ds
|
---|
99 | ; mov ax, DATA16
|
---|
100 | ; mov ds, ax
|
---|
101 | ; push FLAT
|
---|
102 | pop ds
|
---|
103 | ASSUME DS:FLAT
|
---|
104 | cmp eax, offset achBuffer
|
---|
105 | jne ReleaseBuffer_nok
|
---|
106 | mov al, 1
|
---|
107 | mov ah, 0
|
---|
108 | lock cmpxchg fBuffer, ah
|
---|
109 | jnz ReleaseBuffer_nok
|
---|
110 | ReleaseBuffer_ok:
|
---|
111 | xor eax, eax
|
---|
112 | pop ds
|
---|
113 | ret
|
---|
114 | ReleaseBuffer_nok:
|
---|
115 | mov eax, 87 ;some error
|
---|
116 | pop ds
|
---|
117 | ret
|
---|
118 | ReleaseBuffer ENDP
|
---|
119 |
|
---|
120 |
|
---|
121 | ;;
|
---|
122 | ; Gets the 16-bit segment and offset for this buffer.
|
---|
123 | ; @cproto assembly only for time being.
|
---|
124 | ; @returns segment in es and offset in eax
|
---|
125 | ; On error high word of eax is 87.
|
---|
126 | ; @param eax Buffer pointer.
|
---|
127 | ; @uses eax, es
|
---|
128 | ; @status completely implemented.
|
---|
129 | ; @author knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
130 | ; @remark cbBuffer holds the size of the buffer.
|
---|
131 | QueryBufferSegmentOffset PROC NEAR
|
---|
132 | ASSUME DS:NOTHING
|
---|
133 | push ds
|
---|
134 | ; mov ax, DATA16
|
---|
135 | ; mov ds, ax
|
---|
136 | ; push FLAT
|
---|
137 | pop ds
|
---|
138 | ASSUME DS:FLAT
|
---|
139 | cmp eax, offset achBuffer
|
---|
140 | jne QueryBufferSegmentOffset_nok
|
---|
141 | cmp fBuffer, 1
|
---|
142 | jne QueryBufferSegmentOffset_nok
|
---|
143 |
|
---|
144 | QueryBufferSegmentOffset_ok:
|
---|
145 | xor eax, eax
|
---|
146 | jmp far ptr CODE16:GetBufferSegmentOffset16
|
---|
147 | QueryBufferSegmentOffset_Back::
|
---|
148 | pop ds
|
---|
149 | ret
|
---|
150 |
|
---|
151 | QueryBufferSegmentOffset_nok:
|
---|
152 | mov eax, 00570000h
|
---|
153 | pop ds
|
---|
154 | ret
|
---|
155 | QueryBufferSegmentOffset ENDP
|
---|
156 |
|
---|
157 |
|
---|
158 | CODE32 ENDS
|
---|
159 |
|
---|
160 | CODE16 SEGMENT
|
---|
161 |
|
---|
162 | ;;
|
---|
163 | ; Gets the segment(->es) and offset(->ax) of the achBuffer.
|
---|
164 | ; Jumps back to GetBufferOffset32
|
---|
165 | GetBufferSegmentOffset16:
|
---|
166 | ASSUME CS:CODE16, DS:NOTHING
|
---|
167 | mov ax, seg achBuffer
|
---|
168 | mov es, ax
|
---|
169 | mov ax, offset achBuffer
|
---|
170 | jmp far ptr FLAT:QueryBufferSegmentOffset_Back
|
---|
171 | CODE16 ENDS
|
---|
172 |
|
---|
173 | END
|
---|
174 |
|
---|