emulator crashing when sep/rep processor status bits

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
emulator crashing when sep/rep processor status bits
by on (#80723)
hello, im using Neviksti's snes-starterkit (WLA-DX assembler) and messing with the example Hello.asm...

let me show some example code:
Code:
   
; some other init code/misc stuff goes here....

; do some math with the decimal flag clear
   PrintString "\nDecimal flag clear: 9+8 = "
   lda #9
   clc
   adc #8
   sta var2   
   PrintNum var2

;this is what i put in
   rep #$30 ;16 bit A, X, Y
   lda #$FEEB
   sta $0000
   sep #$30 ;8 bit A,X,Y
;end of 'this is what i put in'

forever:
   wai   ;wait for next frame
   ;do whatever you feel like here   
   ;let's print the current frame number
   SetCursorPos 20, 10
   ldy #FrameNum
   PrintString "Frame num = %d    "
   jmp forever


Snes9x Geiger's Debugger will crash every time (as in program hard crash)
bsnes will just give be a blank screen.

Why is this happening? I was told to look at the output generated by WLA-DX after it processes the macros, but I'm not sure how to do that. I do suspect that there is an issue with the macros here, I just don't know how to pinpoint it.

I also thought maybe interrupt had something to do with it, like it was trying to run some other code in the middle of the thing i inserted, so i
disabled interrupts before and then enabled them after my snippet but it did not help.

any help would be appreciated, thanks.

by on (#80753)
I don't know why Snes9x crashes. What I can say is that you should ditch Snes9x right away and use BSNES instead, as it's a lot more accurate and also has a debugger.

What were the register size bits set to before the instructions you inserted? You should make sure they're set to the same as they were before. Otherwise you might start executing garbage.

by on (#80778)
mic_ wrote:
I don't know why Snes9x crashes. What I can say is that you should ditch Snes9x right away and use BSNES instead, as it's a lot more accurate and also has a debugger.

What were the register size bits set to before the instructions you inserted? You should make sure they're set to the same as they were before. Otherwise you might start executing garbage.


im not sure what they were set to before but im 100% sure that its crashing at the first occurrence of modifying the register size bits. (so its not even getting a chance to execute garbage code)

i can fiddle with the decmial and IRQ, etc flags all day but as soon as i touch the register size, everything breaks.

i am not running in 6502 emulation mode either, at least i dont think i am. i put this at the start of my code:
Code:
   clc
   xce

by on (#80780)
I couldn't even assemble the code if I added those 4 lines. The assembler chokes at an LDX instruction in SetCursorPos that is trying to load an immediate larger than 8 bits after you've set all the registers to 8-bit with SEP #$30.

by on (#80788)
ZSNES and SNES9x are cheating emulators that hide technical shortcommings with game-specific patching.

I find all the interrupt stuff confusing and not very well documented. I just had to keep manipulating my code until it worked.

by on (#80807)
Solution, use BSNES. It's the best emulator for testing things. But testing in real hardware is always going to be the only way to really know if your programs work or not.

by on (#80814)
mic_ wrote:
I couldn't even assemble the code if I added those 4 lines. The assembler chokes at an LDX instruction in SetCursorPos that is trying to load an immediate larger than 8 bits after you've set all the registers to 8-bit with SEP #$30.


Yeah not sure how i was getting the code to assemble...i restarted over and youre right, it would not assemble (which makes sense).
(i know bsnes is the accuracy emulator but it wasnt performing as expected in bsnes either, meaning the problem is my ability to code :lol: )

i've been messing with it more and i think i have got it working.

Code:
forever:
   wai   ;wait for next frame
   ;do whatever you feel like here   
   ;let's print the current frame number
   ;rep #$10
   SetCursorPos 20, 10
   ldy #FrameNum
   PrintString "Frame num = %d    "
   
   rep #$20
   lda #$EFBE
   sta $0000
   sep #$20
   
jmp forever


so in conclusion i think i'm just a retard of some kind. thank you for the help.