Subversion Repositories shark

Rev

Rev 3 | Rev 1063 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
#include <ll/i386/hw-data.h>
2
#include <ll/i386/hw-instr.h>
3
#include <ll/i386/mem.h>
4
#include <ll/stdlib.h>
5
 
6
#include <drivers/gd.h>
7
 
151 giacomo 8
#include "font.h"
2 pj 9
#include "fun16.h"
10
 
11
#define fontaddr       0xffa6eL     /* indirizzo set caratteri         */
12
 
13
extern DWORD flbaddr;
14
 
15
void RdWin_Hi(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf)
16
{
17
    WORD b_bank, b_offset, display_ptr;
18
    int dx, len1, len2, bank_num, row;
19
/*    int bank, enmem;*/
20
    DWORD end_of_line, display_offset;
21
    WORD bytes_per_row;
22
    LIN_ADDR p;
23
 
24
    bytes_per_row = gd_getbpr();
25
    p = buf;
26
 
27
    Seg_Off_Hi(x1, y1, bytes_per_row, &b_offset, &b_bank);
28
    dx = (x2 - x1) + 1;
29
    /*dx = (x2 - x1);*/
30
    row = y1;
31
    display_offset = b_offset;
32
    display_ptr = display_offset;
33
    bank_num = b_bank;
34
    Load_Write_Bank_256(bank_num);
35
    do {
36
        end_of_line = display_ptr + (2 * (x2 - x1));
37
        if (end_of_line >= 65536L) {
38
            len2 = (1 + (end_of_line - 65536L) / 2);
39
            len1 = dx - len2;
40
/*              Clr_Part(color, length_1, display_ptr);*/
41
            memcpy(p, (LIN_ADDR)(0xA0000 + display_ptr), len1 * 2); /* NON CI VA *2???*/
42
            p += len1 * 2;
43
            bank_num++;
44
            Load_Write_Bank_256(bank_num);
45
            display_ptr = 0;
46
/*              Clr_Part(color, length_2, display_ptr);*/
47
            memcpy(p, (LIN_ADDR)(0xA0000 + display_ptr), len2 * 2); /* NON CI VA * 2 ???*/
48
            p += len2 * 2;
49
            display_ptr = (bytes_per_row - (len1 * 2));
50
        } else {
51
/*      Clr_Part(color, dx, display_ptr);*/
52
            memcpy(p, (LIN_ADDR)(0xA0000 + display_ptr), dx * 2); /* NON CI VA * 2 ???*/
53
            p += (dx * 2);
54
            display_offset = (DWORD)display_ptr + (DWORD)bytes_per_row;
55
            if (display_offset >= 65536L) {
56
                bank_num++;
57
                Load_Write_Bank_256(bank_num);
58
                display_ptr = display_offset - 65536L;
59
            } else {
60
                display_ptr += bytes_per_row;
61
            }  
62
        }
63
        row++;
64
    } while (row <= y2);
65
    Load_Write_Bank_256(0);
66
}
67
 
68
void WrWin_Hi(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf)
69
{
70
    WORD b_bank, b_offset, display_ptr;
71
    int dx, len1, len2, bank_num, row;
72
/*    int bank, enmem;*/
73
    DWORD end_of_line, display_offset;
74
    WORD bytes_per_row;
75
    LIN_ADDR p;
76
 
77
    bytes_per_row = gd_getbpr();
78
    p = buf;
79
 
80
    Seg_Off_Hi(x1, y1, bytes_per_row, &b_offset, &b_bank);
81
    dx = (x2 - x1) + 1;
82
    /*dx = (x2 - x1);*/
83
    row = y1;
84
    display_offset = b_offset;
85
    display_ptr = display_offset;
86
    bank_num = b_bank;
87
    Load_Write_Bank_256(bank_num);
88
    do {
89
        end_of_line = display_ptr + (2 * (x2 - x1));
90
        if (end_of_line >= 65536L) {
91
            len2 = (1 + (end_of_line - 65536L) / 2);
92
            len1 = dx - len2;
93
/*              Clr_Part(color, length_1, display_ptr);*/
94
            memcpy((LIN_ADDR)(0xA0000 + display_ptr), p, len1 * 2); /* NON CI VA *2???*/
95
            p += len1 * 2;
96
            bank_num++;
97
            Load_Write_Bank_256(bank_num);
98
            display_ptr = 0;
99
/*              Clr_Part(color, length_2, display_ptr);*/
100
            memcpy((LIN_ADDR)(0xA0000 + display_ptr), p, len2 * 2); /* NON CI VA * 2 ???*/
101
            p += len2 * 2;
102
            display_ptr = (bytes_per_row - (len1 * 2));
103
        } else {
104
/*      Clr_Part(color, dx, display_ptr);*/
105
            memcpy((LIN_ADDR)(0xA0000 + display_ptr), p, dx * 2); /* NON CI VA * 2 ???*/
106
            p += (dx * 2);
107
            display_offset = (DWORD)display_ptr + (DWORD)bytes_per_row;
108
            if (display_offset >= 65536L) {
109
                bank_num++;
110
                Load_Write_Bank_256(bank_num);
111
                display_ptr = display_offset - 65536L;
112
            } else {
113
                display_ptr += bytes_per_row;
114
            }  
115
        }
116
        row++;
117
    } while (row <= y2);
118
    Load_Write_Bank_256(0);
119
}
120
 
