summaryrefslogtreecommitdiffstats
path: root/qemu/roms/SLOF/slof/fs/graphics.fs
blob: 7d5d9306d5fd43db944a6714f776c4aeef676383 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
\ *****************************************************************************
\ * Copyright (c) 2015 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ *     IBM Corporation - initial implementation
\ ****************************************************************************/

\ Provide some of the functions that are defined in the
\ "OF Recommended Practice: 8bit Graphics Extension" document

: draw-rectangle ( adr x y w h -- )
   frame-buffer-adr 0= IF 4drop drop EXIT THEN
   0 ?DO
      4dup drop                              ( adr x y w adr x y )
      \ calculate offset into framebuffer: ((y + i) * width + x) * depth
      i + screen-width * + screen-depth *    ( adr x y w adr offs )
      frame-buffer-adr +                     ( adr x y w adr fb_adr )
      over 3 pick screen-depth * i * +       ( adr x y w adr fb_adr src )
      swap 3 pick screen-depth *             ( adr x y w adr src fb_adr len )
      rmove                                  \ copy line ( adr x y w adr )
      drop                                   ( adr x y w )
   LOOP
   4drop
;

: fill-rectangle ( col x y w h -- )
   frame-buffer-adr 0= IF 4drop drop EXIT THEN
   0 ?DO
      4dup drop                              ( col x y w col x y )
      \ calculate offset into framebuffer: ((y + i) * width + x) * depth
      i + screen-width * + screen-depth *    ( col x y w col offs )
      frame-buffer-adr +                     ( col x y w col adr )
      2 pick screen-depth * 2 pick           ( col x y w col adr len col )
      rfill                                  \ draw line ( col x y w col )
      drop                                   ( col x y w )
   LOOP
   4drop
;

: read-rectangle ( adr x y w h -- )
   frame-buffer-adr 0= IF 4drop drop EXIT THEN
   0 ?DO
      4dup drop                              ( adr x y w adr x y )
      \ calculate offset into framebuffer: ((y + i) * width + x) * depth
      i + screen-width * + screen-depth *    ( adr x y w adr offs )
      frame-buffer-adr +                     ( adr x y w adr fb_adr )
      over 3 pick screen-depth * i * +       ( adr x y w adr fb_adr dst )
      3 pick                                 ( adr x y w adr fb_adr dst w )
      rmove                                  \ copy line ( adr x y w adr )
      drop                                   ( adr x y w )
   LOOP
   4drop
;

: dimensions ( -- width height )
   screen-width screen-height
;

\ Initialize a default palette (not a standard command, but useful anyway)
: init-default-palette
   \ Grayscale ramp for upper colors
   100 10 DO
     i i i i color!
   LOOP
   \ Standard colors from "16-color Text Extension" specification
   00 00 00 0 color!
   00 00 aa 1 color!
   00 aa 00 2 color!
   00 aa aa 3 color!
   aa 00 00 4 color!
   aa 00 aa 5 color!
   aa 55 00 6 color!
   aa aa aa 7 color!
   55 55 55 8 color!
   55 55 ff 9 color!
   55 ff 55 a color!
   55 ff ff b color!
   ff 55 55 c color!
   ff 55 ff d color!
   ff ff 55 e color!
   ff ff ff f color!
;