diff --git a/inc/chksum64.h b/inc/chksum64.h index ff8096f..67f64f2 100644 --- a/inc/chksum64.h +++ b/inc/chksum64.h @@ -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 #define _CHKSUM64_H diff --git a/inc/fat.h b/inc/fat.h index 5f2b1d4..de61b8b 100644 --- a/inc/fat.h +++ b/inc/fat.h @@ -8,8 +8,6 @@ #define _FAT_H #include "types.h" -#include "errors.h" - diff --git a/inc/image.h b/inc/image.h new file mode 100644 index 0000000..f1e5aa2 --- /dev/null +++ b/inc/image.h @@ -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 diff --git a/inc/main.h b/inc/main.h index 322788c..4ed601a 100644 --- a/inc/main.h +++ b/inc/main.h @@ -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 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'))) diff --git a/inc/mem.h b/inc/mem.h index b5f0661..686cf48 100644 --- a/inc/mem.h +++ b/inc/mem.h @@ -7,8 +7,6 @@ #ifndef _MEM_H #define _MEM_H -#include "types.h" - #define SPI_SPEED_INIT 2 #define SPI_SPEED_25 1 #define SPI_SPEED_50 0 diff --git a/inc/sram.h b/inc/sram.h index a8f4c32..58ebd63 100644 --- a/inc/sram.h +++ b/inc/sram.h @@ -8,7 +8,6 @@ #define _SRAM_H #include -#include #include "types.h" void data_cache_hit_writeback_invalidate(volatile void *, unsigned long); diff --git a/inc/sys.h b/inc/sys.h index a2e5ded..bec1454 100644 --- a/inc/sys.h +++ b/inc/sys.h @@ -8,8 +8,6 @@ #define _SYS_H #include "types.h" -#include "utils.h" -#include void dma_read_s(void * ram_address, unsigned long pi_address, unsigned long len); diff --git a/inc/types.h b/inc/types.h index b8e481f..b5a37cb 100644 --- a/inc/types.h +++ b/inc/types.h @@ -4,11 +4,11 @@ // See LICENSE file in the project root for full license information. // -#include - #ifndef _TYPES_H #define _TYPES_H +#include + #define u8 unsigned char #define u16 unsigned short #define u32 unsigned long diff --git a/inc/usb.h b/inc/usb.h index 93f962f..25958ce 100644 --- a/inc/usb.h +++ b/inc/usb.h @@ -7,7 +7,7 @@ #ifndef _USB_H #define _USB_H -#include "types.h" +//#include "types.h" u8 usbListener(); diff --git a/inc/utils.h b/inc/utils.h index 9cb60ff..c9347a7 100644 --- a/inc/utils.h +++ b/inc/utils.h @@ -9,9 +9,9 @@ #define _UTILS_H // rom.h // rom tools - header inspect -#include -#include -#include "rom.h" +//#include +//#include +//#include "rom.h" @@ -34,13 +34,9 @@ }) #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 _data_cache_invalidate_all(void); -void printText(char *msg, int x, int y, display_context_t dcon); // End ... diff --git a/src/chksum64.c b/src/chksum64.c index 5b2c2ba..3b0348b 100644 --- a/src/chksum64.c +++ b/src/chksum64.c @@ -18,8 +18,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#include -#include + #include #include "sys.h" diff --git a/src/disk.c b/src/disk.c index 2c84dc7..dda0dd2 100644 --- a/src/disk.c +++ b/src/disk.c @@ -4,14 +4,11 @@ // See LICENSE file in the project root for full license information. // -#include - #include "disk.h" #include "mem.h" #include "everdrive.h" #include "errors.h" #include "sys.h" -#include "usb.h" #define CMD0 0x40 // software reset #define CMD1 0x41 // brings card out of idle state diff --git a/src/everdrive.c b/src/everdrive.c index c4dcef2..7339f08 100644 --- a/src/everdrive.c +++ b/src/everdrive.c @@ -4,14 +4,9 @@ // See LICENSE file in the project root for full license information. // -#include "types.h" #include "everdrive.h" -#include -#include #include "sys.h" #include "errors.h" -//#include "rom.h" -#include "disk.h" #define CMD0 0x40 // software reset #define CMD1 0x41 // brings card out of idle state diff --git a/src/fat.c b/src/fat.c index 4e35e8f..32ec924 100644 --- a/src/fat.c +++ b/src/fat.c @@ -4,17 +4,15 @@ // See LICENSE file in the project root for full license information. // -#include #include +#include #include "fat.h" #include "disk.h" #include "mem.h" #include "everdrive.h" -#include "sys.h" -#include #include "strlib.h" - +#include "errors.h" diff --git a/src/image.c b/src/image.c new file mode 100644 index 0000000..3d7897c --- /dev/null +++ b/src/image.c @@ -0,0 +1,182 @@ + +#include +#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; jdata, 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; jdata, 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; jdata, 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; jvslices; j++) { + x = 0; + for (int i=0; ihslices; 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(); +} \ No newline at end of file diff --git a/src/main.c b/src/main.c index 39097c6..9998a64 100644 --- a/src/main.c +++ b/src/main.c @@ -46,6 +46,8 @@ #include "mem.h" #include "chksum64.h" #include "version.h" +#include "image.h" +#include "rom.h" #ifdef USE_TRUETYPE #define STB_TRUETYPE_IMPLEMENTATION diff --git a/src/mem.c b/src/mem.c index bfc27f2..05654ee 100644 --- a/src/mem.c +++ b/src/mem.c @@ -4,14 +4,13 @@ // See LICENSE file in the project root for full license information. // -#include "types.h" #include "everdrive.h" #include "sys.h" - -u8 spi_dma; #include "errors.h" #include "mem.h" +u8 spi_dma; + u8 memSpiReadDma(void *dst, u16 slen); u8 memSpiReadPio(void *dst, u16 slen); u8 mem_buff[512]; diff --git a/src/mp3.c b/src/mp3.c index 4537314..eab9790 100644 --- a/src/mp3.c +++ b/src/mp3.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "fat.h" #include "mp3.h" diff --git a/src/rom.c b/src/rom.c index 0a40319..35cca00 100644 --- a/src/rom.c +++ b/src/rom.c @@ -7,6 +7,7 @@ #include "sram.h" #include "everdrive.h" #include "sys.h" +#include "rom.h" void pif_boot() { diff --git a/src/sram.c b/src/sram.c index f787407..3f31fc9 100644 --- a/src/sram.c +++ b/src/sram.c @@ -5,12 +5,12 @@ // #include -#include #include + #include "sys.h" -#include "types.h" #include "utils.h" #include "sram.h" +#include "rom.h" void PI_Init(void) { diff --git a/src/strlib.c b/src/strlib.c index 50ea0c8..ecc041f 100644 --- a/src/strlib.c +++ b/src/strlib.c @@ -5,6 +5,7 @@ // #include "strlib.h" +#include "types.h" char *strcpytrim(char *d, // destination char *s, // source diff --git a/src/sys.c b/src/sys.c index c3154ff..f78a01f 100644 --- a/src/sys.c +++ b/src/sys.c @@ -8,10 +8,11 @@ #include #include #include "sys.h" -#include "types.h" -#include "everdrive.h" -#include "errors.h" -#include "usb.h" +//#include "types.h" +//#include "everdrive.h" +//#include "errors.h" +//#include "usb.h" +#include "rom.h" u32 asm_date; diff --git a/src/usb.c b/src/usb.c index 0c684ad..c64f7f5 100644 --- a/src/usb.c +++ b/src/usb.c @@ -6,8 +6,6 @@ #include "everdrive.h" #include "sys.h" -#include "types.h" -#include #include "rom.h" u8 cmdTest(); diff --git a/src/utils.c b/src/utils.c index 6427a71..a1c4e57 100644 --- a/src/utils.c +++ b/src/utils.c @@ -4,23 +4,21 @@ // See LICENSE file in the project root for full license information. // -#include -#include +//#include +//#include #include -#include -#include +//#include +//#include #include -#include +//#include #include "everdrive.h" #include "sys.h" #include "types.h" #include "utils.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 force_tv; @@ -450,179 +448,6 @@ void restoreTiming(void) { 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; jdata, 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; jdata, 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; jdata, 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; jvslices; j++) { - x = 0; - for (int i=0; ihslices; 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_6102 2