; ----------------------------------------------------------------------------
;
;               steps on the blitter
;
; ----------------------------------------------------------------------------
orgcpu          equ $00004000           ;Zieladresse im Jaguar-Ram
                >PART 'Loader'

startsub        equ $00000083
writelongs      equ $00000088
firsttimeoutinit equ 120
timeoutinit     equ 70
sendregs        reg d1-d3/d6-a2

                bra.s   header0

                dc.b "PHOBYX",$00,$00

header0:        pea     header(pc)
                move.w  #38,-(sp)
                trap    #14
                addq.l  #6,sp

                clr.w   -(sp)
                trap    #1

header:         sf      $ffff9203.w

                lea     jag_prg(pc),a0
                lea     orgcpu.w,a1
                move.l  #jag_end-jag_prg,d0
                bsr.s   sendprg2jaggy

                rts

sendprg2jaggy:  lea     jag_prg(pc),a0
                move.l  #(jag_end-jag_prg)>>2,d2
                move.l  #orgcpu,d1
                bsr     writedumpl
                beq.s   error_sp

                move.w  #startsub,d0
                bsr.s   sendword
                beq.s   error_sp

                move.l  #orgcpu,d0
                bsr     sendlong

error_sp:       rts

print:          movem.l d0-d2/a0-a2,-(sp)
                move.l  7*4(sp),-(sp)
                move.w  #9,-(sp)
                trap    #1
                addq.l  #6,sp
                movem.l (sp)+,d0-d2/a0-a2
                move.l  (sp)+,(sp)
                rts

sendword:       movem.l sendregs,-(sp)
                lea     $000004ba.w,a2
                moveq   #firsttimeoutinit,d7
                add.l   (a2),d7
                lea     $ffff9201,a0

sendword1:      btst    #3,(a0)
                bne.s   sendword2
                cmp.l   (a2),d7
                bhi.s   sendword1
                moveq   #0,d0
                movem.l (sp)+,sendregs
                rts

sendword2:      lea     2(a0),a1
                rol.w   #8,d0
                moveq   #$10,d2
                moveq   #3,d3
                moveq   #7,d6
sendword3:      moveq   #$c0,d1
                and.w   d0,d1
                rol.w   #2,d0
                or.b    d2,d1

                moveq   #timeoutinit,d7
                add.l   (a2),d7
sendword4:      btst    #3,(a0)
                bne.s   sendword5       ; auf BUSY high warten
                cmp.l   (a2),d7
                bhi.s   sendword4
                bra     timeout1

sendword5:      move.b  d1,(a1)         ; Bit mit STROBE
                moveq   #timeoutinit,d7
                add.l   (a2),d7
sendword6:      btst    #3,(a0)
                beq.s   sendword7       ; auf BUSY low warten
                cmp.l   (a2),d7
                bhi.s   sendword6
                bra     timeout1
sendword7:      clr.b   (a1)            ; STROBE low

                dbra    d6,sendword3
                moveq   #-1,d0
                movem.l (sp)+,sendregs
                rts

sendlong:       movem.l sendregs,-(sp)
                lea     $ffff9201,a0
                lea     2(a0),a1
                lea     $000004ba.w,a2
                moveq   #firsttimeoutinit,d7
                add.l   (a2),d7

sendlong1:      btst    #3,(a0)
                bne.s   sendlong2       ; auf BUSY high warten
                cmp.l   (a2),d7
                bhi.s   sendlong1
                moveq   #0,d0
                movem.l (sp)+,sendregs
                rts

sendlong2:      rol.l   #3,d0
                moveq   #$10,d2
                moveq   #3,d3
                moveq   #9,d6           ; 10*3 Bit
sendlong3:      moveq   #$e0,d1
                and.w   d0,d1
                rol.l   #3,d0
                or.b    d2,d1

                moveq   #timeoutinit,d7
                add.l   (a2),d7
sendlong4:      btst    #3,(a0)
                bne.s   sendlong5       ; auf BUSY high warten
                cmp.l   (a2),d7
                bhi.s   sendlong4
                bra     timeout1
sendlong5:      move.b  d1,(a1)         ; Bit mit STROBE
                moveq   #timeoutinit,d7
                add.l   (a2),d7
sendlong6:      btst    d3,(a0)
                beq.s   sendlong7
                cmp.l   (a2),d7
                bhi.s   sendlong6
                bra     timeout1        ; auf Busy low warten
sendlong7:      sf      (a1)            ; STROBE low
                dbra    d6,sendlong3

                moveq   #$c0,d1
                and.w   d0,d1
                or.b    d2,d1

                moveq   #timeoutinit,d7
                add.l   (a2),d7
sendlong8:      btst    #3,(a0)
                bne.s   sendlong9       ; auf BUSY high warten
                cmp.l   (a2),d7
                bhi.s   sendlong8
                bra     timeout1
sendlong9:      move.b  d1,(a1)         ; Bit mit STROBE
                moveq   #timeoutinit,d7
                add.l   (a2),d7
sendlong10:     btst    d3,(a0)
                beq.s   sendlong11
                cmp.l   (a2),d7
                bhi.s   sendlong10
                bra     timeout1        ; auf Busy low warten
sendlong11:     sf      (a1)            ; STROBE low

                moveq   #-1,d0
                movem.l (sp)+,sendregs
                rts

recvword:       movem.l sendregs,-(sp)
                moveq   #firsttimeoutinit,d7
                add.l   $000004ba.w,d7
                lea     $ffff9201,a0
recvword1:      btst    #3,(a0)
                beq.s   recvword2
                cmp.l   $000004ba.w,d7
                bhi.s   recvword1

                moveq   #0,d0
                movem.l (sp)+,sendregs
                rts

recvword2:      lea     2(a0),a1
                moveq   #0,d0
                moveq   #0,d2

                moveq   #7,d6
recvword3:      st      (a1)            ; /Busy high
                bsr     waitshi
                move.b  (a1),d1
                sf      (a1)            ; /Busy low
                add.b   d1,d1
                roxl.w  #1,d0
                add.b   d1,d1
                roxl.w  #1,d0
                bsr     waitslo
                dbra    d6,recvword3
                moveq   #-1,d1
                movem.l (sp)+,sendregs
                rts

recvlong:       movem.l sendregs,-(sp)
                lea     $000004ba.w,a2
                moveq   #20,d7
                add.l   (a2),d7
                lea     $ffff9201,a0
                sf      2(a0)
recvlong1:      btst    #3,(a0)
                beq.s   recvlong2
                cmp.l   (a2),d7
                bhi.s   recvlong1
                sf      2(a0)
                moveq   #0,d0
                movem.l (sp)+,sendregs
                rts

recvlong2:      lea     2(a0),a1
                moveq   #0,d0
                moveq   #0,d2
                moveq   #9,d6
recvlong3:      st      (a1)            ; Busy high
                moveq   #timeoutinit,d7
                add.l   (a2),d7
recvlong4:      btst    #3,(a0)
                bne.s   recvlong5
                cmp.l   (a2),d7
                bhi.s   recvlong4
                bra     timeout1
recvlong5:      moveq   #$e0,d1
                and.b   (a1),d1
                sf      (a1)            ; Busy low
                rol.l   #3,d0
                or.b    d1,d0

                moveq   #timeoutinit,d7
                add.l   (a2),d7
recvlong6:      btst    #3,(a0)
                beq.s   recvlong7
                cmp.l   (a2),d7
                bhi.s   recvlong6
                bra.s   timeout1
recvlong7:      dbra    d6,recvlong3

                st      (a1)
                moveq   #timeoutinit,d7
                add.l   (a2),d7
recvlong8:      btst    #3,(a0)
                bne.s   recvlong9
                cmp.l   (a2),d7
                bhi.s   recvlong8
                bra.s   timeout1

recvlong9:      moveq   #$c0,d1
                and.b   (a1),d1
                sf      (a1)            ; Busy low
                rol.l   #3,d0
                or.b    d1,d0
                rol.l   #1,d0

                moveq   #timeoutinit,d7
                add.l   (a2),d7
