Hi Andy, > Could be a simple solution such as an incorrect stack but it's > confusing me as when I save the SP do the above then restore > the SP it works then resets.
Looks like that from just a quick glance at chk2... You aren't doing anything to preserve the stack, or create a new one. When you CALL your routine at 32768 to run it from BASIC, the SP will be somewhere in lower memory area... You are then paging in the screen page in the lower memory, so SP is pointing to somewhere in that screen memory.... then you CALL the fill routine, which will PUSH the program counter somewhere into there, and then it will get wiped when it does the 24576 byte fill... so the RET will POP crap back and jump to that address - hence your crash. You need to always watch where your stack is! Very quickly something like this off the top of my head, at the start of "start": LD (oldstack),SP ; store current SP LD SP, newstack+62 ; set up new stack in high memory then before your RET to BASIC at the end of 'start' LD SP,(oldstack) ; restore original stack pointer then at your end of the code, just a few temp variables/stores, which will be in high memory when you compile and run: oldstack: Defw 0 ; two bytes for storing the old SP newstack: Defs 64 ; 64 bytes of space for the new stack. Colin ===== Quazar : Hardware, Software, Spares and Repairs for the Sam Coupe 1995-2007 - Celebrating 12 Years of developing for the Sam Coupe Website: http://www.samcoupe.com/