Jump to content

Photo

cc65 news: OS structure


10 replies to this topic

#1 Irgendwer OFFLINE  

Irgendwer

    Stargunner

  • 1,463 posts
  • Location:Germany

Posted Tue Mar 12, 2019 3:33 PM

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<<8), 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)>>8);
	
	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.

JAI.png

 

 

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

Attached Files


Edited by Irgendwer, Tue Mar 12, 2019 3:35 PM.

  • Stephen , devwebcl , pirx and 5 others like this

#2 Yaron Nir OFFLINE  

Yaron Nir

    Chopper Commander

  • 125 posts

Posted Mon Mar 18, 2019 11:33 PM

Thanks irgendwer, any difference in performance ?
Also where can I find reference to the things I can use with the OS prefix?

#3 sanny OFFLINE  

sanny

    Moonsweeper

  • 375 posts
  • Location:Bavaria

Posted Tue Mar 19, 2019 9:48 AM

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

 

Look into include/_atarios.h.



#4 Yaron Nir OFFLINE  

Yaron Nir

    Chopper Commander

  • 125 posts

Posted Tue Mar 19, 2019 9:50 AM

Thanks sanny

#5 Irgendwer OFFLINE  

Irgendwer

    Stargunner

  • Topic Starter
  • 1,463 posts
  • Location:Germany

Posted Tue Mar 19, 2019 2:15 PM

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.atarimani...-Memory-Map.pdf

 

(Starting on page 32)


Edited by Irgendwer, Tue Mar 19, 2019 2:16 PM.


#6 Yaron Nir OFFLINE  

Yaron Nir

    Chopper Commander

  • 125 posts

Posted Wed Mar 20, 2019 7:22 AM

Thanks irgendwer, 

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



#7 Irgendwer OFFLINE  

Irgendwer

    Stargunner

  • Topic Starter
  • 1,463 posts
  • Location:Germany

Posted Wed Mar 20, 2019 1:40 PM

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, Wed Mar 20, 2019 1:43 PM.

  • Stephen and Wrathchild like this

#8 Yaron Nir OFFLINE  

Yaron Nir

    Chopper Commander

  • 125 posts

Posted Wed Mar 20, 2019 3:23 PM

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....


#9 Irgendwer OFFLINE  

Irgendwer

    Stargunner

  • Topic Starter
  • 1,463 posts
  • Location:Germany

Posted Wed Mar 20, 2019 4:00 PM

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")


  • popmilo likes this

#10 Yaron Nir OFFLINE  

Yaron Nir

    Chopper Commander

  • 125 posts

Posted Wed Mar 20, 2019 4:05 PM

yes, i've managed to fix that. i was using legacy cc65....



#11 sanny OFFLINE  

sanny

    Moonsweeper

  • 375 posts
  • Location:Bavaria

Posted Wed Mar 20, 2019 4:25 PM

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


  • Wrathchild , Irgendwer and popmilo like this




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users