conversion to hexadecimal format

131 views
Skip to first unread message

Bob

unread,
Apr 14, 2023, 7:56:07 AM4/14/23
to RC2014-Z80
Hi everyone,
using SCM 1.0.0 monitor, I'm looking for a function call to convert a binary value in hexadecimal format to be sent to the terminal.
For example: with a value of $FF in the A register, I want to print "FF" on the terminal. I couldn't find any documented function call for this.
I assume there must be a routine somewhere in SCM to do that because SCM can display such format when listing memory content.


Steve Cousins

unread,
Apr 14, 2023, 9:32:41 AM4/14/23
to RC2014-Z80
Hi Bob,

There is indeed a function in SCM to do that but unfortunately it is not available as an API call.

I'm sure there are examples on the net to do that but if you want to use the code from SCM you can download the source. You will need to look at the files Strings.asm and Utilities.asm in SCWorkshop\SCMonitor\Source\Monitor.

Steve

Derek Cooper

unread,
Apr 14, 2023, 10:48:25 AM4/14/23
to RC2014-Z80
This simple example prints the hex value of keys pressed on the terminal, terminates with the return key. Not very well written, but it is one of my first z80 programs for 35 years!

The phex routene does as you ask, but in cpm.

A>type keyval.z80
;
bdos    equ     5
                org     0100h
;
                ld      de,str
                ld      c,9
                call    bdos
wait            ld      c,6
                ld      e,0ffh
                call    bdos
                or      a
                jr      z,wait
                cp      13
                ret     z
                call    phex
                ld      de,crlf
                ld      c,9
                call    bdos
                jr      wait
phex            ld      c,a
                rra
                rra
                rra
                rra
                call    phex2
                ld      a,c
phex2           and     0fh
                add     a,090h
                daa
                adc     a,040h
                daa
                push    bc
                ld      c,2
                ld      e,a
                call    bdos
                pop     bc
                ret
;              
str     db      'Press a key to see it',027h,'s hex value CR to exit'
crlf    db      0ah,0dh,'$'

Bob

unread,
Apr 14, 2023, 10:57:32 AM4/14/23
to rc201...@googlegroups.com
Thank you Steve,

I will peek into these files surely. Yes I know it can be done with a bunch of AND's, OR's and shifts. Just lazy :)
Ron

--
You received this message because you are subscribed to a topic in the Google Groups "RC2014-Z80" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rc2014-z80/geZUHHR-pKg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rc2014-z80+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rc2014-z80/bc136515-d189-4ed2-8369-084bc3225e81n%40googlegroups.com.

Bob

unread,
Apr 14, 2023, 11:03:21 AM4/14/23
to rc201...@googlegroups.com
I will take a look at your code. This will give me an idea how to do the ANDing's, ORing's and SHIFTing's. I've done this with the 6502 and the 1802 but I don't have much experience with the z80. Time to learn. Steve also proposed to take a look at the assembly files of SCM.


--
You received this message because you are subscribed to a topic in the Google Groups "RC2014-Z80" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rc2014-z80/geZUHHR-pKg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rc2014-z80+...@googlegroups.com.

Bob

unread,
Apr 14, 2023, 11:22:39 AM4/14/23
to rc201...@googlegroups.com
Well,

I just tried the"phex" routine, just changed the call to output a character, and it works fine. This could be useful if some else is looking for a solution to this.
I will still dig in the SCM assembly files to locate the code doing the same thing.

phex:  ld      c,a
        rra
        rra
        rra
        rra
        call    phex2
        ld      a,c
phex2:  and     0fh
        add     a,090h
        daa
        adc     a,040h
        daa
        push    bc
       
        ld c, $02     ; call to SCM API $02 (output character)
        rst API
        pop     bc
        ret

On Fri, Apr 14, 2023 at 10:48 AM Derek Cooper <derek.coo...@gmail.com> wrote:

Phil G

unread,
Apr 15, 2023, 5:09:11 AM4/15/23
to RC2014-Z80
I first saw the "ADI $90, DAA, ACI $40, DAA"  hex-to-ascii trick in the TDL Zapple source in 1977  :-)     (TDL mnemonics)
Reply all
Reply to author
Forward
0 new messages