recvlong10:     btst    #3,(a0)
                beq.s   recvlong11
                cmp.l   (a2),d7
                bhi.s   recvlong10
                bra.s   timeout1
recvlong11:     moveq   #-1,d1
                movem.l (sp)+,sendregs
                rts

waitshi:        moveq   #60,d7
                add.l   $000004ba.w,d7
waitshi1:       btst    #3,(a0)         ; 12
                bne.s   waitshi2        ;  8    auf BUSY high warten
                cmp.l   $000004ba.w,d7
                bhi.s   waitshi1
                bra.s   timeout
waitshi2:       rts

waitslo:        moveq   #60,d7
                add.l   $000004ba.w,d7
waitslo1:       btst    #3,(a0)         ; 12
                beq.s   waitslo2        ;  8    auf BUSY high warten
                cmp.l   $000004ba.w,d7
                bhi.s   waitslo1
                bra.s   timeout
waitslo2:       rts

timeout:        addq.l  #4,sp
timeout1:       movem.l (sp)+,d1-d3/d6-a1
                sf      $ffff9203.w
                pea     timeout3(pc)
                bsr     print
                moveq   #0,d0
timeout2:       rts
timeout3:       dc.b "TimeOut",13,10,0
                even

writedumpl:     movem.l d0-d2/a0-a2,-(sp)
                sf      $ffff9203.w

writedumpl1:    move.w  #writelongs,d0
                bsr     sendword        ; Commando
                beq.s   writedumpl5

                move.l  d1,d0
                bsr     sendlong        ; Start-Adress
                beq.s   writedumpl5

                move.l  d2,d0
                bsr     sendlong        ; Anzahl der Lang-Worte
                beq.s   writedumpl5

                sf      $ffff9203.w

writedumpl2:    bsr     recvword
                beq.s   writedumpl4
                cmp.w   #writelongs,d0
                bne.s   writedumpl5

                moveq   #0,d3
writedumpl3:    move.l  (a0)+,d0
                move.l  d0,d1

                eor.l   d3,d1
                add.l   d1,d3

                bsr     sendlong
                beq.s   writedumpl5

                dbra    d2,writedumpl3
                sub.l   #$00010000,d2
                bpl.s   writedumpl3
                bsr     recvlong
                cmp.l   d0,d3
                bne.s   writedumpl6

                moveq   #-1,d0
                movem.l (sp)+,d0-d2/a0-a2
                rts

writedumpl4:    pea     writedumpl8(pc)
                bra.s   writedumpl7

writedumpl5:    pea     timeout(pc)
                bra.s   writedumpl7
writedumpl6:    pea     writedumpl9(pc)
writedumpl7:    bsr     print
                moveq   #0,d0
                movem.l (sp)+,d0-d2/a0-a2
                rts
writedumpl8:    dc.b "WriteDumpL-TimeOut",13,10,0
writedumpl9:    dc.b "Error in transmission !",13,10,0
                even

                endpart
; ----------------------------------------------------------------------------
                >PART 'Equates (Jaguar Hardware)'
;
;               changes
;               aug 27  started
;               aug 29  blitter added
;                       video added

memcon1         equ $00f00000           ;memory configuration register 1
memcon2         equ $00f00002           ;memory configuration register 2

;            ---------- video

hc              equ $00f00004           ;horizontal count
vc              equ $00f00006           ;vertical count
lph             equ $00f00008           ;horizontal light pen
lpv             equ $00f0000a           ;vertical light pen
ob0             equ $00f00010           ;object code 0
ob1             equ $00f00012           ;object code 1
ob2             equ $00f00014           ;object code 2
ob3             equ $00f00016           ;object code 3
olp             equ $00f00020           ;object list pointer
opf             equ $00f00026           ;object processor flag
vmode           equ $00f00028           ;video mode
bord1           equ $00f0002a           ;border colour red & green
bord2           equ $00f0002c           ;border colour blue
hp              equ $00f0002e           ;horizontal period
hbb             equ $00f00030           ;horizontal blanking begin
hbe             equ $00f00032           ;horizontal blanking end
hs              equ $00f00034           ;horizontal sync
hvs             equ $00f00036           ;horizontal vertical sync
hdb1            equ $00f00038           ;horizontal display begin 1
hdb2            equ $00f0003a           ;horizontal display begin 2
hde             equ $00f0003c           ;horizontal display end
vp              equ $00f0003e           ;vertical period
vbb             equ $00f00040           ;vertical blanking begin
vbe             equ $00f00042           ;vertical blanking end
vs              equ $00f00044           ;vertical sync
vdb             equ $00f00046           ;vertical display begin
vde             equ $00f00048           ;vertical display end
veb             equ $00f0004a           ;vertical equalization begin
vee             equ $00f0004c           ;vertical equalization end
vi              equ $00f0004e           ;vertical interrupt
pit0            equ $00f00050           ;programmable interrupt timer 0
pit1            equ $00f00052           ;programmable interrupt timer 1
heq             equ $00f00054           ;horizontal equalization end
bg              equ $00f00058           ;background cry colour
int1            equ $00f000e0           ;cpu interrupt control register
int2            equ $00f000e2           ;cpu interrupt resume register
clut            equ $00f00400           ;colour look-up-table
lbuf            equ $00f00800           ;line-buffer

;            ---------- gpu

gpubase         equ $00f02000           ;gpu registers base
gpuflags        equ $00f02100           ;gpu flags
gpumtxcr        equ $00f02104           ;gpu matrix control register
gpumtxar        equ $00f02108           ;gpu matrix adress register
gpudor          equ $00f0210c           ;gpu data organisation register
gpupc           equ $00f02110           ;gpu program counter
gpucr           equ $00f02114           ;gpu control register
gpusr           equ $00f02114           ;gpu status reguster
gpuhdr          equ $00f02118           ;gpu high data register
gpudivrem       equ $00f0211c           ;gpu divide unit remainder
gpudivctl       equ $00f0211c           ;gpu divide unit control

;            -- blitter

blitbase        equ $00f02200           ;blitter registers base

blita1base      equ $00f02200           ;blitter a1 base register
blita1flags     equ $00f02204           ;blitter a1 flags
blita1clip      equ $00f02208           ;blitter a1 clipping size
blita1pix       equ $00f0220c           ;blitter a1 pixel pointer
blita1step      equ $00f02210           ;blitter a1 step value
blita1stepf     equ $00f02214           ;blitter a1 step fraction value
blita1pixf      equ $00f02218           ;blitter a1 pixel pointer fraction
blita1inc       equ $00f0221c           ;blitter a1 increment
blita1incf      equ $00f02220           ;blitter a1 increment fraction

blita2base      equ $00f02224           ;blitter a2 base register
blita2flags     equ $00f02228           ;blitter a2 flags
blita2mask      equ $00f0222c           ;blitter a2 window mask
blita2pix       equ $00f02230           ;blitter a2 window pointer
blita2step      equ $00f02234           ;blitter a2 step value

blitcmd         equ $00f02238           ;blitter command register
blitsr          equ $00f02238           ;blitter status register
blitcount       equ $00f0223c           ;blitter counters register
blitsrcdr       equ $00f02240           ;blitter source data register
blitdstdr       equ $00f02248           ;blitter destination data register
blitdstz        equ $00f02250           ;blitter destination z register
blitsrcz1       equ $00f02258           ;blitter source z register 1
blitsrcz2       equ $00f02260           ;blitter source z register 2
blitpattern     equ $00f02268           ;blitter pattern data register
blitintinc      equ $00f02270           ;blitter intensity increment
blitzinc        equ $00f02274           ;blitter z increment
blitcctl        equ $00f02278           ;blitter collision control
blitint0        equ $00f0227c           ;blitter intensity 0
blitint1        equ $00f02280           ;blitter intensity 1
blitint2        equ $00f02284           ;blitter intensity 2
blitint3        equ $00f02288           ;blitter intensity 3
blitz0          equ $00f0228c           ;blitter z 0
blitz1          equ $00f02290           ;blitter z 1
blitz2          equ $00f02294           ;blitter z 2
blitz3          equ $00f02298           ;blitter z 3

;            -- dsp io

