; UNASM 1.0 - hERMOL/CPCRULEZ
;
xxxxxxxxxxxxxxxx
	x

	nolist
	org &8FD0


	    ld      bc,RSXTABLE
	    ld      hl,loc_8FD9
	    jp      &0BCD1



loc_8FD9:   db    &0
	    db    &0
	    db    &0
	    db    &0
RSXTABLE:   dw RSXNAME

	    jp      loc_90BA
	    jp      loc_90D4
	    jp      loc_90F1
	    jp      loc_9151
	    jp      loc_916D

RSXNAME:	 db 'DECGU',&0CE
		 db 'GUNFLAS',&0C8
		 db 'INPUTGU',&0CE
		 db 'INGU',&0CE
		 db 'GTRI',&0C7
		 db &0


txt_aNotEnough:  db 'Not enough parameters',&0A,&0D,&7,0
txt_aTooMuC:     db 'Too much parameters',&0A,&0D,&7,0


byte_903F:  db   &54,&44,&55,&5C,&58,&5D,&4C,&45,&4D,&56,&46
	    db   &57,&5E,&40,&5F,&4E,&47,&4F,&52,&42,&53,&5A
	    db   &59,&5B,&4A,&43,&4B


word_905A:      dw   &0
byte_905C:      db   &0
word_905D:      dw   &4B




loc_905F:   ld      a,(hl)
	    or      a
	    ret      z
	    call      &0BB5A
	    inc      hl
	    jr      loc_905F



loc_9068:   di
	    ld      bc,&0F40E
	    out      (c),c
	    ld      b,&0F6
	    in      a,(c)
	    and      &30
	    ld      c,a
	    or      &0C0
	    out      (c),a
	    out      (c),c
	    inc      b
	    ld      a,&92
	    out      (c),a
	    push      bc
	    set      &6,c
	    ld      a,c
	    or      &8
	    ld      c,a
	    dec      b
	    out      (c),c
	    ld      b,&0F4
	    in      a,(c)
	    ld      e,&1
	    bit      &2,a
	    jr      z,loc_9099
	    bit      &5,a
	    jr      z,loc_9099
	    dec      e

loc_9099:   pop      bc
	    ld      a,&82
	    out      (c),a
	    dec      b
	    out      (c),c
	    ei
	    ld      a,e
	    ret



loc_90A4:   cp      b
	    ret      z
	    jr      c,loc_90B1
	    ld      hl,txt_aTooMuC ; "Too much parameters"
	    call      loc_905F
	    ld      a,&0FF
	    ret


loc_90B1:   ld      hl,txt_aNotEnough ; "Not enough parameters"
	    call      loc_905F
	    ld      a,&0FF
	    ret

loc_90BA:   ld      b,&2
	    call      loc_90A4
	    inc      a
	    ret      z
	    ld      a,(ix+&0)
	    ld      (word_905A+&1),a
	    ld      a,(ix+&1)
	    ld      (byte_905C),a
	    ld      a,(ix+&2)
	    ld      (word_905A),a
	    ret


loc_90D4:   ld      b,&1
	    call      loc_90A4
	    inc      a
	    ret      z
	    ld      a,(ix+&0)
	    cp      &1A
	    jr      c,loc_90E4
	    ld      a,&1A

loc_90E4:   ld      hl,byte_903F
	    add      a,l
	    ld      l,a
	    jr      nc,loc_90EC
	    inc      h

loc_90EC:   ld      a,(hl)
	    ld      (word_905D),a
	    ret


loc_90F1:   ld      b,&2
	    call      loc_90A4
	    inc      a
	    ret      z

loc_90F8:   call      loc_9068
	    and      a
	    jr      z,loc_90F8

loc_90FE:   call      loc_9068
	    and      a
	    jr      nz,loc_90FE
	    call      &0BD19
	    call      &0BD19
	    call      &0BD19
	    call      &0BD19
	    push      ix
	    call      loc_94C0
	    ld      a,l
	    inc      a
	    jr      nz,loc_9139
	    call      loc_94C0

loc_911C:   ld      a,l
	    inc      a
	    jr      nz,loc_9139
	    pop      ix
	    ld      h,(ix+&1)
	    ld      l,(ix+&0)
	    ld      (hl),&0FF
	    inc      hl
	    ld      (hl),&0FF
	    ld      h,(ix+&3)
	    ld      l,(ix+&2)
	    ld      (hl),&0FF
	    inc      hl
	    ld      (hl),&0FF
	    ret


