Jump to content
IGNORED

cc65 news: OS structure


Recommended Posts

If you are tired of using "Peeks and Pokes" in C source files to fiddle with OS locations, then the current build of cc65 brings relief:

Just use the global structure "OS" and the usual location names to access the variables.

 

Here a small demo program:

// A simple optical illusion programm
// for the Atari 8-bit computers
// (c) 2019 Ch. "Irgendwer" Krüger

#include <atari.h>
#include <conio.h>
#include <unistd.h>
#include <string.h>

#define ScreenMemory		(void *)(0x2000)
#define DisplayListMemory	(void *)(0x2700)
#define CharsetMemory 		(unsigned char *)(0x2800)
#define PAL_MAGENTA			HUE_ORANGE

#define MIX(a,b,c,d)  (((a)<<6)|((b)<<4)|((c)<<2)|(d))

unsigned char FontData[] = {MIX(0,0,0,0),
							MIX(0,0,0,2),
							MIX(0,0,2,1),
							MIX(0,2,1,3),
							MIX(0,2,1,3),
							MIX(0,2,1,3),
							MIX(0,0,2,1),
							MIX(0,0,0,2),

							MIX(0,0,0,0),
							MIX(2,2,0,0),
							MIX(1,1,2,0),
							MIX(3,3,1,2),
							MIX(3,3,1,2),
							MIX(3,3,1,2),
							MIX(1,1,2,0),
							MIX(2,2,0,0),

							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(0,0,3,3),
							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(0,0,0,0),

							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(3,0,0,0),
							MIX(3,0,0,0),
							MIX(3,3,3,0),
							MIX(3,0,0,0),
							MIX(3,0,0,0),
							MIX(0,0,0,0),

							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(0,0,0,0),
							MIX(0,0,0,0)													
							}; 


// Screen layout:
//							
//            111111111122222222223333333333 
//  0123456789012345678901234567890123456789
// "                   ab                   "		// 0
// "              ab        ab              "		// 1
// "                                        "		// 2
// "          ab                ab          "		// 3
// "                                        "		// 4
// "         ab        cd        ab         "		// 5
// "                                        "		// 6
// "          ab                ab          "		// 7
// "                                        "		// 8
// "              ab        ab              "		// 9
// "                   ab                   "		// 10

unsigned char PositionsX[] = { 19, 24, 28, 29, 28, 24, 19, 14, 10, 9, 10, 14, 19, 24};
unsigned char PositionsY[] = {  0,  1,  3,  5,  7,  9, 10,  9,  7, 5,  3,  1,  0,  1};

unsigned char EmptySpace[] = "ee";
unsigned char Cross[] = "cd"; 
unsigned char PinkDot[] = {'a'+128, 'b'+128, 0}; 
unsigned char Label[] = "JUST AN ILLUSION";

void DisplayList =
{
	DL_BLK8,
	DL_BLK8,
	DL_BLK4,
	DL_LMS(DL_CHR40x16x4),
	ScreenMemory,
	DL_CHR40x16x4,
	DL_CHR40x16x4,
	DL_CHR40x16x4,
	DL_CHR40x16x4,
	DL_CHR40x16x4,
	DL_CHR40x16x4,
	DL_CHR40x16x4,
	DL_CHR40x16x4,
	DL_CHR40x16x4,
	DL_CHR40x16x4,
	DL_BLK8,
	DL_CHR40x8x1,
	DL_JVB
};


void wait(unsigned char fiftiesthseconds)
{
	unsigned char goalVcount = ANTIC.vcount;

	do
	{
		while (ANTIC.vcount == goalVcount);
		while (ANTIC.vcount != goalVcount);
		--fiftiesthseconds;
	}
	while (fiftiesthseconds);
}


