Jag 256

Let's get coding!

Moderator: a31chris

Post Reply
User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Jag 256

Post by a31chris » Fri Feb 21, 2014 7:40 am

This thread is for a discussion of Belboz's Jag256 program. This is a quick demonstration program that Mike Hill(Belboz) put together to demonstrate how the Atari Jaguar sets up a simple graphics display.

http://www.hillsoftware.com/files/atari ... jag256.zip

This thread will not include a listing or discussion of the font.h program.

jag.c

Code: Select all

/******************************************************************************
  jag.c 
  
  Copyright (C) 2005 Michael Hill
  
  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 program 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 General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  ***************************************************************************
***/
  
  /******************************************************************************
  This code will setup the jag for a 320 X 200 X 256 color display. 
  
  The startup.s file is a basic standard Atari sample file.  It has been edited
  for our video settings, it jumps to our main() routine in this file.  The 
  startup.s file also includes the raw image that is displayed on the screen.
  
  This file has routines to do some SIMPLE text output on the screen.  It also
  handles setting the CLUT on the Jag to the palette values contained in pal16.h
  
  font.h contains a simple character font.
  
  Upon execution the code displayes the image stored in pic.raw using the color
  palette values in pal16.h and displays some text in a couple sizes and colors
  using the text routines.
  
  It then goes into an infinite loop.
  
  To compile type "make".  
  
  Load the code into address $4000 and execute from there also.
  
  ***************************************************************************
***/
  
  #include"pal16.h"
  #include"font.h"
  
  extern void *vidmem;
  unsigned char *jagscreen;
  
  unsigned char shift[] = { 7, 6, 5, 4, 3, 2, 1, 0 };
  int TextSize=1,TextColor=2;
  
  void DrawCharLine (int charloc, int screenloc)
  {
    int xcnt;
    int xsize;
  
    for (xcnt = 0; xcnt < F_WIDTH; xcnt++) {
      if (((textfont[charloc] >> shift[xcnt]) & 0x1)) {
        for (xsize = 0; xsize < TextSize; xsize++)
              jagscreen[screenloc++] = TextColor;
      }
      else {
        for (xsize = 0; xsize < TextSize; xsize++) {
              /*if (!Transparency)
                jagscreen[screenloc++] = 0;
              else
                jagscreen[screenloc++] = 1;*/
                screenloc++;
        }
      }
    }
  }
  
  void DrawChar (int x, int y, char ch)
  {
    int ycnt, charloc, screenloc;
    int ysize;
  
    charloc = ch * F_CHARSIZE;
  
    screenloc = (y * T_XREZ) + x;
  
    for (ycnt = 0; ycnt < F_HEIGHT; ycnt++) {
      for (ysize = 1; ysize <= TextSize; ysize++) {
        DrawCharLine (charloc, screenloc);
        screenloc += T_XREZ;
      }
      charloc++;
    }
  }
  
  void DrawString (int x, int y, char *str)
  {
    int cnt;
  
    for (cnt = 0; str[cnt] != 0; cnt++) {
      DrawChar (x, y, str[cnt]);
      x += (F_WIDTH * TextSize);
    }
  }
  
  
  void __main(void) {
    jagscreen = (unsigned char *)&vidmem;
  
    TextColor = 1;
  
    DrawString(10,10,"Atari Jaguar");
  
    TextColor = 45;
    TextSize  = 3;
  
    DrawString(70,100,"Hot Chicks");
  
    for(;;); /* Infinite loop added so BJL users dont hit illegal instruct*/
    asm(" illegal");
  }
  
  void SetPallete(void) {
    int x;
    unsigned long add=0xf00400;
  
    for(x=0;x<256;x++) {
      *(unsigned short int *) add = pallete[x];
      add+=2;
    }
   }
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: Jag 256

Post by a31chris » Fri Feb 21, 2014 7:40 am

pal16.h

Code: Select all

unsigned short int pallete[]={
0x0000,
0xffff,
0x418d,
0xf6b3,
0xdad0,
0x93dc,
0xe45c,
0x6a93,
0xeda6,
0x7b58,
0xcbd3,
0x5a93,
0xc51b,
0x6b16,
0x0841,
0x2107,
0x1083,
0x18c5,
0x318b,
0xbe22,
0x9d26,
0x7c1f,
0x0041,
0x10c5,
0x18c7,
0xf7fd,
0x0883,
0xa66b,
0x9f6b,
0x6b5a,
0xa6ec,
0x21ca,
0x84a2,
0x2c94,
0x3d18,
0x4d9c,
0x4456,
0x54da,
0x8f2b,
0x5418,
0x3352,
0x5d1e,
0x2412,
0x3ddc,
0x461e,
0x5de0,
0x4314,
0x649e,
0x1b0e,
0x8f6d,
0x6d62,
0x5662,
0x6623,
0x97b0,
0x8f2d,
0x976f,
0x3a10,
0x4661,
0x4ea3,
0x5e64,
0x6e65,
0x9f70,
0x0a0a,
0x7f6d,
0x8f6f,
0x86aa,
0x8eed,
0x972f,
0x7da6,
0x56e6,
0x1107,
0x7f2d,
0x220d,
0xa731,
0x8d26,
0xa5ec,
0x4ea5,
0x1a0c,
0x198a,
0x876f,
0x86ec,
0x8f2f,
0x7e6a,
0x8eac,
0x96ef,
0x9e2c,
0x95a9,
0x3662,
0x4f28,
0x66e9,
0x77af,
0x76eb,
0x97b3,
0x9ff5,
0xa6f0,
0xb6f2,
0x676c,
0x776d,
0x8fb2,
0x872f,
0x1949,
0x8eef,
0x9731,
0xa6af,
0xae6f,
0x7fb1,
0x97f5,
0x8f71,
0x86ad,
0x8e6c,
0xbfb7,
0xbeb2,
0x0947,
0x86ef,
0x9fb5,
0x9f73,
0x96af,
0xc736,
0x8ff5,
0x97b5,
0x9ff7,
0xa7b6,
0x97f7,
0xaff8,
0xd778,
0xa7f8,
0x9fb7,
0xdfbb,
0x8f75,
0x97b7,
0x9ff9,
0xb7fa,
0xaffb,
0xafb9,
0xa7fb,
0xefbc,
0xb7bb,
0xc7fd,
0xcffd,
0xeffe,
0x0885,
0xb7fd,
0x0043,
0x1909,
0x10c7,
0xf7ff,
0x214a,
0x298d,
0x5ad7,
0xe77a,
0x1087,
0x0003,
0x0845,
0x318e,
0xf7bf,
0xef7d,
0x20c9,
0xd674,
0xdeb7,
0x0803,
0x1887,
0xff7f,
0xeef9,
0xa467,
0xbd2d,
0xd5f3,
0xf73c,
0x1045,
0xacea,
0xf6fb,
0x9423,
0x314c,
0x7b9d,
0xde35,
0xc5af,
0x6193,
0x69d5,
0x7217,
0x6993,
0x7a17,
0x6151,
0x79d5,
0x61d3,
0x7257,
0x590e,
0x594f,
0x7151,
0x8217,
0x494d,
0x59d1,
0x6a55,
0x8a17,
0x6191,
0x9259,
0x69d3,
0x7215,
0x7a57,
0x49cf,
0x614f,
0x40ca,
0x81d5,
0x71d3,
0x30c8,
0x2087,
0x5a13,
0x7a15,
0x8257,
0x390a,
0x72d9,
0x6990,
0x9217,
0x9a99,
0xa2db,
0x92d9,
0xcc66,
0x8215,
0x8a57,
0xc3e2,
0x4a52,
0x8a15,
0x410b,
0xb35f,
0xa35d,
0x9b5d,
0x7255,
0x82d8,
0x518f,
0xb3a0,
0x7a54,
0x8a55,
0x6211,
0x931b,
0xab9e,
0x6253,
0x4887,
0x1043,
0x7212,
0xa31b,
0xb422,
0x5909,
0x614c,
0x1885,
0x7296,
0x8295,
0x8b19,
0x9b9e,
0x8252,
0x71d0,
0x8b5b,
0x0801,
0x6a95,
0xffff,
0x1085,
0x0843,
0x0001,
0xffff
};
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: Jag 256

