Hello World Frustration

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Hello World Frustration
by on (#40745)
Hey there, alright. So I've done the basics. I've read quite a few guides (GBAGUY, NES101, Bunnyboy's NESASM Tutorial) and skimmed through YOSHi's master-documentation.

I made a couple small programs including a small pong-like program, and the set-up for a tic-tac-toe program... but my biggest frustration is finding information on how to write text.

Every place I've found briefly mentions something about $2006 or something, and putting sprites in the "right spot" in your chr file... but I searched the pages here and several places online including zophar's... and I just can't seem to find something that will help me display text on the screen.

Now I most likely just missed something but I've been looking for about an hour and a half now for this info... and it is slightly frustrating. (Not blaming anyone, I'm mostly frustrated with myself!)

Can anyone point me in the right direction? :)

Thanks.

by on (#40746)
Welcome to the NESdev community :).

First of all, I'd just like to say that writing text isn't really a category in NES programming. You put stuff on the background, or you put sprites on the screen. Most of the time, however, writing text is done by placing tiles which hold the graphical data of alphabetical characters on the background.

Do you know how to put a string of tiles on the screen? If you type this in your asm file:

.db "HELLO"

Your assembler should translate it to:

.db $48,$45,$4C,$4C,$4F

So if you know how to copy that string of tiles on screen, then there's one thing to do. Draw the alphabetical characters A-Z in the pattern table starting at $41, so tile $41 will contain the letter 'A', tile $42 will contain the letter 'B', etc. You should end with 'Z' on $5A.

Sorry if I'm not making any sense. I'm assuming if you've made a pong clone or a tic-tac-toe setup, you know how to write to the background. If you don't, that's not a problem; I'd be happy to explain it. It's just late right now and I'd like to save a useless explanation if I can.

EDIT: Okay, just quick, if that didn't help, try this:

lda #$21
sta $2006
lda #$C9
sta $2006

lda #$48
sta $2007
lda #$45
sta $2007
lda #$4C
sta $2007
sta $2007
lda #$4F
sta $2007

lda #$00
sta $2005
sta $2005

Where in the pattern table, tile $48 contains the graphics for the letter 'H', in tile $45 the graphics for 'E', for $4C the graphics for 'L', and for $4F the graphics for 'O'. For testing purposes, I don't think that it's wise to try and draw an alphabet though. If you have something like YY-CHR you can totally rip off a font from almost any game.

by on (#40754)
Alright, awesome. First, thanks for the welcome :)

Now next, When I do this, I seem to get the same character no matter what I change .db "HELLO" to. I'm not looping it so I only expect to get the "H", but instead I just get this blob character no matter what I change the "H" to.

If you'd like me to include some source, I'd be glad to :)

Thanks again for the big help. I've been doing hobby programming since .. around '92 in QBasic (Then went on to VB, C, FreeBasic, and all that HTML/CSS/PHP stuff), but this is the first language I've done where you learn graphics before text! Hah :)

As far as this goes though, I think if I looked at an example that simply includes the CHR file and the ASM file that displays "HELLO WORLD", I should be fine.

Thanks again :)

edit: I guess my main confusion is this: Is there a set place where you're SUPPOSED to put your text tiles? I'd assume since $48 is "H" that I can only place my "H" character in $48? Also, are there any tile editors that show the tile information of the tile your editing? I'll look a bit more... but I was told Tile Edit, but honestly, while it does its job... I hate not having the information I need in each tile.

