; modified version of gba (optimised version) gba_initmap: ld bc,0 ld (temp),bc ld hl,Carte_addr ld bc,(scroll_x) add hl,bc ld bc,(map_width) ld de,(scroll_y) call gba_hl_plus_dexbc ld (mask_y),a ; a=0 ld (mask_x2),a ld a,%10000000 ld (mask_x),a ld de,APD_BUF ld b,12 Initcarte_ligne: ld c,8 push de push hl Initcarte_colonne: push bc push hl call gba_find_tile Findujeu_repere = $-2 ld a,8 Dessinbloc_8xa: ld b,(hl) inc hl ex de,hl ld (hl),b ld bc,12 add hl,bc ex de,hl dec a jr nz,Dessinbloc_8xa ld a,8 ld hl,temp add a,(hl) ld (hl),a pop hl ld bc,(map_width) add hl,bc pop bc dec c jr nz,Initcarte_colonne ld hl,temp ld (hl),0 ld a,8 inc hl add a,(hl) ld (hl),a pop hl inc hl pop de inc de djnz Initcarte_ligne ret gba_hl_plus_dexbc: add hl,de dec bc ld a,b or c jr nz,gba_hl_plus_dexbc ret ;******************************** SCROLL HORIZONTAL *************************************** gba_scroll_right: ld hl,(map_width) ld de,(scroll_x) or a sbc hl,de ld de,13 sbc hl,de ret c ld a,spritemax ld hl,Table_sprite+4 ld de,8 Scrolld_sprite: dec (hl) add hl,de dec a jr nz,Scrolld_sprite ld hl,arme2loc+1 dec (hl) ld bc,$5f00 ld (temp),bc ld hl,APD_BUF+11 ld b,64 SD_boucle: sla (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl ld de,24 add hl,de djnz SD_boucle ld a,%00000001 ld (temp3),a ld hl,Carte_addr+12 ld de,APD_BUF+11 call gba_scroll_horizontal ld a,(mask_x2) inc a and %111 ld (mask_x2),a ld a,(mask_x) srl a ld (mask_x),a ret nc ld a,%10000000 ld (mask_x),a ld bc,(scroll_x) inc bc ld (scroll_x),bc or a ret gba_scroll_left: ld a,(mask_x) cp %10000000 jr nz,SG_verifok ld hl,(scroll_x) ld de,1 sbc hl,de ret c SG_verifok: ld a,spritemax ld hl,Table_sprite+4 ld de,8 Scrollg_sprite: inc (hl) add hl,de dec a jr nz,Scrollg_sprite ld hl,arme2loc+1 inc (hl) ld a,(mask_x) ld b,-2 temp_boucle: inc b add a,a jr nc,temp_boucle ld a,b and %111 neg ld b,a ld c,0 ld (temp),bc ld hl,APD_BUF ld b,64 SG_boucle: srl (hl) inc hl rr (hl) inc hl rr (hl) inc hl rr (hl) inc hl rr (hl) inc hl rr (hl) inc hl rr (hl) inc hl rr (hl) inc hl rr (hl) inc hl rr (hl) inc hl rr (hl) inc hl rr (hl) inc hl djnz SG_boucle ld a,(mask_x2) dec a and %111 ld (mask_x2),a ld a,(mask_x) add a,a jr nc,SG_suite ld a,%00000001 ld bc,(scroll_x) dec bc ld (scroll_x),bc SG_suite: ld (mask_x),a ld a,%10000000 ld (temp3),a ld hl,Carte_addr ld de,APD_BUF call gba_scroll_horizontal or a ret gba_scroll_horizontal: push de ld bc,(scroll_x) add hl,bc ld bc,(map_width) ld de,(scroll_y) call gba_hl_plus_dexbc pop de ld a,(mask_y) sub 8 neg call gba_colonne_1xa ld b,7 SH_boucle2: push bc ld a,8 call gba_colonne_1xa pop bc djnz SH_boucle2 ld a,(mask_y) or a ret z gba_colonne_1xa: push hl push af ld bc,Colonne_preboucle push bc ld a,(temp) or a jp nz,gba_find_tile ld a,(mask_y) neg ld (temp),a call gba_find_tile xor a ld (temp),a ld bc,(mask_y) ld b,0 add hl,bc ret Colonne_preboucle: pop af Colonne_boucle: push af ld a,(mask_x) and (hl) jr z,Colonne_suite ex de,hl ld a,(temp3) or (hl) ld (hl),a ex de,hl Colonne_suite: inc hl ex de,hl ld bc,(temp) inc c ld (temp),bc ld bc,12 add hl,bc ex de,hl pop af dec a jr nz,Colonne_boucle pop hl ld bc,(map_width) add hl,bc ret ;********************************* SCROLL VERTICAL *************************************** gba_scroll_up: ld a,(mask_y) or a jr nz,SH_verifok ld hl,(scroll_y) ld de,1 sbc hl,de ret c SH_verifok: ld a,spritemax ld hl,Table_sprite+3 ld de,8 Scrollh_sprite: inc (hl) add hl,de dec a jr nz,Scrollh_sprite ld hl,arme2loc inc (hl) ld a,(mask_y) dec a and %111 neg ld c,a ld b,0 ld (temp),bc ld bc,768 ld hl,APD_BUF+755 ld de,APD_BUF+767 lddr ld a,(mask_y) dec a and %111 ld (mask_y),a cp 7 jr nz,SH_suite ld bc,(scroll_y) dec bc ld (scroll_y),bc SH_suite: ld a,(APD_BUF+12) ld (temp3),a ld hl,Carte_addr ld de,(scroll_x) add hl,de ld bc,(map_width) ld de,(scroll_y) call gba_hl_plus_dexbc ld de,APD_BUF call gba_scroll_vertical ld a,(temp3) ld (hl),a or a ret gba_scroll_down: ld hl,(map_height) ld de,(scroll_y) or a sbc hl,de ld de,8 or a sbc hl,de ret c ld a,spritemax ld hl,Table_sprite+3 ld de,8 Scrollb_sprite: dec (hl) add hl,de dec a jr nz,Scrollb_sprite ld hl,arme2loc dec (hl) ld a,(mask_x2) neg ld (temp2),a ld a,63 ld (temp),a ld bc,768 ld hl,APD_BUF+12 ld de,APD_BUF ldir ld a,(de) ld (temp3),a ld bc,64 ; b=0 c=64 call gba_collision ld de,APD_BUF+756 call gba_scroll_vertical ld a,(temp3) ld (hl),a ld a,(mask_y) inc a and %111 ld (mask_y),a ret nz ld hl,(scroll_y) inc hl ld (scroll_y),hl or a ret gba_scroll_vertical: ld b,13 SV_boucle: push bc push hl push af ; utilisé pour Camera_up call gba_find_tile pop af ld bc,(mask_y) ld b,0 add hl,bc ld a,(hl) ld (de),a inc de ld bc,8 ld hl,(temp2) add hl,bc ld (temp2),hl pop hl inc hl pop bc djnz SV_boucle dec de ex de,hl ld a,(mask_x2) or a ret z SV_boucle2: push hl sla (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) dec hl rl (hl) pop hl dec a jr nz,SV_boucle2 ret gba_collision: ; entrée: - bc: coords x et y, positives ld hl,Carte_addr ; ou négatives, d'un point de ld de,(scroll_x) ; l'écran (0,0) en haut à gauche add hl,de ; sortie: - hl pointe sur le bloc qui contient ld a,(mask_x2) ; le point add a,b ; - a=(hl) numéro de ce bloc sra a \ sra a \ sra a ; détruit: - af,bc,de,hl ld e,a ld d,0 bit 7,a jr z,Collision_suite dec d Collision_suite: add hl,de ld de,(scroll_y) ld a,(mask_y) add a,c sra a \ sra a \ sra a ld b,0 ld c,a bit 7,a jr z,Collision_suite2 dec b Collision_suite2: ex de,hl add hl,bc ex de,hl ld bc,(map_width) call gba_hl_plus_dexbc ld a,(hl) ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GESTION DES SPRITES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; gba_find_tile: push de push hl ld hl,Carte_addr ld de,(map_width) ld bc,(map_height) push af call gba_hl_plus_dexbc pop af ex de,hl pop hl or a sbc hl,de push af add hl,de pop af pop de ret nc ld b,a ld a,(hl) cp 210 jr nc,Sprite_nouveau cp num_blocs2 jr c,Bloc_normal Bloc2: ld a,b ld hl,Blocs ret Bloc_normal: ld a,b Bloc_normal2: ld l,(hl) ld h,0 add hl,hl add hl,hl add hl,hl ld bc,Blocs add hl,bc ret Sprite_nouveau: push de push bc ld bc,gba_fin_sprite push bc and %1 ret nz inc (hl) push hl call gba_findsprite pop de ret nz ld (hl),e inc hl ld (hl),d inc hl ex de,hl ld a,211 sub (hl) neg ld c,a ex de,hl ld (hl),a inc hl ld a,(temp) ld (hl),a inc hl ld a,(temp2) ld (hl),a inc hl ex de,hl ld a,c jp Nouveau_sprite gba_fin_sprite: pop bc pop de jr Bloc2 gba_findsprite: ld hl,Table_sprite ld de,8 ld b,spritemax CHCHSPR_boucle: push hl ld a,(hl) inc hl or (hl) inc hl pop hl ret z add hl,de djnz CHCHSPR_boucle or a ret gba_initsprite: ; réinitialise la carte et la liste ld hl,0 ; des sprites ld de,(map_width) ld bc,(map_height) call gba_hl_plus_dexbc ex de,hl ld hl,Carte_addr IS_boucle: ld a,210 cp (hl) jr nc,ISboucle_suite ld a,%11111110 and (hl) ld (hl),a ISboucle_suite: inc hl dec de ld a,d or e jr nz,IS_boucle ld hl,Table_sprite ld de,7 ld b,spritemax IS_boucle2: ld (hl),0 inc hl ld (hl),0 add hl,de djnz IS_boucle2 ret gba_drawinverted: push hl ld hl,repere ld (hl),$2f ; cpl inc hl ld (hl),$a8 ; xor b pop hl call gba_drawsprite ld hl,repere ld (hl),0 inc hl ld (hl),0 ret gba_drawsprite: bit 7,b ret nz ld a,12 sub d add a,a add a,a add a,a sub b ret c bit 7,c jr z,Cliphaut_ok Cliphaut_boucle: dec e ret z ld a,d add a,a CH_boucle2: inc hl dec a jr nz,CH_boucle2 inc c jr nz,Cliphaut_boucle Cliphaut_ok: ld a,56 sub c ret c ret z cp e jr nc,Clip_ok ld e,a Clip_ok: push de push hl ld hl,GRAPH_MEM-12 inc c ld de,12 Trouver_ligne: add hl,de dec c jr nz,Trouver_ligne ld a,b Trouver_colonne: sub 8 jr c,Findpixel_fin inc hl jr Trouver_colonne Findpixel_fin: add a,8 ld (temp3),a pop de pop bc PSM_colonne: push bc push hl PSM_ligne: push bc ld a,(de) ld b,a ld c,%11111111 inc de push de ld a,(de) repere: nop ; utilisé pour la routine gba_drawinverted nop ld d,a ld e,0 ld a,(temp3) or a jr z,PSM_fin PSM_Rotation: scf rr b rr c srl d rr e dec a or a jr nz,PSM_Rotation PSM_fin: ld a,(hl) and b or d ld (hl),a inc hl ld a,(hl) and c or e ld (hl),a pop de inc de pop bc djnz PSM_ligne pop hl ld bc,12 add hl,bc pop bc dec c jr nz,PSM_colonne ret .end