gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > gba.h modification suggestions anyone?

#49322 - jarobi - Thu Jul 28, 2005 5:36 pm

Hi all! I have an old copy of gba.h that I can't stand to part with because I have made various modifications and corrections; most of which I can't remember. There are a few issues with this version I am concerned about though. Some registers are not defined as volatile when they should be and some of the type definitions are shady (e.g. u16's are shorts as expected, but u32's are longs... why is that?). Also, at the time this file was made, the purpose of some of the registers was unknown, like windowing for example. I could scour all of the the CowBite specs and correct all this information, but given the amount of documentation and the very little time I have in between school, it is not very practical to do so. That's why I'm asking anyone who has a little bit of time to correct at least one thing or suggest something that would help me make this file as accurate as possible. Thanks in advance!

FYI: I renamed gba.h to gbareg.h

Code:
/*****************************\
*    gbareg.h
*   Original by eloist
*   Modified by staringmonkey
*  Modified by Uze
*   Last modified on 29/11/2001
\*****************************/

//////////////////////////////////////////////////////////////////////////////
// GBAREG.h                                                                    //
//////////////////////////////////////////////////////////////////////////////
#ifndef   _GBAREG_H_
#define   _GBAREG_H_



//#ifdef __cplusplus
//extern "C" {
//#endif

/////////////Type Definitions/////////////
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;

typedef volatile unsigned char vu8;
typedef volatile unsigned short vu16;
typedef volatile unsigned long vu32;

typedef const unsigned char const_u8;
typedef const unsigned short const_u16;
typedef const unsigned long const_u32;

typedef signed char s8;
typedef signed short s16;
typedef signed long s32;

typedef unsigned char byte;
typedef unsigned short hword;
typedef unsigned long word;
typedef void (*fp)(void);   //this is the definition you will find in gba.h.  It is just delaring fp to represent a pointer to a function

#define TMR_PRESCALER_1CK       0x0000  // Prescaler 1 Clock
#define TMR_PRESCALER_64CK      0x0001  //            64 clocks
#define TMR_PRESCALER_256CK     0x0002  //          256 clocks
#define TMR_PRESCALER_1024CK    0x0003  //        1024 clocks
#define TMR_IF_ENABLE           0x0040  // Interrupt Request Enable
#define TMR_ENABLE              0x0080  // Run Timer

///////////////Interrupts/////////////////////////////
#define INT_VBLANK 0x0001
#define INT_HBLANK 0x0002
#define INT_VCOUNT 0x0004 //you can set the display to generate an interrupt when it reaches a particular line on the screen
#define INT_TIMER0 0x0008
#define INT_TIMER1 0x0010
#define INT_TIMER2 0x0020
#define INT_TIMER3 0x0040
#define INT_COMUNICATION 0x0080 //serial communication interupt
#define INT_DMA0 0x0100
#define INT_DMA1 0x0200
#define INT_DMA2 0x0400
#define INT_DMA3 0x0800
#define INT_KEYBOARD 0x1000
#define INT_CART 0x2000 //the cart can actually generate an interupt
#define INT_ALL 0x4000 //this is just a flag we can set to allow the my function to enable or disable all interrupts. Doesn't actually correspond to a bit in REG_IE

////////////////sound channels/////////////
#define SOUNDINIT         0x8000   // makes the sound restart
#define SOUNDDUTY87         0x0000   //87.5% wave duty
#define SOUNDDUTY75         0x0040   //75% wave duty
#define SOUNDDUTY50         0x0080   //50% wave duty
#define SOUNDDUTY25         0x00C0   //25% wave duty

#define SOUND1PLAYONCE      0x4000   // play sound once
#define SOUND1PLAYLOOP      0x0000   // play sound looped
#define SOUND1INIT         0x8000   // makes the sound restart
#define SOUND1SWEEPSHIFTS(n)   n   // number of sweep shifts (0-7)
#define SOUND1SWEEPINC      0x0000   // sweep add (freq increase)
#define SOUND1SWEEPDEC      0x0008   // sweep dec (freq decrese)
#define SOUND1SWEEPTIME(n)   (n<<4)   // time of sweep (0-7)
#define SOUND1ENVSTEPS(n)   (n<<8)   // envelope steps (0-7)
#define SOUND1ENVINC      0x0800   // envellope increase
#define SOUND1ENVDEC      0x0000   // envellope decrease
#define SOUND1ENVINIT(n)   (n<<12) // initial envelope volume (0-15)


