Welcome, Guest. Please login or register.

Author Topic: commented source code  (Read 2356 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline peroxidechickenTopic starter

  • Full Member
  • ***
  • Join Date: Apr 2002
  • Posts: 170
    • Show only replies by peroxidechicken
commented source code
« on: June 20, 2003, 01:45:50 AM »
Can anyone recommend a well written application with commented assembler source?  I'd be particularly interested in something by Nico Francois (or did he use C?).  And more particularly, examples dealing with interface setup, using gadtools and the clipboard device.  
H2O2
 

  • Guest
Re: commented source code
« Reply #1 on: June 20, 2003, 03:54:21 AM »
RTFM
 

Offline peroxidechickenTopic starter

  • Full Member
  • ***
  • Join Date: Apr 2002
  • Posts: 170
    • Show only replies by peroxidechicken
Re: commented source code
« Reply #2 on: June 20, 2003, 05:26:48 AM »
I don't understand C well enough to even come close to fully comprehending the examples in the RKMs.  I got almightily tripped up on an event loop example that used Wait() instead of Waitport() - I read and re-read the function description and couldn't see what I was doing wrong.  I resorted to looking through my own old source code (targeted at 1.3) to find out that Waitport() was the way to go.  I just think the source code from actual applications is a better way to learn what to do and quickly apply what's learned in my own efforts.  
H2O2
 

Offline csirac_

  • Full Member
  • ***
  • Join Date: Feb 2002
  • Posts: 154
    • Show only replies by csirac_
Re: commented source code
« Reply #3 on: June 20, 2003, 07:27:12 AM »
It's quite helpful to know C when working in assembler if you are writing assembler that has to interoperate with libraries written in C.. so you know how structures work, how to set up/preserve the stack etc.

Since you obviously already know asm, I guess you knew that already ;) I find it strange you know asm and yet you are reluctant to use C. Surely you've got enough time to sit through a few C tutorials ;) C code should be readable even if you haven't used it much (compared to ASM!).

Here's my suggestion: there must be a few Amiga apps out there compiled with GCC, that has the source freely available. Take the C program, compile with debugging symbols, and then decompile it again with verbose output. For example, after compiling an elf file with GCC with my MC68HC12 "beeos" project using:

Quote
m68hc12-gcc -m68hc12 -mshort -Wall -Wmissing-prototypes -g -Os -msoft-reg-count=0 -fomit-frame-pointer -ffixed-z   -c -o beeos.o beeos.c


I can "decompile" it using:
Quote
m68hc12-objdump -xDSstrGg beeos.elf > beeos.dump


So from the following C code excerpt from beeos.c:

Quote
void addTask(void (*addr)(void), uchar meta, uint tickinterval)   /* 55 bytes */
{   /* addTask(): sbrk's space for a new task */

   tasknode_t *pNewTask = (tasknode_t*) bsbrk(sizeof(tasknode_t));
   tasknode_t *pTask = pHeadTask;   /*holds node of where insert search is at */

   pNewTask->next = NULL;
   pNewTask->addr = addr;
   pNewTask->tickinterval = tickinterval;
   pNewTask->lastrun = 0;
   pNewTask->meta = meta;
   if (pHeadTask == NULL) pHeadTask = pNewTask;
   else {   /* append task: first tasks have priority over tasks @end of list */
      while (pTask->next != NULL) pTask = pTask->next;
      pTask->next = pNewTask;
   }
   
   return;
}


I get this dissassembly:

Quote
00000e20 :

void addTask(void (*addr)(void), uchar meta, uint tickinterval)   /* 55 bytes */
{   /* addTask(): sbrk's space for a new task */
 e20:   34             pshx
 e21:   6c 80          std   0,SP

   tasknode_t *pNewTask = (tasknode_t*) bsbrk(sizeof(tasknode_t));
 e23:   cc 00 0a       ldd   #a <__data_section_size>
 e26:   16 0d 89       jsr   d89
 e29:   b7 45          tfr   D,X
   tasknode_t *pTask = pHeadTask;   /*holds node of where insert search is at */
 e2b:   fd 08 02       ldy   802

   pNewTask->next = NULL;
 e2e:   69 01          clr   1,X
 e30:   69 00          clr   0,X
   pNewTask->addr = addr;
 e32:   18 02 80 02    movw   0,SP, 2,X
   pNewTask->tickinterval = tickinterval;
 e36:   18 02 86 06    movw   6,SP, 6,X
   pNewTask->lastrun = 0;
 e3a:   69 05          clr   5,X
 e3c:   69 04          clr   4,X
   pNewTask->meta = meta;
 e3e:   18 02 84 08    movw   4,SP, 8,X
   if (pHeadTask == NULL) pHeadTask = pNewTask;
 e42:   04 66 05       tbne   Y,e4a
 e45:   7c 08 02       std   802
 e48:   20 0c          bra   e56
   else {   /* append task: first tasks have priority over tasks @end of list */
      while (pTask->next != NULL) pTask = pTask->next;
 e4a:   ec 40          ldd   0,Y
 e4c:   27 06          beq   e54
 e4e:   ed 40          ldy   0,Y
 e50:   ec 40          ldd   0,Y
 e52:   26 fa          bne   e4e
      pTask->next = pNewTask;
 e54:   6e 40          stx   0,Y
   }
   
   return;
}
 e56:   30             pulx
 e57:   3d             rts


Not as good as proper commented asm, but better than nothing :P The m68hc12- prefixed commands "gcc" and "objdump" should be comparable to the gcc chain for other CPUs, such as M68k and x86 but I haven't confirmed that. I was using GCC 3.2.x.

Cheers,

- Paul
 

Offline Rogue

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 566
    • Show only replies by Rogue
    • http://www.hyperion-entertainment.com
Re: commented source code
« Reply #4 on: June 20, 2003, 11:02:39 AM »
Quote

peroxidechicken wrote:
 I got almightily tripped up on an event loop example that used Wait() instead of Waitport()  


That could happen to you in assembler, too, if you use "jsr LVOWait(a6)" instead of "jsr LVOWaitPort(a6)".

I don't recommend using assembler, really. Whatever you will be programming for in the future, be it AmigaOS, MorphOS or whatever, chances are that assembler will only be emulated...
Look out, I\'ve got a gun
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: commented source code
« Reply #5 on: June 20, 2003, 11:14:12 AM »
Quote

Rogue wrote:
I don't recommend using assembler, really. Whatever you will be programming for in the future, be it AmigaOS, MorphOS or whatever, chances are that assembler will only be emulated...


Well, it depends on what you want to do. I've been doing a lot of assembler recently, because i've been writing a demo, targetted at ECS/030. I also have an Emerson Arcadia 2001 emulator which is entirely asm, because i'm targetting it at low-end classic Amigas.

But, generally, if you're writing AmigaOS applications and tools, a high level language is your friend :-D

I just really hope that someone makes an E compiler that targets OS4 and PPC. I mean, I am proficient in C, and C++ (and plenty of other languages), but i've always really enjoyed programming in E. Some really good Amiga software is written in E, too, like AmiNetRadio, SuperTV, DynAMIte etc. so a nice E compiler for next-gen AmigaOS would aid porting them.

Hmm... I seem to be straying somewhat from the original topic :-D
Playstation Network ID: xeron6