You are on page 1of 5

; ZLib v1.6 .nolist .org #include #define data .list .dw .dw .dw .dw .dw .dw .

dw .dw .dw .dw .dw .dw .dw .dw .dw .dw

$0000 "joeti83.inc" cmdshad+38 beep sprite rand getbit detect error decomp error error error error error getpix hiscr error version ; ; ; ; ; ; 2 bytes of data

beep 0 draw a sprite 1 random number 2 get the bit for a pixel 3 detect a program in the vat 4

; decompress level data 6

; find a pixel C ; check for/set high score D

;---------= Make a sound =--------; c=frequency, b=duration beep: di ld e,$D0 beepl1: ld a,c beepl2: dec a jr nz,beepl2 ld a,e xor %00000011 ld e,a out (0),a djnz beepl1 ei error: ret ;---------= XOR a sprite =--------; b=size of sprite ; l=yc ; a=xc ; ix holds pointer sprite: ld e,l ld h,$00 ld d,h add hl,de add hl,de add hl,hl add hl,hl ld e,a and $07 ld c,a srl e srl e srl e add hl,de

sl1:

sl2:

sl3:

ld add ld ld ld or jr srl rr dec jr ld xor ld inc ld xor ld ld add inc djnz ret

de,gbuf hl,de d,(ix) e,$00 a,c a z,sl3 d e a nz,sl2 a,(hl) d (hl),a hl a,(hl) e (hl),a de,$0B hl,de ix sl1

;---------= Random number generator =--------; input b=upper bound ; ouput a=answer 0<=a<b ; all registers are preserved except: af and bc rand: push hl push de ld hl,(data) ld a,r ld d,a ld e,(hl) add hl,de add a,l xor h ld (data),hl ld hl,0 ld e,a ld d,h randl: add hl,de djnz randl ld a,h pop de pop hl nomore: ret ;---------= Get location of a pixel =--------; input: e=y coordinate ; a=x coordinate ; output: a holds data for pixel (e.g. %00100000) ; hl->byte where pixel is on the gbuf getpix: ld d,$00 ld h,d ld l,e add hl,de add hl,de add hl,hl add hl,hl

ld add ;---------= Get ; input: ; ; returns: ; ; ; getbit: ld ld and srl srl srl add ld inc ld gblp: rrca djnz ret

de,gbuf hl,de the bit for a pixel =--------a - x coordinate hl - start location ; includes gbuf a - holds bit hl - location + x coordinate/8 b=0 c=a/8 b,$00 c,a %00000111 c c c hl,bc b,a b a,%00000001 gblp

;---------= Detect Program =--------; input: ; hl=place to start looking ; ix->first line of data (0 terminated) ; output: ; de=place stopped + 1 ; hl->program data (after the string) ; z=0 if found, z=1 if not found. ; most registers are messed up detect: chgwlp: push hl ; in case a program is found ld a,(hl) ; but no good. and %00011111 dec a ; 1 jr z,list cp $0D-1 ; D jr z,list sub 4 ; 5 jr z,list dec a ; 6 jr z,cwchck pop hl ret cwchck: dec hl ; move to ptr (skip var type) ld b,(hl) dec hl push hl ld h,(hl) ld l,b ; now we are at the program inc hl ; skip file length inc hl push ix pop de ckprog: ld a,(de) cp (hl) jr nz,nogood

inc inc ld or jr ex pop dec ld inc snamel: dec djnz ex pop xor ret nogood: pop list: pop dec dec dec ld inc lnamel: dec djnz jr

de hl a,(de) a nz,ckprog de,hl hl ; back at the fat hl b,(hl) b hl snamel de,hl af a hl hl hl hl hl b,(hl) b hl lnamel chgwlp

;---------= Decompress =--------; input: ; hl->compressed data ; de->place to load data ; b=length of compressed data ; c=compression factor (1, 3, or 15) ; output: ; level is decompressed ; hl->next byte of compressed data decomp: di decompLoop: push bc ld a,(hl) ex af,af' ld a,c ld b,8 cp 1 jr z,dcmp1 ld b,4 cp 3 jr z,dcmp1 ld b,2 dcmp1: push bc ld a,c ld b,1 cp 1 jr z,dcmp2 inc b cp 3 jr z,dcmp2 ld b,4 dcmp2: ex af,af' dcmp3: rlca

djnz ld ex ld and ld inc pop djnz inc pop djnz ret

dcmp3 b,a af,af' a,b c (de),a de bc dcmp1 hl bc decompLoop

;---------= High Score =--------; Input: de=previous high score ; hl=current score ; Output: hl=high score ; z=1 (a=0) if new high score, z=0 (a=1) if not ; Registers destroyed: af, de, hl hiscr: push hl xor a sbc hl,de pop hl jr z,nnhs jr nc,nhs nnhs: ex de,hl inc a ret nhs: or a ret ;---------= Get Version =--------;Input: nothing ;Output: h=major,l=minor version: ld hl,1*256+6 ret .end END

You might also like