#define SOUND2PLAYONCE      0x4000   // play sound once
#define SOUND2PLAYLOOP      0x0000   // play sound looped
#define SOUND2INIT         0x8000   // makes the sound restart
#define SOUND2ENVSTEPS(n)   (n<<8)   // envelope steps (0-7)
#define SOUND2ENVINC      0x0800   // envellope increase
#define SOUND2ENVDEC      0x0000   // envellope decrease
#define SOUND2ENVINIT(n)   (n<<12) // initial envelope volume (0-15)



#define SOUND3BANK32      0x0000   // Use two banks of 32 steps each
#define SOUND3BANK64      0x0020   // Use one bank of 64 steps
#define SOUND3SETBANK0      0x0000   // Bank to play 0 or 1 (non set bank is written to)
#define SOUND3SETBANK1      0x0040
#define SOUND3PLAY         0x0080   // Output sound

#define SOUND3OUTPUT0      0x0000   // Mute output
#define SOUND3OUTPUT1      0x2000   // Output unmodified
#define SOUND3OUTPUT12      0x4000   // Output 1/2
#define SOUND3OUTPUT14      0x6000   // Output 1/4
#define SOUND3OUTPUT34      0x8000  // Output 3/4

#define SOUND3PLAYONCE      0x4000   // Play sound once
#define SOUND3PLAYLOOP      0x0000   // Play sound looped
#define SOUND3INIT         0x8000   // Makes the sound restart


#define SOUND4PLAYONCE      0x4000   // play sound once
#define SOUND4PLAYLOOP      0x0000   // play sound looped
#define SOUND4INIT         0x8000   // makes the sound restart
#define SOUND4ENVSTEPS(n)   (n<<8)   // envelope steps (0-7)
#define SOUND4ENVINC      0x0800   // envellope increase
#define SOUND4ENVDEC      0x0000   // envellope decrease
#define SOUND4ENVINIT(n)   (n<<12) // initial envelope volume (0-15)


#define SOUND4STEPS7      0x0004
#define SOUND4STEPS15      0x0000
#define SOUND4PLAYONCE      0x4000
#define SOUND4PLAYLOOP      0x0000
#define SOUND4INIT         0x8000

