Listing? = 1  

; revision from https://board.flatassembler.net/topic.php?p=191017#191017
; https://board.flatassembler.net/topic.php?t=19190
namespace Listing 
        base = $$  
        offset = $ 
        virtual at 0 
                HexDigits:: db '0123456789ABCDEF' 
        end virtual 
        macro disphex number*,digits:8 
                repeat digits  
                        load digit:byte from HexDigits:((number) shr ((%%-%) shl 2)) and 0Fh
                        display digit 
                end repeat 
        end macro  
end namespace

macro nolist?  
end macro  

macro list?  
end macro  

macro ? line&  
        line  
        match =nolist?, line  
                Listing? =: 0  
        else match =list?, line  
                restore Listing?  
        else  
                if Listing  
                        namespace Listing  
                                if ~ $$ eq base  
                                        base = $$  
                                        offset = $$  
                                end if  
                                bytes = $ - offset  
                                if $ - bytes < $$  
                                        bytes = $ - $$  
                                end if  
                                offset = $  
                                disphex (offset scale 0)-bytes,8  
                                display ': '  
                                column = 0  
                                while bytes > 0  
                                        if column = 8  
                                                column = 0  
                                                display 13,10,'          '  
                                        end if  
                                        load data:byte from $ - bytes  
                                        disphex data,2  
                                        display ' '  
                                        bytes = bytes - 1  
                                        column = column + 1  
                                end while  
                                repeat 8-column  
                                        display '   '  
                                end repeat  
                                display `line,13,10  
                        end namespace  
                end if  
        end match  
end macro