Project

General

Profile

Revision 111

implemented 3rd function

View differences:

lab5.c
75 75
    return 0;
76 76
}
77 77

  
78
///lcom_run lab5 "rectangle 105 3 3 30 30 12 -t 1"
78
// lcom_run lab5 "rectangle 105 100 100 100 100 1"
79
// lcom_run lab5 "rectangle 115 100 100 100 100 FF0000"
79 80
int(video_test_rectangle)(uint16_t mode, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint32_t color) {
80 81
    int r;
81 82
    if ((r = get_permissions_first_mbyte()))
......
165 166
}
166 167

  
167 168
int(video_test_pattern)(uint16_t mode, uint8_t no_rectangles, uint32_t first, uint8_t step) {
168
  /* To be completed */
169
  printf("%s(0x%03x, %u, 0x%08x, %d): under construction\n", __func__,
170
         mode, no_rectangles, first, step);
169
    int r;
170
    if ((r = get_permissions_first_mbyte()))
171
        panic("%s: sys_privctl (ADD MEM) failed: %d\n", __func__, r);
171 172

  
172
  return 1;
173
    if (vbe_get_mode_information(mode)) {
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__);
177
        return 1;
178
    }
179

  
180
    map_vram(); // if function fails it aborts program
181

  
182
    if (set_graphics_mode(mode)) {
183
        printf("%s: failed to set graphic mode %x.\n", __func__, mode);
184
        if (vg_exit()) printf("%s: vg_exit failed to exit to text mode.\n", __func__);
185
        return 1;
186
    }
187
    uint16_t W = get_XRes()/no_rectangles;
188
    uint16_t H = get_YRes()/no_rectangles;
189
    uint32_t color, R, G, B;
190
    for(uint8_t row = 0; row < no_rectangles; ++row){
191
        for(uint8_t col = 0; col < no_rectangles; ++col){
192
            if(mode == 0x105){
193
                color = (first + (row * no_rectangles + col) * step) % (1 << get_bits_pixel());
194
            }else{
195
                R = (first + col*step) % (1 << get_RedMaskSize());
196
                G = (first + row*step) % (1 << get_GreenMaskSize());
197
                B = (first + (col+row)*step) % (1 << get_BlueMaskSize());
198
                color = (R<<16) | (G<<8) | (B);
199
            }
200
            if (vg_draw_rectangle(col*W,row*H,W,H,color)) {
201
                if (vg_exit()) {
202
                    printf("%s: vg_exit failed to exit to text mode.\n", __func__);
203
                    if (free_memory()) printf("%s: lm_free failed\n", __func__);
204
                }
205
                return 1;
206
            }
207
        }
208
    }
209

  
210
    /// loop stuff
211
    int ipc_status;
212
    message msg;
213
    /// Keyboard interrupt handling
214
    uint8_t kbc_irq_bit = KBC_IRQ;
215
    int kbc_id = 0;
216
    int kbc_irq = BIT(kbc_irq_bit);
217
    if (subscribe_kbc_interrupt(kbc_irq_bit, &kbc_id)) {
218
        if (vg_exit()) {
219
            printf("%s: vg_exit failed to exit to text mode.\n", __func__);
220
            if (free_memory()) printf("%s: lm_free failed\n", __func__);
221
        }
222
        return 1;
223
    }
224
    /// cycle
225
    int good = 1;
226
    while (good) {
227
        /* Get a request message. */
228
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
229
            printf("driver_receive failed with %d", r);
230
            continue;
231
        }
232
        if (is_ipc_notify(ipc_status)) { /* received notification */
233
            switch (_ENDPOINT_P(msg.m_source)) {
234
                case HARDWARE: /* hardware interrupt notification */
235
                    if (msg.m_notify.interrupts & kbc_irq) { /* subscribed interrupt */
236
                        kbc_ih();
237
                        if (scancode[0] == ESC_BREAK_CODE) good = 0;
238
                    }
239
                    break;
240
                default:
241
                    break; /* no other notifications expected: do nothing */
242
            }
243
        } else { /* received standart message, not a notification */
244
            /* no standart message expected: do nothing */
245
        }
246
    }
247

  
248
    if (unsubscribe_interrupt(&kbc_id)) {
249
        if (vg_exit()) {
250
            printf("%s: vg_exit failed to exit to text mode.\n", __func__);
251
            if (free_memory()) printf("%s: lm_free failed\n", __func__);
252
        }
253
        return 1;
254
    };
255

  
256
    if (vg_exit()) {
257
        printf("%s: vg_exit failed to exit to text mode.\n", __func__);
258
        if (free_memory()) printf("%s: lm_free failed\n", __func__);
259
        return 1;
260
    }
261

  
262
    if (free_memory()) {
263
        printf("%s: lm_free failed\n", __func__);
264
        return 1;
265
    }
266

  
267
    return 0;
173 268
}
174 269

  
175 270
int(video_test_xpm)(xpm_map_t xpm, uint16_t x, uint16_t y) {

Also available in: Unified diff