6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat May 04, 2024 9:39 am

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Thu Apr 27, 2017 2:24 am 
Offline

Joined: Sat Mar 11, 2017 1:56 am
Posts: 276
Location: Lynden, WA
I spent a couple nights trying to track down some strange behavior in my fledgling monitor program. Basically, it had all the hallmarks of some sort of RAM corruption leading to inadvertent crashes.

Finally I inspected the identifier window of the simulator.

In my code, I have the following:

previou
Code:
STRING_PTR:   .DS    $02      ;pointer to current output message string
STRING_INDEX:    .DS    $01      ;index into input buffer
LINE_CNT:    .DS   $01      ;clear screen line count
CMD_INDEX:   .DS   $02      ;index into command string list
SELECTED_CMD:   .DS   $02      ;pointer to slected command routine


LINE_CNT, and CMD_INDEX weren't shown in the sim's identifier window. Even after re-assembling. What was weirder, SELECTED_CMD was show to be where it should have been if the two missing identifiers were ther as they should have been.

So I saved, closed, re-opened, and re-assembled. I checked the identifier window, and everything was fixed! Put the code in ROM, and all the weird crashes stopped.

Any idea what happened here? Is it a bug, or could I have done something strange? BTW, the two identifiers had been in use before the weirdness, so adding them wasn't the trigger.


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 27, 2017 4:46 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8173
Location: Midwestern USA
Dan Moos wrote:
I spent a couple nights trying to track down some strange behavior in my fledgling monitor program. Basically, it had all the hallmarks of some sort of RAM corruption leading to inadvertent crashes.

Finally I inspected the identifier window of the simulator.

In my code, I have the following:

previou
Code:
STRING_PTR:   .DS    $02      ;pointer to current output message string
STRING_INDEX:    .DS    $01      ;index into input buffer
LINE_CNT:    .DS   $01      ;clear screen line count
CMD_INDEX:   .DS   $02      ;index into command string list
SELECTED_CMD:   .DS   $02      ;pointer to slected command routine


LINE_CNT, and CMD_INDEX weren't shown in the sim's identifier window. Even after re-assembling. What was weirder, SELECTED_CMD was show to be where it should have been if the two missing identifiers were ther as they should have been.

So I saved, closed, re-opened, and re-assembled. I checked the identifier window, and everything was fixed! Put the code in ROM, and all the weird crashes stopped.

Any idea what happened here? Is it a bug, or could I have done something strange? BTW, the two identifiers had been in use before the weirdness, so adding them wasn't the trigger.

Are these supposed to be zero page locations you are defining or absolute memory?

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 27, 2017 7:36 pm 
Offline

Joined: Sat Mar 11, 2017 1:56 am
Posts: 276
Location: Lynden, WA
Zero page.

I'm no longer sure the erratic behaviour was related, as it came back. It turned out a resistor I'd put in s series with the clock to tame ringing was making poor contact, so my clock was screwy. Dealing with that caused all trouble to cease.

Still, strange that those identifiers didn't show up in the list until I restarted the editor.


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 27, 2017 7:53 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8430
Location: Southern California
Dan Moos wrote:
I'm no longer sure the erratic behaviour was related, as it came back. It turned out a resistor I'd put in s series with the clock to tame ringing was making poor contact, so my clock was screwy. Dealing with that caused all trouble to cease.

I don't want to sound discouraging, but it sounds like it's on the raggedy edge of working. Putting a resistor in a clock line is very bad practice, but in this case maybe just not quite as bad as what you had before. If you're still confined to a solderless breadboard, at least make the clock connections as short and direct as possible, not big hoops. The same goes for power and ground which should have wires making short connections across boards so the return current doesn't have to go all the way out to the end of the board to get its connection to the next board over. We want you to be successful of course.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 28, 2017 4:23 am 
Offline

Joined: Sat Mar 11, 2017 1:56 am
Posts: 276
Location: Lynden, WA
It was a small resistor on the recommendation of another forum member.

I just have some ringing, that wasn't causing me any trouble, but bugged me on principle. The resistor cured it. I have removed the resistor altogether, and have had no issues since, with rigorous torture testing. I'm only running at 1 MHZ, and the system seems completely stable.

If I go permanent build, I'm going PCB It will either be home-brewed, or pro etched. Haven't decided. I am confident, based on past efforts, that I can do a home brewed pcb with the needed specs. I know having true dedicated power/ground planes is huge, but I feel if I can get the thing to work on a breadboard, I can get it to work on a 2 sided PCB.

Remember, this is just for fun, and "see how far I can take it" purposes, so failed attempts are all part of the game. Once I switch from the fun of building the thing, to the fun of creating software for it, I'll most certainly have a board house make me a proper pcb.

The thing seems pretty stable on my current setup though.


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 28, 2017 2:26 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8173
Location: Midwestern USA
Dan Moos wrote:
Zero page...Still, strange that those identifiers didn't show up in the list until I restarted the editor.

Zero page assignments are best not done with .DS (which is the equivalent of *=*+). Conventionally, zero page locations are assigned with simple equates. For example, here is how I do it in POC's firmware:

