2018-09-09 03:52:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "6502_emulate.h"
|
|
|
|
#include "gr-sim.h"
|
|
|
|
|
2018-09-09 19:54:53 +00:00
|
|
|
#define HGR_HORIZ 0xff
|
2018-09-09 03:52:58 +00:00
|
|
|
#define TEMP_R 0xfe
|
|
|
|
|
|
|
|
static void fancy_div(int d, int *q, int *r) {
|
|
|
|
|
|
|
|
//;Divide by 7 (From December '84 Apple Assembly Line)
|
|
|
|
//;15 bytes, 27 cycles
|
|
|
|
|
|
|
|
// y=xhigh x=xlow a=??
|
2018-09-09 19:54:53 +00:00
|
|
|
// q in y, r in a
|
2018-09-09 03:52:58 +00:00
|
|
|
|
|
|
|
y=(d>>8)&0xff;
|
|
|
|
x=d&0xff;
|
|
|
|
|
|
|
|
a=x;
|
|
|
|
|
|
|
|
sta(TEMP_R);
|
|
|
|
|
|
|
|
c=0;
|
2018-09-09 19:54:53 +00:00
|
|
|
sta(HGR_HORIZ); // 0
|
2018-09-09 03:52:58 +00:00
|
|
|
lsr(); // 0
|
|
|
|
lsr(); // 0
|
|
|
|
lsr(); // 0
|
2018-09-09 19:54:53 +00:00
|
|
|
adc_mem(HGR_HORIZ); // 0
|
2018-09-09 03:52:58 +00:00
|
|
|
ror(); // 0
|
|
|
|
lsr(); // 0
|
|
|
|
lsr(); // 0
|
2018-09-09 19:54:53 +00:00
|
|
|
adc_mem(HGR_HORIZ); // 0
|
2018-09-09 03:52:58 +00:00
|
|
|
ror(); // 0
|
|
|
|
lsr(); // 0
|
|
|
|
lsr(); // 0
|
|
|
|
|
2018-09-09 19:54:53 +00:00
|
|
|
// calc remainder
|
|
|
|
|
2018-09-09 03:52:58 +00:00
|
|
|
c=0;
|
2018-09-09 19:54:53 +00:00
|
|
|
sta(HGR_HORIZ);
|
2018-09-09 03:52:58 +00:00
|
|
|
asl();
|
2018-09-09 19:54:53 +00:00
|
|
|
adc_mem(HGR_HORIZ);
|
2018-09-09 03:52:58 +00:00
|
|
|
asl();
|
2018-09-09 19:54:53 +00:00
|
|
|
adc_mem(HGR_HORIZ);
|
|
|
|
// HGR_HORIZ=x/7, A=HGR_HORIZ*7
|
|
|
|
|
2018-09-09 03:52:58 +00:00
|
|
|
|
|
|
|
c=1;
|
2018-09-09 19:54:53 +00:00
|
|
|
eor(0xff);
|
|
|
|
// printf("%d+%d=",d&0xff,a);
|
|
|
|
adc(d&0xff);
|
|
|
|
// printf("%d\n",a);
|
|
|
|
|
|
|
|
|
|
|
|
// sta(TEMP_R);
|
|
|
|
// txa();
|
|
|
|
// sbc_mem(TEMP_R);
|
|
|
|
// tax();
|
2018-09-09 03:52:58 +00:00
|
|
|
|
|
|
|
if (y) {
|
|
|
|
c=0;
|
2018-09-09 19:54:53 +00:00
|
|
|
adc(4);
|
|
|
|
pha();
|
|
|
|
lda(HGR_HORIZ);
|
2018-09-09 03:52:58 +00:00
|
|
|
adc(36);
|
2018-09-09 19:54:53 +00:00
|
|
|
sta(HGR_HORIZ);
|
|
|
|
pla();
|
2018-09-09 03:52:58 +00:00
|
|
|
}
|
|
|
|
|
2018-09-09 19:54:53 +00:00
|
|
|
if (a>6) {
|
2018-09-09 03:52:58 +00:00
|
|
|
c=1;
|
|
|
|
sbc(7);
|
2018-09-09 19:54:53 +00:00
|
|
|
ram[HGR_HORIZ]++;
|
2018-09-09 03:52:58 +00:00
|
|
|
}
|
|
|
|
|
2018-09-09 19:54:53 +00:00
|
|
|
y=ram[HGR_HORIZ];
|
|
|
|
|
2018-09-09 03:52:58 +00:00
|
|
|
*q=y;
|
2018-09-09 19:54:53 +00:00
|
|
|
*r=a;
|
2018-09-09 03:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
int i,actual_q,actual_r;
|
|
|
|
int fancy_q,fancy_r;
|
|
|
|
|
|
|
|
grsim_init();
|
|
|
|
|
|
|
|
for(i=0;i<280;i++) {
|
|
|
|
|
|
|
|
fancy_div(i,&fancy_q,&fancy_r);
|
|
|
|
|
|
|
|
actual_q=i/7;
|
|
|
|
actual_r=i%7;
|
|
|
|
|
|
|
|
if ((fancy_q!=actual_q) || (fancy_r!=actual_r)) {
|
|
|
|
printf("%03x\t%d,%d\t%d,%d\n",
|
|
|
|
i,actual_q,actual_r,fancy_q,fancy_r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|