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

All times are UTC




Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Sat Oct 21, 2017 3:41 pm 
Offline

Joined: Wed Oct 18, 2017 11:26 am
Posts: 14
barrym95838 wrote:
Comments and critiques are welcome.
What a great learning experience, thank you. I analyzed it but I need some time to digest! So, like you wrote, the approach is to minimize loop overhead by painting more pixels per iteration. I assume the fastest program would just be a series of STA calls that paints the picture without any branching or jumps.

Here is a solution that does 16 loops, and paints all pixels that are the same color in one iteration:

Code:
main:
    CLD
    LDA  #0
    TAX       ; from left to middle
    LDA  #31
    TAY       ; from right to middle
    LDA  #0   ; starting color is black

loop:
    STA  $200,X  ; paint left
    STA  $220,X
    STA  $240,X
    STA  $260,X
    STA  $280,X
    STA  $2A0,X
    STA  $2C0,X
    STA  $2E0,X
    STA  $300,X
    STA  $320,X
    STA  $340,X
    STA  $360,X
    STA  $380,X
    STA  $3A0,X
    STA  $3C0,X
    STA  $3E0,X
    STA  $400,X
    STA  $420,X
    STA  $440,X
    STA  $460,X
    STA  $480,X
    STA  $4A0,X
    STA  $4C0,X
    STA  $4E0,X
    STA  $500,X
    STA  $520,X
    STA  $540,X
    STA  $560,X
    STA  $580,X
    STA  $5A0,X
    STA  $5C0,X
    STA  $5E0,X
    INX          ; move to the right

    STA  $200,Y  ; paint right
    STA  $220,Y
    STA  $240,Y
    STA  $260,Y
    STA  $280,Y
    STA  $2A0,Y
    STA  $2C0,Y
    STA  $2E0,Y
    STA  $300,Y
    STA  $320,Y
    STA  $340,Y
    STA  $360,Y
    STA  $380,Y
    STA  $3A0,Y
    STA  $3C0,Y
    STA  $3E0,Y
    STA  $400,Y
    STA  $420,Y
    STA  $440,Y
    STA  $460,Y
    STA  $480,Y
    STA  $4A0,Y
    STA  $4C0,Y
    STA  $4E0,Y
    STA  $500,Y
    STA  $520,Y
    STA  $540,Y
    STA  $560,Y
    STA  $580,Y
    STA  $5A0,Y
    STA  $5C0,Y
    STA  $5E0,Y
    DEY          ; move to the left

    ADC #1
    CMP #16
    BCS end
    JMP  loop

end:
    BRK


Top
 Profile  
Reply with quote  
PostPosted: Sat Oct 21, 2017 8:44 pm 
Offline

Joined: Wed Oct 18, 2017 11:26 am
Posts: 14
BigDumbDinosaur wrote:
KLset wrote:
BigDumbDinosaur wrote:
POC V2 generates wait-states by controlling the MPU's RDY input, which is the least problematic method, in my opinion. As Ed noted, changing clock speeds requires some very careful planning to avoid a glitch that will crash the machine.
I found the RDY signal in the datasheet! Let's see if I get this right... So you set the output of the RDY pin to low to indicate that the 6502 is now waiting (WAI mode), and when the device it is interfacing with is ready to go again, that device sends an interrupt to the 6502, for example by sending low to the IRQB pin, to tell the 6502 that "wake up, we're ready to go". Can the 6502 escape from WAI mode by itself somehow, like a timeout?

See Ed's and Garth's responses. I'll reiterate some of what they said.

For the purposes of making the MPU wait on a slow device, RDY is an input, not an output. When RDY is held high, the MPU runs as expected, executing instructions. When RDY is brought low, the MPU stops on the next Ø2 high and remains stopped until RDY is brought high again. While the MPU is stopped in this fashion it maintains the state of the address and data buses, as well as RWB.

In your system, you would have logic that would detect when the current address is that of a device that is slow and requires wait-stating, such as a ROM. That logic would pull RDY low for one or more Ø2 cycles, after which it would return RDY high. If you do a search of the forum you will find additional topics on the use of RDY to generate wait-states. In particular, Jeff Laughton (Dr. Jefyll) posted a circuit that uses a couple of flip-flops and is simple to implement.

On a final note, we have been blithely assuming you are using the 65C02. Unlike the 65C02, the NMOS 6502 doesn't respond to RDY during a write cycle. Hence another method of wait-stating slow peripherals when writing to them has to be devised. It is strongly recommended that you do not use the NMOS parts in a new design, for this reason and others.
I get it now, thanks. I also found the circuit by Dr. Jefyll (viewtopic.php?p=38470#p38470 for future reference).

I have yet to decide on my first project, so at the moment I have no 6502/65C02 nor any other electronics!


Top
 Profile  
Reply with quote  
PostPosted: Sat Oct 21, 2017 9:55 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
Yeah, you (KLset) have a firm grasp of the concept involving the trade-off between code size and speed. I noticed that you weren't making use of LDX # and LDY # at the beginning of your latest creation, and that you made the dangerous assumption further down that the carry was clear before the ADC #1 in the first run through the loop.

Happy coding!

Mike B.


Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 22, 2017 6:55 am 
Offline

Joined: Wed Oct 18, 2017 11:26 am
Posts: 14
barrym95838 wrote:
I noticed that you weren't making use of LDX # and LDY # at the beginning of your latest creation, and that you made the dangerous assumption further down that the carry was clear before the ADC #1 in the first run through the loop.
I should have done both of those! Thank you having a look.


Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 22, 2017 8:53 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
Next thing you need to learn is assembler directives. In the Kowalski simulator you can bloat your code automatically:
Code:
    .org $1000
main:
    CLD
    LDX  #0   ; from left to middle
    LDY  #31  ; from right to middle

loop:
    TXA
next_line .set $200
    .rept 32
      STA  next_line,X  ; paint left
      STA  next_line,Y  ; paint right
next_line .set next_line + $20
    .endr
    INX
    DEY
    CPX #16
    BCS end
    JMP  loop

end:
    BRK
Unfortunately every assembler supports a different set and its own style of directives.

The list output from above:
Attachment:
Output.txt [6.61 KiB]
Downloaded 69 times

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 22, 2017 1:31 pm 
Offline

Joined: Wed Oct 18, 2017 11:26 am
Posts: 14
Klaus2m5 wrote:
Next thing you need to learn is assembler directives. In the Kowalski simulator you can bloat your code automatically: [...]
Very useful! And I see you also made better use of the X register, doubling as both the color and location; nice! I had a look at the ca65 syntax for repetition, and indeed it is not the same as the Kowalski (the equivalent to .rept in ca65 is .repeat, see http://cc65.github.io/doc/ca65.html#ss11.92 for reference).


Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 22, 2017 10:21 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8390
Location: Midwestern USA
KLset wrote:
I had a look at the ca65 syntax for repetition, and indeed it is not the same as the Kowalski (the equivalent to .rept in ca65 is .repeat, see http://cc65.github.io/doc/ca65.html#ss11.92 for reference).

.REPT is an alternative to .REPEAT in the Kowalski assembler.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 23, 2017 6:49 am 
Offline

Joined: Wed Oct 18, 2017 11:26 am
Posts: 14
BigDumbDinosaur wrote:
.REPT is an alternative to .REPEAT in the Kowalski assembler.
Sorry! My mistake. It's even in the kowalski_directives.txt that you shared.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 38 posts ]  Go to page Previous  1, 2, 3

All times are UTC


Who is online

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