Re: Fast GCR decoding?

From: Michał Pleban <lists_at_michau.name>
Date: Wed, 16 Jan 2013 10:21:20 +0100
Message-ID: <50F67110.20808@michau.name>
Hello!

After some private discussion and a night of thinking, this morning I
wrote the code that decodes GCR on the fly ;-) Decoding 5 GCR bytes into
4 output bytes takes me 112 cycles, including storing the bytes with STA
(output), Y + INY. This does not, however, include BVC / CLV
instructions for reading from VIA, as the code should rather be run on
the computer (it requires nearly 10 kB of tables).

The code is self modifying for fastest execution, so it must reside in
RAM. The basic idea is that when we read a GCR byte, we parse it through
two decoding tables. One decodes a nibble directly, and the other one
selects a decoding table to be used for the remaining nibble, when the
next GCR byte is read. Sounds complicated, but the code is actually
pretty simple (at the cost of 38 decoding tables).

Oh, I just realized that if the code was stored in the zero page, we
could save 4 more cycles (though I don't know if it were practical):

; Read GCR byte 0
ldx input

lda table_1_x, x	; 1 intermediary table
sta addr1+2
lda table_0_0, x	; 1 decoding table

; 4+4+4+4 = 16

; Read GCR byte 1
ldx input

addr1:
ora table_1_0, x	; 8 decoding tables
sta (output), y
iny
lda table_3_x, x	; 1 intermediary table
sta addr3+2
lda table_2_0, x	; 1 decoding table

; 4+4+5+2+4+4+4 = 27

; Read GCR byte 2
ldx input

addr3:
ora table_3_0, x	; 2 decoding tables
sta (output), y
iny
lda table_4_x, x	; 1 intermediary table
sta addr4+2

; 4+4+5+2+4+4 = 23

; Read GCR byte 3
ldx input

addr4:
lda table_4_0, x	; 16 decoding tables
ora table_5_0, x	; 1 decoding table
sta (output), y
iny
lda table_6_x, x	; 1 intermediary table
sta addr6+2

; 4+4+4+5+2+4+4 = 27

; Read GCR byte 4
ldx input

addr6:
lda table_6_0, x	; 4 decoding tables
ora table_7_0, x	; 1 decoding table
sta (output), y
iny

; 4+4+4+5+2 = 19

; Total = 112 cycles
; Data = 38 tables (9.5 kB)

Regards,
Michau.

       Message was sent through the cbm-hackers mailing list
Received on 2013-01-16 10:00:03

Archive generated by hypermail 2.2.0.