For characters I use the MUCH faster aligned byte mode:

-- use for sprites or fonts that are multiple of 8 high
procedure BlitColumn (byte in x, byte in y,  byte in column ) is
    _ks0108_inst() -- Set for instruction
    if (x > 128) then
       x = x -128
    end if
        if y > 191 then
         y = y -192
    elsif y > 127 then
         y = y - 128
    elsif y > SCREEN_MAX_Y then
         y = y -SCREEN_ROWS
    end if
    if (x > SCREEN_SUB_X ) then
        _ks0108_column(_KS0108_RIGHT, x-(SCREEN_SUB_X +1)) -- Set the
horizontal address
        _ks0108_page(_KS0108_RIGHT, (y / 8)) -- Set the page address
        _ks0108_data() -- Set for data
        _ks0108_write(_KS0108_RIGHT, column) -- Write the pixel data

    else
        _ks0108_column(_KS0108_LEFT,x) -- Set the horizontal address
        _ks0108_page(_KS0108_LEFT, (y / 8)) -- Set the page address
        _ks0108_data() -- Set for data
        _ks0108_write(_KS0108_LEFT, column) -- Write the pixel data

    end if
end procedure


-- Title: dev_glcd_ks0108 - Library for KS0108 compatible LCD
-- Author: Serkan Ayyýldýz Copyright (c) 2006..2009, all rights
reserved.
-- Adapted-by: Joep Suijs, Michael Watterson (c)2010
-- Compiler: >=2.4
--
-- This file is part of jallib (http://jallib.googlecode.com)
-- Released under the ZLIB license
--     (http://www.opensource.org/licenses/zlib-license.html)
--
-- Sources:
--
-- Description: Library for KS0108 / KS0107 graphic lcd with 128x64
resolution.
--
--
-- Notes:
--  This panel uses 2 off 64 x64 sharing drivers on one axis
-- if CSI and CS1 both active then both halves can written
simultaneously.

-- ******************************

--     Default port usage, all D, most B and one E

--     using port E allows sharing D & B with a Keyboard.
--  *****************************
if (defined(GLCD_RW )== false) then
    alias  GLCD_CS2           is pin_b2
    alias  GLCD_CS2_direction is pin_b2_direction
    alias  GLCD_CS1           is pin_b3
    alias  GLCD_CS1_direction is pin_b3_direction
    alias  GLCD_RW            is pin_b6
    alias  GLCD_RW_direction  is pin_b6_direction
    alias  GLCD_DI            is pin_b7 -- LCD command/data select.
    alias  GLCD_DI_direction  is pin_b7_direction
    alias  GLCD_E             is pin_E2
    alias  GLCD_E_direction   is pin_E2_direction
    alias  GLCD_LED           is pin_E1
    alias  GLCD_LED_direction is pin_E1_direction
    alias GLCD_dataprt        is portd    -- LCD data
    alias GLCD_DATAPRT_DIR    is portd_direction
end if




-- ******************************

--            PUBLIC

--  *****************************
const SCREEN_ROWS = 64
const SCREEN_COLS = 128
const SCREEN_MAX_X = SCREEN_COLS -1
const SCREEN_SUB_X = 63
const SCREEN_MAX_Y = SCREEN_ROWS -1
const SCREEN_BLIT_PIXELS = 8

-- *******************************

--             Private

-- *******************************




const _KS0108_LEFT = 0
const _KS0108_RIGHT = 1
const _KS0108_BOTH = 3
const _KS0108_CMD_ON = 0x3F
const _KS0108_CMD_OFF = 0x3E
const _KS0108_CMD_PAGE = 0xB8
const _KS0108_CMD_COLUMN = 0x40
const _KS0108_CMD_TOP_RAM = 0xC0



-- Purpose: Write a byte of data to the specified chip
-- Inputs: 1) chipSelect - which chip to write the data to
-- 2) data - the byte of data to write
procedure _ks0108_write(byte in side, byte in data) is
    if side ==  _KS0108_RIGHT then -- Choose which side to write to
        GLCD_CS2 = high
    elsif side ==  _KS0108_LEFT then
        GLCD_CS1 = high
    else
        GLCD_CS1 = high
        GLCD_CS2 = high
    end if
    GLCD_RW = low -- Set for writing
    GLCD_DATAPRT = data -- Put the data on the port
    GLCD_DATAPRT_DIR = all_output
    _usec_delay (1)
    GLCD_E = high -- Pulse the enable pin
    _usec_delay (2)
    --delay2_us
    GLCD_E = low
    GLCD_CS1 = low -- Reset the chip select lines
    GLCD_CS2 = low
    --delay_2us()
    _usec_delay (2)
