;=======================================;
;Title: DBZ: Assault of the Saiyans ;
;TTE Routine and Implementation ;
;=======================================;
;This code is located in Bank $00. This ;
;more or less replaces the original code;
;for the Japanese dakuten/handakuten ;
;characters. Set up for code at $D7F0 ;
;can be found in dbz1_dte_prep.asm ;
;=======================================;
.org $bb00
.mem 8
.index 8
dte_routine:
cmp #$90 ;Since the current character to read is already in the
bcc end_of_dte ;accumulator we don't need to load it again. First
clc ;test the character is within the range of the TTE values.
cmp #$df ;If so we'll move onto the actually decompression, otherwise
beq run_check ;we'll branch to end_of_dte and store the character in RAM.
bcs end_of_dte ;Note: Since there isn't anyway to accomplish a A > Mem
;comparison, we've used a beq to allow for the last TTE entry
;to be processed.
run_check:
stx $06fe ;Preserve the current value of X by storing it in unused RAM.
sec
sbc #$90 ;Subtract the start value of the TTE values to use as a base
clc ;for determining the TTE number.
sta $06fc ;Will be used later.
ldx $06fd ;Load X with the test byte.
beq first_run ;If X = 0, we want the first character.
bne second_run ;Otherwise, we want the second character or third character.
first_run:
ldx #$01 ;Load X with 1 so we can get the second character next time.
dec $50 ;Decrement the load index. This way the same character will
;be read AGAIN, but we'll store a value of 1 at $06fd so that
;the code for the second letter of the trio will be executed
;the next go through.
asl a ;Double the accumulator and add the load index offset-thing
clc ;to get the trio.
adc $06fc
jmp dte_char_load
second_run:
cpx #$02 ;If the test byte = 2, then we're on the third character
beq third_run ;of the trio.
ldx #$02 ;Load X with 2 so we can get the third character next time.
dec $50 ;Decrement the load index once again so we get the third
;character next time.
asl a ;Double the accumulator to determine the TTE number.
clc
adc #$01 ;Add 1 to the accumulator and the index offset thing so that
adc $06fc ;we get the second character of the TTE set.
jmp dte_char_load
third_run:
asl a ;Double the accumulator to determine the trio number.
clc
adc #$02 ;Add 2 and the index thing so that we get the third character.
adc $06fc
ldx #$00 ;Reset X so we get the right results next time we encounter a TTE
;byte.
stx $06fc ;Reset the temp index offset holder thing.
dte_char_load:
stx $06fd ;Store test byte.
tax ;Transfer A to X for the TTE table lookup.
lda dte_table,x ;Load the accumulator with the character from the dte to be
;displayed.
ldx $06fe ;Restore X.
end_of_dte:
sta $0605,x ;Before returning to the text read routine, store the tile
;in RAM where it will be loaded from into VRAM later.
lda #$01 ;Store a space character for what originally was the
sta $0604,x ;dakuten, handakuten character. This really isn't necessary,
;but I've included it as a fail-safe of sorts.
rts ;Jump back to the end of the DTE Prep routine, and restore
;the banks before returning to the text read routine.
dte_table:
.dsl 79 ;Build an empty table of 79 ($4F) entries for the DTE look-up
;table.
(That was written to be compatible with x816.)
No nasty multiplication required (aside from the asl, of course), and it worked perfectly. I ended up ditching this in favor for a huffman compression scheme, as I couldn’t get the compression I wanted. Glad to see you’re getting the hang of it. 