joy1            equ $00f14000
joy2            equ $00f14002

                endpart
                >PART 'Equates (Blitter)'

;Blitter Command-Register

b_srcen         equ $00000001           ; d00:source data read (inner loop)
b_srcenz        equ $00000002           ; d01:source Z read (inner loop)
b_srcenx        equ $00000004           ; d02:source data read (realign)
b_dsten         equ $00000008           ; d03:destination data read (inner loop)
b_dstenz        equ $00000010           ; d04:destination Z read (inner loop)
b_dstwrz        equ $00000020           ; d05:destination Z write (inner loop)
b_clip_a1       equ $00000040           ; d06:A1 clipping enable
b_nogo          equ $00000080           ; d07:diagnostic
b_upda1f        equ $00000100           ; d08:A1 update step fraction
b_upda1         equ $00000200           ; d09:A1 update step
b_upda2         equ $00000400           ; d10:A2 update step
b_dsta2         equ $00000800           ; d11:reverse usage of A1 and A2
b_gourd         equ $00001000           ; d12:enable Gouraud shading
b_zbuff         equ $00002000           ; d13:polygon Z data updates
b_topben        equ $00004000           ; d14:intensity carry into byte
b_topnen        equ $00008000           ; d15:intensity carry into nibble
b_patdsel       equ $00010000           ; d16:Select pattern data
b_adddsel       equ $00020000           ; d17:diagnostic
; d18-d20: Z comparator inhibit
b_zmodelt       equ $00040000           ;        source < destination
b_zmodeeq       equ $00080000           ;        source = destination
b_zmodegt       equ $00100000           ;        source > destination
; d21-d24: Logic function control
b_lfu_nan       equ $00200000           ;        !source & !destination
b_lfu_na        equ $00400000           ;        !source &  destination
b_lfu_an        equ $00800000           ;         source & !destination
b_lfu_a         equ $01000000           ;         source &  destination

; The following are ALL 16 possible logical operations of the LFUs

b_lfu_zero      equ $00000000           ; All Zeros
b_lfu_nsand     equ $00200000           ; NOT Source AND NOT Destination
b_lfu_nsad      equ $00400000           ; NOT Source AND Destination
b_lfu_nots      equ $00600000           ; NOT Source
b_lfu_sand      equ $00800000           ; Source AND NOT Destination
b_lfu_notd      equ $00a00000           ; NOT Destination
b_lfu_n_sxord   equ $00c00000           ; NOT (Source XOR Destination)
b_lfu_nsornd    equ $00e00000           ; NOT Source OR NOT Destination
b_lfu_sad       equ $01000000           ; Source AND Destination
b_lfu_sxord     equ $01200000           ; Source XOR Destination
b_lfu_d         equ $01400000           ; Destination
b_lfu_nsord     equ $01600000           ; NOT Source OR Destination
b_lfu_s         equ $01800000           ; Source
b_lfu_sornd     equ $01a00000           ; Source OR NOT Destination
b_lfu_sord      equ $01c00000           ; Source OR Destination
b_lfu_one       equ $01e00000           ; All Ones

; These are some common combinations with less boolean names

b_lfu_replace   equ $01800000           ; Source REPLACEs destination
b_lfu_xor       equ $01200000           ; Source XOR with destination
b_lfu_clear     equ $00000000           ; CLEAR destination

b_cmpdst        equ $02000000           ; d25: pixel compare pattern & dest
b_bcompen       equ $04000000           ; d26: bit compare write inhibit
b_dcompen       equ $08000000           ; d27: data compare write inhibit
b_bkgwren       equ $10000000           ; d28: data write back
b_bushi         equ $20000000           ; d29: blitter priority
b_srcshade      equ $40000000           ; d30: shade src data w/IINC value

;*======================================================================*
;* BLITTER Flags (A1 or A2) register equates
;*======================================================================*

; Pitch d00-d01:
;       distance between pixel phrases
b_pitch1        equ $00000000           ; 0 phrase gap
b_pitch2        equ $00000001           ; 1 phrase gap
b_pitch4        equ $00000002           ; 3 phrase gap
b_pitch8        equ $00000003           ; 7 phrase gap
b_pitch3        equ $00000003           ; 3 phrase gap

; Pixel d03-d05
;       bit depth (2^n)
b_pixel1        equ $00000000           ; n = 0 0 color
b_pixel2        equ $00000008           ; n = 1 2 colors
b_pixel4        equ $00000010           ; n = 2 4 colors
b_pixel8        equ $00000018           ; n = 3 8 colors
b_pixel16       equ $00000020           ; n = 4 16 colors
b_pixel32       equ $00000028           ; n = 5 32 colors

; Z offset d06-d08
;       offset from phrase of pixel data from its corresponding
;       Z data phrases
b_zoffs0        equ $00000000           ; offset = 0    UNUSED
b_zoffs1        equ $00000040           ; offset = 1
b_zoffs2        equ $00000080           ; offset = 2
b_zoffs3        equ $000000c0           ; offset = 3
b_zoffs4        equ $00000100           ; offset = 4
b_zoffs5        equ $00000140           ; offset = 5
b_zoffs6        equ $00000180           ; offset = 6
b_zoffs7        equ $000001c0           ; offset = 7    UNUSED

; Width d09-d14
;       width used for address generation
;       This is a 6-bit floating point value in pixels
;       4-bit unsigned exponent
;       2-bit mantissa with implied 3rd bit of 1
b_wid2          equ $00000800           ; 1.00 X 2^1  ( 4<<9)
b_wid4          equ $00001000           ; 1.00 X 2^2  ( 8<<9)
b_wid6          equ $00001400           ; 1.10 X 2^2  (10<<9)
b_wid8          equ $00001800           ; 1.00 x 2^3  (12<<9)
b_wid10         equ $00001a00           ; 1.01 X 2^3  (13<<9)
b_wid12         equ $00001c00           ; 1.10 X 2^3  (14<<9)
b_wid14         equ $00001e00           ; 1.11 X 2^3  (15<<9)
b_wid16         equ $00002000           ; 1.00 X 2^4  (16<<9)
b_wid20         equ $00002200           ; 1.01 X 2^4  (17<<9)
b_wid24         equ $00002400           ; 1.10 X 2^4  (18<<9)
b_wid28         equ $00002600           ; 1.11 X 2^4  (19<<9)
b_wid32         equ $00002800           ; 1.00 X 2^5  (20<<9)
b_wid40         equ $00002a00           ; 1.01 X 2^5  (21<<9)
b_wid48         equ $00002c00           ; 1.10 X 2^5  (22<<9)
b_wid56         equ $00002e00           ; 1.11 X 2^5  (23<<9)
b_wid64         equ $00003000           ; 1.00 X 2^6  (24<<9)
b_wid80         equ $00003200           ; 1.01 X 2^6  (25<<9)
b_wid96         equ $00003400           ; 1.10 X 2^6  (26<<9)
b_wid112        equ $00003600           ; 1.11 X 2^6  (27<<9)
b_wid128        equ $00003800           ; 1.00 X 2^7  (28<<9)
b_wid160        equ $00003a00           ; 1.01 X 2^7  (29<<9)
b_wid192        equ $00003c00           ; 1.10 X 2^7  (30<<9)
b_wid224        equ $00003e00           ; 1.11 X 2^7  (31<<9)
b_wid256        equ $00004000           ; 1.00 X 2^8  (32<<9)
b_wid320        equ $00004200           ; 1.01 X 2^8  (33<<9)
b_wid384        equ $00004400           ; 1.10 X 2^8  (34<<9)
b_wid448        equ $00004600           ; 1.11 X 2^8  (35<<9)
b_wid512        equ $00004800           ; 1.00 X 2^9  (36<<9)
b_wid640        equ $00004a00           ; 1.01 X 2^9  (37<<9)
b_wid768        equ $00004c00           ; 1.10 X 2^9  (38<<9)
b_wid896        equ $00004e00           ; 1.11 X 2^9  (39<<9)
b_wid1024       equ $00005000           ; 1.00 X 2^10 (40<<9)
b_wid1280       equ $00005200           ; 1.01 X 2^10 (41<<9)
b_wid1536       equ $00005400           ; 1.10 X 2^10 (42<<9)
b_wid1792       equ $00005600           ; 1.11 X 2^10 (43<<9)
b_wid2048       equ $00005800           ; 1.00 X 2^11 (44<<9)
b_wid2560       equ $00005a00           ; 1.01 X 2^11 (45<<9)
b_wid3072       equ $00005c00           ; 1.10 X 2^11 (46<<9)
b_wid3584       equ $00005e00           ; 1.11 X 2^11 (47<<9)

