English Amiga Board


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

 
 
Thread Tools
Old 18 March 2013, 23:55   #21
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 53
Posts: 80
Perhaps
And you probably don't need to change DDFSTRT/STOP I was thinking of overscan, as I have been doing some test my self in overscan-mode rather recently.
Vikke is offline  
Old 19 March 2013, 14:39   #22
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
can't do much else right now as my WinUAE has developed some dody error. I thin it is related to my coding, I think something has become corrupted. Even rebooting my PC wont allow me to boot anything via WINUAE!

Even booting with no startup causes it to crash!
BippyM is offline  
Old 19 March 2013, 15:22   #23
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 53
Posts: 80
Thats sad. Have you tried to reinstall WinUAE yet?

This actually gets me thinking about tweaking my Acronis backupsettings for my Amiga coding. Better take daily copies of the code, and all other related files as well
Vikke is offline  
Old 19 March 2013, 15:35   #24
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Re: Code issues

Well I have started using a different install which is running.

After lots of work it now runs, but I get crashed gfx. I think Bpl pointers are wrong, or cooperlist is

Code:
; 32 Col screen 1
; Open a 32 colour low-res screen, and display a picture in asm.
;
; 19/3/2013 14:30
;
; 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

start:
	movem.l	d0-d7/a0-a6,-(sp)


; Store the current system parameters so we can restore the system when we exit!
	lea			CUSTOM,a6

	move.w		DMACONR(a6),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(a6),d0						; Store contents of ADKON
	or.w		#$8000,d0
	move.w		d0,adkonsystem

	move.w		INTENAR(a6),d0
	or.w		#$8000,d0
	move.w		d0,intenarsystem

	move.w		INTREQR(a6),d0
	or.w		#$8000,d0
	move.w		d0,intreqsystem

; Next we need to take the system

	move.l		execbase.w,a6
	moveq.l		#0,d0							; Minimum lib version
	lea			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,a1
	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	#2560,d0		; 2560 longs (320/8)*(256/4)
	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 #10240*4,d7	; bpl5
		move.l	(a6,d7.L),(a4)+		; This adds the contents of a6 to d7, and places the result in a4
		
		move.l #10240*3,d7
		move.l	(a6,d7.L),(a3)+		; bpl4
		
		move.l #10240*2,d7
		move.l	(a6,d7.L),(a2)+		; bpl3
		
		move.l #10240,d7
		move.l	(a6,d7.L),(a1)+		; 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.
	lea		CUSTOM,a6	
	move.w	#$5200,BPLCON0(a6)				; 5 bitplane lowres mode
	move.w	#$0000,BPLCON1(a6)				; horizontal scroll 0
	move.w	#$0000,BPL1MOD(a6)				; odd modulo 0
	move.w	#$0000,BPL2MOD(a6)				; even modulo 0
	move.w	#$2c81,DIWSTRT(a6)				; DIWSTRT - topleft corner (2c81)
	move.w	#$2cc1,DIWSTOP(a6)				; DIVSTOP - bottomright corner (f4d1)
	move.w	#$0038,DDFSTRT(a6)				; DDFSTRT - max overscan $0018 ; standard 0038 & 00d0
	move.w	#$00d0,DDFSTOP(a6)				; DDFSTOP - max overscan $00d8 ; max overscan: 368x283px in PAL
	move.w 	#%1000010111000000, DMACON(a6)	; DMA set ON
	move.w 	#%0000000000111111, DMACON(a6)	; DMA set OFF
	move.w 	#%1100000000000000, INTENA(a6)	; IRQ set ON
	move.w 	#%0011111111111111, INTENA(a6)	; 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
	lea CUSTOM,a6
	move.w #$7fff,DMACON(a6)
	move.w	dmasystem,DMACON(a6)
	move.w #$7fff,INTENA(a6)
	move.w	intenarsystem,INTENA(a6)
	move.w #$7fff,INTREQ(a6)
	move.w	intreqsystem,INTREQ(a6)
	move.w #$7fff,ADKCON(a6)
	move.w	adkonsystem,ADKCON(a6)

	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
	movem.l	(sp)+,d0-d7/a0-a6
	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"

Last edited by BippyM; 19 March 2013 at 15:44.
BippyM is offline  
Old 19 March 2013, 16:51   #25
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
My suggestions for approaches to fixing anything that doesn't work right:

Narrow down your search for the error as far as possible by first thinking logically about where the type of error seen can and cannot occur.

Test pieces of code in isolation using the debugger and make sure that what you have assumed is working code really is working code.

Sleep on it. This might sound trite but I have fixed many annoying little issues in my code by taking myself away from something that doesn't work, stopping thinking about it, getting a good night's sleep and looking again in the morning with a fresh pair of eyes.

Once all of the above has been done exhaustively and something still doesn't work, only then ask for help.

Don't let asking for the answers become a substitute for logical thinking and testing. It'll help in the short term (you'll fix the problems quicker) but will hinder in the long term as you won't have gained any of the really worthwhile experience of finding and fixing a problem yourself which is where all your real learning is done.

I hope the above is taken in the spirit that it was written with: as helpful advice that I really believe is true. Good luck with fixing your code!
pmc is offline  
Old 19 March 2013, 17:04   #26
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 53
Posts: 80
pmc,

you're absolutely right, and I would suggest using REM (start remark) and EREM (end remark) to filter out code to be able to narrow down on the bug/bugs.
Vikke is offline  
Old 19 March 2013, 17:21   #27
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 53
Posts: 80
bippy,

Even though I just commented that it would be best to learn by doing it by yourself, I will give one more clue (and this was a little hard for me to notice, as I am used to using addresses in hex-value for the chipset):

When setting up the bitplanes for the copper, and having the real address as a longword in a dataregister it is possible to just write the lower word first and then swap the two words in the longword around and then write the new lower word (previous upper word).

You are trying to do it here:
Code:
	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)+
But take care to look at the order on how the words in the longword d0 gets written.

And one last thing, and everything should work: I already mentioned the BPLxPTL/H values at the beginning of your code, check them one more time.
Vikke is offline  
Old 19 March 2013, 18:09   #28
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
@bippym - what Vikke said and this is a nice example of something that could easily be found and fixed by following the first two steps in my previous post.
pmc is offline  
Old 19 March 2013, 19:45   #29
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 53
Posts: 80
Hmmm.....

I have a feeling this error with writing the wrong word into the wrong pointer can be because of me.

I looked at the remarks, and they seemed a little too familiar. I think you have looked at my code, and it seems like I have written the remarks wrong

Sorry for that. I have to update the sources on my site. Documenting the source is _a lot_ harder than just making the code, when you get into the "coding-mode" everything is so clear, but later on when you have to put remarks you have already lost a bit of the inspiration for the code and get sloppy
Vikke is offline  
Old 19 March 2013, 19:50   #30
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by Vikke View Post
when you get into the "coding-mode" everything is so clear, but later on when you have to put remarks you have already lost a bit of the inspiration for the code and get sloppy
That sounds very familiar. However, especially in the case of tutorials, remember the old saying: Wrong comments are worse than no comments. Which is totally true IMHO.
StingRay is offline  
Old 19 March 2013, 19:59   #31
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by Vikke
I looked at the remarks, and they seemed a little too familiar. I think you have looked at my code, and it seems like I have written the remarks wrong
Well... these things can happen sometimes. Certainly nothing to beat yourself up over.

However, one thing it does show goes back to what I said recently about source codes: don't confuse having source codes with learning asm. Unfortunately the temptation can sometimes be to trust something in a source code that has been done slightly wrong and lead yourself astray. That just highlights the difference between *thinking* you understand how something works and *really* understanding it...
pmc is offline  
Old 19 March 2013, 20:01   #32
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Well said pmc! I couldn't agree more.
StingRay is offline  
Old 19 March 2013, 20:04   #33
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 53
Posts: 80
Yes, one shouldn't make errors in remarks in code. I will from now on double check everything that is of importance.

And looking at earlier versions of my codesnippets I can see from where the wrong comments came into the code.
At first I wanted to write the Hi-bits first, and then the Lo-bits, as it is the "normal" way of thinking in a big-endian system. However at some point I decided I didn't want an extra SWAP-instruction, so I made some small changes to the code. But of course not to the comments. Bah humbug!

Last edited by Vikke; 19 March 2013 at 20:22.
Vikke is offline  
Old 19 March 2013, 20:15   #34
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 53
Posts: 80
pmc, you are of course right. However in coding the same golden formula applies as to learning mathematics: theory, demonstration and exercise. Theory you can read on your own, demonstration would be available sources and then the last and most important thing doing it yourself.

