Skip to content

Debugging – How the Heck Did That Ever Work?

June 9, 2017

Because I’m lazy, I do everything in C and, if it works, I leave it alone til it doesn’t. In this case, I had written the fake loader in C. So I was going through all the init code, setting up stacks and registers then eventually loading or branching to an already loaded program that repeated the initialization code. Critically, the CPU was running with R3 as the program counter when it hit the second copy of the init code. The init code expects to be running on R0 so when it started loading R3, hilarity ensued. That was tough. Thankfully it failed nicely in the emulator so it turned up after some head scratching.

On the plus side, this forced me to redo the loader in assembly which i should have done from the beginning. It only takes 21 bytes but i’m going to settle on location 0x100 for the target program to leave me room for a better loader, maybe a register save etc.

When I get to the serial/xmodem loader that won’t be enough room so maybe I’ll make it 512 – that just saves me changing the target code location.

;;1806loader simulates 1802 load mode in run for 1805/6
target: equ 256
	b4 run		;bypass bootloader if IN pressed
	ldi	(target)&255
	plo	14
	ldi	(target)>>8; was/256
	phi	14
	sex 14		;in X register
noEF4:	bn4 noEF4	;loop til IN pressed
	inp 6		;load memory
	nop		;let the AVR breathe
	out 7		; echo
yEF4:	b4 yEF4		;wait til switch released
	br noEF4	;back for more
run:	lbr target	;finally - off we go

From → Uncategorized

One Comment

Trackbacks & Pingbacks

  1. Adding A Narrow ROM To the 1802 Olduino | olduino

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: