68k initialization: Difference between revisions

From NeoGeo Development Wiki
Jump to navigation Jump to search
No edit summary
 
mNo edit summary
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== Vectors ==
Vector table and header for AES/MVS roms:
<pre>
    org $0
    dc.l $0010F300         ; Initial SP
    dc.l $00C00402         ; Initial PC
    dc.l $00C00408,$00C0040E,$00C0040E,$0000034C      ; Bus error (2),Address error (3),Illegal Instruction (4),Divide by 0 (5)
    dc.l $0000034E,$0000034E,$00C0041A,$00C00420      ; CHK Instruction (6),TRAPV Instruction (7),Privilege Violation (8),Trace (9)
    dc.l $0000034E,$0000034E,$00C00426,$00C00426      ; Emu(10),Emu(11),Reserved,Reserved
    dc.l $00C00426,$00C0042C,$00C00426,$00C00426      ; Reserved,Reserved,Reserved,Reserved
    dc.l $00C00426,$00C00426,$00C00426,$00C00426      ; Reserved,Reserved,Reserved,Reserved
    dc.l $00C00426,$00C00426,$00C00432,VBlank          ; Reserved,Reserved,Spurious Interrupt(24)
    dc.l IRQ2,$00C00426,$00C00426,$00C00426
    dc.l $00C00426,$00C00426,$0000056E,$0000056E      ; Auto,Auto,Trap 0, Trap1...
    dc.l $0000056E,$0000056E,$0000056E,$0000056E
    dc.l $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
    dc.l $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
    dc.l $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
    dc.l $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
    dc.l $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
    dc.l $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
    dc.l $FFFFFFFF,$FFFFFFFF
    org $0100
    dc.b "NEO-GEO",$00
    dc.w $0052 ; NGH Number in BCD (0052 is ssideki)
    dc.l $00080000      ; ?
    dc.l $00100000 ; ?
    dc.w $0000
    org $0114
    dc.b $01            ; Bootscreen flag ($00 skips it)
    dc.b $1B ; First tile number of the NeoGeo logo in the C ROM
    dc.l $00000200 ; Japanese config menu pointer
    dc.l $00000200 ; English config menu pointer
    dc.l $00000200 ; European config menu pointer
    jmp Start
    jmp Start  ; Not used ?
    jmp Start  ; Not used ?
    jmp Start  ; Not used ?
    dc.l $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
    dc.l $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
    dc.l $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
    dc.l $FFFFFFFF,$FFFFFFFF,$FFFFFFFF,$FFFFFFFF
    dc.l $FFFFFFFF,$FFFFFFFF
    dc.l $00000186  ; Security code pointer ?
    org $186            ; ???
    dc.l $76004A6D,$0A146600,$003C206D,$0A043E2D
    dc.l $0A0813C0,$00300001,$32100C01,$00FF671A
    dc.l $30280002,$B02D0ACE,$66103028,$0004B02D
    dc.l $0ACF6606,$B22D0AD0,$67085088,$51CFFFD4
    dc.l $36074E75,$206D0A04,$3E2D0A08,$3210E049
    dc.l $0C0100FF,$671A3010,$B02D0ACE,$66123028
    dc.l $0002E048,$B02D0ACF,$6606B22D,$0AD06708
    dc.l $588851CF,$FFD83607
    dc.w $4e75
    org $200          ; Config menus, need to find format...
    dc.b "0123456789ABCDEF"
    dc.l $FFFFFFFF
    dc.w $0364
    dc.b $14,$13,$24,$01
</pre>
== Basic init code ==
== Basic init code ==
The initial PC value in your [[68k]] binary must be $C00402 (Init [[BIOS Calls|BIOS call]]), the initial SP value must be $10F300 (end of [[68k user RAM|user RAM]]).
The initial PC value in the [[68k]] binary must be $C00402 (Init [[BIOS calls|BIOS call]]), the initial SP value must be $10F300 (end of the [[68k user RAM|user RAM]]).


The entrypoints for your [[68k]] code start at $000122. There's usually 4 JMP instructions there (why ?).
The entrypoints for the [[68k]] code start at $000122. See [[68k program header]].


<pre>
<syntaxhighlight>
     lea    $10F300, sp
     lea    $10F300, sp
     lea    $10F300, a7
     lea    $10F300, a7       ; Depends on assemblers
     move.b  d0,REG_DIPSW      ; Kick the watchdog
     move.b  d0,REG_DIPSW      ; Kick watchdog
     move.w  #7,REG_IRQACK    ; Acknowledge any pending interrupts
     move.w  #7,REG_IRQACK    ; Acknowledge any pending interrupts
     move.w  #$2700,sr        ; Disable all interrupts
     move.w  #$2700,sr        ; Disable all interrupts
</pre>
</syntaxhighlight>


See [[68k interrupts]] and [[Watchdog]] for more informations.
See [[68k interrupts]] and [[Watchdog]] for more informations.


Clearing [[user RAM]]:
Clearing the [[68k user RAM]]:
<pre>
<syntaxhighlight>
     lea    RAMSTART,a0       ; Should be $100000
     lea    RAMSTART,a0
     move.l  #($F300/4)-1,d0  ; User RAM's size is $F300, and we clear longwords (4 bytes)
     move.l  #($F300/4)-1,d0  ; User RAM's size is $F300, and we clear longwords (4 bytes)
clram:
clram:
     clr.l  (a0)+
     clr.l  (a0)+
     dbra    d0,clram
     dbra    d0,clram
</pre>
</syntaxhighlight>


Note that this function also clears the stack. Don't make a subroutine out of it unless you're sure of what addresses you're clearing.
Note that this function also clears the stack. Don't make a subroutine out of it unless you're sure that the return address won't be cleared.


Clearing sprites: make a BIOS call.
BIOS calls '''BIOSF_CLEARFIX''' ($C004C2) and '''BIOSF_CLEARSPR''' ($C004C8) can be used to clear [[sprites]] and the [[fix layer]].
Clearing fix: make a BIOS call too.


Don't forget to kick the [[watchdog]] regularly in your init code if the VBL interrupt isn't enabled or doesn't kick it itself.
Don't forget to kick the [[watchdog]] regularly in your init code if the VBL interrupt isn't enabled or doesn't kick it itself.


[[Category:CPUs]]
[[Category:Base system]]
[[Category:Code]]
[[Category:Code]]

Latest revision as of 23:37, 5 April 2012

Basic init code

The initial PC value in the 68k binary must be $C00402 (Init BIOS call), the initial SP value must be $10F300 (end of the user RAM).

The entrypoints for the 68k code start at $000122. See 68k program header.

    lea     $10F300, sp
    lea     $10F300, a7       ; Depends on assemblers
    move.b  d0,REG_DIPSW      ; Kick watchdog
    move.w  #7,REG_IRQACK     ; Acknowledge any pending interrupts
    move.w  #$2700,sr         ; Disable all interrupts

See 68k interrupts and Watchdog for more informations.

Clearing the 68k user RAM:

    lea     RAMSTART,a0
    move.l  #($F300/4)-1,d0   ; User RAM's size is $F300, and we clear longwords (4 bytes)
clram:
    clr.l   (a0)+
    dbra    d0,clram

Note that this function also clears the stack. Don't make a subroutine out of it unless you're sure that the return address won't be cleared.

BIOS calls BIOSF_CLEARFIX ($C004C2) and BIOSF_CLEARSPR ($C004C8) can be used to clear sprites and the fix layer.

Don't forget to kick the watchdog regularly in your init code if the VBL interrupt isn't enabled or doesn't kick it itself.