I think it may be useful to learn assembly coding by doing it yourself first, but putting too much time on hunting for bugs early in your learning curve isn't productive. It can be done, and we that started a long time ago didn't have any other possibilities than to hunt down those bug, no matter how long it took. Now with the internet I think it is good to be able to get a helping hand once in a while.
When you progress in your learning, then it is absolutely vital to be able to find those pesky bugs yourself. And really, in my opinion the best way of learning almost everything is the trial-and-error-method.
Vikke is offline  
Old 19 March 2013, 21:16   #35
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Re: Code issues

I've started again, and I am trying a different approach.

The point of me basing this on previous code, is to give me a basic to understanding of how stuff is stored etc, how the system offsets are accessed etc.

Anyway this time a little less ambitious. An 8 colour screen using a basic copperlist.

I'll post more soon

Here is my plan

Code:
; 8 Col screen 1
; Open an 8 colour low-res screen, and display a picture in asm.
;
; 19/3/2013 14:30
;
; Process for opening the screen is:
;
; 1). Backup current system. View, Copper,DMA, Audio/Disk controller (ADKON), Interrupts (INTENA, INTREQ)
; 2). Load in the GFX file and setup the bitplane pointers
; 3). Setup the palette
; 4). Create my copperlist (Include the enabling of the DMA, interrupts etc)
; 5). Copy the copper address into COP1
; 7). Start the copper to display the picture
; 8). Display picture for 5 seconds (or so)
; 9). Restore the system copper(s), view and DMA, Interrupts etc
; 10). Exit the program

Last edited by BippyM; 19 March 2013 at 21:31.
BippyM is offline  
Old 19 March 2013, 22:37   #36
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Quote:
Originally Posted by bippym View Post
I've started again, and I am trying a different approach.
Sometimes it is good idea to start again with a fresh approach and a mentally recharged head. Sometimes it is too easy to waste time trying to fix something, when a few minutes rest will allow the answer to come to you

The other smart option is to print out the code (assuming the code isn't too long) and work through it manually.
Lonewolf10 is offline  
Old 20 March 2013, 19:04   #37
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Quick question.

Do I disable the dma and interrupts, build my copperlist then enable copper and bitplane DMA, or disable then enable?
BippyM is offline  
Old 20 March 2013, 21:08   #38
Vikke
Registered User
 
Join Date: Feb 2013
Location: Lovisa / Finland
Age: 53
Posts: 80
You don't have to disable DMA or INT when doing a copperlist. The new copperlist get activated by moving the address of the start of the copperlist to COPxLCH & COPxLCL , after the address is written, then you have to write to the associated COPJMPx strobe-address (just write #$0000 to COPJMPx).

EDIT: There are 2 possible copperlists: namely 1 and 2, that can be used, just trigger the right copperlist by writing to its strobe-address.
Vikke is offline  
Old 20 March 2013, 22:23   #39
Lonewolf10
AMOS Extensions Developer
 
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 44
Posts: 1,924
Quote:
Originally Posted by Vikke View Post
You don't have to disable DMA or INT when doing a copperlist.
But what if you are modifying the currently active one (not sure why anyone would do that!)? Presumably it would crash the Amiga, or at very least corrupt the screen?


Quote:
Originally Posted by bippym View Post
Do I disable the dma and interrupts, build my copperlist then enable copper and bitplane DMA, or disable then enable?

As Vikke says, you don't have to disable them.

Normally it is best to have 2 separate copperlists... one that is active and another that is being modified, and swap between them when necessary by writing the new address to the appropriate register.
Lonewolf10 is offline  
Old 20 March 2013, 22:28   #40
BippyM
Global Moderator
 
BippyM's Avatar
 
Join Date: Nov 2001
Location: Derby, UK
Age: 48
Posts: 9,355
Okay,

well I have disabled the system and blanked the screen.

I am simply displaying a picture, I assume once the copperlist is displayed I can wait and then exit.

Will play tomorrow. Been fishing today so pretty knackered atm!
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 11:04
What's this code doing? Jherek Carnelia Coders. General 13 15 August 2011 17:55
vB code for strikethrough alexh project.EAB 3 07 May 2009 10:36
New EAB's vB Code RCK project.EAB 6 23 April 2003 21:39
3D code and/or internet code for Blitz Basic 2.1 EdzUp Retrogaming General Discussion 0 10 February 2002 11: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 11:07.

Top

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