diff --git a/compiler/res/prog8lib/conv.p8 b/compiler/res/prog8lib/conv.p8 index 15a395dbc..ad518fe26 100644 --- a/compiler/res/prog8lib/conv.p8 +++ b/compiler/res/prog8lib/conv.p8 @@ -155,6 +155,30 @@ asmsub str_uwhex (uword value @ AY) -> str @AY { }} } +sub str_ulhex(long value) -> str { + %asm {{ + lda value+3 + jsr internal_ubyte2hex + sta string_out + sty string_out+1 + lda value+2 + jsr internal_ubyte2hex + sta string_out+2 + sty string_out+3 + lda value+1 + jsr internal_ubyte2hex + sta string_out+4 + sty string_out+5 + lda value + jsr internal_ubyte2hex + sta string_out+6 + sty string_out+7 + lda #0 + sta string_out+8 + }} + return &string_out +} + asmsub str_uw0 (uword value @ AY) clobbers(X) -> str @AY { ; ---- convert the uword in A/Y in decimal string form, with left padding 0s (5 positions total) %asm {{ diff --git a/compiler/res/prog8lib/shared_cbm_textio_functions.p8 b/compiler/res/prog8lib/shared_cbm_textio_functions.p8 index 25a000100..8ae93d73c 100644 --- a/compiler/res/prog8lib/shared_cbm_textio_functions.p8 +++ b/compiler/res/prog8lib/shared_cbm_textio_functions.p8 @@ -109,6 +109,12 @@ txt { }} } + sub print_ulhex(long value, bool prefix) { + if prefix + cbm.CHROUT('$') + print(conv.str_ulhex(value)) + } + asmsub print_uw0 (uword value @ AY) clobbers(A,X,Y) { ; ---- print the uword in A/Y in decimal form, with left padding 0s (5 positions total) %asm {{ diff --git a/compiler/res/prog8lib/virtual/conv.p8 b/compiler/res/prog8lib/virtual/conv.p8 index 81435ff75..39d32d46a 100644 --- a/compiler/res/prog8lib/virtual/conv.p8 +++ b/compiler/res/prog8lib/virtual/conv.p8 @@ -102,7 +102,7 @@ sub str_uwbin (uword value) -> str { } sub str_uwhex (uword value) -> str { - ; ---- convert the uword in A/Y in hexadecimal string form (4 digits) + ; ---- convert the uword in hexadecimal string form (4 digits) ubyte bits = msb(value) string_out[0] = hex_digits[bits>>4] string_out[1] = hex_digits[bits&15] @@ -113,6 +113,26 @@ sub str_uwhex (uword value) -> str { return string_out } +sub str_ulhex (long value) -> str { + ; ---- convert the long in hexadecimal string form (8 digits) + uword upperw = msw(value) + uword lowerw = lsw(value) + ubyte bits = msb(upperw) + string_out[0] = hex_digits[bits>>4] + string_out[1] = hex_digits[bits&15] + bits = lsb(upperw) + string_out[2] = hex_digits[bits>>4] + string_out[3] = hex_digits[bits&15] + bits = msb(lowerw) + string_out[4] = hex_digits[bits>>4] + string_out[5] = hex_digits[bits&15] + bits = lsb(lowerw) + string_out[6] = hex_digits[bits>>4] + string_out[7] = hex_digits[bits&15] + string_out[8] = 0 + return string_out +} + sub str_uw0 (uword value) -> str { ; ---- convert the uword in A/Y in decimal string form, with left padding 0s (5 positions total) uword value2 = value/10 diff --git a/compiler/res/prog8lib/virtual/textio.p8 b/compiler/res/prog8lib/virtual/textio.p8 index 2d7473d75..7d8ea3574 100644 --- a/compiler/res/prog8lib/virtual/textio.p8 +++ b/compiler/res/prog8lib/virtual/textio.p8 @@ -136,6 +136,13 @@ sub print_uwhex (uword value, bool prefix) { print(conv.str_uwhex(value)) } +sub print_ulhex (long value, bool prefix) { + ; ---- print the ulong in hexadecimal form (4 digits) + if prefix + chrout('$') + print(conv.str_ulhex(value)) +} + sub print_uw0 (uword value) { ; ---- print the uword value in decimal form, with left padding 0s (5 positions total) print(conv.str_uw0(value)) diff --git a/examples/test.p8 b/examples/test.p8 index 29a4c7471..c9d8f66a8 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -16,7 +16,11 @@ main { sub start() { txt.print_l(mklong2($a000,$bbbb)) txt.spc() + txt.print_ulhex(mklong2($a000,$bbbb), true) + txt.spc() txt.print_l(mklong(9,8,7,6)) + txt.spc() + txt.print_ulhex(mklong(9,8,7,6), true) txt.nl() cx16.r8 = $a000 cx16.r9 = $bbbb @@ -26,7 +30,11 @@ main { cx16.r5L = 6 txt.print_l(mklong2(cx16.r8, cx16.r9)) txt.spc() + txt.print_ulhex(mklong2(cx16.r8, cx16.r9), true) + txt.spc() txt.print_l(mklong(cx16.r2L,cx16.r3L,cx16.r4L,cx16.r5L)) + txt.spc() + txt.print_ulhex(mklong(cx16.r2L,cx16.r3L,cx16.r4L,cx16.r5L), true) txt.nl() ; long[] array = [-1999888777, -999, 42, 0, 77, 123456, 999999999]