6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 21, 2024 9:33 pm

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: 65816 code
PostPosted: Wed Oct 03, 2007 11:10 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1738
Location: Sacramento, CA
Hi all

I have completed the design for my next video project. It consists of a 320x200 pixel window with 8 bits of color for each pixel. Thats 64,000 bytes for a complete display window. I want to test/debug using a pattern generator program.

I want it to fill the display buffer ($010000 - $01FFFF) with a color pattern, wait 10 seconds, inc the color pattern (repeating all 256 patterns), and refill the buffer.

I am using a 65816 running at 7.159MHz with 512K of RAM. I'll need to run the processor in native mode in order to access RAM above 64K.

This is my first 65816 program and just want you "experts" to check my code. I'm not looking to optimize for speed or size, I just want it to work as expected. My assember does not support the 65816 opcodes so I use the .byte psuedo-op to correct it.

Will this code do what I want?

Code:

ptr            =      $10              ; zero page pointer (2 byte)
chr            =      $12              ; color character

Reset          SEI                     ; diable interupts
               CLD                     ; clear decimal mode                     
               LDX   #$FF              ;
               TXS                     ; init stack pointer
               CLC                     ; Clear carry flag, pre for native mode
               .byte $FB               ; XCE - Set native Mode ON, leave in 8 bit reg mode

               lda    #$00             ; init variable
               sta    chr
               sta    ptr
               sta    ptr+1            ; init pointer to $0000

; set Data Back register to $010000, Video display buffer

               lda    #$01             ; Page 1 for video mem
               pha                     ; put on stack
               .byte  $AB              ; PLB -> set DBR

; Fill vid buffer

Loop1          lda    chr              ; get color code
Loop2          sta    (ptr)            ; save to vid buffer
               inc    ptr              ; inc zero page pointer
               bne    Loop2            ; do inner loop if not zero
               inc    ptr+1            ; inc zero page pointer
               bne    Loop2            ; do outer loop if not zero

; we exit the loop above with ptr pointing back to $0000

; done, now wait

               ldx    #$00             ; basic 3 stage delay loop
               ldy    #$00             ; all stages loop 256 times
               lda    #$00             ; at 7.15MHz, expect it
Loop3          dec                     ; to take 11.5 seconds
               bne    Loop3
               dex
               bne    Loop3
               dey   
               bne    Loop3           

; set next color and repeat           
               inc    chr              ; inc to next color pattern 
               jmp    Loop1            ; repeat Fill and delay forever


thanks for looking!

Daryl


Top
 Profile  
Reply with quote  
 Post subject: Re: 65816 code
PostPosted: Thu Oct 04, 2007 11:09 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
8BIT wrote:
Will this code do what I want?


In a word, yes. However, I'm curious about the fill vid buffer chunk of
code:

Code:
; Fill vid buffer

Loop1          lda    chr              ; get color code
Loop2          sta    (ptr)            ; save to vid buffer
               inc    ptr              ; inc zero page pointer
               bne    Loop2            ; do inner loop if not zero
               inc    ptr+1            ; inc zero page pointer
               bne    Loop2            ; do outer loop if not zero


I would have written it using (dp),Y addressing mode, since it doesn't
appear you're using Y at this point. Any reason why not? I'm just
curious.

BTW, I can heartily recommend ca65 as a near perfect 65816 assembler.
With only marginal investment in learning how its linker works (it
becomes very clear after a few examples), you'll find it hard to go back
to other assemblers. Since it groks 65816 natively, you can use real
16-bit instructions too.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 04, 2007 11:25 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1738
Location: Sacramento, CA
I didn't use (dp),y because I have not studied the '816 new instructions enough yet. I am literally just starting. I should have the hardware built within the next week. If this test is successful, then I'll start playing with more test code.

I have used ca65 a little. I'll get a copy and try to dig into it more.

thanks for the advice.

Daryl


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Oct 04, 2007 11:38 pm 
Offline

Joined: Sat Jan 04, 2003 10:03 pm
Posts: 1706
Note that (dp),Y is the 6502's (zp),Y addressing mode. You could also have used [dp],Y and not bothered with the program bank -- note the use of square brackets to indicate a long-address, versus a short address. :)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 05, 2007 12:42 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1738
Location: Sacramento, CA
I know I'm in for a lot of reading!!!! Thanks for the input!

Daryl


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 05, 2007 1:59 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
I don't see any problems with your code, though I did not actually try it.

One suggestion I would make if you do decide to stick with a non-65816 assembler is to make EQUates for the 65816 instructions like PHB, REP, RTL, TXY, XCE, etc., which will help make the code far more readable, e.g.:

Code:
RTL =     $6B
TXY =     $9B
REP =     $C2
XCE =     $FB
    CLC
    .byte XCE
    .byte REP,$30
    .byte TXY
    .byte RTL


You can see an example of this (for the Apple IIgs) here:

http://bob-bishop.awardspace.com/Oscill ... index.html

P.S. I agree that it would be a good exercise to modify your program several times to use [zp] addressing, to use absolute long,X addressing, to use the MVN instruction to fill the buffer, etc. just to get familiar with the addressing modes and capabilities of the 65816.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 05, 2007 2:17 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1738
Location: Sacramento, CA
I like the use of the equates, I'll use it until I'm ready to move assembers.

I too agree with using the [zp] addressing. Once I get the hardware working, I will experiment with using the 16 bit instructions. This will hopefully show faster fill rates. I can modify the code to show frame refresh rates using various fill routines.

thanks for the inputs.

Daryl


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 05, 2007 9:38 am 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1041
Location: near Heidelberg, Germany
8BIT wrote:
I like the use of the equates, I'll use it until I'm ready to move assembers.


you should also try xa65, which has a 65816 mode and can produce relocatable code (shameless self-plug, I know ;)

Just try then decide what you like best.

André


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 12, 2007 1:58 am 
Offline

Joined: Sat Sep 22, 2007 1:31 am
Posts: 24
8bit, what video hardware are you using to generate the display?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Oct 12, 2007 1:07 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1738
Location: Sacramento, CA
I am using a Xilinx XC95108 CPLD and an Analog Devices AD724.

It is based loosely on this design:
http://elm-chan.org/works/crtc/report.html

I am having some issues with my first CPLD. I have another on order and hope to get the project back on track after it arrives.

Daryl


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 16, 2007 12:26 pm 
Offline

Joined: Sat May 20, 2006 2:54 pm
Posts: 43
Location: Brighton, England
Will your design do PAL or only NTSC? If it does PAL, I will be very interested in it.

_________________
Shift to the left, shift to the right,
mask in, mask out,
BYTE! BYTE! BYTE!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Oct 16, 2007 12:47 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1738
Location: Sacramento, CA
Right now, I'm working with NTSC only. A PAL version would not be hard to adapt.

I found out my power supply was not stable, and it destroyed my first 95108. The second 95108 seems to be working. However, it runs very hot. I'll need to find out if that is normal.

I am still having issues with the 65816 not running correctly. I'll be troubleshooting that part next.

Daryl


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Nov 16, 2007 7:26 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
Keep me up on it, I was trying one with an RGB out based on that Elm design as well. (and gettign so darned busy with other projects, I got sidetracked. Bleah)

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 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: