 lst off
* Prime 2.2
*
*  MAKE.NEW.ML - By John Hagen - 05 Feb 90
*
*  An ML program to allow faster logon of new users.
*  Does not display the scanning mailboxes to the user
*
TEMP EQU $DE ;Temp storage

TSTMDM = $7200 ;Test Modem hook address
POUT = TSTMDM+2 ;Print to screen hook
MOUT = POUT+2 ;
MOUT1 = MOUT+2 ;
MINP = MOUT1+2 ;
PUSH = MINP+2 ;
CASE = PUSH+2 ;Convert to upper case
RDCHAR = CASE+2 ;Keyboard input 1 key
DHOME = RDCHAR+2 ;Do HOME/Clear screen

 PUT EQUATES

 ORG $6800 ;Buffer workspace

 JMP FILSETUP ;To allow storage of New Alias
NEWALIAS DS 20 ;New Alias storage space
NEWBOX DS 2 ;New users box number
NEWDUP DS 1 ;New user duplicate alias flag
USERBOX DS 2 ;Track next user box

*
*  Set up the FIL.USR into the buffer
*
FILSETUP LDX #0 ;Clear the index
FILOOP LDA FILUSR,X ;Get the filename character
 BEQ FILDONE ;Finished, go open the file
 STA PATHNAME+1,X ;Save the char
 INX ;Inc the char cntr
 JMP FILOOP ;Continue
FILDONE STX PATHNAME ;Save the char count

*
*  Open the user file
*
FILOPEN LDX #0 ;Clear the index
 JSR MLI ;Call the MLI
 HEX C8 ;OPEN
 DA POPEN ;OPEN Param list
 BCC SETREFN ;MLI Call successful
 JMP HANDLERR ;MLI Error

*
*  Update all the file reference number pointers
*
SETREFN LDA OPREFNUM ;Get the ref number
 STA RDREFNUM ;For the READ command
 STA EOREFNUM ;EOF Command
 STA MKREFNUM ;MARK commands
 STA CLREFNUM ;CLOSE command

*
*  Time For The GET_EOF
*
GETEOF JSR MLI ;Call the MLI
 HEX D1 ;GET_EOF
 DA PEOF
 BCC STARTUSR ;MLI Successful
 JMP HANDLERR ;MLI Error

*
*  Set up user input and initialize variables
*
STARTUSR LDA #0 ;Clear the data
 STA TBUFF ;Clear modem input
 STA MARKPOS ;Clear the pointer LSByte
 STA MARKPOS+1 ; and the middle byte
 STA MARKPOS+2 ; and the MSByte

*
*  Set the position via SET_MARK
*
SETMARK JSR MLI ;Call the MLI
 HEX CE ;SET_MARK
 DA PMARK ;Paramater pointer
 BCC SETMARK1 ;MLI Successful
 JMP HANDLERR ;MLI Error
SETMARK1 CLC ;Clear the carry bit
 LDA MARKPOS+1 ;Lets get the middle byte
 ADC #2 ;Add 2 to the marker middle byte
 STA MARKPOS+1 ; and save it
 LDA #0 ;To see if we carried
 ADC MARKPOS+2 ; and add it in
 STA MARKPOS+2 ; and save it
 CLC ;Clear it just to be sure

*
*  Let's read the data from the file
*
READFIL JSR MLI ;Call the MLI
 HEX CA ;READ
 DA PREAD
 BCC PRINTBUF ;MLI Successful
 JMP HANDLERR ;MLI Error

*
*  Examine Buffer Contents
*
PRINTBUF EQU *

*
*  User 1 in the buffer
*
 LDX #21 ;Start of user alias
 JSR USERCK ;Ck status of this user
 JSR POSITION ;Update the actual position

*
*  User 2 in the buffer
*
 LDX #149 ;Start of next alias
 JSR USERCK ;Ck status of user
 JSR POSITION ;Update the actual position

*
*  User 3 in the buffer
*
 LDX #21 ;Start of next alias
 JSR USERCK ;Ck status of user
 JSR POSITION ;Update actual position

*
*  User 4 in the buffer
*
 LDX #149 ;Start of the 4th alias
 JSR USERCK ;Ck status of user
 JSR POSITION ;UPdate the position

*
*  Do next block of user data
*
 JMP SETMARK ;Move the pointer forward!

