; Block Dude - TCPA
; By Brandon Sterner (vortexx15@aol.com)
; MirageOS port by Joel Walters (halide@carolina.rr.com)

.NOLIST
;       name    location        bytes and description
#define mx      apd_buf                 ;1 x coor of man
#define my	apd_buf+1	;1 y coor of man
#define x	apd_buf+2	;1 generic x
#define y	apd_buf+3	;1 generic y
#define curloc	apd_buf+4	;2 current location of compressed data
#define height  apd_buf+6	;1
#define width	apd_buf+7	;1
#define guyloc	apd_buf+8	;2 location of guy in boardmap
#define toploc	apd_buf+10	;2 location of the top left square in screen
#define direction apd_buf+12	;1 direction of man; 0 if left; not 0 if right
#define carry	apd_buf+13	;1 if the dude is carrying something =1 if not =0
#define textloc apd_buf+14	;2 bytes
#define textxy	apd_buf+16	;2 bytes
#define option	apd_buf+18	;1 byte
#define options	apd_buf+19	;1 byte
#define mode	apd_buf+20	;1 byte flag; demo(1) or play(0) mode
#define counter apd_buf+21	;1 byte timing moves
#define mask	apd_buf+22	;1 mask for decompressing
#define password apd_buf+23	;4 3 bytes will be chars the last being the zero terminated string
#define byte	apd_buf+27	;6 a clear buffer
#define level	apd_buf+33	;1 the # of the level you are on
#define secbuf	apd_buf+34	;4 buffer for secret presses
#define levloc	apd_buf+34+4	;2 location of the current level
#define passloc	apd_buf+36+4	;2 location in passbuff
#define passbuff apd_buf+38+4	;3 an inputted password
#define char	apd_buf+41+4	;1 current char# in the inout routine
#define page	apd_buf+46	;1 byte used for instructions routine
#define boardmap apd_buf+50	;651 bytes of data

#include "ti83plus.inc"
#include "mirage.inc"

.LIST

apd_buf	= saferam1
get_key = _GETCSC
second	= $36
smsprt	= isprite

;MirageOS header

 .org   $9D93
 .db    $BB,$6D
 ret
 .db    1
 .db    %00000000,%00000000
 .db    %00000000,%00000000
 .db    %00011100,%11111110
 .db    %01111110,%10000000
 .db    %00010010,%10000000
 .db    %00100010,%10000000
 .db    %00010100,%10000000
 .db    %00101010,%10000000
 .db    %00001000,%10000000
 .db    %00110110,%11111110
 .db    %11111011,%11111010
 .db    %11111011,%11111010
 .db    %00000000,%00000000
 .db    %11111110,%11111110
 .db    %11111110,%11111110
 .db    "Block Dude - TCPA",0

prog_start:
 ld     hl,password
 ld	(hl),0
 ld	de,password+1
 ld	bc,14
 ldir			;needed zeros for byte,password, and level

 call	erasescreen
 set	1,(iy+$05)	;underline
 set	textwrite,(iy+sgrflags)	;to graphbuffer

 call	loaddemo
 call   ifastcopy
 ld	hl,endtxt
 ld	de,57*256+5
 ld	a,4
 call	choosemode
 xor	a
 ld	(mode),a

 ld	a,(option)
 cp	4
 jp	z,new
 cp	3
 jr	z,enterpass
 dec	a
 jr	nz,loadhelp
 res	1,(iy+$05)	;underline
 res	textwrite,(iy+sgrflags)	;to graphbuffer			;exit
 ret
loadhelp:
 res    textwrite,(iy+sgrflags)
 bcall(_ClrScrn)
 ld	hl,instructions
 ld	a,1
 ld	(page),a
loadhelp2:
 xor    a
 ld	(x),a
 ld	(y),a
 ld	b,10
loadhelp3:
 push	bc
 ld	de,(x)
 call   setvputs
 ld	a,(y)
 add	a,6
 ld	(y),a
 pop	bc
 djnz	loadhelp3
 push	hl
 call	wait
 bcall(_ClrScrn)
 pop	hl
 ld	a,(page)
 inc	a
 ld	(page),a
 cp	3
 jr	nz,loadhelp2
 jp	prog_start

enterpass:
 call	box
 ld	hl,please
 ld	de,256*24+28
 call   setvputs
 ld	de,256*31+26
 call   setvputs
 call   ifastcopy
 ld	bc,256*38+42
 res	textwrite,(iy+sgrflags)
 call	input
 set	textwrite,(iy+sgrflags)

 ld	hl,level1-1
 ld	(curloc),hl
 xor	a
 ld	(level),a
checkpass:
 ld	hl,(curloc)
 ld	(levloc),hl
 ld	ix,passbuff-1
 ld	c,3
checkpass2:
 inc	hl
 inc	ix
 ld	a,(hl)
 ld	b,a
 ld	a,(ix)
 cp	b
 jr	nz,nextcheck
 dec	c
 jr	nz,checkpass2
 ld	hl,(levloc)
 ld	(curloc),hl
 jr	setuplevel			;found level
nextcheck:
 ld	hl,(levloc)
 ld	bc,4
 add	hl,bc
 ld	(curloc),hl
 call	erasemap
 ld	a,(level)
 inc	a
 ld	(level),a
 cp	11
 jr	nz,checkpass

new:
 xor	a
 ld	(level),a
 ld	hl,level1-1	;beginning of compressed data
 ld	(curloc),hl

