English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 25 April 2021, 14:19   #1
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Hidden margins either side of screen

Hi folks! Apologies for the influx of noob questions, but I'm on week 2 of my Amiga assembly adventures, and I'm really stuck on this problem.

I'm trying to set up my 320x244 PAL display so that it has 16 pixels (for now) of hidden space either side (in the borders, so to speak), but I can't seem to understand the description in the HRM. I looked at some similar forum posts, and I thought I had a grip on it, but it's not happening, so any corrections to my list of what I'm doing would be great.

- DIWSTART/DIWSTOP: $3b81/$1b1C (From what I understand...)
- DDFSTART/DDFSTOP: $38/$D0 (...these remain unchanged)
- Screen Mem Width: 352 (Account for extra 16 pixels either side)
- Bitplane Pointers: +2 (+16 Pixels on LEFT)
- Screen Modulos(s): +4 (+32 pixels overall)
- Blitter D Modulo: +4 (display image correctly over larger area)

I've tried variations on these settings, but I'm getting nowhere, so any help would be great. I really tried to solve this issue without resorting to asking on here, so again apologies.

Code and test image below (if needed):

Test image:
https://drive.google.com/file/d/1Sch...ew?usp=sharing

Code:
	ORG $20000
	SECTION code,CODE

;------------------------------------------------------------------------------------------------------------
;	-- CALL INIT SUBS --
;-----------------------------------------------------------------------------------------------;
		
	jsr INIT
	jsr BLIT	; Initial blit of image
	
;------------------------------------------------------------------------------------------------------------
;		MAIN LOOP
;------------------------------------------------------------------------------------------------------------
	
MAIN_LOOP:

	jsr JOYSTICK_READER
	jsr P1_CONTROLS
	jsr VBLANK
	
	jmp MAIN_LOOP				; -- MAIN LOOP END / EXIT --

EXIT:

;-------------------------------------------------------------------------------------------------------	
;	SUBROUTINES
;-------------------------------------------------------------------------------------------------------

	; -- SCREEN CONSTANTS --
INIT:

SCR_W				= 	352					; Display Window WIDTH
SCR_H				=	224	
SCR_BPL				=	SCR_W/8
SCR_BPLSIZE			=	SCR_BPL*SCR_H
SCR_B_WIDTH			= 	SCR_BPL*4
SCR_MODULO			= 	SCR_BPL*3

	; -- BLITTER CONSTANTS (Old) -- 

;bltX		= 0
;bltY 		= 0
		; SCR_B_WIDTH already mul by 4
;bltOffs 	= (bltY*SCR_B_WIDTH)+(bltX/8)

;blt_height 	= 93
;blt_widthV	= 96
;blt_width 	= blt_widthV/16
;blt_modu 	= (SCR_W-blt_widthV)/8
;blt_brcorner = (blt_height-1)*SCR_BPL+blt_widthV*2-2

	; -- Turn off the Amiga Operating System --

OSoff:
	
	move.l 	4.w,a6							; Execbase
	clr.l 	d0
	move.l 	#GFXNAME,a1
	jsr 	-408(a6)						; oldopenlibrary()
	move.l 	d0,a1
	move.l 	38(a1),d4						; Original copper ptr
	jsr 	-414(a6)						; Closelibrary()
	
	; -- Enable/Disable relebant bits in registers --

EnaDis:	
	move.w 	$dff01c,d5
	move.w 	$dff002,d3	
	move.w 	#%1000000000000000,$dff096		; Set relevant bits in DMACON	- dff096	
	move.w 	#%0111111111111111,$dff09a		; Disable all bits in INTENA	- dff09a
	move.w 	#%0111111111111111,$dff09c		; Disable all bits in INTENAQ	- dff09c			
	
CopperInit:

	;-----------------------------------	
	;	BITPLANE POINTERS POKE
	;-----------------------------------

	lea SCREEN+2,a0	   				; Pointer to first bitplne of screen (+2 for hidden area)
	lea CoBplPr,a1					; Where to poke the bitplane pointer words.
	moveq	#4-1,d0					; Loop Counter
	
.bpl_loop:
	move.l a0,d1
	swap d1
	move.w d1,2(a1)					; High word
	swap d1
	move.w d1,6(a1)					; Low word
	addq #8,a1						; Point to next bpl to poke in copper
	lea	SCR_BPL(a0),a0 				; interleaved bitmap (see BPLxMOD in copperlist)
	dbf d0,.bpl_loop
	
	;-----------------------------------	
	;	SET COPPER LIST	
	;-----------------------------------

SetCopper:
	
	move.l 	#COPPER,$dff080		;COP1LCH

	rts
	
; ----------------------------------------------------------------------------------------------------------
;	WAIT FOR VERTICAL BLANK
; ----------------------------------------------------------------------------------------------------------

VBLANK:
.loop	
	move.l	$dff004,d0
	and.l	#$1ff00,d0
	cmp.l	#$12c00,d0
	bne.b	.loop
	rts
	
; ----------------------------------------------------------------------------------------------------------
;	BLITTER / DRAW
; ----------------------------------------------------------------------------------------------------------
	
BLIT:	

	movem.l d0-a6,-(sp)
	
	lea FRAME,a1					; Base address for graphics frame to be blitted
	lea SCREEN,a2					; Base address for Screen to be written to
	
	; -- CALCULATE X/Y OFFSET --
	
	;bltOffs 	= (bltY*SCR_B_WIDTH)+(bltX/8)	
	
	moveq #0,d1
	moveq #0,d2
	moveq #0,d3
	
	move.b (P1TABLE),d1			; X-Coordinate (Words)
	move.b (P1TABLE+1),d2		; Y-Coordinate (Lines) +1 Offset in Table
	move.b #SCR_B_WIDTH,d3	
	
	mulu d2,d3		
	divu #8,d1	
	add d3,d1		
	add d1,a2
		
	; -- CALCULATE WIDTH & HEGHT --
	
	;move.w #blt_height*4*64+blt_width,$058(a6)	; BLTSIZE - Size of Rectangle
	
	moveq #0,d4			
	moveq #0,d5			
	
	move.b (P1TABLE+4),d4	; Height
	mulu #4,d4
	mulu #64,d4								
	move.b (P1TABLE+3),d5	; Width
	
	divu #16,d5
	
	add d4,d5
	
	;-- DESTINATION MODULO --
	
	;blt_modu 	= (SCR_W-blt_widthV)/8
	
	moveq #0,d0
	moveq #0,d6
	
	move.w #SCR_W,d0
	move.b (P1TABLE+3),d6
	
	sub d6,d0
	divu #8,d0
	
	add #4,d0	; Add 4 for extra hidden screen areas
	
	; PASTE BACKGROUND
;	bsr WAITFORBLITTER
;	move.l #$09f00000,$040(a6)			; BLTCON0 - Set Blitter Control bits
;	move.l #$ffffffff,$044(a6)			; BLTAFWM - Set Source Mask
;	move.l #$ffffffff,$046(a6)			; BLTALWM - Set Source Mask
;	move.l #0,$050(a6)					; BLTAPTH - Source (A) pointer - MASK
;	move.l a2,$054(a6)					; BLTDPTH - Destination (D) pointer
	
;	move.w #0,$064(a6)					; BLTAMOD - Source Modulo
;	move.w d0,$066(a6)					; BLTDMOD - Destination Modulo
;	move.w d5,$058(a6)					; BLTSIZE - Size of Rectangle
	
	;-- COPY BACKGROUND --
;	bsr WAITFORBLITTER	
;	move.l #$09f00000,$040(a6)			; BLTCON0 - Set Blitter Control bits
;	move.l #$ffff,$044(a6)				; BLTAFWM - Set Source Mask
;	move.l #$f,$046(a6)					; BLTALWM - Set Source Mask
;	move.l a2,$050(a6)					; BLTAPTH - Source (A) pointer - MASK
;	move.l FRAMEBUFFER,$054(a6)			; BLTDPTH - Destination (D) pointer
	
;	move.w #0,$064(a6)					; BLTAMOD - Source Modulo
;	move.w d0,$066(a6)					; BLTDMOD - Destination Modulo
;	move.w d5,$058(a6)					; BLTSIZE - Size of Rectangle
	
	; -- BLIT SPRITE --
	
	lea $dff000,a6						; Custom Chip base address (a6)	
	tst $002(a6)						; DMACONR
	
	bsr WAITFORBLITTER

	moveq #0,d7
	move.b (P1TABLE+2),d7
	lsl.l #8,d7
	lsl.l #8,d7
	lsl.l #8,d7
	lsl.l #4,d7
	
	move.l #$09f00000,d6				; Set ASCENDING MODE (Shift RIGHT)
	or.l d7,d6		
	move.l d6,$040(a6)					; BLTCON0 - Set Blitter Control bits
	move.l #$ffffffff,$044(a6)			; BLTAFWM - Set Source Mask
	move.l #$ffffffff,$046(a6)			; BLTALWM - Set Source Mask
	;move.l a1,$04c(a6)					; BLTAPTH - Source (C) pointer - 
	;move.l a1,$04c(a6)					; BLTAPTH - Source (B) pointer - IMAGE
	move.l a1,$050(a6)					; BLTAPTH - Source (A) pointer - MASK
	move.l a2,$054(a6)					; BLTDPTH - Destination (D) pointer
	
	move.w #0,$064(a6)					; BLTAMOD - Source Modulo
	move.w d0,$066(a6)					; BLTDMOD - Destination Modulo
	move.w d5,$058(a6)					; BLTSIZE - Size of Rectangle
	

	movem.l (sp)+,d0-a6
	rts
	
