Jump to content
Sign in to follow this  
Pioneer4x4

Do I have to use asm code to write to swcha?

Recommended Posts

I want to toggle the normally input ports high or low.

code such as

 

SWCHA = %00000000

or

 

SWCHA = %11111111

Doesn't seem to do it. They consistantly read high. After either command.

 

One thing I was wondering, it may be just that it is only setting it instantly, and not "latching" them high or low, and it is too fast for it to be detected.

I will try looping it MANY times to see if it works.

I would like them to stay high or low for a while, possibly several frames.

 

 

This is for something else I am working on, and I am trying to get it working myself, but I am starting to think it is not possible with pure batari Basic code.

Edited by Pioneer4x4

Share this post


Link to post
Share on other sites

I'm not sure if its possible in batari Basic but the theory is as follows :-

 

To drive a bit out you first need to make the port bits of interest an output by writing '1' to them in the port A Data Direction Register (DDR) on RIOT (at address 0x281 called SWACNT).

 

To drive to a logic low you would write the data pattern with the desired bit(s) low to SWCHA first and then make it an output by writing '1' to those same bits in SWACNT. That way you avoid glitches on the output.

 

To "drive" a logic high you just make the bit of interest an input again and rely on the internal RIOT pull-ups to pull the line high. This seems like a strange thing to do but there are external switches connected to the port. If you made it an output and then drive it to a logic high and the switch is closed you'd short the RIOT output to GND which isn't good.

Share this post


Link to post
Share on other sites

Thanks a bunch, I think I understand that.

Now,

How do I set bits for output via batari basic? Is there an equivalent to "POKE" (Or PEEK) in batari basic? If not, call it a feature request! ;-)

 

And let's assume that I get this working, once a bit is set low, will it remain that way until it is made an input?

Edited by Pioneer4x4

Share this post


Link to post
Share on other sites
How do I set bits for output via batari basic? Is there an equivalent to "POKE" (Or PEEK) in batari basic?

 

You can treat any 2600 hardware register like a variable in bB. So to POKE use "REGISTER=value", and to PEEK use "somevariable=REGISTER", where REGISTER is the name of the HW register you want. (SWACNT in your case)

 

Just keep in mind that many registers are read-only and write-only.

Share this post


Link to post
Share on other sites
How do I set bits for output via batari basic? Is there an equivalent to "POKE" (Or PEEK) in batari basic?

 

You can treat any 2600 hardware register like a variable in bB. So to POKE use "REGISTER=value", and to PEEK use "somevariable=REGISTER", where REGISTER is the name of the HW register you want. (SWACNT in your case)

 

Just keep in mind that many registers are read-only and write-only.

 

as in

0x281 = %10101010 will enable every other bit to be set out output?

Share this post


Link to post
Share on other sites

as in

0x281 = %10101010 will enable every other bit to be set out output?

 

Looking at that post I quoted of batari's you should be able to do :-

 

SWACNT=%01010101

Share this post


Link to post
Share on other sites

THANKS!!!!! I think it is working, at least stella says it is.

Let me putz and get back.

I think part of my problems was I was typing swacnt, not SWACNT!

Share this post


Link to post
Share on other sites

It works for me, at least in Stella:

 

  rem * Test SWACNT and SWCHA
  scorecolor = $0E
  SWACNT = %11110000
  SWCHA = %01010000
  score = 0
  if !joy0right then score = score + 1000
  if !joy0left then score = score + 100
  if !joy0down then score = score + 10
  if !joy0up then score = score + 1
loop1
  drawscreen
  a = a + 1
  if a <> 0 then goto loop1
  SWCHA = %10100000
  score = 0
  if !joy0right then score = score + 1000
  if !joy0left then score = score + 100
  if !joy0down then score = score + 10
  if !joy0up then score = score + 1
loop2
  drawscreen
  a = a + 1
  if a <> 0 then goto loop2
  SWCHA = %01010000
  score = 0
  if !joy0right then score = score + 1000
  if !joy0left then score = score + 100
  if !joy0down then score = score + 10
  if !joy0up then score = score + 1
  goto loop1

Share this post


Link to post
Share on other sites

OK, what does that do, and how are you testing?

In my program, I do see the SWACNT: Line of bits in stella changing every frame, but I did not see any change on the actual ports on the real hardware.

 

Where in stella would I see if the joystick port is actually high or low?

post-25375-0-48900800-1324248316.png

Share this post


Link to post
Share on other sites

OK, what does that do, and how are you testing?

In my program, I do see the SWACNT: Line of bits in stella changing every frame, but I did not see any change on the actual ports on the real hardware.

 

Where in stella would I see if the joystick port is actually high or low?

post-25375-0-48900800-1324248316.png

All my program does is set the four high bits of port A to output mode, then I'm toggling those bits from 0101 to 1010.

 

To test whether the values are being retained in the upper four bits of the port A register, I'm setting the last four digits of the score to match those bits. Since those bits are used for the left joystick, I'm using the joystick functions to determine whether a given bit is 0 (the joystick is pressed in that direction) or 1 (the joystick is not pressed in that direction). I may have been able to just do something like "b = SWCHA" to read the whole register at once, but I didn't try that yet. I don't know how this will behave on real hardware.

Share this post


Link to post
Share on other sites

I figured out what you were doing and looked at io in stella and saw it matching the score, thanks!

What I was working on was a proof of concept where I switched 2 joystick lines high and low every other frame.

And...

THEN I connect, my LCD shutters to pin 7 and the 2 pins that switch, and drumroll badabadabada!

I see every other frame with oposite eyes, and 3D may be possible!

 

I just mocked up a all grey playfield that with lines in different places, and 1 static.

I would love to say it works beautifully, but like the SEGA 3D there is TONS of bleedthrough. But it does appear to work! I will putz some more this week, and post results.

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...