	org 105
__START_PROGRAM:
	di
	push ix
	push iy
	exx
	push hl
	exx
	ld hl, 0
	add hl, sp
	ld (__CALL_BACK__), hl
	ei
#line 0
		ld sp,$E7FF
#line 1
	ld hl, 0
	ld (_seed), hl
	ld hl, 0
	push hl
	ld a, 16
	push af
	ld a, 23
	push af
	call _thelegendofkagescrolldeprecated
	ld hl, 0
	ld (_eee), hl
	jp __LABEL0
__LABEL3:
	ld de, 15
	ld hl, (_eee)
	call __BAND16
	ld de, 273
	call __MUL16_FAST
	push hl
	ld hl, (_eee)
	push hl
	call _thelegendofkagepalette
__LABEL4:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL0:
	ld hl, 1023
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL3
__LABEL2:
	ld hl, 3204
	push hl
	ld hl, 274
	push hl
	call _thelegendofkagepalette
	ld hl, 1808
	push hl
	ld hl, 272
	push hl
	call _thelegendofkagepalette
	ld hl, 0
	ld (_ee2), hl
	jp __LABEL5
__LABEL8:
	ld hl, 0
	ld (_ee3), hl
	jp __LABEL10
__LABEL13:
	ld hl, 0
	push hl
	ld a, 46
	push af
	ld hl, (_ee2)
	push hl
	ld hl, (_ee3)
	push hl
	call _thelegendofkageputchar
__LABEL14:
	ld hl, (_ee3)
	inc hl
	ld (_ee3), hl
__LABEL10:
	ld hl, 31
	ld de, (_ee3)
	or a
	sbc hl, de
	jp nc, __LABEL13
__LABEL12:
__LABEL9:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL5:
	ld hl, 31
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL8
__LABEL7:
	ld hl, 0
	ld (_ee2), hl
	jp __LABEL15
__LABEL18:
	ld hl, 0
	ld (_ee3), hl
	jp __LABEL20
__LABEL23:
	ld hl, 0
	push hl
	ld hl, (_ee2)
	ld de, 16
	call __MUL16_FAST
	ex de, hl
	ld hl, (_ee3)
	add hl, de
	ld a, l
	push af
	ld hl, (_ee2)
	ld de, 10
	add hl, de
	push hl
	ld hl, (_ee3)
	ld de, 12
	add hl, de
	push hl
	call _thelegendofkageputchar
__LABEL24:
	ld hl, (_ee3)
	inc hl
	ld (_ee3), hl
__LABEL20:
	ld hl, 15
	ld de, (_ee3)
	or a
	sbc hl, de
	jp nc, __LABEL23
__LABEL22:
__LABEL19:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL15:
	ld hl, 15
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL18
__LABEL17:
	ld hl, 61696
	ld (_ee2), hl
	jp __LABEL25
__LABEL28:
	ld hl, (_seed)
	call _smsrnd
	ld (_seed), hl
	ld a, l
	ld hl, (_ee2)
	ld (hl), a
__LABEL29:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL25:
	ld hl, 61791
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL28
__LABEL27:
	ld hl, 5
	ld (_ex0), hl
	ld hl, 5
	ld (_ey0), hl
	ld hl, 0
	ld (_eee), hl