int
main(void)
{
	memset(ScreenMemory, 0, 11*40);			                // clear screen
	memcpy(DisplayListMemory, &DisplayList, sizeof(DisplayList));	// DL to target address
	memcpy(CharsetMemory, (void*)(OS.chbas<<, 1024);		// copy font and
	memcpy(CharsetMemory + 97*8, FontData, sizeof(FontData));	// patch it (97 = 'a' internally)

	OS.savmsc = ScreenMemory;
	OS.color0 = _gtia_mkcolor(PAL_MAGENTA, 4);
	OS.color1 = _gtia_mkcolor(PAL_MAGENTA, 5);
	OS.color2 = COLOR_BLACK;
	OS.color3 = _gtia_mkcolor(PAL_MAGENTA, 2);
	OS.color4 = _gtia_mkcolor(HUE_GREY,5);

	// center cross
	cputsxy(19,5, Cross);
	// label...
	cputsxy(12,11, Label);
	
	OS.sdlst = DisplayListMemory;
	OS.chbas = (((unsigned int)CharsetMemory)>>;
	
	do
	{
		unsigned char index0 = 0;
		unsigned char index1 = 1;
		unsigned char index2 = 2;	
		do
		{
			cputsxy(PositionsX[index0], PositionsY[index0], PinkDot);
			cputsxy(PositionsX[index1], PositionsY[index1], EmptySpace);
			cputsxy(PositionsX[index2], PositionsY[index2], PinkDot);
			wait(4);
			++index0;
			++index1;
			++index2;
		}
		while (index2 < sizeof(PositionsX));
	}
	while (1);

	return 0;
}

You can build the program above (if you call the code file "main.c") with:

cl65 -Cl -O --start-addr 0x3000 -t atari main.c -o jaillu.xex

To 'watch' this demo just focus the cross in the middle and watch how a non-existing greenish dot appears and pink dots seem to vanish.

post-7778-0-84641900-1552426043.png

 

 

(The effect is quite popular and was already used in the demo "Optical" (http://a8.fandal.cz/detail.php?files_id=6624)).

jaillu.xex

Edited by Irgendwer
  • Like 10
  • Thanks 1
Link to comment
Share on other sites

Thanks irgendwer, any difference in performance ?

 

No, access by structure is as fast as direct peek/poke or load/store from/to the address in assembler.

 

Also where can I find reference to the things I can use with the OS prefix?

 

Sanny already answered.

 

In general all OS locations up to page 6 are available now. The names are the usual ones you find in the system reference manual/OS source code.

In "Mapping the Atari" they are a little bit scattered, so in "De Re Atari" or "Atari System Reference Manual".

 

 

Best source for a consecutive list of locations and their meaning in English I found is:

 

http://www.atarimania.com/documents/The-Mastery-Memory-Map.pdf

 

(Starting on page 32)

Edited by Irgendwer
Link to comment
Share on other sites

are you part of the CC65 developers? or just a really good high end user? :)

 

I'm contributing (like the OS structure) from time to time to cc65. Actually this "idea" was more than 8 years old, but some things take longer...

 

Another "not that old" change was the introduction of the keyboard codes, so that you can write:

    while (!kbhit());
    switch (OS.ch)
    {
        case KEY_RETURN:
        ...
        case KEY_SPACE:
        ...
        case KEY_1:
        ...
        case KEY_W:
        ... 
    }

- you may find that useful too...

 

Edit: I like to use the opportunity to thank "sanny" - he has the doubtful privilege to review my changes targeting the Atari. Thanks for that!

Edited by Irgendwer
  • Like 2
Link to comment
Share on other sites

issues while compiling:

 

main.c(14): Error: Undefined symbol: `DL_BLK8'
main.c(14): Error: Constant expression expected
main.c(15): Error: Constant expression expected
main.c(16): Error: Undefined symbol: `DL_BLK4'
main.c(16): Error: Constant expression expected
main.c(17): Error: Call to undefined function `DL_LMS'
main.c(17): Error: Undefined symbol: `DL_CHR40x16x4'
main.c(17): Error: Constant expression expected
main.c(18): Error: Undefined symbol: `ScreenMemory'
main.c(18): Error: Constant expression expected
main.c(19): Error: Constant expression expected
main.c(19): Fatal: Too many errors
i have the same includes as your demo has....
Link to comment
Share on other sites

issues while compiling:

...

 

The reason is the outdated version from the legacy project page:

 

https://www.cc65.org/

 

Please use the active project page:

 

https://cc65.github.io/

 

where Windows users can find also a "Windows Snapshot" containing binaries.

 

Other versions have to be build on your own! (via https://github.com/cc65/cc65"Clone or download")

  • Like 1
Link to comment
Share on other sites

Edit: I like to use the opportunity to thank "sanny" - he has the doubtful privilege to review my changes targeting the Atari. Thanks for that!

 

Thanks :-)

 

I'm open to any contribution which improves the Atari (and Atari5200) support. And you did a good job!

 

regards,

chris

  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...