English Amiga Board


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

 
 
Thread Tools
Old 18 March 2013, 21:23   #1
BippyM
Registered User

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 43
Posts: 8,696
Code issues

Guys,

What is wrong with the following code?

It simply freezes winuae (invokes the debugger!)

Code:
; 32 Col screen 1
; Open a 32 colour low-res screen, and display a picture in asm.
;
; 18/3/2013 14:10
;
; Process for opening the screen is:
; For now we are going to be system friendly

	incdir "mark_asm:open_screen/"

; Some equates for hardware and libary offsets

; Base custom address

CUSTOM			equ		$dff000

; Read addresses
DMACONR			equ		$002
ADKCONR			equ		$010
INTENAR			equ		$01c
INTREQR			equ		$01e

; Write addresses
DMACON			equ		$096
ADKCON			equ		$09e
INTENA			equ		$09a
INTREQ			equ		$09c
BPLCON0			equ		$100
BPLCON1			equ		$102
BPL1MOD			equ		$108
BPL2MOD			equ		$10a
DIWSTRT			equ		$08e
DIWSTOP			equ		$090
DDFSTRT			equ		$092
DDFSTOP			equ		$094
BPL1PTH			equ		$0e0
BPL1PTL			equ		$0e2
BPL2PTH			equ		$0e4
BPL2PTL			equ		$0e6
BPL3PTH			equ		$0e0
BPL3PTL			equ		$0e2
BPL4PTH			equ		$0e4
BPL4PTL			equ		$0e6
BPL5PTH			equ		$0e0
BPL5PTL			equ		$0e2
BPL6PTH			equ		$0e4
BPL6PTL			equ		$0e6


; Library offsets

execbase		equ		$4
openlibrary		equ		-552
closelibrary	equ		-414
forbid			equ		-132
permit			equ		-138
supervisor		equ		-30
loadview		equ		-222
waittoff		equ		-270
ownblitter		equ		-456
disownblitter	equ		-462
waitblit		equ		-228

; My offsets
old_View_off	equ		34
old_Clist1_off	equ		38
old_Clist2_off	equ		50




; Store the current system parameters so we can restore the system when we exit!

	move.w		DMACONR,d0						; Copy DMA Control Registers
	or.w		#$8000,d0						; Or to set the control register for later (bit 15)
	move.w		d0,dmasystem					; Copy to safe haven :)

	move.w		ADKCONR,d0						; Store contents of ADKON
	or.w		#$8000,d0
	move.w		d0,adkonsystem

	move.w		INTENAR,d0
	or.w		#$8000,d0
	move.w		d0,intenarsystem

	move.w		INTREQR,d0
	or.w		#$8000,d0
	move.w		d0,intreqsystem

; Next we need to take the system

		move.l		execbase,a6

	move.l		gfxname,a1						; name of graphics.library into a1
	jsr			openlibrary(a6)					; Open the library, base address is returned in d0, if it is 0 then library failed to open
	move.l		d0,gfxbase						; Store base address
;	beq			.libfail						; Library failed to open, let's quit
	move.l		d0,a6							; Base address of gfx lib into a6
	move.l		old_View_off(a6),viewsystem
	move.l		old_Clist1_off(a6),coppersystem

	move.l		#0,d1
	jsr			loadview(a6)
	jsr			waittoff(a6)
	jsr			waittoff(a6)
	jsr			ownblitter(a6)
	jsr			waitblit(a6)

	move.l		execbase,a6
	jsr			forbid(a6)						; Disable multitasking 
	
