changing the background colour

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

catsoncrack1
Posts: 7
Joined: Tue Jan 22, 2019 3:04 pm

changing the background colour

Post by catsoncrack1 » Tue Jan 29, 2019 2:50 pm

Hey guys, I'm new to assembly and nes programming, after watching a few tutorials, copying and pasting their code into VIM I have made this mess:

Code: Select all

.segment "HEADER"
  .byte "NES" 
  .byte $1a 
  .byte $02
  .byte $01
  .byte %00000000
  .byte $00 
  .byte $00 
  .byte $00
  .byte $00 
  .byte $00,$00,$00,$00,$00
;  ----------------------------------------------------------

.segment "STARTUP"            ; avoids warnings
.segment "CODE"

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

Reset:                        ; reset routine
  SEI
  CLD
  LDX #$00                    ; turn of screen
  STX $2000
  STX $2001
  DEX
  TXS
  LDX #0
  TXA
ClearMemory:                  ; clr mem b/c old memory may be left on reset
  LDA #$00
  STA $0000, x
  STA $0100, x
  STA $0200, x
  STA $0400, x
  STA $0500, x
  STA $0600, x
  STA $0700, x
  LDA #$FE
  STA $0300, x
  INX
  BNE ClearMemory

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

  LDA #%00000000              ; loading PPU?
  STA $2001
  LDA #%10001000
  STA $2000
  LDA #$3F
  STA $2006
  LDA #$00
  STA $2006
  STA $2007
  CLI

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

.segment "VECTORS"

.segment "CHARS"
i am using ca65, the program compiles and runs on fceux
it gives me a grey background, is there a way to change the background to a different colour?
i tried messing with LDA #$00 and LDA #$3F and got nothing :(
any help will be useful thanks :)

User avatar
dougeff
Posts: 2600
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: changing the background colour

Post by dougeff » Tue Jan 29, 2019 3:35 pm

LDA #%00000000 ; loading PPU?
STA $2001
that's not how you turn the screen on.

usually it's $1e (0001 1110)
LDA #$3F
STA $2006
LDA #$00
STA $2006
STA $2007
You shouldn't write to the PPU unless you are in vertical blank period, or the screen is off. Probably should go before the write to 2001.

Do you understand what 2006 and 2007 do? or why this might change the BG to gray?
CLI
Don't turn interrupts on, until you learn a little more.

And, you should have an infinite loop at the end.

Infinite:
jmp Infinite
nesdoug.com -- blog/tutorial on programming for the NES

catsoncrack1
Posts: 7
Joined: Tue Jan 22, 2019 3:04 pm

Re: changing the background colour

Post by catsoncrack1 » Tue Jan 29, 2019 4:06 pm

dougeff wrote:
LDA #$3F
STA $2006
LDA #$00
STA $2006
STA $2007
You shouldn't write to the PPU unless you are in vertical blank period, or the screen is off. Probably should go before the write to 2001.

Do you understand what 2006 and 2007 do? or why this might change the BG to gray?
CLI
Don't turn interrupts on, until you learn a little more.

And, you should have an infinite loop at the end.

