Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
4867 leency 1
; KolSPForth v12
2
 
3
;Memory Map
4
;
5
;0
6
;0x02C7D	;I_END
7
;0x05430	;CTOP
8
 
9
;0x3F800	;Data stack
10
;0x3FA00	;return stack
11
;0x3FC00	;User
12
;0x3FE00	;TIB
13
;0x30000	;FILE BUFF
14
;0x40000 (256K)
15
 
16
   ;; Version control
17
 
18
   VER             EQU     1                       ;major release version
19
   EXT             EQU     0                       ;minor extension
20
 
21
   ;; Constants
22
 
23
   TRUEE		EQU	-1			;true flag
24
 
25
   COMPO		EQU	040H			;lexicon compile only bit
26
   IMEDD		EQU	080H			;lexicon immediate bit
27
   MASKK		EQU	01FH			;lexicon bit mask
28
 
29
   CELLL		EQU	4			;size of a cell
30
   BASEE		EQU	10			;default radix
31
   VOCSS		EQU	8			;depth of vocabulary stack
32
 
33
   BKSPP		EQU	8			;back space
34
   LF		EQU	10			;line feed
35
   CRR		EQU	13			;carriage return
36
   ERR		EQU	27			;error escape
37
   TIC		EQU	39			;tick
38
 
39
   CALLL		EQU	0E8H			;CALL opcodes
40
 
41
   ROWH   EQU 13
42
   KEY_DELAY EQU 20
43
   FW_WIDTH equ 500
44
   FW_HEIGHT equ 352
45
 
46
 
47
   ;; Memory allocation
48
 
49
   EM		EQU	256*1024		;top of memory
50
   FILE_BS	EQU	64*1024			;file buff size
51
   US		EQU	128*CELLL		;user area size in cells
52
   RTS		EQU	1024*CELLL		;return stack/TIB size
53
 
54
   FILE_B	EQU	EM-FILE_BS		;terminal input buffer (TIB)
55
   TIBB		EQU	FILE_B-RTS		;terminal input buffer (TIB)
56
;   UPP		EQU	TIBB-US                 ;start of user area (UP0)
57
   RPP		EQU	UPP-RTS                 ;start of return stack (ESP0)
58
   SPP		EQU	RPP-RTS                 ;start of data stack (EBP0)
59
 
60
LastNFA = 0
61
 
62
LastCFA EQU INIT
63
 
64
 
65
 
66
macro AHEADER FLAG,ID,F_CFA {
67
	db	FLAG
68
	DD	F_CFA
69
	DD	LastNFA
70
The_Nfa = $
71
	DB	ID,0
72
LastNFA = The_Nfa
73
F_CFA:
74
}
75
 
76
macro cfa_AHEADER FLAG,ID,F_CFA {
77
	db	FLAG
78
	DD	cfa_#F_CFA
79
	DD	LastNFA
80
The_Nfa = $
81
	DB	ID,0
82
LastNFA = The_Nfa
83
cfa_#F_CFA:
84
}
85
 
86
 
4868 leency 87
;; Main entry points and COLD start data
4867 leency 88
 
89
 use32
4868 leency 90
 format binary as ""
4867 leency 91
 
92
 	org    0x0
93
 
4868 leency 94
 	db     'MENUET01'
95
 	dd     0x01
96
 	dd     ORIG         ; start of code
97
 	dd     I_END        ; size of image
98
MEMS: 	dd     EM       ; memory for app
99
 	dd     SPP          ; esp
4869 leency 100
	dd     params
101
	dd     cur_dir_path
4867 leency 102
 
103
 lang fix ru
7134 dunkaist 104
 include 'macros.inc'
105
 include 'proc32.inc'
4867 leency 106
 
107
align 4
108
proc strncmp stdcall, s1:dword, s2:dword, n:dword
109
 
4869 leency 110
	   push esi
111
	   push edi
112
	   mov ecx, [n]
113
	   test ecx, ecx         ; Max length is zero?
114
	   je .done
4867 leency 115
 
4869 leency 116
	   mov esi, [s1]         ; esi = string s1
117
	   mov edi, [s2]         ; edi = string s2
118
	   cld
4867 leency 119
.compare:
4869 leency 120
	   cmpsb                 ; Compare two bytes