__LABEL30:
	ld a, (61572)
	cpl
	ld l, a
	ld h, 0
	ld (_ej0), hl
	ld a, (61574)
	cpl
	ld l, a
	ld h, 0
	ld (_ej1), hl
	ld hl, 0
	push hl
	ld hl, (_ej0)
	ld de, 10
	call __MODU16
	ld de, 48
	add hl, de
	ld a, l
	push af
	ld hl, 25
	push hl
	ld hl, 8
	push hl
	call _thelegendofkageputchar
	ld hl, 0
	push hl
	ld hl, (_ej0)
	ld de, 10
	call __DIVU16
	ld de, 0
	push de
	push hl
	ld de, 0
	ld hl, 10
	call __SWAP32
	call __MODI32
	ld bc, 0
	push bc
	ld bc, 48
	push bc
	pop bc
	add hl, bc
	ex de, hl
	pop bc
	adc hl, bc
	ex de, hl
	ld a, l
	push af
	ld hl, 25
	push hl
	ld hl, 7
	push hl
	call _thelegendofkageputchar
	ld hl, 0
	push hl
	ld hl, (_ej0)
	ld de, 100
	call __DIVU16
	ld de, 0
	push de
	push hl
	ld de, 0
	ld hl, 10
	call __SWAP32
	call __MODI32
	ld bc, 0
	push bc
	ld bc, 48
	push bc
	pop bc
	add hl, bc
	ex de, hl
	pop bc
	adc hl, bc
	ex de, hl
	ld a, l
	push af
	ld hl, 25
	push hl
	ld hl, 6
	push hl
	call _thelegendofkageputchar
	ld hl, 0
	push hl
	ld hl, (_ej1)
	ld de, 10
	call __MODU16
	ld de, 48
	add hl, de
	ld a, l
	push af
	ld hl, 26
	push hl
	ld hl, 8
	push hl
	call _thelegendofkageputchar
	ld hl, 0
	push hl
	ld hl, (_ej1)
	ld de, 10
	call __DIVU16
	ld de, 0
	push de
	push hl
	ld de, 0
	ld hl, 10
	call __SWAP32
	call __MODI32
	ld bc, 0
	push bc
	ld bc, 48
	push bc
	pop bc
	add hl, bc
	ex de, hl
	pop bc
	adc hl, bc
	ex de, hl
	ld a, l
	push af
	ld hl, 26
	push hl
	ld hl, 7
	push hl
	call _thelegendofkageputchar
	ld hl, 0
	push hl
	ld hl, (_ej1)
	ld de, 100
	call __DIVU16
	ld de, 0
	push de
	push hl
	ld de, 0
	ld hl, 10
	call __SWAP32
	call __MODI32
	ld bc, 0
	push bc
	ld bc, 48
	push bc
	pop bc
	add hl, bc
	ex de, hl
	pop bc
	adc hl, bc
	ex de, hl
	ld a, l
	push af
	ld hl, 26
	push hl
	ld hl, 6
	push hl
	call _thelegendofkageputchar
	ld de, 4
	ld hl, (_ej0)
	call __BAND16
	ld de, 4
	call __DIVU16
	ex de, hl
	ld hl, (_ex0)
	or a
	sbc hl, de
	push hl
	ld de, 8
	ld hl, (_ej0)
	call __BAND16
	ld de, 8
	call __DIVU16
	ex de, hl
	pop hl
	add hl, de
	ld (_ex0), hl
	ld de, 16
	ld hl, (_ej0)
	call __BAND16
	ld de, 16
	call __DIVU16
	ex de, hl
	ld hl, (_ey0)
	add hl, de
	push hl
	ld de, 32
	ld hl, (_ej0)
	call __BAND16
	ld de, 32
	call __DIVU16
	ex de, hl
	pop hl
	or a
	sbc hl, de
	ld (_ey0), hl
	ld hl, 0
	push hl
	ld hl, (_eee)
	ld a, l
	push af
	ld de, 31
	ld hl, (_ey0)
	call __BAND16
	push hl
	ld de, 31
	ld hl, (_ex0)
	call __BAND16
	push hl
	call _thelegendofkageputchar
	ld hl, 1
	ld (_ee2), hl
	jp __LABEL32
__LABEL35:
__LABEL36:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL32:
	ld hl, 1000
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL35
__LABEL34:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
	jp __LABEL30
__LABEL31:
__LABEL37:
	jp __LABEL37
__LABEL38:
	ld hl, 59392
	ld (_eee), hl
	jp __LABEL39
__LABEL42:
	ld hl, (_eee)
	ex de, hl
	ld hl, (_eee)
	ld (hl), e
	inc hl
	ld (hl), d
__LABEL43:
	ld hl, (_eee)
	inc hl
	inc hl
	ld (_eee), hl
