VERY TIME CONSUMING!!! That's especially true when working on games like Chaos Seed and Slayers. In chaos seed, I had to deal with ( and still need to finish ) codind numerous variable width font routines. And the game still screams at Draken due to the lack of Video RAM space allocated per text / menu box. But I trust we will figure something out...
As for Slayers, the menu system had to be rewritten three times so far. ( why no word for 3 like twice for 2 )
Once for compression using DTE. That was scratched. Then added 2 Line support, but was still limited. Then I decided to use a form of compression, redirection and space filling. I feel good about my efforts but I swear if anyone else wanted to handle such a thing they would have NOT liked it!
Hope you all appreciate our efforts in trying to bring out the best we can achieve with these projects.
I attached the core of Slayers' Variable Width ROutine source code for your viewing pleasure. Maybe some one can learn from it!
Code:
;###########################################;
; Variable width font routine for Slayers ;
; The change affects the main dialogue only ;
; Compiled using Byuu's xKas software. ;
; NOTE: Code inserted Assuming NO HEADER ;
;###########################################;
;##########################
; Variables that exist #
;##########################
!Character = $FFF0
!BitsLeft = $FFF2
!iFlag = $FFF4
!FTable = $FFDE
!BkData = $16
!iLoop = $18
!TextPosi = $0A,x
!TilePosi = $0D,x
!MapPosi = $0E,x
!ScrollTilePosi = $1A,x
!CharFlag = $FFDC
!CharCount = $1C,x
;##########################
; Variables that exist #
;##########################
lorom
;###################################################;
; ;
; ;
; Brand new font routine code ;
; ;
; ;
;###################################################;
main() {
org _NewCodeLocation_
;
_RedirectFontRoutine_:
; 154 BYTES available for new code
;
; Assumes: Y = font index
; X = buffer position for storage
;
rep #$20
;
jsl _CalculateFontIndex_
;----------------------
phb
lda.w #_FontData_
sta.b $1A
sep #$20
lda.b #$7E
pha
plb
;----------------------
lda.b $12,x
bit.b #$40
beq _UseClearBackGround_
;-------------------
rep #$20
lda.w #$0000
bra _StoreColor_
_UseClearBackGround_:
rep #$20
lda.w #$FF00
_StoreColor_:
sta.b !BkData
;-------------------------;
; ;
;-------------------------;
_StandardVWFont_:
;-------------------------;
; Loop and store the data ;
;-------------------------;
sep #$20
lda.w !BitsLeft ; Max pixels per tile is 16
and.b #$0F ; Clear all garbage and use only max tile size ALWAYS!
sta.w !BitsLeft ; replace the "pixels remaining" variable
;--------------------------------------;
; Test to see if buffer needs clearing ;
;--------------------------------------;
lda.w !BitsLeft+1 ; Test this first because it is set
bne _ClearBuffer_ ; when we need to shift data to the left!
lda.w !BitsLeft ; If pixels are left on a tile, do not clear
bne _NoBufferClear_ ; the existing tile data
;---------------
_ClearBuffer_:
jsl _ClearTheBuffer_
;-------------------
_NoBufferClear_:
;
rep #$20
ldx #$0010
stx.b !iLoop
ldx.w #$0000
;-------------------
_StoreTopAndBottom_:
rep #$20
lda [$1A],y
xba
iny
iny
;---------------
phx
;---------------
ldx !BitsLeft+1
bne _ShiftCodeLeft_
;---------------
_ShiftCodeRight_:
;
jsl _ShiftBitsRight_ ; This will shift the character according
bra _DidRightShift_ ; to pixels remaining on the current tile
;---------------
_ShiftCodeLeft_:
;
jsl _ShiftBitsLeft_ ; This will shift the character according
; to pixels left
;----------------------;
; ;
;----------------------;
_DidRightShift_:
sep #$20
plx ; Get X back
; Transfer the adjusted font data to the transfer buffer
;
jsl _StoreFont_
inx
inx
cpx.w #$0010
bne _NoAddYet_
;------------------
rep #$20
txa
clc
adc.w #$0010
tax
sep #$20
;------------------
_NoAddYet_:
;---------------
dec !iLoop
bne _StoreTopAndBottom_
rep #$20
jmp _FinishProcessingText_
;#######################################################;
; ;
; Location of Most font code, New font and Width table ;
; ;
;#######################################################;
org _LocationForCodeProcessing_
;
;#################;
; Fix pixels left ;
;#################;
_FixPixelsLeft_:
; If tile was shifted left give a new BitsLeft
php
phb
;---------------
sep #$20
lda.b #$7E
pha
plb
;--------------
lda.w !BitsLeft+1
beq _SetBitsLeft_
;--------------
rep #$20
lda.w #$0000
sta.w !BitsLeft+1 ; Clear the Left shift flag
;--------------
lda.w $161F
sec
sbc.w #$0020
inc.w !iFlag
;--------------
plb
plp
rtl
;-----------------;
; Set pixels left ;
;-----------------;
_SetBitsLeft_:
lda.w !BitsLeft
bne _PixelsLeftOnTile_
;---------------
lda.b #$10
ldx.w !Character
sec
sbc.l _FontWids_,x
beq _UniversalEnd_
;-----------------
_MultiPurpose_:
sta.w !BitsLeft
;--------------
rep #$20
lda.w $161F
sec
sbc.w #$0020
inc.w !iFlag
;--------------
plb
plp
rtl
;---------------------;
; ;
;---------------------;
_PixelsLeftOnTile_:
; Assumes: Accum = Bits left
;
ldx.w !Character
sec
sbc.l _FontWids_,x
bmi _BitsOverFlowed_
beq _UniversalEnd_
bra _MultiPurpose_
;---------------------;
; ;
;---------------------;
_BitsOverFlowed_:
; Calculate what the new pixels left will
; be for the NEW tile!
;
eor.b #$FF
inc
;--------------
ldx.w !BitsLeft
stx.w !BitsLeft+1 ; We want to do a LEFT shift
; with THIS amount next time
;--------------
sta.w !BitsLeft
lda.b #$10
sec
sbc.w !BitsLeft
;--------------
rep #$20
ldx.b $64
dec !TextPosi ; Go back and get the same character
; but do a LEFT shift instead!
sep #$20
;---------------------;
; Go to Universal End ;
;---------------------;
_UniversalEnd_:
sta.w !BitsLeft
;--------------
rep #$20
lda.w $161F
plb
plp
rtl
;##############################################;
; ;
; Right Bit Shifting Code ;
; ;
;##############################################;
_ShiftBitsRight_:
;
; Assumes X = Index to Shift Table
;
php
phx
rep #$20
pha
lda !BitsLeft
and.w #$000F
bne _ShiftTheData_
;------------------
pla
bra _NoShift_
;------------------
_ShiftTheData_:
dec
asl
tax
pla
jmp (_RShifter_,X)
_RShifter_:
dw _R1,_R2,_R3,_R4,_R5,_R6,_R7,_R8,_R9,_RA,_RB,_RC,_RD,_RE,_RF
;##########################;
; Shift bits to the right ;
;##########################;
_R1:
LSR
_R2:
LSR
_R3:
LSR
_R4:
LSR
_R5:
LSR
_R6:
LSR
_R7:
LSR
_R8:
LSR
_R9:
LSR
_RA:
LSR
_RB:
LSR
_RC:
LSR
_RD:
LSR
_RE:
LSR
_RF:
LSR
;------------;
_NoShift_:
plx
plp
rtl
;##############################################;
; ;
; Left Bit Shifting Code ;
; ;
;##############################################;
_ShiftBitsLeft_:
;
; Assumes X = Index to Shift Table
;
php
phx
rep #$20
pha
lda.w !BitsLeft+1
and.w #$000F
;------------------
_LeftShiftTheData_:
dec
asl
tax
pla
jmp (_LShifter_,X)
_LShifter_:
dw _LF,_LE,_LD,_LC,_LB,_LA,_L9,_L8,_L7,_L6,_L5,_L4,_L3,_L2,_L1
;--------------------;
; Left shifting code ;
;--------------------;
_L1:
ASL
_L2:
ASL
_L3:
ASL
_L4:
ASL
_L5:
ASL
_L6:
ASL
_L7:
ASL
_L8:
ASL
_L9:
ASL
_LA:
ASL
_LB:
ASL
_LC:
ASL
_LD:
ASL
_LE:
ASL
_LF:
ASL
;------------;
_NoLShift_:
plx
plp
rtl
;##########################;
; ;
;##########################;
_StoreFont_:
;
php
rep #$20
pha
;----------------
and.w #$00FF
ora.l $7E2810,x ; Right side
ora.b !BkData
sta.l $7E2810,x ; Right side
pla
xba
and.w #$00FF
ora.l $7E2800,x ; Right side
ora.b !BkData
sta.l $7E2800,x ; Left side
;----------------
plp
rtl
;##########################;
; ;
;##########################;
_ClearTheBuffer_:
php
phb
phy
phx
;---------------
rep #$20
lda.b !BkData
sta.l $7E2800
ldx.w #$2800
ldy.w #$2802
lda.w #$003D
mvn $7E7E
;---------------
plx
ply
plb
plp
rtl
;##########################;
; ;
;##########################;
_CalculateFontIndex_:
pha
;
clc
adc !FTable+$7E0000
sta !Character+$7E0000 ; How we access a different font table's width data
;----------------------
; Shift for NEW 16x16 font
lda !FTable+$7E0000 ; Accessing a different font table??
rep 4 : asl ; left shift 4 times
pha
;
lda $03,s
asl
asl
asl
asl
asl
clc
adc $01,s
tay
pla
pla
rtl
;-------------------------------;
; Where the font data is stored ;
;-------------------------------;
_FontData_:
; Font file found here
_FontWids_:
; Width file found here
}