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:

.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
24 bit color to 16 bit
Here's a routine for converting a 24 bit RGB triplet to 16 bit. If anyone can optimize it please do!

Code:

;Input: AHL - 24 bit RGB color
;Output: DE - 16 bit color
;Destroys: A,HL
ConvertColor:
    and 11111000b
    ld d,a
    rlc h
    rlc h
    rlc h
    ld a,111b
    and h
    or d
    ld d,a

    ;Use 11100000b to use all available green precision
    ;Use 11000000b to have green precision match red and blue
    ld a,11100000b
    and h
    ld e,a

    ld a,l
    and 11111000b
    rra
    rra
    rra
    or e
    ld e,a
    ret
[/b]
Challenge accepted. (As a bonus, it no longer destroys HL.)

Code:
;Input: AHL - 24 bit RGB color
;Output: DE - 16 bit color
;Destroys: A
ConvertColor:
   ld d,a
   ld a,h
   rlca
   rlca
   rlca
   ld e,a
   xor d
   and %00000111
   xor d
   ld d,a
   ld a,l
   rrca
   rrca
   rrca
   xor e
   and %00011111
   xor e
   ld e,a
   ret


Edit: Of course, the routine could possibly be two bytes smaller if the Green byte of the input was in A.
The DCSE_SDK on the ticalc website does not have compile.sh in the asm folder. I know the terminal and cmd commands are different (obviously) so where can I download it?
Asian wrote:
The DCSE_SDK on the ticalc website does not have compile.sh in the asm folder. I know the terminal and cmd commands are different (obviously) so where can I download it?
This is the completely wrong thread for this, so I hesitate to even answer, but I'll be updating the DCSE SDK with a compile.sh. For now, just use the one from the Doors CS SDK.
Ah, they are the same? OK, I will download it. Thanks!
I believe an admin/mod told me to post this here, (tifreak or merth) on the SAX/IRC
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement