So, there is NO elias-gamma NULL , took me some time to realise that one ...
but it should write the encoding correct in mem, which is actualy just a shift with 8 bytes inside 16 bytes, so why dont i do that?
well, that seems to work now, although 1toooooooo much ...
Code: Select all
; elias_gamma ENCoding
; https://en.wikipedia.org/wiki/Elias_gamma_coding
;
; elias-gamma uses infact BOTH big-endian AND little-endian in 1 answer
; eg 0x49 = %01001001
; 76543210
; > ^ < points to 2^6
; %000000 1 001001 13 bits
; 012345 6 543210
; there is NO elias-gamma NUL ??
;Number Binary γ encoding
;0 = + 0 0 0 ; NOT CALCULATED
;1 = 2^0 + 0 1 1
;2 = 2^1 + 0 10 010
; almost working !
; eliasg_036
; pasmo -d --tapbas --name elias_036 eliasg_036.asm eliasg_036.tap eliasg_036.symbol
setchan equ 0x1601 ; ROM openchannel routine
here equ 40000
org here
exx
push hl
ld a,2
call setchan ; set SCREEN as print channel
call printcr ; set next line
ld de,source
ld hl,encoding
ld bc,endsource-source ; length
do1 call list
ld hl,encoding
ld de,the-encoding ; length
do2 call print
pop hl
exx
ld bc,encoding
ret
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
list push bc
call inve_0
call elias
pop bc
inc de ; next 8 bit value source
inc hl ; next encode field 1 to 15 bits on 16bit
dec bc
ld a,b
or c
ret z
jr list
;+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_
; rewrite off res/set b,(hl) needs pretty much double calculation in exx again
; SET and RES have -0x30 difference in code value
; set 7,(hl) CB FE
; res 7,(hl) CB BE
; set 6,(hl) CB F6
; res 6,(hl) CB B6
; set 5,(hl) CB EE
; res 5,(hl) CB AE
; set 4,(hl) CB E6
; res 4,(hl) CB A6
; set 3,(hl) CB DE
; res 3,(hl) CB 9E
; set 2,(hl) CB D6
; res 2,(hl) CB 96
; set 1,(hl) CB CE
; res 1,(hl) CB 8E
; set 0,(hl) CB C6
; res 0,(hl) CB 86
; the elias-gamma format ; all PRINT routines should protect A by push AF
elias ld a,(de)
and a
push af
ld c,a
call print8
call print__
pop af
jr nz,el1
call printcr
ret z ; if PRINT is excluded the ret Z is needed
el1 ld (hl),1 ; gamma 1st %10000000
m00 ld b,8
count0 rrc (hl)
sla a ; c<7-6543210-<0
jr c,highest
djnz count0
highest ld c,(hl) ; fetch "1"
m01 srl c
call print01 ; print last bits as '0' prelead
jr nc,m01
; printed and stored up to first gamma bit 2^b
ld c,a
ld a,b
exx ; remain7 to remain6 is 0x0a difference in adress
ld hl,remain7
ld b,a ; b>=1
ld a,8
sub b
ld b,a
and a
jr z,setret
ld de,remain6-remain7 ; size of code block to jump over
down add hl,de
djnz down
setret push hl ; jump adres
exx
ret ; (pop hl) is a JUMP from STACK
remain7 sla c ; c< xxxxxxx0
jr nc,remain7b
set 7,(hl) ;
jr remain7c
remain7b res 7,(hl)
remain7c call print01
remain6 sla c ; c< xxxxxx00
jr nc,remain6b
set 6,(hl) ;
jr remain6c
remain6b res 6,(hl)
remain6c call print01
remain5 sla c ; c< xxxxx000
jr nc,remain5b
set 5,(hl) ;
jr remain5c
remain5b res 5,(hl)
remain5c call print01
remain4 sla c ; c< xxxx0000
jr nc,remain4b
set 4,(hl)
jr remain4c
remain4b res 4,(hl)
remain4c call print01
remain3 sla c ; c< xxx00000
jr nc,remain3b
set 3,(hl)
jr remain3c
remain3b res 3,(hl)
remain3c call print01
remain2 sla c ; c< xx000000
jr nc,remain2b
set 2,(hl)
jr remain2c
remain2b res 2,(hl)
remain2c call print01
remain1 sla c ; c< x0000000
jr nc,remain1b
set 1,(hl)
jr remain1c
remain1b res 1,(hl)
remain1c call print01
remain0 sla c ; c< 00000000
jr nc,remain0b
set 0,(hl)
jr remain0c
remain0b res 0,(hl)
remain0c call print01
remained
inc hl ; on bit0=1 encoding needs a next space (8 bit)
ld (hl),c ; last bits dumped on new bit7 and lower
; forcing a constant 16 bit space
call print8
call printcr
ret
;+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_
; print full byte
print8 push bc
ld b,8
bits sla c ; c=7<6543210<0
call print01
djnz bits ; do 8 bits
pop bc
ret
INVE_1 push af
ld a,20 ; INVERSE
rst 16
ld a,1 ; 1 = ON
rst 16
pop af
ret
inve_0 push af
ld a,20 ; INVERSE
rst 16
ld a,0 ; 0 = off
rst 16
pop af
ret
prnotnul push af
ld a,"."
rst 16
pop af
ret
print__ push af
ld a,">"
rst 16
ld a," "
rst 16
pop af
ret
prdot push af
ld a,"."
rst 16
pop af
ret
printcr push af
ld a,13 ; set CR
pr6 rst 16 ; print on next line after 16bit
pop af
ret
; print 0 or 1
print01 push af
ld a,48
jr nc,pr01
inc a ;"1"
pr01 rst 16 ; print
pop af
ret
print ld c,(hl)
call print8
bit 0,l ; hl = 256 aligned, l=0 at start
jr z,nextelias ;
ld a,13 ; set CR
rst 16 ; print on next line after 16bit
nextelias inc hl ; next byte
countdown dec de
ld a,e
or d
jr nz,print
ret
;---------------------------------------------------------
source
defb 0,1,2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,33,44,55,66,77,88,99,111,123,234,240,250,251,252,253,254
endsource equ $
sourcelen equ endsource-source
defw 65535,65535,65535
space equ $
spa equ space/256
sp1 equ spa+1
sp0 equ sp1*256
space2 equ sp0-space
defs space2,0 ; empty block upto 0x..00, must have an easier soltion
encoding ; the result, hopefully
defs sourcelen*2 ,0 ; reserved 0 space
the END here