It is currently Thu Dec 14, 2017 8:17 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Mon Jan 30, 2006 4:22 am 
Hi, i download a artistic hello world code
from internet. I wanna that output be:

Hello World. Pando
6502

Then i modify it..
but result output by Virtuanes emu is:

Hello world. Pando 6502

how can i make the output with writeln?? where logic are
bad here???
i am a novice, it's my first edit code since i read lot of
documents

... I know that all this letters are for background (nametable)...

it's the code for NESASM:
Code:
;INES header setup
   .inesprg   1   ; 16k prg bank
   .ineschr   1   ; 8k  chr bank
   .inesmir   0   ; Horizontal
   .inesmap   0   ; Use mapper #0

   .bank 0
   .org $C000
RESET
   cld
   sei
.WaitV
   lda $2002
   bpl .WaitV
   
   ldx #$00
   stx $2000
   stx $2001      ;screen off
   
   lda #$3F
   sta $2006
   stx $2006      ;PPU $3F00 - Palette
   
   lda #$0F
   sta $2007
   lda #$00
   sta $2007
   lda #$10
   sta $2007
   lda #$30
   sta $2007      ;Palette 0F,00,10,30

   lda #$21
   sta $2006
   lda #$C9
   sta $2006      ;cursor address

   ldy #$00
   ldx #17      ;size of .data

.readdata
   lda .data,y
   sta $2007   
   iny
   dex
   bne .readdata

   lda #%00001110 
   sta $2001   

   ldx #$49
   stx $2005   
   ldx #$70   
   stx $2005


   ldy #$00 ; INITIALIZE FOR readdata2
   ldx #4    ; INITIALIZE FOR readdata2
   lda $2007
   lda $2007 ; clear 2007?

.readdata2
      
   lda .data2,y
   sta $2007
   iny
   dex
   bne .readdata2
   
   ldx #$49   
   stx $2005
   ldx #$68   
   stx $2005

.loop
   jmp .loop

.data
   db "Hello World. Pando"

.data2
   db "6502"

NMI
IRQ
   rti
   .bank 1
   .org $E000
   .org  $FFFA
   .dw      NMI
   .dw      RESET
   .dw      IRQ

   .bank 2
   ;character data
   db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00 etc....

[edit by Quietust - changed color tag to CODE tag, since the color was completely unreadable in SubSilver]


Top
  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 5:09 am 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3487
Location: Indianapolis
I see a couple odd things. You set $2005 in between writes, that will only offset the display, it won't affect the 2 text string's relative position to eachother. I think you want to set $2006 instead (previous cursor address + $20 to put '6502' below the first text). And it's probably simplest to write 0,0 to $2005 to start with.

And you turned the screen on before readdata2. That will very likely cause some glitches (if it doesn't now, it will as soon as your code is too long for vblank). Turn it on only after all the PPU writing is done.

Also, you read $2007, I can see no need for that. That incremented your VRAM address and gave you a space or 2 between Pando and 6502. But you did do an extra read to fill it's reading buffer, so I see you know what to do if you really wanted to read it (almost noone ever does, it's normally slow and kinda pointless since it can't be indexed easily. and limited to vblank time).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 8:21 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10164
Location: Rio de Janeiro - Brazil
Memblers wrote:
I see a couple odd things. You set $2005 in between writes, that will only offset the display, it won't affect the 2 text string's relative position to eachother. I think you want to set $2006 instead (previous cursor address + $20 to put '6502' below the first text). And it's probably simplest to write 0,0 to $2005 to start with.

And you turned the screen on before readdata2. That will very likely cause some glitches (if it doesn't now, it will as soon as your code is too long for vblank). Turn it on only after all the PPU writing is done.

I think he did all those things because he's adding stuff to existing code. Probably the original wrote just 1 string. That's why $2005 was set and the screen was on by the time the second write was performed.

Quote:
Also, you read $2007, I can see no need for that. That incremented your VRAM address and gave you a space or 2 between Pando and 6502.

That can be kinda interesting... it is a way to write your strings without the spaces erasing what was already there... I don't know how useful that can be, but is an interesting idea...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 8:43 am 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3487
Location: Indianapolis
tokumaru wrote:
Quote:
Also, you read $2007, I can see no need for that. That incremented your VRAM address and gave you a space or 2 between Pando and 6502.

That can be kinda interesting... it is a way to write your strings without the spaces erasing what was already there... I don't know how useful that can be, but is an interesting idea...


Yeah, that'd work well for cursor keys on a keyboard. But it'd have to reset the address to move left or up.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 9:25 am 
.data2
db "6502"

initialize..

.readdata2

i added it.. because i was thinking writing like a pc...
then i understand now that off display...write all to memory and start on the display... is correct?


Top
  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 10:07 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10164
Location: Rio de Janeiro - Brazil
Try the following changes to the code you presented:

change this:
Code:
lda $2007
lda $2007 ; clear 2007?


into this:
Code:
lda #$21
sta $2006
lda #$E9
sta $2006 ;cursor address


delete this: (this is not doing anything useful)
Code:
ldx #$49
stx $2005
ldx #$70
stx $2005


move this:
Code:
lda #%00001110
sta $2001


to right before this:
Code:
.loop
jmp .loop


That should do for now...


Top
 Profile  
 
PostPosted: Tue Jan 31, 2006 4:48 am 
thanks tokumaru and memblers.. I can get it working!!
now one question more..

virtuanes, fceud, and anothers emu display it
for this code:

Hola Mundo. Pando
Assembler Procesador 65
____________________02

(underline is not showed.. i draw it here (on this page)
to show 02 on correct place where screens show)

i wanna get it:

Hola Mundo. Pando
Assembler Procesador 6502

What is bad on this code?????

Code:
;INES header setup
   .inesprg   1   ; 16k prg bank
   .ineschr   1   ; 8k  chr bank
   .inesmir   0   ; Horizontal
   .inesmap   0   ; Use mapper #0

   .bank 0
   .org $C000
RESET
   cld
   sei
.WaitV
   lda $2002
   bpl .WaitV
   
   ldx #$00
   stx $2000
   stx $2001      ;screen off
   
   lda #$3F
   sta $2006
   stx $2006      ;PPU $3F00 - Palette
   
   lda #$0F
   sta $2007
   lda #$00
   sta $2007
   lda #$10
   sta $2007
   lda #$30
   sta $2007      ;Palette 0F,00,10,30

   lda #$21
   sta $2006
   lda #$C9
   sta $2006      ;cursor address

   ldy #$00
   ldx #17      ;size of .data

.readdata
   lda .data,y
   sta $2007   
   iny
   dex
   bne .readdata   

   ldy #$00 ; INITIALIZE FOR readdata2
   ldx #25    ; INIT size of data2
   lda #$21
   sta $2006
   lda #$E9
   sta $2006 ;cursor address

.readdata2
       
   lda .data2,y
   sta $2007
   iny
   dex
   bne .readdata2
   
   ldx #$38   
   stx $2005
   ldx #$00   
   stx $2005
 
lda #%00001110 
 sta $2001

.loop
   jmp .loop

.data
   db "Hola Mundo. Pando"

.data2
   db "Assembler Procesador 6502"

NMI
IRQ
   rti
   .bank 1
   .org $E000
   .org  $FFFA
   .dw      NMI
   .dw      RESET
   .dw      IRQ

   .bank 2
   ;character data
   db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00 etc....


Top
  
 
PostPosted: Tue Jan 31, 2006 6:51 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10164
Location: Rio de Janeiro - Brazil
lord_Chile wrote:
Hola Mundo. Pando
Assembler Procesador 65
____________________02


That's because you wrote your 2nd string, wich is 25 characters in size (according to your code), to address $21E9. I know I said you should write here, but I didn't expect your string to be so long. Do the math:

.you're writing to address $21E9;
.the name table starts at $2000, so that's $1E9 into it;
.divide that by 32 (the length of the name table in characters) and you get 15 ($F), with 9 as remainder;
.that means you started writing at position 9, plus the 25 of the string that's 34, 2 beyond the end of the line, wich means the last 2 characters are printed in the next line;
.since your screen is scrolled, the start of the next line will be at the end of the current, but one line down.

To solve this, please, start writing at the *start* of the line ($21C0 and $21E0) and write 0's to $2005 (don't do any scrolling for now) instead of $38... Maybe it's better that you place your strings 1 or 2 characters from the start of the line ($21C2 and $21E2), so they don't get cut off.


Top
 Profile  
 
PostPosted: Wed Feb 01, 2006 4:39 am 
tokumaru, i get working hello world with writeln, thanks!!

now...
i wanna playing sound on nes...

my first question is: i have a single .nsf sound file with only 1 song..
how can i include it on my hello world demo????

my second question is:

i want that my hello world demo output a sound
named gun. it's like a gun in action..

but when loop advance by time i can listening sound 4 times. bam-bam-bam-bam
just good and at speed that i wanna..

then virtuanes says: executed an undefined order and crash..

what's bad??.. my code is

Code:
; INES header setup
   .inesprg   1   ; 16k prg bank
   .ineschr   1   ; 8k  chr bank
   .inesmir   0   ; Horizontal
   .inesmap   0   ; Use mapper #0

   .bank 0
   .org $C000

RESET
   cld
   sei

.WaitV
   lda $2002
   bpl .WaitV
   
   ldx #$00
   stx $2000
   stx $2001      ;screen off
   
   lda #$3F
   sta $2006
   stx $2006      ;PPU $3F00 - Palette
   
   lda #$0F
   sta $2007
   lda #$00
   sta $2007
   lda #$10
   sta $2007
   lda #$30
   sta $2007      ;Palette 0F,00,10,30

.init_for_data
   lda #$21
   sta $2006
   lda #$C2
   sta $2006      ;cursor address

   ldy #$00   ;init counter
   ldx #17   ;size of .data

.readdata
   lda .data,y
   sta $2007   
   iny
   dex
   bne .readdata

.init_for_data2
   ldy #$00 ; INIT counter
   ldx #25    ; INIT size of .data2
   
   lda #$21
   sta $2006
   lda #$E2
   sta $2006 ;cursor address for data2

.readdata2
      
   lda .data2,y
   sta $2007
   iny
   dex
   bne .readdata2
   
.screen_on
   
   ldx #$00   
   stx $2005
   ldx #$00   
   stx $2005

   lda #%00001110
   sta $2001

.gun_sound
        pha
        lda #$09
        sta $4015
        lda #$87
        sta $4000
        sta $400C
        lda #$AA
        sta $4002
        lda #$A2
        sta $4001
        lda #$0E
        sta $400E
        lda #$09
        sta $4003
        lda #$08
        sta $400F
        pla
        rts

.loop
   jsr .gun_sound
   jmp .loop

.data
   db "Hola Mundo. Pando"

.data2
   db "Assembler Procesador 6502"

NMI
IRQ
   rti

   .bank 1
   .org $E000
   .org  $FFFA
   .dw      NMI
   .dw      RESET
   .dw      IRQ

   .bank 2
   ;character data
   db $00,$00,$00,$00, etc...

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

now if delete .loop code (jsr and jmp) and i change into

Code:
.gun_sound
        pha
        lda #$09
        sta $4015
        lda #$87
        sta $4000
        sta $400C
        lda #$AA
        sta $4002
        lda #$A2
        sta $4001
        lda #$0E
        sta $400E
        lda #$09
        sta $4003
        lda #$08
        sta $400F
        pla
       
        jmp .gun_sound


emu works fine.. but gun is so fast that is only noise!!!


Top
  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 6:17 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19343
Location: NE Indiana, USA (NTSC)
That's because you're restarting the sound continuously. If you really want to imitate the sound of an automatic firearm, you need to play the sound and then wait for 8 or 10 vblanks before playing it again.


Top
 Profile  
 
PostPosted: Wed Feb 01, 2006 7:12 am 
lord_Chile wrote:
i want that my hello world demo output a sound
named gun. it's like a gun in action..

but when loop advance by time i can listening sound 4 times. bam-bam-bam-bam
just good and at speed that i wanna..

then virtuanes says: executed an undefined order and crash..

what's bad??.. my code is

Code:
; INES header setup
   .inesprg   1   ; 16k prg bank
   .ineschr   1   ; 8k  chr bank
   .inesmir   0   ; Horizontal
   .inesmap   0   ; Use mapper #0

   .bank 0
   .org $C000

RESET
   cld
   sei

.WaitV
   lda $2002
   bpl .WaitV
   
   ldx #$00
   stx $2000
   stx $2001      ;screen off
   
   lda #$3F
   sta $2006
   stx $2006      ;PPU $3F00 - Palette
   
   lda #$0F
   sta $2007
   lda #$00
   sta $2007
   lda #$10
   sta $2007
   lda #$30
   sta $2007      ;Palette 0F,00,10,30

.init_for_data
   lda #$21
   sta $2006
   lda #$C2
   sta $2006      ;cursor address

   ldy #$00   ;init counter
   ldx #17   ;size of .data

.readdata
   lda .data,y
   sta $2007   
   iny
   dex
   bne .readdata

.init_for_data2
   ldy #$00 ; INIT counter
   ldx #25    ; INIT size of .data2
   
   lda #$21
   sta $2006
   lda #$E2
   sta $2006 ;cursor address for data2

.readdata2
      
   lda .data2,y
   sta $2007
   iny
   dex
   bne .readdata2
   
.screen_on
   
   ldx #$00   
   stx $2005
   ldx #$00   
   stx $2005

   lda #%00001110
   sta $2001

.gun_sound
        pha
        lda #$09
        sta $4015
        lda #$87
        sta $4000
        sta $400C
        lda #$AA
        sta $4002
        lda #$A2
        sta $4001
        lda #$0E
        sta $400E
        lda #$09
        sta $4003
        lda #$08
        sta $400F
        pla
        rts

.loop
   jsr .gun_sound
   jmp .loop

.data
   db "Hola Mundo. Pando"

.data2
   db "Assembler Procesador 6502"

NMI
IRQ
   rti

   .bank 1
   .org $E000
   .org  $FFFA
   .dw      NMI
   .dw      RESET
   .dw      IRQ

   .bank 2
   ;character data
   db $00,$00,$00,$00, etc...



My question is: for it specific code.. what is bad??.. why virtuanes crashed..???
i am overflowing any buffer????

and why pha, pla????... i get this sound code of a demo and i understand it but i dont understand for what code is using stack...


Top
  
 
 Post subject: aboutn my last code
PostPosted: Wed Feb 01, 2006 7:14 am 
my last code is working fine. because i can listening bam-bam-bam-bam
the 4 times a good speed like a machine gun.... but in 4th bam virtuanes get into crash...


Top
  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 12:11 pm 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3487
Location: Indianapolis
You've underflowed the stack. Move the gun_sound subroutine down below the main loop. Because right now it doesn't make it to the loop, it runs into that RTS in gun_sound and tries to pull a return address off the stack and dies because there isn't one.


Top
 Profile  
 
 Post subject: thanks and finally..
PostPosted: Wed Feb 01, 2006 12:19 pm 
for what pha, pla????... what is reason that use stack in order to play sounds???..


Top
  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 12:48 pm 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3487
Location: Indianapolis
No sound-related reason. Doing PHA/PLA like that will preserve whatever value was in A before calling the subroutine. You can remove those instructions since there's nothing in A to save, but they won't hurt anything by being there either.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: qalle, Yahoo [Bot] and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group