summaryrefslogtreecommitdiffstats
path: root/firmware/target/coldfire/mpio/hd200/lcd-as-hd200.S
blob: 7ea0b8f921558277af0e1c6dce028388e4eb1cb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id:$
 *
 * Copyright (C) 2010 Marcin Bukat
 * based on lcd-as-m3.S by Jens Arnold
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "config.h" 
#include "cpu.h"


#define LCD_BASE_ADDRESS 0xf0000000

    .section    .icode,"ax",@progbits

    .align      2
    .global     lcd_write_command
    .type       lcd_write_command,@function

lcd_write_command:
    move.l  (4, %sp), %d0
    move.w  %d0, LCD_BASE_ADDRESS	/* data is 1byte but CF uses word
                                         * transfers only */
    rts
.wc_end:
    .size   lcd_write_command,.wc_end-lcd_write_command


    .align      2
    .global     lcd_write_command_e
    .type       lcd_write_command_e,@function

lcd_write_command_e:
    lea.l   LCD_BASE_ADDRESS, %a0

    move.l  (4, %sp), %d0       /* Command */
    move.w  %d0, (%a0)         
    move.l  (8, %sp), %d0       /* Data */
    move.w  %d0, (%a0)          /* Write to LCD */

    rts
.wce_end:
    .size   lcd_write_command_e,.wce_end-lcd_write_command_e


    .align      2
    .global     lcd_write_data
    .type       lcd_write_data,@function

/* PIXELFORMAT = VERTICAL_INTERLEAVED
 * this means that data is packed verticaly in 8 pixels columns
 * first byte is lsb of 2bit color in column
 * second byte is msb of 2bit color in column
 * so one word of data equals 8 pixels i 2bits color depth packed
 * verticaly
 */
lcd_write_data:
    movem.l (4, %sp), %a0	     /* Data pointer */
    move.l  (8, %sp), %d0            /* Length i in words */
    lea.l   LCD_BASE_ADDRESS+2, %a1  /* LCD data port address */

    btst    #0, %d0    /* longwords multiply? */
    jeq    .l_write

.w_write:
    move.w  (%a0)+, %d1  /* load data         3 cycles*/
    move.w  %d1, (%a1)   /* first byte        1 cycle*/
    lsr.l   #8, %d1      /* load second byte  1 cycle*/
    move.w  %d1, (%a1)   /* transfer          1 cycle*/
    subq.l  #1, %d0      /* decrement counter 1 cycle*/
    jeq     .write_end   
    
.l_write:
    move.l  (%a0)+, %d1  /* load data         2 cycles*/
    swap    %d1          /*                   1 cycle */
    move.w  %d1, (%a1)   /* first byte        1 cycle*/
    lsr.l   #8, %d1      /*                   1 cycle */
    move.w  %d1, (%a1)   /* second byte       1 cycle*/
    lsr.l   #8, %d1      /*                   1 cycle */
    move.w  %d1, (%a1)   /* third byte        1 cycle*/
    lsr.l   #8, %d1      /*                   1 cycle */
    move.w  %d1, (%a1)   /* forth byte        1 cycle*/
    subq.l  #2, %d0      /* decrement counter 1 cycle*/
    bne.s   .l_write

.write_end:
    rts
.wd_end:
    .size   lcd_write_data,.wd_end-lcd_write_data

    .global lcd_mono_data
    .type   lcd_mono_data, @function

lcd_mono_data:
    move.l  (4, %sp), %a0       /* p_bytes */
    move.l  (8, %sp), %d0       /* count */
    lea.l   LCD_BASE_ADDRESS+2, %a1  /* LCD data port address */

.md_loop:
    move.b  (%a0)+, %d1
    move.w  %d1, (%a1)    /* byte transfers actually */
    move.w  %d1, (%a1)
    subq.l  #1, %d0
    bne.s   .md_loop
    rts
.md_end:
    .size   lcd_mono_data,.md_end-lcd_mono_data

    .global     lcd_grey_data
    .type       lcd_grey_data,@function

lcd_grey_data:
    lea.l   (-2*4, %sp), %sp
    movem.l  %a2-%a3, (%sp)
    movem.l (2*4+4, %sp), %a0-%a2  /* values, phases, length */
    add.l   %a2, %a2
    lea.l   (%a1, %a2.l*4), %a2    /* end address */
    lea.l   LCD_BASE_ADDRESS+2, %a3 /* LCD data port address */
.ph_loop:
    clr.l   %d1
    move.l  (%a1), %d0          /* fetch 4 pixel phases */
    bclr.l  #31, %d0            /* Z = !(p0 & 0x80); p0 &= ~0x80; */
    seq.b   %d1                 /* %d1 = ........................00000000 */
    lsl.l   #1, %d1             /* %d1 = .......................00000000. */
    bclr.l  #23, %d0            /* Z = !(p1 & 0x80); p1 &= ~0x80; */
    seq.b   %d1                 /* %d1 = .......................011111111 */
    lsl.l   #1, %d1             /* %d1 = ......................011111111. */
    bclr.l  #15, %d0            /* Z = !(p2 & 0x80); p2 &= ~0x80; */
    seq.b   %d1                 /* %d1 = ......................0122222222 */
    lsl.l   #1, %d1             /* %d1 = .....................0122222222. */
    bclr.l  #7, %d0             /* Z = !(p3 & 0x80); p3 &= ~0x80; */
    seq.b   %d1                 /* %d1 = .....................01233333333 */
    lsl.l   #1, %d1             /* %d1 = ....................01233333333. */
    add.l   (%a0)+, %d0         /* add 4 pixel values to the phases */
    move.l  %d0, (%a1)+         /* store new phases, advance pointer */

    move.l  (%a1), %d0          /* fetch 4 pixel phases */
    bclr.l  #31, %d0            /* Z = !(p0 & 0x80); p0 &= ~0x80; */
    seq.b   %d1                 /* %d1 = ....................012344444444 */
    lsl.l   #1, %d1             /* %d1 = ...................012344444444. */
    bclr.l  #23, %d0            /* Z = !(p1 & 0x80); p1 &= ~0x80; */
    seq.b   %d1                 /* %d1 = ...................0123455555555 */
    lsl.l   #1, %d1             /* %d1 = ..................0123455555555. */
    bclr.l  #15, %d0            /* Z = !(p2 & 0x80); p2 &= ~0x80; */
    seq.b   %d1                 /* %d1 = ..................01234566666666 */
    lsl.l   #1, %d1             /* %d1 = .................01234566666666. */
    bclr.l  #7, %d0             /* Z = !(p3 & 0x80); p3 &= ~0x80; */
    seq.b   %d1                 /* %d1 = .................012345677777777 */
    lsr.l   #7, %d1             /* %d1 = ........................01234567 */
    add.l   (%a0)+, %d0         /* add 4 pixel values to the phases */
    move.l  %d0, (%a1)+         /* store new phases, advance pointer */

    move.w  %d1, (%a3)          /* transfer to lcd */
    move.w  %d1, (%a3)          /* transfer to lcd */

    cmp.l   %a2, %a1
    bls.s   .ph_loop

    movem.l (%sp), %a2-%a3
    lea.l   (2*4, %sp), %sp
    rts
.grey_end:
    .size    lcd_grey_data,.grey_end-lcd_grey_data