
; This is an example about gfxboard.s
;
; As i cannot code in Blitz Basic, it is a PLAIN ASM EXAMPLE.
; But you can, of course, put the example code into a Blitz Board Source
; File, using the inline Assembler (one small modification see below)

; If you have problems with the Assembler code, please mail me and ask !!!
; (The basic stuff is : move.l d0,myscreen is something like LET myscreen=d0,
; expressed in BASIC (i am assuming BB makes this similar to this, putting
; stuff to a variable. You will have to use the move's, though, as these
; d-somewhat's and a-somewhat's are REGISTERS, not VARIABLES)

; To test this, you need a PCX image sized 320x200 8 Bit named ram:test.pcx
; You should test it with a 320x200 GFX Board Mode.

start:
    jsr _SCREEN                       ; Open a Screenmoderequester and a screen
    move.l d0,myscreen                ; Save the Screen Handle
    move.l d1,Map0                    ; Save the Front (real) Bitmap
    move.l d2,Map1                    ; Save the Back (real) Bitmap
    move.l d3,scwidth                 ; Save the width of the Screen
    move.l d4,scheight                ; Save the height of the Screen
    move.l d5,scdepth                 ; Save the depth of the Screen
    move.l d6,BytesPerRow             ; Save the Bytes Per Row
    lea colortable,a1                 ; Get Address of the colortable
    move.l myscreen,a0                ; Get Address of the Screen
    move.l #$FFFFFFFF,16(a1)          ; Color 1 => RED
    move.l #$FFFFFFFF,32(a1)          ; Color 2 => GREEN
    jsr _SHOWPALETTE                  ; Show the Palette
    move.l #320*200,d1                ; We want a 320x200 sized Fastram Buffer
    jsr _BITMAP                       ; _SCREENSBITMAP does exactly the same, BTW...
    move.l d0,frbuffer                ; Save the Fastram Buffer
    lea filename,a0
    lea pcxdata,a1
    jsr _LOADGFX                      ; Load the PCX Image to RAM
                                      ; Note: This function allocates its own
                                      ; Fastram Buffer. It does NOT load the
                                      ; Palette of the PCX Image, though, you
                                      ; have to handle the Palette yourselves.
mainloop:                             ; Now we start the mainloop
    move.l Map0,a0
    move.l #50,d0
    move.l #50*320,d1
    move.l #1,d2
    jsr _PLOT                         ; Plot 50/50 in color 1 on Map0
    move.l Map0,a0
    move.l #100,d0
    move.l #110,d1
    move.l #130,d2
    move.l #140,d3
    move.l #2,d4
    jsr _LINE                         ; Draw the line (100,110)-(130,140) in color
                                      ; 2 on Map1

    move.l frbuffer,a0                ; Fill some example data to the
    move.l #$01010101,(a0)            ; Fastram Buffer
    add.l #320,a0
    move.l #$02020202,(a0)
    add.l #320,a0
    move.l #$01010101,(a0)

    ;move.l myscreen,a0               ; Example of mode DOUBLEBUFFER of _BLIT.
    ;move.l Map0,a1                   ; Note: This is no real blitting, but
    ;move.l Map1,a2                   ; Doublebuffering instead, so BOTH
    ;move.l #DOUBLEBUFFER,d0          ; Bitmaps have to be in real VRAM
    ;move.l #WAIT,d1                  ; (only the two "real" Bitmaps are valid)
    ;move.l #0,d2                     ; ALWAYS does Fullscreen BLIT, of course,
    ;move.l #0,d3                     ; as it is Doublebuffering.
    ;move.l #320,d4
    ;move.l #200,d5
    ;jsr _BLIT

    ;move.l myscreen,a0               ; Example of mode MOVEM (note width has to
    ;move.l Map1,a1                   ; be divisible by 64). The Width also can
    ;move.l frbuffer,a2               ; differ from the actual width of the
    ;move.l #MOVEM,d0                 ; data (which is NOT possible for mode
    ;move.l #WAIT,d1                  ; RTGMASTER)
    ;move.l #100,d2
    ;move.l #100,d3
    ;move.l #64,d4
    ;move.l #64,d5
    ;jsr _BLIT
                                     ; Example of mode RTGMASTER. Destination
    move.l myscreen,a0              ; ALWAYS has to be a TRUE VRAM Buffer
    move.l Map0,a1                  ; (here Map1). NOTE: The Width of the
    move.l frbuffer,a2              ; rectangle ALWAYS has to be IDENTICAL
    move.l #RTGMASTER,d0            ; with the width of the image data !!!
    move.l #WAIT,d1                 ; (here the image is 320x200, so d4
    move.l #0,d2                    ; HAS to contain 320)
    move.l #30,d3
    move.l #320,d4
    move.l #100,d5
    jsr _BLIT

    move.l myscreen,a0               ; Example of mode FCOPY (note, that Width and
    move.l Map1,a1                   ; X Offset and both addresses have to be
    move.l bitmap,a2
    move.l #FCOPY,d0                 ; Offset are ALWAYS the same, does not work
    move.l #WAIT,d1                  ; on the Cybervision64, needs 040 or 060)
    move.l #0,d2                     ; Needs the external file fcopy in the same
    move.l #0,d3                     ; directory like the executable.
    move.l #320,d4
    move.l #200,d5
    jsr _BLIT

    move.l myscreen,a0                ; Get the Screen Address
    move.l #1,d0
    sub.l bufnum,d0                   ; Buffer number to switch to
    move.l d0,bufnum
    jsr _SHOWBITMAP                   ; Now Map1 is the front bitmap, and Map0 the Back
                                      ; (Doublebuffering)
    move.l myscreen,a0                ; Get the Screen Address
    jsr _INPUT                        ; Check for Input (Blitz Basic functions should also work,
                                      ; if they don't, use this function)
    move.l d0,a0
    move.w me_rawkey(a0),d0           ; access rawkey value
    move.w me_qualifier(a0),d1        ; access qualifier value
    cmp.w #0,d0
    beq mainloop                      ; no key pressed => Mainloop
    cmp.w #16,d0
    bne mainloop                      ; Key 'q' not pressed => Mainloop
    and.w #CONTROL,d1
    cmp.w #0,d1
    beq mainloop                      ; Qualifier 'CTRL' not pressed => Mainloop
pressed:                              ; CTRL+q was pressed !!! (Quit)
    move.l myscreen,a0                ; get the Screen Address
    jsr _CLOSESCREEN                  ; Close the Screen again
    move.l frbuffer,a0
    move.l #320*200,d0
    jsr _CLOSEBITMAP                  ; Close the Fastram Buffer
    move.l bitmap,a0
    move.l imagebytes,d0
    jsr _CLOSEBITMAP                  ; Close the Fastram Buffer of the loaded image
    rts                               ; Quit ASM function

; Now the variables

myscreen: dc.l 0                      ; The Screenhandle
Map0: dc.l 0                          ; The (at startup) Front Map
Map1: dc.l 0                          ; The (at startup) Back Map
scwidth: dc.l 0                       ; The Screen Width
scheight: dc.l 0                      ; The Screen Height
scdepth: dc.l 0                       ; The Screen Color-Depth
BytesPerRow: dc.l 0                   ; The BytesPerRow of the Screen
frbuffer: dc.l 0                      ; Handle for a Fastram Buffer
colortable: dc.w 256,0                ; 256 colors, starting with color 0
            ds.l 768,0                ; color data
            dc.w 0                    ; the end of the color list
blit1:
    dc.b 1,1,1,2,2,2,1,1,1            ; Some Color Data for a Blit
    even
bufnum: dc.l 0                        ; The Number of the current Front Buffer
pcxdata:                              ; The PCX Image Data
    dc.l 0,0,0,0,0,0,0,0              ; 128 Bytes to be ignored
    dc.l 0,0,0,0,0,0,0,0
    dc.l 0,0,0,0,0,0,0,0
    dc.l 0,0,0,0,0,0,0,0
bitmap:                               ; The (from LoadPcxImage) allocated Fastrambuffer
    dc.l 0
    ds.b 768                          ; Here the Palette will be put
imagebytes:
    dc.l 0                            ; The size of the imagedata in Bytes (Width*Height)
width:
    dc.l 0                            ; The Width of the Image Data
height:
    dc.l 0                            ; The Height of the Image Data
filename:
    dc.b 'ram:test.pcx',0
    even

; BB does not *have* ASM Source includes !!!! Instead of the following line,
; simply include the whole file gfxboard.s here...
    include "Blitz.s"

