Subversion Repositories shark

Rev

Rev 1063 | Details | Compare with Previous | Last modification | View Log | RSS feed

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