It is currently Tue May 26, 2020 11:51 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Sep 24, 2014 10:56 pm 

Joined: Wed Sep 24, 2014 10:37 pm
Posts: 3
Hey there. I'm working on a rather ambitious project for the Sega Genesis and I'm coding it in 68000 Assembly. The project is a music sequencer that utilizes the FM and PSG sound chips. I haven't yet reached the stage for coding the sound driver. But I've started with displaying graphics and so far the results are coming along nicely. Now, I'm only going to ask general questions about the 68k language itself, rather than hardware specific questions (I have all my hardware information needs taken care of). Keep in mind that I'm very new to assembly. I'm learning 68k and working on this project as a hobby, so I don't have access to the same education as some others on this forum do, please keep that in mind. Any questions asked here will never have specific portions of code, rather I seek a general understanding on particular topics. So the topic today is making nested subroutines portable.

In a nutshell, I'm using nested subroutines to handle drawing graphical elements on to the screen. These subroutines use very specific parameters to make sure all the proper addresses are used, where to draw on screen, reading arrays of bytes for important info on certain graphical elements... etc. I've noticed now that my source code is a mess, because a lot of these subroutines do roughly the same thing as the other, the exception being the parameters used within these subroutines. I understand that subroutines can be made for reuse of code, so what's a really efficient way of doing this? I'm looking for ways to do this with reasonable execution speed and cleanliness, because when I start working on the sound driver... timing is very likely to be critical. So I want to get this right the first time, as much as I can anyways. Thank you for your time.

PostPosted: Thu Sep 25, 2014 3:02 pm 
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1122
Sounds like a fun project :D

Sounds like you want a way to pass parameters to your subroutine.

One option is to use the CPU registers. If the subroutine is used as part of an interrupt handler or may be called recursively it needs to be re-entrant. To make a subroutine re-entrant, save all of the registers used by the subroutine to the stack at the beginning of the subroutine using MOVEM and restore all of the registers at the end of the subroutine.

Another option for parameter passing is to use the stack. See the example tutorial4 that is included with EASy68K for an example. Using the stack for parameter passing and local variables creates subroutines that are also re-entrant.

Prof. Kelly

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: Google [Bot] and 9 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group