WAITFORBLITTER:
.waitblit								; Wait for Blitter to finish
	btst #6,$002(a6)
	bne.s .waitblit	
	rts

;----------------------------------------------------------------------------------------------
;		CONTROLS
;----------------------------------------------------------------------------------------------

; BIT 	- ACTION
; ---   - ------
; 0 	- UP
; 1 	- DOWN
; 2 	- LEFT
; 3 	- RIGHT
; 4 	- FIRE 1
; 5 	- FIRE 2
; --------------

HSPEED = 2
VSPEED = 2
RLIMIT = 16
LLIMIT = 0

P1_CONTROLS:
;------------------------------------------
;	RIGHT
;------------------------------------------
.PLAYER1_MOVERIGHT:
	btst #3,d0
	bne .PLAYER1_MOVELEFT
		bset #0,P1FLAGS
		btst #1,d0						; Check if Diagoinal RIGHT-DOWN is pushed
		bne .NO_RD
			move.b (P1TABLE+1),d1
			add #VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_RD
		btst #0,d0						 ; Check if Diagoinal RIGHT-UP is pushed
		bne .NO_RU
		
			move.b (P1TABLE+1),d1
			add #-VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_RU
		moveq #0,d1
		move.b (P1TABLE+2),d1			; Move RIGHT within frame shift									; If we are at 0 don't sub, but go to 16pxl WORD shift		
		add #HSPEED,d1
		move.b d1,(P1TABLE+2)
			cmp.b #RLIMIT,d1
			blt .no_wordshiftR

			moveq #0,d1
			move.b (P1TABLE),d1			; Move frame RIGHT BY 16pxls
			add #16,d1
			move.b d1,(P1TABLE)	
			moveq #0,d1					; Move LEFT within frame shift
			move.b d1,(P1TABLE+2)			
.no_wordshiftR	
		jsr BLIT
		jmp .P1_CONTROLS_DONE
;------------------------------------------
;	LEFT
;------------------------------------------
.PLAYER1_MOVELEFT:
		btst #2,d0
		bne .PLAYER1_MOVEDOWN
		bclr #0,P1FLAGS					; Set XFLIP to '0' (LEFT)
			btst #1,d0					; Test for LEFT-DOWN
			bne .NO_LD
			move.b (P1TABLE+1),d1
			add #VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_LD
		btst #0,d0						; Test for LEFT-UP
		bne .NO_LU
			move.b (P1TABLE+1),d1
			add #-VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_LU
		;moveq #0,d2					; Check for left screen Boundary
		;move.b (P1TABLE),d2	
		;cmp #0,d2
		;beq .no_wordshiftL
		moveq #0,d1
		move.b (P1TABLE+2),d1			; Move SHIFT left
		cmp.b #LLIMIT,d1
		beq .goto_wordmoveL
		sub #HSPEED,d1
		move.b d1,(P1TABLE+2)
			cmp.b #LLIMIT,d1
			bgt .no_wordshiftL
.goto_wordmoveL
			moveq #0,d1
			move.b (P1TABLE),d1			; Move FRAME left
			sub #16,d1
			move.b d1,(P1TABLE)	
			moveq #0,d1
			move.b #15,d1
			move.b d1,(P1TABLE+2)			
.no_wordshiftL	
		jsr BLIT
		jmp .P1_CONTROLS_DONE
.PLAYER1_MOVEDOWN

		moveq #0,d2						; Check for bottom screen Boundary
		move.b (P1TABLE+1),d2	
		cmp #126,d2
		bge .PLAYER1_MOVEUP
		
		btst #1,d0
		bne .PLAYER1_MOVEUP
		move.b (P1TABLE+1),d1
		add #VSPEED,d1
		move.b d1,(P1TABLE+1)
		jsr BLIT
		jmp .P1_CONTROLS_DONE

.PLAYER1_MOVEUP

		btst #0,d0
		bne .P1_CONTROLS_DONE
		move.b (P1TABLE+1),d1
		add #-VSPEED,d1
		move.b d1,(P1TABLE+1)
		jsr BLIT
		jmp .P1_CONTROLS_DONE
		
.P1_CONTROLS_DONE:

	rts
;------------------------------------------------------------------------------------------------------------
;		JOYSTICK
;-----------------------------------------------------------------------------------------------

JOYSTICK_READER: ;---7654S321RLDU

	move.b #%00111111,$BFE201	;Direction for port A (BFE001)...0=in 1=out...(For fire buttons)

	move.w $dff00A,d2			;Joystick-mouse 0 data (vert,horiz) (Joy2)	
	move.b $bfe001,d5			;/FIR1 /FIR0  /RDY /TK0  /WPRO /CHNG /LED  OVL
	
	rol.b #1,d5					;Fire0 for joy 2
	
	bsr Player_ReadControlsOne	;Process Joy2
	
	move.l d0,-(sp)
	move.w $dff00c,d2			;Joystick-mouse 1 data (vert,horiz) (Joy1)
	move.b $bfe001,d5			;/FIR1 /FIR0  /RDY /TK0  /WPRO /CHNG /LED  OVL
	
	bsr Player_ReadControlsOne ;Process Joy 1
	move.l (sp)+,d1
	rts
	
Player_ReadControlsOne:	;Translate HV data into joystick values
	moveq #0,d0	
	moveq #0,d1	
	moveq #0,d3	
	moveq #0,d4	
	
	; -- Get the 4 bits that are needed for the directions -- 
	
	roxr.l #1,d2	;bit 0
	roxl.l #1,d3
	
	roxr.l #1,d2	;bit 1
	roxl.l #1,d4
	
	roxr.l #7,d2	;bit 8
	roxl.l #1,d0
	
	and.l #1,d2		;bit 9
	
	; -- Calculate the new directions --
	
	move.b d2,d1
	eor.b d0,d1
	roxr.b d1
	roxr.b d0		;Up (Bit 9 Xor 8)
	
	move.b d4,d1
	eor.b d3,d1
	roxr.b d1
	roxr.b d0		;Down (Bit 1 Xor 0)
	
	roxr.b d2
	roxr.b d0		;Left (Bit 9)
	
	roxr.b d4
	roxr.b d0		;Right (Bit 1)

	roxl.b d5
	roxr.b d0		;Fire
	
	ror.b #3,d0
	eor.b #%11101111,d0	;Invert UDLR bits
	or.l #$FFFFFF00,d0	;Set unused bits
	rts
;------------------------------------------------------------------------------------------------------------
;		DATA (COPPER, TABLES, GRAPHICS)
;-----------------------------------------------------------------------------------------------------------	

GFXNAME:	dc.b "graphics.library",0
	
	SECTION qq,DATA_C
	
; ----- COPPER ---------------------------------------------------------------------------------------------	

COPPER:

; -- DISPLAY SCREEN SIZE --

	dc.w $1fc,0	
	dc.w $08E,$3b81						; Display Screen Top Left  		(VVHH)
	dc.w $090,$1bc1 					; Display Screen Botom Right 	(VVHH)
	dc.w $092,$38						; Display Bitplane Fetch Start 	(XXHH)
	dc.w $094,$d0						; Display Bitplane Fetch Stop	(XXHH)
	
	dc.w $100,%0100001000000001			; BPLCON0
	;dc.w $102,%0000000011111111		; BPLCON1
	dc.w $106,%0000000000100000			; BPLCON3 - Enable ECS Border Blanking
	
	dc.w $108,SCR_MODULO+4				; Bitplane Modulo SCR_BPL*3 (odd planes) 
	dc.w $10A,SCR_MODULO+4				; Bitplane Modulo SCR_BPL*3 (even planes)		
		
; -- BITPLANE POINTERS -- 				;	-- 4 Bitplanes --

CoBplPr:
	dc.w $0e0,0							; Bitplane Pointer 1 (High 5 Bits) (ECS)
	dc.w $0e2,0							; Bitplane Pointer 1 (Low 15 Bits)
	
	dc.w $0e4,0							; Bitplane Pointer 2 (High 5 Bits)
	dc.w $0e6,0							; Bitplane Pointer 2 (Low 15 Bits)
	
	dc.w $0e8,0							; Bitplane Pointer 3 (High 5 Bits)
	dc.w $0ea,0							; Bitplane Pointer 3 (Low 15 Bits)
	
	dc.w $0ec,0							; Bitplane Pointer 4 (High 5 Bits)
	dc.w $0ee,0							; Bitplane Pointer 4 (Low 15 Bits)

SprPtr:
	dc.w $120,0						
	dc.w $122,0					
	dc.w $124,0		
	dc.w $126,0						
	dc.w $128,0							
	dc.w $12a,0							
	dc.w $12c,0							
	dc.w $12e,0		

	dc.w $120,0						
	dc.w $132,0					
	dc.w $134,0		
	dc.w $136,0						
	dc.w $138,0							
	dc.w $13a,0							
	dc.w $13c,0							
	dc.w $13e,0	

; -- PALETTE COLOURS -- ;	

PalDefs:
	dc.w $180,$0a00					; Colour 0
	dc.w $182,$0111					; Colour 1
	dc.w $184,$0620					; Colour 2
	dc.w $186,$0864					; Colour 3
	dc.w $188,$0A86					; Colour 4
	dc.w $18a,$0046					; Colour 5
	dc.w $18c,$00AC					; Colour 6
	dc.w $18e,$08EE					; Colour 7
	dc.w $190,$0A40					; Colour 8
	dc.w $192,$0E60					; Colour 9
	dc.w $194,$0EA0					; Colour 10
	dc.w $196,$0080					; Colour 11
	dc.w $198,$00C0					; Colour 12
	dc.w $19a,$0ECA					; Colour 13
	dc.w $19c,$0CCC					; Colour 14
	dc.w $19e,$0EEE					; Colour 15
	
; -- COPPER END --

	dc.w $ffff,$fffe				; COPPER END
	
;------------------------------------------------------------------------------------------------------------
;		FLAGS  (WIP)
;------------------------------------------------------------------------------------------------------------
; P1FLAGS
; --------
; BIT - ACTION
; ------------
; 0 - XFLIP
; 1 - 
; 2 - 
; 3 - 
; 4 - 
; 5 - 
; 6 - DIE		(Maybe)
; 7 - ACTIVE	(Maybe)

P1FLAGS:    dc.b %00000001

;------------------------------------------------------------------------------------------------------------
;		TABLES & VARIABLES (WIP)
;-----------------------------------------------------------------------------------------------------------
; -------------
; BYTE - ACTION
; -------------
;
; 0 - X
; 1 - Y
; 2 - S (Shift)
; 3 - Width
; 4 - Height
; 5 - State 	(Maybe)
; 6 - Energy 	(Maybe)
; 7 - Lives 	(Maybe)

P1TABLE		dc.b 16,16,0,96,93 		; X,Y,S,W,H

	EVEN
	
FRAME:
	INCBIN "C:\Amiga\FFARES\TEST_IMAGE.RAW"
FRAME_END:

;FRAMEBUFFER: ds.b 255

;------------------------------------------------------------------------------------------------------------
;		BSS
;------------------------------------------------------------------------------------------------------------

	SECTION BSS,BSS_C

SCREEN:
	ds.w SCR_BPLSIZE
SCREEN_END:

	END
Brick Nash is offline  
Old 25 April 2021, 16:07   #2
Old_Bob
BiO-sanitation Battalion
 
Old_Bob's Avatar
 
Join Date: Jun 2017
Location: Scotland
Posts: 151
The only things that you need to change are the bitplane modulo values to account for the extra four bytes of line width. All the other stuff can stay the same as for a normal 320 pixel wide screen.

B
Old_Bob is offline  
Old 25 April 2021, 17:48   #3
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Quote:
Originally Posted by Old_Bob View Post
The only things that you need to change are the bitplane modulo values to account for the extra four bytes of line width. All the other stuff can stay the same as for a normal 320 pixel wide screen.

B
Thank you for the reply.

Ok, I set the screen modulos to account for the extra bytes and left everything else the same, but it's not quite doing what I want. I even doubled the screen memory width to 640 and added 40 to the screen modulos, but it's not giving me any extra margins at the sides.

Basically I'm looking to pseudo-clip the Bobs so that they can move on and off the screen without them wrapping around. This is so that enemies and the like can move on screen from beyond the borders etc.
Brick Nash is offline  
Old 25 April 2021, 18:26   #4
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
Quote:
Originally Posted by Brick Nash View Post
Hi folks! Apologies for the influx of noob questions, but I'm on week 2 of my Amiga assembly adventures, and I'm really stuck on this problem.

I'm trying to set up my 320x244 PAL display so that it has 16 pixels (for now) of hidden space either side (in the borders, so to speak), but I can't seem to understand the description in the HRM. I looked at some similar forum posts, and I thought I had a grip on it, but it's not happening, so any corrections to my list of what I'm doing would be great.

- DIWSTART/DIWSTOP: $3b81/$1b1C (From what I understand...)
- DDFSTART/DDFSTOP: $38/$D0 (...these remain unchanged)
- Screen Mem Width: 352 (Account for extra 16 pixels either side)
- Bitplane Pointers: +2 (+16 Pixels on LEFT)
- Screen Modulos(s): +4 (+32 pixels overall)
- Blitter D Modulo: +4 (display image correctly over larger area)

I've tried variations on these settings, but I'm getting nowhere, so any help would be great. I really tried to solve this issue without resorting to asking on here, so again apologies.

Code and test image below (if needed):

Test image:
https://drive.google.com/file/d/1Sch...ew?usp=sharing

Code:
	ORG $20000
	SECTION code,CODE

;------------------------------------------------------------------------------------------------------------
;	-- CALL INIT SUBS --
;-----------------------------------------------------------------------------------------------;
		
	jsr INIT
	jsr BLIT	; Initial blit of image
	
;------------------------------------------------------------------------------------------------------------
;		MAIN LOOP
;------------------------------------------------------------------------------------------------------------
	
MAIN_LOOP:

	jsr JOYSTICK_READER
	jsr P1_CONTROLS
	jsr VBLANK
	
	jmp MAIN_LOOP				; -- MAIN LOOP END / EXIT --

EXIT:

;-------------------------------------------------------------------------------------------------------	
;	SUBROUTINES
;-------------------------------------------------------------------------------------------------------

	; -- SCREEN CONSTANTS --
INIT:

SCR_W				= 	352					; Display Window WIDTH
SCR_H				=	224	
SCR_BPL				=	SCR_W/8
SCR_BPLSIZE			=	SCR_BPL*SCR_H
SCR_B_WIDTH			= 	SCR_BPL*4
SCR_MODULO			= 	SCR_BPL*3

	; -- BLITTER CONSTANTS (Old) -- 

;bltX		= 0
;bltY 		= 0
		; SCR_B_WIDTH already mul by 4
;bltOffs 	= (bltY*SCR_B_WIDTH)+(bltX/8)

;blt_height 	= 93
;blt_widthV	= 96
;blt_width 	= blt_widthV/16
;blt_modu 	= (SCR_W-blt_widthV)/8
;blt_brcorner = (blt_height-1)*SCR_BPL+blt_widthV*2-2

	; -- Turn off the Amiga Operating System --

OSoff:
	
	move.l 	4.w,a6							; Execbase
	clr.l 	d0
	move.l 	#GFXNAME,a1
	jsr 	-408(a6)						; oldopenlibrary()
	move.l 	d0,a1
	move.l 	38(a1),d4						; Original copper ptr
	jsr 	-414(a6)						; Closelibrary()
	
	; -- Enable/Disable relebant bits in registers --

EnaDis:	
	move.w 	$dff01c,d5
	move.w 	$dff002,d3	
	move.w 	#%1000000000000000,$dff096		; Set relevant bits in DMACON	- dff096	
	move.w 	#%0111111111111111,$dff09a		; Disable all bits in INTENA	- dff09a
	move.w 	#%0111111111111111,$dff09c		; Disable all bits in INTENAQ	- dff09c			
	
CopperInit:

	;-----------------------------------	
	;	BITPLANE POINTERS POKE
	;-----------------------------------

	lea SCREEN+2,a0	   				; Pointer to first bitplne of screen (+2 for hidden area)
	lea CoBplPr,a1					; Where to poke the bitplane pointer words.
	moveq	#4-1,d0					; Loop Counter
	
.bpl_loop:
	move.l a0,d1
	swap d1
	move.w d1,2(a1)					; High word
	swap d1
	move.w d1,6(a1)					; Low word
	addq #8,a1						; Point to next bpl to poke in copper
	lea	SCR_BPL(a0),a0 				; interleaved bitmap (see BPLxMOD in copperlist)
	dbf d0,.bpl_loop
	
	;-----------------------------------	
	;	SET COPPER LIST	
	;-----------------------------------

SetCopper:
	
	move.l 	#COPPER,$dff080		;COP1LCH

	rts
	
