Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "include/display.h"
- #include "include/keyboard.hpp"
- #include "include/string.h"
- #include "include/keyboard_syscalls.h"
- #include "include/color.h"
- #include "include/system.h"
- #include "include/stdlib.h"
- #include "include/stdio.h"
- #include "include/rtc.h"
- #include "data1.c"
- #include "types.c"
- #define CLEAN_EXIT 0
- #define ERROR_EXIT -1
- #define MODE_TITLE 1
- #define MODE_ABOUT 2
- #define MODE_NEW_GAME 3
- #define MODE_LOAD_GAME 4
- #define MODE_PRE_RUNNING_GAME 5
- #define MODE_RUNNING_GAME 6
- #define D_VRAM (char*)0xA8000000
- int renderloop(int*mode);
- int titlescreenrenderloop(int*cursor_pos, int*outside_mode);
- int aboutscreenrenderloop(int*outside_mode);
- int newgamerenderloop(int*outside_mode, int*SAVE_HANDLE);
- int loadgamerenderloop(int*outside_mode, int*SAVE_HANDLE);
- city_cell*prerunninggamerenderloop(int*outside_mode, city_cell*map);
- int runninggamerenderloop(int*outside_mode, city_cell*map);
- city_cell*generatemap(int density, int altitude, int climate, int gradualism, int variance);
- void drawtilemap(city_cell*map, int xpos, int ypos);
- city_cell*access_map_element(city_cell*map, int x, int y);
- void CopySprite(const char* data, int x, int y, int width, int height);
- void CopySpriteMasked(const char* data, int x, int y, int width, int height, int maskcolor);
- int GetKeyNB(void);
- void GetKeyWaitNone(void);
- void GetKeyHold(int key);
- void*FillData(void*pointer, unsigned char element, int amount);
- unsigned short random(int extra_seed);
- void drawprintnum(int x, int y, int num);
- void drawprint(int x, int y, char*string);
- void rectangle(int x, int y, int width, int height, unsigned short color);
- void draw_info_box(int x, int y, int width, int height);
- void CopySpriteMasked2(const char* data, int x, int y, int width, int height, int maskcolor);
- static city_data cur_data = {0, 0, 0x00000000};
- static int SAVE_HANDLE = -1;
- int main() {
- int escape_errors = CLEAN_EXIT;
- int cur_screen_mode = 1;
- Bdisp_EnableColor(1);
- Bdisp_AllCr_VRAM();
- CopySprite(OMNIMAGA_LOGO, 40, 12, 306, 46);
- CopySprite(CEMETECH_LOGO, 35, 78, 313, 40);
- CopySprite(DALANIAN_SOFTWARE, 112, 138, 159, 66);
- Bdisp_PutDisp_DD();
- GetKeyHold(KEY_PRGM_F1);
- while(!escape_errors) {
- escape_errors = renderloop(&cur_screen_mode);
- }
- return CLEAN_EXIT;
- }
- int renderloop(int*mode) {
- int error_log = CLEAN_EXIT;
- int cursorx = 0;
- static int SAVE_HANDLE = -1;
- while(!error_log) {
- switch(*(mode)) {
- case MODE_TITLE:
- error_log = titlescreenrenderloop(&cursorx, mode);
- break;
- case MODE_ABOUT:
- error_log = aboutscreenrenderloop(mode);
- break;
- case MODE_NEW_GAME:
- if(cur_data.map) {
- free(cur_data.map);
- }
- error_log = newgamerenderloop(mode, &SAVE_HANDLE);
- break;
- case MODE_LOAD_GAME:
- error_log = loadgamerenderloop(mode, &SAVE_HANDLE);
- break;
- case MODE_PRE_RUNNING_GAME:
- cur_data.map = prerunninggamerenderloop(mode, cur_data.map);
- error_log = (cur_data.map)?(CLEAN_EXIT):(ERROR_EXIT);
- break;
- case MODE_RUNNING_GAME:
- error_log = runninggamerenderloop(mode, cur_data.map);
- break;
- default:
- error_log = ERROR_EXIT;
- break;
- }
- }
- if(SAVE_HANDLE >= 0) {
- Bfile_CloseFile_OS(SAVE_HANDLE);
- SAVE_HANDLE = -1;
- }
- free(cur_data.map);
- return error_log;
- }
- city_cell*prerunninggamerenderloop(int*outside_mode, city_cell*map){
- int choice[5] = {2, 2, 2, 2, 2};
- int done = 0;
- int cur_choice = 0;
- while(!done) {
- GetKeyWaitNone();
- Bdisp_AllCr_VRAM();
- PrintXY(1, 1, " Choose Map Params:", 0x0, TEXT_COLOR_BLUE);
- PrintXY(2, 3, " Density :", 0x0, TEXT_COLOR_BLACK);
- PrintXY(2, 4, " Altitude :", 0x0, TEXT_COLOR_BLACK);
- PrintXY(2, 5, " Climate :", 0x0, TEXT_COLOR_BLACK);
- PrintXY(2, 6, " Gradualism :", 0x0, TEXT_COLOR_BLACK);
- PrintXY(2, 7, " Variance :", 0x0, TEXT_COLOR_BLACK);
- PrintXY(2, 8, " Empty Map", 0x0, TEXT_COLOR_BLACK);
- for(int i = 0; i < 5; i++) {
- switch(choice[i]) {
- case 1:
- PrintXY(15, i+3, " 1", 0x0, TEXT_COLOR_BLACK);
- break;
- case 2:
- PrintXY(15, i+3, " 2", 0x0, TEXT_COLOR_BLACK);
- break;
- case 3:
- PrintXY(15, i+3, " 3", 0x0, TEXT_COLOR_BLACK);
- break;
- }
- }
- PrintXY(1, cur_choice+3, " >", 0x0, TEXT_COLOR_PURPLE);
- Bdisp_PutDisp_DD();
- switch(GetKeyNB()) {
- case KEY_PRGM_UP:
- cur_choice--;
- if(cur_choice < 0) cur_choice = 5;
- break;
- case KEY_PRGM_DOWN:
- cur_choice++;
- if(cur_choice > 5) cur_choice = 0;
- break;
- case KEY_PRGM_F1:
- if(cur_choice == 5) {
- if(map) { free(map); }
- map = FillData(malloc(sizeof(city_cell)*3600), 0x00, sizeof(city_cell)*3600);
- done--; } else {
- done++;
- }
- break;
- case KEY_PRGM_LEFT:
- if(choice[cur_choice] > 1) choice[cur_choice]--;
- break;
- case KEY_PRGM_RIGHT:
- if(choice[cur_choice] < 3) choice[cur_choice]++;
- break;
- }
- }
- if(done != -1) {
- map = generatemap(choice[0], choice[1], choice[2], choice[3], choice[4]);
- }
- if(!map) {
- Bdisp_AllCr_VRAM();
- PrintXY(1, 1, " *BIG* error :(", 0x0, TEXT_COLOR_RED);
- Bdisp_PutDisp_DD();
- OS_InnerWait_ms(2000);
- *(outside_mode) = MODE_TITLE;
- return 0x00000000;
- }
- *(outside_mode) = MODE_RUNNING_GAME;
- return map;
- }
- int runninggamerenderloop(int*outside_mode, city_cell*map){
- int exit_sequence = 0;
- int xpos = 0;
- int ypos = 0;
- int cur_xpos = 0;
- int cur_ypos = 0;
- int HUD_option = 0;
- int HUD_option_2 = 0;
- int HUD_x = 0;
- int HUD_y = 0;
- int HUD_x2 = 0;
- int HUD_y2 = 0;
- int s = 0;
- while(!exit_sequence) {
- switch(GetKeyNB()) {
- case KEY_PRGM_EXIT:
- *(outside_mode) = MODE_TITLE;
- return CLEAN_EXIT;
- break;
- case KEY_PRGM_LEFT:
- cur_xpos -= (cur_xpos>0);
- while(cur_xpos < (xpos+2) && xpos > 0 ) { xpos--; }
- break;
- case KEY_PRGM_RIGHT:
- cur_xpos += (cur_xpos<59);
- while(cur_xpos > (xpos+18) && xpos < 40 ) { xpos++; }
- break;
- case KEY_PRGM_UP:
- cur_ypos -= (cur_ypos>0);
- while(cur_ypos < (ypos+2) && ypos > 0 ) { ypos--; }
- break;
- case KEY_PRGM_DOWN:
- cur_ypos += (cur_ypos<59);
- while(cur_ypos > (ypos+8) && ypos < 50 ) { ypos++; }
- break;
- case KEY_PRGM_F1:
- HUD_option = 1;
- break;
- case KEY_PRGM_F2:
- HUD_option = 2;
- break;
- case KEY_PRGM_F3:
- HUD_option = 3;
- break;
- case KEY_PRGM_F4:
- HUD_option = 4;
- break;
- case KEY_PRGM_F5:
- HUD_option = 5;
- break;
- case KEY_PRGM_F6:
- HUD_option = 6;
- break;
- case KEY_PRGM_1:
- HUD_option_2 = 1;
- break;
- case KEY_PRGM_2:
- HUD_option_2 = 2;
- break;
- case KEY_PRGM_3:
- HUD_option_2 = 3;
- break;
- case KEY_PRGM_4:
- HUD_option_2 = 4;
- break;
- case KEY_PRGM_5:
- HUD_option_2 = 5;
- break;
- case KEY_PRGM_6:
- HUD_option_2 = 6;
- break;
- case KEY_PRGM_7:
- HUD_option_2 = 7;
- break;
- case KEY_PRGM_8:
- HUD_option_2 = 8;
- break;
- }
- HUD_x = (HUD_option-1)*26+163;
- HUD_y = ((HUD_option-1)%2)*14+9;
- HUD_x2 = ((HUD_option_2-1)%2)*26+325;
- HUD_y2 = (HUD_option_2-1)*13+58;
- drawtilemap(map, xpos, ypos);
- CopySpriteMasked(map_cursor, 16*(cur_xpos - xpos), 16*(cur_ypos - ypos)+56-8, 16, 16, 0xFFFF);
- CopySprite(HUD_top, 0, 0, 384, 56);
- CopySprite(HUD_right, 384-64, 56, 64, 216-56);
- drawprintnum(31, 11, cur_data.money);
- drawprintnum(31, 32, cur_data.population);
- if(HUD_option) {
- CopySpriteMasked2(HUD_option_trans, HUD_x, HUD_y, 24, 24, 0xFFFF);
- if(HUD_option_2) {
- CopySpriteMasked2(HUD_option_trans, HUD_x2, HUD_y2, 24, 24, 0xFFFF);
- }
- } else {
- HUD_option_2 = 0;
- }
- switch(HUD_option) {
- case 1:
- CopySpriteMasked(HUD_options_1, 384-64+5, 58, 50, 63, 0xFFFF);
- switch(HUD_option_2) {
- case 1:
- if(GetKeyNB() == KEY_PRGM_SHIFT) {
- access_map_element(map, cur_xpos, cur_ypos)->occupied_type = residential;
- access_map_element(map, cur_xpos, cur_ypos)->occupied = 1;
- }
- break;
- case 2:
- if(GetKeyNB() == KEY_PRGM_SHIFT) {
- access_map_element(map, cur_xpos, cur_ypos)->occupied_type = commercial;
- access_map_element(map, cur_xpos, cur_ypos)->occupied = 1;
- }
- break;
- case 3:
- if(GetKeyNB() == KEY_PRGM_SHIFT) {
- access_map_element(map, cur_xpos, cur_ypos)->occupied_type = industrial;
- access_map_element(map, cur_xpos, cur_ypos)->occupied = 1;
- }
- break;
- case 4:
- if(GetKeyNB() == KEY_PRGM_SHIFT) {
- access_map_element(map, cur_xpos, cur_ypos)->occupied = 0;
- }
- break;
- }
- break;
- case 2:
- CopySpriteMasked(HUD_options_2, 384-64+5, 58, 50, 115, 0xFFFF);
- break;
- case 3:
- CopySpriteMasked(HUD_options_3, 384-64+5, 58, 50, 50, 0xFFFF);
- break;
- case 6:
- draw_info_box(60, 110, 180, 42);
- drawprint(68, 118, "press f1 to save\nor f2 to cancel\0");
- Bdisp_PutDisp_DD();
- while(!s) {
- switch(GetKeyNB()) {
- case KEY_PRGM_F1:
- realloc(map, sizeof(city_cell)*3600+5000);
- memcpy(sizeof(city_cell)*3600+map, &(cur_data.money), sizeof(int));
- memcpy(sizeof(city_cell)*3600+sizeof(int)+map, &(cur_data.population), sizeof(int));
- Bfile_WriteFile_OS(SAVE_HANDLE, (const char*) map, sizeof(city_cell)*3600+5000);
- s++;
- draw_info_box(60, 152, 120, 28);
- if(SAVE_HANDLE > 0) {
- drawprint(68, 160, "data saved\0");
- } else {
- drawprint(68, 160, "save error\0");
- }
- Bdisp_PutDisp_DD();
- GetKeyHold(KEY_PRGM_F1);
- break;
- case KEY_PRGM_F2:
- s++;
- break;
- }
- }
- s = 0;
- HUD_option = 0;
- break;
- }
- if(HUD_option_2) {
- switch(HUD_option) {
- case 1:
- if(HUD_option_2 > 4) { HUD_option_2 = 0; }
- break;
- case 3:
- if(HUD_option_2 > 3) { HUD_option_2 = 0; }
- break;
- }
- }
- if(HUD_option) {
- CopySpriteMasked2(HUD_option_trans, HUD_x, HUD_y, 24, 24, 0xFFFF);
- if(HUD_option_2) {
- CopySpriteMasked2(HUD_option_trans, HUD_x2, HUD_y2, 24, 24, 0xFFFF);
- }
- } else {
- HUD_option_2 = 0;
- }
- Bdisp_PutDisp_DD();
- }
- return CLEAN_EXIT;
- }
- void drawtilemap(city_cell*map, int xpos, int ypos) {
- city_cell*cur_element = 0x00000000;
- const char*tile = 0x00000000;
- for(int j = 0; j < 10 ; j++) {
- for(int i = 0; i < 20; i++) {
- cur_element = access_map_element(map, xpos+i, ypos+j);
- if(cur_element->occupied) {
- switch(cur_element->occupied_type) {
- case utility:
- break;
- case residential:
- case commercial:
- case industrial:
- tile = ((cur_element->occupied_type-1)*512)+zoning_tiles;
- break;
- case school:
- break;
- case police:
- break;
- case firestation:
- break;
- case hospital:
- break;
- case road:
- break;
- case political:
- break;
- case park:
- break;
- case landmark:
- break;
- case ruins:
- break;
- }
- } else {
- switch(cur_element->natural_cell){
- case grass:
- tile = grass_tile;
- break;
- case water:
- tile = water_tile;
- break;
- case dirt:
- tile = dirt_tile;
- break;
- case sand:
- tile = sand_tile;
- break;
- case tree:
- tile = tree_tile;
- break;
- case mountain:
- tile = mountain_tile;
- break;
- }
- }
- CopySprite(tile, i*16, j*16+56, 16, 16);
- tile = 0x00000000;
- }
- }
- }
- city_cell*generatemap(int density, int altitude, int climate, int gradualism, int variance){
- city_cell*cur_cell = 0x00000000;
- int surroundings[25];
- Bdisp_AllCr_VRAM();
- int loop_index = 0;
- int cell_in_q = 0;
- int types[6];
- int cur_max_type = 0;
- PrintXY(1, 1, " Generating Map.", 0x0, TEXT_COLOR_BLUE);
- PrintXY(1, 2, " Please Wait...", 0x0, TEXT_COLOR_BLUE);
- Bdisp_PutDisp_DD();
- city_cell*map = FillData(malloc(sizeof(city_cell)*3600), 0x00, sizeof(city_cell)*3600);
- if(!map) return 0x00000000;
- PrintXY(2, 5, " Debouncing Buildings", 0x0, random(0)%7);
- Bdisp_PutDisp_DD();
- for(int j = 0; j < 60; j++) {
- for(int i = 0; i < 60; i++) {
- if(!i) { switch(j) {
- case 9:
- PrintXY(2, 5, " ", 0x0, TEXT_COLOR_WHITE);
- PrintXY(2, 5, " Parsing Mountains", 0x0, random(0)%7);
- Bdisp_PutDisp_DD();
- break;
- case 17:
- PrintXY(2, 5, " ", 0x0, TEXT_COLOR_WHITE);
- PrintXY(2, 5, " Cleaning Water", 0x0, random(0)%7);
- Bdisp_PutDisp_DD();
- break;
- case 26:
- PrintXY(2, 5, " ", 0x0, TEXT_COLOR_WHITE);
- PrintXY(2, 5, " Seeding Trees", 0x0, random(0)%7);
- Bdisp_PutDisp_DD();
- break;
- case 34:
- PrintXY(2, 5, " ", 0x0, TEXT_COLOR_WHITE);
- PrintXY(2, 5, " Adding Gatorade", 0x0, random(0)%7);
- Bdisp_PutDisp_DD();
- break;
- case 45:
- PrintXY(2, 5, " ", 0x0, TEXT_COLOR_WHITE);
- PrintXY(2, 5, " Tapping Supplies", 0x0, random(0)%7);
- Bdisp_PutDisp_DD();
- break;
- case 55:
- PrintXY(2, 5, " ", 0x0, TEXT_COLOR_WHITE);
- PrintXY(2, 5, " Printing Currency", 0x0, random(0)%7);
- Bdisp_PutDisp_DD();
- break;
- } }
- for(int k = -1; k <= 1; k++) {
- for(int l = -1; l <= 1; l++) {
- if(j + k <= 0 || j + k >= 59 || i + l <= 0 || i + l >= 59) {
- surroundings[loop_index++] = -1;
- continue;
- }
- surroundings[loop_index++] = access_map_element(map, i+l, j+k)->natural_cell;
- }
- }
- loop_index = 0;
- cur_cell = access_map_element(map, i, j);
- if(!i && !j){
- switch(altitude) {
- case 1:
- cur_cell->natural_cell = water;
- break;
- case 2:
- cur_cell->natural_cell = grass;
- break;
- case 3:
- cur_cell->natural_cell = dirt;
- break;
- }
- continue;
- }
- if(!(random(0)%(density+1))) {
- for(int i = 0; i < 4; i++) {
- if(surroundings[i]<0) {
- types[(altitude==1)?(1):((altitude==2)?(0):(2))]++;
- continue;
- }
- types[surroundings[i]]++;
- }
- if(altitude == 1) {
- cur_cell->natural_cell = water;
- continue;
- }
- for(int i = 1; i < 6; i++) {
- cur_max_type = (types[cur_max_type]>types[i])?(cur_max_type):(i);
- }
- cell_in_q = cur_max_type;
- cur_max_type = 0;
- switch(cell_in_q) {
- case grass:
- if(random(RTC_GetTicks())%(2*climate)) {
- cur_cell->natural_cell = tree; } else {
- cur_cell->natural_cell = grass;
- }
- break;
- case water:
- cur_cell->natural_cell = water;
- break;
- case dirt:
- if(random(RTC_GetTicks())%3){
- cur_cell->natural_cell = dirt;
- } else {
- cur_cell->natural_cell = mountain;
- }
- break;
- case sand:
- cur_cell->natural_cell = water;
- break;
- case tree:
- if(random(RTC_GetTicks())%(2*(climate*climate))) {
- cur_cell->natural_cell = tree; } else {
- cur_cell->natural_cell = grass;
- }
- break;
- case mountain:
- if(random(RTC_GetTicks())%(altitude+2)) {
- cur_cell->natural_cell = dirt; } else {
- cur_cell->natural_cell = mountain;
- }
- break;
- }
- } else {
- if(!(random(RTC_GetTicks())%(2*gradualism))) {
- switch(altitude) {
- case 1:
- cur_cell->natural_cell = water;
- break;
- case 2:
- cur_cell->natural_cell = (random(RTC_GetTicks())%(2*climate))?(tree):(grass);
- break;
- case 3:
- cur_cell->natural_cell = (random(RTC_GetTicks())%2)?(dirt):(mountain);
- break;
- }
- } else {
- switch(altitude) {
- case 1:
- cur_cell->natural_cell = water;
- break;
- case 2:
- cur_cell->natural_cell = grass;
- break;
- case 3:
- cur_cell->natural_cell = dirt;
- break;
- }
- }
- cell_in_q = 0;
- }
- OS_InnerWait_ms(random(RTC_GetTicks())%64);
- }
- }
- int width, height, x, y, selection;
- for(int k = 0; k < (variance+(density-2)); k++) {
- switch(altitude) {
- case 1:
- width = 16 + (random(RTC_GetTicks())%16);
- OS_InnerWait_ms(((random(0)+1)*(random(0)+1)*(random(0)+1)*(random(0)+1)*64)%1024);
- height = 16 + (random(RTC_GetTicks())%16);
- OS_InnerWait_ms(((random(0)+1)*(random(0)+1)*(random(0)+1)*(random(0)+1)*64)%1024);
- x = random(RTC_GetTicks()) % (60-width);
- OS_InnerWait_ms(((random(0)+1)*(random(0)+1)*(random(0)+1)*(random(0)+1)*64)%1024);
- y = random(RTC_GetTicks()) % (60-height);
- selection = random(RTC_GetTicks())%4;
- for(int j = y; j < y+height; j++) {
- for(int i = x; i < x+width; i++) {
- if(island_seed[selection][((j-y)*16)/height][((i-x)*16)/width] != 1) {
- access_map_element(map, i, j)->natural_cell = island_seed[selection][((j-y)*16)/height][((i-x)*16)/width];
- }
- }
- }
- break;
- case 2:
- case 3:
- width = 16 + (random(RTC_GetTicks())%16);
- OS_InnerWait_ms(((random(0)+1)*(random(0)+1)*(random(0)+1)*(random(0)+1)*64)%1024);
- height = 16 + (random(RTC_GetTicks())%16);
- OS_InnerWait_ms(((random(0)+1)*(random(0)+1)*(random(0)+1)*(random(0)+1)*64)%1024);
- x = random(RTC_GetTicks()) % (60-width);
- OS_InnerWait_ms(((random(0)+1)*(random(0)+1)*(random(0)+1)*(random(0)+1)*64)%1024);
- y = random(RTC_GetTicks()) % (60-height);
- selection = random(RTC_GetTicks())%2;
- for(int j = y; j < y+height; j++) {
- for(int i = x; i < x+width; i++) {
- if(lake_seed[selection][((j-y)*16)/height][((i-x)*16)/width] != 4) {
- access_map_element(map, i, j)->natural_cell = lake_seed[selection][((j-y)*16)/height][((i-x)*16)/width];
- }
- }
- }
- break;
- }
- }
- Bdisp_AllCr_VRAM();
- return map;
- }
- city_cell*access_map_element(city_cell*map, int x, int y) {
- return (y*60+x+map);
- }
- int titlescreenrenderloop(int*cursor_pos, int*outside_mode) {
- *(cursor_pos) %= 3;
- switch(GetKeyNB()) {
- case KEY_PRGM_UP:
- --(*(cursor_pos));
- *(cursor_pos)=(*(cursor_pos) < 0)?(2):(*(cursor_pos));
- break;
- case KEY_PRGM_DOWN:
- ++(*(cursor_pos));
- *(cursor_pos)=(*(cursor_pos) > 2)?(0):(*(cursor_pos));
- break;
- case KEY_PRGM_F1:
- *(outside_mode) = ((*(cursor_pos)==2)?(MODE_ABOUT):((*(cursor_pos)==1)?(MODE_LOAD_GAME):(MODE_NEW_GAME)));
- break;
- }
- GetKeyWaitNone();
- memcpy(D_VRAM, TitleScreen, LCD_HEIGHT_PX * LCD_WIDTH_PX * 2);
- CopySpriteMasked(cursor01, 250, 25*(*(cursor_pos))+105, 24, 24, 0xFFFF);
- Bdisp_PutDisp_DD();
- return CLEAN_EXIT;
- }
- int aboutscreenrenderloop(int*outside_mode) {
- while(GetKeyNB() != KEY_PRGM_NONE) { }
- memcpy(D_VRAM, AboutScreen, LCD_HEIGHT_PX * LCD_WIDTH_PX * 2);
- Bdisp_PutDisp_DD();
- GetKeyHold(KEY_PRGM_F1);
- *(outside_mode) = MODE_TITLE;
- return CLEAN_EXIT;
- }
- int newgamerenderloop(int*outside_mode, int*SAVE_HANDLE) {
- int decision = 0;
- int size_needed = (sizeof(city_cell)*3600)+5000;
- unsigned short*file_name = malloc(64);
- Bdisp_AllCr_VRAM();
- PrintXY(2, 2, " Start New Game?", 0x0, TEXT_COLOR_BLACK);
- Bdisp_PutDisp_DD();
- OS_InnerWait_ms(1000);
- PrintXY(5, 4, " F1 -- YES", 0x0, TEXT_COLOR_GREEN);
- PrintXY(5, 5, " F2 -- NO", 0x0, TEXT_COLOR_RED);
- Bdisp_PutDisp_DD();
- while(!decision) {
- switch(GetKeyNB()) {
- case KEY_PRGM_F1:
- *(outside_mode) = MODE_PRE_RUNNING_GAME;
- GetKeyWaitNone();
- decision++;
- Bfile_StrToName_ncpy(file_name, (const unsigned char*) "\\\\fls0\\city.pcc\0", 64);
- *(SAVE_HANDLE) = Bfile_OpenFile_OS(file_name, 0x03);
- if(*(SAVE_HANDLE) < 0) {
- Bdisp_AllCr_VRAM();
- PrintXY(2, 2, " No previous file!", 0x0, TEXT_COLOR_BLACK);
- PrintXY(2, 3, " Making new file", 0x0, TEXT_COLOR_BLACK);
- OS_InnerWait_ms(1000);
- Bdisp_PutDisp_DD();
- PrintXY(3, 4, " Please wait...", 0x0, TEXT_COLOR_GREEN);
- Bdisp_PutDisp_DD();
- OS_InnerWait_ms(500);
- Bfile_CreateEntry_OS(file_name, 1, &size_needed);
- *(SAVE_HANDLE) = Bfile_OpenFile_OS(file_name, 0x03);
- if(*(SAVE_HANDLE) < 0) {
- Bdisp_AllCr_VRAM();
- PrintXY(1, 2, " FATAL CREATION ERROR", 0x0, TEXT_COLOR_RED);
- PrintXY(2, 4, " Successful Troll", 0x0, TEXT_COLOR_CYAN);
- PrintXY(2, 5, " Is Successful :(", 0x0, TEXT_COLOR_CYAN);
- Bdisp_PutDisp_DD();
- GetKeyHold(KEY_PRGM_F1);
- *(outside_mode) = MODE_TITLE;
- free(file_name);
- return CLEAN_EXIT;
- }
- cur_data.money = 50000;
- cur_data.population = 0;
- // TODO: setup/load stuff
- }
- break;
- case KEY_PRGM_F2:
- *(outside_mode) = MODE_TITLE;
- GetKeyWaitNone();
- decision--;
- break;
- }
- }
- if(*(SAVE_HANDLE) >= 0) {
- Bfile_CloseFile_OS(*(SAVE_HANDLE));
- *(SAVE_HANDLE) = -1;
- }
- free(file_name);
- return CLEAN_EXIT;
- }
- int loadgamerenderloop(int*outside_mode, int*SAVE_HANDLE) {
- Bdisp_AllCr_VRAM();
- unsigned short*file_name = malloc(64);
- Bfile_StrToName_ncpy(file_name, (const unsigned char*) "\\\\fls0\\city.pcc\0", 64);
- PrintXY(1, 2, " Attempt to get file", 0x0, TEXT_COLOR_BLACK);
- PrintXY(1, 3, " from \'city.pcc\' ", 0x0, TEXT_COLOR_BLACK);
- Bdisp_PutDisp_DD();
- for(int i = 17; i <= 19; i++) {
- OS_InnerWait_ms(500);
- PrintXY(i, 3, " .", 0x0, TEXT_COLOR_BLACK);
- Bdisp_PutDisp_DD();
- }
- OS_InnerWait_ms(500);
- *(SAVE_HANDLE) = Bfile_OpenFile_OS(file_name, 0x03);
- if(*(SAVE_HANDLE) < 0) {
- PrintXY(2, 5, " ERROR: NONE EXISTS!", 0x0, TEXT_COLOR_RED);
- Bdisp_PutDisp_DD();
- GetKeyHold(KEY_PRGM_F1);
- *(outside_mode) = MODE_TITLE;
- } else {
- PrintXY(2, 5, " LOAD SUCCESSFUL.", 0x0, TEXT_COLOR_GREEN);
- Bdisp_PutDisp_DD();
- GetKeyHold(KEY_PRGM_F1);
- *(outside_mode) = MODE_TITLE;
- // TODO: load stuff
- }
- if(*(SAVE_HANDLE) >= 0) {
- Bfile_CloseFile_OS(*(SAVE_HANDLE));
- *(SAVE_HANDLE) = -1;
- }
- free(file_name);
- return CLEAN_EXIT;
- }
- void*FillData(void*pointer, unsigned char element, int amount){
- void*pointer_ref = pointer;
- for(int i = amount; i > 0; i--) {
- *((unsigned char*) pointer++) = element;
- }
- return pointer_ref;
- }
- int PRGM_GetKey(){
- unsigned char buffer[12];
- PRGM_GetKey_OS( buffer );
- return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
- }
- int GetKeyNB() {
- int key;
- key = PRGM_GetKey();
- if (key == KEY_PRGM_MENU) {
- GetKey(&key);
- Bdisp_EnableColor(1);
- Bdisp_PutDisp_DD();
- }
- return key;
- }
- void GetKeyHold(int key) {
- while(GetKeyNB() != key) { }
- while(GetKeyNB() != KEY_PRGM_NONE) { }
- }
- void GetKeyWaitNone() {
- while(GetKeyNB() != KEY_PRGM_NONE) { }
- }
- void CopySprite(const char* data, int x, int y, int width, int height) {
- char* VRAM = (char*)0xA8000000;
- VRAM += 2*(LCD_WIDTH_PX*y + x);
- for(int j=y; j<y+height; j++) {
- memcpy(VRAM,data,2*width);
- VRAM += 2*LCD_WIDTH_PX;
- data += 2*width;
- }
- }
- void CopySpriteMasked(const char* data, int x, int y, int width, int height, int maskcolor) {
- char* VRAM = (char*)0xA8000000;
- VRAM += 2*(LCD_WIDTH_PX*y + x);
- for(int j=y; j<y+height; j++) {
- for(int i=x; i<x+width; i++) {
- if ((((((int)(*data))&0x000000FF)<<8) | ((((int)(*(data+1))))&0x000000FF)) != maskcolor) {
- *(VRAM++) = *(data++);
- *(VRAM++) = *(data++);
- } else { VRAM += 2; data += 2; }
- }
- VRAM += 2*(LCD_WIDTH_PX-width);
- }
- }
- void CopySpriteMasked2(const char* data, int x, int y, int width, int height, int maskcolor) {
- char* VRAM = (char*)0xA8000000;
- VRAM += 2*(LCD_WIDTH_PX*y + x);
- for(int j=y; j<y+height; j++) {
- for(int i=x; i<x+width; i++) {
- if ((((((int)(*data))&0x000000FF)<<8) | ((((int)(*(data+1))))&0x000000FF)) != maskcolor) {
- *(VRAM) = (((int)(*(data++) + (*(VRAM))))/2);
- VRAM++;
- *(VRAM) = (((int)(*(data++) + (*(VRAM))))/2);
- VRAM++;
- } else { VRAM += 2; data += 2; }
- }
- VRAM += 2*(LCD_WIDTH_PX-width);
- }
- }
- unsigned short random(int extra_seed) {
- int seed = 0;
- int seed2 = 0;
- for(int i = 0; i < 32; i++ ){
- seed <<= 1;
- seed |= (RTC_GetTicks()%2);
- }
- for(int i = 0; i < 32; i++ ){
- seed2 <<= 1;
- seed2 |= (RTC_GetTicks()%16);
- }
- seed ^= seed2;
- seed = (( 0x41C64E6D*seed ) + 0x3039);
- seed2 = (( 0x1045924A*seed2 ) + 0x5023);
- extra_seed = (extra_seed)?(( 0xF201B35C*extra_seed ) + 0xD018):(extra_seed);
- seed ^= seed2;
- if(extra_seed){ seed ^= extra_seed; }
- return ((seed >> 16) ^ seed) >> 16;
- }
- void drawprintnum(int x, int y, int num) {
- int digits[10] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
- int pos_num = (num<0)?(-num):(num);
- int num_digits = 0;
- for(int i = 0; i < 10; i++) {
- if(!pos_num) { break; }
- digits[i] = pos_num%10;
- pos_num = (pos_num - (pos_num%10)) / 10;
- num_digits++;
- }
- if(num<0) {
- CopySpriteMasked(glyph_nums + 2400, x, y, 10, 12, 0xFFFF);
- x += 12;
- } else if (num == 0) {
- CopySpriteMasked(glyph_nums, x, y, 10, 12, 0xFFFF);
- return;
- }
- for(int i = 0; i < num_digits; i++) {
- CopySpriteMasked((digits[i]*240)+glyph_nums, x, y, 10, 12, 0xFFFF);
- x += 12;
- }
- }
- void drawprint(int x, int y, char*string) {
- int i = 0;
- int len = 0;
- int s = 0;
- int xs = x;
- while(1) {
- if(*(string+(i++))) {
- len++;
- } else {
- break;
- }
- }
- for(int j = 0; j < len; j++) {
- switch(*(string+j)) {
- case 0:
- return;
- break;
- case ' ':
- x += 10;
- s++;
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- s++;
- drawprintnum(x, y, *(string+j)-'0');
- x += 10;
- break;
- case '\n':
- s++;
- y += 16;
- x = xs;
- break;
- }
- if(s) {
- s = 0;
- continue;
- }
- CopySpriteMasked((*(string+j) - 'a')*192+glyph_chars, x, y, 8, 12, 0xFFFF);
- x += 10;
- }
- }
- void rectangle(int x, int y, int width, int height, unsigned short color) {
- unsigned short*VRAM = (unsigned short*)0xA8000000;
- for(int j = y; j < y+height; j++) {
- for(int i = x; i < x+width; i++) {
- *(j*LCD_WIDTH_PX+i+VRAM) = color;
- }
- }
- }
- void draw_info_box(int x, int y, int width, int height) {
- rectangle(x, y, width, height, 0xFD10);
- rectangle(x+2, y+2, width-4, height-4, 0xFF85);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement