Post useful z80 routines here that are specific to the CSE! I'd imagine that for the most part it'd be related to LCD and image things. If your routine isn't specific to the CSE you may want to post it here instead.
Monospace Font Renderer
Code for a custom monospace font renderer. Has a routine to render a null terminated string, as well as a single character. Output locations and colors are stored in ram and auto incremented, similar to the OS routines.
The code expects your text data to be in the TI encoding.
Here's a link to the font image I'm using with it. It's 7x11, loosely based on the monochrome calculator TI fonts. http://i.imgur.com/a6yhdgR.png
Code:
Monospace Font Renderer
Code for a custom monospace font renderer. Has a routine to render a null terminated string, as well as a single character. Output locations and colors are stored in ram and auto incremented, similar to the OS routines.
The code expects your text data to be in the TI encoding.
Here's a link to the font image I'm using with it. It's 7x11, loosely based on the monochrome calculator TI fonts. http://i.imgur.com/a6yhdgR.png
Code:
.module fontRendering
;Font rendering routine, written for BRASS and the ti84pcse inc file included with DCSE
;In the font bitmap, include [ and $ at the end. These are special cases
;_FONT_WIDTH / 8 * _FONT_HEIGHT must not be larger than 256
_FONT_WIDTH = 8
_FONT_HEIGHT = 11
_FONT_MULT_HE = MultHE_2 ;Set this to a routine that multiplies H and E, and outputs to HL
_FONT_CHAR_SIZE_BYTES = (_FONT_WIDTH / 8) * _FONT_HEIGHT
;Ram addresses to store font X/Y, and font colors
;X should be 2 bytes, Y should be 1
;fontFG and fontBG should both be 2 bytes. Color should
;be stored in them little endian
fontX = 8782h ;OS variable-width font column
fontY = 8784h ;OS variable-width font row
fontFG = A038h ;OS variable-width font foreground
fontBG = A036h ;OS variable-width font background
;Define this if you want the background to be transparent
;instead of using fontBG
;.define TRANSPARENT_BACKGROUND
;Input:
;hl = Pointer to null terminated string
;Output:
;hl = Pointer to the byte after the termination
;Destroys: all but hl
DrawString:
ld a,(hl)
inc hl
or a
ret z
push hl
call DrawChar
pop hl
jr DrawString
;Input:
;a = Character to draw
;Output:
;fontX = fontX + 8
;Destroys: all
DrawChar:
sub 20h ;Only support ' ' to '~' in the TI charset
cp '[' - 20h
jr nz,{@}
ld a,95
jr {2@}
@:
cp '$' - 20h
jr nz,{@}
ld a,96
@:
ld h,a
ld e,_FONT_CHAR_SIZE_BYTES
call _FONT_MULT_HE
ld de,_FONT_IMG
add hl,de ;HL now has the address of the character
push hl
ld hl,(fontX)
ld a,(fontY)
ld e,a
ld bc,0011h
;Window Left/X/Right
ld a,lrWinLeft
out (10h),a
out (10h),a
out (c),h
out (c),l
ld a,lrCol
out (10h),a
out (10h),a
out (c),h
out (c),l
ld a,lrWinRight
out (10h),a
out (10h),a
ld a,_FONT_WIDTH - 1
add a,l
ld l,a
jr nc,{@}
inc h
@:
out (c),h
out (c),l
inc hl
ld (fontX),hl ;Save new column
;Window Top/Y/Bottom
ld a,lrWinTop
out (10h),a
out (10h),a
out (c),b
out (c),e
ld a,lrRow
out (10h),a
out (10h),a
out (c),b
out (c),e
ld a,lrWinBottom
out (10h),a
out (10h),a
ld a,_FONT_HEIGHT - 1
add a,e
out (c),b
out (11h),a
ld a,lrGram
out (10h),a
out (10h),a
pop ix ;Data loc in ix
ld hl,(fontFG)
.ifndef TRANSPARENT_BACKGROUND
ld de,(fontBG)
.endif
ld b,_FONT_CHAR_SIZE_BYTES
_fontCharFill:
push bc
ld bc,0811h ;08 for 8 iterations, 11h for the output port
ld a,(ix)
inc ix
_fontByteFill:
rla
jr c,_fontFillBG
_fontFillFG:
out (c),h
out (c),l
djnz _fontByteFill
jr {@}
_fontFillBG:
.ifdef TRANSPARENT_BACKGROUND
;Dummy read, followed by real read
in d,(c)
in e,(c)
in d,(c)
in e,(c)
.endif
out (c),d
out (c),e
djnz _fontByteFill
@:
pop bc
djnz _fontCharFill
ret
;Include a monochrome font file.
;The image should be _FONT_WIDTH pixels wide, and _FONT_HEIGHT * 97 pixels high if you use .incbmp like this.
;But, as long as the resulting data is a series of bytes for the pixel data
;for each character, it does not really matter what you do
;
;As for the order of the characters: You can use this as a referrence tibasicdev.wikidot.com/83lgfont
;Start at 20h, so 20h (empty space) is the first character in your data.
;Then, end at 7Eh. After that add [ and $ as the final 2 characters. These are special
;cases since they are way off into the TI font, and they are handled specially in the code.
;Keep in mind that the routine as it stands right now will add _FONT_WIDTH to the char x,
;so if your _FONT_WIDTH is 8, your characters need to be at max 7 pixels wide if you want spaces.
;You can of course change the spacing yourself
_FONT_IMG:
.incbmp path/to/your/font
.endmodule