[comp.sys.amiga.games] Gameboy Tetris Compiles but no go yet

iwoehr@isis.cs.du.edu (Ivan Woehr) (04/22/91)

	I have just succesfully compiles the Tetris.z80 code that was
included in the emulators file with Steve Kelly's Z80 cross assembler.
After a bit of work it compiled fine but the gameboy emulator refuses to load
it due to a bad file format. My question is the the author of the gameboy
file or whoever knows the answer :) :

	What kind of header do I have to put in the file for the emulator
to recognize the file as it's format? If anyone actually knows what I am
doing wrong please respond!

	My compileable source code follows:
-----------------------------------------------------------------------------

	org	0

; modifications for z80 argasm:
;
; even command
; dw's
; out (n),a
; cnops

SIZE_Y	equ	18
SIZE_X	equ	20


	ld	a,0+(char_set/256)
	ld	(60003),a
	ld	a,0+((char_set)&255)
	ld	(60002),a
	ld	a,0+(char_map/256)
	ld	(60001),a
	ld	a,0+((char_map)&255)
	ld	(60000),a

	ld	hl,char_map
	xor	a
	ld	bc,SIZE_Y*SIZE_X
loop
	ld	(hl),0	; clear the screen
	inc	hl
	dec	bc
	ld	a,b
	or	c
	jr	nz,loop

	ld	hl,char_map
	call	draw_wall
	ld	hl,char_map+11
	call	draw_wall

	call	random
	and	3
	ld	(next_shape),a

	ld	a,35
	ld	(tetris_speed),a
	ld	b,7
rep_loop
	xor	a
	ld	(char),a
	ld	a,15
	ld	(shape_x),a
	ld	a,14
	ld	(shape_y),a
	
	call	draw_nextshape
	ld	a,(next_shape)
	ld	(new_shape),a
	ld	(current_shape),a
get_another
	call	random
	and	7
	jr	z,get_another
	dec	a
	ld	(next_shape),a
	ld	a,2
	ld	(char),a
	call	draw_nextshape

	ld	a,5
	ld	(shape_x),a
	ld	(newshape_x),a
	ld	a,1
	ld	(shape_y),a
	ld	(newshape_y),a
	call	display_score

main_loop
	halt
	ld	a,(speed_count)
	and	3
	jp	nz,no_moving
	ld	a,(newshape_x)
	ld	c,a
	ld	a,(60004)
	and	3
	jr	nz,xmove_it
	xor	a
	ld	(lastmove),a
	jr	no_xmove
xmove_it
	ld	b,a
	ld	a,(lastmove)
	cp	b
	jr	nz,move_active
	ld	a,(move_count)
	inc	a
	and	7
	jr	nz,xwait
	call	inc_seed
	bit	0,b
	jr	z,noqleft
	dec	c
	jr	x_fin
noqleft	inc	c
	jr	x_fin
xwait
	ld	(move_count),a
	jr	nz,no_xmove
	bit	0,b
	jr	z,norepleft
	dec	c
	jr	x_fin
norepleft	inc	c
	jr	x_fin
move_active	ld	a,b
	ld	(lastmove),a
	xor	a
	ld	(move_count),a
	bit	0,b
	jr	z,noleft
	dec	c
	jr	x_fin
noleft	inc	c
x_fin
	ld	a,c
	ld	(newshape_x),a

	call	check_shape
	jr	nc,no_xmove
	ld	a,(shape_x)
	ld	(newshape_x),a
no_xmove
	ld	a,(lastfire)
	or	a
	jr	z,fire_con
	xor	a
	ld	(lastfire),a
	jp	no_fire
fire_con
	ld	a,(60004)
	bit	4,a
	jr	z,no_fire
	ld	a,1
	ld	(lastfire),a
	ld	a,(new_rot)
	inc	a
	and	3
	ld	(new_rot),a
	call	check_shape
	jr	nc,no_fire
	ld	a,(rotation)
	ld	(new_rot),a

no_fire

no_moving:
	call	update_shape

	ld	a,(60004)
	ld	c,a
	ld	a,(tetris_speed)
	ld	b,a
	bit	3,c
	jr	z,no_down
;*!
	ld	b,3
