Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
some more minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenni Hein committed Jul 20, 2019
1 parent ae36d15 commit 026ab68
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
5 changes: 2 additions & 3 deletions docs/info.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### Memory

|||
| | |
|:---:|:---:|
Interrupt Enable Regs | 0xffff
Internal RAM | 0xff80
Expand All @@ -19,8 +19,7 @@ echo | 0xe000
8kB switchable RAM bank | 0xa000
8kB VRAM | 0x8000
16kB switchable ROM bank | 0x4000
16 kB ROM bank #0 | 0x0000
```// todo: find out about the upper bound of interrupt enable regs```
16 kB ROM bank #0 | 0x0000```// todo: find out about the upper bound of interrupt enable regs```

#### echo

Expand Down
48 changes: 23 additions & 25 deletions source/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ FILE* LOG_OUTPUT;

// Zero Flag
#define FLAG_Z ((F&0x80)>>7)
#define SET_FLAG_Z(X) F&=0x7F; F|=X<<7;
#define SET_FLAG_Z(X) F&=0x7F; F|=(X)<<7;

// Add/Sub Flag (BCD)
#define FLAG_N ((F&0x40)>>6)
#define SET_FLAG_N(X) F&=0xBF; F|=X<<6;
#define SET_FLAG_N(X) F&=0xBF; F|=(X)<<6;

//Half Carry Flag
#define FLAG_H ((F&0x20)>>5)
#define SET_FLAG_H(X) F&=0xDF; F|=X<<5;
#define SET_FLAG_H(X) F&=0xDF; F|=(X)<<5;

// Carry Flag
#define FLAG_C ((F&0x10)>>4)
#define SET_FLAG_C(X) F&=0xEF; F|=X<<4;
#define SET_FLAG_C(X) F&=0xEF; F|=(X)<<4;

// 0x9800 - 0x9FFF
#define BG_CUR_FRAME MEM[0x9800]
Expand All @@ -83,15 +83,15 @@ FILE* LOG_OUTPUT;

#define WINDOW_Y_COORDINATE MEM[0xFF4A]
#define WINDOW_X_COORDINATE MEM[0xFF4B]
#define SPRITE_Y_COORDINATE(x) MEM[0xFE00+x*4]
#define SPRITE_X_COORDINATE(x) MEM[0xFE01+x*4]
#define SPRITE_Y_COORDINATE(x) MEM[0xFE00+(x)*4]
#define SPRITE_X_COORDINATE(x) MEM[0xFE01+(x)*4]

#define PRIORITY(x) MEM[0xFE03+x*4]&128
#define PRIORITY(x) MEM[0xFE03+(x)*4]&128
// flipped vertically
#define IS_FLIPPED_V(x) MEM[0xFE03+x*4]&64
#define IS_FLIPPED_V(x) MEM[0xFE03+(x)*4]&64
// flipped horizontal
#define IS_FLIPPED_H(x) MEM[0xFE03+x*4]&32
#define PALETTE(x) MEM[0xFE03+x*4]&16
#define IS_FLIPPED_H(x) MEM[0xFE03+(x)*4]&32
#define PALETTE(x) MEM[0xFE03+(x)*4]&16

uint8_t interrupt_master_enable;

Expand All @@ -102,15 +102,15 @@ uint8_t interrupt_master_enable;
#define INTERRUPT_ENABLE (MEM[0xFFFF])
#define INTERRUPT_FLAGS (MEM[0xFF0F])
#define INTERRUPT_VBLANK (INTERRUPT_FLAGS&0x01)
#define SET_INTERRUPT_VBLANK(X) INTERRUPT_FLAGS&=0x01; INTERRUPT_FLAGS|=X;
#define SET_INTERRUPT_VBLANK(X) INTERRUPT_FLAGS&=0x01; INTERRUPT_FLAGS|=(X);
#define INTERRUPT_LCD (INTERRUPT_FLAGS&0x02)
#define SET_INTERRUPT_LCD(X) INTERRUPT_FLAGS&=0x02; INTERRUPT_FLAGS|=X<<1;
#define SET_INTERRUPT_LCD(X) INTERRUPT_FLAGS&=0x02; INTERRUPT_FLAGS|=(X)<<1;
#define INTERRUPT_TIMER (INTERRUPT_FLAGS&0x04)
#define SET_INTERRUPT_TIMER(X) INTERRUPT_FLAGS&=0x04; INTERRUPT_FLAGS|=X<<2;
#define SET_INTERRUPT_TIMER(X) INTERRUPT_FLAGS&=0x04; INTERRUPT_FLAGS|=(X)<<2;
#define INTERRUPT_SERIAL (INTERRUPT_FLAGS&0x08)
#define SET_INTERRUPT_SERIAL(X) INTERRUPT_FLAGS&=0x08; INTERRUPT_FLAGS|=X<<3;
#define SET_INTERRUPT_SERIAL(X) INTERRUPT_FLAGS&=0x08; INTERRUPT_FLAGS|=(X)<<3;
#define INTERRUPT_JOYPAD (INTERRUPT_FLAGS&0x10)
#define SET_INTERRUPT_JOYPAD(X) INTERRUPT_FLAGS&=0x10; INTERRUPT_FLAGS|=X<<4;
#define SET_INTERRUPT_JOYPAD(X) INTERRUPT_FLAGS&=0x10; INTERRUPT_FLAGS|=(X)<<4;