__LABEL39:
	ld hl, 61439
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL42
__LABEL41:
	ld hl, 3204
	ld (59392), hl
	ld hl, 3840
	ld (59394), hl
	ld hl, 240
	ld (59400), hl
	ld hl, 15
	ld (59408), hl
	ld hl, 15
	ld (59416), hl
	ld hl, 15
	ld (59424), hl
	ld hl, 15
	ld (59432), hl
	ld hl, 15
	ld (59456), hl
	ld hl, 15
	ld (59520), hl
	ld hl, 15
	ld (59648), hl
	ld hl, 15
	ld (59904), hl
	ld hl, 15
	ld (60160), hl
	ld hl, 15
	ld (60416), hl
	ld hl, 15
	ld (60672), hl
	ld hl, 15
	ld (60928), hl
	ld hl, 15
	ld (61184), hl
	ld hl, 0
	ld (_eee), hl
	jp __LABEL44
__LABEL47:
	ld hl, (_eee)
	add hl, hl
	ld de, 59392
	add hl, de
	push hl
	ld de, 15
	ld hl, (_eee)
	call __BAND16
	ld de, 273
	call __MUL16_FAST
	ex de, hl
	pop hl
	ld (hl), e
	inc hl
	ld (hl), d
__LABEL48:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL44:
	ld hl, 1023
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL47
__LABEL46:
	ld hl, 0
	ld (_eee), hl
	jp __LABEL49
__LABEL52:
	ld hl, (_eee)
	add hl, hl
	ld de, 59424
	add hl, de
	push hl
	ld de, 15
	ld hl, (_eee)
	call __BAND16
	ld de, 272
	call __MUL16_FAST
	ex de, hl
	pop hl
	ld (hl), e
	inc hl
	ld (hl), d
__LABEL53:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL49:
	ld hl, 15
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL52
__LABEL51:
	ld hl, 0
	ld (_eee), hl
	jp __LABEL54
__LABEL57:
	ld hl, (_eee)
	add hl, hl
	ld de, 59456
	add hl, de
	push hl
	ld de, 15
	ld hl, (_eee)
	call __BAND16
	ld de, 257
	call __MUL16_FAST
	ex de, hl
	pop hl
	ld (hl), e
	inc hl
	ld (hl), d
__LABEL58:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL54:
	ld hl, 15
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL57
__LABEL56:
	ld hl, 0
	ld (_eee), hl
	jp __LABEL59
__LABEL62:
	ld hl, (_eee)
	add hl, hl
	ld de, 59488
	add hl, de
	push hl
	ld de, 15
	ld hl, (_eee)
	call __BAND16
	ld de, 17
	call __MUL16_FAST
	ex de, hl
	pop hl
	ld (hl), e
	inc hl
	ld (hl), d
__LABEL63:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL59:
	ld hl, 15
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL62
__LABEL61:
	ld hl, 256
	ld (_eee), hl
	jp __LABEL64
__LABEL67:
	ld hl, (_eee)
	add hl, hl
	ld de, 59392
	add hl, de
	push hl
	ld de, 15
	ld hl, (_eee)
	call __BAND16
	ld de, 256
	call __MUL16_FAST
	ex de, hl
	pop hl
	ld (hl), e
	inc hl
	ld (hl), d
__LABEL68:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL64:
	ld hl, 271
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL67
__LABEL66:
	ld hl, 272
	ld (_eee), hl
	jp __LABEL69
__LABEL72:
	ld hl, (_eee)
	add hl, hl
	ld de, 59392
	add hl, de
	push hl
	ld de, 15
	ld hl, (_eee)
	call __BAND16
	ex de, hl
	pop hl
	ld (hl), e
	inc hl
	ld (hl), d
__LABEL73:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL69:
	ld hl, 287
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL72
__LABEL71:
	ld hl, 288
	ld (_eee), hl
	jp __LABEL74
__LABEL77:
	ld hl, (_eee)
	add hl, hl
	ld de, 59392
	add hl, de
	push hl
	ld de, 15
	ld hl, (_eee)
	call __BAND16
	ld de, 16
	call __MUL16_FAST
	ex de, hl
	pop hl
	ld (hl), e
	inc hl
	ld (hl), d
