Fixed up support for the gbz80 such that it will at least run (and fail badly) the...
[fw/sdcc] / device / lib / z80 / crt0.s
index c05ae1d18d31d2a1e1cf98556c0a9f7ec2eebc17..d5d68dd829064e767967eeb7c43a0b0cffb97bfb 100644 (file)
@@ -45,16 +45,6 @@ __clock::
         rst     0x08
        ret
        
-_getsp::
-       ld      hl,#0
-       add     hl,sp
-       ret
-
-__printTStates::       
-       ld      a,#3
-       out     (0xff),a
-       ret
-
 _exit::
        ;; Exit - special code to the emulator
        ld      a,#0
@@ -63,6 +53,57 @@ _exit::
        halt
        jr      1$
 
+        ;; Special RLE decoder used for initing global data
+__initrleblock::
+        ;; Pop the return address
+        pop     hl
+        ;; Save registers
+        push    bc
+        push    de
+
+        ;; Pull the destination address out
+        ld      c,(hl)
+        inc     hl
+        ld      b,(hl)
+        inc     hl
+1$:
+        ;; Fetch the run
+        ld      e,(hl)
+        inc     hl
+        ;; Negative means a run
+        bit     7,e
+        jp      z,2$
+        ;; Code for expanding a run
+        ld      a,(hl)
+        inc     hl
+3$:
+        ld      (bc),a
+        inc     bc
+        inc     e
+        jp      nz,3$
+        jp      1$
+2$:
+        ;; Zero means end of a block
+        xor     a
+        or      e
+        jp      z,4$
+        ;; Code for expanding a block
+5$:     
+        ld      a,(hl)        
+        inc     hl
+        ld      (bc),a
+        inc     bc
+        dec     e
+        jp      nz,5$
+        jp      1$
+4$:     
+        pop     de
+        pop     bc
+
+        ;; Push the return address back onto the stack
+        push    hl
+        ret
+
         .area   _GSINIT
 gsinit::