English Amiga Board

English Amiga Board (https://eab.abime.net/index.php)
-   Coders. Asm / Hardware (https://eab.abime.net/forumdisplay.php?f=112)
-   -   Why the screen does not open? (https://eab.abime.net/showthread.php?t=107692)

TCH 21 July 2021 21:57

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?

ross 21 July 2021 22:01

move.l #copperlist,COP1LCH(a2)

Galahad/FLT 21 July 2021 22:10

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.

TCH 21 July 2021 22:38

Quote:

Originally Posted by ross (Post 1497019)
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 (Post 1497024)
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 (Post 1497024)
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 (Post 1497024)
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.

ross 21 July 2021 22:41

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 :)

TCH 21 July 2021 22:50

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?

roondar 21 July 2021 22:58

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.

ross 21 July 2021 23:00

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 ;)

Galahad/FLT 21 July 2021 23:04

Quote:

Originally Posted by TCH (Post 1497031)
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

redblade 21 July 2021 23:04

Quote:

Originally Posted by ross (Post 1497037)
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.

roondar 21 July 2021 23:10

Quote:

Originally Posted by Galahad/FLT (Post 1497039)
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.

TCH 21 July 2021 23:17

Quote:

Originally Posted by roondar (Post 1497036)
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 (Post 1497037)
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 (Post 1497039)
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 (Post 1497040)
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 (Post 1497043)
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.

ross 21 July 2021 23:27

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 :p

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


roondar 21 July 2021 23:32

Quote:

Originally Posted by TCH (Post 1497045)
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?

ross 21 July 2021 23:45

Quote:

Originally Posted by roondar (Post 1497049)
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.

TCH 22 July 2021 00:06

Quote:

Originally Posted by ross (Post 1497048)
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 (Post 1497049)
Regardless, it is needed for it to work - I made that mistake so many times :)

I see, thanks.
Quote:

Originally Posted by roondar (Post 1497049)
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 (Post 1497049)
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 (Post 1497052)
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?

ross 22 July 2021 00:20

Quote:

Originally Posted by TCH (Post 1497058)
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.

StingRay 22 July 2021 00:22

Quote:

Originally Posted by TCH (Post 1497058)
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.

TCH 22 July 2021 00:28

Sorry, in the meantime, i've noticed the
move.l      38(a5),$80(a2)
Quote:

Originally Posted by ross (Post 1497063)
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

ross 22 July 2021 00:37

Quote:

Originally Posted by TCH (Post 1497067)
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.


All times are GMT +2. The time now is 22:25.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.

Page generated in 0.05679 seconds with 11 queries