__LABEL78:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL74:
	ld hl, 511
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL77
__LABEL76:
	ld hl, 3204
	ld (59940), hl
	ld hl, 371
	ld (59936), hl
	ld a, 23
	ld (61632), a
	ld a, 16
	ld (61633), a
	xor a
	ld (61634), a
	xor a
	ld (61635), a
	xor a
	ld (61636), a
	xor a
	ld (61637), a
	ld hl, 62464
	ld (_eee), hl
	jp __LABEL79
__LABEL82:
	ld hl, 1
	ld (_ee2), hl
	jp __LABEL84
__LABEL87:
__LABEL88:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL84:
	ld hl, 200
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL87
__LABEL86:
	ld de, 1023
	ld hl, (_eee)
	call __BXOR16
	push hl
	ld de, 127
	ld hl, (_eee)
	call __BAND16
	ld a, l
	pop hl
	ld (hl), a
__LABEL83:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL79:
	ld hl, 63487
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL82
__LABEL81:
	ld hl, 63488
	ld (_eee), hl
	jp __LABEL89
__LABEL92:
	ld hl, 1
	ld (_ee2), hl
	jp __LABEL94
__LABEL97:
__LABEL98:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL94:
	ld hl, 2000
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL97
__LABEL96:
	ld hl, (_seed)
	call _smsrnd
	ld (_seed), hl
	ld a, l
	ld hl, (_eee)
	ld (hl), a
__LABEL93:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL89:
	ld hl, 64511
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL92
__LABEL91:
	ld hl, 64512
	ld (_eee), hl
	jp __LABEL99
__LABEL102:
	ld hl, 1
	ld (_ee2), hl
	jp __LABEL104
__LABEL107:
__LABEL108:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL104:
	ld hl, 2000
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL107
__LABEL106:
	ld hl, (_seed)
	call _smsrnd
	ld (_seed), hl
	ld a, l
	ld hl, (_eee)
	ld (hl), a
__LABEL103:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL99:
	ld hl, 65535
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL102
__LABEL101:
__LABEL109:
	ld hl, 62464
	ld (_eee), hl
	jp __LABEL111
__LABEL114:
	ld hl, 1
	ld (_ee2), hl
	jp __LABEL116
__LABEL119:
__LABEL120:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL116:
	ld hl, 2000
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL119
__LABEL118:
	ld hl, (_seed)
	call _smsrnd
	ld (_seed), hl
	ld de, 1023
	ld hl, (_eee)
	call __BXOR16
	push hl
	ld hl, (_seed)
	ld a, l
	pop hl
	ld (hl), a
__LABEL115:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL111:
	ld hl, 63487
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL114
__LABEL113:
	ld hl, 63488
	ld (_eee), hl
	jp __LABEL121
__LABEL124:
	ld hl, 1
	ld (_ee2), hl
	jp __LABEL126
__LABEL129:
__LABEL130:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL126:
	ld hl, 10
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL129
__LABEL128:
	ld hl, (_seed)
	call _smsrnd
	ld (_seed), hl
	ld a, l
	ld hl, (_eee)
	ld (hl), a
__LABEL125:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL121:
	ld hl, 64511
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL124
__LABEL123:
	ld hl, 64512
	ld (_eee), hl
	jp __LABEL131
__LABEL134:
	ld hl, 1
	ld (_ee2), hl
	jp __LABEL136
__LABEL139:
__LABEL140:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL136:
	ld hl, 10
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL139
__LABEL138:
	ld hl, (_seed)
	call _smsrnd
	ld (_seed), hl
	ld a, l
	ld hl, (_eee)
	ld (hl), a
__LABEL135:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL131:
	ld hl, 65535
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL134
__LABEL133:
	ld hl, 61696
	ld (_eee), hl
	jp __LABEL141
__LABEL144:
	ld hl, 1
	ld (_ee2), hl
	jp __LABEL146
