Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2021-03-08 11:07:57

dr-ivan
New member
Registered: 2021-03-08
Posts: 3

What is best practice for program structure?

Hi all,

I am kinda new to GB development, my only previous experience with z80 assembly being a snake on a TI-83 calculator. I am now making a breakout clone (for a change) as my first GB project. A quick question about program structure, interrupts etc...

What I have now is:

- main loop basically containing ei and halt instruction looped over and over again
- Vblank interrupt which calls a function to check if my game logic has asked for updates to some BG tiles or whatever, and then plus runs through the DMA routine
- Timer interrupt, currently at 4kHz, which runs the game logic, updates ball position, and will do some collision detection etc in the future

My question is: Is it standard practice to run main game logic from the timer interrupt? Is it good / bad, what do you people prefer? Any "best practice" advice?

Thanks in advance!

Offline

 

#2 2021-03-08 15:28:32

toxa
Member
Registered: 2020-02-13
Posts: 309

Re: What is best practice for program structure?

i guess the best practice is not overcomplicate things. smile

Offline

 

#3 2021-03-10 08:05:22

tmk
Member
Registered: 2017-05-01
Posts: 63
Website

Re: What is best practice for program structure?

Honestly, I've never heard of or seen any game coded in such manner. Using timer you're wasting a couple of frames, so why not to move it to main loop?

Offline

 

#4 2021-03-10 17:10:09

dr-ivan
New member
Registered: 2021-03-08
Posts: 3

Re: What is best practice for program structure?

Yeah, dunno - not the way I would have done it under any other circumstance either, so perhaps I *am* over-complicating things for myself. I thought that it would gave me better timing control if I wanted do sound and somesuch later on (I have no idea how it works, but I guess there is some tight timing involved?)

So the standard way would be something like:

Code:

main_loop:
    ; game logic goes here...
    call wait_vblank
    ; update shadow OAM / tiles etc...
    call dma_transfer_routine
    jp main_loop

Please do not take offense to this - my assembly experience is limited, and my GB-knowledge is basically non-existent. I am just looking for some basic advice smile

Last edited by dr-ivan (2021-03-10 19:00:06)

Offline

 

#5 2021-03-11 05:44:43

tmk
Member
Registered: 2017-05-01
Posts: 63
Website

Re: What is best practice for program structure?

Well. it's natural when you've just started. Get yourself a manual. This is quite handy and page 116 has typical template used in many games.
As for sound, majority of replay routines is called once per frame, so vblank or LCD interrupt are better suited for this.

Offline

 

#6 2021-03-16 10:31:15

dr-ivan
New member
Registered: 2021-03-08
Posts: 3

Re: What is best practice for program structure?

Thank you for the pointer - working nicely so far! smile

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson