-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdl.fs
93 lines (69 loc) · 1.82 KB
/
sdl.fs
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
88
89
90
91
92
93
[undefined] sdl.fs [if]
c-library sdl
s" SDL" add-lib
\c #include <SDL/SDL.h>
c-function sdl-init SDL_Init n -- n
c-function sdl-set-video-mode SDL_SetVideoMode n n n n -- a
c-function sdl-flip SDL_Flip a -- n
c-function sdl-quit SDL_Quit -- void
c-function sdl-delay SDL_Delay n -- void
c-function sdl-poll-event SDL_PollEvent a -- void
end-c-library
vocabulary sdl.fs also sdl.fs definitions
$00000000 constant SDL_SWSURFACE
$80000000 constant SDL_FULLSCREEN
$00000020 constant SDL_INIT_VIDEO
$0000FFFF constant SDL_INIT_EVERYTHING
$00000002 constant SDL_KEYDOWN
32 constant sdl-pixels-offset
24 constant sdl-event-type-size
1024 constant #width
768 constant #height
#width 4 * constant #stride
variable color 3 cells allot
variable surface
variable pixels
variable sdl-event sdl-event-type-size allot
: wait-key
begin
sdl-event sdl-poll-event
sdl-event c@ SDL_KEYDOWN =
until
;
: set-color ( b g r -- )
color c!
color 1 + c!
color 2 + c!
;
: get-pixel-addr ( x y -- addr )
pixels @ -rot #stride * swap 4 * + +
;
: set-pixel ( addr -- )
dup color c@ swap c!
dup color 1 + c@ swap 1 + c!
color 2 + c@ swap 2 + c!
;
: put-pixel ( x y -- )
get-pixel-addr set-pixel
;
: pixel-off? ( x y -- t )
dup #height >= swap 0 < or swap
dup #width >= swap 0 < or
or
;
: clear-screen ( -- )
#stride #height * pixels @ + pixels @ do
0 i c!
loop
;
: init-sdl
SDL_INIT_EVERYTHING sdl-init
0<> if ." Error sdl-init" exit then
#width #height 32 SDL_SWSURFACE sdl-set-video-mode
dup 0< if ." Error sdl-set-video-mode" exit then surface !
\ save screen buffer address
surface @ sdl-pixels-offset + @ pixels !
;
: flip-screen surface @ sdl-flip throw ;
previous definitions
[then]