loc_9139:   ex      de,hl
	    pop      ix
	    ld      h,(ix+&1)
	    ld      l,(ix+&0)
	    ld      (hl),d
	    inc      hl
	    ld      (hl),&0
	    ld      h,(ix+&3)
	    ld      l,(ix+&2)
	    ld      (hl),e
	    inc      hl
	    ld      (hl),&0
	    ret


loc_9151:   ld      b,&2
	    call      loc_90A4
	    inc      a
	    ret      z
	    di
	    ld      iy,loc_94BC
	    ld      (iy+&0),&0
	    push      ix
	    call      loc_9216
	    call      loc_94C3
	    jp      loc_911C

	    db   &0C9


loc_916D:   ld      b,&1
	    call      loc_90A4
	    inc      a
	    ret      z
	    call      loc_9068
	    ld      h,(ix+&1)
	    ld      l,(ix+&0)
	    ld      (hl),a
	    inc      hl
	    ld      (hl),&0
	    ret

	    jp      loc_94C0

loc_9185:   db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
loc_918B:   db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
loc_9191:   db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
loc_9197:   db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db    &0
	    db   &3A
	    db    &1
	    db    &0
	    db   &0A7
	    db   &0C8
	    db   &0FE
	    db    &2
	    db   &0D8




loc_91AB:   di
	    ld      bc,&0F40E
	    out      (c),c
	    ld      b,&0F6
	    in      a,(c)
	    and      &30
	    ld      c,a
	    or      &0C0
	    out      (c),a
	    out      (c),c
	    inc      b
	    ld      a,&92
	    out      (c),a
	    push      bc
	    set      &6,c
	    ld      a,c
	    or      &9
	    ld      c,a
	    dec      b
	    out      (c),c
	    ld      b,&0F4
	    in      a,(c)
	    bit      &5,a
	    jp      nz,loc_91E6
	    ld      b,&0FF
	    ld      (word_94BE),bc
	    pop      bc
	    ld      a,&82
	    out      (c),a
	    dec      b
	    out      (c),c
	    ei
	    ret


loc_91E6:   pop      bc
	    ld      a,&82
	    out      (c),a
	    dec      b
	    out      (c),c
	    xor      a
	    ld      (&1),a
	    ld      iy,loc_94BC
	    ld      (iy+&0),a
	    ld      b,&0F5

loc_91FB:   in      a,(c)
	    rra
	    jr      nc,loc_91FB
	    ld      bc,(word_905D)
	    ld      b,&7F
	    xor      a

loc_9207:   out      (c),a
	    out      (c),c
	    inc      a
	    cp      &10
	    jr      nz,loc_9207
	    ld      a,&10
	    out      (c),a
	    out      (c),c

loc_9216:   xor      a
	    ld      (word_94BE),a
	    ld      (word_94BE+&1),a
	    ld      (byte_94BD),a
	    ld      a,(&38)
	    ld      (byte_94B7),a
	    ld      hl,(&39)
	    ld      (word_94B8),hl
	    ld      a,&0C3
	    ld      (&38),a
	    ld      hl,func_int38
	    ld      (&39),hl

loc_9237:   di
	    ld      bc,&0F40E
	    out      (c),c
	    ld      b,&0F6
	    in      a,(c)
	    and      &30
	    ld      c,a
	    or      &0C0
	    out      (c),a
	    out      (c),c
	    inc      b
	    ld      a,&92
	    out      (c),a
	    push      bc
	    set      &6,c
	    ld      a,c
	    or      &9
	    ld      c,a
	    ld      b,&0F6
	    out      (c),c
	    ld      b,&0F4
	    ei

loc_925D:   in      a,(c)
	    rrca
	    jp      nc,loc_925D

loc_9263:   in      a,(c)
	    rrca
	    jr      c,loc_9263
	    ld      d,&7

