diff --git a/sample/a.o65 b/sample/a.o65 new file mode 100644 index 0000000..cc97692 Binary files /dev/null and b/sample/a.o65 differ diff --git a/sample/draw.asm b/sample/draw.asm index 87b428f..218cfe1 100644 --- a/sample/draw.asm +++ b/sample/draw.asm @@ -1,9 +1,72 @@ - lda #$0 +; head position +ldx #$00 +stx $00 ; head position low +ldx #$e0 +stx $01 ; head position high + +; old head position +ldx #$ff ; start one behind head +stx $02 ; old head position low +ldx #$e0 +stx $03 ; old head position high + +; colours +ldx #$f0 +stx $04 ; paint colour +ldx #$00 +stx $05 ; rubber colour + +move_head_right + inc $00 + + lda $04 + ldx #$00 + sta ($00, x) + + clv + bvc move_rubber_right + +after_rubbed + ldx $00 + cpx #$ff + beq move_head_down + bne move_head_right + +move_rubber_right + inc $02 + + lda $05 + ldx #$02 + sta ($00, x) + +; ldx $02 +; cpx #$40 +; bne continue_rubbing +; dec $02 + clv +; bvc continue_rubbing + +;continue_rubbing + ldx $02 + cpx #$ff + beq move_rubber_down + clv + bvc after_rubbed + +move_head_down + inc $01 + + ldx $00 + stx $00 + + clv + bvc move_head_right + +move_rubber_down + inc $03 + ldx $00 + stx $02 + bvc after_rubbed + - loop - sta $e000, x - inx - adc #$1 - cpx #$ff - bne loop diff --git a/src/machine/terminal.cpp b/src/machine/terminal.cpp index 1f2264f..f129666 100644 --- a/src/machine/terminal.cpp +++ b/src/machine/terminal.cpp @@ -29,14 +29,11 @@ namespace emu_6502 { x = (i - LOW_ADDR) % WIDTH; y = (i - LOW_ADDR) / HEIGHT; - auto colour = memory.get_at(i); - if (colour) { - draw_pixel(x, y, colour); - } + draw_pixel(x, y, memory.get_at(i)); } SDL_RenderPresent(renderer); - SDL_Delay(5); + //SDL_Delay(20); } void Terminal::draw_pixel(int x, int y, uint8_t colour) { @@ -45,15 +42,14 @@ namespace emu_6502 { green = (colour >> 2) & 0x07; blue = colour & 0x03; - cout << "RED: " << (int)red << " GREEN: " << (int)green << " BLUE: " << (int)blue << endl; + //cout << "x: " << (int)x << " y: " << (int)y << " RED: " << (int)red << " GREEN: " << (int)green << " BLUE: " << (int)blue << endl; - SDL_SetRenderDrawColor(renderer, red * 36, green * 36, blue * 85, 0); - for (int i = 0; i < PIXEL_WEIGHT; i++) { - SDL_RenderDrawPoint(renderer, (x * PIXEL_WEIGHT) + i, (y * PIXEL_WEIGHT)); - - for (int j = 0; j < PIXEL_WEIGHT; j++) { - SDL_RenderDrawPoint(renderer, (x * PIXEL_WEIGHT) + i, (y * PIXEL_WEIGHT) + j); - } - } + SDL_SetRenderDrawColor(renderer, red * 36, green * 36, blue * 85, 255); + SDL_Rect rect{}; + rect.x = x * PIXEL_WEIGHT; + rect.y = y * PIXEL_WEIGHT; + rect.w = PIXEL_WEIGHT; + rect.h = PIXEL_WEIGHT; + SDL_RenderFillRect(renderer, &rect); } } \ No newline at end of file diff --git a/src/machine/terminal.h b/src/machine/terminal.h index d3f6e2a..cd901c2 100644 --- a/src/machine/terminal.h +++ b/src/machine/terminal.h @@ -2,6 +2,7 @@ #define INC_6502_EMULATOR_TERMINAL_H #include +#include #include #include "memory.h" @@ -10,11 +11,11 @@ using namespace std; namespace emu_6502 { class Terminal { private: - const uint16_t LOW_ADDR = 0xE000; - const uint16_t HIGH_ADDR = 0xF000; - const uint8_t WIDTH = 64; - const uint8_t HEIGHT = 64; - const uint8_t PIXEL_WEIGHT = 8; + static const uint16_t LOW_ADDR = 0xE000; + static const uint16_t HIGH_ADDR = 0xF000; + static const uint8_t WIDTH = 64; + static const uint8_t HEIGHT = 64; + static const uint8_t PIXEL_WEIGHT = 8; Memory& memory; diff --git a/src/main.cpp b/src/main.cpp index 07355ef..a928e6e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ int main() { (istreambuf_iterator())); auto machine = make_unique(); - machine->load(code, 0x600); + machine->load(code, 0x1000); machine->execute(); return 0; diff --git a/src/opcode/handler/maths-opcode-handler-container.cpp b/src/opcode/handler/maths-opcode-handler-container.cpp index a63f76a..eaaa394 100644 --- a/src/opcode/handler/maths-opcode-handler-container.cpp +++ b/src/opcode/handler/maths-opcode-handler-container.cpp @@ -154,7 +154,6 @@ namespace emu_6502 { void MathsOpcodeHandlerContainer::inc(Machine& machine, uint16_t address) { uint8_t value = machine.get_memory().get_at(address) + 1; machine.get_memory().set_at(address, value); - set_zero_and_neg_flags(machine.get_cpu().get_ps(), value); } diff --git a/src/utils.cpp b/src/utils.cpp index 3ab86e6..aa54e83 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -65,7 +65,6 @@ namespace emu_6502 { auto low = machine.get_memory().get_at(paddress); auto high = machine.get_memory().get_at(paddress + 1); uint16_t address = (high << 8) + low; - return address; } diff --git a/src/utils.h b/src/utils.h index 969ec0e..34a2336 100644 --- a/src/utils.h +++ b/src/utils.h @@ -4,6 +4,7 @@ #include "machine/machine.h" #include #include +#include using namespace std;