Compiling asm6 for OS X

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

Post Reply
User avatar
noattack
Posts: 147
Joined: Tue Feb 13, 2007 9:02 pm
Location: Richmond, VA

Compiling asm6 for OS X

Post by noattack »

This is a continuation of a previous thread: http://nesdev.com/bbs/viewtopic.php?t=4812&start=0

I downloaded XCode, opened a standard tool, compiled, and got a working binary. I run the binary in Terminal on a sample .asm file, which works properly, but I'm "Illegal Instruction" warnings on every line with an opcode. Labels pass through without error. I've tried opening the source in TextEdit (in plain text mode) and TextWrangler, but to no avail. I'm not sure what I'm tripping up on.

Any suggestions? My transition to Mac development is so close...
User avatar
beneficii
Posts: 127
Joined: Tue Jul 12, 2005 4:37 pm

Post by beneficii »

Did you try using the source I posted?

http://sm2.beneficii.net/asm6.c

EDIT: Also check that the default fill value is now 0, not 0xff.

EIDT 2: Also, could you post a source of what you're trying to assemble?
User avatar
noattack
Posts: 147
Joined: Tue Feb 13, 2007 9:02 pm
Location: Richmond, VA

Post by noattack »

Yes, I compiled your provided source, so I think the binary is working fine. I suppose there was something wrong with my code (which I really can't figure out), but I've since gotten another source to compile with no errors. It's just an adaptation of one of blargg's tutorials (to print 'Hello World'):

Code: Select all

;FILLVALUE 0
$ = $0000
; iNES identifier 
.byte "NES",$1a 
.byte $01 ; 1 PRG-ROM block 
.byte $01 ; 1 CHR-ROM block 
.byte $00 ; unsure about these...which is mapper? 
.byte $00 ; 
.pad 16,0 ; fill out remainder of header
	

$ = $C000

; Give names to NES registers
PPUCTRL   = $2000 ; These two control the PPU in various ways
PPUMASK   = $2001
PPUSTATUS = $2002 ; Can be read to get current PPU status
PPUSCROLL = $2005 ; Sets X/Y scrolling of background
PPUADDR   = $2006 ; Sets VRAM address in PPU
PPUDATA   = $2007 ; Writes data to current VRAM address

reset:
	; Initialize NES hardware
	ldx #$FF        ; reset stack pointer to $FF
	txs
	sei             ; be sure IRQ interrupt is disabled
	lda #0
	sta PPUCTRL     ; be sure NMI is off
	sta PPUMASK     ; be sure PPU rendering is off
	
	; Give PPU time to warm up
@wait1: bit PPUSTATUS   ; loop until top bit of PPUSTATUS is set
	bpl @wait1
			; reading PPUSTATUS also clears top bit,
			; so it's clear now
@wait2: bit PPUSTATUS   ; wait for bit to be set AGAIN
	bpl @wait2
	
	; Set first four palette entries
	lda #$3F        ; set PPU address to palette RAM
	sta PPUADDR
	lda #0
	sta PPUADDR
	lda #$0F
	sta PPUDATA     ; set background to black
	lda #$30
	sta PPUDATA     ; set three foreground colors to white
	sta PPUDATA
	sta PPUDATA
	
	; Clear nametable
	lda #$20        ; nametable is at $2000
	sta PPUADDR
	lda #$00
	sta PPUADDR
	lda #0
	ldx #0          ; execute loop 256 times (0 wraps around)
@clear_nt:
	sta PPUDATA     ; clear four bytes each time through loop
	sta PPUDATA
	sta PPUDATA
	sta PPUDATA
	dex
	bne @clear_nt
	
	; Write message at center of screen
	lda #$21        ; put it at address $21AA
	sta PPUADDR
	lda #$AA
	sta PPUADDR
	ldx #0
	lda message     ; first byte of message
@next_char:
	sta PPUDATA     ; write byte to nametable
	inx
	lda message,x   ; get next byte of message
	bne @next_char  ; loop back if it's not zero
	
	; Wait for VBL before enabling display
	bit PPUSTATUS
@wait3: bit PPUSTATUS
	bpl @wait3
	
	; Enable background display
	lda #%00001000  ; enable background
	sta PPUMASK
	lda #0          ; scroll to top-left of nametable at $2000
	sta PPUCTRL
	sta PPUSCROLL
	sta PPUSCROLL
	
	; Loop forever
forever:
	jmp forever


; Message to print, terminated by zero byte
message:
	.byte "Hello, world!",0


; Interrupt handlers (not used in this example)
irq:    rti
nmi:    rti

.pad $FFAA
	.dw nmi
	.dw reset
	.dw irq

.incbin "ascii.chr"
So this assembles to an .nes file (as well as another source I tried) but won't open in NEStopia. It claims the file may be 'damaged'. I'm stumped at this point. I don't know if it's the code, the binary, or the .nes file.

Also, I didn't know what you meant by checking the fill value. Did you mean inserting

Code: Select all

FILLVALUE 0
at the beginning of my code?
User avatar
beneficii
Posts: 127
Joined: Tue Jul 12, 2005 4:37 pm

Post by beneficii »

noattack,

No I'm saying do fill value 0 in the source, because loopy said 0 will now be the default fillval.

Your source assembles fine with the source of ASM6 I have on my Mac OS X. You say you have issues with illegal instruction? I remember when I first tried to get ASM6 to work on the Mac, I had that error come up a lot; I don't remember why it occurred though. It was fixed when I corrected the endianness problem, though.

Your source assembles fine with what I have. Perhaps you can create a listing and post it by typing in -l or -L in the command line when you use ASM6?

EDIT: Also, the vectors start at $FFFA, not $FFAA.
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

Could the line endings of the file be wrong? That often causes cryptic errors.
Post Reply