; X add control d16-d17
;       controls the update of the X pointer on each pass
;       round the inner loop
b_xaddphr       equ $00000000           ; 00 - add phrase width and truncate
b_xaddpix       equ $00010000           ; 01 - add pixel size (add 1)
b_xadd0         equ $00020000           ; 10 - add zero
b_xaddinc       equ $00030000           ; 11 - add the increment

; Y add control d18
;       controls the update of the Y pointer within the inner loop.
;       it is overridden by the X add control if they are in add increment
b_yadd0         equ $00000000           ; 00 - add zero
b_yadd1         equ $00040000           ; 01 - add 1

; X sign d19
;       add or subtract pixel size if X add control = 01 (XADDPIX)
b_xsignadd      equ $00000000           ; 0 - add pixel size
b_xsignsub      equ $00080000           ; 1 - subtract pixel size

; X sign d20
;       add or subtract pixel size if X add control = 01 (YADD1)
b_ysignadd      equ $00000000           ; 0 - add 1
b_ysignsub      equ $00100000           ; 1 - sub 1
;* added 02/24/95 B.SCHICK
b_mask          equ 1<<15
                endpart
                endpart

                org $00004000

                path 'D:\FIRE.JAG\'
                opt P+
                base A6,basis

;>rgb16           set %0000010011000111
;rgb16           set %0000011001000111
rgb16           equ $000006c7
;>rgb16           set %0000111001000111

object          equ $000f0000
screen          equ $00100000
firedata        equ $00180000

jag:
jag_prg:
                >PART 'INIT'
* created 24.09.95
* (c) Bastian Schick
*
* setup OP,GPU,DSP,CPU to a defined state
* OP = STOP (at $0)
* DSP,GPU : big-endian,stopped,IRQs disabled
* dummy irq
* inits SP to $1000
* stops PIT and JPIT1 & 2
* 68k-SR set to $2000
* CPU-IRQs disabled
* CPU registers are cleared (for debug purposes)
;-----------------
;--    INIT     --
init:           move    #$2700,sr
                lea     $00001000.w,sp
                lea     $00f00000,a0
                move.l  #$00070007,d0   ; big endian
                move.l  d0,$210c(a0)
                move.l  d0,$00f1a10c
                moveq   #0,d0
                move.l  d0,$2114(a0)    ; stop gpu
                move.l  d0,$00f1a114    ; stop dsp
                move.l  d0,$2100(a0)    ; disable GPU-IRQs
; disable DSP-IRQs
                move.l  #%00000000000000010001111100000000,$00f1a100
                move.l  #%0000000000111111<<8,$00f10020 ; clear and disable IRQs

                move.l  d0,0.w
                moveq   #4,d0
                move.l  d0,4.w
                moveq   #0,d0
                move.l  d0,$0020(a0)    ; set OP to STOP-OBJECT
                move.w  d0,$0026(a0)    ; clear OP-Flag
                move.l  d0,$002a(a0)    ; border black
                move.w  d0,$0056(a0)    ; set CRY mode to color/not BW
                move.w  d0,$0058(a0)    ; background black
                move.l  d0,$0050(a0)    ; stop PIT
                move.l  d0,$00f10000    ; stop JPIT1
                move.l  d0,$00f10004    ; stop JPIT2
                move.l  #$1f00<<16,$00e0(a0) ; clear pending irqs
                move.w  #$7fff,$004e(a0) ; no VI
                lea     dummy_irq(pc),a0
                move.l  a0,$00000100.w
                bra.s   init1
dummy_irq:      move.l  #$1f00<<16,$00f000e0
                rte
init1:          moveq   #0,d0
                moveq   #0,d1
                moveq   #0,d2
                moveq   #0,d3
                moveq   #0,d4
                moveq   #0,d5
                moveq   #0,d6
                moveq   #0,d7
                movea.l d0,a0
                movea.l d0,a1
                movea.l d0,a2
                movea.l d0,a3
                movea.l d0,a4
                movea.l d0,a5
                movea.l d0,a6
                move    a0,usp
;-----------------
                endpart
                >PART 'Main'
                lea     $00008000,sp
;>                lea     $00003ffc.w,sp
                lea     basis(pc),a6

                bsr     initvideo
                bsr     createobjects
                bsr     initop

                lea     0.w,a0
                bsr     jagpad

                clr.l   $00000800

                bsr     fire_init

                bsr     text_cls
                lea     text1(pc),a0
                bsr     text_print

                lea     text2(pc),a0
                bsr     text_print

                move.l  #$0000ffff,clut
                move.l  #$0000ffff,$00000800

                clr.w   bord1
                clr.w   bord2

;            ----------

wait:

waitbut:        stop    #$2000
                move.l  #$0000ffff,$00000800.w
                clr.l   $00000800.w
                bsr     vsync
                bsr     jagdebug
                bsr.s   some
                bra.s   wait

                endpart
                >PART 'SomeEffect'

some:           lea     firedata+160*2*198,a6
                move.l  start(pc),d0
                move.l  start+4(pc),d1
                move.l  #$62951413,d2
                move.l  $91827364,d3
                move.w  #320-1,d7
some1:          move.l  d0,d4
                and.w   #63*2,d4
                add.w   #63*2,d4
                move.w  d4,(a6)+
                eor.l   d1,d0
                rol.l   #3,d0
                addq.l  #1,d0
                dbra    d7,some1
                lea     start(pc),a0
                move.l  d0,(a0)+
                eor.l   d2,d1
                ror.l   #5,d1
                subq.l  #2,d1
                move.l  d1,(a0)

                bra.s   zonk

                rts

start:          dc.l $31415926
                dc.l $83458922

zonk:           lea     angle(pc),a0
                move.w  #511,d1
                addq.w  #4,(a0)
                and.w   d1,(a0)
                move.w  (a0)+,d0
                addq.w  #3,(a0)
                and.w   d1,(a0)
                move.w  (a0),d1
                lsl.w   #1,d0
                lsl.w   #1,d1
                lea     cos(pc),a0
                lea     sin(pc),a1
                move.w  0(a1,d1.w),d1
                move.w  0(a0,d0.w),d0
                muls    #((160-8)/2)-1,d0
                muls    #((200-8)/2)-1,d1
                add.l   d0,d0
                add.l   d1,d1
                swap    d0
                swap    d1
                add.w   #(160/2),d0
                add.w   #(200/2),d1

                lea     firedata,a0
                adda.w  d0,a0
                adda.w  d0,a0
                mulu    #(160)*2,d1
                adda.l  d1,a0
                move.w  #63*4,d0
                moveq   #3,d1
as:             move.w  d0,(a0)+
                move.w  d0,(a0)+
                move.w  d0,(a0)+
                move.w  d0,(a0)+
                lea     160*2-2*4(a0),a0
                dbra    d1,as

                rts
angle:          ds.w 1
                ds.w 1

                endpart
                >PART 'sinus'
