
************************************************************************
Text   plotter   by   Phil!95/Neř.   Code  is  NOT  meant  to  be  fully
optomized-wizz  bang-rumba-snort,  its just intended to illustrate a way
of coding a simple routine!
************************************************************************

    section maincode,code   ;Amiga dos hunk header-NOT ASSEMBLY!

* Preparation!

    move.l #$dff000,a0      ;A0 = Custom chips Base Address.
    move.w #$7fff,$9a(a0)   ;Disable ALL Interupts
    move.w #$8710,$96(a0)   ;Switch on DMA channels required.
    
    move.l #screen_area,d0  ;d0 = screen location
    move.l #bitplane,a1     ;a1 = location of bitplane store in 
                ;copper list

    move.w d0,6(a1)     ;Put low word into copper list
    swap d0         ;Swap register halves.
    move.w d0,2(a1)     ;Put high word (now low) into cop list

    move.l #Philscopper,$80(a0) ;Set copper to read my copper list
    clr.w $88(a0)       ;restarts copper immediately.

************************************************************************

    bsr example_program     ;Call the main program
loop    bra loop            ;loops forever!

************************************************************************

* Position / Display the text!

example_program

    move.w #2,d0        ;pos of 1st char of text, x=column 2
    move.w #128,d1      ;pos of 1st char of text, y=line 128
    move.l #message1,a0     ;message 1's location pointer
    bsr display_text        ;call text displayer.

    move.w #12,d0       ;column 12
    move.w #144,d1      ;line 144
    move.l #message2,a0     ;message 2 location
    bsr display_text
    rts
    
************************************************************************


* Here's the routine that actually plots the text on screen!

display_text

    movem.l a0-a3/d0/d7,-(SP)   ;push all used registers onto stack
    move.l #screen_area,a1  ;a1 = address of 1st byte of screen
    mulu #40,d1     ;multiply (y) value by 40 bytes (a line)
    add.w d0,d1     ;add on the (x) value for column
    add.w d1,a1     ;add this to screen start (in A1)

sentence_loop

    move.l #font_data,a2    ;1st byte of font address (base)
    moveq #0,d0     
    move.b (a0),d0      ;get 1st char ascii code in d0 (byte)
    beq sentence_done       ;if zero, all chars done.
    sub.w #32,d0        ;subtract 32 as SPACE is 1st character
                ;in charset
    lsl.w #3,d0     ;multiply char number by 8
    add.w d0,a2     ;add resulting offset to font base.
    
    move.l a1,a3        ;copy reg a1 into a3
    moveq #7,d7     ;d7 = $00000007 (no. lines in font-1)
charloop    move.b (a2)+,(a3)       ;copy a byte from font to screen
                ;char address is incremented
    add.w #40,a3        ;get to next byte down of screen
    dbra d7,charloop        ;decrease d7 by 1 and branch if not
                ;-1 to charloop (loop 8 times)

    addq.w #1,a0        ;increment a0, (next char in message)
    addq.w #1,a1        ;move 1 byte right for next char pos
    bra sentence_loop       ;and repeat for next char

sentence_done
    
    movem.l (SP)+,a0-a3/d0/d7   ;retrieve used registers from stack
    rts         ;and return

************************************************************************

* DATA!

message1    dc.b "Hello there, Err.. 10 PRINT 'Hello'.",$0  ;Simple enuf
    even        

message2    dc.b "(How do they do that?)",$0    ;Just the Data Bytes (ascii)
    even

font_data   incbin font1.bin    ;includes (loads) the BINARY file "font1.bin"
    even        ;EVEN pads out to an even address

************************************************************************

* More data, but stuff that must go in CHIP RAM.

    section chipstuff,data_c    ;Hunk header, DATA_C=DATA in Chip RAM

Philscopper 

    dc.w $0101,$ff00    ;wait for scan line 1
    dc.w $0100,$1200    ;set $dff100 to $1200 (1 bitplane screen)
    dc.w $0102,$0000    ;clear $dff102 (scrolling)
    dc.w $0104,$0000    ;clear $dff104 (video priorities)
    dc.w $01fc,$0000    ;clear $dff1fc (AGA off!)

    dc.w $008e,$2c81    ;display window starts line $2c,pixel column $81
    dc.w $0090,$2cc1    ;display window stops line $12c,pixel colum $1c1

    dc.w $0092,$0038    ;hardware data fetch x postion starts pos $38
    dc.w $0094,$00d0    ;hardware data fetch x postion ends pos $d0

    dc.w $0108,$0000    ;bitplane modulos = 0, no addition at end of
    dc.w $010a,$0000    ;each scan line

bitplane    dc.w $00e0,$0000    ;high word of address of bitplane 1
    dc.w $00e2,$0000    ;lo word of address of bitplane 1

    dc.w $0180,$0000    ;background colour (0)
    dc.w $0182,$0fff    ;text colour (col 0) = white. 
    
    dc.w $0120,$0000,$0122,$0000,$0124,$0000,$0126,$0000 ;zero
    dc.w $0128,$0000,$012a,$0000,$012c,$0000,$012e,$0000 ;sprite
    dc.w $0130,$0000,$0132,$0000,$0134,$0000,$0136,$0000 ;locations
    dc.w $0138,$0000,$013a,$0000,$013c,$0000,$013e,$0000

    dc.w $ffff,$fffe    ;=end of copperlist.

screen_area

    ds.b 40*256 ;data array of 256 lines x 40 bytes.

************************************************************************