; ----------------------------------------------------------------------------------------------------------
;	WAIT FOR VERTICAL BLANK
; ----------------------------------------------------------------------------------------------------------

VBLANK:
.loop	
	move.l	$dff004,d0
	and.l	#$1ff00,d0
	cmp.l	#$12c00,d0
	bne.b	.loop
	rts
	
; ----------------------------------------------------------------------------------------------------------
;	BLITTER / DRAW
; ----------------------------------------------------------------------------------------------------------
	
BLIT:	

	movem.l d0-a6,-(sp)
	
	lea FRAME,a1					; Base address for graphics frame to be blitted
	lea SCREEN,a2					; Base address for Screen to be written to
	
	; -- CALCULATE X/Y OFFSET --
	
	;bltOffs 	= (bltY*SCR_B_WIDTH)+(bltX/8)	
	
	moveq #0,d1
	moveq #0,d2
	moveq #0,d3
	
	move.b (P1TABLE),d1			; X-Coordinate (Words)
	move.b (P1TABLE+1),d2		; Y-Coordinate (Lines) +1 Offset in Table
	move.b #SCR_B_WIDTH,d3	
	
	mulu d2,d3		
	divu #8,d1	
	add d3,d1		
	add d1,a2
		
	; -- CALCULATE WIDTH & HEGHT --
	
	;move.w #blt_height*4*64+blt_width,$058(a6)	; BLTSIZE - Size of Rectangle
	
	moveq #0,d4			
	moveq #0,d5			
	
	move.b (P1TABLE+4),d4	; Height
	mulu #4,d4
	mulu #64,d4								
	move.b (P1TABLE+3),d5	; Width
	
	divu #16,d5
	
	add d4,d5
	
	;-- DESTINATION MODULO --
	
	;blt_modu 	= (SCR_W-blt_widthV)/8
	
	moveq #0,d0
	moveq #0,d6
	
	move.w #SCR_W,d0
	move.b (P1TABLE+3),d6
	
	sub d6,d0
	divu #8,d0
	
	add #4,d0	; Add 4 for extra hidden screen areas
	
	; PASTE BACKGROUND
;	bsr WAITFORBLITTER
;	move.l #$09f00000,$040(a6)			; BLTCON0 - Set Blitter Control bits
;	move.l #$ffffffff,$044(a6)			; BLTAFWM - Set Source Mask
;	move.l #$ffffffff,$046(a6)			; BLTALWM - Set Source Mask
;	move.l #0,$050(a6)					; BLTAPTH - Source (A) pointer - MASK
;	move.l a2,$054(a6)					; BLTDPTH - Destination (D) pointer
	
;	move.w #0,$064(a6)					; BLTAMOD - Source Modulo
;	move.w d0,$066(a6)					; BLTDMOD - Destination Modulo
;	move.w d5,$058(a6)					; BLTSIZE - Size of Rectangle
	
	;-- COPY BACKGROUND --
;	bsr WAITFORBLITTER	
;	move.l #$09f00000,$040(a6)			; BLTCON0 - Set Blitter Control bits
;	move.l #$ffff,$044(a6)				; BLTAFWM - Set Source Mask
;	move.l #$f,$046(a6)					; BLTALWM - Set Source Mask
;	move.l a2,$050(a6)					; BLTAPTH - Source (A) pointer - MASK
;	move.l FRAMEBUFFER,$054(a6)			; BLTDPTH - Destination (D) pointer
	
;	move.w #0,$064(a6)					; BLTAMOD - Source Modulo
;	move.w d0,$066(a6)					; BLTDMOD - Destination Modulo
;	move.w d5,$058(a6)					; BLTSIZE - Size of Rectangle
	
	; -- BLIT SPRITE --
	
	lea $dff000,a6						; Custom Chip base address (a6)	
	tst $002(a6)						; DMACONR
	
	bsr WAITFORBLITTER

	moveq #0,d7
	move.b (P1TABLE+2),d7
	lsl.l #8,d7
	lsl.l #8,d7
	lsl.l #8,d7
	lsl.l #4,d7
	
	move.l #$09f00000,d6				; Set ASCENDING MODE (Shift RIGHT)
	or.l d7,d6		
	move.l d6,$040(a6)					; BLTCON0 - Set Blitter Control bits
	move.l #$ffffffff,$044(a6)			; BLTAFWM - Set Source Mask
	move.l #$ffffffff,$046(a6)			; BLTALWM - Set Source Mask
	;move.l a1,$04c(a6)					; BLTAPTH - Source (C) pointer - 
	;move.l a1,$04c(a6)					; BLTAPTH - Source (B) pointer - IMAGE
	move.l a1,$050(a6)					; BLTAPTH - Source (A) pointer - MASK
	move.l a2,$054(a6)					; BLTDPTH - Destination (D) pointer
	
	move.w #0,$064(a6)					; BLTAMOD - Source Modulo
	move.w d0,$066(a6)					; BLTDMOD - Destination Modulo
	move.w d5,$058(a6)					; BLTSIZE - Size of Rectangle
	

	movem.l (sp)+,d0-a6
	rts
	
WAITFORBLITTER:
.waitblit								; Wait for Blitter to finish
	btst #6,$002(a6)
	bne.s .waitblit	
	rts

;----------------------------------------------------------------------------------------------
;		CONTROLS
;----------------------------------------------------------------------------------------------

; BIT 	- ACTION
; ---   - ------
; 0 	- UP
; 1 	- DOWN
; 2 	- LEFT
; 3 	- RIGHT
; 4 	- FIRE 1
; 5 	- FIRE 2
; --------------

HSPEED = 2
VSPEED = 2
RLIMIT = 16
LLIMIT = 0

P1_CONTROLS:
;------------------------------------------
;	RIGHT
;------------------------------------------
.PLAYER1_MOVERIGHT:
	btst #3,d0
	bne .PLAYER1_MOVELEFT
		bset #0,P1FLAGS
		btst #1,d0						; Check if Diagoinal RIGHT-DOWN is pushed
		bne .NO_RD
			move.b (P1TABLE+1),d1
			add #VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_RD
		btst #0,d0						 ; Check if Diagoinal RIGHT-UP is pushed
		bne .NO_RU
		
			move.b (P1TABLE+1),d1
			add #-VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_RU
		moveq #0,d1
		move.b (P1TABLE+2),d1			; Move RIGHT within frame shift									; If we are at 0 don't sub, but go to 16pxl WORD shift		
		add #HSPEED,d1
		move.b d1,(P1TABLE+2)
			cmp.b #RLIMIT,d1
			blt .no_wordshiftR

			moveq #0,d1
			move.b (P1TABLE),d1			; Move frame RIGHT BY 16pxls
			add #16,d1
			move.b d1,(P1TABLE)	
			moveq #0,d1					; Move LEFT within frame shift
			move.b d1,(P1TABLE+2)			
.no_wordshiftR	
		jsr BLIT
		jmp .P1_CONTROLS_DONE
;------------------------------------------
;	LEFT
;------------------------------------------
.PLAYER1_MOVELEFT:
		btst #2,d0
		bne .PLAYER1_MOVEDOWN
		bclr #0,P1FLAGS					; Set XFLIP to '0' (LEFT)
			btst #1,d0					; Test for LEFT-DOWN
			bne .NO_LD
			move.b (P1TABLE+1),d1
			add #VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_LD
		btst #0,d0						; Test for LEFT-UP
		bne .NO_LU
			move.b (P1TABLE+1),d1
			add #-VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_LU
		;moveq #0,d2					; Check for left screen Boundary
		;move.b (P1TABLE),d2	
		;cmp #0,d2
		;beq .no_wordshiftL
		moveq #0,d1
		move.b (P1TABLE+2),d1			; Move SHIFT left
		cmp.b #LLIMIT,d1
		beq .goto_wordmoveL
		sub #HSPEED,d1
		move.b d1,(P1TABLE+2)
			cmp.b #LLIMIT,d1
			bgt .no_wordshiftL
.goto_wordmoveL
			moveq #0,d1
			move.b (P1TABLE),d1			; Move FRAME left
			sub #16,d1
			move.b d1,(P1TABLE)	
			moveq #0,d1
			move.b #15,d1
			move.b d1,(P1TABLE+2)			
.no_wordshiftL	
		jsr BLIT
		jmp .P1_CONTROLS_DONE
.PLAYER1_MOVEDOWN

		moveq #0,d2						; Check for bottom screen Boundary
		move.b (P1TABLE+1),d2	
		cmp #126,d2
		bge .PLAYER1_MOVEUP
		
		btst #1,d0
		bne .PLAYER1_MOVEUP
		move.b (P1TABLE+1),d1
		add #VSPEED,d1
		move.b d1,(P1TABLE+1)
		jsr BLIT
		jmp .P1_CONTROLS_DONE

