;
; NTSCBoot.asm
;
; Copyright (C) 1990 By Udi Finkelstein.
; 17 feb 1990
;
; Reboot a SuperAgnus equipped PAL machine into NTSC mode.
;
; With thanks to Bart Whitebrook from CBM for his article on the new ECS
; registers in the 3rd european DevCon notes!

; get into supervisor state, since we can only execute RESET there.
       xref    _LVOSuperState
       move.l  4,a6
       jsr     _LVOSuperState(a6)

; ************************************
; Warning!!! a grand hack ahead!!!!!!!
; Never do this stuff alone at home!!!
; ************************************

; Now we are in supervisor mode, and can issue a RESET command.
; Unfortunately, after RESET there is no RAM in the system!
; We can issue exacly *one* instruction ( 1 word length ) because
; the instruction was fetched before RESET was executed. This
; instruction can be a 'jmp (aX)', to somewhere on the ROM, where the
; program can continue. After searching the Kickstart 1.3 ROM, I found
; that at address $ff4120 you can find the code:

; [ Notice - for Kickstart 1.3 ***ONLY***!!! Is there anybody out there
;   with a Kickstart 1.2/super Agnus combination? you have a problem! ;-) ]

;00FF4120 2741 0038              move.l  d1,$38(a3)
;00FF4124 4281                   clr.l   d1
;00FF4126 4ED6                   jmp     (a6)

; We can use this code fragment to set the NTSC bit in the super agnus,
; and then jump to the reset code. The PAL/NTSC bit is contained in
; address $DFF1DC   (BEAMCON0 !).
;
; 'move.l d1,$38(a3)' writes a longword, therefor $38(a3) must point to
; $dff1da because it's a read only location, which we can't harm, and
; $dff1dc contains the PAL/NTSC bit.
; $38(a3) == $dff1da   -->  a3 == $ddf1a2
; we must reset d1 ofcourse, or set d1 == #$00000020 to set PAL mode.
;
; ofcourse we have to set a6 to $00000002 to run the reset code later.
;

ROMADR =       ($ff4120-$fc0000)

; ROMADR points to $ff4120 after the ROM appears in address $0000.

       lea.l   $dff1a2,a3
       move.l  #$0,d1
       move.l  2,a6
       cnop    0,4
       lea.l   ROMADR,a5
       RESET                   ;reset the machine...
       jmp     (a5)            ;execute our code fragment.

; Well, that's it. I tried writing a more portable code by trying to
; set/reset the OVL bit in $BFE001 instead of 'jmp (aX)' after RESET,
; but I wasn't able to get it working, so the only way I found to run
; a code after RESET is to find a ROM fragment that happenes to match
; my requirement. You don't have to tell me how bad it is. Hopefully,
; the 1.4 preferences will have a PAL/NTSC software switch ( Will it?!!)

       END
