Jump to content

Photo

GCC for the TI


484 replies to this topic

#476 jedimatt42 OFFLINE  

jedimatt42

    Stargunner

  • 1,857 posts
  • Location:Beaverton, OR

Posted Fri Feb 1, 2019 3:43 PM

Here is my take on bank switching in cartridge space:

https://github.com/j...cc-cartbanking/

And here is some work in progress using it:

https://github.com/jedimatt42/tipicmd


-M@

#477 ralphb OFFLINE  

ralphb

    Dragonstomper

  • 626 posts
  • Location:Germany

Posted Sat Feb 2, 2019 7:45 AM

I'm still having problems of making my own programs run.

.

#include <system.h>
#include <conio.h>
#include <string.h>  // from libc99, for later

#define printf  cprintf
#define getchar cgetc

int main(int argc, char * argv[])
{
  set_text();
  charsetlc();
  textcolor(COLOR_WHITE);
  bgcolor(COLOR_DKBLUE);
  cursor(1);

  printf("HELLO WORLD\n");
  printf("HELLO GCC\n");

  halt();
}

.

I'm compiling with:

.

arcturus ~/ti99/sdd99/demo/ > make test 
/home/ralph/ti99/gcc/bin/tms9900-gcc -I/home/ralph/ti99/gcc/include/libti99 -I/h
ome/ralph/ti99/gcc/libc99/include -c test.c -std=c99 -O2 -s -fno-builtin -o test
.o
/home/ralph/ti99/gcc/bin/tms9900-ld test.o /home/ralph/ti99/gcc/libti99/crt0_ea5
.o --section-start .text=a000 --section-start .data=2080 -M -L/home/ralph/ti99/g
cc/lib -lc -lti99 -o test.elf > ea5.map
/home/ralph/ti99/gcc/bin/elf2ea5 test.elf test.bin

.

But when I run this test.bin (an EA5 file), I only get a yellow screen, and a crash.  The testlib program in libti99 works, though.

 

Am I missing a crucial step here?  Also, why is this very simple program 4K in size?  :-o



#478 ralphb OFFLINE  

ralphb

    Dragonstomper

  • 626 posts
  • Location:Germany

Posted Sat Feb 2, 2019 8:17 AM

OK, I found even that bug, I had to swap test.o and crt0_ea5.o for the link step.  :ponder:



#479 TheBF OFFLINE  

TheBF

    Dragonstomper

  • 921 posts
  • Location:The Great White North

Posted Sat Feb 2, 2019 8:46 AM

<snip>

Also, why is this very simple program 4K in size?  :-o

 

The simple program has included some pretty sophisticated code.

printf is actually a small interpreter that understands not just quoted text but also all the escape codes and numeric formatting for different data types.

printf  is not too big but it typically calls a lot of other routines but here is a printf example:

/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.
   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */
#include <libioP.h>
#include <stdarg.h>
#include <stdio.h>
#undef printf
/* Write formatted output to stdout from the format string FORMAT.  */
/* VARARGS1 */
int
__printf (const char *format, ...)
{
  va_list arg;
  int done;
  va_start (arg, format);
  done = vfprintf (stdout, format, arg);
  va_end (arg);
  return done;
}
#undef _IO_printf
ldbl_strong_alias (__printf, printf);
/* This is for libg++.  */
ldbl_strong_alias (__printf, _IO_printf);

I don't know the TI GCC code but to give you an example of what it can become see this monster:  :)

 

https://code.woboq.o...vfprintf.c.html


Edited by TheBF, Sat Feb 2, 2019 8:52 AM.


#480 Tursi OFFLINE  

Tursi

    Quadrunner

  • 5,499 posts
  • HarmlessLion
  • Location:BUR

Posted Sat Feb 2, 2019 7:58 PM

Am I missing a crucial step here?  Also, why is this very simple program 4K in size?  :-o

 

When you start getting curious about what is taking up space in your program, that's when you start to learn about the MAP file. ;)

 

I'm assuming that will be "ea5.map" in your build there. It describes the layout of all the memory the linker assigned -- all the program, all the data, and all the variables are laid out in there. Takes a bit to learn to read it, but it's worth it.

 

