Browse Source

removed includes from headers

corrected location of some protos
removed un-needed includes from source files
master
Robin Jones 4 years ago
parent
commit
e923de78aa
24 changed files with 230 additions and 226 deletions
  1. +4
    -1
      inc/chksum64.h
  2. +0
    -2
      inc/fat.h
  3. +14
    -0
      inc/image.h
  4. +1
    -0
      inc/main.h
  5. +0
    -2
      inc/mem.h
  6. +0
    -1
      inc/sram.h
  7. +0
    -2
      inc/sys.h
  8. +2
    -2
      inc/types.h
  9. +1
    -1
      inc/usb.h
  10. +4
    -8
      inc/utils.h
  11. +1
    -2
      src/chksum64.c
  12. +0
    -3
      src/disk.c
  13. +0
    -5
      src/everdrive.c
  14. +2
    -4
      src/fat.c
  15. +182
    -0
      src/image.c
  16. +2
    -0
      src/main.c
  17. +2
    -3
      src/mem.c
  18. +0
    -1
      src/mp3.c
  19. +1
    -0
      src/rom.c
  20. +2
    -2
      src/sram.c
  21. +1
    -0
      src/strlib.c
  22. +5
    -4
      src/sys.c
  23. +0
    -2
      src/usb.c
  24. +6
    -181
      src/utils.c

+ 4
- 1
inc/chksum64.h 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
#define _CHKSUM64_H


+ 0
- 2
inc/fat.h View File

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


+ 14
- 0
inc/image.h 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

+ 1
- 0
inc/main.h 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 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')))


+ 0
- 2
inc/mem.h View File

@ -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


+ 0
- 1
inc/sram.h View File

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


+ 0
- 2
inc/sys.h View File

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


+ 2
- 2
inc/types.h View File

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


+ 1
- 1
inc/usb.h View File

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


+ 4
- 8
inc/utils.h View File

@ -9,9 +9,9 @@
#define _UTILS_H
// rom.h
// rom tools - header inspect
#include <stdint.h>
#include <libdragon.h>
#include "rom.h"
//#include <stdint.h>
//#include <libdragon.h>
//#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 ...


+ 1
- 2
src/chksum64.c View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <libdragon.h>
#include "sys.h"


+ 0
- 3
src/disk.c View File

@ -4,14 +4,11 @@
// See LICENSE file in the project root for full license information.
//
#include <console.h>
#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


+ 0
- 5
src/everdrive.c View File

@ -4,14 +4,9 @@
// See LICENSE file in the project root for full license information.
//
#include "types.h"
#include "everdrive.h"
#include <libdragon.h>
#include <stdio.h>
#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


+ 2
- 4
src/fat.c View File

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


+ 182
- 0
src/image.c 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();
}

+ 2
- 0
src/main.c View File

@ -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


+ 2
- 3
src/mem.c View File

@ -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];


+ 0
- 1
src/mp3.c View File

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


+ 1
- 0
src/rom.c View File

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


+ 2
- 2
src/sram.c View File

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


+ 1
- 0
src/strlib.c View File

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


+ 5
- 4
src/sys.c View File

@ -8,10 +8,11 @@
#include <dma.h>
#include <n64sys.h>
#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;


+ 0
- 2
src/usb.c View File

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


+ 6
- 181
src/utils.c View File

@ -4,23 +4,21 @@
// See LICENSE file in the project root for full license information.
//
#include <stdio.h>
#include <stdlib.h>
//#include <stdio.h>
//#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <malloc.h>
//#include <stdint.h>
//#include <malloc.h>
#include <libdragon.h>
#include <n64sys.h>
//#include <n64sys.h>
#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; 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_6102 2


Loading…
Cancel
Save