This commit is contained in:
mibi88 2023-04-23 17:30:26 +02:00
parent 2ce71fa048
commit 38fd7a546e
37 changed files with 1212 additions and 0 deletions

41
Makefile Normal file
View File

@ -0,0 +1,41 @@
NAME = dictatormanager
ELF = $(NAME).elf
BIN = $(NAME).bin
CC = sh-elf-gcc
SRC = src/main.c \
src/dictatorship.c \
src/draw.c
OBJ = $(SRC:src/%=build/%.o)
ICON = icon.png
LIB = lib
BUILD = build
VERSION = v.1.0
all: $(BIN)
fxgxa --g1a -n $(NAME) -i $(ICON) --version="$(VERSION)" -o $(NAME).g1a build/$(BIN)
sh-elf-objdump -h $(BUILD)/$(ELF)
$(BIN): $(ELF)
sh-elf-objcopy -O binary build/$(ELF) build/$(BIN) -R .bss
$(ELF): $(OBJ) | $(LIB)/
$(CC) $(OBJ) $(LIB)/libMicrofx.a -o $(BUILD)/$@ -nostdlib -T lib/fx98xx.ld -ffreestanding -mb -m3 -Os -Wa,--dsp -lgcc
$(BUILD)/%.o: src/% | $(BUILD)/
$(CC) -c $< -o $@ -Os -Ilib/include/ -std=c89 -Wall -Wextra -Wpedantic
.PRECIOUS: %/
%/:
@ mkdir -p $@
clean: $(BUILD)
rm $(BUILD) --recursive
rm $(NAME).g1a

BIN
assets/fkeys/censorship.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

BIN
assets/fkeys/christians.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

BIN
assets/fkeys/help.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

BIN
assets/fkeys/industry.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

BIN
assets/fkeys/invest.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

BIN
assets/fkeys/jews.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

BIN
assets/fkeys/minus.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 B

BIN
assets/fkeys/plus.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 B

BIN
assets/fkeys/propaganda.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

BIN
assets/fkeys/repression.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 B

BIN
assets/fkeys/stats.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

BIN
assets/title.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

BIN
concept.rnote Normal file

Binary file not shown.

72
gfx/screens.h Normal file
View File

@ -0,0 +1,72 @@
#ifndef SCREENS_H
#define SCREENS_H
static const unsigned char title[]={
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x1, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x3, 0xe0, 0x30, 0x0, 0x1e, 0x0, 0x0, 0xfc, 0x0, 0xf0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x3, 0x70, 0x30, 0x18, 0x7e, 0x0, 0x7, 0xfc, 0x1, 0xf8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x7, 0x38, 0x30, 0x38, 0xfc, 0x6, 0xf, 0x80, 0x79, 0xfc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
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, 0x0,
0x0, 0x1e, 0x7b, 0x39, 0x17, 0xc0, 0x51, 0x87, 0xce, 0x5b, 0x88, 0x12, 0x88, 0x13, 0x42, 0x6e,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0x16, 0x88, 0x13, 0x62, 0xea,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0xcc, 0x33, 0xf2, 0xac,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0x12, 0x2, 0xea,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
};
#endif

BIN
icon.ase Normal file

Binary file not shown.

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

18
inc/basetech.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef BASETECH_H
#define BASETECH_H
#include "../inc/dictatorship.h"
const Technology t_nuclear = {"nuclear", 0};
const Technology t_guns = {"guns", 40};
const Technology t_planes = {"planes", 20};
const Technology t_explosive = {"explosive", 30};
const Technology basetechs[TECHS_AMOUNT] = {
{"nuclear", 0},
{"guns", 40},
{"planes", 20},
{"explosive", 30}
};
#endif

113
inc/dictatorship.h Normal file
View File

