› Foros › Retro y descatalogado › Consolas clásicas
pocket_lucho escribió:no puse un ejemplo de dibujar mapas?
pocket_lucho escribió:Lo único que no hemos visto es la función para dibujar mapas de tiles usada para dibujar el escenario de la que tratará un futuro tutorial.
Manveru Ainu escribió:Creo que he aprendido y conseguido saber cómo se usan los mapas. Si aún sigues interesado te puedo explicar un poco, aunque será de aquella manera poco pro , si prefieres que te lo explique pocket_lucho que lo hará en condiciones lo comprenderé perfectamente
int main()
{
//bg_pal: paleta de la imagen.
VDP_setPalette(PAL0, (const u16 *)bg_pal);
//bg_tiles: tiles de la imagen.
//bg_vram: posición inicial donde se guardan los tiles de la imagen.
//bg_num_tiles: número de tiles(únicos) de la imagen.
VDP_loadTileData( (const u32 *)bg_tiles, bg_vram, bg_num_tiles, 1);
//h: coordenada horizontal de la imagen, de 0 a 39.
//v: coordenada vertical de la imagen, de 0 a 27.
//pos: posición en el array del mapa al recorrer cada fila y cada columna de la imagen.
u16 h, v, pos;
//Recorro primero filas porque es como guardamos el array en el Imagenesis, sólo por comodidad.
for(v = 0; v < 28; v++)
for(h = 0; h < 40; h++)
{
//pos: convierte las coordenadas bidimensionales de la imagen en la posición de memoria correspondiente del mapa.
pos = h + (40 * v);
if (bg_map[pos]) VDP_setTileMap(APLAN, TILE_ATTR_FULL(PAL0, 0, 0, 0, bg_map[pos] + bg_vram), h, v);
}
while(1)
{
VDP_waitVSync();
}
return 0;
}
if (bg_map[pos]) VDP_setTileMap(APLAN, TILE_ATTR_FULL(PAL0, 0, 0, 0, bg_map[pos] + bg_vram), h, v);
Mueve el plano plan un número value de píxeles hacia la derecha si value es positivo o a la izquierda si value es negativo
int main ()
{
u16 i;
VDP_setScrollingMode(HSCROLL_PLANE, VSCROLL_PLANE);
// BUCLE FOR sin condicion de parada
for (i=(VDP_getPlanWidth()*8); ; i--)
{
VDP_setHorizontalScroll(APLAN, i);
VDP_waitVSync();
if (i==0) // SE HABRIA REALIZADO EL SCROLL ENTERO
i=(VDP_getPlanWidth()*8); // VOLVEMOS A EMPEZAR DE NUEVO
}
}
void VDP_setHorizontalScrollTile(u16 plan, u16 tile, u16* values, u16 len, u16 use_dma);
int main ()
{
u16 valores[1];
VDP_setScrollingMode(HSCROLL_TILE, VSCROLL_PLANE);
for (i=(VDP_getPlanWidth()*8); ; i--)
{
valores [0] = i;
VDP_setHorizontalScrollTile(APLAN, 26, (u16*) valores, 1, 0);
VDP_waitVSync();
if (i==0)
i=(VDP_getPlanWidth()*8);
}
}
u16 v[4] = {0,0,0,0};
while(1)
{
u8 i;
for(i = 0; i < 4; i++) v[i] = (i % 2 ? v[i] - 1 : v[i] - 2);
VDP_setHorizontalScrollTile(BPLAN , 0, v, 4, 1);
}
// assert reset
void assert_reset()
{
asm("reset\n\t");
}
// soft reset
void reset()
{
asm("move #0x2700,%sr\n\t"
"move.l (0),%a7\n\t"
"move.l (4),%a0\n\t"
"jmp (%a0)");
}
/***********************************************************************************
TEST DE SIMULACION DE HACES DE LUZ COMBINANDO MODO SHADOW CON RASTER DE LINEAS
***********************************************************************************/
#include "mini_lib.h"
// CONSTANTES Y MACROS /////////////////////////////////////////////////////////////
#define VRAM_POS_TILE1 1
#define VRAM_POS_LADRILLO_A 1
#define VRAM_POS_LADRILLO_B 2
#define VRAM_POS_TILE_TRANSPARENTE 3
#define NUM_COLUMNAS 40
#define NUM_FILAS 28
#define NUM_LINEAS NUM_FILAS * 8
#define NUM_TILES_TILESET 3
#define ANCHO_HAZ 8
#define NUM_HACES NUM_COLUMNAS / ANCHO_HAZ
// TILEMAP ====================================================================
// TILESET ====================================================================
const u32 fondo_tileset[NUM_TILES_TILESET*8] =
{
0x11211111, 0x12222222, 0x12422222, 0x12242222, 0x12422222, 0x12222222, 0x12222222, 0x33333333,
0x11111113, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x32333333,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
};
// PALETA =====================================================================
const u16 fondo_paleta[16] = {
0x0000,0x06CE,0x044E,0x0008,0x008C,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
};
// OTROS DATOS GLOBALES =======================================================
fix32 planoA_scroll;
const fix32 planoA_velocidad_scroll = FIX32(0.075);
// DECLARACION DE FUNCIONES ===================================================
// MACROS =====================================================================
#define DibujarMuro(); \
for(fila=0; fila<NUM_FILAS; fila+=2) \
for(columna=0; columna<NUM_COLUMNAS; columna+=2) \
{ \
VDP_setTileMap( BPLAN, VRAM_POS_LADRILLO_A, columna, fila); \
VDP_setTileMap( BPLAN, VRAM_POS_LADRILLO_B, columna+1, fila); \
VDP_setTileMap( BPLAN, VRAM_POS_LADRILLO_B, columna, fila+1); \
VDP_setTileMap( BPLAN, VRAM_POS_LADRILLO_A, columna+1, fila+1); \
}
#define DibujarHaces(); \
for(fila=0; fila<NUM_FILAS; fila++) \
for(columna=0; columna<NUM_HACES; columna++) \
for(tile_haz=0; tile_haz<ANCHO_HAZ; tile_haz++) \
{ \
VDP_setTileMap( APLAN, TILE_ATTR_FULL(PAL0, columna%2, 0, 0, VRAM_POS_TILE_TRANSPARENTE), \
(columna * ANCHO_HAZ) + tile_haz, fila); \
}
#define InicializarTablaScroll(); \
for(linea=0; linea<NUM_LINEAS; linea++) scroll_lineas[linea] = FIX16(0);
#define InicializarVelocidadesScroll(); \
velocidad_scroll_lineas[0] = FIX16(0.05); \
for(linea=1; linea<NUM_LINEAS; linea++) \
velocidad_scroll_lineas[linea] = fix16Add(velocidad_scroll_lineas[linea-1], FIX16(0.1));
//=============================================================================
// MAIN
//=============================================================================
int main()
{
// Variables locales ______________________________________________________
// Indices
u8 fila, columna, tile_haz, linea, i;
// Buffer de valores de scroll y tabla de velocidad de cada linea
fix16 scroll_lineas[NUM_LINEAS];
fix16 velocidad_scroll_lineas[NUM_LINEAS];
// Proceso ________________________________________________________________
// Mandar tiles y paleta a VRAM/CRAM
VDP_setPalette((u16 *) fondo_paleta, 0,16);
VDP_loadTileData( (const u32 *) fondo_tileset, VRAM_POS_TILE1, NUM_TILES_TILESET, 1);
// Configurar la pantalla
VDP_setReg(16, 0x11); // Establecer tamaño del plano scrolleable a 64x64 tiles
VDP_setReg(11, 0x03); // Activacion del scroll horizontal por líneas
VDP_setHilightShadow(1);// Activacion del modo hilight/shadow
// Preparar la tabla de velocidades de scroll para cada una de las lineas
InicializarTablaScroll();
InicializarVelocidadesScroll();
// Dibujar el fondo y los haces de luz
DibujarMuro();
DibujarHaces();
// BUCLE PRINCIPAL ________________________________________________________
while(1)
{
for(linea = 0; linea < NUM_LINEAS; linea++)
{
VDP_setHorizontalScroll(APLAN, linea, fix16ToInt(scroll_lineas[linea]) );
// Aplicamos la velocidad
scroll_lineas[linea] = fix16Add(scroll_lineas[linea], velocidad_scroll_lineas[linea]);
// Rebotamos el movimiento en cuanto la linea inferior alcance
// su tope izquierdo o derecho
if(scroll_lineas[NUM_LINEAS-1] >= FIX16(60) || scroll_lineas[NUM_LINEAS-1] <= FIX16(-60))
velocidad_scroll_lineas[linea] *= -1;
}
// Ralentizamos el movimiento
for(i=0; i<8; i++) VDP_waitVSync();
}
return 1;
} // fin main()
realbrucest escribió:Ufff.. esto mereciera que lo plantease en plan tuto
nolddor escribió:Manveru si no es molestia podrías subir el codigo corregido conlos comandos del sgdk nuevo?
// BUCLE PRINCIPAL ________________________________________________________
while(1)
{
for(linea = 0; linea < NUM_LINEAS; linea++)
{
VDP_setHorizontalScroll(APLAN, linea, fix16ToInt(scroll_lineas[linea]) );
....................
VDP_setScrollingMode(HSCROLL_LINE, VSCROLL_PLANE);
// BUCLE PRINCIPAL ________________________________________________________
while(1)
{
u16 aux[NUM_LINEAS], n;
for(n = 0; n < NUM_LINEAS; n++) aux[n] = fix16ToInt(scroll_lineas[n]);
VDP_setHorizontalScrollLine(APLAN, 0, aux, NUM_LINEAS, 1 );
for(linea = 0; linea < NUM_LINEAS; linea++)
{
...........................
Manveru Ainu escribió:Lo que me creo que no me queda claro es el tema de usar un múltiplo de 2. Entiendo que multiplicando por 10000 transformamos un decimal en entero, pero multiplicando por 1024 por ejemplo no siempre obtendremos un entero.
#define FIX16_INT_BITS 10
#define FIX16_FRAC_BITS (16 - FIX16_INT_BITS)
#define FIX16_INT_MASK (((1 << FIX16_INT_BITS) - 1) << FIX16_FRAC_BITS)
#define FIX16_FRAC_MASK ((1 << FIX16_FRAC_BITS) - 1)
/**
* \def FIX16
* Convert specified value to fix16
*
* Ex : f16 v = FIX16(-27.12);
*/
#define FIX16(value) ((fix16) ((value) * (1 << FIX16_FRAC_BITS)))
/**
* \def intToFix16
* Convert integer to fix16.
*/
#define intToFix16(value) ((value) << FIX16_FRAC_BITS)
/**
* \def fix16ToInt
* Convert fix16 to integer.
*/
#define fix16ToInt(value) ((value) >> FIX16_FRAC_BITS)
realbrucest escribió:Tanto los fix16 como fix32 son variables enteras. Por tanto da igual que la multiplicación diese decimales, al almacenarse el dato se discriminarían. El caso es "multiplicar" el dato base y "dividir" el resultado por un valor tan alto como sea posible para que la perdida de precisión sea mínima.
if seems that this project has not been built yet. Do you want built it now
-------------- Build: Debug in Prueba2 (compiler: Sega Megadrive)---------------
Running command: make.exe -f c:\sgdk\makefile.gen Debug
make: *** No rule to make target `Debug'. Stop.
Process terminated with status 2 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)
Building to ensure sources are up-to-date
Selecting target:
Debug
ERROR: You need to specify a debugger program in the debuggers's settings.
(For MinGW compilers, it's 'gdb.exe' (without the quotes))
(For MSVC compilers, it's 'cdb.exe' (without the quotes))
/******************************************************************************
DEMO TEST SPOTLIGHT EFFECT (LINE SCROLL + SHADOW MODE)
******************************************************************************/
#include <genesis.h>
// CONSTANTS ==================================================================
// Some data to deal with graphical data
#define NUM_COLUMNS 40
#define NUM_ROWS 28
#define NUM_LINES NUM_ROWS * 8
#define NUM_TILES_TILESET 3
// Places where we place tiles at Genesis VRAM
#define VRAM_POS_TILE1 1
#define VRAM_POS_BRICK_A 1
#define VRAM_POS_BRICK_B 2
#define VRAM_POS_TILE_VOID 3
// How many pixels bottom line is going to swing
#define SPOTLIGHT_SWING_RANGE 50
// Some other data
#define SPOTLIGHT_WIDTH 8
#define NUM_SPOTLIGHTS NUM_COLUMNS / SPOTLIGHT_WIDTH
// TILESET ====================================================================
const u32 background_tileset[NUM_TILES_TILESET*8] =
{
// TILE 1: brick left half
0x11211111, 0x12222222, 0x12422222, 0x12242222, 0x12422222, 0x12222222, 0x12222222, 0x33333333,
// TILE 2: brick right half
0x11111113, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x32333333,
// TILE 3: empty/transparent tile
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
};
// PALETTE ====================================================================
const u16 background_palette[16] = {
0x0000,0x06CE,0x044E,0x0008,0x008C,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
};
// MACROS =====================================================================
#define DrawWall(); \
for(row = 0; row < NUM_ROWS; row += 2) \
for(column = 0; column < NUM_COLUMNS; column += 2) \
{ \
VDP_setTileMap( BPLAN, VRAM_POS_BRICK_A, column, row); \
VDP_setTileMap( BPLAN, VRAM_POS_BRICK_B, column+1, row); \
VDP_setTileMap( BPLAN, VRAM_POS_BRICK_B, column, row+1); \
VDP_setTileMap( BPLAN, VRAM_POS_BRICK_A, column+1, row+1); \
}
#define DrawSpotlights(); \
for(row = 0; row < NUM_ROWS; row++) \
for(column = 0; column < NUM_SPOTLIGHTS; column++) \
for(tile_spotlight = 0; tile_spotlight < SPOTLIGHT_WIDTH; tile_spotlight++) \
{ \
VDP_setTileMap( APLAN, TILE_ATTR_FULL(PAL0, column%2, 0, 0, VRAM_POS_TILE_VOID), \
(column * SPOTLIGHT_WIDTH) + tile_spotlight, row); \
}
#define InitializeScrollTable(); \
for(line = 0; line < NUM_LINES; line++) line_scroll_data[line] = FIX16(0);
#define InitializeSpeedTable(); \
line_speed_data[0] = FIX16(0.05); \
for(line = 1; line < NUM_LINES; line++) \
line_speed_data[line] = fix16Add(line_speed_data[line-1], FIX16(0.04));
//=============================================================================
// MAIN =======================================================================
//=============================================================================
int main()
{
// Local data _____________________________________________________________
// Indexes
u8 row, column; // Horizontal and vertical tile placement index/coords
u8 line; // Pixel line/row index
u8 tile_spotlight; // Horizontal tile counter for drawing spotlights
u8 i; // Auxiliar loop index
// Line scroll buffers
fix16 line_scroll_data[NUM_LINES]; // Current line scroll values
fix16 line_speed_data[NUM_LINES]; // Line scroll speeds
s16 aux[NUM_LINES]; // Needed for VDP_setHorizontalScrollLine
// Initialization lot _____________________________________________________
// Scroll
InitializeScrollTable();
InitializeSpeedTable();
// Process ________________________________________________________________
// Screen setting
VDP_setScrollingMode(HSCROLL_LINE, VSCROLL_PLANE);
VDP_setHilightShadow(1); // Hilight/shadow activation
// Loading tile stuff and color data into VRAM/CRAM
VDP_setPalette(PAL0, (u16 *) background_palette);
VDP_loadTileData( (const u32 *) background_tileset, VRAM_POS_TILE1, NUM_TILES_TILESET, 1);
// Drawing
DrawWall();
DrawSpotlights();
// MAIN LOOP ______________________________________________________________
while(1)
{
for(line = 0; line < NUM_LINES; line++)
{
// Sum the speed value
line_scroll_data[line] = fix16Add(line_scroll_data[line], line_speed_data[line]);
// Rebound when movement of bottom line reaches its left or right boundary
if(line_scroll_data[NUM_LINES-1] >= FIX16(SPOTLIGHT_SWING_RANGE)
|| line_scroll_data[NUM_LINES-1] <= FIX16(-SPOTLIGHT_SWING_RANGE))
line_speed_data[line] *= -1;
// An auxiliar "regular integer" buffer is needed for VDP_setHorizontalScrollLine
aux[line] = fix16ToInt(line_scroll_data[line]);
}// end for(NUM_LINES)
// Set Horizontal Scroll
VDP_setHorizontalScrollLine(APLAN, 0, aux, NUM_LINES, 1);
// Drawing/movement speed down
for(i=0; i<4; i++) VDP_waitVSync();
} // end main loop
return 0; // Ok ... we'll return something
} // end main()
Changing directory to: C:/DOCUME~1/yo/MYDOCU~1/Sega/Prueba2/.
Set variable: PATH=.;C:\sgdk\bin;C:\sgdk\bin\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\wbem
Starting debugger: C:\MinGW\bin\gdb.exe -nx -fullname -quiet -args "C:/Documents and Settings/yo/My Documents/Sega/Prueba2/bin/Debug/Prueba2.exe"
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.4
Starting the debuggee failed: No executable specified, use `target exec'.
Debugger finished with status 0
Karaculo escribió:realbrucest, no viene en el archivo que has puesto el gdb.
Dios como odio el software libre!!!!!!!!!!!!!
Karaculo escribió:Chicos lo dejo compilar compila pero no me va, me voy con el de basic total me da igual el lenguaje y el proyecto que voy ha realizar no necesito mucha velocidad.
Os doy las gracias y lamento haber sido tan pesado.
News from Neoflash:
NEO Summer Retro Coding Contest 2013 for all retro platform announcement
*** Close time: Aug.20th 2013 ***
more info: http://www.neoflash.com/forum/index.php ... 624.0.html
* Homebrew Game division
There are top 3 winners for all platform
* Homebrew APP division
There are top 3 winners for all platform
Note: The platform just specify to the retro console, something like NES/PC-E/MD/SNES/N64/GBA/NDS/PSP/Wii ......
The rules of NEO Summer retro coding contest 2013:
[1] All original entries will get +5 "original score " , but the second entry (same project from last contest but improved, and just enter one more time again ) will don't get any "original score" in this contest.
[2] If your production have enter other contest before, you can use it to enter this NEO contest still.
[3] The No.1 winner from last Neo contest can't use their same project (even it come with many updated) to enter this contest again.
[4] You can submit more than one project for any platform at the same time, without any limit.
[5] You must put the NEO Retro Compo badge and NEO website link to your program and show it in the first page.
The top 3 prize list for the winners:
The No.1 : US$500 cash , OR choose any items from the NEO online shop, just not over U$800 total value.
The No.2 : US$300 cash , OR choose any items from the NEO online shop, just not over U$500 total value.
The No.3 : US$200 cash , OR choose any items from the NEO online shop, just not over U$300 total value.