Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3530 esevece 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;                                                  ;
3
;      BROWSER for KolibriOS                       ;
4
;                                                  ;
5
;      Compile with FASM                           ;
6
;                                                  ;
7
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
 
9
; It's a work in progress but I (esevece) commit it, because if I don't continue developing it someone can continue.
10
; Please, keep the code clean
11
 
12
; The header
13
 
14
use32                                   ; Tell compiler to use 32 bit instructions
15
 
16
org 0x0                                 ; the base address of code, always 0x0
17
 
18
db 'MENUET01'
19
dd 0x01
20
dd START
21
dd I_END
22
dd 0x100000
23
dd 0x7fff0
24
dd 0, 0
25
 
26
; The code area
27
 
28
;include 'macros.inc'
29
 
30
START:                                  ; start of execution
31
        call    draw_window             ; draw the window
32
 
33
; After the window is drawn, it's practical to have the main loop.
34
; Events are distributed from here.
35
 
36
event_wait:
37
        mov     eax, 10                 ; function 10 : wait until event
38
        int     0x40                    ; event type is returned in eax
39
 
40
        cmp     eax, 1                  ; Event redraw request ?
41
        je      redraw                  ; Expl.: there has been activity on screen and
42
                                        ; parts of the applications has to be redrawn.
43
 
44
        cmp     eax, 2                  ; Event key in buffer ?
45
        je      key                     ; Expl.: User has pressed a key while the
46
                                        ; app is at the top of the window stack.
47
 
48
        cmp     eax, 3                  ; Event button in buffer ?
49
        je      button                  ; Expl.: User has pressed one of the
50
                                        ; applications buttons.
51
 
52
        jmp     event_wait
53
 
54
;  The next section reads the event and processes data.
55
 
56
redraw:                                 ; Redraw event handler
57
        call    draw_window             ; We call the window_draw function and
58
        jmp     event_wait              ; jump back to event_wait
59
 
60
key:                                    ; Keypress event handler
61
        mov     eax, 2                  ; The key is returned in ah. The key must be
62
        int     0x40                    ; read and cleared from the system queue.
63
        jmp     event_wait              ; Just read the key, ignore it and jump to event_wait.
64
 
65
button:                                 ; Buttonpress event handler
66
        mov     eax,17                  ; The button number defined in window_draw
67
        int     0x40                    ; is returned to ah.
68
 
69
        cmp     ah,1                    ; button id=1 ?
70
        jne     noclose
71
        mov     eax,-1                  ; Function -1 : close this program
72
        int     0x40
73
 
74
noclose:
75
        cmp     ah, 2                   ; call fetch_thread
76
        jne     no_fetch_thread
77
        call    fetch_thread
78
        jmp     event_wait              ; This is for ignored events, useful at development
79
 
80
no_fetch_thread:
81
        jmp     event_wait
82
 
83
 
84
; FETCHER
85
FETCH:
86
        mov     ecx, 1000
87
get_free_port:
88
        inc     ecx
89
        mov     eax, 53
90
        mov     ebx, 9
91
        int     0x40
92
        cmp     eax, 0    ; is port used?
93
        jz      get_free_port
94
open_socket:
95
        mov     eax, 53
96
        mov     ebx, 5
97
        mov     edx, 80
98
        mov     esi, 0x0417042E ; 46.4.23.4 (kolibrios.org), only for try
99
        mov     edi, 1
100
        int     0x40
101
        mov     [socket], eax
102
        cmp     [socket], -1    ; error?
103
        jne      status_socket
104
        ret
105
status_socket:
106
        mov     eax, 53
107
        mov     ebx, 6
108
        mov     ecx, [socket]
109
        int     0x40
110
        cmp     eax, 4   ; connected?
111
        jne     status_socket
112
send_request:
113
.concat_request:
114
        mov     edi, request
115
        mov     ebx, 0   ; request_length
116
        mov     esi, request_first_line
117
._first_line:
118
        movsb
119
        inc     ebx  ; request_length
120
        cmp     byte [edi], 0
121
        jne     ._first_line
122
        mov     esi, request_second_line
123
._second_line:
124
        movsb
125
        inc     ebx  ; request_length
126
        cmp     byte [edi], 0
127
        jne     ._second_line
128
        mov     esi, host
129
._second_line_host:
130
        movsb
131
        inc     ebx  ; request_length
132
        cmp     byte [edi], 0
133
        jne     ._second_line_host
134
        mov     esi, request_third_line
135
._third_line:
136
        movsb
137
        inc     ebx  ; request_length
138
        cmp     byte [edi], 0
139
        jne     ._third_line
140
        mov     [request_length], ebx
141
.write_to_socket:
142
        mov     eax, 53
143
        mov     ebx, 7
144
        mov     ecx, [socket]
145
        mov     edx, [request_length]
146
        mov     esi, request
147
        int     0x40
148
        cmp     eax, -1   ; error?
149
        je      .write_to_socket
150
.poll_socket:
151
	mov     eax, 53
152
	mov     ebx, 2
153
	mov     ecx, [socket]
154
	int     0x40
155
	cmp     eax, 0
156
	jne      .read_socket
157
	; only for test purposes
158
	mov     eax, 63
159
        mov     ebx, 1
160
        mov     cl,  's'
161
        int     0x40
162
.status_socket:
163
	mov     eax, 53
164
	mov	ebx, 6
