Jump to content

Help With Code From Hugg's Book

Recommended Posts



I'm going through some code from Hugg's book "Making Games For Atari 2600";

particularly the LDA BGColor. Is A being loaded initially with #$00?

Since the variable BGColor location is at $81 (zero page), and zero page has been cleared after the CLEAN_START macro?


Thanks for any help clarifying this.


; Let's define a variable to hold the starting color
; at memory address $81
BGColor	equ $81

; The CLEAN_START macro zeroes RAM and registers

; Enable VBLANK (disable output)
	lda #2
        sta VBLANK
; At the beginning of the frame we set the VSYNC bit...
	lda #2
	sta VSYNC
; And hold it on for 3 scanlines...
	sta WSYNC
	sta WSYNC
	sta WSYNC
; Now we turn VSYNC off.
	lda #0
	sta VSYNC

; Now we need 37 lines of VBLANK...
	ldx #37
LVBlank	sta WSYNC	; accessing WSYNC stops the CPU until next scanline
	dex		; decrement X
	bne LVBlank	; loop until X == 0

; Re-enable output (disable VBLANK)
	lda #0
        sta VBLANK
; 192 scanlines are visible
; We'll draw some rainbows
	ldx #192
	lda BGColor	; load the background color out of RAM
	adc #1		; add 1 to the current background color in A
	sta COLUBK	; set the background color
	sta WSYNC	; WSYNC doesn't care what value is stored
	bne ScanLoop

; Enable VBLANK again
	lda #2
        sta VBLANK
; 30 lines of overscan to complete the frame
	ldx #30
LVOver	sta WSYNC
	bne LVOver
; The next frame will start with current color value - 1
; to get a downwards scrolling effect
	dec BGColor

; Go back and do another frame
	jmp NextFrame
	org $fffc
	.word Start
	.word Start


Link to comment
Share on other sites

Posted (edited)



I saw this code in another book, for initially clearing memory;


    ldx #$ff

    lda #$00


    sta $00,x ; when x=#$00 it doesn't get stored into memory location $00 due to the "bne clear"


    bne clear

With above code Memory location $00 is left uncleared?

Would this be a good solution?


    ldx #$0

    lda #$0


    sta $00,x

    dex           ;1st time through loop, x now = #$ff

    bne clear

Edited by TonyAme
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.

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.

  • Recently Browsing   0 members

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