removed includes from headers

corrected location of some protos
removed un-needed includes from source files
This commit is contained in:
Robin Jones 2017-10-11 23:04:17 +01:00
parent 2fbf21d4f1
commit e923de78aa
24 changed files with 230 additions and 226 deletions

View File

@ -1,4 +1,7 @@
//
// Copyright (c) 2017 The Altra64 project contributors
// See LICENSE file in the project root for full license information.
//
#ifndef _CHKSUM64_H #ifndef _CHKSUM64_H
#define _CHKSUM64_H #define _CHKSUM64_H

View File

@ -8,8 +8,6 @@
#define _FAT_H #define _FAT_H
#include "types.h" #include "types.h"
#include "errors.h"

14
inc/image.h Normal file
View File

@ -0,0 +1,14 @@
//
// Copyright (c) 2017 The Altra64 project contributors
// See LICENSE file in the project root for full license information.
//
#ifndef _IMAGE_H
#define _IMAGE_H
sprite_t *loadImage32DFS(char *fname);
sprite_t *loadImageDFS(char *fname);
sprite_t *loadImage32(u8 *tbuf, int size);
void drawImage(display_context_t dcon, sprite_t *sprite);
#endif

View File

@ -16,6 +16,7 @@ int saveTypeToSd(display_context_t disp, char* save_filename ,int type);
void drawShortInfoBox(display_context_t disp, char* text, u8 mode); void drawShortInfoBox(display_context_t disp, char* text, u8 mode);
void drawTextInput(display_context_t disp,char *msg); void drawTextInput(display_context_t disp,char *msg);
void printText(char *msg, int x, int y, display_context_t dcon);
//#define ishexchar(c) (((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F')) || ((c >= 'a') && (c <= 'f'))) //#define ishexchar(c) (((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F')) || ((c >= 'a') && (c <= 'f')))

View File

@ -7,8 +7,6 @@
#ifndef _MEM_H #ifndef _MEM_H
#define _MEM_H #define _MEM_H
#include "types.h"
#define SPI_SPEED_INIT 2 #define SPI_SPEED_INIT 2
#define SPI_SPEED_25 1 #define SPI_SPEED_25 1
#define SPI_SPEED_50 0 #define SPI_SPEED_50 0

View File

@ -8,7 +8,6 @@
#define _SRAM_H #define _SRAM_H
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include "types.h" #include "types.h"
void data_cache_hit_writeback_invalidate(volatile void *, unsigned long); void data_cache_hit_writeback_invalidate(volatile void *, unsigned long);

View File

@ -8,8 +8,6 @@
#define _SYS_H #define _SYS_H
#include "types.h" #include "types.h"
#include "utils.h"
#include <libdragon.h>
void dma_read_s(void * ram_address, unsigned long pi_address, unsigned long len); void dma_read_s(void * ram_address, unsigned long pi_address, unsigned long len);

View File

@ -4,11 +4,11 @@
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
// //
#include <stdint.h>
#ifndef _TYPES_H #ifndef _TYPES_H
#define _TYPES_H #define _TYPES_H
#include <stdint.h>
#define u8 unsigned char #define u8 unsigned char
#define u16 unsigned short #define u16 unsigned short
#define u32 unsigned long #define u32 unsigned long

View File

@ -7,7 +7,7 @@
#ifndef _USB_H #ifndef _USB_H
#define _USB_H #define _USB_H
#include "types.h" //#include "types.h"
u8 usbListener(); u8 usbListener();

View File

@ -9,9 +9,9 @@
#define _UTILS_H #define _UTILS_H
// rom.h // rom.h
// rom tools - header inspect // rom tools - header inspect
#include <stdint.h> //#include <stdint.h>
#include <libdragon.h> //#include <libdragon.h>
#include "rom.h" //#include "rom.h"
@ -34,13 +34,9 @@
}) })
#endif #endif
sprite_t *loadImage32DFS(char *fname);
sprite_t *loadImageDFS(char *fname);
sprite_t *loadImage32(u8 *tbuf, int size);
void drawImage(display_context_t dcon, sprite_t *sprite);
void _sync_bus(void); void _sync_bus(void);
void _data_cache_invalidate_all(void); void _data_cache_invalidate_all(void);
void printText(char *msg, int x, int y, display_context_t dcon);
// End ... // End ...

