Files
AmigaExamples/024.simple_text/blittext.s
T
2016-03-29 13:27:28 +11:00

125 lines
3.1 KiB
ArmAsm

include "includes.i"
xdef DrawText8
BLIT_LF_MINTERM equ $ca ; cookie cut
BLIT_WIDTH_WORDS equ 2 ; blit 2 words to allow shifting
BLIT_WIDTH_BYTES equ 4
DrawText8:
;; a0 - bitplane
;; a1 - text
;; d0 - xpos
;; d1 - ypos
movem.l d0-d7/a0-a4,-(sp)
WaitBlitter
;; blitter config that is shared for every character
move.w #SCREEN_WIDTH_BYTES-BLIT_WIDTH_BYTES,BLTAMOD(a6) ; A modulo
move.w #SCREEN_WIDTH_BYTES-BLIT_WIDTH_BYTES,BLTBMOD(a6) ; B modulo
move.w #SCREEN_WIDTH_BYTES-BLIT_WIDTH_BYTES,BLTCMOD(a6) ; C modulo
move.w #SCREEN_WIDTH_BYTES-BLIT_WIDTH_BYTES,BLTDMOD(a6) ; D modulo
mulu.w #SCREEN_WIDTH_BYTES*SCREEN_BIT_DEPTH,d1 ; ypos bytes
move.w #$0000,BLTALWM(a6) ; mask out extra word used for shifting
move.w #$ffff,BLTADAT(a6) ; preload source mask so only BLTA?WM mask is used
move.l a1,a3
move.l #font,d6
move.l #fontMask,d7
.loop:
clr.l d2
move.b (a3)+,d2 ; get next character
cmp.b #0,d2 ; 0 terminates the string
beq .done
move.l a0,a4
bsr DrawChar8 ; draw it
add.w #FONT_WIDTH,d0 ; increment the x position
bra .loop
.done:
movem.l (sp)+,d0-d7/a0-a4
rts
DrawChar8:
;; kills d2,d3,d4,d5,a1,a2,a4
;; d0 - xpos
;; d1 - ypos bytes
;; d2 - char
;; a4 - bitplane
sub.w #'!',d2 ; index = char - '!'
move.w d2,d5
lsr.w #5,d5 ; char / 32 = fontmap line
move.w d5,d4 ;
lsl.w #5,d4 ; line * 32 = start of line
sub.w d4,d2 ; char index in line
add.w #1,d5 ; while we have a weird font image, '!' starts on second line
move.l d6,a1 ; #font
mulu.w #SCREEN_WIDTH_BYTES*SCREEN_BIT_DEPTH*FONT_HEIGHT,d5
if MASKED_FONT==1
move.l d7,a2 ; #fontMask
add.w d5,a2 ; add y offset in lines to fontMask address
endif
add.w d5,a1 ; add y offset in lines to font address
add.w d2,a1 ; add offset into font
if MASKED_FONT==1
add.w d2,a2 ; add offset into mask
endif
.blitChar8:
;; kills a4,d2,d4,d5
;; d0 - xpos
;; d1 - ypos bytes
;; d2.0 - odd character = 1, even character = 0
;; a4 - display
;; a1 - object
;; a2 - mask
move.l d0,d4
move.l d0,d5
lsr.w #3,d4 ; d4 = XPOS_BYTES
WaitBlitter
btst #0,d2
beq .evenChar
.oddChar
subq #8,d5 ; offset the x position for the odd character
move.w #$00FF,BLTAFWM(a6) ; select the second (odd) character in the word
subq #1,a4
bra .continue
.evenChar:
move.w #$FF00,BLTAFWM(a6) ; select the first character in the word
.continue:
;; this shift will give us the bits to shift (bits 0-3) in bits (12-15) of d5
swap d5 ; d5 << 12
lsr.l #4,d5
move.w d5,BLTCON1(A6)
if MASKED_FONT==1
ori.w #BLIT_SRCA|BLIT_SRCB|BLIT_SRCC|BLIT_DEST|BLIT_LF_MINTERM,d5
move.l a2,BLTAPTH(a6) ; mask bitplane
else
ori.w #BLIT_SRCB|BLIT_SRCC|BLIT_DEST|BLIT_LF_MINTERM,d5
endif
move.l a1,BLTBPTH(a6) ; source bitplane
move.w d5,BLTCON0(a6) ; set minterm, dma channel and shift
add.l d4,a4 ; dest += XPOS_BYTES
add.l d1,a4 ; dest += YPOS_BYTES
move.l a4,BLTCPTH(a6) ; background top left corner
move.l a4,BLTDPTH(a6) ; destination top left corner
move.w #(FONT_HEIGHT*SCREEN_BIT_DEPTH)<<6|(BLIT_WIDTH_WORDS),BLTSIZE(a6) ;rectangle size, starts blit
rts
font:
incbin "out/font.bin"
fontMask:
incbin "out/font-mask.bin"