/////////////////Registers/////////////////
#define REG_INTERUPT   *(u32*)0x3007FFC      //Interrupt Register
#define REG_IRQ_HAND   *(fp)0x3007FFC      //Interrupt Request Handler Location
#define REG_DISPCNT    *(u32*)0x4000000      //Display Control (Mode)
#define REG_DISPCNT_L  *(u16*)0x4000000      //???
#define REG_DISPCNT_H  *(u16*)0x4000002      //???
#define REG_DISPSTAT   *(vu16*)0x4000004   //VBlank, HBlank, VTrigger Status
#define REG_VCOUNT     *(vu16*)0x4000006   //Vertical Control (Sync)
#define REG_BG0CNT     *(u16*)0x4000008      //Background 0
#define REG_BG1CNT     *(u16*)0x400000A      //Background 1
#define REG_BG2CNT     *(u16*)0x400000C      //Background 2
#define REG_BG3CNT     *(u16*)0x400000E      //Background 3
#define REG_BG0HOFS    *(u16*)0x4000010      //Background 0 Horizontal Offset
#define REG_BG0VOFS    *(u16*)0x4000012      //Background 0 Vertical Offset
#define REG_BG1HOFS    *(u16*)0x4000014      //Background 1 Horizontal Offset
#define REG_BG1VOFS    *(u16*)0x4000016      //Background 1 Vertical Offset
#define REG_BG2HOFS    *(u16*)0x4000018      //Background 2 Horizontal Offset
#define REG_BG2VOFS    *(u16*)0x400001A      //Background 2 Vertical Offset
#define REG_BG3HOFS    *(u16*)0x400001C      //Background 3 Horizontal Offset
#define REG_BG3VOFS    *(u16*)0x400001E      //Background 3 Vertical Offset
#define REG_BG2PA      *(u16*)0x4000020      //Background 2 PA Rotation (pa = x_scale * cos(angle);)
#define REG_BG2PB      *(u16*)0x4000022      //Background 2 PB Rotation (pb = y_scale * sin(angle);)
#define REG_BG2PC      *(u16*)0x4000024      //Background 2 PC Rotation (pc = x_scale * -sin(angle);)
#define REG_BG2PD      *(u16*)0x4000026      //Background 2 PD Rotation (pd = y_scale * cos(angle);)
#define REG_BG2X       *(u32*)0x4000028      //Background 2 X Location
#define REG_BG2X_L     *(u16*)0x4000028      //???
#define REG_BG2X_H     *(u16*)0x400002A      //???
#define REG_BG2Y       *(u32*)0x400002C      //Background 2 Y Location
#define REG_BG2Y_L     *(u16*)0x400002C      //???
#define REG_BG2Y_H     *(u16*)0x400002E      //???
#define REG_BG3PA      *(u16*)0x4000030      //Background 3 PA Rotation (pa = x_scale * cos(angle);)
#define REG_BG3PB      *(u16*)0x4000032      //Background 3 PB Rotation (pb = y_scale * sin(angle);)
#define REG_BG3PC      *(u16*)0x4000034      //Background 3 PC Rotation (pc = x_scale * -sin(angle);)
#define REG_BG3PD      *(u16*)0x4000036      //Background 3 PD Rotation (pd = y_scale * cos(angle);)
#define REG_BG3X       *(u32*)0x4000038      //Background 3 X Location
#define REG_BG3X_L     *(u16*)0x4000038      //???
#define REG_BG3X_H     *(u16*)0x400003A      //???
#define REG_BG3Y       *(u32*)0x400003C      //Background 3 Y Location
#define REG_BG3Y_L     *(u16*)0x400003C      //???
#define REG_BG3Y_H     *(u16*)0x400003E      //???
#define REG_WIN0H      *(u16*)0x4000040      //Window 0 X coords (bits 0-7 right, bits 8-16 left)
#define REG_WIN1H      *(u16*)0x4000042      //Window 1 X coords (bits 0-7 right, bits 8-16 left)
#define REG_WIN0V      *(u16*)0x4000044      //Window 0 Y coords (bits 0-7 bottom, bits 8-16 top)
#define REG_WIN1V      *(u16*)0x4000046      //Window 1 Y coords (bits 0-7 bottom, bits 8-16 top)
#define REG_WININ      *(u16*)0x4000048      //Inside Window Settings
#define REG_WINOUT     *(u16*)0x400004A      //Outside Window Settings
#define REG_MOSAIC     *(u32*)0x400004C      //Mosaic Mode
#define REG_MOSAIC_L   *(u32*)0x400004C      //???
#define REG_MOSAIC_H   *(u32*)0x400004E      //???
#define REG_BLDMOD     *(u16*)0x4000050      //Blend Mode
#define REG_BLDCNT     *(u16*)0x4000050      //Blend Mode under updated name
#define REG_COLEV      *(u16*)0x4000052      //Alpha blending coefficients
#define REG_BLDALPHA   *(u16*)0x4000052      //Alpha blending coefficients under updated name
#define REG_COLEY      *(u16*)0x4000054      //Brightness
#define REG_BLDY       *(u16*)0x4000054      //Brightness under updated name

#define REG_SOUND1CNT   *(vu32*)0x4000060      //sound 1
#define REG_SOUND1CNT_L *(vu16*)0x4000060      //
#define REG_SOUND1CNT_H *(vu16*)0x4000062      //
#define REG_SOUND1CNT_X *(vu16*)0x4000064      //

#define REG_SOUND2CNT_L *(vu16*)0x4000068      //sound 2 lenght & wave duty
#define REG_SOUND2CNT_H *(vu16*)0x400006C      //sound 2 frequency+loop+reset

#define REG_SG30       *(vu32*)0x4000070      //???
#define REG_SOUND3CNT  *(vu32*)0x4000070      //???
#define REG_SG30_L     *(vu16*)0x4000070      //???
#define REG_SOUND3CNT_L *(vu16*)0x4000070      //???
#define REG_SG30_H     *(vu16*)0x4000072      //???
#define REG_SOUND3CNT_H *(vu16*)0x4000072      //???
#define REG_SG31       *(vu16*)0x4000074      //???
#define REG_SOUND3CNT_X *(vu16*)0x4000074      //???

#define REG_SOUND4CNT_L *(vu16*)0x4000078      //???
#define REG_SOUND4CNT_H *(vu16*)0x400007C      //???

#define REG_SGCNT0     *(vu32*)0x4000080
#define REG_SGCNT0_L   *(vu16*)0x4000080
#define REG_SOUNDCNT   *(vu32*)0x4000080
#define REG_SOUNDCNT_L *(vu16*)0x4000080      //DMG sound control

#define REG_SGCNT0_H   *(vu16*)0x4000082
#define REG_SOUNDCNT_H *(vu16*)0x4000082      //Direct sound control