121
	   jne .done
122
	   cmp byte [esi-1], 0   ; End of string?
123
	   je .done
124
	   dec ecx               ; Length limit reached?
125
	   jne .compare
4867 leency 126
.done:
4869 leency 127
	   seta al               ; al = (s1 > s2)
128
	   setb ah               ; ah = (s1 < s2)
129
	   sub al, ah
130
	   movsx eax, al         ; eax = (s1 > s2) - (s1 < s2), i.e. -1, 0, 1
131
	   pop edi
132
	   pop esi
133
	   ret
4867 leency 134
endp
135
 
136
align 4
137
proc GetPr stdcall, exp:dword, sz_name:dword
138
           mov edx, [exp]
139
.next:
140
           push edx
141
           stdcall strncmp, edx, [sz_name], 16
142
           pop edx
143
           test eax, eax
144
           jz .ok
145
           mov edx, [edx-4]
146
           test edx, edx
147
           jnz .next
148
	mov eax,edx
149
           ret
150
.ok:
151
           mov eax, [edx-8]
152
           ret
153
endp
154
 
155
AHEADER 0 ,'GETPR',cfa_GETPR
156
 JMP GetPr
157
 
158
 
159
   ORIG:
160
 
161
   	MOV	EBP,RPP			;initialize RP
162
   	CLD				;ESI gets incremented
163
   	finit
164
 	call draw_window
165
 	call  calc_lines
166
	XCHG	ESP,EBP
167
	CALL amain
168
BYE:	mcall -1
169
 
170
 
171
   ULAST:    ;      DD      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
172
 
173
 
174
 draw_cursor:
175
 
176
 draw_window:
4868 leency 177
	pusha
178
	mcall 12,1
179
	mov   [fRed],ebx
180
	mcall 0, <0,FW_WIDTH>, <0,FW_HEIGHT>, 0x54000000
181
	; mcall 0,,,COL_WINDOW_BG, ,title ; define window
182
	mcall 71, 1, header
4867 leency 183
 
4868 leency 184
	mcall 9,pinfo,-1
7134 dunkaist 185
	mov   eax,[pinfo.box.width]
4868 leency 186
	cdq
187
	sub   eax,20
188
	mov   ebx,6
189
	div   ebx
7134 dunkaist 190
	mov   [pinfo.box.left],eax
4867 leency 191
 
7134 dunkaist 192
	mov   eax,[pinfo.box.height]
4868 leency 193
	cdq
194
	sub   eax,40
195
	mov   ebx,ROWH
196
	div   ebx
4867 leency 197
 
7134 dunkaist 198
	mov   [pinfo.box.top],eax
4868 leency 199
	call  erase_screen
200
	mcall 12, 2
201
	mcall 67,-1,-1,FW_WIDTH,FW_HEIGHT
202
	popa
203
	ret
4867 leency 204
 
205
 
4868 leency 206
macro GetSkinHeight
207
{
208
	mov  eax,48
209
	mov  ebx,4
210
	int 0x40
211
}
4867 leency 212
 
4868 leency 213
erase_screen:
214
	GetSkinHeight
215
	mov ecx,eax
216
	shl ecx,16
7134 dunkaist 217
	add ecx,[pinfo.box.height]
4868 leency 218
	sub ecx,eax
219
	sub ecx,4
7134 dunkaist 220
	mov   ebx,[pinfo.box.width]
4868 leency 221
	add   ebx,5 shl 16 - 9
222
	mcall 13,,,0;xff
223
	ret
4867 leency 224
 
4868 leency 225
 
4867 leency 226
AHEADER 0,"CC_LINES",cfa_CC_LINES
227
 calc_lines:
228
	 cmp dword[UPP+10*4],0
229
	 je  .ex
230
 		pusha
231
 		mov  ebp,os_work
232
 		mov  al,0xd
233
 		mov  edi,screen_buf
234
; 		mov  esi,[cursor]
235
; 		mov  byte[esi],'_'
236
; 		inc  [cursor]
237
 	.again:
238
 		mov  [ebp],edi
239
 		mov  esi,[cursor]
240
 		sub  esi,edi
7134 dunkaist 241
 		mov  ecx,[pinfo.box.left]
