
; Storm C Compiler
; OS_:HD/Work/Up/CDDB-lib/demo/TestCDDB.c


	XREF	_exit
	XREF	_printf
	XREF	_std__in
	XREF	_std__out
	XREF	_std__err
	XREF	_SysBase

	SECTION ":0",CODE


;void fail(char *str)
	XDEF	_fail
_fail
L17	EQU	0
	link	a5,#L17
	movem.l	a2/a6,-(a7)
	move.l	$8(a5),a2
L12
;    if (CDDBbase) 
	tst.l	_CDDBbase
	beq.b	L14
L13
;    if (CDDBbase) CloseLibrary(CDDBbase);
	move.l	_CDDBbase,a1
	move.l	_SysBase,a6
	jsr	-$19E(a6)
L14
;    if (str) 
	cmp.w	#0,a2
	beq.b	L16
L15
;    if (str) 
;        printf(str);
	move.l	a2,-(a7)
	jsr	_printf
	addq.w	#4,a7
;	exit(20);
	pea	$14.w
	jsr	_exit
	addq.w	#4,a7
L16
;    exit(0);
	clr.l	-(a7)
	jsr	_exit
	addq.w	#4,a7
	movem.l	(a7)+,a2/a6
	unlk	a5
	rts

;void init(void)
	XDEF	_init
_init
L23	EQU	0
	link	a5,#L23
	move.l	a6,-(a7)
L20
;	if (!(CDDBbase = OpenLibrary("cddb.library", 44)))
	move.l	_SysBase,a6
	moveq	#$2C,d0
	lea	L18(pc),a1
	jsr	-$228(a6)
	move.l	d0,_CDDBbase
	tst.l	_CDDBbase
	bne.b	L22
L21
;		fail("Failed to open cddb.library.");
	move.l	#L19,-(a7)
	jsr	_fail
	addq.w	#4,a7
L22
	move.l	(a7)+,a6
	unlk	a5
	rts

;void main(void)
	XDEF	_main
_main
L34	EQU	-$26A
	link	a5,#L34
	movem.l	d2/a6,-(a7)
L27
;	init();
	jsr	_init
; errStr = NULL;
	clr.l	-4(a5)
;	for (i=0;
	moveq	#0,d2
	bra.b	L29
L28
;	
;	  CDDB_ErrorStr(i, &errStr);
	move.l	_CDDBbase,a6
	move.l	d2,d0
	lea	-4(a5),a0
	jsr	-$30(a6)
;	  printf("errStr = '%s'\n", errStr);
	move.l	-4(a5),-(a7)
	move.l	#L24,-(a7)
	jsr	_printf
	addq.w	#$8,a7
	addq.l	#1,d2
L29
	cmp.l	#$C,d2
	blt.b	L28
L30
;	CDDB_LoadKnownCD (0x00129C13, &kcd);
	move.l	_CDDBbase,a6
	move.l	#$129C13,a0
	lea	-$260(a5),a1
	jsr	-$24(a6)
;	printf("kcd: length %ld, %ld tracks,artist '%s', title '%s'\n",
	lea	-$260(a5),a0
	pea	$6C(a0)
	lea	-$260(a5),a0
	pea	$8(a0)
	move.w	-$25A(a5),d0
	ext.l	d0
	move.l	d0,-(a7)
	move.w	-$25C(a5),d0
	ext.l	d0
	move.l	d0,-(a7)
	move.l	#L25,-(a7)
	jsr	_printf
	add.w	#$14,a7
;   for (tr=0;
	moveq	#0,d2
	bra.b	L32
L31
;   
;     track = kcd.track[tr];
	lea	-$260(a5),a0
	move.w	d2,d0
	ext.l	d0
	lea	$D0(a0),a0
	asl.l	#2,d0
	move.l	0(a0,d0.l),a0
;     printf("  %02ld: %02ld '%s'\n", tr+1, track->length,track-
	move.l	a0,-(a7)
	move.w	$64(a0),d0
	ext.l	d0
	move.l	d0,-(a7)
	move.w	d2,d0
	ext.l	d0
	addq.l	#1,d0
	move.l	d0,-(a7)
	move.l	#L26,-(a7)
	jsr	_printf
	add.w	#$10,a7
	addq.w	#1,d2
L32
	cmp.w	-$25A(a5),d2
	blt.b	L31
L33
;	CloseLibrary (CDDBbase);
	move.l	_CDDBbase,a1
	move.l	_SysBase,a6
	jsr	-$19E(a6)
	movem.l	(a7)+,d2/a6
	unlk	a5
	moveq	#0,d0
	rts

L26
	dc.b	'  %02ld: %02ld '%s'',$A,0
L19
	dc.b	'Failed to open cddb.library.',0
L18
	dc.b	'cddb.library',0
L24
	dc.b	'errStr = '%s'',$A,0
L25
	dc.b	'kcd: length %ld, %ld tracks,artist '%s', title '%s'',$A,0

	SECTION ":1",DATA

_errNoError
	dc.l	0
_errNoTCPStack
	dc.l	1
_errResolve
	dc.l	2
_errSocket
	dc.l	3
_errConnect
	dc.l	4
_errServerError
	dc.l	5
_errHello
	dc.l	6
_errQuery
	dc.l	7
_errQNoMatch
	dc.l	$8
_errQInexactMatch
	dc.l	$9
_errNoTags
	dc.l	$A
_errNoCDInfo
	dc.l	$B
_errCOUNT
	dc.l	$C

	SECTION ":2",BSS

	XDEF	_CDDBbase
_CDDBbase
	ds.l	1

	END