__LABEL149:
__LABEL150:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL146:
	ld hl, 2
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL149
__LABEL148:
	ld hl, (_seed)
	call _smsrnd
	ld (_seed), hl
	ld a, l
	ld hl, (_eee)
	ld (hl), a
__LABEL145:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL141:
	ld hl, 61791
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL144
__LABEL143:
	ld hl, 61792
	ld (_eee), hl
	jp __LABEL151
__LABEL154:
	ld hl, 1
	ld (_ee2), hl
	jp __LABEL156
__LABEL159:
__LABEL160:
	ld hl, (_ee2)
	inc hl
	ld (_ee2), hl
__LABEL156:
	ld hl, 2
	ld de, (_ee2)
	or a
	sbc hl, de
	jp nc, __LABEL159
__LABEL158:
	ld hl, (_seed)
	call _smsrnd
	ld (_seed), hl
	ld a, l
	ld hl, (_eee)
	ld (hl), a
__LABEL155:
	ld hl, (_eee)
	inc hl
	ld (_eee), hl
__LABEL151:
	ld hl, 16383
	ld de, (_eee)
	or a
	sbc hl, de
	jp nc, __LABEL154
__LABEL153:
	jp __LABEL109
__LABEL110:
	ld hl, 0
	ld b, h
	ld c, l
__END_PROGRAM:
	di
	ld hl, (__CALL_BACK__)
	ld sp, hl
	exx
	pop hl
	exx
	pop iy
	pop ix
	ei
	ret
__CALL_BACK__:
	DEFW 0
_smsrnd:
#line 2
		ld  d, h
		ld  e, l
		ld  a, d
		ld  h, e
		ld  l, 253
		or  a
		sbc  hl, de
		sbc  a, 0
		sbc  hl, de
		ld  d, 0
		sbc  a, d
		ld  e, a
		sbc  hl, de
		jr  nc, smsrndloop
		inc  hl
smsrndloop:
		ret
#line 19
_smsrnd__leave:
	ret
_thelegendofkageputchar:
	push ix
	ld ix, 0
	add ix, sp
	ld l, (ix+10)
	ld h, (ix+11)
	ld de, 3
	call __MODU16
	ld de, 1024
	call __MUL16_FAST
	ld de, 62464
	add hl, de
	push hl
	ld l, (ix+4)
	ld h, (ix+5)
	push hl
	ld l, (ix+6)
	ld h, (ix+7)
	ld de, 32
	call __MUL16_FAST
	ex de, hl
	pop hl
	add hl, de
	push hl
	ld de, 1023
	pop hl
	call __BXOR16
	ex de, hl
	pop hl
	add hl, de
	push hl
	ld a, (ix+9)
	pop hl
	ld (hl), a
_thelegendofkageputchar__leave:
	ld sp, ix
	pop ix
	exx
	pop hl
	pop bc
	pop bc
	pop bc
	ex (sp), hl
	exx
	ret
_thelegendofkagepalette:
	push ix
	ld ix, 0
	add ix, sp
	ld l, (ix+4)
	ld h, (ix+5)
	add hl, hl
	ld de, 59392
	add hl, de
	push hl
	ld l, (ix+6)
	ld h, (ix+7)
	ex de, hl
	pop hl
	ld (hl), e
	inc hl
	ld (hl), d
_thelegendofkagepalette__leave:
	ld sp, ix
	pop ix
	exx
	pop hl
	pop bc
	ex (sp), hl
	exx
	ret
_thelegendofkagescrolldeprecated:
	push ix
	ld ix, 0
	add ix, sp
	ld l, (ix+8)
	ld h, (ix+9)
	add hl, hl
	ld de, 61632
	add hl, de
	push hl
	ld a, (ix+5)
	pop hl
	ld (hl), a
	ld l, (ix+8)
	ld h, (ix+9)
	add hl, hl
	ld de, 61633
	add hl, de
	push hl
	ld a, (ix+7)
	pop hl
	ld (hl), a