Post by a31chris » Fri Feb 21, 2014 7:41 am

In this _vidmem defining a space of 64kbits is commented out. Earlier the vidmem is defined as this:

Code: Select all

_vidmem:        .incbin "pic.raw"
So this automatically sets the pictures as background?
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: Jag 256

Post by a31chris » Fri Feb 21, 2014 7:43 am

Tursi wrote:Nothing is automatic on the Jaguar. All this does is include the file "pic.raw", as binary data, at this point in the output file.

The assembly language function titled "; Write a standard BITMAP object" writes a bitmap object to the OP which includes a pointer to this data. That makes the picture show up (assuming pic.raw is in the right format (ie: color depth and mode) for the bitmap object).

This makes the label available to other modules for linking: .globl _vidmem

And this line in the C code references that label to get the address into a variable: jagscreen = (unsigned char *)&vidmem;

Note that there's no underscore in the C version of the name. The C compiler adds the underscore when it compiles to assembly.

With the address loaded into jagscreen by that line, all the other C code writes directly into the buffer, which will overwrite the picture as needed.

What do you think would happen if we compiled this program to run from cartridge?
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: Jag 256

Post by a31chris » Fri Feb 21, 2014 7:47 am

Wozencl wrote:I'll give it a go using my basic understanding...

Code: Select all

 

void SetPallete(void) {
    int x; 
    unsigned long add=0xf00400 -  Value representing the start address of the Jag's Colour Look-Up Table (CLUT). 
  
    for(x=0;x<256;x++) {  - Run the following 256 times.
      *(unsigned short int *) add = pallete[x]; - Casts add to a short  and pointer then sets it according to the value held in element x in palette. 
      add+=2; - Increment add by 2, or 16 bits. Means on the next iteration we'll be getting our next colour from the table.
    }
   }
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: Jag 256

Post by a31chris » Fri Feb 21, 2014 7:51 am

Tursi wrote:
JagChris wrote:Found setpalette but not sure what's its doing. I need some instruction on that. And as for the original question, I dont know. You can let me off the hook anytime now.
Sorry, I missed your last reply. You were correct - the image being overwritten would be in ROM. So you'd get the picture on screen, but nothing drawn overtop of it.

Set palette just copies the palette from the program memory to the dedicated address on the Jaguar for palettes, also called the CLUT as wozencl posted. CLUT just stands for Color Look Up Table, and is another common term.

His description is close - adding 2 to 'add' updates the destination of the write, not the source. The source of the copy is "pallete[x]", where pallete will be an array in the program somewhere.
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

User avatar
a31chris
Jaguar MOD
Posts: 894
Joined: Mon Apr 01, 2013 7:09 am

Re: Jag 256

Post by a31chris » Fri Feb 21, 2014 7:55 am

Belboz wrote:Those are the 256 color values for each palette entry.
256 buckets of paint with those numbers being the "color" of paint in them
pic.raw is the image. It is 64000 bytes. 320x200 picture (320 times 200 is 64000).
First byte in pic.raw is which color register to use to draw the top left pixel of the screen.
Next 319 bytes are the colors for the next 319 pixels of the top line
What came after the Jaguar was the PS1 which for all it's greatness, ushered in corporate development and with it the bleached, repetitive, bland titles which for the most part we're still playing today. - David Wightman

Post Reply