@ -0,0 +1,113 @@
#ifndef DICTATORSHIP_H
#define DICTATORSHIP_H
#define REL_AMOUNT 5
#define PROD_AMOUNT 5
#define MAT_AMOUNT 3
#define TECHS_AMOUNT 4
typedef enum {
FALSE = 0,
TRUE
} bool;
/*** Politic ***/
typedef enum {
S_RIGHT,
S_LEFT
} Side;
typedef enum {
R_BFF,
R_FRIEND,
R_VERYGOOD,
R_GOOD,
R_NEUTRAL,
R_BAD,
R_VERYBAD,
R_ENNEMY,
R_WORSTENEMY
} Relation;
/*** Items ***/
typedef enum {
ID_WHEAT,
ID_FLOUR
} Id;
typedef struct {
enum {
T_METAL,
T_COAL,
T_AGRI,
T_WOOD,
T_GLASS,
T_ANIMAL,
T_OIL,
T_TRANSFORMED,
T_PAPER,
T_ELECTRONIC
} type;
char name[15];
int amount_per_day;
int quality;
float price;
int time;
Id id;
Id required[MAT_AMOUNT];
int reqamount;
} Item;
typedef struct {
Id id;
Item item;
} Itemlist;
/*** Production ***/
typedef struct {
bool used;
int quality;
int import;
int export;
Item materials[MAT_AMOUNT];
} Production;
typedef struct {
char item[15];
int percent;
} Technology;
typedef struct {
/* Some informations */
char name[16];
int year;
/* Political party */
Side g_side;
Relation g_relations[REL_AMOUNT];
/* Production */
Production p_agri[PROD_AMOUNT], p_industry[PROD_AMOUNT];
Production p_service[PROD_AMOUNT];
/* Army */
int nuclear;
int motivation;
int soldiers;
Technology technologies[TECHS_AMOUNT];
/* Money */
int inflation;
float money;
/* Population */
int population_amount;
int happyness;
int homeless;
int unemployed;
int happyness_gov;
int propaganda_year_investment
} Dictatorship;
void set_production(Production *production, int quality, int import, int export);
void init_dictatorship(Dictatorship *dictatorship, Side side);
#endif

11
inc/draw.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef DRAW_H
#define DRAW_H
#include "../inc/dictatorship.h"
void warning(void);
void keyvalid(int key);
void new_dictatorship(Dictatorship *dictatorship);
void draw_main(Dictatorship *dictatorship);
#endif

16
inc/materials.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef MATERIALS_H
#define MATERIALS_H
#include "../inc/dictatorship.h"
#define ITEM_AMOUNT 2
const Item wheat = {T_AGRI, "wheat", 30, 40, 0.5, 8, ID_WHEAT, {0}, 0};
const Item flour = {T_AGRI, "flour", 30, 40, 0.8, 8, ID_FLOUR, {ID_WHEAT}, 1};
const Itemlist items[ITEM_AMOUNT] = {
{ID_WHEAT, wheat},
{ID_FLOUR, flour}
};
#endif

33
lib/fx98xx.ld Normal file
View File

@ -0,0 +1,33 @@
ENTRY(_start)
MEMORY
{
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
}

View File

@ -0,0 +1,20 @@
#ifndef MICROFX_IMG_H
#define MICROFX_IMG_H
enum {SNORMAL = 0, SINVERTED, STRANSP, SNOWHITE, SNOBLACK};
/* void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
Draws an image from a Sprite Coder string that is in img,
where the top left corner is at (sx, sy).
w is the width and h the height of the image.
mode can be :
SNORMAL : Draws the image normally.
SINVERTED : Draws the image with inverted colors.
STRANSP : Black is white and white is not drawn. Useful for
transparency in sprites.
*/
void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
#endif

View File