no_down
	ld	hl,speed_count
	inc	(hl)
	ld	a,(hl)
	cp	b
	jp	c,main_loop

	ld	(hl),0
	ld	a,(newshape_y)
	inc	a
	ld	(newshape_y),a
	call	check_shape
	jp	nc,main_loop

le_fin
	ld	a,(shape_y)
	cp	2
	jr	c,dead_meat
	ld	a,3
	ld	(char),a
	call	draw_shape
	call	scan_rows
	jr	z,none_completed
	push	hl
	call	flash_rows
	call	remove_rows
	pop	hl
	ld	a,l
	add	a,a
	ld	l,a
	add	a,a
	add	a,a
	add	a,l
	ld	c,a
	ld	b,0
	call	add_score
	ld	a,(tetris_speed)
	dec	a
	jr	z,none_completed
	ld	(tetris_speed),a
none_completed
	jp	rep_loop
dead_meat
	ld	hl,char_map+SIZE_X*SIZE_Y-1
	ld	c,SIZE_Y
splaty	halt
	ld	b,SIZE_X
splatx
	ld	(hl),1
	dec	hl
	djnz	splatx
	dec	c
	jr	nz,splaty
	

	db	0d3h	; stop program



display_score
	ld	hl,score
	ld	de,char_map+13+4*SIZE_X
	ld	b,5
copy_byte	ld	a,(hl)
	ld	(de),a
	inc	hl
	inc	de
	djnz	copy_byte
	ret

random
inc_seed	push	hl
	push	bc
	ld	hl,(seed1)
	ld	bc,(seed2)
	ld	a,l
	rla
	rl	h
	rla
	rl	h
	rla
	rl	h
	sub	7
	xor	c
	ld	l,a
	ld	(seed2),a
	ld	a,h
	ld	(seed2+1),a
	ld	a,c
	ld	(seed1),a
	ld	a,b
	ld	(seed1+1),a
	ld	a,l
	pop	bc
	pop	hl
	ret

draw_wall
	ld	de,SIZE_X
	ld	b,SIZE_Y
	ld	a,4
next_part
	ld	(hl),a
	add	hl,de
	djnz	next_part

	ret


scan_rows:
	ld	de,rowstoremove+3
	xor	a
	ld	(de),a
	dec	de
	ld	(de),a
	dec	de
	ld	(de),a
	dec	de
	ld	(de),a
	push	de

	ld	c,a
	ld	hl,char_map+1
	ld	b,SIZE_Y
do_nextrow
	push	bc
	push	hl
	ld	b,10
	xor	a
chk_nextbyte
	cp	(hl)
	jr	z,chk_nextrow
	inc	hl
	djnz	chk_nextbyte
; now remove the row
	ld	a,c
	ld	(de),a
	inc	de

chk_nextrow
	pop	hl
	ld	bc,SIZE_X
	add	hl,bc
	pop	bc
	inc	c
	djnz	do_nextrow
	pop	hl
	xor	a
	ex	de,hl
	sbc	hl,de
	ret

remove_rows
	ld	hl,rowstoremove
	ld	b,4
remove_next
	ld	a,(hl)
	call	remove_a_row
	inc	hl
	djnz	remove_next
	ret

remove_a_row
; a = number of row to remove
	push	bc
	push	hl
	or	a
	jr	z,row_0
	add	a,a
	add	a,a
	ld	c,a
	ld	l,a
	ld	h,0
	ld	b,h
	add	hl,hl
	add	hl,hl
	add	hl,bc
	ld	de,char_map-SIZE_X+10
	add	hl,de
	ld	e,l
	ld	d,h
	ld	bc,SIZE_X
	add	hl,bc

	srl	a
	srl	a
	ld	c,a
next_row
	ld	b,10
next_column
	ld	a,(de)
	ld	(hl),a
	dec	hl
	dec	de
	djnz	next_column
	ld	a,e
	sub	SIZE_X-10
	ld	e,a
	ld	a,d
	sbc	a,0
	ld	d,a
	ld	a,l
	sub	SIZE_X-10
	ld	l,a
	ld	a,h
	sbc	a,0
	ld	h,a
	dec	c
	jr	nz,next_row

	xor	a	; clear top row
row_0
	call	clear_row
	pop	hl
	pop	bc
	ret