#define REG_SGCNT1     *(vu16*)0x4000084
#define REG_SOUNDCNT_X *(vu16*)0x4000084       //Extended sound control

#define REG_SGBIAS     *(vu16*)0x4000088
#define REG_SOUNDBIAS  *(vu16*)0x4000088      //bit rate+sound bias

#define REG_WAVE_RAM0  *(vu32*)0x4000090      //???
#define REG_SGWR0_L    *(vu16*)0x4000090      //???
#define REG_SGWR0_H    *(vu16*)0x4000092      //???
#define REG_WAVE_RAM1  *(vu32*)0x4000094      //???
#define REG_SGWR1_L    *(vu16*)0x4000094      //???
#define REG_SGWR1_H    *(vu16*)0x4000096      //???
#define REG_WAVE_RAM2  *(vu32*)0x4000098      //???
#define REG_SGWR2_L    *(vu16*)0x4000098      //???
#define REG_SGWR2_H    *(vu16*)0x400009A      //???
#define REG_WAVE_RAM3  *(vu32*)0x400009C      //???
#define REG_SGWR3_L    *(vu16*)0x400009C      //???
#define REG_SGWR3_H    *(vu16*)0x400009E      //???

#define REG_SGFIFOA    *(vu32*)0x40000A0      //???
#define REG_SGFIFOA_L  *(vu16*)0x40000A0      //???
#define REG_SGFIFOA_H  *(vu16*)0x40000A2      //???
#define REG_SGFIFOB    *(vu32*)0x40000A4      //???
#define REG_SGFIFOB_L  *(vu16*)0x40000A4      //???
#define REG_SGFIFOB_H  *(vu16*)0x40000A6      //???
#define REG_DMA0SAD     *(u32*)0x40000B0      //DMA0 Source Address
#define REG_DMA0SAD_L   *(u16*)0x40000B0      //DMA0 Source Address Low Value
#define REG_DMA0SAD_H   *(u16*)0x40000B2      //DMA0 Source Address High Value
#define REG_DMA0DAD     *(u32*)0x40000B4      //DMA0 Destination Address
#define REG_DMA0DAD_L   *(u16*)0x40000B4      //DMA0 Destination Address Low Value
#define REG_DMA0DAD_H   *(u16*)0x40000B6      //DMA0 Destination Address High Value
#define REG_DMA0CNT     *(u32*)0x40000B8      //DMA0 Control (Amount)
#define REG_DMA0CNT_L   *(u16*)0x40000B8      //DMA0 Control Low Value
#define REG_DMA0CNT_H   *(u16*)0x40000BA      //DMA0 Control High Value

#define REG_DMA1SAD     *(u32*)0x40000BC      //DMA1 Source Address
#define REG_DMA1SAD_L   *(u16*)0x40000BC      //DMA1 Source Address Low Value
#define REG_DMA1SAD_H   *(u16*)0x40000BE      //DMA1 Source Address High Value
#define REG_DMA1DAD     *(u32*)0x40000C0      //DMA1 Desination Address
#define REG_DMA1DAD_L   *(u16*)0x40000C0      //DMA1 Destination Address Low Value
#define REG_DMA1DAD_H   *(u16*)0x40000C2      //DMA1 Destination Address High Value
#define REG_DMA1CNT     *(u32*)0x40000C4      //DMA1 Control (Amount)
#define REG_DMA1CNT_L   *(u16*)0x40000C4      //DMA1 Control Low Value
#define REG_DMA1CNT_H   *(u16*)0x40000C6      //DMA1 Control High Value

#define REG_DMA2SAD     *(u32*)0x40000C8      //DMA2 Source Address
#define REG_DMA2SAD_L   *(u16*)0x40000C8      //DMA2 Source Address Low Value
#define REG_DMA2SAD_H   *(u16*)0x40000CA      //DMA2 Source Address High Value
#define REG_DMA2DAD     *(u32*)0x40000CC      //DMA2 Destination Address
#define REG_DMA2DAD_L   *(u16*)0x40000CC      //DMA2 Destination Address Low Value
#define REG_DMA2DAD_H   *(u16*)0x40000CE      //DMA2 Destination Address High Value
#define REG_DMA2CNT     *(u32*)0x40000D0      //DMA2 Control (Amount)
#define REG_DMA2CNT_L   *(u16*)0x40000D0      //DMA2 Control Low Value
#define REG_DMA2CNT_H   *(u16*)0x40000D2      //DMA2 Control High Value

