mirror of
https://github.com/tdinucci/6502-emulator.git
synced 2025-02-17 08:30:39 +00:00
Start of graphics support
This commit is contained in:
parent
737b50e211
commit
5acb3ba8bb
BIN
sample/a.o65
Normal file
BIN
sample/a.o65
Normal file
Binary file not shown.
@ -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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
#define INC_6502_EMULATOR_TERMINAL_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <SDL2/SDL.h>
|
||||
#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;
|
||||
|
||||
|
@ -21,7 +21,7 @@ int main() {
|
||||
(istreambuf_iterator<char>()));
|
||||
|
||||
auto machine = make_unique<Machine>();
|
||||
machine->load(code, 0x600);
|
||||
machine->load(code, 0x1000);
|
||||
machine->execute();
|
||||
|
||||
return 0;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "machine/machine.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user