mirror of
https://github.com/irmen/prog8.git
synced 2025-02-25 04:29:36 +00:00
vm: fixed abs() and word-to-string conversion
This commit is contained in:
parent
5037033fcf
commit
4e863ecdac
@ -106,19 +106,21 @@ sub str_uwhex (uword value) {
|
|||||||
|
|
||||||
sub str_uw0 (uword value) {
|
sub str_uw0 (uword value) {
|
||||||
; ---- convert the uword in A/Y in decimal string form, with left padding 0s (5 positions total)
|
; ---- convert the uword in A/Y in decimal string form, with left padding 0s (5 positions total)
|
||||||
ubyte tenthousands = (value / 10000) as ubyte
|
uword value2 = value/10
|
||||||
value -= 10000*tenthousands
|
ubyte digits = value-value2*10 as ubyte
|
||||||
ubyte thousands = (value / 1000) as ubyte
|
uword value3 = value2/10
|
||||||
value -= 1000*thousands
|
ubyte tens = value2-value3*10 as ubyte
|
||||||
ubyte hundreds = (value / 100) as ubyte
|
uword value4 = value3/10
|
||||||
value -= 100 as uword * hundreds
|
ubyte hundreds = value3-value4*10 as ubyte
|
||||||
ubyte tens = (value / 10) as ubyte
|
uword value5 = value4/10
|
||||||
value -= 10*tens
|
ubyte thousands = value4-value5*10 as ubyte
|
||||||
|
uword value6 = value5/10
|
||||||
|
ubyte tenthousands = value5-value6*10 as ubyte
|
||||||
string_out[0] = tenthousands+'0'
|
string_out[0] = tenthousands+'0'
|
||||||
string_out[1] = thousands+'0'
|
string_out[1] = thousands+'0'
|
||||||
string_out[2] = hundreds+'0'
|
string_out[2] = hundreds+'0'
|
||||||
string_out[3] = tens+'0'
|
string_out[3] = tens+'0'
|
||||||
string_out[4] = value as ubyte + '0'
|
string_out[4] = digits+'0'
|
||||||
string_out[5] = 0
|
string_out[5] = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,14 +141,16 @@ sub str_w (word value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub internal_str_uw(uword value, uword out_ptr) {
|
sub internal_str_uw(uword value, uword out_ptr) {
|
||||||
ubyte tenthousands = (value / 10000) as ubyte
|
uword value2 = value/10
|
||||||
value -= 10000*tenthousands
|
ubyte digits = value-value2*10 as ubyte
|
||||||
ubyte thousands = (value / 1000) as ubyte
|
uword value3 = value2/10
|
||||||
value -= 1000*thousands
|
ubyte tens = value2-value3*10 as ubyte
|
||||||
ubyte hundreds = (value / 100) as ubyte
|
uword value4 = value3/10
|
||||||
value -= 100 as uword * hundreds
|
ubyte hundreds = value3-value4*10 as ubyte
|
||||||
ubyte tens = (value / 10) as ubyte
|
uword value5 = value4/10
|
||||||
value -= 10*tens
|
ubyte thousands = value4-value5*10 as ubyte
|
||||||
|
uword value6 = value5/10
|
||||||
|
ubyte tenthousands = value5-value6*10 as ubyte
|
||||||
if tenthousands
|
if tenthousands
|
||||||
goto output_tenthousands
|
goto output_tenthousands
|
||||||
if thousands
|
if thousands
|
||||||
@ -169,7 +173,7 @@ output_tens:
|
|||||||
@(out_ptr) = tens+'0'
|
@(out_ptr) = tens+'0'
|
||||||
out_ptr++
|
out_ptr++
|
||||||
output_ones:
|
output_ones:
|
||||||
@(out_ptr) = value as ubyte + '0'
|
@(out_ptr) = digits+'0'
|
||||||
out_ptr++
|
out_ptr++
|
||||||
@(out_ptr) = 0
|
@(out_ptr) = 0
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
- fix VM print_w
|
|
||||||
- fix VM abs(byte) it always returns 0 also check abs(word)
|
|
||||||
- IR: instructions that do type conversion (SZ etc, CONCAT, SGN) should put the result in a DIFFERENT register.
|
- IR: instructions that do type conversion (SZ etc, CONCAT, SGN) should put the result in a DIFFERENT register.
|
||||||
|
|
||||||
...
|
...
|
||||||
|
@ -3,14 +3,7 @@
|
|||||||
%option no_sysinit
|
%option no_sysinit
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub set_color(ubyte dummy, uword arg) {
|
|
||||||
arg++
|
|
||||||
}
|
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte intens
|
|
||||||
set_color(0, (intens >> 1) * $111)
|
|
||||||
|
|
||||||
byte intensity = -25
|
byte intensity = -25
|
||||||
txt.print_b(intensity)
|
txt.print_b(intensity)
|
||||||
txt.nl()
|
txt.nl()
|
||||||
@ -19,9 +12,10 @@ main {
|
|||||||
txt.nl()
|
txt.nl()
|
||||||
txt.print_b(intensity)
|
txt.print_b(intensity)
|
||||||
txt.nl()
|
txt.nl()
|
||||||
word intensityw = 2555
|
|
||||||
txt.print_uw0(12345)
|
txt.print_uw0(12345)
|
||||||
txt.nl()
|
txt.nl()
|
||||||
|
word intensityw = -12345
|
||||||
txt.print_w(intensityw)
|
txt.print_w(intensityw)
|
||||||
txt.nl()
|
txt.nl()
|
||||||
txt.print_w(abs(intensityw))
|
txt.print_w(abs(intensityw))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user