flash_rows
; this routine flashes any full lines (if any exist)

	ld	hl,rowstoremove
	ld	de,temp_store
	ld	a,(hl)
	inc	hl
	call	store_row
	ld	a,(hl)
	inc	hl
	call	store_row
	ld	a,(hl)
	inc	hl
	call	store_row
	ld	a,(hl)
	inc	hl
	call	store_row

	ld	c,3

next_flash
	ld	b,8
pause1
	halt
	djnz	pause1
	ld	hl,rowstoremove
	ld	a,(hl)
	inc	hl
	call	clear_row
	ld	a,(hl)
	inc	hl
	call	clear_row
	ld	a,(hl)
	inc	hl
	call	clear_row
	ld	a,(hl)
	inc	hl
	call	clear_row

	ld	b,8
pause2
	halt
	djnz	pause2
	ld	hl,rowstoremove
	ld	de,temp_store
	ld	a,(hl)
	inc	hl
	call	restore_row
	ld	a,(hl)
	inc	hl
	call	restore_row
	ld	a,(hl)
	inc	hl
	call	restore_row
	ld	a,(hl)
	inc	hl
	call	restore_row

	dec	c
	jr	nz,next_flash	
	
	

fr_exit	ret


store_row
	push	hl
	push	bc
	add	a,a
	add	a,a
	ld	c,a
	ld	l,a
	ld	h,0
	ld	b,h
	add	hl,hl
	add	hl,hl
	add	hl,bc
	ld	bc,char_map+1
	add	hl,bc
	ld	b,10
next_copy
	ld	a,(hl)
	ld	(de),a
	inc	hl
	inc	de
	djnz	next_copy
	pop	bc
	pop	hl
	ret

restore_row
	push	hl
	push	bc
	add	a,a
	add	a,a
	ld	c,a
	ld	l,a
	ld	h,0
	ld	b,h
	add	hl,hl
	add	hl,hl
	add	hl,bc
	ld	bc,char_map+1
	add	hl,bc
	ld	b,10
next_copy2
	ld	a,(de)
	ld	(hl),a
	inc	hl
	inc	de
	djnz	next_copy2
	pop	bc
	pop	hl
	ret


clear_row
	push	hl
	push	bc
	add	a,a
	add	a,a
	ld	c,a
	ld	l,a
	ld	h,0
	ld	b,h
	add	hl,hl
	add	hl,hl
	add	hl,bc
	ld	bc,char_map+1
	add	hl,bc
	ld	b,10
	xor	a
next_clear
	ld	(hl),a
	inc	hl
	djnz	next_clear
	pop	bc
	pop	hl
	ret



check_shape
	ld	a,(new_rot)
	ld	b,a
	ld	a,(new_shape)
	call	calc_addr
	ld	b,4	; 4 blocks

; hl now points to the shape offsets
check_it
	ld	de,(newshape_x)
	ld	a,(hl)
	add	a,e
	cp	SIZE_X
	jr	nc,check_error	; off limits
	ld	e,a
	inc	hl
	ld	a,(hl)
	add	a,d
	cp	SIZE_Y
	jr	nc,check_error
	ld	d,a
	inc	hl

	push	hl
	push	bc
	ld	a,d
	add	a,a
	add	a,a
	ld	c,a
	ld	l,a
	ld	h,0
	ld	b,h
	add	hl,hl
	add	hl,hl
	add	hl,bc
	ld	a,l
	add	a,e
	ld	l,a
	ld	a,h
	adc	a,0
	ld	h,a

	ld	de,char_map
	add	hl,de

	ld	a,(hl)
	pop	bc
	pop	hl
	cp	2
	jr	z,no_check
	or	a	; overwriting something
	jr	nz,check_error
no_check

	djnz	check_it
	xor	a
	ret
check_error	scf
	ret

calc_addr
	add	a,a
	add	a,a
	add	a,a
	add	a,a
	add	a,a
	ld	e,a
	ld	d,0
	ld	hl,shapes
	add	hl,de
	ld	a,b
	add	a,a
	add	a,a
	add	a,a
	add	a,l
	ld	l,a
	ld	a,h
	adc	a,0
	ld	h,a
	ret

draw_nextshape
	xor	a
	ld	b,a
	ld	a,(next_shape)
	jp	drawnext

draw_shape
	ld	a,(rotation)
	ld	b,a
	ld	a,(current_shape)
drawnext
	call	calc_addr
	ld	b,4	; 4 blocks