Infinite:
jmp Infinite
im not 100% on what 2006 and 2007 do :(
also i have no clue on why CLI turns the background grey

my goal is to get the background to turn purple or green
Also BIG thank you for the help, ill write in a VBLANK and infinite loop then.

EDIT:

Code: Select all

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

.segment "STARTUP"            ; avoids warnings
.segment "CODE"

WaitVblank:
:
    BIT $2002
    BPL :-
    RTS

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

Reset:                        ; reset routine
  SEI
  CLD
  LDX #$00                    ; turn of screen
  STX $2000
  STX $2001
  DEX
  TXS
  LDX #0
  TXA
  
  JSR WaitVblank

ClearMemory:                  ; clr mem b/c old memory may be left on reset
  LDA #$00
  STA $0000, x
  STA $0100, x
  STA $0200, x
  STA $0400, x
  STA $0500, x
  STA $0600, x
  STA $0700, x
  LDA #$FE
  STA $0300, x
  INX
  BNE ClearMemory

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

  JSR WaitVblank

  LDA #%00000000
  STA $2001
  LDA #%10001000
  STA $2000
  LDA #$3F
  STA $2006
  LDA #$00
  STA $2006
  STA $2007
  CLI
Infinite:
  JMP Infinite

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

here is the code now, idk what waitvblank does or JSR i just took it from a sample i found online
sorry for being so for my lack of knowledge :p

User avatar
tokumaru
Posts: 11445
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: changing the background colour

Post by tokumaru » Tue Jan 29, 2019 4:22 pm

First, here's a list of some needed changes so this becomes a working NES program:

1- Wait for the PPU to warm up: the PPU needs some time to "boot up" before it can be used. Clearing RAM takes some time, but not enough. Put something like this after clearing the memory to make sure the PPU is ready for use:

Code: Select all

  bit $2002 ;make sure the vblank flag is clear
Wait1:
  bit $2002 ;read the vblank flag
  bpl Wait1 ;keep reading until it's set
Wait2:
  bit #2002 ;read the vblank flag
  bpl Wait2 ;keep reading until it's set again
2- Enable rendering: rendering is enabled via PPU register $2001. You're writing 0 to it, which keeps rendering off. The background color will sometimes still show when rendering is off, but in order to display proper graphics you need to turn rendering on. And be sure to do it *after* the color has been written, since you can't write to the PPU when rendering is on.

3- Remove the CLI and replace it with an infinite loop instead: CLI clears the IRQ inhibit flag, allowing IRQs to fire (it has nothing to do with the gray color). You're not using IRQs, so you don't need that. An infinite loop is just a JMP to itself:

Code: Select all

WaitForever:
  JMP WaitForever
OK, once all that is sorted out, let's get to changing the background color. The background color is defined by the byte stored at PPU memory address $3F00. To access that address (which can only be done during vblank or when rendering is off), we write it to register $2006 (that's the PPU address register). Then, we write the color value to $2007 (PPU data register).

That code is trying to be "smart", reusing the lower byte of the address ($00) for the color. Color $00 is gray, so that's why you're getting that color. Simply changing the $00 to something else (like you said you tried) doesn't work because that also changes the address being written, so the color doesn't go to $3F00 anymore (e.g. you may end up writing color $25 to address $3F25, which's *not* the background color). What you want to do is write another LDA #$XX command before the STA $2007 line (where $XX is the number of the color you want), so that the address remains $3F00 but a color other than $00 gets written there.

catsoncrack1
Posts: 7
Joined: Tue Jan 22, 2019 3:04 pm

Re: changing the background colour

Post by catsoncrack1 » Tue Jan 29, 2019 4:42 pm

Code: Select all

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

  BIT $2002                   ; checks for clear vblank flag -> PPU WARM UP
Wait1:
  BIT $2002                   ; read vblank flag
  BPL Wait1                   ; keep reading until vblank flag is set
Wait2:
  BIT $2002                   ; read the vblank flag -> # typo? @tokumaru
  BPL Wait2                   ; keep reading until it's set again

  LDA #%00000000
  STA $2001
  LDA #%10001000
  STA $2000
  LDA #$3F
  STA $2006
  LDA #$00
  STA $2006
  LDA #$03
  STA $2007
Infinite:
  JMP Infinite

; -----------------------------------------------------------
ok so this is the ppu code now where do i write the turn on rendering bit?
after the Infinite jump or before?
Again thanks for the help everyone this experience has been really insightful :)

User avatar
tokumaru
Posts: 11445
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: changing the background colour

Post by tokumaru » Tue Jan 29, 2019 4:56 pm

catsoncrack1 wrote:now where do i write the turn on rendering bit?
These 2 instructions are supposed to turn rendering on:

Code: Select all

  LDA #%00000000
  STA $2001