View File

@ -18,8 +18,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#include <stdio.h>
#include <stdlib.h>
#include <libdragon.h> #include <libdragon.h>
#include "sys.h" #include "sys.h"

View File

@ -4,14 +4,11 @@
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
// //
#include <console.h>
#include "disk.h" #include "disk.h"
#include "mem.h" #include "mem.h"
#include "everdrive.h" #include "everdrive.h"
#include "errors.h" #include "errors.h"
#include "sys.h" #include "sys.h"
#include "usb.h"
#define CMD0 0x40 // software reset #define CMD0 0x40 // software reset
#define CMD1 0x41 // brings card out of idle state #define CMD1 0x41 // brings card out of idle state

View File

@ -4,14 +4,9 @@
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
// //
#include "types.h"
#include "everdrive.h" #include "everdrive.h"
#include <libdragon.h>
#include <stdio.h>
#include "sys.h" #include "sys.h"
#include "errors.h" #include "errors.h"
//#include "rom.h"
#include "disk.h"
#define CMD0 0x40 // software reset #define CMD0 0x40 // software reset
#define CMD1 0x41 // brings card out of idle state #define CMD1 0x41 // brings card out of idle state

View File

@ -4,17 +4,15 @@
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
// //
#include <console.h>
#include <malloc.h> #include <malloc.h>
#include <libdragon.h>
#include "fat.h" #include "fat.h"
#include "disk.h" #include "disk.h"
#include "mem.h" #include "mem.h"
#include "everdrive.h" #include "everdrive.h"
#include "sys.h"
#include <libdragon.h>
#include "strlib.h" #include "strlib.h"
#include "errors.h"

182
src/image.c Normal file
View File