4867 leency 242
;   test ecx,ecx
243
;   jnz  .no0
244
;   inc  ecx
245
;  .no0:
246
 		cmp  ecx,esi
247
 		jbe  .ok
248
 		mov  ecx,esi
249
 	.ok:
250
 		repne scasb
251
 		jecxz .nocrlf
252
 		cmp  byte[edi],10
253
 		jne  .nocrlf
254
 		inc  edi
255
 	.nocrlf:
256
 		mov  ecx,edi
257
 		sub  ecx,[ebp]
258
 		add  ebp,8
259
 		mov  [ebp-4],ecx
260
 		cmp  edi,[cursor]
261
 		jb   .again
262
 		and  dword[ebp],0
263
 ;		dpd  esi
7134 dunkaist 264
 		mov  eax,[pinfo.box.top]
4867 leency 265
 		shl  eax,3
266
 		sub  ebp,eax
267
 		cmp  ebp,os_work
268
 		jae  .ok2
269
 		mov  ebp,os_work
270
 	.ok2:
271
 	 cmp  ebp,[last_ebp]
272
   je   .ok3
273
   mov  [last_ebp],ebp
274
   call erase_screen
275
  .ok3:
276
 		mov  ebx,10 shl 16 +30
277
 ;		ud2
278
 	.newl:
279
 		mcall 4,,0xffffff,[ebp],[ebp+4]
280
 		add  ebp,8
281
 		add  ebx,ROWH
282
 		cmp  dword[ebp],0
283
 		jnz  .newl
284
		SUB   ebx,ROWH
285
		call set_cur
286
 		popa
287
 .ex:
288
 		ret
289
 
290
 
291
set_cur:
292
	MOV	ecx,EBX
293
	shl	ecx,16
294
	add	ecx,EBX
295
	MOV 	EAX,[ebp+4-8]
296
	add 	EAX,2
297
	imul	EAX,6
298
	mov 	EBX,EAX
299
	shl	ebx,16
300
	add 	EBX,EAX
301
	mov	[lastcur],ecx
302
	mov	[lastcur+4],ebx
303
	ret
304
 
305
 e_calc_lines:
306
	 cmp dword[UPP+10*4],0
307
	 je  e_.ex
308
 		pusha
309
 		mov  ebp,os_work
310
 		mov  al,0xd
311
 		mov  edi,screen_buf
312
; 		mov  esi,[cursor]
313
; 		mov  byte[esi],'_'
314
; 		inc  [cursor]
315
 	e_.again:
316
 		mov  [ebp],edi
317
 		mov  esi,[cursor]
318
 		sub  esi,edi
7134 dunkaist 319
 		mov  ecx,[pinfo.box.left]
4867 leency 320
;   test ecx,ecx
321
;   jnz  .no0
322
;   inc  ecx
323
;  .no0:
324
 		cmp  ecx,esi
325
 		jbe  e_.ok
326
 		mov  ecx,esi
327
 	e_.ok:
328
 		repne scasb
329
 		jecxz e_.nocrlf
330
 		cmp  byte[edi],10
331
 		jne  e_.nocrlf
332
 		inc  edi
333
 	e_.nocrlf:
334
 		mov  ecx,edi
335
 		sub  ecx,[ebp]
336
 		add  ebp,8
337
 		mov  [ebp-4],ecx
338
 		cmp  edi,[cursor]
339
 		jb   e_.again
340
 		and  dword[ebp],0
341
 ;		dpd  esi
7134 dunkaist 342
 		mov  eax,[pinfo.box.top]
4867 leency 343
 		shl  eax,3
344
 		sub  ebp,eax
345
 		cmp  ebp,os_work
346
 		jae  e_.ok2
347
 		mov  ebp,os_work
348
 	e_.ok2:
349
 	 cmp  ebp,[last_ebp]
350
   je   e_.ok3
351
   mov  [last_ebp],ebp
352
	cmp  byte[edi],10
353
	jne  e_.ok3
354
 
355
   call erase_screen
356
  e_.ok3:
357
 		mov  ebx,10 shl 16+30
358
 ;		ud2
359
 	e_.newl:
360
; 		mcall 4,,0xffffff,[ebp],[ebp+4]
361
 		add  ebp,8
