0 Members and 3 Guests are viewing this topic.
;calcmaniac84cpHLDE: or a sbc hl,de add hl,de ret;Important note: because the code is 3 bytes and a call is 3 bytes, just macro in:;SPASM, TASM and BRASS compatible, I guess#define cp_HLDE or a \ sbc hl,de \ add hl,de;- Reverse a;input: Byte in A;output: Reversed byte in A;destroys B;Clock cycles: 66;Bytes: 18;author: calcmaniac84reversea: ld b,a rrca rrca xor b and %10101010 xor b ld b,a rrca rrca rrca rrca xor b and %01100110 xor b rrca ret;reverse hl;curiosity: a easy port of a common reverse A register is more efficient than tricky stuff;calcmaniac84;28 bytes and 104 cyclesld a,lrlarr hrlarr hrlarr hrlarr hrlarr hrlarr hrlarr hrlarr hrlarrcald l,aret;calc84maniac;in: a = ABCDEFGH;out: hl= AABBCCDDEEFFGGHHrrcarrarrald l,arrasra lrlarr lsra lrrarr lsra lrrcarrarrald h,arrasra hrlarr hsra hrrarr hsra hret
;Galandros optimized routines;try to beat me... maybe is possible...;Displays A register content on screen in decimal ASCII number, using no addition memoryDispA: ld c,-100 call Na1 ld c,-10 call Na1 ld c,-1Na1: ld b,'0'-1Na2: inc b add a,c jr c,Na2 sub c ;works as add 100/10/1 push af ;safer than ld c,a ld a,b ;char is in b CALL PUTCHAR ;plot a char. Replace with bcall(_PutC) or similar. pop af ;safer than ld a,c ret;Note the following one is optimized for RPGs menus and the such, it is quite flexible. I am going to use in Lost Legends I ^^;I started with one which used addition RAM for temporary storage (made by me, too), and optimized for size, speed and no extra memory use! ^.^;the inc's and dec's were trick to debug -.-", the registers b and c are like counters and flags;DispHL for games;input: hl=num, d=row,e=col, c=number of algarisms to skip;number of numbers' characters to display: 5 ; example: 65000;output: hl displayed, with algarisms skiped and spaces for initial zerosDispHL_games: inc c ld b,1 ;skip 0 flag ld (CurRow),de;Number in hl to decimal ASCII;Thanks to z80 Bits;inputs: hl = number to ASCII;example: hl=300 outputs ' 300';destroys: af, hl, de used ld de,-10000 call Num1 ld de,-1000 call Num1 ld de,-100 call Num1 ld e,-10 call Num1 ld e,-1Num1: ld a,'0'-1Num2: inc a add hl,de jr c,Num2 sbc hl,de dec c ;c is skipping jr nz,skipnum inc c djnz notcharnumzero cp '0' jr nz,notcharnumzeroleadingzero: inc bskipnum: ld a,' 'notcharnumzero: push bc call PUTCHAR ;bcall(_PutC) works, not sure if it preserves bc pop bc retPUTCHAR: bcall(_PutC) ret;Example usage of DispHL_games to understand what I meanTest2: ld hl,60003 ld de,$0101 ld c,0 call DispHL_games ld hl,60003 ld de,$0102 ld c,1 call DispHL_games ret
ld a,xxout (1),ald a,(de)in a,(1)and yy
ld a,xxout (1),ald b,yyin a,(1)and b
dild a,$99ld bc,$0100ld h,ald d,ald l,cld e,bld i,ainc ald (hl),aldirld l,ald (hl),$c3inc lld (hl),intvec & $ffinc lld (hl),intvec >> 8im 2ei
;author: calcmaniac84, I think;Copy zero terminated string at HL to DE.StrCopy: xor adocopystr: cp (hl) ldi jr nz,docopystr ret
scroll_up:#ifdef DEBUG cp 64+1 call c,ErrorOverFlow#endif add a,a add a,a ld l,a ld e,a ld h,0 ld d,h add hl,hl add hl,de ; hl=a*12 push hl ld de,768 ex de,hl; carry is never set here if input is correct; or a sbc hl,de ld b,h ld c,l ; bc=768-12*a ex de,hl ld de,plotsscreen add hl,de ldir;blank remaining area ld h,d ld l,e inc de ld (hl),$00 pop bc dec bc ; bc=12*a-1 ldir ret;PSEUDO CODE; ld hl,plotsscreen+12*a; ld de,plotsscreen; ld bc,768-12*a; ldir; ld h,d; ld l,e; ld (hl),$00; inc de; ld bc,12*a; dec bc; ldir; retscroll_down:#ifdef DEBUG cp 64+1 call c,ErrorOverFlow#endif; a can be from 1 to 63; a can be multiplied by 4 add a,a add a,a ; a*4 ld l,a ; hl = a*4 ld e,a xor a ld h,a ld d,a add hl,hl ; hl = a*8 add hl,de ; hl = a*12 ld e,a ; de = 0 push hl ; a*12 will needed later push hl ; 2 times ex de,hl;carry is never set here; or a sbc hl,de ; hl= -a*12, de=a*12 ld de,plotsscreen+767 add hl,de ; hl=plotsscreen+767-12*a pop bc push hl ld hl,768+1;carry always set; or a sbc hl,bc ld b,h ld c,l pop hl lddr;blank remaining area ld h,d ld l,e ld (hl),$00 dec de pop bc dec bc lddr ret; ld hl,plotsscreen+767-12*a; ld de,plotsscreen+767; ld bc,768-12*a; lddr; or; ld (hl),$00 ;; ld hl,plotsscreen; ld h,d ;; ld (hl),$00; ld l,e ;; ld de,hl+1; dec de ;; ld bc,12*a-1; ld bc,12*a-1 ;; ldir; lddr ;; ret; ret
Very nice! I'll add these to my utils.z80 file that is included in all my app builds.Anyone wanting to compile a stdlib.c and revive the tisdcc project? j/k
Seems pretty impossible to me.
B_CALL(_SetXXXXOP2)B_CALL(_Op2ToOP1)ld hl,$yyxxld (PenCol),hlld a,5B_CALL(_DispOP1A)
push hlld hl,$yyxxld (PenCol),hlpop hlB_CALL(_DispHL)
Quigibo's Challenge!Can any of the following be done in 6 or fewer bytes? The input and output must be HL.Multiply by 128?Signed division by any nontrivial constant, other than 2, including negative numbers?Modulus with any constant that is not a power of 2?