;*---------------------------------------------------------------------------
;  :Program.    QText.ASM
;  :Contents.   Procedure for fast text-output on a BitMap
;  :Author.     Fridtjof Siebert
;  :Address.    Nobileweg 67, D-7-Stgt-40
;  :Phone.      (0)711/822509
;  :Shortcut.   [fbs]
;  :Version.    1.0
;  :Date.       29-Apr-89
;  :Copyright.  Publik Domain
;  :Language.   68000 Assembler
;  :Translator. M2Amiga v3.1d / Profimat
;  :Remark.     Sorry. This compiles only under m2c V3.1d, but
;  :Remark.     this is imported by MuchMore, and I don't want
;  :Remark.     to recompile MuchMore! [fbs]
;---------------------------------------------------------------------------*

; BitMap:
bm_BytesPerRow = 0
bm_Rows        = 2
bm_Flags       = 4
bm_Depth       = 5
bm_Pad         = 6
bm_Planes      = 8
bm_SIZEOF      = 40

; TextFont:
tf_YSize      = 20
tf_Style      = 22
tf_Flags      = 23
tf_XSize      = 24
tf_Baseline   = 26
tf_BoldSmear  = 28
tf_Accessors  = 30
tf_LoChar     = 32
tf_HiChar     = 33
tf_CharData   = 34
tf_Modulo     = 38
tf_CharLoc    = 40
tf_CharSpace  = 44
tf_CharKern   = 48
tf_SIZEOF     = 52

;* d0 - horizontal position  (text position, not pixel position)
;* d1 - vertical position    (pixel position)
;* a0 - Pointer to String (0C-Termination)
;* a1 - Pointer to BitMap to store String
;* a2 - Pointer to TextFont

QText:
  movem.l     d0-d3/a0-a3,-(sp)      ;save used registers
  move        bm_bytesPerRow(a1),d2;
  ext.l       d2;
  mulu        d2,d1;
  ext.l       d0;
  add.l       d0,d1;
  move.l      bm_Planes(a1),a1 ;Position in BitMap to a1
  add.l       d1,a1;
  move.l      d2,d1;
  asl.l       #3,d1;
  sub.l       d2,d1;
  subq.l      #1,d1;
  move.l      tf_CharData(a2),a2  ;get addr of the font data

\loop:
  move.b      (a0)+,d0;           ; get character
  beq         return;

  move.b      d0,d3;
  and.b       #$60,d3;            ; unknown char?
  bne         \knownchar;

  move.b      #$fe,(a1)
  add.l       d2,a1;
  move.b      #$c6,(a1);
  add.l       d2,a1;
  move.b      #$c6,(a1);
  add.l       d2,a1;
  move.b      #$c6,(a1);
  add.l       d2,a1;
  move.b      #$c6,(a1);
  add.l       d2,a1;
  move.b      #$c6,(a1);
  add.l       d2,a1;
  move.b      #$fe,(a1);
  add.l       d2,a1;
  move.b      #$00,(a1);
  sub.l       d1,a1;
  bra         \loop;

\knownchar:
  sub.b       #$20,d0;
  bpl.s       \special;
  sub.b       #$20,d0;

\special:
  and.w       #$ff,d0;
  lea         0(a2,d0.w),a3;

  move.b      (a3),(a1)
  add.l       d2,a1
  move.b      $c0(a3),(a1)
  add.l       d2,a1
  move.b      $180(a3),(a1)
  add.l       d2,a1
  move.b      $240(a3),(a1)
  add.l       d2,a1
  move.b      $300(a3),(a1)
  add.l       d2,a1
  move.b      $3c0(a3),(a1)
  add.l       d2,a1
  move.b      $480(a3),(a1)
  add.l       d2,a1
  move.b      $540(a3),(a1)
  sub.l       d1,a1;
  bra         \loop;

return:
  movem.l     (sp)+,d0-d3/a0-a3; restore regs
  rts;
  END;