.PLAYER1_MOVEUP

		btst #0,d0
		bne .P1_CONTROLS_DONE
		move.b (P1TABLE+1),d1
		add #-VSPEED,d1
		move.b d1,(P1TABLE+1)
		jsr BLIT
		jmp .P1_CONTROLS_DONE
		
.P1_CONTROLS_DONE:

	rts
;------------------------------------------------------------------------------------------------------------
;		JOYSTICK
;-----------------------------------------------------------------------------------------------

JOYSTICK_READER: ;---7654S321RLDU

	move.b #%00111111,$BFE201	;Direction for port A (BFE001)...0=in 1=out...(For fire buttons)

	move.w $dff00A,d2			;Joystick-mouse 0 data (vert,horiz) (Joy2)	
	move.b $bfe001,d5			;/FIR1 /FIR0  /RDY /TK0  /WPRO /CHNG /LED  OVL
	
	rol.b #1,d5					;Fire0 for joy 2
	
	bsr Player_ReadControlsOne	;Process Joy2
	
	move.l d0,-(sp)
	move.w $dff00c,d2			;Joystick-mouse 1 data (vert,horiz) (Joy1)
	move.b $bfe001,d5			;/FIR1 /FIR0  /RDY /TK0  /WPRO /CHNG /LED  OVL
	
	bsr Player_ReadControlsOne ;Process Joy 1
	move.l (sp)+,d1
	rts
	
Player_ReadControlsOne:	;Translate HV data into joystick values
	moveq #0,d0	
	moveq #0,d1	
	moveq #0,d3	
	moveq #0,d4	
	
	; -- Get the 4 bits that are needed for the directions -- 
	
	roxr.l #1,d2	;bit 0
	roxl.l #1,d3
	
	roxr.l #1,d2	;bit 1
	roxl.l #1,d4
	
	roxr.l #7,d2	;bit 8
	roxl.l #1,d0
	
	and.l #1,d2		;bit 9
	
	; -- Calculate the new directions --
	
	move.b d2,d1
	eor.b d0,d1
	roxr.b d1
	roxr.b d0		;Up (Bit 9 Xor 8)
	
	move.b d4,d1
	eor.b d3,d1
	roxr.b d1
	roxr.b d0		;Down (Bit 1 Xor 0)
	
	roxr.b d2
	roxr.b d0		;Left (Bit 9)
	
	roxr.b d4
	roxr.b d0		;Right (Bit 1)

	roxl.b d5
	roxr.b d0		;Fire
	
	ror.b #3,d0
	eor.b #%11101111,d0	;Invert UDLR bits
	or.l #$FFFFFF00,d0	;Set unused bits
	rts
;------------------------------------------------------------------------------------------------------------
;		DATA (COPPER, TABLES, GRAPHICS)
;-----------------------------------------------------------------------------------------------------------	

GFXNAME:	dc.b "graphics.library",0
	
	SECTION qq,DATA_C
	
; ----- COPPER ---------------------------------------------------------------------------------------------	

COPPER:

; -- DISPLAY SCREEN SIZE --

	dc.w $1fc,0	
	dc.w $08E,$3b81						; Display Screen Top Left  		(VVHH)
	dc.w $090,$1bc1 					; Display Screen Botom Right 	(VVHH)
	dc.w $092,$38						; Display Bitplane Fetch Start 	(XXHH)
	dc.w $094,$d0						; Display Bitplane Fetch Stop	(XXHH)
	
	dc.w $100,%0100001000000001			; BPLCON0
	;dc.w $102,%0000000011111111		; BPLCON1
	dc.w $106,%0000000000100000			; BPLCON3 - Enable ECS Border Blanking
	
	dc.w $108,SCR_MODULO+4				; Bitplane Modulo SCR_BPL*3 (odd planes) 
	dc.w $10A,SCR_MODULO+4				; Bitplane Modulo SCR_BPL*3 (even planes)		
		
; -- BITPLANE POINTERS -- 				;	-- 4 Bitplanes --

CoBplPr:
	dc.w $0e0,0							; Bitplane Pointer 1 (High 5 Bits) (ECS)
	dc.w $0e2,0							; Bitplane Pointer 1 (Low 15 Bits)
	
	dc.w $0e4,0							; Bitplane Pointer 2 (High 5 Bits)
	dc.w $0e6,0							; Bitplane Pointer 2 (Low 15 Bits)
	
	dc.w $0e8,0							; Bitplane Pointer 3 (High 5 Bits)
	dc.w $0ea,0							; Bitplane Pointer 3 (Low 15 Bits)
	
	dc.w $0ec,0							; Bitplane Pointer 4 (High 5 Bits)
	dc.w $0ee,0							; Bitplane Pointer 4 (Low 15 Bits)

SprPtr:
	dc.w $120,0						
	dc.w $122,0					
	dc.w $124,0		
	dc.w $126,0						
	dc.w $128,0							
	dc.w $12a,0							
	dc.w $12c,0							
	dc.w $12e,0		

	dc.w $120,0						
	dc.w $132,0					
	dc.w $134,0		
	dc.w $136,0						
	dc.w $138,0							
	dc.w $13a,0							
	dc.w $13c,0							
	dc.w $13e,0	

; -- PALETTE COLOURS -- ;	

PalDefs:
	dc.w $180,$0a00					; Colour 0
	dc.w $182,$0111					; Colour 1
	dc.w $184,$0620					; Colour 2
	dc.w $186,$0864					; Colour 3
	dc.w $188,$0A86					; Colour 4
	dc.w $18a,$0046					; Colour 5
	dc.w $18c,$00AC					; Colour 6
	dc.w $18e,$08EE					; Colour 7
	dc.w $190,$0A40					; Colour 8
	dc.w $192,$0E60					; Colour 9
	dc.w $194,$0EA0					; Colour 10
	dc.w $196,$0080					; Colour 11
	dc.w $198,$00C0					; Colour 12
	dc.w $19a,$0ECA					; Colour 13
	dc.w $19c,$0CCC					; Colour 14
	dc.w $19e,$0EEE					; Colour 15
	
; -- COPPER END --

	dc.w $ffff,$fffe				; COPPER END
	
;------------------------------------------------------------------------------------------------------------
;		FLAGS  (WIP)
;------------------------------------------------------------------------------------------------------------
; P1FLAGS
; --------
; BIT - ACTION
; ------------
; 0 - XFLIP
; 1 - 
; 2 - 
; 3 - 
; 4 - 
; 5 - 
; 6 - DIE		(Maybe)
; 7 - ACTIVE	(Maybe)

P1FLAGS:    dc.b %00000001

;------------------------------------------------------------------------------------------------------------
;		TABLES & VARIABLES (WIP)
;-----------------------------------------------------------------------------------------------------------
; -------------
; BYTE - ACTION
; -------------
;
; 0 - X
; 1 - Y
; 2 - S (Shift)
; 3 - Width
; 4 - Height
; 5 - State 	(Maybe)
; 6 - Energy 	(Maybe)
; 7 - Lives 	(Maybe)

P1TABLE		dc.b 16,16,0,96,93 		; X,Y,S,W,H

	EVEN
	
FRAME:
	INCBIN "C:\Amiga\FFARES\TEST_IMAGE.RAW"
FRAME_END:

;FRAMEBUFFER: ds.b 255

;------------------------------------------------------------------------------------------------------------
;		BSS
;------------------------------------------------------------------------------------------------------------

	SECTION BSS,BSS_C

SCREEN:
	ds.w SCR_BPLSIZE
SCREEN_END:

	END
Side note, bin off that ORG statement at the top, totally unecessary.

Youre using sytem friendly code, but forcing your code to operate in a memory area that might not be free or safe.
Galahad/FLT is offline  
Old 25 April 2021, 18:37   #5
Old_Bob
BiO-sanitation Battalion
 
Old_Bob's Avatar
 
Join Date: Jun 2017
Location: Scotland
Posts: 151
Quote:
Originally Posted by Brick Nash View Post
Thank you for the reply.

Ok, I set the screen modulos to account for the extra bytes and left everything else the same, but it's not quite doing what I want. I even doubled the screen memory width to 640 and added 40 to the screen modulos, but it's not giving me any extra margins at the sides.

Basically I'm looking to pseudo-clip the Bobs so that they can move on and off the screen without them wrapping around. This is so that enemies and the like can move on screen from beyond the borders etc.
Sorry, dude. I guess I didn't word my reply very well.

The DDF and DIW start and stop values need to be set as you would for a normal 320 pixel screen. Something like this...


Code:
move.w	#$2c81,(DIWSTRT)	; normal start value is the same for NTSC or PAL
move.w	#$2cc1,(DIWSTOP)	; 256 lines tall for PAL

move.w	#$38,(DDFSTRT)		; 
move.w	#$d0,(DDFSTOP)		;

move.w	#120,(BPL1MOD)		; using interleaved mode
move.w	#120,(BPL2MOD)

move.w	#$4200,(BPLCON0)	; 4 bitplanes selected, colour burst on

