Videopac / Odyssey2 forum

Programming the Videopac / Odyssey2 => Homebrews => Topic started by: Chris! on March 22, 2011, 06:48:37 AM

Title: Ants! (a WIP)
Post by: Chris! on March 22, 2011, 06:48:37 AM
Hey all, I'm working (or TRYING to work, anyway), on an Odyssey2 homebrew called Ants! I don't really understand what I'm doing (I hardly understand assembly), but if someone could take a look and tell me some ways to program or how to do things better, I'd really appreciate it. What I've been doing and what I've used to create the game so far is tweak samples. I do know a little Basic and C+, but I just can't seem to grasp assembly yet. Anyway, here's the link:
http://www.atari2600land.com/ants.html (http://www.atari2600land.com/ants.html)
Title: Re: Ants! (a WIP)
Post by: Janzl on March 22, 2011, 09:52:42 AM
Okay the beginning is there!  :)

Did you check all the programming links in te links section of the forum. Lot's of information can be found there.

I like the Melvin sprite  :)
Title: Re: Ants! (a WIP)
Post by: Chris! on March 23, 2011, 01:58:41 AM
I looked at the links. The problem is, I don't know assembly, so I didn't understand any of it, except, by chance, I did change the background color to red. I still haven't found through trial and error how to change the two to a one and how to make it stay a one when Melvin stops touching the ant. I was hoping someone could go through the code and tell me how to do this. I was modifying Soren's code I got from his website.  ???
Title: Re: Ants! (a WIP)
Post by: Rafael on March 23, 2011, 02:43:49 AM
Hi Chris. I made some changes on my adventure attempt to change it to your Gosub project.  Have fun!
Title: Re: Ants! (a WIP)
Post by: Chris! on March 23, 2011, 05:36:30 AM
Perhaps someone can offer some code about a score and how to make it increase by 1? Not much progress with this, except I did make a border around the play area, but it's kind of useless unless you bounce back into it.
Title: Re: Ants! (a WIP)
Post by: gertk on March 23, 2011, 08:17:08 AM
This is some code from my program 'omegarace'

It uses two quads to display a 4 digit score (the 4 remaining characters in the quads are for displaying the number of lives left but that is not in this code)

Title: Re: Ants! (a WIP)
Post by: Chris! on March 23, 2011, 08:58:23 AM
It doesn't like vdc_quad0 and vdc_quad1 and calls it "an invalid symbol name."
Title: Re: Ants! (a WIP)
Post by: gertk on March 23, 2011, 05:22:01 PM
Ah, you need some "equates" (.equ) for that :)

Depending on the assembler you use (I switched to a different one, see Omega race on the Videopac):


vdc_quad0       equ     040h
vdc_quad1       equ     050h

or

vdc_quad0       .equ    0x040;
vdc_quad1       .equ    0x050;

Or have a look at the source of my Omega Race attempt under 'Programming', there is quite some comment in there.
;D

Title: Re: Ants! (a WIP)
Post by: Chris! on March 24, 2011, 01:05:32 AM
Nope, it still doesn't like it.
Title: Re: Ants! (a WIP)
Post by: Chris! on March 24, 2011, 01:33:46 AM
OK, I figured out the problem. My asm doesn't like 0x00-type numbers, so I switched them all to 000h. After I got this all taken care of, two new problems arise:  #1 - there are four halves of the letter V to the left of the score, and #2 - It adds one to the score when Melvin touches an ant, but then SUBTRACTS it when he isn't. I don't remember telling the program to do that, plus I thought that the BIOS doesn't even have a subtraction routine built in it. You can find my .a48 file at the Ants! website I made http://www.atari2600land.com/ants.html (http://www.atari2600land.com/ants.html) here.
Title: Re: Ants! (a WIP)
Post by: manopac on March 24, 2011, 08:45:32 AM
subtraction of 1 in 8048 assembler is just adding FFh - same effect  :-)
Title: Re: Ants! (a WIP)
Post by: Chris! on March 24, 2011, 10:23:25 AM
OK, I have made the score increase by one whenever he touches the ant. Next up is the border collision. Since I've added a border, I want to have it be like the walls in Adventure (Melvin bounces back when he attempts to cross it). I have attempted to do it myself. I have only made the top horizontal border work and when he crossed the bottom horizontal border, he went to the top for some reason. I have deleted the non working code at hopes that I can get one that does work. I have added the link to the game in my signature for easier access to it.
Title: Re: Ants! (a WIP)
Post by: gertk on March 24, 2011, 01:23:40 PM
Nice work so far !