@ -0,0 +1,132 @@
#ifndef MICROFX_STRTOOLS_H
#define MICROFX_STRTOOLS_H
/* Some string.h functions */
/* int memcmp(void const *__s1, void const *__s2, size_t __n);
Compares the __n first bytes of __s1 and __s2.
Returns
- 0 if they are equal
- a number <0 if the first unsigned char that is diffrent is smaller in __s1
than in __s2.
- a number >0 if the first unsigned char that is diffrent is bigger in __s1 than
in __s2.
*/
int memcmp(void const *__s1, void const *__s2, size_t __n);
/* void *memcpy(void *__dest, void const *__src, size_t __n);
Copy __n first bytes from __src to __dest.
Returns __s1.
*/
void *memcpy(void *__dest, void const *__src, size_t __n);
/* void *memset(void *__s, int __c, size_t __n);
Fills __n first bytes of __s with __c (note that __c is converted to an unsigned
char).
__s is returned.
Overlapping is not allowed.
*/
void *memset(void *__s, int __c, size_t __n);
/* char *strcat(char *__dest, char const *__src);
Copies __src to the end of __dest. The \0 at the end of __dest will be
overwritten, and \0 will be appended at the end of the __dest.
Returns __dest.
*/
char *strcat(char *__dest, char const *__src);
/* int strcmp(char const *__s1, char const *__s2);
Compares __s1 and __s2.
Returns
- 0 if they are equal
- a number <0 if the first char that is diffrent is smaller in __s1 than in
__s2.
- a number >0 if the first char that is diffrent is bigger in __s1 than in __s2.
*/
int strcmp(char const *__s1, char const *__s2);
/* size_t strlen(char const *__s);
Returns the size of the null-terminated string __s, whitout counting the \0.
*/
size_t strlen(char const *__s);
/* char *strncat(char *__dest, char const *__src, size_t __n);
Copies the first __n chars of __src to the end of __dest. The \0 at the end of
__dest will be overwritten, and \0 will be appended at the end of the __dest. If
__n is bigger than the size of the string, only the chars up to the \0 will be
copied.
Returns __dest.
*/
char *strncat(char *__dest, char const *__src, size_t __n);
/* int strncmp(char const *__s1, char const *__s2, size_t __n);
Compares the __n first char of __s1 and __s2.
Returns
- 0 if they are equal
- a number <0 if the first char that is diffrent is smaller in __s1 than in
__s2.
- a number >0 if the first char that is diffrent is bigger in __s1 than in __s2.
If __n is bigger than the size of one of the string, only the chars up to the \0
will be copied.
*/
int strncmp(char const *__s1, char const *__s2, size_t __n);
/* char *strncpy(char *__dest, char const *__src, size_t __n);
Copy __n first bytes from __src to __dest. No \0 is appended at the end of
__dest. If __src is smaller than __n, __dest will be filled with \0 until __n is
reached.
Returns __s1.
*/
char *strncpy(char *__dest, char const *__src, size_t __n);
/* char *strrchr(char const *__s, int __c);
Returns a pointer to the last occurence of __c in __s. The \0 at the end of __s
is included.
*/
char *strrchr(char const *__s, int __c);
/* char *strchr(char const *__s, int __c);
Returns a pointer to the first occurence of __c in __s. The \0 at the end of __s
is included.
*/
char *strchr(char const *__s, int __c);
/* char *strstr(char const *__s1, char const *__s2);
Returns a pointer to the first occurence of __s2 in __s1, or NULL if there was
no one. The \0 at the end of the strings is not included.
*/
char *strstr(char const *__s1, char const *__s2);
/* void *memmove(void *__dest, void const *__src, size_t __n);
Copies the __n first bytes of __src to __dest, but __src and __dest can overlap.
__dest is returned.
*/
void *memmove(void *__dest, void const *__src, size_t __n);
#endif

View File

@ -0,0 +1,63 @@
#ifndef MICROFX_KEYCODES_H
#define MICROFX_KEYCODES_H
#define KCF1 79
#define KCF2 69
#define KCF3 59
#define KCF4 49
#define KCF5 39
#define KCF6 29
#define KCSHIFT 78
#define KCOPTN 68
#define KCVARS 58
#define KCMENU 48
#define KCLEFT 38
#define KCUP 28
#define KCALPHA 77
#define KCX2 67
#define KCPOW 57
#define KCEXIT 47
#define KCDOWN 37
#define KCRIGHT 27
#define KCXOT 76
#define KCLOG 66
#define KCLN 56
#define KCSIN 46
#define KCCOS 36
#define KCTAN 26
#define KCFRAC 75
#define KCSD 65
#define KCLPAR 55
#define KCRPAR 45
#define KCCOMMA 35
#define KCARROW 25
#define KC7 74
#define KC8 64
#define KC9 54
#define KCDEL 44
#define KCAC 10
#define KC4 73
#define KC5 63
#define KC6 53
#define KCMULTI 43
#define KCDIV 33
#define KC1 72
#define KC2 62
#define KC3 52
#define KCPLUS 42
#define KCMIN 32
#define KC0 71
#define KCDOT 61
#define KCEXP 51
#define KCNEGA 41
#define KCEXE 31
#endif

View File