setuplevel:
 ld	a,(level)
 inc	a
 ld	(level),a
 cp	12
 jp	z,message2
 ld	hl,(curloc)
 ld	(levloc),hl	;in case you want to restart level
 inc	hl		;if we are on a level>1 then we just decompressed this byte so we need to increment
 ld	de,password
 ld	bc,3
 ldir
 ld	(curloc),hl
 call	erasemap
 call	box
 ld	hl,leveltxt
 ld	de,27*256+27	;y,x
 call   setvputs
 ld     a,(level)
 ld	l,a
 ld	h,0
 call   disphl

 ld	hl,passtxt
 ld	de,36*256+27	;y,x
 call   setvputs
 ld	hl,password
 bcall(_VPutS)

 call   ifastcopy
 call	get2nd
 call	dispall

main:
 halt
 halt
 call   ifastcopy
;check if clear was pressed
 ld     a,0fdh
 call   directin
 cp	%10111111
 jp	z,message1
 ld     a,0bfh
 call   directin
;check if 2nd was pressed
 cp 	%11011111
 jr 	z,scan

 ld     a,0FEh
 call   directin
 cp	%11110111
 call	z,up
 cp	%11111110
 call	z,down
 cp	%11111101
 call	z,left
 cp	%11111011
 call	z,right

 jr	main
scan:
 ld	hl,(toploc)
 push	hl
scan2:
 halt
 ld     a,0FEh
 call   directin
 cp	%11110111
 call	z,checkup2
 cp	%11111110
 call	z,checkdown2
 cp	%11111101
 call	z,checkleft2
 cp	%11111011
 call	z,checkright2
 call	dispall
 call   ifastcopy
 halt
 ld     a,0bfh
 call   directin
;check if 2nd was pressed
 cp 	%11011111
 jr 	z,scan2
 pop	hl
 ld	(toploc),hl
 call	dispall
 jr	main

Direct_Input:
; ld     a,0ffh
; out    (1),a
; ld     a,b
; out    (1),a
; in     a,(1)
; ret
left:
 ld	ix,(guyloc)
 ld	a,(ix-1)
 cp	3
 jp	z,nextlevel
 or	a
 jr	nz,left4	;can't walk through a wall you idiot!
 ld	a,(carry)
 or	a
 jr	z,left3
 ld	a,(ix-32)
 or	a
 jr	z,left2
 ld	(ix),2
 xor	a
 ld	(ix-31),a
 ld	(carry),a
 jr	left31
left2:
 ld	(ix-31),a
 ld	(ix-32),2
left3:
 ld	(ix),0
left31:
 dec	ix
left4:
 ld	(ix),4
 ld	(guyloc),ix
 xor	a
 ld	(direction),a
 call	checkleft
 call	checkfall
 jp	dispall

right:
 ld	ix,(guyloc)
 ld	a,(ix+1)
 cp	3
 jp	z,nextlevel
 or	a
 jr	nz,right4	;can't walk through a wall you idiot!
 ld	a,(carry)
 or	a
 jr	z,right3	;no carry
 ld	a,(ix-30)
 or	a
 jr	z,right2
 ld	(ix),2
 xor	a
 ld	(ix-31),a
 ld	(carry),a
 jr	right31
right2:
 ld	(ix-31),a
 ld	(ix-30),2
right3:
 ld	(ix),0
right31:
 inc	ix
right4:
 ld	(ix),5
 ld	(guyloc),ix
 ld	a,1
 ld	(direction),a
 call	checkright
 call	checkfall
 jp	dispall

up:
 ld	ix,(guyloc)
 ld	a,(ix-31)
 dec    a       ;(cp 1)
 ret	z	;you can't go up, there is brick above you
 ld	a,(direction)
 or	a
 jr	nz,upright
upleft:
 ld	a,(ix-1)
 or	a
 ret	z	;bozo there's nothing to climb:)
 cp	3
 jp	z,nextlevel
 ld	a,(ix-32)
 cp	3
 jp	z,nextlevel
 or	a
 ret	nz	;its too tall
 ld	a,(carry)
 or	a
 jr	z,upleft2
 ld	a,(ix-63)
 or	a
 ret	nz	;there is something on top of the empty space you're trying to move into
 ld	(ix-31),a ;erase current block carried 
 ld	(ix-63),2 ;put up where you will be
upleft2:
 ld	(ix),a
 ld	de,-32
 add	ix,de
 ld	(ix),4
 ld	(guyloc),ix
 xor	a
 ld	(direction),a
 call	checkleft
 call	checkup
 jp	dispall
upright:
 ld	a,(ix+1)
 or	a
 ret	z	;bozo there's nothing to climb:)
 cp	3
 jp	z,nextlevel
 ld	a,(ix-30)
 cp	3
 jp	z,nextlevel
 or	a
 ret	nz	;its too tall
 ld	a,(carry)
 or	a
 jr	z,upright2
 ld	a,(ix-61)
 or	a
 ret	nz
 ld	(ix-31),a
 ld	(ix-61),2
upright2:
 ld	(ix),a
 ld	de,-30
 add	ix,de
 ld	(ix),5
 ld	(guyloc),ix
 ld	a,1
 ld	(direction),a
 call	checkright
 call	checkup
 jp	dispall