You asked for if-then examples in assembler.

It mostly comes down to doing some kind of function and then jump conditionally on the outcome or result:

Like you do in the collision part

        ; check collisions
        mov r0,#03dh                       ; address of collision register in VDC
        mov a,@r0                           ; get value of collisionregister in A
        anl a,#002h                         ; test bit 1 (check for s1)
        jz check_collision_grid           ; if zero then jump to check_collision_grid


There are several conditional jumps in the 8048 which all respond to bits set in the flag register.

Have a look at the 8048 manual pointed to in https://videopac.nl/forum/index.php?topic=1611.0
The manual mentioned there gets interesting from page 56 (Instruction set)
Title: Re: Ants! (a WIP)
Post by: Chris! on September 06, 2011, 05:13:07 AM
Hi, everyone, I'm back! I have never seen a warning about topics not being posted in for at least 120 days before. I'm sure I want to because I'm back trying to figure this out again. I'd like some help regarding whether or not there is a random number generator for the Odyssey^2 and if so, how to work it.
Title: Re: Ants! (a WIP)
Post by: Rene_G7400 on September 06, 2011, 12:52:43 PM
There is a random number generator for the Odyssey2, but it's not a good idea to use it, since Videopac+ consoles (G7400, Jopac) don't have it anymore.
Usually, the timer is used to get random numbers.
Title: Re: Ants! (a WIP)
Post by: Chris! on September 06, 2011, 11:57:45 PM
What is the timer, and how do I use it to get random numbers?
Title: Re: Ants! (a WIP)
Post by: Chris! on September 08, 2011, 05:59:38 AM
OK, let's forget that for now. Let's say I have an internal variable named iram_y. iram_y is set to begin at #068h. So, at the start, iram_y is at #068h, which is approximately the middle of the screen. So, with that in mind, how would I check to see if iram_y is at, well, let's just for now say, for the sake of example, #020h, and if it is, nudge it down a notch because it's at the top of the screen? I tried the following, which doesn't work:

check_up_point

mov r1,#iram_y ; y position
mov a,@r1 ; get it
anl a,#020h
jnz check_down_point

inc r3


check_down_point


I have figured out that increasing or decreasing r3 makes the player go up or down accordingly. I thought that if I moved #iram_y to a analyzable point that I could analyze it and then either increase or decrease r3 accordingly, but nooooo, that would be too easy...  :(
My code can be downloaded at http://www.atari2600land.com/ants


Title: Re: Ants! (a WIP)
Post by: Rene_G7400 on September 09, 2011, 04:24:51 PM
I haven't checked your code yet, but it looks like the "anl a,#020h" needs to be replaced by "xrl a,#020h".
Title: Re: Ants! (a WIP)
Post by: Rene_G7400 on September 09, 2011, 04:46:30 PM
Quote from: Chris! on September 06, 2011, 11:57:45 PM
What is the timer, and how do I use it to get random numbers?

The timer is a feature of the 8048 microcontroller. It's a countdown timer. It's clock frequency is the instruction cycle clock divided by 32. You start it with STRT T. Before starting it you can initialize it with MOV T,A , but for the random function you won't need that. You can read the value of the timer with MOV A,T . Some extra calculations will probably be required to get a good random value, but it would be best to first try which values you get.
Title: Re: Ants! (a WIP)
Post by: Chris! on September 10, 2011, 01:59:51 AM
Thanks for your help so far, I really appreciate it. Now, I have the ant moving to different spots on the screen when I touch it. How would I make it stay within the confines of the border? I moved the ant calling spot subroutine to its own thingy. It's called "ant_new_spot." And this is it:

ant_new_spot
; set sprite position for ant
mov r0,#vdc_spr1_ctrl
mov a,t ; y position
movx @r0,a
inc r0
mov a,t ; x position
movx @r0,a
inc r0
mov a,#col_spr_black
movx @r0,a
ret

I really enjoyed the samples on soeren.informationstheater.de I learn best when I tweak samples. I then can understand this means such-and-such and that means something else, etc. Link to my code and ROM is in my signature.
Title: Re: Ants! (a WIP)
Post by: Chris! on September 10, 2011, 04:56:19 AM
By the way, I changed the border. I was having trouble activating the right wall since it was too far to the right, so I just said "To heck with it, I'll just make the area smaller." So I did.
Title: Re: Ants! (a WIP)
Post by: Rene_G7400 on September 10, 2011, 04:25:07 PM
Quote from: Chris! on September 10, 2011, 01:59:51 AM
How would I make it stay within the confines of the border? I moved the ant calling spot subroutine to its own thingy. It's called "ant_new_spot." And this is it:

ant_new_spot
; set sprite position for ant
mov r0,#vdc_spr1_ctrl
mov a,t ; y position
movx @r0,a
inc r0
mov a,t ; x position
movx @r0,a
inc r0
mov a,#col_spr_black
movx @r0,a
ret


The easiest way would be to limit the range to 080h and add an offset, but it won't match your current playfield exactly:

mov a,t
anl a,#07fh  ; you will only get values from 00 to 7F
add a,#025h ; add offset (use 00dh for X offset)
movx @r0,a

Title: Re: Ants! (a WIP)
Post by: Chris! on September 10, 2011, 06:09:49 PM
Thanks. Now, what is causing the blue things next to the score that I call "half-zeroes," because they look like it, and how would I get rid of them?
Title: Re: Ants! (a WIP)
Post by: Rene_G7400 on September 10, 2011, 10:09:50 PM
You have use two quads for the score. A quad is a row of 4 characters. The space between these characters is fixed in a quad, therefore usually two quads are interleaved (like in your game). You have used the last two characters of each quad for the score, but you haven't initialized the first two characters of these quads. You should put spaces in them.
Title: Re: Ants! (a WIP)
Post by: Chris! on September 11, 2011, 01:50:58 AM
I thought they WERE initialized:

init_score:
; preset x positions (they are fixed in my program)
mov r3,#50 ; quad 0 xposition
mov r4,#202 ; quad 0 and 1 yposition

mov r0,#quad0 ; pointer to quad0 vdc
call store_r3r4 ; I made this a subroutine as it is used so often here

mov r0,#quad0+004h ; next character in quad
call store_r3r4

mov r0,#quad0+008h ; and the next
call store_r3r4

mov r0,#quad0+00ch ; and another
call store_r3r4

mov r3,#58 ; quad 1 xposition (8 pixels further to interleave)

mov r0,#quad1 ; pointer to quad1 in vdc
call store_r3r4

mov r0,#quad1+004h ; next character in quad
call store_r3r4

mov r0,#quad1+008h ; and the next
call store_r3r4

mov r0,#quad1+00ch ; and another one
call store_r3r4

ret

store_r3r4:
mov a,r4
movx @r0,a ; store it
inc r0
mov a,r3
movx @r0,a
ret

If this doesn't do it, then how do I initialize them?
Title: Re: Ants! (a WIP)
Post by: Rene_G7400 on September 12, 2011, 12:17:08 AM
For each quad, X and Y only need to be initialized once, so you can remove 3 of the 4 store_r3r4 calls.
But it's important that all unused characters of a quad contain spaces. This requires some calculation, so it's best to use a BIOS routine for that. Register R4 should contain the Ypos of the quad. In your program you could do:

mov r0,#quad0+002h  ; pointer to first character byte of quad0
mov r5,#00ch ; code for character "space"
call 0261h ; convert character code and store in VDC
mov r0,#quad0+006h ; pointer to second character byte of quad0
mov r5,#00ch
call 0261h

This should be repeated for quad1.
Normally register R6 should contain the color, but for a space it won't matter.
Title: Re: Ants! (a WIP)
Post by: Chris! on September 12, 2011, 01:09:46 AM
Success! I got those stupid half-zeroes off the screen. Now, I'd like some suggestions for what to do next to the game. As it stands right now, it's pretty boring going around chasing ants with no way to die. Should I put in an enemy that chases you, or a timer, or what? By the way, I wonder why the guy providing the original sample code decided to initialize all eight characters.
Title: Re: Ants! (a WIP)
Post by: gertk on September 12, 2011, 07:38:17 AM
Quote from: Chris! on September 12, 2011, 01:09:46 AM
Success! I got those stupid half-zeroes off the screen. Now, I'd like some suggestions for what to do next to the game. As it stands right now, it's pretty boring going around chasing ants with no way to die. Should I put in an enemy that chases you, or a timer, or what? By the way, I wonder why the guy providing the original sample code decided to initialize all eight characters.

The quad characters are spaced apart a character so with just one quad it would look like:

A B C D

Which is not so nice for a score counter (it would look just like 4 single numbers)

With the two quads interleaved the gaps are filled with the other quad
(ABCD are in the first quad and EFGH in the second)


AEBFCGDH

But then you have to do some more work to get the score into CGDH  (and use AEBF for something else or just blanks) but the end result looks better.

In my Omega Race startup https://videopac.nl/forum/index.php?topic=1598.0 (https://videopac.nl/forum/index.php?topic=1598.0) in the center box I used 4 quads for displaying the number of ships left (4 positions), the current score (3 positions) and the hi-score (2 + 5 positions) so that is quite a bit of interleaving.. ;:)

But anyway, great that you figured it out!
Title: Re: Ants! (a WIP)
Post by: Chris! on September 12, 2011, 09:43:08 AM
Well, I need help again. I decided the route to go is to have an ant bounce around inside the borders of the screen. This ant is called the "tan ant" both in the game and in the code. ("tan" is an anagram of "ant". Also, I renamed the little green guy Stan, which is an anagram of "ants".) I tried to move it around by myself but I just couldn't do it. It just kept flashing on different parts of the screen, so I just deleted the code that made it do that. I think even getting a third sprite on the screen is a success for me, but darned if I know how to make it bounce around the screen. Code is attached.
Title: Re: Ants! (a WIP)
Post by: Rafael on September 16, 2011, 03:19:57 AM
The new ants looks better. Maybe you can think about some strategy game, like ants armys defending their anthill, or something like take the ants safely to its nest.
Title: Re: Ants! (a WIP)
Post by: Chris! on September 17, 2011, 02:36:00 PM
I tried again with putting some more code in. What I basically did was copy and paste the code for the green guy and tried to put info on how to bounce on the walls. I put this in a call routine since the info on getting the joystick info was this way, too. Instead, I got what I did the first time: A bunch of flashing sprites. Can someone help me with the code I posted and help me actually get this working?
Title: Re: Ants! (a WIP)
Post by: Chris! on September 19, 2011, 02:38:30 PM
All I want to do is have the tan ant move around inside the board diagonally and if he hits a wall, go the opposite direction. Why can't I do this?! In Basic, I'd have a variable add every frame, and when it reaches a certain point, move the ant an x and a y direction. Then, if the ant goes past one of the four certain points in the grid, have it change course the opposite directions.
Title: Re: Ants! (a WIP)
Post by: manopac on September 19, 2011, 04:03:39 PM
Hey Chris,

sorry, I currently don't have any time to look at your code, but in theory what you do in BASIC is what you would do here as well - for every coordinate (X and Y) you have a memory location where you store either $01 or $FF, if the ant hits the limit you want it to reach (-> the grid), you just change the content of the variable, e.g.


so your code could look something like this:
(PSEUDO CODE !!)


mov r0,#25       ; this is an example wherever you store the up/down counter    (either +1 or -1 (FF) -> you have to store it there first !!)
mov r1,#26       ; this is an example wherever you store the coordinate

       mov           a,@r0
       mov           r2,a          ; contains now  +1 / -1 (FF)

       mov           a,@r1
       add            a, r2        ; increase / decrease the position
       mov           @r1,a       ; and write it back

; now see if we need to change the counter as we hit a border
       xrl             a,#1Fh      ; e.g. left border
       jz              ChangeCounter

       mov           a,@r1
       xrl             a,#99       ; e.g. right border
       jz              ChangeCounter

Done
       ret

ChangeCounter
       mov       a,r2        ; get the counter
       cpl         a           ; invert it and add 1    ->    1 -> FF,  FF-> 1
       add        a,1
       mov       @r0,a     ; and write it back
       jmp Done



you get the principle ?   (I didn't try to write optimized code but rather one that is understandable, so don't kill me for bad coding style :-) )
Title: Re: Ants! (a WIP)
Post by: Chris! on September 19, 2011, 04:29:51 PM
Thanks to Rene, I have updated the code majorly. It's now a lot smaller than it was, but there are a few problems.
#1 - the visible border flickers.
#2 - The tan ant, which I want to move diagonally, is only going down, which is weird because in his example, it says the object should be going left/right.
#3 - The extreme left/right/up/down points for the tan ant and Stan (the little green guy) need to be changed to fit the border.
So, would any one like to look through the new code and see what's going on?
Title: Re: Ants! (a WIP)
Post by: Chris! on September 19, 2011, 09:29:49 PM
OK, I got problem #1 and #3 solved on my own, but still need help on problem #2.
Title: Re: Ants! (a WIP)
Post by: Rene_G7400 on September 19, 2011, 10:33:24 PM
Quote from: Chris! on September 19, 2011, 09:29:49 PM
OK, I got problem #1 and #3 solved on my own, but still need help on problem #2.

