        pea     super(pc)
        move    #$26,-(a7)
        trap    #$e
        addq.l  #$6,a7
        clr     -(a7)
        trap    #$1
super:
        move.l  #$40000,d6
        move.l  #$00ff0000,d7
        and.l   $4.w,d7         ;entry point in ROM
        lea     buffer(pc),a1
        move.l  d7,a0
        cmp.l   #$fc0000,d7
        bne.s   .notos1
        move.l  #$30000,d6
.notos1:
        lea     tosversion(pc),a2
        move    2(a0),d0
        moveq   #$f,d1
        and     d0,d1
        add.b   d1,$e(a2)
        lsr.b   #4,d0
        add.b   d0,$d(a2)
        lsr     #8,d0
        add.b   d0,$b(a2)
        pea     (a2)
        move    #$9,-(a7)
        trap    #$1
        addq.l  #$6,a7

        move.l  d6,d0
.cpy:   move.l  (a0)+,(a1)+
        subq.l  #4,d0
        bne.s   .cpy


        clr     -(a7)           ;attrib
        pea     fname(pc)
        move    #$3c,-(a7)      ;fcreate
        trap    #$1
        addq.l  #$8,a7       
        pea     buffer(pc)
        move.l  d6,-(a7)
        move    d0,-(a7)
        move    #$40,-(a7)      ;fwrite
        trap    #$1
        move    #$3e,(a7)       ;fclose
        trap    #$1
        lea     $c(a7),a7
        rts

tosversion:
        dc.b    "Saving TOS 0.00 under TOS.ROM file.",0
fname   dc.b    "TOS.ROM",0
	SECTION BSS
buffer  ds.l    $10000