#define REG_DMA3SAD     *(u32*)0x40000D4      //DMA3 Source Address
#define REG_DMA3SAD_L   *(u16*)0x40000D4      //DMA3 Source Address Low Value
#define REG_DMA3SAD_H   *(u16*)0x40000D6      //DMA3 Source Address High Value
#define REG_DMA3DAD     *(u32*)0x40000D8      //DMA3 Destination Address
#define REG_DMA3DAD_L   *(u16*)0x40000D8      //DMA3 Destination Address Low Value
#define REG_DMA3DAD_H   *(u16*)0x40000DA      //DMA3 Destination Address High Value
#define REG_DMA3CNT     *(u32*)0x40000DC      //DMA3 Control (Amount)
#define REG_DMA3CNT_L   *(u16*)0x40000DC      //DMA3 Control Low Value
#define REG_DMA3CNT_H   *(u16*)0x40000DE      //DMA3 Control High Value

#define REG_TM0D        *(vu16*)0x4000100      //Timer 0 counter
#define REG_TM0CNT      *(u16*)0x4000102      //Timer 0 control
#define REG_TM1D        *(vu16*)0x4000104      //Timer 1 counter
#define REG_TM1CNT      *(u16*)0x4000106      //Timer 1 control
#define REG_TM2D        *(vu16*)0x4000108      //Timer 2 counter
#define REG_TM2CNT      *(u16*)0x400010A      //Timer 2 control
#define REG_TM3D        *(vu16*)0x400010C      //Timer 3 counter
#define REG_TM3CNT      *(u16*)0x400010E      //Timer 3 control

#define REG_SCD0       *(u16*)0x4000120      //32-bit Normal Serial Communication Data 0 / Multi-play
#define REG_SCD1       *(u16*)0x4000122      //32-bit Normal Serial Communication Data 1 /Multi-play
#define REG_SCD2       *(u16*)0x4000124      //Multi-play Communication Data 2
#define REG_SCD3       *(u16*)0x4000126      //Multi-play Communication Data 3
#define REG_SCCNT      *(u32*)0x4000128      //???
#define REG_SCCNT_L    *(u16*)0x4000128      //???
#define REG_SCCNT_H    *(u16*)0x400012A      //???
#define REG_P1         *(vu16*)0x4000130      //Player 1 Input
#define REG_KEYPAD     *(vu16*)0x4000130      //Player 1 Input
#define REG_P1CNT      *(vu16*)0x4000132      //Player 1 Input Interrupt Status
#define REG_KEYCNT     *(vu16*)0x4000132      //REG_P1CNT alias
#define REG_R          *(u16*)0x4000134      //???
#define REG_HS_CTRL    *(u16*)0x4000140      //???
#define REG_JOYRE      *(u32*)0x4000150      //???
#define REG_JOYRE_L    *(u16*)0x4000150      //???
#define REG_JOYRE_H    *(u16*)0x4000152      //???
#define REG_JOYTR      *(u32*)0x4000154      //???
#define REG_JOYTR_L    *(u16*)0x4000154      //???
#define REG_JOYTR_H    *(u16*)0x4000156      //???
#define REG_JSTAT      *(u32*)0x4000158      //???
#define REG_JSTAT_L    *(u16*)0x4000158      //???
#define REG_JSTAT_H    *(u16*)0x400015A      //???
#define REG_IE         *(u16*)0x4000200      //Interrupt Enable
#define REG_IF         *(vu16*)0x4000202      //Interrupt Flags
#define REG_WSCNT      *(u16*)0x4000204      //Wait State Control
#define REG_IME        *(u16*)0x4000208      //Interrupt Master Enable
#define REG_PAUSE      *(u16*)0x4000300      //Pause


//#ifdef __cplusplus
//}      /* extern "C" */
//#endif


#endif   // _GBAREG_H_

[/code]
_________________
Nihongo o hanasemasen!

#49323 - tepples - Thu Jul 28, 2005 5:49 pm

The slickest trick is making the DMA, timers, and other array-like registers into macros that act like arrays. This lets a single function work on multiple background layers.

First off, BG0CNT through BG3CNT become this:
Code:
/* From pin8gba.h */
#define BGCTRL ((volatile u16 *)0x04000008)

For example, BG0CNT through BG3CNT turn into BGCTRL[0] through BGCTRL[3] or even BGCTRL[x] if x is a variable.

Similarly with the scrolling registers:
Code:
/* From pin8gba.h */
struct BGPOINT
{
  u16 x, y;
};

