broke everything to remove bmp

This commit is contained in:
Cuptain 2024-09-01 12:10:10 +10:00
parent d13287996c
commit a2d95fd15c

View File

@ -4,10 +4,23 @@
#define TABLE_LENGTH 720 #define TABLE_LENGTH 720
#define SPEED 5 #define SPEED 5
#define FRAC_BITS 8 #define FRAC_BITS 8
#define TILE_WIDTH 8
#define TILE_HEIGHT 8
#define TILE_SIZE (TILE_WIDTH * TILE_HEIGHT / 2)
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 224
#define SCREEN_TILES_X 40
#define SCREEN_TILES_Y 28
#define TILE_EMPTY 0
#define TILE_FILLED 1
#define MAP_WIDTH 10
#define MAP_HEIGHT 10
Line l; Line l;
s16 angle = 0; s16 angle = 0;
s16 x, y; s16 x, y;
u8 tileBuffer[TILE_SIZE];
u16 tileIndex = 0;
const u8 map[10][10] = {{1,1,1,1,1,1,1,1,1,1}, const u8 map[10][10] = {{1,1,1,1,1,1,1,1,1,1},
@ -89,7 +102,7 @@ void castRay(s16 angle){
s16 vx = l.pt1.x << FRAC_BITS; s16 vx = l.pt1.x << FRAC_BITS;
s16 vy = l.pt1.y << FRAC_BITS; s16 vy = l.pt1.y << FRAC_BITS;
s16 nTan = -tan; s16 nTan = -tan;
s16 threshold = (20 << FRAC_BITS); threshold = (20 << FRAC_BITS);
if(nTan > threshold){ if(nTan > threshold){
nTan = threshold; nTan = threshold;
} }
@ -144,128 +157,114 @@ void castRay(s16 angle){
} }
void mapscan(){
u8 mapcolor = 12; void initTileBuffer(u8 color) {
mapcolor |= mapcolor << 4; u8 colorValue = (color << 4) | color; // Color for both nibbles
int mapscale = 10; for (int i = 0; i < TILE_SIZE; i++) {
tileBuffer[i] = colorValue;
for(u8 x = 0; x < 10; x++){ }
for(u8 y = 0; y < 10; y++){
if(map[y][x] == 1){
Vect2D_s16 mapverts[4] = {{x*mapscale,y*mapscale},{(x+1)*mapscale,y*mapscale},{(x+1)*mapscale,(y+1)*mapscale},{x*mapscale,(y+1)*mapscale}};
BMP_drawPolygon(mapverts, 4, mapcolor);
}
}
}
} }
void uploadTileDataToVRAM(u16 vramTileIndex) {
void render(){ VDP_loadTileData(tileBuffer, vramTileIndex, 1, DMA); // Load 1 tile to VRAM
l.pt1.x = x / 10;
l.pt1.y = y / 10;
//Clear the bitmap
BMP_clear();
//Draw the line defined above (in the background, hidden)
mapscan();
if(angle >= 360) angle = angle - 360;
if(angle < 0) angle = 360 + angle;
castRay(angle-20);
BMP_drawLine(&l);
castRay(angle-10);
BMP_drawLine(&l);
for (int i = 0; i < 16; i++){
castRay(angle);
BMP_drawLine(&l);
}
castRay(angle+10);
BMP_drawLine(&l);
castRay(angle+20);
BMP_drawLine(&l);
BMP_showFPS(0);
//Flip the data to the screen - i.e. actually draw the complete image on screen
BMP_flip(1);
//Increment the destination y coordinate
//l.pt2.y = l.pt2.y + 2;
//Reset the destination y coordinate if it hits 160
//if (l.pt2.y == 160)
//{
//l.pt2.y = 0;
//}
SYS_doVBlankProcess();
} }
void update(){ void mapscan() {
u16 joy = JOY_readJoypad(JOY_1); u8 mapcolor = 12; // map color
if(joy & BUTTON_LEFT) { mapcolor |= mapcolor << 4;
//l.pt1.x -= SPEED;
angle -= 1; for (u8 x = 0; x < 10; x++) {
} for (u8 y = 0; y < 10; y++) {
if(joy & BUTTON_RIGHT) { if (map[y][x] == 1) {
//l.pt1.x += SPEED; // Draw a filled tile for the map block
angle += 1; for (u8 px = 0; px < TILE_WIDTH; px++) {
} for (u8 py = 0; py < TILE_HEIGHT; py++) {
if(joy & BUTTON_UP) { setPixelInBuffer(px, py, mapcolor);
s16 ind = (int)((float)angle/360.0f*1024.0f); }
fix16 dy = sinFix16(ind); }
fix16 dx = cosFix16(ind); // Upload the filled tile to VRAM
y += fix16ToInt(fix16Mul(dy, FIX16(SPEED))); uploadTileDataToVRAM(tileIndex);
x += fix16ToInt(fix16Mul(dx, FIX16(SPEED))); VDP_setTileMapXY(VDP_BG_A, tileIndex, x, y);
} }
if(joy & BUTTON_DOWN) { }
s16 ind = (int)((float)angle/360.0f*1024.0f); }
fix16 dy = sinFix16(ind);
fix16 dx = cosFix16(ind);
y -= fix16ToInt(fix16Mul(dy, FIX16(SPEED)));
x -= fix16ToInt(fix16Mul(dx, FIX16(SPEED)));
}
} }
void initVDP(){ void clearScreenWithTile(u16 tileIndex) {
SYS_disableInts(); // Fill the entire screen with the background tile
VDP_setPlaneSize(64,32,TRUE); VDP_fillTileMapRect(BG_A, TILE_ATTR_FULL(PAL1, 0, FALSE, FALSE, tileIndex), 0, 0, SCREEN_TILES_X, SCREEN_TILES_Y);
SYS_enableInts();
} }
int main() void drawMap() {
{ for (u16 y = 0; y < MAP_HEIGHT; y++) {
x = 150; for (u16 x = 0; x < MAP_WIDTH; x++) {
y = 150; u8 tileType = map[y][x] ? TILE_FILLED : TILE_EMPTY;
initVDP(); VDP_setTileMapXY(BG_A, TILE_ATTR_FULL(PAL1, 0, FALSE, FALSE, tileType), x, y);
}
}
}
//Initialise the bitmap engine void render() {
BMP_init(FALSE, BG_A, PAL0, FALSE); clearScreenWithTile(TILE_EMPTY);
initTileBuffer(12); // map color
uploadTileDataToVRAM(TILE_FILLED);
initTileBuffer(0); // background color
uploadTileDataToVRAM(TILE_EMPTY);
drawMap();
VDP_setTextPlane(BG_B);
VDP_setTextPalette(2);
VDP_showFPS(0);
SYS_doVBlankProcess();
}
//Set the colour of the line. We are using pallete 0 for the bitmap, so we have 0->15. 15 is used for white text, so we set an unused pallet colour, 14 to blue - RGB 0000FF. void update() {
u16 colour_blue = RGB24_TO_VDPCOLOR(0x0000ff); u16 joy = JOY_readJoypad(JOY_1);
u16 colour_red = RGB24_TO_VDPCOLOR(0x756a4a); if (joy & BUTTON_LEFT) {
PAL_setColor(14, colour_blue); angle -= 1;
PAL_setColor(13, colour_red); }
PAL_setColor(12, RGB24_TO_VDPCOLOR(0x00ff00)); if (joy & BUTTON_RIGHT) {
PAL_setColor(15, RGB24_TO_VDPCOLOR(0xff0000)); angle += 1;
VDP_setBackgroundColor(13); }
if (joy & BUTTON_UP) {
s16 ind = (int)((float)angle / 360.0f * 1024.0f);
fix16 dy = sinFix16(ind);
fix16 dx = cosFix16(ind);
y += fix16ToInt(fix16Mul(dy, FIX16(SPEED)));
x += fix16ToInt(fix16Mul(dx, FIX16(SPEED)));
}
if (joy & BUTTON_DOWN) {
s16 ind = (int)((float)angle / 360.0f * 1024.0f);
fix16 dy = sinFix16(ind);
fix16 dx = cosFix16(ind);
y -= fix16ToInt(fix16Mul(dy, FIX16(SPEED)));
x -= fix16ToInt(fix16Mul(dx, FIX16(SPEED)));
}
}
//A line needs a source coordinate x,y and a destination coordinate x,y along with a pallete colour. void initVDP() {
l.pt1.x = 15; SYS_disableInts();
l.pt1.y = 15; VDP_setPlaneSize(64, 32, TRUE);
l.pt2.x = 255; SYS_enableInts();
l.pt2.y = 0; }
l.col = 14;
l.col |= l.col << 4; // if we do not left shift the colour, we get gaps in the line
while(TRUE) int main() {
{ SYS_disableInts();
render(); VDP_setPlaneSize(64, 32, TRUE);
update(); SYS_enableInts();
} PAL_setColor(14, RGB24_TO_VDPCOLOR(0x0000ff));
return 0; PAL_setColor(15, RGB24_TO_VDPCOLOR(0xff0000));
VDP_setBackgroundColor(14);
// Initialize and upload tile data for TILE_EMPTY and TILE_FILLED
initTileBuffer(12); // Color for TILE_FILLED
VDP_loadTileData(tileBuffer, TILE_FILLED, 1, DMA);
initTileBuffer(0); // Color for TILE_EMPTY
VDP_loadTileData(tileBuffer, TILE_EMPTY, 1, DMA);
while (TRUE) {
render();
}
return 0;
} }