sin:            dc.w $0000,$0192,$0324,$04b6,$0647,$07d9,$096a,$0afb,$0c8b,$0e1b
                dc.w $0fab,$1139,$12c8,$1455,$15e2,$176d,$18f8,$1a82,$1c0b,$1d93
                dc.w $1f19,$209f,$2223,$23a6,$2528,$26a8,$2826,$29a3,$2b1f,$2c98
                dc.w $2e11,$2f87,$30fb,$326e,$33de,$354d,$36ba,$3824,$398c,$3af2
                dc.w $3c56,$3db8,$3f17,$4073,$41ce,$4325,$447a,$45cd,$471c,$4869
                dc.w $49b4,$4afb,$4c3f,$4d81,$4ebf,$4ffb,$5133,$5269,$539b,$54ca
                dc.w $55f5,$571d,$5842,$5964,$5a82,$5b9d,$5cb4,$5dc7,$5ed7,$5fe3
                dc.w $60ec,$61f1,$62f2,$63ef,$64e8,$65dd,$66cf,$67bd,$68a6,$698c
                dc.w $6a6d,$6b4a,$6c24,$6cf9,$6dca,$6e96,$6f5f,$7023,$70e2,$719e
                dc.w $7255,$7307,$73b5,$745f,$7504,$75a5,$7641,$76d9,$776c,$77fa
                dc.w $7884,$7909,$798a,$7a05,$7a7d,$7aef,$7b5d,$7bc5,$7c29,$7c89
                dc.w $7ce3,$7d39,$7d8a,$7dd6,$7e1d,$7e5f,$7e9d,$7ed5,$7f09,$7f38
                dc.w $7f62,$7f87,$7fa7,$7fc2,$7fd8,$7fe9,$7ff6,$7ffd,$8000,$7ffd
cos:            dc.w $7fff,$7fe9,$7fd8,$7fc2,$7fa7,$7f87,$7f62,$7f38,$7f09,$7ed5
                dc.w $7e9d,$7e5f,$7e1d,$7dd6,$7d8a,$7d39,$7ce3,$7c89,$7c29,$7bc5
                dc.w $7b5d,$7aef,$7a7d,$7a05,$798a,$7909,$7884,$77fa,$776c,$76d9
                dc.w $7641,$75a5,$7504,$745f,$73b5,$7307,$7255,$719e,$70e2,$7023
                dc.w $6f5f,$6e96,$6dca,$6cf9,$6c24,$6b4a,$6a6d,$698c,$68a6,$67bd
                dc.w $66cf,$65dd,$64e8,$63ef,$62f2,$61f1,$60ec,$5fe3,$5ed7,$5dc7
                dc.w $5cb4,$5b9d,$5a82,$5964,$5842,$571d,$55f5,$54ca,$539b,$5269
                dc.w $5133,$4ffb,$4ebf,$4d81,$4c3f,$4afb,$49b4,$4869,$471c,$45cd
                dc.w $447a,$4325,$41ce,$4073,$3f17,$3db8,$3c56,$3af2,$398c,$3824
                dc.w $36ba,$354d,$33de,$326e,$30fb,$2f87,$2e11,$2c98,$2b1f,$29a3
                dc.w $2826,$26a8,$2528,$23a6,$2223,$209f,$1f19,$1d93,$1c0b,$1a82
                dc.w $18f8,$176d,$15e2,$1455,$12c8,$1139,$0fab,$0e1b,$0c8b,$0afb
                dc.w $096a,$07d9,$0647,$04b6,$0324,$0192,$0000,$fe6e,$fcdc,$fb4a
                dc.w $f9b9,$f827,$f696,$f505,$f375,$f1e5,$f055,$eec7,$ed38,$ebab
                dc.w $ea1e,$e893,$e708,$e57e,$e3f5,$e26d,$e0e7,$df61,$dddd,$dc5a
                dc.w $dad8,$d958,$d7da,$d65d,$d4e1,$d368,$d1ef,$d079,$cf05,$cd92
                dc.w $cc22,$cab3,$c946,$c7dc,$c674,$c50e,$c3aa,$c248,$c0e9,$bf8d
                dc.w $be32,$bcdb,$bb86,$ba33,$b8e4,$b797,$b64c,$b505,$b3c1,$b27f
                dc.w $b141,$b005,$aecd,$ad97,$ac65,$ab36,$aa0b,$a8e3,$a7be,$a69c
                dc.w $a57e,$a463,$a34c,$a239,$a129,$a01d,$9f14,$9e0f,$9d0e,$9c11
                dc.w $9b18,$9a23,$9931,$9843,$975a,$9674,$9593,$94b6,$93dc,$9307
                dc.w $9236,$916a,$90a1,$8fdd,$8f1e,$8e62,$8dab,$8cf9,$8c4b,$8ba1
                dc.w $8afc,$8a5b,$89bf,$8927,$8894,$8806,$877c,$86f7,$8676,$85fb
                dc.w $8583,$8511,$84a3,$843b,$83d7,$8377,$831d,$82c7,$8276,$822a
                dc.w $81e3,$81a1,$8163,$812b,$80f7,$80c8,$809e,$8079,$8059,$803e
                dc.w $8000,$8017,$800a,$8003,$8000,$8003,$800a,$8017,$8028,$803e
                dc.w $8059,$8079,$809e,$80c8,$80f7,$812b,$8163,$81a1,$81e3,$822a
                dc.w $8276,$82c7,$831d,$8377,$83d7,$843b,$84a3,$8511,$8583,$85fb
                dc.w $8676,$86f7,$877c,$8806,$8894,$8927,$89bf,$8a5b,$8afc,$8ba1
                dc.w $8c4b,$8cf9,$8dab,$8e62,$8f1e,$8fdd,$90a1,$916a,$9236,$9307
                dc.w $93dc,$94b6,$9593,$9674,$975a,$9843,$9931,$9a23,$9b18,$9c11
                dc.w $9d0e,$9e0f,$9f14,$a01d,$a129,$a239,$a34c,$a463,$a57e,$a69c
                dc.w $a7be,$a8e3,$aa0b,$ab36,$ac65,$ad97,$aecd,$b005,$b141,$b27f
                dc.w $b3c1,$b505,$b64c,$b797,$b8e4,$ba33,$bb86,$bcdb,$be32,$bf8d
                dc.w $c0e9,$c248,$c3aa,$c50e,$c674,$c7dc,$c946,$cab3,$cc22,$cd92
                dc.w $cf05,$d079,$d1ef,$d368,$d4e1,$d65d,$d7da,$d958,$dad8,$dc5a
                dc.w $dddd,$df61,$e0e7,$e26d,$e3f5,$e57e,$e708,$e893,$ea1e,$ebab
                dc.w $ed38,$eec7,$f055,$f1e5,$f375,$f505,$f696,$f827,$f9b9,$fb4a
                dc.w $fcdc,$fe6e,$0000,$0192,$0324,$04b6,$0647,$07d9,$096a,$0afb
                dc.w $0c8b,$0e1b,$0fab,$1139,$12c8,$1455,$15e2,$176d,$18f8,$1a82
                dc.w $1c0b,$1d93,$1f19,$209f,$2223,$23a6,$2528,$26a8,$2826,$29a3
                dc.w $2b1f,$2c98,$2e11,$2f87,$30fb,$326e,$33de,$354d,$36ba,$3824
                dc.w $398c,$3af2,$3c56,$3db8,$3f17,$4073,$41ce,$4325,$447a,$45cd
                dc.w $471c,$4869,$49b4,$4afb,$4c3f,$4d81,$4ebf,$4ffb,$5133,$5269
                dc.w $539b,$54ca,$55f5,$571d,$5842,$5964,$5a82,$5b9d,$5cb4,$5dc7
                dc.w $5ed7,$5fe3,$60ec,$61f1,$62f2,$63ef,$64e8,$65dd,$66cf,$67bd
                dc.w $68a6,$698c,$6a6d,$6b4a,$6c24,$6cf9,$6dca,$6e96,$6f5f,$7023
                dc.w $70e2,$719e,$7255,$7307,$73b5,$745f,$7504,$75a5,$7641,$76d9
                dc.w $776c,$77fa,$7884,$7909,$798a,$7a05,$7a7d,$7aef,$7b5d,$7bc5
                dc.w $7c29,$7c89,$7ce3,$7d39,$7d8a,$7dd6,$7e1d,$7e5f,$7e9d,$7ed5
                dc.w $7f09,$7f38,$7f62,$7f87,$7fa7,$7fc2,$7fd8,$7fe9,$7ff6,$7ffd
                endpart
                >PART 'Fire '

image           equ $00f03ec0
line1           equ $00f03d80
line0           equ $00f03c40
next            equ $00f03840
palette         equ $00f03740
gpufire         equ $00f03000

