Page 1 of 2
This is really ridiculous but...
Posted: Fri Sep 02, 2011 6:05 am
by IvanDSM
Here's some code i TRIED to put together by mashing up some things from JUNKDEMO.ASM from NESASM and some things i've learned from Assembly in One Step (6502guid.txt)...
Code: Select all
.inesprg 1 ; One 16k prg bank
.ineschr 0 ; One 8k chr bank
.inesmir 1 ; Vertical map mirroring
.inesmap 0 ; Use mapper 0
.bank 0
.org $C000
reset:
lda #$1F ; Make all sound channels active, stolen from NESASM's JUNKDEMO...
sta $4015
lda #$0F ; See NES Document for register values and meaning
sta $4000 ; Square 1
sta $4004 ; Square 2
sta $4008 ; Triangle
lda #$00 ; See NES Document for register values and meaning
sta $4001 ; Square 1
sta $4005 ; Square 2
sta $4009 ; Triangle
ldx #$4F ;<Little tune, i think...
ldy #$A8 ;...>
lda #$00 ;<Get the joysticks ready, i think...
sta $4016 ;...
lda #$01 ;...
sta $4016 ;>
jsr cjs ;Calls cjs (Check JoyStick)
cjs:
sta $4016 ;Reads A (?)
bne lol ;If the result isn't zero jumps to lol (?)
lol:
stx $4006 ; Stolen from JUNKDEMO again.
sty $4007
rts
It says corrupt file in Nestopia and does nothing in FCEUX, what's going on? Am i being an idiot?[/code]
Posted: Fri Sep 02, 2011 6:09 am
by Shiru
You can't org $c000 in bank 0, it is in bank 2. Also, you've forgot about reset/nmi vectors, and a program won't work without them.
Posted: Fri Sep 02, 2011 6:13 am
by IvanDSM
Shiru wrote:You can't org $c000 in bank 0, it is in bank 2. Also, you've forgot about reset/nmi vectors, and a program won't work without them.
What should i put in bank 0? Also, is the code i improvised ok? May i leave it in bank 0 or move to 2?
Posted: Fri Sep 02, 2011 6:18 am
by IvanDSM
I studied (read "read, copied, moved, changed") some code from COLOR.ASM and updated my code, but, no luck for me yet:
Code: Select all
.bank 0
.org $8000
.dw nmi_stuph
.dw reset
.dw irq
nmi_stuph:
sta $4016 ;Reads A (?)
bne lol ;If the result isn't zero jumps to lol (?)
irq:
rti
reset:
lda #$1F ; Make all sound channels active, stolen from NESASM's JUNKDEMO...
sta $4015
lda #$0F ; See NES Document for register values and meaning
sta $4000 ; Square 1
sta $4004 ; Square 2
sta $4008 ; Triangle
lda #$00 ; See NES Document for register values and meaning
sta $4001 ; Square 1
sta $4005 ; Square 2
sta $4009 ; Triangle
ldx #$4F ;<Little tune, i think...
ldy #$A8 ;...>
lda #$00 ;<Get the joysticks ready, i think...
sta $4016 ;...
lda #$01 ;...
sta $4016 ;>
lol:
stx $4006 ; Stolen from JUNKDEMO again.
sty $4007
rts
[/code]
Posted: Fri Sep 02, 2011 6:21 am
by Shiru
You will have no luck if you won't set vectors properly - CPU just does not know where to start without them. They have to be in $fffa.
I.e.:
Code: Select all
.bank 0
.org $8000
;your code
.bank 3
.org $fffa
.dw nmi
.dw reset
.dw 0
Posted: Fri Sep 02, 2011 6:29 am
by IvanDSM
Even after receiving advice from veterans, i suck. No corrupt file, just nothing. Reorganised code:
Code: Select all
.bank 0
.org $8000
reset:
lda #$00 ;<Get the joysticks ready, i think...
sta $4016 ;...
lda #$01 ;...
sta $4016 ;>
.bank 3
.org $fffa
.dw nmi_stuph
.dw reset
.dw 0
I did not include lol or nmi_stuph because they're still the same.[/code]
Posted: Fri Sep 02, 2011 6:39 am
by Shiru
What you expect from all that random code? Make code that actually do something, and it will do something.
Also, you need to init hardware. Set stack and wait PPU to 'warm up', at least. Example of an empty program:
Code: Select all
.inesprg 2
.ineschr 1
.inesmir 0
.inesmap 0
.bank 0
.org $8000
PPU_CTRL equ $2000
PPU_MASK equ $2001
PPU_STATUS equ $2002
PPU_SCROLL equ $2005
PPU_ADDR equ $2006
PPU_DATA equ $2007
PPU_FRAMECNT equ $4017
DMC_FREQ equ $4010
CTRL_PORT1 equ $4016
FRAME_CNT equ $ff
reset
;init hardware
sei
ldx #$40
stx PPU_FRAMECNT
ldx #$ff
txs
inx
stx PPU_MASK
stx DMC_FREQ
lda #%10000000
sta PPU_CTRL
jsr waitVBlank
;clear ram content
txa
clearRAM
sta $000,x
sta $100,x
sta $200,x
sta $300,x
sta $400,x
sta $500,x
sta $600,x
sta $700,x
inx
bne clearRAM
;clear vram too
clearVRAM
lda #$00
sta PPU_ADDR
sta PPU_ADDR
ldx #$00
.1
ldy #$40
.2
sta PPU_DATA
iny
bne .2
inx
bne .1
jsr waitNMI
lda #%00011110 ;enable display
sta PPU_MASK
mainLoop
;do anything you want here
jmp mainLoop
waitVBlank
bit PPU_STATUS
.1
bit PPU_STATUS
bpl .1
rts
waitNMI
lda FRAME_CNT
.1
cmp FRAME_CNT
beq .1
rts
nmi
rti
.org $fffa
.dw nmi
.dw reset
.dw 0
.bank 4
.incbin "patterns.chr"
Re: This is really ridiculous but...
Posted: Fri Sep 02, 2011 6:50 am
by tokumaru
Nestopia says that files are corrupt when the size of the ROM doesn't match what it expects.
For example, your iNES header says the program has 16KB of PRG-ROM, yet you have ORG'd stuff at $8000 and $FFFA, which would make your ROM have 32KB. If you really want 16KB, you could try putting the vectors at $BFFA in bank 1 instead (not sure if it would work, because I hate NESASM so I don't use it).
Also, I don't see any CHR file being included, and Nestopia will definitely miss it if you select mapper 0.
Posted: Fri Sep 02, 2011 7:07 am
by tepples
Shiru wrote:You can't org $c000 in bank 0, it is in bank 2
Most NROM-128 games use $C000-$DFFF as bank 0 and $E000-$FFFF as bank 1. It is this fact that allows Forbidden Four and MGC multicart engines to work.
Posted: Fri Sep 02, 2011 8:06 am
by IvanDSM
Subquestion: How do i use a CHR file? I already made one using BMPNES, and now i don't know how to organise it.
Posted: Fri Sep 02, 2011 8:10 am
by tokumaru
IvanDSM wrote:Subquestion: How do i use a CHR file? I already made one using BMPNES, and now i don't know how to organise it.
Just look at the sample code Shiru posted: put another bank after the last one and then include the CHR file.
I don't know much about NESASM, but Shiru's template appears to be very good. You should study it and make sure you understand how it works.
Posted: Fri Sep 02, 2011 8:16 am
by IvanDSM
tokumaru wrote:Just look at the sample code Shiru posted: put another bank after the last one and then include the CHR file.
Yes, i used Shiru's code for a base. I just changed the name of the chr bank. It works, but it doesn't prints it.
Posted: Fri Sep 02, 2011 8:34 am
by Shiru
The init code is not really mine, it is composed of some other base code from some tutorial (forgot which one, it was few years ago).
Posted: Fri Sep 02, 2011 8:39 am
by Grumskiz
A CHR File is not a background!
It is the pure graphics data that can be used by your program and it usually is saved on a seperate ROM Chip called CHR-ROM on real carts.(sometimes it's RAM and one copies graphics from PRG-ROM - that's where the code is saved - into CHR-RAM)
To draw a background on the screen, you would need to create name tables and attribute tables based on your CHR file. These then need to be passed to the PPU by your code during NMI or with rendering turned off.
I recommend you follow the Nerdy Nights Tutorials on Nintendoage.com which are especially useful if you want to stick to NESASM for now.
These Tutorials also explain how to work with name tables and attribute tables better than I could ever explain it in a small post.
Also the nesdev wiki is a good place to read about this stuff.
Posted: Fri Sep 02, 2011 7:08 pm
by Celius
As Grumskiz mentions, the CHR file is not a background by itself. What the CHR data does is provide you with 8x8 chunks of graphics (called "tiles") for you to arrange to make a background. If you look at CHR data, you'll notice there are $FF (or 255) tiles to choose from. The NES screen displays 1024 tiles, so clearly there is a need to specify which graphics you want displayed where.
If you want the entire CHR file just displayed in the middle of the screen, here is a piece of code that will do that:
Code: Select all
lda #$20 ;Set PPU Pointer to start drawing tiles at $20E8
sta $2006
pha ;Push High byte onto stack
lda #$E8
sta $2006
pha ;Push Low byte onto stack
ldx #0 ;Save tile ID in X, start with tile 0
ldy #$10 ;Y is a counter, counting down from 16 to 0 for each row
;of tiles being displayed
DisplayCHR:
stx $2007 ;Place tile on the screen at PPU Pointer's location.
;PPU Pointer will go up by 1 automatically.
inx ;Move onto the next tile number
dey ;Count down until row is done being drawn
bne DisplayCHR ;Go back to the start of the loop
clc ;Clear Carry flag
pla ;Pull saved PPU Pointer low byte from stack
adc #$20 ;Add 32 to get the PPU Pointer address of the next tile row
tay ;Save this value in Y temporarily
pla ;Pull saved PPU Pointer high byte from stack
adc #0 ;Add nothing (will add 1 if the low byte wrapped past 0 when adding 32)
pha ;Push back onto the stack for later use
sta $2006 ;Set PPU Pointer to the new value (Previous value of entire pointer + 32)
tya ;Transfer saved low value from Y into A to write to $2006
sta $2006
pha ;And push back onto stack
ldy #$10 ;Load Y with 16 to count 16 tiles for the next row of tiles
cpx #0 ;Only if X is not 0, in which case all tiles have been drawn.
bne DisplayCHR ;Otherwise, move onto next row.
This will also give you some additional study material for understanding 6502.