*
*  Check to see if user is valid or not
*
USERCK STX USERDATX ;Save the X reg
 STY USERDATY ;SAve the Y reg
 TXA ;Load user alias address offset
 SEC ;Set the carry for subtraction
 SBC #21 ;Sub offset from the class code
 TAX ;Put in the X reg
 INC USERCNTR ;Increment the user cntr
 LDA USERCNTR ; and load it in the Accum
 CMP #1 ;is it the first pass?
 BEQ USEROLD ;Yes, bypass the offset
 CMP #2 ;Is it the 2nd pass?
 BEQ USEROLD ;Yes, bypass the offset
 CMP #4 ;Is it the 4th pass?
 BNE USEROFF1 ;Nope, do the offset
 LDA #0 ;Clear the Accum
 STA USERCNTR ; and the counter
USEROFF1 LDA READBUF+256,X ;Get the users class code
 JMP USEROLD1 ; and press on
USEROLD LDA READBUF,X ;Get the users class code
USEROLD1 CMP #$44 ;Is it a "D"eleted user?
 BNE USEALIAS ;Normal user, check alias
*
*  Deleted user, save the box number for issue
*
USERDELE LDA NEWBOX ;New user box data
 CMP #0 ;Anything there yet?
 BNE USEREXIT ;Yes, don't mess with it
 LDA NEWBOX+1 ;Now ck the MSByte
 CMP #0 ;Anything here?
 BNE USEREXIT ;Yes, so we're setup
 LDA USERBOX ;Get the LSByte
 STA NEWBOX ; and save it for issue
 LDA USERBOX+1 ;Get the MSByte
 STA NEWBOX+1 ; and save it too
 JMP USEREXIT ;Continue looking

*
*  User alias check routine
*
USEALIAS LDX USERDATX ;Restore the X register
 LDY #0 ;Clear the index
USEALIA1 LDA USERCNTR ;Load it in the A
 CMP #1 ;First Pass?
 BEQ USEALOLD ;Yes, bypass offset
 CMP #2 ;Second pass?
 BEQ USEALOLD ;Yes, bypass offset
 LDA READBUF+256,X ;Read the alias byte
 JMP USEALOL1 ; and press on
USEALOLD LDA READBUF,X ;Load the alias byte
USEALOL1 CMP NEWALIAS,Y ;Is it the same?
 BNE USEREXIT ;Looks okay, let 'em keep it
 INY ;For the next byte
 INX ;Add for the offset
 CPY #20 ;Finished yet?
 BNE USEALIA1 ;Nope, keep looking
 LDA #255 ;To set the duplicate flag
 STA NEWDUP ; and please set it now
 JSR CLOSEALL ;Now, close the file
 PLA ;Pop the stack
 PLA ;And the last one
 RTS ;Back to BASic we go

*
*  Increment the box counter
*
USEREXIT CLC ;Clear the carry flag
 LDA USERBOX ;Get the LSByte of current box
 ADC #1 ;Add one to it
 STA USERBOX ; and save it for later
 LDA #0 ;Clear the Accum
 ADC USERBOX+1 ; and add it up
 STA USERBOX+1 ; then save it.
 LDX USERDATX ;Restore the X
 LDY USERDATY ;Restore the Y
USEREND RTS

USERDATX DS 1 ;Temp storage for X Reg
USERDATY DS 1 ;temp storage for Y Reg
USERCNTR DS 1 ;User pass counter

*
*  Check for past end of position
*
POSITION CLC ;Clear the carry bit
 LDA #128 ;To update the actual position
 ADC POSACT ;Add to the LSByte
 STA POSACT ; and save for next pass
 LDA #0 ;For the middle byte update
 ADC POSACT+1 ; to keep it current
 STA POSACT+1 ; and save for next pass
 LDA #0 ;For the MSByte position
 ADC POSACT+2 ; and add it to the actual MSB
 STA POSACT+2 ; and save for next pass
 CMP EOFVAL+2 ;IS it the same as the MSByte?
 BNE POSRTS ;Nope, keep working
 LDA POSACT+1 ;Yes, how about the middle byte
 CMP EOFVAL+1 ;Is it the same too for the EOF?
 BNE POSRTS ;Nope, keep working
 LDA POSACT ;Now check the LSByte
 CMP EOFVAL ;Match the LSByte too?
 BNE POSRTS ;Nope, keep working
 PLA ;Clear the last
 PLA  ; two JSR's
 JMP POSRTS ;Back to BASic