end procedure

-- Purpose: Reads a byte of data from the specified chip
-- Ouputs: A byte of data read from the chip
function _ks0108_read(byte in side) return byte is
var byte data -- Stores the data read from the LCD
    GLCD_DATAPRT_DIR = all_input -- Set port d to input
    if side ==  _KS0108_RIGHT then -- Choose which side to write to
       GLCD_CS2 = high
    elsif side ==  _KS0108_LEFT  then
        GLCD_CS1 = high
    else   -- can only read one side at a time
        GLCD_CS1 = low
        GLCD_CS2 = low
        return (0)     -- exit
    end if
    GLCD_RW = high -- Set for reading
    _usec_delay (1) -- delay_cycles(1)
    GLCD_E = high -- Pulse the enable pin
    _usec_delay (2)
    data = GLCD_DATAPRT -- Get the data from the display's output
register
    GLCD_E = low
    GLCD_CS1 = low -- Reset the chip select lines
    GLCD_CS2 = low
    _usec_delay (2)

    return data -- Return the read data
end function

-- Purpose: Turn the display on
procedure _ks0108_on() is
    _ks0108_write(_KS0108_LEFT, _KS0108_CMD_ON)
    _ks0108_write(_KS0108_RIGHT, _KS0108_CMD_ON)
end procedure

-- Purpose: Turn the display off
procedure _ks0108_off() is
    _ks0108_write(_KS0108_LEFT, _KS0108_CMD_OFF)
    _ks0108_write(_KS0108_RIGHT, _KS0108_CMD_OFF)
end procedure

-- Purpose: Set the page number
-- Inputs: A page number (0 - 7)
procedure _ks0108_page(byte in side , byte in page) is
   _ks0108_write(side, _KS0108_CMD_PAGE | page)
end procedure

-- Purpose: Set the column address
-- Inputs: The column address (0 - SCREEN_SUB_X)
procedure _ks0108_column(byte in side, byte in column) is
    _ks0108_write(side, _KS0108_CMD_COLUMN | column)
end procedure

-- Purpose: Specify reads and writes are instructions
procedure _ks0108_inst() is
    GLCD_DI = low
end procedure

-- Purpose: Specify reads and writes are data
procedure _ks0108_data() is
    GLCD_DI = high
end procedure


procedure _ks0108_write_byte(byte in x, byte in y, byte in veri) is
var byte side = _KS0108_LEFT -- Stores which chip to use on the LCD
    if x > 127 then
       x = x -128
    end if
    if (x > SCREEN_SUB_X)then -- Check for first or second display
area
        x = x - (SCREEN_SUB_X +1)
        side = _KS0108_RIGHT
    end if
    if y > 191 then
         y = y -192
    elsif y > 127 then
         y = y - 128
    elsif y > SCREEN_MAX_Y then
         y = y -SCREEN_ROWS
    end if
    _ks0108_inst() -- Set for instruction
    _ks0108_column(side,x) -- Set the horizontal address
    _ks0108_page(side,(y / SCREEN_BLIT_PIXELS)) -- Set the page
address
    _ks0108_data() -- Set for data
    _ks0108_write(side, ! veri) -- Write the pixel data
end procedure


-- Purpose: Fill the LCD screen with the passed in color
-- Inputs: ON - turn all the pixels on
-- OFF - turn all the pixels off
procedure _ks0108_fill(byte in data) is
var byte i, j
    i = 0 -- Loop through the vertical pages
    for (SCREEN_ROWS / SCREEN_BLIT_PIXELS) loop
        _ks0108_inst() -- Set for instruction
        _ks0108_page(_KS0108_LEFT,i) -- Set page address
        _ks0108_page(_KS0108_RIGHT,i)
        _ks0108_column(_KS0108_LEFT,0) -- Set horizontal address to 0
        _ks0108_column(_KS0108_RIGHT,0)
        _ks0108_data() -- Set for data
        -- Loop through the horizontal sections
        for SCREEN_SUB_X +1 loop
            _ks0108_write(_KS0108_LEFT ,data) -- Write the byte of
data
            _ks0108_write(_KS0108_RIGHT,data)
        end loop
        i = i + 1
    end loop
end procedure

-- Purpose: Initialize the LCD.
-- Call before using any other LCD function.
procedure _ks0108_init() is
    -- Initialze some pins
    GLCD_DATAPRT = 0x00
    GLCD_DATAPRT_DIR = all_output
    GLCD_RW_DIRECTION = output
    GLCD_CS1_DIRECTION = output
    GLCD_E_DIRECTION = output
    GLCD_DI_DIRECTION = output
    --GLCD_RST_DIRECTION = output
    GLCD_CS2_DIRECTION = output
    --GLCD_RST = high
    GLCD_E = low
    GLCD_CS1 = low
    GLCD_LED = off
    GLCD_LED_direction = output

    _ks0108_inst() -- Set for instruction
    _ks0108_write(_KS0108_LEFT, _KS0108_CMD_TOP_RAM | 0) -- First RAM
line at the top of the screen
    _ks0108_write(_KS0108_RIGHT, _KS0108_CMD_TOP_RAM | 0) -- First RAM
line at the top of the screen
    _ks0108_page (_KS0108_LEFT ,0) -- Set the page address to 0
    _ks0108_page (_KS0108_RIGHT,0)
    _ks0108_column(_KS0108_LEFT ,0) -- Set the column address to 0
    _ks0108_column(_KS0108_RIGHT,0)
    _ks0108_on() -- Turn the display on
    _ks0108_fill(0) -- Clear the display
end procedure

var byte _ks0108_lastLcdCmd = 0    -- private current state of LCD
panel



In my "graphics library"

