Strange effects using zeropage with ML

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
darkatx
Vic 20 Afficionado
Posts: 473
Joined: Wed Feb 04, 2009 2:17 pm
Location: Canada

Strange effects using zeropage with ML

Post by darkatx »

I've been working on my line drawing routine and I'm trying to optimize it some more since the code is pretty sloppy in CC65.
:oops:
I have it setup to execute with a Basic RUN command...(SYS whatever) Everything seems to be pointing OK.
My main problem is I cannot for the life of me add one to a memory location in $26 (YCOORDLO)

Code: Select all

inc YCOORDLO 
- doesn't seem to work yet...

Code: Select all

		stx YTEMP

		inc y0
		ldx y0

		lda YTABLELOBYTE,x 		
		sta YCOORDLO			;lo byte in zero page

		ldx YTEMP
...incrementing another memory location and then using it as an index to the memory location and storing does work? The table just goes in increments of one and I have checks for when it crosses the page.

If I add a simple delay loop to slow things down I get strange effects too.

I can't even seem to use simple TSX and TXS codes without causing a crash?
:?
Learning all the time... :)
User avatar
tokra
Vic 20 Scientist
Posts: 1124
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

Post by tokra »

If you're doing stuff in the zeropage or with the stack, it's probably a good idea to disable interrupts first using SEI. The strange effects you are witnessing could well be caused by the interrupt-routines kicking in
Kananga
Vic 20 Afficionado
Posts: 317
Joined: Mon Mar 08, 2010 2:11 pm

Post by Kananga »

If cyou manipulate the stack pointer (TXS), it is safer to disable interrupts, unless you take the effects of an interrupt executing just after TXS into account.

For the zeropage, it depends on which location you use. $26 should be no problem, but have you tried debugging your code in an emulator?
cc65 can generate label files (.lbl), which can be loaded into the VICE debugger, or, if you don't like typing in commands, but prefer a point and click interface, into vic20emu (shamelessly advertising my own emulator ;-) )

The benefit of a debugger running on top of an emulator is that you can set 'watchpoints' to trigger a break, if something is reading from or writing to a memory location. This comes in handy, if you see memory changing its contents and you don't know why.
Buy the new Bug-Wizard, the first 100 bugs are free!
User avatar
tokra
Vic 20 Scientist
Posts: 1124
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

Post by tokra »

The VICE-monitor supports watchpoints as well, I'm using this feature a lot when developing for the VIC.
Post Reply