@ -0,0 +1,483 @@
#ifndef MICROFX_H
#define MICROFX_H
#include "keycodes.h"
#define size_t unsigned int
#define NULL 0
/******* DISPLAY *******/
#define SWIDTH 128
#define SHEIGHT 64
enum {SWHITE = 0, SBLACK};
/* void sclear(void);
Clears the VRAM in white.
*/
void sclear(void);
/* void supdate(void);
Put the VRAM on the screen.
*/
void supdate(void);
/* void srect(int x1, int y1, int x2, int y2);
Draws a white rectangle with a black border of one pixel from (x1, y1) to
(x2, y2) in the VRAM.
*/
void srect(int x1, int y1, int x2, int y2);
/* void sline(int x1, int y1, int x2, int y2, int color);
Draws a line with a width of one pixel from (x1, y1) to (x2, y2) in the VRAM of
color color.
The available colors are SWHITE or SBLACK.
*/
void sline(int x1, int y1, int x2, int y2, int color);
/* void spixel(int x, int y, int color);
Set the pixel at (x, y) in the color color in the VRAM.
The available colors are SWHITE or SBLACK.
*/
void spixel(int x, int y, int color);
/* void stext(int x, int y, char *text, int color);
Puts the text text at (x, y) on the screen using casio default font with color
color.
*/
void stext(int x, int y, char *text, int color);
/* void slocate(int x, int y, char *text);
Works like the Locate function of CASIO Basic.
*/
void slocate(int x, int y, char *text);
/* void saddlocate(char *text);
Continues the text displayed with slocate, can be used multiple times after a
locate.
*/
void saddlocate(char *text);
/* void sgoto(int x, int y);
Moves the position where you can add text with saddlocate.
*/
void sgoto(int x, int y);
/* void stextmini(int x, int y, char *text);
Works like stext, but here the font is PrintMini and you cannot set the color.
*/
void stextmini(int x, int y, char *text);
/* char* sgetvram(void);
Get the address of the VRAM.
*/
char* sgetvram(void);
/******* KEYBOARD *******/
/* int kisdown(void);
Returns a positive int if a key is down.
Returns 0 if there is no key down.
*/
int kisdown(void);
/* int kcheck(int key);
Checks if the key key is down or not : returns a positive int if the key is
down, or 0 if the key key is not down.
*/
int kcheck(int key);
/* int kgetkey(void);
Works like the Getkey function of CASIO Basic.
Returns the pressed key.
*/
int kgetkey(void);
/******* TOOLS *******/
/* void itoa(int n, char *buffer);
Put a string of the int n in buffer.
*/
void itoa(int n, char *buffer);
/* void *malloc(size_t __size);
returns a pointer of size __size.
*/
void *malloc(size_t __size);
/* void *calloc(size_t __nmemb, size_t __size);
returns a pointer of size __nmemb * __size.
*/
void *calloc(size_t __nmemb, size_t __size);
/* void *realloc(void *__ptr, size_t __size);
returns __ptr but changes the size of this pointer to __size.
*/
void *realloc(void *__ptr, size_t __size);
/* void free(void *__ptr);
Free __ptr.
*/
void free(void *__ptr);
/* void itohex(char *buffer, int value, int len);
Puts the hex representation of value into buffer. The hex number will have the
size len.
*/
void itohex(char *buffer, int value, int len);
/******* TIME *******/
/* void tsleep_ms(int ms);
Wait ms miliseconds.
*/
void tsleep_ms(int ms);
/* void tgetticks(void);
Get 1/128 seconds ticks since midnight.
*/
int tgetticks(void);
/* int tiselapsed(int start, int ms);
Check if ms where elapsed since start (ticks that you can get with tgetticks).
Returns 1 if ms is elapsed and 0 if it is not.
*/
int tiselapsed(int start, int ms);
/* void treset(void);
Resets RTC.
*/
void treset(void);
/* int tinittimer(int ms, void (*callback)(void));
Initializes a timer that call callback each ms miliseconds.
The timers have a precision of 25 ms.
Returns the id of the timer.
*/
int tinittimer(int ms, void (*callback)(void));
/* void tfreetimer(int id);
Free the timer id.
*/
void tfreetimer(int id);
/* void tstarttimer(int id);
Start the timer id.
*/
void tstarttimer(int id);
/* void tstoptimer(int id);
Stop the timer id.
*/
void tstoptimer(int id);
/******* RTC *******/
typedef struct {
int year, month, day; /* The current date (unused) */
int hour, minute, second, millisecond; /* The current time */
} MRtc;
/* void rgettime(MRtc *rtc);
Puts the current hour, minute, second and millisecond in the rtc Mrtc struct.
*/
void rgettime(MRtc *rtc);
/******* CPU *******/
/* void csleep(void);
Uses asm sleep instruction.
Can be used to reduce battery usage of some loops.
*/
void csleep(void);
/******* GUI *******/
enum {GDEC = 0, GHEX};
/* int gnumask(char *message, int maxlen, int type);
Asks for a num that is returned. message contains the message that will be
displayed when asking for the number. maxlen is the maximal length of the input
and type can be GDEC or GHEX. Set type to GDEC if you want to ask for a decimal
number or GHEX if you want that the user inputs a hexadecimal number.
*/
int gnumask(char *message, int maxlen, int type);
/* void gstrask(char *buffer, char *message, int maxlen);
Asks for a str that will be in buffer. message contains the message that will be
displayed when asking for the string and maxlen is the maximal length of the
input.
*/
void gstrask(char *buffer, char *message, int maxlen);
/* void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
Draws an fkey from a Sprite Coder string that is in img, at fkey position pos.
*/
void gfkeyset(int pos, unsigned char *img);
/* void gmessagebox(int height, char *message);
Draws a message box of height height with that contains message.
*/
void gmessagebox(int height, char *message);
/* void gpopup(int hlines);
Draws a popup that has a height of hlines lines.
*/
void gpopup(int hlines);
/******* Memory *******/
/* File structure */
typedef struct {
int fd; /* The file descriptor of the file */
int fpos; /* The position in the file (0 after mopen) */
int fwpos; /* The writing position in the file */
int error; /* Positive if there was an error, NULL if there was no one */
int out; /* There was an error if this value is negative */
} MFile;
/* Errors */
enum {
MTOOBIGSIZE = 2,
MODDSIZEWRITE = 1,
MBF_ENTRYNOTFOUND = -1,
MBF_ILLEGALPARAM = -2,
MBF_ILLEGALPATH = -3,
MBF_DEVICEFULL = -4,
MBF_ILLEGALDEVICE = -5,
MBF_ILLEGALFS = -6,
MBF_ILLEGALSYS = -7,
MBF_ACCESSDENIED = -8,
MBF_ALREADYLOCKED = -9,
MBF_ILLEGALTASKID = -10,
MBF_PERMISSIONERROR = -11,
MBF_ENTRYFULL = -12,
MBF_ALREADYEXISTS = -13,
MBF_READONLYFILE = -14,
MBF_ILLEGALFILTER = -15,
MBF_ENUMEND = -16,
MBF_DEVICECHANGED = -17,
MBF_NOTRECORDFILE = -18,
MBF_ILLEGALSEEKPOS = -19,
MBF_ILLEGALBLOCKFILE = -20,
MBF_NOSUCHDEVICE = -21,
MBF_EOF = -22,
MBF_NOTMOUNTDEVICE = -23,
MBF_NOTUNMOUNTDEVICE = -24,
MBF_CANNOTLOCKSYS = -25,
MBF_RECORDNOTFOUND = -26,
MBF_NOTDUALRECORDFILE = -27,
MBF_NOALARMSUPPORT = -28,
MBF_CANNOTADDALARM = -29,
MBF_FILEFINDUSED = -30,
MBF_DEVICEERROR = -31,
MBF_SYSTEMNOTLOCKED = -32,
MBF_DEVICENOTFOUND = -33,
MBF_FILETYPEMISMATCH = -34,
MBF_NOTEMPTY = -35,
MBF_BROKENSYSTEMDATA = -36,
MBF_MEDIANOTREADY = -37,
MBF_TOOMANYALARMS = -38,
MBF_SAMEALARMEXISTS = -39,
MBF_ACCESSSWAPAREA = -40,
MBF_MULTIMEDIACARD = -41,
MBF_COPYPROTECTION = -42,
MBF_ILLEGALFILEDATA = -43
};
/* File types */
enum {
MFILE = 1,
MFOLDER = 5
};
/* Open modes */
enum {
MREAD = 0x01,
MWRITE = 0x02,
MREADW = (MREAD | MWRITE),
MSHARE = 0x80,
MRWS = (MREADW | MSHARE)
};
/* Defines */
#define MRCONTINUE -1 /* Start reading from the current position. */
#define PATHSIZELIMIT 256 /* Max. path size */
/* Prototypes */
/* IMPORTANT NOTES :
- The CASIOWIN/Fugue compatibility is made automatically.
- To see if there is an error, check if the int error in the MFile struct. If
error is not NULL, there was an error. To get the error code just get the
output of the function.
- To get the output of a function, read the int out in the MFile struct.
- Errors are defined later on.
- DO NOT MODIFY fwpos : MODIFING THIS VARIABLE MAY BREAK THINGS !
*/
/* int mfugue(void);
Returns a postive int if the calculator has a fugue filesystem, or 0 if his fs
is CASIOWIN.
*/
int mfugue(void);
/* int mremove(const char *filename);
Removes the file filename. filename is a const char path for UNIX.
If the returned int is negative there was an error (errors are listed above in
an enum).
*/
int mremove(const char *filename);
/* int mcreate(const char *filename, int type, int size);
Creates the file or folder filename with size size. filename is a const char
path for UNIX.
Set type to MFILE if you want to create a file. Please consider that your add-in
may run on a CASIOWIN calculator, so please enter the real size of your file,
and not 0.
But if you want to create a folder, set type to MFOLDER and then you can also
set the size to 0 and I also recommend that because fxlib does that.
Returns a negative int if there was an error.
*/
int mcreate(const char *filename, int type, int size);
/* MFile mopen(const char *filename, int mode);
Opens the file filename with mode mode.
Available modes are :
- MREAD : Opens the file only for reading.
- MWRITE : Opens the file only for writing.
- MREADW : Opens the file for reading and writing.
- MSHARE : (I don't know what it is XD) Opens the file in shared mode.
- MRWS : Opens the file for reading, writing and in shared mode.
As always the filename is for UNIX and is fixed for the calc.
The error, if there was one, is as I described it in "IMPORTANT NOTES" above,
stored in the MFile struct file.
*/
MFile mopen(const char *filename, int mode);
/* void mwrite(MFile *file, const void *data, int size);
Writes size bytes of data to the file at fwpos of MFile struct file that you can
initialise with mopen.
As always, if there was an error, she's stored in MFile.
*/
void mwrite(MFile *file, const void *data, int size);
/* void mread(MFile *file, void *data, int size, int whence);
Read size bytes of the file of the MFile struct file and put them into data. Set
whence to a positive value to set where mread should start reading, or to
MRCONTINUE to continue reading from the current position.
As always, if there was an error, she's stored in MFile.
*/
void mread(MFile *file, void *data, int size, int whence);
/* void mclose(MFile *file);
Close the file MFile.
*/
void mclose(MFile *file);
/* void mseek(MFile *file, int pos);
Jump to the position pos in the file. if the position is invalid, errors may
occur later on. Pass the MFile struct of the file.
*/
void mseek(MFile *file, int pos);
/* void msize(MFile *file);
Puts the size of the file into out of file. Pass the MFile struct of the file.
*/
void msize(MFile *file);
#endif

BIN
lib/libMicrofx.a Normal file

Binary file not shown.

35
src/dictatorship.c Normal file
View File

@ -0,0 +1,35 @@
#include "../inc/dictatorship.h"
#include "../inc/materials.h"
#include "../inc/basetech.h"
#include <microfx/microfx.h>
#include <microfx/ext/strtools.h>
void set_production(Production *production, int quality, int import, int export) {
production->quality = quality;
production->import = import;
production->export = export;
}
void init_dictatorship(Dictatorship *dictatorship, Side side) {
int i;
dictatorship->year = 1917;
/* Political party */
dictatorship->g_side = side;
for(i=0;i<REL_AMOUNT;i++) dictatorship->g_relations[i] = R_NEUTRAL;
/* Production */
for(i=0;i<PROD_AMOUNT;i++){
dictatorship->p_agri[i].used = FALSE;
dictatorship->p_industry[i].used = FALSE;
dictatorship->p_service[i].used = FALSE;
}
/* Army */
dictatorship->nuclear = 0; /* No nuclear bombs. */
dictatorship->motivation = 75;
dictatorship->soldiers = 100000;
/* Army tech */
memcpy(dictatorship->technologies, basetechs,
TECHS_AMOUNT*sizeof(Technology));
/* Money */
dictatorship->inflation = 20;
dictatorship->money = 2000000000.0;
}

