Commit 0d73c680 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Conversions rationalisation.

Delete pmf/convdate, moved to conversions.
Moved OS_BinaryToDecimal to conversions.
Remove OS_ConvertHex16 and friends.
Add OS_ConvertVariform skeleton.
Tidied conversions.

Version 5.35, 4.79.2.125. Tagged as 'Kernel-5_35-4_79_2_125'
parent 2d883d8d
......@@ -37,7 +37,7 @@ ARMASM = objasm
LD = link
CP = copy
RM = remove
WIPE = -wipe
XWIPE = x wipe
PERL = do <Perl$Dir>.perl
CCFLAGS = -c -depend !Depend -IC:
ASFLAGS = -depend !Depend ${THROWBACK} -Stamp -quit -To $@ -From
......@@ -96,11 +96,11 @@ install_rom: ${TARGET}
clean:
${RM} s.TMOSHelp
${RM} s.Time+Date
${WIPE} o.* ${WFLAGS}
${XWIPE} o.* ${WFLAGS}
${RM} ${TARGET}
${WIPE} aif ${WFLAGS}
${XWIPE} aif ${WFLAGS}
${RM} ${GPADBG}
${WIPE} list.* ${WFLAGS}
${XWIPE} list.* ${WFLAGS}
@echo ${COMPONENT}: cleaned
export: ${EXPORTS}
......
......@@ -13,11 +13,11 @@
GBLS Module_ComponentPath
Module_MajorVersion SETS "5.35"
Module_Version SETA 535
Module_MinorVersion SETS "4.79.2.124"
Module_MinorVersion SETS "4.79.2.125"
Module_Date SETS "27 Nov 2011"
Module_ApplicationDate SETS "27-Nov-11"
Module_ComponentName SETS "Kernel"
Module_ComponentPath SETS "castle/RiscOS/Sources/Kernel"
Module_FullVersion SETS "5.35 (4.79.2.124)"
Module_HelpVersion SETS "5.35 (27 Nov 2011) 4.79.2.124"
Module_FullVersion SETS "5.35 (4.79.2.125)"
Module_HelpVersion SETS "5.35 (27 Nov 2011) 4.79.2.125"
END
......@@ -5,12 +5,12 @@
*
*/
#define Module_MajorVersion_CMHG 5.35
#define Module_MinorVersion_CMHG 4.79.2.124
#define Module_MinorVersion_CMHG 4.79.2.125
#define Module_Date_CMHG 27 Nov 2011
#define Module_MajorVersion "5.35"
#define Module_Version 535
#define Module_MinorVersion "4.79.2.124"
#define Module_MinorVersion "4.79.2.125"
#define Module_Date "27 Nov 2011"
#define Module_ApplicationDate "27-Nov-11"
......@@ -18,6 +18,6 @@
#define Module_ComponentName "Kernel"
#define Module_ComponentPath "castle/RiscOS/Sources/Kernel"
#define Module_FullVersion "5.35 (4.79.2.124)"
#define Module_HelpVersion "5.35 (27 Nov 2011) 4.79.2.124"
#define Module_FullVersion "5.35 (4.79.2.125)"
#define Module_HelpVersion "5.35 (27 Nov 2011) 4.79.2.125"
#define Module_LibraryVersionInfo "5:35"
......@@ -199,14 +199,7 @@ SWIClass SETS RISCOS_StringConversionSWI_Name
AddSWI ConvertNetStation ; &EA
AddSWI ConvertFixedFileSize ; &EB
AddSWI ConvertFileSize ; &EC
AddSWI ConvertHex16 ; &ED
AddSWI ConvertCardinal8 ; &EE
AddSWI ConvertInteger8 ; &EF
AddSWI ConvertBinary8 ; &F0
AddSWI ConvertSpacedCardinal8 ; &F1
AddSWI ConvertSpacedInteger8 ; &F2
AddSWI ConvertFixedFileSize64 ; &F3
AddSWI ConvertFileSize64 ; &F4
AddSWI ConvertVariform ; &ED
ASSERT @ <= &100
......@@ -231,7 +224,6 @@ stack RN r13
Stack RN r13
STACK RN r13
; Vector numbers
UserV * &00
......@@ -308,6 +300,25 @@ Buff_Sound3 * 7
Buff_Speech * 8
Buff_Mouse * 9
; Conversions for OS_ConvertVariform in R4
^ 0
ConvertToHex # 1
ConvertToCardinal # 1
ConvertToInteger # 1 ; Signed
ConvertToBinary # 1
ConvertToSpacedCardinal # 1
ConvertToSpacedInteger # 1 ; Signed
ConvertToPunctCardinal # 1
ConvertToPunctInteger # 1 ; Signed
ConvertToFixedFileSize # 1
ConvertToFileSize # 1
ConvertToIPv4 # 1
ConvertToEUI # 1
ConvertToIPv6 # 1
ConvertToShortestIPv6 # 1 ; See RFC5952 section 4
ConvertToHexLowercase # 1
; Event numbers. 0..31 available
Event_OutputEmpty * 0
......@@ -354,23 +365,12 @@ KBStat_ShiftEnable * &80
KBStat_NoCapsLockBitNo * 4
MainVars * &A6
MosVer * 6 ; nice non-zero value
GBLS MosTitle
MosTitle SETS "Tim's Arthur Operating System 0.00"
; If assembling arthur, there are better strings to use!!
NIL * &80000000 ; An interesting value
MainVars * &A6 ; Start of OS_Byte readable variables
MaxLengthDateLo * &33EA0000 ; Wednesday, 28th September 1988
MaxLengthDateHi * &00000041 ; 11:34:36.80 am
MosVer * 6 ; As returned by OS_Byte 0
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; And a handy variable or three
; From here on, due for retirement
GBLL True
True SETL {TRUE}
......@@ -378,16 +378,17 @@ True SETL {TRUE}
GBLL False
False SETL {FALSE}
NIL * &80000000 ; An interesting value
MaxLengthDateLo * &33EA0000 ; Wednesday, 28th September 1988
MaxLengthDateHi * &00000041 ; 11:34:36.80 am
GBLL AssemblingArthur
AssemblingArthur SETL False
; This needs to be defined for some builds of the Wimp to correctly
; select delegation of application memory management code to the kernel.
GBLL AMBKernel
AMBKernel SETL True
; Tells Switcher it's being built on a system with OS_DynamicArea 6 and 7
; available - activated by Kernel's internal DynArea_QuickHandles switch.
; Actually: is just used by Switcher
GBLL OSD6and7Kernel
OSD6and7Kernel SETL True
......
......@@ -71,9 +71,8 @@ DebugSysVars SETL {FALSE}
; OS_GSInit
; OS_GSRead
; OS_GSTrans
; OS_BinaryToDecimal
; These have been grouped because GSTrans makes direct use of the system variables'
; structures and OS_BinaryToDecimal is used by readvarval.
; structures.
;
; The system variables are stored as a one way sorted alphabetically linked list hanging
; off the zero-page location VariableList:
......@@ -1111,82 +1110,6 @@ ReadVarVal_SetVExit
RVVNFError
MakeErrorBlock VarCantFind
;***************************************************************************
; The convert number to string SWI
; In : R0 signed 32-bit integer
; R1 pointer to buffer
; R2 max buffer length
; Out : R0, R1 unmodified
; R2 actual chars given
; V Set if buffer overflow
; Format : - if negative, leading zeros stripped.
CvtToDecimal ROUT
Push "R0, R3-R5"
MOV R12, R2
MOV R2, #0
CMP R0, #0
BPL %FT01
SUBS R12, R12, #1
BMI %FT10
MOV R11, #"-"
STRB R11, [R1]
MOV R2, #1
RSB R0, R0, #0
; now do digits.
01 RSB R0, R0, #0 ; get negative so minint works.
ADR R3, TenTimesTable
MOV R10, #9 ; max entry
MOV R4, #0 ; non-0 had flag
02 LDR R11, [R3, R10, LSL #2]
MOV R5, #-1 ; digit value
03 ADDS R0, R0, R11
ADD R5, R5, #1
BLE %BT03
SUB R0, R0, R11
CMP R5, #0
CMPEQ R4, #0
BNE %FT04 ; put digit
05 SUBS R10, R10, #1
BPL %BT02 ; next digit
CMP R4, #0
BEQ %FT04 ; R5 must be 0
Pull "R0, R3-R5"
ExitSWIHandler
04 SUBS R12, R12, #1
BMI %FT10 ; naff Exit
ADD R5, R5, #"0"
MOV R4, #-1
STRB R5, [R1, R2]
ADD R2, R2, #1
B %BT05
10
ADR R0, BufferOFloError
[ International
Push "lr"
BL TranslateError
Pull "lr"
]
Pull "R3" ; discard R0 in
Pull "R3-R5"
B SLVK_SetV
TenTimesTable
& 1
& 10
& 100
& 1000
& 10000
& 100000
& 1000000
& 10000000
& 100000000
& 1000000000
; *****************************************************************************
; SWI OS_SetVarVal : create/update/destroy a variable.
......
......@@ -12,28 +12,42 @@
; See the License for the specific language governing permissions and
; limitations under the License.
;
TTL => Convrsions : varicose number->string routines
TTL => Convrsions : various number to string routines
despatchConvert ROUT
MOV r12, #0 ; All conversions want initial cnt = 0
; All conversions want initial count = 0
MOV r12, #0
; Pick off the non table driven ones
CMP R11, #OS_ConvertVariform
BEQ Variform_Code
CMP R11, #OS_ConvertStandardDateAndTime
BEQ StandardDateTime_Code
CMP R11, #OS_ConvertDateAndTime
BEQ DateTime_Code
ASSERT OS_ConvertFixedFileSize > OS_ConvertFixedNetStation
CMP R11, #OS_ConvertFixedFileSize
BGE FileSize_Code
CMP R11, #OS_ConvertFixedNetStation
BGE EconetStation
BGE NetStation_Code
Push "R1, lr"
; Chop into groups of 4 and use a table
SUB R10, R11, #OS_ConvertHex1 + 1
BIC R10, R10, #3
ADD PC, PC, R10
B Hex_Output ; one digit : -4
B Hex_Output ; 2,3,4,8 digits: 0
B Cardinal_Output ; 4
B Signed_Output ; 8
B Binary_Output ; 12
B Cardinal_Spaced_Output ; 16
B Signed_Spaced_Output ; 20
B Hex_Code ; -4 Hex1
B Hex_Code ; 0 Hex2/4/6/8
B Cardinal_Code ; 4
B Signed_Code ; 8
B Binary_Code ; 12
B Cardinal_Spaced_Code ; 16
B Signed_Spaced_Code ; 20
Hex_Output ROUT
Hex_Code ROUT
SUBS R11, R11, #OS_ConvertHex1
MOVNE R11, R11, LSL #3
......@@ -59,7 +73,7 @@ endconversion
SUB R2, R2, R12
ADD R2, R2, #1 ; null not really a char.
SUB R1, R1, #1
ExitSWIHandler
B SLVK
naffconversion
ADRL R0, ErrorBlock_BuffOverflow
......@@ -70,7 +84,7 @@ naffconversion_ErrorSet
Pull "R1, lr"
B SLVK_SetV
Binary_Output ROUT
Binary_Code ROUT
SUB R11, R11, #OS_ConvertBinary1-1
MOV R11, R11, LSL #3
......@@ -84,10 +98,7 @@ Binary_Output ROUT
BNE %BT01
B endconversion
; cardinal output very similar to BinaryToDecimal
Cardinal_Output ROUT
Cardinal_Code ROUT
SUB R11, R11, #OS_ConvertCardinal1-1
MOV R11, R11, LSL #3
......@@ -121,8 +132,7 @@ Cardinal_Output ROUT
Pull "R3-R5"
B naffconversion
Signed_Output ROUT
Signed_Code ROUT
SUB R11, R11, #OS_ConvertInteger1-1
MOV R11, R11, LSL #3
......@@ -138,9 +148,8 @@ Signed_Output ROUT
Swap R2, R12, VC
B endconversion
Cardinal_Spaced_Output ROUT
Signed_Spaced_Output
Cardinal_Spaced_Code ROUT
Signed_Spaced_Code
SUB sp, sp, #12 ; get 12 byte buffer
Push "r1,r2,lr"
......@@ -175,35 +184,24 @@ space_conv_exit
code_of_swi
DCD XOS_ConvertCardinal1 - OS_ConvertSpacedCardinal1
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; R1 current buffer pos
; R12 character count, R2 character limit
; R10 character
addconvchar ROUT
CMP R2, R12
BLE addconvcharoverflow
ADD R12, R12, #1
STRB R10, [R1], #1
RETURNVC
addconvcharoverflow
RETURNVS
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; EcoNet conversions
EconetStation ROUT
CMP R11, #OS_ConvertFixedFileSize
BGE FileSizeConversion
; OS_ConvertNetStation
; OS_ConvertFixedNetStation
; -------------------------
; EcoNet conversions of the form 'nnn.sss' for the fixed variant, or shorter
; In : R0 pointer to two word net/station number block
; R1 pointer to buffer
; R2 max buffer length
; Out : R0 pointer to buffer
; R1 pointer to terminator
; R2 free bytes in buffer
; V Set if buffer overflow
NetStation_Code ROUT
Push "R1, lr"
Push "R0"
LDR R0, [R0, #4]
LDR R0, [R0, #4] ; network number
CMP R0, #256
BHS invalidnetworknumber
MOV R10, #" "
......@@ -215,11 +213,10 @@ EconetStation ROUT
BLEQ addconvchar
CMP R10, #"."
MOVEQ R10, #"0"
01
Pull "R0"
BVS naffconversion
LDR R0, [R0]
LDR R0, [R0, #0] ; station number
CMP R0, #0
CMPNE R0, #256
BHS invalidstationnumber
......@@ -227,7 +224,7 @@ EconetStation ROUT
B endconversion
invalidnetworknumber
INC sp, 4 ; Pull "R0"
ADD sp, sp, #4 ; Pull "R0"
ADR R0, ErrorBlock_BadNetwork
B naffconversion_ErrorSet
......@@ -248,8 +245,8 @@ ErrorBlock_BadStation
ALIGN
doabyte ROUT
; R0 is byte, R11 SWI number (to indicate pad or not)
; return VS for oflo
; R0 is byte, R11 SWI number (to indicate pad or not)
; return VS for oflo
Push "lr"
CMP R11, #OS_ConvertNetStation
BEQ %FT03
......@@ -269,7 +266,7 @@ doabyte ROUT
B addconvchar
01 MOV R10, R2
SUB R2, R2, R12 ; bytes left
SUB R2, R2, R12 ; bytes left
SWI XOS_BinaryToDecimal
ADD R12, R12, R2
ADD R1, R1, R2
......@@ -277,36 +274,97 @@ doabyte ROUT
MOV R10, #"0"
Pull "PC"
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Do length as xxxx bytes or xxxx Kbytes or xxxx Mbytes
addconvchar ROUT
; R1 current buffer pos
; R12 character count, R2 character limit
; R10 character
CMP R2, R12
RETURNVS LE
ADD R12, R12, #1
STRB R10, [R1], #1
RETURNVC
; In r0 = size in bytes
; r1 -> buffer
; r2 = buffer length
; r12 = 0
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; OS_ConvertDateAndTime
; ---------------------
; Convert from 5-byte cs representation to format specified in <SYS$DateFormat>
; In : R0 -> time block
; R1 -> buffer to accept conversion
; R2 = size of buffer
; R3 -> format string
;
; Out : R0 = input value of R1, or error block
; R1 = updated pointer to buffer
; R2 = updated size of buffer
; V Set if error
StandardDateTime_Code ROUT
Push "R3,R14"
MOV R3, R2 ; Territory SWI wants things one register up
MOV R2, R1
MOV R1, R0
MOV R0, #-1 ; Use configured territory
SWI XTerritory_ConvertStandardDateAndTime
Pull "R3, R14"
B SLVK_TestV
; Out r0 = r1in
; r1 -> terminating zero
; r2 = amount of buffer left
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; OS_ConvertDateAndTime
; ---------------------
; Convert from 5-byte cs representation to format specified by user
; In : R0 -> time block
; R1 -> buffer to accept conversion
; R2 = size of buffer
; R3 -> format string
;
; Out : R0 = input value of R1, or error block
; R1 = updated pointer to buffer
; R2 = updated size of buffer
; V Set if error
DateTime_Code ROUT
Push "R4, R14"
MOV R4, R3 ; Territory SWI wants things one register up.
MOV R3, R2
MOV R2, R1
MOV R1, R0
MOV R0, #-1 ; Use configured territory.
SWI XTerritory_ConvertDateAndTime
Pull "R4, R14"
B SLVK_TestV
FileSizeConversion ROUT
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; OS_ConvertFileSize
; OS_ConvertFixedFileSize
; -----------------------
; Do length as xxxx bytes or xxxx kbytes or xxxx Mbytes
; In : R0 file size in bytes
; R1 pointer to buffer
; R2 max buffer length
; Out : R0 pointer to buffer
; R1 pointer to terminator
; R2 free bytes in buffer
; V Set if buffer overflow
FileSize_Code ROUT
Push "r1, lr"
Push "r4-r7"
SUB sp, sp, #16 ; May need temp frame
MOV r4, #0 ; No char by default
CMP r0, #4096 ; Only go to 'K' format if > 4K
MOVCS r4, #"K" ; Kilo
CMP r0, #4096 ; Only go to 'k' format if > 4k
MOVCS r4, #"k"
MOVCSS r0, r0, LSR #10 ; /1024
ADC r0, r0, #0 ; Round up iff divided and bit fell out
CMP r0, #4096 ; Only go to 'M' format if > 4M
MOVCS r4, #"M" ; Mega
MOVCS r4, #"M"
MOVCSS r0, r0, LSR #10 ; /1024 again
ADC r0, r0, #0 ; Round up iff divided and bit fell out
; No need to go to 'G' format as 2^32 = 4096M!
; No need to go to 'G' format as 2^32 = 4096M!
MOV r5, r0 ; Remember for prettiness
......@@ -383,5 +441,103 @@ FileSizeConversion ROUT
B endconversion
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; OS_ConvertVariform
; ------------------
; Convert some value into some string
; In : R0 pointer to input value (word alignment)
; R1 pointer to buffer
; R2 max buffer length, or -ve to read space required
; R3 bytes to use from input value (or nybbles if hex output reqd)
; R4 type to convert to
; Out : R0 pointer to buffer
; R1 pointer to terminator
; R2 free bytes in buffer, or NOT space required if R2 -ve on entry
; V Set if buffer overflow
Variform_Code ROUT
MOVS r2, r2
MVNMI r2, #0
BMI SLVK
Push "R0, lr"
B endconversion
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; OS_BinaryToDecimal
; ------------------
; Convert int32_t to string SWI (with no terminator)
; prefixed '-' if negative, leading zeros always stripped.
; In : R0 signed 32-bit integer
; R1 pointer to buffer
; R2 max buffer length
; Out : R0, R1 unmodified
; R2 actual chars given
; V Set if buffer overflow
BinaryToDecimal_Code ROUT
Push "R0, R3-R5"
MOV R12, R2 ; Keep buffer length
MOV R2, #0
CMP R0, #0
BPL %FT01
SUBS R12, R12, #1 ; Check enough buffer for '-'
BMI %FT10
MOV R11, #"-"
STRB R11, [R1] ; Place the '-'
MOV R2, #1
RSB R0, R0, #0
; now do digits.
01 RSB R0, R0, #0 ; get negative so minint works.
ADR R3, TenTimesTable
MOV R10, #9 ; max entry 10^9
MOV R4, #0 ; non-0 had flag
02 LDR R11, [R3, R10, LSL #2]
MOV R5, #-1 ; digit value
03 ADDS R0, R0, R11
ADD R5, R5, #1
BLE %BT03
SUB R0, R0, R11
CMP R5, #0
CMPEQ R4, #0
BNE %FT05 ; put digit
04 SUBS R10, R10, #1
BPL %BT02 ; next digit
CMP R4, #0
BEQ %FT05 ; finished, nothing output, must be '0'
Pull "R0, R3-R5"
B SLVK
05 SUBS R12, R12, #1
BMI %FT10 ; naff Exit
ADD R5, R5, #"0"
MOV R4, #-1 ; set flag, a non-zero had
STRB R5, [R1, R2]
ADD R2, R2, #1
B %BT04
10
ADRL R0, BufferOFloError
[ International
Push "lr"