Jump to content
IGNORED

Advice on Unnecessary Code


Recommended Posts

Dear Forum Members:

 

I have been following the Andrew Davie Tutorial on Randomterrain.com . I think that it is very well written. Essentially, I am learning assembly language from scratch. I have three questions that I hope that you may be able to help me with:

 

1. The code below is from an Excercise in chapter 13 : Playfield Basics. I have been able to complete the exercise making the playfield rainbow striped vs. the background. However, in achieving the effect, I believe that I have unnecessary code, which apparently is a 'no-no' in Atari programming because of the limitations. What unnecessary code can I take out below to make the solution still work?

 

2. The last exercise in this section asks, how do you make the Stripe appear on one side and not the other? It hints that you have to change the playfield mid-scanline. I do not know how to do this, but I think that it will be explained in a later chapter. Anyone have a very concise explanation?

 

I have a renewed appreciation for early video game programmers after going through the first 13 chapters! Any and all help is greatly appreciated!

 

 

------------------------------------------------

;

; My VCS Game

; by Author

;

; VCS template file by Ian Bogost

; http://www.bogost.com

;

;------------------------------------------------

processor 6502

include vcs.h

include macro.h

;------------------------------------------------------------------------------

 

 

 

PATTERN = $80 ; storage location (1st byte in RAM)

 

TIMETOCHANGE = 1 ; speed of "animation" - change as desired

;------------------------------------------------------------------------------

 

 

 

SEG

 

ORG $F000

 

 

 

Reset

 

 

 

; Clear RAM and all TIA registers

 

 

 

ldx #0

 

lda #0

 

Clear sta 0,x

 

inx

 

bne Clear

 

 

 

;------------------------------------------------

 

; Once-only initialization...

 

 

 

lda #%11111111

 

sta PATTERN ; The binary PF 'pattern'

 

 

 

lda #$54

 

sta COLUPF ; set the playfield color

 

 

ldy #0 ; "speed" counter

 

 

 

;------------------------------------------------

 

 

 

StartOfFrame

 

 

 

; Start of new frame

 

; Start of vertical blank processing

 

 

 

lda #0

 

sta VBLANK

 

 

 

lda #2

 

sta VSYNC

 

 

 

sta WSYNC

 

sta WSYNC

 

sta WSYNC ; 3 scanlines of VSYNC signal

 

 

 

lda #0

 

sta VSYNC

 

 

 

 

 

;------------------------------------------------

 

; 37 scanlines of vertical blank...

 

 

 

ldx #0

 

VerticalBlank sta WSYNC

 

inx

 

cpx #37

 

bne VerticalBlank

 

 

 

;------------------------------------------------

 

; Handle a change in the pattern once every 1 frames

 

; and write the pattern to the PF1 register

 

 

iny ; increment speed count by one

cpy #TIMETOCHANGE ; has it reached our "change point"?

 

bne notyet ; no, so branch past

 

ldy #0

 

 

 

notyet

 

 

 

 

lda PATTERN

 

sta PF1 ; as the playfield shape

 

;------------------------------------------------

 

; Do 192 scanlines of color-changing (our picture)

 

 

ldx #0 ; this counts our scanline number

 

 

 

Picture ; change background color (rainbow effect)

 

sta WSYNC ; wait till end of scanline

 

stx COLUPF

 

 

inx

 

cpx #192

 

bne Picture

 

 

 

;------------------------------------------------

 

 

 

 

 

 

 

lda #%01000010

 

sta VBLANK ; end of screen - enter blanking

 

 

 

; 30 scanlines of overscan...

 

 

 

ldx #0

 

Overscan sta WSYNC

 

inx

 

cpx #30

 

bne Overscan

 

 

 

 

 

 

 

 

 

 

 

jmp StartOfFrame

 

 

 

 

;------------------------------------------------------------------------------

 

 

 

ORG $FFFA

 

 

 

InterruptVectors

 

 

 

.word Reset ; NMI

 

.word Reset ; RESET

 

.word Reset ; IRQ

 

 

 

END

Link to comment
Share on other sites

jonmower,

very cool you are learning 6502 Asm! :)

 

The only unnecessary code I see is pretty minor:

1. you can remove notyet bne and ldy #0; this code is superflous because the register "wraps around" to zero after 255.

2. If you dex down x instead of incrementing it a cpx #0 is implicit - you don't need to issue it, can just beq or bne.

 

For the concise explanation you are looking for issue a bunch of nop's (try 10,15 or 20)

then lda #0 sta PF1; this will clear the playfield register after it's been written on one side of the screen but before it is written to the other side (later you could replace the nop's with usefull code that takes as many cycles).

 

You might also like to try the Abstract Assembly Development Kit (in my signature) to build games fast with less emphasis on counting cycles and optimising.

  • Like 1
Link to comment
Share on other sites

Thanks, Moonsweeper. I have played with the Nops, but I am still getting symmetry. In the above code, where should I stick the Nops and PF1 =0?

Right after you've set it, however you are setting it outside your 192 colour changing loop so also move that block to right after

the colour change - everything should happen there so that it occurs with each visible scanline:

 

stx COLUPF lda PATTERN sta PF1 nops.... lda #0 sta PF1

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...