_thelegendofkagescrolldeprecated__leave:
	ld sp, ix
	pop ix
	exx
	pop hl
	pop bc
	pop bc
	ex (sp), hl
	exx
	ret
_thelegendofkageputspritedeprecated:
	push ix
	ld ix, 0
	add ix, sp
	ld l, (ix+4)
	ld h, (ix+5)
	add hl, hl
	add hl, hl
	ld de, 61696
	add hl, de
	push hl
	ld a, (ix+7)
	pop hl
	ld (hl), a
	ld l, (ix+4)
	ld h, (ix+5)
	add hl, hl
	add hl, hl
	ld de, 61697
	add hl, de
	push hl
	ld a, (ix+9)
	pop hl
	ld (hl), a
	ld l, (ix+4)
	ld h, (ix+5)
	add hl, hl
	add hl, hl
	ld de, 61698
	add hl, de
	push hl
	ld a, (ix+11)
	pop hl
	ld (hl), a
	ld l, (ix+4)
	ld h, (ix+5)
	add hl, hl
	add hl, hl
	ld de, 61699
	add hl, de
	push hl
	ld a, (ix+13)
	pop hl
	ld (hl), a
_thelegendofkageputspritedeprecated__leave:
	ld sp, ix
	pop ix
	exx
	pop hl
	pop bc
	pop bc
	pop bc
	pop bc
	ex (sp), hl
	exx
	ret
#line 1 "mul16.asm"
__MUL16:	; Mutiplies HL with the last value stored into de stack
				; Works for both signed and unsigned
	
			PROC
	
			LOCAL __MUL16LOOP
	        LOCAL __MUL16NOADD
			
			ex de, hl
			pop hl		; Return address
			ex (sp), hl ; CALLEE caller convention
	
;;__MUL16_FAST:	; __FASTCALL ENTRY: HL = 1st operand, DE = 2nd Operand
	;;		ld c, h
	;;		ld a, l	 ; C,A => 1st Operand
	;;
	;;		ld hl, 0 ; Accumulator
	;;		ld b, 16
	;;
;;__MUL16LOOP:
	;;		sra c	; C,A >> 1  (Arithmetic)
	;;		rra
	;;
	;;		jr nc, __MUL16NOADD
	;;		add hl, de
	;;
;;__MUL16NOADD:
	;;		sla e
	;;		rl d
	;;			
	;;		djnz __MUL16LOOP
	
__MUL16_FAST:
	        ld b, 16
	        ld a, d
	        ld c, e
	        ex de, hl
	        ld hl, 0
	
__MUL16LOOP:
	        add hl, hl  ; hl << 1
	        sla c
	        rla         ; a,c << 1
	        jp nc, __MUL16NOADD
	        add hl, de
	
__MUL16NOADD:
	        djnz __MUL16LOOP
	
			ret	; Result in hl (16 lower bits)
	
			ENDP
	
#line 1168 "example01.zxb"
#line 1 "bxor16.asm"
; vim:ts=4:et:
	; FASTCALL bitwise xor 16 version.
	; result in Accumulator (0 False, not 0 True)
; __FASTCALL__ version (operands: A, H)
	; Performs 16bit xor 16bit and returns the boolean
; Input: HL, DE
; Output: HL <- HL XOR DE
	
__BXOR16:
		ld a, h
		xor d
	    ld h, a
	
	    ld a, l
	    xor e
	    ld l, a
	
	    ret 
	
#line 1169 "example01.zxb"
#line 1 "div32.asm"
#line 1 "neg32.asm"
__ABS32:
		bit 7, d
		ret z
	
