void app_halt(){ delete filepathname; if (needcleanup==true){ delete question; delete answerA; delete answerB; delete answerC; delete answerD; } kos_ExitApp(); }
void OnExit() { kos_WriteTextToWindow(WINDOW_WIDTH / 2 - 35, WINDOW_HEIGHT / 2 - 10, 0, TEXT_COLOR, "Game Over", 9); //while(kos_WaitForEvent() != 2); kos_Pause(200); /*kos_DeleteMouseCursor(cur_handle); for (int i = 0; i < R_COUNT; i++) { delete crosses[i]; delete rockets[i]; } for (int i = 0; i < B_COUNT; i++) { delete bombs[i]; } for (int i = 0; i < R_COUNT + B_COUNT; i++) { delete explodes[i]; } delete[] crosses; delete[] rockets; delete[] bombs; delete[] explodes; delete gun; delete house; if (HARDWARE_CURSOR == 0) { delete cursor; }*/ kos_ExitApp(); }
Byte *allocmem( Dword reqsize ) { MemBlock *BlockForCheck; MemBlock *LastKnownGood; Dword tail; Byte *address; //подровняем размер if( ( tail = reqsize % SIZE_ALIGN ) != 0 ) { reqsize += SIZE_ALIGN - tail; } LastKnownGood = NULL; // ждём освобождения мьютекса while ( rtlInterlockedExchange( &mmMutex, TRUE ) ) { // kos_Pause( 1 ); } //ищем подходящий свободный блок if( rootfree != NULL ) { for ( BlockForCheck = rootfree; ; BlockForCheck = BlockForCheck->Next ) { if ( BlockForCheck->Size >= reqsize ) { //нашли if ( LastKnownGood != NULL ) { if ( LastKnownGood->Size >= BlockForCheck->Size ) LastKnownGood = BlockForCheck; } else LastKnownGood = BlockForCheck; if ( LastKnownGood->Size == reqsize ) break; } if ( BlockForCheck->Next == NULL ) break; } } if ( LastKnownGood != NULL ) { //проверим найденный блок на возможность деления tail = LastKnownGood->Size - reqsize; if ( tail >= ( sizeof(MemBlock) + SIZE_ALIGN ) ) { //будем разбивать BlockForCheck = (MemBlock *)( ( (Byte *)LastKnownGood ) + tail ); BlockForCheck->Size = reqsize; //вставим занятый блок в начало списка занатых блоков if( rootuser != NULL ) { BlockForCheck->Next = rootuser; rootuser->Previous = BlockForCheck; BlockForCheck->Previous = NULL; rootuser = BlockForCheck; } else { rootuser = BlockForCheck; BlockForCheck->Next = NULL; BlockForCheck->Previous = NULL; } //изменим размер оставшейся части LastKnownGood->Size = tail - sizeof(MemBlock); address = ( (Byte *)BlockForCheck ) + sizeof(MemBlock); // отпустим мьютекс rtlInterlockedExchange( &mmMutex, FALSE ); return address; } else { //перемести блок из очереди свободных в начало очереди занятых //сначала выкинем его из очереди свободных if ( LastKnownGood->Previous != NULL ) { LastKnownGood->Previous->Next = LastKnownGood->Next; } else { //блок стоит в начале очереди rootfree = LastKnownGood->Next; } if( LastKnownGood->Next != NULL ) { LastKnownGood->Next->Previous = LastKnownGood->Previous; } //теперь вставим его в очередь занятых if( rootuser != NULL ) { LastKnownGood->Next = rootuser; rootuser->Previous = LastKnownGood; LastKnownGood->Previous = NULL; rootuser = LastKnownGood; } else { rootuser = LastKnownGood; LastKnownGood->Next = NULL; LastKnownGood->Previous = NULL; } // address = ( (Byte *)LastKnownGood ) + sizeof(MemBlock); // отпустим мьютекс rtlInterlockedExchange( &mmMutex, FALSE ); return address; } } else { // надо получить ещё блок памяти LastKnownGood = (MemBlock *)kos_malloc( (reqsize > 0x10000 - sizeof(MemBlock)) ? (reqsize + sizeof(MemBlock)) : 0x10000); if (LastKnownGood != NULL) { LastKnownGood->Size = reqsize; // теперь вставим его в очередь занятых LastKnownGood->Next = rootuser; LastKnownGood->Previous = NULL; if (rootuser != NULL) rootuser->Previous = LastKnownGood; rootuser = LastKnownGood; // а также добавим хвост свежевыделенного большого блока в список свободных if (reqsize < 0x10000 - sizeof(MemBlock)) { MemBlock* free = (MemBlock*)((Byte*)LastKnownGood + sizeof(MemBlock) + reqsize); free->Next = rootfree; free->Previous = NULL; if (rootfree != NULL) rootfree->Previous = free; rootfree = free; } address = (Byte*)LastKnownGood + sizeof(MemBlock); // отпустим мьютекс rtlInterlockedExchange(&mmMutex, FALSE); return address; } } // отпустим мьютекс rtlInterlockedExchange( &mmMutex, FALSE ); // rtlDebugOutString( "allocmem failed." ); kos_ExitApp(); // return NULL; }
void process_button() { Dword mouse_btn, ckeys, shift, ctrl; int mouse_x, mouse_y, i, p, dx = 0, dy = 0; int redraw = 0; Dword button; kos_GetButtonID(button); /* sprintf(debuf, "button %U", button); rtlDebugOutString(debuf); //*/ switch (button) { case 1: kos_ExitApp(); case SCROLL_LEFT_BUTTON: //rtlDebugOutString("scroll left btn"); stop_edit(); scroll_x--; if (scroll_x <= 0) scroll_x = 1; sel_moved = 0; /*if (sel_x > nx - 1) { nx - 1; sel_end_x = sel_x; }*/ draw_window(); return; case SCROLL_RIGHT_BUTTON: //rtlDebugOutString("scroll right btn"); stop_edit(); scroll_x++; if (scroll_x >= col_count - 1) scroll_x = col_count - 1; sel_moved = 0;/* if (sel_x < scroll_x) { sel_x = scroll_x; sel_end_x = sel_x; }*/ draw_window(); return; case SCROLL_WIDTH: { //rtlDebugOutString("scroll width btn"); stop_edit(); kos_GetMouseState(mouse_btn, mouse_x, mouse_y); mouse_x -= 5; mouse_y -= kos_GetSkinHeight(); // всего: wi - SCROLL_BAR_WIDTH - 2 * 14 int tmp_w = (nx - scroll_x) * (wi - SCROLL_BAR_WIDTH - 3 * 14) / (col_count + 1); if (tmp_w < 16) tmp_w = 16; scroll_x = (mouse_x - 14 - tmp_w / 2) * (col_count + 1) / (wi - SCROLL_BAR_WIDTH - 3 * 14) + 1; if (scroll_x <= 0) scroll_x = 1; else if (scroll_x >= col_count - 1) scroll_x = col_count - 1; sel_moved = 0; draw_window(); return; } case SCROLL_UP_BUTTON: stop_edit(); scroll_y--; if (scroll_y <= 0) scroll_y = 1; sel_moved = 0; //draw_window(); draw_grid(); /* if (sel_y > ny - 1) { sel_y = ny - 1; sel_end_y = sel_y; }*/ return; case SCROLL_DOWN_BUTTON: stop_edit(); scroll_y++; if (scroll_y >= row_count - 1) scroll_y = row_count - 1; sel_moved = 0;/* if (sel_y < scroll_y) { sel_y = scroll_y; sel_end_y = sel_y; }*/ draw_grid(); return; case SCROLL_HEIGHT: { stop_edit(); kos_GetMouseState(mouse_btn, mouse_x, mouse_y); mouse_x -= 5; mouse_y -= kos_GetSkinHeight(); int tmp_h = (ny - scroll_y) * (he - SCROLL_BAR_HEIGHT - 2 * 14) / row_count; if (tmp_h < 16) tmp_h = 16; scroll_y = (mouse_y - 2 * 14) * (row_count + 1) / (he - SCROLL_BAR_HEIGHT - 3 * 14) + 1; if (scroll_y <= 0) scroll_y = 1; else if (scroll_y >= row_count - 1) scroll_y = row_count - 1; sel_moved = 0; draw_grid(); return; } case NEW_BUTTON: // clear the table reinit(); draw_window(); break; case FILENAME_BUTTON: sel_moved = 1; stop_edit(); fn_edit = 1; strcpy(edit_text, fname); draw_window(); break; case SAVE_BUTTON: stop_edit(); kos_DrawBar(320, panel_y, wi - 320 - 10, 10, 0xe4dfe1); if (SaveFile(fname)) kos_WriteTextToWindow(320, panel_y, 0, 0x000000, (char*)msg_save, strlen(msg_save)); break; case LOAD_BUTTON: stop_edit(); int r = LoadFile(fname); kos_DrawBar(320, panel_y, wi - 320 - 10, 10, 0xe4dfe1); if (r > 0) { calculate_values(); sel_moved = 0; draw_window(); kos_WriteTextToWindow(320, panel_y,0,0x000000,(char*)msg_load, strlen(msg_load)); } else if (r == -1) kos_WriteTextToWindow(320, panel_y,0,0x000000,(char*)er_file_not_found,strlen(er_file_not_found)); else if (r == -2) kos_WriteTextToWindow(320, panel_y,0,0x000000,(char*)er_format,strlen(er_format)); break; } if (button >= COL_HEAD_BUTTON && button < ROW_HEAD_BUTTON) { sel_end_x = sel_x = button - COL_HEAD_BUTTON; sel_y = 1; sel_end_y = row_count - 1; stop_edit(); draw_window(); return; } else if (button >= ROW_HEAD_BUTTON && button < CELL_BUTTON) { sel_end_y = sel_y = button - ROW_HEAD_BUTTON; sel_x = 1; sel_end_x = col_count - 1; stop_edit(); draw_window(); return; } }