...but they're in the wrong place and you're using the wrong value. Move that to just before the infinite loop (i.e. after you're done writing data to the PPU) and change the #%00000000 to a value that will actually turn rendering on, like #%00011110 (as suggested by dougeff). You can check the wiki to see what each bit does.

Keep in mind that you might get garbage graphics after turning rendering on, since you did not setup the name tables, the scroll, or the sprites.
after the Infinite jump or before?
Nothing after the infinite loop will run... it is an infinite loop after all! The only way to execute code after that loop is by explicitly jumping there with a branch, JMP or JSR, from within the infinite loop.

catsoncrack1
Posts: 7
Joined: Tue Jan 22, 2019 3:04 pm

Re: changing the background colour

Post by catsoncrack1 » Tue Jan 29, 2019 6:31 pm

Code: Select all

.segment "CODE"

WaitVblank:
:
    BIT $2002
    BPL :-
    RTS

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

Reset:                        ; reset routine
  SEI
  CLD
  LDX #$00                    ; turn of screen
  STX $2000
  STX $2001
  DEX
  TXS
  LDX #0
  TXA
  
  JSR WaitVblank

ClearMemory:                  ; clr mem b/c old memory may be left on reset
  LDA #$00
  STA $0000, x
  STA $0100, x
  STA $0200, x
  STA $0400, x
  STA $0500, x
  STA $0600, x
  STA $0700, x
  LDA #$FE
  STA $0300, x
  INX
  BNE ClearMemory

; -----------------------------------------------------------
  
  BIT $2002                   ; checks for clear vblank flag -> PPU WARM UP
Wait1:
  BIT $2002                   ; read vblank flag
  BPL Wait1                   ; keep reading until vblank flag is set
Wait2:
  BIT $2002                   ; read the vblank flag
  BPL Wait2                   ; keep reading until it's set again

  LDA #%10001000
  STA $2000
  LDA #$3F
  STA $2006
  LDA #$03                    ; purple background
  STA $2007
  LDA #%00011110              ; rendering on
  STA $2001
Infinite:
  JMP Infinite

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

.segment "VECTORS"

.segment "CHARS"
Ok this is what i have so far ( minus the header segment )
The background is still grey, but how does this look so far?

User avatar
tokumaru
Posts: 11445
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: changing the background colour

Post by tokumaru » Tue Jan 29, 2019 7:08 pm

No, your PPU writes are still wrong. You need:

Code: Select all

lda #$3F ;high byte of PPU address
sta $2006
lda #$00 ;low byte of PPU address
sta $2006
lda #$03 ;color you want to write
sta $2007
Addresses are 16 bits, so you need 2 8-bit writes to have the PPU point to the address where the background color goes, and then you write the color to the data port.

User avatar
koitsu
Posts: 4214
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: changing the background colour

Post by koitsu » Tue Jan 29, 2019 7:11 pm

The "grey background" is an effect of FCEUX: basically, if you haven't fully initialised most of the PPU RAM (nametables, attribute tables, palette, pattern table or CHR-RAM, etc.), the emulator defaults to showing you a grey background.

We have a Wiki page which gives proper/good initialisation code, and the order of such: https://wiki.nesdev.com/w/index.php/Init_code -- yours differs quite a bit (particularly for PPU warmup), so you'd be best following what's there.

Next stuff for you to try doing is initialising nametables and attribute table -- your pattern table appears to be CHR-ROM, so no need to worry about $0000-1FFF -- followed by the palette. What you're going to need to know:

https://wiki.nesdev.com/w/index.php/PPU_memory_map
https://wiki.nesdev.com/w/index.php/PPU_nametables
https://wiki.nesdev.com/w/index.php/PPU ... ute_tables
https://wiki.nesdev.com/w/index.php/PPU_palettes

Your goal should be to initialise the PPU RAM memory so that all the tiles are the same (say, tile $00) and all the pixels end up colour 0 so that you end up changing the colour of the entire screen/background.

Your existing code for interfacing with the PPU is incorrect (code: lda #$3f / sta $2006 / lda #$03 / sta $2007).

PPU RAM addresses are 16-bit. The way you set the PPU RAM address is through $2006. But $2006 is an 8-bit MMIO register, so how do you write a 16-bit address to it? You write to it twice. $2007 is the MMIO register that you use to read or write data to/from the PPU RAM, 8 bits at a time. The PPU RAM address will internally will auto-increment by 1 or 32 (depending on what you set in $2000), so you don't necessarily have to set $2006 every single time. For example, if you wanted to make PPU RAM $3f00 (colour #0 in the palette) contain the value $03 (a kind of purple) and PPU RAM $3f01 (colour #0 in the palette) contain the value $0a, you'd do this:

Code: Select all

lda #$3f
sta $2006
lda #$00
sta $2006
lda #$03
sta $2007
lda #$0a
sta $2007
What you're going to end up spending most of your time understanding on the NES is how $2000/2002/2005/2006/2007 work and interact. The general concept is very easy/simple ("oh, you write the address of the PPU RAM you want to access to $2006, then you write the data to $2007!"), but it's highly nuanced given that $2005 and $2000 and $2002 play a very important role (and the order in which you write to or read from those registers matters!). I'm intentionally avoiding linking to that wiki page because it will overwhelm you and you'll become frustrated and probably lose interest (just trust me).

Stick with something like:

1. Changing the colour of the entire screen so that it's purple ($03)
2. Make the top half of the screen purple ($03) and the lower half green ($0a)
3. Changing your CHR-ROM graphics so that they use multiple colours (say, the letter "T" where part of the T is one colour and another part is a different colour) and adding those colours to the palette using code -- stick to using the lower 8 colours at first (trust me! This doesn't require familiarity with the attribute table)
4. Learning about the attribute table, and start to experiment with using the additional 8 colours -- the "Worked example" section of the PPU attribute table wiki page is helpful because it shows you visually how things break down
5. Understand how palette entries 0, 4, 8, and 12 behave (hint: you essentially only have one colour shared between all of those, so the NES only has effectively 13 palette entries available to use. It'll make more sense later)

catsoncrack1
Posts: 7
Joined: Tue Jan 22, 2019 3:04 pm

Re: changing the background colour

Post by catsoncrack1 » Thu Jan 31, 2019 3:02 pm

Ok so i took a shot at initializing nametable 0, not sure if im doing it right. No assembler errors though :)

Code: Select all

  
LDA #%00000000              ; init nametable 0?
  STA $2000
  LDA #$20
  STA $2006
  LDA #$00
  STA $2006
I stored #%00000000 into 2000 because i guess that sets off the nametable 0 flag
and then i wrote #$20 and #$00 to $2006 because i want to write my rending code to nametable 0?
I think I am missing something, Is my thinking on the right track though?

User avatar
dougeff
Posts: 2600
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: changing the background colour

Post by dougeff » Thu Jan 31, 2019 3:51 pm

The nametable bits in 2000 are part of the scrolling system. It probably should be written at least once, just so the scrolling goes where you want. It doesn't affect writes to PPU. Also the control for writing +1 (left to right) rather than +32 (top to bottom) is in 2000. That's important, and does affect writes to PPU.

Usually when people talk about initializing, they also mean zeroing out the RAM. So, adding a loop that writes 1024 zeros starting at PPU $2000 would do it.

STA $2007 for writing to PPU.
nesdoug.com -- blog/tutorial on programming for the NES

catsoncrack1
Posts: 7
Joined: Tue Jan 22, 2019 3:04 pm

Re: changing the background colour

Post by catsoncrack1 » Thu Jan 31, 2019 5:34 pm

hey guys so this is the PPU code now

Code: Select all

; -----------------------------------------------------------
  
  BIT $2002                   ; checks for clear vblank flag -> PPU WARM UP
Wait1:
  BIT $2002                   ; read vblank flag
  BPL Wait1                   ; keep reading until vblank flag is set
Wait2:
  BIT $2002                   ; read the vblank flag
  BPL Wait2                   ; keep reading until it's set again

  LDA #$3F                    ; point to palette in VRAM - $3F00
  STA $2006
  LDA #$00
  STA $2006
  
  LDA #$20                    ; point to nametable 0 in VRAM
  STA $2006
  LDA #$00
  STA $2006

  LDY #04                     ; clear nametables
ClearNameTables:
  LDX #$00
  LDA #$00
PPULoop:
  STA $2007
  DEX
  BNE PPULoop

  DEY
  BNE ClearNameTables

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

  LDA #$20                    ; point to first nametable in VRAM
  STA $2006
  LDA #$00
  STA $2006

  LDY #$00
  LDX #$04

  LDA #$03                    ; writing colour
  STA $2007
  LDA #$0A
  STA $2007
  
Vblank:                       ; turning on screen
 BIT $2002
 BPL Vblank

 LDA #%10001000
 STA $2000
 LDA #%00011110               ; rendering on
 STA $2001

 LDX #$00                     ; set scroll to zero
 STX $2005
 STX $2005

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

Infinite:
  JMP Infinite

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

it is starting to get pretty crazy, i still get the grey screen how does it look so far though?
Im not sure if my ClearNameTables and PPULoop is the right way to refresh the nameable memory.
Also do i still have to point to the attribute table?

User avatar
dougeff
Posts: 2600
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: changing the background colour

Post by dougeff » Thu Jan 31, 2019 8:32 pm

Code: Select all

  LDA #$20                    ; point to first nametable in VRAM
  STA $2006
  LDA #$00
  STA $2006 ;SETS AN ADDRESS TO $2000 = tilemap #0

...

  LDA #$03                    ; writing colour
  STA $2007
  LDA #$0A
  STA $2007
Well, you haven't written to the palette. This wrote tile 3 at the top left of the screen, and tile A to the square to the right of that.

The palette is at $3f00, and nothing has been written to that.

lda #$3f
sta $2006
lda #$00
sta $2006
lda #$12 ;blue
sta $2007

This would turn the background color blue.
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
tokumaru
Posts: 11445
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: changing the background colour

Post by tokumaru » Thu Jan 31, 2019 10:11 pm

catsoncrack1, I hope this doesn't sound rude, but it's clear by now that you have absolutely no idea what you're doing here... you're randomly trying things to see what works, and this clearly isn't working out for you. I mean, even if you got something to work by accident, you wouldn't learn much from that because you wouldn't know *why* it worked.

I suggest you take a step back and try to understand the basics of how the console works so you can better understand what needs to be done in order for the console to generate an image, and you'll have much better chances of writing working code.

The PPU generates images based on a set of configuration and a bunch of data. The configurations are things like "which set of tiles to use", "which name table to display", "color and grayscale filters", and so on. These settings are modified via memory mapped registers, you basically read the documentation about these registers and write the values that will select the settings you want.

As for the data that the PPU needs, that's the pattern tables (the 8x8 bitmap tiles used for sprites and backgrounds), name tables (which tiles compose the background "grid"), attribute tables (what palettes color the tiles in name tables), palette RAM (which colors make each palette) and OAM (where sprites go, which tiles they use, and other sprite settings). All of these is stored in memory in different parts of the system, but, except for the OAM, everything appears to the programmer as a single chunk of memory, which's very convenient. PPU memory isn't directly accessible by the CPU though, so you need to use a couple of PPU registers to access that memory (i.e. you tell the PPU where you want to store the data, then you send the data, and the PPU will take care of putting it where you requested).

The PPU registers used to access the PPU memory are visible at addresses $2006 and $2007 in the CPU addressing space, which the CPU *does" have access to. This is a bit complicated, bit this is how communication between different pieces of hardware in oldschool computer works: The console "listens" to accesses to special memory addresses and redirects these to the corresponding pieces of hardware. No need to think too much about this for now, just keep in mind that accessing memory and talking to other parts of the hardware looks the same as far as the CPU is concerned, the different is in the specific addresses being accessed.

The 2 PPU registers used for accessing PPU memory are called PPUADDR ($2006) and PPUDATA ($2007). The former is used to tell the PPU which address you're going to access, and the latter is what you use to transfer the data itself. Addresses are 16-bit, but the 6502 can only transfer 8-bits at once, so you need 2 writes to set an address. After that, you can write one or more bytes of data and they'll be stored sequentially starting from the address you specified. Example:

Code: Select all

;PPU, can you please point to address $3F00?
lda #$3F
sta $2006
lda #$00
sta $2006

;PPU, can you please store $1A at the address you're currently pointing to?
lda #$1A
sta $2007
and that's how you write stuff to PPU memory. A valid picture needs at least:

1- Tiles in the pattern tables. If you're using the NROM mapper, the pattern tables are automatically populated by the .chr file included in your project, you don't need to do anything else.

2- Name table pointing to the tiles present in the pattern table selected for the background. Each tile has an index, ranging from 0 to 255. A full name table is 32x30 tiles, so you need to write 960 bytes starting at PPU address $2000 (where the first name table is - don't confuse with the memory-mapped register PPUCTRL, which's visible in CPU address $2000) to have a completely filled name table.

3- Attribute table. Yeah, these are kinda hard to grasp at first, so be sure to write all 0s to the attribute table corresponding to the name table you're using (the first AT is at PPU $23C0). This will cause all tiles to use palette 0. A full attribute table is 64 bytes.

4- A palette. Since all your tiles will be using the same palette, just writing one palette is fine. Palettes start at PPU $3F00, so if you write 4 bytes starting from that address, that'll be the first palette.

Once all that memory is properly populated, you can set the scroll to point to the name table you're using (select the name table via PPUCTRL -accessible via CPU $2000-, and then reset the scroll to 0 by writing to PPUSCROLL -accessible at CPU $2005- twice) and turn background rendering on.

Does this make sense so far? If not, please ask anything you want here and we'll try to make things clearer for you. Writing your first program can be hard if you're not familiarized with the concepts of retro computer architecture, but resorting to random guesses can be really frustrating and can even teach you the wrong things. If you have a basic understanding of how things work, you can at least come up with theories on how to achieve your goals, and make educated guesses about what code you need to write.

catsoncrack1
Posts: 7
Joined: Tue Jan 22, 2019 3:04 pm

Re: changing the background colour

Post by catsoncrack1 » Mon Feb 04, 2019 7:09 pm

Hey guys I got it to work, thanks for the help everyone!!
My next quest is to display a sprite on the screen :)
Here is the code, remember to write in vectors lmao!

Code: Select all

.segment "HEADER"
  .byte "NES" 
  .byte $1a 
  .byte $02
  .byte $01
  .byte %00000000
  .byte $00 
  .byte $00 
  .byte $00
  .byte $00 
  .byte $00,$00,$00,$00,$00
;  ----------------------------------------------------------

.segment "STARTUP"            ; avoids warnings
.segment "CODE"

WaitVblank:
:
    BIT $2002
    BPL :-
    RTS

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

RESET:                        ; reset routine
  SEI
  CLD
  LDX #$00                    ; turn of screen
  STX $2000
  STX $2001
  DEX
  TXS
  LDX #0
  TXA
  
  JSR WaitVblank

ClearMemory:                  ; clr mem b/c old memory may be left on reset
  LDA #$00
  STA $0000, x
  STA $0100, x
  STA $0200, x
  STA $0400, x
  STA $0500, x
  STA $0600, x
  STA $0700, x
  LDA #$FE
  STA $0300, x
  INX
  BNE ClearMemory

  JSR WaitVblank

; -----------------------------------------------------------
  
  BIT $2002                   ; checks for clear vblank flag -> PPU WARM UP
Wait1:
  BIT $2002                   ; read vblank flag
  BPL Wait1                   ; keep reading until vblank flag is set
Wait2:
  BIT $2002                   ; read the vblank flag
  BPL Wait2                   ; keep reading until it's set again

  LDA #$3F                    ; point to palette in VRAM - $3F00
  STA $2006
  LDA #$00
  STA $2006
  
  LDA #$20                    ; point to nametable 0 in VRAM
  STA $2006
  LDA #$00
  STA $2006

  LDY #04                     ; clear nametables
ClearNameTables:
  LDX #$00
  LDA #$00
PPULoop:
  STA $2007
  DEX
  BNE PPULoop

  DEY
  BNE ClearNameTables

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

  LDA #$20                    ; point to first nametable in VRAM
  STA $2006
  LDA #$00
  STA $2006

  LDY #$00
  LDX #$04

  LDA #$3F                   ; writing colour
  STA $2006
  LDA #$00
  STA $2006
  LDA #$16                    ; orange
  STA $2007
  
VBLANK:                       ; turning on screen
 BIT $2002
 BPL VBLANK

 LDA #%10001000
 STA $2000
 LDA #%00011110               ; rendering on
 STA $2001

 LDX #$00                     ; set scroll to zero
 STX $2005
 STX $2005

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

Infinite:
  JMP Infinite

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

.segment "VECTORS"
    .word VBLANK
    .word RESET
    .word 0

.segment "CHARS" 

Post Reply