Textmode Sideways Scroller

Since we do not have native C compilers on the Oric, this forum will be mostly be used by people using CC65 or the OSDK. But any general C related post will be welcome !
User avatar
Badger
Pilot Officer
Posts: 84
Joined: Sat Sep 22, 2018 10:04 am
Location: Wigan, England

Textmode Sideways Scroller

Post by Badger »

Hi all,

Firstly, thankyou for providing and letting me join this forum. My mother recently moved house and I re-aquired my old Oric-1 from her attic.
This awakened a desire to see if I could still remember things from way back when.

I had always wanted to create a sideways scrolling shoot-em-up like harrier attack or scramble but I could only program in Basic at the time, so it was impractical.

Forward to now - could I learn assembler? Well it turns out I had no immediate need to, since the OSDK kindly let me code in C. I am not ruling out the possibility of dabbling later.

In a couple of hours I created a rudimentary text-mode scroller with a ship (if ships are shaped like the letter 'A') with movement (A,Z,K,L keys).

The code is probably very ugly, but it works. However, I do have a couple of questions.

1) The generate_terrain/next_mountain routines use a 'for' loop to plot blocks in columns in a screen buffer.

bufferstart is the memory location of a slice of ram I use to store a copy of screen data. This is updated and a memcopy is used to transfer that data to the screen ram.

Code: Select all

hgt =26- lastheight; // height of mountain
			for (n=26;n>27-maxheight;n--) 
				{
					if (n>hgt)
					{
						poke(bufferstart+39+n*40,128);	// add block characters to end column
					}
					else
					{
						poke(bufferstart+39+n*40,32);	 // add blank characters to end column
					}
				}
}
Is this the optimum way or am I missing something?

2) I would like to add in-game music as well as SFX at some point. Is this practical or would I be asking too much of the Oric.

GitHub repository here for source code and tap files etc
https://github.com/BadgeOric/Sideways

Thanks for reading and I hope I can do something with this just for my own satisfaction and pleasure.

Badger.
flag_uk Amateurs built the Ark, Professionals built the Titanic.
User avatar
waskol
Flight Lieutenant
Posts: 414
Joined: Wed Jun 13, 2007 8:20 pm
Location: FRANCE, Paris

Re: Textmode Sideways Scroller

Post by waskol »

There is a sideway scrolling in the BomberZ sample program.
Although BomberZ is in BASIC, the scroll part is in assembly (well, it's a sequence of DATA in BomberZ).
You can copy this part and reuse it.

It comes from the french book, "Oric Atmos, vos programmes", available in the Defence force Library.

In the book, BomberZ is called "Mission Bombardement", pages 65-71

COmment p71, translated into english
The machine code routine can be used in another game. A first part of DATA given
at the beginning of the program plus a second one from line 100 to 130 (POKE from #400 to #48D)
in charge of placing the routine at the good address location in Oric memory.
The routine can be used in 2 ways :
- with DOKE 0,#BBA9:DOKE 2,#BBA8:CALL#400
we obtain a scrolling from right to left.
- with CALL#431 instea, you obtain a scrolling from right to left
plus the display of 2 characters whose ASCII value must be set at the
beginning of your game at #4FD and #4FF. More over, used in this way,
this routine handles your keyboard input and moves the characters accordingly.
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Textmode Sideways Scroller

Post by Dbug »

So, regarding your routines, there's rarely an "optimal way" of doing things, in your particular case, the killer is the "n*40" which the compiler will not optimize for you.

What I suggest instead of

Code: Select all

for (n=26;n>27-maxheight;n--) 
{
	if (n>hgt)
	{
	poke(bufferstart+39+n*40,128);	
	}
	else
	{
		poke(bufferstart+39+n*40,32);	 // add new characters to ernd column
	}
}
is to use a pointer and change the value:
char* writePtr=(unsigned char*)bufferstart+39+26*40;

Code: Select all

for (n=26;n>27-maxheight;n--) 
{
	if (n>hgt)
	{
		*writePtr=128;	
	}
	else
	{
		*writePtr=32;
	}
	writePtr-=40;
}
Generally speaking, "peek" and "poke" are there to help transitioning for people coming from BASIC, but they should not be used if not necessary.
Using real pointers to char instead of integer, is generally a good idea :)

For the sound, well, there are many possibilities, it's definitely something the Oric can do, just look at recent games from Chema or Twilighte, or the Defence-Force demos.
User avatar
Badger
Pilot Officer
Posts: 84
Joined: Sat Sep 22, 2018 10:04 am
Location: Wigan, England

Re: Textmode Sideways Scroller

Post by Badger »

Thankyou both waskol and Dbug for the replies.

Waskol:
I looked at the bomber example which is similar to the eliminator code in "Meteoric Programming" - ie basic with some machine code thrown in to speed
things up. The reason I didn't use the code is purely personal , as I wanted to see if I could acheive the effect myself without using a pre-written routine.

Having said that , once I have worked out the mechanics of how it works in my head, I am not averse to re-using useful routines. So probably , some future version will use the bomber code.

Dbug:
Thats great. I don't know why I didn't use that initially. Its so obvious now.

The peek and poke were only used to start off with to get the program up and running, I was trying to stay clear of any oric specific commands as much as I could. I will work on replacing them all when work and wife allow :D

Badger
flag_uk Amateurs built the Ark, Professionals built the Titanic.
User avatar
Badger
Pilot Officer
Posts: 84
Joined: Sat Sep 22, 2018 10:04 am
Location: Wigan, England

Re: Textmode Sideways Scroller

Post by Badger »

A bit of an update, if anyone is interested.

Re-wrote a lot of the code to remove most of the Oric specific calls (a couple left to go) and did some tidying of some routines as per Dbug's hints above.

Added a graphic for the ship (now a helicopter) and basic animation of it.

Please feel free to copy, steal, laugh at me for all the basic errors and bas code :D , but this is fun . I only wish I could have done it 35 years ago.
SIDEWA.tap
Current latest version of TAP file.
(5.54 KiB) Downloaded 335 times
The source is at the github repository in the original post.
flag_uk Amateurs built the Ark, Professionals built the Titanic.
User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Textmode Sideways Scroller

Post by Chema »

It looks nice! Congratulations!

I had some squares appearing on the top row (occasionally) and maybe you'd like to configure the keyboard reading delay and repetition rate (as was done from BASIC-see the manual), but the demo is already looking good and the helicopter graphic is nice indeed.

Now you are trapped into retro-programming. The next step will be digging into assembly code. When you see that scroll moving 10x faster with a code which is 1/10 in size, you'll be hooked forever :twisted:
User avatar
Badger
Pilot Officer
Posts: 84
Joined: Sat Sep 22, 2018 10:04 am
Location: Wigan, England

Re: Textmode Sideways Scroller

Post by Badger »

Thanks Chema,

Learning assembly at some point is my goal, which once this project is done I will probably look at converting it piece by piece, borrowing others code, seeing how it works etc.

The keyboard delay and the occaisional block on the top line (which is actually the cursor flash) and a couple of other bits (keyclicks, some colour and getting rid of the "oops you hit a mountain!" line :) )

Still a long way off and lots to do, but if I spend a little time daily it will progress. I've waited 35 years to do this, I'm sure a couple of months more will be fine :)

Ian
flag_uk Amateurs built the Ark, Professionals built the Titanic.
User avatar
Dbug
Site Admin
Posts: 4437
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Textmode Sideways Scroller

Post by Dbug »

A "soft" way to learn assembler is to look in your osdk/temp folder for the content of the "linked.s", it's basically the output of the C compiler.

You will experience multiple-phases of enlightment:
1) Duh, what's that shit, don't understand anything, is that magic incantations????
2) Oh, I see, I can find the name of the various functions, main, doSomething, _printf, etc...
3) Ha, yeah, make sense, "y" is used to access the parameters, load this, save there, not sure what this thing does, but that looks like a loop
4) Yeah, I understand everything, makes sense, direct mapping from C to assembler. Gotcha
5) OH MY GOD; THIS CODE IS HORRIBLE; SLOW AS HELL; HELP ME!!!!!
User avatar
waskol
Flight Lieutenant
Posts: 414
Joined: Wed Jun 13, 2007 8:20 pm
Location: FRANCE, Paris

Re: Textmode Sideways Scroller

Post by waskol »

:mrgreen: I definetly recognize myself in this.
User avatar
Chema
Game master
Posts: 3013
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Textmode Sideways Scroller

Post by Chema »

Lol Dbug. Exactly my experience with pinforic... then I went and learn assembly :lol:
User avatar
ibisum
Wing Commander
Posts: 1643
Joined: Fri Apr 03, 2009 8:56 am
Location: Vienna, Austria
Contact:

Re: Textmode Sideways Scroller

Post by ibisum »

This is brilliant! Nice work! I was pretty surprised at how concise the C code ended up being .. very inspiring.
User avatar
Badger
Pilot Officer
Posts: 84
Joined: Sat Sep 22, 2018 10:04 am
Location: Wigan, England

Re: Textmode Sideways Scroller

Post by Badger »

Confused of England writes :-

Writing the keyboard handling routine is causes me problems.

Here is some test code that produces odd results.

Code: Select all

#include<lib.h>

int touch;
char *keyPtr;



void main()
{
	keyPtr=(char*)520; //mem location for keyboard scanning
	while(1)
	{
	touch=*keyPtr; 
	if(touch!=56) // 56 seems to be no key press and this works
		{
			printf("touch = %d     \n",touch);  //pressing 'A' key gives me a value of 82
			if (touch==82)
				{
					printf("A");  //this never happens 
				}  
			printf("touch+1 = %d    \n",touch+1); // odd result  82+1=81!!!!!
		}
	}
}
Just a simple little routine to show me the values in 520 (#208) on keypresses.
56 seems to be the "no keypress" and the first if statement works.

Pressing the letter 'A' gives me 82 as a value, but the second if statment never prints an "A".

Even more worrisome is that by adding 1 to the value of touch it actually minuses 1??????

Also, if I write a similar BASIC routine :-

Code: Select all

10 PRINT PEEK(520)
20 GOTO 10
This gives me different values for keypresses (A = 174) but no press is still 56.

I know its my brain that is missing something obvious, so I'm going to go and watch some golf and get my head onto something else for a while :?

Still having fun though :)

Badger
flag_uk Amateurs built the Ark, Professionals built the Titanic.
User avatar
iss
Wing Commander
Posts: 1637
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: Textmode Sideways Scroller

Post by iss »

Yes, it's confusing :).
Try this code:

Code: Select all

int touch;
char *keyPtr;

void main(void)
{
  keyPtr=(char*)520; //mem location for keyboard scanning
  while(1)
  {
    touch = 0x7f & *keyPtr; 
    if(touch!=56) // 56 seems to be no key press and this works
    {
      printf("touch = %d     \n",touch);  //pressing 'A' key gives me a value of 82
      if (touch==46)
      {
        printf("\nA\n");  //this never happens 
      }  
      printf("touch+1 = %d    \n",touch+1); // odd result  82+1=81!!!!!
    }
  }
}
Here 'A' is 46, where from did you get the value 82 for 'A'?
Hope this will help (somehow).
User avatar
Badger
Pilot Officer
Posts: 84
Joined: Sat Sep 22, 2018 10:04 am
Location: Wigan, England

Re: Textmode Sideways Scroller

Post by Badger »

That works perfectly.

Thankyou :)
flag_uk Amateurs built the Ark, Professionals built the Titanic.
User avatar
Badger
Pilot Officer
Posts: 84
Joined: Sat Sep 22, 2018 10:04 am
Location: Wigan, England

Re: Textmode Sideways Scroller

Post by Badger »

Updated TAP file

Intro screen, colours, aliens. what more could one want?

Oh yes, sounds, missiles, an objective!
Attachments
SIDEWA.tap
(9.94 KiB) Downloaded 322 times
flag_uk Amateurs built the Ark, Professionals built the Titanic.
Post Reply