move.w	#0,(BPLCON1)		; no scroll
If, for example, you had your bitplanes starting at address $1000, I would simply set the bitplane pointers two bytes in at $1002 giving 16 pixels elbow room at the left side, and increase the modulo values (in this little snippet) to 132 to skip over the extra four bytes in each of the bitplanes.

If you're not using an interleaved arrangement, then the modulo would simply be a value of 4.

I hope that's clear enough, this time.

B

Last edited by Old_Bob; 25 April 2021 at 18:52.
Old_Bob is offline  
Old 25 April 2021, 20:05   #6
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Quote:
Originally Posted by Old_Bob View Post
Sorry, dude. I guess I didn't word my reply very well.

B
No, please don't apologise mate!

There's obviously something wrong with my code, as I tried the exact suggestions you made but it's still not working for me. I can get the left hand side to clip the bob by increasing the Bitplane pointers starting address, but doing that makes the bob start wrapping a word early from the right hand border which is inside the visible screen.

I've been bashing my head against a wall with this for a few days now, so I'm thinking there's something else I've overlooked which is stopping it from working.
Brick Nash is offline  
Old 25 April 2021, 21:46   #7
a/b
Registered User
 
Join Date: Jun 2016
Location: europe
Posts: 1,039
OK, here it goes...
There are 3 bugs:
1. blit first/last word mask code also hits top word of C pointer
2. only 1 bitmap bitplane is allocated (again :P )
3. blit D modulo is wrong (extra width included twice)
Honorable mention:
4. screen is not cleared, added a few lines to handle that

I didn't look at control/joystick stuff.
I also changed a few other things. Some are generic optimizations (mostly mul/div replaced with shifts), some I find very annoying (missing .BWL :P ). Take them or leave them, they are there for educational purposes (not trying to be a dick).


Code:
;	ORG $20000
	SECTION code,CODE

;------------------------------------------------------------------------------------------------------------
;	-- CALL INIT SUBS --
;-----------------------------------------------------------------------------------------------;
		
;	jsr INIT
;	jsr BLIT	; Initial blit of image
 bsr.s INIT
 bsr.w BLIT	; Initial blit of image
	
;------------------------------------------------------------------------------------------------------------
;		MAIN LOOP
;------------------------------------------------------------------------------------------------------------
	
MAIN_LOOP:

;	jsr JOYSTICK_READER
;	jsr P1_CONTROLS
;	jsr VBLANK
 bsr.w	JOYSTICK_READER
 bsr.w	P1_CONTROLS
 bsr.w	VBLANK
	
;	jmp MAIN_LOOP				; -- MAIN LOOP END / EXIT --
 btst	#6,$bfe001		; left mouse button
 bne.s	MAIN_LOOP

EXIT:

;-------------------------------------------------------------------------------------------------------	
;	SUBROUTINES
;-------------------------------------------------------------------------------------------------------

	; -- SCREEN CONSTANTS --
INIT:

SCR_DEPTH			=	4	; interleaved bitmap
; full area
SCR_W				= 	352					; Display Window WIDTH
SCR_H				=	224	
SCR_BPL				=	SCR_W/8
SCR_BPLSIZE			=	SCR_BPL*SCR_H
SCR_B_WIDTH			= 	SCR_BPL*SCR_DEPTH
; visible area (centered)
VSCR_W			= 	320
VSCR_OFFSET			=	(SCR_W-VSCR_W)/2
SCR_MODULO			= 	SCR_BPL*(SCR_DEPTH-1)+(SCR_W-VSCR_W)/8

	; -- BLITTER CONSTANTS (Old) -- 

;bltX		= 0
;bltY 		= 0
		; SCR_B_WIDTH already mul by 4
;bltOffs 	= (bltY*SCR_B_WIDTH)+(bltX/8)

;blt_height 	= 93
;blt_widthV	= 96
;blt_width 	= blt_widthV/16
;blt_modu 	= (SCR_W-blt_widthV)/8
;blt_brcorner = (blt_height-1)*SCR_BPL+blt_widthV*2-2

	; -- Turn off the Amiga Operating System --

OSoff:
	
	move.l 	4.w,a6							; Execbase
;	clr.l 	d0
;	move.l 	#GFXNAME,a1
 moveq	#0,d0
 lea	GFXNAME(pc),a1
	jsr 	-408(a6)						; oldopenlibrary()
	move.l 	d0,a1
	move.l 	38(a1),d4						; Original copper ptr
	jsr 	-414(a6)						; Closelibrary()
	
	; -- Enable/Disable relebant bits in registers --

EnaDis:	
	move.w 	$dff01c,d5
	move.w 	$dff002,d3	
;	move.w 	#%1000000000000000,$dff096		; Set relevant bits in DMACON	- dff096	
	move.w 	#%0111111111111111,$dff09a		; Disable all bits in INTENA	- dff09a
	move.w 	#%0111111111111111,$dff09c		; Disable all bits in INTENAQ	- dff09c			
; order matters: disable interrupts first
 move.w 	#%1000000000000000,$dff096		; Set relevant bits in DMACON	- dff096	
	
	lea	SCREEN,a0
	moveq	#0,d0
	move.w	#(SCREEN_END-SCREEN)/4-1,d1
ClrScreen:	move.l	d0,(a0)+
	dbf	d1,ClrScreen

CopperInit:

	;-----------------------------------	
	;	BITPLANE POINTERS POKE
	;-----------------------------------

	lea SCREEN+2,a0	   				; Pointer to first bitplne of screen (+2 for hidden area)
	lea CoBplPr,a1					; Where to poke the bitplane pointer words.
;	moveq	#4-1,d0					; Loop Counter
 moveq	#SCR_DEPTH-1,d0					; Loop Counter
	
.bpl_loop:
	move.l a0,d1
	swap d1
	move.w d1,2(a1)					; High word
	swap d1
	move.w d1,6(a1)					; Low word
;	addq #8,a1						; Point to next bpl to poke in copper
 addq.l	#8,a1						; Point to next bpl to poke in copper
	lea	SCR_BPL(a0),a0 				; interleaved bitmap (see BPLxMOD in copperlist)
	dbf d0,.bpl_loop
	
	;-----------------------------------	
	;	SET COPPER LIST	
	;-----------------------------------

SetCopper:
	
	move.l 	#COPPER,$dff080		;COP1LCH

	rts
	
; ----------------------------------------------------------------------------------------------------------
;	WAIT FOR VERTICAL BLANK
; ----------------------------------------------------------------------------------------------------------

VBLANK:
.loop	
	move.l	$dff004,d0
	and.l	#$1ff00,d0
	cmp.l	#$12c00,d0
	bne.b	.loop
	rts
	
; ----------------------------------------------------------------------------------------------------------
;	BLITTER / DRAW
; ----------------------------------------------------------------------------------------------------------
	
BLIT:	

	movem.l d0-a6,-(sp)
	
	lea FRAME,a1					; Base address for graphics frame to be blitted
	lea SCREEN,a2					; Base address for Screen to be written to
	
	; -- CALCULATE X/Y OFFSET --
	
	;bltOffs 	= (bltY*SCR_B_WIDTH)+(bltX/8)	
	
	moveq #0,d1
	moveq #0,d2
;	moveq #0,d3
	
	move.b (P1TABLE),d1			; X-Coordinate (Words)
	move.b (P1TABLE+1),d2		; Y-Coordinate (Lines) +1 Offset in Table
;	move.b #SCR_B_WIDTH,d3	
	
;	mulu d2,d3		
;	divu #8,d1	
;	add d3,d1		
;	add d1,a2
 add.w	#VSCR_OFFSET,d1		; skip left hidden area
 lsr.w	#3,d1
 add.w	d1,a2
 mulu.w	#SCR_B_WIDTH,d2
 add.l	d2,a2
		
	; -- CALCULATE WIDTH & HEGHT --
	
	;move.w #blt_height*4*64+blt_width,$058(a6)	; BLTSIZE - Size of Rectangle
	
	moveq #0,d4			
	moveq #0,d5			
	
	move.b (P1TABLE+4),d4	; Height
;	mulu #4,d4
;	mulu #64,d4
 lsl.w	#2+6,d4			; also mul by SCR_DEPTH
	move.b (P1TABLE+3),d5	; Width
	
;	divu #16,d5
 lsr.w	#4,d5
	
;	add d4,d5
 add.w	d4,d5
	
	;-- DESTINATION MODULO --
	
	;blt_modu 	= (SCR_W-blt_widthV)/8
	
;	moveq #0,d0
	moveq #0,d6
	
	move.w #SCR_W,d0
	move.b (P1TABLE+3),d6
	
;	sub d6,d0
;	divu #8,d0
 sub.w	d6,d0
 lsr.w	#3,d0

;	add #4,d0	; Add 4 for extra hidden screen areas
;BUG: SCR_W already includes extra width
	
	; PASTE BACKGROUND
