implement print_ulhex(long, prefix)

This commit is contained in:
Irmen de Jong
2025-09-20 03:45:31 +02:00
parent b058f1c7c2
commit 557b12668d
5 changed files with 66 additions and 1 deletions

View File

@@ -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 {{

View File

@@ -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 {{

View File

@@ -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

View File

@@ -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))

View File

@@ -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]