; hl now points to the shape offsets
loop_it
	ld	de,(shape_x)
	ld	a,(hl)
	add	a,e
	ld	e,a
	inc	hl
	ld	a,(hl)
	add	a,d
	ld	d,a
	inc	hl

	call	draw_square

	djnz	loop_it
	ret




draw_square
; de = y,x
	push	bc
	push	hl
	ld	a,d
	add	a,a
	add	a,a
	ld	c,a
	ld	l,a
	ld	h,0
	ld	b,h
	add	hl,hl
	add	hl,hl
	add	hl,bc

	ld	bc,char_map
	add	hl,bc
	ld	a,e
	add	a,l
	ld	l,a
	ld	a,h
	adc	a,0
	ld	h,a

	ld	a,(char)
	ld	(hl),a
	pop	hl
	pop	bc

	ret


update_shape
	xor	a
	ld	(char),a
	ld	hl,(newshape_x)
	ld	de,(shape_x)
	sbc	hl,de
	jr	nz,has_changed

	ld	a,(new_rot)
	ld	b,a
	ld	a,(rotation)
	cp	b
	ret	z
has_changed
	call	draw_shape	; delete old shape
	ld	a,(newshape_x)
	ld	(shape_x),a
	ld	a,(newshape_y)
	ld	(shape_y),a
	ld	a,(new_shape)
	ld	(current_shape),a
	ld	a,(new_rot)
	ld	(rotation),a
	ld	a,2
	ld	(char),a
	call	draw_shape
	ret

inc_score	ld	hl,score+4
inc_next
	inc	(hl)
	ld	a,(hl)
	cp	5+10
	ret	c
	ld	(hl),5
	dec	hl
	jp	inc_next

add_score
	call	inc_score	; look at this for crap code
	dec	bc		; who gives a shit though?
	ld	a,b
	or	c
	jp	nz,add_score
	ret


temp_store	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
rowstoremove	db	0,0,0,0,0
move_count	db	0
lastmove	db	0
lastfire	db	0
shape_x	db	0
shape_y	db	0
current_shape	db	0
rotation	db	0
char	db	0
next_shape	db	0

newshape_x	db	0
newshape_y	db	0
new_shape	db	0
new_rot	db	0

tetris_speed	db	0
speed_count	db	0
seed1	dw	0
seed2	dw	0

score	db	5,5,5,5,5

shapes
shape1	
; long
	db	-1,0,0,0,1,0,2,0
	db	0,-1,0,0,0,1,0,2
	db	1,0,0,0,-1,0,-2,0
	db	0,1,0,0,0,-1,0,-2

shape2	
; square
	db	0,0,0,1,1,1,1,0
	db	0,0,0,1,1,1,1,0
	db	0,0,0,1,1,1,1,0
	db	0,0,0,1,1,1,1,0
shape3	
; s-shape 1
	db	-1,1,0,1,0,0,1,0
	db	-1,-1,-1,0,0,0,0,1
	db	-1,1,0,1,0,0,1,0
	db	-1,-1,-1,0,0,0,0,1
shape4	
; s-shape 2
	db	-1,-1,0,-1,0,0,1,0
	db	1,-1,1,0,0,0,0,1
	db	-1,-1,0,-1,0,0,1,0
	db	1,-1,1,0,0,0,0,1
shape5	
; l-shape 1
	db	0,-1,0,0,0,1,1,1
	db	-1,1,-1,0,0,0,1,0
	db	-1,-1,0,-1,0,0,0,1
	db	-1,0,0,0,1,0,1,-1
shape6	
; l-shape 2
	db	-1,0,0,0,1,0,1,1
	db	0,-1,0,0,0,1,-1,1
	db	-1,-1,-1,0,0,0,1,0
	db	1,-1,0,-1,0,0,0,1
shape7	
; t-shape
	db	-1,0,0,0,1,0,0,1
	db	0,-1,0,0,0,1,-1,0
	db	-1,0,0,0,1,0,0,-1
	db	0,-1,0,0,0,1,1,0


	ds	$&1

char_map	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

	ds	$&1
