Title: distorter
Author: aymeric


\ distorter.f
\ a fullscreen vertical distorter
\ a tribute to the 90's intro distorters :)
\ aym3ric -at- goto10 -dot- org


\ variables
: init-variables
	variable counter
	1 counter !
	variable counter-saved
	1 counter-saved !
;

init-variables

\ utils
: ndup   for dup next ;
: n+	 for + next ;
: transx for nop next ;

\ counter stuff
: count   		counter @ 1 + counter ! ;
: store-counter   	counter @ counter-saved ! ;
: restore-counter	counter-saved @ counter ! ;
: counts		for count next ;

\ update line size (linear bouncexor!)
: get-size 
	counter @ 
	1st 
	4 high? if
		#x1F xor #x1F and 5 +
	else
		#x1F and 5 +
	then
	;

\ pattern and chess
: X     WHITE 1 transx ;
: _     BLACK 1 transx ;    

: X0	for X _ next ;
: 0X	for _ X next ;

: line1	for hsync 15 0X next ;
: line2 for hsync 15 X0 next ;

: lines
	3 counts
    	get-size dup
    	line2

    	3 counts
    	get-size dup
    	line1
	;

: chess	8 for lines next ;

\ finally...
: distorter

    screen ->

    hsync 
	restore-counter count store-counter
    get-size dup
    line1

    chess 

    16 n+ 
    249 nop swap - line2
    ;

Title: smile
Author: marc



\ draw a big pixel
: X     WHITE 2 usec ;
: _     BLACK 2 usec ;    
: __    BLACK 3 usec ;    


\ blinking pixel
variable blink
: O	blink @ 8 >? if X else _ then drop drop ;

\ total number of lines = 250    

: smile
	screen ->

	1 blink +!

	50 blanks

	20 for hsync _ _ _ _ X X X X X _ 	next
	20 for hsync _ _ _ X _ _ _ _ _ X _ 	next
	20 for hsync _ _ X _ _ X _ O __  X _ 	next
	20 for hsync _ _ X _ _ _ _ _ _ _ X _ 	next
	20 for hsync _ _ X _ X _ _ _ X _ X _ 	next
	20 for hsync _ _ X _ _ X X X _ _ X _ 	next
	20 for hsync _ _ _ X _ _ _ _ _ X _ 	next
	20 for hsync _ _ _ _ X X X X X _ 	next

	60 blanks

	;

Title: soccer field
Author: dirk

?v=0



\ display area with 2 usec  x 14 lines = 19 x 19 

\ smaller then usec
: pix  for nop next ;

: X     WHITE nop ;
: _     BLACK nop ;    
: O     GREY nop ;

: zijlijn WHITE 115 for nop next ;
: halfveld GREY 54 for nop next ;
: keeperlijn WHITE 16 for nop next ;
: keeperveld GREY 37 for nop next ;
: keepervlak GREY 13 for nop next ;
: middelvlak GREY 24 for nop next ;

: keeperleft X keepervlak X middelvlak ;
: keeperight middelvlak X keepervlak X ;

\ display area with (only one nop)

: field
    screen ->

	45 blanks
	5 for hsync _ _ _ _ _ _ zijlijn _ next
	30 for hsync _ _ _ _ _ _ X halfveld X halfveld X _ next
	5 for hsync _ _ _ _ _ _ keeperlijn keeperveld X keeperveld keeperlijn _ next
	5 for hsync _ _ _ _ _ _ keeperleft O O O O O O O X O O O O O O O keeperight _ next
	5 for hsync _ _ _ _ _ _ keeperleft O O O O O O O X O O O O O O O keeperight _ next
	5 for hsync _ _ _ _ _ _ keeperleft O O O O O X X X X X O O O O O keeperight _ next
	5 for hsync _ _ _ X X X keeperleft O O O X X O O X O O X X O O O keeperight X X X _ next
	5 for hsync _ _ _ X _ _ keeperleft O O X O O O O X O O O O X O O keeperight _ _ X _ next
	5 for hsync _ _ _ X _ _ keeperleft O X O O O O O X O O O O O X O keeperight _ _ X _ next
	5 for hsync _ _ _ X _ _ keeperleft X O O O O O O X O O O O O O X keeperight _ _ X _ next
	5 for hsync _ _ _ X _ _ keeperleft X O O O O O X X X O O O O O X keeperight _ _ X _ next
	5 for hsync _ _ _ X _ _ keeperleft X O O O O O O X O O O O O O X keeperight _ _ X _ next
	5 for hsync _ _ _ X _ _ keeperleft O X O O O O O X O O O O O X O keeperight _ _ X _ next
	5 for hsync _ _ _ X _ _ keeperleft O O X O O O O X O O O O X O O keeperight _ _ X _ next
	5 for hsync _ _ _ X X X keeperleft O O O X X O O X O O X X O O O keeperight X X X _ next
	5 for hsync _ _ _ _ _ _ keeperleft O O O O O X X X X X O O O O O keeperight _ next
	5 for hsync _ _ _ _ _ _ keeperleft O O O O O O O X O O O O O O O keeperight _ next
	5 for hsync _ _ _ _ _ _ keeperleft O O O O O O O X O O O O O O O keeperight _ next
	5 for hsync _ _ _ _ _ _ keeperlijn keeperveld X keeperveld keeperlijn _ next
	30 for hsync _ _ _ _ _ _ X halfveld X halfveld X _ next
	5 for hsync _ _ _ _ _ _ zijlijn _ next

	50 blanks
	;


Title: the eye
Author: heerko, pieter en niels


\ pic18 analog->digital conversion

\ this is currently hardcoded for the CATkit board. i had some trouble
\ getting it to work, so i'm just following instructions.


macro
: ad-ready? ADCON0 GO_DONE low? ;
forth

\ turn on the AD covertor
\ ref = VDD/VSS
\ ( channel -- )
: ad-channel! 7 and << << 1 or ADCON0 ! ;
: ad-start    ADCON0 GO_DONE high ;    

\ wait for a conversion to finish, then collect the high bits
: ad-collect  begin ad-ready? until ADRESH @ ;

: ad@
    ad-channel!
    ad-start
    ad-collect ;

macro
: init-ad
    #x7E ADCON2 !   \ left justified, 20 TAD, fosc/2
    ;
forth


\ registers of interest:
\ ADCON1 for analog/digital select
\ TRISA/TRISB for input/output select

variable count

\ draw a big pixel
: X     WHITE 1 usec ;
: _     BLACK 1 usec ;    
: G GREY 1 usec ;

\ total number of lines = 250    
\ each pixel is 10 lines high, so it needs to be drawn 10 times, hence
\ the for .. next loop.

\ once the electron gun is off ( _ ) the rest of the line doesn't need
\ to be drawn.




: eye
    4 TRISA !
    screen ->

	2 ad@  200 >? if
            frame_1
        else
            frame_2
        then
        drop drop
    ;


: animate  1 count +! ;

: frame_1
    50 blanks
    10 for hsync _ _ _ _ _ X X X X X _ next
    10 for hsync _ _ _ X X _ G G G _ X _ next
    10 for hsync _ _ X _ _ _ G X G _ _ X _ next
    10 for hsync _ _ _ X X _ G G G _ X _ next
    10 for hsync _ _ _ _ _ X X X X X _ next
    150 blanks

 ;

: frame_2
    50 blanks
    10 for hsync _ next
    10 for hsync _ next
    10 for hsync _ next
    10 for hsync _ _ _ X X _ _ _ _ _ X _ next
    10 for hsync _ _ _ _ _ X X X X X _ next
    150 blanks

;