@ -0,0 +1,182 @@
#include <libdragon.h>
#include "types.h"
#include "image.h"
//#define STBI_HEADER_FILE_ONLY
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
/*
* Load an image from the rom filesystem, returning a pointer to the
* sprite that hold the image.
*/
sprite_t *loadImageDFS(char *fname) {
int size, x, y, n, fd;
u8 *tbuf;
u8 *ibuf;
sprite_t *sbuf;
fd = dfs_open(fname);
if (fd < 0)
return 0; // couldn't open image
size = dfs_size(fd);
tbuf = malloc(size);
if (!tbuf) {
dfs_close(fd);
return 0; // out of memory
}
dfs_read(tbuf, 1, size, fd);
dfs_close(fd);
ibuf = stbi_load_from_memory(tbuf, size, &x, &y, &n, 4);
free(tbuf);
if (!ibuf)
return 0; // couldn't decode image
sbuf = (sprite_t*)malloc(sizeof(sprite_t) + x * y * 2);
if (!sbuf) {
stbi_image_free(ibuf);
return 0; // out of memory
}
sbuf->width = x;
sbuf->height = y;
sbuf->bitdepth = 2;
sbuf->format = 0;
sbuf->hslices = x / 32;
sbuf->vslices = y / 16;
color_t *src = (color_t*)ibuf;
u16 *dst = (u16*)((u32)sbuf + sizeof(sprite_t));
for (int j=0; j<y; j++)
for (int i=0; i<x; i++)
dst[i + j*x] = graphics_convert_color(src[i + j*x]) & 0x0000FFFF;
/* Invalidate data associated with sprite in cache */
data_cache_hit_writeback_invalidate( sbuf->data, sbuf->width * sbuf->height * sbuf->bitdepth );
stbi_image_free(ibuf);
return sbuf;
}
sprite_t *loadImage32(u8 *png, int size) {
int x, y, n, fd;
u8 *tbuf;
u32 *ibuf;
sprite_t *sbuf;
tbuf = malloc(size);
memcpy(tbuf,png,size);
ibuf = (u32*)stbi_load_from_memory(tbuf, size, &x, &y, &n, 4);
free(tbuf);
if (!ibuf)
return 0; // couldn't decode image
sbuf = (sprite_t*)malloc(sizeof(sprite_t) + x * y * 4);
if (!sbuf) {
stbi_image_free(ibuf);
return 0; // out of memory
}
sbuf->width = x;
sbuf->height = y;
sbuf->bitdepth = 4;
sbuf->format = 0;
sbuf->hslices = x / 32;
sbuf->vslices = y / 32;
// color_t *src = (color_t*)ibuf;
u32 *dst = (u32*)((u32)sbuf + sizeof(sprite_t));
for (int j=0; j<y; j++)
for (int i=0; i<x; i++)
dst[i + j*x] = ibuf[i + j*x];
/* Invalidate data associated with sprite in cache */
data_cache_hit_writeback_invalidate( sbuf->data, sbuf->width * sbuf->height * sbuf->bitdepth );
stbi_image_free(ibuf);
return sbuf;
}
sprite_t *loadImage32DFS(char *fname) {
int size, x, y, n, fd;
u8 *tbuf;
u32 *ibuf;
sprite_t *sbuf;
fd = dfs_open(fname);
if (fd < 0)
return 0; // couldn't open image
size = dfs_size(fd);
tbuf = malloc(size);
if (!tbuf) {
dfs_close(fd);
return 0; // out of memory
}
dfs_read(tbuf, 1, size, fd);
dfs_close(fd);
ibuf = (u32*)stbi_load_from_memory(tbuf, size, &x, &y, &n, 4);
free(tbuf);
if (!ibuf)
return 0; // couldn't decode image
sbuf = (sprite_t*)malloc(sizeof(sprite_t) + x * y * 4);
if (!sbuf) {
stbi_image_free(ibuf);
return 0; // out of memory
}
sbuf->width = x;
sbuf->height = y;
sbuf->bitdepth = 4;
sbuf->format = 0;
sbuf->hslices = x / 32;
sbuf->vslices = y / 32;
// color_t *src = (color_t*)ibuf;
u32 *dst = (u32*)((u32)sbuf + sizeof(sprite_t));
for (int j=0; j<y; j++)
for (int i=0; i<x; i++)
dst[i + j*x] = ibuf[i + j*x];
/* Invalidate data associated with sprite in cache */
data_cache_hit_writeback_invalidate( sbuf->data, sbuf->width * sbuf->height * sbuf->bitdepth );
stbi_image_free(ibuf);
return sbuf;
}
/*
* Draw an image to the screen using the sprite passed.
*/
void drawImage(display_context_t dcon, sprite_t *sprite) {
int x, y = 0;
rdp_sync(SYNC_PIPE);
rdp_set_default_clipping();
rdp_enable_texture_copy();
rdp_attach_display(dcon);
// Draw image
for (int j=0; j<sprite->vslices; j++) {
x = 0;
for (int i=0; i<sprite->hslices; i++) {
rdp_sync(SYNC_PIPE);
rdp_load_texture_stride(0, 0, MIRROR_DISABLED, sprite, j*sprite->hslices + i);
rdp_draw_sprite(0, x, y);
x += 32;
}
y += 16;
}
rdp_detach_display();
}

View File

@ -46,6 +46,8 @@
#include "mem.h" #include "mem.h"
#include "chksum64.h" #include "chksum64.h"
#include "version.h" #include "version.h"
#include "image.h"
#include "rom.h"
#ifdef USE_TRUETYPE #ifdef USE_TRUETYPE
#define STB_TRUETYPE_IMPLEMENTATION #define STB_TRUETYPE_IMPLEMENTATION

View File

@ -4,14 +4,13 @@
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
// //
#include "types.h"
#include "everdrive.h" #include "everdrive.h"
#include "sys.h" #include "sys.h"
u8 spi_dma;
#include "errors.h" #include "errors.h"
#include "mem.h" #include "mem.h"
u8 spi_dma;
u8 memSpiReadDma(void *dst, u16 slen); u8 memSpiReadDma(void *dst, u16 slen);
u8 memSpiReadPio(void *dst, u16 slen); u8 memSpiReadPio(void *dst, u16 slen);
u8 mem_buff[512]; u8 mem_buff[512];

