News:

Let's find out together what makes a PIC Tick!

Main Menu

Problem replaceing Cdata

Started by flosigud, Sep 17, 2024, 12:29 AM

Previous topic - Next topic

flosigud

I'm converting my TFT driver for 16 bits ad I have a problem with replacing Cdata with cPtr. Below is the working 8 bit code:
bChrPtr = bChrPtr * 4 + 8 ' Each poiner is four bytes starting at address eight
wChrAddr = wFontAddress + bChrPtr '
bCOLS = cPtr8(wChrAddr) ' Width of the character
  wChrAddr = CRead wChrAddr + 1 '
wChrAddr = wChrAddr + wFontAddress ' Address of character

And the non working 16bi code:

bChrPtr = bChrPtr * 4 + 8 ' Each poiner is four bytes starting at address eight
wChrAddr = wFontAddress + bChrPtr
bCols = cPtr8(wChrAddr) ' Width of the character
Inc wChrAddr
wChrAddr = cPtr16(wChrAddr)
wChrAddr = wChrAddr + wFontAddress ' Address of character

And finallay the font header I'm trying to get past to read the character offset.

' Font header
' -----------------------------------
Arial_12: CData Byte $00,_ ' Font ID
$00,_ ' Font information:  1 bit per pixel, Characters zero degress rotation
$20, $00,_ ' First Character
$7E, $00,_ ' Last Character
$0F, $00,_ ' Height
'
' Font Glyph Table
' -----------------------------------
$03,_ '  width of the glyph
$84, $01, $00,_ ' Character - 32, offset ($00000184)
$03,_ '  width of the glyph

trastikata

#1
QuoteInc wChrAddr
wChrAddr = cPtr16(wChrAddr)

Why reading 2 bytes?

P.s. Try cPtr8 instead of cPtr16 and please give some feedback if it worked?

wChrAddr.Byte0 = cPtr8(wChrAddr)
wChrAddr.Byte1 = cPtr8(wChrAddr + 1)

Stephen Moss

It has been a while since I use the Ptr commands but instead of...
    bCols = cPtr8(wChrAddr)                        ' Width of the character
    Inc wChrAddr
    wChrAddr = cPtr16(wChrAddr)
try
    bCols = cPtr8(wChrAddr++)                        ' Width of the character
    wChrAddr = cPtr16(wChrAddr)
to post increment the address after the read in case Inc wChrAddr is not having the desired effect.

But I believe that as the cPtr8 command is used the post increment will increment the address to the next byte address and your next command is on a word value, are you sure you do not need a second byte address increment to correctly align the address to the word value, as otherwise you may be reading only have of the intended value.

flosigud

Thanks for the input. I have tried both of your suggestions and I get some random characters and part characters, as with some of the things I have previously tried. I think the problem has to do with the fact that the word I'm trying to read starts on an odd numbered byte. I get a nice capital B in correct place in one of my fonts if i Use Trasticata suggestion. I ill keep trying.

top204

#4
Below is a code listing for a demonstration of reading flash memory data tables using the cPtrX commands on a 16-bit device:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Demonstrate reading for a Flash memory data table using the cPtrX commands.
' Reads from a Flash memory data table and transmits the hexadecimal values to a serial terminal.
'
' Written by Les Johnson for the Positron16 BASIC compiler.
'
    Device = 24FJ64GA002                        ' Tell the compiler what device to compile for
    Declare Xtal = 32                           ' Tell the compiler what frequency the device is operating at (in MHz)
'
' Setup USART1
'
    Declare Hserial_Baud = 9600                 ' USART1 Baud rate
    Declare HRSOut1_Pin = PORTB.14              ' Select the pin for TX with USART1
'
' Create some variable here
'
    Dim ByteOut  As Byte
    Dim Wordout  As Word
    Dim DwordOut As Dword
    Dim wAddress As Word

'-------------------------------------------------------------------------------------------------------------
' The main program starts here
' Read and transmit (in ASCII) the data from a flash memory table
'
Main:
    Setup()                                     ' Setup the program, and any peripherals

    wAddress = AddressOf(Table_Start)           ' Load wAddress with the address of the Flash memory data table

    Wordout = cPtr16(wAddress++)                ' Read the data as 16-bits, with auto increment (low byte first)
    HRSOutLn IHex4 Wordout                      ' Transmit the 16-bits hex value

    ByteOut = cPtr8(wAddress++)                 ' Read the data as 8-bits, with Auto increment
    HRSOutLn IHex2 ByteOut                      ' Transmit the 8-bits hex value

    Wordout = cPtr16(wAddress++)                ' Read the data as 16-bits, with Auto increment (low byte first)
    HRSOutLn IHex4 Wordout                      ' Transmit the 16-bits hex value

    ByteOut = cPtr8(wAddress++)                 ' Read the data as 8-bits, with Auto increment
    HRSOutLn IHex2 ByteOut                      ' Transmit the 8-bits hex value

    DwordOut = cPtr32(wAddress++)               ' Read the data as 32-bits, with Auto increment (low byte first)
    HRSOutLn IHex8 DwordOut                     ' Transmit the 32-bits hex value
    Stop

'-------------------------------------------------------------------------------------------------------------
' Setup the program, and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    PPS_Unlock()
    PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)     ' Make PPS Pin RP14 U1TX
EndProc

'-------------------------------------------------------------------------------------------------------------
' Create a data table in flash memory
'
Table_Start: CData $01, 02,_
                   $03,_
                   $04, 05,_
                   $06,_
                   $0A, $0B, $0C, $0D

It shows the 8-bit orientation of the data items being read from the data table.

When the data in the table consists of only 8-bit values, they need to be in the correct orientation if being read as multi-byte values.

On the serial terminal, it will display:

$0201
$03
$0504
$06
$0D0C0B0A


Make sure you orientate the 8-bit values in the table into their correct format for the size of the value they represent.

Note that it is better to use the Dim As Flash mechanism for flash memory data tables, so the compiler can control where the flash memory data is stored.