Jump to content
IGNORED

Switch off all interrupts


Recommended Posts

In this situation, I need to stop the current game and launch ($2000, then $4000). And then restart the game with JMP $aa00.

 

What should be after org $600 in the following example?:

  org $600

;HERE SHOULD BE ALL INTERRUPTS OFF:
  lda #0
  sta DMACTL
  sta SDMCTL
  ...
;THEN CONTINUE:
  jsr $2000                                   ;start something
  jsr $4000                                   ;start something
  jmp $aa00                                   ;JMP

 

 

 

It was tested inserting the following, but the example does not work as desired:

 

Macro ClearSystem:

;--------------------------------------------------------------------------------
; ClearSystem
;--------------------------------------------------------------------------------

	.macro ClearSystem
	   .if :0 <> 0
	      .error "ClearSystem error"

	   .else
	      clc
	      cld

	      sei

	      lda #0
	      sta IRQEN	; clear interrupts and screen
	      sta NMIEN

	      sta DMACTL
	      sta COLBK

	      sta GRAFP0	; clear P/M
	      sta GRAFP1
	      sta GRAFP2
	      sta GRAFP3
	      sta GRAFM

	      sta HPOSP0
	      sta HPOSP0+1
	      sta HPOSP0+2
	      sta HPOSP0+3
	      sta HPOSM0
	      sta HPOSM0+1
	      sta HPOSM0+2
	      sta HPOSM0+3

	      sta PRIOR	; clear GTIA also

	      sta AUDCTL	; clear sound
	      sta AUDC1
	      sta AUDC2
	      sta AUDC3
	      sta AUDC4

	      lda #3
	      sta SKCTL
	   .endif

	.endm

 

Link to comment
Share on other sites

Disable interrupts before doing shadow register stuff.

 


  sei

  lda pactl

  and #$fe

  sta pactl

  lda pbctl

  and #$fe

  sta pbctl

  lda porta

  lda portb ; clear any pending PIA IRQs

  lda #0

  sta nmien

  sta irqen

  sta sdmctl

  sta dmactl

 

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Rybags said:

Disable interrupts before doing shadow register stuff.

Thanks, but it didn't work. Here is a simple example:

  • Original game: Game.xex
  • An image:       Image.xex
  • The game with the image: Game with Image.xex. The image should be launched when reaching Bridge 2, it's done, but changing the interrupts don't stop the game, and the image is not shown.
  • The code to be fixed at $8000: code.asm. Here is where the game must be stopped before launching the image, in label "newchange".
  • Macros required for ClearSystem, CopyMemory: sys_macros.m65  sys_equates.m65

 

Description of segments for "Game with Image.xex":

Segments.png.db81549a3566eb2896c9db05839d0825.png

 

 

code.asm, label "new change":

newchange
  sei
  lda pactl
  and #$fe
  sta pactl
  lda pbctl
  and #$fe
  sta pbctl
  lda porta
  lda portb ; clear any pending PIA IRQs
;  lda #0
;  sta nmien
;  sta irqen
;  sta sdmctl
;  sta dmactl
  lda #$00       ; disable the display
  sta DMACTL
  sta SDMCTL
  lda PORTB      ; disable BASIC on XL/XE
  ora #$02
  sta PORTB
  ClearSystem			           ;sys_macros.m65
  CopyMemory $82B6,$2000, ($908C-$82B6+1)  ;sys_macros.m65 (it says it uses page zero memory): move image from $82B6-$908C to $2000-$2DD6
  jsr $2c00                                ;INI image
  jmp $9ff6                                ;JMP $9ff6 launch the game again

 

Link to comment
Share on other sites

He's commented out the NMI disable so it's not going to work properly because of that.

 

As you're disabling the display, I'd suggest to do that offscreen so there's no unwanted glitches.

 

Insert before all of the other stuff:

 


wait_offscr

  lda vcount

  cmp #$10

  bcs wait_offscr

 

(using VCOUNT as RTCLOK won't work if NMI already inactive)

Link to comment
Share on other sites

9 hours ago, MaPa said:

You disable NMI (DLI + VBI) and at $2c00 waiting for RTCLOCK to be increased which happens in the disabled VBI... so infinite loop there.

 

8 hours ago, Rybags said:

Insert before all of the other stuff:

 

Thank you guys, but still not launching the image.

The segment of the image is copied to $2000, and yep, then at the moment of launching the image with jsr $2c00, it crashes.

 

I tested adding the code suggested by Rybags, as the following, but nothing. Still I don't get why to add a wait in that moment, before all of the other stuff, being that nothing has been disabled yet.

Also, the part with NMI and ClearSystem was commented, in order to not to disable NMI, but the same.

 

 

What should be changed in  code.asm  ?

 

	icl "sys_equates.m65"
	icl "sys_macros.m65"


  org $8000
  lda $62					;original code
  sed						;original code
  adc #$00					;original code
  sta $62					;original code
  lda $61					;original code
  adc #$00					;original code
  cld						;original code
  sta $61					;original code
  inc $2e					;original code
  lda $62
  cmp #$02
  beq newchange
  jmp	$a500                             ;Else: Back to normal code


newchange

wait_offscr
  lda vcount
  cmp #$10
  bcs wait_offscr
  
  sei
  lda pactl
  and #$fe
  sta pactl
  lda pbctl
  and #$fe
  sta pbctl
  lda porta
  lda portb ; clear any pending PIA IRQs
;  lda #0
;  sta nmien
;  sta irqen
;  sta sdmctl
;  sta dmactl
  lda #$00                                      ; disable the display
  sta DMACTL
  sta SDMCTL
  lda PORTB                                     ; disable BASIC on XL/XE
  ora #$02
  sta PORTB
;  ClearSystem			                ;sys_macros.m65
  CopyMemory $82B6,$2000, ($908C-$82B6+1)	;sys_macros.m65: move image from $82B6-$908C to $2000-$2DD6
  jsr	$2c00                                   ;INI image
  jmp	$9ff6                                   ;JMP $9ff6 launch game again

 

Link to comment
Share on other sites

The wait is due to disabling DMACTL.  If you do that partway down the screen you get a dirty transition, like half a displayed frame then black.

Atari programs for the most part are good in that display transitions are usually clean.

 

Once you're done with needing interrupts disabled you should probably enable them again.

If IRQs are left masked by SEI, the stage 2 VBlank won't execute (assuming the VBlank NMI is enabled again to begin with)

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Here's a simple way to combine the Image.xex with Game.xex:

    opt h-
    ins 'Image.xex'
    opt h+
    ini $2C00
    opt h-
    ins 'Game.xex'

ImageGame.xex

 

No need to disable interrupts because Image.xex already does that. It also re-enables them when it exits, so any disk I/O, to continue loading will operate correctly.

 

The important thing is to get the whole Image.xex loaded, then have an INI segment to run it, then the Game.xex, in that order. See also:

 

https://www.atarimax.com/jindroush.atari.org/afmtexe.html

  • Thanks 1
Link to comment
Share on other sites

2 hours ago, Xuel said:

Here's a simple way to combine the Image.xex with Game.xex:

Thanks, but that's not the idea, it's an example of an ending screen, not in the beginning. Go to Bridge 2 (Level 2) and you'll realize. Now when reaching bridge 2, it jumps to $8000, here the image must be loaded (jsr $2c00), and then restart the game with jmp $9ff6. But for some reason (likely some process of the game are still running), when executing jsr $2c00, it crashes.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...