home *** CD-ROM | disk | FTP | other *** search
- \ code for driving a LCD
- \ Specific numbers are for 480 by 128 pixels on 4 parallel bits.
-
-
- code bitmasks \ this is how the 4 bits are wired up
- $10 c, $80 c, $40 c, $20 c,
- 1 c, 2 c, 4 c, 8 c,
- $0EF c, $07F c, $0BF c, $0DF c,
- $0FE c, $0FD c, $0FB c, $0F7 c,
- end-code
-
- fload chartbl \ 8x8 pixel character table
-
- code dxy_addr ( x y -- [bitmask] addr ) \ point to byte and bit for x,y
-
- cmp ttos # 128
- 0>= if \ wrap around for y > 127
- clrb w1
- ldb w0 ttos
- divub w0 # 128
- ldb ttos w1 \ y mod 128
- clrb ttosh
- then
-
- ld w0 [] psp
- cmp w0 # 480
- 0>= if \ wrap around for x > 479
- clr w2
- divu w0 # 480
- ld w0 w2 \ x mod 480
- st w0 [] psp
- then
-
- ld w2 # DBUF \ start of display buffer
- cmp w0 # 240
- 0< if inc w2 \ odd address for x < 240
- else sub w0 # 240 \ now have (x mod 240)
- then
-
- ldb w1 # 239
- subb w1 w0 \ 239 - ( x mod 240 )
- shrb w1 # 1
- andb w1 # $0FE \ /4 *2
- ldb w0 w1
- clrb w1
- add w2 w0 \ add to address
-
- ldb w0 ttos
- incb w0
- andb w0 # $3F
- ldb w1 # 63 \ 63 - ( [y+1] mod 64 )
- subb w1 w0
- ldb w0 # 120
- mulub w0 w1 \ * 120
- add w2 w0 \ add to address
- \ now the address to return is in w2
-
- shr ttos # 4
- and ttos # 4 \ 4 * y/64
- ld w0 [] psp
- and w0 # 3 \ x mod 4
- add w0 ttos
- add w0 # bitmasks
- st w0 [] psp \ return [bitmask] next-on-stack
-
- ld ttos w2 \ return display address in top-of-stack
- ret
-
- end-code
-
- \ Note that the following code can be used from hilevel
- \ ( because of the "code" name ), or called directly from a code
- \ difinition ( because of the "label" name ).
- \ Note that the "label" and "code" lines must stay together.
-
- code dLPLOT-lab ( x y -- ) \ set color of pixel at x,y
- end-code
- code dLPLOT ( x y -- ) \ set color of pixel at x,y
- call dxy_addr
- ldb w2 [] ttos \ get display byte
- ld w0 [] psp \ address of bitmask
- bitset tcolor 7 if orb w2 [] w0
- else andb w2 [I] 8 w0 \ change the bit
- then
- stb w2 [] ttos \ store the changed display byte
- add psp # 2
- load_ttos \ pop two off stack
- ret
- end-code
-
- code dLPOINT ( x y -- n1 ) \ Get status of pixel at x,y
- call dxy_addr
- ld w0 [] psp \ address of bitmask is next-on-stack
- ldb w0 [] w0 \ now get bitmask in w0
- andb w0 [] ttos \ now and with display byte
- add psp # 2 \ pop one off stack
- ld ttos w0
- ret
- end-code
-
- code L-emit ( c -- ) \ display character c
- push tcolor
- sub psp # 2 \ make room for x on stack
- shl ttos # 3
- add ttos # tchartbl \ point to character in table
-
- ldb w2 # 8
- begin
- ld w0 [] sp \ get saved color
- push ttos
- ldb tcolor [] ttos \ get a byte from the table
- bitclear w0 7 if not tcolor then \ invert if dark
- ldb w3 # 8
- begin
- push w2
- ld ttos # 8
- subb ttos w3
- add ttos tlcdx
- st ttos [] psp \ pixel x
- ldb ttos # 8
- subb ttos w2
- add ttos tlcdy \ pixel y
- call dlplot-lab
- sub psp # 4 \ ( dlplot popped 2 off the stack )
- pop w2
- shl tcolor # 1
- dec0= w3 until
- pop ttos
- inc ttos
- dec0= w2 until
-
- add tlcdx # 8
- cmp tlcdx # 480
- 0>= if
- add tlcdy # 8
- clr tlcdx
- cmp tlcdy # 128
- 0>= if clr tlcdy then
- then
- add psp # 2
- ld ttos []+ psp \ pop one off stack
- pop tcolor
- ret
- end-code
-
- : dark ( -- ) \ clear the screen to all dark
- DBUF
- ROWS ROW_WORDS * 2* $FF fill ;
-
- : light ( -- ) \ clear the screen to all white
- DBUF
- ROWS ROW_WORDS * 2* erase ;
-
- : testemit ( -- ) \ test the LCD emit by filling the screen with text
- light \ clear the screen
- 0 tlcdx ! \ start at top left corner
- 0 tlcdy !
- 480 8 / \ for the whole screen...
- 128 8 / *
- 0 do i 127 and l-emit \ emit incrementing characters
- loop
- ;
-
- ' l-emit alias emit
-
- : at ( x y -- ) \ place characters at x,y
- 8 * tlcdy !
- 8 * tlcdx ! ;
-
-
- comment:
-
- code JUMPTABLE
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
- 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
- end-code
-
- dlplot-LAB $100 - $1000 + jumptable t!
- T['] dlpoint jumptable 2+ t!
- ' l-emit jumptable 4 + t!
- ' dark jumptable 6 + t!
- ' light jumptable 8 + t!
-
- : lemit ( c -- )
- tcolor @
- swap 8 * tchartbl +
- 8 0 do dup @
- 2 pick 0= if not then
- 8 0 do dup tcolor !
- i tlcdx @ + over lplot
- 2*
- loop
- drop 1+
- loop
- drop
- tlcdx @ 8 +
- dup 480 >= if drop 0 tlcdy 8 +! then
- tlcdx !
- tcolor ! ;
- comment;
-
-