home *** CD-ROM | disk | FTP | other *** search
-
- incpath include:
- maclib sm.mac
- macfile macro.i
- macfile snoopy.i
- macfile extern/main
- macfile extern/parse
-
- section main,code
-
- cnop 0,4
-
- *******************************************************************************
- ;-------------- Diese Funktion konvertiert einen String in eine Zahl, wobei der
- ;-------------- String in Hexadezimal($),Dezimal(#),Oktal(@) oder Dual(%) vorliegen
- ;-------------- kann. Zusätzlich kann eine Voreinstellung angenommen werden, um
- ;-------------- z.B. ständige '#' bei rein Dezimalen Strings zu überbrücken.
- ;-------------- Irgendwann mal in absolut ferner Zukunft habe ich vor, hier noch
- ;-------------- einen 'Calculator' reinzuhängen: Damit wäre in jedem Programm,
- ;-------------- daß über StringToValue aus Strings Zahlen macht, gleich eine
- ;-------------- Taschenrechnerfunktion drinnen..
- ;-------------- => d0: ULONG Vordefinierter Typ des Strings
- ;-------------- a0: APTR Der String mit der Zahl
- ;-------------- <= d0: LONG Die (vorzeichenbehaftete) IntegerZahl
- ENTRY StringToValue,d1-d2
- moveq #10,d2
- cmp.l #STVFORMAT_HEX,d0
- bne.b .NotHex
- moveq #16,d2
- .NotHex cmp.l #STVFORMAT_BIN,d0
- bne.b .NotBin
- moveq #2,d2
- .NotBin cmp.l #STVFORMAT_OCT,d0
- bne.b .NotOct
- moveq #8,d2
- .NotOct cmpi.b #'-',(a0)
- bne.b .NormalUse
- addq.l #1,a0
- bsr.b .Check4Sign
- bsr.b .Get_s2v
- neg.l d0
- bra StringToValue_done
-
- .NormalUse bsr.b .Check4Sign
- bsr.b .Get_s2v
- bra StringToValue_done
-
- .Check4Sign move.b (a0),d0
- cmpi.b #STVTYPE_DEC,d0
- bne.b 1$
- moveq #10,d2
- addq.l #1,a0
- 1$ cmpi.b #STVTYPE_HEX,d0
- bne.b 2$
- moveq #16,d2
- addq.l #1,a0
- 2$ cmpi.b #STVTYPE_OCT,d0
- bne.b 3$
- moveq #8,d2
- addq.l #1,a0
- 3$ cmpi.b #STVTYPE_BIN,d0
- bne.b 4$
- moveq #2,d2
- addq.l #1,a0
- 4$ moveq #0,d0
- rts
-
- .Get_s2v moveq #0,d1
- move.b (a0)+,d1
- cmpi.b #'a',d1
- blt.b .NoUpcaseChose
- cmpi.b #'z',d1
- bgt.b .NoUpcaseChose
- sub.b #('a'-'A'),d1
- .NoUpcaseChose subi.b #"0",d1
- cmpi.b #10,d1
- bls.b .s2v_Overdose
- cmpi.l #16,d2
- bne.s .s2v_Overdose
- subq.b #'A'-('9'+1),d1
- .s2v_Overdose cmp.b d2,d1
- bcc.b .s2v_Done
- bsr.b ExtendedMulu
- add d1,d0
- bra.b .Get_s2v
- .s2v_Done rts
- DONE StringToValue
-
- ;-------------- Diese Funktion Multipliziert zwei Langwerte
- ;-------------- => d1: LONG Wert 1
- ;-------------- d2: LONG Wert 2
- ;-------------- <= d0: LONG Result
- ENTRY ExtendedMulu,d1-d2
- cmpi.l #$7FFF,d2
- bcc.b 2$
- cmpi.l #$7FFF,d0
- bcc.b 2$
- mulu d2,d0
- bra.b ExtendedMulu_done
- 2$ moveq #0,d1
- subq.l #1,d2
- 1$ add.l d0,d1
- dbra d2,1$
- move.l d1,d0
- DONE ExtendedMulu
-
- *******************************************************************************
- ;-------------- clears an allocated list with all its elements
- ;--------------
- ;-------------- => a0: struct List *
- ;-------------- d0: LONG size of each element (0=don't call FreeMem() on it)
- ;--------------
- ENTRY RemoveList,d0-d7/a0-a6
- movea.l a0,a5
- move.l d0,d7
- movea.l (execBase).w,a6
- rl.LOOP IFEMPTY a5,rl.DONE
- move.l (LH_HEAD,a5),a4
- movea.l a5,a0
- REMHEAD
- tst.l d7
- beq.b rl.LOOP
- movea.l a4,a1
- move.l d7,d0
- CALL FreeMem
- bra.b rl.LOOP
- rl.DONE DONE RemoveList
-
- ***********************************************************************************
- ;-------------- send message to window
- ;--------------
- ;-------------- => a0: APTR string
- ;--------------
- ENTRY ShowMessage,d0-d7/a0-a6
-
- ;-------------- WARNING: SEGTRACKER() does its own thing
- move.l (window),d1
- move.l a0,d2
- move.l #outputArgs,d3
- CALL VFPrintf,<(dosBase)>
- DONE ShowMessage
-
- ***********************************************************************************
- ;-------------- send error message to the default output stream
- ;--------------
- ;-------------- => a0: APTR string
- ;--------------
- ENTRY ShowErrorMessage,d0-d7/a0-a6
- move.l a0,d1
- move.l #outputArgs,d2
- bsr.b ShowWarning
- DONE ShowErrorMessage
-
- *******************************************************************************
- ;-------------- print out some warning message
- ;--------------
- ;-------------- => d1: APTR message
- ;-------------- d2: APTR arguments
- ENTRY ShowWarning,d0-d7/a0-a6
- lea (easyStruct),a1
- move.l #es_SIZEOF,(es_StructSize,a1)
- move.l #snoopyTitle,(es_Title,a1)
- move.l d1,(es_TextFormat,a1)
- move.l #snoopyGadform,(es_GadgetFormat,a1)
- CLEAR.L a0,a2
- movea.l d2,a3
- CALL EasyRequestArgs,<(intBase)>
- DONE ShowWarning
-
- ***********************************************************************************
- ;-------------- send error message to the default output stream
- ;--------------
- ;-------------- => a0: APTR string
- ;--------------
- ENTRY ShowEchoMessage,d1-d7/a0-a6
- lea (easyStruct),a1
- move.l #es_SIZEOF,(es_StructSize,a1)
- move.l #snoopyTitle,(es_Title,a1)
- move.l a0,(es_TextFormat,a1)
- move.l #snoopyEchoform,(es_GadgetFormat,a1)
- CLEAR.L a0,a2
- suba.l a3,a3
- CALL EasyRequestArgs,<(intBase)>
- DONE ShowEchoMessage
-
- ***********************************************************************************
- ;-------------- show a DOS errorcode
-
- ENTRY ShowDosError,d0-d7/a0-a6
- CALL IoErr,<(dosBase)>
- move.l d0,d1 ; code
- moveq #0,d2 ; header
- move.l #errorMsgBuffer,d3 ; buffer
- move.l #256,d4 ; len
- CALL Fault
- move.l #errorMsgBuffer,d1
- moveq #0,d2
- bsr ShowWarning
- DONE ShowDosError
-
- *******************************************************************************
- ;-------------- c-style sprintf()-function using exec.library [no buffer overflow
- ;-------------- checking has been added (due to a general lazyness on my part)]
- ;--------------
- ;-------------- => a0: APTR format string (see exec/RawDoFmt() for limitations)
- ;-------------- a1: APTR format data
- ;-------------- a2: APTR target string
- ENTRY SPrintf,d0-d3/a0-a3/a6
- movea.l a2,a3
- lea (sprintf_cout,pc),a2
- CALL RawDoFmt,<(execBase).w>
- DONE SPrintf
-
- sprintf_cout move.b d0,(a3)+
- rts
-
- snoopyTitle dc.b 'Snoopy ',_VALOF(VERSION),'.',_VALOF(REVISION),' Message',0
- snoopyGadform dc.b 'Ok',0
- snoopyEchoform dc.b 'Ok|Abort',0
- even
-
- section memory,bss
-
- easyStruct ds.b es_SIZEOF
- errorMsgBuffer ds.b 256
-
- end
-