Page 1 of 2

Textmode Sideways Scroller

Posted: Sun Sep 23, 2018 12:28 pm
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.

Re: Textmode Sideways Scroller

Posted: Sun Sep 23, 2018 1:23 pm
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.

Re: Textmode Sideways Scroller

Posted: Sun Sep 23, 2018 2:06 pm
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.

Re: Textmode Sideways Scroller

Posted: Sun Sep 23, 2018 5:53 pm
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

Re: Textmode Sideways Scroller

Posted: Tue Sep 25, 2018 9:45 pm
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 334 times
The source is at the github repository in the original post.

Re: Textmode Sideways Scroller

Posted: Wed Sep 26, 2018 9:18 am
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:

Re: Textmode Sideways Scroller

Posted: Wed Sep 26, 2018 6:03 pm
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

Re: Textmode Sideways Scroller

Posted: Wed Sep 26, 2018 6:13 pm
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!!!!!

Re: Textmode Sideways Scroller

Posted: Wed Sep 26, 2018 7:11 pm
by waskol
:mrgreen: I definetly recognize myself in this.

Re: Textmode Sideways Scroller

Posted: Wed Sep 26, 2018 7:41 pm
by Chema
Lol Dbug. Exactly my experience with pinforic... then I went and learn assembly :lol:

Re: Textmode Sideways Scroller

Posted: Thu Sep 27, 2018 9:41 am
by ibisum
This is brilliant! Nice work! I was pretty surprised at how concise the C code ended up being .. very inspiring.

Re: Textmode Sideways Scroller

Posted: Sat Sep 29, 2018 9:32 am
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

Re: Textmode Sideways Scroller

Posted: Sat Sep 29, 2018 12:10 pm
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).

Re: Textmode Sideways Scroller

Posted: Sat Sep 29, 2018 5:42 pm
by Badger
That works perfectly.

Thankyou :)

Re: Textmode Sideways Scroller

Posted: Sat Sep 29, 2018 8:50 pm
by Badger
Updated TAP file

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

Oh yes, sounds, missiles, an objective!