On 28.10.2008 19:58 in vtech-hex-ebcdic Mendel Deren wrote:
>
> I want to write a Hex file based on numbers stored in Numeric
> registers.
>
> e.g. If Reg#25 contains the number 255 and Reg#26 contains the number
> 0,I want to create a Hex file that will read "FF OO." without any
> other bytes.
>
> i.e in bitwise mode I will only see two bytes.
>
>
> Also, can you tell me how to do the above if the numbers in the
> numeric registers are greater than 255 and I don't want to write more
> bytes than necessary for a number for example for numbers between 0
> 255 I would write one byte and between 256 and 65535 I would write
> two bytes etc.
For values lower than 256 it's easy. You can use Ins_Char().
For higher values it depends.
The following macro may be used as possible starting point.
//
// Write a binary file out of a block of numeric registers
//
// (Quick'n'dirty)
//
#104=10 // the first register
#105=20 // the last register
for (#103=#104 ; #103<=#105 ; #103++) { // loop through registers
#106=#@103 // get content of current numeric register
if (#106 < 256) { // if it's only one byte
Ins_Char(#106) // write it directly
} else { // otherwise divide it into several bytes...
// This algorithm may not the best one,
// but it works...
Out_Reg(103)
Num_Type(#106, HEX+NOMSG+NOCR) // write value as hex to t-reg 103
Out_Reg(CLEAR)
#107=Reg_Size(103) // get the # of hex digits of it
for (#108=0 ; #108<#107 ; #108+=2) { // loop through digits pairs
Reg_Set(104, "0x") // prepare a "hex" reg
Out_Reg(104, APPEND) // and append
Reg_Type_Block(103, #108, #108+2) // two hex digits (one byte)
Out_Reg(CLEAR) // to it
#109=Num_Eval_Reg(104) // evaluate dec value of byte
Ins_Char(#109) // insert it into the file
}
}
}
Christian