Jump to content



0

Does my Kernel code is Efficient?


4 replies to this topic

#1 fromo OFFLINE  

fromo

    Combat Commando

  • 7 posts
  • Location:from Monterrey, Mexico

Posted Sun Aug 7, 2005 10:53 AM

Hi!

I am just about to finish Andrew's 2600 Tutorial, but I decided to start again, because I felt that I needed more confidence at the moment I were doing my firts programs, so I decided to go to Kernel section.

I tried to modify a little bit the program that explain how to make the first Kernel, trying to make some blue stripes on the background, starting with light color blue, and ending with a little hard color blue, repeating in all the background, in order to share to you (the masters), this simple code (but great achievement for me), and know if I am in the right way.

Warning,,,,I am aware that this code is far to be efficient, so I would like to know what tricks I need to be present in order to make efficient code.

Sorry for the spanish comments that are included in my code, but Masters, is only a Kernel.



My best regards
Fernando Romo

Attached Files



#2 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Mon Aug 8, 2005 2:22 PM

Hi Fernando,

a few comments:

-generally speaking, you want to enable VBLANK at the start of the overscan and disable VBLANK immediately before drawing your picture (right before you begin the kernel) - your code as written is writing to the screen during the entire vblank period. I noticed this by running your .bin in z26; notice the line way at the bottom of the screen? That's where you are turning the screen back on right before VSYNC.

-you should mostly count down all your loops whenever possible:
               ldx #0
VerticalBlank   sta WSYNC
               inx
               cpx #37
               bne VerticalBlank
Would be better written as:
               ldx #37
VerticalBlank   sta WSYNC
               dex
                bne VerticalBlank

-and while we are looking at your vertical blank code, you will almost always want to use the timer, rather than counting scanlines, during the vertical blank and during the overscan.

-bob



fromo, on Sun Aug 7, 2005 9:53 AM, said:

Hi!

  I am just about to finish Andrew's 2600 Tutorial, but I decided to start again, because I felt that I needed more confidence at the moment I were doing my firts programs, so I decided to go to Kernel section.

  I tried to modify a little bit the program that explain how to make the first Kernel, trying to make some blue stripes on the background, starting with light color blue, and ending with a little hard color blue, repeating in all the background, in order to share to you (the masters), this simple code (but great achievement for me), and know if I am in the right way.

  Warning,,,,I am aware that this code is far to be efficient, so I would like to know what tricks I need to be present in order to make efficient code.

  Sorry for the spanish comments that are included in my code, but Masters, is only a Kernel.



My best regards
Fernando Romo

View Post



#3 fromo OFFLINE  

fromo

    Combat Commando

  • 7 posts
  • Location:from Monterrey, Mexico

Posted Mon Aug 8, 2005 8:52 PM

vdub_bobby, on Mon Aug 8, 2005 2:22 PM, said:

Hi Fernando,

a few comments:

-generally speaking, you want to enable VBLANK at the start of the overscan and disable VBLANK immediately before drawing your picture (right before you begin the kernel) - your code as written is writing to the screen during the entire vblank period.  I noticed this by running your .bin in z26; notice the line way at the bottom of the screen?  That's where you are turning the screen back on right before VSYNC.

-you should mostly count down all your loops whenever possible:
               ldx #0
VerticalBlank   sta WSYNC
               inx
               cpx #37
               bne VerticalBlank
Would be better written as:
               ldx #37
VerticalBlank   sta WSYNC
               dex
                bne VerticalBlank

-and while we are looking at your vertical blank code, you will almost always want to use the timer, rather than counting scanlines, during the vertical blank and during the overscan.

-bob



fromo, on Sun Aug 7, 2005 9:53 AM, said:

Hi!

  I am just about to finish Andrew's 2600 Tutorial, but I decided to start again, because I felt that I needed more confidence at the moment I were doing my firts programs, so I decided to go to Kernel section.

  I tried to modify a little bit the program that explain how to make the first Kernel, trying to make some blue stripes on the background, starting with light color blue, and ending with a little hard color blue, repeating in all the background, in order to share to you (the masters), this simple code (but great achievement for me), and know if I am in the right way.

  Warning,,,,I am aware that this code is far to be efficient, so I would like to know what tricks I need to be present in order to make efficient code.

  Sorry for the spanish comments that are included in my code, but Masters, is only a Kernel.



My best regards
Fernando Romo

View Post

View Post



Bob :

Thanks a lot for your comments, I would try to use the count down concept and also the timer, but regarding the way I am trying to do the things?, I mean, my goal was to see some blue stripes (horizontaly), over the background and I did it, but I donīt know if they were made in the right way?