down:	;pick up/put down
 ld	ix,(guyloc)
 ld	a,(carry)
 or	a
 jr	nz,putdown
 ld	a,(ix-31)
 or	a
 ret	nz	;there is something over your head
 ld	a,(direction)
 or	a
 jr	nz,pickupr
 ld	a,(ix-1)
 cp	2
 ret	nz	;yes you're still stupid, you can't pick it up(if there was anything there in the first place)
 ld	a,(ix-32)
 or	a
 ret	nz	;can't pick up something if something is on top of it
 ld	a,2
 ld	(carry),a
 ld	(ix-1),0
 ld	(ix-31),a
 call	dispall
 ld	c,1
 jp	nodkey
pickupr:
 ld	a,(ix+1)
 cp	2
 ret	nz	;yes you're still stupid, you can't pick it up(if there was anything there in the first place)
 ld	a,(ix-30)
 or	a
 ret	nz	;can't pick up something if something is on top of it
 ld	(ix+1),a
 ld	a,2
 ld	(carry),a
 ld	(ix-31),a
 call	dispall
 jp	nodkey
putdown:
 ld	a,(direction)
 rla
 ld	e,a
 ld	d,0
 dec	de
 add	ix,de	;either ix-1 or ix+1
 ld	de,-31
 add	ix,de	;now we have the blocks location left or right one
 ld	a,(ix)
 or	a
 ret	nz	;something is in the way
putdown2:
 ld	de,31
 add	ix,de
 ld	a,(ix)
 or	a
 jr	z,putdown2
putdown3:
 ld	(ix-31),2
 ld	ix,(guyloc)
 xor	a
 ld	(ix-31),a
 ld	(carry),a
 call	dispall
 jp	nodkey
checkup:
 ld	a,(my)
 cp	40
 ret	nc
checkup2:
 ld	hl,(toploc)
 ld	de,-31
 add	hl,de
 ld	a,(hl)
 inc	a
 ret	z
 ld	(toploc),hl
 ret
checkdown:
 ld	a,(my)
 cp	24
 ret	c
checkdown2:
 ld	hl,(toploc)
 ld	de,248
 add	hl,de
 ld	a,(hl)
 inc	a
 ret	z
 ld	de,-217
 add	hl,de
 ld	(toploc),hl
 ret
checkright:
 ld	a,(mx)
 cp	56
 ret	c
checkright2:
 ld	ix,(toploc)
 ld	a,(ix+12)
 inc	a
 ret	z
 inc	ix
 ld	(toploc),ix
 ret
checkleft:
 ld	a,(mx)
 cp	48
 ret	nc
checkleft2:
 ld	ix,(toploc)
 dec	ix
 ld	a,(ix)
 inc	a
 ret	z
 ld	(toploc),ix
 ret
checkfall:
 ld	ix,(guyloc)
 ld	a,(ix+31)
 or	a
 jr	nz,checkfall3
 ld	a,(my)
 add	a,8
 ld	(my),a
 call	checkdown
 ld	(ix),0
 ld	de,31
 add	ix,de
 ld	a,(direction)
 add	a,4
 ld	(ix),a
 ld	(guyloc),ix
 ld	a,(carry)
 or	a
 jr	z,checkfall2
 ld	(ix-31),a	;i think it'll always be 2
 ld	(ix-62),0
checkfall2:
 jr	checkfall
checkfall3:
 cp	3
 ret	nz
 call	dispall
 pop	hl		;de increment stack by 2
 jp	nextlevel

dispall:
 call	erasescreen
 call	drawtiles
delay:	;or nokey
 call   ifastcopy
 ld	c,10
delay2:
 halt
 ld     a,0FEh
 call   directin
 inc	a
 jr	z,delay3
 dec	c
 jr	nz,delay2
delay3:
 ret

getdata2:
 push	bc
 push	hl
 push	de
 push	ix
 ld	c,0
getdata3:
 ld	hl,(curloc)
 ld	a,(mask)
 ld	b,a
 ld	a,(hl)
 and	b
 cp	b
 jr	nz,gotbyte
 inc	c
 call	nec
 jr	getdata3
gotbyte:
 call	nec
 ld	a,c
 pop	ix
 pop	de
 pop	hl
 pop	bc
 ret
nec:
 ld	a,(mask)
 rrca
 ld	(mask),a
 cp	128
 ret	nz
 inc	hl
 ld	(curloc),hl
 ret

interpret:
 or	a
 ret	z
 ld	ix,brick-8
 ld	de,8
interpret2:
 add	ix,de
 dec	a
 jr	nz,interpret2
 ld	a,(y)
 ld	l,a
 ld	a,(x)
sprite:
 ld     b,8
 jp     smsprt

;draw the tiles on screen from location (toploc)
drawtiles:
 ld	hl,(toploc)
 xor	a
 ld	(y),a
drawtiles2:
 xor	a
 ld	(x),a
drawtiles3:
 ld	a,(hl)
 cp	4
 jr	c,drawtiles4
 ld	(guyloc),hl
 sub	4
 ld	(direction),a
 ld	de,(x)
 ld	(mx),de
 add	a,4
drawtiles4:
 push	hl
 call	interpret
 pop	hl
 inc	hl
 ld	a,(x)
 add	a,8
 ld	(x),a
 cp	96
 jr	nz,drawtiles3
 ld	de,19
 add	hl,de
 ld	a,(y)
 add	a,8
 ld	(y),a
 cp	64
 jr	nz,drawtiles2
 ret
erasescreen:
 ld	hl,plotsscreen
 ld	(hl),0
 ld	de,plotsscreen+1
 ld	a,(mode)
 or	a
 jr	nz,part
 ld	bc,767
 ldir
 ret
part:
 ld	bc,671
 ldir
 ld     bc,264
 ld	HL,titlescreen
 ld	DE,plotsscreen
 call   DispRLEL        ;decompress rle title screen
 ret
wait:
get2nd:
 bcall(get_key)
 cp     second
 jr	nz,get2nd
 ret
nodkey:
 ld	c,1	;mask for nokey
nokey:
 push	bc
 call   ifastcopy
 pop	bc
nokey2:
 halt
 ld     a,0FEh
 call   directin
 and	c
 cp	c
 jr	nz,nokey2
 ret

nextlevel:
 ld	a,(mode)
 or	a
 jr	nz,loaddemo
 pop	hl	;de increment stack by 2
 jp	setuplevel

loaddemo:
 ld	a,1
 ld	(mode),a
 ld	a,20
 ld	(counter),a
 ld	hl,level1+3	;beginning of compressed data (skipping the password
 ld	(curloc),hl
 call	erasemap
 ld	a,128
 ld	(mask),a
 ld	hl,moves
 ld	(curloc),hl
 ret
;-----Menu Routine------;
;as it is now, this is	;
;a sideways menu routine;
;to move use right and	;
;left. Use del to select;
;an option		;
;required vars:		;
;textloc 	;2 bytes;
;textxy		;2 bytes;
;option		;1 byte	;
;options	;1 byte	;
;be sure to put option	;
;right before the the 	;
;var options in memory	;
;			;
;input for menu:	;
;hl=start of text	;
;de=coors of menu	;
;a=options		;
;			;
;output:		;
;option= # of options-1st or 2nd or...;
;--------Code-----------;
choosemode:		;
 ld	(textloc),hl	;store the variables
 ld	(textxy),de	;
 ld	(options),a	;
 ld	(option),a	;a=the num of options. If there were 5 then five would point to the first option
writemenu:
 ld	hl,(textloc)
 ld	de,(textxy)
 ld	(pencol),de
 ld	a,(options)	;load a and b with the
 ld	b,a		;number of option
writemenu2:		;
 push	bc		;save bc
 ld	a,(option)	;see if option(the one that sould be highlighted)
 cp	b		;= b(the current option being written
 jr     nz,iVPutS       ;
 set	textInverse,(iy+textflags);
 bcall(_VPutS)          ;
 res	textInverse,(iy+textflags);

writemenu3:		;
 pop	bc		;recall bc
 djnz	writemenu2	;

writemenu4:		;main loop for selecting
 ld	a,(mode)
 or	a
 call	nz,demomode

 halt
 halt

 call   ifastcopy
 bcall(get_key)
 cp     second          ;2nd?
 ret	z
 cp	$02		;left?
 jr	z,leftmen	;then move left
 cp	$03		;right?
 jr	z,rightmen	;then move right
 cp	$30
 jr	nz,writemenu4
 ld	a,(mode)
 or	a
 jr	z,writemenu4
 ld	a,(option)
 dec	a
 ld	hl,secbuf
 ld	d,0
 ld	e,a
 add	hl,de
 ld	(hl),1
 ld	hl,secbuf
 ld	b,4
secloop:
 ld	a,(hl)
 dec	a
 jr	nz,writemenu4
 inc	hl
 djnz	secloop
 jp	secretselect

leftmen:		;move left in the menu
 ld	de,(option)	;compare
 ld	a,e		;option to
 cp	d		;options
 jr	z,writemenu4	;if = then go back
 inc	a		;increase the option pointer
 ld	(option),a	;
 jr	writemenu	;rewrite the menu
rightmen:		;
 ld	a,(option)	;compare
; cp	1		;option # to 1
 dec a
 jr	z,writemenu4	;if = then go back
; dec	a		;else decrease the option #
 ld	(option),a	;
 jr	writemenu	;rewrite menu
iVPutS:                 ;text w/ underline
 bcall(_VPutS)          ;
 jr	writemenu3	;
;-----------------------;
secretselect:
 xor	a
 ld	(mode),a
 call	box
 ld	hl,select
 ld	de,256*24+27
 call   setvputs
 ld	de,256*31+38
 call   setvputs
 call   ifastcopy
 ld	a,1
 ld	(level),a
secretloop:
 ld	de,256*38+46
 ld	(pencol),de
 ld	a,(level)
 ld	h,0
 ld	l,a
 call   disphl
 call   ifastcopy
secretl2:
 bcall(get_key)
 cp	$04
 jr	z,sup
 cp     second
 jr	z,secl3
 dec    a
 jr	z,sdown
 jr	secretl2
sup:
 ld	a,(level)
 dec	a
 jr	z,secretl2
 ld	(level),a
 jr	secretloop
sdown:
 ld	a,(level)
 cp	11
 jr	z,secretl2
 inc	a
 ld	(level),a
 jr	secretloop
secl3:
 ld	hl,level1-1
 ld	(curloc),hl
 ld	a,(level)
 ld	b,a
secl4:
 ld	hl,(curloc)
 ld	(levloc),hl
 ld	de,4
 add	hl,de
 ld	(curloc),hl
 push	bc
 call	erasemap
 pop	bc
 djnz	secl4
 pop	hl	;rid ourselves of a call
 jp	restart
erasemap:
 ld	hl,boardmap
 ld	(hl),$ff
 ld	de,boardmap+1
 ld	bc,650
 ldir
 call	erasescreen
 ld	a,128
 ld	(mask),a
copydata:
 ld	hl,(curloc)
 ld	a,(hl)
 ld	e,a
 inc	hl
 ld	a,(hl)
 ld	d,a
 inc	hl
 ld	(toploc),de
 ld	a,(hl)
 ld	(height),a
 inc	hl
 ld	a,(hl)
 ld	(width),a
 inc	hl
 ld	(curloc),hl
 ld	hl,boardmap+32
copydata2:
 ld	a,(width)
 ld	b,a
copydata3:
 call	getdata2
 ld	(hl),a
 inc	hl
 djnz	copydata3
 ld	a,(width)
 ld	b,a
 ld	a,31
 sub	b
 ld	d,0
 ld	e,a
 add	hl,de
 ld	a,(height)
 dec	a
 ld	(height),a
 jr	nz,copydata2
 xor	a
 ld	(carry),a
 jp	drawtiles
demomode:
 ld	hl,counter
 dec	(hl)
 ret	nz
 ld	(hl),20
 call	getdata2
 dec    a       ;cp 1
 jp	z,up
 dec    a       ;cp 2
 jp	z,right
 dec    a       ;cp 3
 jp	z,down
 dec    a       ;cp 4
 jp	z,left
 ret
;===========================================================
; RLE picture displayer v1.1
; Decodes a RLE picture made by RLE2PIC
; 82/83 version
;
; written by David Phillips <electrum@tfs.net>
; started: 8/19/98
; last update: 1/12/98
;
; input: HL = RLE encoded picture, DE = where to display
; output: 1024 byte decoded picture
; destroys: AF, BC, DE, HL
; current size: 32 bytes
;===========================================================
;DispRLE:
; ld bc,264                     ; we need to copy 768 bytes
;DispRLEL:
; ld a,(hl)                     ; get the next byte
; cp $91                        ; is it a run?
; jr z,DispRLERun               ; then we need to decode the run
; ldi                           ; copy the byte, and update counters
;DispRLEC:
; ld a,b                        ; check the low byte and
; or c                          ; the high byte for 0
; jr nz,DispRLEL                ; if not, then we're not done either
; ret                           ; if it's zero, we're done
;DispRLERun:
; inc hl                        ; move to the run value
; ld a,(hl)                     ; get the run value
; inc hl                        ; move to the run count
; push hl                       ; save source pointer
; ld h,(hl)                     ; get the run count
; ex de,hl                      ; swap source and destination pointers
;DispRLERunL:
; ld (hl),a                     ; copy the byte
; inc hl                        ; increase destination pointer
; dec bc                        ; decrease byte count
; dec d                         ; decrease run count
; jr nz,DispRLERunL             ; if we're not done, then loop
; ex de,hl                      ; swap pointers back
; pop hl                        ; recover source pointer
; inc hl                        ; advance the source pointer
; jr DispRLEC                   ; check to see if we should loop
;
box:				; START OF CODE By Chris Hiszpanski (Man in the Moon)
 ld	a,31			; Height + 1 again
 ld	de,$plotsscreen+195		; Top left corner
clearline:			; Clear the section saved
 ld	hl,byte
 ld	bc,6			;
 ldir				;
 inc	de			; Skip last four bytes
 inc	de			;
 inc	de			; Skip last four bytes
 inc	de			;
 inc	de			;
 inc	de			;
 dec	a			;
;or     a                       ;
 jr	nz,clearline		;

;vortexx15
;put title in
 ld	hl,description
 ld	de,17*256+25
 set	textInverse,(iy+textflags)
 call   setvputs
 res	textInverse,(iy+textflags)
;end of title
;/vortexx15
  res   plotloc,(iy+plotflags)
;draw first line
;  ld    hl,71*256+47
;  ld    de,24*256+47
;  call  fastlineb
;draw second line
;  ld    hl,24*256+47
;  ld    de,24*256+17
;  call  fastlineb
;draw third line
;  ld    hl,71*256+17
;  ld    de,24*256+17
;  call  fastlineb
;draw fourth line
;  ld    hl,71*256+17
;  ld    de,71*256+47
;  jp    fastlineb
;(ret)

 ld hl,24*256+17
 ld de,71*256+47
 ld a,1
 jp fastrectangle


;input: hl(to be displayed)
;------------------------
disphl:                 ;
 bcall(_SetXXXXOP2)     ;
 bcall(_OP2ToOP1)       ;
 bcall(_DispOP1A)       ;
 ret                    ;
;------------------------
message2:
 call	box
 ld	hl,endmess
 ld	de,24*256+32
 call   setvputs
 ld	de,30*256+29
 call   setvputs
 ld	de,36*256+31
 call   setvputs
 call   ifastcopy
 call	wait
 jp	prog_start

message1:
 call	box
 ld	hl,joke
 ld	de,27*256+28
 call   setvputs
 ld	hl,mess1txt
 ld	de,36*256+27
 ld	a,2
 call	choosemode
 ld	a,(option)
 dec	a
 jp	z,prog_start

;restart level
restart:
 ld	hl,(levloc)
 ld	(curloc),hl
 ld	hl,level
 dec	(hl)
 jp	setuplevel

;input:
;bc= coors

input:
 ld	hl,passbuff
 ld	(passloc),hl
 ld	(textxy),bc
 ld	(pencol),bc
 ld	a,3
 ld	(option),a
alphastart:
 ld	a,'A'
 ld	(char),a
placechar:
 push	af
 ld	hl,(textxy)
 push	hl
 ld	(pencol),hl
 ld	hl,blanks
 bcall(_VPutS)
 pop	hl
 ld	(pencol),hl
 pop	af
 bcall(_VPutMap)
inputmain:
 bcall(get_key)
 cp     second          ;2nd?
 jr     z,nextchar
 cp	$04		;up?
 jr	z,inputup
 dec    a               ;down?
 jr	z,inputdown
 jr	inputmain
inputdown:
 ld	a,(char)
 cp	'Z'
 jr	z,inputdown2
 cp	'z'
 jr	z,alphastart
 inc	a
 ld	(char),a
 jr	placechar
inputdown2:
 ld	a,'a'
 ld	(char),a
 jr	placechar
inputup:
 ld	a,(char)
 cp	'A'
 jr	z,lalphaend
 cp	'a'
 jr	z,alphaend
 dec	a
 ld	(char),a
 jr	placechar
alphaend:
 ld	a,'Z'
 ld	(char),a
 jr	placechar
lalphaend:
 ld	a,'z'
 ld	(char),a
 jr	placechar
nextchar:
 ld	a,(char)
 ld	hl,(passloc)
 ld	(hl),a
 inc	hl
 ld	(passloc),hl
 ld	hl,(pencol)
 ld	(textxy),hl
 ld	hl,option
 dec	(hl)
 ret	z
 jr	placechar

brick:
 .db	%11111011
 .db	%11111011
 .db	%00000000
 .db	%11111110
 .db	%11111110
 .db	%00000000
 .db	%11111011
 .db	%11111011
block:			;varible sized block
 .db	%11111111
 .db	%10000001
 .db	%10000001
 .db	%10000001
 .db	%10000001
 .db	%10000001
 .db	%10000001
 .db	%11111111
door:
 .db	%01111110
 .db	%01000010
 .db	%01000010
 .db	%01000010
 .db	%01000110
 .db	%01000010
 .db	%01000010
 .db	%01111110
manl:
 .db	%00011100
 .db	%01111110
 .db	%00010010
 .db	%00100010
 .db	%00010100
 .db	%00101010
 .db	%00001000
 .db	%00110110
manr:
 .db	%00111000
 .db	%01111110
 .db	%01001000
 .db	%01000100
 .db	%00101000
 .db	%01010100
 .db	%00010000
 .db	%01101100
titlescreen:	;rle
 .db    $91,$00,$09,$40,$91,$00,$04,$3f,$b0,$00,$08,$1f
 .db    $f0,$00,$40,$91,$00,$04,$0c,$90,$00,$08,$08,$18
 .db    $00,$40,$91,$00,$04,$09,$10,$00,$10,$08,$08,$00
 .db    $40,$91,$00,$04,$16,$20,$e3,$96,$10,$0e,$21,$c6
 .db    $91,$00,$04,$1f,$a3,$2c,$28,$10,$0a,$46,$9a,$91
 .db    $00,$04,$20,$a4,$30,$30,$20,$14,$59,$14,$91,$00
 .db    $04,$20,$a4,$50,$50,$20,$24,$91,$91,$01,$28,$91
 .db    $00,$04,$21,$44,$92,$48,$20,$45,$93,$20,$91,$00
 .db    $04,$3e,$47,$1c,$4c,$3f,$86,$5d,$b8,$91,$00,$07
 .db    $40,$00,$00,$01,$91,$00,$06,$04,$39,$b1,$06,$4d
 .db    $b8,$91,$00,$06,$0a,$12,$2a,$88,$aa,$a0,$91,$00
 .db    $06,$0e,$12,$33,$8a,$ea,$b0,$91,$00,$06,$0a,$12
 .db    $22,$8a,$aa,$a0,$91,$00,$06,$0a,$11,$a2,$86,$a8
 .db    $b8,$91,$00,$12,$32,$8a,$4c,$ee,$aa,$4e,$91,$00
 .db    $06,$2a,$8a,$aa,$48,$aa,$c8,$91,$00,$06,$31,$0a
 .db    $ac,$4c,$44,$4c,$91,$00,$06,$29,$0a,$aa,$48,$aa
 .db    $42,$91,$00,$06,$31,$04,$4a,$4e,$aa,$ec,$91,$00
 .db    $03
; Total compression: 264 bytes compressed to 205 (22% smaller)

;levels are compressed huffman meathod
level1:
 .db	"tcP"		;password
 .dw	boardmap+40	;screen starting position
 .db	8	;height
 .db	20	;widht
 .db	128,0,10,0,0,40,0,0,160,0,2,132,2,2,184,132,201,159,21
 .db	85,85,85,85,80,0,0,0	;27 bytes of blocks

level2:
 .db	"ARo"
 .dw	boardmap+104	;screen starting position
 .db	10	;height
 .db	22	;widht
 .db	%01000001,%01000000,%00010100,%00001000,%00000000,%00000010
 .db	%00010100,%00000000,%00000000,%10001011,%10000000,%00000000
 .db	%00001001,%01000000,%00000000,%00000010,%01000000,%00000010
 .db	%00110000,%01001000,%00000000,%01011001,%10110111,%10001001
 .db	%01010101,%00001010,%10101010,%10101010,%10101000,%00010001
 .db	%10100000,%00000000,%00000101,%01010100,%00000000,%00000000
;36 bytes of blocks
level3:
 .db	"CKs"
 .dw	boardmap+97
 .db	11	;height
 .db	19	;width
 .db	%01000000,%00000000,%00000100,%00101010,%10101010,%10101010
 .db	%10100100,%10010000,%00000000,%00101000,%10000000,%00000000
 .db	%10100000,%00000000,%00001101,%01000000,%00000000,%00110110
 .db	%10100101,%01000001,%11100001,%01100101,%00100100,%10000010
 .db	%00101010,%10100010,%01001011,%01100101,%00010000,%00010111
 .db	%01001010,%10101010,%01010000,%00010101,%00101000,%01010100
 .db	%00000000
level4:
 .db	"daN"
 .dw	boardmap+198
 .db	16
 .db	24
 .db	%00000000,%00000000,%00100000,%00000000,%00000000,%00100100,%00000000,%00100000
 .db	%00001000,%01000000,%00001001,%00000001,%00000010,%00000101,%01000010,%00001000
 .db	%00000100,%00100000,%00010001,%00000000,%00100100,%00000000,%10100000,%00000010
 .db	%01000000,%00000000,%00000001,%10100100,%00000000,%00000000,%00110110,%10010000
 .db	%00000000,%00001111,%00001010,%10101000,%00100000,%00000010,%00010001,%01110000
 .db	%01001100,%00000001,%01010101,%00010101,%01010010,%01100001,%10001010,%10000000
 .db	%00001001,%00110010,%01011001,%00000000,%00000100,%10101010,%10101010,%10100000
 .db	%00000000,%10101000,%00000000,%0000000
level5:
 .db	"BAH"
 .dw	boardmap+163
 .db	14
 .db	22
 .db	%00000101,%01000001,%01010101,%01010101,%00010101,%01000010,%10101000,%00000001
 .db	%01000000,%00000000,%00000001,%01000000,%00000000,%00000001,%01000000,%00000000
 .db	%00000001,%01000000,%10000000,%00000000,%10100000,%01000000,%00000000,%01010000
 .db	%00101101,%10110110,%00000000,%00101011,%10000101,%01010101,%01011110,%00000000
 .db	%10101001,%01010000,%00101001,%00000011,%01001001,%00000000,%01001010,%00011011
 .db	%01001001,%00000000,%01001010,%00110110,%11010010,%10100000,%00001001,%01010101
 .db	%01010100,%00000000,%00010101,%00000000,%0
level6:
 .db	"Ion"
 .dw	boardmap+134
 .db	13
 .db	21
 .db	%01010100,%00000000,%00001010,%10100100,%01010101,%01010101,%01010101,%01000010
 .db	%10100000,%00000000,%00000010,%10111000,%00000000,%00000000,%10101000,%00000000
 .db	%00000000,%10010000,%00000000,%00000110,%11010010,%11011000,%00000010,%00110001
 .db	%01010010,%11011011,%00000000,%10111101,%10110110,%01000010,%11011011,%01100000
 .db	%00101010,%10100100,%00101010,%10100000,%10101000,%01010100,%00000010,%00011010
 .db	%00000000,%00000001,%01001010,%10000000,%00000000,%00101010,%00000000,%0000
level7:
 .db	"Twe"
 .dw	boardmap+198
 .db	14
 .db	24
 .db	%00100001,%01010101,%00001010,%00010101,%00001001,%00100000,%01001000,%10010000
 .db	%10001000,%10100000,%00101000,%01010000,%01001000,%01000000,%00100000,%10000010
 .db	%01000000,%00000000,%00000001,%10100100,%00000000,%00000000,%00011010,%10100000
 .db	%00000000,%00000001,%10110101,%01110000,%11000000,%00000000,%00101010,%10100001
 .db	%00110000,%00100000,%10100100,%00100001,%00110000,%01010011,%00111101,%01010100
 .db	%00101000,%10011011,%01100010,%10011011,%01101000,%00000100,%01010101,%01010010
 .db	%10101010,%10100000,%00010100,%10000010,%10100000,%00000000,%00101010,%00000000
 .db	%00000000,%00
level8:
 .db	"nTy"
 .dw	boardmap+326
 .db	17
 .db	27
 .db	%01010100,%00000010,%10101000,%01010101,%01010100,%01000010,%00000100,%00010010
 .db	%00000001,%00100000,%10000100,%00001010,%00000000,%01010110,%00001010,%10000010
 .db	%01000000,%10101000,%10101101,%10000000,%00010100,%00000101,%00100010,%10101010
 .db	%00000001,%01000000,%00000101,%11001000,%01010000,%00000000,%01010000,%01010010
 .db	%00100000,%11001000,%00001000,%10000000,%10001000,%00110100,%10000010,%00010000
 .db	%00010010,%00010101,%00001000,%00100010,%00000110,%10010000,%00010010,%00000010
 .db	%10000001,%10110101,%00000000,%01000000,%00000010,%10101010,%10100000,%00000000
 .db	%11000000,%00000001,%01000001,%10000000,%10101000,%00000000,%11010100,%00101010
 .db	%00000000,%00000000,%01101101,%01000000,%00011000,%00000110,%00111100,%01101101
 .db	%10101010,%10101010,%10101010,%10101010,%10101010,%10101010,%10101010,%10101010
level9:
 .db	"iRC"
 .dw	boardmap+132
 .db	16
 .db	20
 .db	%00000000,%10101000,%00000000,%00000010,%00010000,%00000000,%00010000,%00100010
 .db	%10101010,%00000100,%00000010,%10000010,%00001000,%00011000,%00000010,%00010000
 .db	%00011011,%00000001,%10100010,%00000001,%01010000,%01101101,%00100000,%00000000
 .db	%11110010,%10101010,%00000000,%00000110,%00001010,%11100000,%00000001,%01010000
 .db	%10101000,%00101000,%01000000,%01101001,%00000101,%01100010,%10000101,%01010010
 .db	%00001010,%10101010,%10001010,%00001010,%10001000,%00010010,%10000000,%01001010
 .db	%00000101,%01000000,%00010101,%00000000,%0000000
level10:
 .db	"JmK"
 .dw	boardmap+258
 .db	19
 .db	27
 .db	%00010101,%01010101,%01010101,%01010101,%01010101,%01010000,%01010000,%00000000
 .db	%10000000,%00010001,%01010101,%10000000,%01101101,%01100001,%10110110,%01101010
 .db	%01000101,%00010000,%10101010,%10001101,%01010010,%10010100,%00100010,%10000000
 .db	%00101010,%01010100,%01010000,%10100010,%10110110,%11011000,%00000000,%00101011
 .db	%10000000,%01010101,%01010100,%00000000,%01010100,%00000001,%00001010,%10000000
 .db	%00101001,%00000011,%00001001,%00010100,%00000001,%00100000,%01000001,%00000101
 .db	%00000000,%10010101,%01000101,%00000000,%00000010,%10101010,%00010101,%01010000
 .db	%00011110,%00000000,%00010000,%10000000,%00001000,%00000000,%01000010,%00000000
 .db	%01010000,%01010101,%01010101,%00001000,%00000010,%10000000,%00000100,%00010000
 .db	%00000001,%10000000,%00011010,%00001011,%00000101,%01010101,%01010101,%01000011
 .db	%01101000,%00101101,%10001010,%00000000,%01010011,%01101101,%00000101,%01010101
 .db	%00000000,%00001010,%10101010,%0
level11:
 .db	"wTF"
 .dw	boardmap+39
 .db	19
 .db	29
 .db	%10101010,%10101010,%10101010,%10101010,%10101010,%10101010,%10101010,%10100010
 .db	%00010000,%00000000,%00000000,%01010000,%00110101,%10110000,%00000000,%01010101
 .db	%01001010,%11000010,%10100110,%10100000,%01100010,%10001110,%01001010,%11011000
 .db	%00101010,%00011110,%00110000,%00001001,%00101010,%10001101,%10100000,%01001100
 .db	%00000000,%01001010,%00010101,%01000000,%01000101,%01000010,%10100010,%10110000
 .db	%00000000,%01001000,%00001000,%11001010,%11011000,%00000101,%01001001,%01100000
 .db	%10001010,%10101010,%10100110,%00010101,%00010010,%10110001,%00110010,%00101000
 .db	%00000000,%01100101,%01000110,%10000100,%00101000,%01100000,%01101100,%10000101
 .db	%01010000,%00001010,%00001010,%10101010,%10101000,%00000010,%10101010,%01010000
 .db	%00000000,%00011000,%01101010,%00001001,%01010101,%00000000,%00001100,%00100000
 .db	%11011010,%01010110,%10100001,%00000100,%00000000,%01010101,%00101010,%11010101
 .db	%00100000,%10000110,%11011001,%10000000,%01010110,%10110101,%10101000,%00100000
 .db	%00001101,%10110000,%01010101,%01010101,%01010101,%01010101,%01010101,%01010101
 .db	%01010101,%01010000
instructions:
 .db	"The object of this game is",0
 .db	"to reach the door in each",0
 .db	"level.  If you are unsure",0
 .db	"where it is you can hold 2nd",0
 .db	"down and use the arrow keys",0
 .db	"to scroll freely.  You can",0
 .db	"only clinb one block at a time",0
 .db	"and lift only one block at a",0
 .db	"time.  To lift up a block",0
 .db	"press down.  To set it down",0
 .db	"press down again.  CLEAR will",0
 .db	"give you the choice of",0
 .db	"restarting or quiting.  There",0
 .db	"are 11 levels in this game.",0
 .db	"Please visit our web page at",0
 .db	"tcpa.calc.org for additional",0
 .db	"information.  Thanks to all",0
 .db	"the beta testers and the ACZ",0
 .db	"for all there useful utilities",0
 .db	" ",0

moves:	;for demo are compressed huffman style
 .db	%11110111,%01111011,%10101011,%11010111,%10101101,%01101111
 .db	%01110111,%10111101,%01111011,%11011101,%01011110,%11110111
 .db	%10000000
endtxt:
 .db	" New ",0," Password ",0," Help ",0," Quit ",0
mess1txt:
 .db	" Restart ",0," Quit ",0
leveltxt:
 .db	"Level: ",0
passtxt:
 .db	"Pass: ",0
please:
 .db	"Please Enter",0
 .db	"The Password",0
joke:
 .db	"Too hard? :)",0
select:
 .db	"Secret Level",0
 .db	"Select",0

description:
 .db	"     Block Dude     ",0
endmess:
 .db	"Well done!",0
 .db	"You beat all",0
 .db	"the levels.",0
blanks:
 .db	"      ",0

.end
END