121
void linPut16(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf)
122
{
123
    WORD bpr;
124
    LIN_ADDR addr, p;
125
    WORD dx, y;
126
 
127
    bpr = gd_getbpr();
128
    p = buf;
129
    addr = (LIN_ADDR)(flbaddr + x1 * 2 + bpr * y1);
130
    dx = (x2 - x1 + 1) * 2;
131
    /*dx = (x2 - x1) * 2;*/
132
 
133
    for (y = y1; y <= y2; y++) {
134
        memcpy(addr, p, dx);
135
        p += dx;
136
        addr += bpr;
137
    }
138
}
139
 
140
void linGet16(WORD x1, WORD y1, WORD x2, WORD y2, BYTE *buf)
141
{
142
    WORD bpr;
143
    LIN_ADDR addr, p;
144
    WORD dx, y;
145
 
146
    bpr = gd_getbpr();
147
    p = buf;
148
    addr = (LIN_ADDR)(flbaddr + x1 * 2 + bpr * y1);
149
    dx = (x2 - x1 + 1) * 2;
150
    /*dx = (x2 - x1) * 2;*/
151
 
152
    for (y = y1; y <= y2; y++) {
153
        memcpy(p, addr, dx);
154
        p += dx;
155
        addr += bpr;
156
    }
157
}
158
 
159
void ClrWin_Hi(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color)
160
{
161
    WORD b_bank, b_offset, display_ptr;
162
    int dx, len1, len2, bank_num, row;
163
/*    int bank, enmem;*/
164
    DWORD end_of_line, display_offset;
165
    WORD bytes_per_row;
166
 
167
    bytes_per_row = gd_getbpr();
168
 
169
    Seg_Off_Hi(x1, y1, bytes_per_row, &b_offset, &b_bank);
170
    dx = (x2 - x1) + 1;
171
    row = y1;
172
    display_offset = b_offset;
173
    display_ptr = display_offset;
174
    bank_num = b_bank;
175
    Load_Write_Bank_256(bank_num);
176
    do {
177
        end_of_line = display_ptr + (2 * (x2 - x1));
178
        if (end_of_line >= 65536L) {
179
            len2 = (1 + (end_of_line - 65536L) / 2);
180
            len1 = dx - len2;
181
/*              Clr_Part(color, length_1, display_ptr);*/
182
            memsetw((LIN_ADDR)(0xA0000 + display_ptr), color, len1 * 2); /* FORSE NON* 2???*/
183
            bank_num++;
184
            Load_Write_Bank_256(bank_num);
185
            display_ptr = 0;
186
/*              Clr_Part(color, length_2, display_ptr);*/
187
            memsetw((LIN_ADDR)(0xA0000 + display_ptr), color, len2 * 2); /* FORSE NON* 2??? */
188
            display_ptr = bytes_per_row - (2 * len1);
189
        } else {
190
/*          Clr_Part(color, dx, display_ptr);*/
191
            memsetw((LIN_ADDR)(0xA0000 + display_ptr), color, dx * 2); /* FORSE NON* 2??? */
192
            display_offset = (DWORD)display_ptr + (DWORD)bytes_per_row;
193
            if (display_offset >= 65536L) {
194
                bank_num++;
195
                Load_Write_Bank_256(bank_num);
196
                display_ptr = display_offset - 65536L;
197
            } else {
198
                display_ptr += bytes_per_row;
199
            }
200
        }
201
        row++;
202
    } while (row <= y2);
203
    Load_Write_Bank_256(0);
204
}
205
 