362
 		add  ebx,ROWH
363
 		cmp  dword[ebp],0
364
 		jnz  e_.newl
365
		SUB   ebx,ROWH
366
 		mcall 4,,0x00ffffff,[ebp-8],[ebp+4-8]
367
		call set_cur
368
 		popa
369
 e_.ex:
370
 		ret
371
 
372
 
373
AHEADER 0,"?KEY",cfa_queKEY
374
	PUSH	EDI
375
	XCHG	EBP,ESP
376
	PUSH	EAX
377
       POP  EBX
378
       mov  eax,10
379
       test ebx,ebx
380
       jz   QRX0
381
       inc  eax
382
    QRX0:
383
   		XOR	ECX,ECX			;EBX=0 setup for false flag
384
       mcall
385
       cmp  eax,1
386
       jne  QRX_
387
       call draw_window
388
       call calc_lines
389
    QRX_:
390
       cmp  eax,3
391
       je  BYE
392
       cmp  eax,2
393
       jne QRX3
394
 
395
       mcall 2
396
   QRX1:		MOVZX	ECX,AH
397
   QRX2:		PUSH	ECX			;save character
398
   QRX_TRUE:
399
   		MOV	ECX,TRUEE		;true flag
400
   QRX3:		PUSH	ECX
401
	POP	eax
402
	XCHG	EBP,ESP
403
	POP	EDI
404
	ret
405
 
406
   ;   ?RX		( -- c T | F )
407
   ;		Return input character and true, or a false if no input.
408
 
409
 
410
AHEADER 0,"EMIT_N",cfa_EMIT_N
411
 
412
	PUSH	EDI
413
	XCHG	EBP,ESP
414
			;char in AL
415
   		CMP	AL,0FFH			;0FFH is interpreted as input
416
   		JNZ	TX2			;do NOT allow input
417
   		MOV	AL,32			;change to blank
418
   TX2:
419
   		mov  ebx,[cursor]
420
   		mov  [ebx],AL
421
   		inc  [cursor]
422
 
423
	POP	eax
424
	XCHG	EBP,ESP
425
	POP	EDI
426
RET
427
 
428
 
429
 ;; Basic I/O
430
 
431
cfa_AHEADER 0,'CL_CUR',CL_CUR
432
	PUSH	EAX
433
	mcall 38,[lastcur+4],[lastcur],0
434
	POP	EAX
435
	RET
436
 
437
	cfa_AHEADER 0,'DR_CUR',DR_CUR
438
	PUSH	EAX
439
	mcall 38,[lastcur+4],[lastcur],0x00FF00FF
440
	POP	EAX
441
	RET
442
 
443
 
444
COLOR_ORDER equ MENUETOS
445
include 'gif_lite.inc'
446
 
447
cfa_AHEADER 0,'READ_GIF',READ_GIF ;( gif_ptr, out_ptr -- result )
448
	push esi
449
	push edi
450
	push ebp
451
	mov  edi, eax
452
	mov  esi,[ebp]
453
	mov  eax,os_work
454
	call ReadGIF
455
	pop  ebp
456
	pop  edi
457
	pop  esi
458
	add  ebp,4
459
	RET
460
 
461
   ;===============================================================
462
 cursor  dd screen_buf
463
  fRed  dd 1
464
 last_ebp dd 0
465
 
466
 include 'amain.asm'
4868 leency 467
 
468
 header db   'Kolibri Forth v12.1',0
4869 leency 469
 params: rb 256
470
 cur_dir_path: rb 4096
4867 leency 471
 
4869 leency 472
 
4867 leency 473
 FINFO:
474
 	.mode dd 0
4869 leency 475
		  dd 0
4867 leency 476
 	.blk  dd 1
477
 	.buf  dd 0
478
 	.work dd os_work
479
 
480
 
481
lastcur dd 0,0
482
 
483
I_END:
484
 squote_buf rb 1024
485
 sys_v rd 6
486
 screen_buf:
487
; sc_end:
488
 rb 4096
489
 pinfo process_information
490
 os_work rb 16*1024
491
 
492
   CTOP            =     $   ;next available memory in code dictionary
7134 dunkaist 493
   ;=============================================================