Changed indent, started adding tools for making games.
This commit is contained in:
parent
9624d64b23
commit
a5f1840911
|
@ -1,3 +1,4 @@
|
|||
build/
|
||||
lib/
|
||||
*g1a
|
||||
/tools/mapconv/mapconv
|
||||
|
|
|
@ -13,7 +13,8 @@ SRC = src/start.c \
|
|||
src/gui.c \
|
||||
src/memory.c \
|
||||
src/rtc.c \
|
||||
src/ext/img.c
|
||||
src/ext/img.c \
|
||||
src/ext/gametools/map.c
|
||||
OBJ = $(SRC:src/%=build/%.o)
|
||||
|
||||
CFLAGS = -Os -Wall -Wextra -Wpedantic -Werror -std=c89
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef GAMETOOLS_H
|
||||
#define GAMETOOLS_H
|
||||
|
||||
/******* MAP *******/
|
||||
|
||||
/* Struct */
|
||||
|
||||
typedef struct {
|
||||
unsigned char *map; /* Map data (size w*h)
|
||||
the tile 0 contains nothing, and the other tiles are decremented and grabbed
|
||||
in tileset, so 1 is the first tile in tileset. */
|
||||
unsigned char **tileset; /* Tileset (Sprite Coder sprite table) */
|
||||
int w, h; /* Map width and height */
|
||||
int tw, th; /* Tile width and height */
|
||||
int px, py; /* Contains the position of the player on the screen, after
|
||||
drawing the map */
|
||||
} MMap;
|
||||
|
||||
/* Prototypes */
|
||||
|
||||
/* void dmap(int sx, int sy, MMap *map);
|
||||
|
||||
Draws a map contained in a MMap struct.
|
||||
dmap draw the map from sx, sy.
|
||||
*/
|
||||
|
||||
void vmap(int sx, int sy, MMap *map);
|
||||
|
||||
#endif
|
|
@ -273,7 +273,7 @@ input.
|
|||
|
||||
void gstrask(char *buffer, char *message, int maxlen);
|
||||
|
||||
/* void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
|
||||
/* void gfkeyset(int pos, unsigned char *img);
|
||||
|
||||
Draws an fkey from a Sprite Coder string that is in img, at fkey position pos.
|
||||
*/
|
||||
|
|
|
@ -19,52 +19,52 @@ char* _GetVRAMAddress(void);
|
|||
/* Microfx */
|
||||
|
||||
void sclear() {
|
||||
_Bdisp_AllClr_VRAM();
|
||||
_Bdisp_AllClr_VRAM();
|
||||
}
|
||||
|
||||
void supdate() {
|
||||
_Bdisp_PutDisp_DD();
|
||||
_Bdisp_PutDisp_DD();
|
||||
}
|
||||
|
||||
void spixel(int x, int y, int color) {
|
||||
if(x>=0 && x<SWIDTH && y>=0 && y<SHEIGHT){
|
||||
_Bdisp_SetPoint_VRAM(x, y, color);
|
||||
}
|
||||
if(x>=0 && x<SWIDTH && y>=0 && y<SHEIGHT){
|
||||
_Bdisp_SetPoint_VRAM(x, y, color);
|
||||
}
|
||||
}
|
||||
|
||||
void srect(int x1, int y1, int x2, int y2) {
|
||||
_Bdisp_DrawRectangle(x1, y1, x2, y2);
|
||||
_Bdisp_DrawRectangle(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
void sline(int x1, int y1, int x2, int y2, int color) {
|
||||
if(color){
|
||||
_Bdisp_DrawLineVRAM(x1, y1, x2, y2);
|
||||
}else{
|
||||
_Bdisp_ClearLineVRAM(x1, y1, x2, y2);
|
||||
}
|
||||
if(color){
|
||||
_Bdisp_DrawLineVRAM(x1, y1, x2, y2);
|
||||
}else{
|
||||
_Bdisp_ClearLineVRAM(x1, y1, x2, y2);
|
||||
}
|
||||
}
|
||||
|
||||
void stext(int x, int y, char *text, int color) {
|
||||
_PrintXY(x, y, (unsigned char*)text, !color);
|
||||
_PrintXY(x, y, (unsigned char*)text, !color);
|
||||
}
|
||||
|
||||
void slocate(int x, int y, char *text) {
|
||||
_locate(x, y);
|
||||
_Print((unsigned char*)text);
|
||||
_locate(x, y);
|
||||
_Print((unsigned char*)text);
|
||||
}
|
||||
|
||||
void saddlocate(char *text) {
|
||||
_Print((unsigned char*)text);
|
||||
_Print((unsigned char*)text);
|
||||
}
|
||||
|
||||
void sgoto(int x, int y) {
|
||||
_locate(x, y);
|
||||
_locate(x, y);
|
||||
}
|
||||
|
||||
void stextmini(int x, int y, char *text) {
|
||||
_PrintMiniSd(x, y, (unsigned char*)text, 0);
|
||||
_PrintMiniSd(x, y, (unsigned char*)text, 0);
|
||||
}
|
||||
|
||||
char* sgetvram(void) {
|
||||
return _GetVRAMAddress();
|
||||
return _GetVRAMAddress();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
#include "../../../include/microfx/ext/gametools.h"
|
||||
#include "../../../include/microfx/ext/img.h"
|
||||
#include "../../../include/microfx/microfx.h"
|
||||
|
||||
void vmap(int sx, int sy, MMap *map) {
|
||||
/* Dessine la map à l'écran. */
|
||||
/* x et y contiendront la position à laquelle je suis dans la boucle. */
|
||||
int x, y;
|
||||
/* Le nombre de tuiles sur x avant le bout de carte qu'on voit est dans tx,
|
||||
pareil pour y. */
|
||||
int tx = sx/map->tw, ty = sy/map->th;
|
||||
/* mx contient le nombre de pixels qui seront cachés sur x, pareil pour
|
||||
y. */
|
||||
int mx = sx-tx*map->tw, my = sy-ty*map->th;
|
||||
/* tile contient la tuile à dessiner */
|
||||
unsigned char tile;
|
||||
/* J'ajuste sx. */
|
||||
if(sx-SWIDTH/2<0){
|
||||
/* Si je ne peux pas centrer le joueur car je suis trop proche du bord
|
||||
gauche de la map. */
|
||||
map->px = sx;
|
||||
sx = 0;
|
||||
}else if(sx+SWIDTH/2>map->w*map->tw){
|
||||
/* Si je ne peux pas centrer le joueur car je suis trop proche du bord
|
||||
droit de la map. */
|
||||
map->px = sx-(map->w*map->tw-SWIDTH/2);
|
||||
sx = map->w*map->tw-SWIDTH/2;
|
||||
}else{
|
||||
/* Sinon je peux centrer le joueur. */
|
||||
sx = sx-SWIDTH/2;
|
||||
map->px = SWIDTH/2;
|
||||
}
|
||||
/* J'ajuste sy. */
|
||||
if(sy-SHEIGHT/2<0){
|
||||
/* Si je ne peux pas centrer le joueur car je suis trop proche du haut
|
||||
de la map. */
|
||||
map->py = sy;
|
||||
sy = 0;
|
||||
}else if(sy+SHEIGHT/2>map->h*map->th){
|
||||
/* Si je ne peux pas centrer le joueur car je suis trop proche du bas de
|
||||
la map. */
|
||||
map->py = sy-(map->h*map->th-SHEIGHT/2);
|
||||
sy = map->h*map->th-SHEIGHT/2;
|
||||
}else{
|
||||
/* Sinon je peux centrer le joueur. */
|
||||
sy = sy-SHEIGHT/2;
|
||||
map->py = SHEIGHT/2;
|
||||
}
|
||||
tx = sx/map->tw;
|
||||
ty = sy/map->th;
|
||||
for(y=0;y<map->h;y++){
|
||||
for(x=0;x<map->w;x++){
|
||||
/* Je récupère la tuile dans map et je la dessine si tx+x est plus
|
||||
petit que la largeur de la map. */
|
||||
if(tx+x < map->w){
|
||||
tile = map->map[(ty+y)*map->w+tx+x];
|
||||
if(tile > 0){
|
||||
simage(x*map->tw-mx, y*map->th-my, map->tw, map->th,
|
||||
map->tileset[(int)tile-1], SNORMAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,28 +2,28 @@
|
|||
#include <microfx/microfx.h>
|
||||
|
||||
void simage(int sx, int sy, int w, int h, unsigned char *img, int mode) {
|
||||
/* Draws an image from a sprite coder string */
|
||||
int x, y, rpos, gpos, bpos, color;
|
||||
for(y=0;y<h;y++){
|
||||
for(x=0;x<w;x++){
|
||||
rpos = y*(w+(w%2))+x;
|
||||
gpos = rpos/8;
|
||||
bpos = rpos%8;
|
||||
color = (img[gpos] << bpos) & 0x80;
|
||||
switch(mode){
|
||||
case STRANSP:
|
||||
if(color) spixel(sx+x, sy+y, SWHITE);
|
||||
break;
|
||||
case SNOWHITE:
|
||||
if(color) spixel(sx+x, sy+y, SBLACK);
|
||||
break;
|
||||
case SNOBLACK:
|
||||
if(!color) spixel(sx+x, sy+y, SWHITE);
|
||||
break;
|
||||
default: /* SNORMAL or SINVERTED */
|
||||
spixel(sx+x, sy+y, mode ? !color : color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Draws an image from a sprite coder string */
|
||||
int x, y, rpos, gpos, bpos, color;
|
||||
for(y=0;y<h;y++){
|
||||
for(x=0;x<w;x++){
|
||||
rpos = y*(w+(w%2))+x;
|
||||
gpos = rpos/8;
|
||||
bpos = rpos%8;
|
||||
color = (img[gpos] << bpos) & 0x80;
|
||||
switch(mode){
|
||||
case STRANSP:
|
||||
if(color) spixel(sx+x, sy+y, SWHITE);
|
||||
break;
|
||||
case SNOWHITE:
|
||||
if(color) spixel(sx+x, sy+y, SBLACK);
|
||||
break;
|
||||
case SNOBLACK:
|
||||
if(!color) spixel(sx+x, sy+y, SWHITE);
|
||||
break;
|
||||
default: /* SNORMAL or SINVERTED */
|
||||
spixel(sx+x, sy+y, mode ? !color : color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,32 +2,32 @@ ENTRY(_start)
|
|||
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x00300200, LENGTH = 512K
|
||||
ram (rw) : ORIGIN = 0x08100200, LENGTH = 20K
|
||||
rom (rx) : ORIGIN = 0x00300200, LENGTH = 512K
|
||||
ram (rw) : ORIGIN = 0x08100200, LENGTH = 20K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : {
|
||||
*(.pretext)
|
||||
*(.text)
|
||||
} > rom
|
||||
.rodata : {
|
||||
*(.rodata)
|
||||
*(.rodata.str1.4)
|
||||
_romdata_start = . ;
|
||||
} > rom
|
||||
.bss : {
|
||||
_start_bss = . ;
|
||||
_bssdatasize = . ;
|
||||
LONG(0);
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
_end_bss = . ;
|
||||
} > ram
|
||||
.data : AT(_romdata_start) {
|
||||
_start_data = . ;
|
||||
*(.data)
|
||||
_end_data = . ;
|
||||
} > ram
|
||||
.text : {
|
||||
*(.pretext)
|
||||
*(.text)
|
||||
} > rom
|
||||
.rodata : {
|
||||
*(.rodata)
|
||||
*(.rodata.str1.4)
|
||||
_romdata_start = . ;
|
||||
} > rom
|
||||
.bss : {
|
||||
_start_bss = . ;
|
||||
_bssdatasize = . ;
|
||||
LONG(0);
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
_end_bss = . ;
|
||||
} > ram
|
||||
.data : AT(_romdata_start) {
|
||||
_start_data = . ;
|
||||
*(.data)
|
||||
_end_data = . ;
|
||||
} > ram
|
||||
}
|
||||
|
|
|
@ -13,21 +13,21 @@ void _PopupWin(int nlines);
|
|||
/* Microfx */
|
||||
|
||||
int gnumask(char *message, int maxlen, int type) {
|
||||
return _InputNumber((unsigned char *)message, maxlen, type);
|
||||
return _InputNumber((unsigned char *)message, maxlen, type);
|
||||
}
|
||||
|
||||
void gstrask(char *buffer, char *message, int maxlen) {
|
||||
_InputString((unsigned char *)buffer, (unsigned char *)message, maxlen);
|
||||
_InputString((unsigned char *)buffer, (unsigned char *)message, maxlen);
|
||||
}
|
||||
|
||||
void gfkeyset(int pos, unsigned char *img) {
|
||||
_DisplayFKeyIcon(pos, img);
|
||||
_DisplayFKeyIcon(pos, img);
|
||||
}
|
||||
|
||||
void gmessagebox(int height, char *message) {
|
||||
_DisplayMessageBox(height, (unsigned char*)message);
|
||||
_DisplayMessageBox(height, (unsigned char*)message);
|
||||
}
|
||||
|
||||
void gpopup(int hlines) {
|
||||
_PopupWin(hlines);
|
||||
_PopupWin(hlines);
|
||||
}
|
||||
|
|
|
@ -10,33 +10,33 @@ int _Keyboard_PRGM_GetKey(unsigned char* buffer);
|
|||
/* Microfx */
|
||||
|
||||
int kisdown(void) {
|
||||
return _Keyboard_KeyDown();
|
||||
return _Keyboard_KeyDown();
|
||||
}
|
||||
|
||||
int kcheck(int key) {
|
||||
/* TODO : Compatibility with older calcs. */
|
||||
/* Get the column and the row of the key. */
|
||||
int row = key%10;
|
||||
int column = key/10 - 1;
|
||||
/* The bit that I will read in the KIUDATA
|
||||
register. */
|
||||
int column_pos = column + 8 * (row & 1);
|
||||
/* row_data will contain the data of the
|
||||
KIUDATA register that we need.
|
||||
keyboard_register contains the address of
|
||||
KIUDATA0. */
|
||||
unsigned short *keyboard_register = (unsigned short*)0xA44B0000;
|
||||
unsigned short row_data;
|
||||
/* Get KIUDATAx where x is row / 2 because two rows
|
||||
are stored in each KIUDATA register. */
|
||||
row_data = keyboard_register[row/2];
|
||||
/* Get the bit located at column. */
|
||||
return (row_data >> column_pos) & 1;
|
||||
/* TODO : Compatibility with older calcs. */
|
||||
/* Get the column and the row of the key. */
|
||||
int row = key%10;
|
||||
int column = key/10 - 1;
|
||||
/* The bit that I will read in the KIUDATA
|
||||
register. */
|
||||
int column_pos = column + 8 * (row & 1);
|
||||
/* row_data will contain the data of the
|
||||
KIUDATA register that we need.
|
||||
keyboard_register contains the address of
|
||||
KIUDATA0. */
|
||||
unsigned short *keyboard_register = (unsigned short*)0xA44B0000;
|
||||
unsigned short row_data;
|
||||
/* Get KIUDATAx where x is row / 2 because two rows
|
||||
are stored in each KIUDATA register. */
|
||||
row_data = keyboard_register[row/2];
|
||||
/* Get the bit located at column. */
|
||||
return (row_data >> column_pos) & 1;
|
||||
}
|
||||
|
||||
int kgetkey(void){
|
||||
/* Made a prgm like getkey in the same way as simlo described it. */
|
||||
unsigned char buffer[12];
|
||||
_Keyboard_PRGM_GetKey(buffer);
|
||||
return (buffer[1] & 0x0F) * 10 + ((buffer[2] & 0xF0 ) >> 4);
|
||||
/* Made a prgm like getkey in the same way as simlo described it. */
|
||||
unsigned char buffer[12];
|
||||
_Keyboard_PRGM_GetKey(buffer);
|
||||
return (buffer[1] & 0x0F) * 10 + ((buffer[2] & 0xF0 ) >> 4);
|
||||
}
|
||||
|
|
|
@ -19,57 +19,57 @@ int _Bfile_Size(int fd);
|
|||
extern int fugue;
|
||||
|
||||
int mfugue(void) {
|
||||
return fugue;
|
||||
return fugue;
|
||||
}
|
||||
|
||||
unsigned short int fname[PATHSIZELIMIT];
|
||||
|
||||
void _fixname(const char *filename) {
|
||||
int len, i;
|
||||
len = 0;
|
||||
/* Getting the lenght of the filename */
|
||||
while(filename[len] != '\0' && len < PATHSIZELIMIT){
|
||||
len++;
|
||||
}
|
||||
/* Clearing fname, the file name for Bfile. */
|
||||
for(i=0;i<PATHSIZELIMIT;i++){
|
||||
fname[i] = '\0';
|
||||
}
|
||||
/* Copying the start of a Bfile file name to fname */
|
||||
for(i=0;i<7;i++){
|
||||
fname[i] = fname_start[i];
|
||||
}
|
||||
/* Copying the file name to fname, slashs are also replaced by backslashs */
|
||||
for(i=0;i<len;i++){
|
||||
if(filename[i+1] != '/'){
|
||||
fname[i+7] = filename[i+1];
|
||||
}else{
|
||||
fname[i+7] = '\\';
|
||||
}
|
||||
}
|
||||
int len, i;
|
||||
len = 0;
|
||||
/* Getting the lenght of the filename */
|
||||
while(filename[len] != '\0' && len < PATHSIZELIMIT){
|
||||
len++;
|
||||
}
|
||||
/* Clearing fname, the file name for Bfile. */
|
||||
for(i=0;i<PATHSIZELIMIT;i++){
|
||||
fname[i] = '\0';
|
||||
}
|
||||
/* Copying the start of a Bfile file name to fname */
|
||||
for(i=0;i<7;i++){
|
||||
fname[i] = fname_start[i];
|
||||
}
|
||||
/* Copying the file name to fname, slashs are also replaced by backslashs */
|
||||
for(i=0;i<len;i++){
|
||||
if(filename[i+1] != '/'){
|
||||
fname[i+7] = filename[i+1];
|
||||
}else{
|
||||
fname[i+7] = '\\';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int mremove(const char *filename) {
|
||||
_fixname(filename);
|
||||
return _Bfile_DeleteEntry(fname);
|
||||
_fixname(filename);
|
||||
return _Bfile_DeleteEntry(fname);
|
||||
}
|
||||
|
||||
int mcreate(const char *filename, int type, int size) {
|
||||
int out;
|
||||
_fixname(filename);
|
||||
out = _Bfile_Create(fname, type, &size);
|
||||
return out;
|
||||
int out;
|
||||
_fixname(filename);
|
||||
out = _Bfile_Create(fname, type, &size);
|
||||
return out;
|
||||
}
|
||||
|
||||
MFile mopen(const char *filename, int mode) {
|
||||
MFile file;
|
||||
_fixname(filename);
|
||||
file.out = _Bfile_Open(fname, mode);
|
||||
_fixname(filename);
|
||||
file.out = _Bfile_Open(fname, mode);
|
||||
if(file.out > 0){
|
||||
file.fd = file.out;
|
||||
file.error = 0;
|
||||
file.fpos = 0;
|
||||
file.fwpos = 0;
|
||||
file.fwpos = 0;
|
||||
}else{
|
||||
file.error = 1;
|
||||
}
|
||||
|
@ -77,23 +77,23 @@ MFile mopen(const char *filename, int mode) {
|
|||
}
|
||||
|
||||
void mwrite(MFile *file, const void *data, int size) {
|
||||
/* Some checks to make the operation more secure. */
|
||||
if(!fugue && size%2){
|
||||
/* Some checks to make the operation more secure. */
|
||||
if(!fugue && size%2){
|
||||
file->error = MODDSIZEWRITE;
|
||||
file->out = 1;
|
||||
return;
|
||||
}
|
||||
msize(file);
|
||||
if(file->fwpos + size > file->out && !file->error){
|
||||
file->out = MTOOBIGSIZE;
|
||||
file->error = 1;
|
||||
return;
|
||||
}
|
||||
/* Calling the Bfile syscall and updating the MFile struct. */
|
||||
file->out = _Bfile_Write(file->fd, data, size);
|
||||
file->fpos += size;
|
||||
file->fwpos += size;
|
||||
if(file->out < 0){
|
||||
return;
|
||||
}
|
||||
msize(file);
|
||||
if(file->fwpos + size > file->out && !file->error){
|
||||
file->out = MTOOBIGSIZE;
|
||||
file->error = 1;
|
||||
return;
|
||||
}
|
||||
/* Calling the Bfile syscall and updating the MFile struct. */
|
||||
file->out = _Bfile_Write(file->fd, data, size);
|
||||
file->fpos += size;
|
||||
file->fwpos += size;
|
||||
if(file->out < 0){
|
||||
file->error = 1;
|
||||
}else{
|
||||
file->error = 0;
|
||||
|
@ -101,17 +101,17 @@ void mwrite(MFile *file, const void *data, int size) {
|
|||
}
|
||||
|
||||
void mread(MFile *file, void *data, int size, int whence) {
|
||||
/* Making an absolute position out of whence. */
|
||||
/* Making an absolute position out of whence. */
|
||||
if(whence == MRCONTINUE) whence = file->fpos;
|
||||
/* A check to make the operation more secure. */
|
||||
msize(file);
|
||||
if(whence + size > file->out && !file->error){
|
||||
file->out = MTOOBIGSIZE;
|
||||
file->error = 1;
|
||||
return;
|
||||
}
|
||||
/* Calling the Bfile syscall and updating the MFile struct. */
|
||||
file->out = _Bfile_Read(file->fd, data, size, whence);
|
||||
/* A check to make the operation more secure. */
|
||||
msize(file);
|
||||
if(whence + size > file->out && !file->error){
|
||||
file->out = MTOOBIGSIZE;
|
||||
file->error = 1;
|
||||
return;
|
||||
}
|
||||
/* Calling the Bfile syscall and updating the MFile struct. */
|
||||
file->out = _Bfile_Read(file->fd, data, size, whence);
|
||||
file->fpos += size;
|
||||
if(file->out < 0){
|
||||
file->error = 1;
|
||||
|
@ -121,8 +121,8 @@ void mread(MFile *file, void *data, int size, int whence) {
|
|||
}
|
||||
|
||||
void mclose(MFile *file) {
|
||||
/* Calling the Bfile syscall and updating the MFile struct. */
|
||||
file->out = _Bfile_Close(file->fd);
|
||||
/* Calling the Bfile syscall and updating the MFile struct. */
|
||||
file->out = _Bfile_Close(file->fd);
|
||||
if(file->out < 0){
|
||||
file->error = 1;
|
||||
}else{
|
||||
|
@ -131,17 +131,17 @@ void mclose(MFile *file) {
|
|||
}
|
||||
|
||||
void mseek(MFile *file, int pos) {
|
||||
/* Setting the new position whitout making checks because more informations
|
||||
are required to make checks, so they are made directly when doing operations
|
||||
on the file.
|
||||
error and out are set to 0 because no error can occur when doing this. */
|
||||
/* Setting the new position whitout making checks because more informations
|
||||
are required to make checks, so they are made directly when doing operations
|
||||
on the file.
|
||||
error and out are set to 0 because no error can occur when doing this. */
|
||||
file->fpos = pos;
|
||||
file->error = 0;
|
||||
file->out = 0;
|
||||
}
|
||||
|
||||
void msize(MFile *file) {
|
||||
/* Calling the Bfile syscall and updating the MFile struct. */
|
||||
/* Calling the Bfile syscall and updating the MFile struct. */
|
||||
file->out = _Bfile_Size(file->fd);
|
||||
if(file->out < 0){
|
||||
file->error = 1;
|
||||
|
|
|
@ -9,7 +9,7 @@ int _LongToAscHex(int value, char *dest, int digits);
|
|||
/* Microfx */
|
||||
|
||||
void itohex(char *buffer, int value, int len) {
|
||||
_LongToAscHex(value, buffer, len);
|
||||
_LongToAscHex(value, buffer, len);
|
||||
}
|
||||
|
||||
/******* CPU *******/
|
||||
|
@ -17,5 +17,5 @@ void itohex(char *buffer, int value, int len) {
|
|||
/* Microfx */
|
||||
|
||||
void csleep(void) {
|
||||
__asm__("sleep");
|
||||
__asm__("sleep");
|
||||
}
|
||||
|
|
|
@ -17,28 +17,28 @@ int fugue;
|
|||
__attribute__((section(".pretext")))
|
||||
|
||||
int start(void) {
|
||||
int i;
|
||||
char *bss_startptr, *data_startptr, *romdataptr;
|
||||
char *os_version = (void *)0x80010020;
|
||||
/* Clearing the bss. */
|
||||
bss_startptr = &start_bss;
|
||||
for(i=0;i<&end_bss - &start_bss;i++){
|
||||
bss_startptr[i] = 0;
|
||||
}
|
||||
/* Load the ROM data into the RAM. */
|
||||
data_startptr = &start_data;
|
||||
romdataptr = &romdata_start;
|
||||
for(i=0;i<&end_data - &start_data;i++){
|
||||
data_startptr[i] = romdataptr[i];
|
||||
}
|
||||
/* Checking if the calculator has a fugue filesystem, because it is
|
||||
important to know that when using Bfile. */
|
||||
if(os_version[1] == '3'){
|
||||
fugue = 1;
|
||||
}else{
|
||||
fugue = 0;
|
||||
}
|
||||
/* Calling main. The return value of main is directly returned because no
|
||||
modifications need to be made. */
|
||||
return main();
|
||||
int i;
|
||||
char *bss_startptr, *data_startptr, *romdataptr;
|
||||
char *os_version = (void *)0x80010020;
|
||||
/* Clearing the bss. */
|
||||
bss_startptr = &start_bss;
|
||||
for(i=0;i<&end_bss - &start_bss;i++){
|
||||
bss_startptr[i] = 0;
|
||||
}
|
||||
/* Load the ROM data into the RAM. */
|
||||
data_startptr = &start_data;
|
||||
romdataptr = &romdata_start;
|
||||
for(i=0;i<&end_data - &start_data;i++){
|
||||
data_startptr[i] = romdataptr[i];
|
||||
}
|
||||
/* Checking if the calculator has a fugue filesystem, because it is
|
||||
important to know that when using Bfile. */
|
||||
if(os_version[1] == '3'){
|
||||
fugue = 1;
|
||||
}else{
|
||||
fugue = 0;
|
||||
}
|
||||
/* Calling main. The return value of main is directly returned because no
|
||||
modifications need to be made. */
|
||||
return main();
|
||||
}
|
||||
|
|
|
@ -64,130 +64,130 @@
|
|||
.global __PopupWin
|
||||
|
||||
#define syscall(syscall_number) \
|
||||
mov.l 1f, r0 ;\
|
||||
mov.l do_syscall, r2 ;\
|
||||
jmp @r2 ;\
|
||||
nop ;\
|
||||
mov.l 1f, r0 ;\
|
||||
mov.l do_syscall, r2 ;\
|
||||
jmp @r2 ;\
|
||||
nop ;\
|
||||
.align 4 ;\
|
||||
1: .long syscall_number
|
||||
1: .long syscall_number
|
||||
|
||||
/* Display */
|
||||
__Bdisp_PutDisp_DD:
|
||||
syscall(0x028)
|
||||
syscall(0x028)
|
||||
__Bdisp_DrawRectangle:
|
||||
syscall(0x0763)
|
||||
syscall(0x0763)
|
||||
__Bdisp_AllClr_VRAM:
|
||||
syscall(0x143)
|
||||
syscall(0x143)
|
||||
__Bdisp_SetPoint_VRAM:
|
||||
syscall(0x146)
|
||||
syscall(0x146)
|
||||
__Bdisp_GetPoint_VRAM:
|
||||
syscall(0x149)
|
||||
syscall(0x149)
|
||||
__PrintXY:
|
||||
syscall(0x150)
|
||||
syscall(0x150)
|
||||
__locate:
|
||||
syscall(0x807)
|
||||
syscall(0x807)
|
||||
__Print:
|
||||
syscall(0x808)
|
||||
syscall(0x808)
|
||||
__Bdisp_DrawLineVRAM:
|
||||
syscall(0x030)
|
||||
syscall(0x030)
|
||||
__Bdisp_ClearLineVRAM:
|
||||
syscall(0x031)
|
||||
syscall(0x031)
|
||||
__PrintMiniSd:
|
||||
syscall(0xC4F)
|
||||
syscall(0xC4F)
|
||||
__DisplayMessageBox:
|
||||
syscall(0x0901)
|
||||
syscall(0x0901)
|
||||
__GetVRAMAddress:
|
||||
syscall(0x135)
|
||||
syscall(0x135)
|
||||
/* Keyboard */
|
||||
__Keyboard_KeyDown:
|
||||
syscall(0x24D)
|
||||
syscall(0x24D)
|
||||
__Keyboard_PRGM_GetKey:
|
||||
syscall(0x6C4)
|
||||
syscall(0x6C4)
|
||||
/* Time */
|
||||
__Sleep:
|
||||
syscall(0x0420)
|
||||
syscall(0x0420)
|
||||
__RTC_GetTicks:
|
||||
syscall(0x03B)
|
||||
syscall(0x03B)
|
||||
__RTC_Elapsed_ms:
|
||||
syscall(0x03C)
|
||||
syscall(0x03C)
|
||||
__RTC_Reset:
|
||||
syscall(0x039)
|
||||
syscall(0x039)
|
||||
__Timer_Install:
|
||||
syscall(0x0118)
|
||||
syscall(0x0118)
|
||||
__Timer_Deinstall:
|
||||
syscall(0x0119)
|
||||
syscall(0x0119)
|
||||
__Timer_Start:
|
||||
syscall(0x011A)
|
||||
syscall(0x011A)
|
||||
__Timer_Stop:
|
||||
syscall(0x011B)
|
||||
syscall(0x011B)
|
||||
/* RTC */
|
||||
__RTC_GetTime:
|
||||
syscall(0x03A)
|
||||
syscall(0x03A)
|
||||
/* Files */
|
||||
__Bfile_DeleteEntry:
|
||||
mov #0, r5
|
||||
syscall(0x0439)
|
||||
mov #0, r5
|
||||
syscall(0x0439)
|
||||
__Bfile_Create:
|
||||
syscall(0x434)
|
||||
syscall(0x434)
|
||||
__Bfile_Write:
|
||||
syscall(0x435)
|
||||
syscall(0x435)
|
||||
__Bfile_Open:
|
||||
mov #0, r6
|
||||
syscall(0x42C)
|
||||
mov #0, r6
|
||||
syscall(0x42C)
|
||||
__Bfile_Read:
|
||||
syscall(0x432)
|
||||
syscall(0x432)
|
||||
__Bfile_Close:
|
||||
syscall(0x042D)
|
||||
syscall(0x042D)
|
||||
__Bfile_Size:
|
||||
syscall(0x042F)
|
||||
syscall(0x042F)
|
||||
/* Tools */
|
||||
_itoa:
|
||||
syscall(0x541)
|
||||
syscall(0x541)
|
||||
_malloc:
|
||||
syscall(0xACD)
|
||||
syscall(0xACD)
|
||||
_calloc:
|
||||
syscall(0xE6B)
|
||||
syscall(0xE6B)
|
||||
_realloc:
|
||||
syscall(0xE6D)
|
||||
syscall(0xE6D)
|
||||
_free:
|
||||
syscall(0xACC)
|
||||
syscall(0xACC)
|
||||
__LongToAscHex:
|
||||
syscall(0x467)
|
||||
syscall(0x467)
|
||||
_memcmp:
|
||||
syscall(0xACE)
|
||||
syscall(0xACE)
|
||||
_memcpy:
|
||||
syscall(0xACF)
|
||||
syscall(0xACF)
|
||||
_memset:
|
||||
syscall(0xAD0)
|
||||
syscall(0xAD0)
|
||||
_strcat:
|
||||
syscall(0xAD4)
|
||||
syscall(0xAD4)
|
||||
_strcmp:
|
||||
syscall(0xAD5)
|
||||
syscall(0xAD5)
|
||||
_strlen:
|
||||
syscall(0xAD6)
|
||||
syscall(0xAD6)
|
||||
_strncat:
|
||||
syscall(0xAD7)
|
||||
syscall(0xAD7)
|
||||
_strncmp:
|
||||
syscall(0xAD8)
|
||||
syscall(0xAD8)
|
||||
_strncpy:
|
||||
syscall(0xAD9)
|
||||
syscall(0xAD9)
|
||||
_strrchr:
|
||||
syscall(0xADA)
|
||||
syscall(0xADA)
|
||||
_strchr:
|
||||
syscall(0xE6E)
|
||||
syscall(0xE6E)
|
||||
_strstr:
|
||||
syscall(0xE6F)
|
||||
syscall(0xE6F)
|
||||
_memmove:
|
||||
syscall(0xE6C)
|
||||
syscall(0xE6C)
|
||||
/* GUI */
|
||||
__InputNumber:
|
||||
syscall(0x0CC4)
|
||||
syscall(0x0CC4)
|
||||
__InputString:
|
||||
syscall(0x0CC5)
|
||||
syscall(0x0CC5)
|
||||
__DisplayFKeyIcon:
|
||||
syscall(0x04D1)
|
||||
syscall(0x04D1)
|
||||
__PopupWin:
|
||||
syscall(0x08FE)
|
||||
syscall(0x08FE)
|
||||
/* Menu */
|
||||
/* Nothing here ... */
|
||||
|
||||
|
|
|
@ -17,33 +17,33 @@ int _Timer_Stop(int InternalTimerID);
|
|||
/* Microfx */
|
||||
|
||||
void tsleep_ms(int ms) {
|
||||
_Sleep(ms);
|
||||
_Sleep(ms);
|
||||
}
|
||||
|
||||
int tgetticks(void) {
|
||||
return _RTC_GetTicks();
|
||||
return _RTC_GetTicks();
|
||||
}
|
||||
|
||||
int tiselapsed(int start, int ms) {
|
||||
return _RTC_Elapsed_ms(start, ms);
|
||||
return _RTC_Elapsed_ms(start, ms);
|
||||
}
|
||||
|
||||
void treset(void) {
|
||||
_RTC_Reset(1);
|
||||
_RTC_Reset(1);
|
||||
}
|
||||
|
||||
int tinittimer(int ms, void (*callback)(void)) {
|
||||
return _Timer_Install(0, callback, ms);
|
||||
return _Timer_Install(0, callback, ms);
|
||||
}
|
||||
|
||||
void tfreetimer(int id) {
|
||||
_Timer_Deinstall(id);
|
||||
_Timer_Deinstall(id);
|
||||
}
|
||||
|
||||
void tstarttimer(int id) {
|
||||
_Timer_Start(id);
|
||||
_Timer_Start(id);
|
||||
}
|
||||
|
||||
void tstoptimer(int id) {
|
||||
_Timer_Stop(id);
|
||||
_Timer_Stop(id);
|
||||
}
|
||||
|
|
|
@ -2,32 +2,32 @@ ENTRY(_start)
|
|||
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x00300200, LENGTH = 512K
|
||||
ram (rw) : ORIGIN = 0x08100200, LENGTH = 20K
|
||||
rom (rx) : ORIGIN = 0x00300200, LENGTH = 512K
|
||||
ram (rw) : ORIGIN = 0x08100200, LENGTH = 20K
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text : {
|
||||
*(.pretext)
|
||||
*(.text)
|
||||
} > rom
|
||||
.rodata : {
|
||||
*(.rodata)
|
||||
*(.rodata.str1.4)
|
||||
_romdata_start = . ;
|
||||
} > rom
|
||||
.bss : {
|
||||
_start_bss = . ;
|
||||
_bssdatasize = . ;
|
||||
LONG(0);
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
_end_bss = . ;
|
||||
} > ram
|
||||
.data : AT(_romdata_start) {
|
||||
_start_data = . ;
|
||||
*(.data)
|
||||
_end_data = . ;
|
||||
} > ram
|
||||
.text : {
|
||||
*(.pretext)
|
||||
*(.text)
|
||||
} > rom
|
||||
.rodata : {
|
||||
*(.rodata)
|
||||
*(.rodata.str1.4)
|
||||
_romdata_start = . ;
|
||||
} > rom
|
||||
.bss : {
|
||||
_start_bss = . ;
|
||||
_bssdatasize = . ;
|
||||
LONG(0);
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
_end_bss = . ;
|
||||
} > ram
|
||||
.data : AT(_romdata_start) {
|
||||
_start_data = . ;
|
||||
*(.data)
|
||||
_end_data = . ;
|
||||
} > ram
|
||||
}
|
||||
|
|
|
@ -273,7 +273,7 @@ input.
|
|||
|
||||
void gstrask(char *buffer, char *message, int maxlen);
|
||||
|
||||
/* void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
|
||||
/* void gfkeyset(int pos, unsigned char *img);
|
||||
|
||||
Draws an fkey from a Sprite Coder string that is in img, at fkey position pos.
|
||||
*/
|
||||
|
|
Binary file not shown.
|
@ -1,16 +1,16 @@
|
|||
#include <microfx/microfx.h>
|
||||
|
||||
int main(void) {
|
||||
while(kisdown());
|
||||
/* Clear the screen */
|
||||
sclear();
|
||||
stext(1, 1, "A Microfx Add-in !", SBLACK);
|
||||
/* Update the screen */
|
||||
supdate();
|
||||
/* Waits that the user presses EXIT. */
|
||||
int key = 0;
|
||||
while(key != KCEXIT){
|
||||
key = kgetkey();
|
||||
}
|
||||
return 1;
|
||||
while(kisdown());
|
||||
/* Clear the screen */
|
||||
sclear();
|
||||
stext(1, 1, "A Microfx Add-in !", SBLACK);
|
||||
/* Update the screen */
|
||||
supdate();
|
||||
/* Waits that the user presses EXIT. */
|
||||
int key = 0;
|
||||
while(key != KCEXIT){
|
||||
key = kgetkey();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
NAME = mapconv
|
||||
|
||||
SRC = src/main.c
|
||||
OBJ = $(SRC:src/%=build/%.o)
|
||||
|
||||
BUILD = build
|
||||
|
||||
all: $(OBJ)
|
||||
$(CC) $(OBJ) -o $(NAME)
|
||||
|
||||
$(OBJ): $(SRC) | $(BUILD)/
|
||||
$(CC) -c $< -o $@ -Os -Iinc -std=c89
|
||||
|
||||
.PRECIOUS: %/
|
||||
|
||||
%/:
|
||||
@ mkdir -p $@
|
||||
|
||||
clean: $(BUILD)
|
||||
rm $(BUILD) --recursive
|
||||
rm $(NAME)
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef HELP_H
|
||||
#define HELP_H
|
||||
|
||||
const char help[] = "mapconv - Microfx map creator\n\n"
|
||||
"This little tool makes it easier to create maps for the Microfx gametools ext."
|
||||
"\n"
|
||||
"Use :\n"
|
||||
" mapconv map.txt conf.txt map.h\n"
|
||||
"map.txt should contain a map made out of ASCII characters. Each line in the\n"
|
||||
"map.txt file should represent one line in the map.\n"
|
||||
"conf.txt should contain the map width, on the next line the height and then,\n"
|
||||
"after, the number of the tile followed by a space and her ASCII character like"
|
||||
"\n"
|
||||
"this :\n"
|
||||
" 1 #\n"
|
||||
"The last argument is the header file that will be generated. You'll just need"
|
||||
"\n"
|
||||
"to modify it to add some informations into the MMap struct before using it in"
|
||||
"\n"
|
||||
"your game.";
|
||||
|
||||
#endif
|
|
@ -0,0 +1,101 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <help.h>
|
||||
|
||||
void grabint(char *data, int size, int *start, char stop, int *out) {
|
||||
int i;
|
||||
*out=0;
|
||||
for(i=0;*start<size-1;i++){
|
||||
if(data[*start] == stop) break;
|
||||
(*out) += data[*start] - 48;
|
||||
if(data[(*start)+1] != stop) (*out) *= 10;
|
||||
(*start)++;
|
||||
}
|
||||
(*start)++;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
FILE *fp;
|
||||
FILE *fp_map;
|
||||
size_t size;
|
||||
char tile[256];
|
||||
int i, n, oldn, a, len;
|
||||
int w, h;
|
||||
if(argc < 4){
|
||||
puts(help);
|
||||
return 1;
|
||||
}
|
||||
char *data = NULL;
|
||||
fp = fopen(argv[2], "rb");
|
||||
if(fp == NULL){
|
||||
printf("[mapconv] Can't open \"%s\"\n", argv[2]);
|
||||
return 2;
|
||||
}
|
||||
fseek(fp, 0L, SEEK_END);
|
||||
size = ftell(fp);
|
||||
rewind(fp);
|
||||
data = malloc(sizeof(unsigned char) * size);
|
||||
if(data == NULL){
|
||||
puts("[mapconv] More memory needed !");
|
||||
return 3;
|
||||
}
|
||||
if(!fread(data, 1, sizeof(unsigned char) * size, fp)){
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
fclose(fp);
|
||||
/* Get the width and the height */
|
||||
n=0;
|
||||
grabint(data, size, &n, '\n', &w);
|
||||
grabint(data, size, &n, '\n', &h);
|
||||
oldn = n;
|
||||
len = 0;
|
||||
for(i=0;i<256 && n<size-1;i++){
|
||||
if(data[n] == '\n') break;
|
||||
grabint(data, size, &n, ' ', (int *)&tile[i]);
|
||||
i++;
|
||||
tile[i] = data[n];
|
||||
n+=2;
|
||||
len++;
|
||||
}
|
||||
free(data);
|
||||
/* Make the map */
|
||||
fp = fopen(argv[1], "rb");
|
||||
if(fp == NULL){
|
||||
printf("[mapconv] Can't open \"%s\"\n", argv[1]);
|
||||
return 2;
|
||||
}
|
||||
fseek(fp, 0L, SEEK_END);
|
||||
size = ftell(fp);
|
||||
rewind(fp);
|
||||
data = malloc(sizeof(unsigned char) * size);
|
||||
if(data == NULL){
|
||||
puts("[mapconv] More memory needed !");
|
||||
return 3;
|
||||
}
|
||||
if(!fread(data, 1, sizeof(unsigned char) * size, fp)){
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
fclose(fp);
|
||||
fp_map = fopen(argv[3], "w");
|
||||
fputs("#ifndef MAP_H\n#define MAP_H\n\n#include \"TILESET.h\"\n"
|
||||
"#include <microfx/ext/gametools.h>\n\n"
|
||||
"const unsigned char _map[] = {", fp_map);
|
||||
for(i=0;i<size;i++){
|
||||
if(data[i] != '\n'){
|
||||
for(a=0;a<len;a++){
|
||||
if(tile[a*2+1] == data[i]) fprintf(fp_map, "%d, ", tile[a*2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
fseek(fp_map, -2L, SEEK_CUR);
|
||||
fputs("};", fp_map);
|
||||
fprintf(fp_map, "\n\nMMap map = {(unsigned char *)_map, (unsigned char **)"
|
||||
"TILESET_HERE, %d, %d, TILEWIDTH_HERE, TILEHEIGHT_HERE, 0, 0};\n\n#endif\n",
|
||||
w, h);
|
||||
fclose(fp_map);
|
||||
free(data);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue