Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Most useful/needed stuff which should be added
#8
Ok, a simple PUTCHAR, with no ATTR which uses x, y position and c ASCII code. Click on the right <|> symbol to expand the view.
Code:
Sub FASTCALL PutChar(x as Ubyte, y as Ubyte, c as uByte)
     Asm
        ; x comes in A register (FastCall)
        ; y and charCode
        pop hl ; Return Address
        pop de ; get Y in D register
        ex (sp), hl ;  => get c in H register and push return address back

        ; At this point you have X in a; Y in D; an C in H. Now proceed as you want.
        ; This routine is fascalled => you can simply RET at any point.
    
        ld e, a ; D, E = Y, X
        ld b, h ; Saves C char code in B register

        ; This is a very standard routine. Also used in PRINT
        ld hl, (SCREEN_ADDR) ; This will make the routine SCREEN-Relocatable

        ld a, d
        ld b, a     ; Saves it for later
        and 0F8h    ; Masks 3 lower bit ; zy
        ld d, a
        ld a, b     ; Recovers it
        and 07h     ; MOD 7 ; y1
        rrca
        rrca
        rrca
        or e
        ld e, a
        add hl, de  ; HL = Screen address + DE
        ;; At this point, we have the SCREEN ADDRESS

        ex de, hl ; DE => Screen address (saves it temporarily)

        ld a, b ; char ASCII code
        ld bc, (CHARS) ; CHARS Variable, pointing to our charset
        add a, a    ; A = a * 2 (since a < 80h) ; Thanks to Metalbrain at http://foro.speccy.org
        ld l, a
        ld h, 0     ; HL = a * 2 (accumulator)
        add hl, hl
        add hl, hl ; HL = a * 8
        add hl, bc ; HL = CHARS address

        ld b, 8
LOOP:
        ld a, (hl)
        ld (de), a
        inc hl
        inc d
        djnz LOOP
     End Asm
End SuB
Haven't tried this sub, but it should work. Also, if you are going to use 16384 screen address everytime, you can forget about the SCREEN ADDRESS and use the classic scheme (Already used by LCD, Britlion, ROM, etc...). And Finally, it's much faster to use the @address directly instead of ASCII code (as LCD suggested). So your routine could be really fast (I wonder what are you planning... Confusedhock: )
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)