.TITLE PHOBUF - BUFFER MANIPULATION ROUTINES .IDENT /1.0/ .ENABL LC ;+ ; ; Free software BY ; Project Software & Development, Inc. ; ; This software is furnished for free and may be used and copied as ; desired. This software or any other copies thereof may be provided or ; otherwise made available to any other person. No title to and ; ownership of the software is hereby transferred or allowed. ; ; The information in this software is subject to change without notice ; and should not be construed as a commitment by PROJECT SOFTWARE ; AND DEVELOPMENT, INC. ; ; PROJECT SOFTWARE assumes no responsibility for the use or reliability ; of this software on any equipment whatsoever. ; ; Project Software & Development, Inc. ; 14 Story St. ; Cambridge, Ma. 02138 ; 617-661-1444 ; ; ; Title: PHOBUF.MAC ; Author: Robin Miller ; Date: August 16, 1982 ; ; Description: ; ; Buffer manipulation routines for PHONE utility. ; ; ; Modification History: ; ;- .ENABL AMA .NLIST BEX .SBTTL ADDBUF - ADD A BUFFER TO A TABLE ENTRY ;+ ; ; ADDBUF - Add a buffer to a table entry. ; ; This routine is called to add a buffer to a table entry. The buffer ; is added to the end of the queue (O.TAIL) so buffers are removed FIFO ; (first in/first out). ; ; Inputs: ; R0 = the buffer address to add. ; R3 = the table entry address to add the buffer to. ; ; Outputs: ; None. ; ;- ADDBUF::MOV R0,@O.TAIL(R3) ; ADDRESS OF BUFFER ADDING MOV R0,O.TAIL(R3) ; SAVE LAST LINK WORD CLR (R0) ; CLEAR THE LINK WORD INCB O.BCNT(R3) ; COUNT BUFFERS QUEUED RETURN .SBTTL REMBUF - REMOVE A BUFFER FROM A TABLE ENTRY ;+ ; ; REMBUF - Remove a buffer from a table entry. ; ; This routine is used to remove a buffer from a table entry. This ; routine removes the buffer from the head of the queue (O.HEAD). ; ; Inputs: ; R3 = The table entry address to return the buffer from. ; ; Outputs: ; R0 = the address of the buffer removed. ; C bit clear/set = buffer returned / no more buffers. ; ;- REMBUF::MOV O.HEAD(R3),R0 ; GET ADDRESS OF BUFFER BEQ 20$ ; IF EQ, NO MORE BUFFERS DECB O.BCNT(R3) ; ADJUST QUEUED BUFFERS COUNT MOV (R0),O.HEAD(R3) ; UPDATE QUEUE HEADER POINTER BNE 10$ ; IF NE, NOT LAST BUFFER ON QUEUE MOV R3,O.TAIL(R3) ; SPECIAL QUEUE-EMPTY LOGIC ADD #O.HEAD,O.TAIL(R3) ; INITIALIZE TO EMPTY QUEUE 10$: CLC ; SHOW BUFFER REMOVED RETURN 20$: JSR R2,$SAVVR ; SAVE R0 - R2 ERRMSG NOBUFS, SEC ; SHOW NO MORE BUFFERS RETURN .SBTTL GETFRE - GET A BUFFER FROM THE FREE QUEUE ;+ ; ; GETFRE - Get a buffer from the free queue. ; ; This routine is called to retrieve a buffer from the free buffer ; queue. If a buffer is avilable, R0 is returned with a pointer to ; the buffer listhead which has the following format: ; ; R0 --> .WORD 0 ; Chain pointer (0) ; .BLKW 2 ; I/O status block (2) ; .BLKB n ; Data part of buffer (6) ; ; Inputs: ; None. ; ; Outputs: ; R0 = Points to retrieved buffer listhead. ; C bit clear if buffer was available. ; C bit set if queue is empty. ; FREEQ updated with address of next free buffer. ; ;- GETFRE:: MOV FREEQ,R0 ; ADDRESS OF NEXT BUFFER BEQ 20$ ; IF EQ, QUEUE IS EMPTY. MOV (R0),FREEQ ; POINT TO NEXT FREE BUFFER CLR (R0) ; CLEAR THE LINK WORD CLR 2(R0) ; CLEAR THE CLR 4(R0) ; I/O STATUS BLOCK DEC FRECT ; ADJUST THE FREE COUNT CLC ; SHOW SUCESS RETURN 20$: ERRMSG NOBUFF, SEC ; SHOW QUEUE IS EMPTY RETURN .SBTTL FREBUF - RETURN A BUFFER TO THE FREE QUEUE ;+ ; ; FREBUF - Return a buffer to the free queue. ; ; This routine is used to return a buffer to the free buffer queue. ; ; Inputs: ; R0 = address of buffer to return. ; ; Outputs: ; All registers are preserved. ; ;- FREBUF::JSR R2,$SAVVR ; SAVE R0 - R2 CMP R0,#FREEQ ; RETURNING A VALID BUFFER ? BLOS 20$ ; IF LOS, NO (BAD ADDRESS) ; Link in the free buffer. MOV FREEQ,(R0) ; LINK IN FREE BUFFER MOV R0,FREEQ ; UPDATE FREE BUFFER POINTER INC FRECT ; COUNT BUFFER AS FREE CLC ; SHOW SUCCESS RETURN 20$: ERRMSG BADBUF, SEC ; SHOW FAILURE RETURN .SBTTL DEVICE BUFFER POOL .PSECT $$ZZZZ,RW,D,REL,CON ; FORCE BUFFERS TO END OF PROGRAM ; ; The buffer size is large for two reasons. First, it allows us to ; clear the entire window using one buffer instead of up to eight. ; Second, this size is needed for the FACSIMILE command which will ; allow up to 80 byte records (plus cursor addresssing) to be used. ; DBLEN = 100. ; LENGTH OF DEVICE BUFFERS NDBUF = 30. ; NUMBER OF DEVICE BUFFERS BUFOFF = 6 ; OFFSET TO DATA PART OF BUFFER ; LINK WORD AND I/O STATUS BLOCK FRECT:: .WORD NDBUF ; FREE BUFFER COUNT FREEQ:: .WORD .+2 ; POINTER TO NEXT FREE BUFFER .REPT NDBUF-1 .WORD .+DBLEN+BUFOFF ; CHAIN POINTER .BLKW 2 ; I/O STATUS BLOCK .BLKB DBLEN .ENDR .WORD 0 ; LAST BUFFER (0=END OF CHAIN) .BLKW 2 ; I/O STATUS BLOCK .BLKB DBLEN .PSECT ; RETURN TO ORIGINAL PSECT .END