procedure PlotChar(byte in x, byte in y, byte in ch, bit in inkColour,
bit in large, bit in bold ) is
; 96 * 5 bytes = 455
const byte _FONT_5x7_MAP[] = {
0x00, 0x00, 0x00, 0x00, 0x00, ;; space, 32
0x00, 0x00, 0x2f, 0x00, 0x00, ;; !, 33
0x00, 0x07, 0x00, 0x07, 0x00, ;; ", 34
0x14, 0x7f, 0x14, 0x7f, 0x14, ;; #, 35
0x24, 0x2a, 0x7f, 0x2a, 0x12, ;; $, 36
0xc4, 0xc8, 0x10, 0x26, 0x46, ;; %, 37
0x36, 0x49, 0x55, 0x22, 0x50, ;; &, 38
0x00, 0x05, 0x03, 0x00, 0x00, ;; ', 39
0x00, 0x1c, 0x22, 0x41, 0x00, ;; (, 40
0x00, 0x41, 0x22, 0x1c, 0x00, ;; ), 41
0x14, 0x08, 0x3E, 0x08, 0x14, ;; *, 42
0x08, 0x08, 0x3E, 0x08, 0x08, ;; +, 43
0x00, 0x00, 0x50, 0x30, 0x00, ;; ,, 44
0x10, 0x10, 0x10, 0x10, 0x10, ;; -, 45
0x00, 0x60, 0x60, 0x00, 0x00, ;; ., 46
0x20, 0x10, 0x08, 0x04, 0x02, ;; /, 47
0x3E, 0x51, 0x49, 0x45, 0x3E, ;; 0, 48
0x00, 0x42, 0x7F, 0x40, 0x00, ;; 1, 49
0x42, 0x61, 0x51, 0x49, 0x46, ;; 2, 50
0x21, 0x41, 0x45, 0x4B, 0x31, ;; 3, 51
0x18, 0x14, 0x12, 0x7F, 0x10, ;; 4, 52
0x27, 0x45, 0x45, 0x45, 0x39, ;; 5, 53
0x3C, 0x4A, 0x49, 0x49, 0x30, ;; 6, 54
0x01, 0x71, 0x09, 0x05, 0x03, ;; 7, 55
0x36, 0x49, 0x49, 0x49, 0x36, ;; 8, 56
0x06, 0x49, 0x49, 0x29, 0x1E, ;; 9, 57
0x00, 0x36, 0x36, 0x00, 0x00, ;; :, 58
0x00, 0x56, 0x36, 0x00, 0x00, ;; ;, 59
0x08, 0x14, 0x22, 0x41, 0x00, ;; <, 60
0x14, 0x14, 0x14, 0x14, 0x14, ;; =, 61
0x00, 0x41, 0x22, 0x14, 0x08, ;; >, 62
0x02, 0x01, 0x51, 0x09, 0x06, ;; ?, 63
0x32, 0x49, 0x59, 0x51, 0x3E, ;; @, 64
0x7E, 0x11, 0x11, 0x11, 0x7E, ;; A, 65
0x7F, 0x49, 0x49, 0x49, 0x36, ;; B, 66
0x3E, 0x41, 0x41, 0x41, 0x22, ;; C, 67
0x7F, 0x41, 0x41, 0x22, 0x1C, ;; D, 68
0x7F, 0x49, 0x49, 0x49, 0x41, ;; E, 69
0x7F, 0x09, 0x09, 0x09, 0x01, ;; F, 70
0x3E, 0x41, 0x49, 0x49, 0x7A, ;; G, 71
0x7F, 0x08, 0x08, 0x08, 0x7F, ;; H, 72
0x00, 0x41, 0x7F, 0x41, 0x00, ;; I, 73
0x20, 0x40, 0x41, 0x3F, 0x01, ;; J, 74
0x7F, 0x08, 0x14, 0x22, 0x41, ;; K, 75
0x7F, 0x40, 0x40, 0x40, 0x40, ;; L, 76
0x7F, 0x02, 0x0C, 0x02, 0x7F, ;; M, 77
0x7F, 0x04, 0x08, 0x10, 0x7F, ;; N, 78
0x3E, 0x41, 0x41, 0x41, 0x3E, ;; O, 79
0x7F, 0x09, 0x09, 0x09, 0x06, ;; P, 80
0x3E, 0x41, 0x51, 0x21, 0x5E, ;; Q, 81
0x7F, 0x09, 0x19, 0x29, 0x46, ;; R, 82
0x46, 0x49, 0x49, 0x49, 0x31, ;; S, 83
0x01, 0x01, 0x7F, 0x01, 0x01, ;; T, 84
0x3F, 0x40, 0x40, 0x40, 0x3F, ;; U, 85
0x1F, 0x20, 0x40, 0x20, 0x1F, ;; V, 86
0x3F, 0x40, 0x38, 0x40, 0x3F, ;; W, 87
0x63, 0x14, 0x08, 0x14, 0x63, ;; X, 88
0x07, 0x08, 0x70, 0x08, 0x07, ;; Y, 89
0x61, 0x51, 0x49, 0x45, 0x43, ;; Z, 90
0x00, 0x7F, 0x41, 0x41, 0x00, ;; [, 91
0x55, 0x2A, 0x55, 0x2A, 0x55, ;; \, 92
0x00, 0x41, 0x41, 0x7F, 0x00, ;; ], 93
0x04, 0x02, 0x01, 0x02, 0x04, ;; ^, 94
0x40, 0x40, 0x40, 0x40, 0x40, ;; _, 95
0x00, 0x01, 0x02, 0x04, 0x00, ;; ', 96
0x20, 0x54, 0x54, 0x54, 0x78, ;; a, 97
0x7F, 0x48, 0x44, 0x44, 0x38, ;; b, 98
0x38, 0x44, 0x44, 0x44, 0x20, ;; c, 99
0x38, 0x44, 0x44, 0x48, 0x7F, ;; d, 100
0x38, 0x54, 0x54, 0x54, 0x18, ;; e, 101
0x08, 0x7E, 0x09, 0x01, 0x02, ;; f, 102
0x0C, 0x52, 0x52, 0x52, 0x3E, ;; g, 103
0x7F, 0x08, 0x04, 0x04, 0x78, ;; h, 104
0x00, 0x44, 0x7D, 0x40, 0x00, ;; i, 105
0x20, 0x40, 0x44, 0x3D, 0x00, ;; j, 106
0x7F, 0x10, 0x28, 0x44, 0x00, ;; k, 107
0x00, 0x41, 0x7F, 0x40, 0x00, ;; l, 108
0x7C, 0x04, 0x18, 0x04, 0x78, ;; m, 109
0x7C, 0x08, 0x04, 0x04, 0x78, ;; n, 110
0x38, 0x44, 0x44, 0x44, 0x38, ;; o, 111
0x7C, 0x14, 0x14, 0x14, 0x08, ;; p, 112
0x08, 0x14, 0x14, 0x18, 0x7C, ;; q, 113
0x7C, 0x08, 0x04, 0x04, 0x08, ;; r, 114
0x48, 0x54, 0x54, 0x54, 0x20, ;; s, 115
0x04, 0x3F, 0x44, 0x40, 0x20, ;; t, 116
0x3C, 0x40, 0x40, 0x20, 0x7C, ;; u, 117
0x1C, 0x20, 0x40, 0x20, 0x1C, ;; v, 118
0x3C, 0x40, 0x30, 0x40, 0x3C, ;; w, 119
0x44, 0x28, 0x10, 0x28, 0x44, ;; x, 120
0x0C, 0x50, 0x50, 0x50, 0x3C, ;; y, 121
0x44, 0x64, 0x54, 0x4C, 0x44, ;; z, 122
0x08, 0x7F, 0x41, 0x41, 0x00, ;; {, 123
0x00, 0x00, 0x7F, 0x00, 0x00, ;; |, 124
0x00, 0x41, 0x41, 0x7F, 0x08, ;; }, 125
0x10, 0x20, 0x10, 0x40, 0x10 ;; ~, 126
}