by on (#40756)
I'm not sure what the problem would be; you should post the source up. perhaps it's a typo like .include instead of .incbin for the CHR file.

Well, you've certainly been programming longer than I have. I started programming around 2005, but I've learned a lot since. I know some Qbasic, a little visual basic, I'm pretty far in learning C, I know 6502, I forgot all the HTML I ever learned pretty much (since it was so small), I know some Z80, and probably a little more of other stuff. I'm mainly focused now on learning C so I can make level building apps for my NES games.

by on (#40757)
Regardless of Experience, you still have me beat at ASM :D

Here is my file:

hellotest.asm
Code:
; Header
   .inesprg 1 
   .ineschr 1 
   .inesmir 1 
   .inesmap 0 

   .bank 1   
   .org $FFFA
   .dw 0
   .dw Start          ; Start Address
   .dw 0            ; PPU - Don't make an Interupt for VBlank

   .bank 0
   .org $0000   
; Variables
Hello   .db "H"

   .org $8000        ; Code starts at $8000
; PPU   
Start: 
   lda #%00001000     ; Setup PPU
   sta $2000
   lda #%00011110
   sta $2001

   ldx #$00          ; Clear x

   lda #$3F          ; $2006 tells $2007
   sta $2006         ; To start at $3F00
   lda #$00          ; (The Pallete)
   sta $2006
; Pallete
loadpal:
   lda tilepal, x 
   sta $2007
   inx
   cpx #32
   bne loadpal         ; X <> 32 then goto loadpal
; Main
waitblank:
   lda $2002
   bpl waitblank      ; If top bit isn't set THEN loop until it is.

   lda #$00            ; $2003 tells $2004 to start
   sta $2003           ; at $0000
   lda #$00
   sta $2003
   
   lda #20           ; Load/Store Y-Pos
   sta $2004
   lda Hello         ; Load/Store Tile Number
   sta $2004
   lda #$00          ; Load/Store Flag
   sta $2004
   lda #20           ; Load/Store X-pos
   sta $2004          ; Do not change this order. YTFX

iLOOP:
   jmp iLOOP         ; Infinite Loop

; Extra Info
                  ; Pallete
tilepal: .incbin "our.pal"

   .bank 2
   .org $0000        ; Origin (start) at $0000
   .incbin "our.bkg"     ; Background File
   .incbin "test.chr"  ; Tile/Sprite File
                  ; Must be done Background then Sprite
                  ; END


Background File:
http://www.davidbradbury.us/NES/our.bkg

CHR file:
http://www.davidbradbury.us/NES/test.chr

by on (#40758)
Turn off the screen before writing to it. Write #$00 to $2000 and $2001. After setting up the palette and setting up sprites, turn the screen back on.

Also, the CHR file isn't set up so that tile $48 is 'H'. When you do .db 'H' it translates to .db $48. I think at tile $48 in that file, it's a blob of some sort. So in the CHR file, copy/paste numbers 0-9 to tiles $30-$39, and letters A-Z to $41-$58 (I think Z would be at $58, but copy it so A is at $41, B is at $42, etc.)

by on (#40759)
Celius wrote:
Turn off the screen before writing to it. Write #$00 to $2000 and $2001. After setting up the palette and setting up sprites, turn the screen back on.

Also, the CHR file isn't set up so that tile $48 is 'H'. When you do .db 'H' it translates to .db $48. I think at tile $48 in that file, it's a blob of some sort. So in the CHR file, copy/paste numbers 0-9 to tiles $30-$39, and letters A-Z to $41-$58 (I think Z would be at $58, but copy it so A is at $41, B is at $42, etc.)


Alright, almost there! ((Sorry I'm having so many issues xD)

I can get text to display if I enter in the correct tile number (#$48 )... but if I do "H", it still shows a blob.

My text is being saved by


Code:
hello   .db "H"


and loaded by

Code:
   lda hello         ; Load/Store Tile Number
   sta $2004


Is there anything obvious that I might be doing wrong?

by on (#40760)
You're doing this:

Hello:
.db "H"

.org $8000

With this statement, you are basically saying "place a value of $48 here". Then when you do:

lda Hello

it's loading a byte from an address. And since the address of the "Hello" label is outside of ROM, it's loading some garbage value. And also, keep in mind that it's loading a value from an address, like:

lda $8020

Where the value of $8020 is loaded into A. When you do:

lda #$48

you immediately load a value of $48 into A.

In WLA-DX, I know you can use the .define statement like this:

.define Hello "H"

Though I think it's different with NESASM. There's one thing I'd try, and one thing I'm fairly sure will work.

First, try putting a "#" in front of Hello in LDA Hello. Because maybe if .db is outside of ROM, NESASM sees this like WLA sees .define.

Otherwise, and you'll want to do this if you load a string of text onto the screen, move this:

Hello:
.db "H"

to somewhere in ROM around where you keep the palette.

Summary:
So basically I'm pretty sure the problem is that it sees "Hello" as a label, and not just another name for the value $48. But I seem to remember using the .db statement to make names for variables outside of ROM. If this is the case, a simple lda #Hello should fix the problem. But if you're going to be making "Hello" a label from which to load a string, you need to move that into ROM. If you DO move that label to ROM even as is, it should work, but it will use a byte to hold the value $48 in ROM, and you will load using an address instead of an immediate value.

by on (#40763)
You nailed it on that 'seeing garbage' bit. It wasn't even seeing it! ( hello .db "H" ) ... I loaded the variable by the palette, and BAM! It worked!

Thanks for your awesome help :) If I ever complete a game, I'll be sure to put you in the credits! :D

by on (#40764)
Oh, it's no problem. It's partially what I'm here for. :)

I probably don't deserve to be in the credits of any game you make ;). I'm just helping out with the basics. If you have any more questions, feel free to come back.

by on (#40768)
Heh, well I've always believed that those who have helped you get where you are should always get credit for helping! I mean, I wouldn't have awesome text flashing "Hello World" every other second now :D

Also, I checked out a few other lessons and ordered a 6502 reference book from Amazon...

I had mostly been using http://patater.com/gbaguy/nesasm.htm before... eh.... There are some mistakes in that, that really didn't make sense!

I should be able to finish up the tic tac toe game by the end of this next week, so we'll see how it goes! I'll be sure to stick around though. Thanks again.