Test z80 syntax

testing syntax highlighting

ORG &8000

start:
    LD HL, &C000        ; Video RAM start
    LD BC, 256          ; Counter
loop:
    LD (HL), &AA        ; Write pattern
    INC HL
    DEC BC
    JP NZ, loop
    RET
;;
;; This program demonstrates converting the number in HL to
;; ASCII and outputing it.
;;

; Set HL to 0xffff
ld hl, 0
dec hl

; Display the value
call DispHLhex
halt

;
; Display a 16- or 8-bit number in hex.
; The value to be shown should be stored in HL
;
DispHLhex:

; show "0x" as a prefix
ld a, '0'
out(1),a
ld a, 'x'
out(1),a

; Show the high-value
ld  c,h
call  OutHex8

; Show the low-value
ld  c,l
call OutHex8

; Return to our caller
ret

;
; Output the hex value of the 8-bit number stored in C
;
OutHex8:
ld  a,c
rra
rra
rra
rra
call  Conv
ld  a,c
Conv:
and  $0F
add  a,$90
daa
adc  a,$40
daa
; Show the value.
out (1),a
ret

Nice, will be helpful.

Yeah, looks nice. Not sure if it’s complete, but at least obviously I got something right - I had to create and define the highlight rules by hand

Ok, so maybe we will need to have a look for completion and adding information (registers / labels / values)…

Can you share how you do it so we can help?

Yeah, sure.

Discourse uses components -basically, background scripts- that attach to Themes (hence some functoinality can work on one theme and not on another).

Syntax highlighters intercept raw text before rendering, injecting CSS.

Now there’s an ambiguity on how precisely a custom highlighter works: the z80 is not part of the core group of languages the forum supports hence it can’t be chosen when you quote code; supposedly the code block should begin with " ```z80" (two spaces, three backticks), but I’ve seen it work without that declaration? Really not sure about this one.

Anyhow, here’s the addition to the forum code:

EDIT: on second thought, if you wanna take a look I can send it to you, better not have it up for security reasons.

Strange that RRA and DAA aren’t highlighted in your sample… They are part of your keywords. Or maybe you just copy/paste result in your message? That would explain.

To fully integrate z80 language, I found this link: Configure which programming languages are available for syntax highlighting - Site Management - Discourse Meta

And google gemini proposed this for highlightjs z80:

const z80Language = function(hljs) {
return {
name: ‘z80’,
aliases: [‘z80asm’],
case_insensitive: true,
keywords: {
$pattern: ‘[a-zA-Z_][a-zA-Z0-9_]*’,
keyword: 'ld adc add and bit call ccf cp cpd cpdr cpi cpir cpl daa dec di djnz ei ex ’ +
‘exx halt im in ind indr ini inir jp jr ld ldd lddr ldi ldir neg nop or ’ +
‘otdr otir out outd outi pop push res ret reti retn rl rla rlc rlca rld ’ +
‘rr rra rrc rrca rrd rst sbc scf set sla sll sra srl sub xor’,
built_in: ‘a b c d e h l i r ix iy af bc de hl sp ixh ixl iyh iyl’ },
contains: [
hljs.COMMENT(’;’, ‘$’), // Commentaires commençant par un point-virgule
hljs.C_NUMBER_MODE, // Nombres standards
{
className: ‘number’,
begin: ‘\\b[0-9a-fA-F]+h\\b’ // Support du format hexadécimal “0ffh”
},
{
className: ‘symbol’,
begin: ‘^[a-zA-Z_][a-zA-Z0-9_]*:’ // Détection des labels (ex: LOOP:) },
hljs.QUOTE_STRING_MODE // Chaînes de caractères ]
};
};

Got it before it disappears :grin:

Yeah, I’m stuck as to the RRA and DDA instances not being highlighted. I’m thinking they should, but…

Will take a look at your patterns, thanks.

Maybe it is using x86asm instead of z80… That may explain why it works without the ‘’'z80

Ah yes could be - though I think I did see it labelling it ‘z80’ upon editing. Go figure ¯\_(ツ)_/¯

Just posted some z80 code-snippets and noticed that the available syntax highlighters do not include Zilog/Z80 assembly language. I ultimately selected avrasm from the available options, as it seems to be close enough, but not all instructions were accurately highlighted, pretty much like in your test-snippet above.

Link?

Ok will take a look when I’m done with the BASIC and firmware hover cards. I didn’t try it any more after the initial push but I know more about the inner workings of the forum now do maybe I’ll be able to do something.