Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; DrawString - INPUTS
- ; (Text_X) = X position (pixels)
- ; (Text_Y) = Y position (pixels)
- ; HL = string
- ; OUTPUTS
- ; HL = byte after string
- ; Destroys EVERYTHING else
- DrawString:
- ; Save the X pos for when starting a new line
- ld bc,(Text_X)
- ld (Text_XBuf),bc
- DrawString_Loop:
- ld a,(hl) ; Grab the next character of A
- inc hl
- or a ; Does A = 0?
- ret z ; If so, return
- push hl
- cp 1 ; Does A = 1?
- jr z,DrawString_NewLine ; If so, go to the next line
- call DrawChar ; Draw the character
- ld hl,(Text_X)
- ld bc,Font_Width + Font_HSpacing
- add hl,bc ; Move the X pos to the next character
- ld (Text_X),hl
- pop hl
- jr DrawString_Loop ; Repeat for the next charactar!
- DrawString_NewLine:
- ; Reset the X pos for the new line
- Text_XBuf: =$+1
- ld bc,$000000
- ld (Text_X),bc
- ld hl,(Text_Y)
- ld bc,Font_Height + Font_VSpacing
- add hl,bc ; Add the font height + spacing to the Y pos
- ld (Text_Y),hl
- pop hl
- jr DrawString_Loop ; Draw the next character
- ; DrawChar - INPUTS
- ; A = Character to be drawn
- ; (Text_X) = X position (pixels)
- ; (Text_Y) = Y position (pixels)
- ; Destroys EVERYTHING
- DrawChar:
- ; First get the memory location of the character data
- sbc hl,hl
- ld l,a
- ; Each character is 14 bytes total, so we will multiply by 14 (Font_CharBytes)
- ld h,Font_Height
- mlt hl
- ; Add in the actual RAM location
- SMC_Font = $+1
- ld bc,Font_CharData
- add hl,bc
- ex de,hl
- ; Now get the memory location of the top-left screen pixel
- ; Multiply Y pos by screen height (160)
- Text_Y = $+1
- ld hl,$000000
- ld h,160
- mlt hl ; x160
- add hl,hl ; x320
- ; Add in the X pos and vRAM location
- Text_X = $+1
- ld bc,$000000
- add hl,bc
- ld bc,vRAM
- add hl,bc
- ; DE is now pointing to the first byte of the character
- ; HL is now pointing to the top left corner pixel where the character will be printed
- ld b,Font_Height ; Font height
- DrawChar_LoopV:
- push bc
- ld a,(de) ; Grab next byte of character
- ld b,Font_Width ; Number of bits we actually care about
- DrawChar_LoopPixel:
- Text_BG = $+1
- ld (hl),BgColor
- rla
- jr nc,DrawChar_PixelOff
- Text_FG = $+1
- ld (hl),FgColor
- DrawChar_PixelOff:
- inc hl
- djnz DrawChar_LoopPixel
- inc de
- ld bc,320-Font_Width ; 320 (screen width) minus char width
- add hl,bc ; This will advance us the next row of pixels
- pop bc
- djnz DrawChar_LoopV
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement