Sonic and Sega Retro Message Board: Need help with making a loop work - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
Loading News Feed...
 

Need help with making a loop work

#1 User is offline Puto 

Posted 10 June 2007 - 06:07 AM

  • Shin'ichi Kudō, detective.
  • Posts: 1979
  • Joined: 31-July 05
  • Gender:Male
  • Location:Portugal, Oeiras
  • Project:Part of Team Megamix, but haven't done any actual work in ages.
  • Wiki edits:51
Right, I've got a small problem. I'm trying to make jman's Sonic 1 sound driver to load without kosinski compression. This works if I manually copy every byte into Z80 RAM, like this:

	 move.b (Kos_Z80+$000),($A00000+$000).l   
	 move.b (Kos_Z80+$001),($A00000+$001).l
	 move.b (Kos_Z80+$002),($A00000+$002).l
	 move.b (Kos_Z80+$003),($A00000+$003).l
	 move.b (Kos_Z80+$004),($A00000+$004).l
	 move.b (Kos_Z80+$005),($A00000+$005).l
	 move.b (Kos_Z80+$006),($A00000+$006).l
	 move.b (Kos_Z80+$007),($A00000+$007).l
	 move.b (Kos_Z80+$008),($A00000+$008).l
	 move.b (Kos_Z80+$009),($A00000+$009).l
	 ...


But this is horribly ugly, it takes a shitload of ROM space, and it's not very extensible. Unfortunately, I seem to not get along with address registers and the like, so could someone help me get this in a proper loop plz?

EDIT: Oh, and the size of the driver can be obtained by doing (Kos_Z80_End-Kos_Z80).
This post has been edited by Puto: 10 June 2007 - 06:07 AM

#2 User is offline Quickman 

Posted 10 June 2007 - 06:22 AM

  • Posts: 5558
  • Joined: 03-December 03
  • Gender:Male
  • Location::x
  • Project:omg porjcet
  • Wiki edits:10
lea (Kos_Z80),a0
lea ($A00000).l,a1
move.w ((Kos_Z80_End-Kos_Z80)/4),d1

$$loop:
move.l (a0)+,(a1)+
dbf d1,$$loop


EDIT: Just noticed your own edit, made the extra code I added redundant. Be sure to change the label - I've assumed $$ as a prefix for a local label. If you were using AS I'd use a nameless temporary symbol.
This post has been edited by Quickman: 10 June 2007 - 06:24 AM

#3 User is offline Puto 

Posted 10 June 2007 - 06:39 AM

  • Shin'ichi Kudō, detective.
  • Posts: 1979
  • Joined: 31-July 05
  • Gender:Male
  • Location:Portugal, Oeiras
  • Project:Part of Team Megamix, but haven't done any actual work in ages.
  • Wiki edits:51
Thanks, it worked :)

#4 User is offline Puto 

Posted 12 June 2007 - 11:20 AM

  • Shin'ichi Kudō, detective.
  • Posts: 1979
  • Joined: 31-July 05
  • Gender:Male
  • Location:Portugal, Oeiras
  • Project:Part of Team Megamix, but haven't done any actual work in ages.
  • Wiki edits:51
OK, continuation of problem. Apparently, access to Z80 RAM, aka $A00000-$A1FFFF, can only be done in bytes. How do I increment an address register by only one byte, instead of 4?

#5 User is offline JoseTB 

Posted 12 June 2007 - 11:47 AM

  • Posts: 623
  • Joined: 01-June 04
  • Location:Spain
  • Wiki edits:4
That's defined by the size of the instruction if I'm not mistaken, therefore use move.b instead of move.l, and change the rest of the loop accordingly.

#6 User is offline Puto 

Posted 12 June 2007 - 11:49 AM

  • Shin'ichi Kudō, detective.
  • Posts: 1979
  • Joined: 31-July 05
  • Gender:Male
  • Location:Portugal, Oeiras
  • Project:Part of Team Megamix, but haven't done any actual work in ages.
  • Wiki edits:51
This code doesn't seem to work:

move.w (Z80_Driver_End-Z80_Driver),d1
@loop:
move.b (a0)+,(a1)+
dbf d1,@loop

So what am I doing wrong?

EDIT: Wait a minute...

How did this work:

move.w (Z80_Driver_End-Z80_Driver)/4,d1
@loop:
move.b (a0)+,(a1)+
dbf d1,@loop
move.w (Z80_Driver_End-Z80_Driver)/4,d1
@loop2:
move.b (a0)+,(a1)+
dbf d1,@loop2
move.w (Z80_Driver_End-Z80_Driver)/4,d1
@loop3:
move.b (a0)+,(a1)+
dbf d1,@loop3
move.w (Z80_Driver_End-Z80_Driver)/4,d1
@loop4:
move.b (a0)+,(a1)+
dbf d1,@loop4

