dyn_arr *dyn_arr_init(int array_size) { dyn_arr *arr = (dyn_arr*) malloc(sizeof (dyn_arr)); arr->array = (dyn_arr_node*) malloc_and_clear(sizeof (dyn_arr_node)*(u32) array_size); arr->array_size = array_size; arr->size = 0; return arr; }
void trainerschool_test_init(){ generic_callback1(); *var_access(TRAINERSCHOOL_CORRECT_ANSWERS) = 0; fmem.tst_mem = (trainerschool_test_memory*) malloc_and_clear(sizeof(trainerschool_test_memory)); fmem.tst_mem->current_question = 0; fadescreen_all(1, 0); callback1_set(trainerschool_test_init_components); setflag(MAP_BGN_AUTO_ALIGN_OFF); }
/** * Resizes the array if overhead is too great or the array is too short * @param size * @param heap */ void dyn_arr_resize(int size, dyn_arr *heap) { dyn_arr_node *array_x; if (size > heap->array_size) { array_x = (dyn_arr_node*) malloc_and_clear(sizeof (dyn_arr_node)*(u32) size * 2); memcpy(array_x, heap->array, sizeof (dyn_arr_node)*(u32) heap->array_size); heap->array_size = size * 2; heap->size = size; } else if (size <= heap->array_size / 2) { array_x = (dyn_arr_node*) malloc_and_clear(sizeof (dyn_arr_node)*(u32) heap->array_size / 2); memcpy(array_x, heap->array, sizeof (dyn_arr_node)*(u32) size); heap->array_size /= 2; heap->size = size; } else { heap->size = size; return; } //if we have reached this point we need to change the array references free(heap->array); heap->array = array_x; }
void loadBigSprite2(u32 img, u32 pal, u32 dest, u8 bgid, u8 x) { u8 *ptr; void *data; u8 i; gpu_pal_apply(pal, 0x60, 0x40); LZ77UnCompVram(img, dest); data = malloc_and_clear(0x60); /* Generate tilemap on the fly */ ptr = (u8*) data; for (i = 0; i < 0x60; ++i) { ptr[i] = i; } int (*func)(u8,u8*,u8,u8,u8,u8,u8,u8,u8,u8,u8,u8) = (int (*)(void)) 0x0800226C + 1; /* BGID, tilemap, ?, ?, width, height ,x, y, width, height, ?, offset */ func(bgid, ptr, 0, 0, 8, 0xC, x, 2, 8, 0xC, 0x10, 0x18); gpu_sync_bg_show(bgid); bgid_send_tilemap(bgid); }
/** * Creates new anim task with given priority * @param priority priority of new task. Will be executed after all tasks of * same priority * @param callback the callback function * @param size_var_space size of allocated memory for variables * if 0 is passed no memory will be allocated * @param root root task * @return NULL on failure (not enough consecutive memory or no availible), pointer to task * structure else */ anim_engine_task *anim_engine_task_new(int priority, void (*callback)(anim_engine_task*), size_t size_var_space, anim_engine_task *root){ int id = anim_engine_task_next_id(root); if(id < 0) return NULL; anim_engine_task *next = root->next; while(next && next->priority <= priority){ root = next; next = next->next; } //Insert between root (root->priority <= priority) and next (either NULL or next->priority > priority) //dprintf("New task inserted between prev @%x, next @%x\n", root, next); anim_engine_task *t = malloc_and_clear(sizeof(anim_engine_task) + size_var_space); if(!t) return NULL; t->priority = priority; t->callback = callback; if(size_var_space) t->vars = &t[1]; //Consecutive area after self is var space else t->vars = NULL; t->id = id; t->prev = root; t->next = next; root->next = t; next->prev = t; return t; }
void fadeInProfBg(u8 index) { if (check_a_pressed(0)) return; audio_play(0x124); /* * Tilemap dimensions */ u8 *tilemap; u16 i, j, k; u32 size; void *data; BUP config = { 0 }; /* * Allocated enough space for a full screen tilemap */ tilemap = (u8*) malloc_and_clear(SCREEN_SIZE); gmemset(tilemap, 0xFF, SCREEN_SIZE); /* * Generate the tilemap on the fly */ for (k = PROF_MAP_BASE, i = PROF_Y; i < PROF_Y + PROF_HEIGHT; ++i) { for (j = PROF_X; j < PROF_X + PROF_WIDTH; ++j) tilemap[i * SCREEN_WIDTH + j] = k++; } /* * Unpack the professor graphics */ data = malloc_and_LZ77UnComp((void *) profTiles, &size); config.SrcNum = size; /* * Upscale 4bpp to 8bpp */ config.SrcBitNum = 4; config.DestBitNum = 8; /* * Select palette 4 */ config.DestOffset = 64; /* * Copy professor graphics to the map base of BG2 */ bitUnPack(data, (void *) 0x06000600, &config); gpu_pal_apply((void *) profPal, 0x40, 0x40); free(data); bgid_set_tilemap(2, tilemap); bgid_send_tilemap(2); /* * Slow unfade */ fadescreen(0xFFFFFFFF, 0x10, 0x10, 0x0, 0x0000); gpu_sync_bg_show(1); gpu_sync_bg_show(2); textbox_close(); tasks[index].args[6] = 0xA0; tasks[index].function = (u32) profIntroduce; }
void trainerschool_test_init_components(){ generic_callback1(); if(!fading_is_active()){ //init gfx and stuff big_callback_delete_all(); oam_reset(); oam_palette_allocation_reset(); bg_reset(0); bg_setup(0, trainerschool_test_bg_configs, 3); bg_sync_display_and_show(0); bg_sync_display_and_show(1); bg_sync_display_and_show(2); bg_display_sync(); bg_virtual_map_displace(0, 0, 0); bg_virtual_set_displace(0, 0, 0); bg_virtual_map_displace(1, 0, 0); bg_virtual_set_displace(1, 0, 0); bg_virtual_map_displace(2, 0, 0); bg_virtual_set_displace(2, 0, 0); io_set(0x10, 0); io_set(0x12, 4); io_set(0x14, 0); io_set(0x16, 0); io_set(0x18, 0); io_set(0x1A, 0); void *bg0map = malloc_and_clear(0x800); void *bg1map = malloc_and_clear(0x800); void *bg2map = malloc_and_clear(0x800); bg_set_tilemap(0, bg0map); bg_set_tilemap(1, bg1map); bg_set_tilemap(2, bg2map); lz77uncompwram(gfx_trainerschool_paperMap, bg2map); lz77uncompvram(gfx_trainerschool_paperTiles, (void*) 0x06000000); lz77uncompvram(gfx_trainerschool_page_0Tiles, (void*) 0x06004000); bg_copy_vram(0, bg0map, 0x800, 0, 2); bg_copy_vram(1, bg1map, 0x800, 0, 2); bg_copy_vram(2, bg2map, 0x800, 0, 2); pal_decompress(gfx_trainerschool_paperPal, 0, 32); u8 pal_id = oam_allocate_palette(0xA0E0); pal_decompress(gfx_trainerschool_correctPal, (u16)(256 + pal_id * 16), 32); pal_set_all_to_black(); //we avoid the 1frame show of a pal tbox_sync_with_virtual_bg_and_init_all(trainerschool_test_tboxes); trainerschool_test_load_question(); oam_load_graphic(&trainerschool_test_graphic_correct); oam_load_graphic(&trainerschool_test_graphic_wrong); fadescreen_all(0, 0); callback1_set(trainerschool_test_idle); vblank_handler_set(generic_vblank_handler); bg_virtual_sync(0); bg_virtual_sync(1); bg_virtual_sync(2); } }