0 Members and 3 Guests are viewing this topic.
If conditiondo stuffElse16->WEnd
Also, I found it a bit annoying that when I did something like If E<(96*256), the part in the parentheses wasn't reduced to a constant before doing the less-than operation. Could the look-ahead parsing be able to detect constants in parentheses?
Quote from: calc84maniac on July 14, 2011, 11:31:27 pmAlso, I found it a bit annoying that when I did something like If E<(96*256), the part in the parentheses wasn't reduced to a constant before doing the less-than operation. Could the look-ahead parsing be able to detect constants in parentheses?This times a million.
p_GetArc: .db __GetArcEnd-1-$ push de MOV9TOOP1() B_CALL(_ChkFindSym) jr c,__GetArcFail dec b inc b jr z,__GetArcRam B_CALL(_IsFixedName) ld hl,9 jr z,__GetArcName__GetArcStatic: ld l,12 and %00011111 jr z,__GetArcDone cp l jr z,__GetArcDone ld l,14 jr __GetArcDone__GetArcName: add hl,de bit 7,h jr z,$+7 res 7,h set 6,h inc b B_CALL(_LoadDEIndPaged) ld d,0 inc e inc e__GetArcDone: add hl,de ex de,hl__GetArcStore: pop hl ld (hl),e inc hl ld (hl),d inc hl ld (hl),b ex de,hl ret__GetArcRam: and %00011111 jr z,__GetArcStore cp CplxObj jr z,__GetArcStore inc de inc de jr __GetArcStore__GetArcFail: ld hl,0 pop de ret__GetArcEnd:
p_GetArc: .db __GetArcEnd-1-$ push de MOV9TOOP1() B_CALL(_ChkFindSym) jr c,__GetArcFail dec b inc b jr z,__GetArcRam B_CALL(_IsFixedName) ld hl,9 jr z,__GetArcName ld l,12__GetArcChkFloat: and %00011111 jr z,__GetArcDone cp CplxObj jr z,__GetArcDone inc l inc l jr __GetArcDone__GetArcName: add hl,de bit 7,h jr z,$+7 res 7,h set 6,h inc b B_CALL(_LoadDEIndPaged) ld d,0 inc e inc e__GetArcDone: add hl,de ex de,hl pop hl ld (hl),e inc hl ld (hl),d inc hl ld (hl),b ex de,hl ret__GetArcRam: ld h,b ld l,b jr __GetArcChkFloat__GetArcFail: ld hl,0 pop de ret__GetArcEnd:
And on the topic of stuff that involves port 6, I think it would be nice if the archive byte reading routine avoided using a B_CALL for a massive speed boost, especially for code compiled as programs:p_ReadArc: 18 bytes (2x) larger, but ~1400 cycles (!!!10x!!!) fasterCode: (36 bytes, ~142 cycles) [Select]p_ReadArc: .db __ReadArcEnd-1-$ ld c,a in a,(6) ld b,a ld a,h set 6,h res 7,h rlca rlca dec a and %00000011 add a,c out (6),a ld c,(hl) inc hl bit 7,h jr z,__ReadArcNoBoundary set 6,h res 7,h inc a out (6),a__ReadArcNoBoundary: ld l,(hl) ld h,c ld a,b out (6),a ret__ReadArcEnd:p_ReadArcApp: 36 bytes (3x) larger, but ~1050 cycles (4x) fasterCode: (54 bytes, ~396 cycles) [Select]p_ReadArcApp: .db __ReadArcAppEnd-1-$ push hl ld hl,$0000 ld de,ramCode ld bc,__ReadArcAppRamCodeEnd-__ReadArcAppRamCode ldir pop hl ld e,a ld c,6 in b,(c) ld a,h set 6,h res 7,h rlca rlca dec a and %00000011 add a,e call ramCode ld e,d inc hl bit 7,h jr z,__ReadArcAppNoBoundary set 6,h res 7,h inc a__ReadArcAppNoBoundary: call ramCode ex de,hl ret__ReadArcAppEnd: .db rp_Ans,__ReadArcAppEnd-p_ReadArcApp-3__ReadArcAppRamCode: out (6),a ld d,(hl) out (c),b ret__ReadArcAppRamCodeEnd:
p_ReadArc: .db __ReadArcEnd-1-$ ld c,a in a,(6) ld b,a ld a,h set 6,h res 7,h rlca rlca dec a and %00000011 add a,c out (6),a ld c,(hl) inc hl bit 7,h jr z,__ReadArcNoBoundary set 6,h res 7,h inc a out (6),a__ReadArcNoBoundary: ld l,(hl) ld h,c ld a,b out (6),a ret__ReadArcEnd:
p_ReadArcApp: .db __ReadArcAppEnd-1-$ push hl ld hl,$0000 ld de,ramCode ld bc,__ReadArcAppRamCodeEnd-__ReadArcAppRamCode ldir pop hl ld e,a ld c,6 in b,(c) ld a,h set 6,h res 7,h rlca rlca dec a and %00000011 add a,e call ramCode ld e,d inc hl bit 7,h jr z,__ReadArcAppNoBoundary set 6,h res 7,h inc a__ReadArcAppNoBoundary: call ramCode ex de,hl ret__ReadArcAppEnd: .db rp_Ans,__ReadArcAppEnd-p_ReadArcApp-3__ReadArcAppRamCode: out (6),a ld d,(hl) out (c),b ret__ReadArcAppRamCodeEnd:
p_CopyArc: .db __CopyArcEnd-1-$ pop ix pop de ex (sp),hl ld b,a ld a,h rlca rlca dec a and %00000011 add a,b set 6,h res 7,h pop bc B_CALL(_FlashToRAM) jp (ix)__CopyArcEnd:
p_CopyArc: .db __CopyArcEnd-1-$ ex (sp),hl pop bc pop de ex (sp),hl or a jr z,__CopyArcRam push bc ld b,a ld a,h rlca rlca dec a and %00000011 add a,b set 6,h res 7,h pop bc B_CALL(_FlashToRAM) ret__CopyArcRam: ldir ret__CopyArcEnd:
;===============================================================sqrtE:;===============================================================;Input:; E is the value to find the square root of;Outputs:; A is E-D^2; B is 0; D is the rounded result; E is not changed; HL is not changed;Destroys:; C; xor a ;1 4 4 ld d,a ;1 4 4 ld c,a ;1 4 4 ld b,4 ;2 7 7sqrtELoop: rlc d ;2 8 32 ld c,d ;1 4 16 scf ;1 4 16 rl c ;2 8 32 rlc e ;2 8 32 rla ;1 4 16 rlc e ;2 8 32 rla ;1 4 16 cp c ;1 4 16 jr c,$+4 ;4 12|15 48+3x inc d ;-- -- -- sub c ;-- -- -- djnz sqrtELoop ;2 13|8 47 cp d ;1 4 4 jr c,$+3 ;3 12|11 12|11 inc d ;-- -- -- ret ;1 10 10;===============================================================;Size : 29 bytes;Speed : 347+3x cycles plus 1 if rounded down; x is the number of set bits in the result.;===============================================================
Wow, I just did something I didn't think was even possible. I found a good use for a forward djnz.
ld b,a or a \ jr nz,Next1 ;codeNext1: djnz Next2 ;codeNext2: djnz Next3 ;code;...et cetera
p_DKeyVar: .db __DKeyVarEnd-1-$ dec l ld a,l rra rra rra and %00000111 inc a ld b,a ld a,%01111111 rlca djnz $-1 ld h,a ld a,l and %00000111 inc a ld b,a ld a,%10000000 rlca djnz $-1 ld l,a ret__DKeyVarEnd:
p_DKeyVar: .db __DKeyVarEnd-1-$ ld a,l ld hl,%0111111111110111 rlc h adc a,l jr c,$-3 ld l,%0000001 rrc l inc a jr nz,$-3 ret__DKeyVarEnd: