English Amiga Board


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

 
 
Thread Tools
Old 21 July 2021, 21:57   #1
TCH
Newbie Amiga programmer
 
TCH's Avatar
 
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
Why the screen does not open?

I have this code:
Code:
		move.l		CUSTOM,a2
		move.w		DMACONR(a2),d1				; Old DMA flags in d1.
		move.l		$4,a6					; Open graphics.library.
		move.l		#graphics_lib,a1
		jsr		OldOpenLibrary(a6)
		move.l		d0,a3					; graphics.library handle stored in a3.
		move.l		38(a6),d2				; Old Copper settings in d2.
		move.l 		a3,a6					; Wait for finish.
		jsr		WaitTOF(a6)
		move.l		$4,a6					; Set new DMA and Copper.
		jsr		Disable(a6)
		move.l		copperlist,COP1LCH(a2)
		move.w		#$7fff,DMACON(a2)
		move.w		#SETCLR|COPEN|BPLEN,DMACON(a2)

		move.l		#CIAA+CIAPRA,a1
WaitForLMB:	btst		#bFIR0,(a1)
		bne		WaitForLMB

...

Exit:		move.w		#$7fff,DMACON(a2)			; Restore old DMA flags.
		or.w		#SETCLR,d1
		move.w		d1,DMACON(a2)
		move.l		d2,COP1LCH(a2)				; Restore old Copper settings.
		move.l		a3,a6					; Wait for finish.
		jsr		WaitTOF(a6)
		move.l		$4,a6					; Close graphics.library.
		move.l		a3,a1
		jsr		CloseLibrary(a6)
		moveq		#0,d0					; Exit.
		jmp		Enable(a6)

...

graphics_lib:	dc.b		"graphics.library",0
		align		2
copperlist:	dc.w		BPL1PTH,$0007
		dc.w		BPL1PTL,$c080
		dc.w		BPL2PTH,$0007
		dc.w		BPL2PTL,$dfc0
		dc.w		BPL1MOD,$0000
		dc.w		BPL2MOD,$0000
		dc.w		BPLCON0,(BPUx*2)|COLOR
		dc.w		BPLCON1,$0000
		dc.w		BPLCON2,$0010
		dc.w		DIWSTRT,$2c81
		dc.w		DIWSTOP,$2cc1
		dc.w		DDFSTRT,$0038
		dc.w		DDFSTOP,$00d0
		dc.w		COLOR00,$0000
		dc.w		COLOR01,$0080
		dc.w		COLOR02,$00f0
		dc.w		COLOR03,$0fff
		dc.w		$ffff,$fffe
When i run it, the screen freezes/mouse freezes, but when i click, it properly exits and comes back to the shell. Why the screen does not open?
TCH is offline  
Old 21 July 2021, 22:01   #2
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
move.l #copperlist,COP1LCH(a2)
ross is offline  
Old 21 July 2021, 22:10   #3
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
And also, as well as what Ross said, is your copper list in chipmem?

Also at start of code it should be move.l #custom, a2

Also your copper list sets bitplane 1 as $7c080 and bitplane 2 as $7dfc0, yet there is nothing in your code to suggest you are clearing or setting any data at those addresses.

Last edited by Galahad/FLT; 21 July 2021 at 22:28.
Galahad/FLT is offline  
Old 21 July 2021, 22:38   #4
TCH
Newbie Amiga programmer
 
TCH's Avatar
 
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
Quote:
Originally Posted by ross View Post
move.l #copperlist,COP1LCH(a2)
Originally it was that, with the hashmark, but if i do it that way, then the executable becomes corrupted and the Amiga refuses to run it with error 121...
Quote:
Originally Posted by Galahad/FLT View Post
And also, as well as what Ross said, is your copper list in chipmem?
Must be, as there is no FastRAM in the machine...but point taken, you're right, if someone runs the program with a machine with FastRAM, then the Amiga will most likely load it into the FastRAM, thanks for pointing out.
Quote:
Originally Posted by Galahad/FLT View Post
Also at start of code it should be move.l #custom, a2
If i do that, the entire machine crashes when i run the program. This way it works, just the screen does not open. The disassembly also shows correct values for
CUSTOM
.
Quote:
Originally Posted by Galahad/FLT View Post
Also your copper list sets bitplane 1 as $7c080 and bitplane 2 as $7dfc0, yet there is nothing in your code to suggest you are clearing or setting any data at those addresses.
True, but this code is not needed to be system friendly; right after it finishes, a single-task game will take over.
TCH is offline  
Old 21 July 2021, 22:41   #5
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Well, there are quite a few mistakes in fact...

move.w DMACONR(a2),d1
....
or.w #SETCLR,d1
move.w d1,DMACON(a2)

and there are system calls in between that don't preserve the value of D1

I just looked quickly, probably there is more
ross is offline  
Old 21 July 2021, 22:50   #6
TCH
Newbie Amiga programmer
 
TCH's Avatar
 
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
Okay, maybe, but that code is at the exit, when the program closes the graphics library. It does not explain why the screen is not opening, as d1 is not used anywhere else. But thanks for pointing out, d1 and d2 should be stored in a variable.

Edit: Aaaaand if i try to store them in a variable, then the exe is corrupted again and refuses to run with error 121. What is this?

Last edited by TCH; 21 July 2021 at 22:57. Reason: error 121
TCH is offline  
Old 21 July 2021, 22:58   #7
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,406
One possibility is the DMACON value.
You set it to
Code:
move.w		#SETCLR|COPEN|BPLEN,DMACON(a2)
But this is not correct, you need to set the DMAEN bit (bit 9) as well.
Edit: I know this sounds like an odd thing, but DMAEN does not do what you might think if you read the HRM description. The HRM description suggests it activates all the DMA channels in bits 0-8. Instead, it merely makes it so that you can enable the DMA in those bits.

Last edited by roondar; 21 July 2021 at 23:12.
roondar is offline  
Old 21 July 2021, 23:00   #8
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
jsr OldOpenLibrary(a6)
move.l d0,a3 ; graphics.library handle stored in a3.
move.l 38(a6),d2 ; Old Copper settings in d2.

38(a6) read from execbase...

Rewrite it from scratch with more attention.
In assembler you cannot afford errors of any kind
ross is offline  
Old 21 July 2021, 23:04   #9
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
Quote:
Originally Posted by TCH View Post
Originally it was that, with the hashmark, but if i do it that way, then the executable becomes corrupted and the Amiga refuses to run it with error 121...Must be, as there is no FastRAM in the machine...but point taken, you're right, if someone runs the program with a machine with FastRAM, then the Amiga will most likely load it into the FastRAM, thanks for pointing out.If i do that, the entire machine crashes when i run the program. This way it works, just the screen does not open. The disassembly also shows correct values for
CUSTOM
.True, but this code is not needed to be system friendly; right after it finishes, a single-task game will take over.
But it's not working

Its "working" completely by accident, not by design.

Your first line is moving the contents of $dff000 into a2, when the value $dff000 should be in a2.

If that line is incorrect, the next line is also wrong as it's not going to be pulling from the correct register.

So here is my advice.

Cut first two lines.

Where you move #$7fff,dmacon(a2), put that before your move of the copper list, dont forget # Ross told you.

The two top lines you cut from the top, put them both before the #$7fff,dmacon(a2), not forgetting the # in front of custom.

Make sure custom = $dff000
Make sure setclr= $8000

That big setup for DMA before you wait for left mouse button, trim all that out and put in the value $87d0
See how you get on
Galahad/FLT is offline  
Old 21 July 2021, 23:04   #10
redblade
Zone Friend
 
redblade's Avatar
 
Join Date: Mar 2004
Location: Middle Earth
Age: 40
Posts: 2,127
Quote:
Originally Posted by ross View Post
38(a6) read from execbase...

Rewrite it from scratch with more attention.
In assembler you cannot afford errors of any kind
I was about to post that one..
TCH: What assembler are you using? I got used to seeing that blinking red box (GURU) quite quickly.
redblade is offline  
Old 21 July 2021, 23:10   #11
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,406
Quote:
Originally Posted by Galahad/FLT View Post
Your first line is moving the contents of $dff000 into a2, when the value $dff000 should be in a2.
I completely missed that. Yeah 100%. It should either be lea CUSTOM,a2 or move.l #CUSTOM,a2.
roondar is offline  
Old 21 July 2021, 23:17   #12
TCH
Newbie Amiga programmer
 
TCH's Avatar
 
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
Quote:
Originally Posted by roondar View Post
One possibility is the DMACON value.
You set it to
Code:
move.w		#SETCLR|COPEN|BPLEN,DMACON(a2)
But this is not correct, you need to set the DMAEN bit (bit 9) as well.
Edit: I know this sounds like an odd thing, but DMAEN does not do what you might think if you read the HRM description. The HRM description suggests it activates all the DMA channels in bits 0-8. Instead, it merely makes it so that you can enable the DMA in those bits.
Thanks, but nothing changed.

Also, this line:
move.w		DMACONR(a5),DMABackup
causes the program to refuse to run with error 121. Why? It does not help, if i put the value into
d1
first.
Quote:
Originally Posted by ross View Post
jsr OldOpenLibrary(a6)
move.l d0,a3 ; graphics.library handle stored in a3.
move.l 38(a6),d2 ; Old Copper settings in d2.

38(a6) read from execbase...

Rewrite it from scratch with more attention.
In assembler you cannot afford errors of any kind
Thanks. It's late. :P
Quote:
Originally Posted by Galahad/FLT View Post
Cut first two lines.

Where you move #$7fff,dmacon(a2), put that before your move of the copper list, dont forget # Ross told you.

The two top lines you cut from the top, put them both before the #$7fff,dmacon(a2), not forgetting the # in front of custom.

Make sure custom = $dff000
Make sure setclr= $8000

That big setup for DMA before you wait for left mouse button, trim all that out and put in the value $87d0
I did. New code snippet:
Code:
		move.l		#CUSTOM,a2
		move.w		DMACONR(a2),d1				; Old DMA flags in d1.
		move.w		#$7fff,DMACON(a2)
		move.l		#copperlist,COP1LCH(a2)
		move.w		#$87d0,DMACON(a2)
Result: error 121, does not run.
Quote:
Originally Posted by redblade View Post
TCH: What assembler are you using? I got used to seeing that blinking red box (GURU) quite quickly.
It's vasm.
Quote:
Originally Posted by roondar View Post
I completely missed that. Yeah 100%. It should either be lea CUSTOM,a2 or move.l #CUSTOM,a2.
Thanks, that was it!
lea
was the correct solution, if i used the hashmark, then error 121 was all i got. Finally, a black screen. I now will test, if the bitplanes are in the right place.

Edit: If i try to save the original copper and DMA into variables instead of d1 and d2, then the program crashes...

Edit: Galahad, you were right about the
$87d0
, thanks.

Last edited by TCH; 21 July 2021 at 23:27. Reason: too much post, lost track, fixing
TCH is offline  
Old 21 July 2021, 23:27   #13
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
The following code is the 'correct' version of what you tried to do.
I would never write it like this, too many important parts are missing

For the old farts, don't look at me badly, I just got the code and "fixed" it