#define BGSCROLL ((volatile struct BGPOINT *)0x04000010)

Then BG0HOFS becomes BGSCROLL[0].x, BG2VOFS becomes BGSCROLL[2].y, etc.

Continuing with the affine registers, the DMA registers, the timer registers, and even the text-mode background maps in VRAM:
Code:
/* From pin8gba.h */
struct BGAFFINEREC
{
  s16 pa;  /* map_x increment per pixel */
  s16 pb;  /* map_x increment per scanline */
  s16 pc;  /* map_y increment per pixel */
  s16 pd;  /* map_y increment per scanline */
  u32 x_origin, y_origin;
};

#define BGAFFINE ((volatile struct BGAFFINEREC *)0x04000000)

struct DMACHN
{
  const void *src;
  void *dst;
  u16 count;
  u16 control;
};

#define DMA ((volatile struct DMACHN *)0x040000b0)

typedef struct TIMER_REC
{
  unsigned short count;
  unsigned short control;
} TIMER_REC;

#define TIMER ((volatile TIMER_REC *)0x04000100)

typedef u16 NAMETABLE[32][32];

#define MAP ((NAMETABLE *)0x06000000)

Access a single element at (x, y) of map n using MAP[n][y][x].

And here's where it gets tricky. I use actual macros rather than fake arrays for computation of addresses of tile pattern data in VRAM.
Code:
/* From pin8gba.h */
#define PATRAM(x) ((u32 *)(0x06000000 | ((x) << 14)))
#define PATRAM4(x, tn) ((u32 *)(0x06000000 | (((x) << 14) + ((tn) << 5)) ))
#define PATRAM8(x, tn) ((u32 *)(0x06000000 | (((x) << 14) + ((tn) << 6)) ))
#define SPR_VRAM(tn) ((u32 *)(0x06010000 | ((tn) << 5)))

where x is the ID of the pattern table (from 0 to 3) and tn is the tile number.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#49325 - jarobi - Thu Jul 28, 2005 6:02 pm

That is some neat stuff! Thanks tepples! Anyone else have a suggestion?
_________________
Nihongo o hanasemasen!

#49394 - Cearn - Fri Jul 29, 2005 10:11 am

You can use fake arrays for tiles/pattern data too:
Code:
// tile 8x8@4bpp: 32bytes; 8 ints
typedef struct { u32 data[8];  } TILE, TILE4;

// tile block: 32x16 tiles
typedef TILE CHARBLOCK[512];

#define tile_mem ((CHARBLOCK*)0x06000000)

Then use it like this:
Code:
//In code somewhere
TILE *ptr= &tile_mem[4][12];   // point to block 4 (== lower object block), tile 12

// Copy a tile from attached data to sprite-VRAM, tile 12
tile_mem[4][12] = *(TILE*)spriteData;

It may take a little used to but it's actually pretty easy. Good deal faster than u16/u32 array copies too. It does rely on the source data to be 4-byte aligned, though. If you feel like it, you can do something similar for palettes.

Also, as to the 'long' type. In ancient history, CPUs were 16bit and the types were char (8bit), short (16bit) and long (32bit). The int type was usually set to the CPU size: then 16bit and synomynous with short. Then came 32bit chips and the int-size became 32bit, an alias for long. By the way, does anyone know what this is for 64bit chips, and beyond?

#49400 - NighTiger - Fri Jul 29, 2005 1:31 pm

something like that:

Code:

#define RGB(r,g,b,) ((u16) (r | (g<<5) | (b<<10)))

#49421 - poslundc - Fri Jul 29, 2005 5:49 pm

Cearn wrote:
Also, as to the 'long' type. In ancient history, CPUs were 16bit and the types were char (8bit), short (16bit) and long (32bit). The int type was usually set to the CPU size: then 16bit and synomynous with short. Then came 32bit chips and the int-size became 32bit, an alias for long. By the way, does anyone know what this is for 64bit chips, and beyond?


Do 64-bit chips actually have 64-bit register width for their general-purpose registers? (Asks the guy with a 6-year-old computer.) That seems so wasteful, if true.

Dan.

#49422 - strager - Fri Jul 29, 2005 6:00 pm

poslundc wrote:
Do 64-bit chips actually have 64-bit register width for their general-purpose registers? (Asks the guy with a 6-year-old computer.) That seems so wasteful, if true.

Dan.


Chars are 8-bit, shorts are 16-bit, ints are 32-bit, and longs are 64-bit. (I think...)