fire_init:      lea     fire_gpucode(pc),a0
                bsr     gpuinit

;            -- palette

                lea     fire_palette(pc),a0
                lea     palette,a1
                moveq   #63,d7
                moveq   #0,d0
fire_i0:        move.w  (a0),d0
                move.w  d0,d1
                move.w  d0,d2
                and.w   #%1111100000000000,d0
                and.w   #%0000011111100000,d1
                and.w   #%0000000000011111,d2
                lsr.w   #5,d1
                lsl.w   #6,d2
                or.w    d1,d0
                or.w    d2,d0
                move.l  d0,(a1)+
                adda.w  #256/64*2,a0
                dbra    d7,fire_i0

;            -- next-table

                lea     next,a0
                lea     nexttab(pc),a1

chk:            move.w  #64*4-1,d7
                moveq   #0,d0
fire_i2:        move.w  d0,d1
                lsr.w   #4,d1
                lsl.w   #2,d1
                move.l  0(a1,d1.w),d2
                ror.l   #8,d2
                move.l  d2,0(a1,d1.w)
                ext.w   d2
                add.w   d0,d2
                bpl.s   fire_i3
                moveq   #0,d2
fire_i3:        cmp.w   #63*3,d2
                ble.s   fire_i3a
                move.w  #63*3,d2
fire_i3a:       ext.l   d2
                lsr.l   #2,d2
                lsl.l   #2,d2
                move.l  d2,(a0)+
                addq.w  #1,d0
                dbra    d7,fire_i2

;            -- init fire data

                lea     firedata,a1
                move.l  a1,$00001000.w
                move.w  #0,d4
                move.w  #200-1,d3
fire_i4:        move.w  #160-1,d2
                move.l  d4,d0
                swap    d0
                lsl.w   #2,d0
fire_i5:        move.w  #0,(a1)+
                dbra    d2,fire_i5
                add.l   #(63<<16)/200,d4
                dbra    d3,fire_i4

;            -- upload gpu code

                moveq   #1,d0
                move.l  d0,gpucr

                rts

nexttab:        dc.l $ffffffff
                dc.l $ffffff02
                dc.l $fefd0303
                dc.l $fefd0304
                dc.l $fefe0303
                dc.l $fdfd0304
                dc.l $fefe0703
                dc.l $fcfd0705
                dc.l $fffe0703
                dc.l $fcfe0706
                dc.l $fffe0703
                dc.l $fcfe0706
                dc.l $fdff0703
                dc.l $fffe0705
                dc.l $ffff0703
                dc.l $ffff0702

fire_palette:   dc.w $0000,$0001,$0002,$0003
                dc.w $0804,$0805,$0806,$0807
                dc.w $1008,$1009,$100a,$100b
                dc.w $180c,$180d,$180e,$180f
                dc.w $2010,$200f,$200e,$200d
                dc.w $280c,$280b,$280a,$2809
                dc.w $3008,$3007,$3006,$3005
                dc.w $3804,$3803,$3802,$3801
                dc.w $4000,$4000,$4000,$4000
                dc.w $4800,$4800,$4800,$4800
                dc.w $5000,$5000,$5000,$5000
                dc.w $5800,$5800,$5800,$5800
                dc.w $6000,$6000,$6000,$6000
                dc.w $6800,$6800,$6800,$6800
                dc.w $7000,$7000,$7000,$7000
                dc.w $7800,$7800,$7800,$7800
                dc.w $8000,$8000,$8020,$8020
                dc.w $8840,$8840,$8860,$8860
                dc.w $9080,$9080,$90a0,$90a0
                dc.w $98c0,$98c0,$98e0,$98e0
                dc.w $a100,$a100,$a120,$a120
                dc.w $a940,$a940,$a960,$a960
                dc.w $b180,$b180,$b1a0,$b1a0
                dc.w $b9c0,$b9c0,$b9e0,$b9e0
                dc.w $c200,$c200,$c220,$c220
                dc.w $ca40,$ca40,$ca60,$ca60
                dc.w $d280,$d280,$d2a0,$d2a0
                dc.w $dac0,$dac0,$dae0,$dae0
                dc.w $e300,$e300,$e320,$e320
                dc.w $eb40,$eb40,$eb60,$eb60
                dc.w $f380,$f380,$f3a0,$f3a0
                dc.w $fbc0,$fbc0,$fbe0,$fbe0
                dc.w $fc00,$fc00,$fc20,$fc20
                dc.w $fc41,$fc41,$fc61,$fc61
                dc.w $fc82,$fc82,$fca2,$fca2
                dc.w $fcc3,$fcc3,$fce3,$fce3
                dc.w $fd04,$fd04,$fd24,$fd24
                dc.w $fd45,$fd45,$fd65,$fd65
                dc.w $fd86,$fd86,$fda6,$fda6
                dc.w $fdc7,$fdc7,$fde7,$fde7
                dc.w $fe08,$fe08,$fe28,$fe28
                dc.w $fe49,$fe49,$fe69,$fe69
                dc.w $fe8a,$fe8a,$feaa,$feaa
                dc.w $fecb,$fecb,$feeb,$feeb
                dc.w $ff0c,$ff0c,$ff2c,$ff2c
                dc.w $ff4d,$ff4d,$ff6d,$ff6d
                dc.w $ff8e,$ff8e,$ffae,$ffae
                dc.w $ffcf,$ffcf,$ffef,$ffef
                dc.w $fff0,$fff0,$fff0,$fff0
                dc.w $fff1,$fff1,$fff1,$fff1
                dc.w $fff2,$fff2,$fff2,$fff2
                dc.w $fff3,$fff3,$fff3,$fff3
                dc.w $fff4,$fff4,$fff4,$fff4
                dc.w $fff5,$fff5,$fff5,$fff5
                dc.w $fff6,$fff6,$fff6,$fff6
                dc.w $fff7,$fff7,$fff7,$fff7
                dc.w $fff8,$fff8,$fff8,$fff8
                dc.w $fff9,$fff9,$fff9,$fff9
                dc.w $fffa,$fffa,$fffa,$fffa
                dc.w $fffb,$fffb,$fffb,$fffb
                dc.w $fffc,$fffc,$fffc,$fffc
                dc.w $fffd,$fffd,$fffd,$fffd
                dc.w $fffe,$fffe,$fffe,$fffe
                dc.w $ffff,$ffff,$ffff,$ffff

                path 'E:\FIRE.JAG\'
fire_gpucode:   ibytes 'FIRE7.O'

                endpart
                >PART 'GPU ...'

gpuinit:        addq.w  #4,a0           ;header berspringen
                lea     gpupc,a1
                clr.l   4(a1)           ;gpu halt
                movea.l (a0)+,a2        ;startadresse
                move.l  a2,(a1)         ;in den pc bertragen
                move.l  (a0)+,d0        ; Lnge in Bytes
                lsr.l   #2,d0           ;Lnge in longs
gpuinit1:       move.l  (a0)+,(a2)+
                dbra    d0,gpuinit1
                sub.l   #$00010000,d0
                bpl.s   gpuinit1
                rts


                endpart
                >PART 'JagDebug'

jagdebug:       bsr.s   jagpad+4
                lea     jagstate(pc),a0
                bsr.s   jagpad+8

                lea     jagstate(pc),a0
                move.l  (a0)+,d0
;>                swap    d0
;>                not.w   d0
;>                and.w   #$c000,d0
;>                beq.s   jagdebug_illegal
                btst    #29,d0
                bne.s   jagdebug_illegal
                rts

jagdebug_illegal:
                illegal

jagstate:       ds.l 4

                endpart
                >PART 'JagPad-Abfrage 2.4J'
jagpad:         base A6,jagpad

                opt P+,O-
                bra     jagpad_init
                bra     jagpad_exec
                bra     jagpad_lyze
                bra     jagpad_code
                opt O+

                dc.b 'JagPad 2.4 Seb/SPR'
                even

jagpad_init:    movem.l d0-d5/a0-a2/a6,-(sp)
                lea     jagpad(pc),a6

                move.l  a0,d0
                beq.s   jagpad_i2
                moveq   #0,d0
