.TITLE PRMCHK .IDENT /V01/ .ENABLE LC ; ; This is a generalised parameter checking co-routine designed to be ; called by macro subroutines called with parameters. ; ; Author: V01 25-Jan-80 Phil Stephensen-Payne ; ; Calling Sequence: ; ; The subroutine assumes that all the subroutines that call it ; are themselves called with a number of parameters of which the ; last is an optional error return. ; The calling suboutine should put the number of expected parameters ; (including the error parameter) in R0, leave R5 unchanged and do a ; CALL PRMCHK ; PRMCHK will return with one of the three following cases:- ; i) C-bit clear, R0 = address of error return ; This implies that all expected parameters were specified ; ii) C-bit clear, R0 = 0 ; This implies that all expected parameters except the error ; return were specified ; iii) C-bit set, R0 = -1 ; This implies an invalid number of parameters were specified. ; In addition, when the calling subroutine exits control is returned ; to PRMCHK which expects an error/success value to be stored in R0. ; It then stores this value in the error return parameter (if specified). ; Note that:- ; i) If an invalid number of parameters is specified the last ; parameter is assumed to be an error parameter. ; ii) The error parameter is assumed to be a word if word-alined ; and a byte otherwise. ; iii) PRMCHK saves all registers,thus avoiding the need for each ; subroutine to do so. ; RETURN: .WORD ; Return Address PRMCHK:: MOV (SP)+,RETURN ; Save the Return Address JSR R5,.SAVR1 ; Save all Registers CMP (R5),R0 ;COMPARE NUMBER PASSED WITH LIMIT BLT 10$ ;IF LT - CHECK IF ONE LESS BGT 20$ ;IF GT THEN ERROR ASL R0 ;EQ THEREFORE OK - CONVERT TO WORD OFFSET ADD R5,R0 ;CONVERT TO OFFSET OF ERROR PARAMETER MOV (R0),R0 ;NO - PUT ADDRESS IN R0 MOV R0,-(SP) ; Save the address CLC ; Show Success BR 40$ ;EXIT ; 10$: DEC R0 ;SET TO ONE LESS THAN REQUIRED CMP (R5),R0 ;NOW RIGHT? BLT 20$ ;IF LT NO - SET ERROR CLR R0 ;OK BUT NO ERROR RETURN - FLAG IT MOV R0,-(SP) ;Save Result CLC ;Show Success BR 40$ ;EXIT ; 20$: MOV (R5),R0 ;GET REAL NUMBER OF PARAMETERS BEQ 30$ ; If eq none - no error return ASL R0 ;CONVERT NUMBER TO WORD OFFSET ADD R5,R0 ;ADD BASE ADDRESS MOV (R0),R0 ; Get Error Address ; 30$: MOV R0,-(SP) ; Save Address SEC ; Set Error MOV #-1,R0 ;SET ERROR RETURN ; 40$: CALL @RETURN ; Call back the caller MOV (SP)+,R1 ; Get back the error address BEQ 60$ ; If eq no error BIT #1,R1 ; Odd address? BNE 50$ ; If eq yes - only move a byte MOV R0,(R1) ; No - store a word BR 60$ ; Exit ; 50$: MOVB R0,(R1) ; Store a byte ; 60$: RETURN .END