__NEG32: ; Negates DEHL (Two's complement)
		ld a, l
		cpl
		ld l, a
	
		ld a, h
		cpl
		ld h, a
	
		ld a, e
		cpl
		ld e, a
		
		ld a, d
		cpl
		ld d, a
	
		inc l
		ret nz
	
		inc h
		ret nz
	
		inc de
		ret
	
#line 2 "div32.asm"
	
				 ; ---------------------------------------------------------
__DIVU32:    ; 32 bit unsigned division
	             ; DEHL = Dividend, Stack Top = Divisor
	             ; OPERANDS P = Dividend, Q = Divisor => OPERATION => P / Q
				 ;
				 ; Changes A, BC DE HL B'C' D'E' H'L'
				 ; ---------------------------------------------------------
	        exx
	        pop hl   ; return address
	        pop de   ; low part
	        ex (sp), hl ; CALLEE Convention ; H'L'D'E' => Dividend
	
__DIVU32START: ; Performs D'E'H'L' / HLDE
	        ; Now switch to DIVIDEND = B'C'BC / DIVISOR = D'E'DE (A / B)
	        push de ; push Lowpart(Q)
			ex de, hl	; DE = HL
	        ld hl, 0
	        exx
	        ld b, h
	        ld c, l
	        pop hl
	        push de
	        ex de, hl
	        ld hl, 0        ; H'L'HL = 0
	        exx
	        pop bc          ; Pop HightPart(B) => B = B'C'BC
	        exx
	
	        ld a, 32 ; Loop count
	
__DIV32LOOP:
	        sll c  ; B'C'BC << 1 ; Output most left bit to carry
	        rl  b
	        exx
	        rl c
	        rl b
	        exx
	
	        adc hl, hl
	        exx
	        adc hl, hl
	        exx
	
	        sbc hl,de
	        exx
	        sbc hl,de
	        exx
	        jp nc, __DIV32NOADD	; use JP inside a loop for being faster
	
	        add hl, de
	        exx
	        adc hl, de
	        exx
	        dec bc
	
__DIV32NOADD:
	        dec a
	        jp nz, __DIV32LOOP	; use JP inside a loop for being faster
	        ; At this point, quotient is stored in B'C'BC and the reminder in H'L'HL
	
	        push hl
	        exx
	        pop de
	        ex de, hl ; D'E'H'L' = 32 bits modulus
	        push bc
	        exx
	        pop de    ; DE = B'C'
	        ld h, b
	        ld l, c   ; DEHL = quotient D'E'H'L' = Modulus
	
	        ret     ; DEHL = quotient, D'E'H'L' = Modulus
	
	
	
__MODU32:    ; 32 bit modulus for 32bit unsigned division
	             ; DEHL = Dividend, Stack Top = Divisor (DE, HL)
	
	        exx
	        pop hl   ; return address
	        pop de   ; low part
	        ex (sp), hl ; CALLEE Convention ; H'L'D'E' => Dividend
	
	        call __DIVU32START	; At return, modulus is at D'E'H'L'
	
__MODU32START:
	
			exx
			push de
			push hl
	
			exx 
			pop hl
			pop de
	
			ret
	
	
__DIVI32:    ; 32 bit signed division
	             ; DEHL = Dividend, Stack Top = Divisor
	             ; A = Dividend, B = Divisor => A / B
	        exx
	        pop hl   ; return address
	        pop de   ; low part
	        ex (sp), hl ; CALLEE Convention ; H'L'D'E' => Dividend
	
__DIVI32START:
			exx
			ld a, d	 ; Save sign
			ex af, af'
			bit 7, d ; Negative?
			call nz, __NEG32 ; Negates DEHL
	
			exx		; Now works with H'L'D'E'
			ex af, af'
			xor h
			ex af, af'  ; Stores sign of the result for later
	
			bit 7, h ; Negative?
			ex de, hl ; HLDE = DEHL
			call nz, __NEG32
			ex de, hl 
	
			call __DIVU32START
			ex af, af' ; Recovers sign
			and 128	   ; positive?
			ret z
	
			jp __NEG32 ; Negates DEHL and returns from there
			
			
__MODI32:	; 32bits signed division modulus
			exx
	        pop hl   ; return address
	        pop de   ; low part
	        ex (sp), hl ; CALLEE Convention ; H'L'D'E' => Dividend
	
			call __DIVI32START
			jp __MODU32START		
	
#line 1170 "example01.zxb"
#line 1 "div16.asm"
	; 16 bit division and modulo functions 
	; for both signed and unsigned values
	
#line 1 "neg16.asm"
	; Negates HL value (16 bit)
__ABS16:
		bit 7, h
		ret z
	
__NEGHL:
		ld a, l			; HL = -HL
		cpl
		ld l, a
		ld a, h
		cpl
		ld h, a
		inc hl
		ret
	
#line 5 "div16.asm"
	
__DIVU16:    ; 16 bit unsigned division
	             ; HL = Dividend, Stack Top = Divisor
	
		;   -- OBSOLETE ; Now uses FASTCALL convention
		;   ex de, hl
	    ;	pop hl      ; Return address
	    ;	ex (sp), hl ; CALLEE Convention
	
__DIVU16_FAST:
	    ld a, h
	    ld c, l
	    ld hl, 0
	    ld b, 16
	
__DIV16LOOP:
	    sll c
	    rla
	    adc hl,hl
	    sbc hl,de
	    jr  nc, __DIV16NOADD
	    add hl,de
	    dec c
	
__DIV16NOADD:
	    djnz __DIV16LOOP
	
	    ex de, hl
	    ld h, a
	    ld l, c
	
	    ret     ; HL = quotient, DE = Mudulus
	
	
	
__MODU16:    ; 16 bit modulus
	             ; HL = Dividend, Stack Top = Divisor
	
	    ;ex de, hl
	    ;pop hl
	    ;ex (sp), hl ; CALLEE Convention
	
	    call __DIVU16_FAST
	    ex de, hl	; hl = reminder (modulus)
					; de = quotient
	
	    ret
	
	
__DIVI16:	; 16 bit signed division
		;	--- The following is OBSOLETE ---
		;	ex de, hl
		;	pop hl
		;	ex (sp), hl 	; CALLEE Convention
	
__DIVI16_FAST:
		ld a, d
		xor h
		ex af, af'		; BIT 7 of a contains result
	
		bit 7, d		; DE is negative?
		jr z, __DIVI16A	
	
		ld a, e			; DE = -DE
		cpl
		ld e, a
		ld a, d
		cpl
		ld d, a
		inc de
	
__DIVI16A:
		bit 7, h		; HL is negative?
		call nz, __NEGHL
	
__DIVI16B:
		call __DIVU16_FAST
		ex af, af'
	
		or a	
		ret p	; return if positive
	    jp __NEGHL
	
		
__MODI16:    ; 16 bit modulus
	             ; HL = Dividend, Stack Top = Divisor
	
	    ;ex de, hl
	    ;pop hl
	    ;ex (sp), hl ; CALLEE Convention
	
	    call __DIVI16_FAST
	    ex de, hl	; hl = reminder (modulus)
					; de = quotient
	
	    ret
	
#line 1171 "example01.zxb"
#line 1 "band16.asm"
; vim:ts=4:et:
	; FASTCALL bitwise and16 version.
	; result in hl 
; __FASTCALL__ version (operands: A, H)
	; Performs 16bit or 16bit and returns the boolean
; Input: HL, DE
; Output: HL <- HL AND DE
	
__BAND16:
		ld a, h
		and d
	    ld h, a
	
	    ld a, l
	    and e
	    ld l, a
	
	    ret 
	
#line 1172 "example01.zxb"
#line 1 "swap32.asm"
	; Exchanges current DE HL with the
	; ones in the stack
	
__SWAP32:
		pop bc ; Return address
	
		exx
		pop hl	; exx'
		pop de
	
		exx
		push de ; exx
		push hl
	
		exx		; exx '
		push de
		push hl
		
		exx		; exx
		pop hl
		pop de
	
		push bc
	
		ret
	
#line 1173 "example01.zxb"
	
ZXBASIC_USER_DATA:
	_eee EQU 57360
	_seed EQU 57362
	_ee2 EQU 57364
	_ee3 EQU 57366
	_ex0 EQU 57368
	_ey0 EQU 57370
	_ej0 EQU 57372
	_ej1 EQU 57374
	; Defines DATA END --> HEAP size is 0
ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP
	; Defines USER DATA Length in bytes
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
	END