loc_926A:   dec      d
	    jr      nz,loc_926A
	    in      c,(c)
	    in      a,(c)
	    in      l,(c)
	    in      h,(c)
	    in      e,(c)
	    in      d,(c)
	    ld      ix,loc_9185
	    ld      (ix+&0),c
	    ld      (ix+&1),a
	    ld      (ix+&2),l
	    ld      (ix+&3),h
	    ld      (ix+&4),e
	    ld      (ix+&5),d
	    ld      de,&6
	    add      ix,de
	    nop
	    nop
	    in      c,(c)
	    in      a,(c)
	    in      l,(c)
	    in      h,(c)
	    in      e,(c)
	    in      d,(c)
	    ld      (ix+&0),c
	    ld      (ix+&1),a
	    ld      (ix+&2),l
	    ld      (ix+&3),h
	    ld      (ix+&4),e
	    ld      (ix+&5),d
	    ld      de,&6
	    add      ix,de
	    inc      de
	    nop
	    nop
	    nop
	    in      c,(c)
	    in      a,(c)
	    in      l,(c)
	    in      h,(c)
	    in      e,(c)
	    in      d,(c)
	    ld      (ix+&0),c
	    ld      (ix+&1),a
	    ld      (ix+&2),l
	    ld      (ix+&3),h
	    ld      (ix+&4),e
	    ld      (ix+&5),d
	    ld      de,&6
	    add      ix,de
	    in      c,(c)
	    in      a,(c)
	    in      l,(c)
	    in      h,(c)
	    in      e,(c)
	    in      d,(c)
	    ld      (ix+&0),c
	    ld      (ix+&1),a
	    ld      (ix+&2),l
	    ld      (ix+&3),h
	    ld      (ix+&4),e
	    ld      (ix+&5),d
	    nop
	    nop
	    in      c,(c)
	    in      a,(c)
	    in      l,(c)
	    in      h,(c)
	    in      e,(c)
	    in      d,(c)
	    ld      (ix+&6),c
	    ld      (ix+&7),a
	    ld      (ix+&8),l
	    ld      (ix+&9),h
	    ld      (ix+&0A),e
	    ld      (ix+&0B),d
	    ld      d,&0
	    ld      e,&0

loc_9322:   ld      b,&0
	    ld      c,&0

loc_9326:   inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      c
	    inc      b
	    jp      nz,loc_9326
	    ld      b,&0FF
	    ld      e,&0

func_int38: ex      (sp),hl
	    ld      (word_94BA),hl
	    ex      (sp),hl
	    push      af
	    push      bc
	    push      de
	    push      hl
	    inc      (iy+&0)
	    ld      a,(iy+&0)
	    cp      &7
	    jr      z,loc_9496
	    ld      hl,(word_94BA)
	    ld      bc,loc_9322
	    sbc      hl,bc
	    jr      nc,loc_945C
	    pop      hl
	    pop      de
	    pop      bc
	    pop      af
	    pop      af
	    di
	    pop      bc
	    ld      a,&82
	    out      (c),a
	    dec      b
	    out      (c),c
	    jp      loc_9237


loc_945C:   ld      a,d
	    and      a
	    jr      z,loc_9467
	    pop      hl
	    pop      de
	    pop      bc
	    pop      af
	    inc      e
	    ei
	    ret


loc_9467:   pop      hl
	    pop      de
	    pop      bc
	    ld      (word_94BE),bc
	    pop      af
	    pop      af
	    ld      de,&101
	    ld      b,&0F5
	    ei

loc_9476:   in      a,(c)
	    rra
	    jr      nc,loc_9476
	    di
	    ld      a,e
	    ld      (byte_94BD),a
	    pop      bc
	    ld      a,&82
	    out      (c),a
	    dec      b
	    out      (c),c
	    ld      a,(byte_94B7)
	    ld      (&38),a
	    ld      hl,(word_94B8)
	    ld      (&39),hl
	    ei
	    ret


loc_9496:   pop      hl
	    pop      de
	    pop      bc
	    pop      af
	    pop      af
	    ld      b,&0FF
	    ld      (word_94BE),bc
	    pop      bc
	    ld      a,&82
	    out      (c),a
	    dec      b
	    out      (c),c
	    ld      a,(byte_94B7)
	    ld      (&38),a
	    ld      hl,(word_94B8)
	    ld      (&39),hl
	    ei
	    ret

byte_94B7:      db   &0
word_94B8:      dw   &0
word_94BA:      dw   &0
loc_94BC:       db   &0
byte_94BD:      db   &0
word_94BE:      dw   &0




loc_94C0:   call      loc_91AB

loc_94C3:   ld      a,(word_94BE+&1)
	    inc      a
	    jp      z,loc_95BA
	    ld      hl,loc_9185
	    ld      b,&6

loc_94CF:   ld      a,(hl)
	    and      &1
	    jr      z,loc_94D7
	    inc      hl
	    djnz      loc_94CF

loc_94D7:   ld      a,&6
	    sub      b
	    jr      nz,loc_94DE
	    ld      a,&7

loc_94DE:   push      af
	    ld      hl,loc_918B
	    ld      b,&6

loc_94E4:   ld      a,(hl)
	    and      &1
	    jr      z,loc_94EC
	    inc      hl
	    djnz      loc_94E4

loc_94EC:   ld      a,&6
	    sub      b
	    push      af
	    ld      hl,loc_9191
	    ld      b,&6

loc_94F5:   ld      a,(hl)
	    and      &1
	    jr      z,loc_94FD
	    inc      hl
	    djnz      loc_94F5

loc_94FD:   ld      a,&6
	    sub      b
	    push      af
	    ld      hl,loc_9197
	    ld      b,&6

loc_9506:   ld      a,(hl)
	    and      &1
	    jr      z,loc_950E
	    inc      hl
	    djnz      loc_9506

loc_950E:   ld      a,&6
	    sub      b
	    pop      bc
	    add      a,b
	    pop      bc
	    add      a,b
	    pop      bc
	    add      a,b
	    add      a,&0C
	    push      af
	    ld      hl,(word_94BE)
	    add      hl,hl
	    add      hl,hl
	    push      hl
	    ld      a,(word_94BE+&1)
	    add      a,a
	    ld      l,a
	    ld      h,&0
	    push      hl
	    add      hl,hl
	    push      hl
	    add      hl,hl
	    pop      de
	    add      hl,de
	    pop      de
	    add      hl,de
	    pop      de
	    add      hl,de
	    srl      h
	    rr      l
	    srl      h
	    rr      l
	    pop      de
	    ld      e,d
	    ld      d,&0
	    and      a
	    sbc      hl,de
	    add      hl,hl
	    add      hl,hl
	    add      hl,hl
	    ld      de,&1FF
	    call      loc_95BF
	    push      de
	    ld      a,(byte_94BD)
	    cp      &1
	    jr      nz,loc_9557
	    ld      de,&0C0
	    jp      loc_956E


loc_9557:   cp      &2
	    jr      nz,loc_9561
	    ld      de,&98
	    jp      loc_956E


loc_9561:   cp      &3
	    jr      nz,loc_956B
	    ld      de,&60
	    jp      loc_956E


loc_956B:   ld      de,&30

loc_956E:   ex      de,hl
	    and      a
	    sbc      hl,de
	    pop      de
	    push      hl
	    ld      hl,&1FE
	    and      a
	    sbc      hl,de
	    srl      h
	    rr      l
	    ld      a,l
	    srl      a
	    sub      &0B
	    ld      bc,(word_905A)
	    sub      c
	    jp      p,loc_958C
	    xor      a

loc_958C:   cp      &50
	    jr      c,loc_9592
	    ld      a,&4F

loc_9592:   pop      hl

loc_9593:   ld      de,(word_905A+&1)
	    and      a
	    sbc      hl,de
	    jp      p,loc_95A0
	    ld      hl,&0

loc_95A0:   ld      de,&0C7
	    and      a
	    sbc      hl,de
	    jp      m,loc_95AF
	    ld      de,&0
	    ld      hl,&0C7

loc_95AF:   add      hl,de
	    ld      h,l
	    ld      l,a
	    ld      b,&0FF
	    ld      (word_94BE),bc
	    ei
	    ret


loc_95BA:   ld      a,&0FF
	    jp      loc_9593


loc_95BF:   ex      de,hl
	    push      hl
	    pop      bc
	    ld      a,&10
	    ld      hl,&0
	    and      a
	    jp      loc_95D7


loc_95CB:   and      a
	    sbc      hl,bc
	    jp      p,loc_95D6
	    add      hl,bc
	    and      a
	    jp      loc_95D7


loc_95D6:   scf

loc_95D7:   rl      e
	    rl      d
	    rl      l
	    rl      h
	    dec      a
	    jp      p,loc_95CB
            ex      de,hl
	    srl      d
	    rr      e
	    ret