var word indx = 0
var byte cx, bitIdx
var bit ink
    if (ch > 31)& (ch < 127) then
        indx = indx + 5 * word(ch - 32)
        if large then
           for 5 loop
               cx = _FONT_5x7_MAP[indx]
               if ! inkColour then
                  cx = !cx
               end if
               bitIdx = 1    -- index bits of font
               for 8 loop
                   ink = ((cx & bitIdx) > 0)
                   PlotPixel(x, y, ink)
                   PlotPixel(x+1, y, ink)
                   PlotPixel(x, y+1, ink)
                   PlotPixel(x+1, y+1, ink)
                   if (bitIdx < 128) then
                      bitIdx = bitIdx * 2
                   end if
                   y = y +2
               end loop
               y = y -16
               indx = indx + 1
               x = x + 2
           end loop
        elsif ((y % 8) == 0) then   -- only on 8 boundries
            for 5 loop
                cx = _FONT_5x7_MAP[indx]
                if !inkColour then
                   cx = ! cx
                end if
                BlitColumn (x, y, cx)
                indx = indx + 1
                x = x + 1
            end loop
            if bold then
                indx = indx-5
                x = x -4
                for 4 loop
                    cx = _FONT_5x7_MAP[indx]
                        -- plot in OR mode
                    PlotColumn(x, y, cx, inkColour, false)
                    indx = indx + 1
                    x = x + 1
                end loop
                cx = _FONT_5x7_MAP[indx]
                if !inkColour then
                   cx = ! cx
                end if
                BlitColumn (x, y, cx)
            end if
        else  -- not on 8 bit boundary, so BlitColumn and PlotColumn
don't work!
            for 5 loop
               cx = _FONT_5x7_MAP[indx]
               if ! inkColour then    -- black background, white text
                  cx = !cx
               end if
               bitIdx = 1
               for 8  loop
                   ink = ((cx & bitIdx) > 0)
                   PlotPixel(x, y, ink)
                   if  bold then
                       if (inkColour & ink) then
                           PlotPixel(x+1, y, on)
                       elsif ((!inkColour) & (!ink)) then
                           PlotPixel(x+1, y, off)
                       end if
                   end if
                   if (bitIdx < 128) then
                        bitIdx = bitIdx * 2
                   end if
                   y = y +1
               end loop    -- rows of font
               y = y -8
               indx = indx + 1
               x = x+1
            end loop   -- cols of font
         end if    -- double or normal
    end if      -- characters
end procedure



-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to