diff --git a/gr-sim/6502_emulate.c b/gr-sim/6502_emulate.c index 616019cf..9b38e46f 100644 --- a/gr-sim/6502_emulate.c +++ b/gr-sim/6502_emulate.c @@ -104,6 +104,45 @@ void cmp(int value) { z=(result==0); } +void cpy(int value) { + + int temp_y; + int temp_value; + int result; + + temp_y=a&0xff; + temp_value=(~value)&0xff; + + result=temp_y+temp_value+1; + + c=(result&0x100)>>8; + + result&=0xff; + + n=(result&0x80)>>7; + z=(result==0); +} + +void cpx(int value) { + + int temp_x; + int temp_value; + int result; + + temp_x=x&0xff; + temp_value=(~value)&0xff; + + result=temp_x+temp_value+1; + + c=(result&0x100)>>8; + + result&=0xff; + + n=(result&0x80)>>7; + z=(result==0); +} + + void pha(void) { sp--; @@ -223,6 +262,34 @@ void rol_mem(int addr) { } +void dex(void) { + x--; + + z=(x==0); + n=!!(x&0x80); +} + +void dey(void) { + y--; + + z=(y==0); + n=!!(y&0x80); +} + +void inx(void) { + x++; + + z=(x==0); + n=!!(x&0x80); +} + +void iny(void) { + y++; + + z=(y==0); + n=!!(y&0x80); +} + unsigned char high(int value) { return (value>>8)&0xff; diff --git a/gr-sim/6502_emulate.h b/gr-sim/6502_emulate.h index cdf00854..8c54fd6c 100644 --- a/gr-sim/6502_emulate.h +++ b/gr-sim/6502_emulate.h @@ -9,6 +9,8 @@ int init_6502(void); void adc(int value); void sbc(int value); void cmp(int value); +void cpy(int value); +void cpx(int value); void pha(void); void pla(void); void lsr(void); @@ -17,6 +19,15 @@ void ror(void); void rol(void); void ror_mem(int addr); void rol_mem(int addr); +void dex(void); +void dey(void); +void inx(void); +void iny(void); +void tax(void); +void tay(void); +void txa(void); +void tya(void); + unsigned char high(int value); unsigned char low(int value); diff --git a/gr-sim/hgr-sim.c b/gr-sim/hgr-sim.c index 49f390b6..172e09fb 100644 --- a/gr-sim/hgr-sim.c +++ b/gr-sim/hgr-sim.c @@ -187,8 +187,143 @@ int hplot(int xx, int yy) { return 0; } +static void move_left_or_right(void) { + // F465 + if (n==0) goto move_right; + + a=ram[HMASK]; + lsr(); + if (c==1) goto lr_2; + a=a^0xc0; +lr_1: + ram[HMASK]=a; + return; +lr_2: + dey(); + if (n==0) goto lr_3; + y=39; +lr_3: + a=0xc0; +lr_4: + ram[HMASK]=a; + ram[HGR_HORIZ]=y; + a=ram[HGR_BITS]; + color_shift(); + return; + +move_right: + a=ram[HMASK]; + asl(); + a=a^0x80; + if (a&0x80) goto lr_1; + a=0x81; + iny(); + cpy(40); + if (c==0) goto lr_4; + y=0; + goto lr_4; + +} + +static void move_up_or_down(void) { + +} + +static void hglin(void) { + + // F53A + pha(); + c=1; + sbc(ram[HGR_X]); + pha(); + a=x; + sbc(ram[HGR_X+1]); + ram[HGR_QUADRANT]=a; + // F544 + if (c==1) goto hglin_1; + pla(); + a=a^0xff; + adc(1); + pha(); + a=0; + sbc(ram[HGR_QUADRANT]); + // F550 +hglin_1: + ram[HGR_DX+1]=a; + ram[HGR_E+1]=a; + pla(); + ram[HGR_DX]=a; + ram[HGR_E]=a; + pla(); + ram[HGR_X]=a; + ram[HGR_X+1]=x; + a=y; + c=0; + sbc(ram[HGR_Y]); + if (c==0) goto hglin_2; + a=a^0xff; + adc(0xfe); +hglin_2: + // F566 + ram[HGR_DY]=a; + ram[HGR_Y]=y; + ror_mem(HGR_QUADRANT); + c=1; + sbc(ram[HGR_DX]); + x=a; + a=0xff; + sbc(ram[HGR_DX+1]); + ram[HGR_COUNT]=a; + y=ram[HGR_HORIZ]; + if (c==1) goto movex2; // always? + // f57c +movex: + asl(); + move_left_or_right(); + c=1; + + // f581 +movex2: + a=ram[HGR_E]; + adc(ram[HGR_DY]); + ram[HGR_E]=a; + a=ram[HGR_E+1]; + sbc(0); +movex2_1: + ram[HGR_E+1]=a; + a=ram[y_indirect(GBASL,y)]; + a=a^ram[HGR_BITS]; + a=a&ram[HMASK]; + a=a^ram[y_indirect(GBASL,y)]; + ram[y_indirect(GBASL,y)]=a; + x++; + if (x!=0) goto movex2_2; + ram[HGR_COUNT]++; + if (ram[HGR_COUNT]==0) return; + // F59e +movex2_2: + a=ram[HGR_QUADRANT]; + if (c==1) goto movex; + move_up_or_down(); + c=0; + a=ram[HGR_E]; + adc(ram[HGR_DX]); + ram[HGR_E]=a; + a=ram[HGR_E+1]; + adc(ram[HGR_DX+1]); + goto movex2_1; +} + int hplot_to(int xx, int yy) { + // F712 + hfns(xx,yy); + ram[DSCTMP]=y; + y=a; + a=x; + x=ram[DSCTMP]; + hglin(); + return 0; } diff --git a/gr-sim/tfv_zp.h b/gr-sim/tfv_zp.h index 5c583354..07300347 100644 --- a/gr-sim/tfv_zp.h +++ b/gr-sim/tfv_zp.h @@ -42,7 +42,16 @@ #define HGR_SHAPE 0x1A #define HGR_SHAPE_H 0x1B #define HGR_BITS 0x1C +#define HGR_COUNT 0x1D +#define DSCTMP 0x9D + +#define HGR_DX 0xD0 +#define HGR_DX_H 0xD1 +#define HGR_DY 0xD2 +#define HGR_QUADRANT 0xD3 +#define HGR_E 0xD4 +#define HGR_E_H 0xD5 #define HGR_X 0xE0 #define HGR_X_H 0xE1 #define HGR_Y 0xE2