#define ENABLE_VBLANK INTERRUPT_ENABLE|=0x01;
#define DISABLE_VBLANK INTERRUPT_ENABLE&=0xFE;
Expand Down Expand Up @@ -227,8 +227,6 @@ void reset_coredump(uint32_t length, uint16_t coredumpnum);

void remove_all_coredumps(uint16_t coredumpnum);

void PPU();

void convert_tile(uint8_t* input_ptr, uint32_t* output_ptr);

void convert_line(const uint8_t* input_ptr, uint32_t* output_ptr);
Expand All @@ -239,22 +237,22 @@ void background_tiles();
#define CHAR_TO_INT8(R) comma=0;\
buf[0]=fgetc(coredump); \
buf[1]=fgetc(coredump); \
if(buf[1]==44){R=buf[0]-48; comma=1;} \
if(buf[1]==44){(R)=buf[0]-48; comma=1;} \
else{buf[2]=fgetc(coredump); \
if(buf[2]==44){R=buf[1]-48+(buf[0]-48)*10; comma=1;} \
else{R=buf[2]-48+(buf[1]-48)*10+(buf[0]-48)*100;}} \
if(buf[2]==44){(R)=buf[1]-48+(buf[0]-48)*10; comma=1;} \
else{(R)=buf[2]-48+(buf[1]-48)*10+(buf[0]-48)*100;}} \
if(!comma){fgetc(coredump);}

#define CHAR_TO_INT16(R) buf[0]=fgetc(coredump); \
buf[1]=fgetc(coredump); \
if(buf[1]==44){R=buf[0]-48; comma=1;} \
if(buf[1]==44){(R)=buf[0]-48; comma=1;} \
else{buf[2]=fgetc(coredump); \
if(buf[2]==44){R=buf[1]-48+(buf[0]-48)*10; comma=1;} \
if(buf[2]==44){(R)=buf[1]-48+(buf[0]-48)*10; comma=1;} \
else{buf[3]=fgetc(coredump);\
if(buf[3]==44){R=buf[2]-48+(buf[1]-48)*10+(buf[0]-48)*100; comma=1;}\
if(buf[3]==44){(R)=buf[2]-48+(buf[1]-48)*10+(buf[0]-48)*100; comma=1;}\
else{buf[4]=fgetc(coredump);\
if(buf[4]==44){R=buf[3]-48+(buf[2]-48)*10+(buf[1]-48)*100+(buf[0]-48)*1000;comma=1;}\
else{R=buf[4]-48+(buf[3]-48)*10+(buf[2]-48)*100+(buf[1]-48)*1000+(buf[0]-48)*10000;comma=1;}}}} \
if(buf[4]==44){(R)=buf[3]-48+(buf[2]-48)*10+(buf[1]-48)*100+(buf[0]-48)*1000;comma=1;}\
else{(R)=buf[4]-48+(buf[3]-48)*10+(buf[2]-48)*100+(buf[1]-48)*1000+(buf[0]-48)*10000;comma=1;}}}} \
if(!comma){fgetc(coredump); comma=0;}

// flags
Expand Down
8 changes: 6 additions & 2 deletions source/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
if(!A){SET_FLAG_Z(1);}else{SET_FLAG_Z(0);} SET_FLAG_N(0); SET_FLAG_H(0);

// 0x10
#define OP_STOP /* TODO */
// todo
#define OP_STOP

// 0x11
#define OP_LD_DE_D16 DE = *((uint16_t*) (MEM+PC+1));
Expand Down Expand Up @@ -140,6 +141,7 @@
#define OP_LD_H_D8 H = MEM[PC+1];

// 0x27 decimal adjust register A
// todo
#define OP_DAA if(!A){SET_FLAG_Z(1);}else{SET_FLAG_Z(0);} SET_FLAG_H(0); /* TODO */
// https://www.tutorialspoint.com/daa-instruction-in-8085-microprocessor

Expand Down Expand Up @@ -205,6 +207,7 @@
if((uint32_t)HL+(uint32_t)SP<32767){SET_FLAG_C(1);}else{SET_FLAG_C(0);} \
HL=HL+SP; SET_FLAG_N(0);
// 0x3A
// todo
#define OP_LD_A_PHLD A=MEM[HL--];

// 0x3B
Expand Down Expand Up @@ -387,7 +390,8 @@
#define OP_LD_PHL_L MEM[HL]=L;

// 0x76
#define OP_HALT /* TODO HALT */
// todo
#define OP_HALT

// 0x77
#define OP_LD_PHL_A MEM[HL]=A;
Expand Down

0 comments on commit 026ab68

Please sign in to comment.