Project

General

Profile

Revision 114

[ignore]

View differences:

lab5.c
172 172

  
173 173
    if (vbe_get_mode_information(mode)) {
174 174
        printf("%s: failed to get information for mode %x.\n", __func__, mode);
175
        if (vg_exit())
176
            printf("%s: vg_exit failed to exit to text mode.\n", __func__);
175
        if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__);
177 176
        return 1;
178 177
    }
179 178

  
......
276 275
}
277 276

  
278 277
int(video_test_move)(xpm_map_t xpm, uint16_t xi, uint16_t yi, uint16_t xf, uint16_t yf, int16_t speed, uint8_t fr_rate) {
279
    /* To be completed */
280
    printf("%s(%8p, %u, %u, %u, %u, %d, %u): under construction\n",
281
    __func__, xpm, xi, yi, xf, yf, speed, fr_rate);
278
    int r;
279
    if ((r = get_permissions_first_mbyte()))
280
        panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
282 281

  
283
    return 1;
282
    if (vbe_get_mode_information(mode)) {
283
        printf("%s: failed to get information for mode %x.\n", __func__, mode);
284
        if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__);
285
        return 1;
286
    }
287

  
288
    map_vram(); // if function fails it aborts program
289

  
290
    if (set_graphics_mode(mode)) {
291
        printf("%s: failed to set graphic mode %x.\n", __func__, mode);
292
        if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__);
293
        return 1;
294
    }
295

  
296
    uint16_t W = get_XRes()/no_rectangles;
297
    uint16_t H = get_YRes()/no_rectangles;
298
    uint32_t color, R, G, B;
299
    for(uint8_t row = 0; row < no_rectangles; ++row){
300
        for(uint8_t col = 0; col < no_rectangles; ++col){
301
            if(get_bytes_pixel() == 1){
302
                color = (first + (row * no_rectangles + col) * step) % (1 << get_bits_pixel());
303
            }else{
304
                R = (GET_RED(first) + col*step) % (1 << get_RedMaskSize());
305
                G = (GET_GRE(first) + row*step) % (1 << get_GreenMaskSize());
306
                B = (GET_BLU(first) + (col+row)*step) % (1 << get_BlueMaskSize());
307
                color = SET_COLOR(R,G,B);
308
            }
309
            if (vg_draw_rectangle(col*W,row*H,W,H,color)) {
310
                if (vg_exit()) {
311
                    printf("%s: vg_exit failed to exit to text mode.\n", __func__);
312
                    if (free_memory()) printf("%s: lm_free failed\n", __func__);
313
                }
314
                return 1;
315
            }
316
        }
317
    }
318

  
319
    /// loop stuff
320
    int ipc_status;
321
    message msg;
322
    /// Keyboard interrupt handling
323
    uint8_t kbc_irq_bit = KBC_IRQ;
324
    int kbc_id = 0;
325
    int kbc_irq = BIT(kbc_irq_bit);
326
    if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) {
327
        if (vg_exit()) {
328
            printf("%s: vg_exit failed to exit to text mode.\n", __func__);
329
            if (free_memory()) printf("%s: lm_free failed\n", __func__);
330
        }
331
        return 1;
332
    }
333
    /// cycle
334
    int good = 1;
335
    while (good) {
336
        /* Get a request message. */
337
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
338
            printf("driver_receive failed with %d", r);
339
            continue;
340
        }
341
        if (is_ipc_notify(ipc_status)) { /* received notification */
342
            switch (_ENDPOINT_P(msg.m_source)) {
343
                case HARDWARE: /* hardware interrupt notification */
344
                    if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */
345
                        kbc_ih();
346
                        if (scancode[0] == ESC_BREAK_CODE) good = 0;
347
                    }
348
                    break;
349
                default:
350
                    break; /* no other notifications expected: do nothing */
351
            }
352
        } else { /* received standart message, not a notification */
353
            /* no standart message expected: do nothing */
354
        }
355
    }
356

  
357
    if (unsubscribe_interrupt(&kbc_id)) {
358
        if (vg_exit()) {
359
            printf("%s: vg_exit failed to exit to text mode.\n", __func__);
360
            if (free_memory()) printf("%s: lm_free failed\n", __func__);
361
        }
362
        return 1;
363
    };
364

  
365
    if (vg_exit()) {
366
        printf("%s: vg_exit failed to exit to text mode.\n", __func__);
367
        if (free_memory()) printf("%s: lm_free failed\n", __func__);
368
        return 1;
369
    }
370

  
371
    if (free_memory()) {
372
        printf("%s: lm_free failed\n", __func__);
373
        return 1;
374
    }
375

  
376
    return 0;
284 377
}
285 378

  
286 379
int(video_test_controller)() {

Also available in: Unified diff