Rev 539 | Blame | Compare with Previous | Last modification | View Log | Download
# file opened: hw_safe_cspect_break.asm1 0000 ; The `s_break` macro is "safe" wrapper for CSpect breakpoint fake instruction `break`.2 0000 ;3 0000 ; On HW board (Z80N or regular Z80) the `break` opcode DD 01 will be processed4 0000 ; as wrongly prefixed `ld bc,imm16`, eating further two bytes of the code after5 0000 ; `break`, damaging value in BC register, and skipping two bytes of machine code.6 0000 ;7 0000 ; The `s_break` macro will produce 6 byte machine code which is "mostly harmless"8 0000 ; on real HW except using stack to preserve BC value and taking 11+4+10+10 T cycles9 0000 ; to execute. While in CSpect emulator with breakpoints enabled the code will still10 0000 ; trigger the debugger (and add the "nop : nop : pop bc" extra instruction sequence11 0000 ; after it).12 0000 ;13 0000 ; (I would still recommend to configure "debug" builds with exit/break enabled and14 0000 ; having separate "release" configuration with `--zxnext` only, which will report15 0000 ; any remaining break/exit instruction left in the source)16 0000 ;17 0000 ; (so this example is more like documentation that bad things happen if you forget18 0000 ; CSpect `break` instruction somewhere and try such code on the HW board)19 0000 ;20 000021 0000 MACRO s_break22 0000 ~ OPT push reset --zxnext=cspect23 0000 ~ push bc23 0000 ~ break23 0000 ~ nop23 0000 ~ nop23 0000 ~ pop bc24 0000 ~ OPT pop25 0000 ENDM26 000027 0000 ; example of usage28 0000 DEVICE ZXSPECTRUM4828 0000 ORG $800029 8000 start:30 8000 06 04 ld b,431 8002 AF xor a32 8003 s_break32 8003 > OPT push reset --zxnext=cspect32 8003 C5 > push bc32 8004 DD 01 > break32 8006 00 > nop32 8007 00 > nop32 8008 C1 > pop bc32 8009 > OPT pop33 8009 myLoop:34 8009 3C inc a35 800A D3 FE out (254),a36 800C 10 FB djnz myLoop37 800E ; `exit` has opcode DD 00, which on regular Z80[N] works as 8T "nop" instruction38 800E OPT --zxnext=cspect38 800E DD 00 exit ; i.e. no need for wrapping macro39 8010 18 FE jr $40 801241 8012 SAVESNA "break.sna", start41 8012 CSPECTMAP "break.map"42 8012# file closed: hw_safe_cspect_break.asmValue Label------ - -----------------------------------------------------------0x8009 myLoop0x8000 X start