But one loop without a /4 didn't?
This post has been edited by Puto: 12 June 2007 - 11:54 AM

#7 User is offline Aurochs 

Posted 13 June 2007 - 01:45 PM

  • Единый, могучий Советский Союз!
  • Posts: 2343
  • Joined: 09-January 05
  • Gender:Male
  • Project:Whatever catches my fancy
  • Wiki edits:325
DBcc operates on a 16-bit counter. If your driver is longer than 65535 ($FFFF) bytes, the loop will terminate prematurely.
This post has been edited by Aurochs: 13 June 2007 - 01:47 PM
Reason for edit: lol can't edit a non-html post to include html elements

#8 User is offline drx 

Posted 13 June 2007 - 02:02 PM

  • <Shade> fuck MJ
  • Posts: 2088
  • Joined: 02-March 04
  • Gender:Male
  • Project::rolleyes:
  • Wiki edits:8
Seeing as you Z80 RAM is limited to $2000 (or $4000, I don't remember which) bytes, the scenario you provided is impossible anyway ($2000 < $FFFF). I still can't quite understand why this occurs... What Puto posted seems pretty much impossible, as the code is pretty much identical, so I must be blind and not seeing something.

#9 User is offline Aurochs 

Posted 13 June 2007 - 03:11 PM

  • Единый, могучий Советский Союз!
  • Posts: 2343
  • Joined: 09-January 05
  • Gender:Male
  • Project:Whatever catches my fancy
  • Wiki edits:325
Indeed. I can't see any other problems with this... Try running both of them through your assembler, then disassembling it again (68kd works for this), or just read back the listing file. It may not be generating code as expected.

#10 User is offline Quickman 

Posted 13 June 2007 - 03:12 PM

  • Posts: 5558
  • Joined: 03-December 03
  • Gender:Male
  • Location::x
  • Project:omg porjcet
  • Wiki edits:10
The Z80 can access 64KB ($A00000 - $A01000) but the high 32KB of that are bank-switched to look at a 32KB chunk of 68k memory.

#11 User is offline drx 

Posted 13 June 2007 - 04:29 PM

  • <Shade> fuck MJ
  • Posts: 2088
  • Joined: 02-March 04
  • Gender:Male
  • Project::rolleyes:
  • Wiki edits:8

View PostQuickman, on Jun 13 2007, 10:12 PM, said:

The Z80 can access 64KB ($A00000 - $A01000) but the high 32KB of that are bank-switched to look at a 32KB chunk of 68k memory.


Wow, that is so wrong that I don't know where to start.

First of all 64KB is $10000, not $1000, second, we're not talking about what the Z80 can access, but rather what the 68000 can access. And yea... stuff.

#12 User is offline Tweaker 

Posted 13 June 2007 - 06:24 PM

  • Posts: 12389
  • Joined: 27-June 04
  • Gender:Male
IIRC, the 68k can only access Z80 at a byte level.

EDIT: Oh cool, we've established that. So what exactly IS the problem?

#13 User is offline JoseTB 

Posted 13 June 2007 - 10:00 PM

  • Posts: 623
  • Joined: 01-June 04
  • Location:Spain
  • Wiki edits:4
I can't see where is the problem either. Do you clean D1 before using it? Judging by the code it shouldn't really matter, but who knows.

Also, what happens with the non-working loop? Does it crash in a never-ending loop, or does the loop actually end, but before all data has been sent?
This post has been edited by JoseTB: 13 June 2007 - 10:02 PM

#14 User is offline drx 

Posted 14 June 2007 - 08:07 AM

  • <Shade> fuck MJ
  • Posts: 2088
  • Joined: 02-March 04
  • Gender:Male
  • Project::rolleyes:
  • Wiki edits:8

Quote

I can't see where is the problem either. Do you clean D1 before using it? Judging by the code it shouldn't really matter, but who knows.


Yea, as the DBcc instruction never even touches the higher register word.

A good idea would be to run your debugging tools of choice and trace what is happening byte by byte.

#15 User is offline Puto 

Posted 14 June 2007 - 09:52 AM

  • Shin'ichi Kudō, detective.
  • Posts: 1979
  • Joined: 31-July 05
  • Gender:Male
  • Location:Portugal, Oeiras
  • Project:Part of Team Megamix, but haven't done any actual work in ages.
  • Wiki edits:51
Eventually I just ended up doing this:

<tt>move.w (Z80_Driver_End-Z80_Driver)/4,d1
@loop:
move.b (a0)+,(a1)+
move.b (a0)+,(a1)+
move.b (a0)+,(a1)+
move.b (a0)+,(a1)+
dbf d1,@loop</tt>

Which seems to work perfectly. I still don't understand why taking out the /4 and putting in just one move.b doesn't work though.

  • 2 Pages +
  • 1
  • 2
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users