(Edit: but the biggest reason is likely pulling in conio, particularly cprintf as noted. While I wrote my own conio rather than just porting a standard one (as I had to in order to be PD), it's still doing a fair bit of work and cprintf will include a lot of the other support functions. If you drop conio and use putstring() instead (from vdp.h), it will be a lot smaller. It will be smaller still if you can do without carriage returns and scrolling and just use writestring() (also from vdp.h).

 

That said, if you DO want the features of conio, there's no harm in it, and it won't grow much further. ;)


Edited by Tursi, Sat Feb 2, 2019 8:06 PM.


#481 tschak909 ONLINE  

tschak909

    River Patroller

  • 3,108 posts
  • Location:USA

Posted Sun Feb 3, 2019 12:08 AM

If you want to see an example of a larger program that uses libti99:

https://github.com/t...909/platoterm99

 

-Thom



#482 TheBF OFFLINE  

TheBF

    Dragonstomper

  • 921 posts
  • Location:The Great White North

Posted Sun Feb 3, 2019 1:32 PM

If you want to see an example of a larger program that uses libti99:

https://github.com/t...909/platoterm99

 

-Thom

 

I am curious. How big is the final binary? (I don't have GCC for TI-99)



#483 arcadeshopper ONLINE  

arcadeshopper

    River Patroller

  • 4,196 posts
  • Location:Portland, Oregon USA

Posted Sun Feb 3, 2019 1:44 PM

 
I am curious. How big is the final binary? (I don't have GCC for TI-99)

Pretty small two files one 9k and one 6k ea5 load

Sent from my LG-H872 using Tapatalk

#484 tschak909 ONLINE  

tschak909

    River Patroller

  • 3,108 posts
  • Location:USA

Posted Wed Feb 6, 2019 12:32 AM

Is there a possible compiler bug, here?

 

I have a piece of code, that works across a bunch of other compilers, some of them gcc, some others... It is code that processes incoming character set data, and shrinks the character set on the fly using image processing techniques (essentially re-plotting pixels against sets of tables, split across two different algorithms that are selected dependent on pixel density)...

 

...however on the TI, I am getting corrupted character set data, for some reason, on both TIPI and RS232 targets, so it's not mangled input (from eager translation) causing the issue...

 

Here is the original code, the relevant function is terminal_char_load() ... 

/**
 * PLATOTerm64 - A PLATO Terminal for the Commodore 64
 * Based on Steve Peltz's PAD
 *
 * Author: Thomas Cherryhomes <thom.cherryhomes at gmail dot com>
 *
 * terminal.c - Terminal state functions
 */

/* Some functions are intentionally stubbed. */
#pragma warn(unused-param, off)

#include <stdbool.h>
#include <string.h>
#include "terminal.h"
#include "screen.h"
#include "protocol.h"

/**
 * ASCII Features to return in Features
 */
#define ASC_ZFGT        0x01
#define ASC_ZPCKEYS     0x02
#define ASC_ZKERMIT     0x04
#define ASC_ZWINDOW     0x08

/**
 * protocol.c externals
 */
extern CharMem CurMem;
extern padBool TTY;
extern padBool ModeBold;
extern padBool Rotate;
extern padBool Reverse;
extern DispMode CurMode;
extern padBool FlowControl;

/**
 * screen.c externals
 */
extern unsigned char CharWide;
extern unsigned char CharHigh;
extern padPt TTYLoc;

extern unsigned char already_started;

#define FONTPTR(a) (((a << 1) + a) << 1)

// Temporary PLATO character data, 8x16 matrix
static unsigned char char_data[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                                  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

static unsigned char BTAB[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; // flip one bit on (OR)
static unsigned char BTAB_5[]={0x08,0x10,0x10,0x20,0x20,0x40,0x80,0x80}; // flip one bit on for the 5x6 matrix (OR)

static unsigned char TAB_0_5[]={0x05,0x05,0x05,0x04,0x04,0x04,0x03,0x03,0x02,0x02,0x01,0x01,0x01,0x00,0x00,0x00};
static unsigned char TAB_0_5i[]={0x00,0x00,0x00,0x01,0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04,0x04,0x05,0x05,0x05};

static unsigned char TAB_0_4[]={0x00,0x00,0x01,0x02,0x02,0x03,0x03,0x04}; // return 0..4 given index 0 to 7

static unsigned char PIX_THRESH[]={0x03,0x02,0x03,0x03,0x02, // Pixel threshold table.
                                   0x03,0x02,0x03,0x03,0x02,
                                   0x02,0x01,0x02,0x02,0x01,
                                   0x02,0x01,0x02,0x02,0x01,
                                   0x03,0x02,0x03,0x03,0x02,
                                   0x03,0x02,0x03,0x03,0x02};

static unsigned char PIX_WEIGHTS[]={0x00,0x00,0x00,0x00,0x00, // Pixel weights
                                    0x00,0x00,0x00,0x00,0x00,
                                    0x00,0x00,0x00,0x00,0x00,
                                    0x00,0x00,0x00,0x00,0x00,
                                    0x00,0x00,0x00,0x00,0x00,
                                    0x00,0x00,0x00,0x00,0x00};

static unsigned char TAB_0_25[]={0,5,10,15,20,25}; // Given index 0 of 5, return multiple of 5.

static unsigned char pix_cnt;     // total # of pixels
static unsigned char curr_word;   // current word
static unsigned char u,v;       // loop counters

extern unsigned char fontm23[768];

/**
 * terminal_init()
 * Initialize terminal state
 */
void terminal_init(void)
{
  terminal_set_tty();
}

/**
 * terminal_initial_position()
 * Set terminal initial position after splash screen.
 */
void terminal_initial_position(void)
{
  TTYLoc.x=0;
  TTYLoc.y=100; // Right under splashscreen.
}

/**
 * terminal_set_tty(void) - Switch to TTY mode
 */
void terminal_set_tty(void)
{
  if (already_started)
    screen_clear();
  TTY=true;
  ModeBold=padF;
  Rotate=padF;
  Reverse=padF;
  CurMem=M0;
  /* CurMode=ModeRewrite; */
  CurMode=ModeWrite;    /* For speed reasons. */
  CharWide=8;
  CharHigh=16;
  TTYLoc.x = 0;        // leftmost coordinate on screen
  TTYLoc.y = 495;      // Top of screen - one character height
}

/**
 * terminal_set_plato(void) - Switch to PLATO mode
 */
void terminal_set_plato(void)
{
  TTY=false;
  screen_clear();
}

/**
 * terminal_get_features(void) - Inquire about terminal ASCII features
 */
unsigned char terminal_get_features(void)
{
  return ASC_ZFGT; /* This terminal can do Fine Grained Touch (FGT) */
}

/**
 * terminal_get_type(void) - Return the appropriate terminal type
 */
unsigned char terminal_get_type(void)
{
  return 12; /* ASCII terminal type */
}

/**
 * terminal_get_subtype(void) - Return the appropriate terminal subtype
 */
unsigned char terminal_get_subtype(void)
{
  return 1; /* ASCII terminal subtype IST-III */
}

/**
 * terminal_get_load_file(void) - Return the appropriate terminal loadfile (should just be 0)
 */
unsigned char terminal_get_load_file(void)
{
  return 0; /* This terminal does not load its resident from the PLATO system. */
}

/**
 * terminal_get_configuration(void) - Return the terminal configuration
 */
unsigned char terminal_get_configuration(void)
{
  return 0x40; /* Touch panel is present. */
}

/**
 * terminal_get_char_address(void) - Return the base address of the character set.
 */
unsigned short terminal_get_char_address(void)
{
  return 0x3000; /* What the? Shouldn't this be 0x3800? */
}

/**
 * terminal_mem_read - Read a byte of program memory.
 * not needed for our terminal, but must
 * be decoded.
 */
padByte terminal_mem_read(padWord addr)
{
  return (0xFF);
}

/**
 * terminal_mem_load - Write a byte to non-character memory.
 * not needed for our terminal, but must be decoded.
 */
void terminal_mem_load(padWord addr, padWord value)
{
  /* Not Implemented */
}

/**
 * Mode5, 6, and 7 are basically stubbed.
 */
void terminal_mode_5(padWord value)
{
}

void terminal_mode_6(padWord value)
{
}

void terminal_mode_7(padWord value)
{
}

/**
 * terminal_ext_allow - External Input allowed. Not implemented.
 */
void terminal_ext_allow(padBool allow)
{
  /* Not Implemented */
}

/**
 * terminal_set_ext_in - Set which device to get input from.
 * Not implemented
 */
void terminal_set_ext_in(padWord device)
{
}

/**
 * terminal_set_ext_out - Set which device to send external data to.
 * Not implemented
 */
void terminal_set_ext_out(padWord device)
{
}

/**
 * terminal_ext_in - get an external input from selected device.
 * Not implemented.
 */
padByte terminal_ext_in(void)
{
  return 0;
}

/**
 * terminal_ext_out - Send an external output to selected device
 * Not implemented.
 */
void terminal_ext_out(padByte value)
{
}

void memset(char* buf, char val, short len)
{
  for (int i=0;i<len;++i)
    buf[i]=val;
}

/**
 * terminal_char_load - Store a character into the user definable
 * character set.
 */
void terminal_char_load(padWord charnum, charData theChar)
{
  // Clear char data.
  memset(char_data,0,sizeof(char_data));
  memset(PIX_WEIGHTS,0,sizeof(PIX_WEIGHTS));
  memset(&fontm23[FONTPTR(charnum)],0,6);
  pix_cnt=0;

  // Transpose character data.
  for (curr_word=0;curr_word<8;curr_word++)
    {
      for (u=16; u-->0; )
        {
          if (theChar[curr_word] & 1<<u)
            {
              pix_cnt++;
              PIX_WEIGHTS[TAB_0_25[TAB_0_5[u]]+TAB_0_4[curr_word]]++;
              char_data[u^0x0F&0x0F]|=BTAB[curr_word];
            }
        }
    }

  // Determine algorithm to use for number of pixels.
  // Algorithm A is used when roughly half of the # of pixels are set.
  // Algorithm B is used either when the image is densely or sparsely populated (based on pix_cnt).
  if ((54 <= pix_cnt) && (pix_cnt < 85))
    {
      // Algorithm A - approx Half of pixels are set
      for (u=6; u-->0; )
        {
          for (v=5; v-->0; )
            {
              if (PIX_WEIGHTS[TAB_0_25[u]+v] >= PIX_THRESH[TAB_0_25[u]+v])
                fontm23[FONTPTR(charnum)+u]|=BTAB[v];
            }
        }
    }
  else if ((pix_cnt < 54) || (pix_cnt >= 85))
    {
      // Algorithm B - Sparsely or heavily populated bitmaps
      for (u=16; u-->0; )
        {
          if (pix_cnt >= 85)
            char_data[u]^=0xFF;

          for (v=8; v-->0; )
            {
              if (char_data[u] & (1<<v))
                {
                  fontm23[FONTPTR(charnum)+TAB_0_5i[u]]|=BTAB_5[v];
                }
            }
        }
      if (pix_cnt >= 85)
        {
          for (u=6; u-->0; )
            {
              fontm23[FONTPTR(charnum)+u]^=0xFF;
              fontm23[FONTPTR(charnum)+u]&=0xF8;
            }
        }
    }
}

Which gets translated into the following 9900 assembler:

        pseg
        even

        def     terminal_initial_position
terminal_initial_position
        li   r1, TTYLoc
        clr  *r1+
        li   r2, >64
        mov  r2, *r1
        b    *r11
        .size   terminal_initial_position, .-terminal_initial_position
        even

        def     terminal_get_features
terminal_get_features
        li   r1, >100
        b    *r11
        .size   terminal_get_features, .-terminal_get_features
        even

        def     terminal_get_type
terminal_get_type
        li   r1, >C00
        b    *r11
        .size   terminal_get_type, .-terminal_get_type
        even

        def     terminal_get_subtype
terminal_get_subtype
        li   r1, >100
        b    *r11
        .size   terminal_get_subtype, .-terminal_get_subtype
        even

        def     terminal_get_load_file
terminal_get_load_file
        clr  r1
        b    *r11
        .size   terminal_get_load_file, .-terminal_get_load_file
        even

        def     terminal_get_configuration
terminal_get_configuration
        li   r1, >4000
        b    *r11
        .size   terminal_get_configuration, .-terminal_get_configuration
        even

        def     terminal_get_char_address
terminal_get_char_address
        li   r1, >3000
        b    *r11
        .size   terminal_get_char_address, .-terminal_get_char_address
        even

        def     terminal_mem_read
terminal_mem_read
        seto r1
        b    *r11
        .size   terminal_mem_read, .-terminal_mem_read
        even

        def     terminal_mem_load
terminal_mem_load
        b    *r11
        .size   terminal_mem_load, .-terminal_mem_load
        even

        def     terminal_mode_5
terminal_mode_5
        b    *r11
        .size   terminal_mode_5, .-terminal_mode_5
        even

        def     terminal_mode_6
terminal_mode_6
        b    *r11
        .size   terminal_mode_6, .-terminal_mode_6
        even

        def     terminal_mode_7
terminal_mode_7
        b    *r11
        .size   terminal_mode_7, .-terminal_mode_7
        even

        def     terminal_ext_allow
terminal_ext_allow
        b    *r11
        .size   terminal_ext_allow, .-terminal_ext_allow
        even

        def     terminal_set_ext_in
terminal_set_ext_in
        b    *r11
        .size   terminal_set_ext_in, .-terminal_set_ext_in
        even

        def     terminal_set_ext_out
terminal_set_ext_out
        b    *r11
        .size   terminal_set_ext_out, .-terminal_set_ext_out
        even

        def     terminal_ext_in
terminal_ext_in
        clr  r1
        b    *r11
        .size   terminal_ext_in, .-terminal_ext_in
        even

        def     terminal_ext_out
terminal_ext_out
        b    *r11
        .size   terminal_ext_out, .-terminal_ext_out
        even

        def     memset
memset
        mov  r3, r3
        jlt  L38
        jeq  L38
        clr  r4
L37
        mov  r1, r5
        a    r4, r5
        movb r2, *r5
        inc  r4
        c    r4, r3
        jne  L37
L38
        b    *r11
        .size   memset, .-memset
        even

        def     terminal_char_load
terminal_char_load
        dect r10
        mov  r9, *r10
        li   r3, char_data
L42
        clr  r4
        movb r4, *r3+
        ci   r3, char_data+16
        jne  L42
        li   r3, PIX_WEIGHTS
L43
        clr  r5
        movb r5, *r3+
        ci   r3, PIX_WEIGHTS+30
        jne  L43
        mov  r1, r12
        a    r1, r12
        a    r1, r12
        a    r12, r12
        mov  r12, r4
        ai   r4, fontm23
        clr  r1
L44
        mov  r4, r3
        a    r1, r3
        clr  r7
        movb r7, *r3
        inc  r1
        ci   r1, >6
        jne  L44
        clr  r6
        movb r7, r5
        seto r4
        li   r8, >F00
L48
        li   r3, >1000
L72
        ai   r3, >FF00
        cb   r3, r4
        jeq  L75
L46
        movb r3, r0
        srl  r0, 8
        mov  *r2, r1
        abs  r0
        jeq  $+4
        sra  r1, 0
        andi r1, >1
        abs  r1
        jeq  L72
        ai   r5, >100
        mov  r0, r7
        movb @TAB_0_5(r7), r1
        srl  r1, 8
        movb @TAB_0_25(r1), r1
        srl  r1, 8
        movb @TAB_0_4(r6), r7
        srl  r7, 8
        a    r7, r1
        li   r9, >100
        ab   r9, @PIX_WEIGHTS(r1)
        movb r3, r1
        xor  r8, r1
        srl  r1, 8
        socb @BTAB(r6), @char_data(r1)
        movb r5, r7
        ai   r3, >FF00
        cb   r3, r4
        jne  L46
L75
        inc  r6
        inct r2
        ci   r6, >8
        jeq  L47
        movb r7, r5
        jmp  L48
L47
        movb r3, @u
        movb r7, @pix_cnt
        li   r1, >800
        movb r1, @curr_word
        movb r5, r2
        ai   r2, >CA00
        ci   r2, >1EFF
        jh  L49
        li   r3, >400
        li   r2, >500
        seto r5
        li   r6, >FE00
        jmp  L53
L76
        movb r3, r4
        ai   r4, >FF00
        cb   r4, r6
        jeq  L52
        movb r3, r2
        movb r4, r3
L53
        li   r1, >500
        srl  r2, 8
        mov  r2, r4
        ai   r4, TAB_0_25
        a    r12, r2
        ai   r2, fontm23
L73
        ai   r1, >FF00
        cb   r1, r5
        jeq  L76
        movb r1, r8
        srl  r8, 8
        movb *r4, r7
        srl  r7, 8
        a    r8, r7
        cb   @PIX_WEIGHTS(r7), @PIX_THRESH(r7)
        jl  L73
        socb @BTAB(r8), *r2
        jmp  L73
L52
        movb r1, @u
        movb r1, @v
L62
        mov  *r10+, r9
        b    *r11
        b    @L77
L49
        li   r1, >F00
        li   r8, >5400
        seto r6
        jmp  L58
L79
        ai   r1, >FF00
        cb   r1, r2
        jeq  L78
L58
        cb   r5, r8
        jle  L54
        movb r1, r2
        srl  r2, 8
        inv  @char_data(r2)
L54
        li   r2, >800
        movb r1, r3
        srl  r3, 8
        mov  r3, r7
        ai   r7, char_data
        ai   r3, TAB_0_5i
L74
        ai   r2, >FF00
        cb   r2, r6
        jeq  L79
        movb r2, r0
        srl  r0, 8
        movb *r7, r4
        srl  r4, 8
        abs  r0
        jeq  $+4
        sra  r4, 0
        andi r4, >1
        abs  r4
        jeq  L74
        movb *r3, r4
        srl  r4, 8
        a    r12, r4
        mov  r0, r9
        socb @BTAB_5(r9), @fontm23(r4)
        jmp  L74
L78
        movb r1, @u
        movb r1, @v
        ci   r5, >54FF
        jle  L62
        li   r2, >500
        movb r2, r1
        seto r4
        jmp  L61
L80
        movb r1, r2
L61
        srl  r1, 8
        a    r12, r1
        ai   r1, fontm23
        movb *r1, r3
        inv  r3
        andi r3, >F800
        movb r3, *r1
        movb r2, r1
        ai   r1, >FF00
        cb   r1, r4
        jne  L80
        movb r1, @u
        mov  *r10+, r9
        b    *r11
L77
        .size   terminal_char_load, .-terminal_char_load
        even

        def     terminal_set_plato
terminal_set_plato
        clr  @TTY
        b    @screen_clear
        .size   terminal_set_plato, .-terminal_set_plato
        even

        def     terminal_set_tty
terminal_set_tty
        dect r10
        mov  r11, *r10
        movb @already_started, @already_started
        jeq  L84
        bl   @screen_clear
L84
        li   r1, >1
        mov  r1, @TTY
        clr  @ModeBold
        clr  @Rotate
        clr  @Reverse
        clr  @CurMem
        clr  @CurMode
        li   r1, >810
        movb r1, @CharWide
        swpb r1
        movb r1, @CharHigh
        clr  @TTYLoc
        li   r1, >1EF
        mov  r1, @TTYLoc+2
        mov  *r10+, r11
        b    *r11
        .size   terminal_set_tty, .-terminal_set_tty
        even

        def     terminal_init
terminal_init
        b    @terminal_set_tty
        .size   terminal_init, .-terminal_init
        cseg

        even
char_data
        bss 16

        even
PIX_WEIGHTS
        bss 30
        pseg
        .type   TAB_0_5, @object
        .size   TAB_0_5, 16
TAB_0_5
        byte    5
        byte    5
        byte    5
        byte    4
        byte    4
        byte    4
        byte    3
        byte    3
        byte    2
        byte    2
        byte    1
        byte    1
        byte    1
        byte    0
        byte    0
        byte    0
        .type   TAB_0_25, @object
        .size   TAB_0_25, 6
TAB_0_25
        byte    0
        byte    5
        byte    10
        byte    15
        byte    20
        byte    25
        .type   TAB_0_4, @object
        .size   TAB_0_4, 8
TAB_0_4
        byte    0
        byte    0
        byte    1
        byte    2
        byte    2
        byte    3
        byte    3
        byte    4
        .type   BTAB, @object
        .size   BTAB, 8
BTAB
        byte    -128
        byte    64
        byte    32
        byte    16
        byte    8
        byte    4
        byte    2
        byte    1
        .type   PIX_THRESH, @object
        .size   PIX_THRESH, 30
PIX_THRESH
        byte    3
        byte    2
        byte    3
        byte    3
        byte    2
        byte    3
        byte    2
        byte    3
        byte    3
        byte    2
        byte    2
        byte    1
        byte    2
        byte    2
        byte    1
        byte    2
        byte    1
        byte    2
        byte    2
        byte    1
        byte    3
        byte    2
        byte    3
        byte    3
        byte    2
        byte    3
        byte    2
        byte    3
        byte    3
        byte    2
        .type   TAB_0_5i, @object
        .size   TAB_0_5i, 16
TAB_0_5i
        byte    0
        byte    0
        byte    0
        byte    1
        byte    1
        byte    1
        byte    2
        byte    2
        byte    3
        byte    3
        byte    4
        byte    4
        byte    4
        byte    5
        byte    5
        byte    5
        .type   BTAB_5, @object
        .size   BTAB_5, 8
BTAB_5
        byte    8
        byte    16
        byte    16
        byte    32
        byte    32
        byte    64
        byte    -128
        byte    -128
        cseg

        even
pix_cnt
        bss 1

        even
curr_word
        bss 1

        even
u
        bss 1

        even
v
        bss 1

        ref     TTYLoc

        ref     CharHigh

        ref     CharWide

        ref     CurMode

        ref     CurMem

        ref     Reverse

        ref     Rotate

        ref     ModeBold

        ref     TTY

        ref     screen_clear

        ref     already_started

        ref     fontm23


...anything hinky?

 

-Thom



#485 tschak909 ONLINE  

tschak909

    River Patroller

  • 3,108 posts
  • Location:USA

Posted Sat Feb 9, 2019 12:26 PM

I'm definitely seeing bugs when doing bitwise manipulations with variables that are unsigned chars, I suspect there is some data type promotion to int happening, as changing my padRGB elements for red green and blue from unsigned char to int suddenly made my color mapping code work properly...

 

...character set loading is still messed up...

/**
 * terminal_char_load - Store a character into the user definable
 * character set.
 */
void terminal_char_load(padWord charnum, charData theChar)
{
  // Clear char data.
  memset(char_data,0,sizeof(char_data));
  memset(PIX_WEIGHTS,0,sizeof(PIX_WEIGHTS));
  memset(&fontm23[FONTPTR(charnum)],0,6);
  pix_cnt=0;
 
  // Transpose character data.
  for (curr_word=0;curr_word<8;curr_word++)
    {
      for (u=16; u-->0; )
        {
          if (theChar[curr_word] & 1<<u)
            {
              pix_cnt++;
              PIX_WEIGHTS[TAB_0_25[TAB_0_5[u]]+TAB_0_4[curr_word]]++;
              char_data[u^0x0F&0x0F]|=BTAB[curr_word];
            }
        }
    }
 
  // Determine algorithm to use for number of pixels.
  // Algorithm A is used when roughly half of the # of pixels are set.
  // Algorithm B is used either when the image is densely or sparsely populated (based on pix_cnt).
  if ((54 <= pix_cnt) && (pix_cnt < 85))
    {
      // Algorithm A - approx Half of pixels are set
      for (u=6; u-->0; )
        {
          for (v=5; v-->0; )
            {
              if (PIX_WEIGHTS[TAB_0_25[u]+v] >= PIX_THRESH[TAB_0_25[u]+v])
                fontm23[FONTPTR(charnum)+u]|=BTAB[v];
            }
        }
    }
  else if ((pix_cnt < 54) || (pix_cnt >= 85))
    {
      // Algorithm B - Sparsely or heavily populated bitmaps
      for (u=16; u-->0; )
        {
          if (pix_cnt >= 85)
            char_data[u]^=0xFF;
 
          for (v=8; v-->0; )
            {
              if (char_data[u] & (1<<v))
                {
                  fontm23[FONTPTR(charnum)+TAB_0_5i[u]]|=BTAB_5[v];
                }
            }
        }
      if (pix_cnt >= 85)
        {
          for (u=6; u-->0; )
            {
              fontm23[FONTPTR(charnum)+u]^=0xFF;
              fontm23[FONTPTR(charnum)+u]&=0xF0;
            }
        }
    }
}

If I comment out the calls which XOR char_data[], then character set loading MOSTLY works, (but sparsely populated bitmaps do not get correctly transformed, because the algorithm removes too many pixels).

 

I'm really frustrated here, because i'm wondering if I need to give myself a crash course in compiler design to fix this...

 

-Thom






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users