144
src/draw.c Normal file
View File

@ -0,0 +1,144 @@
#include "../inc/draw.h"
#include "../inc/dictatorship.h"
#include <microfx/microfx.h>
#include <microfx/ext/strtools.h>
#define T_WIDTH 21
#define T_HEIGHT 7
const char help[] = "The screen you saw before, is the main screen. By pressing"
"various F keys you can access to other screens.\n- F1 propaganda\n- F2"
"censorship\n- F3 stats\n- F4 industry\n- F5 taxes & militia\n- F6"
"relations & army\nI hope you'll enjoy playing this game!"
"Waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
char buffer[20];
void keyvalid(int key) {
int k = kgetkey();
while(k != key) k = kgetkey();
while(k == key) k = kgetkey();
}
void new_dictatorship(Dictatorship *dictatorship) {
slocate(1, 1, "Welcome to this game.");
slocate(1, 3, "Your goal is to make");
slocate(1, 4, "a dictatorship that");
slocate(1, 5, "is working very well.");
slocate(1, 6, "EXE to continue ...");
supdate();
keyvalid(KCEXE);
gstrask(dictatorship->name, "Enter the name of dict.", 15);
}
void warning(void) {
sclear();
slocate(7, 1, "WARNING");
slocate(1, 3, "THIS GAME SHOULD NOT");
slocate(2, 4, "BE TAKEN SERIOUSLY");
slocate(6, 6, "Press EXE");
supdate();
keyvalid(KCEXE);
}
void dtext(char *text, char *title, int w) {
int i, start = 0, x, y, n, len;
char tmp[2];
bool toobig;
char c;
tmp[1] = '\0';
while(start < (int)strlen(text)){
sclear();
slocate(1, 1, title);
x=1;
y=2;
toobig = FALSE;
for(i=start;i<(int)strlen(text);i++){
c = text[i];
/* Get the lenght of the next word if we need to. */
if(c == ' ' || c == '-' || c == '\n'){
n = i;
len = 0;
toobig = FALSE;
while(text[n] != ' ' && n<(int)strlen(text)){
len++;
n++;
}
/* len--; */
itoa(x, buffer);
slocate(1+(y-2)*3, 1, buffer);
}
/* Copy pasta that on the screen !!! */
if(c == ' ' || c == '-' || c == '\n'){
if(len>w) toobig = TRUE;
if(x+len>w){
y++;
x=0;
}
}
if(c == '\n'){
y++;
x=0;
}
if(toobig && x>=w-1){ /* If the word is bigger than the
screen */
slocate(w, y, "-");
y++;
x=0;
tmp[0] = c;
slocate(x, y, tmp);
}else{
tmp[0] = c;
slocate(x, y, tmp);
}
x++;
/* Check if we need to stop */
if(y>T_HEIGHT-1){
break;
}
}
start = i;
if(start >= (int)strlen(text)) slocate(1, 7, "EXE to quit");
else slocate(1, 7, "EXE to continue");
supdate();
while(!kcheck(KCEXE));
while(kcheck(KCEXE));
}
}
void draw_bar(int sx, int sy, int percents, int w, char *text) {
char buffer[6];
int bw = ((w-4)*100/100*percents)/100;
stextmini(sx, sy, text);
srect(sx, sy+7, sx+w, sy+7+5);
srect(sx+2, sy+7+2, sx+2+bw, sy+7+5-2);
itoa(percents, buffer);
strcat(buffer, "%");
stextmini(sx+w+4, sy+7, buffer);
}
/* Diffrent screens */
void draw_propaganda(Dictatorship *dictatorship) {
while(!kcheck(KCMENU)){
sclear();
draw_bar(1, 1, dictatorship->happyness_gov, 40, "Happyness with your gov.:");
supdate();
}
}
void draw_production(void);
void draw_main(Dictatorship *dictatorship) {
int key;
slocate(1, 1, "==");
slocate(4, 1, dictatorship->name);
slocate(20, 1, "==");
key = kgetkey();
if(key == KCF1){
dtext((char *)help, "======= HELP =======", T_WIDTH);
}
if(key == KCF2){
draw_propaganda(dictatorship);
}
}

31
src/main.c Normal file
View File

@ -0,0 +1,31 @@
#include <microfx/microfx.h>
#include <microfx/ext/img.h>
#include "../gfx/screens.h"
#include "../inc/dictatorship.h"
#include "../inc/draw.h"
Dictatorship dictatorship;
int main(void) {
int key = 0;
while(kisdown());
warning();
sclear();
simage(0, 0, 128, 64, (unsigned char *)&title, SNORMAL);
supdate();
keyvalid(KCEXE);
sclear();
slocate(1, 3, "Initializing ...");
supdate();
init_dictatorship(&dictatorship, S_LEFT);
new_dictatorship(&dictatorship);
key = kgetkey();
while(1){
sclear();
draw_main(&dictatorship);
supdate();
key = kgetkey();
if(key == KCEXIT) break;
}
return 1;
}