section display_320_200_1x1,code
;******************************************************************************
;*
;* 320*200 1x1 c2p screen module
;*
;* ..
;*
Display_320_200_1x1:
;*******************************
;* routines
;*
DC.L Init ; availability of the hardware/autoconfiguration
DC.L Open ; open the screen, allocate hardware, etc..
DC.L Update ; update (screen, palette, brightness..)
DC.L Close ; close screen, deallocate hardware, etc..
DC.L BlitIntServer ; read here the pointer to the int routine
FinishedServer: DC.L DefaultRts ; write here the addr of the "end_of_c2p" routine
DC.L 0 ; (was) update bottom 181..199 Y coord screen
DC.L 0 ; (was) update right 256..319 X coord screen
DC.L ScreenShot ; grab screen and make an IFF picture
;*
;*******************************
;* read only variables
;*
c2p_busy DC.L 0 ;flag (LONGWORD/BYTE) 0=free -1=busy
ScreenA_pt DC.L ScreenA ;^ to the screen A
ScreenB_pt DC.L ScreenB ;^ to the screen B
screen_showed DC.L 0 ;^ to the screen being showed
screen_updated DC.L 0 ;^ to the screen being updated by the c2p
DC.L 0 ;(was) ^ to the screen 256..319 X coordinate
DC.L 0 ;(was) ^ to the screen 180..199 Y coordinate
Iff_pt DC.L IFF ;^ to the IFF 320*200 ILBM buffer
;*
;*******************************
;* variables (write here) - run time
;*
chunky_pt DC.L 0 ;^ to the chunky screen
chunky_mode DC.L 0 ;0=linear 1=shuffled
PaletteA_pt DC.L 0 ;^ to a table. 256 colors; LONGWORDS (black)
Palette_pt DC.L 0 ;^ to a table. 256 colors; LONGWORDS
PaletteB_pt DC.L 0 ;^ to a table. 256 colors; LONGWORDS (white)
fade DC.L $1000000 ;0..256..512 *64K (0=pal_a, 256=pal, 512=pal_b)
Y_mode DC.L 0 ;0=bottom_left 1=top_left
h_center DC.L 0 ;30 Khz horizontal centering
v_center DC.L 0 ;30 Khz vertical centering
synch_mode DC.L 0 ; 0=PAL 1=NTSC 2=DBLPAL 3=DBLNTSC 4/5=1942
;*
;*******************************
;* variables - last copy
;*
old_PaletteA_pt DC.L 0 ;^ to a table. 256 colors; LONGWORDS (black)
old_Palette_pt DC.L 0 ;^ to a table. 256 colors; LONGWORDS
old_PaletteB_pt DC.L 0 ;^ to a table. 256 colors; LONGWORDS (white)
old_fade DC.L 0 ;0..256..512 *64K (0=pal_a, 256=pal, 512=pal_b)
old_Y_mode DC.L 0 ;0=bottom_left 1=top_left
old_h_center DC.L 0 ;30 Khz horizontal centering
old_v_center DC.L 0 ;30 Khz vertical centering
old_synch_mode DC.L 0 ; 0=PAL 1=NTSC 2=DBLPAL 3=DBLNTSC 4/5=1942
;*
;******************************************************************************
;*
;* Init
;*
Init: MOVEM.L D0-D7/A0-A6,-(SP)
jsr Check_Chipset
beq.b .error
move.l #ScreenA,ScreenA_pt
move.l #ScreenB,ScreenB_pt
.success moveq #-1,d0
bra.b .exit
.error moveq #0,d0
.exit MOVEM.L (SP)+,D0-D7/A0-A6
rts
;* End of
;******************************************************************************
;*
;* Open
;*
Open: move.l #-1,old_PaletteA_pt
move.l #-1,old_Palette_pt
move.l #-1,old_PaletteB_pt
move.l #-1,old_fade
move.l #-1,old_Y_mode
move.l #$7FFFFFFF,old_h_center
move.l #$7FFFFFFF,old_v_center
move.l #-1,old_synch_mode
move.l #ScreenB,screen_showed
move.l #ScreenA,screen_updated
sf screen_x
JSR SetSPRPT
rts
;* End of
;******************************************************************************
;*
;* Update
;*
Update: MOVEM.L D0-D7/A0-A6,-(SP)
move.l synch_mode,D0
cmp.l old_synch_mode,D0
bne.w .synch
move.l h_center,D0
cmp.l old_h_center,D0
bne.w .synch
move.l v_center,D0
cmp.l old_v_center,D0
bne.w .synch
.synch_ok move.l Y_mode,D0
cmp.l old_Y_mode,D0
bne.w .Y_mode
.Y_mode_ok move.l fade,D0
cmp.l old_fade,D0
bne.w .palette
tst.l D0
beq.b .palA
cmp.l #256*65536,d0
beq.b .pal
blt.b .palA_x
cmp.l #512*65536,d0
beq.b .palB
blt.b .palx_B
bra.b .palette_ok
.palA move.l old_PaletteA_pt,d1
cmp.l PaletteA_pt,d1
bne.w .palette
bra.b .palette_ok
.palA_x move.l old_PaletteA_pt,d1
cmp.l PaletteA_pt,d1
bne.w .palette
move.l old_Palette_pt,d1
cmp.l Palette_pt,d1
bne.w .palette
bra.b .palette_ok
.pal move.l old_Palette_pt,d1
cmp.l Palette_pt,d1
bne.w .palette
bra.b .palette_ok
.palx_B move.l old_Palette_pt,d1
cmp.l Palette_pt,d1
bne.b .palette
move.l old_PaletteB_pt,d1
cmp.l PaletteB_pt,d1
bne.b .palette
bra.b .palette_ok
.palB move.l old_PaletteB_pt,d1
cmp.l PaletteB_pt,d1
bne.b .palette
.palette_ok jsr C2P
.exit MOVEM.L (SP)+,D0-D7/A0-A6
rts
;***************
.synch jsr SetSynchMode
move.l synch_mode,old_synch_mode
move.l h_center,old_h_center
move.l v_center,old_v_center
move.l Y_mode,old_Y_mode
bra.w .synch_ok
;***************
.Y_mode jsr SetModRegs
move.l Y_mode,old_Y_mode
bra.w .Y_mode_ok
;***************
.palette jsr SetPalette
move.l fade,old_fade
move.l PaletteA_pt,old_PaletteA_pt
move.l Palette_pt,old_Palette_pt
move.l PaletteB_pt,old_PaletteB_pt
bra.w .palette_ok
;* End of Update routine
;******************************************************************************
;*
;* Close
;*
Close: rts
;* End of Close routine
;******************************************************************************
;*
DefaultRts: RTS
;*
;******************************************************************************
;*
Check_Chipset: MOVEM.L D0/D1/D2/A0,-(SP)
lea $dff000,a0 ;CUSTOM
move.w $7c(a0),d0 ;display chip id
moveq #31,d2 ;check 32 times
and.w #$00ff,d0
.loop move.w $7c(a0),d1 ;display chip id
and.w #$00ff,d1
cmp.b d0,d1
bne.b .no_aga ;not the same value, then ocs denise
dbra d2,.loop
or.b #$f0,d0
cmp.b #$fc,d0
beq.b .no_aga
cmp.b #$f8,d0
bne.b .no_aga
move.w 4(a0),d0 ;vposr
and.w #$7f00,d0
lsr.w #8,d0
cmp.w #$22,d0
beq.w .aga
cmp.w #$23,d0
beq.w .aga
cmp.w #$32,d0
beq.w .aga
cmp.w #$33,d0
beq.w .aga
.no_aga moveq #0,d0
bra.b .exit
.aga moveq #-1,d0
.exit MOVEM.L (SP)+,D0/D1/D2/A0
rts
;* End of Check_Chipset routine
;******************************************************************************
;*
SetBplPt: MOVEM.L D0/D1/A0,-(SP)
move.l screen_showed,d0
tst.l Y_mode
bne.b .y1
add.l #(320*199)/8,d0
.y1 move.l #(320*200)/8,d1
lea copper_bpl_pt,a0
move.w d0,$06(a0)
swap d0
move.w d0,$02(a0)
swap d0
add.l d1,d0
move.w d0,$0E(a0)
swap d0
move.w d0,$0A(a0)
swap d0
add.l d1,d0
move.w d0,$16(a0)
swap d0
move.w d0,$12(a0)
swap d0
add.l d1,d0
move.w d0,$1E(a0)
swap d0
move.w d0,$1A(a0)
swap d0
add.l d1,d0
move.w d0,$26(a0)
swap d0
move.w d0,$22(a0)
swap d0
add.l d1,d0
move.w d0,$2E(a0)
swap d0
move.w d0,$2A(a0)
swap d0
add.l d1,d0
move.w d0,$36(a0)
swap d0
move.w d0,$32(a0)
swap d0
add.l d1,d0
move.w d0,$3E(a0)
swap d0
move.w d0,$3A(a0)
MOVEM.L (SP)+,D0/D1/A0
rts
;*
;******************************************************************************
;*
SetSPRPT: MOVEM.L D0/D1/A0,-(SP)
lea copper_spr_pt,a0
move.l #SpriteA,d0
move.w d0,$06(a0)
swap d0
move.w d0,$02(a0)
move.l #SpriteB,d0
move.w d0,$0E(a0)
swap d0
move.w d0,$0A(a0)
MOVEM.L (SP)+,D0/D1/A0
rts
;*
;******************************************************************************
;*
SetPalette: MOVEM.L D0-D7/A0-A4,-(SP)
lea copper_color_hi_256+6,a0
lea copper_color_lo_256+6,a1
move.l #$000F0F0F,d4
move.l #$00F0F0F0,d5
move.l fade,d0
bmi.w .exit
cmp.l #512*65536,d0
bgt.w .exit
swap d0
ext.l d0
beq.b .palA
cmp.l #256,d0
beq.b .pal
blt.b .palA_x
cmp.l #512,d0
beq.b .palB
blt.b .palx_B
bra.w .exit
.palA move.l PaletteA_pt,a2
move.l PaletteA_pt,a3
bra.b .sp
.palA_x move.l Palette_pt,a2
move.l PaletteA_pt,a3
bra.b .sp
.pal move.l Palette_pt,a2
move.l Palette_pt,a3
moveq #0,d0
bra.b .sp
.palx_B move.l PaletteB_pt,a2
move.l Palette_pt,a3
sub.l #256,d0
bra.b .sp
.palB move.l PaletteB_pt,a2
move.l PaletteB_pt,a3
moveq #0,d0
.sp tst.l d0 ;needed due to branchs
beq.b .spnull
.spfade move.l #256,d6 ;d0=fade
sub.l d0,d6 ;d6=256-fade
lea palettebuffer,a4
move.w #256-1,d7
.spfade_loop addq.l #1,a2
moveq #0,d1
move.b (a2)+,d1 ;red0
mulu.w d0,d1
addq.l #1,a3
moveq #0,d2
move.b (a3)+,d2 ;red1
mulu.w d6,d2
add.w d2,d1
lsr.l #8,d1
addq.l #1,a4
move.b d1,(a4)+ ;write red
moveq #0,d1
move.b (a2)+,d1 ;grn0
mulu.w d0,d1
moveq #0,d2
move.b (a3)+,d2 ;grn1
mulu.w d6,d2
add.w d2,d1
lsr.l #8,d1
move.b d1,(a4)+ ;write grn
moveq #0,d1
move.b (a2)+,d1 ;blu0
mulu.w d0,d1
moveq #0,d2
move.b (a3)+,d2 ;blu1
mulu.w d6,d2
add.w d2,d1
lsr.l #8,d1
move.b d1,(a4)+ ;write blu
dbra d7,.spfade_loop
lea palettebuffer,a2
.spnull moveq #8-1,d7
.spnull_loop1 moveq #32-1,d6
.spnull_loop0 move.l (a2)+,d1
move.l d1,d2
and.l d4,d1 ;low
and.l d5,d2
lsr.l #4,d2 ;high
moveq #0,d3
move.b d2,d3
lsr.l #4,d2
or.b d2,d3
lsr.l #4,d2
clr.b d2
or.w d2,d3
move.w d3,(a0)
addq.l #4,a0
moveq #0,d3
move.b d1,d3
lsr.l #4,d1
or.b d1,d3
lsr.l #4,d1
clr.b d1
or.w d1,d3
move.w d3,(a1)
addq.l #4,a1
dbra d6,.spnull_loop0
addq.l #4,a0
addq.l #4,a1
dbra d7,.spnull_loop1
.exit MOVEM.L (SP)+,D0-D7/A0-A4
rts
palettebuffer DS.L 256
;*
;******************************************************************************
;*
;* SetSynchMode
;*
;* 0=Pal - 8 sprites
;* 1=Ntsc - 8 sprites
;* 2=DblPal (30.00Khz 50Hz) - 4 sprites
;* 3=DblNtsc (30.00Khz 60Hz) - 4 sprites
;* 4=Multiscan (31.56Khz 60Hz) - 1 sprite
;* 5=DblPal (30.00Khz 50Hz) - 4 sprites - specific for 1942 monitors (may damage other models)
;* 6=DblNtsc (30.00Khz 60Hz) - 4 sprites - specific for 1942 monitors (may damage other models)
;* 7=Multiscan (31.56Khz 60Hz) - 1 sprite - specific for 1942 monitors (may damage other models)
;*
SetSynchMode: movem.l d0/d1/a0/a1/a2/a3,-(sp)
bsr.w WaitVBL
lea $dff000,a0
move.w #$03A0,$096(a0) ;DMACON - disable bpl/cop/spr
lea copper_bpl_regs+2,a2
lea copper_spr_res+2,a3
move.l synch_mode,d0
bmi.w .exit
cmp.l #8,d0
bge.w .exit
jmp ([.jmptab,pc,d0.l*4])
.jmptab dc.l .pal
dc.l .ntsc
dc.l .dblpal
dc.l .dblntsc
dc.l .multiscan
dc.l .1942dblpal
dc.l .1942dblntsc
dc.l .1942multiscan
.pal bsr.w .sprites_pal
move.w #$0211,8(a2) ;BPLCON0
move.w #$0038,$092(a0) ;DDFSTRT
move.w #$00A8,$094(a0) ;DDFSTOP
move.w #$000F,$1FC(a0) ;FMODE
move.w #$0020,$1DC(a0) ;BEAMCON0
move.w #$4481,$08E(a0) ;DIWSTRT
move.w #$0CC1,$090(a0) ;DIWSTOP
move.w #$0000,$102(a0) ;BPLCON1
move.w #$027F,$104(a0) ;BPLCON2
move.w #$0063,(a3) ;BPLCON3 ;spr res
move.w #$0011,$10C(a0) ;BPLCON4
bra.w .exit
.ntsc bsr.w .sprites_ntsc
move.w #$0211,8(a2) ;BPLCON0
move.w #$0038,$092(a0) ;DDFSTRT
move.w #$00A8,$094(a0) ;DDFSTOP
move.w #$000F,$1FC(a0) ;FMODE
move.w #$0000,$1DC(a0) ;BEAMCON0
move.w #$2C81,$08E(a0) ;DIWSTRT
move.w #$F4C1,$090(a0) ;DIWSTOP
move.w #$0000,$102(a0) ;BPLCON1
move.w #$027F,$104(a0) ;BPLCON2
move.w #$0063,(a3) ;BPLCON3 ;spr res
move.w #$0011,$10C(a0) ;BPLCON4
bra.w .exit
.dblpal bsr.w .v_centering_50
bsr.w .h_centering
move.w #$8211,8(a2) ;BPLCON0
move.w #$0028,$092(a0) ;DDFSTRT
move.w #$0068,$094(a0) ;DDFSTOP
move.w #$C00F,$1FC(a0) ;FMODE
move.w #$0009,$1C4(a0) ;HBSTRT
move.w #$0025,$1C2(a0) ;HSSTOP
move.w #$0031,$1C6(a0) ;HBSTOP
move.w #$0077,$1C0(a0) ;HTOTAL
move.w #$0000,$1CC(a0) ;VBSTRT
move.w #$0003,$1E0(a0) ;VSSTRT
move.w #$0005,$1CA(a0) ;VSSTOP
move.w #$001D,$1CE(a0) ;VBSTOP
move.w #$0258,$1C8(a0) ;VTOTAL
move.w #$0B88,$1DC(a0) ;BEAMCON0
move.w #$0000,$102(a0) ;BPLCON1
move.w #$027F,$104(a0) ;BPLCON2
move.w #$00A3,(a3) ;BPLCON3 ;spr res
move.w #$0011,$10C(a0) ;BPLCON4
bra.w .exit
.dblntsc bsr.w .v_centering_60
bsr.w .h_centering
move.w #$8211,8(a2) ;BPLCON0
move.w #$0028,$092(a0) ;DDFSTRT
move.w #$0068,$094(a0) ;DDFSTOP
move.w #$C00F,$1FC(a0) ;FMODE
move.w #$0009,$1C4(a0) ;HBSTRT
move.w #$0025,$1C2(a0) ;HSSTOP
move.w #$0031,$1C6(a0) ;HBSTOP
move.w #$0077,$1C0(a0) ;HTOTAL
move.w #$0000,$1CC(a0) ;VBSTRT
move.w #$0003,$1E0(a0) ;VSSTRT
move.w #$0005,$1CA(a0) ;VSSTOP
move.w #$001D,$1CE(a0) ;VBSTOP
move.w #$01F4,$1C8(a0) ;VTOTAL
move.w #$0B88,$1DC(a0) ;BEAMCON0
move.w #$0000,$102(a0) ;BPLCON1
move.w #$027F,$104(a0) ;BPLCON2
move.w #$00A3,(a3) ;BPLCON3 ;spr res
move.w #$0011,$10C(a0) ;BPLCON4
bra.w .exit
.multiscan bsr.w .m_centering_60
bsr.w .h_centering_m
move.w #$8211,8(a2) ;BPLCON0
move.w #$0018,$092(a0) ;DDFSTRT
move.w #$0058,$094(a0) ;DDFSTOP
move.w #$C00F,$1FC(a0) ;FMODE
move.w #$0009,$1C4(a0) ;HBSTRT
move.w #$0017,$1C2(a0) ;HSSTOP
move.w #$0021,$1C6(a0) ;HBSTOP
move.w #$0071,$1C0(a0) ;HTOTAL
move.w #$0000,$1CC(a0) ;VBSTRT
move.w #$0003,$1E0(a0) ;VSSTRT
move.w #$0005,$1CA(a0) ;VSSTOP
move.w #$001D,$1CE(a0) ;VBSTOP
move.w #$020E,$1C8(a0) ;VTOTAL
move.w #$0B88,$1DC(a0) ;BEAMCON0
move.w #$0000,$102(a0) ;BPLCON1
move.w #$027F,$104(a0) ;BPLCON2
move.w #$00A3,(a3) ;BPLCON3 ;spr res
move.w #$0011,$10C(a0) ;BPLCON4
bra.w .exit
.1942dblpal bsr.w .v_centering_50
bsr.w .h_centering
move.w #$8211,8(a2) ;BPLCON0
move.w #$0028,$092(a0) ;DDFSTRT
move.w #$0068,$094(a0) ;DDFSTOP
move.w #$C00F,$1FC(a0) ;FMODE
move.w #$0009,$1C4(a0) ;HBSTRT
move.w #$0025,$1C2(a0) ;HSSTOP
move.w #$0031,$1C6(a0) ;HBSTOP
move.w #$0077,$1C0(a0) ;HTOTAL
move.w #$0000,$1CC(a0) ;VBSTRT
move.w #$0005,$1E0(a0) ;VSSTRT
move.w #$0003,$1CA(a0) ;VSSTOP
move.w #$001D,$1CE(a0) ;VBSTOP
move.w #$0258,$1C8(a0) ;VTOTAL
move.w #$0B88,$1DC(a0) ;BEAMCON0
move.w #$0000,$102(a0) ;BPLCON1
move.w #$027F,$104(a0) ;BPLCON2
move.w #$00A3,(a3) ;BPLCON3 ;spr res
move.w #$0011,$10C(a0) ;BPLCON4
bra.w .exit
.1942dblntsc bsr.w .v_centering_60
bsr.w .h_centering
move.w #$8211,8(a2) ;BPLCON0
move.w #$0028,$092(a0) ;DDFSTRT
move.w #$0068,$094(a0) ;DDFSTOP
move.w #$C00F,$1FC(a0) ;FMODE
move.w #$0009,$1C4(a0) ;HBSTRT
move.w #$0025,$1C2(a0) ;HSSTOP
move.w #$0031,$1C6(a0) ;HBSTOP
move.w #$0077,$1C0(a0) ;HTOTAL
move.w #$0000,$1CC(a0) ;VBSTRT
move.w #$0005,$1E0(a0) ;VSSTRT
move.w #$0003,$1CA(a0) ;VSSTOP
move.w #$001D,$1CE(a0) ;VBSTOP
move.w #$01F4,$1C8(a0) ;VTOTAL
move.w #$0B88,$1DC(a0) ;BEAMCON0
move.w #$0000,$102(a0) ;BPLCON1
move.w #$027F,$104(a0) ;BPLCON2
move.w #$00A3,(a3) ;BPLCON3 ;spr res
move.w #$0011,$10C(a0) ;BPLCON4
bra.w .exit
.1942multiscan bsr.w .m_centering_60
bsr.w .h_centering_m
move.w #$8211,8(a2) ;BPLCON0
move.w #$0018,$092(a0) ;DDFSTRT
move.w #$0058,$094(a0) ;DDFSTOP
move.w #$C00F,$1FC(a0) ;FMODE
move.w #$0009,$1C4(a0) ;HBSTRT
move.w #$0017,$1C2(a0) ;HSSTOP
move.w #$0021,$1C6(a0) ;HBSTOP
move.w #$0071,$1C0(a0) ;HTOTAL
move.w #$0000,$1CC(a0) ;VBSTRT
move.w #$0005,$1E0(a0) ;VSSTRT
move.w #$0003,$1CA(a0) ;VSSTOP
move.w #$001D,$1CE(a0) ;VBSTOP
move.w #$020E,$1C8(a0) ;VTOTAL
move.w #$0B88,$1DC(a0) ;BEAMCON0
move.w #$0000,$102(a0) ;BPLCON1
move.w #$027F,$104(a0) ;BPLCON2
move.w #$00A3,(a3) ;BPLCON3 ;spr res
move.w #$0011,$10C(a0) ;BPLCON4
.exit jsr SetModRegs
move.l #copper,$080(a0)
move.w #$8380,$096(a0) ;DMACON - enable mast/bpl/cop/(spr)
move.w #$0000,$088(a0)
movem.l (sp)+,d0/d1/a0/a1/a2/a3
rts
;***************
.h_centering move.l h_center,d0
neg.l d0
cmp.l #8,d0
blt.b .h_lt8
moveq #8,d0
.h_lt8 cmp.l #-8,d0
bgt.b .h_gt8
moveq #-8,d0
.h_gt8 add.l #$001B,d0
move.w D0,$1DE(a0) ;HSSTRT
rts
;***************
.h_centering_m move.l h_center,d0
neg.l d0
cmp.l #8,d0
blt.b .h_m_lt8
moveq #8,d0
.h_m_lt8 cmp.l #-8,d0
bgt.b .h_m_gt8
moveq #-8,d0
.h_m_gt8 add.l #$000D,d0
move.w D0,$1DE(a0) ;HSSTRT
rts
;***************
.sprites_pal move.w #$44C0,SpriteA
move.w #$44C0,SpriteB
move.w #$0C02,SpriteA+8
move.w #$0C82,SpriteB+8
rts
;***************
.sprites_ntsc move.w #$2CC0,SpriteA
move.w #$2CC0,SpriteB
move.w #$F400,SpriteA+8
move.w #$F480,SpriteB+8
rts
;***************
.v_centering_50 move.l v_center,d0
cmp.l #23,d0
blt.b .v_50_lt23
moveq #23,d0
.v_50_lt23 cmp.l #-23,d0
bgt.b .v_50_gt23
moveq #-23,d0
.v_50_gt23 sub.l #10,d0
move.l d0,d1 ;sprites
add.l #$80,d1
move.b d1,SpriteA
move.b d1,SpriteB
move.b #$F0,SpriteA+1
move.b #$F0,SpriteB+1
add.l #$90,d1
move.b d1,SpriteA+8
move.b d1,SpriteB+8
move.b #$20,SpriteA+9
move.b #$A0,SpriteB+9
lsl.l #8,d0
add.l #$80*256,d0
move.b #$61,d0
move.w d0,$08E(a0) ;DIWSTRT
add.l #400*256,d0
move.b #$00,d0
move.w D0,$090(a0) ;DIWSTOP
swap d0
lsl.l #8,d0
move.w d0,$1E4(a0) ;DIWHIGH
rts
;***************
.v_centering_60 move.l v_center,d0
cmp.l #23,d0
blt.b .v_60_lt23
moveq #23,d0
.v_60_lt23 cmp.l #-23,d0
bgt.b .v_60_gt23
moveq #-23,d0
.v_60_gt23 sub.l #10,d0
move.l d0,d1 ;sprites
add.l #$50,d1
move.b d1,SpriteA
move.b d1,SpriteB
move.b #$F0,SpriteA+1
move.b #$F0,SpriteB+1
add.l #$90,d1
move.b d1,SpriteA+8
move.b d1,SpriteB+8
move.b #$02,SpriteA+9
move.b #$82,SpriteB+9
lsl.l #8,d0
add.l #$50*256,d0
move.b #$61,d0
move.w d0,$08E(a0) ;DIWSTRT
add.l #400*256,d0
move.b #$00,d0
move.w D0,$090(a0) ;DIWSTOP
swap d0
lsl.l #8,d0
move.w d0,$1E4(a0) ;DIWHIGH
rts
;***************
.m_centering_60 move.l v_center,d0
add.l #12,d0
cmp.l #23,d0
blt.b .m_60_lt23
moveq #23,d0
.m_60_lt23 cmp.l #-23,d0
bgt.b .m_60_gt23
moveq #-23,d0
.m_60_gt23 sub.l #10,d0
lsl.l #8,d0
add.l #$50*256,d0
move.b #$41,d0
move.w d0,$08E(a0) ;DIWSTRT
add.l #400*256,d0
move.b #$E1,d0
move.w D0,$090(a0) ;DIWSTOP
swap d0
lsl.l #8,d0
move.w d0,$1E4(a0) ;DIWHIGH
rts
;*
;******************************************************************************
;*
;* used by SetYmode and SetSynch
;*
SetModRegs: movem.l d0/a0,-(sp)
lea copper_bpl_regs+2,a0
move.l synch_mode,d0
cmp.l #8,d0
bge.w .exit
jmp ([.jmptab,pc,d0.l*4])
.jmptab dc.l .single
dc.l .single
dc.l .double
dc.l .double
dc.l .double
dc.l .double
dc.l .double
dc.l .double
.single tst.l Y_mode
bne.b .singley1
move.w #-80,0(a0) ;BPL1MOD
move.w #-80,4(a0) ;BPL2MOD
bra.b .singleye
.singley1 move.w #0,0(a0) ;BPL1MOD
move.w #0,4(a0) ;BPL2MOD
.singleye bra.b .exit
.double tst.l Y_mode
bne.b .doubley1
move.w #-40,0(a0) ;BPL1MOD
move.w #-80,4(a0) ;BPL2MOD
bra.b .exit
.doubley1 move.w #-40,0(a0) ;BPL1MOD
move.w #0,4(a0) ;BPL2MOD
.exit movem.l (sp)+,d0/a0
rts
;*
;******************************************************************************
;*
;*
WaitVBL: move.l d0,-(sp)
move.b $BFE801,D0
.wait cmp.b $BFE801,D0
beq.b .wait
move.l (sp)+,d0
rts
;*
;******************************************************************************
;*
;*
ScreenShot: MOVEM.L D0-D7/A0-A6,-(SP)
.exit MOVEM.L (SP)+,D0-D7/A0-A6
rts
;*
;******************************************************************************
;*
;* Chunky2Planar
;*
;* -- thanks to Ola Zandelin for the cpu pass and other hints
;*
C2P: tst.l c2p_busy
bne.b C2P
move.l #-1,c2p_busy
tst.l chunky_mode
bne.b .shuffled
jsr cpu_pass_linear
bra.b .cont
.shuffled jsr cpu_pass_shuffled
.cont jsr blitter_pass
rts
;******************************************************************************
get_pixels_shuffled: macro
movem.l (a0)+,d0-d3
endm
get_pixels_linear: macro
movem.l (a0)+,d1-d3
move.l (a0)+,d0
move.w d2,d4 d4=10,11
swap d0 d0=02,03,00,01
move.w d0,d2 d2=08,09,00,01*
move.w d4,d0 d0=02,03,10,11*
ror.w #8,d0 d0=02,03,11,10
ror.l #8,d0 d0=03,11,10,02
ror.w #8,d0 d0=03,11,02,10
swap d0 d0=02,10,03,11**
ror.w #8,d2 d2=08,09,01,00
ror.l #8,d2 d2=09,01,00,08
swap d2 d2=00,08,09,01
ror.w #8,d2 d2=00,08,01,09**
move.w d3,d4
swap d1
move.w d1,d3
move.w d4,d1
ror.w #8,d3
ror.l #8,d3
ror.w #8,d3
swap d3
ror.w #8,d1
ror.l #8,d1
swap d1
ror.w #8,d1
endm
;**************************************
rotb_4: macro
move.l \1,d4
and.l d6,\1
eor.l \1,d4
lsr.l #4,d4
move.l \2,d5
and.l d6,d5
eor.l d5,\2
lsl.l #4,d5
or.l d5,\1
or.l d4,\2
endm
rotb_2: macro
move.l \1,d4
and.l d6,\1
eor.l \1,d4
lsr.l #2,d4
move.l \2,d5
and.l d6,d5
eor.l d5,\2
lsl.l #2,d5
or.l d5,\1
or.l d4,\2
endm
rotb_1: macro
move.l \1,d4
and.l d6,\1
eor.l \1,d4
lsr.l #1,d4
move.l \2,d5
and.l d6,d5
eor.l d5,\2
lsl.l #1,d5
or.l d5,\1
or.l d4,\2
endm
;******************************************************************************
cpu_only_shuffled:
rts
;******************************************************************************
cpu_only_linear:
rts
;******************************************************************************
cpu_pass_shuffled:
move.l chunky_pt,a0 ; chunky buffer
lea chiptempbuffer,a2 ; chip buffer
move.l #$0f0f0f0f,a3
move.l #$33333333,a4
move.w #((320/16)*200)-2,d7 ; 320*200
.first get_pixels_shuffled
move.l a3,d6 ; * pass 1 *
rotb_4 d0,d1
rotb_4 d2,d3
move.l a4,d6 ; * pass 2 *
rotb_2 d0,d2
move.l d0,(a2)+
rotb_2 d1,d3
move.l d2,a1 ;
move.l d1,a5
move.l d3,a6
.loop get_pixels_shuffled
move.l a3,d6 ; * pass 1 *
move.l a1,(a2)+
rotb_4 d0,d1
move.l a5,(a2)+
rotb_4 d2,d3
move.l a4,d6 ; * pass 2 *
move.l a6,(a2)+
rotb_2 d0,d2
move.l d0,(a2)+
rotb_2 d1,d3
move.l d2,a1 ;
move.l d1,a5
move.l d3,a6
dbra d7,.loop
.last move.l a1,(a2)+
move.l a5,(a2)+
move.l a6,(a2)+
rts
;******************************************************************************
cpu_pass_linear:
move.l chunky_pt,a0 ; chunky buffer
lea chiptempbuffer,a2 ; chip buffer
move.l #$0f0f0f0f,a3
move.l #$33333333,a4
move.w #((320/16)*200)-2,d7 ; 320*200
.first get_pixels_linear
move.l a3,d6 ; * pass 1 *
rotb_4 d0,d1
rotb_4 d2,d3
move.l a4,d6 ; * pass 2 *
rotb_2 d0,d2
move.l d0,(a2)+
rotb_2 d1,d3
move.l d2,a1 ;
move.l d1,a5
move.l d3,a6
.loop get_pixels_linear
move.l a3,d6 ; * pass 1 *
move.l a1,(a2)+
rotb_4 d0,d1
move.l a5,(a2)+
rotb_4 d2,d3
move.l a4,d6 ; * pass 2 *
move.l a6,(a2)+
rotb_2 d0,d2
move.l d0,(a2)+
rotb_2 d1,d3
move.l d2,a1 ;
move.l d1,a5
move.l d3,a6
dbra d7,.loop
.last move.l a1,(a2)+
move.l a5,(a2)+
move.l a6,(a2)+
rts
;******************************************************************************
blitter_pass: move.w #$0040,$DFF09A ;disable blitter interrupt
move.l #blitter_bpl0,next_blit
.wblit btst.b #6,$dff002
bne.b .wblit
move.w #$1BF8,$DFF040 ;(A+BC) SHIFT=1 ACD
move.w #16-2,$DFF064 ;amod
move.w #16-2,$DFF060 ;cmod
move.w #0,$DFF066 ;dmod
move.w #$FFFF,$DFF046 ;alwm
move.w #(320*200)/16,$DFF05C ;vsize
move.w #$0400,$DFF096 ;disable blithog
move.w #$8240,$DFF096 ;enable blitter dma
move.w #$8040,$DFF09C ;start blitter interrupt
move.w #$C040,$DFF09A ;enable blitter interrupt
rts
cnop 0,4
next_blit ds.l 1
;**************************************
BlitIntServer:
DC.L $4EF401F1,next_blit ;JMP ([next_blit])
;**************************************
blitter_bpl0:
move.l #blitter_bpl1,next_blit
move.w #$0002,$DFF042 ;DescendingMode
move.w #$5555,$DFF072 ;bdat
move.w #$5555,$DFF044 ;afwm
move.l #chiptempbuffer10b_d,$DFF050 ;apt
move.l #chiptempbuffer10a_d,$DFF048 ;cpt
tst.b screen_x
bne.b .b
move.l #ScreenA_bpl0e-2,$DFF054 ;dpt
bra.b .e
.b move.l #ScreenB_bpl0e-2,$DFF054 ;dpt
.e move.w #1,$DFF05E ;hsize & start
rts
;**************************************
blitter_bpl1:
move.l #blitter_bpl2,next_blit
move.w #$0000,$DFF042 ;AscendingMode
move.w #$AAAA,$DFF072 ;bdat
move.w #$AAAA,$DFF044 ;afwm
move.l #chiptempbuffer10a_a,$DFF050 ;apt
move.l #chiptempbuffer10b_a,$DFF048 ;cpt
tst.b screen_x
bne.b .b
move.l #ScreenA_bpl1,$DFF054 ;dpt
bra.b .e
.b move.l #ScreenB_bpl1,$DFF054 ;dpt
.e move.w #1,$DFF05E ;hsize & start
rts
;**************************************
blitter_bpl2:
move.l #blitter_bpl3,next_blit
move.w #$0002,$DFF042 ;DescendingMode
move.w #$5555,$DFF072 ;bdat
move.w #$5555,$DFF044 ;afwm
move.l #chiptempbuffer32b_d,$DFF050 ;apt
move.l #chiptempbuffer32a_d,$DFF048 ;cpt
tst.b screen_x
bne.b .b
move.l #ScreenA_bpl2e-2,$DFF054 ;dpt
bra.b .e
.b move.l #ScreenB_bpl2e-2,$DFF054 ;dpt
.e move.w #1,$DFF05E ;hsize & start
rts
;**************************************
blitter_bpl3:
move.l #blitter_bpl4,next_blit
move.w #$0000,$DFF042 ;AscendingMode
move.w #$AAAA,$DFF072 ;bdat
move.w #$AAAA,$DFF044 ;afwm
move.l #chiptempbuffer32a_a,$DFF050 ;apt
move.l #chiptempbuffer32b_a,$DFF048 ;cpt
tst.b screen_x
bne.b .b
move.l #ScreenA_bpl3,$DFF054 ;dpt
bra.b .e
.b move.l #ScreenB_bpl3,$DFF054 ;dpt
.e move.w #1,$DFF05E ;hsize & start
rts
;**************************************
blitter_bpl4:
move.l #blitter_bpl5,next_blit
move.w #$0002,$DFF042 ;DescendingMode
move.w #$5555,$DFF072 ;bdat
move.w #$5555,$DFF044 ;afwm
move.l #chiptempbuffer54b_d,$DFF050 ;apt
move.l #chiptempbuffer54a_d,$DFF048 ;cpt
tst.b screen_x
bne.b .b
move.l #ScreenA_bpl4e-2,$DFF054 ;dpt
bra.b .e
.b move.l #ScreenB_bpl4e-2,$DFF054 ;dpt
.e move.w #1,$DFF05E ;hsize & start
rts
;**************************************
blitter_bpl5:
move.l #blitter_bpl6,next_blit
move.w #$0000,$DFF042 ;AscendingMode
move.w #$AAAA,$DFF072 ;bdat
move.w #$AAAA,$DFF044 ;afwm
move.l #chiptempbuffer54a_a,$DFF050 ;apt
move.l #chiptempbuffer54b_a,$DFF048 ;cpt
tst.b screen_x
bne.b .b
move.l #ScreenA_bpl5,$DFF054 ;dpt
bra.b .e
.b move.l #ScreenB_bpl5,$DFF054 ;dpt
.e move.w #1,$DFF05E ;hsize & start
rts
;**************************************
blitter_bpl6:
move.l #blitter_bpl7,next_blit
move.w #$0002,$DFF042 ;DescendingMode
move.w #$5555,$DFF072 ;bdat
move.w #$5555,$DFF044 ;afwm
move.l #chiptempbuffer76b_d,$DFF050 ;apt
move.l #chiptempbuffer76a_d,$DFF048 ;cpt
tst.b screen_x
bne.b .b
move.l #ScreenA_bpl6e-2,$DFF054 ;dpt
bra.b .e
.b move.l #ScreenB_bpl6e-2,$DFF054 ;dpt
.e move.w #1,$DFF05E ;hsize & start
rts
;**************************************
blitter_bpl7:
move.l #Finished_c2p,next_blit
move.w #$0000,$DFF042 ;AscendingMode
move.w #$AAAA,$DFF072 ;bdat
move.w #$AAAA,$DFF044 ;afwm
move.l #chiptempbuffer76a_a,$DFF050 ;apt
move.l #chiptempbuffer76b_a,$DFF048 ;cpt
tst.b screen_x
bne.b .b
move.l #ScreenA_bpl7,$DFF054 ;dpt
bra.b .e
.b move.l #ScreenB_bpl7,$DFF054 ;dpt
.e move.w #1,$DFF05E ;hsize & start
rts
;**************************************
Finished_c2p: bsr.b .SwapScreens
clr.l c2p_busy
move.l FinishedServer,a0
jmp (a0)
;**************************************
.SwapScreens: move.l screen_showed,d0
move.l screen_updated,screen_showed
move.l d0,screen_updated
not.b screen_x
jsr SetBplPt
rts
screen_x dc.b 0
cnop 0,4
;******************************************************************************
section iffbuffer,data
IFF INCBIN EH:T-CUBE/ASM/ILBM_320x200.bin
IFF_CMAP = IFF+$30
IFF_BODY = IFF+$3EC
IFF_E
;******************************************************************************
section chiptempbuffer,bss_c
chiptempbuffer ds.b 320*200
chiptempbuffer_e
chiptempbuffer10a_a = chiptempbuffer+0
chiptempbuffer10b_a = chiptempbuffer+2
chiptempbuffer32a_a = chiptempbuffer+4
chiptempbuffer32b_a = chiptempbuffer+6
chiptempbuffer54a_a = chiptempbuffer+8
chiptempbuffer54b_a = chiptempbuffer+10
chiptempbuffer76a_a = chiptempbuffer+12
chiptempbuffer76b_a = chiptempbuffer+14
chiptempbuffer10a_d = chiptempbuffer_e-16
chiptempbuffer10b_d = chiptempbuffer_e-14
chiptempbuffer32a_d = chiptempbuffer_e-12
chiptempbuffer32b_d = chiptempbuffer_e-10
chiptempbuffer54a_d = chiptempbuffer_e-8
chiptempbuffer54b_d = chiptempbuffer_e-6
chiptempbuffer76a_d = chiptempbuffer_e-4
chiptempbuffer76b_d = chiptempbuffer_e-2
;******************************************************************************
section chipgraphicpages,bss_c
ScreenA
ScreenA_bpl0 ds.b (320*200)/8
ScreenA_bpl0e
ScreenA_bpl1 ds.b (320*200)/8
ScreenA_bpl1e
ScreenA_bpl2 ds.b (320*200)/8
ScreenA_bpl2e
ScreenA_bpl3 ds.b (320*200)/8
ScreenA_bpl3e
ScreenA_bpl4 ds.b (320*200)/8
ScreenA_bpl4e
ScreenA_bpl5 ds.b (320*200)/8
ScreenA_bpl5e
ScreenA_bpl6 ds.b (320*200)/8
ScreenA_bpl6e
ScreenA_bpl7 ds.b (320*200)/8
ScreenA_bpl7e
ScreenB
ScreenB_bpl0 ds.b (320*200)/8
ScreenB_bpl0e
ScreenB_bpl1 ds.b (320*200)/8
ScreenB_bpl1e
ScreenB_bpl2 ds.b (320*200)/8
ScreenB_bpl2e
ScreenB_bpl3 ds.b (320*200)/8
ScreenB_bpl3e
ScreenB_bpl4 ds.b (320*200)/8
ScreenB_bpl4e
ScreenB_bpl5 ds.b (320*200)/8
ScreenB_bpl5e
ScreenB_bpl6 ds.b (320*200)/8
ScreenB_bpl6e
ScreenB_bpl7 ds.b (320*200)/8
ScreenB_bpl7e
;******************************************************************************
section copperlist,data_c
copper:
copper_bpl_regs:
DC.L $01080000 ;BPL1MOD
DC.L $010A0000 ;BPL2MOD
DC.L $01000211 ;BPLCON0
copper_bpl_pt:
DC.L $00E00000 ;BPL1PTH
DC.L $00E20000 ;BPL1PTL
DC.L $00E40000 ;BPL2PTH
DC.L $00E60000 ;BPL2PTL
DC.L $00E80000 ;BPL3PTH
DC.L $00EA0000 ;BPL3PTL
DC.L $00EC0000 ;BPL4PTH
DC.L $00EE0000 ;BPL4PTL
DC.L $00F00000 ;BPL5PTH
DC.L $00F20000 ;BPL5PTL
DC.L $00F40000 ;BPL6PTH
DC.L $00F60000 ;BPL6PTL
DC.L $00F80000 ;BPL7PTH
DC.L $00FA0000 ;BPL7PTL
DC.L $00FC0000 ;BPL8PTH
DC.L $00FE0000 ;BPL8PTL
copper_spr_pt:
DC.L $01200000 ;SPR0PTH
DC.L $01220000 ;SPR0PTL
DC.L $01240000 ;SPR1PTH
DC.L $01260000 ;SPR1PTL
DC.L $01280000 ;SPR2PTH
DC.L $012A0000 ;SPR2PTL
DC.L $012C0000 ;SPR3PTH
DC.L $012E0000 ;SPR3PTL
DC.L $01300000 ;SPR4PTH
DC.L $01320000 ;SPR4PTL
DC.L $01340000 ;SPR5PTH
DC.L $01360000 ;SPR5PTL
DC.L $01380000 ;SPR6PTH
DC.L $013A0000 ;SPR6PTL
DC.L $013C0000 ;SPR7PTH
DC.L $013E0000 ;SPR7PTL
col32 MACRO
DC.L $01800000
DC.L $01820000
DC.L $01840000
DC.L $01860000
DC.L $01880000
DC.L $018A0000
DC.L $018C0000
DC.L $018E0000
DC.L $01900000
DC.L $01920000
DC.L $01940000
DC.L $01960000
DC.L $01980000
DC.L $019A0000
DC.L $019C0000
DC.L $019E0000
DC.L $01A00000
DC.L $01A20000
DC.L $01A40000
DC.L $01A60000
DC.L $01A80000
DC.L $01AA0000
DC.L $01AC0000
DC.L $01AE0000
DC.L $01B00000
DC.L $01B20000
DC.L $01B40000
DC.L $01B60000
DC.L $01B80000
DC.L $01BA0000
DC.L $01BC0000
DC.L $01BE0000
ENDM
copper_color_hi_256:
DC.L $01060063 ;BANK=0 LOCT=0
col32
DC.L $01062063 ;BANK=1 LOCT=0
col32
DC.L $01064063 ;BANK=2 LOCT=0
col32
DC.L $01066063 ;BANK=3 LOCT=0
col32
DC.L $01068063 ;BANK=4 LOCT=0
col32
DC.L $0106A063 ;BANK=5 LOCT=0
col32
DC.L $0106C063 ;BANK=6 LOCT=0
col32
DC.L $0106E063 ;BANK=7 LOCT=0
col32
copper_color_lo_256:
DC.L $01060263 ;BANK=0 LOCT=1
col32
DC.L $01062263 ;BANK=1 LOCT=1
col32
DC.L $01064263 ;BANK=2 LOCT=1
col32
DC.L $01066263 ;BANK=3 LOCT=1
col32
DC.L $01068263 ;BANK=4 LOCT=1
col32
DC.L $0106A263 ;BANK=5 LOCT=1
col32
DC.L $0106C263 ;BANK=6 LOCT=1
col32
DC.L $0106E263 ;BANK=7 LOCT=1
col32
copper_spr_res:
DC.L $01060063 ;$0063=140ns $00A3=70ns
DC.L $FFFFFFFE ;End of CopperList
;******************************************************************************
section test,data_c
SpriteA:
DC.B $50,$F0
DS.W 3
DC.B $50+(200*2)-256,$02
DS.W 3
REPT 200
DC.L $FFFFAFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
ENDR
DS.L 1024
SpriteB:
DC.B $50,$F0
DS.W 3
DC.B $50+(200*2)-256,$82 ;ATT
DS.W 3
REPT 200
DC.L $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
ENDR
DS.L 1024
;******************************************************************************