]> git.sur5r.net Git - cc65/blobdiff - libsrc/pce/crt0.s
Fixed bugs; and, improved the efficiency of some pce library functions.
[cc65] / libsrc / pce / crt0.s
index c9a8e8c8f19fa77f550d45f5b52d13c426d462f0..d6dee3ef42d8d3f4296f7c18626b6d67a99ff476 100644 (file)
@@ -1,18 +1,19 @@
 ;
-; Startup code for cc65 (PCEngine version)
+; Start-up code for cc65 (PC-Engine version)
 ;
-; by Groepaz/Hitmen <groepaz@gmx.net>
+; by Groepaz/Hitmen <groepaz@gmx.net>,
 ; based on code by Ullrich von Bassewitz <uz@cc65.org>
 ;
-; 2018-02-11, Greg King
+; 2018-02-24, Greg King
 ;
 
         .export         _exit
-        .export         __STARTUP__ : absolute = 1      ; Mark as startup
+        .export         __STARTUP__ : absolute = 1      ; Mark as start-up
 
         .import         initlib, donelib
         .import         push0, _main
-        .import         IRQStub
+        .import         IRQStub, __nmi
+        .importzp       sp
 
         ; Linker-generated
         .import         __CARTSIZE__
         .include        "pce.inc"
         .include        "extzp.inc"
 
-        .importzp       sp
-
 ; ------------------------------------------------------------------------
-; Place the startup code in a special segment.
-
-        .segment "STARTUP"
+; Place the start-up code in a special segment.
 
-start:
+.segment        "STARTUP"
 
-        ; Set up the CPU and System-IRQ
-
-        ; Initialize CPU
-        sei
-        nop
-        csh                     ; Set high speed CPU mode
+        ; Initialize the CPU.
+start:  sei
         nop
+        csh                     ; Set high-speed CPU mode
         nop
 
-        ; Set up stack and memory mapping
+        ; Set up the stack and the memory mapping.
         ldx     #$FF            ; Stack top ($21FF)
         txs
 
@@ -65,21 +59,22 @@ start:
         inc     a
 @L1:    tam     #%01000000      ; $C000-$DFFF = ROM bank 3 (32K) or 1 (16K)
         ;lda    #$00            ; (The reset default)
-        ;tam    #%10000000      ; $E000-$FFFF  hucard/syscard bank 0
+        ;tam    #%10000000      ; $E000-$FFFF  Hucard/Syscard bank 0
 
-        ; Initialize hardware
+        ; Initialize the hardware.
         stz     TIMER_CTRL      ; Timer off
-        lda     #$07
+        lda     #%00000111
         sta     IRQ_MASK        ; Interrupts off
-        stz     IRQ_STATUS      ; Acknowledge timer
 
-        ; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/
+        ; FIXME; I don't know why the heck this one doesn't work when called from a constructor. -Groepaz :-/
+.if 0   ; It now seems to work (at least, in Mednafen). -Greg King
         .import vdc_init
         jsr     vdc_init
+.endif
 
-        ; Turn on background and VD interrupt/IRQ1
-        lda     #$05
-        sta     IRQ_MASK        ; IRQ1=on
+        ; Allow interrupts from the VDC.
+        lda     #%00000101
+        sta     IRQ_MASK        ; IRQ1 = on
 
         ; Copy the .data segment to RAM
         tii     __DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__
@@ -92,30 +87,27 @@ start:
         lda     #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
         ldx     #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
         sta     sp
-        stx     sp + 1
+        stx     sp+1
 
-        ; Call module constructors
+        ; Call the module constructors.
         jsr     initlib
 
-        cli     ; allow IRQ only after constructors have run
+        stz     IRQ_STATUS      ; Clear IRQs
+        cli                     ; Allow IRQ only after constructors have run
 
         ; Pass an empty command line
         jsr     push0           ; argc
         jsr     push0           ; argv
 
         ldy     #4              ; Argument size
-        jsr     _main           ; Call the users code
+        jsr     _main           ; Call the user's code
 
-        ; Call module destructors. This is also the _exit entry.
-_exit:
-        jsr     donelib         ; Run module destructors
+        ; Call the module destructors. This is also the exit() entry.
+_exit:  jsr     donelib
 
-        ; reset the PCEngine (start over)
+        ; Reset the PCEngine (start over).
         jmp     start
 
-_nmi:
-        rti
-
         .export initmainargs
 initmainargs:
         rts
@@ -123,10 +115,10 @@ initmainargs:
 ; ------------------------------------------------------------------------
 ; hardware vectors
 ; ------------------------------------------------------------------------
-        .segment "VECTORS"
+.segment        "VECTORS"
 
-        .word   IRQStub         ; $fff6 IRQ2 (External IRQ, BRK)
-        .word   IRQStub         ; $fff8 IRQ1 (VDC)
-        .word   IRQStub         ; $fffa Timer
-        .word   _nmi            ; $fffc NMI
-        .word   start           ; $fffe reset
+        .word   IRQStub         ; $FFF6 IRQ2 (External IRQ, BRK)
+        .word   IRQStub         ; $FFF8 IRQ1 (VDC)
+        .word   IRQStub         ; $FFFA Timer
+        .word   __nmi           ; $FFFC NMI
+        .word   start           ; $FFFE reset