206
void linBox16(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color)
207
{
208
    WORD bpr;
209
    DWORD addr;
210
    WORD dx, y;
211
 
212
    bpr = gd_getbpr();
213
    addr = flbaddr + x1 * 2 + bpr * y1;
214
    dx = (x2 - x1 + 1) * 2;
215
    /*dx = (x2 - x1) * 2;*/
216
 
217
    for (y = y1; y <= y2; y++) {
218
        memsetw((LIN_ADDR)addr, color, dx);
219
        addr += bpr;
220
    }
221
}
222
 
223
void WrRect_Hi(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color)
224
{
225
    WORD bank, offs, ebank, eoffs;
226
    WORD bpr;
227
    WORD line_segment, len;
228
    WORD y;
229
 
230
    bpr = gd_getbpr();
231
    len = 1 + x2 - x1;
232
    Seg_Off_Hi(x2, y1, bpr, &eoffs, &ebank);
233
    Seg_Off_Hi(x1, y1, bpr, &offs, &bank);
234
    Load_Write_Bank_256(bank);
235
    if (bank == ebank) {
236
        memsetw((LIN_ADDR)(0xA0000 + offs), color, len * 2); /* NON CI VA * 2???*/
237
    } else {
238
        line_segment = 65536L - offs;
239
        memsetw((LIN_ADDR)(0xA0000 + offs), color, line_segment); /* NON CI VA * 2???*/
240
        Load_Write_Bank_256(ebank);
241
        memsetw((LIN_ADDR)0xA0000, color, eoffs); /* NON CI VA * 2??? */
242
    }
243
    for (y = y1 + 1; y <= y2 + 1; y++) {
244
        Seg_Off_Hi(x1, y, bpr, &offs, &bank);
245
        Load_Write_Bank_256(bank);
246
        lmempokew((LIN_ADDR)(0xA0000 + offs), color);
247
        Seg_Off_Hi(x2, y, bpr, &offs, &bank);
248
        Load_Write_Bank_256(bank);
249
        lmempokew((LIN_ADDR)(0xA0000 + offs), color);
250
    }
251
    Seg_Off_Hi(x2, y2, bpr, &eoffs, &ebank);
252
    Seg_Off_Hi(x1, y2, bpr, &offs, &bank);
253
    Load_Write_Bank_256(bank);
254
    if (bank == ebank) {
255
        memsetw((LIN_ADDR)(0xA0000 + offs), color, len * 2);  /* NON CI VA * 2???*/
256
    } else {
257
        line_segment = 65536L - offs;
258
        memsetw((LIN_ADDR)(0xA0000 + offs), color, line_segment);  /* NON CI VA * 2???*/
259
        Load_Write_Bank_256(ebank);
260
        memsetw((LIN_ADDR)0xA0000, color, eoffs);   /* NON CI VA * 2???*/
261
    }
262
}
263
 
264
void linRect16(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color)
265
{
266
    WORD bpr;
267
    DWORD addr;
268
    WORD dx, y;
269
 
270
    bpr = gd_getbpr();
271
    addr = flbaddr + x1 * 2 + bpr * y1;
272
    dx = (x2 - x1) * 2;
273
 
274
    memsetw((LIN_ADDR)addr, color, dx+2);
275
    addr += bpr;
276
 
277
    for (y = y1 + 1; y <= y2 - 1; y++) {
278
        lmempokew((LIN_ADDR)addr, color);
279
        lmempokew((LIN_ADDR)(addr + dx), color);
280
        addr += bpr;
281
    }
282
    memsetw((LIN_ADDR)addr, color, dx+2);
283
}
284
 
285
void WrText_Hi(char *text, WORD x, WORD y, DWORD fg, DWORD bg)
286
{
287
    DWORD fp;
288
    WORD offs, bank;
289
    WORD bpr;
290
    int r, c, bits;
291
 
292
    bpr = gd_getbpr();
293
    while (*text) {
151 giacomo 294
        fp = (DWORD)&(font_table[*(BYTE *)text][0]);
2 pj 295
        for (r=0; r<8; r++) {
296
            bits = lmempeekb((LIN_ADDR)(fp++));
297
            for (c=0; c<8; c++)
298
                if (bits & (0x80>>c)) {
299
                    Seg_Off_Hi(x + c, y + r, bpr, &offs, &bank);
300
                    Load_Write_Bank_256(bank);
301
                    lmempokew((LIN_ADDR)(0xA0000 + offs), fg);
302
                }
303
/*                  lmempokew((LIN_ADDR)(addr + (y + r) * bpr + x + c), fg);*/
304
/*                  vbe_putpixel((x+c),(y+r),fg);*/
305
                else {
306
                    Seg_Off_Hi(x + c, y + r, bpr, &offs, &bank);
307
                    Load_Write_Bank_256(bank);
308
                    lmempokew((LIN_ADDR)(0xA0000 + offs), bg);
309
                }
310
/*                  lmempokew((LIN_ADDR)(addr + (y + r) * bpr + x + c), bg);*/
311
/*                  vbe_putpixel((x+c), (y+r), bg);*/
312
        }
313
        text++;
314
        x += 8;
315
    }
316
}
317
 
