Added machine language routines
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
(****************************************************************************
|
(****************************************************************************
|
||||||
* File name: CSTRINGS.D
|
* File name: CSTRINGS.D
|
||||||
* Created On: Fri 02 Oct 2020 07:27:00 PM CEST
|
* Created On: Fri 02 Oct 2020 07:27:00 PM CEST
|
||||||
* Last Modified: Sat 03 Oct 2020 01:59:46 PM CEST
|
* Last Modified: Tue 13 Oct 2020 05:15:30 PM CEST
|
||||||
* Author: Jali <jali@orca-central.de>
|
* Author: Jali <jali@orca-central.de>
|
||||||
****************************************************************************
|
****************************************************************************
|
||||||
* Header file for an implementation of C-Like strings
|
* Header file for an implementation of C-Like strings
|
||||||
@@ -51,18 +51,6 @@ PROCEDURE Compare(strA, strB : CString) : CompareResult;
|
|||||||
*)
|
*)
|
||||||
PROCEDURE Concat(strA, strB : CString) : CString;
|
PROCEDURE Concat(strA, strB : CString) : CString;
|
||||||
|
|
||||||
(*
|
|
||||||
* Checks if *subString* is contained in *string*, and returns the result.
|
|
||||||
*
|
|
||||||
* # Parameters:
|
|
||||||
* - string: The string to compare to
|
|
||||||
* - subString: The substring to search
|
|
||||||
*
|
|
||||||
* # Returns:
|
|
||||||
* TRUE, if subString is part of string, else false.
|
|
||||||
*)
|
|
||||||
PROCEDURE Contains(string, subString : CString) : BOOLEAN;
|
|
||||||
|
|
||||||
(*
|
(*
|
||||||
* Checks, if the CString is NIL or the the string only contains a NULL char.
|
* Checks, if the CString is NIL or the the string only contains a NULL char.
|
||||||
*
|
*
|
||||||
@@ -74,18 +62,6 @@ PROCEDURE Contains(string, subString : CString) : BOOLEAN;
|
|||||||
*)
|
*)
|
||||||
PROCEDURE IsNilOrEmpty(string : CString) : BOOLEAN;
|
PROCEDURE IsNilOrEmpty(string : CString) : BOOLEAN;
|
||||||
|
|
||||||
(*
|
|
||||||
* Checks, if the CString is NIL or the the string only contains a white space
|
|
||||||
* characters.
|
|
||||||
*
|
|
||||||
* # Parameters:
|
|
||||||
* - string: The string to check
|
|
||||||
*
|
|
||||||
* # Returns:
|
|
||||||
* TRUE, if the CString is NIL, or only contains a white space character
|
|
||||||
*)
|
|
||||||
PROCEDURE IsNilOrWhiteSpace(string : CString) : BOOLEAN;
|
|
||||||
|
|
||||||
(*
|
(*
|
||||||
* Returns the length of the string stored in
|
* Returns the length of the string stored in
|
||||||
* the CString.
|
* the CString.
|
||||||
@@ -105,4 +81,4 @@ PROCEDURE ToArray(string : CString) : ARRAY OF CHAR;
|
|||||||
|
|
||||||
END CStrings;
|
END CStrings;
|
||||||
|
|
||||||
(* vim: set filetype=modula2: set nospell: *)
|
(* vim: set filetype=modula2: set nospell: set fileformat=dos: *)
|
||||||
|
|||||||
100
src/cstrings.i
100
src/cstrings.i
@@ -1,7 +1,7 @@
|
|||||||
(****************************************************************************
|
(****************************************************************************
|
||||||
* File name: CSTRINGS.I
|
* File name: CSTRINGS.I
|
||||||
* Created On: Sat 03 Oct 2020 03:18:19 PM CEST
|
* Created On: Sat 03 Oct 2020 03:18:19 PM CEST
|
||||||
* Last Modified: Sun 04 Oct 2020 04:34:02 PM CEST
|
* Last Modified: Tue 13 Oct 2020 05:40:24 PM CEST
|
||||||
* Author: Jali <jali@orca-central.de>
|
* Author: Jali <jali@orca-central.de>
|
||||||
****************************************************************************
|
****************************************************************************
|
||||||
* Implementation for handling C-Like strings
|
* Implementation for handling C-Like strings
|
||||||
@@ -11,59 +11,101 @@ IMPLEMENTATION MODULE CStrings;
|
|||||||
|
|
||||||
FROM Storage IMPORT ALLOCATE;
|
FROM Storage IMPORT ALLOCATE;
|
||||||
|
|
||||||
PROCEDURE Compare(strA : CString, strB : CString) : CompareResult
|
PROCEDURE Compare(strA, strB : CString) : CompareResult
|
||||||
(* $L- *)
|
|
||||||
BEGIN
|
BEGIN
|
||||||
|
(* $L- *)
|
||||||
ASSEMBLER
|
ASSEMBLER
|
||||||
MOVE.L -(A3),A1 ; Read strB from the stack
|
MOVE.L -(A3),A1 ; Read strB from the stack
|
||||||
MOVE.L -(A3),A0 ; Read strA from the stack
|
MOVE.L -(A3),A0 ; Read strA from the stack
|
||||||
MOVE.W 1,D2 ; Preset the return value to CompareResult.Equal
|
MOVE.W #1,D2 ; Preset the return value to CompareResult.Equal
|
||||||
Loop:
|
Loop:
|
||||||
MOVE.S D0,(A0)+ ; Read a byte from strA into D0, and increase the pointer
|
MOVE.B (A0)+,D0 ; Read a byte from strA into D0, and increase the pointer
|
||||||
CMP.S 0,D0 ; Check if the value is NULL
|
CMP.B #0,D0 ; Check if the value is NULL
|
||||||
BEQ Return ; Reached the end of the first string; break
|
BEQ Return ; Reached the end of the first string; break
|
||||||
MOVE.S D1,(A1)+ ; Read a byte from strB into S1 and increase the pointer
|
MOVE.B (A1)+,D1 ; Read a byte from strB into S1 and increase the pointer
|
||||||
CMP.S 0,D0 ; Check if the byte is NULL
|
CMP.B #0,D0 ; Check if the byte is NULL
|
||||||
BEQ Return ; Reached the end of the second string; break
|
BEQ Return ; Reached the end of the second string; break
|
||||||
CMP.S D0,D1 ; Compare the two values for equality
|
CMP.B D0,D1 ; Compare the two values for equality
|
||||||
BEQ Loop ; If equal, continue with the next bytes.
|
BEQ Loop ; If equal, continue with the next bytes.
|
||||||
MOVE.W 2,D2 ; Set the result register to ComepareResult.After
|
MOVE.W #2,D2 ; Set the result register to ComepareResult.After
|
||||||
BHI Return ; Break and retrun result
|
BHI Return ; Break and retrun result
|
||||||
MOVE.W 0,D2 ; Set the result register to CompareResult.Before
|
MOVE.W #0,D2 ; Set the result register to CompareResult.Before
|
||||||
Return:
|
Return:
|
||||||
MOVE D2,(A3)+ ; Push the result to the stack
|
MOVE.W D2,(A3)+ ; Push the result to the stack
|
||||||
END;
|
END;
|
||||||
(* $L+ *)
|
(* $L+ *)
|
||||||
END Compare;
|
END Compare;
|
||||||
|
|
||||||
PROCEDURE CopyMem(tgt, src : CString)
|
PROCEDURE CopyMem(src, tgt : CString, len : CARDINAL)
|
||||||
p : POINTER TO CHAR;
|
|
||||||
BEGIN
|
BEGIN
|
||||||
p := tgt;
|
(* $L- *)
|
||||||
WHILE src^ <> NULL DO
|
ASSEMBLER
|
||||||
p^ := src^;
|
MOVE.W -(A3),D1 ; Read the len parameter
|
||||||
p += 1;
|
MOVE.L -(A3),A1 ; Read tgt from the stack
|
||||||
src += 1;
|
MOVE.L -(A3),A0 ; Read src from the stack
|
||||||
|
BRA Entry ; Forces the loop condition to be checked before
|
||||||
|
; anything else. Cheaper than decrementing D1
|
||||||
|
Loop:
|
||||||
|
MOVE.B (A0)+,D0 ; Read a byte from src into D0, and increase the pointer
|
||||||
|
MOVE.B D0,(A1)+ ; Copy the byte into the target buffer
|
||||||
|
Entry:
|
||||||
|
DBF D1,Loop ; Decrement the counter and branch to loop, until done
|
||||||
END;
|
END;
|
||||||
|
(* $L+ *)
|
||||||
END CopyStr;
|
END CopyStr;
|
||||||
|
|
||||||
PROCEDURE Concat(strA, strB : CString) : CString
|
PROCEDURE Concat(strA, strB : CString) : CString
|
||||||
VAR
|
VAR
|
||||||
r : POINTER TO CHAR;
|
r : POINTER TO CHAR;
|
||||||
len : LONGCARD;
|
lenA : LONGCARD;
|
||||||
|
lenB : LONGCARD;
|
||||||
BEGIN
|
BEGIN
|
||||||
len := Length(strA) + Length(strB);
|
lenA := Length(strA);
|
||||||
ALLOCATE(r, lenA + lenB);
|
lenB := Length(strB);
|
||||||
CopyMem(r, strA);
|
ALLOCATE(r, lenA + lenB + 1);
|
||||||
CopyMem(r, strB);
|
CopyMem(r, strA, lenA);
|
||||||
(r + len)^ := NULL;
|
CopyMem(r + lenA, strB, lenB);
|
||||||
|
CopyMem(r + lenA + lenB, ASC(0), 1);
|
||||||
|
RETURN r;
|
||||||
END Concat;
|
END Concat;
|
||||||
|
|
||||||
PROCEDURE Contains
|
PROCEDURE IsNilOrEmpty(string : CString) : BOOLEAN
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
END Contains;
|
(* $L- *)
|
||||||
|
ASSEMBLER
|
||||||
|
MOVE.L -(A3),A0 ; Get the parameter
|
||||||
|
MOVE.W #0,D1 ; Set the result value to false
|
||||||
|
CMP.L #0,A0 ; Is address == NULL?
|
||||||
|
BEQ IsNil ; We have to return TRUE here
|
||||||
|
CMP.B #0,(A0) ; Is the value of the parameter also NULL?
|
||||||
|
BEQ IsNil ; Set the return value to TRUE
|
||||||
|
BRA End ; Otherwise, return FALSE
|
||||||
|
IsNil:
|
||||||
|
MOVE.W #1,D1 ; Set result TRUE
|
||||||
|
End:
|
||||||
|
MOVE.W D1,(A3)+
|
||||||
|
END;
|
||||||
|
(* $L+ *)
|
||||||
|
END IsNilOrEmpty;
|
||||||
|
|
||||||
|
PROCEDURE Length(string : CString) : LONGCARD
|
||||||
|
BEGIN
|
||||||
|
(* $L- *)
|
||||||
|
ASSEMBLER
|
||||||
|
MOVE.L -(A3),A0 ; Get the address of the string
|
||||||
|
MOVE.L #0,D1 ; Set the return value to 0
|
||||||
|
Loop:
|
||||||
|
MOVE.B (A0)+,D0 ; Load the value from (A0)
|
||||||
|
CMP.B #0,D0 ; Check if D0 is NULL
|
||||||
|
BEQ End ; Jump to the end, when end of string is reached
|
||||||
|
ADDI #1,D1 ; Increase the result value
|
||||||
|
BRA Loop ; Continue the loop
|
||||||
|
End:
|
||||||
|
MOVE.L D1,(A3)+ ; Push the result onto the stack
|
||||||
|
END
|
||||||
|
(* $L+ *)
|
||||||
|
END Length;
|
||||||
|
|
||||||
END CStrings;
|
END CStrings;
|
||||||
|
|
||||||
(* vim: set filetype=modula2: *)
|
(* vim: set filetype=modula2: set nospell: set fileformat=dos: *)
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ BEGIN
|
|||||||
Read(exit);
|
Read(exit);
|
||||||
END Telnet.
|
END Telnet.
|
||||||
|
|
||||||
(* vim: set filetype=modula2: *)
|
(* vim: set filetype=modula2: set nospell: set fileformat=dos: *)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
(****************************************************************************
|
(****************************************************************************
|
||||||
* File name: TRANSPRT.D
|
* File name: TRANSPRT.D
|
||||||
* Created On: Fri 02 Oct 2020 07:27:00 PM CEST
|
* Created On: Fri 02 Oct 2020 07:27:00 PM CEST
|
||||||
* Last Modified: Fri 02 Oct 2020 07:27:23 PM CEST
|
* Last Modified: Tue 13 Oct 2020 12:43:09 PM CEST
|
||||||
* Author: Jali <jali@orca-central.de>
|
* Author: Jali <jali@orca-central.de>
|
||||||
****************************************************************************
|
****************************************************************************
|
||||||
* Header file for all STinG releated source files
|
* Header file for all STinG releated source files
|
||||||
@@ -35,4 +35,4 @@ TYPE
|
|||||||
|
|
||||||
END Transport.
|
END Transport.
|
||||||
|
|
||||||
(* vim: set filetype=modula2: *)
|
(* vim: set filetype=modula2: set nospell: set fileformat=dos: *)
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
|
|
||||||
(* vim: set filetype=modula2: *)
|
(* vim: set filetype=modula2: set nospell: set fileformat=dos: *)
|
||||||
|
|||||||
Reference in New Issue
Block a user