Jump to content
IGNORED

Coding Styles / Code Amnesty!


Recommended Posts

I was wondering if a few developers could release the code to some of their Assembly language projects so that I can get some coding style tips?

 

I think that I write relatively neat code, but there's still lots to be learnt and maybe I could make it easier to follow. Therefore I'd like to see some examples from others. Not just 1 file, but maybe several files from a project and how they all relate to one another.

 

If your code isn't finished, that is not important, as long as the style can be seen.

Link to comment
Share on other sites

Here's an example of the style that I currently prefer. It's from the implementation of the NEW statement in Altirra BASIC.

;===========================================================================
; NEW
;
; Erases all program text and variables, clears the TRAP line, silences
; sound, closes IOCBs, and resets angular mode to radians.
;
; Not affected by new: COLOR
;
.proc stNew
        ldy     memlo+1
        ldx     memlo

        ;set up second argument stack pointer
        txa
        clc
        adc     #$6c
        sta     argstk2
        tya
        adc     #0
        sta     argstk2+1

        ;initialize LOMEM from MEMLO
        iny
        sty     lomem+1
        stx     lomem

        ;clear remaining tables
        ;copy LOMEM to VNTP/VNTD/VVTP/STMTAB/STMCUR/STARP/RUNSTK/MEMTOP2
        ldx     #<-16
        jsr     stClr.reset_loop

        dec     lomem+1

        ;insert byte at VNTD
        inx                     ;!! stClr leaves this at $FF
        stx     degflg          ;!! - set degflg to $00 (radians)
        stx     a2+1
        inx
        stx     a2
        ldx     #vntd
        jsr     MemAdjustTablePtrs

        ;insert three bytes at STARP
        lda     #3
        sta     a2
        ldx     #starp
        jsr     MemAdjustTablePtrs
        
        ;write sentinel into variable name table
        ldy     #3
        mva:rpl empty_program,y (vntp),y-

        ;all done
        jmp     immediateModeReset

empty_program:
        dta     $00,$00,$80,$03
.endp

Link to comment
Share on other sites

Thanks Phaeron and MaPa, both of your coding styles look quite neat. My impression is that only people with neat styles will submit something here, but I implore all people, no matter how tidy your code is to put something up here.

 

I personally can't put anything up as I want to enter my program into the ABBUC contest at some stage (some year that I manage to finish it!!). I think that releasing any code will invalidate my entry.

 

My style is probably most similar to Phaerons, though I use colons after the end of label names and my instructions are in uppercase (most of the time, but not consistent). Do you have one procedure per file or all of them together in one big file? I try to separate things out, though some similar procedures may get dumped together into one file.

 

As for yours MaPa, I took a look at your Atallax code and I tend to comment like you, after the line of code rather than before it.

 

One thing I do tend to do, is use the .ifdef functionality in MADs so that I can re-use code again later but with different defines. I also use a lot of 'icl' (includes) to bring in vast amounts of code from outside.

 

Thank you for your contributions.

Link to comment
Share on other sites

as more closer to deadlines as more "hacks" appear :D

 

I tend to "hack" things in to see if they work and then I go back and fix them later - a pretty bad habit as it takes my time up.

 

However I am not working to a deadline, when it is finished, it is finished. Less pressure then.

 

I reckon I could have hacked a game together by now, but subsequent games wouldn't be able to re-use any code.

Link to comment
Share on other sites

... as each project is in the end too different.

 

That's what I used to think, but I have changed my mind now.

 

As long as you are working on the same kind of project (i.e. 2 games), then I think that a lot of the code can be the same.

 

For example, most games are similar in that they:

a) Have a title screen

b) Have a main game

c) A game over screen

d) High score entry

e) High score table display

 

Now it may well be that game 2 doesn't have high scores, in that case, you use the .ifdef functionality in MADS to not include those sections of code.

 

Then you'll probably say, "Yes, but Gauntlet is very different to Space Harrier, you need completely different dynamics in each".... , and yes, they are different.

 

However, if you take things up a level conceptually, you still have

a) Initialise variables

b) Set up screen

c) Process joystick / keyboard

d) Update hero characters

e) Update screen

f) Check for game / level completion, if so, jump out of main loop

g) Jump to c

 

Then (e) might be very different for updating the screen in Gauntlet to Space Harrier, but you use the .ifdef functionality to choose what functionality to use. You may well find that the general structure of the games underneath is very much the same.

 

Title screen

Load level

Set up game

Play game

Highscore (not needed for Gauntlet)

Display high score (not needed for Gauntlet)

Jump to title screen

 

Everything is coded from a library with lots of optional functionality.

 

That's just my opinion anyway, I've tried to apply what I've learnt in world of systems automation back to A8 programming, time will see if it is useful or not.

Link to comment
Share on other sites

- Display list

- NMI handler when OS is off

- LZ4 depacking while loading in xBIOS

- RMT music

- fastmul routines

 

And the great thing is, you can have all of those fastmul routines (and other routines) in a library, and if they don't get used in your main code, MADS doesn't compile it into the binary. How brilliant is that?

 

I may well be PMing you soon on something soon, I need some advice with some things you've been working on.

Link to comment
Share on other sites

I did put the code of my last game here:

http://atariage.com/forums/topic/191864-pad-15-beta/page-3?do=findComment&comment=2897188

(but this was started like 20 years ago, so there are like two programming styles coexisting here x) )

 

Some old demos with code:

http://www.atariage.com/forums/topic/108283-more-software-sprites/

http://www.atariage.com/forums/topic/119962-why-are-my-shape-tables-flickering/page__view__findpost__p__1453933

http://www.atariage.com/forums/topic/52701-bubble-bobble/page__view__findpost__p__1260463

 

I would say similar to Phaeron.. with lots of comments, starting with memory maps, vars and constants definitions, then the inclusion of some standard equates and macros files, code initialization (for games something like InitSystem, InitGame, InitLevel), a short main loop with some jsr calls (read input, game logic, draw screen, screen sync..), ending with interruptions and data areas and tables (P/M's, fonts, DL's..).

Also when the programs grows, logic groups of methods or data end in their own files.

  • Like 1
Link to comment
Share on other sites

I think that every game is so different that there is almost none code for reusing. At least that's my experience in my few games. All of them was coded from scratch with no code reuse with the exception of Rolltris/Thetris. And if I would reuse some code I would do it by copying and modifying rather than trying to have some universal code.

Edited by MaPa
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...