******************************************************************************* * init 1.2.3 ******************************************************************************* * INFO executes some system inits * SYN success = init[CmdLnPtr,CmdLnLen] * d0.l a0.l d0.w * IN CmdLnPtr pointer to the shell commandline string * CmdLnLen length in characters of the commandline * OUT success 0=ERROR * MOD _DOSBase dos.library pointer * _StdOut standard output filehandle * CmdLn commandline (NULL-terminated) string * REQ _DOSName address of "dos.library",0 * NOTE this code could be improved by using GetArgStr() or ReadArgs() * for standard OS commandline parsing ******************************************************************************* function init[a0/d0.w],d1/d7/a0-a1/a6:d0.l moveq.l #0,d7 subq.w #1,d0 ;don't copy closing RETURN lea.l CmdLn,a1 ;destination buffer when.s {#512»=d0.w} & d0.w subq.w #1,d0 ;"expire" = "dbra" expire d0=d0 move.b (a0)+,(a1)+ ;copy commandline addq.l #1,d7 nexp ewhen clr.b (a1) ;NULL-terminated movea.l 4.w,a6 lea.l _DOSName,a1 moveq.l #37,d0 ;at least KS 2.04 jsr (_LVOOpenLibrary,a6) move.l d0,_DOSBase when.s d0 movea.l d0,a6 jsr (_LVOOutPut,a6) move.l d0,_StdOut ;still true (~0) ewhen efunc ******************************************************************************* * ClnUp 1.1.4 ******************************************************************************* * INFO frees allocated system resources * SYN ClnUp[] * REQ _DOSBase dos.library pointer ******************************************************************************* procedure ClnUp[],d0-d1/a0-a1/a6 move.l InFlHnd,d1 ;source filehandle when.s d1.l movea.l _DOSBase,a6 jsr (_LVOClose,a6) ewhen move.l WrkBufLen,d0 ;free allocated buffer when.s d0.l movea.l 4.w,a6 movea.l WrkBufAdr,a1 jsr (_LVOFreeMem,a6) ewhen movea.l _DOSBase,a1 movea.l 4.w,a6 jsr (_LVOCloseLibrary,a6) moveq.l #0,d0 ;returncode eproc ******************************************************************************* * prt 1.1.1 ******************************************************************************* * INFO prints a text to the standard output if quiet mode is OFF * SYN prt[TxtPtr] * d2.l * IN TxtPtr pointer to NULL-terminated text string * REQ _DOSBase dos.library pointer * _StdOut standard output handle ******************************************************************************* procedure prt[d2],d0-d3/a0-a1/a6 move.b flgs,d0 andi.b #1< ' ' ******************************************************************************* procedure SkpSpcs[a0] .fnd cmpi.b #' ',(a0)+ beq.s .fnd subq.l #1,a0 eproc ******************************************************************************* * ValU 1.1.3 ******************************************************************************* * INFO converts a decimal ASCII string to an unsigned long integer * SYN IntVal = ValU[StrPtr] * d0.l a0.l * IN StrPtr pointer to numerical string * OUT IntVal unsigned integer * MOD a0.l pointer after string * NOTE it stops at the first character not inside ['0'...'9'] ******************************************************************************* function ValU[a0],d1-d2:d0 moveq.l #0,d0 moveq.l #0,d1 do move.b (a0)+,d1 ;get a digit (d) subi.b #'0',d1 ;convert to integer bcs.s .exit ;if d<0... cmpi.b #9,d1 bhi.s .exit ;if d>9... move.l d0,d2 ;IntVal add.l d0,d0 ;2*IntVal lsl.l #3,d2 ;8*IntVal add.l d2,d0 ;10*IntVal add.l d1,d0 ;10*IntVal+d -> IntVal loop .exit efunc ******************************************************************************* * StrU 1.1.1 ******************************************************************************* * INFO converts an unsigned long integer to a NULL-terminated, * decimal ASCII string * SYN StrU[int, DstBufAdr, len] * d0.l a0.l d1.l * IN int integer to convert * DstBufAdr pointer to destination buffer * len the string will be exactly len characters long * (MUST be >0!!!) * NOTE the destination buffer MUST be at least len+1 bytes long! ******************************************************************************* procedure StrU[d0/a0/d1],d0-d2/a0 adda.l d1,a0 ;last digit address+1 clr.b (a0) ;final BLANK subq.l #1,d1 expire d1=d1 divul.l #10,d2:d0 ;last digit addi.b #'0',d2 ;convert to ASCII move.b d2,-(a0) ;store nexp eproc ******************************************************************************* * GetFlSz 1.1.2 ******************************************************************************* * INFO returns the size in bytes of a file * SYN sz=GetFlSz[FlHnd] * d0.l d1.l * IN HlHnd filehandle * OUT d0.l 0 on failure * REQ _DOSName address of "dos.library",0 * NOTE uses TmpBuf (must be on a 4 bytes boundary) ******************************************************************************* function GetFlSz[d1],d1-d2/a0-a1/a6:d0 move.l #TmpBuf,d2 movea.l _DOSBase,a6 jsr (_LVOExamineFH,a6) when.s d0.l lea.l TmpBuf,a0 move.l (fib_Size,a0),d0 ewhen efunc ******************************************************************************* * ChkBrk 1.1.1 ******************************************************************************* * INFO checks if the user is pressing CTRL-C * SYN ErrCode=ChkBrk[] * d0.l * OUT ErrCode E_USRBRK if pressed, 0 otherwise ******************************************************************************* function ChkBrk[],d1/a0-a1/a6:d0 movea.l 4.w,a6 moveq.l #0,d0 move.l #SIGBREAKF_CTRL_C,d1 ;check & clear this signal jsr (-306,a6) ;SetSignal() btst.l #SIGBREAKB_CTRL_C,d0 ;if the signal bit sne.b d0 ;was ON, then return andi.b #E_USRBRK,d0 ;the appropriate ErrCode extb.l d0 efunc