MOVE command success and a bug

just finished testing the MOVE command for the 8-bit project, which copies a block of memory from one location to another, and takes the form

MOVE S$xxxx,D$yyyy,L$zzzz

where S is the Source address, D is the destination address, and L is the length of the block to copy.  as usual the addresses and length must each be exactly 4 hex characters long.  note that the S/D/L characters are, strictly speaking, optional.  i locate hex arguments by searching only for the $ and then looking at the next four characters.  i know this is a bit of a shortcut, but it works for now.  if/when everything is working, i can go back and be more strict about such things.

memory is copied in full 256-byte pages, plus a final partial page if needed.  full pages are copied top to bottom, i.e. starting at offset 0x00 and going to 0xFF.  the partial page, by contrast, is copied bottom to top, i.e. starting at offset 0xzz and going to 0x00.  i did this because it allows me to use the LSB of the stored length parameter as both the counter and the offset index for the LDA/STA commands.

note that their is no argument checking done – so if xxxx < yyyy < xxxx + zzzz, part of the memory to be copied will be overwritten, possibly before it has been copied.  this would obviously lead to unexpected results, and should be avoided.  at some point in the future i hope to improve this function to detect such cases and change the order of the move to produce the intended results.

so, about that bug…as i was debugging MOVE, i found a bug in SHOW (which i was using to verify whether MOVE was working correctly).  The bug was that SHOW would not allow a hex character ‘F’ in its address argument. however, the actual error traced back to the function that converts command line arguments into hex values, meaning that, in reality, NO function would allow an ‘F’ in their arguments.

the cause of the bug is that, in trying to determine if the character i had pulled from the input buffer was a legal hex character, i was doing a CMP #0x0F; BPL err.  however, zero is considered to be positive, so an ‘F’ would cause a branch to an error condition.  but because i was never setting an error code, no error message was generated – it just returned to the input prompt.

the fix was simple – change the CMP #0x0F to CMP 0x10, so that an ‘F’ now goes to -1 and the BPL branches properly.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s