You've got a PM.
Title: Re: Ants! (a WIP)
Post by: Chris! on September 20, 2011, 01:10:47 PM
OK, the ant is bouncing around the screen. I kind of wanted the x axis movement to be the same as the y axis, but at least it's bouncing around the screen now. Check out the official Ants! homepage at http://www.atari2600land.com/ants/ (http://www.atari2600land.com/ants/) for a list of stuff I need to do next.
Title: Re: Ants! (a WIP)
Post by: Janzl on September 20, 2011, 01:28:41 PM
I just tested your game and I must say that I really like the ant-sprite. It's just begs to get animated!
Title: Re: Ants! (a WIP)
Post by: Chris! on September 20, 2011, 05:03:02 PM
Thanks, I had someone else much more skilled than me at making sprites make that for me. I don't know how I would go about programming animation, or what the extra sprites would look like. You mean the tan ant, right?
Title: Re: Ants! (a WIP)
Post by: Chris! on September 21, 2011, 12:25:48 AM
Version 11 is here! Changes are:
Collision detection now works for the tan ant. You only get one life (like in so many other Odyssey2 games) and if you hit the tan ant, press fire to get back to the "GAME SELECT" screen.
The tan ant's speed increases with every twenty black ants you get
I don't know if there was sound in version 9, but I added a sound each time you get an ant.
Title: Re: Ants! (a WIP)
Post by: Rafael on September 21, 2011, 01:48:27 AM
Chris, you?re doing a nice job. The game is cool, but I tested it on O2em v 1.81 and it not works, having time I?ll test on the real console, but by my experiences it will not work. Sugestion, try other colors, black backgroud ever looks good! Congrats by now.
Title: Re: Ants! (a WIP)
Post by: Rafael on September 21, 2011, 01:56:10 AM
In time, my high for while:  51  ;)
Title: Re: Ants! (a WIP)
Post by: Chris! on September 21, 2011, 05:55:40 AM
Where can you get v1.81? I think I have 1.18
Title: Re: Ants! (a WIP)
Post by: Chris! on September 21, 2011, 06:37:02 PM
Version 12:
* Changed the joystick you use to the left one.
* Pressing fire at the death starts a new game, and doesn't go back to the GAME SELECT screen.
Title: Re: Ants! (a WIP)
Post by: Rafael on September 22, 2011, 04:10:21 AM
Quote from: Chris! on September 21, 2011, 05:55:40 AM
Where can you get v1.81? I think I have 1.18


Get it here:
http://guttenbrunner.com/videopac/o2em1181win.zip

Now the black ant is over tan ant.
Title: Re: Ants! (a WIP)
Post by: Chris! on September 24, 2011, 01:52:31 AM
Does this version work now?
Title: Re: Ants! (a WIP)
Post by: Rafael on September 24, 2011, 03:51:50 AM
Quote from: Chris! on September 24, 2011, 01:52:31 AM
Does this version work now?


Yes, very nice. You changed the control, but maybe you forget to update the action button for replay.
Title: Re: Ants! (a WIP)
Post by: TedFoolery on September 24, 2011, 05:32:47 AM
Yes, it now plays fine on my Odyssey2 and my G7400. But yeah, it's still looking at the right-hand joystick for the restart button (a quick fix).

Good job, though.
Title: Re: Ants! (a WIP)
Post by: Chris! on September 24, 2011, 10:23:12 AM
OK, I changed the fire button to the other joystick.
Title: Re: Ants! (a WIP)
Post by: Rafael on September 24, 2011, 09:30:44 PM
Now, I?m playing Ants on my Ody, it?s fun ;)
Title: Re: Ants! (a WIP)
Post by: Chris! on September 25, 2011, 12:26:59 AM
So it works OK on real hardware, then? How do you play a game on real hardware?
Title: Re: Ants! (a WIP)
Post by: Rafael on September 25, 2011, 01:52:46 AM
Check:
https://videopac.nl/forum/index.php?topic=1639.0 (https://videopac.nl/forum/index.php?topic=1639.0)