Page 1 of 1

wdc compiler help needed

Posted: Tue Oct 08, 2019 9:39 am
by Collen
Hi all, after a long time i decided to pull out my w65c265sxb board again.

i started with the 'led blink' from http://www.mikekohn.net/micro/modern_6502.php.
follow directives, used the naken_asm compiler... and yes result, it works.

not a real fan of the "new" code style from naken_asm
so i decided to translate it to wdc compiler style... and here the troubles begin.

i can compile it, but it will not run on the board...
my guess it's some where in the 8/16 bit of the a/x/y
or in the mode where you switch between 8/16 bit part

where do i go wrong... here is the code...
(ps i just want to run it in 8 bit mode, 65c02 mode that is.. but have no clue how to set 8/16 bit modes in the wdc compiler)

Code: Select all

	
        CHIP	65816
	LONGI	OFF 
	LONGA	OFF 
	org $1000 
	
	start: 
	; Disable interrupts to protect from ROM routines running 
	;sei 
	; Set native mode 
	;clc 
	;xce 
	; Set A to 8-bit 
	;sep #$20 
	; Set X/Y to 16-bit 
	;rep #$10 
			 
main: 
			sei 
			cld 
	  	 
go:			jsr delay
			jsr on
			jsr delay
			jsr off
			jmp go
			
			; on led 
on:			lda #$00 
	  		sta $df23 
			rts
	  		 
	  		; led off 
off:		        lda #$ff 
	  		sta $df23 
	  		rts
	  		 
delay: 		ldy #$10
delay1: 	        ldx #$ff 
delay2: 	        dex
	  		bne delay2 
	  		dey 
	  		bne delay1 
	  		rts

Re: wdc compiler help needed

Posted: Tue Oct 08, 2019 10:31 am
by BitWise
The XCE instruction is used to control the processor state. So ..

Code: Select all

  sec
  xce
.. will put the device in 65C02 'emulation' mode and the registers will be 8-bits -- no need for SEP/REP.

I wouldn't use port 7 for I/O. Many of the pins are used to generate chip select signals in the default configuration and will ignore the ports data register.

I tend to connect things to port 5 after ensuring DTR/DSR handshaking is disabled on the Uarts or there are some free pins on port 4 but as some are used for interrupts (e.g. 0 and 1) and ROM bank selection (e.g. 3 and 4) you need to set/clr only the free bits (e.g. 2, 5, 6 and 7) using TSB/TRB.

Re: wdc compiler help needed

Posted: Tue Oct 08, 2019 6:48 pm
by Collen
Thx man.. that's the one..!

all works now..

still hard to figure out what to use at the beginning if you start a program.
setting 8/16 bits, native or emulation.. sep/rep, longi, longa, chip ect ect...
good thing there is nice documentation here at 6502.org ....

all restarts are hard in the beginning...

Re: wdc compiler help needed

Posted: Tue Oct 08, 2019 8:39 pm
by GARTHWILSON
I know you just copied JoeDavisson's routines, but here are just a few pointers anyway:
Quote:
(ps i just want to run it in 8 bit mode, 65c02 mode that is..
Note that running with 8-bit registers is separate from '02 emulation mode. You can still have 8-bit registers in '816 native mode.

SEI (set interrupt disable bit) and CLD (clear decimal-mode bit) are part of the reset sequence and the interrupt sequence; so there's no need to do them in the reset routine unless you might branch to it from a running program. Also, the '816 comes out of reset in '02-emulation mode; so if that's what you want, there's no need to explicitly tell it.

Rather than LDA #0, STA___, you can just use the STZ (store zero) instruction which is faster, takes less memory, and leaves the accumulator and status register alone.

If you know a register or memory location is 0 and you want to make it $FF (or $FFFF if A is 16-bit), you can just do DEC___ instead of LDA #$FF, STA___. If you use a memory location as a flag and want to set it and all that matters is whether it's 0 or not (and you branch on the Z flag), or you only look at the high bit (and then branch on the N flag), you can also just do DEC as long as you can know you're not decrementing so many time that the value again becomes 0 (in the first case) or positive (in the second case).

Your JMP GO could be replaced with BRA GO for a one-byte savings. The execution time is the same.

JSR's to a one-instruction subroutine can be replaced with a macro that just inlines that one instruction (like STZ $DF23) and then the descriptive macro name accomplishes the purpose of being clear about what you're doing, and the JSR/RTS overhead is eliminated.

Almost none of the 6502 primer is specifically about the '816, but you should find its programming tips page helpful anyway, at http://wilsonminesco.com/6502primer/PgmTips.html .