Code:
_LVODisable            equ     -120
_LVOEnable             equ     -126
_LVOOldOpenLibrary     equ     -408
_LVOCloseLibrary       equ     -414
_LVOWaitTOF            equ     -270


        SECTION code,CODE_C

        lea         $dff000,a2
        move.l      $4.w,a6                 ; Open graphics.library.

        lea         graphics_lib(pc),a1
        jsr         _LVOOldOpenLibrary(a6)
        move.l      d0,a5                   ; graphics.library handle stored in a5.

        jsr         _LVODisable(a6)
        lea         copperlist(pc),a0
        move.l      a0,$80(a2)

        move.w      #$8000,d0
        or.w        2(a2),d0                ; Old DMA flags in d0.
        move.w      #$7fff,$96(a2)
        move.w      #$8380,$96(a2)

WaitForLMB:
        btst        #6,$bfe001
        bne.b       WaitForLMB

Exit:   move.w      #$7fff,$96(a2)
        move.l      38(a5),$80(a2)          ; Restore old Copper settings.
        move.w      d0,$96(a2)              ; Restore old DMA flags.

        jsr         _LVOEnable(a6)
        move.l      a5,a1
        jsr         _LVOCloseLibrary(a6)
        moveq       #0,d0                   ; Exit.
        rts

graphics_lib:   dc.b        "graphics.library",0
        even

copperlist:
        dc.w        $e0,$0007
        dc.w        $e2,$c080
        dc.w        $e4,$0007
        dc.w        $e6,$dfc0
        dc.w        $108,$0000
        dc.w        $10a,$0000
        dc.w        $100,$2200
        dc.w        $102,$0000
        dc.w        $104,$0010
        dc.w        $8e,$2c81
        dc.w        $90,$2cc1
        dc.w        $92,$0038
        dc.w        $94,$00d0
        dc.w        $180,$0000
        dc.w        $182,$0080
        dc.w        $184,$00f0
        dc.w        $186,$0fff
        dc.w        $ffff,$fffe

Last edited by ross; 21 July 2021 at 23:42. Reason: code pc relative
ross is offline  
Old 21 July 2021, 23:32   #14
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,406
Quote:
Originally Posted by TCH View Post
Thanks, but nothing changed.
Regardless, it is needed for it to work - I made that mistake so many times
Quote:
Also, this line:
move.w        DMACONR(a5),DMABackup


Edit: If i try to save the original copper and DMA into variables instead of d1 and d2, then the program crashes...
If you're aiming this at a standard A500 with a 68000, your variables need to be aligned to an address which is a multiple of two. If they aren't, you can get a crash. However, I can't be certain this is the case here because you didn't show the part of the code where you declare the variables. Something worth checking for sure.

About error 121: this means your assembled program is not a proper executable. What VASM/VLINK flags are you using and what version of Kickstart/Workbench are you running your code on?
roondar is offline  
Old 21 July 2021, 23:45   #15
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by roondar View Post
About error 121: this means your assembled program is not a proper executable. What VASM/VLINK flags are you using and what version of Kickstart/Workbench are you running your code on?
This is a good point.
vasm require
-kick1hunks
to be KS1.x compatible, probably by default it generates reloc tables for KS2.0+ only.

I edited the code to be fully pc relative, so problem solved at the root.
ross is offline  
Old 22 July 2021, 00:06   #16
TCH
Newbie Amiga programmer
 
TCH's Avatar
 
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
Quote:
Originally Posted by ross View Post
The following code is the 'correct' version of what you tried to do.
Thanks, it is much more clearer. (Although i canot store the DMA value in d0, i need that register, so that will be changed.) What is this
LVO
prefix?
Quote:
Originally Posted by roondar View Post
Regardless, it is needed for it to work - I made that mistake so many times
I see, thanks.
Quote:
Originally Posted by roondar View Post
If you're aiming this at a standard A500 with a 68000, your variables need to be aligned to an address which is a multiple of two. If they aren't, you can get a crash. However, I can't be certain this is the case here because you didn't show the part of the code where you declare the variables. Something worth checking for sure.
You must be right, i am an idiot.
Quote:
Originally Posted by roondar View Post
About error 121: this means your assembled program is not a proper executable. What VASM/VLINK flags are you using and what version of Kickstart/Workbench are you running your code on?
-Fhunkexe -nosym
KickStart 1.3, there is no WorkBench.
Quote:
Originally Posted by ross View Post
This is a good point.
vasm require
-kick1hunks
to be KS1.x compatible, probably by default it generates reloc tables for KS2.0+ only.

I edited the code to be fully pc relative, so problem solved at the root.
Well, it only happened when i tried to access some variables, it worked without
-kick1hunks
, so roondar must be right about the alignment. If i use
-kick1hunks
, then it will not be usable under KS 2.0? (Although the targetted game itself has glitches over 1.3, so it is not recommended to run it on KS 2.0+ anyway.)

Edit: @ross: You open
graphics.library
, but do not call anything from it, you've removed the
WaitTOF
calls; if it is not needed, why open it?

Last edited by TCH; 22 July 2021 at 00:19.
TCH is offline  
Old 22 July 2021, 00:20   #17
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by TCH View Post
Thanks, it is much more clearer. (Although i canot store the DMA value in d0, i need that register.
Sure, you can use what is useful to you in the code.
But as I told you in a previous message, and it seems to me that you did not get the point from your reply, it is that when you call the system functions you cannot save variables into d0/d1/a0/a1 because they are scratch registers.
Unlike you, I don't have any calls in this piece of code so I took the first free register available

Quote:
What is this
LVO
prefix?
Library Vector Offsets

Quote:
If i use -kick1hunks, then it will not be usable under KS 2.0?
Absolutely use it if you want your exe to work on old KS!
KS2.0 are fully compatiple with old generated hunk.

Quote:
Edit: @ross: You open
graphics.library
, but do not call anything from it, you've removed the
WaitTOF
calls; if it is not needed, why open it?
To grab system copper list..
About WaitTOF: not the right way to use it, so useless in your case.
ross is offline  
Old 22 July 2021, 00:22   #18
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by TCH View Post
What is this
LVO
prefix?
L.ibrary V.ector O.ffset

Quote:
You open
graphics.library
, but do not call anything from it, you've removed the
WaitTOF
calls; if it is not needed, why open it?
It is used to restore the system copperlists.
StingRay is offline  
Old 22 July 2021, 00:28   #19
TCH
Newbie Amiga programmer
 
TCH's Avatar
 
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
Sorry, in the meantime, i've noticed the
move.l      38(a5),$80(a2)
Quote:
Originally Posted by ross View Post
But as I told you in a previous message, and it seems to me that you did not get the point from your reply, it is that when you call the system functions you cannot save variables into d0/d1/a0/a1 because they are scratch registers.
No-no, point taken, i will place them in variables. Aligned ones. :P
TCH is offline  
Old 22 July 2021, 00:37   #20
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,468
Quote:
Originally Posted by TCH View Post
No-no, point taken, i will place them in variables. Aligned ones. :P
Quote:
Okay, maybe, but that code is at the exit, when the program closes the graphics library. It does not explain why the screen is not opening, as d1 is not used anywhere else. But thanks for pointing out, d1 and d2 should be stored in a variable.
The point is only regs d0/d1/a0/a1 are scratch registers for system calls (there are very few excetions, well documented in Autodocs).
So you have plenty of registers (or stack) to save (temp)variables.
ross 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
open chunky screen grond Coders. System 7 02 February 2016 16:31
Open Screen / Open Font AGS Coders. System 7 02 March 2014 05:08
Open Amiga Game Database - Open Beta FrodeSolheim support.FS-UAE 3 01 May 2013 22:37
Amiga 600 not booting... Yellow screen, and Red screen when turning PSU off jbenam support.Hardware 34 20 March 2011 22:10
Need a small win98 prog, to open and close a directX screen... keropi Retrogaming General Discussion 9 25 April 2008 18:43

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 08:27.

Top

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