My best regards
Fernando

#4 vdub_bobby OFFLINE  

vdub_bobby

    Quadrunner

  • 5,831 posts
  • Boom bam.
  • Location:Seattle, WA

Posted Mon Aug 8, 2005 9:06 PM

fromo, on Mon Aug 8, 2005 7:52 PM, said:

Bob :

  Thanks a lot for your comments, I would try to use the count down concept and also the timer, but regarding the way I am trying to do the things?, I mean, my goal was to see some blue stripes (horizontaly), over the background and I did it, but I donīt know if they were made in the right way?

My best regards
Fernando

View Post

You're welcome.

I couldn't completely understand your code due to the spanish comments (as long as you understand them!) but here's how I would accomplish what you did:

With two, nested loops:
   ldy #24
OuterLoop
   ldx #LIGHTCOLOR
InnerLoop
   sta WSYNC
   stx COLUBK
   dex
   dex
   cpx #DARKCOLOR
   bne InnerLoop
   dey
   bne Outerloop

Edited by vdub_bobby, Mon Aug 8, 2005 9:08 PM.


#5 fromo OFFLINE  

fromo

    Combat Commando

  • 7 posts
  • Location:from Monterrey, Mexico

Posted Mon Aug 8, 2005 10:11 PM

vdub_bobby, on Mon Aug 8, 2005 9:06 PM, said:

fromo, on Mon Aug 8, 2005 7:52 PM, said:

Bob :

  Thanks a lot for your comments, I would try to use the count down concept and also the timer, but regarding the way I am trying to do the things?, I mean, my goal was to see some blue stripes (horizontaly), over the background and I did it, but I donīt know if they were made in the right way?

My best regards
Fernando

View Post

You're welcome.

I couldn't completely understand your code due to the spanish comments (as long as you understand them!) but here's how I would accomplish what you did:

With two, nested loops:
   ldy #24
OuterLoop
   ldx #LIGHTCOLOR
InnerLoop
   sta WSYNC
   stx COLUBK
   dex
   dex
   cpx #DARKCOLOR
   bne InnerLoop
   dey
   bne Outerloop

View Post


Bob :

Very Impresive,,,,with only some lines you showed how to make a background like I wanted. So in order that you could understand a little bit what I tried to document "comments", in my program, I have just translated those comments to English (I hope that you could understand).

I appreciate a lot the time that you are spending on me. :)

Inicializar
ldy #173 ;begin with light blue
lda #0 ;load the Acumulator with zeros
sta TIEMPO ;initialize TIME var with zeros


Picture
sty COLUBK ;apply background color
inc TIEMPO ;inc, TIEMPO variable (width horizontal stripes)
sty COLOR ;stores current color in COLOR variable
ldy TIEMPO ;load "y", with TIEMPO value
cpy #5 ;Did it pass five scanlines?
bne no_decrementar ;NOP?, then, we must go to "no_decrementar" label
;YES?, the program flow continues here
;here (if we count 5 times, we must initialize TIEMPO)

;--------------------------------------------------------------------------
; This little section of the program is to decrement the "y" register
; in order to apply a darknest color in the background
;--------------------------------------------------------------------------

ldy COLOR ;we rescue COLOR value in "y" register
dey ;decrement the background color
sty COLOR ;store the new color COLOR variable
cpy #162 ;due we want that our color background from light to darknest
;we need to compare those values

beq valor_inicial_y ;if the values are the same, then, we must jump to
;"valor_inicial_y" label
;because there we must initiate again our background color to
;the original blue color (173)
;if the values are not the same, then,
; the flow of the program follows here
;if you remember when we compare against value 5, was true
;I mean, TIEMPO value was equal to 5
;then, we have to initialize TIEMPO variable to zeros


lda #0 ;load the Acumulator with zeros
sta TIEMPO ;store the Acumulator value to TIEMPO variable
jmp no_decrementar ;I did not found another smart idea,,but we need to jump
;to "no_decrementar" label
;---------------------------------------------------------------------------------
; This section "valor_inicial_y", does initiate the y register value
; with the color that we want to apply in the background of our Kernel
;---------------------------------------------------------------------------------
valor_inicial_y
ldy #173 ;load y with the initial color value
;that we want to apply to our background
lda #0 ;load A with zeros (to set TIEMPO)
sta TIEMPO ;store that value in TIEMPO
sty COLOR ;store y value in COLOR variable
;---------------------------------------------------------------------------------

no_decrementar
ldy COLOR
sta WSYNC
inx
cpx #192
bne Picture



Thanks a lot for your help!!!


My best regards
Fernando




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users