[comp.sys.amiga] Help changing custom screen's palette

lphillips@lpami.wimsey.bc.ca (Larry Phillips) (02/12/90)

In <2300@ucqais.uc.edu>, rbatra@ucqais.uc.edu (pri=2 Rajesh Batra) writes:
>	I am trying to change the colors of a custom screen. But instead
>the workbench screen's palette changes, and my custom screen's colors remain 
>unchanged. I used the library call LOADRGB4. Would someone
>please tell me what I am doing wrong? Here is some of the source:
>
>       [ code deleted ]
>
>       move.l 44(a0),a0   ;Loads screen's viewport into register a0.
>
> [code deleted
>
>----------------
>	If you think the error is so obvious that you would rather spare
>me the embarrassment please email me the solution to: 

I don't think you have to be too embarrassed.

What you have done in the abover excerpted line is to load up a pointer to the
_next_ ViewPort. This is because a ViewPort structure is contained in the
Screen struct, rather than a pointer to a ViewPort. The operation you want is:

       add.l  #sc_ViewPort,a0   ; ( or  add.l #44,a0 to use your terms )

Since the pointer to the Screen struct is in a0, adding 44 to it will make it a
pointer to the ViewPort. Your line moved the contents of the first longword in
the ViewPort struct to a0, which pointed you at the next ViewPort.

-larry

--
Gallium Arsenide is the technology of the future;
  always has been, always will be.
+-----------------------------------------------------------------------+ 
|   //   Larry Phillips                                                 |
| \X/    lphillips@lpami.wimsey.bc.ca -or- uunet!van-bc!lpami!lphillips |
|        COMPUSERVE: 76703,4322  -or-  76703.4322@compuserve.com        |
+-----------------------------------------------------------------------+

rbatra@ucqais.uc.edu (pri=2 Rajesh Batra) (02/12/90)

	I am trying to change the colors of a custom screen. But instead
the workbench screen's palette changes, and my custom screen's colors remain 
unchanged. I used the library call LOADRGB4. Would someone
please tell me what I am doing wrong? Here is some of the source:

openscrn= -198
loadrgb4= -192

       move.l intbase,a6
       lea newscreenstructure,a0
       jsr openscrn(a6)       ;The above just opened a custom screen.
       move.l d0,screenhd     ;Saves the screen stucture for later use.
       move.l screenhd,a0
       move.l 44(a0),a0   ;Loads screen's viewport into register a0.
       lea palette,a1     
       moveq #4,d0
       move.l gfxbase,a6
       jsr loadrgb4(a6)  ;And here the workbench colors change!

NewScreenStructure:
 dc.w 0,0 ;screen XY origin relative to View
 dc.w 640,200 ;screen width and height
 dc.w 2 ;screen depth (number of bitplanes)
 dc.b 0,1 ;detail and block pens
 dc.w $8000 ;display modes for this screen v_hires
 dc.w 15 ;screen type custom screen.
 dc.l NULL ;pointer to default screen font
 dc.l NULL ;screen title
 dc.l NULL ;first in list of custom screen gadgets
 dc.l NULL ;pointer to custom BitMap structure

Palette:
 dc.w $0000 ;color #0
 dc.w $0777 ;color #1
 dc.w $000C ;color #2
 dc.w $0F00 ;color #3

       align
screenhd: dc.l 0
gfxbase: dc.l 0
intbase: dc.l 0

----------------
	If you think the error is so obvious that you would rather spare
me the embarrassment please email me the solution to: 

		rbatra@ucqais.uc.edu
	or	rbatra@uceng.uc.edu
	
						Thanks,
				
						Rajesh Batra

bartonr@jove.cs.pdx.edu (Robert Barton) (02/14/90)

>    I am trying to change the colors of a custom screen. But instead the
> workbench screen's palette changes, and my custom screen's colors remain
> unchanged.
>
>       move.l intbase,a6
>       lea newscreenstructure,a0
>       jsr openscrn(a6)       ;The above just opened a custom screen.
>       move.l d0,screenhd     ;Saves the screen stucture for later use.

  You should check screenhd for a non-NULL value at this point.

>       move.l screenhd,a0
>       move.l 44(a0),a0   ;Loads screen's viewport into register a0.

  This is where you have the problem.  The viewport field is a substructure of
the screen structure, and not a pointer.  So the move.l 44(a0),a0 is putting
the first longword of the viewport into a0, rather than the address of the vp.
This longword just happens to be a pointer to the next viewport, which in this
case is the Workbench's viewport.  So that's where the new colors show up.
You need to use lea 44(a0),a0.