View File

@ -7,7 +7,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdint.h>
#include <mad.h> #include <mad.h>
#include "fat.h" #include "fat.h"
#include "mp3.h" #include "mp3.h"

View File

@ -7,6 +7,7 @@
#include "sram.h" #include "sram.h"
#include "everdrive.h" #include "everdrive.h"
#include "sys.h" #include "sys.h"
#include "rom.h"
void pif_boot() void pif_boot()
{ {

View File

@ -5,12 +5,12 @@
// //
#include <malloc.h> #include <malloc.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include "sys.h" #include "sys.h"
#include "types.h"
#include "utils.h" #include "utils.h"
#include "sram.h" #include "sram.h"
#include "rom.h"
void PI_Init(void) { void PI_Init(void) {

View File

@ -5,6 +5,7 @@
// //
#include "strlib.h" #include "strlib.h"
#include "types.h"
char *strcpytrim(char *d, // destination char *strcpytrim(char *d, // destination
char *s, // source char *s, // source

View File

@ -8,10 +8,11 @@
#include <dma.h> #include <dma.h>
#include <n64sys.h> #include <n64sys.h>
#include "sys.h" #include "sys.h"
#include "types.h" //#include "types.h"
#include "everdrive.h" //#include "everdrive.h"
#include "errors.h" //#include "errors.h"
#include "usb.h" //#include "usb.h"
#include "rom.h"
u32 asm_date; u32 asm_date;

View File

@ -6,8 +6,6 @@
#include "everdrive.h" #include "everdrive.h"
#include "sys.h" #include "sys.h"
#include "types.h"
#include <libdragon.h>
#include "rom.h" #include "rom.h"
u8 cmdTest(); u8 cmdTest();

View File

@ -4,23 +4,21 @@
// See LICENSE file in the project root for full license information. // See LICENSE file in the project root for full license information.
// //
#include <stdio.h> //#include <stdio.h>
#include <stdlib.h> //#include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdint.h> //#include <stdint.h>
#include <malloc.h> //#include <malloc.h>
#include <libdragon.h> #include <libdragon.h>
#include <n64sys.h> //#include <n64sys.h>
#include "everdrive.h" #include "everdrive.h"
#include "sys.h" #include "sys.h"
#include "types.h" #include "types.h"
#include "utils.h" #include "utils.h"
#include "sram.h" #include "sram.h"
#include "rom.h"
//#define STBI_HEADER_FILE_ONLY
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
extern short int gCheats; /* 0 = off, 1 = select, 2 = all */ extern short int gCheats; /* 0 = off, 1 = select, 2 = all */
extern short int force_tv; extern short int force_tv;
@ -450,179 +448,6 @@ void restoreTiming(void) {
IO_WRITE(PI_BSD_DOM2_RLS_REG, 0x03); IO_WRITE(PI_BSD_DOM2_RLS_REG, 0x03);
} }
/*
* Load an image from the rom filesystem, returning a pointer to the
* sprite that hold the image.
*/
sprite_t *loadImageDFS(char *fname) {
int size, x, y, n, fd;
u8 *tbuf;
u8 *ibuf;
sprite_t *sbuf;
fd = dfs_open(fname);
if (fd < 0)
return 0; // couldn't open image
size = dfs_size(fd);
tbuf = malloc(size);
if (!tbuf) {
dfs_close(fd);
return 0; // out of memory
}
dfs_read(tbuf, 1, size, fd);
dfs_close(fd);
ibuf = stbi_load_from_memory(tbuf, size, &x, &y, &n, 4);
free(tbuf);
if (!ibuf)
return 0; // couldn't decode image
sbuf = (sprite_t*)malloc(sizeof(sprite_t) + x * y * 2);
if (!sbuf) {
stbi_image_free(ibuf);
return 0; // out of memory
}
sbuf->width = x;
sbuf->height = y;
sbuf->bitdepth = 2;
sbuf->format = 0;
sbuf->hslices = x / 32;
sbuf->vslices = y / 16;
color_t *src = (color_t*)ibuf;
u16 *dst = (u16*)((u32)sbuf + sizeof(sprite_t));
for (int j=0; j<y; j++)
for (int i=0; i<x; i++)
dst[i + j*x] = graphics_convert_color(src[i + j*x]) & 0x0000FFFF;
/* Invalidate data associated with sprite in cache */
data_cache_hit_writeback_invalidate( sbuf->data, sbuf->width * sbuf->height * sbuf->bitdepth );
stbi_image_free(ibuf);
return sbuf;
}
sprite_t *loadImage32(u8 *png, int size) {
int x, y, n, fd;
u8 *tbuf;
u32 *ibuf;
sprite_t *sbuf;
tbuf = malloc(size);
memcpy(tbuf,png,size);
ibuf = (u32*)stbi_load_from_memory(tbuf, size, &x, &y, &n, 4);
free(tbuf);
if (!ibuf)
return 0; // couldn't decode image
sbuf = (sprite_t*)malloc(sizeof(sprite_t) + x * y * 4);
if (!sbuf) {
stbi_image_free(ibuf);
return 0; // out of memory
}
sbuf->width = x;
sbuf->height = y;
sbuf->bitdepth = 4;
sbuf->format = 0;
sbuf->hslices = x / 32;
sbuf->vslices = y / 32;
// color_t *src = (color_t*)ibuf;
u32 *dst = (u32*)((u32)sbuf + sizeof(sprite_t));
for (int j=0; j<y; j++)
for (int i=0; i<x; i++)
dst[i + j*x] = ibuf[i + j*x];
/* Invalidate data associated with sprite in cache */
data_cache_hit_writeback_invalidate( sbuf->data, sbuf->width * sbuf->height * sbuf->bitdepth );
stbi_image_free(ibuf);
return sbuf;
}
sprite_t *loadImage32DFS(char *fname) {
int size, x, y, n, fd;
u8 *tbuf;
u32 *ibuf;
sprite_t *sbuf;
fd = dfs_open(fname);
if (fd < 0)
return 0; // couldn't open image
size = dfs_size(fd);
tbuf = malloc(size);
if (!tbuf) {
dfs_close(fd);
return 0; // out of memory
}
dfs_read(tbuf, 1, size, fd);
dfs_close(fd);
ibuf = (u32*)stbi_load_from_memory(tbuf, size, &x, &y, &n, 4);
free(tbuf);
if (!ibuf)
return 0; // couldn't decode image
sbuf = (sprite_t*)malloc(sizeof(sprite_t) + x * y * 4);
if (!sbuf) {
stbi_image_free(ibuf);
return 0; // out of memory
}
sbuf->width = x;
sbuf->height = y;
sbuf->bitdepth = 4;
sbuf->format = 0;
sbuf->hslices = x / 32;
sbuf->vslices = y / 32;
// color_t *src = (color_t*)ibuf;
u32 *dst = (u32*)((u32)sbuf + sizeof(sprite_t));
for (int j=0; j<y; j++)
for (int i=0; i<x; i++)
dst[i + j*x] = ibuf[i + j*x];
/* Invalidate data associated with sprite in cache */
data_cache_hit_writeback_invalidate( sbuf->data, sbuf->width * sbuf->height * sbuf->bitdepth );
stbi_image_free(ibuf);
return sbuf;
}
/*
* Draw an image to the screen using the sprite passed.
*/
void drawImage(display_context_t dcon, sprite_t *sprite) {
int x, y = 0;
rdp_sync(SYNC_PIPE);
rdp_set_default_clipping();
rdp_enable_texture_copy();
rdp_attach_display(dcon);
// Draw image
for (int j=0; j<sprite->vslices; j++) {
x = 0;
for (int i=0; i<sprite->hslices; i++) {
rdp_sync(SYNC_PIPE);
rdp_load_texture_stride(0, 0, MIRROR_DISABLED, sprite, j*sprite->hslices + i);
rdp_draw_sprite(0, x, y);
x += 32;
}
y += 16;
}
rdp_detach_display();
}
//#define CIC_6101 1 //#define CIC_6101 1
//#define CIC_6102 2 //#define CIC_6102 2