;	bsr WAITFORBLITTER
;	move.l #$09f00000,$040(a6)			; BLTCON0 - Set Blitter Control bits
;	move.l #$ffffffff,$044(a6)			; BLTAFWM - Set Source Mask
;	move.l #$ffffffff,$046(a6)			; BLTALWM - Set Source Mask
;	move.l #0,$050(a6)					; BLTAPTH - Source (A) pointer - MASK
;	move.l a2,$054(a6)					; BLTDPTH - Destination (D) pointer
	
;	move.w #0,$064(a6)					; BLTAMOD - Source Modulo
;	move.w d0,$066(a6)					; BLTDMOD - Destination Modulo
;	move.w d5,$058(a6)					; BLTSIZE - Size of Rectangle
	
	;-- COPY BACKGROUND --
;	bsr WAITFORBLITTER	
;	move.l #$09f00000,$040(a6)			; BLTCON0 - Set Blitter Control bits
;	move.l #$ffff,$044(a6)				; BLTAFWM - Set Source Mask
;	move.l #$f,$046(a6)					; BLTALWM - Set Source Mask
;	move.l a2,$050(a6)					; BLTAPTH - Source (A) pointer - MASK
;	move.l FRAMEBUFFER,$054(a6)			; BLTDPTH - Destination (D) pointer
	
;	move.w #0,$064(a6)					; BLTAMOD - Source Modulo
;	move.w d0,$066(a6)					; BLTDMOD - Destination Modulo
;	move.w d5,$058(a6)					; BLTSIZE - Size of Rectangle
	
	; -- BLIT SPRITE --
	
	lea $dff000,a6						; Custom Chip base address (a6)	
	tst $002(a6)						; DMACONR
	
	bsr WAITFORBLITTER

;	moveq #0,d7
;	move.b (P1TABLE+2),d7
;	lsl.l #8,d7
;	lsl.l #8,d7
;	lsl.l #8,d7
;	lsl.l #4,d7
 move.l #$09f00000<<4+$f,d6				; Set ASCENDING MODE (Shift RIGHT)
 and.b	(P1TABLE+2),d6
 ror.l	#4,d6

	
;	move.l #$09f00000,d6				; Set ASCENDING MODE (Shift RIGHT)
;	or.l d7,d6		
	move.l d6,$040(a6)					; BLTCON0 - Set Blitter Control bits
	move.l #$ffffffff,$044(a6)			; BLTAFWM - Set Source Mask
;	move.l #$ffffffff,$046(a6)			; BLTALWM - Set Source Mask
;BUG: 44.L will set both masks, 46.L is wrong and not needed
	;move.l a1,$04c(a6)					; BLTAPTH - Source (C) pointer - 
	;move.l a1,$04c(a6)					; BLTAPTH - Source (B) pointer - IMAGE
	move.l a1,$050(a6)					; BLTAPTH - Source (A) pointer - MASK
	move.l a2,$054(a6)					; BLTDPTH - Destination (D) pointer
	
	move.w #0,$064(a6)					; BLTAMOD - Source Modulo
	move.w d0,$066(a6)					; BLTDMOD - Destination Modulo
	move.w d5,$058(a6)					; BLTSIZE - Size of Rectangle
	

	movem.l (sp)+,d0-a6
	rts
	
WAITFORBLITTER:
.waitblit								; Wait for Blitter to finish
	btst #6,$002(a6)
	bne.s .waitblit	
	rts

;----------------------------------------------------------------------------------------------
;		CONTROLS
;----------------------------------------------------------------------------------------------

; BIT 	- ACTION
; ---   - ------
; 0 	- UP
; 1 	- DOWN
; 2 	- LEFT
; 3 	- RIGHT
; 4 	- FIRE 1
; 5 	- FIRE 2
; --------------

HSPEED = 2
VSPEED = 2
RLIMIT = 16
LLIMIT = 0

P1_CONTROLS:
;------------------------------------------
;	RIGHT
;------------------------------------------
.PLAYER1_MOVERIGHT:
	btst #3,d0
	bne .PLAYER1_MOVELEFT
		bset #0,P1FLAGS
		btst #1,d0						; Check if Diagoinal RIGHT-DOWN is pushed
		bne .NO_RD
			move.b (P1TABLE+1),d1
			add #VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_RD
		btst #0,d0						 ; Check if Diagoinal RIGHT-UP is pushed
		bne .NO_RU
		
			move.b (P1TABLE+1),d1
			add #-VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_RU
		moveq #0,d1
		move.b (P1TABLE+2),d1			; Move RIGHT within frame shift									; If we are at 0 don't sub, but go to 16pxl WORD shift		
		add #HSPEED,d1
		move.b d1,(P1TABLE+2)
			cmp.b #RLIMIT,d1
			blt .no_wordshiftR

			moveq #0,d1
			move.b (P1TABLE),d1			; Move frame RIGHT BY 16pxls
			add #16,d1
			move.b d1,(P1TABLE)	
			moveq #0,d1					; Move LEFT within frame shift
			move.b d1,(P1TABLE+2)			
.no_wordshiftR	
		jsr BLIT
		jmp .P1_CONTROLS_DONE
;------------------------------------------
;	LEFT
;------------------------------------------
.PLAYER1_MOVELEFT:
		btst #2,d0
		bne .PLAYER1_MOVEDOWN
		bclr #0,P1FLAGS					; Set XFLIP to '0' (LEFT)
			btst #1,d0					; Test for LEFT-DOWN
			bne .NO_LD
			move.b (P1TABLE+1),d1
			add #VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_LD
		btst #0,d0						; Test for LEFT-UP
		bne .NO_LU
			move.b (P1TABLE+1),d1
			add #-VSPEED,d1
			move.b d1,(P1TABLE+1)
.NO_LU
		;moveq #0,d2					; Check for left screen Boundary
		;move.b (P1TABLE),d2	
		;cmp #0,d2
		;beq .no_wordshiftL
		moveq #0,d1
		move.b (P1TABLE+2),d1			; Move SHIFT left
		cmp.b #LLIMIT,d1
		beq .goto_wordmoveL
		sub #HSPEED,d1
		move.b d1,(P1TABLE+2)
			cmp.b #LLIMIT,d1
			bgt .no_wordshiftL
.goto_wordmoveL
			moveq #0,d1
			move.b (P1TABLE),d1			; Move FRAME left
			sub #16,d1
			move.b d1,(P1TABLE)	
			moveq #0,d1
			move.b #15,d1
			move.b d1,(P1TABLE+2)			
.no_wordshiftL	
		jsr BLIT
		jmp .P1_CONTROLS_DONE
.PLAYER1_MOVEDOWN

		moveq #0,d2						; Check for bottom screen Boundary
		move.b (P1TABLE+1),d2	
		cmp #126,d2
		bge .PLAYER1_MOVEUP
		
		btst #1,d0
		bne .PLAYER1_MOVEUP
		move.b (P1TABLE+1),d1
		add #VSPEED,d1
		move.b d1,(P1TABLE+1)
		jsr BLIT
		jmp .P1_CONTROLS_DONE

.PLAYER1_MOVEUP

		btst #0,d0
		bne .P1_CONTROLS_DONE
		move.b (P1TABLE+1),d1
		add #-VSPEED,d1
		move.b d1,(P1TABLE+1)
		jsr BLIT
		jmp .P1_CONTROLS_DONE
		
.P1_CONTROLS_DONE:

	rts
;------------------------------------------------------------------------------------------------------------
;		JOYSTICK
;-----------------------------------------------------------------------------------------------

JOYSTICK_READER: ;---7654S321RLDU

	move.b #%00111111,$BFE201	;Direction for port A (BFE001)...0=in 1=out...(For fire buttons)

	move.w $dff00A,d2			;Joystick-mouse 0 data (vert,horiz) (Joy2)	
	move.b $bfe001,d5			;/FIR1 /FIR0  /RDY /TK0  /WPRO /CHNG /LED  OVL
	
	rol.b #1,d5					;Fire0 for joy 2
	
	bsr Player_ReadControlsOne	;Process Joy2
	
	move.l d0,-(sp)
	move.w $dff00c,d2			;Joystick-mouse 1 data (vert,horiz) (Joy1)
	move.b $bfe001,d5			;/FIR1 /FIR0  /RDY /TK0  /WPRO /CHNG /LED  OVL
	
	bsr Player_ReadControlsOne ;Process Joy 1
	move.l (sp)+,d1
	rts
	
