mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-06-08 00:29:35 +00:00
hgr: more work on constant-time hplot
This commit is contained in:
parent
97a6c49604
commit
e89c0e85dd
111
fireworks/hgr.s
111
fireworks/hgr.s
|
@ -80,13 +80,19 @@ bkgnd_loop:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
msktbl: .byte $81,$82,$84,$88,$90,$A0,$C0
|
msktbl: .byte $81,$82,$84,$88,$90,$A0,$C0 ; original
|
||||||
|
|
||||||
|
|
||||||
hposn:
|
hposn:
|
||||||
; F411
|
; F411
|
||||||
|
; move into expected zp locations
|
||||||
sta HGR_Y ; 3
|
sta HGR_Y ; 3
|
||||||
stx HGR_X ; 3
|
stx HGR_X ; 3
|
||||||
sty HGR_X+1 ; 3
|
sty HGR_X+1 ; 3
|
||||||
|
;===========
|
||||||
|
; 9
|
||||||
|
|
||||||
|
; calc y-position addr. no lookup table?
|
||||||
pha ; 3
|
pha ; 3
|
||||||
and #$C0 ; 2
|
and #$C0 ; 2
|
||||||
sta GBASL ; 3
|
sta GBASL ; 3
|
||||||
|
@ -95,9 +101,6 @@ hposn:
|
||||||
ora GBASL ; 3
|
ora GBASL ; 3
|
||||||
sta GBASL ; 3
|
sta GBASL ; 3
|
||||||
pla ; 4
|
pla ; 4
|
||||||
;===========
|
|
||||||
; 31
|
|
||||||
; F423
|
|
||||||
sta GBASH ; 3
|
sta GBASH ; 3
|
||||||
asl ; 2
|
asl ; 2
|
||||||
asl ; 2
|
asl ; 2
|
||||||
|
@ -112,24 +115,98 @@ hposn:
|
||||||
ora HGR_PAGE ; 3
|
ora HGR_PAGE ; 3
|
||||||
sta GBASH ; 3
|
sta GBASH ; 3
|
||||||
;============
|
;============
|
||||||
; 39
|
; 61
|
||||||
; F438
|
; F438
|
||||||
txa ; 2
|
; divide/mod 16-bit x poisition by 7
|
||||||
cpy #0 ; 2
|
; incoming, X=(y,x)
|
||||||
beq hposn_2 ; 3
|
; outgoing y=q, a=r
|
||||||
|
|
||||||
|
; Divide by 7 (From December '84 Apple Assembly Line)
|
||||||
|
|
||||||
|
txa
|
||||||
|
clc
|
||||||
|
sta HGR_HORIZ
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
adc HGR_HORIZ
|
||||||
|
ror
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
adc HGR_HORIZ
|
||||||
|
ror
|
||||||
|
lsr
|
||||||
|
lsr
|
||||||
|
; x/7 is in A
|
||||||
|
|
||||||
|
; calculate remainder
|
||||||
|
clc
|
||||||
|
sta HGR_HORIZ
|
||||||
|
asl
|
||||||
|
adc HGR_HORIZ
|
||||||
|
asl
|
||||||
|
adc HGR_HORIZ
|
||||||
|
; HGR_HORIZ=x/7, A=HGR_HORIZ*7
|
||||||
|
|
||||||
|
; calculate remainder by X-(Q*7)
|
||||||
|
sec
|
||||||
|
eor #$ff
|
||||||
|
adc HGR_X
|
||||||
|
; A = remainder
|
||||||
|
|
||||||
|
cpy #0
|
||||||
|
beq only_low
|
||||||
|
theres_high:
|
||||||
|
|
||||||
|
clc
|
||||||
|
adc #4 ; make remainder match
|
||||||
|
pha
|
||||||
|
lda HGR_HORIZ
|
||||||
|
adc #36
|
||||||
|
sta HGR_HORIZ
|
||||||
|
pla
|
||||||
|
only_low:
|
||||||
|
cmp #7
|
||||||
|
bcc done_mod ; blt
|
||||||
|
|
||||||
|
sec
|
||||||
|
sbc #7
|
||||||
|
inc HGR_HORIZ
|
||||||
|
|
||||||
|
done_mod:
|
||||||
|
|
||||||
|
|
||||||
|
; txa ; 2
|
||||||
|
; cpy #0 ; 2
|
||||||
|
; beq hposn_2 ; 3
|
||||||
; -1
|
; -1
|
||||||
ldy #35 ; 2
|
; ldy #35 ; 2
|
||||||
adc #4 ; 2
|
; adc #4 ; 2
|
||||||
hposn_1:
|
;hposn_1:
|
||||||
iny ; 2
|
; iny ; 2
|
||||||
; f442
|
; f442
|
||||||
hposn_2:
|
;hposn_2:
|
||||||
sbc #7 ; 2
|
; sbc #7 ; 2
|
||||||
bcs hposn_1 ; 3
|
; bcs hposn_1 ; 3
|
||||||
; -1
|
; -1
|
||||||
sty HGR_HORIZ ; 3
|
ldy HGR_HORIZ
|
||||||
|
; sty HGR_HORIZ ; 3
|
||||||
tax ; 2
|
tax ; 2
|
||||||
lda msktbl-$100+7,x ; LDA MSKTBL-$100+7,X BIT MASK ; 4?
|
lda msktbl,x ;
|
||||||
|
; lda msktbl-$100+7,x ; LDA MSKTBL-$100+7,X BIT MASK ; 4?
|
||||||
|
; weird two's complement?
|
||||||
|
|
||||||
|
; if x=-6 = 249 = fa
|
||||||
|
; F5b2 - 1000 = f4b2
|
||||||
|
; f4b2+7 = f4b9
|
||||||
|
; -1 ff + f4b9 = f5b8 C0 6
|
||||||
|
; -2 fe + f4b9 = f5b7 A0 5
|
||||||
|
; -3 fd + f4b9 = f5b6 90 4
|
||||||
|
; -4 fc + f4b9 = f5b5 88 3
|
||||||
|
; -5 fb + f4b9 = f5b4 84 2
|
||||||
|
; -6 fa + f4b9 = f5b3 82 1
|
||||||
|
; -7 f9 + f4b9 = f5b2 81 0
|
||||||
|
|
||||||
; MSKTBL=F5B2
|
; MSKTBL=F5B2
|
||||||
sta HMASK ; 3
|
sta HMASK ; 3
|
||||||
tya ; 2
|
tya ; 2
|
||||||
|
|
|
@ -423,6 +423,24 @@ void txa(void) {
|
||||||
a=x;
|
a=x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void eor(int value) {
|
||||||
|
|
||||||
|
int temp_a;
|
||||||
|
int temp_value;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
temp_a=a&0xff;
|
||||||
|
temp_value=value&0xff;
|
||||||
|
|
||||||
|
result=(temp_a^temp_value);
|
||||||
|
|
||||||
|
n=(result&0x80)>>7;
|
||||||
|
|
||||||
|
a=result&0xff;
|
||||||
|
z=(a==0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
unsigned char high(int value) {
|
unsigned char high(int value) {
|
||||||
return (value>>8)&0xff;
|
return (value>>8)&0xff;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ unsigned short y_indirect(unsigned char base, unsigned char y);
|
||||||
int init_6502(void);
|
int init_6502(void);
|
||||||
void adc(int value);
|
void adc(int value);
|
||||||
void sbc(int value);
|
void sbc(int value);
|
||||||
|
void eor(int value);
|
||||||
void cmp(int value);
|
void cmp(int value);
|
||||||
void cpy(int value);
|
void cpy(int value);
|
||||||
void cpx(int value);
|
void cpx(int value);
|
||||||
|
@ -39,6 +40,7 @@ void ldx_const(int value);
|
||||||
void ldy(int addr);
|
void ldy(int addr);
|
||||||
void ldy_const(int value);
|
void ldy_const(int value);
|
||||||
void sta(int addr);
|
void sta(int addr);
|
||||||
|
void inc_mem(int addr);
|
||||||
|
|
||||||
unsigned char high(int value);
|
unsigned char high(int value);
|
||||||
unsigned char low(int value);
|
unsigned char low(int value);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "6502_emulate.h"
|
#include "6502_emulate.h"
|
||||||
#include "gr-sim.h"
|
#include "gr-sim.h"
|
||||||
|
|
||||||
#define TEMP_Q 0xff
|
#define HGR_HORIZ 0xff
|
||||||
#define TEMP_R 0xfe
|
#define TEMP_R 0xfe
|
||||||
|
|
||||||
static void fancy_div(int d, int *q, int *r) {
|
static void fancy_div(int d, int *q, int *r) {
|
||||||
|
@ -15,7 +15,7 @@ static void fancy_div(int d, int *q, int *r) {
|
||||||
//;15 bytes, 27 cycles
|
//;15 bytes, 27 cycles
|
||||||
|
|
||||||
// y=xhigh x=xlow a=??
|
// y=xhigh x=xlow a=??
|
||||||
// q in y, r in x
|
// q in y, r in a
|
||||||
|
|
||||||
y=(d>>8)&0xff;
|
y=(d>>8)&0xff;
|
||||||
x=d&0xff;
|
x=d&0xff;
|
||||||
|
@ -25,52 +25,62 @@ static void fancy_div(int d, int *q, int *r) {
|
||||||
sta(TEMP_R);
|
sta(TEMP_R);
|
||||||
|
|
||||||
c=0;
|
c=0;
|
||||||
sta(TEMP_Q); // 0
|
sta(HGR_HORIZ); // 0
|
||||||
lsr(); // 0
|
lsr(); // 0
|
||||||
lsr(); // 0
|
lsr(); // 0
|
||||||
lsr(); // 0
|
lsr(); // 0
|
||||||
adc_mem(TEMP_Q); // 0
|
adc_mem(HGR_HORIZ); // 0
|
||||||
ror(); // 0
|
ror(); // 0
|
||||||
lsr(); // 0
|
lsr(); // 0
|
||||||
lsr(); // 0
|
lsr(); // 0
|
||||||
adc_mem(TEMP_Q); // 0
|
adc_mem(HGR_HORIZ); // 0
|
||||||
ror(); // 0
|
ror(); // 0
|
||||||
lsr(); // 0
|
lsr(); // 0
|
||||||
lsr(); // 0
|
lsr(); // 0
|
||||||
|
|
||||||
|
// calc remainder
|
||||||
|
|
||||||
c=0;
|
c=0;
|
||||||
sta(TEMP_Q);
|
sta(HGR_HORIZ);
|
||||||
asl();
|
asl();
|
||||||
adc_mem(TEMP_Q);
|
adc_mem(HGR_HORIZ);
|
||||||
asl();
|
asl();
|
||||||
adc_mem(TEMP_Q);
|
adc_mem(HGR_HORIZ);
|
||||||
|
// HGR_HORIZ=x/7, A=HGR_HORIZ*7
|
||||||
|
|
||||||
|
|
||||||
c=1;
|
c=1;
|
||||||
sta(TEMP_R);
|
eor(0xff);
|
||||||
txa();
|
// printf("%d+%d=",d&0xff,a);
|
||||||
sbc_mem(TEMP_R);
|
adc(d&0xff);
|
||||||
tax();
|
// printf("%d\n",a);
|
||||||
|
|
||||||
|
|
||||||
|
// sta(TEMP_R);
|
||||||
|
// txa();
|
||||||
|
// sbc_mem(TEMP_R);
|
||||||
|
// tax();
|
||||||
|
|
||||||
if (y) {
|
if (y) {
|
||||||
x+=4;
|
|
||||||
lda(TEMP_Q);
|
|
||||||
c=0;
|
c=0;
|
||||||
|
adc(4);
|
||||||
|
pha();
|
||||||
|
lda(HGR_HORIZ);
|
||||||
adc(36);
|
adc(36);
|
||||||
sta(TEMP_Q);
|
sta(HGR_HORIZ);
|
||||||
|
pla();
|
||||||
}
|
}
|
||||||
|
|
||||||
y=ram[TEMP_Q];
|
if (a>6) {
|
||||||
|
|
||||||
if (x>6) {
|
|
||||||
c=1;
|
c=1;
|
||||||
txa();
|
|
||||||
sbc(7);
|
sbc(7);
|
||||||
tax();
|
ram[HGR_HORIZ]++;
|
||||||
y++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
y=ram[HGR_HORIZ];
|
||||||
|
|
||||||
*q=y;
|
*q=y;
|
||||||
*r=x;
|
*r=a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user