Code:
;================================================================================
;
;BIOS/KERNEL DIRECT PAGE STORAGE
;
zeropage .set 0                ;physical zero page
kerneldp =zeropage             ;kernel's notion of direct page
;
;
;   DUART channel block & pointer allocation...   
;
s_nxpchp =s_ptr*n_nxpch        ;channel
s_nxpbkp =s_ptr*n_nxpblk       ;block
;
;
;   counters & timers...
;
jiffct   =kerneldp             ;jiffy counter
uptime   =jiffct+s_byte        ;uptime counter (seconds)
uxtime   =uptime+s_utcnt       ;UNIX time (seconds)
tdjiffct =uxtime+s_time_t      ;sleep jiffy counter
tdsecct  =tdjiffct+s_byte      ;sleep time (seconds)
;
;
;   TIA-232 driver workspace...
;
tiasr    =tdsecct+s_tdcnt      ;DUART channel status
tiacr    =tiasr+s_nxpchp       ;DUART channel command
tiafif   =tiacr+s_nxpchp       ;DUART channel FIFO
tiaisr   =tiafif+s_nxpchp      ;DUART block IRQ status
tiagetrx =tiaisr+s_nxpbkp      ;RxD FIFO 'get'
tiaputrx =tiagetrx+s_nxpchp    ;RxD FIFO 'put'
tiagettx =tiaputrx+s_nxpchp    ;TxD FIFO 'get'
tiaputtx =tiagettx+s_nxpchp    ;TxD FIFO 'put'
tiatxst  =tiaputtx+s_nxpchp    ;TxD status (bit field)
tiaiblk  =tiatxst+s_byte       ;block offset
tiaicoff =tiaiblk+s_byte       ;input channel offset
tiaocidx =tiaicoff+s_byte      ;output channel index
tiaocoff =tiaocidx+s_byte      ;output channel offset

Values such as S_BYTE and S_TIME_T are externally defined in a different INCLUDE file.

One of the sneaky problems with making zero page assignments as you are doing is you have to set the program counter to the start of zero page, which makes the assembler think it is starting to assemble code at zero page.

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 28, 2017 3:44 pm 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
BigDumbDinosaur wrote:
One of the sneaky problems with making zero page assignments as you are doing is you have to set the program counter to the start of zero page, which makes the assembler think it is starting to assemble code at zero page.

Assuming you set the address back to a code space when you're done, does that matter?

Certainly looks a lot cleaner than calculating the addresses yourself.


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 28, 2017 5:09 pm 
Offline

Joined: Sat Mar 11, 2017 1:56 am
Posts: 276
Location: Lynden, WA
I did it exactly as Arlet said. It works great. This wasn't a code problem, it was a weird sim behavior that a simple restart cured. I'm just curious if it's a known issue, or just a rare fluke.


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 28, 2017 7:57 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8430
Location: Southern California
I'm not familiar with the Kowalski assembler, but I would hope it has something more elegant than
Code:
<label>   =<previous_variable_name> + <previous_variable_size>
to assign variable space. What does .DS (which I assume means "Define Storage") do that's undesirable in ZP, BDD? The two 6502 commercial assemblers I've used are 2500AD and C32. 2500AD uses BLKB (assign a BLocK of so many Bytes), and C32 uses DFS (DeFine Storage), like this:
Code:
.PAGE0

STRING_PTR:    BLKB  2      ; pointer to current output message string
STRING_INDEX:  BLKB  1      ; index into input buffer
LINE_CNT:      BLKB  1      ; clear screen line count
CMD_INDEX:     BLKB  2      ; index into command string list
SELECTED_CMD:  BLKB  2      ; pointer to slected command routine

and
Code:
 ORG 0

STRING_PTR:    DFS   2      ; pointer to current output message string
STRING_INDEX:  DFS   1      ; index into input buffer
LINE_CNT:      DFS   1      ; clear screen line count
CMD_INDEX:     DFS   2      ; index into command string list
SELECTED_CMD:  DFS   2      ; pointer to slected command routine

It's more clear, and it doesn't require changing more than one line when you want to add, delete, or resize a variable.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 28, 2017 9:15 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8173
Location: Midwestern USA
Arlet wrote:
BigDumbDinosaur wrote:
One of the sneaky problems with making zero page assignments as you are doing is you have to set the program counter to the start of zero page, which makes the assembler think it is starting to assemble code at zero page.

Assuming you set the address back to a code space when you're done, does that matter?

It may with the Kowalski assembler, since it may populate part or all of the zero page space with (presumably) nulls, which will result in a saved program being much larger than anticipated.

Quote:
Certainly looks a lot cleaner than calculating the addresses yourself.

It's no cleaner than the "orthodox" method of using simple equates, as I show in my example.

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 28, 2017 10:10 pm 
Offline

Joined: Sat Mar 11, 2017 1:56 am
Posts: 276
Location: Lynden, WA
I can definitely say the through the eyes of a newbie, .DS is way more understandable and clean.


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 28, 2017 10:35 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1928
Location: Sacramento, CA, USA
Meh, six to one, a half dozen to another. I happen to favor the use of equates, but I don't try to push my preferences on others unless they specifically ask me.

Mike B.


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 29, 2017 4:30 am 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
I like the way the ca65 assembler does it. Instead of using ORG, you just start a segment using ".zeropage", and then define the labels. When you want to assemble some code, you start an appropriate code segment. You can switch back and forth as you want, and let the linker figure out all the addresses.

Per segment, you can define whether to fill with a certain value, or use initialized data from the source, and choose an output file to store it.


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 7 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:  
cron