165
	mov	ecx, [socket]
166
	int	0x40
167
	cmp	eax, 4
168
	jne	end_of_request
169
.read_socket:
170
	mov     eax, 53
171
	mov	ebx, 11
172
	mov 	ecx, [socket]
173
	mov	edx, [buffer]
174
	mov     esi, 4096
175
	int	0x40
176
	; only for test purposes
177
	mov     eax, 63
178
        mov     ebx, 1
179
        mov     cl,  'p'
180
        int     0x40
181
	jmp	.poll_socket
182
end_of_request:
183
.close_socket:
184
        mov     eax, 53
185
        mov     ebx, 8
186
        mov     ecx, [socket]
187
        int     0x40
188
        ; only for test purposes
189
        mov     eax, 63
190
        mov     ebx, 1
191
        mov     cl,  'b'
192
        int     0x40
193
        jmp    terminate_thread
194
 
195
fetch_thread:
196
        cmp     [thread_id], 0
197
        jne     terminate_thread
198
        mov     eax, 51
199
        mov     ebx, 1
200
        mov     ecx, FETCH
201
        mov     edx, [thread_stack]
202
        int     0x40
203
        jmp     event_wait
204
 
205
no_new_thread:
206
        ret
207
 
208
terminate_thread:
209
        mov     eax, 18
210
        mov     ebx, 18
211
        mov     ecx, [thread_id]
212
        int     0x40
213
        cmp     eax, 0
214
        jne 	terminate_thread
215
        mov     [thread_id], 0
216
        ret
217
 
218
thread_stack dd 0x80000
219
thread_id    dd 0x0
220
 
221
 
222
;  *********************************************
223
;  ******  WINDOW DEFINITIONS AND DRAW  ********
224
;  *********************************************
225
;
226
;  The static window parts are drawn in this function. The window canvas can
227
;  be accessed later from any parts of this code (thread) for displaying
228
;  processes or recorded data, for example.
229
;
230
;  The static parts *must* be placed within the fn 12 , ebx = 1 and ebx = 2.
231
 
232
draw_window:
233
        mov     eax, 12                 ; function 12: tell os about windowdraw
234
        mov     ebx, 1                  ; 1, start of draw
235
        int     0x40
236
 
237
        mov     eax, 0                  ; function 0 : define and draw window
238
        mov     ebx, 100 * 65536 + 300  ; [x start] *65536 + [x size]
239
        mov     ecx, 100 * 65536 + 120  ; [y start] *65536 + [y size]
240
        mov     edx, 0x14ffffff         ; color of work area RRGGBB
241
                                        ; 0x02000000 = window type 4 (fixed size, skinned window)
242
        mov     esi, 0x808899ff         ; color of grab bar  RRGGBB
243
                                        ; 0x80000000 = color glide
244
        mov     edi, title
245
        int     0x40
246
 
247
        ; Fetch button
248
        mov     eax, 8
249
        mov     ebx, 25 * 65536 + 128
250
        mov     ecx, 88 * 65536 + 20
251
        mov     edx, 2
252
        mov     esi, 0x6677cc
253
        int     0x40
254
 
255
        mov     ebx, 25 * 65536 + 35    ; draw info text with function 4
256
        mov     ecx, 0x224466
257
        mov     edx, text
258
        mov     esi, 40
259
        mov     eax, 4
260
 
261
  .newline:                             ; text from the DATA AREA
262
        int     0x40
263
        add     ebx, 10
264
        add     edx, 40
265
        cmp     byte[edx], 0
266
        jne     .newline
267
 
268
        mov     eax, 12                 ; function 12:tell os about windowdraw
269
        mov     ebx, 2                  ; 2, end of draw
270
        int     0x40
271
 
272
        ret
273
 
274
;  *********************************************
275
;  *************   DATA AREA   *****************
276
;  *********************************************
277
;
278
; Data can be freely mixed with code to any parts of the image.
279
; Only the header information is required at the beginning of the image.
280
 
281
text    db  "It look's like you have just compiled   "
282
        db  "your first program for KolibriOS.       "
283
        db  "                                        "
284
        db  "Congratulations!                        ", 0
285
 
286
title   db  "KolibriOS Browser", 0
287
 
288
socket          dd  0
289
socket_status   dd  0
290
server_ip       db  046,004,023,004
291
server_port     db  0,0
292
request_first_line  db 'GET / HTTP/1.1',0
293
request_second_line db 13,10,'Host: ',0
294
request_third_line  db 13,10,'Connection: close',13,10,13,10,0
295
request             db 0
296
request_length      dd 0
297
host                db 'kolibrios.org',0
298
buffer		dd  0
299
 
300
I_END:
301
 
302
; The area after I_END is free for use as the application memory,
303
; just avoid the stack.
304
;
305
; Application memory structure, according to the used header, 1 Mb.
306
;
307
; 0x00000   - Start of compiled image
308
; I_END     - End of compiled image
309
;
310
;           + Free for use in the application
311
;
312
; 0x7ff00   - Start of stack area
313
; 0x7fff0   - End of stack area                 - defined in the header
314
;
315
;           + Free for use in the application
316
;
317
; 0xFFFFF   - End of freely useable memory      - defined in the header
318
;
319
; All of the the areas can be modified within the application with a
320
; direct reference.
321
; For example, mov [0x80000],byte 1 moves a byte above the stack area.