318
void linText16(char *text, WORD x, WORD y, DWORD fg, DWORD bg)
319
{
320
    DWORD fp, addr;
321
    WORD bpr;
322
    int r, c, bits;
323
 
324
    bpr = gd_getbpr();
325
    addr = gd_getflb();
326
    while (*text) {
327
        /*DOSSetAddr(fp, (fontaddr + (8 * *(BYTE *)text)));*/
328
        /*DOSSetAddr(fp, (fontaddr + (8 * *(BYTE *)text)));*/
151 giacomo 329
        fp = (DWORD)&(font_table[*(BYTE *)text][0]);
2 pj 330
        for (r=0; r<8; r++) {
331
            bits = lmempeekb((LIN_ADDR)fp++);
332
            for (c=0; c<8; c++)
333
                if (bits & (0x80>>c))
334
                    lmempokew((LIN_ADDR)(addr + (y + r) * bpr + ((x + c) * 2)), fg);
335
/*                  vbe_putpixel((x+c),(y+r),fg);*/
336
                else
337
                    lmempokew((LIN_ADDR)(addr + (y + r) * bpr + ((x + c) * 2)), bg);
338
/*                  vbe_putpixel((x+c), (y+r), bg);*/
339
        }
340
        text++;
341
        x += 8;
342
    }
343
}
344
 
345
void WrLine_Hi(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color)
346
{
347
    int dx, dy, incr1, incr2, d, x, y, xend, yend, yinc, xinc;
348
    WORD bpr;
349
    WORD bank, offs, ebank, eoffs;
350
    WORD line_segment, len;
351
 
352
    bpr = gd_getbpr();
353
    if (y2 == y1) {
354
        y = y1;
355
        if (x1 > x2) {
356
            xend = x1;
357
            x1 = x2;
358
            x2 = xend;
359
        }
360
/*      WrHline_256(x1, x2, y1, color, bpr);    */
361
        len = 1 + x2 - x1;
362
        Seg_Off_Hi(x2, y, bpr, &eoffs, &ebank);
363
        Seg_Off_Hi(x1, y, bpr, &offs, &bank);
364
        Load_Write_Bank_256(bank);
365
        if (bank == ebank) {
366
            memsetw((LIN_ADDR)(0xA0000 + offs), color, len * 2);
367
        } else {
368
            line_segment = 65536L - offs;
369
            memsetw((LIN_ADDR)(0xA0000 + offs), color, line_segment);
370
            Load_Write_Bank_256(ebank);
371
            memsetw((LIN_ADDR)0xA0000, color, eoffs);
372
        }
373
    } else {
374
        dx = abs(x2 - x1);
375
        dy = abs(y2 - y1);
376
        if (dx >= dy) {
377
            if (x1 > x2) {
378
                x = x2;
379
                y = y2;
380
                xend = x1;
381
                if (dy == 0) {
382
                    yinc = 0;
383
                } else {
384
                    if (y2 > y1) {
385
                        yinc = -1;
386
                    } else {
387
                        yinc = 1;
388
                    }
389
                }
390
            } else {
391
                x = x1;
392
                y = y1;
393
                xend = x2;
394
                if (dy == 0) {
395
                    yinc = 0;
396
                } else {
397
                    if (y2 > y1) {
398
                        yinc =1;
399
                    } else {
400
                        yinc = -1;
401
                    }
402
                }
403
            }
404
            incr1 = 2 * dy;
405
            d = incr1 - dx;
406
            incr2 = 2 * (dy - dx);
407
            Seg_Off_Hi(x, y, bpr, &offs, &bank);
408
            Load_Write_Bank_256(bank);
409
            lmempokew((LIN_ADDR)(0xA0000 + offs), color);
410
            while (x < xend) {
411
                x++;
412
                if (d < 0) {
413
                    d += incr1;
414
                } else {
415
                    y += yinc;
416
                    d += incr2;
417
                }
418
                Seg_Off_Hi(x, y, bpr, &offs, &bank);
419
                Load_Write_Bank_256(bank);
420
                lmempokew((LIN_ADDR)(0xA0000 + offs), color);
421
            }
422
        } else {
423
            if (y1 > y2) {
424
                x = x2;
425
                y = y2;
426
                yend = y1;
427
                if (dx == 0) {
428
                    xinc = 0;
429
                } else {
430
                    if (x2 > x1) {
431
                        xinc = -1;
432
                    } else {
433
                        xinc = 1;
434
                    }
435
                }
436
            } else {
437
                x = x1;
438
                y = y1;
439
                yend = y2;
440
                if (dx == 0) {
441
                    xinc = 0;
442
                } else {
443
                    if (x2 > x1) {
444
                        xinc = 1;
445
                    } else {
446
                        xinc = -1;
447
                    }
448
                }
449
            }
450
            incr1 = 2 * dx;
451
            d = incr1 - dy;
452
            incr2 = 2 * (dx - dy);
453
            Seg_Off_Hi(x, y, bpr, &offs, &bank);
454
            Load_Write_Bank_256(bank);
455
            lmempokew((LIN_ADDR)(0xA0000 + offs), color);
456
            while (y < yend) {
457
                y++;
458
                if (d < 0) {
459
                    d += incr1;
460
                } else {
461
                    x += xinc;
462
                    d += incr2;
463
                }
464
                Seg_Off_Hi(x, y, bpr, &offs, &bank);
465
                Load_Write_Bank_256(bank);
466
                lmempokew((LIN_ADDR)(0xA0000 + offs), color);
467
            }
468
        }
469
    }
470
}
471
 
