33 lines
1021 B
Plaintext
33 lines
1021 B
Plaintext
// Main program for testing the function
|
|
//
|
|
do {
|
|
#1 = Get_Num("Number to convert: ", STATLINE)
|
|
Call("NUM_TO_ROMAN")
|
|
Num_Type(#1, NOCR) Message(" = ") Reg_Type(1) Type_Newline
|
|
} while (Reg_Size(1))
|
|
Return
|
|
|
|
// Convert numeric value into Roman number
|
|
// #1 = number to convert; on return: T-reg(1) = Roman number
|
|
//
|
|
:NUM_TO_ROMAN:
|
|
Reg_Empty(1) // @1 = Results (Roman number)
|
|
if (#1 < 1) { Return } // non-positive numbers return empty string
|
|
|
|
Buf_Switch(Buf_Free)
|
|
Ins_Text("M1000,CM900,D500,CD400,C100,XC90,L50,XL40,X10,IX9,V5,IV4,I1")
|
|
|
|
BOF
|
|
#2 = #1
|
|
Repeat(ALL) {
|
|
Search("|A|[|A]", ADVANCE+ERRBREAK) // get next item from conversion list
|
|
Reg_Copy_Block(20, CP-Chars_Matched, CP) // @20 = Letter(s) to be inserted
|
|
#11 = Num_Eval() // #11 = magnitude (1000...1)
|
|
while (#2 >= #11) {
|
|
Reg_Set(1, @20, APPEND)
|
|
#2 -= #11
|
|
}
|
|
}
|
|
Buf_Quit(OK)
|
|
Return
|