28 November 2013, 22:48 | #1 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
Help with Amiga C
Hi guys,
I´m trying to make a 'Matrix effect' while learn Amiga C and will need a function that found the screen pens that are nearest my own chosen colors. I think I found some functions that could serve me as example inside some code produced by Harry Piru Sintonen : Code:
static ULONG mk32gun(UBYTE val) { ULONG n; n = val & 0xf; n = (n << 4) | n; n = (val << 24) | (n << 16) | (n << 8) | (n << 0); return n; } WORD *allocpens(struct Screen *scr) { if (GfxBase->LibNode.lib_Version >= 39) { WORD *pens; pens = AllocMem(sizeof(WORD) * NUMPENS, MEMF_ANY); if (pens) { struct ColorMap *cm; int i; cm = scr->ViewPort.ColorMap; for (i = 0; i < NUMPENS; i++) { pens[i] = ObtainBestPen(cm, mk32gun((penrgb[i] & 0xff0000) >> 16), mk32gun((penrgb[i] & 0x00ff00) >> 8), mk32gun((penrgb[i] & 0x0000ff) >> 0), OBP_Precision, PRECISION_GUI, OBP_FailIfBad, FALSE, TAG_DONE); } return pens; } } Can someone explain what is the meaning of that code bits or comment the entire code so can help me understand what it do, please? |
29 November 2013, 07:01 | #2 |
Registered User
Join Date: May 2010
Location: Helsinki, Finland
Posts: 1,341
|
Those are not Amiga specific operations, just normal C bit-banging It's probably worthwhile to get acquainted with them, you could start by reading this Wikipedia article.
The mk32gun() function is essentially replicating the lowest four bits of "val" six times and sticking them after the original "val", leaving you with a 32 bit result. Those other three operations grab the individual 8-bit red, green and blue components from the combined value. Last edited by ajk; 29 November 2013 at 07:09. |
29 November 2013, 08:50 | #3 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,008
|
IMHO the mk32gun function is not correct. If I had to expand for excample 0xAB to 32 bits I would use 0xABABABAB and not 0xABBBBBBB like the function does.
So this is my mk32gun function: Code:
ULONG mk32gun (UBYTE val) { ULONG n = val; return ((n << 24) | (n << 16) | (n << 8) | n ); } |
29 November 2013, 10:24 | #4 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,510
|
BTW, this thread doesn't belong here. I see no assembler code in it.
More suitable would have been Coders.Language or Coders.C/C++. |
29 November 2013, 17:59 | #5 | |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
Quote:
@Moderator: feel free to change the place. Guys, thanks for the help. Knowing what that function is doing it will be easier understand the code. Will look at the code at night after leave my job. Last edited by AlfaRomeo; 29 November 2013 at 18:12. |
|
29 November 2013, 22:15 | #6 |
Global Moderator
Join Date: Aug 2008
Location: Sidcup, England
Posts: 10,300
|
|
13 February 2014, 19:50 | #7 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
Wich is the best way to anim some sprites inside a OS 3+ friendly window?
|
25 February 2014, 14:30 | #8 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
Hello,
Please, can someone tell me why the sprite doesn´t appear in the screen on the next code? #include <exec/types.h> #include <graphics/gfx.h> #include <graphics/GfxBase.h> #include <graphics/sprite.h> #include <graphics/gfxmacros.h> #include <intuition/IntuitionBase.h> #include <intuition/screens.h> #include <hardware/custom.h> #include <hardware/dmabits.h> #include <libraries/dos.h> #include <clib/graphics_protos.h> #include <clib/exec_protos.h> #include <clib/intuition_protos.h> #include <clib/alib_stdio_protos.h> #include <stdlib.h> struct GfxBase *GraphBase=NULL; struct IntuitionBase *IntuiBase=NULL; extern struct Custom custom; #pragma chip UWORD sprite_data[]={ 0, 0, /* position control */ 0xffff, 0x0000, /* image data line 1, color 1 */ 0xffff, 0x0000, /* image data line 2, color 1 */ 0x0000, 0xffff, /* image data line 3, color 2 */ 0x0000, 0xffff, /* image data line 4, color 2 */ 0x0000, 0x0000, /* image data line 5, transparent */ 0x0000, 0xffff, /* image data line 6, color 2 */ 0x0000, 0xffff, /* image data line 7, color 2 */ 0xffff, 0xffff, /* image data line 8, color 3 */ 0xffff, 0xffff, /* image data line 9, color 3 */ 0, 0 /* reserved, must init to 0 0 */ }; void main(int argc, char **argv){ struct SimpleSprite sprite={0}; struct ViewPort *VPort; WORD spriteNum; SHORT deltaMove, ktr1, ktr2, colorReg; struct Screen *MyScr; int returnCode; returnCode=RETURN_OK; GraphBase=(struct GfxBase *)OpenLibrary("graphics.library",0); if(GraphBase == NULL) returnCode=RETURN_FAIL; else { IntuiBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0); if(IntuiBase == NULL) returnCode=RETURN_FAIL; else { MyScr=LockPubScreen(NULL); if(MyScr==NULL) returnCode=RETURN_FAIL; VPort=&MyScr->ViewPort; UnlockPubScreen(NULL,MyScr); spriteNum = GetSprite(&sprite, 2); if(spriteNum==-1) returnCode=RETURN_WARN; else { colorReg = 16 +((spriteNum & 0x06) <<1); printf("colorReg= %d\n", colorReg); SetRGB32(VPort, colorReg +1, 12, 3, 8); SetRGB32(VPort, colorReg +2, 13, 13, 13); SetRGB32(VPort, colorReg +3, 4, 4, 15); sprite.x=0; //Initialize pos & size info sprite.y=0; //to match that shown in sprite_data sprite.height=9; //so later system knows layout of data /* Intall sprite data and move sprite to start position */ ChangeSprite(NULL, &sprite, (APTR)sprite_data); MoveSprite(NULL, &sprite, 30,0); for(ktr1=0, deltaMove=1; ktr1<6; ktr1++, deltaMove = -deltaMove){ for(ktr2=0; ktr2<100; ktr2++){ MoveSprite(NULL, &sprite, (LONG)(sprite.x + deltaMove), (LONG)(sprite.y + deltaMove)); WaitTOF(); //Wait for next frame to move again } } FreeSprite((WORD)spriteNum); } CloseLibrary((struct Library *)IntuiBase); } CloseLibrary((struct Library *)GraphBase); } exit(returnCode); } |
25 February 2014, 16:03 | #9 |
Registered User
Join Date: Aug 2003
Location: hamburg
Posts: 56
|
The RKM example program ssprite.c is working. I assume you used that as a template?
I think that the problem is that you want to display your sprite on the default Public Screen (WB). Perhaps the SPRITE flag is not set for that screen? Code:
ViewModes = the appropriate argument for the data type ViewPort.Modes. These include: HIRES for this screen to be HIRES width. LACE for the display to switch to interlace. SPRITES for this screen to use sprites (the pointer sprite is always displayed) DUALPF for dual-playfield mode (not supported yet) [For V36: The ViewModes field is superseded by a TagItem with tag value SA_DisplayID.] |
25 February 2014, 16:14 | #10 | ||
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,008
|
Quote:
Quote:
1. do you use a graphics card? Hardware sprites only appear on native screens, not on RTG screens. 2. is your background black? You set all three colors to black, so your sprite would be invisible on a black background. Unrelated: 3. you must not rename the base variables for libraries. That the program compiled and runs anyway for you shows that you don't need to open libraries for your compiler, it does this automatically. If it wouldn't, you would see "undefined symbol IntuitionBase" and "GfxBase" errors. Not so unrelated: 4. you must not unlock the screen before you stop using it. If you do, the screen can disappear while your program still runs and it will crash. |
||
25 February 2014, 16:19 | #11 | |
Registered User
Join Date: Aug 2003
Location: hamburg
Posts: 56
|
Quote:
You are right that the sprite does not appear on an RTG screen, switching the WB to a native mode made the example work. Last edited by aragon; 25 February 2014 at 16:26. |
|
25 February 2014, 16:30 | #12 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
Thanks for the help friends.
I didn´t touch in the Sprites flag and, as I see the mouse, so Sprites flag is ON. But thomas was right, I do use a graphics card in my UAE config, so I presume I couldn´t use hardware sprites Will try with virtual sprites instead. |
20 February 2015, 00:43 | #13 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
While trying to compile an old utility it keeps giving a type conflict error
in the line DateStamp(&tnow); from the sub-routine below: Code:
USHORT SetTime(pointer, numpos, pos) register USHORT *pointer; register USHORT numpos; register USHORT *pos; { register int i; struct DateStamp tnow; USHORT hour10, hour1, min10, min1; static USHORT hour10_old = 99; static USHORT hour1_old = 99; static USHORT min10_old = 99; DateStamp(&tnow); hour1 = (tnow.ds_Minute / 60) % 12; hour1 = (hour1 == 0) ? 12 : hour1; hour10 = hour1 / 10; hour1 = hour1 % 10; min1 = tnow.ds_Minute % 60; min10 = min1 / 10; min1 = min1 % 10; if ( hour10_old != hour10 ) { for ( i=0; i < numpos; i++ ) { if ( hour10 == 1 ) pointer[pos[i]] |= 0x8000; else pointer[pos[i]] &= 0x7fff; } hour10_old = hour10; } if ( hour1_old != hour1 ) { for ( i=0; i < numpos; i++ ) { pointer[pos[i]] &= 0xc7ff; pointer[pos[i]] |= (digits[hour1][i] << 11); } hour1_old = hour1; } if ( min10_old != min10 ) { for ( i=0; i < numpos; i++ ) { pointer[pos[i]] &= 0xff1f; pointer[pos[i]] |= (digits[min10][i] << 5); } min10_old = min10; } for ( i=0; i < numpos; i++ ) { pointer[pos[i]] &= 0xfff1; pointer[pos[i]] |= (digits[min1][i] << 1); } return((USHORT)(tnow.ds_Tick/TICKS_PER_SECOND)); } |
20 February 2015, 08:36 | #14 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,008
|
Probably missing function prototype for DateStamp(). You need one of #include <proto/dos.h> or #include <clib/dos_protos.h>
|
20 February 2015, 15:53 | #15 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
You´re right, it was the missed prototype for the DateStamp().
Thanks for the help thomas. |
20 February 2015, 17:00 | #16 |
Coder/webmaster/gamer
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,651
|
|
06 March 2015, 13:52 | #17 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
|
06 March 2015, 14:19 | #18 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
How I could concatenate a string with a qualifier key result so it could be used with the Text() function?
Like used with the printf() function: Code:
printf("Qualifier = %lx, Raw = %d\n", iMsg->Qualifier, iMsg->Code); Code:
Text(RP,"Quality = "+ iMsg->Qualifier,16); Code:
char *string=iMsg->Qualifier; asprintf() could do but it didn´t exist in Amiga C |
06 March 2015, 14:44 | #19 |
Registered User
Join Date: May 2010
Location: Helsinki, Finland
Posts: 1,341
|
How about just regular sprintf()? Allocate the buffer for it yourself either statically or with malloc().
|
06 March 2015, 15:17 | #20 |
A1200 040 SAM440EP 667
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
|
Great, so simple and works so well..
I´ve tried some complex solutions, neglecting the simple ones, and all they failed Thanks ajk |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
|
|