;Next we need a clear screen routine that will set all bitplanes to 0. This will ensure there is no garbage when the bitmap is displayed
; by the copper.
;
; There are two ways. Firstly the long, slow way is to have a loop that set each bit of each bitplane to 0. This is very slow and the
; second option is to use the blitter. 
;
; The copy routine will use addresses a0-a4 for each bitplane
; Image is 320 * 256. This will give us:
; 320/8 = 40 bytes per line
; 40*256 = 10240 bytes per bitplane
; 256/4 = 2560 long words to copy.
;
	move.w	(320/8)*(256/4),d0
	move.l	#bp0,a0
	move.l	#bp1,a1
	move.l	#bp2,a2
	move.l	#bp3,a3
	move.l	#bp4,a4
	
	move.l	#img_bippy,a6
	clr.l	d7
	
	copy_img:
		move.l #320/8*256*5,d7	; bpl5
		move.l	(a6,d7.L),(a4)+		; This adds the contents of a6 to d7, and places the result in a4
		
		move.l #320/8*256*4,d7
		move.l	(a6,d7.L),(a3)+		; bpl4
		
		move.l #320/8*256*3,d7
		move.l	(a6,d7.L),(a3)+		; bpl3
		
		move.l #320/8*256*2,d7
		move.l	(a6,d7.L),(a3)+		; bpl2
		
		move.l (a6)+,(a0)+			; bpl0
		subq.w #1,d0
		bne copy_img
		
; address offsets for each bitplane
; bitplane 0 is a6
; bitplane 1 a6+2560 longwords
; bitplane 2 is a6+2560*2 (add.l (2560*2),a6	
	
;           Table 3-5: Setting the Number of Bitplanes (BPLCON0 Register bits 12, 13 and 14 BPU0-BPU2)
;
;
;                   Number of     Name(s) of
;        Value     Bitplanes     Bitplanes
;       -----     ---------     ----------
;       000       None *
;           001         1           PLANE 1
;           010         2           PLANES 1 and 2
;           011         3           PLANES 1 - 3
;           100         4           PLANES 1 - 4
;           101         5           PLANES 1 - 5
;           110         6           PLANES 1 - 6 **
;           111                     Value not used.;
;
;     *  Shows only a background color; no playfield is visible.
;
;     ** Sixth bitplane is used only in  dual-playfield mode  and in
;         hold-and-modify mode  (described in the section called
;        Advanced Topics.

	move.w	#$5200,BPLCON0				; 5 bitplane lowres mode
	move.w	#$0000,BPLCON1				; horizontal scroll 0
	move.w	#$0000,BPL1MOD				; odd modulo 0
	move.w	#$0000,BPL2MOD				; even modulo 0
	move.w	#$2c81,DIWSTRT				; DIWSTRT - topleft corner (2c81)
	move.w	#$f4d1,DIWSTOP				; DIVSTOP - bottomright corner (f4d1)
	move.w	#$0038,DDFSTRT				; DDFSTRT - max overscan $0018 ; standard 0038 & 00d0
	move.w	#$00d0,DDFSTOP				; DDFSTOP - max overscan $00d8 ; max overscan: 368x283px in PAL
	move.w 	#%1000010111000000, DMACON	; DMA set ON
	move.w 	#%0000000000111111, DMACON	; DMA set OFF
	move.w 	#%1100000000000000, INTENA	; IRQ set ON
	move.w 	#%0011111111111111, INTENA	; IRQ set OFF

; Let's build the copperlist.

	move.l	#copper,a6
	
	move.l	#bp0,d0						; bitplane 0
	move.w	#BPL1PTH,(a6)+				; Hi part of bitplane
	move.w	d0,(a6)+
	swap	d0
	move.w	#BPL1PTL,(a6)+				; Low part of bitplane
	move.w	d0,(a6)+
	
	move.l	#bp1,d0						; bitplane 1
	move.w	#BPL2PTH,(a6)+				; Hi part of bitplane
	move.w	d0,(a6)+
	swap	d0
	move.w	#BPL2PTL,(a6)+				; Low part of bitplane
	move.w	d0,(a6)+

	move.l	#bp2,d0						; bitplane 2
	move.w	#BPL3PTH,(a6)+				; Hi part of bitplane
	move.w	d0,(a6)+
	swap	d0
	move.w	#BPL3PTL,(a6)+				; Low part of bitplane
	move.w	d0,(a6)+
	
	move.l	#bp3,d0						; bitplane 3
	move.w	#BPL4PTH,(a6)+				; Hi part of bitplane
	move.w	d0,(a6)+
	swap	d0
	move.w	#BPL4PTL,(a6)+				; Low part of bitplane
	move.w	d0,(a6)+
	
	move.l	#bp4,d0						; bitplane 3
	move.w	#BPL5PTH,(a6)+				; Hi part of bitplane
	move.w	d0,(a6)+
	swap	d0
	move.w	#BPL5PTL,(a6)+				; Low part of bitplane
	move.w	d0,(a6)+
	
	;Palette
	
	move.l #Palette,a5					; Palette entries
	move.b #32,d0						; 32 colours
	
	copy_pal:
		move.l (a5)+,(a6)+					; copy entries
		subq.b	#1,d0
		bne	copy_pal
		
	move.l #$fffffffe,(a6)+ 	; end copperlist

	; if mousebutton/joystick 1  or 2 pressed then exit
	move.l copper,d0
	move.l d0,$dff080
	
	loop:
	btst.b #6,$bfe001
	beq exit
	btst.b #7,$bfe001
	beq exit	
	bra loop
	
	exit:
; exit gracefully - reverse everything done in init
	move.w #$7fff,DMACON
	move.w	dmasystem,DMACON
	move.w #$7fff,INTENA
	move.w	intenarsystem,INTENA
	move.w #$7fff,INTREQ
	move.w	intreqsystem,INTREQ
	move.w #$7fff,ADKCON
	move.w	adkonsystem,ADKCON

	move.l	coppersystem,$dff080
	move.l 	gfxbase,a6
	move.l 	viewsystem,a1
	jsr loadview(a6)	; LoadView
	jsr waittoff(a6)	; WaitTOF
	jsr waittoff(a6)	; WaitTOF
	jsr waitblit(a6)	; WaitBlit
	jsr disownblitter(a6)	; DisownBlitter
	move.l	$4,a6
	jsr permit(a6)	; Permit

	; end program
	rts
	
	
; *******************************************************************************
; *******************************************************************************
; DATA
; *******************************************************************************
; *******************************************************************************
	CNOP 0,4
coppersystem	dc.l 0
viewsystem		dc.l 0
gfxbase			dc.l 0


; Word aligned storage
	
dmasystem:		dc.w 0
adkonsystem		dc.w 0
intenarsystem	dc.w 0
intreqsystem	dc.w 0

	CNOP 0,4
	
gfxname:		dc.b 'graphics.library',0

	CNOP 0,4
; The following is graphic information that must reside in chipram for the custome chips to access it.
		section chipram,data_c
		
Palette:
	dc.l $01800000,$01820AAA,$01840024,$01860036
	dc.l $01880040,$018A0050,$018C0043,$018E0060
	dc.l $01900044,$01920055,$01940047,$01960410
	dc.l $01980777,$019A0403,$019C0440,$019E0660
	dc.l $01A00772,$01A20232,$01A40500,$01A60049
	dc.l $01A8006C,$01AA0080,$01AC00A0,$01AE00D0
	dc.l $01B0009F,$01B20991,$01B40CC1,$01B60FF4
	dc.l $01B80999,$01BA0555,$01BC0CCC,$01BE0FFF
	
	CNOP 0,4
	
; Bitplanes. 0-4
bp0:			blk.b 320/8*256,0	; (320/8=40 bytes per line. 40*256 lines gives 10200 bytes)
bp1:			blk.b 320/8*256,0
bp2:			blk.b 320/8*256,0
bp3:			blk.b 320/8*256,0
bp4:			blk.b 320/8*256,0

	cnop 0,4
copper:	
			dc.l $ffffffe 	; CHIPMEM!
			blk.l 1023,0 	; CHIPMEM!
	CNOP 0,4


img_bippy: incbin "dh3:Open_Screen1/gamescreen.raw"
BippyM is offline  
Old 18 March 2013, 21:25   #2
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,146
some hints:

move.w DMACONR,d0
move.w ADKCONR,d0
move.w INTENAR,d0
move.w INTREQR,d0

move.l gfxname,a1
StingRay is offline  
Old 18 March 2013, 21:30   #3
BippyM
Registered User

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 43
Posts: 8,696
What an idiot!

Code:
move.l CUSTOM,a6
move.w DMACONR(a6),d0
etc..
Thanks Stingray
BippyM is offline  
Old 18 March 2013, 21:38   #4
BippyM
Registered User

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 43
Posts: 8,696
Right well it now runs (once) shows a plain grey screen and exits.

Running a second time gives me a freeze again..

Oooh the joys!
BippyM is offline  
Old 18 March 2013, 21:38   #5
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 42
Posts: 3,085
Another hint (multiple problems):

Code:
	move.w	(320/8)*(256/4),d0
	move.l	#bp0,a0
	move.l	#bp1,a1
	move.l	#bp2,a2
	move.l	#bp3,a3
	move.l	#bp4,a4
	
	move.l	#img_bippy,a6
	clr.l	d7
	
	copy_img:
		move.l #320/8*256*5,d7	; bpl5
		move.l	(a6,d7.L),(a4)+		; This adds the contents of a6 to d7, and places the result in a4
		
		move.l #320/8*256*4,d7
		move.l	(a6,d7.L),(a3)+		; bpl4
		
		move.l #320/8*256*3,d7
		move.l	(a6,d7.L),(a3)+		; bpl3
		
		move.l #320/8*256*2,d7
		move.l	(a6,d7.L),(a3)+		; bpl2
		
		move.l (a6)+,(a0)+			; bpl0
		subq.w #1,d0
		bne copy_img

Last edited by Thorham; 18 March 2013 at 21:51.
Thorham is offline  
Old 18 March 2013, 21:44   #6
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,146
Quote:
Originally Posted by bippym View Post
Right well it now runs (once) shows a plain grey screen and exits.

Running a second time gives me a freeze again..

Oooh the joys!


move.w #%1000010111000000, DMACON ; DMA set ON
move.w #%0000000000111111, DMACON ; DMA set OFF
move.w #%1100000000000000, INTENA ; IRQ set ON
move.w #%0011111111111111, INTENA

Is this code really doing what it should? It explains the grey screen and the crashes.
StingRay is offline  
Old 18 March 2013, 21:47   #7
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 42
Posts: 3,085
Another hint:

Code:
    move.l  gfxname,a1
Thorham is offline  
Old 18 March 2013, 21:48   #8
BippyM
Registered User

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 43
Posts: 8,696
I'm gonna have to take a leap of faith here and say my maths is out!

I don't know why I don't just supply the actual address offset to d7 without the multiplication. I can add the math to the comments!
BippyM is offline  
Old 18 March 2013, 21:51   #9
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,146
Quote:
Originally Posted by Thorham View Post
Another hint:

Code:
    move.l  gfxname,a1
I gave that hint in my first post already.
StingRay is offline  
Old 18 March 2013, 21:56   #10
BippyM
Registered User

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 43
Posts: 8,696
Quote:
Originally Posted by StingRay View Post
move.w #%1000010111000000, DMACON ; DMA set ON
move.w #%0000000000111111, DMACON ; DMA set OFF
move.w #%1100000000000000, INTENA ; IRQ set ON
move.w #%0011111111111111, INTENA

Is this code really doing what it should? It explains the grey screen and the crashes.
Well I am still not 100% conversant with the DMA etc. I also know it is missing most of the address (CUSTOM).

Will play
BippyM is offline  
Old 18 March 2013, 22:44   #11
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 47
Posts: 80
There are quite a few things that have to be changed.

Do you want me to tell them directly, or just hint at them, like others here?
Vikke is offline  
Old 18 March 2013, 22:58   #12
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 47
Posts: 80
Quote:
Originally Posted by StingRay View Post
move.w #%1000010111000000, DMACON ; DMA set ON
move.w #%0000000000111111, DMACON ; DMA set OFF
move.w #%1100000000000000, INTENA ; IRQ set ON
move.w #%0011111111111111, INTENA

Is this code really doing what it should? It explains the grey screen and the crashes.
Why wouldn't this work?
DMA is set OFF for audio, disks and sprites, ON for blitter, copper, bitplanes and blitter nasty is also set

IRQ is set OFF for all interrupts except master interrupt.

I can't see any big problems in this case, but perhaps I'm wrong.
Vikke is offline  
Old 18 March 2013, 22:59   #13
BippyM
Registered User

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 43
Posts: 8,696
Re: Code issues

I've already made a few changes, all those relating to custom chipset offsets have been done.

I'd prefer hints or advice as opposed to the answer. I won't learn anything if someone else does it for me everytime
BippyM is offline  
Old 18 March 2013, 23:19   #14
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 47
Posts: 80
Ok Bippym, something to check out if aren't already corrected:

1.

BPL3PTH
BPL3PTL
BPL4PTH
BPL4PTL
BPL5PTH
BPL5PTL
BPL6PTH
BPL6PTL

values at the beginning...? Not really a crasher...


2. You already noticed the error with addressing the chipset, you can use an sddressregister for the purpose, but a macroassembler should be able to do this as well: CUSTOM+DMACONR


3. You got hinted at this already: move.l gfxname,a1
gfname is a pointer to a placeholder in memory, you don't want to assign the longword-value in (gfxname) into a1.


4. openLibrary should be called with the wanted minimum version number in d0


5. loadView wants the viewport in a1


6. if you want 256 lines on a display you have to change both DIWSTART/STOP and DDFSTART/STOP, calculating these values aren't the easiest of tasks


7. when assigning a new copperlist we are handling pointers, same as gfxname in #3


These are the things I noticed by going through the code quickly.
Vikke is offline  
Old 18 March 2013, 23:23   #15
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 47
Posts: 80
and of course I forgot this:

8. bitplane numbering goes from 0 upwards, and the offset for bpl0 is usually 0 (because of 320/8*256*0 = 0, for bpl1 the coefficient is 1 etc.
Also check that you are copying to the data to the right bitplane as this is a potential crasher writing data outside allocated area.
Vikke is offline  
Old 18 March 2013, 23:24   #16
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,146
Quote:
Originally Posted by Vikke View Post
I can't see any big problems in this case, but perhaps I'm wrong.
This code is completely wrong, check how f.e. DMACON is defined. $96 !=$dff096.
StingRay is offline  
Old 18 March 2013, 23:36   #17
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 47
Posts: 80
Quote:
Originally Posted by StingRay View Post
This code is completely wrong, check how f.e. DMACON is defined. $96 !=$dff096.
Yes of course it is wrong in addressing, but I think that was already sorted out. I thought you meant that the DMA and INT settings were wrong.
Vikke is offline  
Old 18 March 2013, 23:38   #18
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,146
No, because it doesn't matter which values are used there if none of the custom registers are used correctly. Also, when I posted it the issued wasn't sorted out at all.
StingRay is offline  
Old 18 March 2013, 23:42   #19
BippyM
Registered User

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 43
Posts: 8,696
Re: Code issues

I assume the dma is fixed. Need to go through and check all addressing etc. Then to check the offsets for each bitplane.I will be using the actual size as opposed to the formula.
BippyM is offline  
Old 19 March 2013, 00:01   #20
BippyM
Registered User

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 43
Posts: 8,696
Re: Code issues

Quote:
Originally Posted by Vikke View Post
Ok Bippym, something to check out if aren't already corrected:

5. loadView wants the viewport in a1


6. if you want 256 lines on a display you have to change both DIWSTART/STOP and DDFSTART/STOP, calculating these values aren't the easiest of tasks
$2cc1
BippyM 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
My lost code sardine Looking for a game name ? 0 21 July 2012 12:04
What's this code doing? Jherek Carnelia Coders. General 13 15 August 2011 18:55
vB code for strikethrough alexh project.EAB 3 07 May 2009 11:36
New EAB's vB Code RCK project.EAB 6 23 April 2003 22:39
3D code and/or internet code for Blitz Basic 2.1 EdzUp Retrogaming General Discussion 0 10 February 2002 12:40

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 02:54.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.
Page generated in 0.08941 seconds with 13 queries