POSITIN1 LDA #0 ;Clear the accumulator
 STA TBUFF ; and modem input
 LDA #$8D ;Carriage return
 JSR POUTHK ;Send to user
 JSR POUTHK ;One more for measure
 LDX #0 ;Clear the index
POSEOF LDA ENDUSERS,X ;Get TXT for EOF
 CMP #0 ;Finished yet?
 BEQ POSEND1 ;Yes, finish with a press key
 JSR POUTHK ;Send msg to screen
 INX ;Inc the index
 BNE POSEOF ;Always
POSEND1 LDA #20 ;Press any key char
 JSR POUTHK ;Send to the user
 JSR CLOSEALL ; and close the file
POSRTS RTS ;Back to BASic or the prg

*
*  Error Handler
*
HANDLERR STA TEMP ;Save MLI error code
 CMP #$40 ;Invalid pathname error?
 BEQ E2 ;That's it
 CMP #$44 ;Pathname not found?
 BEQ E2 ;That's it
 CMP #$45 ;Vol/Dir not found?
 BEQ E2 ;That's it
 CMP #$46 ;File not found?
 BEQ E2 ;That's it
 CMP #$4C ;EOF Yet?
 BEQ E4 ;That's it
 CMP #$4D ;Past Marker?
 BEQ E4 ;That's it
 CMP #$56 ;Buffer address bad?
 BEQ E2 ;That's it
 LDX #TXIOERR-ZTXT
 BNE E3 ;Always
E2 LDX #TXFNF-ZTXT
E3 JSR PRINT ;Print error msg
 LDA #$8D ;Carriage Return
 JSR POUTHK ;Send to the user
 JSR CLOSEALL ;Close the files
 RTS ;Finished, back to BASic
E4 JMP POSITIN1

*
*  Print Message
*
PRINT LDA ZTXT,X ;Get the character
 BEQ PRINTRTS ;If 00, then exit
 JSR POUTHK ;Send to the user
 INX ;Increment the counter
 BNE PRINT ;Always
PRINTRTS RTS ;Back to the main routine

*
*  Close all the files
*
CLOSEALL JSR MLI ;Call the MLI
 HEX CC ;CLOSE
 DA PCLOSE ;Paramater List
 RTS ;No error ck

TSTMDMHK JMP (TSTMDM) ;Hook to TSTMDM
POUTHK JMP (POUT) ;Hook to Output
MINPHK JMP (MINP) ;
MOUT1HK JMP (MOUT1) ;
PUSHINP JMP (PUSH) ;
DHOMEHK JMP (DHOME) ;
RDCHARHK JMP (RDCHAR) ;
CASEHK JMP (CASE) ;

*
*  Messages
*
ZTXT EQU *
TXIOERR HEX 87
 ASC "I/O Error            "00
TXFNF HEX 87
 ASC "File/Path not found"00
TXEOF HEX 87
 ASC "End of File!"00
ENDUSERS ASC "End of user list.  "00

DIRCOUNT EQU *
BUFINDX EQU DIRCOUNT+1

*
*  Paramater List
*
POPEN HEX 03 ;OPEN Parm list
 DA PATHNAME ;Pathename pointer
 DA OPENBUF ;I/O Buffer
OPREFNUM HEX 00 ;File ref number

PCLOSE HEX 01 ;Close Parm list
CLREFNUM HEX 00 ;CLOSE Ref number

PREAD HEX 04 ;READ Parm list
RDREFNUM HEX 00 ;READ Ref number
 DA READBUF ;Data pointer
RDCOUNT DW 512 ;Request count
TRANSCNT DW 0 ;Transfer count

PMARK HEX 02 ;SET/GET_MARK Parm list
MKREFNUM HEX 00 ;Reference number
MARKPOS DS 3 ;File position

PEOF HEX 02 ;SET/GET_EOF Parm list
EOREFNUM HEX 00 ;Reference number
EOFVAL DS 03 ;Data Storage for EOF

*
*  Miscellaneous info
*
POSACT DS 3 ;Actual position Bytes
FILUSR ASC "FIL.USR"00
PATHNAME DS 65 ;Pathname storage space
READBUF DS 512 ;User file buffer space

 SAV MAKE.NEW.ML
