pouët.net

balls, touching by HOOY-PROGRAM [web]

; balls, touching
; 
; a party-coded 128b intro by Gasman / H-Prg
; for Outline 2011

	org 0x8000
	
CALC_DELETE		equ 0x02
CALC_MULTIPLY	equ 0x04
CALC_ADDITION	equ 0x0f
CALC_SIN		equ 0x1f
CALC_INT		equ 0x27
CALC_DUPLICATE	equ 0x31
CALC_CONST		equ 0x34
CALC_STK_ZERO	equ 0xa0
CALC_ST_MEM_0	equ 0xc0
CALC_END_CALC	equ	0x38

sine	equ 0xf800

; Generate a sine table
	rst 0x28
	db CALC_STK_ZERO
	db CALC_END_CALC

	ld hl,sine
sinelp
	push hl

	rst 0x28
; the accurate version
;	db CALC_CONST, 0xeb, 0x49, 0x0f, 0xda, 0xd8 ;const pi/128
; the less accurate version
;	db CALC_CONST, 0x6b, 0x49, 0x10 ;const pi/128
; the inaccurate but good enough version
	db CALC_CONST, 0x2b, 0x49 ;const pi/128
	db CALC_ADDITION
	db CALC_DUPLICATE
	db CALC_SIN
	db CALC_CONST, 0x37, 0x7e		; const 127
	db CALC_MULTIPLY
	db CALC_INT
	db CALC_ST_MEM_0
	db CALC_DELETE
	db CALC_END_CALC
	ld a,(iy+0x5a)			; third byte of calculator memory 0
	pop hl
	ld (hl),a
	inc l
	jr nz,sinelp

demolp
	halt
	
	ld hl,sine2pos+1
	inc (hl)

sinepos
	ld hl,sine
	inc l
	inc l
	ld (sinepos+1),hl
	
	ld b,8
dotslp
	push bc
	push hl
	
	push hl	; save sinepos
	
	ld a,(hl)
	
	; a = ypos; convert to screen address
	add a,0x80	; make unsigned
	;and 0xf8	; most significant 5 bits
	and h
	ld l,a
	ld h,0x58/2
	add hl,hl
;	add hl,hl
;	ld de,0x5840
;	add hl,de
	ex (sp),hl	; save y address, recall sinepos
	
cospos
	ld a,0x40
	add a,l
	ld l,a
	ld e,(hl)
	
sine2pos
	ld l,0x40
	ld a,(hl)
	sra a
	ld d,a
	
;	ld c,0

	ld a,e
	neg
	jp m,no_neg_e
	ld e,a
	dec c	; c = 255
no_neg_e
	sla e
	
	xor a
	ld h,a
	ld b,8
mul_lp
	sra d
	sla e
	jr nc,skip_mul
	add a,d
skip_mul
	djnz mul_lp
	xor c
	
	; a = xpos; convert to screen address
	
	;sra a	; /2
	add a,0x80	; make positive
	srl a
	srl a
	srl a
	ld l,a
	;ld h,0
	
	pop de	; recall y address
	add hl,de
	ld (hl),0x3f
	pop hl
	pop bc
	ld a,32
	add a,l
	ld l,a
	djnz dotslp
	
	; fade
;	ld hl,0x5800
;	ld b,0x03
	ld hl,0x5704
	ld b,l
fadelp
	dec (hl)
	jr nz,no_unfade
;	jp p,no_unfade
	inc (hl)
no_unfade
	cpi
	jp pe,fadelp
	jr demolp