jagpad_i1:      tst.l   (a0)+
                beq.s   jagpad_i2
                add.l   d0,d0
                bset    #0,d0
                bra.s   jagpad_i1
jagpad_i2:      move.l  d0,jagpad_cinit(a6)

                move.l  jagpad_cinit(a6),jagpad_cvalid(a6)
                clr.w   jagpad_cstate(a6)
                st      jagpad_release(a6)

                lea     jag_values_0(pc),a2
                lea     jag_table_0(pc),a0
                move.w  #16-1,d4
                move.w  #4*4,d5
                bsr.s   jagpad_i3

                lea     jag_values_1(pc),a2
                lea     jag_table_1(pc),a0
                move.w  #4-1,d4
                move.w  #2*4,d5
                bsr.s   jagpad_i3

                movem.l (sp)+,d0-d5/a0-a2/a6
                rts

jagpad_i3:      move.w  #4-1,d3
jagpad_i4:      move.w  d4,d1
jagpad_i5:      movea.l a2,a1
                move.w  d1,d0
                moveq   #0,d2
jagpad_i6:      lsr.b   #1,d0
                bcc.s   jagpad_i7
                or.l    (a1),d2
jagpad_i7:      addq.w  #4,a1
                tst.b   d0
                bne.s   jagpad_i6
                move.l  d2,(a0)+
                dbra    d1,jagpad_i5
                adda.w  d5,a2
                dbra    d3,jagpad_i4
                rts

jagpad_exec:    movem.l d2-d5/a0-a2,-(sp)

                lea     $00f14000,a0
                lea     jag_table_0(pc),a1
                lea     jag_table_1(pc),a2

                moveq   #0,d0
                moveq   #0,d1

                move.w  #4-1,d5
                move.w  #$ffee,d4

jagpad_1:       move.w  d4,(a0)
                move.b  (a0),d2
                move.b  d2,d3
                and.w   #$000f,d2
                and.w   #$00f0,d3
                lsr.w   #2,d3
                lsl.w   #2,d2
                or.l    0(a1,d2.w),d0
                or.l    0(a1,d3.w),d1

                move.w  d4,(a0)
                move.b  3(a0),d2
                move.b  d2,d3
                and.w   #%0000000000000011,d2
                and.w   #%0000000000001100,d3
                lsl.w   #2,d2
                or.l    0(a2,d2.w),d0
                or.l    0(a2,d3.w),d1

                lea     16*4(a1),a1
                lea     4*4(a2),a2
                rol.b   #1,d4
                bcs.s   jagpad_1

                movem.l (sp)+,d2-d5/a0-a2
                rts

jagpad_lyze:    move.l  d1,-(sp)
                move.l  (a0),4(a0)
                move.l  d0,(a0)+
                eor.l   d0,(a0)
                move.l  (a0)+,d1
                eor.l   d0,(a0)
                move.l  (a0),d0
                and.l   d1,(a0)+
                and.l   d1,d0
                eor.l   d0,(a0)
                move.l  (sp)+,d1
                rts

jagpad_code:    movem.l d2-d6/a6,-(sp)
                lea     jagpad(pc),a6

                cmp.l   jagpad_old(a6),d0
                beq.s   jagpad_c6
                move.l  d0,jagpad_old(a6)
;                tst.l   d0
                beq.s   jagpad_c7
                tst.b   jagpad_release(a6)
                beq.s   jagpad_c6

                clr.w   d3
                move.w  jagpad_cstate(a6),d4
                move.l  jagpad_cvalid(a6),d5

                moveq   #0,d6

jagpad_c1:      move.l  (a0)+,d2
                beq.s   jagpad_c4
                movea.l d2,a1

                btst    d6,d5
                beq.s   jagpad_c3

                cmp.l   0(a1,d4.w),d0
                bne.s   jagpad_c2

                move.w  #4,d3
                sf      jagpad_release(a6)

                tst.l   4(a1,d4.w)
                bne.s   jagpad_c3

                bchg    d6,d1
                move.l  d6,d0

                move.l  jagpad_cinit(a6),jagpad_cvalid(a6)
                clr.w   jagpad_cstate(a6)
                bra.s   jagpad_c6

jagpad_c2:      move.l  d0,d2
                and.l   0(a1,d4.w),d2
                bne.s   jagpad_c3
                bclr    d6,d5

jagpad_c3:      addq.w  #1,d6
                cmp.w   #32,d6
                bne.s   jagpad_c1

jagpad_c4:      add.w   d3,jagpad_cstate(a6)

                tst.l   d5
                bne.s   jagpad_c5
                move.l  jagpad_cinit(a6),d5
                clr.w   jagpad_cstate(a6)

jagpad_c5:      move.l  d5,jagpad_cvalid(a6)
                moveq   #-1,d0

jagpad_c6:      movem.l (sp)+,d2-d6/a6
                rts
jagpad_c7:      st      jagpad_release(a6)
                bra.s   jagpad_c6

jagpad_old:     ds.l 1
jagpad_cinit:   ds.l 1
jagpad_cvalid:  ds.l 1
jagpad_cstate:  ds.w 1
jagpad_release: ds.b 1
                even

jag_values_0:   dc.l $00000001          ;r
                dc.l $00000002          ;l
                dc.l $00000004          ;o
                dc.l $00000008          ;u

                dc.l $80000000          ;*
                dc.l $00800000          ;7
                dc.l $00100000          ;4
                dc.l $00020000          ;1

                dc.l $00010000          ;0
                dc.l $01000000          ;8
                dc.l $00200000          ;5
                dc.l $00040000          ;2

                dc.l $40000000          ;#
                dc.l $02000000          ;9
                dc.l $00400000          ;6
                dc.l $00080000          ;3

jag_values_1:   dc.l $20000000          ;pause
                dc.l $00000180          ;a

                dc.l $00000000
                dc.l $00000280          ;b

                dc.l $00000000
                dc.l $00000480          ;c

                dc.l $00000000
                dc.l $10000000          ;option

                dc.b "(c)'95"

jag_table_0:    ds.l 16
                ds.l 16
                ds.l 16
                ds.l 16

jag_table_1:    ds.l 4
                ds.l 4
                ds.l 4
                ds.l 4

                opt P-

                base A6,OFF


                endpart
                >PART 'videoinit'

initvideo:      lea     $00f00000,a0
                clr.w   $0026(a0)       ;object processor flag
                clr.w   $0028(a0)       ;video mode

                move.w  #856,$002e(a0)  ;horizontal period

                move.w  #203,$0038(a0)  ;horizontal display begin 1
                move.w  #203,$003a(a0)  ;horizontal display begin 2
                move.w  #1665,$003c(a0) ;horizontal display end

                move.w  #619+2,$003e(a0) ;vertical period
                move.w  #610+2,$0040(a0) ;vertical blank begin
                move.w  #20,$0042(a0)   ;vertical blank end
                move.w  #610+2,$0044(a0) ;vertical sync

                move.w  #84,$0046(a0)   ;vertical display begin
                move.w  #518,$0048(a0)  ;vertical display end
                move.w  #519,$004e(a0)  ;vertical interrupt

                move.w  #782,$0054(a0)  ;horizontal equalization end

                move.w  #$ffff,bord1
                move.w  #$ff00,bord2

                rts

                endpart
                >PART 'CreateObjects'
createobjects:  movem.l d0-a6,-(sp)

                lea     obj(pc),a0
                lea     object+32,a1


;>                bra.s   s

                lea     screen,a2
                moveq   #0,d0           ;bit mapped object
                move.w  #(284-200),d1   ;ypos
                move.w  #200,d2         ;height
                move.w  #(320-160)/2+16,d3 ;xpos
                moveq   #(160)/4,d4     ;width (phrase)
                moveq   #4,d5           ;bits per pixel (2^4=16)
                moveq   #1,d6           ;pitch
                moveq   #(160)/4,d7     ;width (phrase)
                bsr     makeobject
                lea     32(a0),a0
                lea     32(a1),a1       ;next link adress
s:

                lea     textscrn(pc),a2
                moveq   #0,d0           ;bit mapped object
                move.w  #(284-200),d1   ;ypos
                move.w  #200,d2         ;height
                move.w  #(320-128)/2+16,d3 ;xpos
;>                clr.w   d3
                moveq   #(128/8)/8,d4   ;width (phrase)
                moveq   #4,d5
                swap    d5
                moveq   #1,d6           ;pitch
                moveq   #(128/8)/8,d7   ;width (phrase)
                bsr     makeobject
                lea     32(a0),a0
                lea     32(a1),a1       ;next link adress

;>                bsr     text_cls

                move.l  #$0000ffff,clut

;            -- Stop object

                clr.l   (a0)+
                moveq   #4,d0
                move.l  d0,(a0)+

                movem.l (sp)+,d0-a6
                rts

                endpart
                >PART 'InitOP'
initop:         lea     $00f00000,a1

;>                moveq   #4,d0
;>                lea     $00080000,a0
;>                clr.l   (a0)
;>                move.l  d0,4(a0)

                move.l  #object,d0
                swap    d0
;>                moveq   #8,d0
                move.l  d0,$0020(a1)    ;object list pointer
                clr.w   $0026(a1)       ;object processor flag
                move.w  #rgb16,$0028(a1) ;video mode

                move.l  #$00ff0000,$002a(a1) ;border colour

                clr.w   $0058(a1)       ;background colour
                move.w  #$1f01,$00e0(a1) ;cpu interrupt control register
                clr.w   $00e2(a1)       ;cpu interrupt resume register

;            -- Interrupts erlauben

                move    sr,d0
                lea     irq(pc),a0
                move.l  a0,$00000100.w
                and.w   #$f8ff,d0
                move    d0,sr

                rts
                endpart
                >PART 'do_obj'
objcopy:        movem.l d1/a0-a1,-(sp)
                moveq   #4,d1
                lea     object,a1
                lea     obj(pc),a0
objcopy1:       move.l  (a0),(a1)+
                cmp.l   (a0)+,d1
                bne.s   objcopy1
                movem.l (sp)+,d1/a0-a1
                rts
                endpart
                >PART 'Interrupt Handler'

irq:            ori     #$0700,sr

                movem.l d0-a6,-(sp)
                move.w  $00f000e0,d0
                btst    #0,d0
                beq.s   irq_novi
                bsr.s   objcopy
                lea     vblc(pc),a0
                addq.l  #1,(a0)
irq_novi:       move.w  #$0101,$00f000e0
                clr.w   $00f000e2
                movem.l (sp)+,d0-a6
                rte

vsync:          move.l  vblc(pc),d0
vsync1:         cmp.l   vblc(pc),d0
                beq.s   vsync1
                rts
vblc:           ds.l 1
                endpart
                PART 'MakeObject'

; ---------------------
;
;               Objekt generieren
;
;            -> a0.l      Ziel-Adresse
;               a1.l      Link-Adresse
;               a2.l      Data
;
;               d0.w      Type
;               d1.w      Ypos
;               d2.w      Hhe
;               d3.w      Xpos
;               d4.w      Breite in Phrase
;               d5.w lo   Bits per Pixel (2^d5)
;                    hi   Bits
;               d6.w      Pitch
;               d7.w lo   Bild-Breite in Phrase
;                    hi   Farb-Index
;
; ---------------------

makeobject:     movem.l d0-a2,-(sp)
                ext.l   d0              ;0-2  : type

                and.w   #$07ff,d1       ;3-13 : ypos
                lsl.w   #3,d1
                or.w    d1,d0

                and.w   #$03ff,d2       ;14-23 : height
                ext.l   d2
                swap    d2
                lsr.l   #2,d2
                or.l    d2,d0

                move.l  a1,d1           ;24-42 : Link
                lsr.l   #3,d1
                move.l  d1,d2

                ror.l   #8,d2
                and.l   #$ff000000,d2
                or.l    d2,d0
                lsr.l   #8,d1
                and.w   #$07ff,d1
                ext.l   d1

                move.l  a2,d2           ;43-63 : Data
                and.w   #$fff8,d2
                lsl.l   #8,d2
                or.l    d2,d1

                move.l  d1,(a0)+
                move.l  d0,(a0)+

;            -- phrase 2

                and.w   #$07ff,d3       ;0-11 : xpos
                ext.l   d3

                and.w   #7,d5           ;12-14 : bits per pixel
                ror.w   #4,d5
                or.w    d5,d3

                and.w   #7,d6           ;15-17 : pitch
                ext.l   d6
                swap    d6
                lsr.l   #1,d6
                or.l    d6,d3

                and.w   #$03ff,d4       ;18-27 : datawidth (phrases)
                lsl.w   #2,d4
                swap    d4
                or.l    d4,d3

                and.w   #$03ff,d7       ;28-37 : imagewidth (phrases)
                moveq   #$0f,d0
                and.w   d7,d0
                ror.w   #4,d0
                swap    d0
                or.l    d0,d3

                lsr.w   #4,d7
                move.w  d7,d0
                ext.l   d0
                swap    d7              ;38-44 : colour index
                and.w   #$007f,d7
                ext.l   d7
                lsl.l   #6,d7
                or.l    d7,d0

                and.l   #$001f0000,d5   ;49-54 : firstpix flags
                lsr.l   #3,d5
                or.l    d5,d0
                move.l  d0,(a0)+
                move.l  d3,(a0)+

                movem.l (sp)+,d0-a2
                rts
                endpart
                >PART 'Text ...'

                base A6,text_var

text_print:     lea     textscrn(pc),a3
                lea     text_font(pc),a4
                lea     text_var(pc),a6

                bsr.s   text_calcpos
                lea     0(a3,d0.l),a2
                adda.l  d1,a3

                move.w  text_x(a6),d1
                move.w  text_y(a6),d2
                moveq   #40,d3
                moveq   #25,d4

text_print1:    clr.w   d0
                move.b  (a0)+,d0
                ble.s   text_esc
                lsl.w   #3,d0
                lea     0(a4,d0.w),a5
c               set 0
                rept 8
                move.b  (a5)+,128/8*c(a2)
c               set c+1
                endr
                addq.w  #1,a2

                addq.w  #1,d1
                cmp.w   d3,d1
                blt.s   text_print1

                moveq   #0,d1
                lea     128/8*8(a3),a3
                movea.l a3,a2
                addq.w  #1,d2
                cmp.w   d4,d2
                blt.s   text_print1

                bra.s   text_print1

                rts

text_esc:       clr.w   d1
                move.w  d1,text_x(a6)
                addq.w  #1,d2
                move.w  d2,text_y(a6)
                rts

text_calcpos:   move.w  text_y(a6),d0
                mulu    #128/8*8,d0
                move.l  d0,d1
                add.w   text_x(a6),d0
                rts

text_var:
text_x:         dc.w 1
text_y:         dc.w 13

text1:          dc.b "  Mururoa 1995"
                dc.b 0
text2:          dc.b "   PHOBYX Tours"
                dc.b 0
                even

text_char:      lea     textscrn(pc),a1
                lea     text_font(pc),a2

                move.w  #"A",d0
                lsl.w   #3,d0
                adda.w  d0,a2
c               set 0
                rept 8
                move.b  (a2)+,128/8*c(a1)
c               set c+1
                endr

                rts

text_cls:       lea     textscrn(pc),a0
                move.w  #128*200/8/16-1,d1
                moveq   #0,d0
text_cls1:      move.l  d0,(a0)+
                move.l  d0,(a0)+
                move.l  d0,(a0)+
                move.l  d0,(a0)+
                dbra    d1,text_cls1
                rts

                base A6,OFF

                path 'E:\JAGUAR\'
text_font:      ibytes 'ASCII8.BIN'

                endpart
                ds.b 1024
jag_end:

; ----------------------------------------------------------------------------

                bss

basis:

                ds.b 8-((*-jag_prg)&7)
textscrn:       ds.b 128*200/8

                ds.b 16-((*-jag_prg)&15)
obj:            ds.l 10*4

fini:


                end
