WJYkK wrote:
Code:
Frames=0
SecondsOnes=0
SecondsTens=0
MinutesOnes=0
MinutesTens=0
This is wrong, because what the assembler understands from this is that all of these variables will use memory location $00. You can imagine that the logic will fail completely in this case. Each of them must use a different memory location:
Code:
.enum $0000
Frames .dsb 1
SecondsOnes .dsb 1
SecondsTens .dsb 1
MinutesOnes .dsb 1
MinutesTens .dsb 1
.ende
I believe you can place this anywhere, but it makes more sense before the actual program, at the top of the source file. This is the best way to declare variables, because it's easy to move them around, remove them or add others as necessary. I suggest you declare all your variables inside ".enum" blocks. Then, before the main loop you clear these variables like
I told you to before:
Code:
lda #0
sta Frames
sta SecondsOnes
sta SecondsTens
sta MinutesOnes
sta MinutesTens
Quote:
Code:
NUMBERS_BASE=48
TIME_SEPARATOR=58
NUMBERS_BASE and TIME_SEPARATOR relate to 0 and : because I arranged my symbols by ASCII codes.
This is correct, because these are constants. But it also makes more sense to declare them at the top of the file, so that all your declarations are easy to find and not scattered across the whole program.
Quote:
Next, this is my main loop:
Code:
loop:
inc Frames
lda Frames
cmp #60
bne Done
ldx #0
stx Frames
inc SecondsOnes
lda SecondsOnes
cmp #10
bne Done
stx SecondsOnes
inc SecondsTens
lda SecondsTens
cmp #6
bne Done
stx SecondsTens
inc MinutesOnes
lda MinutesOnes
cmp #10
bne Done
stx MinutesOnes
inc MinutesTens
lda MinutesTens
cmp #6
bne Done
stx MinutesTens
Done: jmp loop
The problem is that you are jumping back right after updating the timer, which means that the timer will update several times in a single frame (it will run MUCH faster than an actual clock), while you have to update it only once. The program will also be stuck in this loop forever, as there is no way of getting out of it. And since you're stuck in this loop you are never going to write the numbers to the screen.
Quote:
And finally, I place this after my HUD and before the attribute table formation:
Code:
temp_bg:
lda #$20
sta $2006
lda #$60
sta $2006
clc
lda MinutesTens
adc #NUMBERS_BASE
sta $2007
lda MinutesOnes
adc #NUMBERS_BASE
sta $2007
lda #TIME_SEPARATOR
sta $2007
lda SecondsTens
adc #NUMBERS_BASE
sta $2007
lda SecondsOnes
adc #NUMBERS_BASE
sta $2007
This part of the code has nothing to do with the inial drawing of the screen. The initial screen will be drawn normally, before the game loop, but the piece of code above must run EVERY VBlank, not only once, so it must be part of your main loop.
See, this is what you should have as your main loop:
Code:
loop:
;CODE TO UPDATE THE TIMER GOES HERE
jsr wait_for_vblank
;CODE THAT DRAWS THE TIMER TO THE SCREEN GOES HERE
;CODE THAT RESETS THE SCROLL GOES HERE
jmp loop
I omitted the huge blocks of code because they all look correct, there's no reason for me to copy/paste them, so I just marked where they should go.
Remember what I told you about the structure of a game loop. First you update the state of the whole game world (this includes your timer), then you wait for VBlank, and then you do your graphical updates.
You have to program the "wait_for_vblank" subroutine. A very good example was posted
here by tepples. Note that you have to declare the "vblank" variable (you don't have to call it "vblank", you can call it whatever you want) and modify your NMI handler:
Code:
nmi:
inc vblank
rti
And of course, since you will be using NMIs you must make sure to enable them before the main loop starts (it seems you already are, so don't worry).
Resetting the scroll is just selecting the visible name table through $2000 and writing the pixel offsets to $2005. I didn't post any code because it's you who decides what part of the name tables you want to show (make sure to show the part where the numbers are written to!).
I guess this is it. Try to think a little about the order in which you are doing things, think about it logically and you should come to a conclusion about what makes sense. Don't just copy and paste code around hoping for the best, that never works.