Special Feature: ColorForth Commentary

ColorForth: GEN.ASM

Original file

NOTICE: This is a work in progress. Parts of my commentary are still very rough. However, I have it up on the web because even in this rough form it may be useful to ColorForth enthusiasts. Expect the contents of these files to change frequently.

;generic graphics

align 4
frame
;[Refs: switch, clip]
	dd 2000000h-hp*vp*2 ; 32 m

displ
;[Refs: ati0, switch]
	dd 0f0000000h ; fujitsu

"fore" is apparently the foreground color in 5:6:5 format -- the color used to "emit" the characters onto the screen.

fore
;[Refs: color, emit, emit2, line, box]
	dd 0f7deh

xc
;[Refs: clip, box]
	dd 0

yc
;[Refs: clip, box]
	dd 0

rgb

The rgb routine converts a 24-bit color value into a 16-bit one. The 24-bit color value provides eight bits for each of the red, green, and blue parts of the color. The 16-bit value provides five bits for red, six for green, and five for blue.

rgb:
;[Refs: color]
	ror	eax, 8
	shr	ax, 2
	ror	eax, 6
	shr	al, 3
	rol	eax, 6+5
	and	eax, 0f7deh
	ret

white:
;[Refs: text1, cap, caps, text]
	dup_
	mov	eax, 0ffffffh

color:
;[Refs: forth2, cyan, magenta, silver, blue, red, green, blank, keyboard,
;       ring, ww, nw1]
	call	rgb
	mov	fore, eax
	drop
	ret

north:
;[Refs: dev, ati0]
	mov	edx, 0cf8h
	out	dx, eax
	add	edx, 4
	in	eax, dx
	ret

dev:
;[Refs: ati0]
	mov	eax, 80001008h ; find display, start at device 2
	mov	ecx, 31-1 ; end with agp: 10008, bus 1, dev 0
@@:	dup_
	call	north
	and	eax, 0ff000000h
	cmp	eax, 3000000h
	drop
	jz	@f
	add	eax, 800h
	next	@b
@@: ret

ati0:
;[Refs: start1]
	call	dev
	or	dword ptr [eax-4], 2 ; enable memory
	add	al, 24h-8 ; look for prefetch
	mov	cl, 5
@@:	dup_
	call	north
	xor	al, 8
	jz	@f
	drop
	sub	eax, 4
	next	@b
	dup_
	call	north
	and	eax, 0fffffff0h
@@:	mov	displ, eax
	drop
	ret

fifof: ;"fifo"
;[Refs: forth2]
	drop

graphic:
;[Refs: show, forth2]
	ret

The word switch is called by the "god" (screen-update) task. It copies the output image (pointed to by frame) to the AGP video memory (pointed to by displ), then it jumps to pause, which switches to the "main" (wait-for-keyboard) task.

switch:
;[Refs: show]
;	dup_
	push	esi
	mov	esi, frame
	push	edi
	mov	edi, displ ; 0f2000000h emonster nvidia
;	xor	eax, eax
	mov	ecx, hp*vp/2
;@@:	lodsd
;	add	eax, [edi]
;	rcr	eax, 1
;	and	eax, 0f7def7deh
;	stosd
;	next	@b
	rep	movsd
	pop	edi
	pop	esi
;	drop
	jmp	pause

clip:
;[Refs: emit, emit2, line, box]
	mov	edi, xy
	mov	ecx, edi
	test	cx, cx
	jns	@f
	xor	ecx, ecx
@@:	and	ecx, 0ffffh
	mov	yc, ecx
	imul	ecx, hp*2
;	shl	ecx, 10+1
	sar	edi, 16
	jns	@f
	xor	edi, edi
@@:	mov	xc, edi
	lea	edi, [edi*2+ecx]
	add	edi, frame
	ret

bit16:
;[Refs: emit]
	lodsw
	xchg	al, ah
	mov	ecx, 16

b16:
;[Refs: b16]
	shl	ax, 1
	jnc	@f
	mov	[edi], dx
@@:	add	edi, 2
	next	b16
	ret

bit32:
;[Refs: emit2]
	lodsw
	xchg	al, ah
	mov	ecx, 16

b32:
;[Refs: b32]
	shl	eax, 1
	jnc	@f
	mov	[edi], dx
	mov	[edi+2], dx
	mov	[edi+hp*2], dx
	mov	[edi+hp*2+2], dx
@@:	add	edi, 4
	next	b32
	ret

emit:
;Draw character at screen position in foreground color.
;[Refs: forth2, four1, edig, dot10, ring, cap, caps, type2]
	call	qcr
	push	esi
	push	edi
	push	edx
	imul	eax, 16*24/8
	lea	esi, icons[eax]
	call	clip
	mov	edx, fore
	mov	ecx, 24
@@:	push	ecx
	call	bit16
	add	edi, (hp-16)*2
	pop	ecx
	next	@b
	pop	edx
	pop	edi
	pop	esi
bl_:
;[Refs: none]
	drop

space:
;[Refs: forth2, eight, dot, d_2, type0, type2]
	add	xy, iw*10000h
	ret

emit2: ;"2emit"
;Draw large character at screen position in foreground color.
;[Refs: forth2]
	push	esi
	push	edi
	push	edx
	imul	eax, 16*24/8
	lea	esi, icons[eax]
	call	clip
	mov	edx, fore
	mov	ecx, 24
@@:	push	ecx
	call	bit32
	add	edi, (2*hp-16*2)*2
	pop	ecx
	next	@b
	pop	edx
	pop	edi
	pop	esi
	add	xy, iw*10000h*2
	drop
	ret

text1: ;"text"
;Move to upper-left corner; set foreground color to white.
;[Refs: forth2, keyboard, refresh]
	call	white
	mov	lm, 3
	mov	rm, hc*iw
	jmp	top

line:
;[Refs: forth2]
	call	clip
	mov	ecx, [esi]
	shl	ecx, 1
	sub	edi, ecx
	mov	ecx, eax
	mov	eax, fore
	rep	stosw
	inc	xy
	drop
	drop
	ret

box:
;Draw box from screen position to xy in foreground color.
;[Refs: forth2, blank]
	call	clip
	cmp	eax, vp+1
	js	@f
	mov	eax, vp
@@:	mov	ecx, eax
	sub	ecx, yc
	jng	no
	cmp	dword ptr [esi], hp+1
	js	@f
	mov	dword ptr [esi], hp
@@:	mov	eax, xc
	sub	[esi], eax
	jng	no
	mov	edx, hp
	sub	edx, [esi]
	shl	edx, 1
	mov	eax, fore
@@:	push	ecx
	mov	ecx, [esi]
	rep	stosw
	add	edi, edx
	pop	ecx
	next	@b

no:
;[Refs: box]
	drop
	drop
	ret

Check the index for other entries.