Player_ReadControlsOne:	;Translate HV data into joystick values
	moveq #0,d0	
	moveq #0,d1	
	moveq #0,d3	
	moveq #0,d4	
	
	; -- Get the 4 bits that are needed for the directions -- 
	
	roxr.l #1,d2	;bit 0
	roxl.l #1,d3
	
	roxr.l #1,d2	;bit 1
	roxl.l #1,d4
	
	roxr.l #7,d2	;bit 8
	roxl.l #1,d0
	
	and.l #1,d2		;bit 9
	
	; -- Calculate the new directions --
	
	move.b d2,d1
	eor.b d0,d1
	roxr.b d1
	roxr.b d0		;Up (Bit 9 Xor 8)
	
	move.b d4,d1
	eor.b d3,d1
	roxr.b d1
	roxr.b d0		;Down (Bit 1 Xor 0)
	
	roxr.b d2
	roxr.b d0		;Left (Bit 9)
	
	roxr.b d4
	roxr.b d0		;Right (Bit 1)

	roxl.b d5
	roxr.b d0		;Fire
	
	ror.b #3,d0
	eor.b #%11101111,d0	;Invert UDLR bits
	or.l #$FFFFFF00,d0	;Set unused bits
	rts
;------------------------------------------------------------------------------------------------------------
;		DATA (COPPER, TABLES, GRAPHICS)
;-----------------------------------------------------------------------------------------------------------	

GFXNAME:	dc.b "graphics.library",0
	
	SECTION qq,DATA_C
	
; ----- COPPER ---------------------------------------------------------------------------------------------	

COPPER:

; -- DISPLAY SCREEN SIZE --

	dc.w $1fc,0	
	dc.w $08E,$3b81						; Display Screen Top Left  		(VVHH)
	dc.w $090,$1bc1 					; Display Screen Botom Right 	(VVHH)
	dc.w $092,$38						; Display Bitplane Fetch Start 	(XXHH)
	dc.w $094,$d0						; Display Bitplane Fetch Stop	(XXHH)
	
	dc.w $100,%0100001000000001			; BPLCON0
	;dc.w $102,%0000000011111111		; BPLCON1
	dc.w $106,%0000000000100000			; BPLCON3 - Enable ECS Border Blanking
	
;	dc.w $108,SCR_MODULO+4				; Bitplane Modulo SCR_BPL*3 (odd planes) 
;	dc.w $10A,SCR_MODULO+4				; Bitplane Modulo SCR_BPL*3 (even planes)		
 dc.w $108,SCR_MODULO				; Bitplane Modulo SCR_BPL*3 (odd planes) 
 dc.w $10A,SCR_MODULO				; Bitplane Modulo SCR_BPL*3 (even planes)		
		
; -- BITPLANE POINTERS -- 				;	-- 4 Bitplanes --

CoBplPr:
	dc.w $0e0,0							; Bitplane Pointer 1 (High 5 Bits) (ECS)
	dc.w $0e2,0							; Bitplane Pointer 1 (Low 15 Bits)
	
	dc.w $0e4,0							; Bitplane Pointer 2 (High 5 Bits)
	dc.w $0e6,0							; Bitplane Pointer 2 (Low 15 Bits)
	
	dc.w $0e8,0							; Bitplane Pointer 3 (High 5 Bits)
	dc.w $0ea,0							; Bitplane Pointer 3 (Low 15 Bits)
	
	dc.w $0ec,0							; Bitplane Pointer 4 (High 5 Bits)
	dc.w $0ee,0							; Bitplane Pointer 4 (Low 15 Bits)

SprPtr:
	dc.w $120,0						
	dc.w $122,0					
	dc.w $124,0		
	dc.w $126,0						
	dc.w $128,0							
	dc.w $12a,0							
	dc.w $12c,0							
	dc.w $12e,0		

	dc.w $120,0						
	dc.w $132,0					
	dc.w $134,0		
	dc.w $136,0						
	dc.w $138,0							
	dc.w $13a,0							
	dc.w $13c,0							
	dc.w $13e,0	

; -- PALETTE COLOURS -- ;	

PalDefs:
	dc.w $180,$0a00					; Colour 0
	dc.w $182,$0111					; Colour 1
	dc.w $184,$0620					; Colour 2
	dc.w $186,$0864					; Colour 3
	dc.w $188,$0A86					; Colour 4
	dc.w $18a,$0046					; Colour 5
	dc.w $18c,$00AC					; Colour 6
	dc.w $18e,$08EE					; Colour 7
	dc.w $190,$0A40					; Colour 8
	dc.w $192,$0E60					; Colour 9
	dc.w $194,$0EA0					; Colour 10
	dc.w $196,$0080					; Colour 11
	dc.w $198,$00C0					; Colour 12
	dc.w $19a,$0ECA					; Colour 13
	dc.w $19c,$0CCC					; Colour 14
	dc.w $19e,$0EEE					; Colour 15
	
; -- COPPER END --

	dc.w $ffff,$fffe				; COPPER END
	
;------------------------------------------------------------------------------------------------------------
;		FLAGS  (WIP)
;------------------------------------------------------------------------------------------------------------
; P1FLAGS
; --------
; BIT - ACTION
; ------------
; 0 - XFLIP
; 1 - 
; 2 - 
; 3 - 
; 4 - 
; 5 - 
; 6 - DIE		(Maybe)
; 7 - ACTIVE	(Maybe)

P1FLAGS:    dc.b %00000001

;------------------------------------------------------------------------------------------------------------
;		TABLES & VARIABLES (WIP)
;-----------------------------------------------------------------------------------------------------------
; -------------
; BYTE - ACTION
; -------------
;
; 0 - X
; 1 - Y
; 2 - S (Shift)
; 3 - Width
; 4 - Height
; 5 - State 	(Maybe)
; 6 - Energy 	(Maybe)
; 7 - Lives 	(Maybe)

P1TABLE		dc.b 16,16,0,96,93 		; X,Y,S,W,H

	EVEN
	
FRAME:
	INCBIN "C:\Amiga\FFARES\TEST_IMAGE.RAW"
FRAME_END:

;FRAMEBUFFER: ds.b 255

;------------------------------------------------------------------------------------------------------------
;		BSS
;------------------------------------------------------------------------------------------------------------

	SECTION BSS,BSS_C

SCREEN:
;	ds.w SCR_BPLSIZE
;BUG: only 1 bitplane is allocated
 ds.b	SCR_BPLSIZE*SCR_DEPTH
SCREEN_END:

	END

Last edited by a/b; 25 April 2021 at 21:54. Reason: forgot to remove my incbin
a/b is offline  
Old 26 April 2021, 00:16   #8
Old_Bob
BiO-sanitation Battalion
 
Old_Bob's Avatar
 
Join Date: Jun 2017
Location: Scotland
Posts: 151
Quote:
Originally Posted by Brick Nash View Post
No, please don't apologise mate!

There's obviously something wrong with my code, as I tried the exact suggestions you made but it's still not working for me. I can get the left hand side to clip the bob by increasing the Bitplane pointers starting address, but doing that makes the bob start wrapping a word early from the right hand border which is inside the visible screen.

I've been bashing my head against a wall with this for a few days now, so I'm thinking there's something else I've overlooked which is stopping it from working.
First off, I made a small mistake with the bitplane modulo value I suggested earlier. In this case it should be 136, of course...

Having had a little fiddle around with it, I was able to get it to display an image correctly using a little CPU routine to copy the background image to the screen. So all the bitplane setup and modulo stuff is actually working fine. To add to a/b's post... it's definitely your blitter code that's the problem here, dude.

B

Last edited by Old_Bob; 26 April 2021 at 00:28.
Old_Bob is offline  
Old 26 April 2021, 08:20   #9
Brick Nash
Prototron
 
Brick Nash's Avatar
 
Join Date: Mar 2015
Location: Glasgow, Scotland
Posts: 411
Thank you for all the help everyone, it's really appreciated. I'm still very much learning at the moment, so these corrections and advice will be invaluable for improving my skills, as I don't know what I'm even looking for when something goes wrong at this stage.

Everything is just a big experiment at the moment to find out how things work, so the joystick stuff and other bits are just me messing around and aren't important.

I'll go away and study all the changes/suggestions and take notes for future reference.

Once again, thank you all!

EDIT: I managed to solve what was wrong. I was using a byte sized variable for the X-Coordinate of my image, so it was getting to 255 on a 320 display and then going back to 0 which made it look like it was wrapping before it hit the right edge of the screen. I changed the variable to a word value and I can now move my image into the hidden margins at the left and right of the screen.

Last edited by Brick Nash; 29 April 2021 at 13:09.
Brick Nash is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Host side - splash Screen Azvareth request.UAE Wishlist 3 22 July 2022 05:40
1084S-P Vertical brightness banding on left side of screen psoma support.Hardware 13 01 January 2022 15:39
A500 rgb scart Wavy vertical right side screen? jedvard support.Hardware 1 03 April 2019 18:34
Strange side effect on screen in Workbench Snake79 support.WinUAE 3 13 April 2015 19:46
[Found: Barbarian 2 - Palace] laughing skeleton came on the side of the blank screen PiAnt Looking for a game name ? 2 30 October 2007 21:07

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 14:44.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10402 seconds with 15 queries