char_set	db	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	db	170,0,85,0,170,0,85,0
	db	170,0,85,0,170,0,85,0
	db	255,0,129,36,129,126,129,36
	db	129,36,129,126,129,36,255,0
	db	255,0,129,36,129,126,129,36
	db	129,36,129,126,129,36,255,0
	db	255,255,16,255,16,255,16,255
	db	255,255,66,255,66,255,66,255

	db	00000000b,0
	db	01111100b,0
	db	11001110b,0
	db	11011110b,0
	db	11110110b,0
	db	11100110b,0
	db	11000110b,0
	db	01111100b,0

	db	00000000b,0
	db	00110000b,0
	db	01110000b,0
	db	11110000b,0
	db	00110000b,0
	db	00110000b,0
	db	00110000b,0
	db	11111100b,0

	db	00000000b,0
	db	01111000b,0
	db	11000110b,0
	db	00001100b,0
	db	00011000b,0
	db	01100000b,0
	db	11000000b,0
	db	11111110b,0

	db	00000000b,0
	db	11111110b,0
	db	00001100b,0
	db	00011000b,0
	db	00000110b,0
	db	00000110b,0
	db	11000110b,0
	db	01111100b,0

	db	00000000b,0
	db	00001100b,0
	db	00011100b,0
	db	00111100b,0
	db	01101100b,0
	db	11001100b,0
	db	11111110b,0
	db	00001100b,0

	db	00000000b,0
	db	11111110b,0
	db	11000000b,0
	db	11111100b,0
	db	00000110b,0
	db	00000110b,0
	db	11000110b,0
	db	01111100b,0

	db	00000000b,0
	db	01110000b,0
	db	11000000b,0
	db	11111100b,0
	db	11000110b,0
	db	11000110b,0
	db	11000110b,0
	db	01111100b,0

	db	00000000b,0
	db	11111110b,0
	db	00000110b,0
	db	00001100b,0
	db	00011000b,0
	db	00011000b,0
	db	00011000b,0
	db	00011000b,0

	db	00000000b,0
	db	01111100b,0
	db	11000110b,0
	db	01111100b,0
	db	11000110b,0
	db	11000110b,0
	db	11000110b,0
	db	01111100b,0

	db	00000000b,0
	db	01111110b,0
	db	11000110b,0
	db	11000110b,0
	db	00111110b,0
	db	00000110b,0
	db	00000110b,0
	db	00000110b,0

-------------------------------------------------------------------------------
    .....           .     .    * iwoehr@isis.UUCP
    :    :          :.   .:    * "Not to be confused with jwoehr@isis"
    :....: article  : : : : an * -----------------------------------------
    :               :  :  :    * Descartes walks into a bar. The bartender
    :     A.K.A.    :  :  :    * asks 'Do you want a beer?'. Descartes
       -Ivan Woehr-            * replies 'I think not,' and disappears.

jms@vanth.UUCP (Jim Shaffer) (04/24/91)

Why don't you compile a clue?  If you'd read comp.sys.amiga.emulations,
you'd know that you're not even supposed to HAVE the "Gameboy emulator."
For one thing, it's not really a gameboy emulator, for another thing, the
author did NOT give anyone permission to distribute it, it was STOLEN.

--
*  From the disk of:  | jms@vanth.uucp		     | "You know I never knew
Jim Shaffer, Jr.      | amix.commodore.com!vanth!jms | that it could be so
37 Brook Street       | uunet!cbmvax!amix!vanth!jms  | strange..."
Montgomery, PA 17752  | 72750.2335@compuserve.com    |		     (R.E.M.)

v089pfrb@ubvmsb.cc.buffalo.edu (Jeffrey C Murphy) (04/24/91)

In article <1991Apr22.025414.28417@mnemosyne.cs.du.edu>, iwoehr@isis.cs.du.edu (Ivan Woehr) writes...
> 
>	I have just succesfully compiles the Tetris.z80 code that was
>included in the emulators file with Steve Kelly's Z80 cross assembler.
>After a bit of work it compiled fine but the gameboy emulator refuses to load
>it due to a bad file format. My question is the the author of the gameboy
>file or whoever knows the answer :) :


 The archive came with the emulator, tetris.z80 and tetris. Load the file
called 'tetris' NOT 'tetris.z80'. The emulator also makes use of some opcodes
that don't exist on the 68K so you will need something better (i believe it
works on anything above a 68010). If you run the emulator on a 68000 it will
crash. 

l8r
jm

(sheez did you have to post that long source listing?)