472
void linLine16(WORD x1, WORD y1, WORD x2, WORD y2, DWORD color)
473
{
474
    register int t, distance;
475
    register DWORD addr;
476
    register WORD bpr;
477
    int xerr=0, yerr=0, deltax, deltay;
478
    int incx, incy;
479
 
480
    bpr = gd_getbpr();
481
    addr = gd_getflb();
482
    deltax = x2 - x1;                   /* compute both distances */
483
    deltay = y2 - y1;
484
 
485
    if (deltax > 0)                     /* compute increments */
486
        incx = 1;
487
    else if (deltax == 0)
488
        incx = 0;
489
    else
490
        incx = -1;
491
 
492
    if (deltay > 0)
493
        incy = 1;
494
    else if (deltay == 0)
495
        incy = 0;
496
    else
497
        incy = -1;
498
 
499
    deltax = abs(deltax);               /* determine greater distance */
500
    deltay = abs(deltay);
501
    if (deltax > deltay)
502
        distance = deltax;
503
    else
504
        distance = deltay;
505
 
506
    for (t=0; t<=distance+1; t++) {     /* draw the line */
507
/*      vbe_putpixel(x1, y1, colour);*/
508
        lmempokew((LIN_ADDR)(addr + y1 * bpr + (x1 * 2)), color);
509
        xerr += deltax;
510
        yerr += deltay;
511
        if (xerr > distance) {
512
            xerr -= distance;
513
            x1 += incx;
514
        }
515
        if (yerr > distance) {
516
            yerr -= distance;
517
            y1 += incy;
518
        }
519
    }
520
}
521
 
522
void WrPixel_Hi(WORD x, WORD y, DWORD color)
523
{
524
    WORD bpr;
525
    WORD bank, offs;
526
 
527
    bpr = gd_getbpr();
528
    Seg_Off_Hi(x, y, bpr, &offs, &bank);
529
    Load_Write_Bank_256(bank);
530
    lmempokew((LIN_ADDR)(0xA0000 + offs), color);
531
/*    Load_Write_Bank_256(0);*/
532
}
533
 
534
void linWr16(WORD x, WORD y, DWORD color)
535
{
536
    WORD bpr;
537
 
538
    bpr = gd_getbpr();
539
    lmempokew((LIN_ADDR)(flbaddr + y * bpr + (x * 2)), color);
540
}
541
 
542
DWORD RdPixel_Hi(WORD x, WORD y)
543
{
544
    WORD bpr;
545
    WORD bank, offs;
546
    DWORD rv;
547
 
548
    bpr = gd_getbpr();
549
    Seg_Off_Hi(x, y, bpr, &offs, &bank);
550
    Load_Write_Bank_256(bank);
551
    rv = lmempeekw((LIN_ADDR)(0xA0000 + offs));
552
    return rv;
553
}
554
 
555
DWORD linRd16(WORD x, WORD y)
556
{
557
    WORD bpr;
558
    DWORD rv;
559
 
560
    bpr = gd_getbpr();
561
    rv = lmempeekw((LIN_ADDR)(flbaddr + y * bpr + (x * 2)));
562
    return rv;
563
}
564